41#include <sys/kernel.h>
42#include <sys/malloc.h>
43#include <sys/module.h>
56#include <dev/fdt/simplebus.h>
58#include <machine/bus.h>
59#include <machine/resource.h>
104 BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
116 if (device_find_child(
parent,
"ofwbus", -1) == NULL)
117 BUS_ADD_CHILD(
parent, 0,
"ofwbus", -1);
130 device_set_desc(
dev,
"Open Firmware Device Tree");
131 return (BUS_PROBE_NOWILDCARD);
139 struct ofw_bus_devinfo obd;
141 sc = device_get_softc(
dev);
155 simplebus_init(
dev, node);
163 rman_manage_region(&sc->
sc_mem_rman, 0, BUS_SPACE_MAXADDR) != 0)
164 panic(
"%s: failed to set up rmans.", __func__);
169 bus_generic_probe(
dev);
177 simplebus_add_device(
dev, node, 0, NULL, -1, NULL);
179 return (bus_generic_attach(
dev));
182static struct resource *
184 rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
189 struct resource_list_entry *rle;
190 int isdefault, passthrough;
192 isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
193 passthrough = (device_get_parent(
child) != bus);
194 sc = device_get_softc(bus);
196 if (!passthrough && isdefault) {
197 rle = resource_list_find(BUS_GET_RESOURCE_LIST(bus,
child),
201 device_printf(bus,
"no default resources for "
202 "rid = %d, type = %d\n", *rid, type);
206 count = ummax(count, rle->count);
207 end = ummax(rle->end, start + count - 1);
221 rv = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE,
225 rman_set_rid(rv, *rid);
227 if ((flags & RF_ACTIVE) != 0 && bus_activate_resource(
child, type,
229 rman_release_resource(rv);
233 if (!passthrough && rle != NULL) {
235 rle->start = rman_get_start(rv);
236 rle->end = rman_get_end(rv);
237 rle->count = rle->end - rle->start + 1;
245 struct resource *r, rman_res_t start, rman_res_t end)
252 while (strcmp(device_get_name(device_get_parent(ofwbus)),
"root") != 0)
253 ofwbus = device_get_parent(ofwbus);
254 sc = device_get_softc(ofwbus);
267 if (rman_is_region_manager(r, rm) == 0)
269 return (rman_adjust_resource(r, start, end));
274 int rid,
struct resource *r)
276 struct resource_list_entry *rle;
280 passthrough = (device_get_parent(
child) != bus);
283 rle = resource_list_find(BUS_GET_RESOURCE_LIST(bus,
child),
289 if ((rman_get_flags(r) & RF_ACTIVE) != 0) {
290 error = bus_deactivate_resource(
child, type, rid, r);
294 return (rman_release_resource(r));
METHOD phandle_t parent
Return parent of node.
METHOD phandle_t child
Return first child of node.
int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *obd, phandle_t node)
static bus_release_resource_t ofwbus_release_resource
static bus_alloc_resource_t ofwbus_alloc_resource
static device_attach_t ofwbus_attach
EARLY_DRIVER_MODULE(ofwbus, nexus, ofwbus_driver, ofwbus_devclass, 0, 0, BUS_PASS_BUS+BUS_PASS_ORDER_MIDDLE)
static device_identify_t ofwbus_identify
DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods, sizeof(struct ofwbus_softc), simplebus_driver)
MODULE_VERSION(ofwbus, 1)
static bus_adjust_resource_t ofwbus_adjust_resource
static device_method_t ofwbus_methods[]
static devclass_t ofwbus_devclass
static device_probe_t ofwbus_probe
phandle_t OF_peer(phandle_t node)
phandle_t OF_child(phandle_t node)
struct simplebus_softc simplebus_sc