Reduce code duplication by using the GET_RESOURCE_LIST bus method and related
generic resource_list management functions. I'll deal with the EISA bits later. Not objected to by: new-bus
This commit is contained in:
parent
c18bb8265f
commit
2237cef468
@ -495,51 +495,16 @@ mca_alloc_resource (device_t dev, device_t child, int type, int *rid,
|
||||
start, end, count, flags));
|
||||
}
|
||||
|
||||
static int
|
||||
mca_release_resource (device_t dev, device_t child, int type, int rid,
|
||||
struct resource * r)
|
||||
static struct resource_list *
|
||||
mca_get_resource_list (device_t dev, device_t child)
|
||||
{
|
||||
struct mca_device * m_dev = device_get_ivars(child);
|
||||
|
||||
return (resource_list_release(&(m_dev->rl), dev, child, type, rid, r));
|
||||
}
|
||||
|
||||
static int
|
||||
mca_get_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long *startp, u_long *countp)
|
||||
{
|
||||
struct mca_device * m_dev = device_get_ivars(child);
|
||||
struct resource_list * rl = &(m_dev->rl);
|
||||
struct resource_list_entry * rle;
|
||||
|
||||
rle = resource_list_find(rl, type, rid);
|
||||
if (!rle)
|
||||
return ENOENT;
|
||||
|
||||
*startp = rle->start;
|
||||
*countp = rle->count;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mca_set_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long start, u_long count)
|
||||
{
|
||||
struct mca_device * m_dev = device_get_ivars(child);
|
||||
struct resource_list * rl = &(m_dev->rl);
|
||||
|
||||
resource_list_add(rl, type, rid, start, start + count - 1, count);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
mca_delete_resource(device_t dev, device_t child, int type, int rid)
|
||||
{
|
||||
struct mca_device * m_dev = device_get_ivars(child);
|
||||
struct resource_list * rl = &(m_dev->rl);
|
||||
|
||||
resource_list_delete(rl, type, rid);
|
||||
struct mca_device * m_dev = device_get_ivars(child);
|
||||
struct resource_list * rl = &m_dev->rl;
|
||||
|
||||
if (!rl)
|
||||
return (ENOENT);
|
||||
|
||||
return (rl);
|
||||
}
|
||||
|
||||
static device_method_t mca_methods[] = {
|
||||
@ -554,18 +519,19 @@ static device_method_t mca_methods[] = {
|
||||
DEVMETHOD(bus_print_child, mca_print_child),
|
||||
DEVMETHOD(bus_probe_nomatch, mca_probe_nomatch),
|
||||
DEVMETHOD(bus_read_ivar, mca_read_ivar),
|
||||
DEVMETHOD(bus_write_ivar, mca_write_ivar),
|
||||
DEVMETHOD(bus_write_ivar, bus_generic_write_ivar),
|
||||
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
||||
DEVMETHOD(bus_alloc_resource, mca_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, mca_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
||||
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
||||
|
||||
DEVMETHOD(bus_set_resource, mca_set_resource),
|
||||
DEVMETHOD(bus_get_resource, mca_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, mca_delete_resource),
|
||||
DEVMETHOD(bus_get_resource_list,mca_get_resource_list),
|
||||
DEVMETHOD(bus_alloc_resource, mca_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
|
||||
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
||||
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
|
||||
DEVMETHOD(bus_activate_resource,bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
@ -1327,53 +1327,24 @@ pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
start, end, count, flags);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_release_resource(device_t dev, device_t child, int type, int rid,
|
||||
struct resource *r)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
|
||||
return resource_list_release(rl, dev, child, type, rid, r);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_set_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long start, u_long count)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
|
||||
resource_list_add(rl, type, rid, start, start + count - 1, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pci_get_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long *startp, u_long *countp)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
struct resource_list_entry *rle;
|
||||
|
||||
rle = resource_list_find(rl, type, rid);
|
||||
if (!rle)
|
||||
return ENOENT;
|
||||
|
||||
if (startp)
|
||||
*startp = rle->start;
|
||||
if (countp)
|
||||
*countp = rle->count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pci_delete_resource(device_t dev, device_t child, int type, int rid)
|
||||
{
|
||||
printf("pci_delete_resource: PCI resources can not be deleted\n");
|
||||
}
|
||||
|
||||
static struct resource_list *
|
||||
pci_get_resource_list (device_t dev, device_t child)
|
||||
{
|
||||
struct pci_devinfo * dinfo = device_get_ivars(child);
|
||||
struct resource_list * rl = &dinfo->resources;
|
||||
|
||||
if (!rl)
|
||||
return (NULL);
|
||||
|
||||
return (rl);
|
||||
}
|
||||
|
||||
static u_int32_t
|
||||
pci_read_config_method(device_t dev, device_t child, int reg, int width)
|
||||
{
|
||||
@ -1426,15 +1397,17 @@ static device_method_t pci_methods[] = {
|
||||
DEVMETHOD(bus_read_ivar, pci_read_ivar),
|
||||
DEVMETHOD(bus_write_ivar, pci_write_ivar),
|
||||
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
||||
DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, pci_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
||||
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
||||
DEVMETHOD(bus_set_resource, pci_set_resource),
|
||||
DEVMETHOD(bus_get_resource, pci_get_resource),
|
||||
|
||||
DEVMETHOD(bus_get_resource_list,pci_get_resource_list),
|
||||
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
||||
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, pci_delete_resource),
|
||||
DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
|
||||
/* PCI interface */
|
||||
DEVMETHOD(pci_read_config, pci_read_config_method),
|
||||
|
@ -907,32 +907,16 @@ isa_set_resource(device_t dev, device_t child, int type, int rid,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
isa_get_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long *startp, u_long *countp)
|
||||
static struct resource_list *
|
||||
isa_get_resource_list (device_t dev, device_t child)
|
||||
{
|
||||
struct isa_device* idev = DEVTOISA(child);
|
||||
struct resource_list *rl = &idev->id_resources;
|
||||
struct resource_list_entry *rle;
|
||||
|
||||
rle = resource_list_find(rl, type, rid);
|
||||
if (!rle)
|
||||
return ENOENT;
|
||||
|
||||
if (startp)
|
||||
*startp = rle->start;
|
||||
if (countp)
|
||||
*countp = rle->count;
|
||||
if (!rl)
|
||||
return (NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
isa_delete_resource(device_t dev, device_t child, int type, int rid)
|
||||
{
|
||||
struct isa_device* idev = DEVTOISA(child);
|
||||
struct resource_list *rl = &idev->id_resources;
|
||||
resource_list_delete(rl, type, rid);
|
||||
return (rl);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1012,15 +996,17 @@ static device_method_t isa_methods[] = {
|
||||
DEVMETHOD(bus_write_ivar, isa_write_ivar),
|
||||
DEVMETHOD(bus_child_detached, isa_child_detached),
|
||||
DEVMETHOD(bus_driver_added, isa_driver_added),
|
||||
DEVMETHOD(bus_alloc_resource, isa_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, isa_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
DEVMETHOD(bus_setup_intr, isa_setup_intr),
|
||||
DEVMETHOD(bus_teardown_intr, isa_teardown_intr),
|
||||
|
||||
DEVMETHOD(bus_get_resource_list,isa_get_resource_list),
|
||||
DEVMETHOD(bus_alloc_resource, isa_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, isa_release_resource),
|
||||
DEVMETHOD(bus_set_resource, isa_set_resource),
|
||||
DEVMETHOD(bus_get_resource, isa_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, isa_delete_resource),
|
||||
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
|
||||
/* ISA interface */
|
||||
DEVMETHOD(isa_add_config, isa_add_config),
|
||||
|
@ -1327,53 +1327,24 @@ pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
||||
start, end, count, flags);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_release_resource(device_t dev, device_t child, int type, int rid,
|
||||
struct resource *r)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
|
||||
return resource_list_release(rl, dev, child, type, rid, r);
|
||||
}
|
||||
|
||||
static int
|
||||
pci_set_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long start, u_long count)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
|
||||
resource_list_add(rl, type, rid, start, start + count - 1, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pci_get_resource(device_t dev, device_t child, int type, int rid,
|
||||
u_long *startp, u_long *countp)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(child);
|
||||
struct resource_list *rl = &dinfo->resources;
|
||||
struct resource_list_entry *rle;
|
||||
|
||||
rle = resource_list_find(rl, type, rid);
|
||||
if (!rle)
|
||||
return ENOENT;
|
||||
|
||||
if (startp)
|
||||
*startp = rle->start;
|
||||
if (countp)
|
||||
*countp = rle->count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pci_delete_resource(device_t dev, device_t child, int type, int rid)
|
||||
{
|
||||
printf("pci_delete_resource: PCI resources can not be deleted\n");
|
||||
}
|
||||
|
||||
static struct resource_list *
|
||||
pci_get_resource_list (device_t dev, device_t child)
|
||||
{
|
||||
struct pci_devinfo * dinfo = device_get_ivars(child);
|
||||
struct resource_list * rl = &dinfo->resources;
|
||||
|
||||
if (!rl)
|
||||
return (NULL);
|
||||
|
||||
return (rl);
|
||||
}
|
||||
|
||||
static u_int32_t
|
||||
pci_read_config_method(device_t dev, device_t child, int reg, int width)
|
||||
{
|
||||
@ -1426,15 +1397,17 @@ static device_method_t pci_methods[] = {
|
||||
DEVMETHOD(bus_read_ivar, pci_read_ivar),
|
||||
DEVMETHOD(bus_write_ivar, pci_write_ivar),
|
||||
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
||||
DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, pci_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
||||
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
||||
DEVMETHOD(bus_set_resource, pci_set_resource),
|
||||
DEVMETHOD(bus_get_resource, pci_get_resource),
|
||||
|
||||
DEVMETHOD(bus_get_resource_list,pci_get_resource_list),
|
||||
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
||||
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
||||
DEVMETHOD(bus_delete_resource, pci_delete_resource),
|
||||
DEVMETHOD(bus_alloc_resource, pci_alloc_resource),
|
||||
DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
|
||||
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
||||
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
||||
|
||||
/* PCI interface */
|
||||
DEVMETHOD(pci_read_config, pci_read_config_method),
|
||||
|
Loading…
x
Reference in New Issue
Block a user