ofw_cpu.c (227843) | ofw_cpu.c (252115) |
---|---|
1/*- 2 * Copyright (C) 2009 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2009 Nathan Whitehorn 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 10 unchanged lines hidden (view full) --- 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/sys/powerpc/ofw/ofw_cpu.c 227843 2011-11-22 21:28:20Z marius $"); | 27__FBSDID("$FreeBSD: head/sys/powerpc/ofw/ofw_cpu.c 252115 2013-06-23 14:20:54Z jhibbits $"); |
28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/module.h> 33#include <sys/malloc.h> 34#include <sys/bus.h> 35#include <sys/cpu.h> --- 92 unchanged lines hidden (view full) --- 128 return (device_get_ivars(child)); 129} 130 131static int ofw_cpu_probe(device_t); 132static int ofw_cpu_attach(device_t); 133static int ofw_cpu_read_ivar(device_t dev, device_t child, int index, 134 uintptr_t *result); 135 | 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32#include <sys/module.h> 33#include <sys/malloc.h> 34#include <sys/bus.h> 35#include <sys/cpu.h> --- 92 unchanged lines hidden (view full) --- 128 return (device_get_ivars(child)); 129} 130 131static int ofw_cpu_probe(device_t); 132static int ofw_cpu_attach(device_t); 133static int ofw_cpu_read_ivar(device_t dev, device_t child, int index, 134 uintptr_t *result); 135 |
136struct ofw_cpu_softc { 137 struct pcpu *sc_cpu_pcpu; 138 uint32_t sc_nominal_mhz; 139}; 140 |
|
136static device_method_t ofw_cpu_methods[] = { 137 /* Device interface */ 138 DEVMETHOD(device_probe, ofw_cpu_probe), 139 DEVMETHOD(device_attach, ofw_cpu_attach), 140 141 /* Bus interface */ 142 DEVMETHOD(bus_add_child, bus_generic_add_child), 143 DEVMETHOD(bus_read_ivar, ofw_cpu_read_ivar), --- 26 unchanged lines hidden (view full) --- 170 171 device_set_desc(dev, "Open Firmware CPU"); 172 return (0); 173} 174 175static int 176ofw_cpu_attach(device_t dev) 177{ | 141static device_method_t ofw_cpu_methods[] = { 142 /* Device interface */ 143 DEVMETHOD(device_probe, ofw_cpu_probe), 144 DEVMETHOD(device_attach, ofw_cpu_attach), 145 146 /* Bus interface */ 147 DEVMETHOD(bus_add_child, bus_generic_add_child), 148 DEVMETHOD(bus_read_ivar, ofw_cpu_read_ivar), --- 26 unchanged lines hidden (view full) --- 175 176 device_set_desc(dev, "Open Firmware CPU"); 177 return (0); 178} 179 180static int 181ofw_cpu_attach(device_t dev) 182{ |
183 struct ofw_cpu_softc *sc; 184 uint32_t cell; 185 186 sc = device_get_softc(dev); 187 OF_getprop(ofw_bus_get_node(dev), "reg", &cell, sizeof(cell)); 188 sc->sc_cpu_pcpu = pcpu_find(cell); 189 OF_getprop(ofw_bus_get_node(dev), "clock-frequency", &cell, sizeof(cell)); 190 sc->sc_nominal_mhz = cell / 1000000; /* convert to MHz */ 191 |
|
178 bus_generic_probe(dev); 179 return (bus_generic_attach(dev)); 180} 181 182static int 183ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) 184{ | 192 bus_generic_probe(dev); 193 return (bus_generic_attach(dev)); 194} 195 196static int 197ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result) 198{ |
185 uint32_t cell; | 199 struct ofw_cpu_softc *sc; |
186 | 200 |
201 sc = device_get_softc(dev); 202 |
|
187 switch (index) { 188 case CPU_IVAR_PCPU: | 203 switch (index) { 204 case CPU_IVAR_PCPU: |
189 OF_getprop(ofw_bus_get_node(dev), "reg", &cell, sizeof(cell)); 190 *result = (uintptr_t)(pcpu_find(cell)); | 205 *result = (uintptr_t)sc->sc_cpu_pcpu; |
191 return (0); 192 case CPU_IVAR_NOMINAL_MHZ: | 206 return (0); 207 case CPU_IVAR_NOMINAL_MHZ: |
193 cell = 0; 194 OF_getprop(ofw_bus_get_node(dev), "clock-frequency", 195 &cell, sizeof(cell)); 196 cell /= 1000000; /* convert to MHz */ 197 *result = (uintptr_t)(cell); | 208 *result = (uintptr_t)sc->sc_nominal_mhz; |
198 return (0); 199 } 200 201 return (ENOENT); 202} 203 | 209 return (0); 210 } 211 212 return (ENOENT); 213} 214 |