blob: c37baf9448bc8665905c8479942c98ff083ea460 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Peter Chubb97d3a002005-05-31 14:39:30 -070014#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/acpi.h>
16#include <linux/console.h>
17#include <linux/efi.h>
18#include <linux/serial.h>
Mark Maule66b7f8a2005-04-25 13:51:00 -070019#include <asm/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "pcdp.h"
21
22static int __init
23setup_serial_console(struct pcdp_uart *uart)
24{
25#ifdef CONFIG_SERIAL_8250_CONSOLE
26 int mmio;
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070027 static char options[64], *p = options;
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070028 char parity;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070031 p += sprintf(p, "console=uart,%s,0x%lx",
32 mmio ? "mmio" : "io", uart->addr.address);
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070033 if (uart->baud) {
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070034 p += sprintf(p, ",%lu", uart->baud);
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070035 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 Torvalds1da177e2005-04-16 15:20:36 -070044
45 return early_serial_console_init(options);
46#else
47 return -ENODEV;
48#endif
49}
50
51static int __init
Mark Maule66b7f8a2005-04-25 13:51:00 -070052setup_vga_console(struct pcdp_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
Mark Maule66b7f8a2005-04-25 13:51:00 -070055 u8 *if_ptr;
56
57 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
58 if (if_ptr[0] == PCDP_IF_PCI) {
59 struct pcdp_if_pci if_pci;
60
61 /* struct copy since ifptr might not be correctly aligned */
62
63 memcpy(&if_pci, if_ptr, sizeof(if_pci));
64
65 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
66 vga_console_iobase = if_pci.ioport_tra;
67
68 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
69 vga_console_membase = if_pci.mmio_tra;
70 }
71
72 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
74 return -ENODEV;
75 }
76
77 conswitchp = &vga_con;
78 printk(KERN_INFO "PCDP: VGA console\n");
79 return 0;
80#else
81 return -ENODEV;
82#endif
83}
84
85int __init
86efi_setup_pcdp_console(char *cmdline)
87{
88 struct pcdp *pcdp;
89 struct pcdp_uart *uart;
90 struct pcdp_device *dev, *end;
91 int i, serial = 0;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080092 int rc = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080094 if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return -ENODEV;
96
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080097 pcdp = ioremap(efi.hcdp, 4096);
98 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 if (strstr(cmdline, "console=hcdp")) {
101 if (pcdp->rev < 3)
102 serial = 1;
103 } else if (strstr(cmdline, "console=")) {
104 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800105 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107
108 if (pcdp->rev < 3 && efi_uart_console_only())
109 serial = 1;
110
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) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800114 rc = setup_serial_console(uart);
115 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117 }
118 }
119
120 end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
121 for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
122 dev < end;
123 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
124 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
125 if (dev->type == PCDP_CONSOLE_VGA) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800126 rc = setup_vga_console(dev);
127 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129 }
130 }
131
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800132out:
133 iounmap(pcdp);
134 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}