1/*-
2 * Copyright (C) 2009 Nathan Whitehorn
3 * Copyright (C) 2015 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Andrew Turner
7 * under sponsorship from the FreeBSD Foundation.
8 *
--- 15 unchanged lines hidden (view full) ---
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_cpu.c 277491 2015-01-21 16:52:24Z andrew $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/malloc.h>
39#include <sys/bus.h>
40#include <sys/cpu.h>
--- 5 unchanged lines hidden (view full) ---
46
47static int ofw_cpulist_probe(device_t);
48static int ofw_cpulist_attach(device_t);
49static const struct ofw_bus_devinfo *ofw_cpulist_get_devinfo(device_t dev,
50 device_t child);
51
52static MALLOC_DEFINE(M_OFWCPU, "ofwcpu", "OFW CPU device information");
53
54struct ofw_cpulist_softc {
55 pcell_t sc_addr_cells;
56};
57
58static device_method_t ofw_cpulist_methods[] = {
59 /* Device interface */
60 DEVMETHOD(device_probe, ofw_cpulist_probe),
61 DEVMETHOD(device_attach, ofw_cpulist_attach),
62
63 /* Bus interface */
64 DEVMETHOD(bus_add_child, bus_generic_add_child),
65 DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
--- 7 unchanged lines hidden (view full) ---
73 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
74
75 DEVMETHOD_END
76};
77
78static driver_t ofw_cpulist_driver = {
79 "cpulist",
80 ofw_cpulist_methods,
81 sizeof(struct ofw_cpulist_softc)
82};
83
84static devclass_t ofw_cpulist_devclass;
85
86DRIVER_MODULE(ofw_cpulist, ofwbus, ofw_cpulist_driver, ofw_cpulist_devclass,
87 0, 0);
88
89static int
--- 9 unchanged lines hidden (view full) ---
99 device_set_desc(dev, "Open Firmware CPU Group");
100
101 return (0);
102}
103
104static int
105ofw_cpulist_attach(device_t dev)
106{
107 struct ofw_cpulist_softc *sc;
108 phandle_t root, child;
109 device_t cdev;
110 struct ofw_bus_devinfo *dinfo;
111
112 sc = device_get_softc(dev);
113 root = ofw_bus_get_node(dev);
114
115 sc->sc_addr_cells = 1;
116 OF_getencprop(root, "#address-cells", &sc->sc_addr_cells,
117 sizeof(sc->sc_addr_cells));
118
119 for (child = OF_child(root); child != 0; child = OF_peer(child)) {
120 dinfo = malloc(sizeof(*dinfo), M_OFWCPU, M_WAITOK | M_ZERO);
121
122 if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {
123 free(dinfo, M_OFWCPU);
124 continue;
125 }
126 cdev = device_add_child(dev, NULL, -1);
--- 19 unchanged lines hidden (view full) ---
146static int ofw_cpu_probe(device_t);
147static int ofw_cpu_attach(device_t);
148static int ofw_cpu_read_ivar(device_t dev, device_t child, int index,
149 uintptr_t *result);
150
151struct ofw_cpu_softc {
152 struct pcpu *sc_cpu_pcpu;
153 uint32_t sc_nominal_mhz;
154 boolean_t sc_reg_valid;
155 pcell_t sc_reg[2];
156};
157
158static device_method_t ofw_cpu_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, ofw_cpu_probe),
161 DEVMETHOD(device_attach, ofw_cpu_attach),
162
163 /* Bus interface */
--- 28 unchanged lines hidden (view full) ---
192
193 device_set_desc(dev, "Open Firmware CPU");
194 return (0);
195}
196
197static int
198ofw_cpu_attach(device_t dev)
199{
200 struct ofw_cpulist_softc *psc;
201 struct ofw_cpu_softc *sc;
202 phandle_t node;
203 pcell_t cell;
204 int rv;
205
206 sc = device_get_softc(dev);
207 psc = device_get_softc(device_get_parent(dev));
208
209 if (nitems(sc->sc_reg) < psc->sc_addr_cells) {
210 if (bootverbose)
211 device_printf(dev, "Too many address cells\n");
212 return (EINVAL);
213 }
214
215 node = ofw_bus_get_node(dev);
216
217 /* Read and validate the reg property for use later */
218 sc->sc_reg_valid = false;
219 rv = OF_getencprop(node, "reg", sc->sc_reg, sizeof(sc->sc_reg));
220 if (rv < 0)
221 device_printf(dev, "missing 'reg' property\n");
222 else if ((rv % 4) != 0) {
223 if (bootverbose)
224 device_printf(dev, "Malformed reg property\n");
225 } else if ((rv / 4) != psc->sc_addr_cells) {
226 if (bootverbose)
227 device_printf(dev, "Invalid reg size %u\n", rv);
228 } else
229 sc->sc_reg_valid = true;
230
231 sc->sc_cpu_pcpu = pcpu_find(device_get_unit(dev));
232
233 if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) < 0) {
234 if (bootverbose)
235 device_printf(dev,
236 "missing 'clock-frequency' property\n");
237 } else
238 sc->sc_nominal_mhz = cell / 1000000; /* convert to MHz */
239
240 bus_generic_probe(dev);
--- 25 unchanged lines hidden ---
2 * Copyright (C) 2009 Nathan Whitehorn
3 * Copyright (C) 2015 The FreeBSD Foundation
4 * All rights reserved.
5 *
6 * Portions of this software were developed by Andrew Turner
7 * under sponsorship from the FreeBSD Foundation.
8 *
--- 15 unchanged lines hidden (view full) ---
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/ofw/ofw_cpu.c 277491 2015-01-21 16:52:24Z andrew $");
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/malloc.h>
39#include <sys/bus.h>
40#include <sys/cpu.h>
--- 5 unchanged lines hidden (view full) ---
46
47static int ofw_cpulist_probe(device_t);
48static int ofw_cpulist_attach(device_t);
49static const struct ofw_bus_devinfo *ofw_cpulist_get_devinfo(device_t dev,
50 device_t child);
51
52static MALLOC_DEFINE(M_OFWCPU, "ofwcpu", "OFW CPU device information");
53
54struct ofw_cpulist_softc {
55 pcell_t sc_addr_cells;
56};
57
58static device_method_t ofw_cpulist_methods[] = {
59 /* Device interface */
60 DEVMETHOD(device_probe, ofw_cpulist_probe),
61 DEVMETHOD(device_attach, ofw_cpulist_attach),
62
63 /* Bus interface */
64 DEVMETHOD(bus_add_child, bus_generic_add_child),
65 DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
--- 7 unchanged lines hidden (view full) ---
73 DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
74
75 DEVMETHOD_END
76};
77
78static driver_t ofw_cpulist_driver = {
79 "cpulist",
80 ofw_cpulist_methods,
81 sizeof(struct ofw_cpulist_softc)
82};
83
84static devclass_t ofw_cpulist_devclass;
85
86DRIVER_MODULE(ofw_cpulist, ofwbus, ofw_cpulist_driver, ofw_cpulist_devclass,
87 0, 0);
88
89static int
--- 9 unchanged lines hidden (view full) ---
99 device_set_desc(dev, "Open Firmware CPU Group");
100
101 return (0);
102}
103
104static int
105ofw_cpulist_attach(device_t dev)
106{
107 struct ofw_cpulist_softc *sc;
108 phandle_t root, child;
109 device_t cdev;
110 struct ofw_bus_devinfo *dinfo;
111
112 sc = device_get_softc(dev);
113 root = ofw_bus_get_node(dev);
114
115 sc->sc_addr_cells = 1;
116 OF_getencprop(root, "#address-cells", &sc->sc_addr_cells,
117 sizeof(sc->sc_addr_cells));
118
119 for (child = OF_child(root); child != 0; child = OF_peer(child)) {
120 dinfo = malloc(sizeof(*dinfo), M_OFWCPU, M_WAITOK | M_ZERO);
121
122 if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {
123 free(dinfo, M_OFWCPU);
124 continue;
125 }
126 cdev = device_add_child(dev, NULL, -1);
--- 19 unchanged lines hidden (view full) ---
146static int ofw_cpu_probe(device_t);
147static int ofw_cpu_attach(device_t);
148static int ofw_cpu_read_ivar(device_t dev, device_t child, int index,
149 uintptr_t *result);
150
151struct ofw_cpu_softc {
152 struct pcpu *sc_cpu_pcpu;
153 uint32_t sc_nominal_mhz;
154 boolean_t sc_reg_valid;
155 pcell_t sc_reg[2];
156};
157
158static device_method_t ofw_cpu_methods[] = {
159 /* Device interface */
160 DEVMETHOD(device_probe, ofw_cpu_probe),
161 DEVMETHOD(device_attach, ofw_cpu_attach),
162
163 /* Bus interface */
--- 28 unchanged lines hidden (view full) ---
192
193 device_set_desc(dev, "Open Firmware CPU");
194 return (0);
195}
196
197static int
198ofw_cpu_attach(device_t dev)
199{
200 struct ofw_cpulist_softc *psc;
201 struct ofw_cpu_softc *sc;
202 phandle_t node;
203 pcell_t cell;
204 int rv;
205
206 sc = device_get_softc(dev);
207 psc = device_get_softc(device_get_parent(dev));
208
209 if (nitems(sc->sc_reg) < psc->sc_addr_cells) {
210 if (bootverbose)
211 device_printf(dev, "Too many address cells\n");
212 return (EINVAL);
213 }
214
215 node = ofw_bus_get_node(dev);
216
217 /* Read and validate the reg property for use later */
218 sc->sc_reg_valid = false;
219 rv = OF_getencprop(node, "reg", sc->sc_reg, sizeof(sc->sc_reg));
220 if (rv < 0)
221 device_printf(dev, "missing 'reg' property\n");
222 else if ((rv % 4) != 0) {
223 if (bootverbose)
224 device_printf(dev, "Malformed reg property\n");
225 } else if ((rv / 4) != psc->sc_addr_cells) {
226 if (bootverbose)
227 device_printf(dev, "Invalid reg size %u\n", rv);
228 } else
229 sc->sc_reg_valid = true;
230
231 sc->sc_cpu_pcpu = pcpu_find(device_get_unit(dev));
232
233 if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) < 0) {
234 if (bootverbose)
235 device_printf(dev,
236 "missing 'clock-frequency' property\n");
237 } else
238 sc->sc_nominal_mhz = cell / 1000000; /* convert to MHz */
239
240 bus_generic_probe(dev);
--- 25 unchanged lines hidden ---