License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / arch / x86 / kernel / io_delay.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
b02aae9c
RH
2/*
3 * I/O delay strategies for inb_p/outb_p
6e7c4025
IM
4 *
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.
b02aae9c
RH
8 */
9#include <linux/kernel.h>
186f4360 10#include <linux/export.h>
b02aae9c 11#include <linux/delay.h>
d53a4444 12#include <linux/init.h>
b02aae9c 13#include <linux/dmi.h>
d53a4444 14#include <linux/io.h>
b02aae9c 15
6e7c4025 16int io_delay_type __read_mostly = CONFIG_DEFAULT_IO_DELAY_TYPE;
b02aae9c 17
6e7c4025 18static int __initdata io_delay_override;
b02aae9c
RH
19
20/*
21 * Paravirt wants native_io_delay to be a constant.
22 */
23void native_io_delay(void)
24{
6e7c4025
IM
25 switch (io_delay_type) {
26 default:
27 case CONFIG_IO_DELAY_TYPE_0X80:
28 asm volatile ("outb %al, $0x80");
29 break;
30 case CONFIG_IO_DELAY_TYPE_0XED:
31 asm volatile ("outb %al, $0xed");
32 break;
33 case CONFIG_IO_DELAY_TYPE_UDELAY:
34 /*
35 * 2 usecs is an upper-bound for the outb delay but
36 * note that udelay doesn't have the bus-level
37 * side-effects that outb does, nor does udelay() have
38 * precise timings during very early bootup (the delays
39 * are shorter until calibrated):
40 */
41 udelay(2);
42 case CONFIG_IO_DELAY_TYPE_NONE:
43 break;
44 }
b02aae9c
RH
45}
46EXPORT_SYMBOL(native_io_delay);
47
6e7c4025 48static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
b02aae9c 49{
6e7c4025 50 if (io_delay_type == CONFIG_IO_DELAY_TYPE_0X80) {
d53a4444 51 pr_notice("%s: using 0xed I/O delay port\n", id->ident);
6e7c4025
IM
52 io_delay_type = CONFIG_IO_DELAY_TYPE_0XED;
53 }
54
b02aae9c
RH
55 return 0;
56}
57
6e7c4025
IM
58/*
59 * Quirk table for systems that misbehave (lock up, etc.) if port
60 * 0x80 is used:
61 */
6faadbbb 62static const struct dmi_system_id io_delay_0xed_port_dmi_table[] __initconst = {
f9fc5891
IM
63 {
64 .callback = dmi_io_delay_0xed_port,
65 .ident = "Compaq Presario V6000",
66 .matches = {
d53a4444
JSR
67 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
68 DMI_MATCH(DMI_BOARD_NAME, "30B7")
f9fc5891
IM
69 }
70 },
b02aae9c 71 {
6e7c4025 72 .callback = dmi_io_delay_0xed_port,
b02aae9c
RH
73 .ident = "HP Pavilion dv9000z",
74 .matches = {
d53a4444
JSR
75 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
76 DMI_MATCH(DMI_BOARD_NAME, "30B9")
b02aae9c
RH
77 }
78 },
3c274c29
IM
79 {
80 .callback = dmi_io_delay_0xed_port,
81 .ident = "HP Pavilion dv6000",
82 .matches = {
d53a4444
JSR
83 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
84 DMI_MATCH(DMI_BOARD_NAME, "30B8")
3c274c29
IM
85 }
86 },
f9fc5891
IM
87 {
88 .callback = dmi_io_delay_0xed_port,
89 .ident = "HP Pavilion tx1000",
90 .matches = {
d53a4444
JSR
91 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
92 DMI_MATCH(DMI_BOARD_NAME, "30BF")
f9fc5891
IM
93 }
94 },
e6a5652f
CE
95 {
96 .callback = dmi_io_delay_0xed_port,
97 .ident = "Presario F700",
98 .matches = {
d53a4444
JSR
99 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
100 DMI_MATCH(DMI_BOARD_NAME, "30D3")
e6a5652f
CE
101 }
102 },
6e7c4025 103 { }
b02aae9c
RH
104};
105
b02aae9c
RH
106void __init io_delay_init(void)
107{
108 if (!io_delay_override)
6e7c4025 109 dmi_check_system(io_delay_0xed_port_dmi_table);
b02aae9c 110}
b02aae9c
RH
111
112static int __init io_delay_param(char *s)
113{
d6cd7eff
CG
114 if (!s)
115 return -EINVAL;
116
6e7c4025
IM
117 if (!strcmp(s, "0x80"))
118 io_delay_type = CONFIG_IO_DELAY_TYPE_0X80;
119 else if (!strcmp(s, "0xed"))
120 io_delay_type = CONFIG_IO_DELAY_TYPE_0XED;
b02aae9c 121 else if (!strcmp(s, "udelay"))
6e7c4025
IM
122 io_delay_type = CONFIG_IO_DELAY_TYPE_UDELAY;
123 else if (!strcmp(s, "none"))
124 io_delay_type = CONFIG_IO_DELAY_TYPE_NONE;
b02aae9c
RH
125 else
126 return -EINVAL;
127
b02aae9c 128 io_delay_override = 1;
b02aae9c
RH
129 return 0;
130}
131
132early_param("io_delay", io_delay_param);