xref: /netbsd/sys/dev/ic/cacvar.h (revision bf9ec67e)
1 /*	$NetBSD: cacvar.h,v 1.9 2002/01/25 16:10:36 ad 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 "locators.h"
43 
44 #define	CAC_MAX_CCBS	20
45 #define	CAC_MAX_XFER	(0xffff * 512)
46 #define	CAC_SG_SIZE	32
47 
48 #define	cac_inb(sc, port) \
49 	bus_space_read_1((sc)->sc_iot, (sc)->sc_ioh, port)
50 #define	cac_inw(sc, port) \
51 	bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, port)
52 #define	cac_inl(sc, port) \
53 	bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, port)
54 #define	cac_outb(sc, port, val) \
55 	bus_space_write_1((sc)->sc_iot, (sc)->sc_ioh, port, val)
56 #define	cac_outw(sc, port, val) \
57 	bus_space_write_2((sc)->sc_iot, (sc)->sc_ioh, port, val)
58 #define	cac_outl(sc, port, val) \
59 	bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, port, val)
60 
61 /*
62  * Stupid macros to deal with alignment/endianness issues.
63  */
64 
65 #define	CAC_GET1(x)							\
66 	(((u_char *)&(x))[0])
67 #define	CAC_GET2(x)							\
68 	(((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8))
69 #define	CAC_GET4(x)							\
70 	((((u_char *)&(x))[0] | (((u_char *)&(x))[1] << 8)) |		\
71 	(((u_char *)&(x))[0] << 16 | (((u_char *)&(x))[1] << 24)))
72 
73 struct cac_softc;
74 struct cac_ccb;
75 
76 struct cac_context {
77 	void		(*cc_handler)(struct device *, void *, int);
78 	struct device	*cc_dv;
79 	void 		*cc_context;
80 };
81 
82 struct cac_ccb {
83 	/* Data the controller will touch - 276 bytes */
84 	struct cac_hdr	ccb_hdr;
85 	struct cac_req	ccb_req;
86 	struct cac_sgb	ccb_seg[CAC_SG_SIZE];
87 
88 	/* Data the controller won't touch */
89 	int		ccb_flags;
90 	int		ccb_datasize;
91 	paddr_t		ccb_paddr;
92 	bus_dmamap_t	ccb_dmamap_xfer;
93 	SIMPLEQ_ENTRY(cac_ccb) ccb_chain;
94 	struct cac_context ccb_context;
95 };
96 
97 #define	CAC_CCB_DATA_IN		0x0001	/* Map describes inbound xfer */
98 #define	CAC_CCB_DATA_OUT	0x0002	/* Map describes outbound xfer */
99 #define	CAC_CCB_ACTIVE		0x0004	/* Command submitted to controller */
100 
101 struct cac_linkage {
102 	struct	cac_ccb *(*cl_completed)(struct cac_softc *);
103 	int	(*cl_fifo_full)(struct cac_softc *);
104 	void	(*cl_intr_enable)(struct cac_softc *, int);
105 	int	(*cl_intr_pending)(struct cac_softc *);
106 	void	(*cl_submit)(struct cac_softc *, struct cac_ccb *);
107 };
108 
109 struct cac_softc {
110 	struct device		sc_dv;
111 	bus_space_tag_t		sc_iot;
112 	bus_space_handle_t	sc_ioh;
113 	bus_dma_tag_t		sc_dmat;
114 	bus_dmamap_t		sc_dmamap;
115 	int			sc_nunits;
116 	void			*sc_ih;
117 	caddr_t			sc_ccbs;
118 	paddr_t			sc_ccbs_paddr;
119 	SIMPLEQ_HEAD(, cac_ccb)	sc_ccb_free;
120 	SIMPLEQ_HEAD(, cac_ccb)	sc_ccb_queue;
121 	struct cac_linkage	sc_cl;
122 };
123 
124 struct cac_attach_args {
125 	int		caca_unit;
126 };
127 
128 #define	cacacf_unit	cf_loc[CACCF_UNIT]
129 
130 int	cac_cmd(struct cac_softc *, int, void *, int, int, int, int,
131 		struct cac_context *);
132 int	cac_init(struct cac_softc *, const char *, int);
133 int	cac_intr(void *);
134 
135 extern const struct	cac_linkage cac_l0;
136 
137 #endif	/* !_IC_CACVAR_H_ */
138