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"
68 * Default bhnd_nexus implementation of BHND_BUS_GET_SERVICE_REGISTRY().
70 static struct bhnd_service_registry *
71 bhnd_nexus_get_service_registry(device_t dev, device_t child)
73 struct bcm_platform *bp = bcm_get_platform();
74 return (&bp->services);
78 * Default bhnd_nexus implementation of BHND_BUS_ACTIVATE_RESOURCE().
81 bhnd_nexus_activate_resource(device_t dev, device_t child, int type, int rid,
82 struct bhnd_resource *r)
87 if ((error = bus_activate_resource(child, type, rid, r->res)))
95 * Default bhnd_nexus implementation of BHND_BUS_DEACTIVATE_RESOURCE().
98 bhnd_nexus_deactivate_resource(device_t dev, device_t child,
99 int type, int rid, struct bhnd_resource *r)
104 KASSERT(r->direct, ("indirect resource delegated to bhnd_nexus\n"));
106 if ((error = bus_deactivate_resource(child, type, rid, r->res)))
114 * Default bhnd_nexus implementation of BHND_BUS_IS_HW_DISABLED().
117 bhnd_nexus_is_hw_disabled(device_t dev, device_t child)
119 struct bcm_platform *bp;
120 struct bhnd_chipid *cid;
122 bp = bcm_get_platform();
125 /* The BCM4706 low-cost package leaves secondary GMAC cores
127 if (cid->chip_id == BHND_CHIPID_BCM4706 &&
128 cid->chip_pkg == BHND_PKGID_BCM4706L &&
129 bhnd_get_device(child) == BHND_COREID_4706_GMAC &&
130 bhnd_get_core_unit(child) != 0)
139 * Default bhnd_nexus implementation of BHND_BUS_AGET_ATTACH_TYPE().
141 static bhnd_attach_type
142 bhnd_nexus_get_attach_type(device_t dev, device_t child)
144 return (BHND_ATTACH_NATIVE);
148 * Default bhnd_nexus implementation of BHND_BUS_GET_CHIPID().
150 static const struct bhnd_chipid *
151 bhnd_nexus_get_chipid(device_t dev, device_t child)
153 return (&bcm_get_platform()->cid);
157 * Default bhnd_nexus implementation of BHND_BUS_READ_BOARD_INFO().
160 bhnd_nexus_read_board_info(device_t dev, device_t child,
161 struct bhnd_board_info *info)
165 /* Initialize with NVRAM-derived values */
166 if ((error = bhnd_bus_generic_read_board_info(dev, child, info)))
169 /* The board vendor should default to PCI_VENDOR_BROADCOM if not
170 * otherwise specified */
171 if (info->board_vendor == 0)
172 info->board_vendor = PCI_VENDOR_BROADCOM;
178 * Default bhnd_nexus implementation of BHND_BUS_MAP_INTR().
181 bhnd_nexus_map_intr(device_t dev, device_t child, u_int intr, rman_res_t *irq)
183 struct bcm_mips_intr_map_data *imd;
188 /* Fetch the backplane interrupt vector */
189 if ((error = bhnd_get_intr_ivec(child, intr, &ivec))) {
190 device_printf(dev, "error fetching ivec for intr %u: %d\n",
195 /* Determine our interrupt domain */
196 xref = BHND_BUS_GET_INTR_DOMAIN(dev, child, false);
197 KASSERT(xref != 0, ("missing interrupt domain"));
199 /* Allocate our map data */
200 imd = (struct bcm_mips_intr_map_data *)intr_alloc_map_data(
201 INTR_MAP_DATA_BCM_MIPS, sizeof(*imd), M_WAITOK | M_ZERO);
205 *irq = intr_map_irq(NULL, xref, &imd->mdata);
210 * Default bhnd_nexus implementation of BHND_BUS_UNMAP_INTR().
213 bhnd_nexus_unmap_intr(device_t dev, device_t child, rman_res_t irq)
216 panic("invalid irq: %ju", (uintmax_t)irq);
222 * Default bhnd_nexus implementation of BHND_BUS_GET_DMA_TRANSLATION().
225 bhnd_nexus_get_dma_translation(device_t dev, device_t child,
226 u_int width, uint32_t flags, bus_dma_tag_t *dmat,
227 struct bhnd_dma_translation *translation)
229 struct bcm_platform *bp = bcm_get_platform();
231 /* We don't (currently) support any flags */
235 KASSERT(width > 0 && width <= BHND_DMA_ADDR_64BIT,
236 ("invalid width %u", width));
238 /* Is the requested width supported? */
239 if (width > BHND_DMA_ADDR_32BIT) {
240 /* Backplane must support 64-bit addressing */
241 if (!(bp->cid.chip_caps & BHND_CAP_BP64))
242 width = BHND_DMA_ADDR_32BIT;
245 /* No DMA address translation required */
247 *dmat = bus_get_dma_tag(dev);
249 if (translation != NULL) {
250 *translation = (struct bhnd_dma_translation) {
252 .addr_mask = BHND_DMA_ADDR_BITMASK(width),
260 static device_method_t bhnd_nexus_methods[] = {
262 DEVMETHOD(bhnd_bus_get_service_registry,bhnd_nexus_get_service_registry),
263 DEVMETHOD(bhnd_bus_register_provider, bhnd_bus_generic_sr_register_provider),
264 DEVMETHOD(bhnd_bus_deregister_provider, bhnd_bus_generic_sr_deregister_provider),
265 DEVMETHOD(bhnd_bus_retain_provider, bhnd_bus_generic_sr_retain_provider),
266 DEVMETHOD(bhnd_bus_release_provider, bhnd_bus_generic_sr_release_provider),
267 DEVMETHOD(bhnd_bus_activate_resource, bhnd_nexus_activate_resource),
268 DEVMETHOD(bhnd_bus_deactivate_resource, bhnd_nexus_deactivate_resource),
269 DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_nexus_is_hw_disabled),
270 DEVMETHOD(bhnd_bus_get_attach_type, bhnd_nexus_get_attach_type),
271 DEVMETHOD(bhnd_bus_get_chipid, bhnd_nexus_get_chipid),
272 DEVMETHOD(bhnd_bus_get_dma_translation, bhnd_nexus_get_dma_translation),
273 DEVMETHOD(bhnd_bus_get_intr_domain, bhnd_bus_generic_get_intr_domain),
274 DEVMETHOD(bhnd_bus_map_intr, bhnd_nexus_map_intr),
275 DEVMETHOD(bhnd_bus_read_board_info, bhnd_nexus_read_board_info),
276 DEVMETHOD(bhnd_bus_unmap_intr, bhnd_nexus_unmap_intr),
281 DEFINE_CLASS_0(bhnd, bhnd_nexus_driver, bhnd_nexus_methods,
282 sizeof(struct bhnd_softc));