uninorth.c (d2f1e0e4a589fb49f3ac9488def99497465b39ac) uninorth.c (98f8e6c0994e851cd0a5e28e12f7e82c1ad034d4)
1/*-
1/*
2 * Copyright (C) 2002 Benno Rice.
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.

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

22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
2 * Copyright (C) 2002 Benno Rice.
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.

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

22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/module.h>
31#include <sys/bus.h>
32#include <sys/conf.h>
33#include <sys/kernel.h>
34
35#include <dev/ofw/openfirm.h>
30#include <sys/bus.h>
31#include <sys/conf.h>
32#include <sys/kernel.h>
33
34#include <dev/ofw/openfirm.h>
36#include <dev/ofw/ofw_pci.h>
37#include <dev/ofw/ofw_bus.h>
35#include <dev/ofw/ofw_bus.h>
38#include <dev/ofw/ofw_bus_subr.h>
36#include <dev/ofw/ofw_pci.h>
39
40#include <dev/pci/pcivar.h>
41#include <dev/pci/pcireg.h>
42
43#include <machine/bus.h>
44#include <machine/md_var.h>
37
38#include <dev/pci/pcivar.h>
39#include <dev/pci/pcireg.h>
40
41#include <machine/bus.h>
42#include <machine/md_var.h>
45#include <machine/pio.h>
43#include <machine/nexusvar.h>
46#include <machine/resource.h>
47
48#include <sys/rman.h>
49
44#include <machine/resource.h>
45
46#include <sys/rman.h>
47
48#include <powerpc/ofw/ofw_pci.h>
50#include <powerpc/powermac/uninorthvar.h>
51
52#include <vm/vm.h>
53#include <vm/pmap.h>
54
55#include "pcib_if.h"
56
57#define UNINORTH_DEBUG 0

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

78 */
79static int uninorth_maxslots(device_t);
80static u_int32_t uninorth_read_config(device_t, u_int, u_int, u_int,
81 u_int, int);
82static void uninorth_write_config(device_t, u_int, u_int, u_int,
83 u_int, u_int32_t, int);
84static int uninorth_route_interrupt(device_t, device_t, int);
85
49#include <powerpc/powermac/uninorthvar.h>
50
51#include <vm/vm.h>
52#include <vm/pmap.h>
53
54#include "pcib_if.h"
55
56#define UNINORTH_DEBUG 0

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

