uninorth.c (ec3772f3fddb2f1f93f91c761bd51ef841ef9883) uninorth.c (d48bbef30d9a93321e30c9c19cc448de57a17ba9)
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

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

81 u_int, u_int32_t, int);
82static int uninorth_route_interrupt(device_t, device_t, int);
83
84/*
85 * Local routines.
86 */
87static int uninorth_enable_config(struct uninorth_softc *, u_int,
88 u_int, u_int, u_int);
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

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

81 u_int, u_int32_t, int);
82static int uninorth_route_interrupt(device_t, device_t, int);
83
84/*
85 * Local routines.
86 */
87static int uninorth_enable_config(struct uninorth_softc *, u_int,
88 u_int, u_int, u_int);
89static void unin_enable_gmac(void);
89
90/*
91 * Driver methods.
92 */
93static device_method_t uninorth_methods[] = {
94 /* Device interface */
95 DEVMETHOD(device_probe, uninorth_probe),
96 DEVMETHOD(device_attach, uninorth_attach),

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

140 return (0);
141}
142
143static int
144uninorth_attach(device_t dev)
145{
146 struct uninorth_softc *sc;
147 phandle_t node;
90
91/*
92 * Driver methods.
93 */
94static device_method_t uninorth_methods[] = {
95 /* Device interface */
96 DEVMETHOD(device_probe, uninorth_probe),
97 DEVMETHOD(device_attach, uninorth_attach),

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

141 return (0);
142}
143
144static int
145uninorth_attach(device_t dev)
146{
147 struct uninorth_softc *sc;
148 phandle_t node;
149 phandle_t child;
148 u_int32_t reg[2], busrange[2];
149 struct uninorth_range *rp, *io, *mem[2];
150 int nmem, i;
151
152 node = nexus_get_node(dev);
153 sc = device_get_softc(dev);
154
155 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
156 return (ENXIO);
157
158 if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
159 return (ENXIO);
160
161 sc->sc_dev = dev;
162 sc->sc_node = node;
163 sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE);
164 sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE);
165 sc->sc_bus = busrange[0];
166
150 u_int32_t reg[2], busrange[2];
151 struct uninorth_range *rp, *io, *mem[2];
152 int nmem, i;
153
154 node = nexus_get_node(dev);
155 sc = device_get_softc(dev);
156
157 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
158 return (ENXIO);
159
160 if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
161 return (ENXIO);
162
163 sc->sc_dev = dev;
164 sc->sc_node = node;
165 sc->sc_addr = (vm_offset_t)pmap_mapdev(reg[0] + 0x800000, PAGE_SIZE);
166 sc->sc_data = (vm_offset_t)pmap_mapdev(reg[0] + 0xc00000, PAGE_SIZE);
167 sc->sc_bus = busrange[0];
168
167 ofw_pci_fixup(dev, sc->sc_bus, node);
168
169 bzero(sc->sc_range, sizeof(sc->sc_range));
170 sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range,
171 sizeof(sc->sc_range));
172
173 if (sc->sc_nrange == -1) {
174 device_printf(dev, "could not get ranges\n");
175 return (ENXIO);
176 }

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

223 if (rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo,
224 mem[i]->pci_lo + mem[i]->size_lo) != 0) {
225 device_printf(dev,
226 "failed to set up memory range management\n");
227 return (ENXIO);
228 }
229 }
230
169 bzero(sc->sc_range, sizeof(sc->sc_range));
170 sc->sc_nrange = OF_getprop(node, "ranges", sc->sc_range,
171 sizeof(sc->sc_range));
172
173 if (sc->sc_nrange == -1) {
174 device_printf(dev, "could not get ranges\n");
175 return (ENXIO);
176 }

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

