Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ntfy.h
Go to the documentation of this file.
1 /*
2  * ntfy.h
3  *
4  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5  *
6  * Manage lists of notification events.
7  *
8  * Copyright (C) 2005-2006 Texas Instruments, Inc.
9  *
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.
13  *
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.
17  */
18 
19 #ifndef NTFY_
20 #define NTFY_
21 
22 #include <dspbridge/host_os.h>
23 #include <dspbridge/dbdefs.h>
24 #include <dspbridge/sync.h>
25 
32 struct ntfy_object {
33  struct raw_notifier_head head;/* List of notifier objects */
34  spinlock_t ntfy_lock; /* For critical sections */
35 };
36 
45 struct ntfy_event {
47  u32 event; /* Events to be notified about */
48  u32 type; /* Type of notification to be sent */
50 };
51 
52 
60 int dsp_notifier_event(struct notifier_block *this, unsigned long event,
61  void *data);
62 
71 static inline void ntfy_init(struct ntfy_object *no)
72 {
75 }
76 
86 static inline void ntfy_delete(struct ntfy_object *ntfy_obj)
87 {
88  struct ntfy_event *ne;
89  struct notifier_block *nb;
90 
91  spin_lock_bh(&ntfy_obj->ntfy_lock);
92  nb = ntfy_obj->head.head;
93  while (nb) {
94  ne = container_of(nb, struct ntfy_event, noti_block);
95  nb = nb->next;
96  kfree(ne);
97  }
98  spin_unlock_bh(&ntfy_obj->ntfy_lock);
99 }
100 
109 static inline void ntfy_notify(struct ntfy_object *ntfy_obj, u32 event)
110 {
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);
114 }
115 
116 
117 
129 static inline struct ntfy_event *ntfy_event_create(u32 event, u32 type)
130 {
131  struct ntfy_event *ne;
132  ne = kmalloc(sizeof(struct ntfy_event), GFP_KERNEL);
133  if (ne) {
134  sync_init_event(&ne->sync_obj);
135  ne->noti_block.notifier_call = dsp_notifier_event;
136  ne->event = event;
137  ne->type = type;
138  }
139  return ne;
140 }
141 
155 static inline int ntfy_register(struct ntfy_object *ntfy_obj,
156  struct dsp_notification *noti,
157  u32 event, u32 type)
158 {
159  struct ntfy_event *ne;
160  int status = 0;
161 
162  if (!noti || !ntfy_obj) {
163  status = -EFAULT;
164  goto func_end;
165  }
166  if (!event) {
167  status = -EINVAL;
168  goto func_end;
169  }
170  ne = ntfy_event_create(event, type);
171  if (!ne) {
172  status = -ENOMEM;
173  goto func_end;
174  }
175  noti->handle = &ne->sync_obj;
176 
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);
180 func_end:
181  return status;
182 }
183 
195 static inline int ntfy_unregister(struct ntfy_object *ntfy_obj,
196  struct dsp_notification *noti)
197 {
198  int status = 0;
199  struct ntfy_event *ne;
200 
201  if (!noti || !ntfy_obj) {
202  status = -EFAULT;
203  goto func_end;
204  }
205 
206  ne = container_of((struct sync_object *)noti, struct ntfy_event,
207  sync_obj);
208  spin_lock_bh(&ntfy_obj->ntfy_lock);
210  &ne->noti_block);
211  kfree(ne);
212  spin_unlock_bh(&ntfy_obj->ntfy_lock);
213 func_end:
214  return status;
215 }
216 
217 #endif /* NTFY_ */