Change sendfile() to use the new m_ext callback scheme for cleaning up after
[dragonfly.git] / sys / sys / ccbque.h
... / ...
CommitLineData
1/* $NetBSD$ */
2/*
3 * [NetBSD for NEC PC98 series]
4 * Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $FreeBSD: src/sys/i386/isa/ccbque.h,v 1.3.6.2 2000/10/21 07:44:24 nyan Exp $
31 * $DragonFly: src/sys/sys/ccbque.h,v 1.4 2003/08/26 21:42:19 rob Exp $
32 */
33/*
34 * Common command control queue funcs.
35 * Written by N. Honda.
36 */
37
38#ifndef _CCBQUE_H_
39#define _CCBQUE_H_
40
41#define CCB_MWANTED 0x01
42
43/* (I) structure and prototype */
44#define GENERIC_CCB_ASSERT(DEV, CCBTYPE) \
45TAILQ_HEAD(CCBTYPE##tab, CCBTYPE); \
46struct CCBTYPE##que { \
47 struct CCBTYPE##tab CCBTYPE##tab; \
48 int count; \
49 int maxccb; \
50 u_int flags; \
51}; \
52 \
53void DEV##_init_ccbque (int); \
54struct CCBTYPE *DEV##_get_ccb (void); \
55void DEV##_free_ccb (struct CCBTYPE *);
56
57/* (II) static allocated memory */
58#define GENERIC_CCB_STATIC_ALLOC(DEV, CCBTYPE) \
59static struct CCBTYPE##que CCBTYPE##que;
60
61/* (III) functions */
62#define GENERIC_CCB(DEV, CCBTYPE, CHAIN) \
63 \
64void \
65DEV##_init_ccbque(count) \
66 int count; \
67{ \
68 if (CCBTYPE##que.maxccb == 0) \
69 TAILQ_INIT(&CCBTYPE##que.CCBTYPE##tab); \
70 CCBTYPE##que.maxccb += count; \
71} \
72 \
73struct CCBTYPE * \
74DEV##_get_ccb() \
75{ \
76 struct CCBTYPE *cb; \
77 int s = splcam(); \
78 \
79 if (CCBTYPE##que.count < CCBTYPE##que.maxccb) \
80 { \
81 CCBTYPE##que.count ++; \
82 cb = CCBTYPE##que.CCBTYPE##tab.tqh_first; \
83 if (cb != NULL) \
84 { \
85 TAILQ_REMOVE(&CCBTYPE##que.CCBTYPE##tab, cb, CHAIN);\
86 goto out; \
87 } \
88 else \
89 { \
90 cb = malloc(sizeof(*cb), M_DEVBUF, M_NOWAIT); \
91 if (cb != NULL) \
92 { \
93 bzero(cb, sizeof(*cb)); \
94 goto out; \
95 } \
96 } \
97 CCBTYPE##que.count --; \
98 } \
99 \
100 cb = NULL; \
101 \
102out: \
103 splx(s); \
104 return cb; \
105} \
106 \
107void \
108DEV##_free_ccb(cb) \
109 struct CCBTYPE *cb; \
110{ \
111 int s = splcam(); \
112 \
113 TAILQ_INSERT_TAIL(&CCBTYPE##que.CCBTYPE##tab, cb, CHAIN); \
114 CCBTYPE##que.count --; \
115 \
116 if (CCBTYPE##que.flags & CCB_MWANTED) \
117 { \
118 CCBTYPE##que.flags &= ~CCB_MWANTED; \
119 wakeup ((caddr_t) &CCBTYPE##que.count); \
120 } \
121 splx(s); \
122}
123#endif /* !_CCBQUE_H_ */