aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/wait.h
blob: d28518236b62fea581606ee74c76607743153aad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#ifndef _LINUX_WAIT_H
#define _LINUX_WAIT_H

#define WNOHANG		0x00000001
#define WUNTRACED	0x00000002
#define WSTOPPED	WUNTRACED
#define WEXITED		0x00000004
#define WCONTINUED	0x00000008
#define WNOWAIT		0x01000000	/* Don't reap, just poll status.  */

#define __WNOTHREAD	0x20000000	/* Don't wait on children of other threads in this group */
#define __WALL		0x40000000	/* Wait on all children, regardless of type */
#define __WCLONE	0x80000000	/* Wait only on non-SIGCHLD children */

/* First argument to waitid: */
#define P_ALL		0
#define P_PID		1
#define P_PGID		2

#ifdef __KERNEL__

#include <linux/config.h>
#include <linux/list.h>
#include <linux/stddef.h>
#include <linux/spinlock.h>
#include <asm/system.h>
#include <asm/current.h>

typedef struct __wait_queue wait_queue_t;
typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int sync, void *key);
int default_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);

struct __wait_queue {
	unsigned int flags;
#define WQ_FLAG_EXCLUSIVE	0x01
	void *private;
	wait_queue_func_t func;
	struct list_head task_list;
};

struct wait_bit_key {
	void *flags;
	int bit_nr;
};

struct wait_bit_queue {
	struct wait_bit_key key;
	wait_queue_t wait;
};

struct __wait_queue_head {
	spinlock_t lock;
	struct list_head task_list;
};
typedef struct __wait_queue_head wait_queue_head_t;

struct task_struct;

/*
 * Macros for declaration and initialisaton of the datatypes
 */

#define __WAITQUEUE_INITIALIZER(name, tsk) {				\
	.private	= tsk,						\
	.func		= default_wake_function,			\
	.task_list	= { NULL, NULL } }

#define DECLARE_WAITQUEUE(name, tsk)					\
	wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)

#define __WAIT_QUEUE_HEAD_INITIALIZER(name) {				\
	.lock		= SPIN_LOCK_UNLOCKED,				\
	.task_list	= { &(name).task_list, &(name).task_list } }

#define DECLARE_WAIT_QUEUE_HEAD(name) \
	wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)

#define __WAIT_BIT_KEY_INITIALIZER(word, bit)				\
	{ .flags = word, .bit_nr = bit, }

static inline void init_waitqueue_head(wait_queue_head_t *q)
{
	spin_lock_init(&q->lock);
	INIT_LIST_HEAD(&q->task_list);
}

static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
{
	q->flags = 0;
	q->private = p;
	q->func = default_wake_function;
}

static inline void init_waitqueue_func_entry(wait_queue_t *q,
					wait_queue_func_t func)
{
	q->flags = 0;
	q->private = NULL;
	q->func = func;
}

static inline int waitqueue_active(wait_queue_head_t *q)
{
	return !list_empty(&q->task_list);
}

/*
 * Used to distinguish between sync and async io wait context:
 * sync i/o typically specifies a NULL wait queue entry or a wait
 * queue entry bound to a task (current task) to wake up.
 * aio specifies a wait queue entry with an async notification
 * callback routine, not associated with any task.
 */
#define is_sync_wait(wait)	(!(wait) || ((wait)->private))

extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));

static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
{
	list_add(&new->task_list, &head->task_list);
}

/*
 * Used for wake-one threads:
 */
static inline void __add_wait_queue_tail(wait_queue_head_t *head,
						wait_queue_t *new)
{
	list_add_tail(&new->task_list, &head->task_list);
}

static inline void __remove_wait_queue(wait_queue_head_t *head,
							wait_queue_t *old)
{
	list_del(&old->task_list);
}

void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key));
extern void FASTCALL(__wake_up_locked(wait_queue_head_t *q, unsigned int mode));
extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr));
void FASTCALL(__wake_up_bit(wait_queue_head_t *, void *, int));
int FASTCALL(__wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned));
int FASTCALL(__wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned));
void FASTCALL(wake_up_bit(void *, int));
int FASTCALL(out_of_line_wait_on_bit(void *, int, int (*)(void *), unsigned));
int FASTCALL(out_of_line_wait_on_bit_lock(void *, int, int (*)(void *), unsigned));
wait_queue_head_t *FASTCALL(bit_waitqueue(void *, int));

#define wake_up(x)			__wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, NULL)
#define wake_up_nr(x, nr)		__wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr, NULL)
#define wake_up_all(x)			__wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0, NULL)
#define wake_up_interruptible(x)	__wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
#define wake_up_interruptible_nr(x, nr)	__wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
#define wake_up_interruptible_all(x)	__wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
#define	wake_up_locked(x)		__wake_up_locked((x), TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
#define wake_up_interruptible_sync(x)   __wake_up_sync((x),TASK_INTERRUPTIBLE, 1)

