]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/boot: Move boot_printk() code to own file
authorHeiko Carstens <hca@linux.ibm.com>
Wed, 4 Sep 2024 09:39:30 +0000 (11:39 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Sat, 7 Sep 2024 15:12:43 +0000 (17:12 +0200)
Keep the printk code separate from the program check code and move
boot_printk() and helper functions to own printk.c file.

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/boot/Makefile
arch/s390/boot/pgm_check_info.c
arch/s390/boot/printk.c [new file with mode: 0644]

index 1ee63054e085f11b7c5226b5931957bee857ed2b..8bc1308ac892ab71d7671dbd74e1656f33513e95 100644 (file)
@@ -26,7 +26,8 @@ CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
 
 obj-y  := head.o als.o startup.o physmem_info.o ipl_parm.o ipl_report.o vmem.o
 obj-y  += string.o ebcdic.o sclp_early_core.o mem.o ipl_vmparm.o cmdline.o
-obj-y  += version.o pgm_check_info.o ctype.o ipl_data.o relocs.o alternative.o uv.o
+obj-y  += version.o pgm_check_info.o ctype.o ipl_data.o relocs.o alternative.o
+obj-y  += uv.o printk.o
 obj-$(CONFIG_RANDOMIZE_BASE)   += kaslr.o
 obj-y  += $(if $(CONFIG_KERNEL_UNCOMPRESSED),,decompressor.o) info.o
 obj-$(CONFIG_KERNEL_ZSTD) += clz_ctz.o
index 94b4d5fd81594fd8a57ecbf0bcf4164175fa2a00..5abe59fb3bc08ec36f536522e70373c302e90d0b 100644 (file)
 #include <asm/uv.h>
 #include "boot.h"
 
-const char hex_asc[] = "0123456789abcdef";
-
-static char *as_hex(char *dst, unsigned long val, int pad)
-{
-       char *p, *end = p = dst + max(pad, (int)__fls(val | 1) / 4 + 1);
-
-       for (*p-- = 0; p >= dst; val >>= 4)
-               *p-- = hex_asc[val & 0x0f];
-       return end;
-}
-
-static char *symstart(char *p)
-{
-       while (*p)
-               p--;
-       return p + 1;
-}
-
-static noinline char *findsym(unsigned long ip, unsigned short *off, unsigned short *len)
-{
-       /* symbol entries are in a form "10000 c4 startup\0" */
-       char *a = _decompressor_syms_start;
-       char *b = _decompressor_syms_end;
-       unsigned long start;
-       unsigned long size;
-       char *pivot;
-       char *endp;
-
-       while (a < b) {
-               pivot = symstart(a + (b - a) / 2);
-               start = simple_strtoull(pivot, &endp, 16);
-               size = simple_strtoull(endp + 1, &endp, 16);
-               if (ip < start) {
-                       b = pivot;
-                       continue;
-               }
-               if (ip > start + size) {
-                       a = pivot + strlen(pivot) + 1;
-                       continue;
-               }
-               *off = ip - start;
-               *len = size;
-               return endp + 1;
-       }
-       return NULL;
-}
-
-static noinline char *strsym(void *ip)
-{
-       static char buf[64];
-       unsigned short off;
-       unsigned short len;
-       char *p;
-
-       p = findsym((unsigned long)ip, &off, &len);
-       if (p) {
-               strncpy(buf, p, sizeof(buf));
-               /* reserve 15 bytes for offset/len in symbol+0x1234/0x1234 */
-               p = buf + strnlen(buf, sizeof(buf) - 15);
-               strcpy(p, "+0x");
-               p = as_hex(p + 3, off, 0);
-               strcpy(p, "/0x");
-               as_hex(p + 3, len, 0);
-       } else {
-               as_hex(buf, (unsigned long)ip, 16);
-       }
-       return buf;
-}
-
-void boot_printk(const char *fmt, ...)
-{
-       char buf[1024] = { 0 };
-       char *end = buf + sizeof(buf) - 1; /* make sure buf is 0 terminated */
-       unsigned long pad;
-       char *p = buf;
-       va_list args;
-
-       va_start(args, fmt);
-       for (; p < end && *fmt; fmt++) {
-               if (*fmt != '%') {
-                       *p++ = *fmt;
-                       continue;
-               }
-               pad = isdigit(*++fmt) ? simple_strtol(fmt, (char **)&fmt, 10) : 0;
-               switch (*fmt) {
-               case 's':
-                       p = buf + strlcat(buf, va_arg(args, char *), sizeof(buf));
-                       break;
-               case 'p':
-                       if (*++fmt != 'S')
-                               goto out;
-                       p = buf + strlcat(buf, strsym(va_arg(args, void *)), sizeof(buf));
-                       break;
-               case 'l':
-                       if (*++fmt != 'x' || end - p <= max(sizeof(long) * 2, pad))
-                               goto out;
-                       p = as_hex(p, va_arg(args, unsigned long), pad);
-                       break;
-               case 'x':
-                       if (end - p <= max(sizeof(int) * 2, pad))
-                               goto out;
-                       p = as_hex(p, va_arg(args, unsigned int), pad);
-                       break;
-               default:
-                       goto out;
-               }
-       }
-out:
-       va_end(args);
-       sclp_early_printk(buf);
-}
-
 void print_stacktrace(unsigned long sp)
 {
        struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start,
diff --git a/arch/s390/boot/printk.c b/arch/s390/boot/printk.c
new file mode 100644 (file)
index 0000000..35f18f2
--- /dev/null
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/kernel.h>
+#include <linux/stdarg.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <asm/stacktrace.h>
+#include <asm/boot_data.h>
+#include <asm/lowcore.h>
+#include <asm/setup.h>
+#include <asm/sclp.h>
+#include <asm/uv.h>
+#include "boot.h"
+
+const char hex_asc[] = "0123456789abcdef";
+
+static char *as_hex(char *dst, unsigned long val, int pad)
+{
+       char *p, *end = p = dst + max(pad, (int)__fls(val | 1) / 4 + 1);
+
+       for (*p-- = 0; p >= dst; val >>= 4)
+               *p-- = hex_asc[val & 0x0f];
+       return end;
+}
+
+static char *symstart(char *p)
+{
+       while (*p)
+               p--;
+       return p + 1;
+}
+
+static noinline char *findsym(unsigned long ip, unsigned short *off, unsigned short *len)
+{
+       /* symbol entries are in a form "10000 c4 startup\0" */
+       char *a = _decompressor_syms_start;
+       char *b = _decompressor_syms_end;
+       unsigned long start;
+       unsigned long size;
+       char *pivot;
+       char *endp;
+
+       while (a < b) {
+               pivot = symstart(a + (b - a) / 2);
+               start = simple_strtoull(pivot, &endp, 16);
+               size = simple_strtoull(endp + 1, &endp, 16);
+               if (ip < start) {
+                       b = pivot;
+                       continue;
+               }
+               if (ip > start + size) {
+                       a = pivot + strlen(pivot) + 1;
+                       continue;
+               }
+               *off = ip - start;
+               *len = size;
+               return endp + 1;
+       }
+       return NULL;
+}
+
+static noinline char *strsym(void *ip)
+{
+       static char buf[64];
+       unsigned short off;
+       unsigned short len;
+       char *p;
+
+       p = findsym((unsigned long)ip, &off, &len);
+       if (p) {
+               strncpy(buf, p, sizeof(buf));
+               /* reserve 15 bytes for offset/len in symbol+0x1234/0x1234 */
+               p = buf + strnlen(buf, sizeof(buf) - 15);
+               strcpy(p, "+0x");
+               p = as_hex(p + 3, off, 0);
+               strcpy(p, "/0x");
+               as_hex(p + 3, len, 0);
+       } else {
+               as_hex(buf, (unsigned long)ip, 16);
+       }
+       return buf;
+}
+
+void boot_printk(const char *fmt, ...)
+{
+       char buf[1024] = { 0 };
+       char *end = buf + sizeof(buf) - 1; /* make sure buf is 0 terminated */
+       unsigned long pad;
+       char *p = buf;
+       va_list args;
+
+       va_start(args, fmt);
+       for (; p < end && *fmt; fmt++) {
+               if (*fmt != '%') {
+                       *p++ = *fmt;
+                       continue;
+               }
+               pad = isdigit(*++fmt) ? simple_strtol(fmt, (char **)&fmt, 10) : 0;
+               switch (*fmt) {
+               case 's':
+                       p = buf + strlcat(buf, va_arg(args, char *), sizeof(buf));
+                       break;
+               case 'p':
+                       if (*++fmt != 'S')
+                               goto out;
+                       p = buf + strlcat(buf, strsym(va_arg(args, void *)), sizeof(buf));
+                       break;
+               case 'l':
+                       if (*++fmt != 'x' || end - p <= max(sizeof(long) * 2, pad))
+                               goto out;
+                       p = as_hex(p, va_arg(args, unsigned long), pad);
+                       break;
+               case 'x':
+                       if (end - p <= max(sizeof(int) * 2, pad))
+                               goto out;
+                       p = as_hex(p, va_arg(args, unsigned int), pad);
+                       break;
+               default:
+                       goto out;
+               }
+       }
+out:
+       va_end(args);
+       sclp_early_printk(buf);
+}