tables.c 10.2 KB
Newer Older
L
Linus Torvalds 已提交
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
/*
 *  acpi_tables.c - ACPI Boot-Time Table Parsing
 *
 *  Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  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
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/smp.h>
#include <linux/string.h>
#include <linux/types.h>
#include <linux/irq.h>
#include <linux/errno.h>
#include <linux/acpi.h>
#include <linux/bootmem.h>

#define PREFIX			"ACPI: "

38
#define ACPI_MAX_TABLES		128
L
Linus Torvalds 已提交
39 40 41 42

static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" };
static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" };

43
static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata;
L
Linus Torvalds 已提交
44

45
static int acpi_apic_instance __initdata;
L
Len Brown 已提交
46 47

void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
L
Linus Torvalds 已提交
48 49 50 51 52 53
{
	if (!header)
		return;

	switch (header->type) {

54
	case ACPI_MADT_TYPE_LOCAL_APIC:
L
Len Brown 已提交
55
		{
56 57
			struct acpi_madt_local_apic *p =
			    (struct acpi_madt_local_apic *)header;
L
Len Brown 已提交
58 59
			printk(KERN_INFO PREFIX
			       "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n",
60 61
			       p->processor_id, p->id,
			       (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
L
Len Brown 已提交
62
		}
L
Linus Torvalds 已提交
63 64
		break;

65 66 67 68 69 70 71 72 73 74 75 76
	case ACPI_MADT_TYPE_LOCAL_X2APIC:
		{
			struct acpi_madt_local_x2apic *p =
			    (struct acpi_madt_local_x2apic *)header;
			printk(KERN_INFO PREFIX
			       "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
			       p->local_apic_id, p->uid,
			       (p->lapic_flags & ACPI_MADT_ENABLED) ?
			       "enabled" : "disabled");
		}
		break;

77
	case ACPI_MADT_TYPE_IO_APIC:
L
Len Brown 已提交
78
		{
79 80
			struct acpi_madt_io_apic *p =
			    (struct acpi_madt_io_apic *)header;
L
Len Brown 已提交
81 82 83 84
			printk(KERN_INFO PREFIX
			       "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n",
			       p->id, p->address, p->global_irq_base);
		}
L
Linus Torvalds 已提交
85 86
		break;

87
	case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
L
Len Brown 已提交
88
		{
89 90
			struct acpi_madt_interrupt_override *p =
			    (struct acpi_madt_interrupt_override *)header;
L
Len Brown 已提交
91 92
			printk(KERN_INFO PREFIX
			       "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
93 94 95 96 97
			       p->bus, p->source_irq, p->global_irq,
			       mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
			       mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2]);
			if (p->inti_flags  &
			    ~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK))
L
Len Brown 已提交
98 99
				printk(KERN_INFO PREFIX
				       "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
100 101
				       p->inti_flags  &
					~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
L
Linus Torvalds 已提交
102

L
Len Brown 已提交
103
		}
L
Linus Torvalds 已提交
104 105
		break;

106
	case ACPI_MADT_TYPE_NMI_SOURCE:
L
Len Brown 已提交
107
		{
108 109
			struct acpi_madt_nmi_source *p =
			    (struct acpi_madt_nmi_source *)header;
L
Len Brown 已提交
110 111
			printk(KERN_INFO PREFIX
			       "NMI_SRC (%s %s global_irq %d)\n",
112 113
			       mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
			       mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
L
Len Brown 已提交
114 115
			       p->global_irq);
		}
L
Linus Torvalds 已提交
116 117
		break;

118
	case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
L
Len Brown 已提交
119
		{
120 121
			struct acpi_madt_local_apic_nmi *p =
			    (struct acpi_madt_local_apic_nmi *)header;
L
Len Brown 已提交
122 123
			printk(KERN_INFO PREFIX
			       "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
124 125 126
			       p->processor_id,
			       mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK	],
			       mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
L
Len Brown 已提交
127
			       p->lint);
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		}
		break;

	case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
		{
			u16 polarity, trigger;
			struct acpi_madt_local_x2apic_nmi *p =
			    (struct acpi_madt_local_x2apic_nmi *)header;

			polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
			trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;

			printk(KERN_INFO PREFIX
			       "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
			       p->uid,
			       mps_inti_flags_polarity[polarity],
			       mps_inti_flags_trigger[trigger],
			       p->lint);
L
Len Brown 已提交
146
		}
L
Linus Torvalds 已提交
147 148
		break;

149
	case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
L
Len Brown 已提交
150
		{
151 152
			struct acpi_madt_local_apic_override *p =
			    (struct acpi_madt_local_apic_override *)header;
L
Len Brown 已提交
153 154 155 156
			printk(KERN_INFO PREFIX
			       "LAPIC_ADDR_OVR (address[%p])\n",
			       (void *)(unsigned long)p->address);
		}
L
Linus Torvalds 已提交
157 158
		break;

159
	case ACPI_MADT_TYPE_IO_SAPIC:
L
Len Brown 已提交
160
		{
161 162
			struct acpi_madt_io_sapic *p =
			    (struct acpi_madt_io_sapic *)header;
L
Len Brown 已提交
163 164 165 166 167
			printk(KERN_INFO PREFIX
			       "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n",
			       p->id, (void *)(unsigned long)p->address,
			       p->global_irq_base);
		}
L
Linus Torvalds 已提交
168 169
		break;

170
	case ACPI_MADT_TYPE_LOCAL_SAPIC:
L
Len Brown 已提交
171
		{
172 173
			struct acpi_madt_local_sapic *p =
			    (struct acpi_madt_local_sapic *)header;
L
Len Brown 已提交
174 175
			printk(KERN_INFO PREFIX
			       "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
176 177
			       p->processor_id, p->id, p->eid,
			       (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
L
Len Brown 已提交
178
		}
L
Linus Torvalds 已提交
179 180
		break;

181
	case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
L
Len Brown 已提交
182
		{
183 184
			struct acpi_madt_interrupt_source *p =
			    (struct acpi_madt_interrupt_source *)header;
L
Len Brown 已提交
185 186
			printk(KERN_INFO PREFIX
			       "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n",
187 188 189
			       mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK],
			       mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
			       p->type, p->id, p->eid, p->io_sapic_vector,
L
Len Brown 已提交
190 191
			       p->global_irq);
		}
L
Linus Torvalds 已提交
192 193 194
		break;

	default:
L
Len Brown 已提交
195 196 197
		printk(KERN_WARNING PREFIX
		       "Found unsupported MADT entry (type = 0x%x)\n",
		       header->type);
L
Linus Torvalds 已提交
198 199 200 201 202 203
		break;
	}
}


int __init
204 205
acpi_table_parse_entries(char *id,
			     unsigned long table_size,
L
Len Brown 已提交
206
			     int entry_id,
207
			     acpi_table_entry_handler handler,
L
Len Brown 已提交
208
			     unsigned int max_entries)
L
Linus Torvalds 已提交
209
{
210
	struct acpi_table_header *table_header = NULL;
211
	struct acpi_subtable_header *entry;
L
Len Brown 已提交
212
	unsigned int count = 0;
213
	unsigned long table_end;
214
	acpi_size tbl_size;
L
Linus Torvalds 已提交
215

216
	if (acpi_disabled)
217 218
		return -ENODEV;

L
Linus Torvalds 已提交
219 220 221
	if (!handler)
		return -EINVAL;

L
Len Brown 已提交
222
	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
223
		acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
L
Len Brown 已提交
224
	else
225
		acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
L
Linus Torvalds 已提交
226

227
	if (!table_header) {
228
		printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
L
Linus Torvalds 已提交
229 230 231
		return -ENODEV;
	}

232
	table_end = (unsigned long)table_header + table_header->length;
L
Linus Torvalds 已提交
233 234 235

	/* Parse all entries looking for a match. */

