blob: 2e17ec75af03e84756689ce8bca915f2b0e3c2d5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Brown4be44fc2005-08-05 00:44:28 -040033ACPI_MODULE_NAME("acpi_motherboard")
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/* Dell use PNP0C01 instead of PNP0C02 */
36#define ACPI_MB_HID1 "PNP0C01"
37#define ACPI_MB_HID2 "PNP0C02"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/**
39 * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
Bjorn Helgaascd090ee2006-03-28 17:04:00 -050040 * Doesn't care about the failure of 'request_region', since other may reserve
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * the io ports as well
42 */
43#define IS_RESERVED_ADDR(base, len) \
44 (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
Linus Torvalds2ba84682005-08-14 18:21:30 -070045 && ((base) + (len) > PCIBIOS_MIN_IO))
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/*
47 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
48 * the io ports if they really know they can use it, while
Bjorn Helgaascd090ee2006-03-28 17:04:00 -050049 * still preventing hotplug PCI devices from using it.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
Len Brownf4d2e2d2006-09-14 17:16:22 -040051
52/*
53 * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01
54 * and PNP0C02, redundant with acpi_reserve_io_ranges().
55 * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP.
56 */
Len Brown4be44fc2005-08-05 00:44:28 -040057static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 struct resource *requested_res = NULL;
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Bob Moore50eca3e2005-09-30 19:03:00 -040062 if (res->type == ACPI_RESOURCE_TYPE_IO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 struct acpi_resource_io *io_res = &res->data.io;
64
Bob Moore50eca3e2005-09-30 19:03:00 -040065 if (io_res->minimum != io_res->maximum)
Patrick Mocheld550d982006-06-27 00:41:40 -040066 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -040067 if (IS_RESERVED_ADDR
Bob Moore50eca3e2005-09-30 19:03:00 -040068 (io_res->minimum, io_res->address_length)) {
Len Brown4be44fc2005-08-05 00:44:28 -040069 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
70 "Motherboard resources 0x%08x - 0x%08x\n",
Bob Moore50eca3e2005-09-30 19:03:00 -040071 io_res->minimum,
72 io_res->minimum +
73 io_res->address_length));
Len Brown4be44fc2005-08-05 00:44:28 -040074 requested_res =
Bob Moore50eca3e2005-09-30 19:03:00 -040075 request_region(io_res->minimum,
76 io_res->address_length, "motherboard");
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Bob Moore50eca3e2005-09-30 19:03:00 -040078 } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
Len Brown4be44fc2005-08-05 00:44:28 -040079 struct acpi_resource_fixed_io *fixed_io_res =
80 &res->data.fixed_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Len Brown4be44fc2005-08-05 00:44:28 -040082 if (IS_RESERVED_ADDR
Bob Moore50eca3e2005-09-30 19:03:00 -040083 (fixed_io_res->address, fixed_io_res->address_length)) {
Len Brown4be44fc2005-08-05 00:44:28 -040084 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
85 "Motherboard resources 0x%08x - 0x%08x\n",
Bob Moore50eca3e2005-09-30 19:03:00 -040086 fixed_io_res->address,
87 fixed_io_res->address +
88 fixed_io_res->address_length));
Len Brown4be44fc2005-08-05 00:44:28 -040089 requested_res =
Bob Moore50eca3e2005-09-30 19:03:00 -040090 request_region(fixed_io_res->address,
91 fixed_io_res->address_length,
Len Brown4be44fc2005-08-05 00:44:28 -040092 "motherboard");
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94 } else {
95 /* Memory mapped IO? */
96 }
97
98 if (requested_res)
99 requested_res->flags &= ~IORESOURCE_BUSY;
Patrick Mocheld550d982006-06-27 00:41:40 -0400100 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Len Brown4be44fc2005-08-05 00:44:28 -0400103static int acpi_motherboard_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 if (!device)
106 return -EINVAL;
Len Brown4be44fc2005-08-05 00:44:28 -0400107 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
108 acpi_reserve_io_ranges, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 return 0;
111}
112
113static struct acpi_driver acpi_motherboard_driver1 = {
Len Brown4be44fc2005-08-05 00:44:28 -0400114 .name = "motherboard",
115 .class = "",
116 .ids = ACPI_MB_HID1,
117 .ops = {
118 .add = acpi_motherboard_add,
119 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
122static struct acpi_driver acpi_motherboard_driver2 = {
Len Brown4be44fc2005-08-05 00:44:28 -0400123 .name = "motherboard",
124 .class = "",
125 .ids = ACPI_MB_HID2,
126 .ops = {
127 .add = acpi_motherboard_add,
128 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500131static void __init acpi_request_region (struct acpi_generic_address *addr,
132 unsigned int length, char *desc)
133{
134 if (!addr->address || !length)
135 return;
136
137 if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_IO)
138 request_region(addr->address, length, desc);
139 else if (addr->address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
140 request_mem_region(addr->address, length, desc);
141}
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143static void __init acpi_reserve_resources(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500145 acpi_request_region(&acpi_gbl_FADT->xpm1a_evt_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500146 acpi_gbl_FADT->pm1_evt_len, "ACPI PM1a_EVT_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500148 acpi_request_region(&acpi_gbl_FADT->xpm1b_evt_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500149 acpi_gbl_FADT->pm1_evt_len, "ACPI PM1b_EVT_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500151 acpi_request_region(&acpi_gbl_FADT->xpm1a_cnt_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500152 acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1a_CNT_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500154 acpi_request_region(&acpi_gbl_FADT->xpm1b_cnt_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500155 acpi_gbl_FADT->pm1_cnt_len, "ACPI PM1b_CNT_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500157 if (acpi_gbl_FADT->pm_tm_len == 4)
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500158 acpi_request_region(&acpi_gbl_FADT->xpm_tmr_blk, 4, "ACPI PM_TMR");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500160 acpi_request_region(&acpi_gbl_FADT->xpm2_cnt_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500161 acpi_gbl_FADT->pm2_cnt_len, "ACPI PM2_CNT_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* Length of GPE blocks must be a non-negative multiple of 2 */
164
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500165 if (!(acpi_gbl_FADT->gpe0_blk_len & 0x1))
166 acpi_request_region(&acpi_gbl_FADT->xgpe0_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500167 acpi_gbl_FADT->gpe0_blk_len, "ACPI GPE0_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Bjorn Helgaas81507ea2006-03-28 17:04:00 -0500169 if (!(acpi_gbl_FADT->gpe1_blk_len & 0x1))
170 acpi_request_region(&acpi_gbl_FADT->xgpe1_blk,
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500171 acpi_gbl_FADT->gpe1_blk_len, "ACPI GPE1_BLK");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
174static int __init acpi_motherboard_init(void)
175{
176 acpi_bus_register_driver(&acpi_motherboard_driver1);
177 acpi_bus_register_driver(&acpi_motherboard_driver2);
Bjorn Helgaascd090ee2006-03-28 17:04:00 -0500178 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 * Guarantee motherboard IO reservation first
180 * This module must run after scan.c
181 */
182 if (!acpi_disabled)
Len Brown4be44fc2005-08-05 00:44:28 -0400183 acpi_reserve_resources();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return 0;
185}
186
187/**
188 * Reserve motherboard resources after PCI claim BARs,
189 * but before PCI assign resources for uninitialized PCI devices
190 */
191fs_initcall(acpi_motherboard_init);