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 void *work; 183 void (*func)(struct osal_work_struct *work); 184 } osal_work_struct_t; 185 typedef void (*osal_work_func_t)(struct osal_work_struct *work); 186 187 extern int osal_init_work(struct osal_work_struct *work, osal_work_func_t func); 188 189 #define OSAL_INIT_WORK(_work, _func) \ 190 do { \ 191 osal_init_work((_work), (_func)); \ 192 } while (0) 193 194 extern int osal_schedule_work(struct osal_work_struct *work); 195 extern void osal_destroy_work(struct osal_work_struct *work); 196 197 /* schedule */ 198 extern void osal_yield(void); 199 200 /* interrupt api */ 201 enum osal_irqreturn { 202 OSAL_IRQ_NONE = (0 << 0), 203 OSAL_IRQ_HANDLED = (1 << 0), 204 OSAL_IRQ_WAKE_THREAD = (1 << 1), 205 }; 206 207 typedef int (*osal_irq_handler_t)(int, void *); 208 extern int osal_request_irq(unsigned int irq, osal_irq_handler_t handler, osal_irq_handler_t thread_fn, 209 const char *name, void *dev); 210 extern void osal_free_irq(unsigned int irq, void *dev); 211 extern int osal_in_interrupt(void); 212 213 #define OSAL_DIS_IRQ_CNT 2 214 typedef void (*osal_gic_handle_t)(unsigned int, unsigned int, void *); 215 extern int osal_register_gic_handle(unsigned int index, unsigned int irq, osal_gic_handle_t handle, const char *name, 216 void *dev); 217 extern int osal_unregister_gic_handle(unsigned int index, unsigned int irq, void *dev); 218 219 /* task api */ 220 typedef struct osal_task { 221 void *task_struct; 222 } osal_task_t; 223 typedef int (*threadfn_t)(void *data); 224 extern osal_task_t *osal_kthread_create(threadfn_t thread, void *data, const char *name); 225 extern void osal_kthread_destroy(osal_task_t *task, unsigned int stop_flag); 226 227 /* string api */ 228 extern int osal_strcmp(const char *s1, const char *s2); 229 extern int osal_strncmp(const char *s1, const char *s2, int size); 230 extern int osal_strnicmp(const char *s1, const char *s2, int size); 231 extern int osal_strcasecmp(const char *s1, const char *s2); 232 extern int osal_strncasecmp(const char *s1, const char *s2, int n); 233 extern char *osal_strchr(const char *s, int n); 234 extern char *osal_strnchr(const char *s, int count, int c); 235 extern char *osal_strrchr(const char *s, int c); 236 extern char *osal_strstr(const char *s1, const char *s2); 237 extern char *osal_strnstr(const char *s1, const char *s2, int n); 238 extern int osal_strlen(const char *s); 239 extern int osal_strnlen(const char *s, int size); 240 extern char *osal_strpbrk(const char *s1, const char *s2); 241 extern char *osal_strsep(char **s, const char *ct); 242 extern int osal_strspn(const char *s, const char *accept); 243 extern int osal_strcspn(const char *s, const char *reject); 244 extern void *osal_memset(void *str, int c, int count); 245 extern void *osal_memcpy(void *s1, const void *s2, int count); 246 extern void *osal_memscan(void *addr, int c, int size); 247 extern int osal_memcmp(const void *cs, const void *ct, int count); 248 extern void *osal_memchr(const void *s, int c, int n); 249 extern void *osal_memchr_inv(const void *s, int c, int n); 250 251 extern unsigned long long osal_strtoull(const char *cp, char **endp, unsigned int base); 252 extern unsigned long osal_strtoul(const char *cp, char **endp, unsigned int base); 253 extern long osal_strtol(const char *cp, char **endp, unsigned int base); 254 extern long long osal_strtoll(const char *cp, char **endp, unsigned int base); 255 extern int osal_snprintf(char *buf, int size, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 256 extern int osal_sprintf(char *buf, const char *fmt, ...) __attribute__((format(printf, 2, 3))); 257 258 /* addr translate */ 259 extern void *osal_ioremap(unsigned long phys_addr, unsigned long size); 260 extern void *osal_ioremap_nocache(unsigned long phys_addr, unsigned long size); 261 extern void *osal_ioremap_cached(unsigned long phys_addr, unsigned long size); 262 extern void *osal_ioremap_wc(unsigned long phys_addr, unsigned long size); 263 extern void osal_iounmap(void *addr); 264 265 #define osal_readl(x) (*((volatile int *)(x))) 266 #define osal_writel(v, x) (*((volatile int *)(x)) = (v)) 267 268 extern unsigned long osal_copy_from_user(void *to, const void *from, unsigned long n); 269 extern unsigned long osal_copy_to_user(void *to, const void *from, unsigned long n); 270 271 #define OSAL_VERIFY_READ 0 272 #define OSAL_VERIFY_WRITE 1 273 extern int osal_access_ok(int type, const void *addr, unsigned long size); 274 275 /* cache api */ 276 extern void osal_cpuc_flush_dcache_area(void *addr, int size); 277 extern void osal_flush_dcache_area(void *kvirt, unsigned long phys_addr, unsigned long length); 278 279 /* math */ 280 extern unsigned long long osal_div_u64(unsigned long long dividend, unsigned int divisor); 281 extern long long osal_div_s64(long long dividend, int divisor); 282 extern unsigned long long osal_div64_u64(unsigned long long dividend, unsigned long long divisor); 283 extern long long osal_div64_s64(long long dividend, long long divisor); 284 extern unsigned long long osal_div_u64_rem(unsigned long long dividend, unsigned int divisor); 285 extern long long osal_div_s64_rem(long long dividend, int divisor); 286 extern unsigned long long osal_div64_u64_rem(unsigned long long dividend, unsigned long long divisor); 287 extern unsigned int osal_random(void); 288 289 #define osal_max(x, y) ({ \ 290 __typeof__(x) _max1 = (x); \ 291 __typeof__(y) _max2 = (y); \ 292 (void) (&_max1 == &_max2); \ 293 _max1 > _max2 ? _max1 : _max2; }) 294 295 #define osal_min(x, y) ({ \ 296 __typeof__(x) _min1 = (x); \ 297 __typeof__(y) _min2 = (y); \ 298 (void) (&_min1 == &_min2); \ 299 _min1 < _min2 ? _min1 : _min2; }) 300 301 #define osal_abs(x) ({ \ 302 long ret; \ 303 if (sizeof(x) == sizeof(long)) { \ 304 long __x = (x); \ 305 ret = (__x < 0) ? -__x : __x; \ 306 } else { \ 307 int __x = (x); \ 308 ret = (__x < 0) ? -__x : __x; \ 309 } \ 310 ret; \ 311 }) 312 313 /* barrier */ 314 extern void osal_mb(void); 315 extern void osal_rmb(void); 316 extern void osal_wmb(void); 317 extern void osal_smp_mb(void); 318 extern void osal_smp_rmb(void); 319 extern void osal_smp_wmb(void); 320 extern void osal_isb(void); 321 extern void osal_dsb(void); 322 extern void osal_dmb(void); 323 324 /* debug */ 325 extern int osal_printk(const char *fmt, ...) __attribute__((format(printf, 1, 2))); 326 extern void osal_panic(const char *fmt, const char *fun, int line, const char *); 327 #define OSAL_BUG() \ 328 do { \ 329 } while (1) 330 331 #define OSAL_ASSERT(expr) \ 332 do { \ 333 if (!(expr)) { \ 334 osal_printk("\nASSERT failed at:\n" \ 335 " >Condition: %s\n", \ 336 #expr); \ 337 OSAL_BUG(); \ 338 } \ 339 } while (0) 340 341 #define OSAL_BUG_ON(expr) \ 342 do { \ 343 if (expr) { \ 344 osal_printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \ 345 OSAL_BUG(); \ 346 } \ 347 } while (0) 348 349 #ifdef CONFIG_HI_LOG_TRACE_SUPPORT 350 #define osal_trace osal_printk 351 #else 352 #define osal_trace(str, fmt...) 353 #endif 354 355 /* proc */ 356 #define OSAL_MAX_PROC_NAME_LEN 50 357 typedef struct osal_proc_dir_entry { 358 char name[OSAL_MAX_PROC_NAME_LEN]; 359 void *proc_dir_entry; 360 int (*open)(struct osal_proc_dir_entry *entry); 361 int (*read)(struct osal_proc_dir_entry *entry); 362 int (*write)(struct osal_proc_dir_entry *entry, const char *buf, int count, long long *); 363 void *private; 364 void *seqfile; 365 struct osal_list_head node; 366 } osal_proc_entry_t; 367 extern osal_proc_entry_t *osal_create_proc_entry(const char *name, osal_proc_entry_t *parent); 368 extern osal_proc_entry_t *osal_proc_mkdir(const char *name, osal_proc_entry_t *parent); 369 extern void osal_remove_proc_entry(const char *name, osal_proc_entry_t *parent); 370 extern int osal_seq_printf(osal_proc_entry_t *entry, const char *fmt, ...) __attribute__((format(printf, 2, 3))); 371 372 /* device api */ 373 #ifndef _IOC_TYPECHECK 374 #include <sys/ioctl.h> 375 #include "osal_ioctl.h" 376 #endif 377 #define OSAL_MAX_DEV_NAME_LEN 48 378 379 typedef struct osal_dev { 380 char name[OSAL_MAX_DEV_NAME_LEN]; 381 void *dev; 382 int minor; 383 struct osal_fileops *fops; 384 struct osal_pmops *osal_pmops; 385 } osal_dev_t; 386 387 typedef struct osal_vm { 388 void *vm; 389 } osal_vm_t; 390 391 #define OSAL_POLLIN 0x0001U 392 #define OSAL_POLLPRI 0x0002U 393 #define OSAL_POLLOUT 0x0004U 394 #define OSAL_POLLERR 0x0008U 395 #define OSAL_POLLHUP 0x0010U 396 #define OSAL_POLLNVAL 0x0020U 397 #define OSAL_POLLRDNORM 0x0040U 398 #define OSAL_POLLRDBAND 0x0080U 399 #define OSAL_POLLWRNORM 0x0100U 400 401 typedef struct osal_poll { 402 void *poll_table; 403 void *data; 404 } osal_poll_t; 405 406 typedef struct osal_fileops { 407 int (*open)(void *private_data); 408 int (*read)(char *buf, int size, long *offset, void *private_data); 409 int (*write)(const char *buf, int size, long *offset, void *private_data); 410 long (*llseek)(long offset, int whence, void *private_data); 411 int (*release)(void *private_data); 412 long (*unlocked_ioctl)(unsigned int cmd, unsigned long arg, void *private_data); 413 unsigned int (*poll)(osal_poll_t *osal_poll, void *private_data); 414 int (*mmap)(osal_vm_t *vm, unsigned long start, unsigned long end, unsigned long vm_pgoff, void *private_data); 415 #ifdef CONFIG_COMPAT 416 long (*compat_ioctl)(unsigned int cmd, unsigned long arg, void *private_data); 417 #endif 418 } osal_fileops_t; 419 420 typedef struct osal_pmops { 421 int (*pm_prepare)(osal_dev_t *dev); 422 void (*pm_complete)(osal_dev_t *dev); 423 int (*pm_suspend)(osal_dev_t *dev); 424 int (*pm_resume)(osal_dev_t *dev); 425 int (*pm_freeze)(osal_dev_t *dev); 426 int (*pm_thaw)(osal_dev_t *dev); 427 int (*pm_poweroff)(osal_dev_t *dev); 428 int (*pm_restore)(osal_dev_t *dev); 429 int (*pm_suspend_late)(osal_dev_t *dev); 430 int (*pm_resume_early)(osal_dev_t *dev); 431 int (*pm_freeze_late)(osal_dev_t *dev); 432 int (*pm_thaw_early)(osal_dev_t *dev); 433 int (*pm_poweroff_late)(osal_dev_t *dev); 434 int (*pm_restore_early)(osal_dev_t *dev); 435 int (*pm_suspend_noirq)(osal_dev_t *dev); 436 int (*pm_resume_noirq)(osal_dev_t *dev); 437 int (*pm_freeze_noirq)(osal_dev_t *dev); 438 int (*pm_thaw_noirq)(osal_dev_t *dev); 439 int (*pm_poweroff_noirq)(osal_dev_t *dev); 440 int (*pm_restore_noirq)(osal_dev_t *dev); 441 } osal_pmops_t; 442 443 #define OSAL_SEEK_SET 0 444 #define OSAL_SEEK_CUR 1 445 #define OSAL_SEEK_END 2 446 447 extern osal_dev_t *osal_createdev(const char *name); 448 extern int osal_destroydev(osal_dev_t *pdev); 449 extern int osal_registerdevice(osal_dev_t *pdev); 450 extern void osal_deregisterdevice(osal_dev_t *pdev); 451 extern void osal_poll_wait(osal_poll_t *table, osal_wait_t *wait); 452 extern void osal_pgprot_noncached(osal_vm_t *vm); 453 extern void osal_pgprot_cached(osal_vm_t *vm); 454 extern void osal_pgprot_writecombine(osal_vm_t *vm); 455 extern void osal_pgprot_stronglyordered(osal_vm_t *vm); 456 extern int osal_remap_pfn_range(osal_vm_t *vm, unsigned long addr, unsigned long pfn, unsigned long size); 457 extern int osal_io_remap_pfn_range(osal_vm_t *vm, unsigned long addr, unsigned long pfn, unsigned long size); 458 459 /* timer */ 460 typedef struct osal_timer { 461 void *timer; 462 void (*function)(unsigned long); 463 unsigned long data; 464 } osal_timer_t; 465 466 typedef struct osal_timeval { 467 long tv_sec; 468 long tv_usec; 469 } osal_timeval_t; 470 471 typedef struct osal_rtc_time { 472 int tm_sec; 473 int tm_min; 474 int tm_hour; 475 int tm_mday; 476 int tm_mon; 477 int tm_year; 478 int tm_wday; 479 int tm_yday; 480 int tm_isdst; 481 } osal_rtc_time_t; 482 483 /* Return values for the timer callback function */ 484 typedef enum hiOSAL_HRTIMER_RESTART_E { 485 OSAL_HRTIMER_NORESTART, /* < The timer will not be restarted. */ 486 OSAL_HRTIMER_RESTART /* < The timer must be restarted. */ 487 } OSAL_HRTIMER_RESTART_E; 488 489 /* hrtimer struct */ 490 typedef struct osal_hrtimer { 491 void *timer; 492 OSAL_HRTIMER_RESTART_E (*function)(void *timer); 493 unsigned long interval; /* Unit ms */ 494 } osal_hrtimer_t; 495 496 extern int osal_hrtimer_create(osal_hrtimer_t *phrtimer); 497 extern int osal_hrtimer_start(osal_hrtimer_t *phrtimer); 498 extern int osal_hrtimer_destroy(osal_hrtimer_t *phrtimer); 499 500 extern int osal_timer_init(osal_timer_t *timer); 501 extern int osal_set_timer(osal_timer_t *timer, unsigned long interval); /* ms */ 502 extern unsigned long osal_timer_get_private_data(void *data); 503 extern int osal_del_timer(osal_timer_t *timer); 504 extern int osal_timer_destroy(osal_timer_t *timer); 505 506 extern unsigned long osal_msleep(unsigned int msecs); 507 extern void osal_udelay(unsigned int usecs); 508 extern void osal_mdelay(unsigned int msecs); 509 510 extern unsigned int osal_get_tickcount(void); 511 extern unsigned long long osal_sched_clock(void); 512 extern void osal_gettimeofday(osal_timeval_t *tv); 513 extern void osal_rtc_time_to_tm(unsigned long time, osal_rtc_time_t *tm); 514 extern void osal_rtc_tm_to_time(osal_rtc_time_t *tm, unsigned long *time); 515 extern int osal_rtc_valid_tm(struct osal_rtc_time *tm); 516 extern void osal_getjiffies(unsigned long long *pjiffies); 517 518 #define OSAL_O_ACCMODE 00000003 519 #define OSAL_O_RDONLY 00000000 520 #define OSAL_O_WRONLY 00000001 521 #define OSAL_O_RDWR 00000002 522 #define OSAL_O_CREAT 00000100 523 524 extern void *osal_klib_fopen(const char *filename, int flags, int mode); 525 extern void osal_klib_fclose(void *filp); 526 extern int osal_klib_fwrite(const char *buf, int len, void *filp); 527 extern int osal_klib_fread(char *buf, unsigned int len, void *filp); 528 529 /* reboot */ 530 struct osal_notifier_block { 531 int (*notifier_call)(struct osal_notifier_block *nb, unsigned long action, void *data); 532 void *notifier_block; 533 }; 534 typedef int (*osal_notifier_fn_t)(struct osal_notifier_block *nb, unsigned long action, void *data); 535 536 extern int osal_register_reboot_notifier(struct osal_notifier_block *nb); 537 extern int osal_unregister_reboot_notifier(struct osal_notifier_block *nb); 538 539 #include <stdarg.h> 540 541 #ifndef _OSAL_VA_LIST 542 543 #define _OSAL_VA_LIST 544 #define osal_va_list va_list 545 #define osal_va_arg(ap, T) va_arg(ap, T) 546 #define osal_va_end(ap) va_end(ap) 547 #define osal_va_start(ap, A) va_start(ap, A) 548 549 #endif /* va_arg */ 550 551 #define NULL_STRING "NULL" 552 553 extern void osal_vprintk(const char *fmt, osal_va_list args); 554 extern int osal_vsnprintf(char *str, int size, const char *fmt, osal_va_list args); 555 556 #ifdef CONFIG_HISI_SNAPSHOT_BOOT 557 558 #ifndef OSAL_UMH_WAIT_PROC 559 #define OSAL_UMH_WAIT_PROC 2 /* wait for the process to complete */ 560 #endif 561 562 extern int osal_call_usermodehelper_force(char *path, char **argv, char **envp, int wait); 563 #endif 564 565 #define osal_platform_get_module_param(pdev, name, type, value) \ 566 osal_platform_get_modparam_##type(pdev, name, value) 567 568 int osal_platform_get_modparam_uint(void *pdev, const char *name, unsigned int *value); 569 int osal_platform_get_modparam_int(void *pdev, const char *name, int *value); 570 int osal_platform_get_modparam_charp(void *pdev, const char *name, char *value); 571 int osal_platform_get_modparam_string(void *pdev, const char *name, unsigned int size, char *value); 572 int osal_platform_get_modparam_uchar(void *pdev, const char *name, unsigned char *value); 573 int osal_platform_get_modparam_ushort(void *pdev, const char *name, unsigned short *value); 574 /* of function */ 575 int osal_of_property_read_u32(const void *np, const char *propname, unsigned int *value); 576 577 int osal_platform_driver_register(void *drv); 578 void osal_platform_driver_unregister(void *drv); 579 void *osal_platform_get_resource_byname(void *dev, unsigned int type, 580 const char *name); 581 void *osal_platform_get_resource(void *dev, unsigned int type, 582 unsigned int num); 583 int osal_platform_get_irq(void *dev, unsigned int num); 584 int osal_platform_get_irq_byname(void *dev, const char *name); 585 586 #define osal_module_driver(osal_driver, osal_register, osal_unregister, ...) \ 587 static int __init osal_driver##_init(void) \ 588 { \ 589 return osal_register(&(osal_driver)); \ 590 } \ 591 module_init(osal_driver##_init); \ 592 static void __exit osal_driver##_exit(void) \ 593 { \ 594 osal_unregister(&(osal_driver)); \ 595 } \ 596 module_exit(osal_driver##_exit); 597 598 #define osal_module_platform_driver(platform_driver) \ 599 osal_module_driver(platform_driver, osal_platform_driver_register, \ 600 osal_platform_driver_unregister) 601 602 #endif 603