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 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
136struct ofw_cpu_softc {
137 struct pcpu *sc_cpu_pcpu;
138 uint32_t sc_nominal_mhz;
139};
140
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
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{
199 struct ofw_cpu_softc *sc;
200
201 sc = device_get_softc(dev);
202
203 switch (index) {
204 case CPU_IVAR_PCPU:
205 *result = (uintptr_t)sc->sc_cpu_pcpu;
206 return (0);
207 case CPU_IVAR_NOMINAL_MHZ:
208 *result = (uintptr_t)sc->sc_nominal_mhz;
209 return (0);
210 }
211
212 return (ENOENT);
213}
214
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 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
136struct ofw_cpu_softc {
137 struct pcpu *sc_cpu_pcpu;
138 uint32_t sc_nominal_mhz;
139};
140
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
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{
199 struct ofw_cpu_softc *sc;
200
201 sc = device_get_softc(dev);
202
203 switch (index) {
204 case CPU_IVAR_PCPU:
205 *result = (uintptr_t)sc->sc_cpu_pcpu;
206 return (0);
207 case CPU_IVAR_NOMINAL_MHZ:
208 *result = (uintptr_t)sc->sc_nominal_mhz;
209 return (0);
210 }
211
212 return (ENOENT);
213}
214