]> Pileus Git - ~andy/linux/blob - arch/arm64/kernel/early_printk.c
arm64: Fix build error with !SMP
[~andy/linux] / arch / arm64 / kernel / early_printk.c
1 /*
2  * Earlyprintk support.
3  *
4  * Copyright (C) 2012 ARM Ltd.
5  * Author: Catalin Marinas <catalin.marinas@arm.com>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <linux/kernel.h>
20 #include <linux/console.h>
21 #include <linux/init.h>
22 #include <linux/string.h>
23 #include <linux/mm.h>
24 #include <linux/io.h>
25
26 #include <linux/amba/serial.h>
27
28 static void __iomem *early_base;
29 static void (*printch)(char ch);
30
31 /*
32  * PL011 single character TX.
33  */
34 static void pl011_printch(char ch)
35 {
36         while (readl_relaxed(early_base + UART01x_FR) & UART01x_FR_TXFF)
37                 ;
38         writeb_relaxed(ch, early_base + UART01x_DR);
39         while (readl_relaxed(early_base + UART01x_FR) & UART01x_FR_BUSY)
40                 ;
41 }
42
43 struct earlycon_match {
44         const char *name;
45         void (*printch)(char ch);
46 };
47
48 static const struct earlycon_match earlycon_match[] __initconst = {
49         { .name = "pl011", .printch = pl011_printch, },
50         {}
51 };
52
53 static void early_write(struct console *con, const char *s, unsigned n)
54 {
55         while (n-- > 0) {
56                 if (*s == '\n')
57                         printch('\r');
58                 printch(*s);
59                 s++;
60         }
61 }
62
63 static struct console early_console = {
64         .name =         "earlycon",
65         .write =        early_write,
66         .flags =        CON_PRINTBUFFER | CON_BOOT,
67         .index =        -1,
68 };
69
70 /*
71  * Parse earlyprintk=... parameter in the format:
72  *
73  *   <name>[,<addr>][,<options>]
74  *
75  * and register the early console. It is assumed that the UART has been
76  * initialised by the bootloader already.
77  */
78 static int __init setup_early_printk(char *buf)
79 {
80         const struct earlycon_match *match = earlycon_match;
81         phys_addr_t paddr = 0;
82
83         if (!buf) {
84                 pr_warning("No earlyprintk arguments passed.\n");
85                 return 0;
86         }
87
88         while (match->name) {
89                 size_t len = strlen(match->name);
90                 if (!strncmp(buf, match->name, len)) {
91                         buf += len;
92                         break;
93                 }
94                 match++;
95         }
96         if (!match->name) {
97                 pr_warning("Unknown earlyprintk arguments: %s\n", buf);
98                 return 0;
99         }
100
101         /* I/O address */
102         if (!strncmp(buf, ",0x", 3)) {
103                 char *e;
104                 paddr = simple_strtoul(buf + 1, &e, 16);
105                 buf = e;
106         }
107         /* no options parsing yet */
108
109         if (paddr)
110                 early_base = early_io_map(paddr, EARLYCON_IOBASE);
111
112         printch = match->printch;
113         register_console(&early_console);
114
115         return 0;
116 }
117
118 early_param("earlyprintk", setup_early_printk);