xref: /netbsd-src/sys/arch/arm/xscale/i80321_aau.c (revision 7490f9330505725b4cdef5ec3774397dc5644261)
1*7490f933Smatt /*	$NetBSD: i80321_aau.c,v 1.15 2012/02/12 16:31:01 matt Exp $	*/
2036da55eSthorpej 
3036da55eSthorpej /*
4036da55eSthorpej  * Copyright (c) 2002 Wasabi Systems, Inc.
5036da55eSthorpej  * All rights reserved.
6036da55eSthorpej  *
7036da55eSthorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8036da55eSthorpej  *
9036da55eSthorpej  * Redistribution and use in source and binary forms, with or without
10036da55eSthorpej  * modification, are permitted provided that the following conditions
11036da55eSthorpej  * are met:
12036da55eSthorpej  * 1. Redistributions of source code must retain the above copyright
13036da55eSthorpej  *    notice, this list of conditions and the following disclaimer.
14036da55eSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
15036da55eSthorpej  *    notice, this list of conditions and the following disclaimer in the
16036da55eSthorpej  *    documentation and/or other materials provided with the distribution.
17036da55eSthorpej  * 3. All advertising materials mentioning features or use of this software
18036da55eSthorpej  *    must display the following acknowledgement:
19036da55eSthorpej  *	This product includes software developed for the NetBSD Project by
20036da55eSthorpej  *	Wasabi Systems, Inc.
21036da55eSthorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22036da55eSthorpej  *    or promote products derived from this software without specific prior
23036da55eSthorpej  *    written permission.
24036da55eSthorpej  *
25036da55eSthorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26036da55eSthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27036da55eSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28036da55eSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29036da55eSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30036da55eSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31036da55eSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32036da55eSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33036da55eSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34036da55eSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35036da55eSthorpej  * POSSIBILITY OF SUCH DAMAGE.
36036da55eSthorpej  */
37036da55eSthorpej 
38036da55eSthorpej /*
39036da55eSthorpej  * Intel i80321 I/O Processor application accelerator unit support.
40036da55eSthorpej  */
41036da55eSthorpej 
42036da55eSthorpej #include <sys/cdefs.h>
43*7490f933Smatt __KERNEL_RCSID(0, "$NetBSD: i80321_aau.c,v 1.15 2012/02/12 16:31:01 matt Exp $");
44036da55eSthorpej 
45036da55eSthorpej #include <sys/param.h>
46036da55eSthorpej #include <sys/pool.h>
47036da55eSthorpej #include <sys/systm.h>
48036da55eSthorpej #include <sys/device.h>
49036da55eSthorpej #include <sys/uio.h>
50c29520cbSad #include <sys/bus.h>
51c29520cbSad #include <sys/intr.h>
52036da55eSthorpej 
53036da55eSthorpej #include <uvm/uvm.h>
54036da55eSthorpej 
55036da55eSthorpej #include <arm/xscale/i80321reg.h>
56036da55eSthorpej #include <arm/xscale/i80321var.h>
57036da55eSthorpej 
58036da55eSthorpej #include <arm/xscale/iopaaureg.h>
59036da55eSthorpej #include <arm/xscale/iopaauvar.h>
60036da55eSthorpej 
61036da55eSthorpej struct aau321_softc {
62036da55eSthorpej 	/* Shared AAU definitions. */
63036da55eSthorpej 	struct iopaau_softc sc_iopaau;
64036da55eSthorpej 
65036da55eSthorpej 	/* i80321-specific stuff. */
66036da55eSthorpej 	void *sc_error_ih;
67036da55eSthorpej 	void *sc_eoc_ih;
68036da55eSthorpej 	void *sc_eot_ih;
69036da55eSthorpej };
70036da55eSthorpej 
71036da55eSthorpej static struct iopaau_function aau321_func_zero = {
72825088edSmatt 	.af_setup = iopaau_func_zero_setup,
73036da55eSthorpej };
74036da55eSthorpej 
75036da55eSthorpej static struct iopaau_function aau321_func_fill8 = {
76825088edSmatt 	.af_setup = iopaau_func_fill8_setup,
77036da55eSthorpej };
78036da55eSthorpej 
79c070073dSthorpej static struct iopaau_function aau321_func_xor_1_4 = {
80825088edSmatt 	.af_setup = iopaau_func_xor_setup,
81036da55eSthorpej };
82036da55eSthorpej 
830aa15bdfSthorpej static struct iopaau_function aau321_func_xor_5_8 = {
84825088edSmatt 	.af_setup = iopaau_func_xor_setup,
850aa15bdfSthorpej };
860aa15bdfSthorpej 
87036da55eSthorpej static const struct dmover_algdesc aau321_algdescs[] = {
88036da55eSthorpej 	{
89825088edSmatt 	  .dad_name = DMOVER_FUNC_ZERO,
90825088edSmatt 	  .dad_data = &aau321_func_zero,
91825088edSmatt 	  .dad_ninputs = 0
92036da55eSthorpej 	},
93036da55eSthorpej 	{
94825088edSmatt 	  .dad_name = DMOVER_FUNC_FILL8,
95825088edSmatt 	  .dad_data = &aau321_func_fill8,
96825088edSmatt 	  .dad_ninputs = 0
97036da55eSthorpej 	},
98036da55eSthorpej 	{
99825088edSmatt 	  .dad_name = DMOVER_FUNC_COPY,
100825088edSmatt 	  .dad_data = &aau321_func_xor_1_4,
101825088edSmatt 	  .dad_ninputs = 1
102036da55eSthorpej 	},
103c070073dSthorpej 	{
104825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR2,
105825088edSmatt 	  .dad_data = &aau321_func_xor_1_4,
106825088edSmatt 	  .dad_ninputs = 2
107c070073dSthorpej 	},
108c070073dSthorpej 	{
109825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR3,
110825088edSmatt 	  .dad_data = &aau321_func_xor_1_4,
111825088edSmatt 	  .dad_ninputs = 3
112c070073dSthorpej 	},
113c070073dSthorpej 	{
114825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR4,
115825088edSmatt 	  .dad_data = &aau321_func_xor_1_4,
116825088edSmatt 	  .dad_ninputs = 4
117c070073dSthorpej 	},
1180aa15bdfSthorpej 	{
119825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR5,
120825088edSmatt 	  .dad_data = &aau321_func_xor_5_8,
1210aa15bdfSthorpej 	  5
1220aa15bdfSthorpej 	},
1230aa15bdfSthorpej 	{
124825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR6,
125825088edSmatt 	  .dad_data = &aau321_func_xor_5_8,
126825088edSmatt 	  .dad_ninputs = 6
1270aa15bdfSthorpej 	},
1280aa15bdfSthorpej 	{
129825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR7,
130825088edSmatt 	  .dad_data = &aau321_func_xor_5_8,
131825088edSmatt 	  .dad_ninputs = 7
1320aa15bdfSthorpej 	},
1330aa15bdfSthorpej 	{
134825088edSmatt 	  .dad_name = DMOVER_FUNC_XOR8,
135825088edSmatt 	  .dad_data = &aau321_func_xor_5_8,
136825088edSmatt 	  .dad_ninputs = 8
1370aa15bdfSthorpej 	},
138036da55eSthorpej };
139825088edSmatt #define	AAU321_ALGDESC_COUNT	__arraycount(aau321_algdescs)
140036da55eSthorpej 
141036da55eSthorpej static int
aau321_match(device_t parent,cfdata_t match,void * aux)142*7490f933Smatt aau321_match(device_t parent, cfdata_t match, void *aux)
143036da55eSthorpej {
144036da55eSthorpej 	struct iopxs_attach_args *ia = aux;
145036da55eSthorpej 
146d1ad2ac4Sthorpej 	if (strcmp(match->cf_name, ia->ia_name) == 0)
147036da55eSthorpej 		return (1);
148036da55eSthorpej 
149036da55eSthorpej 	return (0);
150036da55eSthorpej }
151036da55eSthorpej 
152036da55eSthorpej static void
aau321_attach(device_t parent,device_t self,void * aux)153*7490f933Smatt aau321_attach(device_t parent, device_t self, void *aux)
154036da55eSthorpej {
155*7490f933Smatt 	struct aau321_softc *sc321 = device_private(self);
156036da55eSthorpej 	struct iopaau_softc *sc = &sc321->sc_iopaau;
157036da55eSthorpej 	struct iopxs_attach_args *ia = aux;
158*7490f933Smatt 	const char *xname = device_xname(self);
159036da55eSthorpej 	int error;
160036da55eSthorpej 
161b43b1645Sthorpej 	aprint_naive("\n");
162b43b1645Sthorpej 	aprint_normal("\n");
163036da55eSthorpej 
164*7490f933Smatt 	sc->sc_dev = self;
165036da55eSthorpej 	sc->sc_st = ia->ia_st;
166036da55eSthorpej 	error = bus_space_subregion(sc->sc_st, ia->ia_sh,
167036da55eSthorpej 	    ia->ia_offset, ia->ia_size, &sc->sc_sh);
168036da55eSthorpej 	if (error) {
169b43b1645Sthorpej 		aprint_error("%s: unable to subregion registers, error = %d\n",
170*7490f933Smatt 		    xname, error);
171036da55eSthorpej 		return;
172036da55eSthorpej 	}
173036da55eSthorpej 
174036da55eSthorpej 	sc->sc_dmat = ia->ia_dmat;
175036da55eSthorpej 
176036da55eSthorpej 	sc321->sc_error_ih = i80321_intr_establish(ICU_INT_AAUE, IPL_BIO,
177036da55eSthorpej 	    iopaau_intr, sc);
178036da55eSthorpej 	if (sc321->sc_error_ih == NULL) {
179b43b1645Sthorpej 		aprint_error("%s: unable to register error interrupt handler\n",
180*7490f933Smatt 		    xname);
181036da55eSthorpej 		return;
182036da55eSthorpej 	}
183036da55eSthorpej 
184036da55eSthorpej 	sc321->sc_eoc_ih = i80321_intr_establish(ICU_INT_AAU_EOC, IPL_BIO,
185036da55eSthorpej 	    iopaau_intr, sc);
186036da55eSthorpej 	if (sc321->sc_eoc_ih == NULL) {
187b43b1645Sthorpej 		aprint_error("%s: unable to register EOC interrupt handler\n",
188*7490f933Smatt 		    xname);
189036da55eSthorpej 		return;
190036da55eSthorpej 	}
191036da55eSthorpej 
192036da55eSthorpej 	sc321->sc_eot_ih = i80321_intr_establish(ICU_INT_AAU_EOT, IPL_BIO,
193036da55eSthorpej 	    iopaau_intr, sc);
194036da55eSthorpej 	if (sc321->sc_eoc_ih == NULL) {
195b43b1645Sthorpej 		aprint_error("%s: unable to register EOT interrupt handler\n",
196*7490f933Smatt 		    xname);
197036da55eSthorpej 		return;
198036da55eSthorpej 	}
199036da55eSthorpej 
200*7490f933Smatt 	sc->sc_dmb.dmb_name = xname;
201036da55eSthorpej 	sc->sc_dmb.dmb_speed = 1638400;			/* XXX */
202036da55eSthorpej 	sc->sc_dmb.dmb_cookie = sc;
203036da55eSthorpej 	sc->sc_dmb.dmb_algdescs = aau321_algdescs;
204036da55eSthorpej 	sc->sc_dmb.dmb_nalgdescs = AAU321_ALGDESC_COUNT;
205036da55eSthorpej 	sc->sc_dmb.dmb_process = iopaau_process;
206036da55eSthorpej 
207036da55eSthorpej 	iopaau_attach(sc);
208a72bb4a2Sad 
20991d14901Sbriggs 	/*
21091d14901Sbriggs 	 * These must be initialized after iopaau_attach()
21191d14901Sbriggs 	 * because iopaau_desc_[48]_cache is set up there.
21291d14901Sbriggs 	 */
21391d14901Sbriggs 	KASSERT(iopaau_desc_4_cache != NULL);
214a72bb4a2Sad 	aau321_func_zero.af_desc_cache = iopaau_desc_4_cache;
215a72bb4a2Sad 	aau321_func_fill8.af_desc_cache = iopaau_desc_4_cache;
216a72bb4a2Sad 	aau321_func_xor_1_4.af_desc_cache = iopaau_desc_4_cache;
21791d14901Sbriggs 
21891d14901Sbriggs 	KASSERT(iopaau_desc_8_cache != NULL);
219a72bb4a2Sad 	aau321_func_xor_5_8.af_desc_cache = iopaau_desc_8_cache;
220036da55eSthorpej }
221036da55eSthorpej 
222*7490f933Smatt CFATTACH_DECL_NEW(iopaau, sizeof(struct aau321_softc),
223c5e91d44Sthorpej     aau321_match, aau321_attach, NULL, NULL);
224