xref: /netbsd-src/sys/dev/ic/cacvar.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: cacvar.h,v 1.16 2007/06/27 17:57:55 mhitch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Andrew Doran.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _IC_CACVAR_H_
40 #define	_IC_CACVAR_H_
41 
42 #include <sys/mutex.h>
43 #include <sys/condvar.h>
44 
45 #define	CAC_MAX_CCBS	256
46 #define	CAC_MAX_XFER	(0xffff * 512)
47 #define	CAC_SG_SIZE	32
48 
49 #define	cac_inb(sc, port) \
50 	bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, port)
51 #define	cac_inw(sc, port) \
52 	bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, port)
53 #define	cac_inl(sc, port) \
54 	bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, port)
55 #define	cac_outb(sc, port, val) \
56 	bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, port, val)
57 #define	cac_outw(sc, port, val) \
58 	bus_space_write_2((sc)->sc_iot, (sc)->sc_ioh, port, val)
59 #define	cac_outl(sc, port, val) \
60 	bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, port, val)
61 
62 /*
63  * Stupid macros to deal with alignment/endianness issues.
64  */
65 
66 #define	CAC_GET1(x)							\
67 	(((u_char *)&(x))[0])
68 #define	CAC_GET2(x)							\
69 	(((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8))
70 #define	CAC_GET4(x)							\
71 	((((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8)) |		\
72 	(((u_char *)&(x))[2] << 16 | (((u_char *)&(x))[3] << 24)))
73 
74 struct cac_softc;
75 struct cac_ccb;
76 
77 struct cac_context {
78 	void		(*cc_handler)(struct device *, void *, int);
79 	struct device	*cc_dv;
80 	void 		*cc_context;
81 };
82 
83 struct cac_ccb {
84 	/* Data the controller will touch - 276 bytes */
85 	struct cac_hdr	ccb_hdr;
86 	struct cac_req	ccb_req;
87 	struct cac_sgb	ccb_seg[CAC_SG_SIZE];
88 
89 	/* Data the controller won't touch */
90 	int		ccb_flags;
91 	int		ccb_datasize;
92 	paddr_t		ccb_paddr;
93 	bus_dmamap_t	ccb_dmamap_xfer;
94 	SIMPLEQ_ENTRY(cac_ccb) ccb_chain;
95 	struct cac_context ccb_context;
96 };
97 
98 #define	CAC_CCB_DATA_IN		0x0001	/* Map describes inbound xfer */
99 #define	CAC_CCB_DATA_OUT	0x0002	/* Map describes outbound xfer */
100 #define	CAC_CCB_ACTIVE		0x0004	/* Command submitted to controller */
101 
102 struct cac_linkage {
103 	struct	cac_ccb *(*cl_completed)(struct cac_softc *);
104 	int	(*cl_fifo_full)(struct cac_softc *);
105 	void	(*cl_intr_enable)(struct cac_softc *, int);
106 	int	(*cl_intr_pending)(struct cac_softc *);
107 	void	(*cl_submit)(struct cac_softc *, struct cac_ccb *);
108 };
109 
110 struct cac_softc {
111 	struct device		sc_dv;
112 	kmutex_t		sc_mutex;
113 	bus_space_tag_t		sc_iot;
114 	bus_space_handle_t	sc_ioh;
115 	bus_dma_tag_t		sc_dmat;
116 	bus_dmamap_t		sc_dmamap;
117 	int			sc_nunits;
118 	void			*sc_ih;
119 	void *			sc_ccbs;
120 	paddr_t			sc_ccbs_paddr;
121 	SIMPLEQ_HEAD(, cac_ccb)	sc_ccb_free;
122 	SIMPLEQ_HEAD(, cac_ccb)	sc_ccb_queue;
123 	kcondvar_t		sc_ccb_cv;
124 	struct cac_linkage	sc_cl;
125 };
126 
127 struct cac_attach_args {
128 	int		caca_unit;
129 };
130 
131 int	cac_cmd(struct cac_softc *, int, void *, int, int, int, int,
132 		struct cac_context *);
133 int	cac_init(struct cac_softc *, const char *, int);
134 int	cac_intr(void *);
135 
136 extern const struct	cac_linkage cac_l0;
137 
138 #endif	/* !_IC_CACVAR_H_ */
139