kernel_os.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * MediaTek Inc. (C) 2016. All rights reserved.
  3. *
  4. * This software/firmware and related documentation ("MediaTek Software") are
  5. * protected under relevant copyright laws. The information contained herein
  6. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  7. * Without the prior written permission of MediaTek inc. and/or its licensors,
  8. * any reproduction, modification, use or disclosure of MediaTek Software,
  9. * and information contained herein, in whole or in part, shall be strictly
  10. * prohibited.
  11. */
  12. /* MNTL os porting layer - Linux Kernel implementation */
  13. //#include <linux/slab.h>
  14. //#include <linux/printk.h>
  15. //#include <linux/string.h>
  16. //#include <linux/spinlock.h>
  17. //#include <linux/bug.h>
  18. #include <printf.h>
  19. #include <string.h>
  20. #include <malloc.h>
  21. #include <mntl_os.h>
  22. void *os_calloc(mntl_size nmemb, mntl_size size)
  23. {
  24. return calloc(nmemb, size);
  25. }
  26. void os_free(void *buf)
  27. {
  28. free(buf);
  29. }
  30. static const char level_str[][sizeof("KERN_WARNING")] = {
  31. "KERN_ERR",
  32. "KERN_WARNING",
  33. "KERN_INFO",
  34. "KERN_DEBUG",
  35. };
  36. void os_print(int level, const char *fmt, ...)
  37. {
  38. char buf[128];
  39. va_list ap;
  40. if (level > MNTL_PR_DEBUG)
  41. level = MNTL_PR_DEBUG;
  42. if (strlen(fmt) < sizeof(buf) - 8) {
  43. snprintf(buf, sizeof(buf), "%smntl: %s", level_str[level], fmt);
  44. fmt = buf;
  45. }
  46. va_start(ap, fmt);
  47. _dvprintf(fmt, ap);
  48. va_end(ap);
  49. }
  50. int os_snprintf(char *buf, int size, const char *fmt, ...)
  51. {
  52. va_list ap;
  53. int ret;
  54. va_start(ap, fmt);
  55. ret = vsnprintf(buf, size, fmt, ap);
  56. va_end(ap);
  57. return ret;
  58. }
  59. void *os_memcpy(void *dest, const void *src, mntl_size n)
  60. {
  61. return memcpy(dest, src, n);
  62. }
  63. void *os_memset(void *dest, int s, mntl_size n)
  64. {
  65. return memset(dest, s, n);
  66. }
  67. #if 0
  68. mntl_lock os_lock_create(void)
  69. {
  70. spinlock_t *lock;
  71. lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL | __GFP_ZERO);
  72. spin_lock_init(lock);
  73. return lock;
  74. }
  75. int os_lock_destroy(mntl_lock lock)
  76. {
  77. kfree(lock);
  78. return 0;
  79. }
  80. int os_lock(mntl_lock lock)
  81. {
  82. spin_lock((spinlock_t *)lock);
  83. return 0;
  84. }
  85. int os_unlock(mntl_lock lock)
  86. {
  87. spin_unlock((spinlock_t *)lock);
  88. return 0;
  89. }
  90. #endif
  91. void os_abort(void)
  92. {
  93. return;
  94. }
  95. #if 0
  96. unsigned long long os_current_time(void)
  97. {
  98. struct timespec64 ts;
  99. getnstimeofday64(&ts);
  100. return ts.tv_sec*1000000000ULL + ts.tv_nsec;
  101. }
  102. #endif