0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/acpi.h>
0012 #include <linux/console.h>
0013 #include <linux/efi.h>
0014 #include <linux/serial.h>
0015 #include <linux/serial_core.h>
0016 #include <asm/vga.h>
0017 #include "pcdp.h"
0018
0019 static int __init
0020 setup_serial_console(struct pcdp_uart *uart)
0021 {
0022 #ifdef CONFIG_SERIAL_8250_CONSOLE
0023 int mmio;
0024 static char options[64], *p = options;
0025 char parity;
0026
0027 mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
0028 p += sprintf(p, "uart8250,%s,0x%llx",
0029 mmio ? "mmio" : "io", uart->addr.address);
0030 if (uart->baud) {
0031 p += sprintf(p, ",%llu", uart->baud);
0032 if (uart->bits) {
0033 switch (uart->parity) {
0034 case 0x2: parity = 'e'; break;
0035 case 0x3: parity = 'o'; break;
0036 default: parity = 'n';
0037 }
0038 p += sprintf(p, "%c%d", parity, uart->bits);
0039 }
0040 }
0041
0042 add_preferred_console("uart", 8250, &options[9]);
0043 return setup_earlycon(options);
0044 #else
0045 return -ENODEV;
0046 #endif
0047 }
0048
0049 static int __init
0050 setup_vga_console(struct pcdp_device *dev)
0051 {
0052 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
0053 u8 *if_ptr;
0054
0055 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
0056 if (if_ptr[0] == PCDP_IF_PCI) {
0057 struct pcdp_if_pci if_pci;
0058
0059
0060
0061 memcpy(&if_pci, if_ptr, sizeof(if_pci));
0062
0063 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
0064 vga_console_iobase = if_pci.ioport_tra;
0065
0066 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
0067 vga_console_membase = if_pci.mmio_tra;
0068 }
0069
0070 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
0071 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
0072 return -ENODEV;
0073 }
0074
0075 conswitchp = &vga_con;
0076 printk(KERN_INFO "PCDP: VGA console\n");
0077 return 0;
0078 #else
0079 return -ENODEV;
0080 #endif
0081 }
0082
0083 extern unsigned long hcdp_phys;
0084
0085 int __init
0086 efi_setup_pcdp_console(char *cmdline)
0087 {
0088 struct pcdp *pcdp;
0089 struct pcdp_uart *uart;
0090 struct pcdp_device *dev, *end;
0091 int i, serial = 0;
0092 int rc = -ENODEV;
0093
0094 if (hcdp_phys == EFI_INVALID_TABLE_ADDR)
0095 return -ENODEV;
0096
0097 pcdp = early_memremap(hcdp_phys, 4096);
0098 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, hcdp_phys);
0099
0100 if (strstr(cmdline, "console=hcdp")) {
0101 if (pcdp->rev < 3)
0102 serial = 1;
0103 } else if (strstr(cmdline, "console=")) {
0104 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
0105 goto out;
0106 }
0107
0108 if (pcdp->rev < 3 && efi_uart_console_only())
0109 serial = 1;
0110
0111 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
0112 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
0113 if (uart->type == PCDP_CONSOLE_UART) {
0114 rc = setup_serial_console(uart);
0115 goto out;
0116 }
0117 }
0118 }
0119
0120 end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
0121 for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
0122 dev < end;
0123 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
0124 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
0125 if (dev->type == PCDP_CONSOLE_VGA) {
0126 rc = setup_vga_console(dev);
0127 goto out;
0128 }
0129 }
0130 }
0131
0132 out:
0133 early_memunmap(pcdp, 4096);
0134 return rc;
0135 }