1 /*-
2 * Copyright (c) 2011-2012 Semihalf.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 */
26
27 #include "opt_platform.h"
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/bus.h>
33 #include <sys/module.h>
34 #include <sys/smp.h>
35
36 #include <machine/bus.h>
37
38 #include <dev/ofw/ofw_bus.h>
39 #include <dev/ofw/ofw_bus_subr.h>
40 #include <dev/ofw/ofw_subr.h>
41
42 #include "bman.h"
43 #include "bman_var.h"
44 #include "portals.h"
45
46 #define FBMAN_DEVSTR "Freescale Buffer Manager"
47
48 static int bman_fdt_probe(device_t);
49
50 static device_method_t bman_methods[] = {
51 /* Device interface */
52 DEVMETHOD(device_probe, bman_fdt_probe),
53 DEVMETHOD(device_attach, bman_attach),
54 DEVMETHOD(device_detach, bman_detach),
55
56 DEVMETHOD(device_suspend, bman_suspend),
57 DEVMETHOD(device_resume, bman_resume),
58 DEVMETHOD(device_shutdown, bman_shutdown),
59
60 DEVMETHOD_END
61 };
62
63 DEFINE_CLASS_0(bman, bman_driver, bman_methods, sizeof(struct bman_softc));
64 EARLY_DRIVER_MODULE(bman, simplebus, bman_driver, 0, 0, BUS_PASS_SUPPORTDEV);
65
66 static int
bman_fdt_probe(device_t dev)67 bman_fdt_probe(device_t dev)
68 {
69
70 if (!ofw_bus_is_compatible(dev, "fsl,bman"))
71 return (ENXIO);
72
73 device_set_desc(dev, FBMAN_DEVSTR);
74
75 return (BUS_PROBE_DEFAULT);
76 }
77
78 /*
79 * BMAN Portals
80 */
81 #define BMAN_PORT_DEVSTR "Freescale Buffer Manager - Portal"
82
83 static int portal_ncpus;
84 static device_probe_t bman_portal_fdt_probe;
85 static device_attach_t bman_portal_fdt_attach;
86
87 static device_method_t bman_portal_methods[] = {
88 /* Device interface */
89 DEVMETHOD(device_probe, bman_portal_fdt_probe),
90 DEVMETHOD(device_attach, bman_portal_fdt_attach),
91 DEVMETHOD(device_detach, bman_portal_detach),
92
93 DEVMETHOD_END
94 };
95
96 DEFINE_CLASS_0(bman_portal, bman_portal_driver, bman_portal_methods,
97 sizeof(struct bman_portal_softc));
98 EARLY_DRIVER_MODULE(bman_portal, simplebus, bman_portal_driver, 0, 0,
99 BUS_PASS_SUPPORTDEV + BUS_PASS_ORDER_MIDDLE);
100
101 static int
bman_portal_fdt_probe(device_t dev)102 bman_portal_fdt_probe(device_t dev)
103 {
104 if (!ofw_bus_is_compatible(dev, "fsl,bman-portal"))
105 return (ENXIO);
106
107 device_set_desc(dev, BMAN_PORT_DEVSTR);
108 return (BUS_PROBE_DEFAULT);
109 }
110
111 static int
bman_portal_fdt_attach(device_t dev)112 bman_portal_fdt_attach(device_t dev)
113 {
114 int portal_cpu = portal_ncpus;
115
116 /* Don't attach to more portals than we have CPUs */
117 if (mp_ncpus == portal_ncpus)
118 return (ENXIO);
119
120 portal_ncpus++;
121
122 return (bman_portal_attach(dev, portal_cpu));
123 }
124