fastrpc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __LINUX_fastrpc_H
  6. #define __LINUX_fastrpc_H
  7. #include <linux/device.h>
  8. #include <linux/errno.h>
  9. #include <linux/kernel.h>
  10. #define FASTRPC_DRV_NAME_SIZE 32
  11. enum fastrpc_driver_status {
  12. FASTRPC_PROC_DOWN = 0,
  13. };
  14. enum fastrpc_driver_invoke_nums {
  15. FASTRPC_DEV_MAP_DMA = 1,
  16. FASTRPC_DEV_UNMAP_DMA,
  17. FASTRPC_DEV_GET_HLOS_PID,
  18. };
  19. /**
  20. * struct fastrpc_dev_map_dma - fastrpc dma buffer map structure
  21. * @buf : Shared DMA buf object
  22. * @attrs : Attributes to map buffer on IOMMU
  23. * @size : Size of DMA buffer
  24. * @v_dsp_addr : Virtual addr of DSP after mapping the buffer on DSP
  25. */
  26. struct fastrpc_dev_map_dma {
  27. struct dma_buf *buf;
  28. uint32_t attrs;
  29. size_t size;
  30. uint64_t v_dsp_addr;
  31. };
  32. /**
  33. * struct fastrpc_dev_unmap_dma - fastrpc dma buffer unmap structure
  34. * @buf : Shared DMA buf object
  35. * @size : Size of DMA buffer
  36. */
  37. struct fastrpc_dev_unmap_dma {
  38. struct dma_buf *buf;
  39. size_t size;
  40. };
  41. /**
  42. * struct fastrpc_dev_get_hlos_pid - fastrpc dma buffer unmap structure
  43. * @hlos_pid : HLOS PID of attached device
  44. */
  45. struct fastrpc_dev_get_hlos_pid {
  46. int hlos_pid;
  47. };
  48. /**
  49. * fastrpc_device - device that belong to the fastrpc bus
  50. * @hn: Head node to add to fastrpc device list
  51. * @dev: the device struct
  52. * @handle: handle of the process
  53. * @fl: process file of fastrpc device
  54. * @dev_close: flag to determine if device is closed
  55. * @refs: reference count of drivers using the device
  56. */
  57. struct fastrpc_device {
  58. struct hlist_node hn;
  59. struct device dev;
  60. int handle;
  61. struct fastrpc_file *fl;
  62. bool dev_close;
  63. unsigned int refs;
  64. };
  65. #define to_fastrpc_device(d) container_of(d, struct fastrpc_device, dev)
  66. /**
  67. * struct fastrpc_driver - fastrpc driver struct
  68. * @hn: Node to add to fastrpc driver list
  69. * @driver: underlying device driver
  70. * @device: device that is matching to driver
  71. * @handle: handle of the process
  72. * @create: 0 to attach, 1 to create process
  73. * @probe: invoked when a matching fastrpc device (i.e. device) is found
  74. * @callback: invoked when there is a status change in the process
  75. */
  76. struct fastrpc_driver {
  77. struct hlist_node hn;
  78. struct device_driver driver;
  79. struct device *device;
  80. int handle;
  81. int create;
  82. int (*probe)(struct fastrpc_device *dev);
  83. int (*callback)(struct fastrpc_device *dev,
  84. enum fastrpc_driver_status status);
  85. };
  86. #define to_fastrpc_driver(x) container_of((x), struct fastrpc_driver, driver)
  87. //#if IS_ENABLED(CONFIG_MSM_ADSPRPC) || IS_ENABLED(CONFIG_MSM_ADSPRPC_TRUSTED)
  88. /**
  89. * function fastrpc_driver_register - Register fastrpc driver
  90. * @drv: Initialized fastrpc driver structure pointer
  91. */
  92. int fastrpc_driver_register(struct fastrpc_driver *drv);
  93. /**
  94. * function fastrpc_driver_unregister - Un-register fastrpc driver
  95. * @drv: fastrpc driver structure pointer
  96. */
  97. void fastrpc_driver_unregister(struct fastrpc_driver *drv);
  98. /**
  99. * function fastrpc_driver_invoke - fastrpc driver invocation function
  100. * Invoke fastrpc driver using fastrpc_device received in probe of registration
  101. * @dev : Device received in probe of registration.
  102. * @invoke_num : Invocation number of operation,
  103. * one of "fastrpc_driver_invoke_nums"
  104. * @invoke_param: Address of invocation structure corresponding to invoke_num
  105. * (struct fastrpc_dev_map_dma *) for FASTRPC_DEV_MAP_DMA
  106. * (struct fastrpc_dev_unmap_dma *) for FASTRPC_DEV_UNMAP_DMA.
  107. */
  108. long fastrpc_driver_invoke(struct fastrpc_device *dev,
  109. enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param);
  110. /*
  111. #else
  112. static inline int fastrpc_driver_register(struct fastrpc_driver *drv)
  113. { return 0; }
  114. static inline void fastrpc_driver_unregister(struct fastrpc_driver *drv)
  115. { return; }
  116. static inline long fastrpc_driver_invoke(struct fastrpc_device *dev,
  117. enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param)
  118. { return 0; }
  119. #endif
  120. */
  121. /**
  122. * module_fastrpc_driver() - Helper macro for registering a fastrpc driver
  123. * @__fastrpc_driver: fastrpc_driver struct
  124. *
  125. * Helper macro for fastrpc drivers which do not do anything special in module
  126. * init/exit. This eliminates a lot of boilerplate code. Each module may only
  127. * use this macro once, and calling it replaces module_init and module_exit.
  128. */
  129. #define module_fastrpc_driver(__fastrpc_driver) \
  130. static int __init __fastrpc_driver##_init(void) \
  131. { \
  132. return fastrpc_driver_register(&(__fastrpc_driver)); \
  133. } \
  134. module_init(__fastrpc_driver##_init); \
  135. static void __exit __fastrpc_driver##_exit(void) \
  136. { \
  137. fastrpc_driver_unregister(&(__fastrpc_driver)); \
  138. } \
  139. module_exit(__fastrpc_driver##_exit)
  140. #endif /* __LINUX_fastrpc_H */