Cleanup some of the newbus infrastructure.
[dragonfly.git] / sys / sys / bus.h
index 02fe870..a4a3631 100644 (file)
@@ -23,8 +23,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/sys/bus.h,v 1.30.2.4 2002/10/10 15:13:33 jhb Exp $
- * $DragonFly: src/sys/sys/bus.h,v 1.8 2004/02/23 21:23:41 dillon Exp $
+ * $FreeBSD: src/sys/sys/bus.h,v 1.30.2.5 2004/03/17 17:54:25 njl Exp $
+ * $DragonFly: src/sys/sys/bus.h,v 1.17 2005/10/28 03:25:57 dillon Exp $
  */
 
 #ifndef _SYS_BUS_H_
 
 #include <sys/queue.h>
 #include <sys/kobj.h>
+#include <sys/serialize.h>
 
 /*
  * Forward declarations
  */
 typedef struct device          *device_t;
-typedef struct driver          driver_t;
+typedef struct kobj_class      driver_t;
 typedef struct devclass                *devclass_t;
 #define        device_method_t         kobj_method_t
 
 typedef void driver_intr_t(void*);
 
 /*
- * We define this in terms of bits because some devices may belong
- * to multiple classes (and therefore need to be included in
- * multiple interrupt masks, which is what this really serves to
- * indicate.  Buses which do interrupt remapping will want to
- * change their type to reflect what sort of devices are underneath.
+ * Interrupt features mask.  Note that DragonFly no longer implements
+ * INTR_TYPE_* flags.
  */
