ACPI: processor driver vs. core
Subsystems (4)
v2 cover ACPI: processor driver vs. core
Original thread:
http://thread.gmane.org/gmane.linux.kernel/942423
Refreshed against lenb/test (a0eb5a84da383539f11e777bdde5e69a31ed25c7)
Added Venki's Acked-by.
The first patch has lots of legacy checkpatch warnings/errors, and I have another series to clean those up after this series is applied.
Thanks,
/ac
---
Alex Chiang (12):
ACPI: processor: mv processor_core.c processor_driver.c
ACPI: processor: mv processor_pdc.c processor_core.c
ACPI: processor: export acpi_get_cpuid()
ACPI: processor: move acpi_get_cpuid into processor_core.c
ACPI: processor: add internal processor_physically_present()
ACPI: processor: remove early _PDC optin quirks
ACPI: processor: driver doesn't need to evaluate _PDC
ACPI: processor: refactor internal map_lapic_id()
ACPI: processor: refactor internal map_x2apic_id()
ACPI: processor: refactor internal map_lsapic_id()
ACPI: processor: push file static MADT pointer into internal map_madt_entry()
ACPI: processor core: style and sparse cleanups
Documentation/kernel-parameters.txt | 4 arch/ia64/kernel/acpi.c | 3 arch/x86/kernel/acpi/boot.c | 3 drivers/acpi/Makefile | 4 drivers/acpi/processor_core.c | 1149 +++++------------------------------ drivers/acpi/processor_driver.c | 976 ++++++++++++++++++++++++++++++ drivers/acpi/processor_pdc.c | 209 ------ include/acpi/processor.h | 10 8 files changed, 1172 insertions(+), 1186 deletions(-) create mode 100644 drivers/acpi/processor_driver.c delete mode 100644 drivers/acpi/processor_pdc.c
PATCH v2 1/12 ACPI: processor: mv processor_core.c processor_driver.c
The ACPI processor driver can be built as a module. But it has pieces of code that should always be built statically into the kernel.
The plan is for processor_core.c to contain the static bits while processor_driver.c contains the module-like bits.
Since the bulk of the code in the current processor_core.c is module-like, first step is to rename the file to processor_driver.c
Next step will re-create processor_core.c and cherry-pick out the static bits.
---
drivers/acpi/Makefile | 2 drivers/acpi/processor_core.c | 1140 --------------------------------------- drivers/acpi/processor_driver.c | 1140 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 1141 insertions(+), 1141 deletions(-) delete mode 100644 drivers/acpi/processor_core.c create mode 100644 drivers/acpi/processor_driver.c
drivers/acpi/Makefile +1 -1
@@ -62,7 +62,7 @@ obj-$(CONFIG_ACPI_SBS) += sbs.o obj-$(CONFIG_ACPI_POWER_METER) += power_meter.o # processor has its own "processor." module_param namespace -processor-y := processor_core.o processor_throttling.o +processor-y := processor_driver.o processor_throttling.o processor-y += processor_idle.o processor_thermal.o processor-$(CONFIG_CPU_FREQ) += processor_perflib.o
drivers/acpi/processor_core.c deleted +0 -1140
1,140 lines not on this page · raw message
drivers/acpi/processor_driver.c new file +1140 -0
1,140 lines not on this page · raw message
PATCH v2 2/12 ACPI: processor: mv processor_pdc.c processor_core.c
In reply to Alex ChiangWe've renamed the old processor_core.c to processor_driver.c, to convey the idea that it can be built modular and has driver-like bits.
Now let's re-create a processor_core.c for the bits needed statically by the rest of the kernel. The contents of processor_pdc.c are a good starting spot, so let's just rename that file and complete our three card monte.
---
drivers/acpi/Makefile | 2 drivers/acpi/processor_core.c | 209 +++++++++++++++++++++++++++++++++++++++++ drivers/acpi/processor_pdc.c | 209 ----------------------------------------- include/acpi/processor.h | 2 4 files changed, 211 insertions(+), 211 deletions(-) create mode 100644 drivers/acpi/processor_core.c delete mode 100644 drivers/acpi/processor_pdc.c
drivers/acpi/Makefile +1 -1
@@ -33,7 +33,7 @@ acpi-$(CONFIG_ACPI_SLEEP) += proc.o # acpi-y += bus.o glue.o acpi-y += scan.o -acpi-y += processor_pdc.o +acpi-y += processor_core.o acpi-y += ec.o acpi-$(CONFIG_ACPI_DOCK) += dock.o acpi-y += pci_root.o pci_link.o pci_irq.o pci_bind.o
drivers/acpi/processor_core.c new file +209 -0
209 lines not on this page · raw message
drivers/acpi/processor_pdc.c deleted +0 -209
209 lines not on this page · raw message
include/acpi/processor.h +1 -1
@@ -320,7 +320,7 @@ static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)#endif /* CONFIG_CPU_FREQ */ -/* in processor_pdc.c */ +/* in processor_core.c */ void acpi_processor_set_pdc (acpi_handle handle);/* in processor_throttling.c */
PATCH v2 3/12 ACPI: processor: export acpi_get_cpuid()
In reply to Alex ChiangRename static get_cpu_id() to acpi_get_cpuid() and export it.
This change also gives us an opportunity to remove the #ifndef CONFIG_SMP from processor_driver.c and into a header file where it properly belongs.
---
drivers/acpi/processor_driver.c | 10 ++++------ include/acpi/processor.h | 8 ++++++++ 2 files changed, 12 insertions(+), 6 deletions(-)
drivers/acpi/processor_driver.c +4 -6
@@ -359,10 +359,7 @@ static inline int acpi_processor_remove_fs(struct acpi_device *device)/* Use the acpiid in MADT to map cpus in case of SMP */ -#ifndef CONFIG_SMP -static int get_cpu_id (acpi_handle handle,int type,u32 acpi_id) {return -1 ; } -#else - +#ifdef CONFIG_SMP static struct acpi_table_madt *madt; static int map_lapic_id(struct acpi_subtable_header *entry,
@@ -494,7 +491,7 @@ exit:return apic_id; } -static int get_cpu_id (acpi_handle handle,int type,u32 acpi_id) +int acpi_get_cpuid (acpi_handle handle,int type,u32 acpi_id) {int i;int apic_id =-1 ;
@@ -511,6 +508,7 @@ static int get_cpu_id(acpi_handle handle, int type, u32 acpi_id) }return -1 ; } +EXPORT_SYMBOL_GPL (acpi_get_cpuid);#endif /* --------------------------------------------------------------------------
@@ -577,7 +575,7 @@ static int acpi_processor_get_info(struct acpi_device *device) device_declaration =1 ; pr->acpi_id = value; } - cpu_index =get_cpu_id (pr->handle, device_declaration, pr->acpi_id); + cpu_index =acpi_get_cpuid (pr->handle, device_declaration, pr->acpi_id);/* Handle UP system running SMP kernel, with no LAPIC in MADT */ if (!cpu0_initialized && (cpu_index == -1) &&
include/acpi/processor.h +8 -0
@@ -322,6 +322,14 @@ static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)/* in processor_core.c */ void acpi_processor_set_pdc (acpi_handle handle); +#ifdef CONFIG_SMP +int acpi_get_cpuid (acpi_handle ,int type,u32 acpi_id); +#else +static inline int acpi_get_cpuid (acpi_handle handle,int type,u32 acpi_id) +{ +return -1 ; +} +#endif /* in processor_throttling.c */ int acpi_processor_tstate_has_changed (struct acpi_processor *pr);
PATCH v2 4/12 ACPI: processor: move acpi_get_cpuid into processor_core.c
In reply to Alex ChiangEnumerating processors (via MADT/_MAT) belongs in the processor core, which is always built-in, rather than living in the processor driver which may not be built.
---
drivers/acpi/processor_core.c | 160 +++++++++++++++++++++++++++++++++++++++ drivers/acpi/processor_driver.c | 159 --------------------------------------- 2 files changed, 160 insertions(+), 159 deletions(-)
drivers/acpi/processor_core.c +160 -0
@@ -42,6 +42,159 @@ static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = { {}, }; +#ifdef CONFIG_SMP +static struct acpi_table_madt *madt; + +static int map_lapic_id (struct acpi_subtable_header *entry, +u32 acpi_id,int *apic_id) +{ +struct acpi_madt_local_apic *lapic = + (struct acpi_madt_local_apic *)entry; +if ((lapic->lapic_flags &ACPI_MADT_ENABLED ) && + lapic->processor_id == acpi_id) { + *apic_id = lapic->id; +return 1 ; + } +return 0 ; +} + +static int map_x2apic_id (struct acpi_subtable_header *entry, +int device_declaration,u32 acpi_id,int *apic_id) +{ +struct acpi_madt_local_x2apic *apic = + (struct acpi_madt_local_x2apic *)entry; +u32 tmp = apic->local_apic_id; + +/* Only check enabled APICs*/ +if (!(apic->lapic_flags &ACPI_MADT_ENABLED )) +return 0 ; + +/* Device statement declaration type */ +if (device_declaration) { +if (apic->uid == acpi_id) + goto found; + } + +return 0 ; +found: + *apic_id = tmp; +return 1 ; +} + +static int map_lsapic_id (struct acpi_subtable_header *entry, +int device_declaration,u32 acpi_id,int *apic_id) +{ +struct acpi_madt_local_sapic *lsapic = + (struct acpi_madt_local_sapic *)entry; +u32 tmp = (lsapic->id <<8 ) | lsapic->eid; + +/* Only check enabled APICs*/ +if (!(lsapic->lapic_flags &ACPI_MADT_ENABLED )) +return 0 ; + +/* Device statement declaration type */ +if (device_declaration) { +if (entry->length <16 ) + printk(KERN_ERR PREFIX +"Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n" , + tmp); +else if (lsapic->uid == acpi_id) + goto found; +/* Processor statement declaration type */ + }else if (lsapic->processor_id == acpi_id) + goto found; + +return 0 ; +found: + *apic_id = tmp; +return 1 ; +} + +static int map_madt_entry (int type,u32 acpi_id) +{ +unsigned long madt_end, entry; +int apic_id =-1 ; + +if (!madt) +return apic_id; + + entry = (unsigned long )madt; + madt_end = entry + madt->header.length; + +/* Parse all entries looking for a match. */ + + entry +=sizeof (struct acpi_table_madt ); +while (entry +sizeof (struct acpi_subtable_header ) < madt_end) { +struct acpi_subtable_header *header = + (struct acpi_subtable_header *)entry; +if (header->type ==ACPI_MADT_TYPE_LOCAL_APIC ) { +if (map_lapic_id (header, acpi_id, &apic_id)) +break ; + }else if (header->type ==ACPI_MADT_TYPE_LOCAL_X2APIC ) { +if (map_x2apic_id (header, type, acpi_id, &apic_id)) +break ; + }else if (header->type ==ACPI_MADT_TYPE_LOCAL_SAPIC ) { +if (map_lsapic_id (header, type, acpi_id, &apic_id)) +break ; + } + entry += header->length; + } +return apic_id; +} + +static int map_mat_entry (acpi_handle handle,int type,u32 acpi_id) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj; +struct acpi_subtable_header *header; +int apic_id =-1 ; + +if (ACPI_FAILURE (acpi_evaluate_object (handle,"_MAT" ,NULL , &buffer))) + goto exit; + +if (!buffer.length || !buffer.pointer) + goto exit; + + obj = buffer.pointer; +if (obj->type !=ACPI_TYPE_BUFFER || + obj->buffer.length <sizeof (struct acpi_subtable_header )) { + goto exit; + } + + header = (struct acpi_subtable_header *)obj->buffer.pointer; +if (header->type ==ACPI_MADT_TYPE_LOCAL_APIC ) { +map_lapic_id (header, acpi_id, &apic_id); + }else if (header->type ==ACPI_MADT_TYPE_LOCAL_SAPIC ) { +map_lsapic_id (header, type, acpi_id, &apic_id); + } + +exit: +if (buffer.pointer) +kfree (buffer.pointer); +return apic_id; +} + +int acpi_get_cpuid (acpi_handle handle,int type,u32 acpi_id) +{ +int i; +int apic_id =-1 ; + + apic_id =map_mat_entry (handle, type, acpi_id); +if (apic_id ==-1 ) + apic_id =map_madt_entry (type, acpi_id); +if (apic_id ==-1 ) +return apic_id; + +for_each_possible_cpu (i) { +if (cpu_physical_id (i) == apic_id) +return i; + } +return -1 ; +} +EXPORT_SYMBOL_GPL (acpi_get_cpuid); +#endif + +static void acpi_set_pdc_bits (u32 *buf) { buf[0 ] =ACPI_PDC_REVISION_ID ;
@@ -188,6 +341,13 @@ early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)void __init acpi_early_processor_set_pdc (void ) { + +#ifdef CONFIG_SMP +if (ACPI_FAILURE (acpi_get_table (ACPI_SIG_MADT ,0 , + (struct acpi_table_header **)&madt))) + madt =NULL ; +#endif +/* * Check whether the system is DMI table. If yes, OSPM * should not use mwait for CPU-states.
drivers/acpi/processor_driver.c +0 -159
171 lines not on this page · raw message
PATCH v2 5/12 ACPI: processor: add internal processor_physically_present()
In reply to Alex ChiangDetect if a processor is physically present before evaluating _PDC.
We want this because some BIOS will provide a _PDC even for processors that are not present. These bogus _PDC methods then attempt to load non-existent tables, which causes problems.
Avoid those bogus landmines.
---
drivers/acpi/processor_core.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-)
drivers/acpi/processor_core.c +42 -0
@@ -194,6 +194,45 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)EXPORT_SYMBOL_GPL (acpi_get_cpuid);#endif +static bool processor_physically_present (acpi_handle handle) +{ +int cpuid, type; +u32 acpi_id; +acpi_status status; +acpi_object_type acpi_type; +unsigned long long tmp; +union acpi_object object = {0 }; +struct acpi_buffer buffer = {sizeof (union acpi_object ), &object }; + + status =acpi_get_type (handle, &acpi_type); +if (ACPI_FAILURE (status)) +return false; + +switch (acpi_type) { +case ACPI_TYPE_PROCESSOR : + status =acpi_evaluate_object (handle,NULL ,NULL , &buffer); +if (ACPI_FAILURE (status)) +return false; + acpi_id = object.processor.proc_id; +break ; +case ACPI_TYPE_DEVICE : + status =acpi_evaluate_integer (handle,"_UID" ,NULL , &tmp); +if (ACPI_FAILURE (status)) +return false; + acpi_id = tmp; +break ; +default : +return false; + } + + type = (acpi_type ==ACPI_TYPE_DEVICE ) ?1 :0 ; + cpuid =acpi_get_cpuid (handle, type, acpi_id); + +if (cpuid ==-1 ) +return false; + +return true; +}static void acpi_set_pdc_bits (u32 *buf) {
@@ -335,6 +374,9 @@ static struct dmi_system_id __cpuinitdata early_pdc_optin_table[] = {static acpi_status early_init_pdc (acpi_handle handle,u32 lvl,void *context,void **rv) { +if (processor_physically_present (handle) == false) +return AE_OK ; +acpi_processor_set_pdc (handle);return AE_OK ; }
PATCH v2 6/12 ACPI: processor: remove early _PDC optin quirks
In reply to Alex ChiangNow that we check for physically present processors before blindly evaluating _PDC, we no longer need to maintain a DMI opt-in table nor a kernel param.
---
Documentation/kernel-parameters.txt | 4 ---- drivers/acpi/processor_core.c | 37 ----------------------------------- 2 files changed, 0 insertions(+), 41 deletions(-)
Documentation/kernel-parameters.txt +0 -4
@@ -198,10 +198,6 @@ and is between 256 and 4096 characters. It is defined in the file acpi_display_output=video See above. - acpi_early_pdc_eval [HW,ACPI] Evaluate processor _PDC methods - early. Needed on some platforms to properly - initialize the EC. - acpi_irq_balance [HW,ACPI] ACPI will balance active IRQs default in APIC mode
drivers/acpi/processor_core.c +0 -37
@@ -341,36 +341,6 @@ void acpi_processor_set_pdc(acpi_handle handle) }EXPORT_SYMBOL_GPL (acpi_processor_set_pdc); -static int early_pdc_optin; -static int set_early_pdc_optin (const struct dmi_system_id *id) -{ - early_pdc_optin =1 ; -return 0 ; -} - -static int param_early_pdc_optin (char *s) -{ - early_pdc_optin =1 ; -return 1 ; -} -__setup ("acpi_early_pdc_eval" , param_early_pdc_optin); - -static struct dmi_system_id __cpuinitdata early_pdc_optin_table[] = { - { - set_early_pdc_optin,"HP Envy" , { -DMI_MATCH (DMI_BIOS_VENDOR ,"Hewlett-Packard" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"HP Envy" ) },NULL }, - { - set_early_pdc_optin,"HP Pavilion dv6" , { -DMI_MATCH (DMI_BIOS_VENDOR ,"Hewlett-Packard" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"HP Pavilion dv6" ) },NULL }, - { - set_early_pdc_optin,"HP Pavilion dv7" , { -DMI_MATCH (DMI_BIOS_VENDOR ,"Hewlett-Packard" ), -DMI_MATCH (DMI_PRODUCT_NAME ,"HP Pavilion dv7" ) },NULL }, - {}, -}; -static acpi_status early_init_pdc (acpi_handle handle,u32 lvl,void *context,void **rv) {
@@ -396,13 +366,6 @@ void __init acpi_early_processor_set_pdc(void)*/ dmi_check_system (processor_idle_dmi_table); -/* -* Allow systems to opt-in to early _PDC evaluation. -*/ -dmi_check_system (early_pdc_optin_table); -if (!early_pdc_optin) -return ; -acpi_walk_namespace (ACPI_TYPE_PROCESSOR ,ACPI_ROOT_OBJECT ,ACPI_UINT32_MAX , early_init_pdc,NULL ,NULL ,NULL );
PATCH v2 7/12 ACPI: processor: driver doesn't need to evaluate _PDC
In reply to Alex ChiangNow that the early _PDC evaluation path knows how to correctly evaluate _PDC on only physically present processors, there's no need for the processor driver to evaluate it later when it loads.
To cover the hotplug case, push _PDC evaluation down into the hotplug paths.
---
arch/ia64/kernel/acpi.c | 3 +++ arch/x86/kernel/acpi/boot.c | 3 +++ drivers/acpi/processor_core.c | 7 ------- drivers/acpi/processor_driver.c | 3 --- 4 files changed, 6 insertions(+), 10 deletions(-)
arch/ia64/kernel/acpi.c +3 -0
@@ -44,6 +44,7 @@#include <linux/efi.h> #include <linux/mmzone.h> #include <linux/nodemask.h> +#include <acpi/processor.h> #include <asm/io.h> #include <asm/iosapic.h> #include <asm/machvec.h>
@@ -936,6 +937,8 @@ int acpi_map_lsapic(acpi_handle handle, int *pcpu)cpu_set (cpu, cpu_present_map); ia64_cpu_to_sapicid[cpu] = physid; +acpi_processor_set_pdc (handle); + *pcpu = cpu;return (0 ); }
arch/x86/kernel/acpi/boot.c +3 -0
@@ -480,6 +480,7 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)* ACPI based hotplug support for CPU */ #ifdef CONFIG_ACPI_HOTPLUG_CPU +#include <acpi/processor.h> static int __cpuinit _acpi_map_lsapic (acpi_handle handle,int *pcpu) {
@@ -538,6 +539,8 @@ static int __cpuinit _acpi_map_lsapic(acpi_handle handle, int *pcpu) goto free_new_map; } +acpi_processor_set_pdc (handle); + cpu =cpumask_first (new_map); *pcpu = cpu;
drivers/acpi/processor_core.c +0 -7
@@ -317,8 +317,6 @@ acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)return status; } -static int early_pdc_done; -void acpi_processor_set_pdc (acpi_handle handle) {struct acpi_object_list *obj_list;
@@ -326,9 +324,6 @@ void acpi_processor_set_pdc(acpi_handle handle)if (arch_has_acpi_pdc () == false)return ; -if (early_pdc_done) -return ; - obj_list =acpi_processor_alloc_pdc ();if (!obj_list)return ;
@@ -369,6 +364,4 @@ void __init acpi_early_processor_set_pdc(void)acpi_walk_namespace (ACPI_TYPE_PROCESSOR ,ACPI_ROOT_OBJECT ,ACPI_UINT32_MAX , early_init_pdc,NULL ,NULL ,NULL ); - - early_pdc_done =1 ; }
drivers/acpi/processor_driver.c +0 -3
@@ -606,9 +606,6 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device) goto err_remove_fs; } -/* _PDC call should be done before doing anything else (if reqd.). */ -acpi_processor_set_pdc (pr->handle); -#ifdef CONFIG_CPU_FREQ acpi_processor_ppc_has_changed (pr,0 );#endif
PATCH v2 8/12 ACPI: processor: refactor internal map_lapic_id()
In reply to Alex ChiangUntangle the if() statement a little for readability.
---
drivers/acpi/processor_core.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/acpi/processor_core.c +9 -6
@@ -50,12 +50,15 @@ static int map_lapic_id(struct acpi_subtable_header *entry, {struct acpi_madt_local_apic *lapic = (struct acpi_madt_local_apic *)entry; -if ((lapic->lapic_flags &ACPI_MADT_ENABLED ) && - lapic->processor_id == acpi_id) { - *apic_id = lapic->id; -return 1 ; - } -return 0 ; + +if (!(lapic->lapic_flags &ACPI_MADT_ENABLED )) +return 0 ; + +if (lapic->processor_id != acpi_id) +return 0 ; + + *apic_id = lapic->id; +return 1 ; } static int map_x2apic_id(struct acpi_subtable_header *entry,
PATCH v2 9/12 ACPI: processor: refactor internal map_x2apic_id()
In reply to Alex ChiangUntangle the nested if conditions to make this function look more similar to the other map_*apic_id() functions.
---
drivers/acpi/processor_core.c | 12 +++--------- 1 files changed, 3 insertions(+), 9 deletions(-)
drivers/acpi/processor_core.c +3 -9
@@ -66,22 +66,16 @@ static int map_x2apic_id(struct acpi_subtable_header *entry, {struct acpi_madt_local_x2apic *apic = (struct acpi_madt_local_x2apic *)entry; -u32 tmp = apic->local_apic_id; -/* Only check enabled APICs*/ if (!(apic->lapic_flags &ACPI_MADT_ENABLED ))return 0 ; -/* Device statement declaration type */ -if (device_declaration) { -if (apic->uid == acpi_id) - goto found; +if (device_declaration && (apic->uid == acpi_id)) { + *apic_id = apic->local_apic_id; +return 1 ; }return 0 ; -found: - *apic_id = tmp; -return 1 ; } static int map_lsapic_id(struct acpi_subtable_header *entry,
PATCH v2 10/12 ACPI: processor: refactor internal map_lsapic_id()
In reply to Alex ChiangUn-nest the if statements for readability.
Remove comments that re-state the obvious.
Change the control flow so that we no longer need a temp variable.
---
drivers/acpi/processor_core.c | 20 +++++--------------- 1 files changed, 5 insertions(+), 15 deletions(-)
drivers/acpi/processor_core.c +5 -15
@@ -83,27 +83,17 @@ static int map_lsapic_id(struct acpi_subtable_header *entry, {struct acpi_madt_local_sapic *lsapic = (struct acpi_madt_local_sapic *)entry; -u32 tmp = (lsapic->id <<8 ) | lsapic->eid; -/* Only check enabled APICs*/ if (!(lsapic->lapic_flags &ACPI_MADT_ENABLED ))return 0 ; -/* Device statement declaration type */ if (device_declaration) { -if (entry->length <16 ) - printk(KERN_ERR PREFIX -"Invalid LSAPIC with Device type processor (SAPIC ID %#x)\n" , - tmp); -else if (lsapic->uid == acpi_id) - goto found; -/* Processor statement declaration type */ - }else if (lsapic->processor_id == acpi_id) - goto found; +if ((entry->length <16 ) || (lsapic->uid != acpi_id)) +return 0 ; + }else if (lsapic->processor_id != acpi_id) +return 0 ; -return 0 ; -found: - *apic_id = tmp; + *apic_id = (lsapic->id <<8 ) | lsapic->eid;return 1 ; }
PATCH v2 11/12 ACPI: processor: push file static MADT pointer into internal map_madt_entry()
In reply to Alex ChiangThere's no real need for a pointer to the MADT to be global. The only function who uses it is map_madt_entry.
This allows us to remove some more ugly #ifdefs.
---
drivers/acpi/processor_core.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
drivers/acpi/processor_core.c +9 -9
@@ -43,8 +43,6 @@ static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = { };#ifdef CONFIG_SMP -static struct acpi_table_madt *madt; -static int map_lapic_id (struct acpi_subtable_header *entry,u32 acpi_id,int *apic_id) {
@@ -100,8 +98,17 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,static int map_madt_entry (int type,u32 acpi_id) {unsigned long madt_end, entry; +static struct acpi_table_madt *madt; +static int read_madt;int apic_id =-1 ; +if (!read_madt) { +if (ACPI_FAILURE (acpi_get_table (ACPI_SIG_MADT ,0 , + (struct acpi_table_header **)&madt))) + madt =NULL ; + read_madt++; + } +if (!madt)return apic_id;
@@ -335,13 +342,6 @@ early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)void __init acpi_early_processor_set_pdc (void ) { - -#ifdef CONFIG_SMP -if (ACPI_FAILURE (acpi_get_table (ACPI_SIG_MADT ,0 , - (struct acpi_table_header **)&madt))) - madt =NULL ; -#endif -/* * Check whether the system is DMI table. If yes, OSPM * should not use mwait for CPU-states.
PATCH v2 12/12 ACPI: processor core: style and sparse cleanups
In reply to Alex ChiangRemove useless comments
Remove useless braces
Cleanup local variable declarations
Remove shadow declarations
---
drivers/acpi/processor_core.c | 39 +++++++++++++++++---------------------- 1 files changed, 17 insertions(+), 22 deletions(-)
drivers/acpi/processor_core.c +17 -22
@@ -46,9 +46,9 @@ static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {static int map_lapic_id (struct acpi_subtable_header *entry,u32 acpi_id,int *apic_id) { -struct acpi_madt_local_apic *lapic = - (struct acpi_madt_local_apic *)entry; +struct acpi_madt_local_apic *lapic; + lapic = (struct acpi_madt_local_apic *)entry;if (!(lapic->lapic_flags &ACPI_MADT_ENABLED ))return 0 ;
@@ -62,14 +62,14 @@ static int map_lapic_id(struct acpi_subtable_header *entry,static int map_x2apic_id (struct acpi_subtable_header *entry,int device_declaration,u32 acpi_id,int *apic_id) { -struct acpi_madt_local_x2apic *apic = - (struct acpi_madt_local_x2apic *)entry; +struct acpi_madt_local_x2apic *lx2apic; -if (!(apic->lapic_flags &ACPI_MADT_ENABLED )) + lx2apic = (struct acpi_madt_local_x2apic *)entry; +if (!(lx2apic->lapic_flags &ACPI_MADT_ENABLED ))return 0 ; -if (device_declaration && (apic->uid == acpi_id)) { - *apic_id = apic->local_apic_id; +if (device_declaration && (lx2apic->uid == acpi_id)) { + *apic_id = lx2apic->local_apic_id;return 1 ; }
@@ -79,9 +79,9 @@ static int map_x2apic_id(struct acpi_subtable_header *entry,static int map_lsapic_id (struct acpi_subtable_header *entry,int device_declaration,u32 acpi_id,int *apic_id) { -struct acpi_madt_local_sapic *lsapic = - (struct acpi_madt_local_sapic *)entry; +struct acpi_madt_local_sapic *lsapic; + lsapic = (struct acpi_madt_local_sapic *)entry;if (!(lsapic->lapic_flags &ACPI_MADT_ENABLED ))return 0 ;
@@ -98,6 +98,7 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,static int map_madt_entry (int type,u32 acpi_id) {unsigned long madt_end, entry; +struct acpi_subtable_header *header;static struct acpi_table_madt *madt;static int read_madt;int apic_id =-1 ;
@@ -115,12 +116,10 @@ static int map_madt_entry(int type, u32 acpi_id) entry = (unsigned long )madt; madt_end = entry + madt->header.length; -/* Parse all entries looking for a match. */ - entry +=sizeof (struct acpi_table_madt );while (entry +sizeof (struct acpi_subtable_header ) < madt_end) { -struct acpi_subtable_header *header = - (struct acpi_subtable_header *)entry; + header = (struct acpi_subtable_header *)entry; +if (header->type ==ACPI_MADT_TYPE_LOCAL_APIC ) {if (map_lapic_id (header, acpi_id, &apic_id))break ;
@@ -151,20 +150,17 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id) obj = buffer.pointer;if (obj->type !=ACPI_TYPE_BUFFER || - obj->buffer.length <sizeof (struct acpi_subtable_header )) { + obj->buffer.length <sizeof (struct acpi_subtable_header )) goto exit; - } header = (struct acpi_subtable_header *)obj->buffer.pointer; -if (header->type ==ACPI_MADT_TYPE_LOCAL_APIC ) { +if (header->type ==ACPI_MADT_TYPE_LOCAL_APIC )map_lapic_id (header, acpi_id, &apic_id); - }else if (header->type ==ACPI_MADT_TYPE_LOCAL_SAPIC ) { +else if (header->type ==ACPI_MADT_TYPE_LOCAL_SAPIC )map_lsapic_id (header, type, acpi_id, &apic_id); - } exit: -if (buffer.pointer) -kfree (buffer.pointer); +kfree (buffer.pointer);return apic_id; }
@@ -179,10 +175,9 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)if (apic_id ==-1 )return apic_id; -for_each_possible_cpu (i) { +for_each_possible_cpu (i)if (cpu_physical_id (i) == apic_id)return i; - }return -1 ; }EXPORT_SYMBOL_GPL (acpi_get_cpuid);