# HG changeset patch
# User Keir Fraser <keir@xen.org>
# Date 1292413934 0
# Node ID 548c808be2a6f166657ce7cfb86df7a296a9526a
# Parent  c0662cb08260d831ae8d211ba16fc7038cb889b6
x86: mpparse and cstate need to use 32bit apic id
References: bnc#656369, bnc#658704

Instead of going with mpc_config_processor struct.
that field ony have 8 bits.

We should not change that struct, because it is shared with mptable.

Also need to increase MAX_APICS.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

Rather than using a fixed value of 512, make this scale with NR_CPUS
(which obviously still doesn't cover all theoretically possible
systems, but at least allows some build time control).

Signed-off-by: Jan Beulich <jbeulich@novell.com>

Index: xen-4.0.3-testing/xen/arch/x86/acpi/cpu_idle.c
===================================================================
--- xen-4.0.3-testing.orig/xen/arch/x86/acpi/cpu_idle.c
+++ xen-4.0.3-testing/xen/arch/x86/acpi/cpu_idle.c
@@ -742,7 +742,7 @@ static void set_cx(
 int get_cpu_id(u8 acpi_id)
 {
     int i;
-    u8 apic_id;
+    u32 apic_id;
 
     apic_id = x86_acpiid_to_apicid[acpi_id];
     if ( apic_id == 0xff )
Index: xen-4.0.3-testing/xen/arch/x86/mpparse.c
===================================================================
--- xen-4.0.3-testing.orig/xen/arch/x86/mpparse.c
+++ xen-4.0.3-testing/xen/arch/x86/mpparse.c
@@ -99,7 +99,8 @@ static int mpc_record;
 static struct mpc_config_translation *translation_table[MAX_MPC_ENTRY] __initdata;
 
 /* Return xen's logical cpu_id of the new added cpu or <0 if error */
-static int __devinit MP_processor_info (struct mpc_config_processor *m)
+static int __devinit MP_processor_info_x(struct mpc_config_processor *m,
+					 u32 apicidx)
 {
  	int ver, apicid, cpu = 0;
 	physid_mask_t phys_cpu;
@@ -107,7 +108,7 @@ static int __devinit MP_processor_info (
 	if (!(m->mpc_cpuflag & CPU_ENABLED))
 		return -EINVAL;
 
-	apicid = mpc_apic_id(m, translation_table[mpc_record]);
+	apicid = mpc_apic_id(m, apicidx, translation_table[mpc_record]);
 
 	if (m->mpc_featureflag&(1<<0))
 		Dprintk("    Floating point unit present.\n");
@@ -159,7 +160,7 @@ static int __devinit MP_processor_info (
 
 	if (m->mpc_cpuflag & CPU_BOOTPROCESSOR) {
 		Dprintk("    Bootup CPU\n");
-		boot_cpu_physical_apicid = m->mpc_apicid;
+		boot_cpu_physical_apicid = apicid;
 	}
 
 	ver = m->mpc_apicver;
@@ -170,10 +171,10 @@ static int __devinit MP_processor_info (
 	if (ver == 0x0) {
 		printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
 				"fixing up to 0x10. (tell your hw vendor)\n",
-				m->mpc_apicid);
+				apicid);
 		ver = 0x10;
 	}
-	apic_version[m->mpc_apicid] = ver;
+	apic_version[apicid] = ver;
 
 	phys_cpu = apicid_to_cpu_present(apicid);
 	physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu);
@@ -216,6 +217,11 @@ static int __devinit MP_processor_info (
     return cpu;
 }
 
+static int __devinit MP_processor_info(struct mpc_config_processor *m)
+{
+	return MP_processor_info_x(m, m->mpc_apicid);
+}
+
 static void __init MP_bus_info (struct mpc_config_bus *m)
 {
 	char str[7];
@@ -844,7 +850,7 @@ int __devinit mp_register_lapic (
 	struct mpc_config_processor processor;
 	int			boot_cpu = 0;
 	
-	if (MAX_APICS - id <= 0) {
+	if (MAX_APICS <= id) {
 		printk(KERN_WARNING "Processor #%d invalid (max %d)\n",
 			id, MAX_APICS);
 		return -EINVAL;
@@ -864,7 +870,7 @@ int __devinit mp_register_lapic (
 	processor.mpc_reserved[0] = 0;
 	processor.mpc_reserved[1] = 0;
 
-    return MP_processor_info(&processor);
+	return MP_processor_info_x(&processor, id);
 }
 
 void mp_unregister_lapic(uint32_t apic_id, uint32_t cpu)
Index: xen-4.0.3-testing/xen/common/sched_sedf.c
===================================================================
--- xen-4.0.3-testing.orig/xen/common/sched_sedf.c
+++ xen-4.0.3-testing/xen/common/sched_sedf.c
@@ -124,7 +124,6 @@ struct sedf_cpu_info {
 
 #define PERIOD_BEGIN(inf) ((inf)->deadl_abs - (inf)->period)
 
-#define MIN(x,y)    (((x)<(y))?(x):(y))
 #define DIV_UP(x,y) (((x) + (y) - 1) / y)
 
 #define extra_runs(inf)      ((inf->status) & 6)
Index: xen-4.0.3-testing/xen/include/asm-x86/mach-generic/mach_apic.h
===================================================================
--- xen-4.0.3-testing.orig/xen/include/asm-x86/mach-generic/mach_apic.h
+++ xen-4.0.3-testing/xen/include/asm-x86/mach-generic/mach_apic.h
@@ -26,15 +26,15 @@ static inline void enable_apic_mode(void
 
 extern u32 bios_cpu_apicid[];
 
-static inline int mpc_apic_id(struct mpc_config_processor *m, 
+static inline int mpc_apic_id(struct mpc_config_processor *m, u32 apicid,
 			struct mpc_config_translation *translation_record)
 {
 	printk("Processor #%d %d:%d APIC version %d\n",
-			m->mpc_apicid,
+			apicid,
 			(m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
 			(m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
 			m->mpc_apicver);
-	return (m->mpc_apicid);
+	return apicid;
 }
 
 static inline void setup_portio_remap(void)
Index: xen-4.0.3-testing/xen/include/asm-x86/mpspec_def.h
===================================================================
--- xen-4.0.3-testing.orig/xen/include/asm-x86/mpspec_def.h
+++ xen-4.0.3-testing/xen/include/asm-x86/mpspec_def.h
@@ -14,7 +14,7 @@
 #define SMP_MAGIC_IDENT	(('_'<<24)|('P'<<16)|('M'<<8)|'_')
 
 #define MAX_MPC_ENTRY 1024
-#define MAX_APICS      256
+#define MAX_APICS     MAX(256, 4 * NR_CPUS)
 
 struct intel_mp_floating
 {
Index: xen-4.0.3-testing/xen/include/xen/kernel.h
===================================================================
--- xen-4.0.3-testing.orig/xen/include/xen/kernel.h
+++ xen-4.0.3-testing/xen/include/xen/kernel.h
@@ -33,6 +33,13 @@
 #define max_t(type,x,y) \
         ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 
+/*
+ * pre-processor, array size, and bit field width suitable variants;
+ * please don't use in "normal" expressions.
+ */
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  *
