remoteproc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. * struct fw_rsc_hdr - firmware resource entry header
  17. * @type: resource type
  18. * @data: resource data
  19. *
  20. * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
  21. * its @type. The content of the entry itself will immediately follow
  22. * this header, and it should be parsed according to the resource type.
  23. */
  24. struct fw_rsc_hdr {
  25. u32 type;
  26. u8 data[0];
  27. };
  28. /**
  29. * enum fw_resource_type - types of resource entries
  30. *
  31. * @RSC_CARVEOUT: request for allocation of a physically contiguous
  32. * memory region.
  33. * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
  34. * @RSC_TRACE: announces the availability of a trace buffer into which
  35. * the remote processor will be writing logs.
  36. * @RSC_VDEV: declare support for a virtio device, and serve as its
  37. * virtio header.
  38. * @RSC_PRELOAD_VENDOR: a vendor resource type that needs to be handled by
  39. * remoteproc implementations before loading
  40. * @RSC_POSTLOAD_VENDOR: a vendor resource type that needs to be handled by
  41. * remoteproc implementations after loading
  42. * @RSC_LAST: just keep this one at the end
  43. *
  44. * For more details regarding a specific resource type, please see its
  45. * dedicated structure below.
  46. *
  47. * Please note that these values are used as indices to the rproc_handle_rsc
  48. * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
  49. * check the validity of an index before the lookup table is accessed, so
  50. * please update it as needed.
  51. */
  52. enum fw_resource_type {
  53. RSC_CARVEOUT = 0,
  54. RSC_DEVMEM = 1,
  55. RSC_TRACE = 2,
  56. RSC_VDEV = 3,
  57. RSC_PRELOAD_VENDOR = 4,
  58. RSC_POSTLOAD_VENDOR = 5,
  59. RSC_LAST = 6,
  60. };
  61. #define FW_RSC_ADDR_ANY (-1)
  62. /**
  63. * struct fw_rsc_carveout - physically contiguous memory request
  64. * @da: device address
  65. * @pa: physical address
  66. * @len: length (in bytes)
  67. * @flags: iommu protection flags
  68. * @reserved: reserved (must be zero)
  69. * @name: human-readable name of the requested memory region
  70. *
  71. * This resource entry requests the host to allocate a physically contiguous
  72. * memory region.
  73. *
  74. * These request entries should precede other firmware resource entries,
  75. * as other entries might request placing other data objects inside
  76. * these memory regions (e.g. data/code segments, trace resource entries, ...).
  77. *
  78. * Allocating memory this way helps utilizing the reserved physical memory
  79. * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
  80. * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
  81. * pressure is important; it may have a substantial impact on performance.
  82. *
  83. * If the firmware is compiled with static addresses, then @da should specify
  84. * the expected device address of this memory region. If @da is set to
  85. * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
  86. * overwrite @da with the dynamically allocated address.
  87. *
  88. * We will always use @da to negotiate the device addresses, even if it
  89. * isn't using an iommu. In that case, though, it will obviously contain
  90. * physical addresses.
  91. *
  92. * Some remote processors needs to know the allocated physical address
  93. * even if they do use an iommu. This is needed, e.g., if they control
  94. * hardware accelerators which access the physical memory directly (this
  95. * is the case with OMAP4 for instance). In that case, the host will
  96. * overwrite @pa with the dynamically allocated physical address.
  97. * Generally we don't want to expose physical addresses if we don't have to
  98. * (remote processors are generally _not_ trusted), so we might want to
  99. * change this to happen _only_ when explicitly required by the hardware.
  100. *
  101. * @flags is used to provide IOMMU protection flags, and @name should
  102. * (optionally) contain a human readable name of this carveout region
  103. * (mainly for debugging purposes).
  104. */
  105. struct fw_rsc_carveout {
  106. u32 da;
  107. u32 pa;
  108. u32 len;
  109. u32 flags;
  110. u32 reserved;
  111. u8 name[32];
  112. };
  113. /**
  114. * struct fw_rsc_devmem - iommu mapping request
  115. * @da: device address
  116. * @pa: physical address
  117. * @len: length (in bytes)
  118. * @flags: iommu protection flags
  119. * @reserved: reserved (must be zero)
  120. * @name: human-readable name of the requested region to be mapped
  121. *
  122. * This resource entry requests the host to iommu map a physically contiguous
  123. * memory region. This is needed in case the remote processor requires
  124. * access to certain memory-based peripherals; _never_ use it to access
  125. * regular memory.
  126. *
  127. * This is obviously only needed if the remote processor is accessing memory
  128. * via an iommu.
  129. *
  130. * @da should specify the required device address, @pa should specify
  131. * the physical address we want to map, @len should specify the size of
  132. * the mapping and @flags is the IOMMU protection flags. As always, @name may
  133. * (optionally) contain a human readable name of this mapping (mainly for
  134. * debugging purposes).
  135. *
  136. * Note: at this point we just "trust" those devmem entries to contain valid
  137. * physical addresses, but this isn't safe and will be changed: eventually we
  138. * want remoteproc implementations to provide us ranges of physical addresses
  139. * the firmware is allowed to request, and not allow firmwares to request
  140. * access to physical addresses that are outside those ranges.
  141. */
  142. struct fw_rsc_devmem {
  143. u32 da;
  144. u32 pa;
  145. u32 len;
  146. u32 flags;
  147. u32 reserved;
  148. u8 name[32];
  149. };
  150. /**
  151. * struct fw_rsc_trace - trace buffer declaration
  152. * @da: device address
  153. * @len: length (in bytes)
  154. * @reserved: reserved (must be zero)
  155. * @name: human-readable name of the trace buffer
  156. *
  157. * This resource entry provides the host information about a trace buffer
  158. * into which the remote processor will write log messages.
  159. *
  160. * @da specifies the device address of the buffer, @len specifies
  161. * its size, and @name may contain a human readable name of the trace buffer.
  162. *
  163. * After booting the remote processor, the trace buffers are exposed to the
  164. * user via debugfs entries (called trace0, trace1, etc..).
  165. */
  166. struct fw_rsc_trace {
  167. u32 da;
  168. u32 len;
  169. u32 reserved;
  170. u8 name[32];
  171. };
  172. /**
  173. * struct fw_rsc_vdev_vring - vring descriptor entry
  174. * @da: device address
  175. * @align: the alignment between the consumer and producer parts of the vring
  176. * @num: num of buffers supported by this vring (must be power of two)
  177. * @notifyid is a unique rproc-wide notify index for this vring. This notify
  178. * index is used when kicking a remote processor, to let it know that this
  179. * vring is triggered.
  180. * @pa: physical address
  181. *
  182. * This descriptor is not a resource entry by itself; it is part of the
  183. * vdev resource type (see below).
  184. *
  185. * Note that @da should either contain the device address where
  186. * the remote processor is expecting the vring, or indicate that
  187. * dynamically allocation of the vring's device address is supported.
  188. */
  189. struct fw_rsc_vdev_vring {
  190. u32 da;
  191. u32 align;
  192. u32 num;
  193. u32 notifyid;
  194. u32 pa;
  195. };
  196. /**
  197. * struct fw_rsc_vdev - virtio device header
  198. * @id: virtio device id (as in virtio_ids.h)
  199. * @notifyid is a unique rproc-wide notify index for this vdev. This notify
  200. * index is used when kicking a remote processor, to let it know that the
  201. * status/features of this vdev have changes.
  202. * @dfeatures specifies the virtio device features supported by the firmware
  203. * @gfeatures is a place holder used by the host to write back the
  204. * negotiated features that are supported by both sides.
  205. * @config_len is the size of the virtio config space of this vdev. The config
  206. * space lies in the resource table immediate after this vdev header.
  207. * @status is a place holder where the host will indicate its virtio progress.
  208. * @num_of_vrings indicates how many vrings are described in this vdev header
  209. * @reserved: reserved (must be zero)
  210. * @vring is an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'.
  211. *
  212. * This resource is a virtio device header: it provides information about
  213. * the vdev, and is then used by the host and its peer remote processors
  214. * to negotiate and share certain virtio properties.
  215. *
  216. * By providing this resource entry, the firmware essentially asks remoteproc
  217. * to statically allocate a vdev upon registration of the rproc (dynamic vdev
  218. * allocation is not yet supported).
  219. *
  220. * Note: unlike virtualization systems, the term 'host' here means
  221. * the Linux side which is running remoteproc to control the remote
  222. * processors. We use the name 'gfeatures' to comply with virtio's terms,
  223. * though there isn't really any virtualized guest OS here: it's the host
  224. * which is responsible for negotiating the final features.
  225. * Yeah, it's a bit confusing.
  226. *
  227. * Note: immediately following this structure is the virtio config space for
  228. * this vdev (which is specific to the vdev; for more info, read the virtio
  229. * spec). the size of the config space is specified by @config_len.
  230. */
  231. struct fw_rsc_vdev {
  232. u32 id;
  233. u32 notifyid;
  234. u32 dfeatures;
  235. u32 gfeatures;
  236. u32 config_len;
  237. u8 status;
  238. u8 num_of_vrings;
  239. u8 reserved[2];
  240. struct fw_rsc_vdev_vring vring[0];
  241. };
  242. /**
  243. * struct rproc_mem_entry - memory entry descriptor
  244. * @va: virtual address
  245. * @dma: dma address
  246. * @len: length, in bytes
  247. * @da: device address
  248. * @priv: associated data
  249. * @name: associated memory region name (optional)
  250. * @node: list node
  251. */
  252. struct rproc_mem_entry {
  253. void *va;
  254. dma_addr_t dma;
  255. int len;
  256. u32 da;
  257. void *priv;
  258. char name[32];
  259. struct list_head node;
  260. };
  261. struct rproc;
  262. typedef u32(*init_func_proto) (u32 core_id, struct rproc *cfg);
  263. struct l3_map {
  264. u32 priv_addr;
  265. u32 l3_addr;
  266. u32 len;
  267. };
  268. struct rproc_intmem_to_l3_mapping {
  269. u32 num_entries;
  270. struct l3_map mappings[16];
  271. };
  272. /**
  273. * enum rproc_crash_type - remote processor crash types
  274. * @RPROC_MMUFAULT: iommu fault
  275. * @RPROC_WATCHDOG: watchdog bite
  276. * @RPROC_FATAL_ERROR fatal error
  277. *
  278. * Each element of the enum is used as an array index. So that, the value of
  279. * the elements should be always something sane.
  280. *
  281. * Feel free to add more types when needed.
  282. */
  283. enum rproc_crash_type {
  284. RPROC_MMUFAULT,
  285. RPROC_WATCHDOG,
  286. RPROC_FATAL_ERROR,
  287. };
  288. /* we currently support only two vrings per rvdev */
  289. #define RVDEV_NUM_VRINGS 2
  290. #define RPMSG_NUM_BUFS (512)
  291. #define RPMSG_BUF_SIZE (512)
  292. #define RPMSG_TOTAL_BUF_SPACE (RPMSG_NUM_BUFS * RPMSG_BUF_SIZE)
  293. /**
  294. * struct rproc_vring - remoteproc vring state
  295. * @va: virtual address
  296. * @dma: dma address
  297. * @len: length, in bytes
  298. * @da: device address
  299. * @align: vring alignment
  300. * @notifyid: rproc-specific unique vring index
  301. * @rvdev: remote vdev
  302. * @vq: the virtqueue of this vring
  303. */
  304. struct rproc_vring {
  305. void *va;
  306. dma_addr_t dma;
  307. int len;
  308. u32 da;
  309. u32 align;
  310. int notifyid;
  311. struct rproc_vdev *rvdev;
  312. struct virtqueue *vq;
  313. };
  314. /** struct rproc - structure with all processor specific information for
  315. * loading remotecore from boot loader.
  316. *
  317. * @num_iommus: Number of IOMMUs for this remote core. Zero indicates that the
  318. * processor does not have an IOMMU.
  319. *
  320. * @cma_base: Base address of the carveout for this remotecore.
  321. *
  322. * @cma_size: Length of the carveout in bytes.
  323. *
  324. * @page_table_addr: array with the physical address of the page table. We are
  325. * using the same page table for both IOMMU's. There is currently no strong
  326. * usecase for maintaining different page tables for different MMU's servicing
  327. * the same CPU.
  328. *
  329. * @mmu_base_addr: base address of the MMU
  330. *
  331. * @entry_point: address that is the entry point for the remote core. This
  332. * address is in the memory view of the remotecore.
  333. *
  334. * @load_addr: Address to which the bootloader loads the firmware from
  335. * persistent storage before invoking the ELF loader. Keeping this address
  336. * configurable allows future optimizations such as loading the firmware from
  337. * storage for remotecore2 via EDMA while the CPU is processing the ELF image
  338. * of remotecore1. This address is in the memory view of the A15.
  339. *
  340. * @firmware_name: Name of the file that is expected to contain the ELF image.
  341. *
  342. * @has_rsc_table: Flag populated after parsing the ELF binary on target.
  343. */
  344. struct rproc {
  345. u32 num_iommus;
  346. unsigned long cma_base;
  347. u32 cma_size;
  348. unsigned long page_table_addr;
  349. unsigned long mmu_base_addr[2];
  350. unsigned long load_addr;
  351. unsigned long entry_point;
  352. char *core_name;
  353. char *firmware_name;
  354. char *ptn;
  355. init_func_proto start_clocks;
  356. init_func_proto config_mmu;
  357. init_func_proto config_peripherals;
  358. init_func_proto start_core;
  359. u32 has_rsc_table;
  360. struct rproc_intmem_to_l3_mapping *intmem_to_l3_mapping;
  361. u32 trace_pa;
  362. u32 trace_len;
  363. };
  364. extern struct rproc *rproc_cfg_arr[2];
  365. /**
  366. * enum rproc_mem_type - What type of memory model does the rproc use
  367. * @RPROC_INTERNAL_MEMORY_MAPPED: Remote processor uses own memory and is memory
  368. * mapped to the host processor over an address range.
  369. *
  370. * Please note that this is an enumeration of memory model of different types
  371. * of remote processors. Few of the remote processors do have own internal
  372. * memories, while others use external memory for instruction and data.
  373. */
  374. enum rproc_mem_type {
  375. RPROC_INTERNAL_MEMORY_MAPPED = 0,
  376. };
  377. /**
  378. * struct dm_rproc_uclass_pdata - platform data for a CPU
  379. * @name: Platform-specific way of naming the Remote proc
  380. * @mem_type: one of 'enum rproc_mem_type'
  381. * @driver_plat_data: driver specific platform data that may be needed.
  382. *
  383. * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
  384. * device.
  385. *
  386. */
  387. struct dm_rproc_uclass_pdata {
  388. const char *name;
  389. enum rproc_mem_type mem_type;
  390. void *driver_plat_data;
  391. };
  392. /**
  393. * struct dm_rproc_ops - Driver model remote proc operations.
  394. *
  395. * This defines the operations provided by remote proc driver.
  396. */
  397. struct dm_rproc_ops {
  398. /**
  399. * init() - Initialize the remoteproc device (optional)
  400. *
  401. * This is called after the probe is completed allowing the remote
  402. * processor drivers to split up the initializations between probe and
  403. * init if needed.
  404. *
  405. * @dev: Remote proc device
  406. * @return 0 if all ok, else appropriate error value.
  407. */
  408. int (*init)(struct udevice *dev);
  409. /**
  410. * load() - Load the remoteproc device using data provided (mandatory)
  411. *
  412. * Load the remoteproc device with an image, do not start the device.
  413. *
  414. * @dev: Remote proc device
  415. * @addr: Address of the image to be loaded
  416. * @size: Size of the image to be loaded
  417. * @return 0 if all ok, else appropriate error value.
  418. */
  419. int (*load)(struct udevice *dev, ulong addr, ulong size);
  420. /**
  421. * start() - Start the remoteproc device (mandatory)
  422. *
  423. * @dev: Remote proc device
  424. * @return 0 if all ok, else appropriate error value.
  425. */
  426. int (*start)(struct udevice *dev);
  427. /**
  428. * stop() - Stop the remoteproc device (optional)
  429. *
  430. * @dev: Remote proc device
  431. * @return 0 if all ok, else appropriate error value.
  432. */
  433. int (*stop)(struct udevice *dev);
  434. /**
  435. * reset() - Reset the remoteproc device (optional)
  436. *
  437. * @dev: Remote proc device
  438. * @return 0 if all ok, else appropriate error value.
  439. */
  440. int (*reset)(struct udevice *dev);
  441. /**
  442. * is_running() - Check if the remote processor is running (optional)
  443. *
  444. * @dev: Remote proc device
  445. * @return 0 if running, 1 if not running, -ve on error.
  446. */
  447. int (*is_running)(struct udevice *dev);
  448. /**
  449. * ping() - Ping the remote device for basic communication (optional)
  450. *
  451. * @dev: Remote proc device
  452. * @return 0 on success, 1 if not responding, -ve on other errors.
  453. */
  454. int (*ping)(struct udevice *dev);
  455. /**
  456. * device_to_virt() - Return translated virtual address (optional)
  457. *
  458. * Translate a device address (remote processor view) to virtual
  459. * address (main processor view).
  460. *
  461. * @dev: Remote proc device
  462. * @da: Device address
  463. * @size: Size of the memory region @da is pointing to
  464. * @return virtual address.
  465. */
  466. void * (*device_to_virt)(struct udevice *dev, ulong da, ulong size);
  467. int (*add_res)(struct udevice *dev,
  468. struct rproc_mem_entry *mapping);
  469. void * (*alloc_mem)(struct udevice *dev, unsigned long len,
  470. unsigned long align);
  471. unsigned int (*config_pagetable)(struct udevice *dev, unsigned int virt,
  472. unsigned int phys, unsigned int len);
  473. };
  474. /* Accessor */
  475. #define rproc_get_ops(dev) ((struct dm_rproc_ops *)(dev)->driver->ops)
  476. #if CONFIG_IS_ENABLED(REMOTEPROC)
  477. /**
  478. * rproc_init() - Initialize all bound remote proc devices
  479. * Return: 0 if all ok, else appropriate error value.
  480. */
  481. int rproc_init(void);
  482. /**
  483. * rproc_dev_init() - Initialize a remote proc device based on id
  484. * @id: id of the remote processor
  485. * Return: 0 if all ok, else appropriate error value.
  486. */
  487. int rproc_dev_init(int id);
  488. /**
  489. * rproc_is_initialized() - check to see if remoteproc devices are initialized
  490. * Return: true if all devices are initialized, false otherwise.
  491. */
  492. bool rproc_is_initialized(void);
  493. /**
  494. * rproc_load() - load binary or elf to a remote processor
  495. * @id: id of the remote processor
  496. * @addr: address in memory where the image is located
  497. * @size: size of the image
  498. * Return: 0 if all ok, else appropriate error value.
  499. */
  500. int rproc_load(int id, ulong addr, ulong size);
  501. /**
  502. * rproc_start() - Start a remote processor
  503. * @id: id of the remote processor
  504. * Return: 0 if all ok, else appropriate error value.
  505. */
  506. int rproc_start(int id);
  507. /**
  508. * rproc_stop() - Stop a remote processor
  509. * @id: id of the remote processor
  510. * Return: 0 if all ok, else appropriate error value.
  511. */
  512. int rproc_stop(int id);
  513. /**
  514. * rproc_reset() - reset a remote processor
  515. * @id: id of the remote processor
  516. * Return: 0 if all ok, else appropriate error value.
  517. */
  518. int rproc_reset(int id);
  519. /**
  520. * rproc_ping() - ping a remote processor to check if it can communicate
  521. * @id: id of the remote processor
  522. * Return: 0 if all ok, else appropriate error value.
  523. *
  524. * NOTE: this might need communication path available, which is not implemented
  525. * as part of remoteproc framework - hook on to appropriate bus architecture to
  526. * do the same
  527. */
  528. int rproc_ping(int id);
  529. /**
  530. * rproc_is_running() - check to see if remote processor is running
  531. * @id: id of the remote processor
  532. * Return: 0 if running, 1 if not running, -ve on error.
  533. *
  534. * NOTE: this may not involve actual communication capability of the remote
  535. * processor, but just ensures that it is out of reset and executing code.
  536. */
  537. int rproc_is_running(int id);
  538. /**
  539. * rproc_elf32_sanity_check() - Verify if an image is a valid ELF32 one
  540. *
  541. * Check if a valid ELF32 image exists at the given memory location. Verify
  542. * basic ELF32 format requirements like magic number and sections size.
  543. *
  544. * @addr: address of the image to verify
  545. * @size: size of the image
  546. * Return: 0 if the image looks good, else appropriate error value.
  547. */
  548. int rproc_elf32_sanity_check(ulong addr, ulong size);
  549. /**
  550. * rproc_elf64_sanity_check() - Verify if an image is a valid ELF32 one
  551. *
  552. * Check if a valid ELF64 image exists at the given memory location. Verify
  553. * basic ELF64 format requirements like magic number and sections size.
  554. *
  555. * @addr: address of the image to verify
  556. * @size: size of the image
  557. * Return: 0 if the image looks good, else appropriate error value.
  558. */
  559. int rproc_elf64_sanity_check(ulong addr, ulong size);
  560. /**
  561. * rproc_elf32_load_image() - load an ELF32 image
  562. * @dev: device loading the ELF32 image
  563. * @addr: valid ELF32 image address
  564. * @size: size of the image
  565. * Return: 0 if the image is successfully loaded, else appropriate error value.
  566. */
  567. int rproc_elf32_load_image(struct udevice *dev, unsigned long addr, ulong size);
  568. /**
  569. * rproc_elf64_load_image() - load an ELF64 image
  570. * @dev: device loading the ELF64 image
  571. * @addr: valid ELF64 image address
  572. * @size: size of the image
  573. * Return: 0 if the image is successfully loaded, else appropriate error value.
  574. */
  575. int rproc_elf64_load_image(struct udevice *dev, ulong addr, ulong size);
  576. /**
  577. * rproc_elf_load_image() - load an ELF image
  578. * @dev: device loading the ELF image
  579. * @addr: valid ELF image address
  580. * @size: size of the image
  581. *
  582. * Auto detects if the image is ELF32 or ELF64 image and load accordingly.
  583. * Return: 0 if the image is successfully loaded, else appropriate error value.
  584. */
  585. int rproc_elf_load_image(struct udevice *dev, unsigned long addr, ulong size);
  586. /**
  587. * rproc_elf_get_boot_addr() - Get rproc's boot address.
  588. * @dev: device loading the ELF image
  589. * @addr: valid ELF image address
  590. *
  591. * This function returns the entry point address of the ELF
  592. * image.
  593. */
  594. ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr);
  595. /**
  596. * rproc_elf32_load_rsc_table() - load the resource table from an ELF32 image
  597. *
  598. * Search for the resource table in an ELF32 image, and if found, copy it to
  599. * device memory.
  600. *
  601. * @dev: device loading the resource table
  602. * @fw_addr: ELF image address
  603. * @fw_size: size of the ELF image
  604. * @rsc_addr: pointer to the found resource table address. Updated on
  605. * operation success
  606. * @rsc_size: pointer to the found resource table size. Updated on operation
  607. * success
  608. *
  609. * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
  610. * is no resource table (which is optional), or another appropriate error value.
  611. */
  612. int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  613. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  614. /**
  615. * rproc_elf64_load_rsc_table() - load the resource table from an ELF64 image
  616. *
  617. * Search for the resource table in an ELF64 image, and if found, copy it to
  618. * device memory.
  619. *
  620. * @dev: device loading the resource table
  621. * @fw_addr: ELF image address
  622. * @fw_size: size of the ELF image
  623. * @rsc_addr: pointer to the found resource table address. Updated on
  624. * operation success
  625. * @rsc_size: pointer to the found resource table size. Updated on operation
  626. * success
  627. *
  628. * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
  629. * is no resource table (which is optional), or another appropriate error value.
  630. */
  631. int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
  632. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  633. /**
  634. * rproc_elf_load_rsc_table() - load the resource table from an ELF image
  635. *
  636. * Auto detects if the image is ELF32 or ELF64 image and search accordingly for
  637. * the resource table, and if found, copy it to device memory.
  638. *
  639. * @dev: device loading the resource table
  640. * @fw_addr: ELF image address
  641. * @fw_size: size of the ELF image
  642. * @rsc_addr: pointer to the found resource table address. Updated on
  643. * operation success
  644. * @rsc_size: pointer to the found resource table size. Updated on operation
  645. * success
  646. *
  647. * Return: 0 if a valid resource table is successfully loaded, -ENODATA if there
  648. * is no resource table (which is optional), or another appropriate error value.
  649. */
  650. int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
  651. ulong fw_size, ulong *rsc_addr, ulong *rsc_size);
  652. unsigned long rproc_parse_resource_table(struct udevice *dev,
  653. struct rproc *cfg);
  654. struct resource_table *rproc_find_resource_table(struct udevice *dev,
  655. unsigned int addr,
  656. int *tablesz);
  657. #else
  658. static inline int rproc_init(void) { return -ENOSYS; }
  659. static inline int rproc_dev_init(int id) { return -ENOSYS; }
  660. static inline bool rproc_is_initialized(void) { return false; }
  661. static inline int rproc_load(int id, ulong addr, ulong size) { return -ENOSYS; }
  662. static inline int rproc_start(int id) { return -ENOSYS; }
  663. static inline int rproc_stop(int id) { return -ENOSYS; }
  664. static inline int rproc_reset(int id) { return -ENOSYS; }
  665. static inline int rproc_ping(int id) { return -ENOSYS; }
  666. static inline int rproc_is_running(int id) { return -ENOSYS; }
  667. static inline int rproc_elf32_sanity_check(ulong addr,
  668. ulong size) { return -ENOSYS; }
  669. static inline int rproc_elf64_sanity_check(ulong addr,
  670. ulong size) { return -ENOSYS; }
  671. static inline int rproc_elf_sanity_check(ulong addr,
  672. ulong size) { return -ENOSYS; }
  673. static inline int rproc_elf32_load_image(struct udevice *dev,
  674. unsigned long addr, ulong size)
  675. { return -ENOSYS; }
  676. static inline int rproc_elf64_load_image(struct udevice *dev, ulong addr,
  677. ulong size)
  678. { return -ENOSYS; }
  679. static inline int rproc_elf_load_image(struct udevice *dev, ulong addr,
  680. ulong size)
  681. { return -ENOSYS; }
  682. static inline ulong rproc_elf_get_boot_addr(struct udevice *dev, ulong addr)
  683. { return 0; }
  684. static inline int rproc_elf32_load_rsc_table(struct udevice *dev, ulong fw_addr,
  685. ulong fw_size, ulong *rsc_addr,
  686. ulong *rsc_size)
  687. { return -ENOSYS; }
  688. static inline int rproc_elf64_load_rsc_table(struct udevice *dev, ulong fw_addr,
  689. ulong fw_size, ulong *rsc_addr,
  690. ulong *rsc_size)
  691. { return -ENOSYS; }
  692. static inline int rproc_elf_load_rsc_table(struct udevice *dev, ulong fw_addr,
  693. ulong fw_size, ulong *rsc_addr,
  694. ulong *rsc_size)
  695. { return -ENOSYS; }
  696. #endif
  697. #endif /* _RPROC_H_ */