aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/tables.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/tables.c')
-rw-r--r--drivers/acpi/tables.c68
1 files changed, 48 insertions, 20 deletions
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 6d5a6cda0734..93b81523a2fe 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
190 } 190 }
191} 191}
192 192
193
194int __init 193int __init
195acpi_table_parse_entries(char *id, 194acpi_parse_entries(char *id, unsigned long table_size,
196 unsigned long table_size, 195 acpi_tbl_entry_handler handler,
197 int entry_id, 196 struct acpi_table_header *table_header,
198 acpi_tbl_entry_handler handler, 197 int entry_id, unsigned int max_entries)
199 unsigned int max_entries)
200{ 198{
201 struct acpi_table_header *table_header = NULL;
202 struct acpi_subtable_header *entry; 199 struct acpi_subtable_header *entry;
203 unsigned int count = 0; 200 int count = 0;
204 unsigned long table_end; 201 unsigned long table_end;
205 acpi_size tbl_size;
206 202
207 if (acpi_disabled) 203 if (acpi_disabled)
208 return -ENODEV; 204 return -ENODEV;
209 205
210 if (!handler) 206 if (!id || !handler)
211 return -EINVAL; 207 return -EINVAL;
212 208
213 if (strncmp(id, ACPI_SIG_MADT, 4) == 0) 209 if (!table_size)
214 acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size); 210 return -EINVAL;
215 else
216 acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
217 211
218 if (!table_header) { 212 if (!table_header) {
219 pr_warn("%4.4s not present\n", id); 213 pr_warn("%4.4s not present\n", id);
@@ -230,9 +224,12 @@ acpi_table_parse_entries(char *id,
230 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) < 224 while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
231 table_end) { 225 table_end) {
232 if (entry->type == entry_id 226 if (entry->type == entry_id
233 && (!max_entries || count++ < max_entries)) 227 && (!max_entries || count < max_entries)) {
234 if (handler(entry, table_end)) 228 if (handler(entry, table_end))
235 goto err; 229 return -EINVAL;
230
231 count++;
232 }
236 233
237 /* 234 /*
238 * If entry->length is 0, break from this loop to avoid 235 * If entry->length is 0, break from this loop to avoid
@@ -240,22 +237,53 @@ acpi_table_parse_entries(char *id,
240 */ 237 */
241 if (entry->length == 0) { 238 if (entry->length == 0) {
242 pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id); 239 pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
243 goto err; 240 return -EINVAL;
244 } 241 }
245 242
246 entry = (struct acpi_subtable_header *) 243 entry = (struct acpi_subtable_header *)
247 ((unsigned long)entry + entry->length); 244 ((unsigned long)entry + entry->length);
248 } 245 }
246
249 if (max_entries && count > max_entries) { 247 if (max_entries && count > max_entries) {
250 pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n", 248 pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
251 id, entry_id, count - max_entries, count); 249 id, entry_id, count - max_entries, count);
252 } 250 }
253 251
254 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
255 return count; 252 return count;
256err: 253}
254
255int __init
256acpi_table_parse_entries(char *id,
257 unsigned long table_size,
258 int entry_id,
259 acpi_tbl_entry_handler handler,
260 unsigned int max_entries)
261{
262 struct acpi_table_header *table_header = NULL;
263 acpi_size tbl_size;
264 int count;
265 u32 instance = 0;
266
267 if (acpi_disabled)
268 return -ENODEV;
269
270 if (!id || !handler)
271 return -EINVAL;
272
273 if (!strncmp(id, ACPI_SIG_MADT, 4))
274 instance = acpi_apic_instance;
275
276 acpi_get_table_with_size(id, instance, &table_header, &tbl_size);
277 if (!table_header) {
278 pr_warn("%4.4s not present\n", id);
279 return -ENODEV;
280 }
281
282 count = acpi_parse_entries(id, table_size, handler, table_header,
283 entry_id, max_entries);
284
257 early_acpi_os_unmap_memory((char *)table_header, tbl_size); 285 early_acpi_os_unmap_memory((char *)table_header, tbl_size);
258 return -EINVAL; 286 return count;
259} 287}
260 288
261int __init 289int __init