xref: /openbsd/sys/arch/macppc/dev/pgs.c (revision d415bd75)
1 /*	$OpenBSD: pgs.c,v 1.6 2022/03/13 12:33:01 mpi 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/param.h>
24 #include <sys/systm.h>
25 #include <sys/proc.h>
26 #include <sys/device.h>
27 
28 #include <ddb/db_var.h>
29 #include <dev/ofw/openfirm.h>
30 
31 #include <machine/bus.h>
32 #include <machine/autoconf.h>
33 
34 struct pgs_softc {
35 	struct device	sc_dev;
36 	int		sc_node;
37 	int 		sc_intr;
38 };
39 
40 void	pgs_attach(struct device *, struct device *, void *);
41 int	pgs_match(struct device *, void *, void *);
42 int	pgs_intr(void *);
43 
44 const struct cfattach pgs_ca = {
45 	sizeof(struct pgs_softc), pgs_match, pgs_attach
46 };
47 
48 struct cfdriver pgs_cd = {
49 	NULL, "pgs", DV_DULL
50 };
51 
52 int
53 pgs_match(struct device *parent, void *arg, void *aux)
54 {
55 	struct confargs *ca = aux;
56 	char type[32];
57 
58 	if (strcmp(ca->ca_name, "programmer-switch") != 0)
59 		return 0;
60 
61 	OF_getprop(ca->ca_node, "device_type", type, sizeof(type));
62 	if (strcmp(type, "programmer-switch") != 0)
63 		return 0;
64 
65 	return 1;
66 }
67 
68 void
69 pgs_attach(struct device *parent, struct device *self, void *aux)
70 {
71 	struct pgs_softc *sc = (struct pgs_softc *)self;
72 	struct confargs *ca = aux;
73 	int intr[2];
74 
75 	sc->sc_node = ca->ca_node;
76 
77 	OF_getprop(sc->sc_node, "interrupts", intr, sizeof(intr));
78 	sc->sc_intr = intr[0];
79 
80 	printf(": irq %d\n", sc->sc_intr);
81 
82 	mac_intr_establish(parent, sc->sc_intr, IST_LEVEL,
83 	    IPL_HIGH, pgs_intr, sc, sc->sc_dev.dv_xname);
84 }
85 
86 int
87 pgs_intr(void *v)
88 {
89 #ifdef DDB
90 	if (db_console)
91 		db_enter();
92 #else
93 	printf("programmer-switch pressed, debugger not available.\n");
94 #endif
95 
96 	return 1;
97 }
98