236
	entry = (struct acpi_subtable_header *)
237
	    ((unsigned long)table_header + table_size);
L
Linus Torvalds 已提交
238

239
	while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
240
	       table_end) {
L
Len Brown 已提交
241 242
		if (entry->type == entry_id
		    && (!max_entries || count++ < max_entries))
243 244 245 246 247 248 249 250 251 252 253
			if (handler(entry, table_end))
				goto err;

		/*
		 * If entry->length is 0, break from this loop to avoid
		 * infinite loop.
		 */
		if (entry->length == 0) {
			pr_err(PREFIX "[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
			goto err;
		}
L
Linus Torvalds 已提交
254

255
		entry = (struct acpi_subtable_header *)
L
Len Brown 已提交
256
		    ((unsigned long)entry + entry->length);
L
Linus Torvalds 已提交
257 258
	}
	if (max_entries && count > max_entries) {
259 260
		printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of "
		       "%i found\n", id, entry_id, count - max_entries, count);
L
Linus Torvalds 已提交
261 262
	}

263
	early_acpi_os_unmap_memory((char *)table_header, tbl_size);
L
Linus Torvalds 已提交
264
	return count;
265 266 267
err:
	early_acpi_os_unmap_memory((char *)table_header, tbl_size);
	return -EINVAL;
