hv_drv_UsbCompat.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. * @file hv_drv_UsbCompat.h
  3. * @brief This file contains some compatibility definitions.
  4. * Because the code is ported from uboot, some adaptations have been made here.
  5. *
  6. * @author HiView SoC Software Team
  7. * @version 1.0.0
  8. * @date 2022-06-15
  9. */
  10. #ifndef __HV_DRV_USB_COMPAT_H_
  11. #define __HV_DRV_USB_COMPAT_H_
  12. #include "hv_drv_UsbDefaultConfig.h"
  13. #include "hv_drv_UsbDefines.h"
  14. #include "hv_vos_Comm.h"
  15. struct unused {};
  16. typedef struct unused unused_t;
  17. struct p_current{
  18. int pid;
  19. };
  20. //extern struct p_current *current;
  21. /* avoid conflict with <dm/device.h> */
  22. #ifdef dev_dbg
  23. #undef dev_dbg
  24. #endif
  25. #ifdef dev_vdbg
  26. #undef dev_vdbg
  27. #endif
  28. #ifdef dev_info
  29. #undef dev_info
  30. #endif
  31. #ifdef dev_err
  32. #undef dev_err
  33. #endif
  34. #ifdef dev_warn
  35. #undef dev_warn
  36. #endif
  37. #ifdef USB_DEBUG
  38. #define dev_dbg(dev, fmt, args...) \
  39. pr_info(fmt, ##args)
  40. #define dev_vdbg(dev, fmt, args...) \
  41. pr_info(fmt, ##args)
  42. #define dev_info(dev, fmt, args...) \
  43. pr_info(fmt, ##args)
  44. #define dev_err(dev, fmt, args...) \
  45. pr_info(fmt, ##args)
  46. #define dev_warn(dev, fmt, args...) \
  47. pr_info(fmt, ##args)
  48. #define debug(fmt, args...) pr_info(fmt, ##args)
  49. #define ERR(fmt, args...) pr_info(fmt, ##args)
  50. #else
  51. #define dev_dbg(dev, fmt, args...)
  52. #define dev_vdbg(dev, fmt, args...)
  53. #define dev_info(dev, fmt, args...)
  54. #define dev_err(dev, fmt, args...) \
  55. pr_err(fmt, ##args)
  56. #define dev_warn(dev, fmt, args...)
  57. #define debug(fmt, args...)
  58. #define ERR(fmt, args...) \
  59. pr_err(fmt, ##args)
  60. #endif
  61. #define GFP_ATOMIC ((gfp_t) 0)
  62. #define GFP_KERNEL ((gfp_t) 0)
  63. #define GFP_NOFS ((gfp_t) 0)
  64. #define GFP_USER ((gfp_t) 0)
  65. #define __GFP_NOWARN ((gfp_t) 0)
  66. #define __GFP_ZERO ((gfp_t)0x8000u) /* Return zeroed page on success */
  67. #ifndef SIZE_MAX
  68. #define SIZE_MAX (~(size_t)0)
  69. #endif
  70. static inline void kfree(const void *block)
  71. {
  72. HV_FREE((void *)block);
  73. }
  74. static inline void vfree(const void *addr)
  75. {
  76. HV_FREE((void *)addr);
  77. }
  78. struct kmem_cache { int sz; };
  79. struct kmem_cache *get_mem(int element_sz);
  80. #define kmem_cache_create(a, sz, c, d, e) get_mem(sz)
  81. void *kmem_cache_alloc(struct kmem_cache *obj, int flag);
  82. static inline void kmem_cache_free(struct kmem_cache *cachep, void *obj)
  83. {
  84. HV_FREE(obj);
  85. }
  86. static inline void kmem_cache_destroy(struct kmem_cache *cachep)
  87. {
  88. HV_FREE(cachep);
  89. }
  90. #define DECLARE_WAITQUEUE(...) do { } while (0)
  91. #define add_wait_queue(...) do { } while (0)
  92. #define remove_wait_queue(...) do { } while (0)
  93. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  94. #define PAGE_SIZE 4096
  95. /* drivers/char/random.c */
  96. #define get_random_bytes(...)
  97. /* include/linux/leds.h */
  98. struct led_trigger {};
  99. #define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
  100. enum led_brightness {
  101. LED_OFF = 0,
  102. LED_HALF = 127,
  103. LED_FULL = 255,
  104. };
  105. static inline void led_trigger_register_simple(const char *name,
  106. struct led_trigger **trigger) {}
  107. static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
  108. static inline void led_trigger_event(struct led_trigger *trigger,
  109. enum led_brightness event) {}
  110. /* uapi/linux/limits.h */
  111. #define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
  112. /**
  113. * The type used for indexing onto a disc or disc partition.
  114. *
  115. * Linux always considers sectors to be 512 bytes long independently
  116. * of the devices real block size.
  117. *
  118. * blkcnt_t is the type of the inode's block count.
  119. */
  120. #ifdef CONFIG_LBDAF
  121. typedef u64 sector_t;
  122. typedef u64 blkcnt_t;
  123. #else
  124. #ifdef sector_t
  125. #undef sector_t
  126. typedef unsigned long sector_t;
  127. #endif
  128. #ifdef blkcnt_t
  129. #undef blkcnt_t
  130. typedef unsigned long blkcnt_t;
  131. #endif
  132. #endif
  133. struct work_struct {};
  134. typedef unused_t spinlock_t;
  135. typedef int wait_queue_head_t;
  136. #define spin_lock_init(lock) do {} while (0)
  137. #define spin_lock(lock) do {} while (0)
  138. #define spin_unlock(lock) do {} while (0)
  139. #define spin_lock_irqsave(lock, flags) do {} while (0)
  140. #define spin_unlock_irqrestore(lock, flags) do { flags = 0; } while (0)
  141. #define DEFINE_MUTEX(...)
  142. #define mutex_init(...)
  143. #define mutex_lock(...)
  144. #define mutex_unlock(...)
  145. #define init_rwsem(...) do { } while (0)
  146. #define down_read(...) do { } while (0)
  147. #define down_write(...) do { } while (0)
  148. #define down_write_trylock(...) 1
  149. #define up_read(...) do { } while (0)
  150. #define up_write(...) do { } while (0)
  151. #define cond_resched() do { } while (0)
  152. #define yield() do { } while (0)
  153. #define __init
  154. #define __exit
  155. #define __devinit
  156. #define __devinitconst
  157. #define kthread_create(...) __builtin_return_address(0)
  158. #define kthread_stop(...) do { } while (0)
  159. #define wake_up_process(...) do { } while (0)
  160. struct rw_semaphore { int i; };
  161. #define down_write(...) do { } while (0)
  162. #define up_write(...) do { } while (0)
  163. #define down_read(...) do { } while (0)
  164. #define up_read(...) do { } while (0)
  165. struct device {
  166. struct device *parent;
  167. struct class *class;
  168. dev_t devt; /* dev_t, creates the sysfs "dev" */
  169. void (*release)(struct device *dev);
  170. /* This is used from drivers/usb/musb-new subsystem only */
  171. void *driver_data; /* data private to the driver */
  172. void *device_data; /* data private to the device */
  173. };
  174. struct mutex { int i; };
  175. struct kernel_param { int i; };
  176. struct cdev {
  177. int owner;
  178. dev_t dev;
  179. };
  180. #define cdev_init(...) do { } while (0)
  181. #define cdev_add(...) 0
  182. #define cdev_del(...) do { } while (0)
  183. #define prandom_u32(...) 0
  184. typedef struct {
  185. uid_t val;
  186. } kuid_t;
  187. typedef struct {
  188. gid_t val;
  189. } kgid_t;
  190. /* from include/linux/types.h */
  191. /**
  192. * struct callback_head - callback structure for use with RCU and task_work
  193. * @next: next update requests in a list
  194. * @func: actual update function to call after the grace period.
  195. */
  196. struct callback_head {
  197. struct callback_head *next;
  198. void (*func)(struct callback_head *head);
  199. };
  200. #define rcu_head callback_head
  201. enum writeback_sync_modes {
  202. WB_SYNC_NONE, /* Don't wait on anything */
  203. WB_SYNC_ALL, /* Wait on every mapping */
  204. };
  205. /* from include/linux/writeback.h */
  206. /*
  207. * A control structure which tells the writeback code what to do. These are
  208. * always on the stack, and hence need no locking. They are always initialised
  209. * in a manner such that unspecified fields are set to zero.
  210. */
  211. struct writeback_control {
  212. long nr_to_write; /* Write this many pages, and decrement
  213. this for each page written */
  214. long pages_skipped; /* Pages which were not written */
  215. /*
  216. * For a_ops->writepages(): if start or end are non-zero then this is
  217. * a hint that the filesystem need only write out the pages inside that
  218. * byterange. The byte at `end' is included in the writeout request.
  219. */
  220. loff_t range_start;
  221. loff_t range_end;
  222. enum writeback_sync_modes sync_mode;
  223. unsigned for_kupdate:1; /* A kupdate writeback */
  224. unsigned for_background:1; /* A background writeback */
  225. unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
  226. unsigned for_reclaim:1; /* Invoked from the page allocator */
  227. unsigned range_cyclic:1; /* range_start is cyclic */
  228. unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
  229. };
  230. typedef int irqreturn_t;
  231. struct timer_list {};
  232. struct notifier_block {};
  233. typedef unsigned long dmaaddr_t;
  234. #define pm_runtime_get_sync(dev) do {} while (0)
  235. #define pm_runtime_put(dev) do {} while (0)
  236. #define pm_runtime_put_sync(dev) do {} while (0)
  237. #define pm_runtime_use_autosuspend(dev) do {} while (0)
  238. #define pm_runtime_set_autosuspend_delay(dev, delay) do {} while (0)
  239. #define pm_runtime_enable(dev) do {} while (0)
  240. #define IRQ_NONE 0
  241. #define IRQ_HANDLED 1
  242. #define IRQ_WAKE_THREAD 2
  243. #define dev_set_drvdata(dev, data) do {} while (0)
  244. #define disable_irq_wake(irq) do {} while (0)
  245. #define enable_irq_wake(irq) -EINVAL
  246. #define free_irq(irq, data) do {} while (0)
  247. #define request_irq(nr, f, flags, nm, data) 0
  248. #define __constant_cpu_to_le16(x) ((__le16)(__u16)(x))
  249. #define cpu_relax() do {} while (0)
  250. #ifndef unlikely
  251. #define unlikely(cond) (cond)
  252. #endif
  253. #ifndef likely
  254. #define likely(cond) (cond)
  255. #endif
  256. /// mark as unused for prevent compiler warning
  257. #ifndef USB_UNUSED
  258. #define USB_UNUSED(var) (void)(var)
  259. #endif
  260. ////linux/bug.h
  261. #define BUG() do { \
  262. pr_info("BUG at :%d/%s()!\n", __LINE__, __func__); \
  263. } while (0)
  264. #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
  265. #define WARN_ON(condition) ({ \
  266. if (condition == 1) \
  267. pr_info("WARNING at :%d/%s()!\n", __LINE__, __func__); \
  268. })
  269. /*
  270. * You can initialize platform's USB host or device
  271. * ports by passing this enum as an argument to
  272. * board_usb_init().
  273. */
  274. enum usb_init_type {
  275. USB_INIT_HOST,
  276. USB_INIT_DEVICE
  277. };
  278. int usb_lowlevel_init(int index, enum usb_init_type init, void **controller);
  279. int usb_lowlevel_stop(int index);
  280. /*
  281. * board-specific hardware initialization, called by
  282. * usb drivers and u-boot commands
  283. *
  284. * @param index USB controller number
  285. * @param init initializes controller as USB host or device
  286. */
  287. int board_usb_init(int index, enum usb_init_type init);
  288. /*
  289. * can be used to clean up after failed USB initialization attempt
  290. * vide: board_usb_init()
  291. *
  292. * @param index USB controller number for selective cleanup
  293. * @param init usb_init_type passed to board_usb_init()
  294. */
  295. int board_usb_cleanup(int index, enum usb_init_type init);
  296. ////include\linux\unaligned\le_byteshift.h
  297. static inline void __put_unaligned_le16(u16 val, u8 *p)
  298. {
  299. *p++ = val;
  300. *p++ = val >> 8;
  301. }
  302. static inline void put_unaligned_le16(u16 val, void *p)
  303. {
  304. __put_unaligned_le16(val, p);
  305. }
  306. unsigned long simple_strtoul(const char *cp, char **endp,
  307. unsigned int base);
  308. static inline void *kmemdup(const void *src, size_t len)
  309. {
  310. void *p;
  311. p = HV_MALLOC(len);
  312. if (p)
  313. HV_MEMCPY(p, src, len);
  314. return p;
  315. }
  316. #define WARN(condition, fmt, args...) ({ \
  317. int ret_warn = !!condition; \
  318. if (ret_warn) \
  319. pr_info(fmt, ##args); \
  320. ret_warn; })
  321. #define device_init_wakeup(dev, a) do {} while (0)
  322. #define platform_data device_data
  323. #ifndef wmb
  324. #define wmb() asm volatile ("" : : : "memory")
  325. #endif
  326. #define msleep(a) udelay(a * 1000)
  327. /*
  328. * Map U-Boot config options to Linux ones
  329. */
  330. #define __set_bit generic_set_bit
  331. #ifndef max_usb
  332. #define max_usb(a, b) (((a) > (b)) ? (a) : (b))
  333. #endif
  334. #ifndef min_usb
  335. #define min_usb(a, b) (((a) < (b)) ? (a) : (b))
  336. #endif
  337. #define min_t_usb(type, x, y) ({ \
  338. type __min1 = (x); \
  339. type __min2 = (y); \
  340. __min1 < __min2 ? __min1: __min2; })
  341. #define max_t_usb(type, x, y) ({ \
  342. type __max1 = (x); \
  343. type __max2 = (y); \
  344. __max1 > __max2 ? __max1: __max2; })
  345. static inline int ffs_me(int x)
  346. {
  347. int r = 1;
  348. if (!x)
  349. return 0;
  350. if (!(x & 0xffff)) {
  351. x >>= 16;
  352. r += 16;
  353. }
  354. if (!(x & 0xff)) {
  355. x >>= 8;
  356. r += 8;
  357. }
  358. if (!(x & 0xf)) {
  359. x >>= 4;
  360. r += 4;
  361. }
  362. if (!(x & 3)) {
  363. x >>= 2;
  364. r += 2;
  365. }
  366. if (!(x & 1)) {
  367. x >>= 1;
  368. r += 1;
  369. }
  370. return r;
  371. }
  372. #define BITS_PER_LONG 32
  373. #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
  374. #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
  375. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  376. #define BITS_PER_BYTE 8
  377. #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
  378. /**
  379. * __set_bit - Set a bit in memory
  380. * @nr: the bit to set
  381. * @addr: the address to start counting from
  382. *
  383. * Unlike set_bit(), this function is non-atomic and may be reordered.
  384. * If it's called on the same region of memory simultaneously, the effect
  385. * may be that only one operation succeeds.
  386. */
  387. static inline void generic_set_bit(int nr, volatile unsigned long *addr)
  388. {
  389. unsigned long mask = BIT_MASK(nr);
  390. unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
  391. *p |= mask;
  392. }
  393. static inline void generic_clear_bit(int nr, volatile unsigned long *addr)
  394. {
  395. unsigned long mask = BIT_MASK(nr);
  396. unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
  397. *p &= ~mask;
  398. }
  399. static inline int test_bit(int nr, const void *addr)
  400. {
  401. return ((unsigned char *)addr)[nr >> 3] & (1u << (nr & 7));
  402. }
  403. /* common */
  404. #define DECLARE_BITMAP(name, bits) \
  405. unsigned long name[BITS_TO_LONGS(bits)]
  406. #define small_const_nbits(nbits) \
  407. (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
  408. static inline void bitmap_zero(unsigned long *dst, int nbits)
  409. {
  410. if (small_const_nbits(nbits))
  411. *dst = 0UL;
  412. else {
  413. int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
  414. HV_MEMSET(dst, 0, len);
  415. }
  416. }
  417. #define dma_cache_maint(addr, size, mode) cache_flush()
  418. void cache_flush(void);
  419. #endif