io_delay.c 3.0 KB

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