public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] x86, acpi: add support for x2apic ACPI extensions
@ 2009-03-25 20:43 Suresh Siddha
  2009-03-27 22:20 ` Len Brown
  2009-03-27 22:24 ` Len Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Suresh Siddha @ 2009-03-25 20:43 UTC (permalink / raw)
  To: lenb, linux-acpi; +Cc: venkatesh.pallipadi, mingo, hpa, steiner

All logical processors with APIC ID values of 255 and greater will have their
APIC reported through Processor X2APIC structure (type-9 entry type) and all
logical processors with APIC ID less than 255 will have their APIC reported
through legacy Processor Local APIC (type-0 entry type) only. This is the
same case even for NMI structure reporting.

The Processor X2APIC Affinity structure provides the association between the
X2APIC ID of a logical processor and the proximity domain to which the logical
processor belongs.

For OSPM, Procssor IDs outside the 0-254 range are to be declared as Device()
objects in the ACPI namespace.

Add support for these x2apic ACPI extensions.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---

Index: tip/arch/x86/kernel/acpi/boot.c
===================================================================
--- tip.orig/arch/x86/kernel/acpi/boot.c
+++ tip/arch/x86/kernel/acpi/boot.c
@@ -230,6 +230,35 @@ static void __cpuinit acpi_register_lapi
 }
 
 static int __init
+acpi_parse_x2apic(struct acpi_subtable_header * header, const unsigned long end)
+{
+	struct acpi_madt_local_x2apic *processor = NULL;
+
+	processor = (struct acpi_madt_local_x2apic *)header;
+
+	if (BAD_MADT_ENTRY(processor, end))
+		return -EINVAL;
+
+	acpi_table_print_madt_entry(header);
+
+#ifdef CONFIG_X86_X2APIC
+	/*
+	 * We need to register disabled CPU as well to permit
+	 * counting disabled CPUs. This allows us to size
+	 * cpus_possible_map more accurately, to permit
+	 * to not preallocating memory for all NR_CPUS
+	 * when we use CPU hotplug.
+	 */
+	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
+			    processor->lapic_flags & ACPI_MADT_ENABLED);
+#else
+	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+#endif
+
+	return 0;
+}
+
+static int __init
 acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
 {
 	struct acpi_madt_local_apic *processor = NULL;
@@ -289,6 +318,24 @@ acpi_parse_lapic_addr_ovr(struct acpi_su
 }
 
 static int __init
+acpi_parse_x2apic_nmi(struct acpi_subtable_header * header, const unsigned long end)
+{
+	struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
+
+	x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
+
+	if (BAD_MADT_ENTRY(x2apic_nmi, end))
+		return -EINVAL;
+
+	acpi_table_print_madt_entry(header);
+
+	if (x2apic_nmi->lint != 1)
+		printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
+
+	return 0;
+}
+
+static int __init
 acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
 {
 	struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
@@ -816,9 +863,12 @@ static int __init acpi_parse_madt_lapic_
 	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
 				      acpi_parse_sapic, MAX_APICS);
 
-	if (!count)
+	if (!count) {
+		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
+					      acpi_parse_x2apic, MAX_APICS);
 		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
 					      acpi_parse_lapic, MAX_APICS);
+	}
 	if (!count) {
 		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
 		/* TBD: Cleanup to allow fallback to MPS */
@@ -830,6 +880,8 @@ static int __init acpi_parse_madt_lapic_
 	}
 
 	count =
+	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI, acpi_parse_x2apic_nmi, 0);
+	count =
 	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
 	if (count < 0) {
 		printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
Index: tip/arch/x86/mm/srat_64.c
===================================================================
--- tip.orig/arch/x86/mm/srat_64.c
+++ tip/arch/x86/mm/srat_64.c
@@ -116,6 +116,36 @@ void __init acpi_numa_slit_init(struct a
 	reserve_early(phys, phys + length, "ACPI SLIT");
 }
 
+/* Callback for Proximity Domain -> x2APIC mapping */
+void __init
+acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
+{
+	int pxm, node;
+	int apic_id;
+
+	if (srat_disabled())
+		return;
+	if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
+		bad_srat();
+		return;
+	}
+	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
+		return;
+	pxm = pa->proximity_domain;
+	node = setup_node(pxm);
+	if (node < 0) {
+		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		bad_srat();
+		return;
+	}
+
+	apic_id = pa->apic_id;
+	apicid_to_node[apic_id] = node;
+	acpi_numa = 1;
+	printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n",
+	       pxm, apic_id, node);
+}
+
 /* Callback for Proximity Domain -> LAPIC mapping */
 void __init
 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
