dmovervar.h revision 1.3.2.2 1 1.3.2.2 thorpej /* $NetBSD: dmovervar.h,v 1.3.2.2 2002/08/04 02:17:07 thorpej Exp $ */
2 1.3.2.2 thorpej
3 1.3.2.2 thorpej /*
4 1.3.2.2 thorpej * Copyright (c) 2002 Wasabi Systems, Inc.
5 1.3.2.2 thorpej * All rights reserved.
6 1.3.2.2 thorpej *
7 1.3.2.2 thorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.3.2.2 thorpej *
9 1.3.2.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.3.2.2 thorpej * modification, are permitted provided that the following conditions
11 1.3.2.2 thorpej * are met:
12 1.3.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.3.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.3.2.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.3.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.3.2.2 thorpej * must display the following acknowledgement:
19 1.3.2.2 thorpej * This product includes software developed for the NetBSD Project by
20 1.3.2.2 thorpej * Wasabi Systems, Inc.
21 1.3.2.2 thorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.3.2.2 thorpej * or promote products derived from this software without specific prior
23 1.3.2.2 thorpej * written permission.
24 1.3.2.2 thorpej *
25 1.3.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.3.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.3.2.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.3.2.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.3.2.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.3.2.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.3.2.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.3.2.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.3.2.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.3.2.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.3.2.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
36 1.3.2.2 thorpej */
37 1.3.2.2 thorpej
38 1.3.2.2 thorpej #ifndef _DMOVER_DMOVERVAR_H_
39 1.3.2.2 thorpej #define _DMOVER_DMOVERVAR_H_
40 1.3.2.2 thorpej
41 1.3.2.2 thorpej #include <sys/lock.h>
42 1.3.2.2 thorpej #include <sys/queue.h>
43 1.3.2.2 thorpej
44 1.3.2.2 thorpej /*
45 1.3.2.2 thorpej * Types of buffers the dmover-api can handle.
46 1.3.2.2 thorpej */
47 1.3.2.2 thorpej typedef enum {
48 1.3.2.2 thorpej DMOVER_BUF_LINEAR,
49 1.3.2.2 thorpej DMOVER_BUF_UIO
50 1.3.2.2 thorpej } dmover_buffer_type;
51 1.3.2.2 thorpej
52 1.3.2.2 thorpej typedef struct {
53 1.3.2.2 thorpej void *l_addr;
54 1.3.2.2 thorpej size_t l_len;
55 1.3.2.2 thorpej } dmover_buf_linear;
56 1.3.2.2 thorpej
57 1.3.2.2 thorpej typedef union {
58 1.3.2.2 thorpej dmover_buf_linear dmbuf_linear;
59 1.3.2.2 thorpej struct uio *dmbuf_uio;
60 1.3.2.2 thorpej } dmover_buffer;
61 1.3.2.2 thorpej
62 1.3.2.2 thorpej /*
63 1.3.2.2 thorpej * dmover_algdesc:
64 1.3.2.2 thorpej *
65 1.3.2.2 thorpej * This structure describes an dmover algorithm.
66 1.3.2.2 thorpej *
67 1.3.2.2 thorpej * All members of this structure are public.
68 1.3.2.2 thorpej */
69 1.3.2.2 thorpej struct dmover_algdesc {
70 1.3.2.2 thorpej const char *dad_name; /* algorithm name */
71 1.3.2.2 thorpej void *dad_data; /* opaque algorithm description */
72 1.3.2.2 thorpej int dad_ninputs; /* number of inputs */
73 1.3.2.2 thorpej };
74 1.3.2.2 thorpej
75 1.3.2.2 thorpej /*
76 1.3.2.2 thorpej * dmover_assignment:
77 1.3.2.2 thorpej *
78 1.3.2.2 thorpej * This structure contains the information necessary to assign
79 1.3.2.2 thorpej * a request to a back-end.
80 1.3.2.2 thorpej *
81 1.3.2.2 thorpej * All members of this structure are public.
82 1.3.2.2 thorpej */
83 1.3.2.2 thorpej struct dmover_assignment {
84 1.3.2.2 thorpej struct dmover_backend *das_backend;
85 1.3.2.2 thorpej const struct dmover_algdesc *das_algdesc;
86 1.3.2.2 thorpej };
87 1.3.2.2 thorpej
88 1.3.2.2 thorpej /*
89 1.3.2.2 thorpej * dmover_session:
90 1.3.2.2 thorpej *
91 1.3.2.2 thorpej * State for a dmover session.
92 1.3.2.2 thorpej */
93 1.3.2.2 thorpej struct dmover_session {
94 1.3.2.2 thorpej /*
95 1.3.2.2 thorpej * PUBLIC MEMBERS
96 1.3.2.2 thorpej */
97 1.3.2.2 thorpej void *dses_cookie; /* for client */
98 1.3.2.2 thorpej int dses_ninputs; /* number of inputs for function */
99 1.3.2.2 thorpej
100 1.3.2.2 thorpej /*
101 1.3.2.2 thorpej * PRIVATE MEMBERS
102 1.3.2.2 thorpej */
103 1.3.2.2 thorpej LIST_ENTRY(dmover_session) __dses_list;
104 1.3.2.2 thorpej
105 1.3.2.2 thorpej /*
106 1.3.2.2 thorpej * XXX Assignment is static when a session is
107 1.3.2.2 thorpej * XXX created, for now.
108 1.3.2.2 thorpej */
109 1.3.2.2 thorpej struct dmover_assignment __dses_assignment;
110 1.3.2.2 thorpej
111 1.3.2.2 thorpej /* List of active requests on this session. */
112 1.3.2.2 thorpej TAILQ_HEAD(, dmover_request) __dses_pendreqs;
113 1.3.2.2 thorpej int __dses_npendreqs;
114 1.3.2.2 thorpej };
115 1.3.2.2 thorpej
116 1.3.2.2 thorpej #define dmover_session_insque(dses, dreq) \
117 1.3.2.2 thorpej do { \
118 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
119 1.3.2.2 thorpej (dses)->__dses_npendreqs++; \
120 1.3.2.2 thorpej } while (/*CONSTCOND*/0)
121 1.3.2.2 thorpej
122 1.3.2.2 thorpej #define dmover_session_remque(dses, dreq) \
123 1.3.2.2 thorpej do { \
124 1.3.2.2 thorpej TAILQ_REMOVE(&(dses)->__dses_pendreqs, (dreq), dreq_sesq); \
125 1.3.2.2 thorpej (dses)->__dses_npendreqs--; \
126 1.3.2.2 thorpej } while (/*CONSTCOND*/0)
127 1.3.2.2 thorpej
128 1.3.2.2 thorpej /*
129 1.3.2.2 thorpej * dmover_request:
130 1.3.2.2 thorpej *
131 1.3.2.2 thorpej * A data dmover request.
132 1.3.2.2 thorpej */
133 1.3.2.2 thorpej struct dmover_request {
134 1.3.2.2 thorpej /*
135 1.3.2.2 thorpej * PUBLIC MEMBERS
136 1.3.2.2 thorpej */
137 1.3.2.2 thorpej
138 1.3.2.2 thorpej /* Links on session and back-end queues. */
139 1.3.2.2 thorpej TAILQ_ENTRY(dmover_request) dreq_sesq;
140 1.3.2.2 thorpej TAILQ_ENTRY(dmover_request) dreq_dmbq;
141 1.3.2.2 thorpej
142 1.3.2.2 thorpej /* Pointer to our session. */
143 1.3.2.2 thorpej struct dmover_session *dreq_session;
144 1.3.2.2 thorpej
145 1.3.2.2 thorpej /* Our current back-end assignment. */
146 1.3.2.2 thorpej struct dmover_assignment *dreq_assignment;
147 1.3.2.2 thorpej
148 1.3.2.2 thorpej /* Function to call when processing is complete. */
149 1.3.2.2 thorpej void (*dreq_callback)(struct dmover_request *);
150 1.3.2.2 thorpej void *dreq_cookie; /* for client */
151 1.3.2.2 thorpej
152 1.3.2.2 thorpej __volatile int dreq_flags; /* flags; see below */
153 1.3.2.2 thorpej int dreq_error; /* valid if DMOVER_REQ_ERROR is set */
154 1.3.2.2 thorpej
155 1.3.2.2 thorpej /* Output buffer. */
156 1.3.2.2 thorpej dmover_buffer_type dreq_outbuf_type;
157 1.3.2.2 thorpej dmover_buffer dreq_outbuf;
158 1.3.2.2 thorpej
159 1.3.2.2 thorpej /* Input buffer. */
160 1.3.2.2 thorpej dmover_buffer_type dreq_inbuf_type;
161 1.3.2.2 thorpej union {
162 1.3.2.2 thorpej uint8_t _immediate[8];
163 1.3.2.2 thorpej dmover_buffer *_inbuf;
164 1.3.2.2 thorpej } _dreq_inbuf_un;
165 1.3.2.2 thorpej
166 1.3.2.2 thorpej #define dreq_immediate _dreq_inbuf_un._immediate
167 1.3.2.2 thorpej #define dreq_inbuf _dreq_inbuf_un._inbuf
168 1.3.2.2 thorpej };
169 1.3.2.2 thorpej
170 1.3.2.2 thorpej /* dreq_flags */
171 1.3.2.2 thorpej #define DMOVER_REQ_DONE 0x0001 /* request is completed */
172 1.3.2.2 thorpej #define DMOVER_REQ_ERROR 0x0002 /* error occurred */
173 1.3.2.2 thorpej #define DMOVER_REQ_RUNNING 0x0004 /* request is being executed */
174 1.3.2.2 thorpej #define DMOVER_REQ_WAIT 0x0008 /* wait for completion */
175 1.3.2.2 thorpej
176 1.3.2.2 thorpej #define __DMOVER_REQ_INBUF_FREE 0x01000000 /* need to free input buffer */
177 1.3.2.2 thorpej
178 1.3.2.2 thorpej #define __DMOVER_REQ_FLAGS_PRESERVE \
179 1.3.2.2 thorpej (DMOVER_REQ_WAIT | __DMOVER_REQ_INBUF_FREE)
180 1.3.2.2 thorpej
181 1.3.2.2 thorpej /*
182 1.3.2.2 thorpej * dmover_backend:
183 1.3.2.2 thorpej *
184 1.3.2.2 thorpej * Glue between the dmover-api middle layer and the dmover
185 1.3.2.2 thorpej * backends.
186 1.3.2.2 thorpej *
187 1.3.2.2 thorpej * All members of this structure are public.
188 1.3.2.2 thorpej */
189 1.3.2.2 thorpej struct dmover_backend {
190 1.3.2.2 thorpej TAILQ_ENTRY(dmover_backend) dmb_list;
191 1.3.2.2 thorpej
192 1.3.2.2 thorpej const char *dmb_name; /* name of back-end */
193 1.3.2.2 thorpej u_int dmb_speed; /* est. KB/s throughput */
194 1.3.2.2 thorpej
195 1.3.2.2 thorpej void *dmb_cookie; /* for back-end */
196 1.3.2.2 thorpej
197 1.3.2.2 thorpej /* List of algorithms this back-ends supports. */
198 1.3.2.2 thorpej const struct dmover_algdesc *dmb_algdescs;
199 1.3.2.2 thorpej int dmb_nalgdescs;
200 1.3.2.2 thorpej
201 1.3.2.2 thorpej /* Back-end functions. */
202 1.3.2.2 thorpej void (*dmb_process)(struct dmover_backend *);
203 1.3.2.2 thorpej
204 1.3.2.2 thorpej /* List of sessions currently on this back-end. */
205 1.3.2.2 thorpej LIST_HEAD(, dmover_session) dmb_sessions;
206 1.3.2.2 thorpej int dmb_nsessions; /* current number of sessions */
207 1.3.2.2 thorpej
208 1.3.2.2 thorpej /* List of active requests on this back-end. */
209 1.3.2.2 thorpej TAILQ_HEAD(, dmover_request) dmb_pendreqs;
210 1.3.2.2 thorpej int dmb_npendreqs;
211 1.3.2.2 thorpej };
212 1.3.2.2 thorpej
213 1.3.2.2 thorpej #define dmover_backend_insque(dmb, dreq) \
214 1.3.2.2 thorpej do { \
215 1.3.2.2 thorpej TAILQ_INSERT_TAIL(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
216 1.3.2.2 thorpej (dmb)->dmb_npendreqs++; \
217 1.3.2.2 thorpej } while (/*CONSTCOND*/0)
218 1.3.2.2 thorpej
219 1.3.2.2 thorpej #define dmover_backend_remque(dmb, dreq) \
220 1.3.2.2 thorpej do { \
221 1.3.2.2 thorpej TAILQ_REMOVE(&(dmb)->dmb_pendreqs, (dreq), dreq_dmbq); \
222 1.3.2.2 thorpej (dmb)->dmb_npendreqs--; \
223 1.3.2.2 thorpej } while (/*CONSTCOND*/0)
224 1.3.2.2 thorpej
225 1.3.2.2 thorpej /*
226 1.3.2.2 thorpej * Well-known data mover functions. Using these for the function name
227 1.3.2.2 thorpej * saves space.
228 1.3.2.2 thorpej */
229 1.3.2.2 thorpej extern const char dmover_funcname_zero[];
230 1.3.2.2 thorpej #define DMOVER_FUNC_ZERO dmover_funcname_zero
231 1.3.2.2 thorpej
232 1.3.2.2 thorpej extern const char dmover_funcname_fill8[];
233 1.3.2.2 thorpej #define DMOVER_FUNC_FILL8 dmover_funcname_fill8
234 1.3.2.2 thorpej
235 1.3.2.2 thorpej extern const char dmover_funcname_copy[];
236 1.3.2.2 thorpej #define DMOVER_FUNC_COPY dmover_funcname_copy
237 1.3.2.2 thorpej
238 1.3.2.2 thorpej extern const char dmover_funcname_xor2[];
239 1.3.2.2 thorpej #define DMOVER_FUNC_XOR2 dmover_funcname_xor2
240 1.3.2.2 thorpej
241 1.3.2.2 thorpej extern const char dmover_funcname_xor3[];
242 1.3.2.2 thorpej #define DMOVER_FUNC_XOR3 dmover_funcname_xor3
243 1.3.2.2 thorpej
244 1.3.2.2 thorpej extern const char dmover_funcname_xor4[];
245 1.3.2.2 thorpej #define DMOVER_FUNC_XOR4 dmover_funcname_xor4
246 1.3.2.2 thorpej
247 1.3.2.2 thorpej extern const char dmover_funcname_xor5[];
248 1.3.2.2 thorpej #define DMOVER_FUNC_XOR5 dmover_funcname_xor5
249 1.3.2.2 thorpej
250 1.3.2.2 thorpej extern const char dmover_funcname_xor6[];
251 1.3.2.2 thorpej #define DMOVER_FUNC_XOR6 dmover_funcname_xor6
252 1.3.2.2 thorpej
253 1.3.2.2 thorpej extern const char dmover_funcname_xor7[];
254 1.3.2.2 thorpej #define DMOVER_FUNC_XOR7 dmover_funcname_xor7
255 1.3.2.2 thorpej
256 1.3.2.2 thorpej extern const char dmover_funcname_xor8[];
257 1.3.2.2 thorpej #define DMOVER_FUNC_XOR8 dmover_funcname_xor8
258 1.3.2.2 thorpej
259 1.3.2.2 thorpej /* Back-end management functions. */
260 1.3.2.2 thorpej void dmover_backend_register(struct dmover_backend *);
261 1.3.2.2 thorpej void dmover_backend_unregister(struct dmover_backend *);
262 1.3.2.2 thorpej int dmover_backend_alloc(struct dmover_session *, const char *);
263 1.3.2.2 thorpej void dmover_backend_release(struct dmover_session *);
264 1.3.2.2 thorpej
265 1.3.2.2 thorpej /* Session management functions. */
266 1.3.2.2 thorpej void dmover_session_initialize(void);
267 1.3.2.2 thorpej int dmover_session_create(const char *, struct dmover_session **);
268 1.3.2.2 thorpej void dmover_session_destroy(struct dmover_session *);
269 1.3.2.2 thorpej
270 1.3.2.2 thorpej /* Request management functions. */
271 1.3.2.2 thorpej void dmover_request_initialize(void);
272 1.3.2.2 thorpej struct dmover_request *dmover_request_alloc(struct dmover_session *,
273 1.3.2.2 thorpej dmover_buffer *);
274 1.3.2.2 thorpej void dmover_request_free(struct dmover_request *);
275 1.3.2.2 thorpej
276 1.3.2.2 thorpej /* Processing engine functions. */
277 1.3.2.2 thorpej void dmover_process_initialize(void);
278 1.3.2.2 thorpej void dmover_process(struct dmover_request *);
279 1.3.2.2 thorpej void dmover_done(struct dmover_request *);
280 1.3.2.2 thorpej
281 1.3.2.2 thorpej /* Utility functions. */
282 1.3.2.2 thorpej const struct dmover_algdesc *
283 1.3.2.2 thorpej dmover_algdesc_lookup(const struct dmover_algdesc *, int,
284 1.3.2.2 thorpej const char *);
285 1.3.2.2 thorpej
286 1.3.2.2 thorpej #endif /* _DMOVER_DMOVERVAR_H_ */
287