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