1/*-
2 * Copyright (c) 2003 Jake Burkholder.
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
--- 11 unchanged lines hidden (view full) ---
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 <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/sparc64/fhc/fhc.c 152684 2005-11-22 16:39:44Z marius $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/pcpu.h>
36
37#include <dev/led/led.h>
38#include <dev/ofw/ofw_bus.h>
39#include <dev/ofw/ofw_bus_subr.h>
40#include <dev/ofw/openfirm.h>
41
42#include <machine/bus.h>
43#include <machine/bus_common.h>
44#include <machine/resource.h>
45
46#include <sys/rman.h>
47
--- 5 unchanged lines hidden (view full) ---
53 driver_intr_t *fc_func;
54 void *fc_arg;
55 void *fc_cookie;
56 bus_space_tag_t fc_bt;
57 bus_space_handle_t fc_bh;
58};
59
60struct fhc_devinfo {
61 struct ofw_bus_devinfo fdi_obdinfo;
62 struct resource_list fdi_rl;
63};
64
65static void fhc_intr_stub(void *);
66static void fhc_led_func(void *, int);
67static int fhc_print_res(struct fhc_devinfo *);
68
69int
70fhc_probe(device_t dev)
71{
72
73 return (0);
74}
75
76int
77fhc_attach(device_t dev)
78{
79 char ledname[sizeof("boardXX")];
80 struct fhc_devinfo *fdi;
81 struct sbus_regs *reg;
82 struct fhc_softc *sc;
83 phandle_t child;
84 phandle_t node;
85 device_t cdev;
86 uint32_t ctrl;
87 uint32_t *intr;
88 uint32_t iv;
89 char *name;
90 int nintr;
91 int nreg;
92 int i;
--- 37 unchanged lines hidden (view full) ---
130 }
131
132 if ((sc->sc_flags & FHC_CENTRAL) == 0) {
133 snprintf(ledname, sizeof(ledname), "board%d", sc->sc_board);
134 sc->sc_led_dev = led_create(fhc_led_func, sc, ledname);
135 }
136
137 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
138 fdi = malloc(sizeof(*fdi), M_DEVBUF, M_WAITOK | M_ZERO);
139 if (ofw_bus_gen_setup_devinfo(&fdi->fdi_obdinfo, child) != 0) {
140 free(fdi, M_DEVBUF);
141 continue;
142 }
143 nreg = OF_getprop_alloc(child, "reg", sizeof(*reg),
144 (void **)®);
145 if (nreg == -1) {
146 device_printf(dev, "<%s>: incomplete\n",
147 fdi->fdi_obdinfo.obd_name);
148 ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo);
149 free(fdi, M_DEVBUF);
150 continue;
151 }
152 resource_list_init(&fdi->fdi_rl);
153 for (i = 0; i < nreg; i++)
154 resource_list_add(&fdi->fdi_rl, SYS_RES_MEMORY, i,
155 reg[i].sbr_offset, reg[i].sbr_offset +
156 reg[i].sbr_size, reg[i].sbr_size);
157 free(reg, M_OFWPROP);
158 nintr = OF_getprop_alloc(child, "interrupts", sizeof(*intr),
159 (void **)&intr);
160 if (nintr != -1) {
161 for (i = 0; i < nintr; i++) {
162 iv = INTINO(intr[i]) |
163 (sc->sc_ign << INTMAP_IGN_SHIFT);
164 resource_list_add(&fdi->fdi_rl, SYS_RES_IRQ, i,
165 iv, iv, 1);
166 }
167 free(intr, M_OFWPROP);
168 }
169 cdev = device_add_child(dev, NULL, -1);
170 if (cdev == NULL) {
171 device_printf(dev, "<%s>: device_add_child failed\n",
172 fdi->fdi_obdinfo.obd_name);
173 resource_list_free(&fdi->fdi_rl);
174 ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo);
175 free(fdi, M_DEVBUF);
176 continue;
177 }
178 device_set_ivars(cdev, fdi);
179 }
180
181 return (bus_generic_attach(dev));
182}
183
184int
185fhc_print_child(device_t dev, device_t child)
186{
187 int rv;
188
189 rv = bus_print_child_header(dev, child);
190 rv += fhc_print_res(device_get_ivars(child));
191 rv += bus_print_child_footer(dev, child);
192 return (rv);
193}
194
195void
196fhc_probe_nomatch(device_t dev, device_t child)
197{
198 const char *type;
199
200 device_printf(dev, "<%s>", ofw_bus_get_name(child));
201 fhc_print_res(device_get_ivars(child));
202 type = ofw_bus_get_type(child);
203 printf(" type %s (no driver attached)\n",
204 type != NULL ? type : "unknown");
205}
206
207int
208fhc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
209 driver_intr_t *func, void *arg, void **cookiep)
210{
211 struct fhc_softc *sc;
212 struct fhc_clr *fc;
--- 137 unchanged lines hidden (view full) ---
350fhc_get_resource_list(device_t bus, device_t child)
351{
352 struct fhc_devinfo *fdi;
353
354 fdi = device_get_ivars(child);
355 return (&fdi->fdi_rl);
356}
357
358const struct ofw_bus_devinfo *
359fhc_get_devinfo(device_t bus, device_t child)
360{
361 struct fhc_devinfo *fdi;
362
363 fdi = device_get_ivars(child);
364 return (&fdi->fdi_obdinfo);
365}
366
367static void
368fhc_led_func(void *arg, int onoff)
369{
370 struct fhc_softc *sc;
371 uint32_t ctrl;
372
373 sc = (struct fhc_softc *)arg;
374
--- 5 unchanged lines hidden (view full) ---
380 ctrl &= ~FHC_CTRL_RLED;
381 ctrl &= ~(FHC_CTRL_AOFF | FHC_CTRL_BOFF | FHC_CTRL_SLINE);
382 bus_space_write_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
383 FHC_CTRL, ctrl);
384 bus_space_read_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
385 FHC_CTRL);
386}
387
388static int
389fhc_print_res(struct fhc_devinfo *fdi)
390{
391 int rv;
392
393 rv = 0;
394 rv += resource_list_print_type(&fdi->fdi_rl, "mem", SYS_RES_MEMORY,
395 "%#lx");
396 rv += resource_list_print_type(&fdi->fdi_rl, "irq", SYS_RES_IRQ, "%ld");
397 return (rv);
398}
2 * Copyright (c) 2003 Jake Burkholder.
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
--- 11 unchanged lines hidden (view full) ---
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 <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/sparc64/fhc/fhc.c 152684 2005-11-22 16:39:44Z marius $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/pcpu.h>
36
37#include <dev/led/led.h>
38#include <dev/ofw/ofw_bus.h>
39#include <dev/ofw/ofw_bus_subr.h>
40#include <dev/ofw/openfirm.h>
41
42#include <machine/bus.h>
43#include <machine/bus_common.h>
44#include <machine/resource.h>
45
46#include <sys/rman.h>
47
--- 5 unchanged lines hidden (view full) ---
53 driver_intr_t *fc_func;
54 void *fc_arg;
55 void *fc_cookie;
56 bus_space_tag_t fc_bt;
57 bus_space_handle_t fc_bh;
58};
59
60struct fhc_devinfo {
61 struct ofw_bus_devinfo fdi_obdinfo;
62 struct resource_list fdi_rl;
63};
64
65static void fhc_intr_stub(void *);
66static void fhc_led_func(void *, int);
67static int fhc_print_res(struct fhc_devinfo *);
68
69int
70fhc_probe(device_t dev)
71{
72
73 return (0);
74}
75
76int
77fhc_attach(device_t dev)
78{
79 char ledname[sizeof("boardXX")];
80 struct fhc_devinfo *fdi;
81 struct sbus_regs *reg;
82 struct fhc_softc *sc;
83 phandle_t child;
84 phandle_t node;
85 device_t cdev;
86 uint32_t ctrl;
87 uint32_t *intr;
88 uint32_t iv;
89 char *name;
90 int nintr;
91 int nreg;
92 int i;
--- 37 unchanged lines hidden (view full) ---
130 }
131
132 if ((sc->sc_flags & FHC_CENTRAL) == 0) {
133 snprintf(ledname, sizeof(ledname), "board%d", sc->sc_board);
134 sc->sc_led_dev = led_create(fhc_led_func, sc, ledname);
135 }
136
137 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
138 fdi = malloc(sizeof(*fdi), M_DEVBUF, M_WAITOK | M_ZERO);
139 if (ofw_bus_gen_setup_devinfo(&fdi->fdi_obdinfo, child) != 0) {
140 free(fdi, M_DEVBUF);
141 continue;
142 }
143 nreg = OF_getprop_alloc(child, "reg", sizeof(*reg),
144 (void **)®);
145 if (nreg == -1) {
146 device_printf(dev, "<%s>: incomplete\n",
147 fdi->fdi_obdinfo.obd_name);
148 ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo);
149 free(fdi, M_DEVBUF);
150 continue;
151 }
152 resource_list_init(&fdi->fdi_rl);
153 for (i = 0; i < nreg; i++)
154 resource_list_add(&fdi->fdi_rl, SYS_RES_MEMORY, i,
155 reg[i].sbr_offset, reg[i].sbr_offset +
156 reg[i].sbr_size, reg[i].sbr_size);
157 free(reg, M_OFWPROP);
158 nintr = OF_getprop_alloc(child, "interrupts", sizeof(*intr),
159 (void **)&intr);
160 if (nintr != -1) {
161 for (i = 0; i < nintr; i++) {
162 iv = INTINO(intr[i]) |
163 (sc->sc_ign << INTMAP_IGN_SHIFT);
164 resource_list_add(&fdi->fdi_rl, SYS_RES_IRQ, i,
165 iv, iv, 1);
166 }
167 free(intr, M_OFWPROP);
168 }
169 cdev = device_add_child(dev, NULL, -1);
170 if (cdev == NULL) {
171 device_printf(dev, "<%s>: device_add_child failed\n",
172 fdi->fdi_obdinfo.obd_name);
173 resource_list_free(&fdi->fdi_rl);
174 ofw_bus_gen_destroy_devinfo(&fdi->fdi_obdinfo);
175 free(fdi, M_DEVBUF);
176 continue;
177 }
178 device_set_ivars(cdev, fdi);
179 }
180
181 return (bus_generic_attach(dev));
182}
183
184int
185fhc_print_child(device_t dev, device_t child)
186{
187 int rv;
188
189 rv = bus_print_child_header(dev, child);
190 rv += fhc_print_res(device_get_ivars(child));
191 rv += bus_print_child_footer(dev, child);
192 return (rv);
193}
194
195void
196fhc_probe_nomatch(device_t dev, device_t child)
197{
198 const char *type;
199
200 device_printf(dev, "<%s>", ofw_bus_get_name(child));
201 fhc_print_res(device_get_ivars(child));
202 type = ofw_bus_get_type(child);
203 printf(" type %s (no driver attached)\n",
204 type != NULL ? type : "unknown");
205}
206
207int
208fhc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
209 driver_intr_t *func, void *arg, void **cookiep)
210{
211 struct fhc_softc *sc;
212 struct fhc_clr *fc;
--- 137 unchanged lines hidden (view full) ---
350fhc_get_resource_list(device_t bus, device_t child)
351{
352 struct fhc_devinfo *fdi;
353
354 fdi = device_get_ivars(child);
355 return (&fdi->fdi_rl);
356}
357
358const struct ofw_bus_devinfo *
359fhc_get_devinfo(device_t bus, device_t child)
360{
361 struct fhc_devinfo *fdi;
362
363 fdi = device_get_ivars(child);
364 return (&fdi->fdi_obdinfo);
365}
366
367static void
368fhc_led_func(void *arg, int onoff)
369{
370 struct fhc_softc *sc;
371 uint32_t ctrl;
372
373 sc = (struct fhc_softc *)arg;
374
--- 5 unchanged lines hidden (view full) ---
380 ctrl &= ~FHC_CTRL_RLED;
381 ctrl &= ~(FHC_CTRL_AOFF | FHC_CTRL_BOFF | FHC_CTRL_SLINE);
382 bus_space_write_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
383 FHC_CTRL, ctrl);
384 bus_space_read_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
385 FHC_CTRL);
386}
387
388static int
389fhc_print_res(struct fhc_devinfo *fdi)
390{
391 int rv;
392
393 rv = 0;
394 rv += resource_list_print_type(&fdi->fdi_rl, "mem", SYS_RES_MEMORY,
395 "%#lx");
396 rv += resource_list_print_type(&fdi->fdi_rl, "irq", SYS_RES_IRQ, "%ld");
397 return (rv);
398}