| 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 | 
|  | 40 | * Doesn't care about the failure of 'request_region', since other may reserve | 
|  | 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 | 
|  | 49 | * still preventing hotplug PCI devices from using it. | 
|  | 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 |  | 
|  | 55 | ACPI_FUNCTION_TRACE("acpi_reserve_io_ranges"); | 
|  | 56 |  | 
|  | 57 | if (res->id == ACPI_RSTYPE_IO) { | 
|  | 58 | struct acpi_resource_io *io_res = &res->data.io; | 
|  | 59 |  | 
|  | 60 | if (io_res->min_base_address != io_res->max_base_address) | 
|  | 61 | return_VALUE(AE_OK); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 62 | if (IS_RESERVED_ADDR | 
|  | 63 | (io_res->min_base_address, io_res->range_length)) { | 
|  | 64 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 65 | "Motherboard resources 0x%08x - 0x%08x\n", | 
|  | 66 | io_res->min_base_address, | 
|  | 67 | io_res->min_base_address + | 
|  | 68 | io_res->range_length)); | 
|  | 69 | requested_res = | 
|  | 70 | request_region(io_res->min_base_address, | 
|  | 71 | io_res->range_length, "motherboard"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } | 
|  | 73 | } else if (res->id == ACPI_RSTYPE_FIXED_IO) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | struct acpi_resource_fixed_io *fixed_io_res = | 
|  | 75 | &res->data.fixed_io; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | if (IS_RESERVED_ADDR | 
|  | 78 | (fixed_io_res->base_address, fixed_io_res->range_length)) { | 
|  | 79 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 80 | "Motherboard resources 0x%08x - 0x%08x\n", | 
|  | 81 | fixed_io_res->base_address, | 
|  | 82 | fixed_io_res->base_address + | 
|  | 83 | fixed_io_res->range_length)); | 
|  | 84 | requested_res = | 
|  | 85 | request_region(fixed_io_res->base_address, | 
|  | 86 | fixed_io_res->range_length, | 
|  | 87 | "motherboard"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } | 
|  | 89 | } else { | 
|  | 90 | /* Memory mapped IO? */ | 
|  | 91 | } | 
|  | 92 |  | 
|  | 93 | if (requested_res) | 
|  | 94 | requested_res->flags &= ~IORESOURCE_BUSY; | 
|  | 95 | return_VALUE(AE_OK); | 
|  | 96 | } | 
|  | 97 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | static int acpi_motherboard_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { | 
|  | 100 | if (!device) | 
|  | 101 | return -EINVAL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, | 
|  | 103 | acpi_reserve_io_ranges, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
|  | 105 | return 0; | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | static struct acpi_driver acpi_motherboard_driver1 = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | .name = "motherboard", | 
|  | 110 | .class = "", | 
|  | 111 | .ids = ACPI_MB_HID1, | 
|  | 112 | .ops = { | 
|  | 113 | .add = acpi_motherboard_add, | 
|  | 114 | }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | }; | 
|  | 116 |  | 
|  | 117 | static struct acpi_driver acpi_motherboard_driver2 = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | .name = "motherboard", | 
|  | 119 | .class = "", | 
|  | 120 | .ids = ACPI_MB_HID2, | 
|  | 121 | .ops = { | 
|  | 122 | .add = acpi_motherboard_add, | 
|  | 123 | }, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; | 
|  | 125 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | static void __init acpi_reserve_resources(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { | 
|  | 128 | if (acpi_gbl_FADT->xpm1a_evt_blk.address && acpi_gbl_FADT->pm1_evt_len) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | request_region(acpi_gbl_FADT->xpm1a_evt_blk.address, | 
|  | 130 | acpi_gbl_FADT->pm1_evt_len, "PM1a_EVT_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 |  | 
|  | 132 | if (acpi_gbl_FADT->xpm1b_evt_blk.address && acpi_gbl_FADT->pm1_evt_len) | 
|  | 133 | request_region(acpi_gbl_FADT->xpm1b_evt_blk.address, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | acpi_gbl_FADT->pm1_evt_len, "PM1b_EVT_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 |  | 
|  | 136 | if (acpi_gbl_FADT->xpm1a_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | request_region(acpi_gbl_FADT->xpm1a_cnt_blk.address, | 
|  | 138 | acpi_gbl_FADT->pm1_cnt_len, "PM1a_CNT_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  | 
|  | 140 | if (acpi_gbl_FADT->xpm1b_cnt_blk.address && acpi_gbl_FADT->pm1_cnt_len) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | request_region(acpi_gbl_FADT->xpm1b_cnt_blk.address, | 
|  | 142 | acpi_gbl_FADT->pm1_cnt_len, "PM1b_CNT_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  | 
|  | 144 | if (acpi_gbl_FADT->xpm_tmr_blk.address && acpi_gbl_FADT->pm_tm_len == 4) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | request_region(acpi_gbl_FADT->xpm_tmr_blk.address, 4, "PM_TMR"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
|  | 147 | if (acpi_gbl_FADT->xpm2_cnt_blk.address && acpi_gbl_FADT->pm2_cnt_len) | 
|  | 148 | request_region(acpi_gbl_FADT->xpm2_cnt_blk.address, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | acpi_gbl_FADT->pm2_cnt_len, "PM2_CNT_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 |  | 
|  | 151 | /* Length of GPE blocks must be a non-negative multiple of 2 */ | 
|  | 152 |  | 
|  | 153 | if (acpi_gbl_FADT->xgpe0_blk.address && acpi_gbl_FADT->gpe0_blk_len && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | !(acpi_gbl_FADT->gpe0_blk_len & 0x1)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | request_region(acpi_gbl_FADT->xgpe0_blk.address, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | acpi_gbl_FADT->gpe0_blk_len, "GPE0_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 |  | 
|  | 158 | if (acpi_gbl_FADT->xgpe1_blk.address && acpi_gbl_FADT->gpe1_blk_len && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | !(acpi_gbl_FADT->gpe1_blk_len & 0x1)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | request_region(acpi_gbl_FADT->xgpe1_blk.address, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | acpi_gbl_FADT->gpe1_blk_len, "GPE1_BLK"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } | 
|  | 163 |  | 
|  | 164 | static int __init acpi_motherboard_init(void) | 
|  | 165 | { | 
|  | 166 | acpi_bus_register_driver(&acpi_motherboard_driver1); | 
|  | 167 | acpi_bus_register_driver(&acpi_motherboard_driver2); | 
|  | 168 | /* | 
|  | 169 | * Guarantee motherboard IO reservation first | 
|  | 170 | * This module must run after scan.c | 
|  | 171 | */ | 
|  | 172 | if (!acpi_disabled) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | acpi_reserve_resources(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return 0; | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | /** | 
|  | 178 | * Reserve motherboard resources after PCI claim BARs, | 
|  | 179 | * but before PCI assign resources for uninitialized PCI devices | 
|  | 180 | */ | 
|  | 181 | fs_initcall(acpi_motherboard_init); |