ACPICA: minimal patch to integrate new tables into Linux
[linux-2.6-block.git] / drivers / acpi / motherboard.c
CommitLineData
1da177e4
LT
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
4be44fcd 33ACPI_MODULE_NAME("acpi_motherboard")
1da177e4
LT
34
35/* Dell use PNP0C01 instead of PNP0C02 */
36#define ACPI_MB_HID1 "PNP0C01"
37#define ACPI_MB_HID2 "PNP0C02"
1da177e4
LT
38/**
39 * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
cd090eed 40 * Doesn't care about the failure of 'request_region', since other may reserve
1da177e4
LT
41 * the io ports as well
42 */
43#define IS_RESERVED_ADDR(base, len) \
44 (((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
2ba84684 45 && ((base) + (len) > PCIBIOS_MIN_IO))
1da177e4
LT
46/*
47 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
48 * the io ports if they really know they can use it, while
cd090eed 49 * still preventing hotplug PCI devices from using it.
1da177e4 50 */
f4d2e2d8
LB
51
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 */
4be44fcd 57static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
1da177e4
LT
58{
59 struct resource *requested_res = NULL;
60
1da177e4 61
50eca3eb 62 if (res->type == ACPI_RESOURCE_TYPE_IO) {
1da177e4
LT
63 struct acpi_resource_io *io_res = &res->data.io;
64
50eca3eb 65 if (io_res->minimum != io_res->maximum)
d550d98d 66 return AE_OK;
4be44fcd 67 if (IS_RESERVED_ADDR
50eca3eb 68 (io_res->minimum, io_res->address_length)) {
4be44fcd
LB
69 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
70 "Motherboard resources 0x%08x - 0x%08x\n",
50eca3eb
BM
71 io_res->minimum,
72 io_res->minimum +
73 io_res->address_length));
4be44fcd 74 requested_res =
50eca3eb
BM
75 request_region(io_res->minimum,
76 io_res->address_length, "motherboard");
1da177e4 77 }
50eca3eb 78 } else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
4be44fcd
LB
79 struct acpi_resource_fixed_io *fixed_io_res =
80 &res->data.fixed_io;
81
82 if (IS_RESERVED_ADDR
50eca3eb 83 (fixed_io_res->address, fixed_io_res->address_length)) {
4be44fcd
LB
84 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
85 "Motherboard resources 0x%08x - 0x%08x\n",
50eca3eb
BM
86 fixed_io_res->address,
87 fixed_io_res->address +
88 fixed_io_res->address_length));
4be44fcd 89 requested_res =
50eca3eb
BM
90 request_region(fixed_io_res->address,
91 fixed_io_res->address_length,
4be44fcd 92 "motherboard");
1da177e4
LT
93 }
94 } else {
95 /* Memory mapped IO? */
96 }
97
98 if (requested_res)
99 requested_res->flags &= ~IORESOURCE_BUSY;
d550d98d 100 return AE_OK;
1da177e4
LT
101}
102
4be44fcd 103static int acpi_motherboard_add(struct acpi_device *device)
1da177e4
LT
104{
105 if (!device)
106 return -EINVAL;
4be44fcd
LB
107 acpi_walk_resources(device->handle, METHOD_NAME__CRS,
108 acpi_reserve_io_ranges, NULL);
1da177e4
LT
109
110 return 0;
111}
112
113static struct acpi_driver acpi_motherboard_driver1 = {
4be44fcd
LB
114 .name = "motherboard",
115 .class = "",
116 .ids = ACPI_MB_HID1,
117 .ops = {
118 .add = acpi_motherboard_add,
119 },
1da177e4
LT
120};
121
122static struct acpi_driver acpi_motherboard_driver2 = {
4be44fcd
LB
123 .name = "motherboard",
124 .class = "",
125 .ids = ACPI_MB_HID2,
126 .ops = {
127 .add = acpi_motherboard_add,
128 },
1da177e4
LT
129};
130
81507ea9
BH
131static 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
ad71860a 137 if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
81507ea9 138 request_region(addr->address, length, desc);
ad71860a 139 else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
81507ea9
BH
140 request_mem_region(addr->address, length, desc);
141}
142
4be44fcd 143static void __init acpi_reserve_resources(void)
1da177e4 144{
ad71860a
AS
145 acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block,
146 acpi_gbl_FADT.pm1_event_length, "ACPI PM1a_EVT_BLK");
1da177e4 147
ad71860a
AS
148 acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block,
149 acpi_gbl_FADT.pm1_event_length, "ACPI PM1b_EVT_BLK");
1da177e4 150
ad71860a
AS
151 acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block,
152 acpi_gbl_FADT.pm1_control_length, "ACPI PM1a_CNT_BLK");
1da177e4 153
ad71860a
AS
154 acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block,
155 acpi_gbl_FADT.pm1_control_length, "ACPI PM1b_CNT_BLK");
1da177e4 156
ad71860a
AS
157 if (acpi_gbl_FADT.pm_timer_length == 4)
158 acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
1da177e4 159
ad71860a
AS
160 acpi_request_region(&acpi_gbl_FADT.xpm2_control_block,
161 acpi_gbl_FADT.pm2_control_length, "ACPI PM2_CNT_BLK");
1da177e4
LT
162
163 /* Length of GPE blocks must be a non-negative multiple of 2 */
164
ad71860a
AS
165 if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
166 acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
167 acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
1da177e4 168
ad71860a
AS
169 if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
170 acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
171 acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
1da177e4
LT
172}
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);
cd090eed 178 /*
1da177e4
LT
179 * Guarantee motherboard IO reservation first
180 * This module must run after scan.c
181 */
182 if (!acpi_disabled)
4be44fcd 183 acpi_reserve_resources();
1da177e4
LT
184 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);