Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 20 | /* Purpose: Prevent PCMCIA cards from using motherboard resources. */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/ioport.h> |
| 27 | #include <asm/io.h> |
| 28 | |
| 29 | #include <acpi/acpi_bus.h> |
| 30 | #include <acpi/acpi_drivers.h> |
| 31 | |
| 32 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 33 | ACPI_MODULE_NAME("acpi_motherboard") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | /* Dell use PNP0C01 instead of PNP0C02 */ |
| 36 | #define ACPI_MB_HID1 "PNP0C01" |
| 37 | #define ACPI_MB_HID2 "PNP0C02" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 40 | * Doesn't care about the failure of 'request_region', since other may reserve |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | * the io ports as well |
| 42 | */ |
| 43 | #define IS_RESERVED_ADDR(base, len) \ |
| 44 | (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \ |
Linus Torvalds | 2ba8468 | 2005-08-14 18:21:30 -0700 | [diff] [blame] | 45 | && ((base) + (len) > PCIBIOS_MIN_IO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
| 47 | * Clearing the flag (IORESOURCE_BUSY) allows drivers to use |
| 48 | * the io ports if they really know they can use it, while |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 49 | * still preventing hotplug PCI devices from using it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
| 53 | struct resource *requested_res = NULL; |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 56 | if (res->type == ACPI_RESOURCE_TYPE_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct acpi_resource_io *io_res = &res->data.io; |
| 58 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 59 | if (io_res->minimum != io_res->maximum) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 60 | return AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | if (IS_RESERVED_ADDR |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 62 | (io_res->minimum, io_res->address_length)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 64 | "Motherboard resources 0x%08x - 0x%08x\n", |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 65 | io_res->minimum, |
| 66 | io_res->minimum + |
| 67 | io_res->address_length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 68 | requested_res = |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 69 | request_region(io_res->minimum, |
| 70 | io_res->address_length, "motherboard"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 72 | } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | struct acpi_resource_fixed_io *fixed_io_res = |
| 74 | &res->data.fixed_io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | if (IS_RESERVED_ADDR |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 77 | (fixed_io_res->address, fixed_io_res->address_length)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 79 | "Motherboard resources 0x%08x - 0x%08x\n", |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 80 | fixed_io_res->address, |
| 81 | fixed_io_res->address + |
| 82 | fixed_io_res->address_length)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | requested_res = |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 84 | request_region(fixed_io_res->address, |
| 85 | fixed_io_res->address_length, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | "motherboard"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | } else { |
| 89 | /* Memory mapped IO? */ |
| 90 | } |
| 91 | |
| 92 | if (requested_res) |
| 93 | requested_res->flags &= ~IORESOURCE_BUSY; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 94 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | static int acpi_motherboard_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | if (!device) |
| 100 | return -EINVAL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, |
| 102 | acpi_reserve_io_ranges, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | static struct acpi_driver acpi_motherboard_driver1 = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | .name = "motherboard", |
| 109 | .class = "", |
| 110 | .ids = ACPI_MB_HID1, |
| 111 | .ops = { |
| 112 | .add = acpi_motherboard_add, |
| 113 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | static struct acpi_driver acpi_motherboard_driver2 = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | .name = "motherboard", |
| 118 | .class = "", |
| 119 | .ids = ACPI_MB_HID2, |
| 120 | .ops = { |
| 121 | .add = acpi_motherboard_add, |
| 122 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 125 | static void __init acpi_request_region (struct acpi_generic_address *addr, |
| 126 | unsigned int length, char *desc) |
| 127 | { |
| 128 | if (!addr->address || !length) |
| 129 | return; |
| 130 | |
| 131 | if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) |
| 132 | request_region(addr->address, length, desc); |
| 133 | else if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
| 134 | request_mem_region(addr->address, length, desc); |
| 135 | } |
| 136 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | static void __init acpi_reserve_resources(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 139 | acpi_request_region(&acpi_gbl_FADT->xpm1a_evt_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 140 | acpi_gbl_FADT->pm1_evt_len, "ACPI PM1a_EVT_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 142 | acpi_request_region(&acpi_gbl_FADT->xpm1b_evt_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 143 | acpi_gbl_FADT->pm1_evt_len, "ACPI PM1b_EVT_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 145 | acpi_request_region(&acpi_gbl_FADT->xpm1a_cnt_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 146 | acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1a_CNT_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 148 | acpi_request_region(&acpi_gbl_FADT->xpm1b_cnt_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 149 | acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1b_CNT_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 151 | if (acpi_gbl_FADT->pm_tm_len == 4) |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 152 | acpi_request_region(&acpi_gbl_FADT->xpm_tmr_blk, 4, "ACPI PM_TMR"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 154 | acpi_request_region(&acpi_gbl_FADT->xpm2_cnt_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 155 | acpi_gbl_FADT->pm2_cnt_len, "ACPI PM2_CNT_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* Length of GPE blocks must be a non-negative multiple of 2 */ |
| 158 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 159 | if (!(acpi_gbl_FADT->gpe0_blk_len & 0x1)) |
| 160 | acpi_request_region(&acpi_gbl_FADT->xgpe0_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 161 | acpi_gbl_FADT->gpe0_blk_len, "ACPI GPE0_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Bjorn Helgaas | 81507ea | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 163 | if (!(acpi_gbl_FADT->gpe1_blk_len & 0x1)) |
| 164 | acpi_request_region(&acpi_gbl_FADT->xgpe1_blk, |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 165 | acpi_gbl_FADT->gpe1_blk_len, "ACPI GPE1_BLK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static int __init acpi_motherboard_init(void) |
| 169 | { |
| 170 | acpi_bus_register_driver(&acpi_motherboard_driver1); |
| 171 | acpi_bus_register_driver(&acpi_motherboard_driver2); |
Bjorn Helgaas | cd090ee | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 172 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | * Guarantee motherboard IO reservation first |
| 174 | * This module must run after scan.c |
| 175 | */ |
| 176 | if (!acpi_disabled) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | acpi_reserve_resources(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Reserve motherboard resources after PCI claim BARs, |
| 183 | * but before PCI assign resources for uninitialized PCI devices |
| 184 | */ |
| 185 | fs_initcall(acpi_motherboard_init); |