Deleted Added
sdiff udiff text old ( 146995 ) new ( 152684 )
full compact
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 146995 2005-06-05 10:16:27Z 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/openfirm.h>
40
41#include <machine/bus.h>
42#include <machine/bus_common.h>
43#include <machine/resource.h>
44
45#include <sys/rman.h>
46

--- 5 unchanged lines hidden (view full) ---

52 driver_intr_t *fc_func;
53 void *fc_arg;
54 void *fc_cookie;
55 bus_space_tag_t fc_bt;
56 bus_space_handle_t fc_bh;
57};
58
59struct fhc_devinfo {
60 char *fdi_compat;
61 char *fdi_model;
62 char *fdi_name;
63 char *fdi_type;
64 phandle_t fdi_node;
65 struct resource_list fdi_rl;
66};
67
68static void fhc_intr_stub(void *);
69static void fhc_led_func(void *, int);
70
71int
72fhc_probe(device_t dev)
73{
74
75 return (0);
76}
77
78int
79fhc_attach(device_t dev)
80{
81 char ledname[sizeof("boardXX")];
82 struct fhc_devinfo *fdi;
83 struct sbus_regs *reg;
84 struct fhc_softc *sc;
85 phandle_t child;
86 phandle_t node;
87 bus_addr_t size;
88 bus_addr_t off;
89 device_t cdev;
90 uint32_t ctrl;
91 uint32_t *intr;
92 uint32_t iv;
93 char *name;
94 int nintr;
95 int nreg;
96 int i;

--- 37 unchanged lines hidden (view full) ---

134 }
135
136 if ((sc->sc_flags & FHC_CENTRAL) == 0) {
137 snprintf(ledname, sizeof(ledname), "board%d", sc->sc_board);
138 sc->sc_led_dev = led_create(fhc_led_func, sc, ledname);
139 }
140
141 for (child = OF_child(node); child != 0; child = OF_peer(child)) {
142 if ((OF_getprop_alloc(child, "name", 1, (void **)&name)) == -1)
143 continue;
144 cdev = device_add_child(dev, NULL, -1);
145 if (cdev != NULL) {
146 fdi = malloc(sizeof(*fdi), M_DEVBUF, M_WAITOK | M_ZERO);
147 if (fdi == NULL)
148 continue;
149 fdi->fdi_name = name;
150 fdi->fdi_node = child;
151 OF_getprop_alloc(child, "compatible", 1,
152 (void **)&fdi->fdi_compat);
153 OF_getprop_alloc(child, "device_type", 1,
154 (void **)&fdi->fdi_type);
155 OF_getprop_alloc(child, "model", 1,
156 (void **)&fdi->fdi_model);
157 resource_list_init(&fdi->fdi_rl);
158 nreg = OF_getprop_alloc(child, "reg", sizeof(*reg),
159 (void **)&reg);
160 if (nreg != -1) {
161 for (i = 0; i < nreg; i++) {
162 off = reg[i].sbr_offset;
163 size = reg[i].sbr_size;
164 resource_list_add(&fdi->fdi_rl,
165 SYS_RES_MEMORY, i, off, off + size,
166 size);
167 }
168 free(reg, M_OFWPROP);
169 }
170 nintr = OF_getprop_alloc(child, "interrupts",
171 sizeof(*intr), (void **)&intr);
172 if (nintr != -1) {
173 for (i = 0; i < nintr; i++) {
174 iv = INTINO(intr[i]) |
175 (sc->sc_ign << INTMAP_IGN_SHIFT);
176 resource_list_add(&fdi->fdi_rl,
177 SYS_RES_IRQ, i, iv, iv, 1);
178 }
179 free(intr, M_OFWPROP);
180 }
181 device_set_ivars(cdev, fdi);
182 } else
183 free(name, M_OFWPROP);
184 }
185
186 return (bus_generic_attach(dev));
187}
188
189int
190fhc_print_child(device_t dev, device_t child)
191{
192 struct fhc_devinfo *fdi;
193 int rv;
194
195 fdi = device_get_ivars(child);
196 rv = bus_print_child_header(dev, child);
197 rv += resource_list_print_type(&fdi->fdi_rl, "mem",
198 SYS_RES_MEMORY, "%#lx");
199 rv += resource_list_print_type(&fdi->fdi_rl, "irq", SYS_RES_IRQ, "%ld");
200 rv += bus_print_child_footer(dev, child);
201 return (rv);
202}
203
204void
205fhc_probe_nomatch(device_t dev, device_t child)
206{
207 struct fhc_devinfo *fdi;
208
209 fdi = device_get_ivars(child);
210 device_printf(dev, "<%s>", fdi->fdi_name);
211 resource_list_print_type(&fdi->fdi_rl, "mem", SYS_RES_MEMORY, "%#lx");
212 resource_list_print_type(&fdi->fdi_rl, "irq", SYS_RES_IRQ, "%ld");
213 printf(" type %s (no driver attached)\n",
214 fdi->fdi_type != NULL ? fdi->fdi_type : "unknown");
215}
216
217int
218fhc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
219 driver_intr_t *func, void *arg, void **cookiep)
220{
221 struct fhc_softc *sc;
222 struct fhc_clr *fc;

--- 137 unchanged lines hidden (view full) ---

360fhc_get_resource_list(device_t bus, device_t child)
361{
362 struct fhc_devinfo *fdi;
363
364 fdi = device_get_ivars(child);
365 return (&fdi->fdi_rl);
366}
367
368static void
369fhc_led_func(void *arg, int onoff)
370{
371 struct fhc_softc *sc;
372 uint32_t ctrl;
373
374 sc = (struct fhc_softc *)arg;
375

--- 5 unchanged lines hidden (view full) ---

381 ctrl &= ~FHC_CTRL_RLED;
382 ctrl &= ~(FHC_CTRL_AOFF | FHC_CTRL_BOFF | FHC_CTRL_SLINE);
383 bus_space_write_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
384 FHC_CTRL, ctrl);
385 bus_space_read_4(sc->sc_bt[FHC_INTERNAL], sc->sc_bh[FHC_INTERNAL],
386 FHC_CTRL);
387}
388
389const char *
390fhc_get_compat(device_t bus, device_t dev)
391{
392 struct fhc_devinfo *dinfo;
393
394 dinfo = device_get_ivars(dev);
395 return (dinfo->fdi_compat);
396}
397
398const char *
399fhc_get_model(device_t bus, device_t dev)
400{
401 struct fhc_devinfo *dinfo;
402
403 dinfo = device_get_ivars(dev);
404 return (dinfo->fdi_model);
405}
406
407const char *
408fhc_get_name(device_t bus, device_t dev)
409{
410 struct fhc_devinfo *dinfo;
411
412 dinfo = device_get_ivars(dev);
413 return (dinfo->fdi_name);
414}
415
416phandle_t
417fhc_get_node(device_t bus, device_t dev)
418{
419 struct fhc_devinfo *dinfo;
420
421 dinfo = device_get_ivars(dev);
422 return (dinfo->fdi_node);
423}
424
425const char *
426fhc_get_type(device_t bus, device_t dev)
427{
428 struct fhc_devinfo *dinfo;
429
430 dinfo = device_get_ivars(dev);
431 return (dinfo->fdi_type);
432}