powerpc: Make core id information available to userspace

Previous thread: powerpc/vio: More fallout from dma_mapping_error API change by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:10 am. (1 message)

Next thread: powerpc/powermac: Use sane default baudrate for SCC debugging by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:10 am. (1 message)
From: Linux Kernel Mailing List
Date: Monday, July 28, 2008 - 10:10 am

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=e9efed...
Commit:     e9efed3b80a83e44b98fc626f3268ae072550b84
Parent:     440a0857e32a05979fb01fc59ea454a723e80e4b
Author:     Nathan Lynch <ntl@pobox.com>
AuthorDate: Sun Jul 27 15:24:54 2008 +1000
Committer:  Benjamin Herrenschmidt <benh@kernel.crashing.org>
CommitDate: Mon Jul 28 16:30:52 2008 +1000

    powerpc: Make core id information available to userspace
    
    Existing Open Firmware practice is to report each processor core as a
    separate node in the device tree.  Report the value of the "reg" OF
    property corresponding to a logical CPU's device node as the core_id
    attribute in /sys/devices/system/cpu/cpu*/topology/core_id.
    
    Signed-off-by: Nathan Lynch <ntl@pobox.com>
    Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 arch/powerpc/kernel/smp.c      |   23 +++++++++++++++++++++++
 include/asm-powerpc/smp.h      |    1 +
 include/asm-powerpc/topology.h |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index f7a2f81..5337ca7 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -380,6 +380,29 @@ int __cpuinit __cpu_up(unsigned int cpu)
 	return 0;
 }
 
+/* Return the value of the reg property corresponding to the given
+ * logical cpu.
+ */
+int cpu_to_core_id(int cpu)
+{
+	struct device_node *np;
+	const int *reg;
+	int id = -1;
+
+	np = of_get_cpu_node(cpu, NULL);
+	if (!np)
+		goto out;
+
+	reg = of_get_property(np, "reg", NULL);
+	if (!reg)
+		goto out;
+
+	id = *reg;
+out:
+	of_node_put(np);
+	return id;
+}
+
 /* Must be called when no change can occur to cpu_present_map,
  * i.e. during cpu online or offline.
  */
diff --git a/include/asm-powerpc/smp.h b/include/asm-powerpc/smp.h
index 32e9100..4d28e1e 100644
--- a/include/asm-powerpc/smp.h
+++ b/include/asm-powerpc/smp.h
@@ ...
Previous thread: powerpc/vio: More fallout from dma_mapping_error API change by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:10 am. (1 message)

Next thread: powerpc/powermac: Use sane default baudrate for SCC debugging by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:10 am. (1 message)