tables.c 8.6 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
	case ACPI_MADT_TYPE_IO_APIC:
L
Len Brown 已提交
66
		{
67 68
			struct acpi_madt_io_apic *p =
			    (struct acpi_madt_io_apic *)header;
L
Len Brown 已提交
69 70 71 72
			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 已提交
73 74
		break;

75
	case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
L
Len Brown 已提交
76
		{
77 78
			struct acpi_madt_interrupt_override *p =
			    (struct acpi_madt_interrupt_override *)header;
L
Len Brown 已提交
79 80
			printk(KERN_INFO PREFIX
			       "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n",
81 82 83 84 85
			       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 已提交
86 87
				printk(KERN_INFO PREFIX
				       "INT_SRC_OVR unexpected reserved flags: 0x%x\n",
88 89
				       p->inti_flags  &
					~(ACPI_MADT_POLARITY_MASK | ACPI_MADT_TRIGGER_MASK));
L
Linus Torvalds 已提交
90

L
Len Brown 已提交
91
		}
L
Linus Torvalds 已提交
92 93
		break;

94
	case ACPI_MADT_TYPE_NMI_SOURCE:
L
Len Brown 已提交
95
		{
96 97
			struct acpi_madt_nmi_source *p =
			    (struct acpi_madt_nmi_source *)header;
L
Len Brown 已提交
98 99
			printk(KERN_INFO PREFIX
			       "NMI_SRC (%s %s global_irq %d)\n",
100 101
			       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 已提交
102 103
			       p->global_irq);
		}
L
Linus Torvalds 已提交
104 105
		break;

106
	case ACPI_MADT_TYPE_LOCAL_APIC_NMI:
L
Len Brown 已提交
107
		{
108 109
			struct acpi_madt_local_apic_nmi *p =
			    (struct acpi_madt_local_apic_nmi *)header;
L
Len Brown 已提交
110 111
			printk(KERN_INFO PREFIX
			       "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n",
112 113 114
			       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 已提交
115 116
			       p->lint);
		}
L
Linus Torvalds 已提交
117 118
		break;

119
	case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
L
Len Brown 已提交
120
		{
121 122
			struct acpi_madt_local_apic_override *p =
			    (struct acpi_madt_local_apic_override *)header;
L
Len Brown 已提交
123 124 125 126
			printk(KERN_INFO PREFIX
			       "LAPIC_ADDR_OVR (address[%p])\n",
			       (void *)(unsigned long)p->address);
		}
L
Linus Torvalds 已提交
127 128
		break;

129
	case ACPI_MADT_TYPE_IO_SAPIC:
L
Len Brown 已提交
130
		{
131 132
			struct acpi_madt_io_sapic *p =
			    (struct acpi_madt_io_sapic *)header;
L
Len Brown 已提交
133 134 135 136 137
			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 已提交
138 139
		break;

140
	case ACPI_MADT_TYPE_LOCAL_SAPIC:
L
Len Brown 已提交
141
		{
142 143
			struct acpi_madt_local_sapic *p =
			    (struct acpi_madt_local_sapic *)header;
L
Len Brown 已提交
144 145
			printk(KERN_INFO PREFIX
			       "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n",
146 147
			       p->processor_id, p->id, p->eid,
			       (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
L
Len Brown 已提交
148
		}
L
Linus Torvalds 已提交
149 150
		break;

151
	case ACPI_MADT_TYPE_INTERRUPT_SOURCE:
L
Len Brown 已提交
152
		{
153 154
			struct acpi_madt_interrupt_source *p =
			    (struct acpi_madt_interrupt_source *)header;
L
Len Brown 已提交
155 156
			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",
157 158 159
			       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 已提交
160 161
			       p->global_irq);
		}
L
Linus Torvalds 已提交
162 163 164
		break;

	default:
L
Len Brown 已提交
165 166 167
		printk(KERN_WARNING PREFIX
		       "Found unsupported MADT entry (type = 0x%x)\n",
		       header->type);
L
Linus Torvalds 已提交
168 169 170 171 172 173
		break;
	}
}


int __init
174 175
acpi_table_parse_entries(char *id,
			     unsigned long table_size,
L
Len Brown 已提交
176
			     int entry_id,
177
			     acpi_table_entry_handler handler,
L
Len Brown 已提交
178
			     unsigned int max_entries)
L
Linus Torvalds 已提交
179
{
180
	struct acpi_table_header *table_header = NULL;
181
	struct acpi_subtable_header *entry;
L
Len Brown 已提交
182
	unsigned int count = 0;
183
	unsigned long table_end;
L
Linus Torvalds 已提交
184 185 186 187

	if (!handler)
		return -EINVAL;

L
Len Brown 已提交
188 189 190 191
	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
		acpi_get_table(id, acpi_apic_instance, &table_header);
	else
		acpi_get_table(id, 0, &table_header);
L
Linus Torvalds 已提交
192

193
	if (!table_header) {
194
		printk(KERN_WARNING PREFIX "%4.4s not present\n", id);
L
Linus Torvalds 已提交
195 196 197
		return -ENODEV;
	}

198
	table_end = (unsigned long)table_header + table_header->length;
L
Linus Torvalds 已提交
199 200 201

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

202
	entry = (struct acpi_subtable_header *)
203
	    ((unsigned long)table_header + table_size);
L
Linus Torvalds 已提交
204

205
	while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
206
	       table_end) {
L
Len Brown 已提交
207 208
		if (entry->type == entry_id
		    && (!max_entries || count++ < max_entries))
209
			if (handler(entry, table_end))
L
Linus Torvalds 已提交
210 211
				return -EINVAL;

212
		entry = (struct acpi_subtable_header *)
L
Len Brown 已提交
213
		    ((unsigned long)entry + entry->length);
L
Linus Torvalds 已提交
214 215
	}
	if (max_entries && count > max_entries) {
216 217
		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 已提交
218 219 220 221 222 223
	}

	return count;
}

int __init
224
acpi_table_parse_madt(enum acpi_madt_type id,
225
		      acpi_table_entry_handler handler, unsigned int max_entries)
L
Linus Torvalds 已提交
226
{
227
	return acpi_table_parse_entries(ACPI_SIG_MADT,
L
Len Brown 已提交
228 229
					    sizeof(struct acpi_table_madt), id,
					    handler, max_entries);
L
Linus Torvalds 已提交
230 231
}

232 233 234 235 236 237 238 239 240
/**
 * 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.
 */
241
int __init acpi_table_parse(char *id, acpi_table_handler handler)
L
Linus Torvalds 已提交
242
{
243
	struct acpi_table_header *table = NULL;
L
Len Brown 已提交
244

L
Linus Torvalds 已提交
245 246 247
	if (!handler)
		return -EINVAL;

L
Len Brown 已提交
248 249 250 251 252
	if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
		acpi_get_table(id, acpi_apic_instance, &table);
	else
		acpi_get_table(id, 0, &table);

253 254 255
	if (table) {
		handler(table);
		return 0;
256 257
	} else
		return 1;
L
Linus Torvalds 已提交
258 259
}

L
Len Brown 已提交
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
/* 
 * 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;

	acpi_get_table(ACPI_SIG_MADT, 2, &table);
	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);

	} else
		acpi_apic_instance = 0;

	return;
}

L
Linus Torvalds 已提交
285 286 287 288 289
/*
 * acpi_table_init()
 *
 * find RSDP, find and checksum SDT/XSDT.
 * checksum all tables, print SDT/XSDT
290
 *
L
Linus Torvalds 已提交
291 292 293
 * result: sdt_entry[] is initialized
 */

L
Len Brown 已提交
294
int __init acpi_table_init(void)
L
Linus Torvalds 已提交
295
{
296
	acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
L
Len Brown 已提交
297 298 299 300 301 302
	check_multiple_madt();
	return 0;
}

static int __init acpi_parse_apic_instance(char *str)
{
303 304
	if (!str)
		return -EINVAL;
L
Len Brown 已提交
305 306 307 308 309 310

	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 已提交
311 312
	return 0;
}
L
Len Brown 已提交
313 314

early_param("acpi_apic_instance", acpi_parse_apic_instance);