1*3af888c1Sjakllsch /* $NetBSD: dmover_request.c,v 1.8 2011/05/14 18:24:47 jakllsch Exp $ */
25d06c0e8Sthorpej
35d06c0e8Sthorpej /*
45d06c0e8Sthorpej * Copyright (c) 2002 Wasabi Systems, Inc.
55d06c0e8Sthorpej * All rights reserved.
65d06c0e8Sthorpej *
75d06c0e8Sthorpej * Written by Jason R. Thorpe for Wasabi Systems, Inc.
85d06c0e8Sthorpej *
95d06c0e8Sthorpej * Redistribution and use in source and binary forms, with or without
105d06c0e8Sthorpej * modification, are permitted provided that the following conditions
115d06c0e8Sthorpej * are met:
125d06c0e8Sthorpej * 1. Redistributions of source code must retain the above copyright
135d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer.
145d06c0e8Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
155d06c0e8Sthorpej * notice, this list of conditions and the following disclaimer in the
165d06c0e8Sthorpej * documentation and/or other materials provided with the distribution.
175d06c0e8Sthorpej * 3. All advertising materials mentioning features or use of this software
185d06c0e8Sthorpej * must display the following acknowledgement:
195d06c0e8Sthorpej * This product includes software developed for the NetBSD Project by
205d06c0e8Sthorpej * Wasabi Systems, Inc.
215d06c0e8Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
225d06c0e8Sthorpej * or promote products derived from this software without specific prior
235d06c0e8Sthorpej * written permission.
245d06c0e8Sthorpej *
255d06c0e8Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
265d06c0e8Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
275d06c0e8Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
285d06c0e8Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
295d06c0e8Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
305d06c0e8Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
315d06c0e8Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
325d06c0e8Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
335d06c0e8Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
345d06c0e8Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
355d06c0e8Sthorpej * POSSIBILITY OF SUCH DAMAGE.
365d06c0e8Sthorpej */
375d06c0e8Sthorpej
385d06c0e8Sthorpej /*
395d06c0e8Sthorpej * dmover_request.c: Request management functions for dmover-api.
405d06c0e8Sthorpej */
415d06c0e8Sthorpej
425d06c0e8Sthorpej #include <sys/cdefs.h>
43*3af888c1Sjakllsch __KERNEL_RCSID(0, "$NetBSD: dmover_request.c,v 1.8 2011/05/14 18:24:47 jakllsch Exp $");
445d06c0e8Sthorpej
455d06c0e8Sthorpej #include <sys/param.h>
465d06c0e8Sthorpej #include <sys/pool.h>
475d06c0e8Sthorpej #include <sys/systm.h>
485d06c0e8Sthorpej #include <sys/malloc.h>
495d06c0e8Sthorpej
505d06c0e8Sthorpej #include <dev/dmover/dmovervar.h>
515d06c0e8Sthorpej
52d18c6ca4Sad pool_cache_t dmover_request_cache;
535d06c0e8Sthorpej
54*3af888c1Sjakllsch static bool initialized;
555d06c0e8Sthorpej
565d06c0e8Sthorpej void
dmover_request_initialize(void)575d06c0e8Sthorpej dmover_request_initialize(void)
585d06c0e8Sthorpej {
595d06c0e8Sthorpej
60*3af888c1Sjakllsch KASSERT(initialized == false);
6154221c3eSad
62*3af888c1Sjakllsch dmover_request_cache = pool_cache_init(sizeof(struct dmover_request),
63*3af888c1Sjakllsch 0, 0, 0, "dmreq", NULL, IPL_BIO, NULL, NULL, NULL);
6454221c3eSad
65*3af888c1Sjakllsch initialized = true;
665d06c0e8Sthorpej }
675d06c0e8Sthorpej
685d06c0e8Sthorpej /*
695d06c0e8Sthorpej * dmover_request_alloc: [client interface function]
705d06c0e8Sthorpej *
71*3af888c1Sjakllsch * Allocate a transform request for the specified session.
725d06c0e8Sthorpej */
735d06c0e8Sthorpej struct dmover_request *
dmover_request_alloc(struct dmover_session * dses,dmover_buffer * inbuf)745d06c0e8Sthorpej dmover_request_alloc(struct dmover_session *dses, dmover_buffer *inbuf)
755d06c0e8Sthorpej {
765d06c0e8Sthorpej struct dmover_request *dreq;
77d18c6ca4Sad int inputs = dses->dses_ninputs;
785d06c0e8Sthorpej
79*3af888c1Sjakllsch if (__predict_false(initialized == false))
805d06c0e8Sthorpej return (NULL);
815d06c0e8Sthorpej
82d18c6ca4Sad dreq = pool_cache_get(dmover_request_cache, PR_NOWAIT);
835d06c0e8Sthorpej if (dreq == NULL)
845d06c0e8Sthorpej return (NULL);
855d06c0e8Sthorpej
865d06c0e8Sthorpej memset(dreq, 0, sizeof(*dreq));
875d06c0e8Sthorpej
885d06c0e8Sthorpej if (inputs != 0) {
895d06c0e8Sthorpej if (inbuf == NULL) {
905d06c0e8Sthorpej inbuf = malloc(sizeof(dmover_buffer) * inputs,
915d06c0e8Sthorpej M_DEVBUF, M_NOWAIT);
925d06c0e8Sthorpej if (inbuf == NULL) {
93d18c6ca4Sad pool_cache_put(dmover_request_cache, dreq);
945d06c0e8Sthorpej return (NULL);
955d06c0e8Sthorpej }
965d06c0e8Sthorpej }
975d06c0e8Sthorpej dreq->dreq_flags |= __DMOVER_REQ_INBUF_FREE;
985d06c0e8Sthorpej dreq->dreq_inbuf = inbuf;
995d06c0e8Sthorpej }
1005d06c0e8Sthorpej
1015d06c0e8Sthorpej dreq->dreq_session = dses;
1025d06c0e8Sthorpej
1035d06c0e8Sthorpej return (dreq);
1045d06c0e8Sthorpej }
1055d06c0e8Sthorpej
1065d06c0e8Sthorpej /*
1075d06c0e8Sthorpej * dmover_request_free: [client interface function]
1085d06c0e8Sthorpej *
1095d06c0e8Sthorpej * Free a dmover request.
1105d06c0e8Sthorpej */
1115d06c0e8Sthorpej void
dmover_request_free(struct dmover_request * dreq)1125d06c0e8Sthorpej dmover_request_free(struct dmover_request *dreq)
1135d06c0e8Sthorpej {
1145d06c0e8Sthorpej
115*3af888c1Sjakllsch KASSERT(initialized == true);
116*3af888c1Sjakllsch
1175d06c0e8Sthorpej if (dreq->dreq_flags & __DMOVER_REQ_INBUF_FREE)
1185d06c0e8Sthorpej free(dreq->dreq_inbuf, M_DEVBUF);
1195d06c0e8Sthorpej
120d18c6ca4Sad pool_cache_put(dmover_request_cache, dreq);
1215d06c0e8Sthorpej }
122