blob: 53c95c0bbf46506826553d0e413c22cfa1c08c1e [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 mmio = (uart->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070030 p += sprintf(p, "console=uart,%s,0x%lx",
31 mmio ? "mmio" : "io", uart->addr.address);
32 if (uart->baud)
33 p += sprintf(p, ",%lu", uart->baud);
34 if (uart->bits)
35 p += sprintf(p, "n%d", uart->bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37 return early_serial_console_init(options);
38#else
39 return -ENODEV;
40#endif
41}
42
43static int __init
Mark Maule66b7f8a2005-04-25 13:51:00 -070044setup_vga_console(struct pcdp_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
Mark Maule66b7f8a2005-04-25 13:51:00 -070047 u8 *if_ptr;
48
49 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
50 if (if_ptr[0] == PCDP_IF_PCI) {
51 struct pcdp_if_pci if_pci;
52
53 /* struct copy since ifptr might not be correctly aligned */
54
55 memcpy(&if_pci, if_ptr, sizeof(if_pci));
56
57 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
58 vga_console_iobase = if_pci.ioport_tra;
59
60 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
61 vga_console_membase = if_pci.mmio_tra;
62 }
63
64 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
66 return -ENODEV;
67 }
68
69 conswitchp = &vga_con;
70 printk(KERN_INFO "PCDP: VGA console\n");
71 return 0;
72#else
73 return -ENODEV;
74#endif
75}
76
77int __init
78efi_setup_pcdp_console(char *cmdline)
79{
80 struct pcdp *pcdp;
81 struct pcdp_uart *uart;
82 struct pcdp_device *dev, *end;
83 int i, serial = 0;
84
85 pcdp = efi.hcdp;
86 if (!pcdp)
87 return -ENODEV;
88
89 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, __pa(pcdp));
90
91 if (strstr(cmdline, "console=hcdp")) {
92 if (pcdp->rev < 3)
93 serial = 1;
94 } else if (strstr(cmdline, "console=")) {
95 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
96 return -ENODEV;
97 }
98
99 if (pcdp->rev < 3 && efi_uart_console_only())
100 serial = 1;
101
102 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
103 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
104 if (uart->type == PCDP_CONSOLE_UART) {
105 return setup_serial_console(uart);
106 }
107 }
108 }
109
110 end = (struct pcdp_device *) ((u8 *) pcdp + pcdp->length);
111 for (dev = (struct pcdp_device *) (pcdp->uart + pcdp->num_uarts);
112 dev < end;
113 dev = (struct pcdp_device *) ((u8 *) dev + dev->length)) {
114 if (dev->flags & PCDP_PRIMARY_CONSOLE) {
115 if (dev->type == PCDP_CONSOLE_VGA) {
Mark Maule66b7f8a2005-04-25 13:51:00 -0700116 return setup_vga_console(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118 }
119 }
120
121 return -ENODEV;
122}