1 /* $NetBSD: jazzio.c,v 1.19 2008/03/14 16:43:27 tsutsui Exp $ */
2 /* $OpenBSD: picabus.c,v 1.11 1999/01/11 05:11:10 millert Exp $ */
3 /* NetBSD: tc.c,v 1.2 1995/03/08 00:39:05 cgd Exp */
6 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
9 * Author: Chris G. Demetriou
10 * Author: Per Fogelstrom. (Mips R4x00)
12 * Permission to use, copy, modify and distribute this software and
13 * its documentation is hereby granted, provided that both the copyright
14 * notice and this permission notice appear in all copies of the
15 * software, derivative works or modified versions, and any portions
16 * thereof, and that both notices appear in supporting documentation.
18 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
20 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
22 * Carnegie Mellon requests users of this software to return to
24 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
25 * School of Computer Science
26 * Carnegie Mellon University
27 * Pittsburgh PA 15213-3890
29 * any improvements or extensions that they make and grant Carnegie the
30 * rights to redistribute these changes.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: jazzio.c,v 1.19 2008/03/14 16:43:27 tsutsui Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
40 #include <machine/bus.h>
41 #include <machine/pio.h>
42 #include <machine/autoconf.h>
43 #include <machine/platform.h>
45 #include <arc/jazz/jazziovar.h>
46 #include <arc/jazz/pica.h>
47 #include <arc/jazz/jazzdmatlbreg.h>
48 #include <arc/jazz/jazzdmatlbvar.h>
49 #include <arc/jazz/dma.h>
50 #include <arc/jazz/pckbc_jazzioreg.h>
54 void arc_sysreset(bus_addr_t
, bus_size_t
);
58 struct arc_bus_dma_tag sc_dmat
;
59 struct pica_dev
*sc_devs
;
62 /* Definition of the driver for autoconfig. */
63 static int jazziomatch(device_t
, cfdata_t
, void *);
64 static void jazzioattach(device_t
, device_t
, void *);
65 static int jazzioprint(void *, const char *);
67 CFATTACH_DECL_NEW(jazzio
, sizeof(struct jazzio_softc
),
68 jazziomatch
, jazzioattach
, NULL
, NULL
);
70 static uint32_t jazzio_intr(uint32_t, struct clockframe
*);
71 static int jazzio_no_handler(void *);
74 * Interrupt dispatch table for jazz i/o bus.
76 struct jazzio_intrhand
{
77 intr_handler_t ih_func
; /* Interrupt handler */
78 void *ih_arg
; /* Parameter to send to handler */
79 struct evcnt ih_evcnt
; /* interrupt counter */
80 char ih_evname
[32]; /* event counter name */
83 static struct jazzio_intrhand jazzio_intrtab
[16];
86 struct jazzio_config
*jazzio_conf
= NULL
;
87 struct pica_dev
*jazzio_devconfig
= NULL
;
88 int jazzio_int_mask
= 0; /* jazz i/o interrupt enable mask */
89 struct arc_bus_space jazzio_bus
;
91 static int jazzio_found
= 0;
94 jazziomatch(device_t parent
, cfdata_t cf
, void *aux
)
96 struct confargs
*ca
= aux
;
98 /* Make sure that we're looking for a jazzio bus. */
99 if (strcmp(ca
->ca_name
, jazzio_cd
.cd_name
) != 0)
106 jazzioattach(device_t parent
, device_t self
, void *aux
)
108 struct jazzio_softc
*sc
= device_private(self
);
109 struct jazzio_attach_args ja
;
114 if (jazzio_conf
== NULL
)
115 panic("jazzio_conf isn't initialized");
116 if (jazzio_devconfig
== NULL
)
117 panic("jazzio_devconfig isn't initialized");
123 /* keep our CPU device description handy */
124 sc
->sc_devs
= jazzio_devconfig
;
126 /* initialize interrupt handler table */
127 for (i
= 0; i
< __arraycount(jazzio_intrtab
); i
++) {
128 jazzio_intrtab
[i
].ih_func
= jazzio_no_handler
;
129 jazzio_intrtab
[i
].ih_arg
= NULL
;
132 /* set up interrupt handlers */
133 (*platform
->set_intr
)(MIPS_INT_MASK_1
, jazzio_intr
, ARC_INTPRI_JAZZ
);
135 /* Initialize jazzio DMA mapping register area and pool */
136 jazz_dmatlb_init(&jazzio_bus
, jazzio_conf
->jc_dmatlbreg
);
138 /* Create bus_dma_tag */
139 jazz_bus_dma_tag_init(&sc
->sc_dmat
);
141 /* Try to configure each jazzio attached device */
142 for (i
= 0; sc
->sc_devs
[i
].ps_ca
.ca_name
!= NULL
; i
++) {
144 ja
.ja_name
= sc
->sc_devs
[i
].ps_ca
.ca_name
;
145 ja
.ja_bust
= &jazzio_bus
;
146 ja
.ja_dmat
= &sc
->sc_dmat
;
147 ja
.ja_addr
= (bus_addr_t
)sc
->sc_devs
[i
].ps_base
;
148 ja
.ja_intr
= sc
->sc_devs
[i
].ps_ca
.ca_slot
;
151 /* Tell the autoconfig machinery we've found the hardware. */
152 config_found(self
, &ja
, jazzioprint
);
157 jazzioprint(void *aux
, const char *pnp
)
159 struct jazzio_attach_args
*ja
= aux
;
162 aprint_normal("%s at %s", ja
->ja_name
, pnp
);
163 aprint_normal(" addr 0x%lx", ja
->ja_addr
);
164 if (ja
->ja_intr
!= -1)
165 aprint_normal(" intr %d", ja
->ja_intr
);
170 jazzio_intr_establish(int intr
, intr_handler_t handler
, void *val
)
172 struct jazzio_intrhand
*jirp
;
174 if (intr
< 0 || intr
>= __arraycount(jazzio_intrtab
))
175 panic("jazzio intr %d out of range", intr
);
176 jirp
= &jazzio_intrtab
[intr
];
177 if (jirp
->ih_func
!= jazzio_no_handler
)
178 panic("jazzio intr %d already set to %p", intr
, jirp
->ih_func
);
180 jazzio_int_mask
|= 1 << intr
;
181 jirp
->ih_func
= handler
;
183 snprintf(jirp
->ih_evname
, sizeof(jirp
->ih_evname
), "intr %d", intr
);
184 evcnt_attach_dynamic(&jirp
->ih_evcnt
, EVCNT_TYPE_INTR
,
185 NULL
, "jazzio", jirp
->ih_evname
);
187 (*jazzio_conf
->jc_set_iointr_mask
)(jazzio_int_mask
);
191 jazzio_intr_disestablish(int intr
)
193 struct jazzio_intrhand
*jirp
;
195 jazzio_int_mask
&= ~(1 << intr
);
196 jirp
= &jazzio_intrtab
[intr
];
197 jirp
->ih_func
= jazzio_no_handler
;
199 evcnt_detach(&jirp
->ih_evcnt
);
201 (*jazzio_conf
->jc_set_iointr_mask
)(jazzio_int_mask
);
205 jazzio_no_handler(void *arg
)
208 panic("uncaught jazzio interrupt with arg %p", arg
);
212 * Handle jazz i/o interrupt.
215 jazzio_intr(uint32_t mask
, struct clockframe
*cf
)
218 struct jazzio_intrhand
*jirp
;
220 while ((vector
= inb(jazzio_conf
->jc_iointr_status_reg
)) != 0) {
221 jirp
= &jazzio_intrtab
[(vector
>> 2) - 1];
222 (*jirp
->ih_func
)(jirp
->ih_arg
);
223 jirp
->ih_evcnt
.ev_count
++;
225 return MIPS_INT_MASK_1
;
232 arc_sysreset(PICA_SYS_KBD
, JAZZIO_KBCMDP
);