xref: /freebsd-13.1/sys/dev/sound/clone.h (revision 1b1f80ae)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2007 Ariff Abdullah <[email protected]>
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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _SND_CLONE_H_
32 #define _SND_CLONE_H_
33 
34 struct snd_clone_entry;
35 struct snd_clone;
36 
37 /*
38  * 750 milisecond default deadline. Short enough to not cause excessive
39  * garbage collection, long enough to indicate stalled VFS.
40  */
41 #define SND_CLONE_DEADLINE_DEFAULT	750
42 
43 /*
44  * Fit within 24bit MAXMINOR.
45  */
46 #define SND_CLONE_MAXUNIT		0xffffff
47 
48 /*
49  * Creation flags, mostly related to the behaviour of garbage collector.
50  *
51  * SND_CLONE_ENABLE     - Enable clone allocation.
52  * SND_CLONE_GC_ENABLE  - Enable garbage collector operation, automatically
53  *                        or if explicitly called upon.
54  * SND_CLONE_GC_UNREF   - Garbage collect during unref operation.
55  * SND_CLONE_GC_LASTREF - Garbage collect during last reference
56  *                        (refcount = 0)
57  * SND_CLONE_GC_EXPIRED - Don't garbage collect unless the global clone
58  *                        handler has been expired.
59  * SND_CLONE_GC_REVOKE  - Revoke clone invocation status which has been
60  *                        expired instead of removing and freeing it.
61  * SND_CLONE_WAITOK     - malloc() is allowed to sleep while allocating
62  *                        clone entry.
63  */
64 #define SND_CLONE_ENABLE	0x00000001
65 #define SND_CLONE_GC_ENABLE	0x00000002
66 #define SND_CLONE_GC_UNREF	0x00000004
67 #define SND_CLONE_GC_LASTREF	0x00000008
68 #define SND_CLONE_GC_EXPIRED	0x00000010
69 #define SND_CLONE_GC_REVOKE	0x00000020
70 #define SND_CLONE_WAITOK	0x80000000
71 
72 #define SND_CLONE_GC_MASK	(SND_CLONE_GC_ENABLE  |			\
73 				 SND_CLONE_GC_UNREF   |			\
74 				 SND_CLONE_GC_LASTREF |			\
75 				 SND_CLONE_GC_EXPIRED |			\
76 				 SND_CLONE_GC_REVOKE)
77 
78 #define SND_CLONE_MASK		(SND_CLONE_ENABLE | SND_CLONE_GC_MASK |	\
79 				 SND_CLONE_WAITOK)
80 
81 /*
82  * Runtime clone device flags
83  *
84  * These are mostly private to the clone manager operation:
85  *
86  * SND_CLONE_NEW    - New clone allocation in progress.
87  * SND_CLONE_INVOKE - Cloning being invoked, waiting for next VFS operation.
88  * SND_CLONE_BUSY   - In progress, being referenced by living thread/proc.
89  */
90 #define SND_CLONE_NEW		0x00000001
91 #define SND_CLONE_INVOKE	0x00000002
92 #define SND_CLONE_BUSY		0x00000004
93 
94 /*
95  * Nothing important, just for convenience.
96  */
97 #define SND_CLONE_ALLOC		(SND_CLONE_NEW | SND_CLONE_INVOKE |	\
98 				 SND_CLONE_BUSY)
99 
100 #define SND_CLONE_DEVMASK	SND_CLONE_ALLOC
101 
102 struct snd_clone *snd_clone_create(int, int, int, uint32_t);
103 int snd_clone_busy(struct snd_clone *);
104 int snd_clone_enable(struct snd_clone *);
105 int snd_clone_disable(struct snd_clone *);
106 int snd_clone_getsize(struct snd_clone *);
107 int snd_clone_getmaxunit(struct snd_clone *);
108 int snd_clone_setmaxunit(struct snd_clone *, int);
109 int snd_clone_getdeadline(struct snd_clone *);
110 int snd_clone_setdeadline(struct snd_clone *, int);
111 uint32_t snd_clone_getflags(struct snd_clone *);
112 uint32_t snd_clone_setflags(struct snd_clone *, uint32_t);
113 uint32_t snd_clone_getdevflags(struct cdev *);
114 uint32_t snd_clone_setdevflags(struct cdev *, uint32_t);
115 int snd_clone_gc(struct snd_clone *);
116 void snd_clone_destroy(struct snd_clone *);
117 int snd_clone_acquire(struct cdev *);
118 int snd_clone_release(struct cdev *);
119 int snd_clone_ref(struct cdev *);
120 int snd_clone_unref(struct cdev *);
121 void snd_clone_register(struct snd_clone_entry *, struct cdev *);
122 struct snd_clone_entry *snd_clone_alloc(struct snd_clone *, struct cdev **,
123     int *, int);
124 
125 #define snd_clone_enabled(x)	((x) != NULL && 			\
126 				(snd_clone_getflags(x) & SND_CLONE_ENABLE))
127 #define snd_clone_disabled(x)	(!snd_clone_enabled(x))
128 
129 #endif /* !_SND_CLONE_H */
130