L
Linus Torvalds 已提交
268 269 270
}

int __init
271
acpi_table_parse_madt(enum acpi_madt_type id,
272
		      acpi_table_entry_handler handler, unsigned int max_entries)
L
Linus Torvalds 已提交
273
{
274
	return acpi_table_parse_entries(ACPI_SIG_MADT,
L
Len Brown 已提交
275 276
					    sizeof(struct acpi_table_madt), id,
					    handler, max_entries);
L
Linus Torvalds 已提交
277 278
}

279 280 281 282 283 284 285 286 287
/**
 * acpi_table_parse - find table with @id, run @handler on it
 *
 * @id: table id to find
 * @handler: handler to run
 *
 * Scan the ACPI System Descriptor Table (STD) for a table matching @id,
 * run @handler on it.  Return 0 if table found, return on if not.
 */
288
int __init acpi_table_parse(char *id, acpi_table_handler handler)
L
Linus Torvalds 已提交
289
{
290
	struct acpi_table_header *table = NULL;
291
	acpi_size tbl_size;
L
Len Brown 已提交
292

293
	if (acpi_disabled)
294 295
		return -ENODEV;

L
Linus Torvalds 已提交
296 297 298
	if (!handler)
		return -EINVAL;

L
Len Brown 已提交
299
	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
300
		acpi_get_table_with_size(id, acpi_apic_instance, &table, &tbl_size);
L
Len Brown 已提交
301
	else
302
		acpi_get_table_with_size(id, 0, &table, &tbl_size);
L
Len Brown 已提交
303

304 305
	if (table) {
		handler(table);
306
		early_acpi_os_unmap_memory(table, tbl_size);
307
		return 0;
308 309
	} else
		return 1;
L
Linus Torvalds 已提交
310 311
}

L
Len Brown 已提交
312 313 314 315 316 317 318 319
/* 
 * The BIOS is supposed to supply a single APIC/MADT,
 * but some report two.  Provide a knob to use either.
 * (don't you wish instance 0 and 1 were not the same?)
 */
static void __init check_multiple_madt(void)
{
	struct acpi_table_header *table = NULL;
320
	acpi_size tbl_size;
L
Len Brown 已提交
321

322
	acpi_get_table_with_size(ACPI_SIG_MADT, 2, &table, &tbl_size);
L
Len Brown 已提交
323 324 325 326 327 328 329 330
	if (table) {
		printk(KERN_WARNING PREFIX
		       "BIOS bug: multiple APIC/MADT found,"
		       " using %d\n", acpi_apic_instance);
		printk(KERN_WARNING PREFIX
		       "If \"acpi_apic_instance=%d\" works better, "
		       "notify linux-acpi@vger.kernel.org\n",
		       acpi_apic_instance ? 0 : 2);
331
		early_acpi_os_unmap_memory(table, tbl_size);
L
Len Brown 已提交
332 333 334 335 336 337 338

	} else
		acpi_apic_instance = 0;

	return;
}

L
Linus Torvalds 已提交
339 340 341 342 343
/*
 * acpi_table_init()
 *
 * find RSDP, find and checksum SDT/XSDT.
 * checksum all tables, print SDT/XSDT
344
 *
L
Linus Torvalds 已提交
345 346 347
 * result: sdt_entry[] is initialized
 */

L
Len Brown 已提交
348
int __init acpi_table_init(void)
L
Linus Torvalds 已提交
349
{
350 351 352 353 354 355
	acpi_status status;

	status = acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
	if (ACPI_FAILURE(status))
		return 1;

L
Len Brown 已提交
356 357 358 359 360 361
	check_multiple_madt();
	return 0;
}

static int __init acpi_parse_apic_instance(char *str)
{
362 363
	if (!str)
		return -EINVAL;
L
Len Brown 已提交
364 365 366 367 368 369

	acpi_apic_instance = simple_strtoul(str, NULL, 0);

	printk(KERN_NOTICE PREFIX "Shall use APIC/MADT table %d\n",
	       acpi_apic_instance);

L
Linus Torvalds 已提交
370 371
	return 0;
}
L
Len Brown 已提交
372 373

early_param("acpi_apic_instance", acpi_parse_apic_instance);