remoteproc.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. * @size: Size of the memory region @da is pointing to
  114. * @return virtual address.
  115. */
  116. void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
  117. };
  118. /* Accessor */
  119. #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
  120. #if CONFIG_IS_ENABLED(REMOTEPROC)
  121. /**
  122. * rproc_init() - Initialize all bound remote proc devices
  123. * @return 0 if all ok, else appropriate error value.
  124. */
  125. int rproc_init(void);
  126. /**
  127. * rproc_dev_init() - Initialize a remote proc device based on id
  128. * @id: id of the remote processor
  129. * @return 0 if all ok, else appropriate error value.
  130. */
  131. int rproc_dev_init(int id);
  132. /**
  133. * rproc_is_initialized() - check to see if remoteproc devices are initialized
  134. * @return true if all devices are initialized, false otherwise.
  135. */
  136. bool rproc_is_initialized(void);
  137. /**
  138. * rproc_load() - load binary or elf to a remote processor
  139. * @id: id of the remote processor
  140. * @addr: address in memory where the image is located
  141. * @size: size of the image
  142. * @return 0 if all ok, else appropriate error value.
  143. */
  144. int rproc_load(int id, ulong addr, ulong size);
  145. /**
  146. * rproc_start() - Start a remote processor
  147. * @id: id of the remote processor
  148. * @return 0 if all ok, else appropriate error value.
  149. */
  150. int rproc_start(int id);
  151. /**
  152. * rproc_stop() - Stop a remote processor
  153. * @id: id of the remote processor
  154. * @return 0 if all ok, else appropriate error value.
  155. */
  156. int rproc_stop(int id);
  157. /**
  158. * rproc_reset() - reset a remote processor
  159. * @id: id of the remote processor
  160. * @return 0 if all ok, else appropriate error value.
  161. */
  162. int rproc_reset(int id);
  163. /**
  164. * rproc_ping() - ping a remote processor to check if it can communicate
  165. * @id: id of the remote processor
  166. * @return 0 if all ok, else appropriate error value.
  167. *
  168. * NOTE: this might need communication path available, which is not implemented
  169. * as part of remoteproc framework - hook on to appropriate bus architecture to
  170. * do the same
  171. */
  172. int rproc_ping(int id);
  173. /**
  174. * rproc_is_running() - check to see if remote processor is running
  175. * @id: id of the remote processor
  176. * @return 0 if running, 1 if not running, -ve on error.
  177. *
  178. * NOTE: this may not involve actual communication capability of the remote
  179. * processor, but just ensures that it is out of reset and executing code.
  180. */
  181. int rproc_is_running(int id);
  182. /**
  183. * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one
  184. *
  185. * Check if a valid ELF32 image exists at the given memory location. Verify
  186. * basic ELF32 format requirements like magic number and sections size.
  187. *
  188. * @addr: address of the image to verify
  189. * @size: size of the image
  190. * @return 0 if the image looks good, else appropriate error value.
  191. */
  192. int rproc_elf32_sanity_check(ulong addr, ulong size);
  193. /**
  194. * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one
  195. *
  196. * Check if a valid ELF64 image exists at the given memory location. Verify
  197. * basic ELF64 format requirements like magic number and sections size.
  198. *
  199. * @addr: address of the image to verify
  200. * @size: size of the image
  201. * @return 0 if the image looks good, else appropriate error value.
  202. */
  203. int rproc_elf64_sanity_check(ulong addr, ulong size);
  204. /**
  205. * rproc_elf_sanity_check() - Verify if an image is a valid ELF one
  206. *
  207. * Check if a valid ELF image exists at the given memory location. Auto
  208. * detects ELF32/ELF64 and verifies basic ELF64/ELF32 format requirements
  209. * like magic number and sections size.
  210. *
  211. * @addr: address of the image to verify
  212. * @size: size of the image
  213. * @return 0 if the image looks good, else appropriate error value.
  214. */
  215. int rproc_elf_sanity_check(ulong addr, ulong size);
  216. /**
  217. * rproc_elf32_load_image() - load an ELF32 image
  218. * @dev: device loading the ELF32 image
  219. * @addr: valid ELF32 image address
  220. * @size: size of the image
  221. * @return 0 if the image is successfully loaded, else appropriate error value.
  222. */
  223. int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
  224. /**
  225. * rproc_elf64_load_image() - load an ELF64 image
  226. * @dev: device loading the ELF64 image
  227. * @addr: valid ELF64 image address
  228. * @size: size of the image
  229. * @return 0 if the image is successfully loaded, else appropriate error value.
  230. */
  231. int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
  232. /**
  233. * rproc_elf_load_image() - load an ELF image
  234. * @dev: device loading the ELF image
  235. * @addr: valid ELF image address
  236. * @size: size of the image
  237. *
  238. * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
  239. * @return 0 if the image is successfully loaded, else appropriate error value.
  240. */
  241. int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size);
  242. /**
  243. * rproc_elf_get_boot_addr() - Get rproc's boot address.
  244. * @dev: device loading the ELF image
  245. * @addr: valid ELF image address
  246. *
  247. * This function returns the entry point address of the ELF
  248. * image.
  249. */
  250. ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
  251. #else
  252. static inline int rproc_init(void) { return -ENOSYS; }
  253. static inline int rproc_dev_init(int id) { return -ENOSYS; }
  254. static inline bool rproc_is_initialized(void) { return false; }
  255. static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; }
  256. static inline int rproc_start(int id) { return -ENOSYS; }
  257. static inline int rproc_stop(int id) { return -ENOSYS; }
  258. static inline int rproc_reset(int id) { return -ENOSYS; }
  259. static inline int rproc_ping(int id) { return -ENOSYS; }
  260. static inline int rproc_is_running(int id) { return -ENOSYS; }
  261. static inline int rproc_elf32_sanity_check(ulong addr,
  262. ulong size) { return -ENOSYS; }
  263. static inline int rproc_elf64_sanity_check(ulong addr,
  264. ulong size) { return -ENOSYS; }
  265. static inline int rproc_elf_sanity_check(ulong addr,
  266. ulong size) { return -ENOSYS; }
  267. static inline int rproc_elf32_load_image(struct udevice *dev,
  268. unsigned long addr, ulong size)
  269. { return -ENOSYS; }
  270. static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
  271. ulong size)
  272. { return -ENOSYS; }
  273. static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
  274. ulong size)
  275. { return -ENOSYS; }
  276. static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
  277. { return 0; }
  278. #endif
  279. #endif /* _RPROC_H_ */