Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/pci/pci_subr.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
pcib_host_res_free(device_t pcib, struct pcib_host_resources *hr) | pcib_host_res_free(device_t pcib, struct pcib_host_resources *hr) | ||||
{ | { | ||||
resource_list_free(&hr->hr_rl); | resource_list_free(&hr->hr_rl); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
pcib_host_res_decodes(struct pcib_host_resources *hr, int type, u_long start, | pcib_host_res_decodes(struct pcib_host_resources *hr, int type, rman_res_t start, | ||||
u_long end, u_int flags) | rman_res_t end, u_int flags) | ||||
{ | { | ||||
struct resource_list_entry *rle; | struct resource_list_entry *rle; | ||||
int rid; | int rid; | ||||
if (bootverbose) | if (bootverbose) | ||||
device_printf(hr->hr_pcib, "decoding %d %srange %#lx-%#lx\n", | device_printf(hr->hr_pcib, "decoding %d %srange %#jx-%#jx\n", | ||||
type, flags & RF_PREFETCHABLE ? "prefetchable ": "", start, | type, flags & RF_PREFETCHABLE ? "prefetchable ": "", start, | ||||
end); | end); | ||||
rid = resource_list_add_next(&hr->hr_rl, type, start, end, | rid = resource_list_add_next(&hr->hr_rl, type, start, end, | ||||
end - start + 1); | end - start + 1); | ||||
if (flags & RF_PREFETCHABLE) { | if (flags & RF_PREFETCHABLE) { | ||||
KASSERT(type == SYS_RES_MEMORY, | KASSERT(type == SYS_RES_MEMORY, | ||||
("only memory is prefetchable")); | ("only memory is prefetchable")); | ||||
rle = resource_list_find(&hr->hr_rl, type, rid); | rle = resource_list_find(&hr->hr_rl, type, rid); | ||||
rle->flags = RLE_PREFETCH; | rle->flags = RLE_PREFETCH; | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
struct resource * | struct resource * | ||||
pcib_host_res_alloc(struct pcib_host_resources *hr, device_t dev, int type, | pcib_host_res_alloc(struct pcib_host_resources *hr, device_t dev, 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_entry *rle; | struct resource_list_entry *rle; | ||||
struct resource *r; | struct resource *r; | ||||
u_long new_start, new_end; | rman_res_t new_start, new_end; | ||||
if (flags & RF_PREFETCHABLE) | if (flags & RF_PREFETCHABLE) | ||||
KASSERT(type == SYS_RES_MEMORY, | KASSERT(type == SYS_RES_MEMORY, | ||||
("only memory is prefetchable")); | ("only memory is prefetchable")); | ||||
rle = resource_list_find(&hr->hr_rl, type, 0); | rle = resource_list_find(&hr->hr_rl, type, 0); | ||||
if (rle == NULL) { | if (rle == NULL) { | ||||
/* | /* | ||||
* No decoding ranges for this resource type, just pass | * No decoding ranges for this resource type, just pass | ||||
* the request up to the parent. | * the request up to the parent. | ||||
*/ | */ | ||||
return (bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, | return (bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, | ||||
start, end, count, flags)); | start, end, count, flags)); | ||||
} | } | ||||
restart: | restart: | ||||
/* Try to allocate from each decoded range. */ | /* Try to allocate from each decoded range. */ | ||||
for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { | for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { | ||||
if (rle->type != type) | if (rle->type != type) | ||||
continue; | continue; | ||||
if (((flags & RF_PREFETCHABLE) != 0) != | if (((flags & RF_PREFETCHABLE) != 0) != | ||||
((rle->flags & RLE_PREFETCH) != 0)) | ((rle->flags & RLE_PREFETCH) != 0)) | ||||
continue; | continue; | ||||
new_start = ulmax(start, rle->start); | new_start = ummax(start, rle->start); | ||||
new_end = ulmin(end, rle->end); | new_end = ummin(end, rle->end); | ||||
if (new_start > new_end || | if (new_start > new_end || | ||||
new_start + count - 1 > new_end || | new_start + count - 1 > new_end || | ||||
new_start + count < new_start) | new_start + count < new_start) | ||||
continue; | continue; | ||||
r = bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, | r = bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, | ||||
new_start, new_end, count, flags); | new_start, new_end, count, flags); | ||||
if (r != NULL) { | if (r != NULL) { | ||||
if (bootverbose) | if (bootverbose) | ||||
device_printf(hr->hr_pcib, | device_printf(hr->hr_pcib, | ||||
"allocated type %d (%#lx-%#lx) for rid %x of %s\n", | "allocated type %d (%#jx-%#jx) for rid %x of %s\n", | ||||
type, rman_get_start(r), rman_get_end(r), | type, rman_get_start(r), rman_get_end(r), | ||||
*rid, pcib_child_name(dev)); | *rid, pcib_child_name(dev)); | ||||
return (r); | return (r); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* If we failed to find a prefetch range for a memory | * If we failed to find a prefetch range for a memory | ||||
* resource, try again without prefetch. | * resource, try again without prefetch. | ||||
*/ | */ | ||||
if (flags & RF_PREFETCHABLE) { | if (flags & RF_PREFETCHABLE) { | ||||
flags &= ~RF_PREFETCHABLE; | flags &= ~RF_PREFETCHABLE; | ||||
rle = resource_list_find(&hr->hr_rl, type, 0); | rle = resource_list_find(&hr->hr_rl, type, 0); | ||||
goto restart; | goto restart; | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
int | int | ||||
pcib_host_res_adjust(struct pcib_host_resources *hr, device_t dev, int type, | pcib_host_res_adjust(struct pcib_host_resources *hr, device_t dev, int type, | ||||
struct resource *r, u_long start, u_long end) | struct resource *r, rman_res_t start, rman_res_t end) | ||||
{ | { | ||||
struct resource_list_entry *rle; | struct resource_list_entry *rle; | ||||
rle = resource_list_find(&hr->hr_rl, type, 0); | rle = resource_list_find(&hr->hr_rl, type, 0); | ||||
if (rle == NULL) { | if (rle == NULL) { | ||||
/* | /* | ||||
* No decoding ranges for this resource type, just pass | * No decoding ranges for this resource type, just pass | ||||
* the request up to the parent. | * the request up to the parent. | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
error = rman_manage_region(&d->pd_bus_rman, 0, PCI_BUSMAX); | error = rman_manage_region(&d->pd_bus_rman, 0, PCI_BUSMAX); | ||||
if (error) | if (error) | ||||
panic("Failed to initialize PCI domain %d rman", domain); | panic("Failed to initialize PCI domain %d rman", domain); | ||||
TAILQ_INSERT_TAIL(&domains, d, pd_link); | TAILQ_INSERT_TAIL(&domains, d, pd_link); | ||||
return (d); | return (d); | ||||
} | } | ||||
struct resource * | struct resource * | ||||
pci_domain_alloc_bus(int domain, device_t dev, int *rid, u_long start, | pci_domain_alloc_bus(int domain, device_t dev, int *rid, rman_res_t start, | ||||
u_long end, u_long count, u_int flags) | rman_res_t end, rman_res_t count, u_int flags) | ||||
{ | { | ||||
struct pci_domain *d; | struct pci_domain *d; | ||||
struct resource *res; | struct resource *res; | ||||
if (domain < 0 || domain > PCI_DOMAINMAX) | if (domain < 0 || domain > PCI_DOMAINMAX) | ||||
return (NULL); | return (NULL); | ||||
d = pci_find_domain(domain); | d = pci_find_domain(domain); | ||||
res = rman_reserve_resource(&d->pd_bus_rman, start, end, count, flags, | res = rman_reserve_resource(&d->pd_bus_rman, start, end, count, flags, | ||||
dev); | dev); | ||||
if (res == NULL) | if (res == NULL) | ||||
return (NULL); | return (NULL); | ||||
rman_set_rid(res, *rid); | rman_set_rid(res, *rid); | ||||
return (res); | return (res); | ||||
} | } | ||||
int | int | ||||
pci_domain_adjust_bus(int domain, device_t dev, struct resource *r, | pci_domain_adjust_bus(int domain, device_t dev, struct resource *r, | ||||
u_long start, u_long end) | rman_res_t start, rman_res_t end) | ||||
{ | { | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
struct pci_domain *d; | struct pci_domain *d; | ||||
#endif | #endif | ||||
if (domain < 0 || domain > PCI_DOMAINMAX) | if (domain < 0 || domain > PCI_DOMAINMAX) | ||||
return (EINVAL); | return (EINVAL); | ||||
#ifdef INVARIANTS | #ifdef INVARIANTS | ||||
Show All 24 Lines |