4
* DSP-BIOS Bridge driver support functions for TI OMAP processors.
6
* Manage lists of notification events.
8
* Copyright (C) 2005-2006 Texas Instruments, Inc.
10
* This package is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License version 2 as
12
* published by the Free Software Foundation.
14
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22
#include <dspbridge/host_os.h>
23
#include <dspbridge/dbdefs.h>
24
#include <dspbridge/sync.h>
27
* ntfy_object - head structure to nofify dspbridge events
28
* @head: List of notify objects
29
* @ntfy_lock: lock for list access.
33
struct raw_notifier_head head;/* List of notifier objects */
34
spinlock_t ntfy_lock; /* For critical sections */
38
* ntfy_event - structure store specify event to be notified
39
* @noti_block: List of notify objects
40
* @event: event that it respond
41
* @type: event type (only DSP_SIGNALEVENT supported)
42
* @sync_obj: sync_event used to set the event
46
struct notifier_block noti_block;
47
u32 event; /* Events to be notified about */
48
u32 type; /* Type of notification to be sent */
49
struct sync_object sync_obj;
54
* dsp_notifier_event() - callback function to nofity events
55
* @this: pointer to itself struct notifier_block
56
* @event: event to be notified.
57
* @data: Currently not used.
60
int dsp_notifier_event(struct notifier_block *this, unsigned long event,
64
* ntfy_init() - Set the initial state of the ntfy_object structure.
65
* @no: pointer to ntfy_object structure.
67
* This function sets the initial state of the ntfy_object in order it
68
* can be used by the other ntfy functions.
71
static inline void ntfy_init(struct ntfy_object *no)
73
spin_lock_init(&no->ntfy_lock);
74
RAW_INIT_NOTIFIER_HEAD(&no->head);
78
* ntfy_delete() - delete list of nofy events registered.
79
* @ntfy_obj: Pointer to the ntfy object structure.
81
* This function is used to remove all the notify events registered.
82
* unregister function is not needed in this function, to unregister
83
* a ntfy_event please look at ntfy_register function.
86
static inline void ntfy_delete(struct ntfy_object *ntfy_obj)
88
struct ntfy_event *ne;
89
struct notifier_block *nb;
91
spin_lock_bh(&ntfy_obj->ntfy_lock);
92
nb = ntfy_obj->head.head;
94
ne = container_of(nb, struct ntfy_event, noti_block);
98
spin_unlock_bh(&ntfy_obj->ntfy_lock);
102
* ntfy_notify() - nofity all event register for an specific event.
103
* @ntfy_obj: Pointer to the ntfy_object structure.
104
* @event: event to be notified.
106
* This function traverses all the ntfy events registers and
107
* set the event with mach with @event.
109
static inline void ntfy_notify(struct ntfy_object *ntfy_obj, u32 event)
111
spin_lock_bh(&ntfy_obj->ntfy_lock);
112
raw_notifier_call_chain(&ntfy_obj->head, event, NULL);
113
spin_unlock_bh(&ntfy_obj->ntfy_lock);
119
* ntfy_init() - Create and initialize a ntfy_event structure.
120
* @event: event that the ntfy event will respond
121
* @type event type (only DSP_SIGNALEVENT supported)
123
* This function create a ntfy_event element and sets the event it will
124
* respond the ntfy_event in order it can be used by the other ntfy functions.
125
* In case of success it will return a pointer to the ntfy_event struct
126
* created. Otherwise it will return NULL;
129
static inline struct ntfy_event *ntfy_event_create(u32 event, u32 type)
131
struct ntfy_event *ne;
132
ne = kmalloc(sizeof(struct ntfy_event), GFP_KERNEL);
134
sync_init_event(&ne->sync_obj);
135
ne->noti_block.notifier_call = dsp_notifier_event;
143
* ntfy_register() - register new ntfy_event into a given ntfy_object
144
* @ntfy_obj: Pointer to the ntfy_object structure.
145
* @noti: Pointer to the handle to be returned to the user space.
146
* @event event that the ntfy event will respond
147
* @type event type (only DSP_SIGNALEVENT supported)
149
* This function register a new ntfy_event into the ntfy_object list,
150
* which will respond to the @event passed.
151
* This function will return 0 in case of error.
152
* -EFAULT in case of bad pointers and
153
* DSP_EMemory in case of no memory to create ntfy_event.
155
static inline int ntfy_register(struct ntfy_object *ntfy_obj,
156
struct dsp_notification *noti,
159
struct ntfy_event *ne;
162
if (!noti || !ntfy_obj) {
170
ne = ntfy_event_create(event, type);
175
noti->handle = &ne->sync_obj;
177
spin_lock_bh(&ntfy_obj->ntfy_lock);
178
raw_notifier_chain_register(&ntfy_obj->head, &ne->noti_block);
179
spin_unlock_bh(&ntfy_obj->ntfy_lock);
185
* ntfy_unregister() - unregister a ntfy_event from a given ntfy_object
186
* @ntfy_obj: Pointer to the ntfy_object structure.
187
* @noti: Pointer to the event that will be removed.
189
* This function unregister a ntfy_event from the ntfy_object list,
190
* @noti contains the event which is wanted to be removed.
191
* This function will return 0 in case of error.
192
* -EFAULT in case of bad pointers and
193
* DSP_EMemory in case of no memory to create ntfy_event.
195
static inline int ntfy_unregister(struct ntfy_object *ntfy_obj,
196
struct dsp_notification *noti)
199
struct ntfy_event *ne;
201
if (!noti || !ntfy_obj) {
206
ne = container_of((struct sync_object *)noti, struct ntfy_event,
208
spin_lock_bh(&ntfy_obj->ntfy_lock);
209
raw_notifier_chain_unregister(&ntfy_obj->head,
212
spin_unlock_bh(&ntfy_obj->ntfy_lock);