motherboard.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_HID "PNP0C01,PNP0C02"
  32. /**
  33. * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
  34. * Doesn't care about the failure of 'request_region', since other may reserve
  35. * the io ports as well
  36. */
  37. #define IS_RESERVED_ADDR(base, len) \
  38. (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
  39. && ((base) + (len) > PCIBIOS_MIN_IO))
  40. /*
  41. * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
  42. * the io ports if they really know they can use it, while
  43. * still preventing hotplug PCI devices from using it.
  44. */
  45. /*
  46. * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01
  47. * and PNP0C02, redundant with acpi_reserve_io_ranges().
  48. * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP.
  49. */
  50. static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
  51. {
  52. struct resource *requested_res = NULL;
  53. if (res->type == ACPI_RESOURCE_TYPE_IO) {
  54. struct acpi_resource_io *io_res = &res->data.io;
  55. if (io_res->minimum != io_res->maximum)
  56. return AE_OK;
  57. if (IS_RESERVED_ADDR
  58. (io_res->minimum, io_res->address_length)) {
  59. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  60. "Motherboard resources 0x%08x - 0x%08x\n",
  61. io_res->minimum,
  62. io_res->minimum +
  63. io_res->address_length));
  64. requested_res =
  65. request_region(io_res->minimum,
  66. io_res->address_length, "motherboard");
  67. }
  68. } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
  69. struct acpi_resource_fixed_io *fixed_io_res =
  70. &res->data.fixed_io;
  71. if (IS_RESERVED_ADDR
  72. (fixed_io_res->address, fixed_io_res->address_length)) {
  73. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  74. "Motherboard resources 0x%08x - 0x%08x\n",
  75. fixed_io_res->address,
  76. fixed_io_res->address +
  77. fixed_io_res->address_length));
  78. requested_res =
  79. request_region(fixed_io_res->address,
  80. fixed_io_res->address_length,
  81. "motherboard");
  82. }
  83. } else {
  84. /* Memory mapped IO? */
  85. }
  86. if (requested_res)
  87. requested_res->flags &= ~IORESOURCE_BUSY;
  88. return AE_OK;
  89. }
  90. static int acpi_motherboard_add(struct acpi_device *device)
  91. {
  92. if (!device)
  93. return -EINVAL;
  94. acpi_walk_resources(device->handle, METHOD_NAME__CRS,
  95. acpi_reserve_io_ranges, NULL);
  96. return 0;
  97. }
  98. static struct acpi_driver acpi_motherboard_driver = {
  99. .name = "motherboard",
  100. .class = "",
  101. .ids = ACPI_MB_HID,
  102. .ops = {
  103. .add = acpi_motherboard_add,
  104. },
  105. };
  106. static int __init acpi_motherboard_init(void)
  107. {
  108. acpi_bus_register_driver(&acpi_motherboard_driver);
  109. return 0;
  110. }
  111. /**
  112. * Reserve motherboard resources after PCI claim BARs,
  113. * but before PCI assign resources for uninitialized PCI devices
  114. */
  115. fs_initcall(acpi_motherboard_init);