1 // SPDX-License-Identifier: GPL-2.0-only
3 * Parse the EFI PCDP table to locate the console device.
5 * (c) Copyright 2002, 2003, 2004 Hewlett-Packard Development Company, L.P.
6 * Khalid Aziz <khalid.aziz@hp.com>
7 * Alex Williamson <alex.williamson@hp.com>
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
11 #include <linux/acpi.h>
12 #include <linux/console.h>
13 #include <linux/efi.h>
14 #include <linux/serial.h>
15 #include <linux/serial_core.h>
20 setup_serial_console(struct pcdp_uart *uart)
22 #ifdef CONFIG_SERIAL_8250_CONSOLE
24 static char options[64], *p = options;
27 mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
28 p += sprintf(p, "uart8250,%s,0x%llx",
29 mmio ? "mmio" : "io", uart->addr.address);
31 p += sprintf(p, ",%llu", uart->baud);
33 switch (uart->parity) {
34 case 0x2: parity = 'e'; break;
35 case 0x3: parity = 'o'; break;
36 default: parity = 'n';
38 p += sprintf(p, "%c%d", parity, uart->bits);
42 add_preferred_console("uart", 8250, &options[9]);
43 return setup_earlycon(options);
50 setup_vga_console(struct pcdp_device *dev)
52 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
55 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
56 if (if_ptr[0] == PCDP_IF_PCI) {
57 struct pcdp_if_pci if_pci;
59 /* struct copy since ifptr might not be correctly aligned */
61 memcpy(&if_pci, if_ptr, sizeof(if_pci));
63 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
64 vga_console_iobase = if_pci.ioport_tra;
66 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
67 vga_console_membase = if_pci.mmio_tra;
70 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
71 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
75 conswitchp = &vga_con;
76 printk(KERN_INFO "PCDP: VGA console\n");
83 extern unsigned long hcdp_phys;
86 efi_setup_pcdp_console(char *cmdline)
89 struct pcdp_uart *uart;
90 struct pcdp_device *dev, *end;
94 if (hcdp_phys == EFI_INVALID_TABLE_ADDR)
97 pcdp = early_memremap(hcdp_phys, 4096);
98 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, hcdp_phys);
100 if (strstr(cmdline, "console=hcdp")) {
103 } else if (strstr(cmdline, "console=")) {
104 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
108 if (pcdp->rev < 3 && efi_uart_console_only())
111 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
112 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
113 if (uart->type == PCDP_CONSOLE_UART) {
114 rc = setup_serial_console(uart);
120 end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
121 for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
123 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
124 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
125 if (dev->type == PCDP_CONSOLE_VGA) {
126 rc = setup_vga_console(dev);
133 early_memunmap(pcdp, 4096);