e24_host_shm.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*********************************Copyright (c)*********************************************
  2. **
  3. **
  4. **
  5. **-------------------------------file info-------------------------------------------------
  6. ** Vrsions: V1.0
  7. ** Filename: e24_host_shm.h
  8. ** Creator: shanlong.li
  9. ** Date: 2021/08/30
  10. ** Description: share memory and mailobx
  11. **
  12. **-------------------------------history----------------------------------------------
  13. ** Name: shanlong.li
  14. ** Versions: V1.0
  15. ** Date: 2021/08/30
  16. ** Description:
  17. **
  18. ** ----------------------------------------------------------------------------------------
  19. ******************************************************************************************/
  20. #ifndef __E24_HOST_SHM_H__
  21. #define __E24_HOST_SHM_H__
  22. #include <stdlib.h>
  23. #define E24_IOCTL_MAGIC 'e'
  24. #define E24_IOCTL_SEND _IO(E24_IOCTL_MAGIC, 1)
  25. #define E24_IOCTL_RECV _IO(E24_IOCTL_MAGIC, 2)
  26. #define E24_IOCTL_GET_CHANNEL _IO(E24_IOCTL_MAGIC, 3)
  27. #define E24_IOCTL_FREE_CHANNEL _IO(E24_IOCTL_MAGIC, 4)
  28. #define E24_IOCTL_ALLOC _IO(E24_IOCTL_MAGIC, 5)
  29. #define E24_IOCTL_FREE _IO(E24_IOCTL_MAGIC, 6)
  30. #define BUF_LEN 28
  31. typedef unsigned long _u64;
  32. typedef unsigned int _u32;
  33. enum e24_status {
  34. E24_STATUS_SUCCESS,
  35. E24_STATUS_FAILURE,
  36. E24_STATUS_PENDING,
  37. };
  38. struct e24_ioctl_alloc {
  39. _u32 size;
  40. _u32 align;
  41. _u64 addr;
  42. };
  43. struct e24_ioctl_user {
  44. _u32 flags;
  45. _u32 in_data_size;
  46. _u32 out_data_size;
  47. _u64 in_data_addr;
  48. _u64 out_data_addr;
  49. };
  50. struct e24_device {
  51. int count;
  52. int fd;
  53. };
  54. struct e24_host_ops {
  55. void (*fn)(struct e24_device *device,struct e24_ioctl_user *data,enum e24_status *status);
  56. };
  57. struct e24_event {
  58. struct e24_device *device;
  59. struct e24_host_ops f_ops;
  60. };
  61. static inline void set_status(enum e24_status *status,enum e24_status v) {
  62. if(status)
  63. *status = v;
  64. }
  65. static inline void *alloc_refcounted(size_t sz) {
  66. void *buf = calloc(1,sz);
  67. struct e24_device *ref = buf;
  68. if(ref)
  69. ref->count = 1;
  70. return buf;
  71. }
  72. struct e24_device *e24_open_device(int idx, enum e24_status *status);
  73. void e24_release_device(struct e24_device *device);
  74. struct e24_event *e24_event_init(struct e24_device *device,enum e24_status *status);
  75. void e24_event_release(struct e24_event *evt);
  76. int e24_alloc_buffer(struct e24_device *device,
  77. struct e24_ioctl_alloc *alloc_buf,enum e24_status *status);
  78. void e24_release_buffer(struct e24_device * device,struct e24_ioctl_alloc *alloc_buf);
  79. void e24_run_command(struct e24_event *evt, void *in_data, size_t in_data_size,
  80. void *out_data, size_t out_data_size, enum e24_status *status);
  81. #endif