-enum intr_type {
-    INTR_TYPE_TTY = 1,
-    INTR_TYPE_BIO = 2,
-    INTR_TYPE_NET = 4,
-    INTR_TYPE_CAM = 8,
-    INTR_TYPE_MISC = 16,
-    INTR_TYPE_CLK = 32,
-    INTR_TYPE_AV = 64,
-    INTR_FAST = 128,
-    INTR_EXCL = 256,
-    INTR_MPSAFE = 512,
-    INTR_ENTROPY = 1024
-};
-
-#define INTR_TYPE_MASK (INTR_TYPE_TTY|INTR_TYPE_BIO|INTR_TYPE_NET|\
-                        INTR_TYPE_CAM|INTR_TYPE_MISC|INTR_TYPE_CLK|\
-                        INTR_TYPE_AV)
+#define        INTR_FAST       0x0080
+#define        INTR_EXCL       0x0100
+#define        INTR_MPSAFE     0x0200
+#define        INTR_ENTROPY    0x0400
+#define INTR_NOPOLL    0x0800  /* interrupt cannot be polled (e.g. ata) */
 
 enum intr_trigger {
     INTR_TRIGGER_CONFORM = 0,
@@ -84,11 +70,6 @@ enum intr_polarity {
 
 typedef int (*devop_t)(void);
 
-struct driver {
-    KOBJ_CLASS_FIELDS;
-    void               *priv;          /* driver private data */
-};
-
 typedef enum device_state {
     DS_NOTPRESENT,                     /* not probed or probe failed */
     DS_ALIVE,                          /* probe succeeded */
@@ -179,7 +160,6 @@ int resource_list_print_type(struct resource_list *rl,
  * The root bus, to which all top-level busses are attached.
  */
 extern device_t root_bus;
-extern devclass_t root_devclass;
 void   root_bus_configure(void);
 
 /*
@@ -203,11 +183,16 @@ 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);
+int    bus_generic_disable_intr(device_t dev, device_t child, void *cookie);
 void   bus_generic_driver_added(device_t dev, driver_t *driver);
+void   bus_generic_enable_intr(device_t dev, device_t child, void *cookie);
 int    bus_print_child_header(device_t dev, device_t child);
 int    bus_print_child_footer(device_t dev, device_t child);
 int    bus_generic_print_child(device_t dev, device_t child);
+int    bus_generic_identify(driver_t *driver, device_t parent);
+int    bus_generic_identify_sameunit(driver_t *driver, device_t parent);
 int    bus_generic_probe(device_t dev);
+int    bus_generic_probe_hack(device_t dev);
 int    bus_generic_read_ivar(device_t dev, device_t child, int which,
                              uintptr_t *result);
 int    bus_generic_release_resource(device_t bus, device_t child,
@@ -215,7 +200,8 @@ int bus_generic_release_resource(device_t bus, device_t child,
 int    bus_generic_resume(device_t dev);
 int    bus_generic_setup_intr(device_t dev, device_t child,
                               struct resource *irq, int flags,
-                              driver_intr_t *intr, void *arg, void **cookiep);
+                              driver_intr_t *intr, void *arg,
+                              void **cookiep, lwkt_serialize_t serializer);
 int    bus_generic_shutdown(device_t dev);
 int    bus_generic_suspend(device_t dev);
 int    bus_generic_teardown_intr(device_t dev, device_t child,
@@ -245,10 +231,13 @@ int       bus_activate_resource(device_t dev, int type, int rid,
                              struct resource *r);
 int    bus_deactivate_resource(device_t dev, int type, int rid,
                                struct resource *r);
+int    bus_disable_intr(device_t dev, void *cookie);
+void   bus_enable_intr(device_t dev, void *cookie);
 int    bus_release_resource(device_t dev, int type, int rid, 
                             struct resource *r);
 int    bus_setup_intr(device_t dev, struct resource *r, int flags,
-                      driver_intr_t handler, void *arg, void **cookiep);
+                      driver_intr_t handler, void *arg,
+                      void **cookiep, lwkt_serialize_t serializer);
 int    bus_teardown_intr(device_t dev, struct resource *r, void *cookie);
 int    bus_set_resource(device_t dev, int type, int rid,
                         u_long start, u_long count);
@@ -257,6 +246,15 @@ 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 child);
+int    bus_child_pnpinfo_str(device_t child, char *buf, size_t buflen);
+int    bus_child_location_str(device_t child, char *buf, size_t buflen);
+
+static __inline struct resource *
+bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags)
+{
+       return (bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags));
+}
 
 /*
  * Access functions for device.
@@ -306,16 +304,18 @@ void      device_verbose(device_t dev);
 /*
  * Access functions for devclass.
  */
-int    devclass_add_driver(devclass_t dc, driver_t *driver);
-int    devclass_delete_driver(devclass_t dc, driver_t *driver);
+int    devclass_add_driver(devclass_t dc, kobj_class_t driver);
+int    devclass_delete_driver(devclass_t dc, kobj_class_t driver);
 devclass_t     devclass_create(const char *classname);
 devclass_t     devclass_find(const char *classname);
-driver_t       *devclass_find_driver(devclass_t dc, const char *classname);
+kobj_class_t   devclass_find_driver(devclass_t dc, const char *classname);
 const char     *devclass_get_name(devclass_t dc);
 device_t       devclass_get_device(devclass_t dc, int unit);
 void   *devclass_get_softc(devclass_t dc, int unit);
 int    devclass_get_devices(devclass_t dc, device_t **listp, int *countp);
 int    devclass_get_maxunit(devclass_t dc);
+void   devclass_set_parent(devclass_t dc, devclass_t pdc);
+devclass_t     devclass_get_parent(devclass_t dc);
 
 /*
  * Access functions for device resources.
@@ -362,40 +362,16 @@ struct driver_module_data {
        int             (*dmd_chainevh)(struct module *, int, void *);
        void            *dmd_chainarg;
        const char      *dmd_busname;
-       driver_t        **dmd_drivers;
-       int             dmd_ndrivers;
+       kobj_class_t    dmd_driver;
        devclass_t      *dmd_devclass;
 };
 
 #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg)       \
                                                                        \
-static driver_t *name##_##busname##_driver_list[] = { &driver };       \
-static struct driver_module_data name##_##busname##_driver_mod = {     \
-       evh, arg,                                                       \
-       #busname,                                                       \
-       name##_##busname##_driver_list,                                 \
-       (sizeof name##_##busname##_driver_list) /                       \
-               (sizeof name##_##busname##_driver_list[0]),             \
-       &devclass                                                       \
-};                                                                     \
-                                                                       \
-static moduledata_t name##_##busname##_mod = {                         \
-       #busname "/" #name,                                             \
-       driver_module_handler,                                          \
-       &name##_##busname##_driver_mod                                  \
-};                                                                     \
-DECLARE_MODULE(name##_##busname, name##_##busname##_mod,               \
-              SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
-
-#define MULTI_DRIVER_MODULE(name, busname, drivers, devclass, evh, arg) \
-                                                                       \
-static driver_t name##_##busname##_driver_list[] = drivers;            \
 static struct driver_module_data name##_##busname##_driver_mod = {     \
        evh, arg,                                                       \
        #busname,                                                       \
-       name##_##busname##_driver_list,                                 \
-       (sizeof name##_##busname##_driver_list) /                       \
-               (sizeof name##_##busname##_driver_list[0]),             \
+       (kobj_class_t) &driver,                                         \
        &devclass                                                       \
 };                                                                     \
                                                                        \