From 5878eb3fca650e2f20205a49181440a7f2ab680e Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sun, 21 Jul 2002 03:28:43 +0000 Subject: [PATCH] Add bus_child_present and the child_present method to bus_if.m --- sys/kern/bus_if.m | 15 +++++++++++---- sys/kern/subr_bus.c | 26 ++++++++++++++++++++++++++ sys/sys/bus.h | 2 ++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m index bf8d4ac1ee7e..c5350beaf9c9 100644 --- a/sys/kern/bus_if.m +++ b/sys/kern/bus_if.m @@ -36,11 +36,10 @@ INTERFACE bus; CODE { static struct resource * null_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 type, int *rid, u_long start, u_long end, + u_long count, u_int flags) { - return 0; + return (0); } }; @@ -244,3 +243,11 @@ METHOD struct resource_list * get_resource_list { device_t _dev; device_t _child; } DEFAULT bus_generic_get_resource_list; + +# +# Is the hardware described by _child still attached to the system? +# +METHOD int child_present { + device_t _dev; + device_t _child; +} DEFAULT bus_generic_child_present; diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 72810519f0ce..7e7df14360c1 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1594,6 +1594,12 @@ bus_generic_rl_alloc_resource (device_t dev, device_t child, int type, start, end, count, flags)); } +int +bus_generic_child_present(device_t bus, device_t child) +{ + return (BUS_CHILD_PRESENT(device_get_parent(bus), bus)); +} + /* * Some convenience functions to make it easier for drivers to use the * resource-management functions. All these really do is hide the @@ -1701,6 +1707,12 @@ bus_delete_resource(device_t dev, int type, int rid) BUS_DELETE_RESOURCE(device_get_parent(dev), dev, type, rid); } +int +bus_child_present(device_t dev) +{ + return (BUS_CHILD_PRESENT(device_get_parent(dev), dev)); +} + static int root_print_child(device_t dev, device_t child) { @@ -1722,6 +1734,19 @@ root_setup_intr(device_t dev, device_t child, driver_intr_t *intr, void *arg, panic("root_setup_intr"); } +/* + * If we get here, assume that the device is permanant and really is + * present in the system. Removable bus drivers are expected to intercept + * this call long before it gets here. We return -1 so that drivers that + * really care can check vs -1 or some ERRNO returned higher in the food + * chain. + */ +static int +root_child_present(device_t dev, device_t child) +{ + return (-1); +} + static kobj_method_t root_methods[] = { /* Device interface */ KOBJMETHOD(device_shutdown, bus_generic_shutdown), @@ -1733,6 +1758,7 @@ static kobj_method_t root_methods[] = { KOBJMETHOD(bus_read_ivar, bus_generic_read_ivar), KOBJMETHOD(bus_write_ivar, bus_generic_write_ivar), KOBJMETHOD(bus_setup_intr, root_setup_intr), + KOBJMETHOD(bus_child_present, root_child_present), { 0, 0 } }; diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 47bea4cf31ba..1559c41f1f5b 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -209,6 +209,7 @@ struct resource * int *rid, u_long start, u_long end, u_long count, u_int flags); int bus_generic_attach(device_t dev); +int bus_generic_child_present(device_t dev, device_t child); int bus_generic_deactivate_resource(device_t dev, device_t child, int type, int rid, struct resource *r); int bus_generic_detach(device_t dev); @@ -269,6 +270,7 @@ int bus_get_resource(device_t dev, int type, int rid, u_long bus_get_resource_start(device_t dev, int type, int rid); u_long bus_get_resource_count(device_t dev, int type, int rid); void bus_delete_resource(device_t dev, int type, int rid); +int bus_child_present(device_t dev); /* * Access functions for device.