36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/malloc.h>
41#include <machine/bus.h>
48#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
49#include <dev/extres/clk/clk.h>
69 DEVMETHOD(bus_add_child, bus_generic_add_child),
101 if (name == NULL || strcmp(name,
"cpus") != 0)
104 device_set_desc(
dev,
"Open Firmware CPU Group");
115 struct ofw_bus_devinfo *dinfo;
117 sc = device_get_softc(
dev);
125 dinfo = malloc(
sizeof(*dinfo), M_OFWCPU, M_WAITOK | M_ZERO);
128 free(dinfo, M_OFWCPU);
131 cdev = device_add_child(
dev, NULL, -1);
133 device_printf(
dev,
"<%s>: device_add_child failed\n",
136 free(dinfo, M_OFWCPU);
139 device_set_ivars(cdev, dinfo);
142 return (bus_generic_attach(
dev));
145static const struct ofw_bus_devinfo *
148 return (device_get_ivars(
child));
169 DEVMETHOD(bus_add_child, bus_generic_add_child),
171 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
172 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
173 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
174 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
175 DEVMETHOD(bus_activate_resource,bus_generic_activate_resource),
195 if (type == NULL || strcmp(type,
"cpu") != 0)
198 device_set_desc(
dev,
"Open Firmware CPU");
210#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
215 sc = device_get_softc(
dev);
216 psc = device_get_softc(device_get_parent(
dev));
220 device_printf(
dev,
"Too many address cells\n");
230 device_printf(
dev,
"missing 'reg' property\n");
231 else if ((rv % 4) != 0) {
233 device_printf(
dev,
"Malformed reg property\n");
236 device_printf(
dev,
"Invalid reg size %u\n", rv);
245 if (
OF_hasprop(node,
"ibm,ppc-interrupt-server#s")) {
246 struct cpuref cpuref;
251 "ibm,ppc-interrupt-server#s", (
void **)&servers)) < 0)
253 nservers /=
sizeof(cell_t);
254 for (i = 0; i < nservers; i++) {
255 for (rv = platform_smp_first_cpu(&cpuref); rv == 0;
256 rv = platform_smp_next_cpu(&cpuref)) {
257 if (cpuref.cr_hwref == servers[i]) {
259 pcpu_find(cpuref.cr_cpuid);
272 device_printf(
dev,
"No CPU found for this device.\n");
279 if (
OF_getencprop(node,
"clock-frequency", &cell,
sizeof(cell)) < 0) {
280#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
281 rv = clk_get_by_ofw_index(
dev, 0, 0, &cpuclk);
283 rv = clk_get_freq(cpuclk, &freq);
284 if (rv != 0 && bootverbose)
286 "Cannot get freq of property clocks\n");
294 "missing 'clock-frequency' property\n");
300 device_printf(
dev,
"Nominal frequency %dMhz\n",
302 bus_generic_probe(
dev);
303 return (bus_generic_attach(
dev));
312 sc = device_get_softc(
dev);
318 case CPU_IVAR_NOMINAL_MHZ:
324 case CPU_IVAR_CPUID_SIZE:
325 psc = device_get_softc(device_get_parent(
dev));
330 *result = (uintptr_t)sc->
sc_reg;
345 char device_type[16];
359 sizeof(addr_cells)) < 0)
365 memset(device_type, 0,
sizeof(device_type));
367 sizeof(device_type) - 1);
370 if (strcmp(device_type,
"cpu") != 0)
384 if (status[0] !=
'\0' && strcmp(status,
"okay") != 0 &&
385 strcmp(status,
"ok") != 0 &&
394 addr_cells *
sizeof(cell_t));
395 if (rv != addr_cells *
sizeof(cell_t))
398 if (callback == NULL || callback(
id,
child, addr_cells, reg))
402 return (only_runnable ? count :
id);
METHOD phandle_t child
Return first child of node.
static __inline phandle_t ofw_bus_get_node(device_t dev)
static __inline const char * ofw_bus_get_compat(device_t dev)
static __inline const char * ofw_bus_get_type(device_t dev)
static __inline const char * ofw_bus_get_model(device_t dev)
static __inline const char * ofw_bus_get_name(device_t dev)
void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *obd)
int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node)
ofw_bus_get_name_t ofw_bus_gen_get_name
ofw_bus_get_node_t ofw_bus_gen_get_node
ofw_bus_get_model_t ofw_bus_gen_get_model
ofw_bus_get_compat_t ofw_bus_gen_get_compat
bus_child_pnpinfo_t ofw_bus_gen_child_pnpinfo
ofw_bus_get_type_t ofw_bus_gen_get_type
static device_method_t ofw_cpulist_methods[]
static devclass_t ofw_cpulist_devclass
static int ofw_cpu_attach(device_t)
static int ofw_cpulist_attach(device_t)
static device_method_t ofw_cpu_methods[]
static devclass_t ofw_cpu_devclass
static int ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
int ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, boolean_t only_runnable)
static int ofw_cpu_probe(device_t)
static const struct ofw_bus_devinfo * ofw_cpulist_get_devinfo(device_t dev, device_t child)
DRIVER_MODULE(ofw_cpulist, ofwbus, ofw_cpulist_driver, ofw_cpulist_devclass, 0, 0)
static int ofw_cpulist_probe(device_t)
static driver_t ofw_cpulist_driver
static MALLOC_DEFINE(M_OFWCPU, "ofwcpu", "OFW CPU device information")
static driver_t ofw_cpu_driver
boolean_t(* ofw_cpu_foreach_cb)(u_int, phandle_t, u_int, pcell_t *)
ssize_t OF_getencprop_alloc(phandle_t package, const char *name, void **buf)
phandle_t OF_peer(phandle_t node)
phandle_t OF_finddevice(const char *device)
ssize_t OF_getencprop(phandle_t node, const char *propname, pcell_t *buf, size_t len)
int OF_hasprop(phandle_t package, const char *propname)
phandle_t OF_child(phandle_t node)
void OF_prop_free(void *buf)
ssize_t OF_getprop(phandle_t package, const char *propname, void *buf, size_t buflen)
struct pcpu * sc_cpu_pcpu