From deb77283797f91626ef3091e0fd71a1aaf36ee29 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Thu, 19 Feb 2015 12:47:48 +0000 Subject: [PATCH] Add support to get the cpu ID from its device driver in a generic way. This will be needed by arm64 to find the value to pass to the psci (Power State Coordination Interface) driver, among other things, used to enable cores. Differential Revision: https://reviews.freebsd.org/D1824 Reviewed by: imp Sponsored by: The FreeBSD Foundation --- sys/dev/ofw/ofw_cpu.c | 11 +++++++++++ sys/sys/cpu.h | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/sys/dev/ofw/ofw_cpu.c b/sys/dev/ofw/ofw_cpu.c index 0432560281a8..250419ffe3c2 100644 --- a/sys/dev/ofw/ofw_cpu.c +++ b/sys/dev/ofw/ofw_cpu.c @@ -244,6 +244,7 @@ ofw_cpu_attach(device_t dev) static int ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) { + struct ofw_cpulist_softc *psc; struct ofw_cpu_softc *sc; sc = device_get_softc(dev); @@ -258,6 +259,16 @@ ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) return (0); } break; + case CPU_IVAR_CPUID_SIZE: + psc = device_get_softc(device_get_parent(dev)); + *result = psc->sc_addr_cells; + return (0); + case CPU_IVAR_CPUID: + if (sc->sc_reg_valid) { + *result = (uintptr_t)sc->sc_reg; + return (0); + } + break; } return (ENOENT); diff --git a/sys/sys/cpu.h b/sys/sys/cpu.h index c16091e1504e..f159e376bba1 100644 --- a/sys/sys/cpu.h +++ b/sys/sys/cpu.h @@ -37,6 +37,8 @@ #define CPU_IVAR_PCPU 1 #define CPU_IVAR_NOMINAL_MHZ 2 +#define CPU_IVAR_CPUID_SIZE 3 +#define CPU_IVAR_CPUID 4 static __inline struct pcpu *cpu_get_pcpu(device_t dev) { @@ -54,6 +56,20 @@ static __inline int32_t cpu_get_nominal_mhz(device_t dev) return ((int32_t)v); } +static __inline const uint32_t *cpu_get_cpuid(device_t dev, size_t *count) +{ + uintptr_t v = 0; + if (BUS_READ_IVAR(device_get_parent(dev), dev, + CPU_IVAR_CPUID_SIZE, &v) != 0) + return (NULL); + *count = (size_t)v; + + if (BUS_READ_IVAR(device_get_parent(dev), dev, + CPU_IVAR_CPUID, &v) != 0) + return (NULL); + return ((const uint32_t *)v); +} + /* * CPU frequency control interface. */