blob: 4adeb7a2bdf5529bbdc700e97c316c161f066411 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Parse the EFI PCDP table to locate the console device.
4 *
5 * (c) Copyright 2002, 2003, 2004 Hewlett-Packard Development Company, L.P.
6 * Khalid Aziz <khalid.aziz@hp.com>
7 * Alex Williamson <alex.williamson@hp.com>
8 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/acpi.h>
12#include <linux/console.h>
13#include <linux/efi.h>
14#include <linux/serial.h>
Peter Hurleydf519e72015-03-09 16:27:22 -040015#include <linux/serial_core.h>
Mark Maule66b7f8a2005-04-25 13:51:00 -070016#include <asm/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include "pcdp.h"
18
19static int __init
20setup_serial_console(struct pcdp_uart *uart)
21{
22#ifdef CONFIG_SERIAL_8250_CONSOLE
23 int mmio;
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070024 static char options[64], *p = options;
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070025 char parity;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +030027 mmio = (uart->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY);
Matthew Wilcoxe088a4a2009-05-22 13:49:49 -070028 p += sprintf(p, "uart8250,%s,0x%llx",
Bjorn Helgaas280dedb2005-06-23 00:10:16 -070029 mmio ? "mmio" : "io", uart->addr.address);
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070030 if (uart->baud) {
Matthew Wilcoxe088a4a2009-05-22 13:49:49 -070031 p += sprintf(p, ",%llu", uart->baud);
Bjorn Helgaas11be00cb2005-07-28 01:07:39 -070032 if (uart->bits) {
33 switch (uart->parity) {
34 case 0x2: parity = 'e'; break;
35 case 0x3: parity = 'o'; break;
36 default: parity = 'n';
37 }
38 p += sprintf(p, "%c%d", parity, uart->bits);
39 }
40 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Yinghai Lu18a8bd92007-07-15 23:37:59 -070042 add_preferred_console("uart", 8250, &options[9]);
Peter Hurleydf519e72015-03-09 16:27:22 -040043 return setup_earlycon(options);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#else
45 return -ENODEV;
46#endif
47}
48
49static int __init
Mark Maule66b7f8a2005-04-25 13:51:00 -070050setup_vga_console(struct pcdp_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
52#if defined(CONFIG_VT) && defined(CONFIG_VGA_CONSOLE)
Mark Maule66b7f8a2005-04-25 13:51:00 -070053 u8 *if_ptr;
54
55 if_ptr = ((u8 *)dev + sizeof(struct pcdp_device));
56 if (if_ptr[0] == PCDP_IF_PCI) {
57 struct pcdp_if_pci if_pci;
58
59 /* struct copy since ifptr might not be correctly aligned */
60
61 memcpy(&if_pci, if_ptr, sizeof(if_pci));
62
63 if (if_pci.trans & PCDP_PCI_TRANS_IOPORT)
64 vga_console_iobase = if_pci.ioport_tra;
65
66 if (if_pci.trans & PCDP_PCI_TRANS_MMIO)
67 vga_console_membase = if_pci.mmio_tra;
68 }
69
70 if (efi_mem_type(vga_console_membase + 0xA0000) == EFI_CONVENTIONAL_MEMORY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 printk(KERN_ERR "PCDP: VGA selected, but frame buffer is not MMIO!\n");
72 return -ENODEV;
73 }
74
75 conswitchp = &vga_con;
76 printk(KERN_INFO "PCDP: VGA console\n");
77 return 0;
78#else
79 return -ENODEV;
80#endif
81}
82
83int __init
84efi_setup_pcdp_console(char *cmdline)
85{
86 struct pcdp *pcdp;
87 struct pcdp_uart *uart;
88 struct pcdp_device *dev, *end;
89 int i, serial = 0;
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080090 int rc = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080092 if (efi.hcdp == EFI_INVALID_TABLE_ADDR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return -ENODEV;
94
Tom Lendackyf7750a72017-07-17 16:10:00 -050095 pcdp = early_memremap(efi.hcdp, 4096);
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -080096 printk(KERN_INFO "PCDP: v%d at 0x%lx\n", pcdp->rev, efi.hcdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 if (strstr(cmdline, "console=hcdp")) {
99 if (pcdp->rev < 3)
100 serial = 1;
101 } else if (strstr(cmdline, "console=")) {
102 printk(KERN_INFO "Explicit \"console=\"; ignoring PCDP\n");
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800103 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
106 if (pcdp->rev < 3 && efi_uart_console_only())
107 serial = 1;
108
109 for (i = 0, uart = pcdp->uart; i < pcdp->num_uarts; i++, uart++) {
110 if (uart->flags & PCDP_UART_PRIMARY_CONSOLE || serial) {
111 if (uart->type == PCDP_CONSOLE_UART) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800112 rc = setup_serial_console(uart);
113 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115 }
116 }
117
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) {
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800124 rc = setup_vga_console(dev);
125 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127 }
128 }
129
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800130out:
Tom Lendackyf7750a72017-07-17 16:10:00 -0500131 early_memunmap(pcdp, 4096);
Bjorn Helgaasb2c99e32006-03-26 01:37:08 -0800132 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}