tables.c 7.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 38
/*
 *  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/sched.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: "

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

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

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

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

	switch (header->type) {

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

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

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

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

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

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

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

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

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

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

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


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

	if (!handler)
		return -EINVAL;

	/* Locate the MADT (if exists). There should only be one. */
188
	acpi_get_table(id, 0, &madt);
L
Linus Torvalds 已提交
189 190

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

195
	madt_end = (unsigned long)madt + madt->length;
L
Linus Torvalds 已提交
196 197 198

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

199
	entry = (struct acpi_subtable_header *)
L
Len Brown 已提交
200
	    ((unsigned long)madt + madt_size);
L
Linus Torvalds 已提交
201

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

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

	return count;
}

int __init
221
acpi_table_parse_madt(enum acpi_madt_type id,
L
Len Brown 已提交
222
		      acpi_madt_entry_handler handler, unsigned int max_entries)
L
Linus Torvalds 已提交
223
{
224
	return acpi_table_parse_madt_family(ACPI_SIG_MADT,
L
Len Brown 已提交
225 226
					    sizeof(struct acpi_table_madt), id,
					    handler, max_entries);
L
Linus Torvalds 已提交
227 228
}

229
int __init acpi_table_parse(char *id, acpi_table_handler handler)
L
Linus Torvalds 已提交
230
{
231
	struct acpi_table_header *table = NULL;
L
Linus Torvalds 已提交
232 233 234
	if (!handler)
		return -EINVAL;

235 236 237 238 239 240
	acpi_get_table(id, 0, &table);
	if (table) {
		handler(table);
		return 1;
	} else
		return 0;
L
Linus Torvalds 已提交
241 242 243 244 245 246 247
}

/*
 * acpi_table_init()
 *
 * find RSDP, find and checksum SDT/XSDT.
 * checksum all tables, print SDT/XSDT
248
 *
L
Linus Torvalds 已提交
249 250 251
 * result: sdt_entry[] is initialized
 */

252

L
Len Brown 已提交
253
int __init acpi_table_init(void)
L
Linus Torvalds 已提交
254
{
255
	acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0);
L
Linus Torvalds 已提交
256 257
	return 0;
}