223 if (rman_manage_region(&sc->sc_mem_rman, mem[i]->pci_lo,
224 mem[i]->pci_lo + mem[i]->size_lo) != 0) {
225 device_printf(dev,
226 "failed to set up memory range management\n");
227 return (ENXIO);
228 }
229 }
230
231 /*
232 * Enable the GMAC ethernet cell if OpenFirmware says it is
233 * used
234 */
235 for (child = OF_child(node); child; child = OF_peer(child)) {
236 char compat[32];
237
238 memset(compat, 0, sizeof(compat));
239 OF_getprop(child, "compatible", compat, sizeof(compat));
240 if (strcmp(compat, "gmac") == 0) {
241 unin_enable_gmac();
242 }
243 }
244
245 /*
246 * Write out the correct PIC interrupt values to config space
247 * of all devices on the bus. This has to be done after the GEM
248 * cell is enabled above.
249 */
250 ofw_pci_fixup(dev, sc->sc_bus, node);
251
231 device_add_child(dev, "pci", device_get_unit(dev));
232 return (bus_generic_attach(dev));
233}
234
235static int
236uninorth_maxslots(device_t dev)
237{
238

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

331 needactivate = flags & RF_ACTIVE;
332 flags &= ~RF_ACTIVE;
333
334 sc = device_get_softc(bus);
335
336 switch (type) {
337 case SYS_RES_MEMORY:
338 rm = &sc->sc_mem_rman;
252 device_add_child(dev, "pci", device_get_unit(dev));
253 return (bus_generic_attach(dev));
254}
255
256static int
257uninorth_maxslots(device_t dev)
258{
259

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

352 needactivate = flags & RF_ACTIVE;
353 flags &= ~RF_ACTIVE;
354
355 sc = device_get_softc(bus);
356
357 switch (type) {
358 case SYS_RES_MEMORY:
359 rm = &sc->sc_mem_rman;
339 bt = sc->sc_memt;
360 bt = PPC_BUS_SPACE_MEM;
361 if (flags & PPC_BUS_SPARSE4)
362 bt |= 4;
340 break;
341 case SYS_RES_IRQ:
342 return (bus_alloc_resource(bus, type, rid, start, end, count,
343 flags));
344 break;
345 default:
346 device_printf(bus, "unknown resource request from %s\n",
347 device_get_nameunit(child));

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

453static driver_t unhb_driver = {
454 "unhb",
455 unhb_methods,
456 1,
457};
458static devclass_t unhb_devclass;
459
460DRIVER_MODULE(unhb, pci, unhb_driver, unhb_devclass, 0, 0);
363 break;
364 case SYS_RES_IRQ:
365 return (bus_alloc_resource(bus, type, rid, start, end, count,
366 flags));
367 break;
368 default:
369 device_printf(bus, "unknown resource request from %s\n",
370 device_get_nameunit(child));

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

476static driver_t unhb_driver = {
477 "unhb",
478 unhb_methods,
479 1,
480};
481static devclass_t unhb_devclass;
482
483DRIVER_MODULE(unhb, pci, unhb_driver, unhb_devclass, 0, 0);
484
485
486/*
487 * Small stub driver for the Uninorth chip itself, to allow setting
488 * of various parameters and cell enables
489 */
490static struct unin_chip_softc *uncsc;
491
492static void
493unin_enable_gmac(void)
494{
495 volatile u_int *clkreg;
496 u_int32_t tmpl;
497
498 if (uncsc == NULL)
499 panic("unin_enable_gmac: device not found");
500
501 clkreg = (void *)(uncsc->sc_addr + UNIN_CLOCKCNTL);
502 tmpl = inl(clkreg);
503 tmpl |= UNIN_CLOCKCNTL_GMAC;
504 outl(clkreg, tmpl);
505}
506
507static int
508unin_chip_probe(device_t dev)
509{
510 char *name;
511
512 name = nexus_get_name(dev);
513
514 if (name == NULL)
515 return (ENXIO);
516
517 if (strcmp(name, "uni-n") != 0)
518 return (ENXIO);
519
520 device_set_desc(dev, "Apple UniNorth System Controller");
521 return (0);
522}
523
524static int
525unin_chip_attach(device_t dev)
526{
527 phandle_t node;
528 u_int reg[2];
529
530 uncsc = device_get_softc(dev);
531 node = nexus_get_node(dev);
532
533 if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
534 return (ENXIO);
535
536 uncsc->sc_physaddr = reg[0];
537 uncsc->sc_size = reg[1];
538
539 /*
540 * Only map the first page, since that is where the registers
541 * of interest lie.
542 */
543 uncsc->sc_addr = (vm_offset_t) pmap_mapdev(reg[0], PAGE_SIZE);
544
545 uncsc->sc_version = *(u_int *)uncsc->sc_addr;
546 device_printf(dev, "Version %d\n", uncsc->sc_version);
547
548 return (0);
549}
550
551static device_method_t unin_chip_methods[] = {
552 /* Device interface */
553 DEVMETHOD(device_probe, unin_chip_probe),
554 DEVMETHOD(device_attach, unin_chip_attach),
555
556 { 0, 0 }
557};
558
559static driver_t unin_chip_driver = {
560 "unin",
561 unin_chip_methods,
562 sizeof(struct unin_chip_softc)
563};
564
565static devclass_t unin_chip_devclass;
566
567DRIVER_MODULE(unin, nexus, unin_chip_driver, unin_chip_devclass, 0, 0);
568
569
570
571