#define __wait_event(wq, condition) 					\
do {									\
	DEFINE_WAIT(__wait);						\
									\
	for (;;) {							\
		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
		if (condition)						\
			break;						\
		schedule();						\
	}								\
	finish_wait(&wq, &__wait);					\
} while (0)

/**
 * wait_event - sleep until a condition gets true
 * @wq: the waitqueue to wait on
 * @condition: a C expression for the event to wait for
 *
 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
 * @condition evaluates to true. The @condition is checked each time
 * the waitqueue @wq is woken up.
 *
 * wake_up() has to be called after changing any variable that could
 * change the result of the wait condition.
 */
#define wait_event(wq, condition) 					\
do {									\
	if (condition)	 						\
		break;							\
	__wait_event(wq, condition);					\
} while (0)

#define __wait_event_timeout(wq, condition, ret)			\
do {									\
	DEFINE_WAIT(__wait);						\
									\
	for (;;) {							\
		prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);	\
		if (condition)						\
			break;						\
		ret = schedule_timeout(ret);				\
		if (!ret)						\
			break;						\
	}								\
	finish_wait(&wq, &__wait);					\
} while (0)

/**
 * wait_event_timeout - sleep until a condition gets true or a timeout elapses
 * @wq: the waitqueue to wait on
 * @condition: a C expression for the event to wait for
 * @timeout: timeout, in jiffies
 *
 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
 * @condition evaluates to true. The @condition is checked each time
 * the waitqueue @wq is woken up.
 *
 * wake_up() has to be called after changing any variable that could
 * change the result of the wait condition.
 *
 * The function returns 0 if the @timeout elapsed, and the remaining
 * jiffies if the condition evaluated to true before the timeout elapsed.
 */
#define wait_event_timeout(wq, condition, timeout)			\
({									\
	long __ret = timeout;						\
	if (!(condition)) 						\
		__wait_event_timeout(wq, condition, __ret);		\
	__ret;								\
})

#define __wait_event_interruptible(wq, condition, ret)			\
do {									\
	DEFINE_WAIT(__wait);						\
									\
	for (;;) {							\
		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
		if (condition)						\
			break;						\
		if (!signal_pending(current)) {				\
			schedule();					\
			continue;					\
		}							\
		ret = -ERESTARTSYS;					\
		break;							\
	}								\
	finish_wait(&wq, &__wait);					\
} while (0)

/**
 * wait_event_interruptible - sleep until a condition gets true
 * @wq: the waitqueue to wait on
 * @condition: a C expression for the event to wait for
 *
 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
 * @condition evaluates to true or a signal is received.
 * The @condition is checked each time the waitqueue @wq is woken up.
 *
 * wake_up() has to be called after changing any variable that could
 * change the result of the wait condition.
 *
 * The function will return -ERESTARTSYS if it was interrupted by a
 * signal and 0 if @condition evaluated to true.
 */
#define wait_event_interruptible(wq, condition)				\
({									\
	int __ret = 0;							\
	if (!(condition))						\
		__wait_event_interruptible(wq, condition, __ret);	\
	__ret;								\
})

#define __wait_event_interruptible_timeout(wq, condition, ret)		\
do {									\
	DEFINE_WAIT(__wait);						\
									\
	for (;;) {							\
		prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);	\
		if (condition)						\
			break;						\
		if (!signal_pending(current)) {				\
			ret = schedule_timeout(ret);			\
			if (!ret)					\
				break;					\
			continue;					\
		}							\
		ret = -ERESTARTSYS;					\
		break;							\
	}								\
	finish_wait(&wq, &__wait);					\
} while (0)

/**
 * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
 * @wq: the waitqueue to wait on
 * @condition: a C expression for the event to wait for
 * @timeout: timeout, in jiffies
 *
 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
 * @condition evaluates to true or a signal is received.
 * The @condition is checked each time the waitqueue @wq is woken up.
 *
 * wake_up() has to be called after changing any variable that could
 * change the result of the wait condition.
 *
 * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
 * was interrupted by a signal, and the remaining jiffies otherwise
 * if the condition evaluated to true before the timeout elapsed.
 */
#define wait_event_interruptible_timeout(wq, condition, timeout)	\
({									\
	long __ret = timeout;						\
	if (!(condition))						\
		__wait_event_interruptible_timeout(wq, condition, __ret); \
	__ret;								\
})

#define __wait_event_interruptible_exclusive(wq, condition, ret)	\
do {									\
	DEFINE_WAIT(__wait);						\
									\
	for (;;) {							\
		prepare_to_wait_exclusive(&wq, &__wait,			\
					TASK_INTERRUPTIBLE);		\
		if (condition)						\
			break;						\
		if (!signal_pending(current)) {				\
			schedule();					\
			continue;					\
		}							\
		ret = -ERESTARTSYS;					\
		break;							\
	}								\
	finish_wait(&wq, &__wait);					\
} while (0)

