Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Parse the EFI PCDP table to locate the console device. | |
3 | * | |
4 | * (c) Copyright 2002, 2003, 2004 Hewlett-Packard Development Company, L.P. | |
5 | * Khalid Aziz <khalid.aziz@hp.com> | |
6 | * Alex Williamson <alex.williamson@hp.com> | |
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #include <linux/acpi.h> | |
15 | #include <linux/console.h> | |
16 | #include <linux/efi.h> | |
17 | #include <linux/serial.h> | |
66b7f8a3 | 18 | #include <asm/vga.h> |
1da177e4 LT |
19 | #include "pcdp.h" |
20 | ||
21 | static int __init | |
22 | setup_serial_console(struct pcdp_uart *uart) | |
23 | { | |
24 | #ifdef CONFIG_SERIAL_8250_CONSOLE | |
25 | int mmio; | |
280dedb8 | 26 | static char options[64], *p = options; |
11be00cb | 27 | char parity; |
1da177e4 | 28 | |
15a58ed1 | 29 | mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY); |
280dedb8 BH |
30 | p += sprintf(p, "console=uart,%s,0x%lx", |
31 | mmio ? "mmio" : "io", uart->addr.address); | |
11be00cb | 32 | if (uart->baud) { |
280dedb8 | 33 | p += sprintf(p, ",%lu", uart->baud); |
11be00cb BH |
34 | if (uart->bits) { |
35 | switch (uart->parity) { | |
36 | case 0x2: parity = 'e'; break; | |
37 | case 0x3: parity = 'o'; break; | |
38 | default: parity = 'n'; | |
39 | } | |
40 | p += sprintf(p, "%c%d", parity, uart->bits); | |
41 | } | |
42 | } | |
1da177e4 LT |
43 | |
44 | return early_serial_console_init(options); | |
45 | #else | |
46 | return -ENODEV; | |
47 | #endif | |
48 | } | |
49 | ||
50 | static int __init | |
66b7f8a3 | 51 | setup_vga_console(struct pcdp_device *dev) |
1da177e4 LT |
52 | { |
53 | #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) | |
66b7f8a3 MM |
54 | u8 *if_ptr; |
55 | ||
56 | if_ptr = ((u8 *)dev + sizeof(struct pcdp_device)); | |
57 | if (if_ptr[0] == PCDP_IF_PCI) { | |
58 | struct pcdp_if_pci if_pci; | |
59 | ||
60 | /* struct copy since ifptr might not be correctly aligned */ | |
61 | ||
62 | memcpy(&if_pci, if_ptr, sizeof(if_pci)); | |
63 | ||
64 | if (if_pci.trans & PCDP_PCI_TRANS_IOPORT) | |
65 | vga_console_iobase = if_pci.ioport_tra; | |
66 | ||
67 | if (if_pci.trans & PCDP_PCI_TRANS_MMIO) | |
68 | vga_console_membase = if_pci.mmio_tra; | |
69 | } | |
70 | ||
71 | if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) { | |
1da177e4 LT |
72 | printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n"); |
73 | return -ENODEV; | |
74 | } | |
75 | ||
76 | conswitchp = &vga_con; | |
77 | printk(KERN_INFO "PCDP: VGA console\n"); | |
78 | return 0; | |
79 | #else | |
80 | return -ENODEV; | |
81 | #endif | |
82 | } | |
83 | ||
84 | int __init | |
85 | efi_setup_pcdp_console(char *cmdline) | |
86 | { | |
87 | struct pcdp *pcdp; | |
88 | struct pcdp_uart *uart; | |
89 | struct pcdp_device *dev, *end; | |
90 | int i, serial = 0; | |
b2c99e3c | 91 | int rc = -ENODEV; |
1da177e4 | 92 | |
b2c99e3c | 93 | if (efi.hcdp == EFI_INVALID_TABLE_ADDR) |
1da177e4 LT |
94 | return -ENODEV; |
95 | ||
b2c99e3c BH |
96 | pcdp = ioremap(efi.hcdp, 4096); |
97 | printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp); | |
1da177e4 LT |
98 | |
99 | if (strstr(cmdline, "console=hcdp")) { | |
100 | if (pcdp->rev < 3) | |
101 | serial = 1; | |
102 | } else if (strstr(cmdline, "console=")) { | |
103 | printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n"); | |
b2c99e3c | 104 | goto out; |
1da177e4 LT |
105 | } |
106 | ||
107 | if (pcdp->rev < 3 && efi_uart_console_only()) | |
108 | serial = 1; | |
109 | ||
110 | for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) { | |
111 | if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) { | |
112 | if (uart->type == PCDP_CONSOLE_UART) { | |
b2c99e3c BH |
113 | rc = setup_serial_console(uart); |
114 | goto out; | |
1da177e4 LT |
115 | } |
116 | } | |
117 | } | |
118 | ||
119 | end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length); | |
120 | for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts); | |
121 | dev < end; | |
122 | dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) { | |
123 | if (dev->flags & PCDP_PRIMARY_CONSOLE) { | |
124 | if (dev->type == PCDP_CONSOLE_VGA) { | |
b2c99e3c BH |
125 | rc = setup_vga_console(dev); |
126 | goto out; | |
1da177e4 LT |
127 | } |
128 | } | |
129 | } | |
130 | ||
b2c99e3c BH |
131 | out: |
132 | iounmap(pcdp); | |
133 | return rc; | |
1da177e4 | 134 | } |