summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/motherboard.c
blob: 8f13b4f3e906a23b9042d67b22a7deccdb77869c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* 
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or (at
 *  your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

/* Purpose: Prevent PCMCIA cards from using motherboard resources. */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/pci.h>
#include <linux/ioport.h>
#include <asm/io.h>

#include <acpi/acpi_bus.h>
#include <acpi/acpi_drivers.h>

#define _COMPONENT		ACPI_SYSTEM_COMPONENT
ACPI_MODULE_NAME("acpi_motherboard")

/* Dell use PNP0C01 instead of PNP0C02 */
#define ACPI_MB_HID			"PNP0C01,PNP0C02"
/**
 * Doesn't care about legacy IO ports, only IO ports beyond 0x1000 are reserved
 * Doesn't care about the failure of 'request_region', since other may reserve
 * the io ports as well
 */
#define IS_RESERVED_ADDR(base, len) \
	(((len) > 0) && ((base) > 0) && ((base) + (len) < IO_SPACE_LIMIT) \
	&& ((base) + (len) > PCIBIOS_MIN_IO))
/*
 * Clearing the flag (IORESOURCE_BUSY) allows drivers to use
 * the io ports if they really know they can use it, while
 * still preventing hotplug PCI devices from using it.
 */

/*
 * When CONFIG_PNP is enabled, pnp/system.c binds to PNP0C01
 * and PNP0C02, redundant with acpi_reserve_io_ranges().
 * But acpi_reserve_io_ranges() is necessary for !CONFIG_PNP.
 */
static acpi_status acpi_reserve_io_ranges(struct acpi_resource *res, void *data)
{
	struct resource *requested_res = NULL;


	if (res->type == ACPI_RESOURCE_TYPE_IO) {
		struct acpi_resource_io *io_res = &res->data.io;

		if (io_res->minimum != io_res->maximum)
			return AE_OK;
		if (IS_RESERVED_ADDR
		    (io_res->minimum, io_res->address_length)) {
			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
					  "Motherboard resources 0x%08x - 0x%08x\n",
					  io_res->minimum,
					  io_res->minimum +
					  io_res->address_length));
			requested_res =
			    request_region(io_res->minimum,
					   io_res->address_length, "motherboard");
		}
	} else if (res->type == ACPI_RESOURCE_TYPE_FIXED_IO) {
		struct acpi_resource_fixed_io *fixed_io_res =
		    &res->data.fixed_io;

		if (IS_RESERVED_ADDR
		    (fixed_io_res->address, fixed_io_res->address_length)) {
			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
					  "Motherboard resources 0x%08x - 0x%08x\n",
					  fixed_io_res->address,
					  fixed_io_res->address +
					  fixed_io_res->address_length));
			requested_res =
			    request_region(fixed_io_res->address,
					   fixed_io_res->address_length,
					   "motherboard");
		}
	} else {
		/* Memory mapped IO? */
	}

	if (requested_res)
		requested_res->flags &= ~IORESOURCE_BUSY;
	return AE_OK;
}

static int acpi_motherboard_add(struct acpi_device *device)
{
	if (!device)
		return -EINVAL;
	acpi_walk_resources(device->handle, METHOD_NAME__CRS,
			    acpi_reserve_io_ranges, NULL);

	return 0;
}

static struct acpi_driver acpi_motherboard_driver = {
	.name = "motherboard",
	.class = "",
	.ids = ACPI_MB_HID,
	.ops = {
		.add = acpi_motherboard_add,
		},
};

static void __init acpi_request_region (struct acpi_generic_address *addr,
	unsigned int length, char *desc)
{
	if (!addr->address || !length)
		return;

	if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
		request_region(addr->address, length, desc);
	else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
		request_mem_region(addr->address, length, desc);
}

static void __init acpi_reserve_resources(void)
{
	acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block,
			       acpi_gbl_FADT.pm1_event_length, "ACPI PM1a_EVT_BLK");

	acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block,
			       acpi_gbl_FADT.pm1_event_length, "ACPI PM1b_EVT_BLK");

	acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block,
			       acpi_gbl_FADT.pm1_control_length, "ACPI PM1a_CNT_BLK");

	acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block,
			       acpi_gbl_FADT.pm1_control_length, "ACPI PM1b_CNT_BLK");

	if (acpi_gbl_FADT.pm_timer_length == 4)
		acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");

	acpi_request_region(&acpi_gbl_FADT.xpm2_control_block,
			       acpi_gbl_FADT.pm2_control_length, "ACPI PM2_CNT_BLK");

	/* Length of GPE blocks must be a non-negative multiple of 2 */

	if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
		acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
			       acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");

	if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
		acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
			       acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
}

static int __init acpi_motherboard_init(void)
{
	acpi_bus_register_driver(&acpi_motherboard_driver);
	/*
	 * Guarantee motherboard IO reservation first
	 * This module must run after scan.c
	 */
	if (!acpi_disabled)
		acpi_reserve_resources();
	return 0;
}

/**
 * Reserve motherboard resources after PCI claim BARs,
 * but before PCI assign resources for uninitialized PCI devices
 */
fs_initcall(acpi_motherboard_init);