You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
7.1 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __ELF_FILE_LOADER_HEADER__
  2. #define __ELF_FILE_LOADER_HEADER__
  3. #define pr_fmt(fmt) "%s: " fmt, __func__
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #include <elf.h>
  7. #include <libelf.h>
  8. //#include <linux/module.h>
  9. //#include <linux/firmware.h>
  10. struct firmware {
  11. size_t size;
  12. const uint8_t *data;
  13. struct page **pages;
  14. /* firmware loader private fields */
  15. void *priv;
  16. };
  17. //#include <linux/remoteproc.h>
  18. /**
  19. * struct resource_table - firmware resource table header
  20. * @ver: version number
  21. * @num: number of resource entries
  22. * @reserved: reserved (must be zero)
  23. * @offset: array of offsets pointing at the various resource entries
  24. *
  25. * A resource table is essentially a list of system resources required
  26. * by the remote processor. It may also include configuration entries.
  27. * If needed, the remote processor firmware should contain this table
  28. * as a dedicated ".resource_table" ELF section.
  29. *
  30. * Some resources entries are mere announcements, where the host is informed
  31. * of specific remoteproc configuration. Other entries require the host to
  32. * do something (e.g. allocate a system resource). Sometimes a negotiation
  33. * is expected, where the firmware requests a resource, and once allocated,
  34. * the host should provide back its details (e.g. address of an allocated
  35. * memory region).
  36. *
  37. * The header of the resource table, as expressed by this structure,
  38. * contains a version number (should we need to change this format in the
  39. * future), the number of available resource entries, and their offsets
  40. * in the table.
  41. *
  42. * Immediately following this header are the resource entries themselves,
  43. * each of which begins with a resource entry header (as described below).
  44. */
  45. struct resource_table {
  46. uint32_t ver;
  47. uint32_t num;
  48. uint32_t reserved[2];
  49. uint32_t offset[0];
  50. };// __packed;
  51. /**
  52. * struct fw_rsc_hdr - firmware resource entry header
  53. * @type: resource type
  54. * @data: resource data
  55. *
  56. * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
  57. * its @type. The content of the entry itself will immediately follow
  58. * this header, and it should be parsed according to the resource type.
  59. */
  60. struct fw_rsc_hdr {
  61. uint32_t type;
  62. uint8_t data[0];
  63. };// __packed;
  64. /**
  65. * enum fw_resource_type - types of resource entries
  66. *
  67. * @RSC_CARVEOUT: request for allocation of a physically contiguous
  68. * memory region.
  69. * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
  70. * @RSC_TRACE: announces the availability of a trace buffer into which
  71. * the remote processor will be writing logs.
  72. * @RSC_VDEV: declare support for a virtio device, and serve as its
  73. * virtio header.
  74. * @RSC_INTMEM: (deprecated) request to map into kernel an internal memory
  75. * region.
  76. * @RSC_CUSTOM: a custom resource type that needs to be handled outside
  77. * remoteproc core.
  78. * @RSC_LAST: just keep this one at the end
  79. *
  80. * For more details regarding a specific resource type, please see its
  81. * dedicated structure below.
  82. *
  83. * Please note that these values are used as indices to the rproc_handle_rsc
  84. * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
  85. * check the validity of an index before the lookup table is accessed, so
  86. * please update it as needed.
  87. */
  88. enum fw_resource_type {
  89. RSC_CARVEOUT = 0,
  90. RSC_DEVMEM = 1,
  91. RSC_TRACE = 2,
  92. RSC_VDEV = 3,
  93. RSC_INTMEM = 4,
  94. RSC_CUSTOM = 5,
  95. RSC_LAST = 6,
  96. };
  97. /* PRU_ICSS_PRU_CTRL registers */
  98. #define PRU_CTRL_CTRL 0x0000
  99. #define PRU_CTRL_STS 0x0004
  100. #define PRU_CTRL_WAKEUP_EN 0x0008
  101. #define PRU_CTRL_CYCLE 0x000C
  102. #define PRU_CTRL_STALL 0x0010
  103. #define PRU_CTRL_CTBIR0 0x0020
  104. #define PRU_CTRL_CTBIR1 0x0024
  105. #define PRU_CTRL_CTPPR0 0x0028
  106. #define PRU_CTRL_CTPPR1 0x002C
  107. /* CTRL register bit-fields */
  108. #define CTRL_CTRL_SOFT_RST_N BIT(0)
  109. #define CTRL_CTRL_EN BIT(1)
  110. #define CTRL_CTRL_SLEEPING BIT(2)
  111. #define CTRL_CTRL_CTR_EN BIT(3)
  112. #define CTRL_CTRL_SINGLE_STEP BIT(8)
  113. #define CTRL_CTRL_RUNSTATE BIT(15)
  114. /* PRU_ICSS_PRU_DEBUG registers */
  115. #define PRU_DEBUG_GPREG(x) (0x0000 + (x) * 4)
  116. #define PRU_DEBUG_CT_REG(x) (0x0080 + (x) * 4)
  117. /**
  118. * enum pru_mem - PRU core memory range identifiers
  119. */
  120. enum pru_mem {
  121. PRU_MEM_IRAM = 0,
  122. PRU_MEM_CTRL,
  123. PRU_MEM_DEBUG,
  124. PRU_MEM_MAX,
  125. };
  126. /**
  127. * struct pru_private_data - PRU core private data
  128. * @id: PRU index
  129. * @fw_name: firmware name to be used for the PRU core
  130. * @eth_fw_name: firmware name to be used for PRUSS ethernet usecases on IDKs
  131. */
  132. struct pru_private_data {
  133. uint32_t id;
  134. const char *fw_name;
  135. const char *eth_fw_name;
  136. };
  137. /**
  138. * struct pru_match_private_data - match private data to handle multiple instances
  139. * @device_name: device name of the PRU processor core instance
  140. * @priv_data: PRU driver private data for this PRU processor core instance
  141. */
  142. struct pru_match_private_data {
  143. const char *device_name;
  144. struct pru_private_data *priv_data;
  145. };
  146. /**
  147. * struct pru_rproc: PRU remoteproc structure
  148. * @id: id of the PRU core within the PRUSS
  149. * @pruss: back-reference to parent PRUSS structure
  150. * @rproc: remoteproc pointer for this PRU core
  151. * @mbox: mailbox channel handle used for vring signalling with MPU
  152. * @client: mailbox client to request the mailbox channel
  153. * @mem_regions: data for each of the PRU memory regions
  154. * @intc_config: PRU INTC configuration data
  155. * @rmw_lock: lock for read, modify, write operations on registers
  156. * @iram_da: device address of Instruction RAM for this PRU
  157. * @pdram_da: device address of primary Data RAM for this PRU
  158. * @sdram_da: device address of secondary Data RAM for this PRU
  159. * @shrdram_da: device address of shared Data RAM
  160. * @fw_name: name of firmware image used during loading
  161. * @dbg_single_step: debug flag to set PRU into single step mode
  162. * @dbg_continuous: debug flag to restore PRU execution mode
  163. */
  164. /* struct pru_rproc {
  165. int id;
  166. struct pruss *pruss;
  167. struct rproc *rproc;
  168. struct mbox_chan *mbox;
  169. struct mbox_client client;
  170. struct pruss_mem_region mem_regions[PRU_MEM_MAX];
  171. struct pruss_intc_config intc_config;
  172. spinlock_t rmw_lock; // register access lock
  173. uint32_t iram_da;
  174. uint32_t pdram_da;
  175. uint32_t sdram_da;
  176. uint32_t shrdram_da;
  177. const char *fw_name;
  178. uint32_t dbg_single_step;
  179. uint32_t dbg_continuous;
  180. };
  181. //#include <linux/elf.h>
  182. //#include "remoteproc_internal.h"
  183. int load_elf_fw( const char *name, const struct firmware *fw );
  184. int elf_sanity_check( const struct firmware *fw );
  185. uint32_t elf_get_boot_addr( const struct firmware *fw );
  186. int elf_load_segments( const struct firmware *fw );
  187. */
  188. #endif