Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi_tables.c - ACPI Boot-Time Table Parsing |
| 3 | * |
| 4 | * Copyright (C) 2001 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 5 | * |
| 6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 23 | * |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/sched.h> |
| 29 | #include <linux/smp.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/irq.h> |
| 33 | #include <linux/errno.h> |
| 34 | #include <linux/acpi.h> |
| 35 | #include <linux/bootmem.h> |
| 36 | |
| 37 | #define PREFIX "ACPI: " |
| 38 | |
Len Brown | 04348e6 | 2005-12-30 02:44:59 -0500 | [diff] [blame] | 39 | #define ACPI_MAX_TABLES 128 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | static char *mps_inti_flags_polarity[] = { "dfl", "high", "res", "low" }; |
| 42 | static char *mps_inti_flags_trigger[] = { "dfl", "edge", "res", "level" }; |
| 43 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 44 | static struct acpi_table_desc initial_tables[ACPI_MAX_TABLES] __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 46 | void acpi_table_print_madt_entry(acpi_table_entry_header * header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | if (!header) |
| 49 | return; |
| 50 | |
| 51 | switch (header->type) { |
| 52 | |
| 53 | case ACPI_MADT_LAPIC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | { |
| 55 | struct acpi_table_lapic *p = |
| 56 | (struct acpi_table_lapic *)header; |
| 57 | printk(KERN_INFO PREFIX |
| 58 | "LAPIC (acpi_id[0x%02x] lapic_id[0x%02x] %s)\n", |
| 59 | p->acpi_id, p->id, |
| 60 | p->flags.enabled ? "enabled" : "disabled"); |
| 61 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | break; |
| 63 | |
| 64 | case ACPI_MADT_IOAPIC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | { |
| 66 | struct acpi_table_ioapic *p = |
| 67 | (struct acpi_table_ioapic *)header; |
| 68 | printk(KERN_INFO PREFIX |
| 69 | "IOAPIC (id[0x%02x] address[0x%08x] gsi_base[%d])\n", |
| 70 | p->id, p->address, p->global_irq_base); |
| 71 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | break; |
| 73 | |
| 74 | case ACPI_MADT_INT_SRC_OVR: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | { |
| 76 | struct acpi_table_int_src_ovr *p = |
| 77 | (struct acpi_table_int_src_ovr *)header; |
| 78 | printk(KERN_INFO PREFIX |
| 79 | "INT_SRC_OVR (bus %d bus_irq %d global_irq %d %s %s)\n", |
| 80 | p->bus, p->bus_irq, p->global_irq, |
| 81 | mps_inti_flags_polarity[p->flags.polarity], |
| 82 | mps_inti_flags_trigger[p->flags.trigger]); |
| 83 | if (p->flags.reserved) |
| 84 | printk(KERN_INFO PREFIX |
| 85 | "INT_SRC_OVR unexpected reserved flags: 0x%x\n", |
| 86 | p->flags.reserved); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | break; |
| 90 | |
| 91 | case ACPI_MADT_NMI_SRC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | { |
| 93 | struct acpi_table_nmi_src *p = |
| 94 | (struct acpi_table_nmi_src *)header; |
| 95 | printk(KERN_INFO PREFIX |
| 96 | "NMI_SRC (%s %s global_irq %d)\n", |
| 97 | mps_inti_flags_polarity[p->flags.polarity], |
| 98 | mps_inti_flags_trigger[p->flags.trigger], |
| 99 | p->global_irq); |
| 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | break; |
| 102 | |
| 103 | case ACPI_MADT_LAPIC_NMI: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | { |
| 105 | struct acpi_table_lapic_nmi *p = |
| 106 | (struct acpi_table_lapic_nmi *)header; |
| 107 | printk(KERN_INFO PREFIX |
| 108 | "LAPIC_NMI (acpi_id[0x%02x] %s %s lint[0x%x])\n", |
| 109 | p->acpi_id, |
| 110 | mps_inti_flags_polarity[p->flags.polarity], |
| 111 | mps_inti_flags_trigger[p->flags.trigger], |
| 112 | p->lint); |
| 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | break; |
| 115 | |
| 116 | case ACPI_MADT_LAPIC_ADDR_OVR: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | { |
| 118 | struct acpi_table_lapic_addr_ovr *p = |
| 119 | (struct acpi_table_lapic_addr_ovr *)header; |
| 120 | printk(KERN_INFO PREFIX |
| 121 | "LAPIC_ADDR_OVR (address[%p])\n", |
| 122 | (void *)(unsigned long)p->address); |
| 123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | break; |
| 125 | |
| 126 | case ACPI_MADT_IOSAPIC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | { |
| 128 | struct acpi_table_iosapic *p = |
| 129 | (struct acpi_table_iosapic *)header; |
| 130 | printk(KERN_INFO PREFIX |
| 131 | "IOSAPIC (id[0x%x] address[%p] gsi_base[%d])\n", |
| 132 | p->id, (void *)(unsigned long)p->address, |
| 133 | p->global_irq_base); |
| 134 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | break; |
| 136 | |
| 137 | case ACPI_MADT_LSAPIC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | { |
| 139 | struct acpi_table_lsapic *p = |
| 140 | (struct acpi_table_lsapic *)header; |
| 141 | printk(KERN_INFO PREFIX |
| 142 | "LSAPIC (acpi_id[0x%02x] lsapic_id[0x%02x] lsapic_eid[0x%02x] %s)\n", |
| 143 | p->acpi_id, p->id, p->eid, |
| 144 | p->flags.enabled ? "enabled" : "disabled"); |
| 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | break; |
| 147 | |
| 148 | case ACPI_MADT_PLAT_INT_SRC: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | { |
| 150 | struct acpi_table_plat_int_src *p = |
| 151 | (struct acpi_table_plat_int_src *)header; |
| 152 | printk(KERN_INFO PREFIX |
| 153 | "PLAT_INT_SRC (%s %s type[0x%x] id[0x%04x] eid[0x%x] iosapic_vector[0x%x] global_irq[0x%x]\n", |
| 154 | mps_inti_flags_polarity[p->flags.polarity], |
| 155 | mps_inti_flags_trigger[p->flags.trigger], |
| 156 | p->type, p->id, p->eid, p->iosapic_vector, |
| 157 | p->global_irq); |
| 158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | break; |
| 160 | |
| 161 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | printk(KERN_WARNING PREFIX |
| 163 | "Found unsupported MADT entry (type = 0x%x)\n", |
| 164 | header->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | break; |
| 166 | } |
| 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | int __init |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 171 | acpi_table_parse_madt_family(char *id, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | unsigned long madt_size, |
| 173 | int entry_id, |
| 174 | acpi_madt_entry_handler handler, |
| 175 | unsigned int max_entries) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 177 | struct acpi_table_header *madt = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | acpi_table_entry_header *entry; |
| 179 | unsigned int count = 0; |
| 180 | unsigned long madt_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (!handler) |
| 183 | return -EINVAL; |
| 184 | |
| 185 | /* Locate the MADT (if exists). There should only be one. */ |
| 186 | |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 187 | acpi_get_table(id, 0, &madt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | if (!madt) { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 190 | printk(KERN_WARNING PREFIX "%4.4s not present\n", id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | return -ENODEV; |
| 192 | } |
| 193 | |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 194 | madt_end = (unsigned long)madt + madt->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | /* Parse all entries looking for a match. */ |
| 197 | |
| 198 | entry = (acpi_table_entry_header *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | ((unsigned long)madt + madt_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | while (((unsigned long)entry) + sizeof(acpi_table_entry_header) < |
| 202 | madt_end) { |
| 203 | if (entry->type == entry_id |
| 204 | && (!max_entries || count++ < max_entries)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (handler(entry, madt_end)) |
| 206 | return -EINVAL; |
| 207 | |
| 208 | entry = (acpi_table_entry_header *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | ((unsigned long)entry + entry->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | if (max_entries && count > max_entries) { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 212 | printk(KERN_WARNING PREFIX "[%4.4s:0x%02x] ignored %i entries of " |
| 213 | "%i found\n", id, entry_id, count - max_entries, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | return count; |
| 217 | } |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | int __init |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | acpi_table_parse_madt(enum acpi_madt_entry_id id, |
| 221 | acpi_madt_entry_handler handler, unsigned int max_entries) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 223 | return acpi_table_parse_madt_family("APIC", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | sizeof(struct acpi_table_madt), id, |
| 225 | handler, max_entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 228 | int __init acpi_table_parse(char *id, acpi_table_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 230 | struct acpi_table_header *table = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | if (!handler) |
| 233 | return -EINVAL; |
| 234 | |
Alexey Starikovskiy | ceb6c46 | 2007-02-02 19:48:22 +0300 | [diff] [blame^] | 235 | acpi_get_table(id, 0, &table); |
| 236 | if (table) { |
| 237 | handler(table); |
| 238 | return 1; |
| 239 | } else |
| 240 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* |
| 244 | * acpi_table_init() |
| 245 | * |
| 246 | * find RSDP, find and checksum SDT/XSDT. |
| 247 | * checksum all tables, print SDT/XSDT |
| 248 | * |
| 249 | * result: sdt_entry[] is initialized |
| 250 | */ |
| 251 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | int __init acpi_table_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 254 | acpi_initialize_tables(initial_tables, ACPI_MAX_TABLES, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | } |