ofwbus.c (183882) | ofwbus.c (205506) |
---|---|
1/*- 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 38 unchanged lines hidden (view full) --- 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09 54 * | 1/*- 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 38 unchanged lines hidden (view full) --- 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * from: FreeBSD: src/sys/i386/i386/nexus.c,v 1.43 2001/02/09 54 * |
55 * $FreeBSD: head/sys/powerpc/aim/nexus.c 183882 2008-10-14 14:54:14Z nwhitehorn $ | 55 * $FreeBSD: head/sys/powerpc/aim/nexus.c 205506 2010-03-23 03:14:44Z nwhitehorn $ |
56 */ 57#include "opt_psim.h" 58 59#include <sys/param.h> 60#include <sys/systm.h> 61#include <sys/module.h> 62#include <sys/bus.h> | 56 */ 57#include "opt_psim.h" 58 59#include <sys/param.h> 60#include <sys/systm.h> 61#include <sys/module.h> 62#include <sys/bus.h> |
63#include <sys/clock.h> | |
64#include <sys/cons.h> 65#include <sys/kernel.h> 66#include <sys/malloc.h> 67 68#include <dev/ofw/openfirm.h> 69 70#include <machine/bus.h> 71#include <machine/frame.h> 72#include <machine/intr_machdep.h> 73#include <machine/resource.h> 74 75#include <sys/rman.h> 76 | 63#include <sys/cons.h> 64#include <sys/kernel.h> 65#include <sys/malloc.h> 66 67#include <dev/ofw/openfirm.h> 68 69#include <machine/bus.h> 70#include <machine/frame.h> 71#include <machine/intr_machdep.h> 72#include <machine/resource.h> 73 74#include <sys/rman.h> 75 |
77#include "clock_if.h" | |
78#include "ofw_bus_if.h" 79#include "pic_if.h" 80 81/* 82 * The nexus (which is a pseudo-bus actually) iterates over the nodes that 83 * exist in Open Firmware and adds them as devices to this bus so that drivers 84 * can be attached to them. 85 * --- 52 unchanged lines hidden (view full) --- 138 * OFW bus interface. 139 */ 140static phandle_t nexus_ofw_get_node(device_t, device_t); 141static const char *nexus_ofw_get_name(device_t, device_t); 142static const char *nexus_ofw_get_type(device_t, device_t); 143static const char *nexus_ofw_get_compat(device_t, device_t); 144 145/* | 76#include "ofw_bus_if.h" 77#include "pic_if.h" 78 79/* 80 * The nexus (which is a pseudo-bus actually) iterates over the nodes that 81 * exist in Open Firmware and adds them as devices to this bus so that drivers 82 * can be attached to them. 83 * --- 52 unchanged lines hidden (view full) --- 136 * OFW bus interface. 137 */ 138static phandle_t nexus_ofw_get_node(device_t, device_t); 139static const char *nexus_ofw_get_name(device_t, device_t); 140static const char *nexus_ofw_get_type(device_t, device_t); 141static const char *nexus_ofw_get_compat(device_t, device_t); 142 143/* |
146 * Clock interface. 147 */ 148static int nexus_gettime(device_t, struct timespec *); 149static int nexus_settime(device_t, struct timespec *); 150 151/* | |
152 * Local routines 153 */ 154static device_t nexus_device_from_node(device_t, phandle_t); 155 156static device_method_t nexus_methods[] = { 157 /* Device interface */ 158 DEVMETHOD(device_probe, nexus_probe), 159 DEVMETHOD(device_attach, nexus_attach), --- 16 unchanged lines hidden (view full) --- 176 DEVMETHOD(bus_release_resource, nexus_release_resource), 177 178 /* OFW bus interface */ 179 DEVMETHOD(ofw_bus_get_node, nexus_ofw_get_node), 180 DEVMETHOD(ofw_bus_get_name, nexus_ofw_get_name), 181 DEVMETHOD(ofw_bus_get_type, nexus_ofw_get_type), 182 DEVMETHOD(ofw_bus_get_compat, nexus_ofw_get_compat), 183 | 144 * Local routines 145 */ 146static device_t nexus_device_from_node(device_t, phandle_t); 147 148static device_method_t nexus_methods[] = { 149 /* Device interface */ 150 DEVMETHOD(device_probe, nexus_probe), 151 DEVMETHOD(device_attach, nexus_attach), --- 16 unchanged lines hidden (view full) --- 168 DEVMETHOD(bus_release_resource, nexus_release_resource), 169 170 /* OFW bus interface */ 171 DEVMETHOD(ofw_bus_get_node, nexus_ofw_get_node), 172 DEVMETHOD(ofw_bus_get_name, nexus_ofw_get_name), 173 DEVMETHOD(ofw_bus_get_type, nexus_ofw_get_type), 174 DEVMETHOD(ofw_bus_get_compat, nexus_ofw_get_compat), 175 |
184 /* Clock interface */ 185 DEVMETHOD(clock_gettime, nexus_gettime), 186 DEVMETHOD(clock_settime, nexus_settime), 187 | |
188 { 0, 0 } 189}; 190 191static driver_t nexus_driver = { 192 "nexus", 193 nexus_methods, 194 sizeof(struct nexus_softc), 195}; --- 39 unchanged lines hidden (view full) --- 235 */ 236 for (child = OF_child(root); child != 0; child = OF_peer(child)) { 237 if (child == -1) 238 panic("nexus_probe(): OF_child failed."); 239 (void)nexus_device_from_node(dev, child); 240 241 } 242 | 176 { 0, 0 } 177}; 178 179static driver_t nexus_driver = { 180 "nexus", 181 nexus_methods, 182 sizeof(struct nexus_softc), 183}; --- 39 unchanged lines hidden (view full) --- 223 */ 224 for (child = OF_child(root); child != 0; child = OF_peer(child)) { 225 if (child == -1) 226 panic("nexus_probe(): OF_child failed."); 227 (void)nexus_device_from_node(dev, child); 228 229 } 230 |
243 clock_register(dev, 1000); | |
244 return (bus_generic_attach(dev)); 245} 246 247static void 248nexus_probe_nomatch(device_t dev, device_t child) 249{ 250 char *name, *type; 251 --- 255 unchanged lines hidden (view full) --- 507 struct nexus_devinfo *dinfo; 508 509 if ((dinfo = device_get_ivars(dev)) == NULL) 510 return (NULL); 511 512 return (dinfo->ndi_compatible); 513} 514 | 231 return (bus_generic_attach(dev)); 232} 233 234static void 235nexus_probe_nomatch(device_t dev, device_t child) 236{ 237 char *name, *type; 238 --- 255 unchanged lines hidden (view full) --- 494 struct nexus_devinfo *dinfo; 495 496 if ((dinfo = device_get_ivars(dev)) == NULL) 497 return (NULL); 498 499 return (dinfo->ndi_compatible); 500} 501 |
515#define DIFF19041970 2082844800 516 517static int 518nexus_gettime(device_t dev, struct timespec *ts) 519{ 520 char path[128]; 521 ihandle_t ih; 522 phandle_t ph; 523 u_int rtc; 524 525 ph = OF_finddevice("rtc"); 526 if (ph == -1) 527 return (ENOENT); 528 529 OF_package_to_path(ph, path, sizeof(path)); 530 ih = OF_open(path); 531 if (ih == -1) 532 return (ENXIO); 533 534 if (OF_call_method("read-rtc", ih, 0, 1, &rtc)) 535 return (EIO); 536 537 ts->tv_sec = rtc - DIFF19041970; 538 ts->tv_nsec = 0; 539 return (0); 540} 541 542static int 543nexus_settime(device_t dev, struct timespec *ts) 544{ 545 char path[128]; 546 ihandle_t ih; 547 phandle_t ph; 548 u_int rtc; 549 550 ph = OF_finddevice("rtc"); 551 if (ph == -1) 552 return (ENOENT); 553 554 OF_package_to_path(ph, path, sizeof(path)); 555 ih = OF_open(path); 556 if (ih == -1) 557 return (ENXIO); 558 559 rtc = ts->tv_sec + DIFF19041970; 560 return ((OF_call_method("write-rtc", ih, 1, 0, rtc) != 0) ? EIO : 0); 561} | |