fastrpc.h 4.4 KB

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