#define wait_event_interruptible_exclusive(wq, condition)		\
({									\
	int __ret = 0;							\
	if (!(condition))						\
		__wait_event_interruptible_exclusive(wq, condition, __ret);\
	__ret;								\
})

/*
 * Must be called with the spinlock in the wait_queue_head_t held.
 */
static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
						   wait_queue_t * wait)
{
	wait->flags |= WQ_FLAG_EXCLUSIVE;
	__add_wait_queue_tail(q,  wait);
}

/*
 * Must be called with the spinlock in the wait_queue_head_t held.
 */
static inline void remove_wait_queue_locked(wait_queue_head_t *q,
					    wait_queue_t * wait)
{
	__remove_wait_queue(q,  wait);
}

/*
 * These are the old interfaces to sleep waiting for an event.
 * They are racy.  DO NOT use them, use the wait_event* interfaces above.  
 * We plan to remove these interfaces during 2.7.
 */
extern void FASTCALL(sleep_on(wait_queue_head_t *q));
extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
				      signed long timeout));
extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
						    signed long timeout));

/*
 * Waitqueues which are removed from the waitqueue_head at wakeup time
 */
void FASTCALL(prepare_to_wait(wait_queue_head_t *q,
				wait_queue_t *wait, int state));
void FASTCALL(prepare_to_wait_exclusive(wait_queue_head_t *q,
				wait_queue_t *wait, int state));
void FASTCALL(finish_wait(wait_queue_head_t *q, wait_queue_t *wait));
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);

#define DEFINE_WAIT(name)						\
	wait_queue_t name = {						\
		.private	= current,				\
		.func		= autoremove_wake_function,		\
		.task_list	= LIST_HEAD_INIT((name).task_list),	\
	}

#define DEFINE_WAIT_BIT(name, word, bit)				\
	struct wait_bit_queue name = {					\
		.key = __WAIT_BIT_KEY_INITIALIZER(word, bit),		\
		.wait	= {						\
			.private	= current,			\
			.func		= wake_bit_function,		\
			.task_list	=				\
				LIST_HEAD_INIT((name).wait.task_list),	\
		},							\
	}

#define init_wait(wait)							\
	do {								\
		(wait)->private = current;				\
		(wait)->func = autoremove_wake_function;		\
		INIT_LIST_HEAD(&(wait)->task_list);			\
	} while (0)

/**
 * wait_on_bit - wait for a bit to be cleared
 * @word: the word being waited on, a kernel virtual address
 * @bit: the bit of the word being waited on
 * @action: the function used to sleep, which may take special actions
 * @mode: the task state to sleep in
 *
 * There is a standard hashed waitqueue table for generic use. This
 * is the part of the hashtable's accessor API that waits on a bit.
 * For instance, if one were to have waiters on a bitflag, one would
 * call wait_on_bit() in threads waiting for the bit to clear.
 * One uses wait_on_bit() where one is waiting for the bit to clear,
 * but has no intention of setting it.
 */
static inline int wait_on_bit(void *word, int bit,
				int (*action)(void *), unsigned mode)
{
	if (!test_bit(bit, word))
		return 0;
	return out_of_line_wait_on_bit(word, bit, action, mode);
}

/**
 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
 * @word: the word being waited on, a kernel virtual address
 * @bit: the bit of the word being waited on
 * @action: the function used to sleep, which may take special actions
 * @mode: the task state to sleep in
 *
 * There is a standard hashed waitqueue table for generic use. This
 * is the part of the hashtable's accessor API that waits on a bit
 * when one intends to set it, for instance, trying to lock bitflags.
 * For instance, if one were to have waiters trying to set bitflag
 * and waiting for it to clear before setting it, one would call
 * wait_on_bit() in threads waiting to be able to set the bit.
 * One uses wait_on_bit_lock() where one is waiting for the bit to
 * clear with the intention of setting it, and when done, clearing it.
 */
static inline int wait_on_bit_lock(void *word, int bit,
				int (*action)(void *), unsigned mode)
{
	if (!test_and_set_bit(bit, word))
		return 0;
	return out_of_line_wait_on_bit_lock(word, bit, action, mode);
}
	
#endif /* __KERNEL__ */

