From: "Jan Beulich" Subject: [PATCH] linux/acpi: adjust extcntl's changes to (mostly) common code, mostly for readability Date: Wed, 23 Jul 2008 14:12:14 +0100 Message-ID: <48874A4E.76E4.0078.0@novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org While I realize that it may have been upon my request that all these #ifdef-s were introduced, I think this went too far here: With the abstraction in include/acpi/processor.h in place, the code still guarantees even without all these #ifdef-s that in native kernels built from the same source the logic will not change. The one thing that appears a little weak still is the NR_ACPI_CPUS construct - nothing guarantees that the ACPI IDs are constrained to 8 bits, and hence using an array here doesn't seem either safe or scalable looking forward. To make the issue explict, the patch adds a respective BUG_ON(). Also remove a stray export. As usual, written and tested on 2.6.26 and made apply to the 2.6.18 tree without further testing. Signed-off-by: Jan Beulich Index: head-2008-07-21/arch/i386/kernel/acpi/processor_extcntl_xen.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-07-21.orig/arch/i386/kernel/acpi/processor_extcntl_xen.c = 2008-07-22 15:58:45.000000000 +0200 +++ head-2008-07-21/arch/i386/kernel/acpi/processor_extcntl_xen.c = 2008-07-22 17:23:07.000000000 +0200 @@ -40,7 +40,6 @@ static int __init set_xen_processor_pmbi return 1; } __setup("xen_processor_pmbits=3D", set_xen_processor_pmbits); -EXPORT_SYMBOL(xen_processor_pmbits); =20 static int xen_cx_notifier(struct acpi_processor *pr, int action) { Index: head-2008-07-21/drivers/acpi/processor_core.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-07-21.orig/drivers/acpi/processor_core.c 2008-07-22 = 17:19:17.000000000 +0200 +++ head-2008-07-21/drivers/acpi/processor_core.c 2008-07-22 = 17:16:50.000000000 +0200 @@ -474,14 +474,9 @@ static int acpi_processor_get_info(struc * they are physically not present. */ if (cpu_index =3D=3D -1) { -#ifdef CONFIG_XEN if (ACPI_FAILURE (acpi_processor_hotadd_init(pr->handle, &pr->id)) && !processor_cntl_external()) { -#else - if (ACPI_FAILURE - (acpi_processor_hotadd_init(pr->handle, &pr->id))) { -#endif /* CONFIG_XEN */ printk(KERN_ERR PREFIX "Getting cpuindex for acpiid 0x%x\n", pr->acpi_id); @@ -523,11 +518,7 @@ static int acpi_processor_get_info(struc return 0; } =20 -#ifdef CONFIG_XEN static void *processor_device_array[NR_ACPI_CPUS]; -#else -static void *processor_device_array[NR_CPUS]; -#endif /* CONFIG_XEN */ =20 static int acpi_processor_start(struct acpi_device *device) { @@ -539,22 +530,14 @@ static int __cpuinit acpi_processor_star pr =3D acpi_driver_data(device); =20 result =3D acpi_processor_get_info(pr); -#ifdef CONFIG_XEN if (result ||=20 ((pr->id =3D=3D -1) && !processor_cntl_external())) { -#else - if (result) { -#endif /* CONFIG_XEN */ /* Processor is physically not present */ return 0; } =20 -#ifdef CONFIG_XEN BUG_ON(!processor_cntl_external() && ((pr->id >=3D NR_CPUS) || (pr->id < 0))); -#else - BUG_ON((pr->id >=3D NR_CPUS) || (pr->id < 0)); -#endif /* CONFIG_XEN */ =20 /* * Buggy BIOS check @@ -562,6 +545,7 @@ static int __cpuinit acpi_processor_star * Don't trust it blindly */ #ifdef CONFIG_XEN + BUG_ON(pr->acpi_id >=3D NR_ACPI_CPUS); if (processor_device_array[pr->acpi_id] !=3D NULL && processor_device_array[pr->acpi_id] !=3D (void *)device) { #else @@ -595,9 +579,9 @@ static int __cpuinit acpi_processor_star =20 acpi_processor_power_init(pr, device); =20 -#ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL - processor_extcntl_init(pr); -#endif + result =3D processor_extcntl_init(pr); + if (result) + goto end; =20 if (pr->flags.throttling) { printk(KERN_INFO PREFIX "%s [%s] (supports", @@ -751,11 +735,9 @@ int acpi_processor_device_add(acpi_handl if (!pr) return -ENODEV; =20 -#ifdef CONFIG_XEN if (processor_cntl_external()) processor_notify_external(pr, PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD); -#endif /* CONFIG_XEN */ =20 if ((pr->id >=3D 0) && (pr->id < NR_CPUS)) { kobject_uevent(&(*device)->kobj, KOBJ_ONLINE); @@ -795,11 +777,9 @@ static void __ref acpi_processor_hotplug break; } =20 -#ifdef CONFIG_XEN if (processor_cntl_external()) processor_notify_external(pr, PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD= ); -#endif /* CONFIG_XEN */ =20 if (pr->id >=3D 0 && (pr->id < NR_CPUS)) { kobject_uevent(&device->kobj, KOBJ_OFFLINE); @@ -838,11 +818,9 @@ static void __ref acpi_processor_hotplug #endif /* CONFIG_XEN */ kobject_uevent(&device->kobj, KOBJ_OFFLINE); =20 -#ifdef CONFIG_XEN if (processor_cntl_external()) processor_notify_external(pr, PROCESSOR_HOTPLUG, HOTPLUG_TYPE_REMOVE= ); -#endif /* CONFIG_XEN */ =20 break; default: Index: head-2008-07-21/drivers/acpi/processor_idle.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-07-21.orig/drivers/acpi/processor_idle.c 2008-05-19 = 11:00:05.000000000 +0200 +++ head-2008-07-21/drivers/acpi/processor_idle.c 2008-07-22 = 17:29:00.000000000 +0200 @@ -714,17 +714,12 @@ static int acpi_processor_get_power_info (reg->space_id !=3D ACPI_ADR_SPACE_FIXED_HARDWARE)) continue; =20 -#ifdef CONFIG_XEN if (!processor_pm_external()) cx.address =3D (reg->space_id =3D=3D ACPI_ADR_SPACE_FIXED_HARDWARE) ? 0 : reg->address; else cx.address =3D reg->address; -#else - cx.address =3D (reg->space_id =3D=3D ACPI_ADR_SPACE_FIXED_H= ARDWARE) ? - 0 : reg->address; -#endif /* CONFIG_XEN */ =20 /* There should be an easy way to extract an integer... */ obj =3D (union acpi_object *)&(element->package.elements[1]= ); @@ -733,17 +728,11 @@ static int acpi_processor_get_power_info =20 cx.type =3D obj->integer.value; =20 -#ifdef CONFIG_XEN /* Following check doesn't apply to external control case = */ - if (!processor_pm_external()) - if ((cx.type !=3D ACPI_STATE_C1) && - (reg->space_id !=3D ACPI_ADR_SPACE_SYSTEM_IO)) - continue; -#else - if ((cx.type !=3D ACPI_STATE_C1) && + if (!processor_pm_external() && + (cx.type !=3D ACPI_STATE_C1) && (reg->space_id !=3D ACPI_ADR_SPACE_SYSTEM_IO)) continue; -#endif /* CONFIG_XEN */ =20 if ((cx.type < ACPI_STATE_C2) || (cx.type > ACPI_STATE_C3))= continue; @@ -1008,24 +997,16 @@ int acpi_processor_cst_has_changed(struc return -ENODEV; =20 /* Fall back to the default idle loop */ -#ifdef CONFIG_XEN if (!processor_pm_external()) pm_idle =3D pm_idle_save; -#else - pm_idle =3D pm_idle_save; -#endif /* CONFIG_XEN */ synchronize_sched(); /* Relies on interrupts forcing exit from = idle. */ =20 pr->flags.power =3D 0; result =3D acpi_processor_get_power_info(pr); -#ifdef CONFIG_XEN if (processor_pm_external()) processor_notify_external(pr, PROCESSOR_PM_CHANGE, PM_TYPE_IDLE); else if ((pr->flags.power =3D=3D 1) && (pr->flags.power_setup_done)= ) -#else - if ((pr->flags.power =3D=3D 1) && (pr->flags.power_setup_done)) -#endif /* CONFIG_XEN */ pm_idle =3D acpi_processor_idle; =20 return result; @@ -1157,11 +1138,7 @@ int __cpuinit acpi_processor_power_init( pr->power.states[i].type); printk(")\n"); =20 -#ifdef CONFIG_XEN if (!processor_pm_external() && (pr->id =3D=3D 0)) { -#else - if (pr->id =3D=3D 0) { -#endif /* CONFIG_XEN */ pm_idle_save =3D pm_idle; pm_idle =3D acpi_processor_idle; } @@ -1180,11 +1157,9 @@ int __cpuinit acpi_processor_power_init( =20 pr->flags.power_setup_done =3D 1; =20 -#ifdef CONFIG_XEN if (processor_pm_external()) processor_notify_external(pr, PROCESSOR_PM_INIT, PM_TYPE_IDLE); -#endif /* CONFIG_XEN */ return 0; } =20 Index: head-2008-07-21/drivers/acpi/processor_perflib.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-07-21.orig/drivers/acpi/processor_perflib.c 2008-07-22 = 17:19:17.000000000 +0200 +++ head-2008-07-21/drivers/acpi/processor_perflib.c 2008-07-22 = 17:09:48.000000000 +0200 @@ -136,11 +136,9 @@ int acpi_processor_ppc_has_changed(struc int ret =3D acpi_processor_get_platform_limit(pr); if (ret < 0) return (ret); -#ifdef CONFIG_XEN else if (processor_pmperf_external()) return processor_notify_external(pr, PROCESSOR_PM_CHANGE, PM_TYPE_PERF); -#endif /* CONFIG_XEN */ else return cpufreq_update_policy(pr->id); } @@ -305,10 +303,9 @@ static int acpi_processor_get_performanc } =20 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL -static int acpi_processor_get_performance_info(struct acpi_processor *pr) -#else -int acpi_processor_get_performance_info(struct acpi_processor *pr) +static #endif +int acpi_processor_get_performance_info(struct acpi_processor *pr) { int result =3D 0; acpi_status status =3D AE_OK; @@ -548,10 +545,9 @@ static void acpi_cpufreq_remove_file(str #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ =20 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL -static int acpi_processor_get_psd(struct acpi_processor *pr) -#else -int acpi_processor_get_psd(struct acpi_processor *pr) +static #endif +int acpi_processor_get_psd(struct acpi_processor *pr) { int result =3D 0; acpi_status status =3D AE_OK; Index: head-2008-07-21/include/acpi/processor.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- head-2008-07-21.orig/include/acpi/processor.h 2008-07-22 = 16:01:43.000000000 +0200 +++ head-2008-07-21/include/acpi/processor.h 2008-07-22 17:25:48.0000000= 00 +0200 @@ -22,7 +22,9 @@ #define ACPI_PSD_REV0_ENTRIES 5 =20 #ifdef CONFIG_XEN -#define NR_ACPI_CPUS 256 +#define NR_ACPI_CPUS (NR_CPUS < 256 ? 256 : NR_CPUS) +#else +#define NR_ACPI_CPUS NR_CPUS #endif /* CONFIG_XEN */ =20 /* @@ -296,7 +298,6 @@ static inline void acpi_thermal_cpufreq_ } #endif =20 -#ifdef CONFIG_XEN /*=20 * Following are interfaces geared to external processor PM control * logic like a VMM @@ -306,7 +307,7 @@ static inline void acpi_thermal_cpufreq_ #define PROCESSOR_PM_CHANGE 2 #define PROCESSOR_HOTPLUG 3 =20 -/* Objects for the PM envents */ +/* Objects for the PM events */ #define PM_TYPE_IDLE 0 #define PM_TYPE_PERF 1 #define PM_TYPE_THR 2 @@ -363,13 +364,12 @@ static inline int processor_pmthr_extern static inline int processor_notify_external(struct acpi_processor *pr, int event, int type) { - return -EINVAL; + return 0; } static inline int processor_extcntl_init(struct acpi_processor *pr) { - return -EINVAL; + return 0; } #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */ -#endif /* CONFIG_XEN */ =20 #endif