Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/bhnd/cores/chipc/chipc_subr.c
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | chipc_init_child_resource(struct resource *r, | ||||
rman_set_virtual(r, (void *) vaddr); | rman_set_virtual(r, (void *) vaddr); | ||||
rman_set_bustag(r, bt); | rman_set_bustag(r, bt); | ||||
rman_set_bushandle(r, child_bh); | rman_set_bushandle(r, child_bh); | ||||
return (0); | return (0); | ||||
} | } | ||||
/** | /** | ||||
* Associate a resource with a given resource ID, relative to the given | * Map an interrupt line to an IRQ, and then register a corresponding SYS_RES_IRQ | ||||
* port and region. | * with @p child's resource list. | ||||
* | * | ||||
* This function behaves identically to bus_set_resource() for all resource | * @param sc chipc driver state. | ||||
* types other than SYS_RES_MEMORY. | * @param child The device to set the resource on. | ||||
* @param rid The resource ID. | |||||
* @param intr The interrupt line to be mapped. | |||||
* @param count The length of the resource. | |||||
* @param port The mapping port number (ignored if not SYS_RES_MEMORY). | |||||
* @param region The mapping region number (ignored if not SYS_RES_MEMORY). | |||||
*/ | |||||
int | |||||
chipc_set_irq_resource(struct chipc_softc *sc, device_t child, int rid, | |||||
u_int intr) | |||||
{ | |||||
struct chipc_devinfo *dinfo; | |||||
int error; | |||||
KASSERT(device_get_parent(child) == sc->dev, ("not a direct child")); | |||||
dinfo = device_get_ivars(child); | |||||
/* We currently only support a single IRQ mapping */ | |||||
if (dinfo->irq_mapped) { | |||||
device_printf(sc->dev, "irq already mapped for child\n"); | |||||
return (ENOMEM); | |||||
} | |||||
/* Map the IRQ */ | |||||
if ((error = bhnd_map_intr(sc->dev, intr, &dinfo->irq))) { | |||||
device_printf(sc->dev, "failed to map intr %u: %d\n", intr, | |||||
error); | |||||
return (error); | |||||
} | |||||
dinfo->irq_mapped = true; | |||||
/* Add to child's resource list */ | |||||
error = bus_set_resource(child, SYS_RES_IRQ, rid, dinfo->irq, 1); | |||||
if (error) { | |||||
device_printf(sc->dev, "failed to set child irq resource %d to " | |||||
"%ju: %d\n", rid, dinfo->irq, error); | |||||
bhnd_unmap_intr(sc->dev, dinfo->irq); | |||||
return (error); | |||||
} | |||||
return (0); | |||||
} | |||||
/** | |||||
* Add a SYS_RES_MEMORY resource with a given resource ID, relative to the | |||||
* given port and region, to @p child's resource list. | |||||
* | * | ||||
* For SYS_RES_MEMORY resources, the specified @p region's address and size | * The specified @p region's address and size will be fetched from the bhnd(4) | ||||
* will be fetched from the bhnd(4) bus, and bus_set_resource() will be called | * bus, and bus_set_resource() will be called with @p start added the region's | ||||
* with @p start added the region's actual base address. | * actual base address. | ||||
* | * | ||||
* To use the default region values for @p start and @p count, specify | * To use the default region values for @p start and @p count, specify | ||||
* a @p start value of 0ul, and an end value of RMAN_MAX_END | * a @p start value of 0ul, and an end value of RMAN_MAX_END | ||||
* | * | ||||
* @param sc chipc driver state. | * @param sc chipc driver state. | ||||
* @param child The device to set the resource on. | * @param child The device to set the resource on. | ||||
* @param type The resource type. | |||||
* @param rid The resource ID. | * @param rid The resource ID. | ||||
* @param start The resource start address (if SYS_RES_MEMORY, this is | * @param start The resource start address (if SYS_RES_MEMORY, this is | ||||
* relative to @p region's base address). | * relative to @p region's base address). | ||||
* @param count The length of the resource. | * @param count The length of the resource. | ||||
* @param port The mapping port number (ignored if not SYS_RES_MEMORY). | * @param port The mapping port number (ignored if not SYS_RES_MEMORY). | ||||
* @param region The mapping region number (ignored if not SYS_RES_MEMORY). | * @param region The mapping region number (ignored if not SYS_RES_MEMORY). | ||||
*/ | */ | ||||
int | int | ||||
chipc_set_resource(struct chipc_softc *sc, device_t child, int type, int rid, | chipc_set_mem_resource(struct chipc_softc *sc, device_t child, int rid, | ||||
rman_res_t start, rman_res_t count, u_int port, u_int region) | rman_res_t start, rman_res_t count, u_int port, u_int region) | ||||
{ | { | ||||
bhnd_addr_t region_addr; | bhnd_addr_t region_addr; | ||||
bhnd_size_t region_size; | bhnd_size_t region_size; | ||||
bool isdefault; | bool isdefault; | ||||
int error; | int error; | ||||
if (type != SYS_RES_MEMORY) | KASSERT(device_get_parent(child) == sc->dev, ("not a direct child")); | ||||
return (bus_set_resource(child, type, rid, start, count)); | |||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, count); | isdefault = RMAN_IS_DEFAULT_RANGE(start, count); | ||||
/* Fetch region address and size */ | /* Fetch region address and size */ | ||||
error = bhnd_get_region_addr(sc->dev, BHND_PORT_DEVICE, port, | error = bhnd_get_region_addr(sc->dev, BHND_PORT_DEVICE, port, | ||||
region, ®ion_addr, ®ion_size); | region, ®ion_addr, ®ion_size); | ||||
if (error) { | if (error) { | ||||
device_printf(sc->dev, | device_printf(sc->dev, | ||||
"lookup of %s%u.%u failed: %d\n", | "lookup of %s%u.%u failed: %d\n", | ||||
Show All 11 Lines | chipc_set_mem_resource(struct chipc_softc *sc, device_t child, int rid, | ||||
if (start > region_size || region_size - start < count) { | if (start > region_size || region_size - start < count) { | ||||
device_printf(sc->dev, | device_printf(sc->dev, | ||||
"%s%u.%u region cannot map requested range %#jx+%#jx\n", | "%s%u.%u region cannot map requested range %#jx+%#jx\n", | ||||
bhnd_port_type_name(BHND_PORT_DEVICE), port, region, start, | bhnd_port_type_name(BHND_PORT_DEVICE), port, region, start, | ||||
count); | count); | ||||
return (ERANGE); | return (ERANGE); | ||||
} | } | ||||
return (bus_set_resource(child, type, rid, region_addr + start, count)); | return (bus_set_resource(child, SYS_RES_MEMORY, rid, | ||||
region_addr + start, count)); | |||||
} | } | ||||
/* | /* | ||||
* Print a capability structure. | * Print a capability structure. | ||||
*/ | */ | ||||
void | void | ||||
chipc_print_caps(device_t dev, struct chipc_caps *caps) | chipc_print_caps(device_t dev, struct chipc_caps *caps) | ||||
▲ Show 20 Lines • Show All 290 Lines • Show Last 20 Lines |