Linux v2.6.13
[linux-2.6/next.git] / drivers / firmware / pcdp.c
blobae1fb45dbb40d20f9b08a5e7537cf2e0e4b876ef
1 /*
2 * Parse the EFI PCDP table to locate the console device.
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>
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.
14 #include <linux/config.h>
15 #include <linux/acpi.h>
16 #include <linux/console.h>
17 #include <linux/efi.h>
18 #include <linux/serial.h>
19 #include <asm/vga.h>
20 #include "pcdp.h"
22 static int __init
23 setup_serial_console(struct pcdp_uart *uart)
25 #ifdef CONFIG_SERIAL_8250_CONSOLE
26 int mmio;
27 static char options[64], *p = options;
28 char parity;
30 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
31 p += sprintf(p, "console=uart,%s,0x%lx",
32 mmio ? "mmio" : "io", uart->addr.address);
33 if (uart->baud) {
34 p += sprintf(p, ",%lu", uart->baud);
35 if (uart->bits) {
36 switch (uart->parity) {
37 case 0x2: parity = 'e'; break;
38 case 0x3: parity = 'o'; break;
39 default: parity = 'n';
41 p += sprintf(p, "%c%d", parity, uart->bits);
45 return early_serial_console_init(options);
46 #else
47 return -ENODEV;
48 #endif
51 static int __init
52 setup_vga_console(struct pcdp_device *dev)
54 #if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
55 u8 *if_ptr;
57 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
58 if (if_ptr[0] == PCDP_IF_PCI) {
59 struct pcdp_if_pci if_pci;
61 /* struct copy since ifptr might not be correctly aligned */
63 memcpy(&if_pci, if_ptr, sizeof(if_pci));
65 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
66 vga_console_iobase = if_pci.ioport_tra;
68 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
69 vga_console_membase = if_pci.mmio_tra;
72 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
73 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
74 return -ENODEV;
77 conswitchp = &vga_con;
78 printk(KERN_INFO "PCDP: VGA console\n");
79 return 0;
80 #else
81 return -ENODEV;
82 #endif
85 int __init
86 efi_setup_pcdp_console(char *cmdline)
88 struct pcdp *pcdp;
89 struct pcdp_uart *uart;
90 struct pcdp_device *dev, *end;
91 int i, serial = 0;
93 pcdp = efi.hcdp;
94 if (!pcdp)
95 return -ENODEV;
97 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, __pa(pcdp));
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");
104 return -ENODEV;
107 if (pcdp->rev < 3 && efi_uart_console_only())
108 serial = 1;
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) {
113 return setup_serial_console(uart);
118 end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
119 for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
120 dev < end;
121 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
122 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
123 if (dev->type == PCDP_CONSOLE_VGA) {
124 return setup_vga_console(dev);
129 return -ENODEV;