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