2 * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org>
3 * Copyright (c) 2017 The FreeBSD Foundation
6 * Portions of this software were developed by Landon Fuller
7 * under sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17 * redistribution must be conditioned upon including a substantially
18 * similar Disclaimer requirement for further binary redistribution.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGES.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * bhnd(4) driver mix-in providing shared common methods for
41 * bhnd bus devices attached via a MIPS root nexus.
44 #include <sys/param.h>
45 #include <sys/systm.h>
48 #include <sys/limits.h>
49 #include <sys/kernel.h>
50 #include <sys/module.h>
52 #include <sys/malloc.h>
54 #include <machine/bus.h>
56 #include <dev/bhnd/bhndvar.h>
57 #include <dev/bhnd/bhnd_ids.h>
59 #include <dev/bhnd/cores/chipc/chipcreg.h>
61 #include "bcm_machdep.h"
62 #include "bcm_mipsvar.h"
64 #include "bhnd_nexusvar.h"
67 * Default bhnd_nexus implementation of BHND_BUS_GET_SERVICE_REGISTRY().
69 static struct bhnd_service_registry *
70 bhnd_nexus_get_service_registry(device_t dev, device_t child)
72 struct bcm_platform *bp = bcm_get_platform();
73 return (&bp->services);
77 * Default bhnd_nexus implementation of BHND_BUS_ACTIVATE_RESOURCE().
80 bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid,
81 struct bhnd_resource *r)
86 if ((error = bus_activate_resource(child, type, rid, r->res)))
94 * Default bhnd_nexus implementation of BHND_BUS_DEACTIVATE_RESOURCE().
97 bhnd_nexus_deactivate_resource(device_t dev, device_t child,
98 int type, int rid, struct bhnd_resource *r)
103 KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n"));
105 if ((error = bus_deactivate_resource(child, type, rid, r->res)))
113 * Default bhnd_nexus implementation of BHND_BUS_IS_HW_DISABLED().
116 bhnd_nexus_is_hw_disabled(device_t dev, device_t child)
118 struct bcm_platform *bp;
119 struct bhnd_chipid *cid;
121 bp = bcm_get_platform();
124 /* The BCM4706 low-cost package leaves secondary GMAC cores
126 if (cid->chip_id == BHND_CHIPID_BCM4706 &&
127 cid->chip_pkg == BHND_PKGID_BCM4706L &&
128 bhnd_get_device(child) == BHND_COREID_4706_GMAC &&
129 bhnd_get_core_unit(child) != 0)
138 * Default bhnd_nexus implementation of BHND_BUS_AGET_ATTACH_TYPE().
140 static bhnd_attach_type
141 bhnd_nexus_get_attach_type(device_t dev, device_t child)
143 return (BHND_ATTACH_NATIVE);
147 * Default bhnd_nexus implementation of BHND_BUS_GET_CHIPID().
149 static const struct bhnd_chipid *
150 bhnd_nexus_get_chipid(device_t dev, device_t child)
152 return (&bcm_get_platform()->cid);
156 * Default bhnd_nexus implementation of BHND_BUS_READ_BOARD_INFO().
159 bhnd_nexus_read_board_info(device_t dev, device_t child,
160 struct bhnd_board_info *info)
164 /* Initialize with NVRAM-derived values */
165 if ((error = bhnd_bus_generic_read_board_info(dev, child, info)))
168 /* The board vendor should default to PCI_VENDOR_BROADCOM if not
169 * otherwise specified */
170 if (info->board_vendor == 0)
171 info->board_vendor = PCI_VENDOR_BROADCOM;
177 * Default bhnd_nexus implementation of BHND_BUS_MAP_INTR().
180 bhnd_nexus_map_intr(device_t dev, device_t child, u_int intr, rman_res_t *irq)
182 struct bcm_mips_intr_map_data *imd;
187 /* Fetch the backplane interrupt vector */
188 if ((error = bhnd_get_intr_ivec(child, intr, &ivec))) {
189 device_printf(dev, "error fetching ivec for intr %u: %d\n",
194 /* Determine our interrupt domain */
195 xref = BHND_BUS_GET_INTR_DOMAIN(dev, child, false);
196 KASSERT(xref != 0, ("missing interrupt domain"));
198 /* Allocate our map data */
199 imd = (struct bcm_mips_intr_map_data *)intr_alloc_map_data(
200 INTR_MAP_DATA_BCM_MIPS, sizeof(*imd), M_WAITOK | M_ZERO);
204 *irq = intr_map_irq(NULL, xref, &imd->mdata);
209 * Default bhnd_nexus implementation of BHND_BUS_UNMAP_INTR().
212 bhnd_nexus_unmap_intr(device_t dev, device_t child, rman_res_t irq)
215 panic("invalid irq: %ju", (uintmax_t)irq);
221 * Default bhnd_nexus implementation of BHND_BUS_GET_DMA_TRANSLATION().
224 bhnd_nexus_get_dma_translation(device_t dev, device_t child,
225 u_int width, uint32_t flags, bus_dma_tag_t *dmat,
226 struct bhnd_dma_translation *translation)
228 struct bcm_platform *bp = bcm_get_platform();
230 /* We don't (currently) support any flags */
234 KASSERT(width > 0 && width <= BHND_DMA_ADDR_64BIT,
235 ("invalid width %u", width));
237 /* Is the requested width supported? */
238 if (width > BHND_DMA_ADDR_32BIT) {
239 /* Backplane must support 64-bit addressing */
240 if (!(bp->cid.chip_caps & BHND_CAP_BP64))
241 width = BHND_DMA_ADDR_32BIT;
244 /* No DMA address translation required */
246 *dmat = bus_get_dma_tag(dev);
248 if (translation != NULL) {
249 *translation = (struct bhnd_dma_translation) {
251 .addr_mask = BHND_DMA_ADDR_BITMASK(width),
259 static device_method_t bhnd_nexus_methods[] = {
261 DEVMETHOD(bhnd_bus_get_service_registry,bhnd_nexus_get_service_registry),
262 DEVMETHOD(bhnd_bus_register_provider, bhnd_bus_generic_sr_register_provider),
263 DEVMETHOD(bhnd_bus_deregister_provider, bhnd_bus_generic_sr_deregister_provider),
264 DEVMETHOD(bhnd_bus_retain_provider, bhnd_bus_generic_sr_retain_provider),
265 DEVMETHOD(bhnd_bus_release_provider, bhnd_bus_generic_sr_release_provider),
266 DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource),
267 DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource),
268 DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled),
269 DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type),
270 DEVMETHOD(bhnd_bus_get_chipid, bhnd_nexus_get_chipid),
271 DEVMETHOD(bhnd_bus_get_dma_translation, bhnd_nexus_get_dma_translation),
272 DEVMETHOD(bhnd_bus_get_intr_domain, bhnd_bus_generic_get_intr_domain),
273 DEVMETHOD(bhnd_bus_map_intr, bhnd_nexus_map_intr),
274 DEVMETHOD(bhnd_bus_read_board_info, bhnd_nexus_read_board_info),
275 DEVMETHOD(bhnd_bus_unmap_intr, bhnd_nexus_unmap_intr),
280 DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods,
281 sizeof(struct bhnd_softc));