Introduce a RMAN_IS_DEFAULT_RANGE() macro, and use it.
This simplifies checking for default resource range for bus_alloc_resource(), and improves readability. This is part of, and related to, the migration of rman_res_t from u_long to uintmax_t. Discussed with: jhb Suggested by: marcel
This commit is contained in:
parent
7a33cbc5f7
commit
f8385663ee
@ -164,7 +164,7 @@ at91_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
return (NULL);
|
||||
if (rle->res)
|
||||
panic("Resource rid %d type %d already in use", *rid, type);
|
||||
if (start == 0UL && end == ~0UL) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
start = rle->start;
|
||||
count = ulmax(count, rle->count);
|
||||
end = ulmax(rle->end, start + count - 1);
|
||||
|
@ -280,7 +280,7 @@ pinctrl_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Request for the default allocation with a given rid: use resource
|
||||
* list stored in the local device info.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -425,7 +425,7 @@ econa_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
}
|
||||
if (rle->res)
|
||||
panic("Resource rid %d type %d already in use", *rid, type);
|
||||
if (start == 0UL && end == ~0UL) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
start = rle->start;
|
||||
count = ulmax(count, rle->count);
|
||||
end = ulmax(rle->end, start + count - 1);
|
||||
|
@ -341,7 +341,7 @@ localbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Request for the default allocation with a given rid: use resource
|
||||
* list stored in the local device info.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -844,7 +844,7 @@ mv_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
type, rid, start, end, count, flags));
|
||||
};
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
start = sc->sc_mem_base;
|
||||
end = sc->sc_mem_base + sc->sc_mem_size - 1;
|
||||
count = sc->sc_mem_size;
|
||||
|
@ -211,7 +211,7 @@ arm_gic_fdt_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Request for the default allocation with a given rid: use resource
|
||||
* list stored in the local device info.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/bus.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/rman.h>
|
||||
|
||||
#include <machine/resource.h>
|
||||
|
||||
@ -180,7 +181,7 @@ gic_v3_ofw_bus_alloc_res(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list_entry *rle;
|
||||
int ranges_len;
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
if (type != SYS_RES_MEMORY)
|
||||
|
@ -223,7 +223,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* (ie. they aren't maintained by a child bus), then work out
|
||||
* the start/end values.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) {
|
||||
if (device_get_parent(child) != bus || ndev == NULL)
|
||||
return(NULL);
|
||||
rle = resource_list_find(&ndev->nx_resources, type, *rid);
|
||||
|
@ -292,7 +292,7 @@ thunder_pcie_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
type, rid, start, end, count, flags));
|
||||
};
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
|
||||
/* Read BAR manually to get resource address and size */
|
||||
pci_read_bar(child, *rid, &map, &testval, NULL);
|
||||
|
@ -283,7 +283,7 @@ thunder_pcie_ofw_bus_alloc_res(device_t bus, device_t child, int type, int *rid,
|
||||
|
||||
sc = device_get_softc(bus);
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
if (type == SYS_RES_IOPORT)
|
||||
|
@ -435,7 +435,7 @@ thunder_pem_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
end, count, flags));
|
||||
};
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
device_printf(dev,
|
||||
"Cannot allocate resource with unspecified range\n");
|
||||
goto fail;
|
||||
|
@ -1334,7 +1334,7 @@ acpi_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list_entry *rle;
|
||||
struct resource_list *rl;
|
||||
struct resource *res;
|
||||
int isdefault = (start == 0UL && end == ~0UL);
|
||||
int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
|
||||
/*
|
||||
* First attempt at allocating the resource. For direct children,
|
||||
|
@ -359,7 +359,7 @@ eisa_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
struct resource *rv, **rvp = 0;
|
||||
|
||||
isdefault = (device_get_parent(child) == dev &&
|
||||
start == 0UL && end == ~0UL && count == 1);
|
||||
RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
|
||||
switch (type) {
|
||||
case SYS_RES_IRQ:
|
||||
|
@ -335,7 +335,7 @@ simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Request for the default allocation with a given rid: use resource
|
||||
* list stored in the local device info.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -516,7 +516,7 @@ gpiobus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
|
||||
if (type != SYS_RES_IRQ)
|
||||
return (NULL);
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
rle = NULL;
|
||||
if (isdefault) {
|
||||
rl = BUS_GET_RESOURCE_LIST(bus, child);
|
||||
|
@ -463,7 +463,7 @@ mca_alloc_resource (device_t dev, device_t child, int type, int *rid,
|
||||
int isdefault;
|
||||
int passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != dev);
|
||||
|
||||
if (!passthrough && !isdefault) {
|
||||
|
@ -186,7 +186,7 @@ ofwbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list_entry *rle;
|
||||
int isdefault, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
sc = device_get_softc(bus);
|
||||
rle = NULL;
|
||||
|
@ -1137,7 +1137,7 @@ pccard_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
struct pccard_ivar *dinfo;
|
||||
struct resource_list_entry *rle = 0;
|
||||
int passthrough = (device_get_parent(child) != dev);
|
||||
int isdefault = (start == 0 && end == ~0UL && count == 1);
|
||||
int isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
struct resource *r = NULL;
|
||||
|
||||
/* XXX I'm no longer sure this is right */
|
||||
|
@ -383,7 +383,7 @@ siba_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
printf("%s: entry\n", __func__);
|
||||
#endif
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
rl = BUS_GET_RESOURCE_LIST(bus, child);
|
||||
rle = NULL;
|
||||
|
@ -139,7 +139,7 @@ mrmlb_ofw_bus_alloc_res(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list_entry *rle;
|
||||
int i;
|
||||
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
if (type == SYS_RES_IOPORT)
|
||||
|
@ -3311,7 +3311,7 @@ resource_list_alloc(struct resource_list *rl, device_t bus, device_t child,
|
||||
{
|
||||
struct resource_list_entry *rle = NULL;
|
||||
int passthrough = (device_get_parent(child) != bus);
|
||||
int isdefault = (start == 0UL && end == ~0UL);
|
||||
int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
|
||||
if (passthrough) {
|
||||
return (BUS_ALLOC_RESOURCE(device_get_parent(bus), child,
|
||||
|
@ -231,7 +231,7 @@ obio_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct rman *rm;
|
||||
int isdefault, needactivate, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
|
@ -232,7 +232,7 @@ obio_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct rman *rm;
|
||||
int isdefault, needactivate, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
|
@ -170,7 +170,7 @@ apb_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct rman *rm;
|
||||
int isdefault, needactivate, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end));
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
/*
|
||||
* Pass memory requests to nexus device
|
||||
|
@ -260,7 +260,7 @@ simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Request for the default allocation with a given rid: use resource
|
||||
* list stored in the local device info.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
if ((di = device_get_ivars(child)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
|
@ -165,7 +165,7 @@ obio_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct rman *rm;
|
||||
int isdefault, needactivate, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end));
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
|
@ -281,7 +281,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
(void *)(intptr_t)end, count, flags);
|
||||
dprintf("%s: requested rid is %d\n", __func__, *rid);
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
|
@ -192,7 +192,7 @@ xlp_simplebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
bustag = NULL;
|
||||
|
||||
if (!passthrough) {
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
if (isdefault) {
|
||||
rle = resource_list_find(&di->rl, type, *rid);
|
||||
if (rle == NULL)
|
||||
|
@ -287,7 +287,7 @@ obio_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct rman *rm;
|
||||
int isdefault, needactivate, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
needactivate = flags & RF_ACTIVE;
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
|
@ -288,7 +288,7 @@ zbbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list_entry *rle;
|
||||
struct zbbus_devinfo *dinfo;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL && count == 1);
|
||||
isdefault = (RMAN_IS_DEFAULT_RANGE(start, end) && count == 1);
|
||||
|
||||
/*
|
||||
* Our direct child is asking for a default resource allocation.
|
||||
|
@ -52,7 +52,7 @@ isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
struct resource_list *rl = &idev->id_resources;
|
||||
int isdefault, passthrough, rids;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL) ? 1 : 0;
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end) ? 1 : 0;
|
||||
passthrough = (device_get_parent(child) != bus) ? 1 : 0;
|
||||
|
||||
if (!passthrough && !isdefault &&
|
||||
|
@ -215,7 +215,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* (ie. they aren't maintained by a child bus), then work out
|
||||
* the start/end values.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) {
|
||||
if (device_get_parent(child) != bus || ndev == NULL)
|
||||
return(NULL);
|
||||
rle = resource_list_find(&ndev->nx_resources, type, *rid);
|
||||
|
@ -228,7 +228,7 @@ central_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
int passthrough;
|
||||
int i;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
res = NULL;
|
||||
rle = NULL;
|
||||
|
@ -438,7 +438,7 @@ ebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
uint64_t cend, cstart, offset;
|
||||
int i, isdefault, passthrough, ridx;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
sc = device_get_softc(bus);
|
||||
rl = BUS_GET_RESOURCE_LIST(bus, child);
|
||||
|
@ -433,7 +433,7 @@ fhc_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
int passthrough;
|
||||
int i;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
res = NULL;
|
||||
rle = NULL;
|
||||
|
@ -279,7 +279,7 @@ isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Consider adding a resource definition.
|
||||
*/
|
||||
int passthrough = (device_get_parent(child) != bus);
|
||||
int isdefault = (start == 0UL && end == ~0UL);
|
||||
int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
struct resource_list *rl;
|
||||
struct resource_list_entry *rle;
|
||||
u_long base, limit;
|
||||
|
@ -238,7 +238,7 @@ apb_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
* out where it's coming from (we should actually never see these) so
|
||||
* we just have to punt.
|
||||
*/
|
||||
if (start == 0 && end == ~0) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end)) {
|
||||
device_printf(dev, "can't decode default resource id %d for "
|
||||
"%s, bypassing\n", *rid, device_get_nameunit(child));
|
||||
goto passup;
|
||||
|
@ -723,7 +723,7 @@ sbus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
int i, slot;
|
||||
int isdefault, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
rle = NULL;
|
||||
sc = device_get_softc(bus);
|
||||
|
@ -370,7 +370,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
device_t nexus;
|
||||
int isdefault, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != bus);
|
||||
nexus = bus;
|
||||
while (strcmp(device_get_name(device_get_parent(nexus)), "root") != 0)
|
||||
|
@ -412,7 +412,7 @@ upa_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
bus_addr_t cend, cstart;
|
||||
int i, isdefault, passthrough;
|
||||
|
||||
isdefault = (start == 0UL && end == ~0UL);
|
||||
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
passthrough = (device_get_parent(child) != dev);
|
||||
sc = device_get_softc(dev);
|
||||
rl = BUS_GET_RESOURCE_LIST(dev, child);
|
||||
|
@ -63,6 +63,8 @@ enum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
|
||||
|
||||
#define RM_MAX_END ((rman_res_t)~0)
|
||||
|
||||
#define RMAN_IS_DEFAULT_RANGE(s,e) ((s) == 0 && (e) == RM_MAX_END)
|
||||
|
||||
/*
|
||||
* Userspace-exported structures.
|
||||
*/
|
||||
|
@ -94,7 +94,7 @@ isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* Consider adding a resource definition.
|
||||
*/
|
||||
int passthrough = (device_get_parent(child) != bus);
|
||||
int isdefault = (start == 0UL && end == ~0UL);
|
||||
int isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
||||
struct isa_device* idev = DEVTOISA(child);
|
||||
struct resource_list *rl = &idev->id_resources;
|
||||
struct resource_list_entry *rle;
|
||||
|
@ -377,7 +377,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
||||
* (ie. they aren't maintained by a child bus), then work out
|
||||
* the start/end values.
|
||||
*/
|
||||
if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
|
||||
if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) {
|
||||
if (device_get_parent(child) != bus || ndev == NULL)
|
||||
return(NULL);
|
||||
rle = resource_list_find(&ndev->nx_resources, type, *rid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user