Skip to content

Commit bc12b70

Browse files
author
Peter Zijlstra
committed
x86/earlyprintk: Clean up pciserial
While working on a GRUB patch to support PCI-serial, a number of cleanups were suggested that apply to the code I took inspiration from. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> # pci_ids.h Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b90cb10 commit bc12b70

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

arch/x86/kernel/early_printk.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,34 +264,34 @@ static __init void early_pci_serial_init(char *s)
264264
bar0 = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0);
265265

266266
/*
267-
* Verify it is a UART type device
267+
* Verify it is a 16550-UART type device
268268
*/
269269
if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) &&
270270
(classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) ||
271-
(((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ {
271+
(((classcode >> 8) & 0xff) != PCI_SERIAL_16550_COMPATIBLE)) {
272272
if (!force)
273273
return;
274274
}
275275

276276
/*
277277
* Determine if it is IO or memory mapped
278278
*/
279-
if (bar0 & 0x01) {
279+
if ((bar0 & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) {
280280
/* it is IO mapped */
281281
serial_in = io_serial_in;
282282
serial_out = io_serial_out;
283-
early_serial_base = bar0&0xfffffffc;
283+
early_serial_base = bar0 & PCI_BASE_ADDRESS_IO_MASK;
284284
write_pci_config(bus, slot, func, PCI_COMMAND,
285-
cmdreg|PCI_COMMAND_IO);
285+
cmdreg|PCI_COMMAND_IO);
286286
} else {
287287
/* It is memory mapped - assume 32-bit alignment */
288288
serial_in = mem32_serial_in;
289289
serial_out = mem32_serial_out;
290290
/* WARNING! assuming the address is always in the first 4G */
291291
early_serial_base =
292-
(unsigned long)early_ioremap(bar0 & 0xfffffff0, 0x10);
292+
(unsigned long)early_ioremap(bar0 & PCI_BASE_ADDRESS_MEM_MASK, 0x10);
293293
write_pci_config(bus, slot, func, PCI_COMMAND,
294-
cmdreg|PCI_COMMAND_MEMORY);
294+
cmdreg|PCI_COMMAND_MEMORY);
295295
}
296296

297297
/*

include/linux/pci_ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
#define PCI_CLASS_COMMUNICATION_MODEM 0x0703
7676
#define PCI_CLASS_COMMUNICATION_OTHER 0x0780
7777

78+
/* Interface for SERIAL/MODEM */
79+
#define PCI_SERIAL_16550_COMPATIBLE 0x02
80+
7881
#define PCI_BASE_CLASS_SYSTEM 0x08
7982
#define PCI_CLASS_SYSTEM_PIC 0x0800
8083
#define PCI_CLASS_SYSTEM_PIC_IOAPIC 0x080010

0 commit comments

Comments
 (0)