Index: tip/drivers/acpi/numa.c
===================================================================
--- tip.orig/drivers/acpi/numa.c
+++ tip/drivers/acpi/numa.c
@@ -131,6 +131,20 @@ acpi_table_print_srat_entry(struct acpi_
 #endif				/* ACPI_DEBUG_OUTPUT */
 		break;
 
+	case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
+#ifdef ACPI_DEBUG_OUTPUT
+		{
+			struct acpi_srat_x2apic_cpu_affinity *p =
+			    (struct acpi_srat_x2apic_cpu_affinity *)header;
+			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+					  "SRAT Processor (x2apicid[0x%08x]) in proximity domain %d %s\n",
+					  p->apic_id,
+					  p->proximity_domain,
+					  (p->flags & ACPI_SRAT_CPU_ENABLED)?
+					  "enabled" : "disabled"));
+		}
+#endif				/* ACPI_DEBUG_OUTPUT */
+		break;
 	default:
 		printk(KERN_WARNING PREFIX
 		       "Found unsupported SRAT entry (type = 0x%x)\n",
@@ -180,6 +194,33 @@ static int __init acpi_parse_slit(struct
 	return 0;
 }
 
+void __init __attribute__ ((weak))
+acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
+{
+	printk(KERN_WARNING PREFIX
+	       "Found unsupported x2apic [0x%08x] SRAT entry\n", pa->apic_id);
+	return;
+}
+
+
+static int __init
+acpi_parse_x2apic_affinity(struct acpi_subtable_header * header,
+				     const unsigned long end)
+{
+	struct acpi_srat_x2apic_cpu_affinity *processor_affinity;
+
+	processor_affinity = (struct acpi_srat_x2apic_cpu_affinity *)header;
+	if (!processor_affinity)
+		return -EINVAL;
+
+	acpi_table_print_srat_entry(header);
+
+	/* let architecture-dependent part to do it */
+	acpi_numa_x2apic_affinity_init(processor_affinity);
+
+	return 0;
+}
+
 static int __init
 acpi_parse_processor_affinity(struct acpi_subtable_header * header,
 			      const unsigned long end)
@@ -241,6 +282,9 @@ int __init acpi_numa_init(void)
 {
 	/* SRAT: Static Resource Affinity Table */
 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
+		acpi_table_parse_srat(ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY,
+				      acpi_parse_x2apic_affinity,
+				      NR_CPUS);
 		acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
 				      acpi_parse_processor_affinity, NR_CPUS);
 		acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
Index: tip/include/linux/acpi.h
===================================================================
--- tip.orig/include/linux/acpi.h
+++ tip/include/linux/acpi.h
@@ -97,6 +97,7 @@ void acpi_table_print_madt_entry (struct
 /* the following four functions are architecture-dependent */
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
 void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa);
+void acpi_numa_x2apic_affinity_init (struct acpi_srat_x2apic_cpu_affinity *pa);
 void acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
 void acpi_numa_arch_fixup(void);
 
Index: tip/drivers/acpi/processor_core.c
===================================================================
--- tip.orig/drivers/acpi/processor_core.c
+++ tip/drivers/acpi/processor_core.c
@@ -427,6 +427,29 @@ static int map_lapic_id(struct acpi_subt
 	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)
 {
@@ -476,6 +499,9 @@ static int map_madt_entry(int type, u32 
 		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;
Index: tip/drivers/acpi/tables.c
===================================================================
--- tip.orig/drivers/acpi/tables.c
+++ tip/drivers/acpi/tables.c
@@ -62,6 +62,17 @@ void acpi_table_print_madt_entry(struct 
 		}
 		break;
 
+	case ACPI_MADT_TYPE_LOCAL_X2APIC:
+		{
+			struct acpi_madt_local_x2apic *p =
+			    (struct acpi_madt_local_x2apic *)header;
+			printk(KERN_INFO PREFIX
+			       "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
+			       p->local_apic_id, p->uid,
+			       (p->lapic_flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
+		}
+		break;
+
 	case ACPI_MADT_TYPE_IO_APIC:
 		{
 			struct acpi_madt_io_apic *p =
@@ -116,6 +127,19 @@ void acpi_table_print_madt_entry(struct 
 		}
 		break;
 
+	case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
+		{
+			struct acpi_madt_local_x2apic_nmi *p =
+			    (struct acpi_madt_local_x2apic_nmi *)header;
+			printk(KERN_INFO PREFIX
+			       "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
+			       p->uid,
+			       mps_inti_flags_polarity[p->inti_flags & ACPI_MADT_POLARITY_MASK	],
+			       mps_inti_flags_trigger[(p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2],
+			       p->lint);
+		}
+		break;
+
 	case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
 		{
 			struct acpi_madt_local_apic_override *p =
Index: tip/include/acpi/actbl1.h
===================================================================
--- tip.orig/include/acpi/actbl1.h
+++ tip/include/acpi/actbl1.h
@@ -1016,9 +1016,9 @@ struct acpi_madt_interrupt_source {
 struct acpi_madt_local_x2apic {
 	struct acpi_subtable_header header;
 	u16 reserved;		/* Reserved - must be zero */
-	u32 local_apic_id;	/* Processor X2_APIC ID  */
+	u32 local_apic_id;	/* Processor x2APIC ID  */
 	u32 lapic_flags;
-	u32 uid;		/* Extended X2_APIC processor ID */
+	u32 uid;		/* ACPI processor UID */
 };
 
 /* 10: Local X2APIC NMI (07/2008) */
@@ -1026,7 +1026,7 @@ struct acpi_madt_local_x2apic {
 struct acpi_madt_local_x2apic_nmi {
 	struct acpi_subtable_header header;
 	u16 inti_flags;
-	u32 uid;		/* Processor X2_APIC ID */
+	u32 uid;		/* ACPI processor ID */
 	u8 lint;		/* LINTn to which NMI is connected */
 	u8 reserved[3];
 };



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] x86, acpi: add support for x2apic ACPI extensions
  2009-03-25 20:43 [patch] x86, acpi: add support for x2apic ACPI extensions Suresh Siddha
@ 2009-03-27 22:20 ` Len Brown
  2009-04-08 16:00   ` Ingo Molnar
  2009-03-27 22:24 ` Len Brown
  1 sibling, 1 reply; 6+ messages in thread
From: Len Brown @ 2009-03-27 22:20 UTC (permalink / raw)
  To: Suresh Siddha; +Cc: linux-acpi, venkatesh.pallipadi, mingo, hpa, steiner


On Wed, 25 Mar 2009, Suresh Siddha wrote:

> All logical processors with APIC ID values of 255 and greater will have their
> APIC reported through Processor X2APIC structure (type-9 entry type) and all
> logical processors with APIC ID less than 255 will have their APIC reported
> through legacy Processor Local APIC (type-0 entry type) only. This is the
> same case even for NMI structure reporting.
> 
> The Processor X2APIC Affinity structure provides the association between the
> X2APIC ID of a logical processor and the proximity domain to which the logical
> processor belongs.
> 
> For OSPM, Procssor IDs outside the 0-254 range are to be declared as Device()
> objects in the ACPI namespace.
> 
> Add support for these x2apic ACPI extensions.
> 
> Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
> ---
> 
> Index: tip/arch/x86/kernel/acpi/boot.c
> ===================================================================
> --- tip.orig/arch/x86/kernel/acpi/boot.c
> +++ tip/arch/x86/kernel/acpi/boot.c
> @@ -230,6 +230,35 @@ static void __cpuinit acpi_register_lapi
>  }
>  
>  static int __init
> +acpi_parse_x2apic(struct acpi_subtable_header * header, const unsigned long end)
> +{
> +	struct acpi_madt_local_x2apic *processor = NULL;
> +
> +	processor = (struct acpi_madt_local_x2apic *)header;
> +
> +	if (BAD_MADT_ENTRY(processor, end))
> +		return -EINVAL;
> +
> +	acpi_table_print_madt_entry(header);
> +
> +#ifdef CONFIG_X86_X2APIC
> +	/*
> +	 * We need to register disabled CPU as well to permit
> +	 * counting disabled CPUs. This allows us to size
> +	 * cpus_possible_map more accurately, to permit
> +	 * to not preallocating memory for all NR_CPUS
> +	 * when we use CPU hotplug.
> +	 */
> +	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
> +			    processor->lapic_flags & ACPI_MADT_ENABLED);
> +#else
> +	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
> +#endif
> +
> +	return 0;
> +}
> +
> +static int __init
>  acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
>  {
>  	struct acpi_madt_local_apic *processor = NULL;
> @@ -289,6 +318,24 @@ acpi_parse_lapic_addr_ovr(struct acpi_su
>  }
>  
>  static int __init
> +acpi_parse_x2apic_nmi(struct acpi_subtable_header * header, const unsigned long end)
> +{
> +	struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
> +
> +	x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
> +
> +	if (BAD_MADT_ENTRY(x2apic_nmi, end))
> +		return -EINVAL;
> +
> +	acpi_table_print_madt_entry(header);
> +
> +	if (x2apic_nmi->lint != 1)
> +		printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
> +
> +	return 0;
> +}
> +
> +static int __init
>  acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
>  {
>  	struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
> @@ -816,9 +863,12 @@ static int __init acpi_parse_madt_lapic_
>  	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
>  				      acpi_parse_sapic, MAX_APICS);
>  
> -	if (!count)
> +	if (!count) {
> +		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
> +					      acpi_parse_x2apic, MAX_APICS);
>  		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
>  					      acpi_parse_lapic, MAX_APICS);

I'm not fond of the idiom

count = a();
count = b();

if (count)...

here and below.

if we really don't care if the x2apic parse routines return,
and we always care what the traditional apic parse routines return,
we should have

a();
count = b();
...

Ingo, this one is probably more ACPI than it is x86 -- shall I handle it?

thanks,
-Len


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] x86, acpi: add support for x2apic ACPI extensions
  2009-03-25 20:43 [patch] x86, acpi: add support for x2apic ACPI extensions Suresh Siddha
  2009-03-27 22:20 ` Len Brown
@ 2009-03-27 22:24 ` Len Brown
  2009-03-30 21:55   ` Suresh Siddha
  1 sibling, 1 reply; 6+ messages in thread
From: Len Brown @ 2009-03-27 22:24 UTC (permalink / raw)
  To: Suresh Siddha; +Cc: linux-acpi, venkatesh.pallipadi, mingo, hpa, steiner


scripts/checkpatch.pl

ERROR: "foo * bar" should be "foo *bar"
#34: FILE: arch/x86/kernel/acpi/boot.c:233:
+acpi_parse_x2apic(struct acpi_subtable_header * header, const unsigned 
long end)

WARNING: line over 80 characters
#70: FILE: arch/x86/kernel/acpi/boot.c:321:
+acpi_parse_x2apic_nmi(struct acpi_subtable_header * header, const 
unsigned long end)

ERROR: "foo * bar" should be "foo *bar"
#70: FILE: arch/x86/kernel/acpi/boot.c:321:
+acpi_parse_x2apic_nmi(struct acpi_subtable_header * header, const 
unsigned long end)

WARNING: line over 80 characters
#109: FILE: arch/x86/kernel/acpi/boot.c:883:
+	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI, 
acpi_parse_x2apic_nmi, 0);

WARNING: line over 80 characters
#169: FILE: drivers/acpi/numa.c:140:
+					  "SRAT Processor 
(x2apicid[0x%08x]) in proximity domain %d %s\n",

ERROR: spaces required around that '?' (ctx:VxE)
#172: FILE: drivers/acpi/numa.c:143:
+					  (p->flags & 
ACPI_SRAT_CPU_ENABLED)?
 					                                    
^

ERROR: "foo * bar" should be "foo *bar"
#194: FILE: drivers/acpi/numa.c:207:
+acpi_parse_x2apic_affinity(struct acpi_subtable_header * header,

WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), 
num_possible_cpus(), for_each_possible_cpu(), etc
#220: FILE: drivers/acpi/numa.c:287:
+				      NR_CPUS);

WARNING: space prohibited between function name and open parenthesis '('
#232: FILE: include/linux/acpi.h:100:
+void acpi_numa_x2apic_affinity_init (struct acpi_srat_x2apic_cpu_affinity 
*pa);

WARNING: line over 80 characters
#295: FILE: drivers/acpi/tables.c:72:
+			       (p->lapic_flags & ACPI_MADT_ENABLED) ? 
"enabled" : "disabled");

WARNING: line over 80 characters
#313: FILE: drivers/acpi/tables.c:137:
+			       mps_inti_flags_polarity[p->inti_flags & 
ACPI_MADT_POLARITY_MASK	],

ERROR: space prohibited before that close square bracket ']'
#313: FILE: drivers/acpi/tables.c:137:
+			       mps_inti_flags_polarity[p->inti_flags & 
ACPI_MADT_POLARITY_MASK	],

WARNING: line over 80 characters
#314: FILE: drivers/acpi/tables.c:138:
+			       mps_inti_flags_trigger[(p->inti_flags & 
ACPI_MADT_TRIGGER_MASK) >> 2],

total: 5 errors, 8 warnings, 259 lines checked


--
Len Brown, Intel Open Source Technology Center


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] x86, acpi: add support for x2apic ACPI extensions
  2009-03-27 22:24 ` Len Brown
@ 2009-03-30 21:55   ` Suresh Siddha
  2009-04-04  0:11     ` Len Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Suresh Siddha @ 2009-03-30 21:55 UTC (permalink / raw)
  To: Len Brown
  Cc: linux-acpi@vger.kernel.org, Pallipadi, Venkatesh, mingo@elte.hu,
	hpa@linux.intel.com, steiner@sgi.com

On Fri, 2009-03-27 at 15:24 -0700, Len Brown wrote:
> scripts/checkpatch.pl

Len, existing acpi code needs fixes then, as I just did cut & paste :(

I am appending a new patch which fixes all the issues in the new code
except for one noted below.

> WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), 
> num_possible_cpus(), for_each_possible_cpu(), etc
> #220: FILE: drivers/acpi/numa.c:287:
> +				      NR_CPUS);

This warning can be ignored, as the cpu_possible_map is not yet setup at
this point.

thanks,
suresh
---
Subject: [patch] x86, acpi: add support for x2apic ACPI extensions

All logical processors with APIC ID values of 255 and greater will have their
APIC reported through Processor X2APIC structure (type-9 entry type) and all
logical processors with APIC ID less than 255 will have their APIC reported
through legacy Processor Local APIC (type-0 entry type) only. This is the
same case even for NMI structure reporting.

The Processor X2APIC Affinity structure provides the association between the
X2APIC ID of a logical processor and the proximity domain to which the logical
processor belongs.

For OSPM, Procssor IDs outside the 0-254 range must be declared as Device()
objects in the ACPI namespace.

Add support for these x2apic ACPI extensions.

Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---

diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index a18eb7c..bd57de1 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -230,6 +230,35 @@ static void __cpuinit acpi_register_lapic(int id, u8 enabled)
 }
 
 static int __init
+acpi_parse_x2apic(struct acpi_subtable_header *header, const unsigned long end)
+{
+	struct acpi_madt_local_x2apic *processor = NULL;
+
+	processor = (struct acpi_madt_local_x2apic *)header;
+
+	if (BAD_MADT_ENTRY(processor, end))
+		return -EINVAL;
+
+	acpi_table_print_madt_entry(header);
+
+#ifdef CONFIG_X86_X2APIC
+	/*
+	 * We need to register disabled CPU as well to permit
+	 * counting disabled CPUs. This allows us to size
+	 * cpus_possible_map more accurately, to permit
+	 * to not preallocating memory for all NR_CPUS
+	 * when we use CPU hotplug.
+	 */
+	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
+			    processor->lapic_flags & ACPI_MADT_ENABLED);
+#else
+	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
+#endif
+
+	return 0;
+}
+
+static int __init
 acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
 {
 	struct acpi_madt_local_apic *processor = NULL;
@@ -289,6 +318,25 @@ acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
 }
 
 static int __init
+acpi_parse_x2apic_nmi(struct acpi_subtable_header *header,
+		      const unsigned long end)
+{
+	struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
+
+	x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
+
+	if (BAD_MADT_ENTRY(x2apic_nmi, end))
+		return -EINVAL;
+
+	acpi_table_print_madt_entry(header);
+
+	if (x2apic_nmi->lint != 1)
+		printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
+
+	return 0;
+}
+
+static int __init
 acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
 {
 	struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
@@ -793,6 +841,7 @@ static int __init early_acpi_parse_madt_lapic_addr_ovr(void)
 static int __init acpi_parse_madt_lapic_entries(void)
 {
 	int count;
+	int x2count = 0;
 
 	if (!cpu_has_apic)
 		return -ENODEV;
@@ -816,22 +865,28 @@ static int __init acpi_parse_madt_lapic_entries(void)
 	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
 				      acpi_parse_sapic, MAX_APICS);
 
-	if (!count)
+	if (!count) {
+		x2count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
+						acpi_parse_x2apic, MAX_APICS);
 		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
 					      acpi_parse_lapic, MAX_APICS);
-	if (!count) {
+	}
+	if (!count && !x2count) {
 		printk(KERN_ERR PREFIX "No LAPIC entries present\n");
 		/* TBD: Cleanup to allow fallback to MPS */
 		return -ENODEV;
-	} else if (count < 0) {
+	} else if (count < 0 || x2count < 0) {
 		printk(KERN_ERR PREFIX "Error parsing LAPIC entry\n");
 		/* TBD: Cleanup to allow fallback to MPS */
 		return count;
 	}
 
+	x2count =
+	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC_NMI,
+				  acpi_parse_x2apic_nmi, 0);
 	count =
 	    acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0);
-	if (count < 0) {
+	if (count < 0 || x2count < 0) {
 		printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
 		/* TBD: Cleanup to allow fallback to MPS */
 		return count;
diff --git a/arch/x86/mm/srat_64.c b/arch/x86/mm/srat_64.c
index 574c8bc..c7d272b 100644
--- a/arch/x86/mm/srat_64.c
+++ b/arch/x86/mm/srat_64.c
@@ -116,6 +116,36 @@ void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
 	reserve_early(phys, phys + length, "ACPI SLIT");
 }
 
+/* Callback for Proximity Domain -> x2APIC mapping */
+void __init
+acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
+{
+	int pxm, node;
+	int apic_id;
+
+	if (srat_disabled())
+		return;
+	if (pa->header.length < sizeof(struct acpi_srat_x2apic_cpu_affinity)) {
+		bad_srat();
+		return;
+	}
+	if ((pa->flags & ACPI_SRAT_CPU_ENABLED) == 0)
+		return;
+	pxm = pa->proximity_domain;
+	node = setup_node(pxm);
+	if (node < 0) {
+		printk(KERN_ERR "SRAT: Too many proximity domains %x\n", pxm);
+		bad_srat();
+		return;
+	}
+
+	apic_id = pa->apic_id;
+	apicid_to_node[apic_id] = node;
+	acpi_numa = 1;
+	printk(KERN_INFO "SRAT: PXM %u -> APIC %u -> Node %u\n",
+	       pxm, apic_id, node);
+}
+
 /* Callback for Proximity Domain -> LAPIC mapping */
 void __init
 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 3a0d8ef..d440ccd 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -131,6 +131,21 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header)
 #endif				/* ACPI_DEBUG_OUTPUT */
 		break;
 
+	case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY:
+#ifdef ACPI_DEBUG_OUTPUT
+		{
+			struct acpi_srat_x2apic_cpu_affinity *p =
+			    (struct acpi_srat_x2apic_cpu_affinity *)header;
+			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+					  "SRAT Processor (x2apicid[0x%08x]) in"
+					  " proximity domain %d %s\n",
+					  p->apic_id,
+					  p->proximity_domain,
+					  (p->flags & ACPI_SRAT_CPU_ENABLED) ?
+					  "enabled" : "disabled"));
+		}
+#endif				/* ACPI_DEBUG_OUTPUT */
+		break;
 	default:
 		printk(KERN_WARNING PREFIX
 		       "Found unsupported SRAT entry (type = 0x%x)\n",
@@ -180,8 +195,35 @@ static int __init acpi_parse_slit(struct acpi_table_header *table)
 	return 0;
 }
 
+void __init __attribute__ ((weak))
+acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa)
+{
+	printk(KERN_WARNING PREFIX
+	       "Found unsupported x2apic [0x%08x] SRAT entry\n", pa->apic_id);
+	return;
+}
+
+
+static int __init
+acpi_parse_x2apic_affinity(struct acpi_subtable_header *header,
+			   const unsigned long end)
+{
+	struct acpi_srat_x2apic_cpu_affinity *processor_affinity;
+
+	processor_affinity = (struct acpi_srat_x2apic_cpu_affinity *)header;
+	if (!processor_affinity)
+		return -EINVAL;
+
+	acpi_table_print_srat_entry(header);
+
+	/* let architecture-dependent part to do it */
+	acpi_numa_x2apic_affinity_init(processor_affinity);
+
+	return 0;
+}
+
 static int __init
-acpi_parse_processor_affinity(struct acpi_subtable_header * header,
+acpi_parse_processor_affinity(struct acpi_subtable_header *header,
 			      const unsigned long end)
 {
 	struct acpi_srat_cpu_affinity *processor_affinity;
@@ -241,6 +283,8 @@ int __init acpi_numa_init(void)
 {
 	/* SRAT: Static Resource Affinity Table */
 	if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
+		acpi_table_parse_srat(ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY,
+				      acpi_parse_x2apic_affinity, NR_CPUS);
 		acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
 				      acpi_parse_processor_affinity, NR_CPUS);
 		acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 0cc2fd3..775324e 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -427,6 +427,29 @@ static int map_lapic_id(struct acpi_subtable_header *entry,
 	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)
 {
@@ -476,6 +499,9 @@ static int map_madt_entry(int type, u32 acpi_id)
 		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;
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index fec1ae3..646d39c 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -62,6 +62,18 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
 		}
 		break;
 
+	case ACPI_MADT_TYPE_LOCAL_X2APIC:
+		{
+			struct acpi_madt_local_x2apic *p =
+			    (struct acpi_madt_local_x2apic *)header;
+			printk(KERN_INFO PREFIX
+			       "X2APIC (apic_id[0x%02x] uid[0x%02x] %s)\n",
+			       p->local_apic_id, p->uid,
+			       (p->lapic_flags & ACPI_MADT_ENABLED) ?
+			       "enabled" : "disabled");
+		}
+		break;
+
 	case ACPI_MADT_TYPE_IO_APIC:
 		{
 			struct acpi_madt_io_apic *p =
@@ -116,6 +128,24 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
 		}
 		break;
 
+	case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI:
+		{
+			u16 polarity, trigger;
+			struct acpi_madt_local_x2apic_nmi *p =
+			    (struct acpi_madt_local_x2apic_nmi *)header;
+
+			polarity = p->inti_flags & ACPI_MADT_POLARITY_MASK;
+			trigger = (p->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2;
+
+			printk(KERN_INFO PREFIX
+			       "X2APIC_NMI (uid[0x%02x] %s %s lint[0x%x])\n",
+			       p->uid,
+			       mps_inti_flags_polarity[polarity],
+			       mps_inti_flags_trigger[trigger],
+			       p->lint);
+		}
+		break;
+
 	case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
 		{
 			struct acpi_madt_local_apic_override *p =
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 7819915..41c907c 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -97,6 +97,7 @@ void acpi_table_print_madt_entry (struct acpi_subtable_header *madt);
 /* the following four functions are architecture-dependent */
 void acpi_numa_slit_init (struct acpi_table_slit *slit);
 void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa);
+void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
 void acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
 void acpi_numa_arch_fixup(void);
 



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [patch] x86, acpi: add support for x2apic ACPI extensions
  2009-03-30 21:55   ` Suresh Siddha
@ 2009-04-04  0:11     ` Len Brown
  0 siblings, 0 replies; 6+ messages in thread
From: Len Brown @ 2009-04-04  0:11 UTC (permalink / raw)
  To: Suresh Siddha
  Cc: linux-acpi@vger.kernel.org, Pallipadi, Venkatesh, mingo@elte.hu,
	hpa@linux.intel.com, steiner@sgi.com

> I am appending a new patch which fixes all the issues in the new code
> except for one noted below.

old patch replaced with new, staged for 2.6.30.

thanks,
Len Brown, Intel Open Source Technology Center


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] x86, acpi: add support for x2apic ACPI extensions
  2009-03-27 22:20 ` Len Brown
@ 2009-04-08 16:00   ` Ingo Molnar
  0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-04-08 16:00 UTC (permalink / raw)
  To: Len Brown; +Cc: Suresh Siddha, linux-acpi, venkatesh.pallipadi, hpa, steiner


* Len Brown <lenb@kernel.org> wrote:

> 
> On Wed, 25 Mar 2009, Suresh Siddha wrote:
> 
> > All logical processors with APIC ID values of 255 and greater will have their
> > APIC reported through Processor X2APIC structure (type-9 entry type) and all
> > logical processors with APIC ID less than 255 will have their APIC reported
> > through legacy Processor Local APIC (type-0 entry type) only. This is the
> > same case even for NMI structure reporting.
> > 
> > The Processor X2APIC Affinity structure provides the association between the
> > X2APIC ID of a logical processor and the proximity domain to which the logical
> > processor belongs.
> > 
> > For OSPM, Procssor IDs outside the 0-254 range are to be declared as Device()
> > objects in the ACPI namespace.
> > 
> > Add support for these x2apic ACPI extensions.
> > 
> > Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
> > ---
> > 
> > Index: tip/arch/x86/kernel/acpi/boot.c
> > ===================================================================
> > --- tip.orig/arch/x86/kernel/acpi/boot.c
> > +++ tip/arch/x86/kernel/acpi/boot.c
> > @@ -230,6 +230,35 @@ static void __cpuinit acpi_register_lapi
> >  }
> >  
> >  static int __init
> > +acpi_parse_x2apic(struct acpi_subtable_header * header, const unsigned long end)
> > +{
> > +	struct acpi_madt_local_x2apic *processor = NULL;
> > +
> > +	processor = (struct acpi_madt_local_x2apic *)header;
> > +
> > +	if (BAD_MADT_ENTRY(processor, end))
> > +		return -EINVAL;
> > +
> > +	acpi_table_print_madt_entry(header);
> > +
> > +#ifdef CONFIG_X86_X2APIC
> > +	/*
> > +	 * We need to register disabled CPU as well to permit
> > +	 * counting disabled CPUs. This allows us to size
> > +	 * cpus_possible_map more accurately, to permit
> > +	 * to not preallocating memory for all NR_CPUS
> > +	 * when we use CPU hotplug.
> > +	 */
> > +	acpi_register_lapic(processor->local_apic_id,	/* APIC ID */
> > +			    processor->lapic_flags & ACPI_MADT_ENABLED);
> > +#else
> > +	printk(KERN_WARNING PREFIX "x2apic entry ignored\n");
> > +#endif
> > +
> > +	return 0;
> > +}
> > +
> > +static int __init
> >  acpi_parse_lapic(struct acpi_subtable_header * header, const unsigned long end)
> >  {
> >  	struct acpi_madt_local_apic *processor = NULL;
> > @@ -289,6 +318,24 @@ acpi_parse_lapic_addr_ovr(struct acpi_su
> >  }
> >  
> >  static int __init
> > +acpi_parse_x2apic_nmi(struct acpi_subtable_header * header, const unsigned long end)
> > +{
> > +	struct acpi_madt_local_x2apic_nmi *x2apic_nmi = NULL;
> > +
> > +	x2apic_nmi = (struct acpi_madt_local_x2apic_nmi *)header;
> > +
> > +	if (BAD_MADT_ENTRY(x2apic_nmi, end))
> > +		return -EINVAL;
> > +
> > +	acpi_table_print_madt_entry(header);
> > +
> > +	if (x2apic_nmi->lint != 1)
> > +		printk(KERN_WARNING PREFIX "NMI not connected to LINT 1!\n");
> > +
> > +	return 0;
> > +}
> > +
> > +static int __init
> >  acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
> >  {
> >  	struct acpi_madt_local_apic_nmi *lapic_nmi = NULL;
> > @@ -816,9 +863,12 @@ static int __init acpi_parse_madt_lapic_
> >  	count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
> >  				      acpi_parse_sapic, MAX_APICS);
> >  
> > -	if (!count)
> > +	if (!count) {
> > +		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_X2APIC,
> > +					      acpi_parse_x2apic, MAX_APICS);
> >  		count = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC,
> >  					      acpi_parse_lapic, MAX_APICS);
> 
> I'm not fond of the idiom
> 
> count = a();
> count = b();
> 
> if (count)...
> 
> here and below.
> 
> if we really don't care if the x2apic parse routines return,
> and we always care what the traditional apic parse routines return,
> we should have
> 
> a();
> count = b();
> ...
> 
> Ingo, this one is probably more ACPI than it is x86 -- shall I handle it?

Sure, please do.

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-04-08 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-25 20:43 [patch] x86, acpi: add support for x2apic ACPI extensions Suresh Siddha
2009-03-27 22:20 ` Len Brown
2009-04-08 16:00   ` Ingo Molnar
2009-03-27 22:24 ` Len Brown
2009-03-30 21:55   ` Suresh Siddha
2009-04-04  0:11     ` Len Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox