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 $");
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
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{
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{
185 uint32_t cell;
186
187 switch (index) {
188 case CPU_IVAR_PCPU:
189 OF_getprop(ofw_bus_get_node(dev), "reg", &cell, sizeof(cell));
190 *result = (uintptr_t)(pcpu_find(cell));
191 return (0);
192 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);
198 return (0);
199 }
200
201 return (ENOENT);
202}
203
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 $");
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
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{
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{
185 uint32_t cell;
186
187 switch (index) {
188 case CPU_IVAR_PCPU:
189 OF_getprop(ofw_bus_get_node(dev), "reg", &cell, sizeof(cell));
190 *result = (uintptr_t)(pcpu_find(cell));
191 return (0);
192 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);
198 return (0);
199 }
200
201 return (ENOENT);
202}
203