1170159Sariff/*- 2170159Sariff * Copyright (c) 2007 Ariff Abdullah <ariff@FreeBSD.org> 3170159Sariff * All rights reserved. 4170159Sariff * 5170159Sariff * Redistribution and use in source and binary forms, with or without 6170159Sariff * modification, are permitted provided that the following conditions 7170159Sariff * are met: 8170159Sariff * 1. Redistributions of source code must retain the above copyright 9170159Sariff * notice, this list of conditions and the following disclaimer. 10170159Sariff * 2. Redistributions in binary form must reproduce the above copyright 11170159Sariff * notice, this list of conditions and the following disclaimer in the 12170159Sariff * documentation and/or other materials provided with the distribution. 13170159Sariff * 14170159Sariff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15170159Sariff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16170159Sariff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17170159Sariff * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18170159Sariff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19170159Sariff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20170159Sariff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21170159Sariff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22170159Sariff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23170159Sariff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24170159Sariff * SUCH DAMAGE. 25170159Sariff * 26170159Sariff * $FreeBSD: releng/10.2/sys/dev/sound/clone.h 170719 2007-06-14 11:10:21Z ariff $ 27170159Sariff */ 28170159Sariff 29170159Sariff#ifndef _SND_CLONE_H_ 30170159Sariff#define _SND_CLONE_H_ 31170159Sariff 32170159Sariffstruct snd_clone_entry; 33170159Sariffstruct snd_clone; 34170159Sariff 35170159Sariff/* 36170159Sariff * 750 milisecond default deadline. Short enough to not cause excessive 37170159Sariff * garbage collection, long enough to indicate stalled VFS. 38170159Sariff */ 39170159Sariff#define SND_CLONE_DEADLINE_DEFAULT 750 40170159Sariff 41170159Sariff/* 42170159Sariff * Fit within 24bit MAXMINOR. 43170159Sariff */ 44170159Sariff#define SND_CLONE_MAXUNIT 0xffffff 45170159Sariff 46170159Sariff/* 47170159Sariff * Creation flags, mostly related to the behaviour of garbage collector. 48170159Sariff * 49170159Sariff * SND_CLONE_ENABLE - Enable clone allocation. 50170159Sariff * SND_CLONE_GC_ENABLE - Enable garbage collector operation, automatically 51170159Sariff * or if explicitly called upon. 52170159Sariff * SND_CLONE_GC_UNREF - Garbage collect during unref operation. 53170159Sariff * SND_CLONE_GC_LASTREF - Garbage collect during last reference 54170159Sariff * (refcount = 0) 55170159Sariff * SND_CLONE_GC_EXPIRED - Don't garbage collect unless the global clone 56170159Sariff * handler has been expired. 57170159Sariff * SND_CLONE_GC_REVOKE - Revoke clone invocation status which has been 58170159Sariff * expired instead of removing and freeing it. 59170719Sariff * SND_CLONE_WAITOK - malloc() is allowed to sleep while allocating 60170719Sariff * clone entry. 61170159Sariff */ 62170159Sariff#define SND_CLONE_ENABLE 0x00000001 63170159Sariff#define SND_CLONE_GC_ENABLE 0x00000002 64170159Sariff#define SND_CLONE_GC_UNREF 0x00000004 65170159Sariff#define SND_CLONE_GC_LASTREF 0x00000008 66170159Sariff#define SND_CLONE_GC_EXPIRED 0x00000010 67170159Sariff#define SND_CLONE_GC_REVOKE 0x00000020 68170719Sariff#define SND_CLONE_WAITOK 0x80000000 69170159Sariff 70170159Sariff#define SND_CLONE_GC_MASK (SND_CLONE_GC_ENABLE | \ 71170159Sariff SND_CLONE_GC_UNREF | \ 72170159Sariff SND_CLONE_GC_LASTREF | \ 73170159Sariff SND_CLONE_GC_EXPIRED | \ 74170159Sariff SND_CLONE_GC_REVOKE) 75170159Sariff 76170719Sariff#define SND_CLONE_MASK (SND_CLONE_ENABLE | SND_CLONE_GC_MASK | \ 77170719Sariff SND_CLONE_WAITOK) 78170159Sariff 79170159Sariff/* 80170159Sariff * Runtime clone device flags 81170159Sariff * 82170159Sariff * These are mostly private to the clone manager operation: 83170159Sariff * 84170159Sariff * SND_CLONE_NEW - New clone allocation in progress. 85170159Sariff * SND_CLONE_INVOKE - Cloning being invoked, waiting for next VFS operation. 86170159Sariff * SND_CLONE_BUSY - In progress, being referenced by living thread/proc. 87170159Sariff */ 88170159Sariff#define SND_CLONE_NEW 0x00000001 89170159Sariff#define SND_CLONE_INVOKE 0x00000002 90170159Sariff#define SND_CLONE_BUSY 0x00000004 91170159Sariff 92170159Sariff/* 93170159Sariff * Nothing important, just for convenience. 94170159Sariff */ 95170159Sariff#define SND_CLONE_ALLOC (SND_CLONE_NEW | SND_CLONE_INVOKE | \ 96170159Sariff SND_CLONE_BUSY) 97170159Sariff 98170159Sariff#define SND_CLONE_DEVMASK SND_CLONE_ALLOC 99170159Sariff 100170159Sariff 101170159Sariffvoid snd_timestamp(struct timespec *); 102170159Sariff 103170159Sariffstruct snd_clone *snd_clone_create(int, int, int, uint32_t); 104170159Sariffint snd_clone_busy(struct snd_clone *); 105170159Sariffint snd_clone_enable(struct snd_clone *); 106170159Sariffint snd_clone_disable(struct snd_clone *); 107170159Sariffint snd_clone_getsize(struct snd_clone *); 108170159Sariffint snd_clone_getmaxunit(struct snd_clone *); 109170159Sariffint snd_clone_setmaxunit(struct snd_clone *, int); 110170159Sariffint snd_clone_getdeadline(struct snd_clone *); 111170159Sariffint snd_clone_setdeadline(struct snd_clone *, int); 112170159Sariffint snd_clone_gettime(struct snd_clone *, struct timespec *); 113170159Sariffuint32_t snd_clone_getflags(struct snd_clone *); 114170159Sariffuint32_t snd_clone_setflags(struct snd_clone *, uint32_t); 115170159Sariffint snd_clone_getdevtime(struct cdev *, struct timespec *); 116170159Sariffuint32_t snd_clone_getdevflags(struct cdev *); 117170159Sariffuint32_t snd_clone_setdevflags(struct cdev *, uint32_t); 118170159Sariffint snd_clone_gc(struct snd_clone *); 119170159Sariffvoid snd_clone_destroy(struct snd_clone *); 120170159Sariffint snd_clone_acquire(struct cdev *); 121170159Sariffint snd_clone_release(struct cdev *); 122170159Sariffint snd_clone_ref(struct cdev *); 123170159Sariffint snd_clone_unref(struct cdev *); 124170159Sariffvoid snd_clone_register(struct snd_clone_entry *, struct cdev *); 125170159Sariffstruct snd_clone_entry *snd_clone_alloc(struct snd_clone *, struct cdev **, 126170159Sariff int *, int); 127170159Sariff 128170159Sariff#define snd_clone_enabled(x) ((x) != NULL && \ 129170159Sariff (snd_clone_getflags(x) & SND_CLONE_ENABLE)) 130170159Sariff#define snd_clone_disabled(x) (!snd_clone_enabled(x)) 131170159Sariff 132170159Sariff#endif /* !_SND_CLONE_H */ 133