77 */
78static int uninorth_maxslots(device_t);
79static u_int32_t uninorth_read_config(device_t, u_int, u_int, u_int,
80 u_int, int);
81static void uninorth_write_config(device_t, u_int, u_int, u_int,
82 u_int, u_int32_t, int);
83static int uninorth_route_interrupt(device_t, device_t, int);
84
86/*
87 * OFW Bus interface
88 */
85static bus_space_tag_t uninorth_alloc_bus_tag(struct uninorth_softc *sc,
86 int type);
89
87
90static phandle_t uninorth_get_node(device_t bus, device_t dev);
91
92/*
93 * Local routines.
94 */
95static int uninorth_enable_config(struct uninorth_softc *, u_int,
96 u_int, u_int, u_int);
88/*
89 * Local routines.
90 */
91static int uninorth_enable_config(struct uninorth_softc *, u_int,
92 u_int, u_int, u_int);
97static void unin_enable_gmac(void);
98
99/*
100 * Driver methods.
101 */
102static device_method_t uninorth_methods[] = {
103 /* Device interface */
104 DEVMETHOD(device_probe, uninorth_probe),
105 DEVMETHOD(device_attach, uninorth_attach),

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

113 DEVMETHOD(bus_activate_resource, uninorth_activate_resource),
114
115 /* pcib interface */
116 DEVMETHOD(pcib_maxslots, uninorth_maxslots),
117 DEVMETHOD(pcib_read_config, uninorth_read_config),
118 DEVMETHOD(pcib_write_config, uninorth_write_config),
119 DEVMETHOD(pcib_route_interrupt, uninorth_route_interrupt),
120
93
94/*
95 * Driver methods.
96 */
97static device_method_t uninorth_methods[] = {
98 /* Device interface */
99 DEVMETHOD(device_probe, uninorth_probe),
100 DEVMETHOD(device_attach, uninorth_attach),

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

108 DEVMETHOD(bus_activate_resource, uninorth_activate_resource),
109
110 /* pcib interface */
111 DEVMETHOD(pcib_maxslots, uninorth_maxslots),
112 DEVMETHOD(pcib_read_config, uninorth_read_config),
113 DEVMETHOD(pcib_write_config, uninorth_write_config),
114 DEVMETHOD(pcib_route_interrupt, uninorth_route_interrupt),
115
121 /* ofw_bus interface */
122 DEVMETHOD(ofw_bus_get_node, uninorth_get_node),
123
124 { 0, 0 }
125};
126
127static driver_t uninorth_driver = {
128 "pcib",
129 uninorth_methods,
130 sizeof(struct uninorth_softc)
131};
132
133static devclass_t uninorth_devclass;
134
135DRIVER_MODULE(uninorth, nexus, uninorth_driver, uninorth_devclass, 0, 0);
136
137static int
138uninorth_probe(device_t dev)
139{
116 { 0, 0 }
117};
118
119static driver_t uninorth_driver = {
120 "pcib",
121 uninorth_methods,
122 sizeof(struct uninorth_softc)
123};
124
125static devclass_t uninorth_devclass;
126
127DRIVER_MODULE(uninorth, nexus, uninorth_driver, uninorth_devclass, 0, 0);
128
129static int
130uninorth_probe(device_t dev)
131{
140 const char *type, *compatible;
132 char *type, *compatible;
141
133
142 type = ofw_bus_get_type(dev);
143 compatible = ofw_bus_get_compat(dev);
134 type = nexus_get_device_type(dev);
135 compatible = nexus_get_compatible(dev);
144
145 if (type == NULL || compatible == NULL)
146 return (ENXIO);
147
136
137 if (type == NULL || compatible == NULL)
138 return (ENXIO);
139
148 if (strcmp(type, "pci") != 0)
140 if (strcmp(type, "pci") != 0 || strcmp(compatible, "uni-north") != 0)
149 return (ENXIO);
150
141 return (ENXIO);
142
151 if (strcmp(compatible, "uni-north") == 0) {
152 device_set_desc(dev, "Apple UniNorth Host-PCI bridge");
153 return (0);
154 } else if (strcmp(compatible,"u3-agp") == 0) {
155 device_set_desc(dev, "Apple U3 Host-AGP bridge");
156 return (0);
157 }
158
159 return (ENXIO);
143 device_set_desc(dev, "Apple UniNorth Host-PCI bridge");
144 return (0);
160}
161
162static int
163uninorth_attach(device_t dev)
164{
165 struct uninorth_softc *sc;
145}
146
147static int
148uninorth_attach(device_t dev)
149{
150 struct uninorth_softc *sc;
166 const char *compatible;
167 phandle_t node, child;
151 phandle_t node;
168 u_int32_t reg[2], busrange[2];
169 struct uninorth_range *rp, *io, *mem[2];
152 u_int32_t reg[2], busrange[2];
153 struct uninorth_range *rp, *io, *mem[2];
170 int nmem, i, error;
154 int nmem, i;
171
155
172 node = ofw_bus_get_node(dev);
156 node = nexus_get_node(dev);
173 sc = device_get_softc(dev);
174
175 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
176 return (ENXIO);
177
178 if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
179 return (ENXIO);
180
157 sc = device_get_softc(dev);
158
159 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
160 return (ENXIO);
161
162 if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
163 return (ENXIO);
164
181 sc->sc_u3 = 0;
182 compatible = ofw_bus_get_compat(dev);
183 if (strcmp(compatible,"u3-agp") == 0)
184 sc->sc_u3 = 1;
185
186 sc->sc_dev = dev;
187 sc->sc_node = node;
165 sc->sc_dev = dev;
166 sc->sc_node = node;
188 if (sc->sc_u3) {
189 sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[1] + 0x800000, PAGE_SIZE);
190 sc->sc_data = (vm_offset_t)pmap_mapdev(reg[1] + 0xc00000, PAGE_SIZE);
191 } else {
192 sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE);
193 sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE);
194 }
167 sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE);
168 sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE);
195 sc->sc_bus = busrange[0];
196
169 sc->sc_bus = busrange[0];
170
171 ofw_pci_fixup(dev, sc->sc_bus, node);
172
197 bzero(sc->sc_range, sizeof(sc->sc_range));
173 bzero(sc->sc_range, sizeof(sc->sc_range));
198 if (sc->sc_u3) {
199 /*
200 * On Apple U3 systems, we have an otherwise standard
201 * Uninorth controller driving AGP. The one difference
202 * is that it uses a new PCI ranges format, so do the
203 * translation.
204 */
174 sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range,
175 sizeof(sc->sc_range));
205
176
206 struct uninorth_range64 range64[6];
207 bzero(range64, sizeof(range64));
208
209 sc->sc_nrange = OF_getprop(node, "ranges", range64,
210 sizeof(range64));
211 for (i = 0; range64[i].pci_hi != 0; i++) {
212 sc->sc_range[i].pci_hi = range64[i].pci_hi;
213 sc->sc_range[i].pci_mid = range64[i].pci_mid;
214 sc->sc_range[i].pci_lo = range64[i].pci_lo;
215 sc->sc_range[i].host = range64[i].host_lo;
216 sc->sc_range[i].size_hi = range64[i].size_hi;
217 sc->sc_range[i].size_lo = range64[i].size_lo;
218 }
219 } else {
220 sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range,
221 sizeof(sc->sc_range));
222 }
223
224 if (sc->sc_nrange == -1) {
225 device_printf(dev, "could not get ranges\n");
226 return (ENXIO);
227 }
228
229 sc->sc_range[6].pci_hi = 0;
230 io = NULL;
231 nmem = 0;

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

