ACPI / table: Add new function to get table entries
PATCH 1/2 ACPI / table: Add new function to get table entries
From: Ashwin Chaugule <[email protected]>
The acpi_table_parse() function has a callback that passes a pointer to a table_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as in acpi_table_parse_madt() which is normally called after acpi_table_parse().
--- drivers/acpi/tables.c | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-)
drivers/acpi/tables.c +44 -19
@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } } -int __init -acpi_table_parse_entries (char *id, -unsigned long table_size, -int entry_id, -acpi_tbl_entry_handler handler, -unsigned int max_entries) +acpi_parse_entries (char *id,unsigned long table_size, +acpi_tbl_entry_handler handler, +struct acpi_table_header *table_header, +int entry_id,unsigned int max_entries) { -struct acpi_table_header *table_header =NULL ;struct acpi_subtable_header *entry; -unsigned int count =0 ; +int count =0 ;unsigned long table_end; -acpi_size tbl_size;if (acpi_disabled)return -ENODEV ; -if (!handler) +if (!id || !handler)return -EINVAL ; -if (strncmp (id,ACPI_SIG_MADT ,4 ) ==0 ) -acpi_get_table_with_size (id, acpi_apic_instance, &table_header, &tbl_size); -else -acpi_get_table_with_size (id,0 , &table_header, &tbl_size); +if (!table_size) +return -EINVAL ;if (!table_header) {pr_warn ("%4.4s not present\n" , id);
@@ -232,7 +226,7 @@ acpi_table_parse_entries(char *id,if (entry->type == entry_id && (!max_entries || count++ < max_entries))if (handler (entry, table_end)) - goto err; +return -EINVAL ;/* * If entry->length is 0, break from this loop to avoid
@@ -240,22 +234,53 @@ acpi_table_parse_entries(char *id,*/ if (entry->length ==0 ) {pr_err ("[%4.4s:0x%02x] Invalid zero length\n" , id, entry_id); - goto err; +return -EINVAL ; } entry = (struct acpi_subtable_header *) ((unsigned long )entry + entry->length); } +if (max_entries && count > max_entries) {pr_warn ("[%4.4s:0x%02x] ignored %i entries of %i found\n" , id, entry_id, count - max_entries, count); } -early_acpi_os_unmap_memory ((char *)table_header, tbl_size);return count; -err: +} + +int __init +acpi_table_parse_entries (char *id, +unsigned long table_size, +int entry_id, +acpi_tbl_entry_handler handler, +unsigned int max_entries) +{ +struct acpi_table_header *table_header =NULL ; +acpi_size tbl_size; +int count; +u32 instance =0 ; + +if (acpi_disabled) +return -ENODEV ; + +if (!id || !handler) +return -EINVAL ; + +if (!strncmp (id,ACPI_SIG_MADT ,4 )) + instance = acpi_apic_instance; + +acpi_get_table_with_size (id, instance, &table_header, &tbl_size); +if (!table_header) { +pr_warn ("%4.4s not present\n" , id); +return -ENODEV ; + } + + count =acpi_parse_entries (id, table_size, handler, table_header, + entry_id, max_entries); +early_acpi_os_unmap_memory ((char *)table_header, tbl_size); -return -EINVAL ; +return count; }int __init
include/linux/acpi.h +4 -0
@@ -124,6 +124,10 @@ int acpi_numa_init (void);int acpi_table_init (void );int acpi_table_parse (char *id,acpi_tbl_table_handler handler); +int __init acpi_parse_entries (char *id,unsigned long table_size, +acpi_tbl_entry_handler handler, +struct acpi_table_header *table_header, +int entry_id,unsigned int max_entries); int __init acpi_table_parse_entries(char *id, unsigned long table_size, int entry_id, acpi_tbl_entry_handler handler,
Signature · 1 line
1.9.1
PATCH 2/2 ACPI / table: Count matched and successfully parsed entries without specifying max entries
From: Tomasz Nowicki <[email protected]>
acpi_parse_entries() allows to traverse all available table entries (aka subtables) by passing max_entries parameter equal to 0, but since its count variable is only incremented if max_entries is not 0, the function always returns 0 for max_entries equal to 0. It would be more useful if it returned the number of entries matched instead, so make it increment count in that case too.
--- drivers/acpi/tables.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/acpi/tables.c +4 -1
@@ -224,10 +224,13 @@ acpi_parse_entries(char *id, unsigned long table_size,while (((unsigned long )entry) +sizeof (struct acpi_subtable_header ) < table_end) {if (entry->type == entry_id - && (!max_entries || count++ < max_entries)) + && (!max_entries || count < max_entries)) {if (handler (entry, table_end))return -EINVAL ; + count++; + } +/* * If entry->length is 0, break from this loop to avoid * infinite loop.
Signature · 1 line
1.9.1
Quoted 24 lines · Hanjun Guo
From: Ashwin Chaugule <[email protected]>
The
acpi_table_parse()function has a callback that passes a pointer to atable_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as inacpi_table_parse_madt()which is normally called afteracpi_table_parse().Acked-by Grant Likely <[email protected]>Signed-off-by Ashwin Chaugule <[email protected]>Signed-off-by Tomasz Nowicki <[email protected]>Signed-off-by Hanjun Guo <[email protected]>--- drivers/acpi/tables.c | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-)drivers/acpi/tables.c +0
-0@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) }
drivers/acpi/tables.c void acpi_table_print_madt_entry(struct acpi_subtable_header *header) · line 194
Quoted 10 lines
drivers/acpi/tables.c +1
-6} - int __init -acpi_table_parse_entries (char *id, -unsigned long table_size, -int entry_id, -acpi_tbl_entry_handler handler, -unsigned int max_entries) +acpi_parse_entries(char *id, unsigned long table_size,
Why isn't this static? Are you going to use it somewhere else?
Quoted 110 lines
drivers/acpi/tables.c +43
-13+acpi_tbl_entry_handler handler, + struct acpi_table_header *table_header, + int entry_id, unsigned int max_entries) { -struct acpi_table_header *table_header =NULL ; struct acpi_subtable_header *entry; -unsigned int count =0 ; +int count =0 ;unsigned long table_end; -acpi_size tbl_size;if (acpi_disabled)return -ENODEV ; -if (!handler) +if (!id || !handler)return -EINVAL ; -if (strncmp (id,ACPI_SIG_MADT ,4 ) ==0 ) -acpi_get_table_with_size (id, acpi_apic_instance, &table_header, &tbl_size); -else -acpi_get_table_with_size (id,0 , &table_header, &tbl_size); +if (!table_size) +return -EINVAL ;if (!table_header) {pr_warn ("%4.4s not present\n" , id);@@ -232,7 +226,7 @@ acpi_table_parse_entries(char *id,if (entry->type == entry_id && (!max_entries || count++ < max_entries))if (handler (entry, table_end)) - goto err; +return -EINVAL ;/* * If entry->length is 0, break from this loop to avoid @@ -240,22 +234,53 @@ acpi_table_parse_entries(char *id,*/ if (entry->length ==0 ) {pr_err ("[%4.4s:0x%02x] Invalid zero length\n" , id, entry_id); - goto err; +return -EINVAL ; } entry = (struct acpi_subtable_header *) ((unsigned long )entry + entry->length); } +if (max_entries && count > max_entries) {pr_warn ("[%4.4s:0x%02x] ignored %i entries of %i found\n" , id, entry_id, count - max_entries, count); } -early_acpi_os_unmap_memory ((char *)table_header, tbl_size);return count; -err: +} + +int __init +acpi_table_parse_entries (char *id, +unsigned long table_size, +int entry_id, +acpi_tbl_entry_handler handler, +unsigned int max_entries) +{ +struct acpi_table_header *table_header =NULL ; +acpi_size tbl_size; +int count; +u32 instance =0 ; + +if (acpi_disabled) +return -ENODEV ; + +if (!id || !handler) +return -EINVAL ; + +if (!strncmp (id,ACPI_SIG_MADT ,4 )) + instance = acpi_apic_instance; + +acpi_get_table_with_size (id, instance, &table_header, &tbl_size); +if (!table_header) { +pr_warn ("%4.4s not present\n" , id); +return -ENODEV ; + } + + count =acpi_parse_entries (id, table_size, handler, table_header, + entry_id, max_entries); +early_acpi_os_unmap_memory ((char *)table_header, tbl_size); -return -EINVAL ; +return count; }int __init include/linux/acpi.h +4
-0@@ -124,6 +124,10 @@ int acpi_numa_init (void);int acpi_table_init (void );int acpi_table_parse (char *id,acpi_tbl_table_handler handler); +int __init acpi_parse_entries (char *id,unsigned long table_size, +acpi_tbl_entry_handler handler, +struct acpi_table_header *table_header, +int entry_id,unsigned int max_entries); int __init acpi_table_parse_entries(char *id, unsigned long table_size, int entry_id, acpi_tbl_entry_handler handler,
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Hanjun Guo
From: Ashwin Chaugule <[email protected]>
The
acpi_table_parse()function has a callback that passes a pointer to atable_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as inacpi_table_parse_madt()which is normally called afteracpi_table_parse().Acked-by Grant Likely <[email protected]>Signed-off-by Ashwin Chaugule <[email protected]>Signed-off-by Tomasz Nowicki <[email protected]>Signed-off-by Hanjun Guo <[email protected]>--- drivers/acpi/tables.c | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-)drivers/acpi/tables.c +0
-0@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } }
Quoted 10 lines
drivers/acpi/tables.c void acpi_table_print_madt_entry(struct acpi_subtable_header *header) · line 194
Quoted 8 lines
drivers/acpi/tables.c +1
-6- int __init -acpi_table_parse_entries (char *id, -unsigned long table_size, -int entry_id, -acpi_tbl_entry_handler handler, -unsigned int max_entries) +acpi_parse_entries(char *id, unsigned long table_size,Why isn't this static? Are you going to use it somewhere else?
Yes, we will use it in the following patches to parse entries in static ACPI tables.
Thanks
Hanjun
Quoted 39 lines · Hanjun Guo
Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Hanjun Guo
From: Ashwin Chaugule <[email protected]>
The
acpi_table_parse()function has a callback that passes a pointer to atable_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as inacpi_table_parse_madt()which is normally called afteracpi_table_parse().Acked-by Grant Likely <[email protected]>Signed-off-by Ashwin Chaugule <[email protected]>Signed-off-by Tomasz Nowicki <[email protected]>Signed-off-by Hanjun Guo <[email protected]>--- drivers/acpi/tables.c | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-)drivers/acpi/tables.c +0
-0@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) } }Quoted 10 lines
drivers/acpi/tables.c void acpi_table_print_madt_entry(struct acpi_subtable_header *header) · line 194
Quoted 8 lines
drivers/acpi/tables.c +1
-6- int __init -acpi_table_parse_entries (char *id, -unsigned long table_size, -int entry_id, -acpi_tbl_entry_handler handler, -unsigned int max_entries) +acpi_parse_entries(char *id, unsigned long table_size,Why isn't this static? Are you going to use it somewhere else?
Quoted 2 lines
Yes, we will use it in the following patches to parse entries in static ACPI tables.
OK, thanks!
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
Quoted 40 lines · Rafael J. Wysocki
Quoted 39 lines · Hanjun Guo
Quoted 37 lines · Rafael J. Wysocki
Quoted 24 lines · Hanjun Guo
From: Ashwin Chaugule <[email protected]>
The
acpi_table_parse()function has a callback that passes a pointer to atable_header. Add a new function which takes this pointer and parses its entries. This eliminates the need to re-traverse all the tables for each call. e.g. as inacpi_table_parse_madt()which is normally called afteracpi_table_parse().Acked-by Grant Likely <[email protected]>Signed-off-by Ashwin Chaugule <[email protected]>Signed-off-by Tomasz Nowicki <[email protected]>Signed-off-by Hanjun Guo <[email protected]>--- drivers/acpi/tables.c | 63 +++++++++++++++++++++++++++++++++++---------------- include/linux/acpi.h | 4 ++++ 2 files changed, 48 insertions(+), 19 deletions(-)drivers/acpi/tables.c +0
-0@@ -190,30 +190,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header) }drivers/acpi/tables.c void acpi_table_print_madt_entry(struct acpi_subtable_header *header) · line 194
Quoted 10 lines
drivers/acpi/tables.c +1
-6} - int __init -acpi_table_parse_entries (char *id, -unsigned long table_size, -int entry_id, -acpi_tbl_entry_handler handler, -unsigned int max_entries) +acpi_parse_entries(char *id, unsigned long table_size,Why isn't this static? Are you going to use it somewhere else?
Quoted 4 lines
Quoted 2 lines
Yes, we will use it in the following patches to parse entries in static ACPI tables.
OK, thanks!
Both queued up for 3.19-rc1, thanks!
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.