2 * linux/drivers/char/hcdp_serial.c
4 * Copyright (C) 2002 Hewlett-Packard Co.
5 * Khalid Aziz <khalid_aziz@hp.com>
7 * Parse the EFI HCDP table to locate serial console and debug ports and
10 * 2002/08/29 davidm Adjust it to new 2.5 serial driver infrastructure.
13 #include <linux/config.h>
14 #include <linux/kernel.h>
15 #include <linux/efi.h>
16 #include <linux/init.h>
17 #include <linux/tty.h>
18 #include <linux/serial.h>
19 #include <linux/serial_core.h>
20 #include <linux/types.h>
21 #include <linux/acpi.h>
24 #include <asm/serial.h>
27 #include "8250_hcdp.h"
29 #undef SERIAL_DEBUG_HCDP
32 * Parse the HCDP table to find descriptions for headless console and debug
33 * serial ports and add them to rs_table[]. A pointer to HCDP table is
34 * passed as parameter. This function should be called before
35 * serial_console_init() is called to make sure the HCDP serial console will
36 * be available for use. IA-64 kernel calls this function from setup_arch()
37 * after the EFI and ACPI tables have been parsed.
40 setup_serial_hcdp(void *tablep
)
43 struct uart_port port
;
48 static int shift_once
= 1;
51 #ifdef SERIAL_DEBUG_HCDP
52 printk("Entering setup_serial_hcdp()\n");
55 /* Verify we have a valid table pointer */
59 memset(&port
, 0, sizeof(port
));
62 * Don't trust firmware to give us a table starting at an aligned
63 * address. Make a local copy of the HCDP table with aligned
66 memcpy(&hcdp
, tablep
, sizeof(hcdp
));
69 * Perform a sanity check on the table. Table should have a signature
70 * of "HCDP" and it should be atleast 82 bytes long to have any
73 if ((strncmp(hcdp
.signature
, HCDP_SIGNATURE
, HCDP_SIG_LEN
) != 0))
78 #ifdef SERIAL_DEBUG_HCDP
79 printk("setup_serial_hcdp(): table pointer = 0x%p, sig = '%.4s'\n",
80 tablep
, hcdp
.signature
);
81 printk(" length = %d, rev = %d, ", hcdp
.len
, hcdp
.rev
);
82 printk("OEM ID = %.6s, # of entries = %d\n", hcdp
.oemid
,
87 * Parse each device entry
89 for (nr
= 0; nr
< hcdp
.num_entries
; nr
++) {
90 hcdp_dev
= hcdp
.hcdp_dev
+ nr
;
92 * We will parse only the primary console device which is
93 * the first entry for these devices. We will ignore rest
94 * of the entries for the same type device that has already
95 * been parsed and initialized
97 if (hcdp_dev
->type
!= HCDP_DEV_CONSOLE
)
100 iobase
= ((u64
) hcdp_dev
->base_addr
.addrhi
<< 32) |
101 hcdp_dev
->base_addr
.addrlo
;
102 gsi
= hcdp_dev
->global_int
;
104 /* See PCI spec v2.2, Appendix D (Class Codes): */
105 switch (hcdp_dev
->pci_prog_intfc
) {
107 port
.type
= PORT_8250
;
110 port
.type
= PORT_16450
;
113 port
.type
= PORT_16550
;
116 port
.type
= PORT_16650
;
119 port
.type
= PORT_16750
;
122 port
.type
= PORT_16850
;
125 port
.type
= PORT_16C950
;
128 printk(KERN_WARNING
"warning: EFI HCDP table reports "
129 "unknown serial programming interface 0x%02x; "
130 "will autoprobe.\n", hcdp_dev
->pci_prog_intfc
);
131 port
.type
= PORT_UNKNOWN
;
135 #ifdef SERIAL_DEBUG_HCDP
136 printk(" type = %s, uart = %d\n",
137 ((hcdp_dev
->type
== HCDP_DEV_CONSOLE
) ?
139 ((hcdp_dev
->type
== HCDP_DEV_DEBUG
) ?
140 "Debug port" : "Huh????")), port
.type
);
141 printk(" base address space = %s, base address = 0x%lx\n",
142 ((hcdp_dev
->base_addr
.space_id
== ACPI_MEM_SPACE
) ?
144 ((hcdp_dev
->base_addr
.space_id
== ACPI_IO_SPACE
) ?
145 "I/O space" : "PCI space")),
147 printk(" gsi = %d, baud rate = %lu, bits = %d, clock = %d\n",
148 gsi
, (unsigned long) hcdp_dev
->baud
, hcdp_dev
->bits
,
149 hcdp_dev
->clock_rate
);
150 if (hcdp_dev
->base_addr
.space_id
== ACPI_PCICONF_SPACE
)
151 printk(" PCI id: %02x:%02x:%02x, vendor ID=0x%x, "
152 "dev ID=0x%x\n", hcdp_dev
->pci_seg
,
153 hcdp_dev
->pci_bus
, hcdp_dev
->pci_dev
,
154 hcdp_dev
->pci_vendor_id
, hcdp_dev
->pci_dev_id
);
157 * Now fill in a port structure to update the 8250 port table..
159 if (hcdp_dev
->clock_rate
)
160 port
.uartclk
= hcdp_dev
->clock_rate
;
162 port
.uartclk
= BASE_BAUD
* 16;
165 * Check if this is an I/O mapped address or a memory mapped
168 if (hcdp_dev
->base_addr
.space_id
== ACPI_MEM_SPACE
) {
170 port
.mapbase
= iobase
;
171 port
.membase
= ioremap(iobase
, 64);
172 port
.iotype
= SERIAL_IO_MEM
;
173 } else if (hcdp_dev
->base_addr
.space_id
== ACPI_IO_SPACE
) {
174 port
.iobase
= iobase
;
177 port
.iotype
= SERIAL_IO_PORT
;
178 } else if (hcdp_dev
->base_addr
.space_id
== ACPI_PCICONF_SPACE
) {
179 printk(KERN_WARNING
"warning: No support for PCI serial console\n");
183 port
.irq
= acpi_register_irq(gsi
, ACPI_ACTIVE_HIGH
,
184 ACPI_EDGE_SENSITIVE
);
188 port
.flags
= UPF_SKIP_TEST
| UPF_BOOT_AUTOCONF
;
190 port
.flags
|= ASYNC_AUTO_IRQ
;
193 * Note: the above memset() initializes port.line to 0,
194 * so we register this port as ttyS0.
196 if (early_serial_setup(&port
) < 0) {
197 printk("setup_serial_hcdp(): early_serial_setup() "
198 "for HCDP serial console port failed. "
199 "Will try any additional consoles in HCDP.\n");
205 #ifdef SERIAL_DEBUG_HCDP
206 printk("Leaving setup_serial_hcdp()\n");
210 #ifdef CONFIG_IA64_EARLY_PRINTK_UART
212 hcdp_early_uart (void)
214 efi_system_table_t
*systab
;
215 efi_config_table_t
*config_tables
;
216 unsigned long addr
= 0;
221 systab
= (efi_system_table_t
*) ia64_boot_param
->efi_systab
;
224 systab
= __va(systab
);
226 config_tables
= (efi_config_table_t
*) systab
->tables
;
229 config_tables
= __va(config_tables
);
231 for (i
= 0; i
< systab
->nr_tables
; i
++) {
232 if (efi_guidcmp(config_tables
[i
].guid
, HCDP_TABLE_GUID
) == 0) {
233 hcdp
= (hcdp_t
*) config_tables
[i
].table
;
241 for (i
= 0, dev
= hcdp
->hcdp_dev
; i
< hcdp
->num_entries
; i
++, dev
++) {
242 if (dev
->type
== HCDP_DEV_CONSOLE
) {
243 addr
= (u64
) dev
->base_addr
.addrhi
<< 32 | dev
->base_addr
.addrlo
;
249 #endif /* CONFIG_IA64_EARLY_PRINTK_UART */