blob: 805b7a341aca2e773b67317aea90f334ea0f96d6 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Rene Hermanb02aae92008-01-30 13:30:05 +01002/*
3 * I/O delay strategies for inb_p/outb_p
Ingo Molnar6e7c4022008-01-30 13:30:05 +01004 *
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.
Rene Hermanb02aae92008-01-30 13:30:05 +01008 */
9#include <linux/kernel.h>
Paul Gortmaker186f4362016-07-13 20:18:56 -040010#include <linux/export.h>
Rene Hermanb02aae92008-01-30 13:30:05 +010011#include <linux/delay.h>
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053012#include <linux/init.h>
Rene Hermanb02aae92008-01-30 13:30:05 +010013#include <linux/dmi.h>
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053014#include <linux/io.h>
Rene Hermanb02aae92008-01-30 13:30:05 +010015
Ingo Molnar6e7c4022008-01-30 13:30:05 +010016int io_delay_type __read_mostly = CONFIG_DEFAULT_IO_DELAY_TYPE;
Rene Hermanb02aae92008-01-30 13:30:05 +010017
Ingo Molnar6e7c4022008-01-30 13:30:05 +010018static int __initdata io_delay_override;
Rene Hermanb02aae92008-01-30 13:30:05 +010019
20/*
21 * Paravirt wants native_io_delay to be a constant.
22 */
23void native_io_delay(void)
24{
Ingo Molnar6e7c4022008-01-30 13:30:05 +010025 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 }
Rene Hermanb02aae92008-01-30 13:30:05 +010045}
46EXPORT_SYMBOL(native_io_delay);
47
Ingo Molnar6e7c4022008-01-30 13:30:05 +010048static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
Rene Hermanb02aae92008-01-30 13:30:05 +010049{
Ingo Molnar6e7c4022008-01-30 13:30:05 +010050 if (io_delay_type == CONFIG_IO_DELAY_TYPE_0X80) {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053051 pr_notice("%s: using 0xed I/O delay port\n", id->ident);
Ingo Molnar6e7c4022008-01-30 13:30:05 +010052 io_delay_type = CONFIG_IO_DELAY_TYPE_0XED;
53 }
54
Rene Hermanb02aae92008-01-30 13:30:05 +010055 return 0;
56}
57
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058/*
59 * Quirk table for systems that misbehave (lock up, etc.) if port
60 * 0x80 is used:
61 */
Christoph Hellwig6faadbb2017-09-14 11:59:30 +020062static const struct dmi_system_id io_delay_0xed_port_dmi_table[] __initconst = {
Rene Hermanb02aae92008-01-30 13:30:05 +010063 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +010064 .callback = dmi_io_delay_0xed_port,
Ingo Molnarf9fc58912008-01-30 13:30:05 +010065 .ident = "Compaq Presario V6000",
66 .matches = {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053067 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
68 DMI_MATCH(DMI_BOARD_NAME, "30B7")
Ingo Molnarf9fc58912008-01-30 13:30:05 +010069 }
70 },
71 {
72 .callback = dmi_io_delay_0xed_port,
Rene Hermanb02aae92008-01-30 13:30:05 +010073 .ident = "HP Pavilion dv9000z",
74 .matches = {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053075 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
76 DMI_MATCH(DMI_BOARD_NAME, "30B9")
Rene Hermanb02aae92008-01-30 13:30:05 +010077 }
78 },
Ingo Molnarf9fc58912008-01-30 13:30:05 +010079 {
80 .callback = dmi_io_delay_0xed_port,
Ingo Molnar3c274c22008-03-21 10:06:32 +010081 .ident = "HP Pavilion dv6000",
82 .matches = {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053083 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
84 DMI_MATCH(DMI_BOARD_NAME, "30B8")
Ingo Molnar3c274c22008-03-21 10:06:32 +010085 }
86 },
87 {
88 .callback = dmi_io_delay_0xed_port,
Ingo Molnarf9fc58912008-01-30 13:30:05 +010089 .ident = "HP Pavilion tx1000",
90 .matches = {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053091 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
92 DMI_MATCH(DMI_BOARD_NAME, "30BF")
Ingo Molnarf9fc58912008-01-30 13:30:05 +010093 }
94 },
Chuck Ebberte6a56522008-09-03 19:33:14 -040095 {
96 .callback = dmi_io_delay_0xed_port,
97 .ident = "Presario F700",
98 .matches = {
Jaswinder Singh Rajputd53a4442009-03-21 16:57:04 +053099 DMI_MATCH(DMI_BOARD_VENDOR, "Quanta"),
100 DMI_MATCH(DMI_BOARD_NAME, "30D3")
Chuck Ebberte6a56522008-09-03 19:33:14 -0400101 }
102 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100103 { }
Rene Hermanb02aae92008-01-30 13:30:05 +0100104};
105
Rene Hermanb02aae92008-01-30 13:30:05 +0100106void __init io_delay_init(void)
107{
108 if (!io_delay_override)
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100109 dmi_check_system(io_delay_0xed_port_dmi_table);
Rene Hermanb02aae92008-01-30 13:30:05 +0100110}
Rene Hermanb02aae92008-01-30 13:30:05 +0100111
112static int __init io_delay_param(char *s)
113{
Cyrill Gorcunovd6cd7ef2008-07-05 15:53:37 +0400114 if (!s)
115 return -EINVAL;
116
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100117 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;
Rene Hermanb02aae92008-01-30 13:30:05 +0100121 else if (!strcmp(s, "udelay"))
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100122 io_delay_type = CONFIG_IO_DELAY_TYPE_UDELAY;
123 else if (!strcmp(s, "none"))
124 io_delay_type = CONFIG_IO_DELAY_TYPE_NONE;
Rene Hermanb02aae92008-01-30 13:30:05 +0100125 else
126 return -EINVAL;
127
Rene Hermanb02aae92008-01-30 13:30:05 +0100128 io_delay_override = 1;
Rene Hermanb02aae92008-01-30 13:30:05 +0100129 return 0;
130}
131
132early_param("io_delay", io_delay_param);