motherboard.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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
  47. acpi_reserve_io_ranges (struct acpi_resource *res, void *data)
  48. {
  49. struct resource *requested_res = NULL;
  50. ACPI_FUNCTION_TRACE("acpi_reserve_io_ranges");
  51. if (res->id == ACPI_RSTYPE_IO) {
  52. struct acpi_resource_io *io_res = &res->data.io;
  53. if (io_res->min_base_address != io_res->max_base_address)
  54. return_VALUE(AE_OK);
  55. if (IS_RESERVED_ADDR(io_res->min_base_address, io_res->range_length)) {
  56. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Motherboard resources 0x%08x - 0x%08x\n",
  57. io_res->min_base_address,
  58. io_res->min_base_address + io_res->range_length));
  59. requested_res = request_region(io_res->min_base_address,
  60. io_res->range_length, "motherboard");
  61. }
  62. } else if (res->id == ACPI_RSTYPE_FIXED_IO) {
  63. struct acpi_resource_fixed_io *fixed_io_res = &res->data.fixed_io;
  64. if (IS_RESERVED_ADDR(fixed_io_res->base_address, fixed_io_res->range_length)) {
  65. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Motherboard resources 0x%08x - 0x%08x\n",
  66. fixed_io_res->base_address,
  67. fixed_io_res->base_address + fixed_io_res->range_length));
  68. requested_res = request_region(fixed_io_res->base_address,
  69. fixed_io_res->range_length, "motherboard");
  70. }
  71. } else {
  72. /* Memory mapped IO? */
  73. }
  74. if (requested_res)
  75. requested_res->flags &= ~IORESOURCE_BUSY;
  76. return_VALUE(AE_OK);
  77. }
  78. static int acpi_motherboard_add (struct acpi_device *device)
  79. {
  80. if (!device)
  81. return -EINVAL;
  82. acpi_walk_resources(device->handle, METHOD_NAME__CRS,
  83. acpi_reserve_io_ranges, NULL);
  84. return 0;
  85. }
  86. static struct acpi_driver acpi_motherboard_driver1 = {
  87. .name = "motherboard",
  88. .class = "",
  89. .ids = ACPI_MB_HID1,
  90. .ops = {
  91. .add = acpi_motherboard_add,
  92. },
  93. };
  94. static struct acpi_driver acpi_motherboard_driver2 = {
  95. .name = "motherboard",
  96. .class = "",
  97. .ids = ACPI_MB_HID2,
  98. .ops = {
  99. .add = acpi_motherboard_add,
  100. },
  101. };
  102. static void __init
  103. acpi_reserve_resources (void)
  104. {
  105. if (acpi_gbl_FADT->xpm1a_evt_blk.address && acpi_gbl_FADT->pm1_evt_len)
  106. request_region(acpi_gbl_FADT->xpm1a_evt_blk.address,
  107. acpi_gbl_FADT->pm1_evt_len, "PM1a_EVT_BLK");
  108. if (acpi_gbl_FADT->xpm1b_evt_blk.address && acpi_gbl_FADT->pm1_evt_len)
  109. request_region(acpi_gbl_FADT->xpm1b_evt_blk.address,
  110. acpi_gbl_FADT->pm1_evt_len, "PM1b_EVT_BLK");
  111. if (acpi_gbl_FADT->xpm1a_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len)
  112. request_region(acpi_gbl_FADT->xpm1a_cnt_blk.address,
  113. acpi_gbl_FADT->pm1_cnt_len, "PM1a_CNT_BLK");
  114. if (acpi_gbl_FADT->xpm1b_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len)
  115. request_region(acpi_gbl_FADT->xpm1b_cnt_blk.address,
  116. acpi_gbl_FADT->pm1_cnt_len, "PM1b_CNT_BLK");
  117. if (acpi_gbl_FADT->xpm_tmr_blk.address && acpi_gbl_FADT->pm_tm_len == 4)
  118. request_region(acpi_gbl_FADT->xpm_tmr_blk.address,
  119. 4, "PM_TMR");
  120. if (acpi_gbl_FADT->xpm2_cnt_blk.address && acpi_gbl_FADT->pm2_cnt_len)
  121. request_region(acpi_gbl_FADT->xpm2_cnt_blk.address,
  122. acpi_gbl_FADT->pm2_cnt_len, "PM2_CNT_BLK");
  123. /* Length of GPE blocks must be a non-negative multiple of 2 */
  124. if (acpi_gbl_FADT->xgpe0_blk.address && acpi_gbl_FADT->gpe0_blk_len &&
  125. !(acpi_gbl_FADT->gpe0_blk_len & 0x1))
  126. request_region(acpi_gbl_FADT->xgpe0_blk.address,
  127. acpi_gbl_FADT->gpe0_blk_len, "GPE0_BLK");
  128. if (acpi_gbl_FADT->xgpe1_blk.address && acpi_gbl_FADT->gpe1_blk_len &&
  129. !(acpi_gbl_FADT->gpe1_blk_len & 0x1))
  130. request_region(acpi_gbl_FADT->xgpe1_blk.address,
  131. acpi_gbl_FADT->gpe1_blk_len, "GPE1_BLK");
  132. }
  133. static int __init acpi_motherboard_init(void)
  134. {
  135. acpi_bus_register_driver(&acpi_motherboard_driver1);
  136. acpi_bus_register_driver(&acpi_motherboard_driver2);
  137. /*
  138. * Guarantee motherboard IO reservation first
  139. * This module must run after scan.c
  140. */
  141. if (!acpi_disabled)
  142. acpi_reserve_resources ();
  143. return 0;
  144. }
  145. /**
  146. * Reserve motherboard resources after PCI claim BARs,
  147. * but before PCI assign resources for uninitialized PCI devices
  148. */
  149. fs_initcall(acpi_motherboard_init);