remoteproc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2015
  4. * Texas Instruments Incorporated - http://www.ti.com/
  5. */
  6. #ifndef _RPROC_H_
  7. #define _RPROC_H_
  8. /*
  9. * Note: The platform data support is not meant for use with newer
  10. * platforms. This is meant only for legacy devices. This mode of
  11. * initialization *will* be eventually removed once all necessary
  12. * platforms have moved to dm/fdt.
  13. */
  14. #include <dm/platdata.h> /* For platform data support - non dt world */
  15. /**
  16. * enum rproc_mem_type - What type of memory model does the rproc use
  17. * @RPROC_INTERNAL_MEMORY_MAPPED: Remote processor uses own memory and is memory
  18. * mapped to the host processor over an address range.
  19. *
  20. * Please note that this is an enumeration of memory model of different types
  21. * of remote processors. Few of the remote processors do have own internal
  22. * memories, while others use external memory for instruction and data.
  23. */
  24. enum rproc_mem_type {
  25. RPROC_INTERNAL_MEMORY_MAPPED = 0,
  26. };
  27. /**
  28. * struct dm_rproc_uclass_pdata - platform data for a CPU
  29. * @name: Platform-specific way of naming the Remote proc
  30. * @mem_type: one of 'enum rproc_mem_type'
  31. * @driver_plat_data: driver specific platform data that may be needed.
  32. *
  33. * This can be accessed with dev_get_uclass_platdata() for any UCLASS_REMOTEPROC
  34. * device.
  35. *
  36. */
  37. struct dm_rproc_uclass_pdata {
  38. const char *name;
  39. enum rproc_mem_type mem_type;
  40. void *driver_plat_data;
  41. };
  42. /**
  43. * struct dm_rproc_ops - Driver model remote proc operations.
  44. *
  45. * This defines the operations provided by remote proc driver.
  46. */
  47. struct dm_rproc_ops {
  48. /**
  49. * init() - Initialize the remoteproc device (optional)
  50. *
  51. * This is called after the probe is completed allowing the remote
  52. * processor drivers to split up the initializations between probe and
  53. * init if needed.
  54. *
  55. * @dev: Remote proc device
  56. * @return 0 if all ok, else appropriate error value.
  57. */
  58. int (*init)(struct udevice *dev);
  59. /**
  60. * load() - Load the remoteproc device using data provided (mandatory)
  61. *
  62. * Load the remoteproc device with an image, do not start the device.
  63. *
  64. * @dev: Remote proc device
  65. * @addr: Address of the image to be loaded
  66. * @size: Size of the image to be loaded
  67. * @return 0 if all ok, else appropriate error value.
  68. */
  69. int (*load)(struct udevice *dev, ulong addr, ulong size);
  70. /**
  71. * start() - Start the remoteproc device (mandatory)
  72. *
  73. * @dev: Remote proc device
  74. * @return 0 if all ok, else appropriate error value.
  75. */
  76. int (*start)(struct udevice *dev);
  77. /**
  78. * stop() - Stop the remoteproc device (optional)
  79. *
  80. * @dev: Remote proc device
  81. * @return 0 if all ok, else appropriate error value.
  82. */
  83. int (*stop)(struct udevice *dev);
  84. /**
  85. * reset() - Reset the remoteproc device (optional)
  86. *
  87. * @dev: Remote proc device
  88. * @return 0 if all ok, else appropriate error value.
  89. */
  90. int (*reset)(struct udevice *dev);
  91. /**
  92. * is_running() - Check if the remote processor is running (optional)
  93. *
  94. * @dev: Remote proc device
  95. * @return 0 if running, 1 if not running, -ve on error.
  96. */
  97. int (*is_running)(struct udevice *dev);
  98. /**
  99. * ping() - Ping the remote device for basic communication (optional)
  100. *
  101. * @dev: Remote proc device
  102. * @return 0 on success, 1 if not responding, -ve on other errors.
  103. */
  104. int (*ping)(struct udevice *dev);
  105. /**
  106. * device_to_virt() - Return translated virtual address (optional)
  107. *
  108. * Translate a device address (remote processor view) to virtual
  109. * address (main processor view).
  110. *
  111. * @dev: Remote proc device
  112. * @da: Device address
  113. * @return virtual address.
  114. */
  115. void * (*device_to_virt)(struct udevice *dev, ulong da);
  116. };
  117. /* Accessor */
  118. #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
  119. #if CONFIG_IS_ENABLED(REMOTEPROC)
  120. /**
  121. * rproc_init() - Initialize all bound remote proc devices
  122. * @return 0 if all ok, else appropriate error value.
  123. */
  124. int rproc_init(void);
  125. /**
  126. * rproc_dev_init() - Initialize a remote proc device based on id
  127. * @id: id of the remote processor
  128. * @return 0 if all ok, else appropriate error value.
  129. */
  130. int rproc_dev_init(int id);
  131. /**
  132. * rproc_is_initialized() - check to see if remoteproc devices are initialized
  133. * @return true if all devices are initialized, false otherwise.
  134. */
  135. bool rproc_is_initialized(void);
  136. /**
  137. * rproc_load() - load binary or elf to a remote processor
  138. * @id: id of the remote processor
  139. * @addr: address in memory where the image is located
  140. * @size: size of the image
  141. * @return 0 if all ok, else appropriate error value.
  142. */
  143. int rproc_load(int id, ulong addr, ulong size);
  144. /**
  145. * rproc_start() - Start a remote processor
  146. * @id: id of the remote processor
  147. * @return 0 if all ok, else appropriate error value.
  148. */
  149. int rproc_start(int id);
  150. /**
  151. * rproc_stop() - Stop a remote processor
  152. * @id: id of the remote processor
  153. * @return 0 if all ok, else appropriate error value.
  154. */
  155. int rproc_stop(int id);
  156. /**
  157. * rproc_reset() - reset a remote processor
  158. * @id: id of the remote processor
  159. * @return 0 if all ok, else appropriate error value.
  160. */
  161. int rproc_reset(int id);
  162. /**
  163. * rproc_ping() - ping a remote processor to check if it can communicate
  164. * @id: id of the remote processor
  165. * @return 0 if all ok, else appropriate error value.
  166. *
  167. * NOTE: this might need communication path available, which is not implemented
  168. * as part of remoteproc framework - hook on to appropriate bus architecture to
  169. * do the same
  170. */
  171. int rproc_ping(int id);
  172. /**
  173. * rproc_is_running() - check to see if remote processor is running
  174. * @id: id of the remote processor
  175. * @return 0 if running, 1 if not running, -ve on error.
  176. *
  177. * NOTE: this may not involve actual communication capability of the remote
  178. * processor, but just ensures that it is out of reset and executing code.
  179. */
  180. int rproc_is_running(int id);
  181. /**
  182. * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one
  183. *
  184. * Check if a valid ELF32 image exists at the given memory location. Verify
  185. * basic ELF32 format requirements like magic number and sections size.
  186. *
  187. * @addr: address of the image to verify
  188. * @size: size of the image
  189. * @return 0 if the image looks good, else appropriate error value.
  190. */
  191. int rproc_elf32_sanity_check(ulong addr, ulong size);
  192. /**
  193. * rproc_elf32_load_image() - load an ELF32 image
  194. * @dev: device loading the ELF32 image
  195. * @addr: valid ELF32 image address
  196. * @return 0 if the image is successfully loaded, else appropriate error value.
  197. */
  198. int rproc_elf32_load_image(struct udevice *dev, unsigned long addr);
  199. #else
  200. static inline int rproc_init(void) { return -ENOSYS; }
  201. static inline int rproc_dev_init(int id) { return -ENOSYS; }
  202. static inline bool rproc_is_initialized(void) { return false; }
  203. static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; }
  204. static inline int rproc_start(int id) { return -ENOSYS; }
  205. static inline int rproc_stop(int id) { return -ENOSYS; }
  206. static inline int rproc_reset(int id) { return -ENOSYS; }
  207. static inline int rproc_ping(int id) { return -ENOSYS; }
  208. static inline int rproc_is_running(int id) { return -ENOSYS; }
  209. static inline int rproc_elf32_sanity_check(ulong addr,
  210. ulong size) { return -ENOSYS; }
  211. static inline int rproc_elf32_load_image(struct udevice *dev,
  212. unsigned long addr) { return -ENOSYS; }
  213. #endif
  214. #endif /* _RPROC_H_ */