io_delay.c 3.4 KB

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