247 }
248
249 if (io == NULL) {
250 device_printf(dev, "can't find io range\n");
251 return (ENXIO);
252 }
253 sc->sc_io_rman.rm_type = RMAN_ARRAY;
254 sc->sc_io_rman.rm_descr = "UniNorth PCI I/O Ports";
177 if (sc->sc_nrange == -1) {
178 device_printf(dev, "could not get ranges\n");
179 return (ENXIO);
180 }
181
182 sc->sc_range[6].pci_hi = 0;
183 io = NULL;
184 nmem = 0;

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

200 }
201
202 if (io == NULL) {
203 device_printf(dev, "can't find io range\n");
204 return (ENXIO);
205 }
206 sc->sc_io_rman.rm_type = RMAN_ARRAY;
207 sc->sc_io_rman.rm_descr = "UniNorth PCI I/O Ports";
255 sc->sc_iostart = io->host;
256 if (rman_init(&sc->sc_io_rman) != 0 ||
257 rman_manage_region(&sc->sc_io_rman, io->pci_lo,
208 if (rman_init(&sc->sc_io_rman) != 0 ||
209 rman_manage_region(&sc->sc_io_rman, io->pci_lo,
258 io->pci_lo + io->size_lo - 1) != 0) {
259 panic("uninorth_attach: failed to set up I/O rman");
210 io->pci_lo + io->size_lo) != 0) {
211 device_printf(dev, "failed to set up io range management\n");
212 return (ENXIO);
260 }
261
262 if (nmem == 0) {
263 device_printf(dev, "can't find mem ranges\n");
264 return (ENXIO);
265 }
266 sc->sc_mem_rman.rm_type = RMAN_ARRAY;
267 sc->sc_mem_rman.rm_descr = "UniNorth PCI Memory";
213 }
214
215 if (nmem == 0) {
216 device_printf(dev, "can't find mem ranges\n");
217 return (ENXIO);
218 }
219 sc->sc_mem_rman.rm_type = RMAN_ARRAY;
220 sc->sc_mem_rman.rm_descr = "UniNorth PCI Memory";
268 error = rman_init(&sc->sc_mem_rman);
269 if (error) {
270 device_printf(dev, "rman_init() failed. error = %d\n", error);
271 return (error);
221 if (rman_init(&sc->sc_mem_rman) != 0) {
222 device_printf(dev,
223 "failed to init mem range resources\n");
224 return (ENXIO);
272 }
273 for (i = 0; i < nmem; i++) {
225 }
226 for (i = 0; i < nmem; i++) {
274 error = rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo,
275 mem[i]->pci_lo + mem[i]->size_lo - 1);
276 if (error) {
227 if (rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo,
228 mem[i]->pci_lo + mem[i]->size_lo) != 0) {
277 device_printf(dev,
229 device_printf(dev,
278 "rman_manage_region() failed. error = %d\n", error);
279 return (error);
230 "failed to set up memory range management\n");
231 return (ENXIO);
280 }
281 }
282
232 }
233 }
234
283 /*
284 * Enable the GMAC Ethernet cell if Open Firmware says it is
285 * used.
286 */
287 for (child = OF_child(node); child; child = OF_peer(child)) {
288 char compat[32];
235#if 0
236 sc->sc_iot = uninorth_alloc_bus_tag(sc, PCI_IO_BUS_SPACE);
237 sc->sc_memt = uninorth_alloc_bus_tag(sc, PCI_MEMORY_BUS_SPACE);
238#endif
289
239
290 memset(compat, 0, sizeof(compat));
291 OF_getprop(child, "compatible", compat, sizeof(compat));
292 if (strcmp(compat, "gmac") == 0) {
293 unin_enable_gmac();
294 }
295 }
296
297 ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(cell_t));
298
299 device_add_child(dev, "pci", device_get_unit(dev));
300 return (bus_generic_attach(dev));
301}
302
303static int
304uninorth_maxslots(device_t dev)
305{
306

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

314 struct uninorth_softc *sc;
315 vm_offset_t caoff;
316
317 sc = device_get_softc(dev);
318 caoff = sc->sc_data + (reg & 0x07);
319
320 if (uninorth_enable_config(sc, bus, slot, func, reg) != 0) {
321 switch (width) {
240 device_add_child(dev, "pci", device_get_unit(dev));
241 return (bus_generic_attach(dev));
242}
243
244static int
245uninorth_maxslots(device_t dev)
246{
247

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

255 struct uninorth_softc *sc;
256 vm_offset_t caoff;
257
258 sc = device_get_softc(dev);
259 caoff = sc->sc_data + (reg & 0x07);
260
261 if (uninorth_enable_config(sc, bus, slot, func, reg) != 0) {
262 switch (width) {
322 case 1:
263 case 1:
323 return (in8rb(caoff));
324 break;
325 case 2:
326 return (in16rb(caoff));
327 break;
328 case 4:
329 return (in32rb(caoff));
330 break;

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

343
344 sc = device_get_softc(dev);
345 caoff = sc->sc_data + (reg & 0x07);
346
347 if (uninorth_enable_config(sc, bus, slot, func, reg)) {
348 switch (width) {
349 case 1:
350 out8rb(caoff, val);
264 return (in8rb(caoff));
265 break;
266 case 2:
267 return (in16rb(caoff));
268 break;
269 case 4:
270 return (in32rb(caoff));
271 break;

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

284
285 sc = device_get_softc(dev);
286 caoff = sc->sc_data + (reg & 0x07);
287
288 if (uninorth_enable_config(sc, bus, slot, func, reg)) {
289 switch (width) {
290 case 1:
291 out8rb(caoff, val);
292 (void)in8rb(caoff);
351 break;
352 case 2:
353 out16rb(caoff, val);
293 break;
294 case 2:
295 out16rb(caoff, val);
296 (void)in16rb(caoff);
354 break;
355 case 4:
356 out32rb(caoff, val);
297 break;
298 case 4:
299 out32rb(caoff, val);
300 (void)in32rb(caoff);
357 break;
358 }
359 }
360}
361
362static int
363uninorth_route_interrupt(device_t bus, device_t dev, int pin)
364{
301 break;
302 }
303 }
304}
305
306static int
307uninorth_route_interrupt(device_t bus, device_t dev, int pin)
308{
365 struct uninorth_softc *sc;
366 struct ofw_pci_register reg;
367 uint32_t pintr, mintr;
368 uint8_t maskbuf[sizeof(reg) + sizeof(pintr)];
369
309
370 sc = device_get_softc(bus);
371 pintr = pin;
372 if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo, &reg,
373 sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf))
374 return (mintr);
375
376 /* Maybe it's a real interrupt, not an intpin */
377 if (pin > 4)
378 return (pin);
379
380 device_printf(bus, "could not route pin %d for device %d.%d\n",
381 pin, pci_get_slot(dev), pci_get_function(dev));
382 return (PCI_INVALID_IRQ);
310 return (0);
383}
384
385static int
386uninorth_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
387{
388 struct uninorth_softc *sc;
389
390 sc = device_get_softc(dev);
391
392 switch (which) {
311}
312
313static int
314uninorth_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
315{
316 struct uninorth_softc *sc;
317
318 sc = device_get_softc(dev);
319
320 switch (which) {
393 case PCIB_IVAR_DOMAIN:
394 *result = device_get_unit(dev);
395 return (0);
396 case PCIB_IVAR_BUS:
397 *result = sc->sc_bus;
398 return (0);
321 case PCIB_IVAR_BUS:
322 *result = sc->sc_bus;
323 return (0);
324 break;
399 }
400
401 return (ENOENT);
402}
403
404static struct resource *
405uninorth_alloc_resource(device_t bus, device_t child, int type, int *rid,
406 u_long start, u_long end, u_long count, u_int flags)
407{
408 struct uninorth_softc *sc;
409 struct resource *rv;
410 struct rman *rm;
325 }
326
327 return (ENOENT);
328}
329
330static struct resource *
331uninorth_alloc_resource(device_t bus, device_t child, int type, int *rid,
332 u_long start, u_long end, u_long count, u_int flags)
333{
334 struct uninorth_softc *sc;
335 struct resource *rv;
336 struct rman *rm;
337 bus_space_tag_t bt;
411 int needactivate;
412
413 needactivate = flags & RF_ACTIVE;
414 flags &= ~RF_ACTIVE;
415
416 sc = device_get_softc(bus);
417
418 switch (type) {
419 case SYS_RES_MEMORY:
420 rm = &sc->sc_mem_rman;
338 int needactivate;
339
340 needactivate = flags & RF_ACTIVE;
341 flags &= ~RF_ACTIVE;
342
343 sc = device_get_softc(bus);
344
345 switch (type) {
346 case SYS_RES_MEMORY:
347 rm = &sc->sc_mem_rman;
348 bt = sc->sc_memt;
421 break;
349 break;
422
423 case SYS_RES_IOPORT:
424 rm = &sc->sc_io_rman;
425 break;
426
427 case SYS_RES_IRQ:
428 return (bus_alloc_resource(bus, type, rid, start, end, count,
429 flags));
350 case SYS_RES_IRQ:
351 return (bus_alloc_resource(bus, type, rid, start, end, count,
352 flags));
430
353 break;
431 default:
432 device_printf(bus, "unknown resource request from %s\n",
433 device_get_nameunit(child));
434 return (NULL);
435 }
436
437 rv = rman_reserve_resource(rm, start, end, count, flags, child);
438 if (rv == NULL) {
439 device_printf(bus, "failed to reserve resource for %s\n",
440 device_get_nameunit(child));
441 return (NULL);
442 }
443
354 default:
355 device_printf(bus, "unknown resource request from %s\n",
356 device_get_nameunit(child));
357 return (NULL);
358 }
359
360 rv = rman_reserve_resource(rm, start, end, count, flags, child);
361 if (rv == NULL) {
362 device_printf(bus, "failed to reserve resource for %s\n",
363 device_get_nameunit(child));
364 return (NULL);
365 }
366
444 rman_set_rid(rv, *rid);
367 rman_set_bustag(rv, bt);
368 rman_set_bushandle(rv, rman_get_start(rv));
445
446 if (needactivate) {
447 if (bus_activate_resource(child, type, *rid, rv) != 0) {
448 device_printf(bus,
449 "failed to activate resource for %s\n",
450 device_get_nameunit(child));
451 rman_release_resource(rv);
452 return (NULL);
453 }
454 }
455
456 return (rv);
457}
458
459static int
460uninorth_activate_resource(device_t bus, device_t child, int type, int rid,
461 struct resource *res)
462{
463 void *p;
369
370 if (needactivate) {
371 if (bus_activate_resource(child, type, *rid, rv) != 0) {
372 device_printf(bus,
373 "failed to activate resource for %s\n",
374 device_get_nameunit(child));
375 rman_release_resource(rv);
376 return (NULL);
377 }
378 }
379
380 return (rv);
381}
382
383static int
384uninorth_activate_resource(device_t bus, device_t child, int type, int rid,
385 struct resource *res)
386{
387 void *p;
464 struct uninorth_softc *sc;
465
388
466 sc = device_get_softc(bus);
467
468 if (type == SYS_RES_IRQ)
469 return (bus_activate_resource(bus, type, rid, res));
470
389 if (type == SYS_RES_IRQ)
390 return (bus_activate_resource(bus, type, rid, res));
391
471 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
472 vm_offset_t start;
473
474 start = (vm_offset_t)rman_get_start(res);
475 /*
476 * For i/o-ports, convert the start address to the
477 * uninorth PCI i/o window
478 */
479 if (type == SYS_RES_IOPORT)
480 start += sc->sc_iostart;
481
482 if (bootverbose)
483 printf("uninorth mapdev: start %x, len %ld\n", start,
484 rman_get_size(res));
485
486 p = pmap_mapdev(start, (vm_size_t)rman_get_size(res));
392 if (type == SYS_RES_MEMORY) {
393 p = pmap_mapdev((vm_offset_t)rman_get_start(res),
394 (vm_size_t)rman_get_size(res));
487 if (p == NULL)
488 return (ENOMEM);
489 rman_set_virtual(res, p);
395 if (p == NULL)
396 return (ENOMEM);
397 rman_set_virtual(res, p);
490 rman_set_bustag(res, &bs_le_tag);
491 rman_set_bushandle(res, (u_long)p);
492 }
493
494 return (rman_activate_resource(res));
495}
496
398 rman_set_bushandle(res, (u_long)p);
399 }
400
401 return (rman_activate_resource(res));
402}
403
404#if 0
405static bus_space_tag_t
406uninorth_alloc_bus_tag(struct uninorth_softc *sc, int type)
407{
408 bus_space_tag_t bt;
409
410 bt = (bus_space_tag_t)malloc(sizeof(struct bus_space_tag), M_DEVBUF,
411 M_NOWAIT | M_ZERO);
412 if (bt == NULL)
413 panic("uninorth_alloc_bus_tag: out of memory");
414
415 bzero(bt, sizeof(struct bus_space_tag));
416 bt->cookie = sc;
417#if 0
418 bt->parent = sc->sc_bustag;
419#endif
420 bt->type = type;
421
422 return (bt);
423}
424#endif
425
497static int
498uninorth_enable_config(struct uninorth_softc *sc, u_int bus, u_int slot,
499 u_int func, u_int reg)
500{
426static int
427uninorth_enable_config(struct uninorth_softc *sc, u_int bus, u_int slot,
428 u_int func, u_int reg)
429{
501 uint32_t cfgval;
502 uint32_t pass;
430 u_int32_t cfgval;
503
431
504 if (resource_int_value(device_get_name(sc->sc_dev),
505 device_get_unit(sc->sc_dev), "skipslot", &pass) == 0) {
506 if (pass == slot)
507 return (0);
508 }
509
510 if (sc->sc_bus == bus) {
511 /*
512 * No slots less than 11 on the primary bus
513 */
514 if (slot < 11)
515 return (0);
516
517 cfgval = (1 << slot) | (func << 8) | (reg & 0xfc);
518 } else {
519 cfgval = (bus << 16) | (slot << 11) | (func << 8) |
520 (reg & 0xfc) | 1;
521 }
432 if (sc->sc_bus == bus) {
433 /*
434 * No slots less than 11 on the primary bus
435 */
436 if (slot < 11)
437 return (0);
438
439 cfgval = (1 << slot) | (func << 8) | (reg & 0xfc);
440 } else {
441 cfgval = (bus << 16) | (slot << 11) | (func << 8) |
442 (reg & 0xfc) | 1;
443 }
522
444
523 do {
524 out32rb(sc->sc_addr, cfgval);
525 } while (in32rb(sc->sc_addr) != cfgval);
526
527 return (1);
528}
529
445 do {
446 out32rb(sc->sc_addr, cfgval);
447 } while (in32rb(sc->sc_addr) != cfgval);
448
449 return (1);
450}
451
530static phandle_t
531uninorth_get_node(device_t bus, device_t dev)
532{
533 struct uninorth_softc *sc;
534
535 sc = device_get_softc(bus);
536 /* We only have one child, the PCI bus, which needs our own node. */
537
538 return sc->sc_node;
539}
540
541/*
542 * Driver to swallow UniNorth host bridges from the PCI bus side.
543 */
544static int
545unhb_probe(device_t dev)
546{
547
548 if (pci_get_class(dev) == PCIC_BRIDGE &&

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

573static driver_t unhb_driver = {
574 "unhb",
575 unhb_methods,
576 1,
577};
578static devclass_t unhb_devclass;
579
580DRIVER_MODULE(unhb, pci, unhb_driver, unhb_devclass, 0, 0);
452/*
453 * Driver to swallow UniNorth host bridges from the PCI bus side.
454 */
455static int
456unhb_probe(device_t dev)
457{
458
459 if (pci_get_class(dev) == PCIC_BRIDGE &&

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

484static driver_t unhb_driver = {
485 "unhb",
486 unhb_methods,
487 1,
488};
489static devclass_t unhb_devclass;
490
491DRIVER_MODULE(unhb, pci, unhb_driver, unhb_devclass, 0, 0);
581
582
583/*
584 * Small stub driver for the Uninorth chip itself, to allow setting
585 * of various parameters and cell enables
586 */
587static struct unin_chip_softc *uncsc;
588
589static void
590unin_enable_gmac(void)
591{
592 volatile u_int *clkreg;
593 u_int32_t tmpl;
594
595 if (uncsc == NULL)
596 panic("unin_enable_gmac: device not found");
597
598 clkreg = (void *)(uncsc->sc_addr + UNIN_CLOCKCNTL);
599 tmpl = inl(clkreg);
600 tmpl |= UNIN_CLOCKCNTL_GMAC;
601 outl(clkreg, tmpl);
602}
603
604static int
605unin_chip_probe(device_t dev)
606{
607 const char *name;
608
609 name = ofw_bus_get_name(dev);
610
611 if (name == NULL)
612 return (ENXIO);
613
614 if (strcmp(name, "uni-n") != 0 && strcmp(name, "u3") != 0)
615 return (ENXIO);
616
617 device_set_desc(dev, "Apple UniNorth System Controller");
618 return (0);
619}
620
621static int
622unin_chip_attach(device_t dev)
623{
624 phandle_t node;
625 u_int reg[3];
626 int i = 0;
627
628 uncsc = device_get_softc(dev);
629 node = ofw_bus_get_node(dev);
630
631 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
632 return (ENXIO);
633
634 if (strcmp(ofw_bus_get_name(dev), "u3") == 0)
635 i = 1; /* #address-cells lies */
636
637 uncsc->sc_physaddr = reg[i];
638 uncsc->sc_size = reg[i+1];
639
640 /*
641 * Only map the first page, since that is where the registers
642 * of interest lie.
643 */
644 uncsc->sc_addr = (vm_offset_t) pmap_mapdev(uncsc->sc_physaddr,
645 PAGE_SIZE);
646
647 uncsc->sc_version = *(u_int *)uncsc->sc_addr;
648 device_printf(dev, "Version %d\n", uncsc->sc_version);
649
650 return (0);
651}
652
653static device_method_t unin_chip_methods[] = {
654 /* Device interface */
655 DEVMETHOD(device_probe, unin_chip_probe),
656 DEVMETHOD(device_attach, unin_chip_attach),
657
658 { 0, 0 }
659};
660
661static driver_t unin_chip_driver = {
662 "unin",
663 unin_chip_methods,
664 sizeof(struct unin_chip_softc)
665};
666
667static devclass_t unin_chip_devclass;
668
669DRIVER_MODULE(unin, nexus, unin_chip_driver, unin_chip_devclass, 0, 0);
670
671
672
673