2 * Copyright (c) 2011-2012 Semihalf.
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 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "opt_platform.h"
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <machine/bus.h>
39 #include <dev/fdt/fdt_common.h>
41 #include <dev/ofw/ofw_bus.h>
42 #include <dev/ofw/ofw_bus_subr.h>
43 #include <dev/ofw/ofw_subr.h>
48 #define FBMAN_DEVSTR "Freescale Buffer Manager"
50 static int bman_fdt_probe(device_t);
52 static device_method_t bman_methods[] = {
53 /* Device interface */
54 DEVMETHOD(device_probe, bman_fdt_probe),
55 DEVMETHOD(device_attach, bman_attach),
56 DEVMETHOD(device_detach, bman_detach),
58 DEVMETHOD(device_suspend, bman_suspend),
59 DEVMETHOD(device_resume, bman_resume),
60 DEVMETHOD(device_shutdown, bman_shutdown),
65 static driver_t bman_driver = {
68 sizeof(struct bman_softc),
71 static devclass_t bman_devclass;
72 DRIVER_MODULE(bman, simplebus, bman_driver, bman_devclass, 0, 0);
75 bman_fdt_probe(device_t dev)
78 if (!ofw_bus_is_compatible(dev, "fsl,bman"))
81 device_set_desc(dev, FBMAN_DEVSTR);
83 return (BUS_PROBE_DEFAULT);
89 #define BMAN_PORT_DEVSTR "Freescale Buffer Manager - Portals"
91 static device_probe_t bman_portals_fdt_probe;
92 static device_attach_t bman_portals_fdt_attach;
94 static device_method_t bm_portals_methods[] = {
95 /* Device interface */
96 DEVMETHOD(device_probe, bman_portals_fdt_probe),
97 DEVMETHOD(device_attach, bman_portals_fdt_attach),
98 DEVMETHOD(device_detach, bman_portals_detach),
103 static driver_t bm_portals_driver = {
106 sizeof(struct dpaa_portals_softc),
109 static devclass_t bm_portals_devclass;
110 DRIVER_MODULE(bman_portals, ofwbus, bm_portals_driver, bm_portals_devclass, 0, 0);
113 get_addr_props(phandle_t node, uint32_t *addrp, uint32_t *sizep)
118 OF_getencprop(node, "#address-cells", addrp, sizeof(*addrp));
119 OF_getencprop(node, "#size-cells", sizep, sizeof(*sizep));
123 bman_portals_fdt_probe(device_t dev)
126 if (!ofw_bus_is_compatible(dev, "bman-portals"))
129 device_set_desc(dev, BMAN_PORT_DEVSTR);
131 return (BUS_PROBE_DEFAULT);
135 bman_portals_fdt_attach(device_t dev)
137 struct dpaa_portals_softc *sc;
138 struct resource_list_entry *rle;
139 phandle_t node, child, cpu_node;
140 vm_paddr_t portal_pa;
141 vm_size_t portal_size;
144 int cpu_num, cpus, intr_rid;
145 struct dpaa_portals_devinfo di;
146 struct ofw_bus_devinfo ofw_di;
149 sc = device_get_softc(dev);
152 node = ofw_bus_get_node(dev);
153 get_addr_props(node, &addr, &size);
155 /* Find portals tied to CPUs */
156 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
157 if (!fdt_is_compatible(child, "fsl,bman-portal")) {
160 /* Checkout related cpu */
161 if (OF_getprop(child, "cpu-handle", (void *)&cpu,
165 /* Acquire cpu number */
166 cpu_node = OF_instance_to_package(cpu);
167 if (OF_getencprop(cpu_node, "reg", &cpu_num, sizeof(cpu_num)) <= 0) {
168 device_printf(dev, "Could not retrieve CPU number.\n");
177 if (ofw_bus_gen_setup_devinfo(&ofw_di, child) != 0) {
178 device_printf(dev, "could not set up devinfo\n");
182 resource_list_init(&di.di_res);
183 if (ofw_bus_reg_to_rl(dev, child, addr, size, &di.di_res)) {
184 device_printf(dev, "%s: could not process 'reg' "
185 "property\n", ofw_di.obd_name);
186 ofw_bus_gen_destroy_devinfo(&ofw_di);
189 if (ofw_bus_intr_to_rl(dev, child, &di.di_res, &intr_rid)) {
190 device_printf(dev, "%s: could not process "
191 "'interrupts' property\n", ofw_di.obd_name);
192 resource_list_free(&di.di_res);
193 ofw_bus_gen_destroy_devinfo(&ofw_di);
196 di.di_intr_rid = intr_rid;
198 ofw_reg_to_paddr(child, 0, &portal_pa, &portal_size, NULL);
199 rle = resource_list_find(&di.di_res, SYS_RES_MEMORY, 0);
201 if (sc->sc_dp_pa == 0)
202 sc->sc_dp_pa = portal_pa - rle->start;
204 portal_size = rle->end + 1;
205 rle = resource_list_find(&di.di_res, SYS_RES_MEMORY, 1);
206 portal_size = ulmax(rle->end + 1, portal_size);
207 sc->sc_dp_size = ulmax(sc->sc_dp_size, portal_size);
209 if (dpaa_portal_alloc_res(dev, &di, cpu_num))
213 ofw_bus_gen_destroy_devinfo(&ofw_di);
215 return (bman_portals_attach(dev));
217 resource_list_free(&di.di_res);
218 ofw_bus_gen_destroy_devinfo(&ofw_di);
219 bman_portals_detach(dev);