remoteproc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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_elf32_load_image() - load an ELF32 image
  206. * @dev: device loading the ELF32 image
  207. * @addr: valid ELF32 image address
  208. * @size: size of the image
  209. * @return 0 if the image is successfully loaded, else appropriate error value.
  210. */
  211. int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
  212. /**
  213. * rproc_elf64_load_image() - load an ELF64 image
  214. * @dev: device loading the ELF64 image
  215. * @addr: valid ELF64 image address
  216. * @size: size of the image
  217. * @return 0 if the image is successfully loaded, else appropriate error value.
  218. */
  219. int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
  220. /**
  221. * rproc_elf_load_image() - load an ELF image
  222. * @dev: device loading the ELF image
  223. * @addr: valid ELF image address
  224. * @size: size of the image
  225. *
  226. * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
  227. * @return 0 if the image is successfully loaded, else appropriate error value.
  228. */
  229. int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size);
  230. /**
  231. * rproc_elf_get_boot_addr() - Get rproc's boot address.
  232. * @dev: device loading the ELF image
  233. * @addr: valid ELF image address
  234. *
  235. * This function returns the entry point address of the ELF
  236. * image.
  237. */
  238. ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
  239. /**
  240. * rproc_elf32_load_rsc_table() - load the resource table from an ELF32 image
  241. *
  242. * Search for the resource table in an ELF32 image, and if found, copy it to
  243. * device memory.
  244. *
  245. * @dev: device loading the resource table
  246. * @fw_addr: ELF image address
  247. * @fw_size: size of the ELF image
  248. * @rsc_addr: pointer to the found resource table address. Updated on
  249. * operation success
  250. * @rsc_size: pointer to the found resource table size. Updated on operation
  251. * success
  252. *
  253. * @return 0 if a valid resource table is successfully loaded, -ENODATA if there
  254. * is no resource table (which is optional), or another appropriate error value.
  255. */
  256. int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  257. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  258. /**
  259. * rproc_elf64_load_rsc_table() - load the resource table from an ELF64 image
  260. *
  261. * Search for the resource table in an ELF64 image, and if found, copy it to
  262. * device memory.
  263. *
  264. * @dev: device loading the resource table
  265. * @fw_addr: ELF image address
  266. * @fw_size: size of the ELF image
  267. * @rsc_addr: pointer to the found resource table address. Updated on
  268. * operation success
  269. * @rsc_size: pointer to the found resource table size. Updated on operation
  270. * success
  271. *
  272. * @return 0 if a valid resource table is successfully loaded, -ENODATA if there
  273. * is no resource table (which is optional), or another appropriate error value.
  274. */
  275. int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
  276. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  277. /**
  278. * rproc_elf_load_rsc_table() - load the resource table from an ELF image
  279. *
  280. * Auto detects if the image is ELF32 or ELF64 image and search accordingly for
  281. * the resource table, and if found, copy it to device memory.
  282. *
  283. * @dev: device loading the resource table
  284. * @fw_addr: ELF image address
  285. * @fw_size: size of the ELF image
  286. * @rsc_addr: pointer to the found resource table address. Updated on
  287. * operation success
  288. * @rsc_size: pointer to the found resource table size. Updated on operation
  289. * success
  290. *
  291. * @return 0 if a valid resource table is successfully loaded, -ENODATA if there
  292. * is no resource table (which is optional), or another appropriate error value.
  293. */
  294. int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
  295. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  296. #else
  297. static inline int rproc_init(void) { return -ENOSYS; }
  298. static inline int rproc_dev_init(int id) { return -ENOSYS; }
  299. static inline bool rproc_is_initialized(void) { return false; }
  300. static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; }
  301. static inline int rproc_start(int id) { return -ENOSYS; }
  302. static inline int rproc_stop(int id) { return -ENOSYS; }
  303. static inline int rproc_reset(int id) { return -ENOSYS; }
  304. static inline int rproc_ping(int id) { return -ENOSYS; }
  305. static inline int rproc_is_running(int id) { return -ENOSYS; }
  306. static inline int rproc_elf32_sanity_check(ulong addr,
  307. ulong size) { return -ENOSYS; }
  308. static inline int rproc_elf64_sanity_check(ulong addr,
  309. ulong size) { return -ENOSYS; }
  310. static inline int rproc_elf_sanity_check(ulong addr,
  311. ulong size) { return -ENOSYS; }
  312. static inline int rproc_elf32_load_image(struct udevice *dev,
  313. unsigned long addr, ulong size)
  314. { return -ENOSYS; }
  315. static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
  316. ulong size)
  317. { return -ENOSYS; }
  318. static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
  319. ulong size)
  320. { return -ENOSYS; }
  321. static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
  322. { return 0; }
  323. static inline int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  324. ulong fw_size, ulong *rsc_addr,
  325. ulong *rsc_size)
  326. { return -ENOSYS; }
  327. static inline int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
  328. ulong fw_size, ulong *rsc_addr,
  329. ulong *rsc_size)
  330. { return -ENOSYS; }
  331. static inline int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
  332. ulong fw_size, ulong *rsc_addr,
  333. ulong *rsc_size)
  334. { return -ENOSYS; }
  335. #endif
  336. #endif /* _RPROC_H_ */