Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/subr_bus.c
Show First 20 Lines • Show All 3,057 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @param rl the resource list to edit | * @param rl the resource list to edit | ||||
* @param type the resource entry type (e.g. SYS_RES_MEMORY) | * @param type the resource entry type (e.g. SYS_RES_MEMORY) | ||||
* @param start the start address of the resource | * @param start the start address of the resource | ||||
* @param end the end address of the resource | * @param end the end address of the resource | ||||
* @param count XXX end-start+1 | * @param count XXX end-start+1 | ||||
*/ | */ | ||||
int | int | ||||
resource_list_add_next(struct resource_list *rl, int type, u_long start, | resource_list_add_next(struct resource_list *rl, int type, rman_res_t start, | ||||
u_long end, u_long count) | rman_res_t end, rman_res_t count) | ||||
{ | { | ||||
int rid; | int rid; | ||||
rid = 0; | rid = 0; | ||||
while (resource_list_find(rl, type, rid) != NULL) | while (resource_list_find(rl, type, rid) != NULL) | ||||
rid++; | rid++; | ||||
resource_list_add(rl, type, rid, start, end, count); | resource_list_add(rl, type, rid, start, end, count); | ||||
return (rid); | return (rid); | ||||
Show All 11 Lines | |||||
* @param type the resource entry type (e.g. SYS_RES_MEMORY) | * @param type the resource entry type (e.g. SYS_RES_MEMORY) | ||||
* @param rid the resource identifier | * @param rid the resource identifier | ||||
* @param start the start address of the resource | * @param start the start address of the resource | ||||
* @param end the end address of the resource | * @param end the end address of the resource | ||||
* @param count XXX end-start+1 | * @param count XXX end-start+1 | ||||
*/ | */ | ||||
struct resource_list_entry * | struct resource_list_entry * | ||||
resource_list_add(struct resource_list *rl, int type, int rid, | resource_list_add(struct resource_list *rl, int type, int rid, | ||||
u_long start, u_long end, u_long count) | rman_res_t start, rman_res_t end, rman_res_t count) | ||||
{ | { | ||||
struct resource_list_entry *rle; | struct resource_list_entry *rle; | ||||
rle = resource_list_find(rl, type, rid); | rle = resource_list_find(rl, type, rid); | ||||
if (!rle) { | if (!rle) { | ||||
rle = malloc(sizeof(struct resource_list_entry), M_BUS, | rle = malloc(sizeof(struct resource_list_entry), M_BUS, | ||||
M_NOWAIT); | M_NOWAIT); | ||||
if (!rle) | if (!rle) | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | |||||
* allocation - see @c RF_XXX flags in | * allocation - see @c RF_XXX flags in | ||||
* <sys/rman.h> for details | * <sys/rman.h> for details | ||||
* | * | ||||
* @returns the resource which was allocated or @c NULL if no | * @returns the resource which was allocated or @c NULL if no | ||||
* resource could be allocated | * resource could be allocated | ||||
*/ | */ | ||||
struct resource * | struct resource * | ||||
resource_list_reserve(struct resource_list *rl, device_t bus, device_t child, | resource_list_reserve(struct resource_list *rl, device_t bus, device_t child, | ||||
int type, int *rid, u_long start, u_long end, u_long count, u_int flags) | int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
struct resource_list_entry *rle = NULL; | struct resource_list_entry *rle = NULL; | ||||
int passthrough = (device_get_parent(child) != bus); | int passthrough = (device_get_parent(child) != bus); | ||||
struct resource *r; | struct resource *r; | ||||
if (passthrough) | if (passthrough) | ||||
panic( | panic( | ||||
"resource_list_reserve() should only be called for direct children"); | "resource_list_reserve() should only be called for direct children"); | ||||
Show All 40 Lines | |||||
* allocation - see @c RF_XXX flags in | * allocation - see @c RF_XXX flags in | ||||
* <sys/rman.h> for details | * <sys/rman.h> for details | ||||
* | * | ||||
* @returns the resource which was allocated or @c NULL if no | * @returns the resource which was allocated or @c NULL if no | ||||
* resource could be allocated | * resource could be allocated | ||||
*/ | */ | ||||
struct resource * | struct resource * | ||||
resource_list_alloc(struct resource_list *rl, device_t bus, device_t child, | resource_list_alloc(struct resource_list *rl, device_t bus, device_t child, | ||||
int type, int *rid, u_long start, u_long end, u_long count, u_int flags) | int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
struct resource_list_entry *rle = NULL; | struct resource_list_entry *rle = NULL; | ||||
int passthrough = (device_get_parent(child) != bus); | int passthrough = (device_get_parent(child) != bus); | ||||
int isdefault = (start == 0UL && end == ~0UL); | int isdefault = (start == 0UL && end == ~0UL); | ||||
if (passthrough) { | if (passthrough) { | ||||
return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child, | return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child, | ||||
type, rid, start, end, count, flags)); | type, rid, start, end, count, flags)); | ||||
▲ Show 20 Lines • Show All 625 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* @brief Helper function for implementing BUS_ADJUST_RESOURCE(). | * @brief Helper function for implementing BUS_ADJUST_RESOURCE(). | ||||
* | * | ||||
* This simple implementation of BUS_ADJUST_RESOURCE() simply calls the | * This simple implementation of BUS_ADJUST_RESOURCE() simply calls the | ||||
* BUS_ADJUST_RESOURCE() method of the parent of @p dev. | * BUS_ADJUST_RESOURCE() method of the parent of @p dev. | ||||
*/ | */ | ||||
int | int | ||||
bus_generic_adjust_resource(device_t dev, device_t child, int type, | bus_generic_adjust_resource(device_t dev, device_t child, int type, | ||||
struct resource *r, u_long start, u_long end) | struct resource *r, rman_res_t start, rman_res_t end) | ||||
{ | { | ||||
/* Propagate up the bus hierarchy until someone handles it. */ | /* Propagate up the bus hierarchy until someone handles it. */ | ||||
if (dev->parent) | if (dev->parent) | ||||
return (BUS_ADJUST_RESOURCE(dev->parent, child, type, r, start, | return (BUS_ADJUST_RESOURCE(dev->parent, child, type, r, start, | ||||
end)); | end)); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
/** | /** | ||||
* @brief Helper function for implementing BUS_ALLOC_RESOURCE(). | * @brief Helper function for implementing BUS_ALLOC_RESOURCE(). | ||||
* | * | ||||
* This simple implementation of BUS_ALLOC_RESOURCE() simply calls the | * This simple implementation of BUS_ALLOC_RESOURCE() simply calls the | ||||
* BUS_ALLOC_RESOURCE() method of the parent of @p dev. | * BUS_ALLOC_RESOURCE() method of the parent of @p dev. | ||||
*/ | */ | ||||
struct resource * | struct resource * | ||||
bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid, | bus_generic_alloc_resource(device_t dev, device_t child, int type, int *rid, | ||||
u_long start, u_long end, u_long count, u_int flags) | rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
/* Propagate up the bus hierarchy until someone handles it. */ | /* Propagate up the bus hierarchy until someone handles it. */ | ||||
if (dev->parent) | if (dev->parent) | ||||
return (BUS_ALLOC_RESOURCE(dev->parent, child, type, rid, | return (BUS_ALLOC_RESOURCE(dev->parent, child, type, rid, | ||||
start, end, count, flags)); | start, end, count, flags)); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* This implementation of BUS_GET_RESOURCE() uses the | * This implementation of BUS_GET_RESOURCE() uses the | ||||
* resource_list_find() function to do most of the work. It calls | * resource_list_find() function to do most of the work. It calls | ||||
* BUS_GET_RESOURCE_LIST() to find a suitable resource list to | * BUS_GET_RESOURCE_LIST() to find a suitable resource list to | ||||
* search. | * search. | ||||
*/ | */ | ||||
int | int | ||||
bus_generic_rl_get_resource(device_t dev, device_t child, int type, int rid, | bus_generic_rl_get_resource(device_t dev, device_t child, int type, int rid, | ||||
u_long *startp, u_long *countp) | rman_res_t *startp, rman_res_t *countp) | ||||
{ | { | ||||
struct resource_list * rl = NULL; | struct resource_list * rl = NULL; | ||||
struct resource_list_entry * rle = NULL; | struct resource_list_entry * rle = NULL; | ||||
rl = BUS_GET_RESOURCE_LIST(dev, child); | rl = BUS_GET_RESOURCE_LIST(dev, child); | ||||
if (!rl) | if (!rl) | ||||
return (EINVAL); | return (EINVAL); | ||||
Show All 14 Lines | |||||
* | * | ||||
* This implementation of BUS_SET_RESOURCE() uses the | * This implementation of BUS_SET_RESOURCE() uses the | ||||
* resource_list_add() function to do most of the work. It calls | * resource_list_add() function to do most of the work. It calls | ||||
* BUS_GET_RESOURCE_LIST() to find a suitable resource list to | * BUS_GET_RESOURCE_LIST() to find a suitable resource list to | ||||
* edit. | * edit. | ||||
*/ | */ | ||||
int | int | ||||
bus_generic_rl_set_resource(device_t dev, device_t child, int type, int rid, | bus_generic_rl_set_resource(device_t dev, device_t child, int type, int rid, | ||||
u_long start, u_long count) | rman_res_t start, rman_res_t count) | ||||
{ | { | ||||
struct resource_list * rl = NULL; | struct resource_list * rl = NULL; | ||||
rl = BUS_GET_RESOURCE_LIST(dev, child); | rl = BUS_GET_RESOURCE_LIST(dev, child); | ||||
if (!rl) | if (!rl) | ||||
return (EINVAL); | return (EINVAL); | ||||
resource_list_add(rl, type, rid, start, (start + count - 1), count); | resource_list_add(rl, type, rid, start, (start + count - 1), count); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
* @brief Helper function for implementing BUS_ALLOC_RESOURCE(). | * @brief Helper function for implementing BUS_ALLOC_RESOURCE(). | ||||
* | * | ||||
* This implementation of BUS_ALLOC_RESOURCE() uses the | * This implementation of BUS_ALLOC_RESOURCE() uses the | ||||
* resource_list_alloc() function to do most of the work. It calls | * resource_list_alloc() function to do most of the work. It calls | ||||
* BUS_GET_RESOURCE_LIST() to find a suitable resource list. | * BUS_GET_RESOURCE_LIST() to find a suitable resource list. | ||||
*/ | */ | ||||
struct resource * | struct resource * | ||||
bus_generic_rl_alloc_resource(device_t dev, device_t child, int type, | bus_generic_rl_alloc_resource(device_t dev, device_t child, int type, | ||||
int *rid, u_long start, u_long end, u_long count, u_int flags) | int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
struct resource_list * rl = NULL; | struct resource_list * rl = NULL; | ||||
if (device_get_parent(child) != dev) | if (device_get_parent(child) != dev) | ||||
return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, | return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, | ||||
type, rid, start, end, count, flags)); | type, rid, start, end, count, flags)); | ||||
rl = BUS_GET_RESOURCE_LIST(dev, child); | rl = BUS_GET_RESOURCE_LIST(dev, child); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* @brief Wrapper function for BUS_ALLOC_RESOURCE(). | * @brief Wrapper function for BUS_ALLOC_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_ALLOC_RESOURCE() method of the | * This function simply calls the BUS_ALLOC_RESOURCE() method of the | ||||
* parent of @p dev. | * parent of @p dev. | ||||
*/ | */ | ||||
struct resource * | struct resource * | ||||
bus_alloc_resource(device_t dev, int type, int *rid, u_long start, u_long end, | bus_alloc_resource(device_t dev, int type, int *rid, rman_res_t start, rman_res_t end, | ||||
u_long count, u_int flags) | rman_res_t count, u_int flags) | ||||
{ | { | ||||
if (dev->parent == NULL) | if (dev->parent == NULL) | ||||
return (NULL); | return (NULL); | ||||
return (BUS_ALLOC_RESOURCE(dev->parent, dev, type, rid, start, end, | return (BUS_ALLOC_RESOURCE(dev->parent, dev, type, rid, start, end, | ||||
count, flags)); | count, flags)); | ||||
} | } | ||||
/** | /** | ||||
* @brief Wrapper function for BUS_ADJUST_RESOURCE(). | * @brief Wrapper function for BUS_ADJUST_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_ADJUST_RESOURCE() method of the | * This function simply calls the BUS_ADJUST_RESOURCE() method of the | ||||
* parent of @p dev. | * parent of @p dev. | ||||
*/ | */ | ||||
int | int | ||||
bus_adjust_resource(device_t dev, int type, struct resource *r, u_long start, | bus_adjust_resource(device_t dev, int type, struct resource *r, rman_res_t start, | ||||
u_long end) | rman_res_t end) | ||||
{ | { | ||||
if (dev->parent == NULL) | if (dev->parent == NULL) | ||||
return (EINVAL); | return (EINVAL); | ||||
return (BUS_ADJUST_RESOURCE(dev->parent, dev, type, r, start, end)); | return (BUS_ADJUST_RESOURCE(dev->parent, dev, type, r, start, end)); | ||||
} | } | ||||
/** | /** | ||||
* @brief Wrapper function for BUS_ACTIVATE_RESOURCE(). | * @brief Wrapper function for BUS_ACTIVATE_RESOURCE(). | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* @brief Wrapper function for BUS_SET_RESOURCE(). | * @brief Wrapper function for BUS_SET_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_SET_RESOURCE() method of the | * This function simply calls the BUS_SET_RESOURCE() method of the | ||||
* parent of @p dev. | * parent of @p dev. | ||||
*/ | */ | ||||
int | int | ||||
bus_set_resource(device_t dev, int type, int rid, | bus_set_resource(device_t dev, int type, int rid, | ||||
u_long start, u_long count) | rman_res_t start, rman_res_t count) | ||||
{ | { | ||||
return (BUS_SET_RESOURCE(device_get_parent(dev), dev, type, rid, | return (BUS_SET_RESOURCE(device_get_parent(dev), dev, type, rid, | ||||
start, count)); | start, count)); | ||||
} | } | ||||
/** | /** | ||||
* @brief Wrapper function for BUS_GET_RESOURCE(). | * @brief Wrapper function for BUS_GET_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_GET_RESOURCE() method of the | * This function simply calls the BUS_GET_RESOURCE() method of the | ||||
* parent of @p dev. | * parent of @p dev. | ||||
*/ | */ | ||||
int | int | ||||
bus_get_resource(device_t dev, int type, int rid, | bus_get_resource(device_t dev, int type, int rid, | ||||
u_long *startp, u_long *countp) | rman_res_t *startp, rman_res_t *countp) | ||||
{ | { | ||||
return (BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | return (BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | ||||
startp, countp)); | startp, countp)); | ||||
} | } | ||||
/** | /** | ||||
* @brief Wrapper function for BUS_GET_RESOURCE(). | * @brief Wrapper function for BUS_GET_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_GET_RESOURCE() method of the | * This function simply calls the BUS_GET_RESOURCE() method of the | ||||
* parent of @p dev and returns the start value. | * parent of @p dev and returns the start value. | ||||
*/ | */ | ||||
u_long | rman_res_t | ||||
bus_get_resource_start(device_t dev, int type, int rid) | bus_get_resource_start(device_t dev, int type, int rid) | ||||
{ | { | ||||
u_long start, count; | rman_res_t start; | ||||
rman_res_t count; | |||||
int error; | int error; | ||||
error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | ||||
&start, &count); | &start, &count); | ||||
if (error) | if (error) | ||||
return (0); | return (0); | ||||
return (start); | return (start); | ||||
} | } | ||||
/** | /** | ||||
* @brief Wrapper function for BUS_GET_RESOURCE(). | * @brief Wrapper function for BUS_GET_RESOURCE(). | ||||
* | * | ||||
* This function simply calls the BUS_GET_RESOURCE() method of the | * This function simply calls the BUS_GET_RESOURCE() method of the | ||||
* parent of @p dev and returns the count value. | * parent of @p dev and returns the count value. | ||||
*/ | */ | ||||
u_long | rman_res_t | ||||
bus_get_resource_count(device_t dev, int type, int rid) | bus_get_resource_count(device_t dev, int type, int rid) | ||||
{ | { | ||||
u_long start, count; | rman_res_t start; | ||||
rman_res_t count; | |||||
int error; | int error; | ||||
error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | error = BUS_GET_RESOURCE(device_get_parent(dev), dev, type, rid, | ||||
&start, &count); | &start, &count); | ||||
if (error) | if (error) | ||||
return (0); | return (0); | ||||
return (count); | return (count); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 814 Lines • Show Last 20 Lines |