2 * Copyright (c) 2015 Landon Fuller <landon@landonf.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.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
39 #include <dev/bhnd/bhnd_ids.h>
40 #include <dev/bhnd/bhndb/bhndbvar.h>
41 #include <dev/bhnd/bhndb/bhndb_hwdata.h>
47 * Supports attachment of siba(4) bus devices via a bhndb bridge.
51 // TODO: PCI rev < 6 interrupt handling
53 // On early PCI cores (rev < 6) interrupt masking is handled via interconnect
54 // configuration registers (SBINTVEC), rather than the PCI_INT_MASK
57 // On those devices, we should handle interrupts locally using SBINTVEC, rather
58 // than delegating to our parent bhndb device.
61 static int siba_bhndb_wars_hwup(struct siba_softc *sc);
63 /* Bridge-specific core device quirks */
65 /** When PCIe-bridged, the D11 core's initiator request
66 * timeout must be disabled to prevent D11 from entering a
67 * RESP_TIMEOUT error state. */
68 SIBA_QUIRK_PCIE_D11_SB_TIMEOUT = (1<<0)
71 static struct bhnd_device_quirk bridge_quirks[] = {
72 BHND_CHIP_QUIRK(4311, HWREV_EQ(2), SIBA_QUIRK_PCIE_D11_SB_TIMEOUT),
73 BHND_CHIP_QUIRK(4312, HWREV_EQ(0), SIBA_QUIRK_PCIE_D11_SB_TIMEOUT),
77 static struct bhnd_device bridge_devs[] = {
78 BHND_DEVICE(BCM, PCI, NULL, bridge_quirks),
83 siba_bhndb_probe(device_t dev)
85 const struct bhnd_chipid *cid;
88 /* Defer to default probe implementation */
89 if ((error = siba_probe(dev)) > 0)
93 cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev);
94 if (cid->chip_type != BHND_CHIPTYPE_SIBA)
97 /* Set device description */
98 bhnd_set_default_bus_desc(dev, cid);
104 siba_bhndb_attach(device_t dev)
106 struct siba_softc *sc;
109 sc = device_get_softc(dev);
111 /* Perform initial attach and enumerate our children. */
112 if ((error = siba_attach(dev)))
115 /* Apply attach/resume workarounds before any child drivers attach */
116 if ((error = siba_bhndb_wars_hwup(sc)))
119 /* Delegate remainder to standard bhnd method implementation */
120 if ((error = bhnd_generic_attach(dev)))
126 device_delete_children(dev);
131 siba_bhndb_resume(device_t dev)
133 struct siba_softc *sc;
136 sc = device_get_softc(dev);
138 /* Apply attach/resume work-arounds */
139 if ((error = siba_bhndb_wars_hwup(sc)))
142 /* Call our superclass' implementation */
143 return (siba_resume(dev));
146 /* Suspend all references to the device's cfg register blocks */
148 siba_bhndb_suspend_cfgblocks(device_t dev, struct siba_devinfo *dinfo) {
149 for (u_int i = 0; i < dinfo->core_id.num_cfg_blocks; i++) {
150 if (dinfo->cfg[i] == NULL)
153 BHNDB_SUSPEND_RESOURCE(device_get_parent(dev), dev,
154 SYS_RES_MEMORY, dinfo->cfg[i]->res);
159 siba_bhndb_suspend_child(device_t dev, device_t child)
161 struct siba_devinfo *dinfo;
164 if (device_get_parent(child) != dev)
165 BUS_SUSPEND_CHILD(device_get_parent(dev), child);
167 dinfo = device_get_ivars(child);
169 /* Suspend the child */
170 if ((error = bhnd_generic_br_suspend_child(dev, child)))
173 /* Suspend resource references to the child's config registers */
174 siba_bhndb_suspend_cfgblocks(dev, dinfo);
180 siba_bhndb_resume_child(device_t dev, device_t child)
182 struct siba_devinfo *dinfo;
185 if (device_get_parent(child) != dev)
186 BUS_SUSPEND_CHILD(device_get_parent(dev), child);
188 if (!device_is_suspended(child))
191 dinfo = device_get_ivars(child);
193 /* Resume all resource references to the child's config registers */
194 for (u_int i = 0; i < dinfo->core_id.num_cfg_blocks; i++) {
195 if (dinfo->cfg[i] == NULL)
198 error = BHNDB_RESUME_RESOURCE(device_get_parent(dev), dev,
199 SYS_RES_MEMORY, dinfo->cfg[i]->res);
201 siba_bhndb_suspend_cfgblocks(dev, dinfo);
206 /* Resume the child */
207 if ((error = bhnd_generic_br_resume_child(dev, child))) {
208 siba_bhndb_suspend_cfgblocks(dev, dinfo);
215 /* Work-around implementation for SIBA_QUIRK_PCIE_D11_SB_TIMEOUT */
217 siba_bhndb_wars_pcie_clear_d11_timeout(struct siba_softc *sc)
219 struct siba_devinfo *dinfo;
224 /* Only applies when bridged by PCIe */
225 if ((hostb_dev = bhnd_find_hostb_device(sc->dev)) == NULL)
228 if (bhnd_get_class(hostb_dev) != BHND_DEVCLASS_PCIE)
231 /* Only applies if there's a D11 core */
232 d11 = bhnd_match_child(sc->dev, &(struct bhnd_core_match) {
233 BHND_MATCH_CORE(BHND_MFGID_BCM, BHND_COREID_D11),
234 BHND_MATCH_CORE_UNIT(0)
239 /* Clear initiator timeout in D11's CFG0 block */
240 dinfo = device_get_ivars(d11);
241 KASSERT(dinfo->cfg[0] != NULL, ("missing core config mapping"));
243 imcfg = bhnd_bus_read_4(dinfo->cfg[0], SIBA_CFG0_IMCONFIGLOW);
244 imcfg &= ~SIBA_IMCL_RTO_MASK;
246 bhnd_bus_write_4(dinfo->cfg[0], SIBA_CFG0_IMCONFIGLOW, imcfg);
252 * Apply any hardware workarounds that are required upon attach or resume
256 siba_bhndb_wars_hwup(struct siba_softc *sc)
262 if ((hostb_dev = bhnd_find_hostb_device(sc->dev)) == NULL)
265 quirks = bhnd_device_quirks(hostb_dev, bridge_devs,
266 sizeof(bridge_devs[0]));
268 if (quirks & SIBA_QUIRK_PCIE_D11_SB_TIMEOUT) {
269 if ((error = siba_bhndb_wars_pcie_clear_d11_timeout(sc)))
276 static device_method_t siba_bhndb_methods[] = {
277 /* Device interface */
278 DEVMETHOD(device_probe, siba_bhndb_probe),
279 DEVMETHOD(device_attach, siba_bhndb_attach),
280 DEVMETHOD(device_resume, siba_bhndb_resume),
283 DEVMETHOD(bus_suspend_child, siba_bhndb_suspend_child),
284 DEVMETHOD(bus_resume_child, siba_bhndb_resume_child),
289 DEFINE_CLASS_2(bhnd, siba_bhndb_driver, siba_bhndb_methods,
290 sizeof(struct siba_softc), bhnd_bhndb_driver, siba_driver);
292 DRIVER_MODULE(siba_bhndb, bhndb, siba_bhndb_driver, bhnd_devclass, NULL, NULL);
294 MODULE_VERSION(siba_bhndb, 1);
295 MODULE_DEPEND(siba_bhndb, siba, 1, 1, 1);
296 MODULE_DEPEND(siba_bhndb, bhnd, 1, 1, 1);
297 MODULE_DEPEND(siba_bhndb, bhndb, 1, 1, 1);