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.
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.
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.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 /* Purpose: Prevent PCMCIA cards from using motherboard resources. */
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>
29 #include <acpi/acpi_bus.h>
30 #include <acpi/acpi_drivers.h>
32 #define _COMPONENT ACPI_SYSTEM_COMPONENT
33 ACPI_MODULE_NAME("acpi_motherboard")
35 /* Dell use PNP0C01 instead of PNP0C02 */
36 #define ACPI_MB_HID "PNP0C01,PNP0C02"
38 * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
39 * Doesn't care about the failure of 'request_region', since other may reserve
40 * the io ports as well
42 #define IS_RESERVED_ADDR(base, len) \
43 (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
44 && ((base) + (len) > PCIBIOS_MIN_IO))
46 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
47 * the io ports if they really know they can use it, while
48 * still preventing hotplug PCI devices from using it.
52 * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01
53 * and PNP0C02, redundant with acpi_reserve_io_ranges().
54 * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP.
56 static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
58 struct resource *requested_res = NULL;
61 if (res->type == ACPI_RESOURCE_TYPE_IO) {
62 struct acpi_resource_io *io_res = &res->data.io;
64 if (io_res->minimum != io_res->maximum)
67 (io_res->minimum, io_res->address_length)) {
68 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
69 "Motherboard resources 0x%08x - 0x%08x\n",
72 io_res->address_length));
74 request_region(io_res->minimum,
75 io_res->address_length, "motherboard");
77 } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
78 struct acpi_resource_fixed_io *fixed_io_res =
82 (fixed_io_res->address, fixed_io_res->address_length)) {
83 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
84 "Motherboard resources 0x%08x - 0x%08x\n",
85 fixed_io_res->address,
86 fixed_io_res->address +
87 fixed_io_res->address_length));
89 request_region(fixed_io_res->address,
90 fixed_io_res->address_length,
94 /* Memory mapped IO? */
98 requested_res->flags &= ~IORESOURCE_BUSY;
102 static int acpi_motherboard_add(struct acpi_device *device)
106 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
107 acpi_reserve_io_ranges, NULL);
112 static struct acpi_driver acpi_motherboard_driver = {
113 .name = "motherboard",
117 .add = acpi_motherboard_add,
121 static void __init acpi_request_region (struct acpi_generic_address *addr,
122 unsigned int length, char *desc)
124 if (!addr->address || !length)
127 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
128 request_region(addr->address, length, desc);
129 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
130 request_mem_region(addr->address, length, desc);
133 static void __init acpi_reserve_resources(void)
135 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block,
136 acpi_gbl_FADT.pm1_event_length, "ACPI PM1a_EVT_BLK");
138 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block,
139 acpi_gbl_FADT.pm1_event_length, "ACPI PM1b_EVT_BLK");
141 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block,
142 acpi_gbl_FADT.pm1_control_length, "ACPI PM1a_CNT_BLK");
144 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block,
145 acpi_gbl_FADT.pm1_control_length, "ACPI PM1b_CNT_BLK");
147 if (acpi_gbl_FADT.pm_timer_length == 4)
148 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
150 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block,
151 acpi_gbl_FADT.pm2_control_length, "ACPI PM2_CNT_BLK");
153 /* Length of GPE blocks must be a non-negative multiple of 2 */
155 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
156 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
157 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
159 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
160 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
161 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
164 static int __init acpi_motherboard_init(void)
166 acpi_bus_register_driver(&acpi_motherboard_driver);
168 * Guarantee motherboard IO reservation first
169 * This module must run after scan.c
172 acpi_reserve_resources();
177 * Reserve motherboard resources after PCI claim BARs,
178 * but before PCI assign resources for uninitialized PCI devices
180 fs_initcall(acpi_motherboard_init);