motherboard.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or (at
  6. * your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. */
  19. /* Purpose: Prevent PCMCIA cards from using motherboard resources. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/types.h>
  23. #include <linux/pci.h>
  24. #include <linux/ioport.h>
  25. #include <asm/io.h>
  26. #include <acpi/acpi_bus.h>
  27. #include <acpi/acpi_drivers.h>
  28. #define _COMPONENT ACPI_SYSTEM_COMPONENT
  29. ACPI_MODULE_NAME("acpi_motherboard")
  30. /* Dell use PNP0C01 instead of PNP0C02 */
  31. #define ACPI_MB_HID1 "PNP0C01"
  32. #define ACPI_MB_HID2 "PNP0C02"
  33. /**
  34. * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
  35. * Doesn't care about the failure of 'request_region', since other may reserve
  36. * the io ports as well
  37. */
  38. #define IS_RESERVED_ADDR(base, len) \
  39. (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
  40. && ((base) + (len) > PCIBIOS_MIN_IO))
  41. /*
  42. * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
  43. * the io ports if they really know they can use it, while
  44. * still preventing hotplug PCI devices from using it.
  45. */
  46. static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
  47. {
  48. struct resource *requested_res = NULL;
  49. ACPI_FUNCTION_TRACE("acpi_reserve_io_ranges");
  50. if (res->type == ACPI_RESOURCE_TYPE_IO) {
  51. struct acpi_resource_io *io_res = &res->data.io;
  52. if (io_res->minimum != io_res->maximum)
  53. return_VALUE(AE_OK);
  54. if (IS_RESERVED_ADDR
  55. (io_res->minimum, io_res->address_length)) {
  56. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  57. "Motherboard resources 0x%08x - 0x%08x\n",
  58. io_res->minimum,
  59. io_res->minimum +
  60. io_res->address_length));
  61. requested_res =
  62. request_region(io_res->minimum,
  63. io_res->address_length, "motherboard");
  64. }
  65. } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
  66. struct acpi_resource_fixed_io *fixed_io_res =
  67. &res->data.fixed_io;
  68. if (IS_RESERVED_ADDR
  69. (fixed_io_res->address, fixed_io_res->address_length)) {
  70. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  71. "Motherboard resources 0x%08x - 0x%08x\n",
  72. fixed_io_res->address,
  73. fixed_io_res->address +
  74. fixed_io_res->address_length));
  75. requested_res =
  76. request_region(fixed_io_res->address,
  77. fixed_io_res->address_length,
  78. "motherboard");
  79. }
  80. } else {
  81. /* Memory mapped IO? */
  82. }
  83. if (requested_res)
  84. requested_res->flags &= ~IORESOURCE_BUSY;
  85. return_VALUE(AE_OK);
  86. }
  87. static int acpi_motherboard_add(struct acpi_device *device)
  88. {
  89. if (!device)
  90. return -EINVAL;
  91. acpi_walk_resources(device->handle, METHOD_NAME__CRS,
  92. acpi_reserve_io_ranges, NULL);
  93. return 0;
  94. }
  95. static struct acpi_driver acpi_motherboard_driver1 = {
  96. .name = "motherboard",
  97. .class = "",
  98. .ids = ACPI_MB_HID1,
  99. .ops = {
  100. .add = acpi_motherboard_add,
  101. },
  102. };
  103. static struct acpi_driver acpi_motherboard_driver2 = {
  104. .name = "motherboard",
  105. .class = "",
  106. .ids = ACPI_MB_HID2,
  107. .ops = {
  108. .add = acpi_motherboard_add,
  109. },
  110. };
  111. static void __init acpi_reserve_resources(void)
  112. {
  113. if (acpi_gbl_FADT->xpm1a_evt_blk.address && acpi_gbl_FADT->pm1_evt_len)
  114. request_region(acpi_gbl_FADT->xpm1a_evt_blk.address,
  115. acpi_gbl_FADT->pm1_evt_len, "PM1a_EVT_BLK");
  116. if (acpi_gbl_FADT->xpm1b_evt_blk.address && acpi_gbl_FADT->pm1_evt_len)
  117. request_region(acpi_gbl_FADT->xpm1b_evt_blk.address,
  118. acpi_gbl_FADT->pm1_evt_len, "PM1b_EVT_BLK");
  119. if (acpi_gbl_FADT->xpm1a_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len)
  120. request_region(acpi_gbl_FADT->xpm1a_cnt_blk.address,
  121. acpi_gbl_FADT->pm1_cnt_len, "PM1a_CNT_BLK");
  122. if (acpi_gbl_FADT->xpm1b_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len)
  123. request_region(acpi_gbl_FADT->xpm1b_cnt_blk.address,
  124. acpi_gbl_FADT->pm1_cnt_len, "PM1b_CNT_BLK");
  125. if (acpi_gbl_FADT->xpm_tmr_blk.address && acpi_gbl_FADT->pm_tm_len == 4)
  126. request_region(acpi_gbl_FADT->xpm_tmr_blk.address, 4, "PM_TMR");
  127. if (acpi_gbl_FADT->xpm2_cnt_blk.address && acpi_gbl_FADT->pm2_cnt_len)
  128. request_region(acpi_gbl_FADT->xpm2_cnt_blk.address,
  129. acpi_gbl_FADT->pm2_cnt_len, "PM2_CNT_BLK");
  130. /* Length of GPE blocks must be a non-negative multiple of 2 */
  131. if (acpi_gbl_FADT->xgpe0_blk.address && acpi_gbl_FADT->gpe0_blk_len &&
  132. !(acpi_gbl_FADT->gpe0_blk_len & 0x1))
  133. request_region(acpi_gbl_FADT->xgpe0_blk.address,
  134. acpi_gbl_FADT->gpe0_blk_len, "GPE0_BLK");
  135. if (acpi_gbl_FADT->xgpe1_blk.address && acpi_gbl_FADT->gpe1_blk_len &&
  136. !(acpi_gbl_FADT->gpe1_blk_len & 0x1))
  137. request_region(acpi_gbl_FADT->xgpe1_blk.address,
  138. acpi_gbl_FADT->gpe1_blk_len, "GPE1_BLK");
  139. }
  140. static int __init acpi_motherboard_init(void)
  141. {
  142. acpi_bus_register_driver(&acpi_motherboard_driver1);
  143. acpi_bus_register_driver(&acpi_motherboard_driver2);
  144. /*
  145. * Guarantee motherboard IO reservation first
  146. * This module must run after scan.c
  147. */
  148. if (!acpi_disabled)
  149. acpi_reserve_resources();
  150. return 0;
  151. }
  152. /**
  153. * Reserve motherboard resources after PCI claim BARs,
  154. * but before PCI assign resources for uninitialized PCI devices
  155. */
  156. fs_initcall(acpi_motherboard_init);