xref: /openbsd/sys/arch/hppa/gsc/gscbus.c (revision 898184e3)
1 /*	$OpenBSD: gscbus.c,v 1.30 2010/11/28 20:09:40 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 1998 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* #define GSCDEBUG */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <sys/malloc.h>
35 #include <sys/mbuf.h>
36 #include <sys/reboot.h>
37 
38 #include <machine/iomod.h>
39 #include <machine/autoconf.h>
40 #include <machine/cpufunc.h>
41 
42 #include <hppa/gsc/gscbusvar.h>
43 
44 int	gscmatch(struct device *, void *, void *);
45 void	gscattach(struct device *, struct device *, void *);
46 
47 struct cfattach gsc_ca = {
48 	sizeof(struct gsc_softc), gscmatch, gscattach
49 };
50 
51 struct cfdriver gsc_cd = {
52 	NULL, "gsc", DV_DULL
53 };
54 
55 int
56 gscmatch(parent, cfdata, aux)
57 	struct device *parent;
58 	void *cfdata;
59 	void *aux;
60 {
61 	struct confargs *ca = aux;
62 
63 	return !strcmp(ca->ca_name, "gsc");
64 }
65 
66 void
67 gscattach(parent, self, aux)
68 	struct device *parent;
69 	struct device *self;
70 	void *aux;
71 {
72 	struct gsc_softc *sc = (struct gsc_softc *)self;
73 	struct gsc_attach_args *ga = aux;
74 
75 	sc->sc_iot = ga->ga_iot;
76 	sc->sc_ic = ga->ga_ic;
77 
78 #ifdef USELEDS
79 	if (machine_ledaddr)
80 		printf(": %sleds", machine_ledword? "word" : "");
81 #endif
82 	printf ("\n");
83 
84 	sc->sc_ih = cpu_intr_establish(IPL_NESTED, ga->ga_irq,
85 	    gsc_intr, (void *)sc->sc_ic->gsc_base, sc->sc_dev.dv_xname);
86 
87 	pdc_scanbus(self, &ga->ga_ca, MAXMODBUS, 0, 0);
88 }
89 
90 int
91 gscprint(aux, pnp)
92 	void *aux;
93 	const char *pnp;
94 {
95 	struct gsc_attach_args *ga = aux;
96 
97 	if (pnp)
98 		printf("%s at %s", ga->ga_name, pnp);
99 	return (UNCONF);
100 }
101 
102 void *
103 gsc_intr_establish(sc, irq, pri, handler, arg, name)
104 	struct gsc_softc *sc;
105 	int pri;
106 	int irq;
107 	int (*handler)(void *v);
108 	void *arg;
109 	const char *name;
110 {
111 	volatile u_int32_t *r = sc->sc_ic->gsc_base;
112 	void *iv;
113 
114 	if ((iv = cpu_intr_map(sc->sc_ih, pri, irq, handler, arg, name)))
115 		r[1] |= (1 << irq);
116 	else {
117 #ifdef GSCDEBUG
118 		printf("%s: attaching irq %d, already occupied\n",
119 		       sc->sc_dev.dv_xname, irq);
120 #endif
121 	}
122 
123 	return (iv);
124 }
125 
126 void
127 gsc_intr_disestablish(sc, v)
128 	struct gsc_softc *sc;
129 	void *v;
130 {
131 #if notyet
132 	volatile u_int32_t *r = sc->sc_ic->gsc_base;
133 
134 	r[1] &= ~(1 << irq);
135 
136 	cpu_intr_unmap(sc->sc_ih, v);
137 #endif
138 }
139