2 * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
37 * bhnd(4) driver mix-in providing shared common methods for
38 * bhnd bus devices attached via a root nexus.
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/module.h>
47 #include <sys/malloc.h>
49 #include <machine/bus.h>
51 #include <dev/bhnd/bhnd_ids.h>
52 #include <dev/bhnd/cores/chipc/chipcreg.h>
54 #include "bhnd_nexusvar.h"
56 static const struct resource_spec bhnd_nexus_res_spec[] = {
57 { SYS_RES_MEMORY, 0, RF_ACTIVE }, /* chipc registers */
62 * Map ChipCommon's register block and read the chip identifier data.
64 * @param dev A bhnd_nexus device.
65 * @param chipid On success, will be populated with the chip identifier.
67 * @retval non-zero An error occurred reading the chip identifier..
70 bhnd_nexus_read_chipid(device_t dev, struct bhnd_chipid *chipid)
72 struct resource_spec rspec[nitems(bhnd_nexus_res_spec)];
75 memcpy(rspec, bhnd_nexus_res_spec, sizeof(rspec));
76 error = bhnd_read_chipid(dev, rspec, 0, chipid);
78 device_printf(dev, "error %d reading chip ID\n", error);
84 bhnd_nexus_is_hw_disabled(device_t dev, device_t child)
89 static bhnd_attach_type
90 bhnd_nexus_get_attach_type(device_t dev, device_t child)
92 return (BHND_ATTACH_NATIVE);
96 bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid,
97 struct bhnd_resource *r)
102 if ((error = bus_activate_resource(child, type, rid, r->res)))
110 bhnd_nexus_deactivate_resource(device_t dev, device_t child,
111 int type, int rid, struct bhnd_resource *r)
116 KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n"));
118 if ((error = bus_deactivate_resource(child, type, rid, r->res)))
125 static device_method_t bhnd_nexus_methods[] = {
127 DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource),
128 DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource),
129 DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled),
130 DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type),
135 DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods,
136 sizeof(struct bhnd_softc));