Cleanup some of the newbus infrastructure.
[dragonfly.git] / sys / sys / bus.h
index 36c7b0e..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.4 2003/11/22 19:30:57 asmodai 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_FAST = 128
+#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,
+    INTR_TRIGGER_EDGE = 1,
+    INTR_TRIGGER_LEVEL = 2
 };
-#define INTR_TYPE_AV INTR_TYPE_TTY     /* for source compatibility with 5.x */
 
-typedef int (*devop_t)(void);
-
-struct driver {
-    KOBJ_CLASS_FIELDS;
-    void               *priv;          /* driver private data */
+enum intr_polarity {
+    INTR_POLARITY_CONFORM = 0,
+    INTR_POLARITY_HIGH = 1,
+    INTR_POLARITY_LOW = 2
 };
 
+typedef int (*devop_t)(void);
+
 typedef enum device_state {
     DS_NOTPRESENT,                     /* not probed or probe failed */
     DS_ALIVE,                          /* probe succeeded */
@@ -159,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);
 
 /*
@@ -168,19 +168,31 @@ void      root_bus_configure(void);
 
 int    bus_generic_activate_resource(device_t dev, device_t child, int type,
                                      int rid, struct resource *r);
-struct resource *bus_generic_alloc_resource(device_t bus, device_t child,
-                                           int type, int *rid,
-                                           u_long start, u_long end,
-                                           u_long count, u_int flags);
+struct resource *
+       bus_generic_alloc_resource(device_t bus, device_t child,
+                                   int type, int *rid,
+                                   u_long start, u_long end,
+                                   u_long count, u_int flags);
+struct resource_list *
+       bus_generic_get_resource_list (device_t, device_t);
+
+int     bus_generic_config_intr(device_t, int, enum intr_trigger,
+                                       enum intr_polarity);
 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);
+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,
@@ -188,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,
@@ -196,6 +209,17 @@ int        bus_generic_teardown_intr(device_t dev, device_t child,
 int    bus_generic_write_ivar(device_t dev, device_t child, int which,
                               uintptr_t value);
 
+struct resource *
+       bus_generic_rl_alloc_resource (device_t, device_t, int, int *,
+                                   u_long, u_long, u_long, u_int);
+void   bus_generic_rl_delete_resource (device_t, device_t, int, int);
+int    bus_generic_rl_get_resource (device_t, device_t, int, int, u_long *,
+                                   u_long *);
+int    bus_generic_rl_set_resource (device_t, device_t, int, int, u_long,
+                                   u_long);
+int    bus_generic_rl_release_resource (device_t, device_t, int, int,
+                                   struct resource *);
+
 /*
  * Wrapper functions for the BUS_*_RESOURCE methods to make client code
  * a little simpler.
@@ -207,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);
@@ -219,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.
@@ -247,6 +283,7 @@ void        *device_get_softc(device_t dev);
 device_state_t device_get_state(device_t dev);
 int    device_get_unit(device_t dev);
 int    device_is_alive(device_t dev); /* did probe succeed? */
+int    device_is_attached(device_t dev);       /* did attach succeed? */
 int    device_is_enabled(device_t dev);
 int    device_is_quiet(device_t dev);
 int    device_print_prettyname(device_t dev);
@@ -267,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.
@@ -288,6 +327,7 @@ int resource_long_value(const char *name, int unit, const char *resname,
                            long *result);
 int    resource_string_value(const char *name, int unit, const char *resname,
                              char **result);
+int     resource_disabled(const char *name, int unit);
 int    resource_query_string(int i, const char *resname, const char *value);
 char   *resource_query_name(int i);
 int    resource_query_unit(int i);
@@ -322,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                                                       \
 };                                                                     \
                                                                        \