Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/ofw/ofwbus.c
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
#ifndef __aarch64__ | #ifndef __aarch64__ | ||||
static device_identify_t ofwbus_identify; | static device_identify_t ofwbus_identify; | ||||
#endif | #endif | ||||
static device_probe_t ofwbus_probe; | static device_probe_t ofwbus_probe; | ||||
static device_attach_t ofwbus_attach; | static device_attach_t ofwbus_attach; | ||||
static bus_alloc_resource_t ofwbus_alloc_resource; | static bus_alloc_resource_t ofwbus_alloc_resource; | ||||
static bus_adjust_resource_t ofwbus_adjust_resource; | static bus_adjust_resource_t ofwbus_adjust_resource; | ||||
static bus_release_resource_t ofwbus_release_resource; | static bus_release_resource_t ofwbus_release_resource; | ||||
#ifdef INTRNG | |||||
static bus_map_intr_t ofwbus_map_intr; | |||||
#endif | |||||
static device_method_t ofwbus_methods[] = { | static device_method_t ofwbus_methods[] = { | ||||
/* Device interface */ | /* Device interface */ | ||||
#ifndef __aarch64__ | #ifndef __aarch64__ | ||||
DEVMETHOD(device_identify, ofwbus_identify), | DEVMETHOD(device_identify, ofwbus_identify), | ||||
#endif | #endif | ||||
DEVMETHOD(device_probe, ofwbus_probe), | DEVMETHOD(device_probe, ofwbus_probe), | ||||
DEVMETHOD(device_attach, ofwbus_attach), | DEVMETHOD(device_attach, ofwbus_attach), | ||||
/* Bus interface */ | /* Bus interface */ | ||||
DEVMETHOD(bus_alloc_resource, ofwbus_alloc_resource), | DEVMETHOD(bus_alloc_resource, ofwbus_alloc_resource), | ||||
DEVMETHOD(bus_adjust_resource, ofwbus_adjust_resource), | DEVMETHOD(bus_adjust_resource, ofwbus_adjust_resource), | ||||
DEVMETHOD(bus_release_resource, ofwbus_release_resource), | DEVMETHOD(bus_release_resource, ofwbus_release_resource), | ||||
#ifdef INTRNG | |||||
DEVMETHOD(bus_map_intr, ofwbus_map_intr), | |||||
#endif | |||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods, | DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods, | ||||
sizeof(struct ofwbus_softc), simplebus_driver); | sizeof(struct ofwbus_softc), simplebus_driver); | ||||
static devclass_t ofwbus_devclass; | static devclass_t ofwbus_devclass; | ||||
EARLY_DRIVER_MODULE(ofwbus, nexus, ofwbus_driver, ofwbus_devclass, 0, 0, | EARLY_DRIVER_MODULE(ofwbus, nexus, ofwbus_driver, ofwbus_devclass, 0, 0, | ||||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | ofwbus_release_resource(device_t bus, device_t child, int type, | ||||
if ((rman_get_flags(r) & RF_ACTIVE) != 0) { | if ((rman_get_flags(r) & RF_ACTIVE) != 0) { | ||||
error = bus_deactivate_resource(child, type, rid, r); | error = bus_deactivate_resource(child, type, rid, r); | ||||
if (error) | if (error) | ||||
return (error); | return (error); | ||||
} | } | ||||
return (rman_release_resource(r)); | return (rman_release_resource(r)); | ||||
} | } | ||||
#ifdef INTRNG | |||||
static void | |||||
ofwbus_destruct_map_data(struct intr_map_data *map_data) | |||||
{ | |||||
struct intr_map_data_fdt *fdt_map_data; | |||||
KASSERT(map_data->type == INTR_MAP_DATA_FDT, | |||||
("%s: bad map_data type %d", __func__, map_data->type)); | |||||
fdt_map_data = (struct intr_map_data_fdt *)map_data; | |||||
OF_prop_free(fdt_map_data->cells); | |||||
free(fdt_map_data, M_OFWPROP); | |||||
} | |||||
static int | |||||
ofwbus_map_intr(device_t bus, device_t child, int *rid, rman_res_t *start, | |||||
rman_res_t *end, rman_res_t *count, struct intr_map_data **imd) | |||||
{ | |||||
phandle_t iparent, node; | |||||
pcell_t *cells; | |||||
int ncells, rv; | |||||
u_int irq; | |||||
struct intr_map_data_fdt *fdt_data; | |||||
node = ofw_bus_get_node(child); | |||||
rv = ofw_bus_intr_by_rid(child, node, *rid, &iparent, &ncells, &cells); | |||||
if (rv != 0) | |||||
return (rv); | |||||
fdt_data = malloc(sizeof(*fdt_data), M_OFWPROP, M_WAITOK | M_ZERO); | |||||
fdt_data->hdr.type = INTR_MAP_DATA_FDT; | |||||
fdt_data->hdr.destruct = ofwbus_destruct_map_data; | |||||
fdt_data->iparent = iparent; | |||||
fdt_data->ncells = ncells; | |||||
fdt_data->cells = cells; | |||||
rv = intr_map_irq(NULL, iparent, (struct intr_map_data *)fdt_data, | |||||
&irq); | |||||
if (rv != 0) { | |||||
ofwbus_destruct_map_data((struct intr_map_data *)fdt_data); | |||||
return (rv); | |||||
} | |||||
*start = irq; | |||||
*end = irq; | |||||
*count = 1; | |||||
*imd = (struct intr_map_data *)fdt_data; | |||||
return (0); | |||||
} | |||||
#endif |