1 /* $OpenBSD: pgs.c,v 1.3 2013/07/01 16:53:24 jasper Exp $ */ 2 /* 3 * Copyright (c) 2010 Jasper Lievisse Adriaanse <jasper@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* 19 * This driver allows entering DDB by pushing the "Programmers Switch", 20 * which can be found on many "Old World" and some early "New World" MacPPC. 21 */ 22 23 #include <sys/types.h> 24 #include <sys/param.h> 25 #include <sys/systm.h> 26 #include <sys/proc.h> 27 #include <sys/device.h> 28 29 #include <ddb/db_var.h> 30 #include <dev/ofw/openfirm.h> 31 32 #include <machine/bus.h> 33 #include <machine/autoconf.h> 34 35 struct pgs_softc { 36 struct device sc_dev; 37 int sc_node; 38 int sc_intr; 39 }; 40 41 void pgs_attach(struct device *, struct device *, void *); 42 int pgs_match(struct device *, void *, void *); 43 int pgs_intr(void *); 44 45 struct cfattach pgs_ca = { 46 sizeof(struct pgs_softc), pgs_match, pgs_attach 47 }; 48 49 struct cfdriver pgs_cd = { 50 NULL, "pgs", DV_DULL 51 }; 52 53 int 54 pgs_match(struct device *parent, void *arg, void *aux) 55 { 56 struct confargs *ca = aux; 57 char type[32]; 58 59 if (strcmp(ca->ca_name, "programmer-switch") != 0) 60 return 0; 61 62 OF_getprop(ca->ca_node, "device_type", type, sizeof(type)); 63 if (strcmp(type, "programmer-switch") != 0) 64 return 0; 65 66 return 1; 67 } 68 69 void 70 pgs_attach(struct device *parent, struct device *self, void *aux) 71 { 72 struct pgs_softc *sc = (struct pgs_softc *)self; 73 struct confargs *ca = aux; 74 int intr[2]; 75 76 sc->sc_node = ca->ca_node; 77 78 OF_getprop(sc->sc_node, "interrupts", intr, sizeof(intr)); 79 sc->sc_intr = intr[0]; 80 81 printf(": irq %d\n", sc->sc_intr); 82 83 mac_intr_establish(parent, sc->sc_intr, IST_LEVEL, 84 IPL_HIGH, pgs_intr, sc, sc->sc_dev.dv_xname); 85 } 86 87 int 88 pgs_intr(void *v) 89 { 90 #ifdef DDB 91 if (db_console) 92 Debugger(); 93 #else 94 printf("programmer-switch pressed, debugger not available.\n"); 95 #endif 96 97 return 1; 98 } 99