• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __HI_OSAL__
17 #define __HI_OSAL__
18 
19 #define HI_OSAL_VERSION    "1.0"
20 
21 #include "osal_list.h"
22 #include "autoconf.h"
23 
24 #define osal_gfp_kernel    0
25 #define osal_gfp_atomic    1
26 extern void *osal_vmalloc(unsigned long size);
27 extern void osal_vfree(const void *addr);
28 extern void *osal_kmalloc(unsigned long size, unsigned int osal_gfp_flag);
29 extern void osal_kfree(const void *addr);
30 
31 /* atomic api */
32 typedef struct {
33     void *atomic;
34 } osal_atomic_t;
35 
36 #define OSAL_ATOMIC_INIT(i)  { (i) }
37 
38 extern int osal_atomic_init(osal_atomic_t *atomic);
39 extern void osal_atomic_destroy(osal_atomic_t *atomic);
40 extern int osal_atomic_read(osal_atomic_t *v);
41 extern void osal_atomic_set(osal_atomic_t *v, int i);
42 extern int osal_atomic_inc_return(osal_atomic_t *v);
43 extern int osal_atomic_dec_return(osal_atomic_t *v);
44 
45 /* semaphore api */
46 #define EINTR              4
47 typedef struct osal_semaphore {
48     void *sem;
49 } osal_semaphore_t;
50 extern int osal_sema_init(osal_semaphore_t *sem, int val);
51 extern int osal_down(osal_semaphore_t *sem);
52 extern int osal_down_interruptible(osal_semaphore_t *sem);
53 extern int osal_down_trylock(osal_semaphore_t *sem);
54 extern void osal_up(osal_semaphore_t *sem);
55 /* notice:must be called when kmod exit, other wise will lead to memory leak; */
56 extern void osal_sema_destroy(osal_semaphore_t *sem);
57 
58 /* mutex api */
59 typedef struct osal_mutex {
60     void *mutex;
61 } osal_mutex_t;
62 extern int osal_mutex_init(osal_mutex_t *mutex);
63 extern int osal_mutex_lock(osal_mutex_t *mutex);
64 extern int osal_mutex_lock_interruptible(osal_mutex_t *mutex);
65 extern int osal_mutex_trylock(osal_mutex_t *mutex);
66 extern void osal_mutex_unlock(osal_mutex_t *mutex);
67 /* notice:must be called when kmod exit, other wise will lead to memory leak; */
68 extern void osal_mutex_destroy(osal_mutex_t *mutex);
69 
70 /* spin lock api */
71 typedef struct osal_spinlock {
72     void *lock;
73 } osal_spinlock_t;
74 extern int osal_spin_lock_init(osal_spinlock_t *lock);
75 extern void osal_spin_lock(osal_spinlock_t *lock);
76 extern int osal_spin_trylock(osal_spinlock_t *lock);
77 extern void osal_spin_unlock(osal_spinlock_t *lock);
78 extern void osal_spin_lock_irqsave(osal_spinlock_t *lock, unsigned long *flags);
79 extern void osal_spin_unlock_irqrestore(osal_spinlock_t *lock, const unsigned long *flags);
80 /* notice:must be called when kmod exit, other wise will lead to memory leak; */
81 extern void osal_spin_lock_destroy(osal_spinlock_t *lock);
82 
83 /* wait api */
84 typedef int (*osal_wait_cond_func_t)(const void *param);
85 
86 typedef struct osal_wait {
87     void *wait;
88 } osal_wait_t;
89 #define ERESTARTSYS        512
90 
91 
92 extern unsigned long osal_msecs_to_jiffies(const unsigned int m);
93 extern int osal_wait_init(osal_wait_t *wait);
94 extern int osal_wait_interruptible(osal_wait_t *wait, osal_wait_cond_func_t func, const void *param);
95 extern int osal_wait_uninterruptible(osal_wait_t *wait, osal_wait_cond_func_t func, const void *param);
96 extern int osal_wait_timeout_interruptible(osal_wait_t *wait, osal_wait_cond_func_t func, const void *param,
97                                            unsigned long ms);
98 extern int osal_wait_timeout_uninterruptible(osal_wait_t *wait, osal_wait_cond_func_t func, const void *param,
99                                              unsigned long ms);
100 
101 #define osal_wait_event_interruptible(wait, func, param)                       \
102     ({                                                                         \
103         int __ret = 0;                                                         \
104                                                                                \
105         for (;;) {                                                             \
106             if (func(param) != 0) {                                            \
107                 __ret = 0;                                                     \
108                 break;                                                         \
109             }                                                                  \
110             __ret = osal_wait_timeout_interruptible(wait, (func), param, 100); \
111             if (__ret < 0) {                                                   \
112                 break;                                                         \
113             }                                                                  \
114         }                                                                      \
115         __ret;                                                                 \
116     })
117 
118 #define osal_wait_event_uninterruptible(wait, func, param)          \
119     ({                                                              \
120         int __ret = 0;                                              \
121                                                                     \
122         for (;;) {                                                  \
123             if (func(param) != 0) {                                      \
124                 __ret = 0;                                          \
125                 break;                                              \
126             }                                                       \
127             __ret = osal_wait_uninterruptible(wait, (func), param); \
128             if (__ret < 0) {                                        \
129                 break;                                              \
130             }                                                       \
131         }                                                           \
132         __ret;                                                      \
133     })
134 
135 #define osal_wait_event_timeout_interruptible(wait, func, param, timeout)        \
136     ({                                                                           \
137         int __ret = timeout;                                                     \
138                                                                                  \
139         if ((func(param) != 0) && ((timeout) == 0)) {                            \
140             __ret = 1;                                                           \
141         }                                                                        \
142                                                                                  \
143         for (;;) {                                                               \
144             if (func(param) != 0) {                                              \
145                 __ret = osal_msecs_to_jiffies(__ret);                            \
146                 break;                                                           \
147             }                                                                    \
148             __ret = osal_wait_timeout_interruptible(wait, (func), param, __ret); \
149             if ((__ret == 0) || (__ret == -ERESTARTSYS)) {                       \
150                 break;                                                           \
151             }                                                                    \
152         }                                                                        \
153         __ret;                                                                   \
154     })
155 
156 #define osal_wait_event_timeout_uninterruptible(wait, func, param, timeout)        \
157     ({                                                                             \
158         int __ret = timeout;                                                       \
159                                                                                    \
160         if ((func(param) != 0) && ((timeout) == 0)) {                              \
161             __ret = 1;                                                             \
162         }                                                                          \
163                                                                                    \
164         for (;;) {                                                                 \
165             if (func(param) != 0) {                                                \
166                 __ret = osal_msecs_to_jiffies(__ret);                              \
167                 break;                                                             \
168             }                                                                      \
169             __ret = osal_wait_timeout_uninterruptible(wait, (func), param, __ret); \
170             if ((__ret == 0) || (__ret == -ERESTARTSYS)) {                         \
171                 break;                                                             \
172             }                                                                      \
173         }                                                                          \
174         __ret;                                                                     \
175     })
176 
177 extern void osal_wakeup(osal_wait_t *wait);  /* same as wake_up_all */
178 extern void osal_wait_destroy(osal_wait_t *wait);
179 
180 /* workqueue api */
181 typedef struct osal_work_struct {
182     int  queue_flag;
183     void *work;
184     void (*func)(struct osal_work_struct *work);
185 } osal_work_struct_t;
186 typedef void (*osal_work_func_t)(struct osal_work_struct *work);
187 
188 extern int osal_init_work(struct osal_work_struct *work, osal_work_func_t func);
189 
190 #define OSAL_INIT_WORK(_work, _func)      \
191     do {                                  \
192         osal_init_work((_work), (_func)); \
193     } while (0)
194 
195 extern int osal_schedule_work(struct osal_work_struct *work);
196 extern void osal_destroy_work(struct osal_work_struct *work);
197 
198 /* schedule */
199 extern void osal_yield(void);
200 
201 /* interrupt api */
202 enum osal_irqreturn {
203     OSAL_IRQ_NONE = (0 << 0),
204     OSAL_IRQ_HANDLED = (1 << 0),
205     OSAL_IRQ_WAKE_THREAD = (1 << 1),
206 };
207 
208 typedef int (*osal_irq_handler_t)(int, void *);
209 extern int osal_request_irq(unsigned int irq, osal_irq_handler_t handler, osal_irq_handler_t thread_fn,
210                             const char *name, void *dev);
211 extern void osal_free_irq(unsigned int irq, void *dev);
212 extern int osal_in_interrupt(void);
213 
214 #define OSAL_DIS_IRQ_CNT   2
215 typedef void (*osal_gic_handle_t)(unsigned int, unsigned int, void *);
216 extern int osal_register_gic_handle(unsigned int index, unsigned int irq, osal_gic_handle_t handle, const char *name,
217                                     void *dev);
218 extern int osal_unregister_gic_handle(unsigned int index, unsigned int irq, void *dev);
219 
220 /* task api */
221 typedef struct osal_task {
222     void *task_struct;
223 } osal_task_t;
224 typedef int (*threadfn_t)(void *data);
225 extern osal_task_t *osal_kthread_create(threadfn_t thread, void *data, const char *name);
226 extern void osal_kthread_destroy(osal_task_t *task, unsigned int stop_flag);
227 
228 /* string api */
229 extern int osal_strcmp(const char *s1, const char *s2);
230 extern int osal_strncmp(const char *s1, const char *s2, int size);
231 extern int osal_strnicmp(const char *s1, const char *s2, int size);
232 extern int osal_strcasecmp(const char *s1, const char *s2);
233 extern int osal_strncasecmp(const char *s1, const char *s2, int n);
234 extern char *osal_strchr(const char *s, int n);
235 extern char *osal_strnchr(const char *s, int count, int c);
236 extern char *osal_strrchr(const char *s, int c);
237 extern char *osal_strstr(const char *s1, const char *s2);
238 extern char *osal_strnstr(const char *s1, const char *s2, int n);
239 extern int osal_strlen(const char *s);
240 extern int osal_strnlen(const char *s, int size);
241 extern char *osal_strpbrk(const char *s1, const char *s2);
242 extern char *osal_strsep(char **s, const char *ct);
243 extern int osal_strspn(const char *s, const char *accept);
244 extern int osal_strcspn(const char *s, const char *reject);
245 extern void *osal_memscan(void *addr, int c, int size);
246 extern int osal_memcmp(const void *cs, const void *ct, int count);
247 extern void *osal_memchr(const void *s, int c, int n);
248 extern void *osal_memchr_inv(const void *s, int c, int n);
249 
250 extern unsigned long long osal_strtoull(const char *cp, char **endp, unsigned int base);
251 extern unsigned long osal_strtoul(const char *cp, char **endp, unsigned int base);
252 extern long osal_strtol(const char *cp, char **endp, unsigned int base);
253 extern long long osal_strtoll(const char *cp, char **endp, unsigned int base);
254 
255 /* addr translate */
256 extern void *osal_ioremap(unsigned long phys_addr, unsigned long size);
257 extern void *osal_ioremap_nocache(unsigned long phys_addr, unsigned long size);
258 extern void *osal_ioremap_cached(unsigned long phys_addr, unsigned long size);
259 extern void *osal_ioremap_wc(unsigned long phys_addr, unsigned long size);
260 extern void osal_iounmap(void *addr, unsigned long size);
261 
262 #define osal_readl(x) (*((volatile int *)(x)))
263 #define osal_writel(v, x) (*((volatile int *)(x)) = (v))
264 
265 extern unsigned long osal_copy_from_user(void *to, const void *from, unsigned long n);
266 extern unsigned long osal_copy_to_user(void *to, const void *from, unsigned long n);
267 
268 #define OSAL_VERIFY_READ   0
269 #define OSAL_VERIFY_WRITE  1
270 extern int osal_access_ok(int type, const void *addr, unsigned long size);
271 
272 /* cache api */
273 extern void osal_flush_dcache_area(void *kvirt, unsigned long phys_addr, unsigned long length);
274 
275 /* math */
276 extern unsigned long long osal_div_u64(unsigned long long dividend, unsigned int divisor);
277 extern long long osal_div_s64(long long dividend, int divisor);
278 extern unsigned long long osal_div64_u64(unsigned long long dividend, unsigned long long divisor);
279 extern long long osal_div64_s64(long long dividend, long long divisor);
280 extern unsigned long long osal_div_u64_rem(unsigned long long dividend, unsigned int divisor);
281 extern long long osal_div_s64_rem(long long dividend, int divisor);
282 extern unsigned long long osal_div64_u64_rem(unsigned long long dividend, unsigned long long divisor);
283 extern unsigned int osal_random(void);
284 
285 #define osal_max(x, y) ({                            \
286         __typeof__(x) _max1 = (x);                  \
287         __typeof__(y) _max2 = (y);                  \
288         (void) (&_max1 == &_max2);              \
289         _max1 > _max2 ? _max1 : _max2; })
290 
291 #define osal_min(x, y) ({            \
292     __typeof__(x) _min1 = (x);       \
293     __typeof__(y) _min2 = (y);       \
294     (void) (&_min1 == &_min2);       \
295     _min1 < _min2 ? _min1 : _min2; })
296 
297 #define osal_abs(x) ({                \
298     long ret;                         \
299     if (sizeof(x) == sizeof(long)) {  \
300         long __x = (x);               \
301         ret = (__x < 0) ? -__x : __x; \
302     } else {                          \
303         int __x = (x);                \
304         ret = (__x < 0) ? -__x : __x; \
305     }                                 \
306     ret;                              \
307 })
308 
309 /* barrier */
310 extern void osal_mb(void);
311 extern void osal_rmb(void);
312 extern void osal_wmb(void);
313 extern void osal_smp_mb(void);
314 extern void osal_smp_rmb(void);
315 extern void osal_smp_wmb(void);
316 extern void osal_isb(void);
317 extern void osal_dsb(void);
318 extern void osal_dmb(void);
319 
320 /* debug */
321 extern int osal_printk(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
322 extern void osal_panic(const char *fmt, const char *fun, int line, const char *);
323 #define OSAL_BUG() \
324     do {           \
325     } while (1)
326 
327 #define OSAL_ASSERT(expr)                       \
328     do {                                        \
329         if (!(expr)) {                          \
330             osal_printk("\nASSERT failed at:\n" \
331                         "  >Condition: %s\n",   \
332                 #expr);                         \
333             OSAL_BUG();                         \
334         }                                       \
335     } while (0)
336 
337 #define OSAL_BUG_ON(expr)                                                               \
338     do {                                                                                \
339         if (expr) {                                                                     \
340             osal_printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
341             OSAL_BUG();                                                                 \
342         }                                                                               \
343     } while (0)
344 
345 #ifdef CONFIG_HI_LOG_TRACE_SUPPORT
346 #define osal_trace osal_printk
347 #else
348 #define osal_trace(str, fmt...)
349 #endif
350 
351 /* proc */
352 #define OSAL_MAX_PROC_NAME_LEN  50
353 typedef struct osal_proc_dir_entry {
354     char name[OSAL_MAX_PROC_NAME_LEN];
355     void *proc_dir_entry;
356     int (*open)(struct osal_proc_dir_entry *entry);
357     int (*read)(struct osal_proc_dir_entry *entry);
358     int (*write)(struct osal_proc_dir_entry *entry, const char *buf, int count, long long *);
359     void *private;
360     void *seqfile;
361     struct osal_list_head node;
362 } osal_proc_entry_t;
363 extern osal_proc_entry_t *osal_create_proc_entry(const char *name, osal_proc_entry_t *parent);
364 extern osal_proc_entry_t *osal_proc_mkdir(const char *name, osal_proc_entry_t *parent);
365 extern void osal_remove_proc_entry(const char *name, osal_proc_entry_t *parent);
366 extern void osal_seq_printf(osal_proc_entry_t *entry, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
367 
368 /* device api */
369 #ifndef _IOC_TYPECHECK
370 #include "osal_ioctl.h"
371 #endif
372 #define OSAL_MAX_DEV_NAME_LEN   48
373 
374 typedef struct osal_dev {
375     struct osal_list_head list;
376     char name[OSAL_MAX_DEV_NAME_LEN];
377     void *dev;
378     unsigned int minor;
379     unsigned int count;
380     struct osal_fileops *fops;
381     struct osal_pmops *osal_pmops;
382 } osal_dev_t;
383 
384 typedef struct osal_vm {
385     void *vm;
386 } osal_vm_t;
387 
388 #define OSAL_POLLIN        0x0001U
389 #define OSAL_POLLPRI       0x0002U
390 #define OSAL_POLLOUT       0x0004U
391 #define OSAL_POLLERR       0x0008U
392 #define OSAL_POLLHUP       0x0010U
393 #define OSAL_POLLNVAL      0x0020U
394 #define OSAL_POLLRDNORM    0x0040U
395 #define OSAL_POLLRDBAND    0x0080U
396 #define OSAL_POLLWRNORM    0x0100U
397 
398 typedef struct osal_poll {
399     void *poll_table;
400     void *data;
401 } osal_poll_t;
402 
403 typedef struct osal_fileops {
404     int (*open)(void *private_data);
405     int (*read)(char *buf, int size, long *offset, void *private_data);
406     int (*write)(const char *buf, int size, long *offset, void *private_data);
407     long (*llseek)(long offset, int whence, void *private_data);
408     int (*release)(void *private_data);
409     long (*unlocked_ioctl)(unsigned int cmd, unsigned long arg, void *private_data);
410     unsigned int (*poll)(osal_poll_t *osal_poll, void *private_data);
411     int (*mmap)(osal_vm_t *vm, unsigned long start, unsigned long end, unsigned long vm_pgoff, void *private_data);
412 #ifdef CONFIG_COMPAT
413     long (*compat_ioctl)(unsigned int cmd, unsigned long arg, void *private_data);
414 #endif
415 } osal_fileops_t;
416 
417 typedef struct osal_pmops {
418     int (*pm_prepare)(osal_dev_t *dev);
419     void (*pm_complete)(osal_dev_t *dev);
420     int (*pm_suspend)(osal_dev_t *dev);
421     int (*pm_resume)(osal_dev_t *dev);
422     int (*pm_freeze)(osal_dev_t *dev);
423     int (*pm_thaw)(osal_dev_t *dev);
424     int (*pm_poweroff)(osal_dev_t *dev);
425     int (*pm_restore)(osal_dev_t *dev);
426     int (*pm_suspend_late)(osal_dev_t *dev);
427     int (*pm_resume_early)(osal_dev_t *dev);
428     int (*pm_freeze_late)(osal_dev_t *dev);
429     int (*pm_thaw_early)(osal_dev_t *dev);
430     int (*pm_poweroff_late)(osal_dev_t *dev);
431     int (*pm_restore_early)(osal_dev_t *dev);
432     int (*pm_suspend_noirq)(osal_dev_t *dev);
433     int (*pm_resume_noirq)(osal_dev_t *dev);
434     int (*pm_freeze_noirq)(osal_dev_t *dev);
435     int (*pm_thaw_noirq)(osal_dev_t *dev);
436     int (*pm_poweroff_noirq)(osal_dev_t *dev);
437     int (*pm_restore_noirq)(osal_dev_t *dev);
438 } osal_pmops_t;
439 
440 #define OSAL_SEEK_SET      0
441 #define OSAL_SEEK_CUR      1
442 #define OSAL_SEEK_END      2
443 
444 extern osal_dev_t *osal_createdev(const char *name);
445 extern int osal_destroydev(osal_dev_t *pdev);
446 extern int osal_registerdevice(osal_dev_t *pdev);
447 extern void osal_deregisterdevice(osal_dev_t *pdev);
448 extern void osal_poll_wait(osal_poll_t *table, osal_wait_t *wait);
449 extern void osal_pgprot_noncached(osal_vm_t *vm);
450 extern void osal_pgprot_cached(osal_vm_t *vm);
451 extern void osal_pgprot_writecombine(osal_vm_t *vm);
452 extern int osal_remap_pfn_range(osal_vm_t *vm, unsigned long addr, unsigned long pfn, unsigned long size);
453 
454 /* timer */
455 typedef struct osal_timer {
456     void *timer;
457     void (*function)(unsigned long);
458     unsigned long data;
459 } osal_timer_t;
460 
461 typedef struct osal_timeval {
462     long tv_sec;
463     long tv_usec;
464 } osal_timeval_t;
465 
466 typedef struct osal_rtc_time {
467     int tm_sec;
468     int tm_min;
469     int tm_hour;
470     int tm_mday;
471     int tm_mon;
472     int tm_year;
473     int tm_wday;
474     int tm_yday;
475     int tm_isdst;
476 } osal_rtc_time_t;
477 
478 /* Return values for the timer callback function */
479 typedef enum hiOSAL_HRTIMER_RESTART_E {
480     OSAL_HRTIMER_NORESTART, /* < The timer will not be restarted. */
481     OSAL_HRTIMER_RESTART /* < The timer must be restarted. */
482 } OSAL_HRTIMER_RESTART_E;
483 
484 /* hrtimer struct */
485 typedef struct osal_hrtimer {
486     void *timer;
487     OSAL_HRTIMER_RESTART_E (*function)(void *timer);
488     unsigned long interval; /* Unit ms */
489 } osal_hrtimer_t;
490 
491 extern int osal_hrtimer_create(osal_hrtimer_t *phrtimer);
492 extern int osal_hrtimer_start(osal_hrtimer_t *phrtimer);
493 extern int osal_hrtimer_destroy(osal_hrtimer_t *phrtimer);
494 
495 extern int osal_timer_init(osal_timer_t *timer);
496 extern int osal_set_timer(osal_timer_t *timer, unsigned long interval);  /* ms */
497 extern unsigned long osal_timer_get_private_data(void *data);
498 extern int osal_del_timer(osal_timer_t *timer);
499 extern int osal_timer_destroy(osal_timer_t *timer);
500 
501 extern unsigned long osal_msleep(unsigned int msecs);
502 extern void osal_udelay(unsigned int usecs);
503 extern void osal_mdelay(unsigned int msecs);
504 
505 extern unsigned int osal_get_tickcount(void);
506 extern unsigned long long osal_sched_clock(void);
507 extern void osal_gettimeofday(osal_timeval_t *tv);
508 extern void osal_rtc_time_to_tm(unsigned long time, osal_rtc_time_t *tm);
509 extern void osal_rtc_tm_to_time(osal_rtc_time_t *tm, unsigned long *time);
510 extern int osal_rtc_valid_tm(struct osal_rtc_time *tm);
511 extern void osal_getjiffies(unsigned long long *pjiffies);
512 
513 #define OSAL_O_ACCMODE     00000003
514 #define OSAL_O_RDONLY      00000000
515 #define OSAL_O_WRONLY      00000001
516 #define OSAL_O_RDWR        00000002
517 #define OSAL_O_CREAT       00000100
518 
519 extern void *osal_klib_fopen(const char *filename, int flags, int mode);
520 extern void osal_klib_fclose(void *filp);
521 extern int osal_klib_fwrite(const char *buf, int len, void *filp);
522 extern int osal_klib_fread(char *buf, unsigned int len, void *filp);
523 
524 /* reboot */
525 struct osal_notifier_block {
526     int (*notifier_call)(struct osal_notifier_block *nb, unsigned long action, void *data);
527     void *notifier_block;
528 };
529 typedef int (*osal_notifier_fn_t)(struct osal_notifier_block *nb, unsigned long action, void *data);
530 
531 extern int osal_register_reboot_notifier(struct osal_notifier_block *nb);
532 extern int osal_unregister_reboot_notifier(struct osal_notifier_block *nb);
533 
534 #include <stdarg.h>
535 
536 #ifndef _OSAL_VA_LIST
537 
538 #define _OSAL_VA_LIST
539 #define osal_va_list       va_list
540 #define osal_va_arg(ap, T) va_arg(ap, T)
541 #define osal_va_end(ap) va_end(ap)
542 #define osal_va_start(ap, A) va_start(ap, A)
543 
544 #endif /* va_arg */
545 
546 #define NULL_STRING        "NULL"
547 
548 extern void osal_vprintk(const char *fmt, osal_va_list args);
549 
550 #define osal_platform_get_module_param(pdev, name, type, value) \
551     osal_platform_get_modparam_##type(pdev, name, value)
552 
553 int osal_platform_get_modparam_uint(void *pdev, const char *name, unsigned int *value);
554 int osal_platform_get_modparam_int(void *pdev, const char *name, int *value);
555 int osal_platform_get_modparam_string(void *pdev, const char *name, unsigned int size, char *value);
556 int osal_platform_get_modparam_uchar(void *pdev, const char *name, unsigned char *value);
557 int osal_platform_get_modparam_ushort(void *pdev, const char *name, unsigned short *value);
558 /* of function */
559 int osal_of_property_read_u32(const void *np, const char *propname, unsigned int *value);
560 
561 int osal_platform_driver_register(void *drv);
562 void osal_platform_driver_unregister(void *drv);
563 void *osal_platform_get_resource_byname(void *dev, unsigned int type,
564                                         const char *name);
565 void *osal_platform_get_resource(void *dev, unsigned int type,
566                                  unsigned int num);
567 int osal_platform_get_irq(void *dev, unsigned int num);
568 int osal_platform_get_irq_byname(void *dev, const char *name);
569 
570 #define osal_module_driver(osal_driver, osal_register, osal_unregister, ...) \
571     static int __init osal_driver##_init(void)                               \
572     {                                                                        \
573         return osal_register(&(osal_driver));                                \
574     }                                                                        \
575     module_init(osal_driver##_init);                                         \
576     static void __exit osal_driver##_exit(void)                              \
577     {                                                                        \
578         osal_unregister(&(osal_driver));                                     \
579     }                                                                        \
580     module_exit(osal_driver##_exit);
581 
582 #define osal_module_platform_driver(platform_driver)                   \
583     osal_module_driver(platform_driver, osal_platform_driver_register, \
584         osal_platform_driver_unregister)
585 
586 /* mmz apis */
587 extern unsigned long long  cmpi_mmz_malloc(const char *mmz_name, const char *buf_name, unsigned long ul_size);
588 extern void cmpi_mmz_free(unsigned long long phy_addr, void *vir_addr);
589 extern int cmpi_mmz_malloc_nocache(const char *cp_mmz_name, const char *buf_name,
590                                    unsigned long long *phy_addr, void **pp_vir_addr, unsigned long ul_len);
591 extern int  cmpi_mmz_malloc_cached(const char *cp_mmz_name, const char *buf_name,
592                                    unsigned long long *phy_addr, void **pp_vir_addr, unsigned long ul_len);
593 extern int cmpi_check_mmz_phy_addr(unsigned long long phy_addr, unsigned int len);
594 
595 void *cmpi_remap_cached(unsigned long long phy_addr, unsigned long ul_size);
596 void *cmpi_remap_nocache(unsigned long long phy_addr, unsigned long ul_size);
597 void cmpi_unmap(void *virt_addr);
598 
599 #ifdef CONFIG_USER_SPACE
600 extern int cmpi_get_fd(void);
601 extern void cmpi_set_fd(int fd);
602 #endif
603 
604 #ifndef IORESOURCE_MEM
605 #define IORESOURCE_MEM  0x00000200
606 #endif
607 
608 #endif
609