cuda.c (194027) | cuda.c (205506) |
---|---|
1/*- 2 * Copyright (c) 2006 Michael Lorenz 3 * Copyright 2008 by Nathan Whitehorn 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Michael Lorenz 3 * Copyright 2008 by Nathan Whitehorn 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 15 unchanged lines hidden (view full) --- 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sys/powerpc/powermac/cuda.c 194027 2009-06-11 17:16:04Z avg $"); | 32__FBSDID("$FreeBSD: head/sys/powerpc/powermac/cuda.c 205506 2010-03-23 03:14:44Z nwhitehorn $"); |
33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38#include <sys/conf.h> 39#include <sys/kernel.h> | 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/module.h> 37#include <sys/bus.h> 38#include <sys/conf.h> 39#include <sys/kernel.h> |
40#include <sys/clock.h> |
|
40 41#include <dev/ofw/ofw_bus.h> 42#include <dev/ofw/openfirm.h> 43 44#include <machine/bus.h> 45#include <machine/intr.h> 46#include <machine/intr_machdep.h> 47#include <machine/md_var.h> 48#include <machine/pio.h> 49#include <machine/resource.h> 50 51#include <vm/vm.h> 52#include <vm/pmap.h> 53 54#include <sys/rman.h> 55 56#include <dev/adb/adb.h> 57 | 41 42#include <dev/ofw/ofw_bus.h> 43#include <dev/ofw/openfirm.h> 44 45#include <machine/bus.h> 46#include <machine/intr.h> 47#include <machine/intr_machdep.h> 48#include <machine/md_var.h> 49#include <machine/pio.h> 50#include <machine/resource.h> 51 52#include <vm/vm.h> 53#include <vm/pmap.h> 54 55#include <sys/rman.h> 56 57#include <dev/adb/adb.h> 58 |
59#include "clock_if.h" |
|
58#include "cudavar.h" 59#include "viareg.h" 60 61/* 62 * MacIO interface 63 */ 64static int cuda_probe(device_t); 65static int cuda_attach(device_t); 66static int cuda_detach(device_t); 67 68static u_int cuda_adb_send(device_t dev, u_char command_byte, int len, 69 u_char *data, u_char poll); 70static u_int cuda_adb_autopoll(device_t dev, uint16_t mask); 71static u_int cuda_poll(device_t dev); 72static void cuda_send_inbound(struct cuda_softc *sc); 73static void cuda_send_outbound(struct cuda_softc *sc); 74 | 60#include "cudavar.h" 61#include "viareg.h" 62 63/* 64 * MacIO interface 65 */ 66static int cuda_probe(device_t); 67static int cuda_attach(device_t); 68static int cuda_detach(device_t); 69 70static u_int cuda_adb_send(device_t dev, u_char command_byte, int len, 71 u_char *data, u_char poll); 72static u_int cuda_adb_autopoll(device_t dev, uint16_t mask); 73static u_int cuda_poll(device_t dev); 74static void cuda_send_inbound(struct cuda_softc *sc); 75static void cuda_send_outbound(struct cuda_softc *sc); 76 |
77/* 78 * Clock interface 79 */ 80static int cuda_gettime(device_t dev, struct timespec *ts); 81static int cuda_settime(device_t dev, struct timespec *ts); 82 |
|
75static device_method_t cuda_methods[] = { 76 /* Device interface */ 77 DEVMETHOD(device_probe, cuda_probe), 78 DEVMETHOD(device_attach, cuda_attach), 79 DEVMETHOD(device_detach, cuda_detach), 80 DEVMETHOD(device_shutdown, bus_generic_shutdown), 81 DEVMETHOD(device_suspend, bus_generic_suspend), 82 DEVMETHOD(device_resume, bus_generic_resume), 83 84 /* bus interface, for ADB root */ 85 DEVMETHOD(bus_print_child, bus_generic_print_child), 86 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 87 88 /* ADB bus interface */ 89 DEVMETHOD(adb_hb_send_raw_packet, cuda_adb_send), 90 DEVMETHOD(adb_hb_controller_poll, cuda_poll), 91 DEVMETHOD(adb_hb_set_autopoll_mask, cuda_adb_autopoll), 92 | 83static device_method_t cuda_methods[] = { 84 /* Device interface */ 85 DEVMETHOD(device_probe, cuda_probe), 86 DEVMETHOD(device_attach, cuda_attach), 87 DEVMETHOD(device_detach, cuda_detach), 88 DEVMETHOD(device_shutdown, bus_generic_shutdown), 89 DEVMETHOD(device_suspend, bus_generic_suspend), 90 DEVMETHOD(device_resume, bus_generic_resume), 91 92 /* bus interface, for ADB root */ 93 DEVMETHOD(bus_print_child, bus_generic_print_child), 94 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 95 96 /* ADB bus interface */ 97 DEVMETHOD(adb_hb_send_raw_packet, cuda_adb_send), 98 DEVMETHOD(adb_hb_controller_poll, cuda_poll), 99 DEVMETHOD(adb_hb_set_autopoll_mask, cuda_adb_autopoll), 100 |
101 /* Clock interface */ 102 DEVMETHOD(clock_gettime, cuda_gettime), 103 DEVMETHOD(clock_settime, cuda_settime), 104 |
|
93 { 0, 0 }, 94}; 95 96static driver_t cuda_driver = { 97 "cuda", 98 cuda_methods, 99 sizeof(struct cuda_softc), 100}; --- 67 unchanged lines hidden (view full) --- 168 mtx_init(&sc->sc_mutex,"cuda",NULL,MTX_DEF | MTX_RECURSE); 169 170 sc->sc_sent = 0; 171 sc->sc_received = 0; 172 sc->sc_waiting = 0; 173 sc->sc_polling = 0; 174 sc->sc_state = CUDA_NOTREADY; 175 sc->sc_autopoll = 0; | 105 { 0, 0 }, 106}; 107 108static driver_t cuda_driver = { 109 "cuda", 110 cuda_methods, 111 sizeof(struct cuda_softc), 112}; --- 67 unchanged lines hidden (view full) --- 180 mtx_init(&sc->sc_mutex,"cuda",NULL,MTX_DEF | MTX_RECURSE); 181 182 sc->sc_sent = 0; 183 sc->sc_received = 0; 184 sc->sc_waiting = 0; 185 sc->sc_polling = 0; 186 sc->sc_state = CUDA_NOTREADY; 187 sc->sc_autopoll = 0; |
188 sc->sc_rtc = -1; |
|
176 177 STAILQ_INIT(&sc->sc_inq); 178 STAILQ_INIT(&sc->sc_outq); 179 STAILQ_INIT(&sc->sc_freeq); 180 181 for (i = 0; i < CUDA_MAXPACKETS; i++) 182 STAILQ_INSERT_TAIL(&sc->sc_freeq, &sc->sc_pkts[i], pkt_q); 183 --- 47 unchanged lines hidden (view full) --- 231 if (bootverbose) 232 device_printf(dev, "CUDA child <%s>\n",name); 233 234 if (strncmp(name, "adb", 4) == 0) { 235 sc->adb_bus = device_add_child(dev,"adb",-1); 236 } 237 } 238 | 189 190 STAILQ_INIT(&sc->sc_inq); 191 STAILQ_INIT(&sc->sc_outq); 192 STAILQ_INIT(&sc->sc_freeq); 193 194 for (i = 0; i < CUDA_MAXPACKETS; i++) 195 STAILQ_INSERT_TAIL(&sc->sc_freeq, &sc->sc_pkts[i], pkt_q); 196 --- 47 unchanged lines hidden (view full) --- 244 if (bootverbose) 245 device_printf(dev, "CUDA child <%s>\n",name); 246 247 if (strncmp(name, "adb", 4) == 0) { 248 sc->adb_bus = device_add_child(dev,"adb",-1); 249 } 250 } 251 |
252 clock_register(dev, 1000); 253 |
|
239 return (bus_generic_attach(dev)); 240} 241 242static int cuda_detach(device_t dev) { 243 struct cuda_softc *sc; 244 245 sc = device_get_softc(dev); 246 --- 192 unchanged lines hidden (view full) --- 439 pkt->len - 2,&pkt->data[2]); 440 } else { 441 adb_receive_raw_packet(sc->adb_bus, 442 pkt->data[0],pkt->data[1],0,NULL); 443 } 444 break; 445 case CUDA_PSEUDO: 446 mtx_lock(&sc->sc_mutex); | 254 return (bus_generic_attach(dev)); 255} 256 257static int cuda_detach(device_t dev) { 258 struct cuda_softc *sc; 259 260 sc = device_get_softc(dev); 261 --- 192 unchanged lines hidden (view full) --- 454 pkt->len - 2,&pkt->data[2]); 455 } else { 456 adb_receive_raw_packet(sc->adb_bus, 457 pkt->data[0],pkt->data[1],0,NULL); 458 } 459 break; 460 case CUDA_PSEUDO: 461 mtx_lock(&sc->sc_mutex); |
447 if (pkt->data[0] == CMD_AUTOPOLL) | 462 switch (pkt->data[1]) { 463 case CMD_AUTOPOLL: |
448 sc->sc_autopoll = 1; | 464 sc->sc_autopoll = 1; |
465 break; 466 case CMD_READ_RTC: 467 memcpy(&sc->sc_rtc, &pkt->data[2], 468 sizeof(sc->sc_rtc)); 469 wakeup(&sc->sc_rtc); 470 break; 471 case CMD_WRITE_RTC: 472 break; 473 } |
|
449 mtx_unlock(&sc->sc_mutex); 450 break; 451 case CUDA_ERROR: 452 /* 453 * CUDA will throw errors if we miss a race between 454 * sending and receiving packets. This is already 455 * handled when we abort packet output to handle 456 * this packet in cuda_intr(). Thus, we ignore --- 253 unchanged lines hidden (view full) --- 710 sc->sc_autopoll = -1; 711 cuda_send(sc, 1, 3, cmd); 712 713 mtx_unlock(&sc->sc_mutex); 714 715 return (0); 716} 717 | 474 mtx_unlock(&sc->sc_mutex); 475 break; 476 case CUDA_ERROR: 477 /* 478 * CUDA will throw errors if we miss a race between 479 * sending and receiving packets. This is already 480 * handled when we abort packet output to handle 481 * this packet in cuda_intr(). Thus, we ignore --- 253 unchanged lines hidden (view full) --- 735 sc->sc_autopoll = -1; 736 cuda_send(sc, 1, 3, cmd); 737 738 mtx_unlock(&sc->sc_mutex); 739 740 return (0); 741} 742 |
743#define DIFF19041970 2082844800 744 745static int 746cuda_gettime(device_t dev, struct timespec *ts) 747{ 748 struct cuda_softc *sc = device_get_softc(dev); 749 uint8_t cmd[] = {CUDA_PSEUDO, CMD_READ_RTC}; 750 751 mtx_lock(&sc->sc_mutex); 752 sc->sc_rtc = -1; 753 cuda_send(sc, 1, 2, cmd); 754 if (sc->sc_rtc == -1) 755 mtx_sleep(&sc->sc_rtc, &sc->sc_mutex, 0, "rtc", 100); 756 757 ts->tv_sec = sc->sc_rtc - DIFF19041970; 758 ts->tv_nsec = 0; 759 mtx_unlock(&sc->sc_mutex); 760 761 return (0); 762} 763 764static int 765cuda_settime(device_t dev, struct timespec *ts) 766{ 767 struct cuda_softc *sc = device_get_softc(dev); 768 uint8_t cmd[] = {CUDA_PSEUDO, CMD_WRITE_RTC, 0, 0, 0, 0}; 769 uint32_t sec; 770 771 sec = ts->tv_sec + DIFF19041970; 772 memcpy(&cmd[2], &sec, sizeof(sec)); 773 774 mtx_lock(&sc->sc_mutex); 775 cuda_send(sc, 0, 6, cmd); 776 mtx_unlock(&sc->sc_mutex); 777 778 return (0); 779} 780 |
|