1 // SPDX-License-Identifier: GPL-2.0
3 * I/O delay strategies for inb_p/outb_p
5 * Allow for a DMI based override of port 0x80, needed for certain HP laptops
6 * and possibly other systems. Also allow for the gradual elimination of
7 * outb_p/inb_p API uses.
9 #include <linux/kernel.h>
10 #include <linux/export.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/dmi.h>
16 #define IO_DELAY_TYPE_0X80 0
17 #define IO_DELAY_TYPE_0XED 1
18 #define IO_DELAY_TYPE_UDELAY 2
19 #define IO_DELAY_TYPE_NONE 3
21 #if defined(CONFIG_IO_DELAY_0X80)
22 #define DEFAULT_IO_DELAY_TYPE IO_DELAY_TYPE_0X80
23 #elif defined(CONFIG_IO_DELAY_0XED)
24 #define DEFAULT_IO_DELAY_TYPE IO_DELAY_TYPE_0XED
25 #elif defined(CONFIG_IO_DELAY_UDELAY)
26 #define DEFAULT_IO_DELAY_TYPE IO_DELAY_TYPE_UDELAY
27 #elif defined(CONFIG_IO_DELAY_NONE)
28 #define DEFAULT_IO_DELAY_TYPE IO_DELAY_TYPE_NONE
31 int io_delay_type __read_mostly
= DEFAULT_IO_DELAY_TYPE
;
33 static int __initdata io_delay_override
;
36 * Paravirt wants native_io_delay to be a constant.
38 void native_io_delay(void)
40 switch (io_delay_type
) {
42 case IO_DELAY_TYPE_0X80
:
43 asm volatile ("outb %al, $0x80");
45 case IO_DELAY_TYPE_0XED
:
46 asm volatile ("outb %al, $0xed");
48 case IO_DELAY_TYPE_UDELAY
:
50 * 2 usecs is an upper-bound for the outb delay but
51 * note that udelay doesn't have the bus-level
52 * side-effects that outb does, nor does udelay() have
53 * precise timings during very early bootup (the delays
54 * are shorter until calibrated):
58 case IO_DELAY_TYPE_NONE
:
62 EXPORT_SYMBOL(native_io_delay
);
64 static int __init
dmi_io_delay_0xed_port(const struct dmi_system_id
*id
)
66 if (io_delay_type
== IO_DELAY_TYPE_0X80
) {
67 pr_notice("%s: using 0xed I/O delay port\n", id
->ident
);
68 io_delay_type
= IO_DELAY_TYPE_0XED
;
75 * Quirk table for systems that misbehave (lock up, etc.) if port
78 static const struct dmi_system_id io_delay_0xed_port_dmi_table
[] __initconst
= {
80 .callback
= dmi_io_delay_0xed_port
,
81 .ident
= "Compaq Presario V6000",
83 DMI_MATCH(DMI_BOARD_VENDOR
, "Quanta"),
84 DMI_MATCH(DMI_BOARD_NAME
, "30B7")
88 .callback
= dmi_io_delay_0xed_port
,
89 .ident
= "HP Pavilion dv9000z",
91 DMI_MATCH(DMI_BOARD_VENDOR
, "Quanta"),
92 DMI_MATCH(DMI_BOARD_NAME
, "30B9")
96 .callback
= dmi_io_delay_0xed_port
,
97 .ident
= "HP Pavilion dv6000",
99 DMI_MATCH(DMI_BOARD_VENDOR
, "Quanta"),
100 DMI_MATCH(DMI_BOARD_NAME
, "30B8")
104 .callback
= dmi_io_delay_0xed_port
,
105 .ident
= "HP Pavilion tx1000",
107 DMI_MATCH(DMI_BOARD_VENDOR
, "Quanta"),
108 DMI_MATCH(DMI_BOARD_NAME
, "30BF")
112 .callback
= dmi_io_delay_0xed_port
,
113 .ident
= "Presario F700",
115 DMI_MATCH(DMI_BOARD_VENDOR
, "Quanta"),
116 DMI_MATCH(DMI_BOARD_NAME
, "30D3")
122 void __init
io_delay_init(void)
124 if (!io_delay_override
)
125 dmi_check_system(io_delay_0xed_port_dmi_table
);
128 static int __init
io_delay_param(char *s
)
133 if (!strcmp(s
, "0x80"))
134 io_delay_type
= IO_DELAY_TYPE_0X80
;
135 else if (!strcmp(s
, "0xed"))
136 io_delay_type
= IO_DELAY_TYPE_0XED
;
137 else if (!strcmp(s
, "udelay"))
138 io_delay_type
= IO_DELAY_TYPE_UDELAY
;
139 else if (!strcmp(s
, "none"))
140 io_delay_type
= IO_DELAY_TYPE_NONE
;
144 io_delay_override
= 1;
148 early_param("io_delay", io_delay_param
);