Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/acpi.h> |
| 15 | #include <linux/console.h> |
| 16 | #include <linux/efi.h> |
| 17 | #include <linux/serial.h> |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 18 | #include <linux/serial_8250.h> |
Mark Maule | 66b7f8a | 2005-04-25 13:51:00 -0700 | [diff] [blame] | 19 | #include <asm/vga.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "pcdp.h" |
| 21 | |
| 22 | static int __init |
| 23 | setup_serial_console(struct pcdp_uart *uart) |
| 24 | { |
| 25 | #ifdef CONFIG_SERIAL_8250_CONSOLE |
| 26 | int mmio; |
Bjorn Helgaas | 280dedb | 2005-06-23 00:10:16 -0700 | [diff] [blame] | 27 | static char options[64], *p = options; |
Bjorn Helgaas | 11be00cb | 2005-07-28 01:07:39 -0700 | [diff] [blame] | 28 | char parity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 30 | mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY); |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 31 | p += sprintf(p, "uart8250,%s,0x%lx", |
Bjorn Helgaas | 280dedb | 2005-06-23 00:10:16 -0700 | [diff] [blame] | 32 | mmio ? "mmio" : "io", uart->addr.address); |
Bjorn Helgaas | 11be00cb | 2005-07-28 01:07:39 -0700 | [diff] [blame] | 33 | if (uart->baud) { |
Bjorn Helgaas | 280dedb | 2005-06-23 00:10:16 -0700 | [diff] [blame] | 34 | p += sprintf(p, ",%lu", uart->baud); |
Bjorn Helgaas | 11be00cb | 2005-07-28 01:07:39 -0700 | [diff] [blame] | 35 | if (uart->bits) { |
| 36 | switch (uart->parity) { |
| 37 | case 0x2: parity = 'e'; break; |
| 38 | case 0x3: parity = 'o'; break; |
| 39 | default: parity = 'n'; |
| 40 | } |
| 41 | p += sprintf(p, "%c%d", parity, uart->bits); |
| 42 | } |
| 43 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Yinghai Lu | 18a8bd9 | 2007-07-15 23:37:59 -0700 | [diff] [blame] | 45 | add_preferred_console("uart", 8250, &options[9]); |
| 46 | return setup_early_serial8250_console(options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #else |
| 48 | return -ENODEV; |
| 49 | #endif |
| 50 | } |
| 51 | |
| 52 | static int __init |
Mark Maule | 66b7f8a | 2005-04-25 13:51:00 -0700 | [diff] [blame] | 53 | setup_vga_console(struct pcdp_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE) |
Mark Maule | 66b7f8a | 2005-04-25 13:51:00 -0700 | [diff] [blame] | 56 | u8 *if_ptr; |
| 57 | |
| 58 | if_ptr = ((u8 *)dev + sizeof(struct pcdp_device)); |
| 59 | if (if_ptr[0] == PCDP_IF_PCI) { |
| 60 | struct pcdp_if_pci if_pci; |
| 61 | |
| 62 | /* struct copy since ifptr might not be correctly aligned */ |
| 63 | |
| 64 | memcpy(&if_pci, if_ptr, sizeof(if_pci)); |
| 65 | |
| 66 | if (if_pci.trans & PCDP_PCI_TRANS_IOPORT) |
| 67 | vga_console_iobase = if_pci.ioport_tra; |
| 68 | |
| 69 | if (if_pci.trans & PCDP_PCI_TRANS_MMIO) |
| 70 | vga_console_membase = if_pci.mmio_tra; |
| 71 | } |
| 72 | |
| 73 | if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n"); |
| 75 | return -ENODEV; |
| 76 | } |
| 77 | |
| 78 | conswitchp = &vga_con; |
| 79 | printk(KERN_INFO "PCDP: VGA console\n"); |
| 80 | return 0; |
| 81 | #else |
| 82 | return -ENODEV; |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | int __init |
| 87 | efi_setup_pcdp_console(char *cmdline) |
| 88 | { |
| 89 | struct pcdp *pcdp; |
| 90 | struct pcdp_uart *uart; |
| 91 | struct pcdp_device *dev, *end; |
| 92 | int i, serial = 0; |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 93 | int rc = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 95 | if (efi.hcdp == EFI_INVALID_TABLE_ADDR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | return -ENODEV; |
| 97 | |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 98 | pcdp = ioremap(efi.hcdp, 4096); |
| 99 | printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | if (strstr(cmdline, "console=hcdp")) { |
| 102 | if (pcdp->rev < 3) |
| 103 | serial = 1; |
| 104 | } else if (strstr(cmdline, "console=")) { |
| 105 | printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n"); |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 106 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | if (pcdp->rev < 3 && efi_uart_console_only()) |
| 110 | serial = 1; |
| 111 | |
| 112 | for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) { |
| 113 | if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) { |
| 114 | if (uart->type == PCDP_CONSOLE_UART) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 115 | rc = setup_serial_console(uart); |
| 116 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length); |
| 122 | for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts); |
| 123 | dev < end; |
| 124 | dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) { |
| 125 | if (dev->flags & PCDP_PRIMARY_CONSOLE) { |
| 126 | if (dev->type == PCDP_CONSOLE_VGA) { |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 127 | rc = setup_vga_console(dev); |
| 128 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
Bjorn Helgaas | b2c99e3 | 2006-03-26 01:37:08 -0800 | [diff] [blame] | 133 | out: |
| 134 | iounmap(pcdp); |
| 135 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |