aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/bhnd/bhnd.c
diff options
context:
space:
mode:
authorLandon J. Fuller <landonf@FreeBSD.org>2016-06-25 04:36:30 +0000
committerLandon J. Fuller <landonf@FreeBSD.org>2016-06-25 04:36:30 +0000
commit688fc8c0d657ab529d56acd62f9d1a1af0193b47 (patch)
tree7d81851b96e0e07452843b84cc281bb906646e1b /sys/dev/bhnd/bhnd.c
parentff29b85a3446f1449715f032fd776406526819b2 (diff)
downloadsrc-688fc8c0d657ab529d56acd62f9d1a1af0193b47.tar.gz
src-688fc8c0d657ab529d56acd62f9d1a1af0193b47.zip
bhnd(4): Add devinfo allocation and child addition methods, modeled on
pci_if. This allows bhnd(4) to manage per-device state (such as per-core pmu/clock refcounting) on behalf of subclass driver instances. Approved by: re (gjb), adrian (mentor) Differential Revision: https://reviews.freebsd.org/D6959
Notes
Notes: svn path=/head/; revision=302191
Diffstat (limited to 'sys/dev/bhnd/bhnd.c')
-rw-r--r--sys/dev/bhnd/bhnd.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/dev/bhnd/bhnd.c b/sys/dev/bhnd/bhnd.c
index 8f85900cef2a..308bc7bf5fc4 100644
--- a/sys/dev/bhnd/bhnd.c
+++ b/sys/dev/bhnd/bhnd.c
@@ -493,6 +493,54 @@ bhnd_child_location_str(device_t dev, device_t child, char *buf,
}
/**
+ * Default bhnd(4) bus driver implementation of BUS_ADD_CHILD().
+ *
+ * This implementation manages internal bhnd(4) state, and must be called
+ * by subclassing drivers.
+ */
+device_t
+bhnd_generic_add_child(device_t dev, u_int order, const char *name, int unit)
+{
+ struct bhnd_devinfo *dinfo;
+ device_t child;
+
+ child = device_add_child_ordered(dev, order, name, unit);
+ if (child == NULL)
+ return (NULL);
+
+ if ((dinfo = BHND_BUS_ALLOC_DEVINFO(dev)) == NULL) {
+ device_delete_child(dev, child);
+ return (NULL);
+ }
+
+ device_set_ivars(child, dinfo);
+
+ /* Inform concrete bus driver. */
+ BHND_BUS_CHILD_ADDED(dev, child);
+
+ return (child);
+}
+
+/**
+ * Default bhnd(4) bus driver implementation of BUS_CHILD_DELETED().
+ *
+ * This implementation manages internal bhnd(4) state, and must be called
+ * by subclassing drivers.
+ */
+void
+bhnd_generic_child_deleted(device_t dev, device_t child)
+{
+ struct bhnd_softc *sc;
+ struct bhnd_devinfo *dinfo;
+
+ sc = device_get_softc(dev);
+
+ /* Free device info */
+ if ((dinfo = device_get_ivars(child)) != NULL)
+ BHND_BUS_FREE_DEVINFO(dev, dinfo);
+}
+
+/**
* Helper function for implementing BUS_SUSPEND_CHILD().
*
* TODO: Power management
@@ -611,6 +659,8 @@ static device_method_t bhnd_methods[] = {
DEVMETHOD(device_resume, bhnd_generic_resume),
/* Bus interface */
+ DEVMETHOD(bus_add_child, bhnd_generic_add_child),
+ DEVMETHOD(bus_child_deleted, bhnd_generic_child_deleted),
DEVMETHOD(bus_probe_nomatch, bhnd_generic_probe_nomatch),
DEVMETHOD(bus_print_child, bhnd_generic_print_child),
DEVMETHOD(bus_child_pnpinfo_str, bhnd_child_pnpinfo_str),