#endif
hl com"> * Purpose: * When notified of DSP error, take appropriate action. * Parameters: * hdeh_mgr: Handle to DEH manager object. * evnt_mask: Indicate the type of exception * error_info: Error information * Returns: * * Requires: * hdeh_mgr != NULL; * evnt_mask with a valid exception * Ensures: */ typedef void (*fxn_deh_notify) (struct deh_mgr *hdeh_mgr, u32 evnt_mask, u32 error_info); /* * ======== bridge_chnl_open ======== * Purpose: * Open a new half-duplex channel to the DSP board. * Parameters: * chnl: Location to store a channel object handle. * hchnl_mgr: Handle to channel manager, as returned by * CHNL_GetMgr(). * chnl_mode: One of {CHNL_MODETODSP, CHNL_MODEFROMDSP} specifies * direction of data transfer. * ch_id: If CHNL_PICKFREE is specified, the channel manager will * select a free channel id (default); * otherwise this field specifies the id of the channel. * pattrs: Channel attributes. Attribute fields are as follows: * pattrs->uio_reqs: Specifies the maximum number of I/O requests which can * be pending at any given time. All request packets are * preallocated when the channel is opened. * pattrs->event_obj: This field allows the user to supply an auto reset * event object for channel I/O completion notifications. * It is the responsibility of the user to destroy this * object AFTER closing the channel. * This channel event object can be retrieved using * CHNL_GetEventHandle(). * pattrs->hReserved: The kernel mode handle of this event object. * * Returns: * 0: Success. * -EFAULT: hchnl_mgr is invalid. * -ENOMEM: Insufficient memory for requested resources. * -EINVAL: Invalid number of IOReqs. * -ENOSR: No free channels available. * -ECHRNG: Channel ID is out of range. * -EALREADY: Channel is in use. * -EIO: No free IO request packets available for * queuing. * Requires: * chnl != NULL. * pattrs != NULL. * pattrs->event_obj is a valid event handle. * pattrs->hReserved is the kernel mode handle for pattrs->event_obj. * Ensures: * 0: *chnl is a valid channel. * else: *chnl is set to NULL if (chnl != NULL); */ typedef int(*fxn_chnl_open) (struct chnl_object **chnl, struct chnl_mgr *hchnl_mgr, s8 chnl_mode, u32 ch_id, const struct chnl_attr * pattrs); /* * ======== bridge_chnl_close ======== * Purpose: * Ensures all pending I/O on this channel is cancelled, discards all * queued I/O completion notifications, then frees the resources allocated * for this channel, and makes the corresponding logical channel id * available for subsequent use. * Parameters: * chnl_obj: Handle to a channel object. * Returns: * 0: Success; * -EFAULT: Invalid chnl_obj. * Requires: * No thread must be blocked on this channel's I/O completion event. * Ensures: * 0: chnl_obj is no longer valid. */ typedef int(*fxn_chnl_close) (struct chnl_object *chnl_obj); /* * ======== bridge_chnl_add_io_req ======== * Purpose: * Enqueue an I/O request for data transfer on a channel to the DSP. * The direction (mode) is specified in the channel object. Note the DSP * address is specified for channels opened in direct I/O mode. * Parameters: * chnl_obj: Channel object handle. * host_buf: Host buffer address source. * byte_size: Number of PC bytes to transfer. A zero value indicates * that this buffer is the last in the output channel. * A zero value is invalid for an input channel. *! buf_size: Actual buffer size in host bytes. * dw_dsp_addr: DSP address for transfer. (Currently ignored). * dw_arg: A user argument that travels with the buffer. * Returns: * 0: Success; * -EFAULT: Invalid chnl_obj or host_buf. * -EPERM: User cannot mark EOS on an input channel. * -ECANCELED: I/O has been cancelled on this channel. No further * I/O is allowed. * -EPIPE: End of stream was already marked on a previous * IORequest on this channel. No further I/O is expected. * -EINVAL: Buffer submitted to this output channel is larger than * the size of the physical shared memory output window. * Requires: * Ensures: * 0: The buffer will be transferred if the channel is ready; * otherwise, will be queued for transfer when the channel becomes * ready. In any case, notifications of I/O completion are * asynchronous. * If byte_size is 0 for an output channel, subsequent CHNL_AddIOReq's * on this channel will fail with error code -EPIPE. The * corresponding IOC for this I/O request will have its status flag * set to CHNL_IOCSTATEOS. */ typedef int(*fxn_chnl_addioreq) (struct chnl_object * chnl_obj, void *host_buf, u32 byte_size, u32 buf_size, u32 dw_dsp_addr, u32 dw_arg); /* * ======== bridge_chnl_get_ioc ======== * Purpose: * Dequeue an I/O completion record, which contains information about the * completed I/O request. * Parameters: * chnl_obj: Channel object handle. * timeout: A value of CHNL_IOCNOWAIT will simply dequeue the * first available IOC. * chan_ioc: On output, contains host buffer address, bytes * transferred, and status of I/O completion. * chan_ioc->status: See chnldefs.h. * Returns: * 0: Success. * -EFAULT: Invalid chnl_obj or chan_ioc. * -EREMOTEIO: CHNL_IOCNOWAIT was specified as the timeout parameter * yet no I/O completions were queued. * Requires: * timeout == CHNL_IOCNOWAIT. * Ensures: * 0: if there are any remaining IOC's queued before this call * returns, the channel event object will be left in a signalled * state. */ typedef int(*fxn_chnl_getioc) (struct chnl_object *chnl_obj, u32 timeout, struct chnl_ioc *chan_ioc); /* * ======== bridge_chnl_cancel_io ======== * Purpose: * Return all I/O requests to the client which have not yet been * transferred. The channel's I/O completion object is * signalled, and all the I/O requests are queued as IOC's, with the * status field set to CHNL_IOCSTATCANCEL. * This call is typically used in abort situations, and is a prelude to * chnl_close(); * Parameters: * chnl_obj: Channel object handle. * Returns: * 0: Success; * -EFAULT: Invalid chnl_obj. * Requires: * Ensures: * Subsequent I/O requests to this channel will not be accepted. */ typedef int(*fxn_chnl_cancelio) (struct chnl_object *chnl_obj); /* * ======== bridge_chnl_flush_io ======== * Purpose: * For an output stream (to the DSP), indicates if any IO requests are in * the output request queue. For input streams (from the DSP), will * cancel all pending IO requests. * Parameters: * chnl_obj: Channel object handle. * timeout: Timeout value for flush operation. * Returns: * 0: Success; * S_CHNLIOREQUEST: Returned if any IORequests are in the output queue. * -EFAULT: Invalid chnl_obj. * Requires: * Ensures: * 0: No I/O requests will be pending on this channel. */ typedef int(*fxn_chnl_flushio) (struct chnl_object *chnl_obj, u32 timeout); /* * ======== bridge_chnl_get_info ======== * Purpose: * Retrieve information related to a channel. * Parameters: * chnl_obj: Handle to a valid channel object, or NULL. * channel_info: Location to store channel info. * Returns: * 0: Success; * -EFAULT: Invalid chnl_obj or channel_info. * Requires: * Ensures: * 0: channel_info points to a filled in chnl_info struct, * if (channel_info != NULL). */ typedef int(*fxn_chnl_getinfo) (struct chnl_object *chnl_obj, struct chnl_info *channel_info); /* * ======== bridge_chnl_get_mgr_info ======== * Purpose: * Retrieve information related to the channel manager. * Parameters: * hchnl_mgr: Handle to a valid channel manager, or NULL. * ch_id: Channel ID. * mgr_info: Location to store channel manager info. * Returns: * 0: Success; * -EFAULT: Invalid hchnl_mgr or mgr_info. * -ECHRNG: Invalid channel ID. * Requires: * Ensures: * 0: mgr_info points to a filled in chnl_mgrinfo * struct, if (mgr_info != NULL). */ typedef int(*fxn_chnl_getmgrinfo) (struct chnl_mgr * hchnl_mgr, u32 ch_id, struct chnl_mgrinfo *mgr_info); /* * ======== bridge_chnl_idle ======== * Purpose: * Idle a channel. If this is an input channel, or if this is an output * channel and flush_data is TRUE, all currently enqueued buffers will be * dequeued (data discarded for output channel). * If this is an output channel and flush_data is FALSE, this function * will block until all currently buffered data is output, or the timeout * specified has been reached. * * Parameters: * chnl_obj: Channel object handle. * timeout: If output channel and flush_data is FALSE, timeout value * to wait for buffers to be output. (Not used for * input channel). * flush_data: If output channel and flush_data is TRUE, discard any * currently buffered data. If FALSE, wait for currently * buffered data to be output, or timeout, whichever * occurs first. flush_data is ignored for input channel. * Returns: * 0: Success; * -EFAULT: Invalid chnl_obj. * -ETIMEDOUT: Timeout occured before channel could be idled. * Requires: * Ensures: */ typedef int(*fxn_chnl_idle) (struct chnl_object *chnl_obj, u32 timeout, bool flush_data); /* * ======== bridge_chnl_register_notify ======== * Purpose: * Register for notification of events on a channel. * Parameters: * chnl_obj: Channel object handle. * event_mask: Type of events to be notified about: IO completion * (DSP_STREAMIOCOMPLETION) or end of stream * (DSP_STREAMDONE). * notify_type: DSP_SIGNALEVENT. * hnotification: Handle of a dsp_notification object. * Returns: * 0: Success. * -ENOMEM: Insufficient memory. * -EINVAL: event_mask is 0 and hnotification was not * previously registered. * -EFAULT: NULL hnotification, hnotification event name * too long, or hnotification event name NULL. * Requires: * Valid chnl_obj. * hnotification != NULL. * (event_mask & ~(DSP_STREAMIOCOMPLETION | DSP_STREAMDONE)) == 0. * notify_type == DSP_SIGNALEVENT. * Ensures: */ typedef int(*fxn_chnl_registernotify) (struct chnl_object *chnl_obj, u32 event_mask, u32 notify_type, struct dsp_notification *hnotification); /* * ======== bridge_dev_create ======== * Purpose: * Complete creation of the device object for this board. * Parameters: * device_ctx: Ptr to location to store a Bridge device context. * hdev_obj: Handle to a Device Object, created and managed by DSP API. * config_param: Ptr to configuration parameters provided by the * Configuration Manager during device loading. * pDspConfig: DSP resources, as specified in the registry key for this * device. * Returns: * 0: Success. * -ENOMEM: Unable to allocate memory for device context. * Requires: * device_ctx != NULL; * hdev_obj != NULL; * config_param != NULL; * pDspConfig != NULL; * Fields in config_param and pDspConfig contain valid values. * Ensures: * 0: All Bridge driver specific DSP resource and other * board context has been allocated. * -ENOMEM: Bridge failed to allocate resources. * Any acquired resources have been freed. The DSP API * will not call bridge_dev_destroy() if * bridge_dev_create() fails. * Details: * Called during the CONFIGMG's Device_Init phase. Based on host and * DSP configuration information, create a board context, a handle to * which is passed into other Bridge BRD and CHNL functions. The * board context contains state information for the device. Since the * addresses of all pointer parameters may be invalid when this * function returns, they must not be stored into the device context * structure. */ typedef int(*fxn_dev_create) (struct bridge_dev_context **device_ctx, struct dev_object * hdev_obj, struct cfg_hostres * config_param); /* * ======== bridge_dev_ctrl ======== * Purpose: * Bridge driver specific interface. * Parameters: * dev_ctxt: Handle to Bridge driver defined device info. * dw_cmd: Bridge driver defined command code. * pargs: Pointer to an arbitrary argument structure. * Returns: * 0 or -EPERM. Actual command error codes should be passed back in * the pargs structure, and are defined by the Bridge driver implementor. * Requires: * All calls are currently assumed to be synchronous. There are no * IOCTL completion routines provided. * Ensures: */ typedef int(*fxn_dev_ctrl) (struct bridge_dev_context *dev_ctxt, u32 dw_cmd, void *pargs); /* * ======== bridge_dev_destroy ======== * Purpose: * Deallocate Bridge device extension structures and all other resources * acquired by the Bridge driver. * No calls to other Bridge driver functions may subsequently * occur, except for bridge_dev_create(). * Parameters: * dev_ctxt: Handle to Bridge driver defined device information. * Returns: * 0: Success. * -EPERM: Failed to release a resource previously acquired. * Requires: * dev_ctxt != NULL; * Ensures: * 0: Device context is freed. */ typedef int(*fxn_dev_destroy) (struct bridge_dev_context *dev_ctxt); /* * ======== bridge_io_create ======== * Purpose: * Create an object that manages I/O between CHNL and msg_ctrl. * Parameters: * io_man: Location to store IO manager on output. * hchnl_mgr: Handle to channel manager. * hmsg_mgr: Handle to message manager. * Returns: * 0: Success. * -ENOMEM: Memory allocation failure. * -EPERM: Creation failed. * Requires: * hdev_obj != NULL; * Channel manager already created; * Message manager already created; * mgr_attrts != NULL; * io_man != NULL; * Ensures: */ typedef int(*fxn_io_create) (struct io_mgr **io_man, struct dev_object *hdev_obj, const struct io_attrs *mgr_attrts); /* * ======== bridge_io_destroy ======== * Purpose: * Destroy object created in bridge_io_create. * Parameters: * hio_mgr: IO Manager. * Returns: * 0: Success. * -ENOMEM: Memory allocation failure. * -EPERM: Creation failed. * Requires: * Valid hio_mgr; * Ensures: */ typedef int(*fxn_io_destroy) (struct io_mgr *hio_mgr); /* * ======== bridge_io_on_loaded ======== * Purpose: * Called whenever a program is loaded to update internal data. For * example, if shared memory is used, this function would update the * shared memory location and address. * Parameters: * hio_mgr: IO Manager. * Returns: * 0: Success. * -EPERM: Internal failure occurred. * Requires: * Valid hio_mgr; * Ensures: */ typedef int(*fxn_io_onloaded) (struct io_mgr *hio_mgr); /* * ======== fxn_io_getprocload ======== * Purpose: * Called to get the Processor's current and predicted load * Parameters: * hio_mgr: IO Manager. * proc_load_stat Processor Load statistics * Returns: * 0: Success. * -EPERM: Internal failure occurred. * Requires: * Valid hio_mgr; * Ensures: */ typedef int(*fxn_io_getprocload) (struct io_mgr *hio_mgr, struct dsp_procloadstat * proc_load_stat); /* * ======== bridge_msg_create ======== * Purpose: * Create an object to manage message queues. Only one of these objects * can exist per device object. * Parameters: * msg_man: Location to store msg_ctrl manager on output. * hdev_obj: Handle to a device object. * msg_callback: Called whenever an RMS_EXIT message is received. * Returns: * 0: Success. * -ENOMEM: Insufficient memory. * Requires: * msg_man != NULL. * msg_callback != NULL. * hdev_obj != NULL. * Ensures: */ typedef int(*fxn_msg_create) (struct msg_mgr **msg_man, struct dev_object *hdev_obj, msg_onexit msg_callback); /* * ======== bridge_msg_create_queue ======== * Purpose: * Create a msg_ctrl queue for sending or receiving messages from a Message * node on the DSP. * Parameters: * hmsg_mgr: msg_ctrl queue manager handle returned from * bridge_msg_create. * msgq: Location to store msg_ctrl queue on output. * msgq_id: Identifier for messages (node environment pointer). * max_msgs: Max number of simultaneous messages for the node. * h: Handle passed to hmsg_mgr->msg_callback(). * Returns: * 0: Success. * -ENOMEM: Insufficient memory. * Requires: * msgq != NULL. * h != NULL. * max_msgs > 0. * Ensures: * msgq !=NULL <==> 0. */ typedef int(*fxn_msg_createqueue) (struct msg_mgr *hmsg_mgr, struct msg_queue **msgq, u32 msgq_id, u32 max_msgs, void *h); /* * ======== bridge_msg_delete ======== * Purpose: * Delete a msg_ctrl manager allocated in bridge_msg_create(). * Parameters: * hmsg_mgr: Handle returned from bridge_msg_create(). * Returns: * Requires: * Valid hmsg_mgr. * Ensures: */ typedef void (*fxn_msg_delete) (struct msg_mgr *hmsg_mgr); /* * ======== bridge_msg_delete_queue ======== * Purpose: * Delete a msg_ctrl queue allocated in bridge_msg_create_queue. * Parameters: * msg_queue_obj: Handle to msg_ctrl queue returned from * bridge_msg_create_queue. * Returns: * Requires: * Valid msg_queue_obj. * Ensures: */ typedef void (*fxn_msg_deletequeue) (struct msg_queue *msg_queue_obj); /* * ======== bridge_msg_get ======== * Purpose: * Get a message from a msg_ctrl queue. * Parameters: * msg_queue_obj: Handle to msg_ctrl queue returned from * bridge_msg_create_queue. * pmsg: Location to copy message into. * utimeout: Timeout to wait for a message. * Returns: * 0: Success. * -ETIME: Timeout occurred. * -EPERM: No frames available for message (max_msgs too * small). * Requires: * Valid msg_queue_obj. * pmsg != NULL. * Ensures: */ typedef int(*fxn_msg_get) (struct msg_queue *msg_queue_obj, struct dsp_msg *pmsg, u32 utimeout); /* * ======== bridge_msg_put ======== * Purpose: * Put a message onto a msg_ctrl queue. * Parameters: * msg_queue_obj: Handle to msg_ctrl queue returned from * bridge_msg_create_queue. * pmsg: Pointer to message. * utimeout: Timeout to wait for a message. * Returns: * 0: Success. * -ETIME: Timeout occurred. * -EPERM: No frames available for message (max_msgs too * small). * Requires: * Valid msg_queue_obj. * pmsg != NULL. * Ensures: */ typedef int(*fxn_msg_put) (struct msg_queue *msg_queue_obj, const struct dsp_msg *pmsg, u32 utimeout); /* * ======== bridge_msg_register_notify ======== * Purpose: * Register notification for when a message is ready. * Parameters: * msg_queue_obj: Handle to msg_ctrl queue returned from * bridge_msg_create_queue. * event_mask: Type of events to be notified about: Must be * DSP_NODEMESSAGEREADY, or 0 to unregister. * notify_type: DSP_SIGNALEVENT. * hnotification: Handle of notification object. * Returns: * 0: Success. * -ENOMEM: Insufficient memory. * Requires: * Valid msg_queue_obj. * hnotification != NULL. * notify_type == DSP_SIGNALEVENT. * event_mask == DSP_NODEMESSAGEREADY || event_mask == 0. * Ensures: */ typedef int(*fxn_msg_registernotify) (struct msg_queue *msg_queue_obj, u32 event_mask, u32 notify_type, struct dsp_notification *hnotification); /* * ======== bridge_msg_set_queue_id ======== * Purpose: * Set message queue id to node environment. Allows bridge_msg_create_queue * to be called in node_allocate, before the node environment is known. * Parameters: * msg_queue_obj: Handle to msg_ctrl queue returned from * bridge_msg_create_queue. * msgq_id: Node environment pointer. * Returns: * Requires: * Valid msg_queue_obj. * msgq_id != 0. * Ensures: */ typedef void (*fxn_msg_setqueueid) (struct msg_queue *msg_queue_obj, u32 msgq_id); /* * Bridge Driver interface function table. * * The information in this table is filled in by the specific Bridge driver, * and copied into the DSP API's own space. If any interface * function field is set to a value of NULL, then the DSP API will * consider that function not implemented, and return the error code * -ENOSYS when a Bridge driver client attempts to call that function. * * This function table contains DSP API version numbers, which are used by the * Bridge driver loader to help ensure backwards compatility between older * Bridge drivers and newer DSP API. These must be set to * BRD_API_MAJOR_VERSION and BRD_API_MINOR_VERSION, respectively. * * A Bridge driver need not export a CHNL interface. In this case, *all* of * the bridge_chnl_* entries must be set to NULL. */ struct bridge_drv_interface { u32 brd_api_major_version; /* Set to BRD_API_MAJOR_VERSION. */ u32 brd_api_minor_version; /* Set to BRD_API_MINOR_VERSION. */ fxn_dev_create pfn_dev_create; /* Create device context */ fxn_dev_destroy pfn_dev_destroy; /* Destroy device context */ fxn_dev_ctrl pfn_dev_cntrl; /* Optional vendor interface */ fxn_brd_monitor brd_monitor; /* Load and/or start monitor */ fxn_brd_start pfn_brd_start; /* Start DSP program. */ fxn_brd_stop pfn_brd_stop; /* Stop/reset board. */ fxn_brd_status pfn_brd_status; /* Get current board status. */ fxn_brd_read brd_read; /* Read board memory */ fxn_brd_write pfn_brd_write; /* Write board memory. */ fxn_brd_setstate pfn_brd_set_state; /* Sets the Board State */ fxn_brd_memcopy brd_mem_copy; /* Copies DSP Memory */ fxn_brd_memwrite brd_mem_write; /* Write DSP Memory w/o halt */ fxn_brd_memmap brd_mem_map; /* Maps MPU mem to DSP mem */ fxn_brd_memunmap brd_mem_un_map; /* Unmaps MPU mem to DSP mem */ fxn_chnl_create pfn_chnl_create; /* Create channel manager. */ fxn_chnl_destroy pfn_chnl_destroy; /* Destroy channel manager. */ fxn_chnl_open pfn_chnl_open; /* Create a new channel. */ fxn_chnl_close pfn_chnl_close; /* Close a channel. */ fxn_chnl_addioreq pfn_chnl_add_io_req; /* Req I/O on a channel. */ fxn_chnl_getioc pfn_chnl_get_ioc; /* Wait for I/O completion. */ fxn_chnl_cancelio pfn_chnl_cancel_io; /* Cancl I/O on a channel. */ fxn_chnl_flushio pfn_chnl_flush_io; /* Flush I/O. */ fxn_chnl_getinfo pfn_chnl_get_info; /* Get channel specific info */ /* Get channel manager info. */ fxn_chnl_getmgrinfo pfn_chnl_get_mgr_info; fxn_chnl_idle pfn_chnl_idle; /* Idle the channel */ /* Register for notif. */ fxn_chnl_registernotify pfn_chnl_register_notify; fxn_io_create pfn_io_create; /* Create IO manager */ fxn_io_destroy pfn_io_destroy; /* Destroy IO manager */ fxn_io_onloaded pfn_io_on_loaded; /* Notify of program loaded */ /* Get Processor's current and predicted load */ fxn_io_getprocload pfn_io_get_proc_load; fxn_msg_create pfn_msg_create; /* Create message manager */ /* Create message queue */ fxn_msg_createqueue pfn_msg_create_queue; fxn_msg_delete pfn_msg_delete; /* Delete message manager */ /* Delete message queue */ fxn_msg_deletequeue pfn_msg_delete_queue; fxn_msg_get pfn_msg_get; /* Get a message */ fxn_msg_put pfn_msg_put; /* Send a message */ /* Register for notif. */ fxn_msg_registernotify pfn_msg_register_notify; /* Set message queue id */ fxn_msg_setqueueid pfn_msg_set_queue_id; }; /* * ======== bridge_drv_entry ======== * Purpose: * Registers Bridge driver functions with the DSP API. Called only once * by the DSP API. The caller will first check DSP API version * compatibility, and then copy the interface functions into its own * memory space. * Parameters: * drv_intf Pointer to a location to receive a pointer to the * Bridge driver interface. * Returns: * Requires: * The code segment this function resides in must expect to be discarded * after completion. * Ensures: * drv_intf pointer initialized to Bridge driver's function * interface. No system resources are acquired by this function. * Details: * Called during the Device_Init phase. */ void bridge_drv_entry(struct bridge_drv_interface **drv_intf, const char *driver_file_name); #endif /* DSPDEFS_ */