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