remoteproc.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * Remote Processor Framework
  3. *
  4. * Copyright(c) 2011 Texas Instruments, Inc.
  5. * Copyright(c) 2011 Google, Inc.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * * Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * * Neither the name Texas Instruments nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef REMOTEPROC_H
  35. #define REMOTEPROC_H
  36. #include <linux/types.h>
  37. #include <linux/mutex.h>
  38. #include <linux/virtio.h>
  39. #include <linux/cdev.h>
  40. #include <linux/completion.h>
  41. #include <linux/idr.h>
  42. #include <linux/of.h>
  43. /**
  44. * struct resource_table - firmware resource table header
  45. * @ver: version number
  46. * @num: number of resource entries
  47. * @reserved: reserved (must be zero)
  48. * @offset: array of offsets pointing at the various resource entries
  49. *
  50. * A resource table is essentially a list of system resources required
  51. * by the remote processor. It may also include configuration entries.
  52. * If needed, the remote processor firmware should contain this table
  53. * as a dedicated ".resource_table" ELF section.
  54. *
  55. * Some resources entries are mere announcements, where the host is informed
  56. * of specific remoteproc configuration. Other entries require the host to
  57. * do something (e.g. allocate a system resource). Sometimes a negotiation
  58. * is expected, where the firmware requests a resource, and once allocated,
  59. * the host should provide back its details (e.g. address of an allocated
  60. * memory region).
  61. *
  62. * The header of the resource table, as expressed by this structure,
  63. * contains a version number (should we need to change this format in the
  64. * future), the number of available resource entries, and their offsets
  65. * in the table.
  66. *
  67. * Immediately following this header are the resource entries themselves,
  68. * each of which begins with a resource entry header (as described below).
  69. */
  70. struct resource_table {
  71. u32 ver;
  72. u32 num;
  73. u32 reserved[2];
  74. u32 offset[];
  75. } __packed;
  76. /**
  77. * struct fw_rsc_hdr - firmware resource entry header
  78. * @type: resource type
  79. * @data: resource data
  80. *
  81. * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
  82. * its @type. The content of the entry itself will immediately follow
  83. * this header, and it should be parsed according to the resource type.
  84. */
  85. struct fw_rsc_hdr {
  86. u32 type;
  87. u8 data[];
  88. } __packed;
  89. /**
  90. * enum fw_resource_type - types of resource entries
  91. *
  92. * @RSC_CARVEOUT: request for allocation of a physically contiguous
  93. * memory region.
  94. * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
  95. * @RSC_TRACE: announces the availability of a trace buffer into which
  96. * the remote processor will be writing logs.
  97. * @RSC_VDEV: declare support for a virtio device, and serve as its
  98. * virtio header.
  99. * @RSC_LAST: just keep this one at the end of standard resources
  100. * @RSC_VENDOR_START: start of the vendor specific resource types range
  101. * @RSC_VENDOR_END: end of the vendor specific resource types range
  102. *
  103. * For more details regarding a specific resource type, please see its
  104. * dedicated structure below.
  105. *
  106. * Please note that these values are used as indices to the rproc_handle_rsc
  107. * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
  108. * check the validity of an index before the lookup table is accessed, so
  109. * please update it as needed.
  110. */
  111. enum fw_resource_type {
  112. RSC_CARVEOUT = 0,
  113. RSC_DEVMEM = 1,
  114. RSC_TRACE = 2,
  115. RSC_VDEV = 3,
  116. RSC_LAST = 4,
  117. RSC_VENDOR_START = 128,
  118. RSC_VENDOR_END = 512,
  119. };
  120. #define FW_RSC_ADDR_ANY (-1)
  121. /**
  122. * struct fw_rsc_carveout - physically contiguous memory request
  123. * @da: device address
  124. * @pa: physical address
  125. * @len: length (in bytes)
  126. * @flags: iommu protection flags
  127. * @reserved: reserved (must be zero)
  128. * @name: human-readable name of the requested memory region
  129. *
  130. * This resource entry requests the host to allocate a physically contiguous
  131. * memory region.
  132. *
  133. * These request entries should precede other firmware resource entries,
  134. * as other entries might request placing other data objects inside
  135. * these memory regions (e.g. data/code segments, trace resource entries, ...).
  136. *
  137. * Allocating memory this way helps utilizing the reserved physical memory
  138. * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
  139. * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
  140. * pressure is important; it may have a substantial impact on performance.
  141. *
  142. * If the firmware is compiled with static addresses, then @da should specify
  143. * the expected device address of this memory region. If @da is set to
  144. * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
  145. * overwrite @da with the dynamically allocated address.
  146. *
  147. * We will always use @da to negotiate the device addresses, even if it
  148. * isn't using an iommu. In that case, though, it will obviously contain
  149. * physical addresses.
  150. *
  151. * Some remote processors needs to know the allocated physical address
  152. * even if they do use an iommu. This is needed, e.g., if they control
  153. * hardware accelerators which access the physical memory directly (this
  154. * is the case with OMAP4 for instance). In that case, the host will
  155. * overwrite @pa with the dynamically allocated physical address.
  156. * Generally we don't want to expose physical addresses if we don't have to
  157. * (remote processors are generally _not_ trusted), so we might want to
  158. * change this to happen _only_ when explicitly required by the hardware.
  159. *
  160. * @flags is used to provide IOMMU protection flags, and @name should
  161. * (optionally) contain a human readable name of this carveout region
  162. * (mainly for debugging purposes).
  163. */
  164. struct fw_rsc_carveout {
  165. u32 da;
  166. u32 pa;
  167. u32 len;
  168. u32 flags;
  169. u32 reserved;
  170. u8 name[32];
  171. } __packed;
  172. /**
  173. * struct fw_rsc_devmem - iommu mapping request
  174. * @da: device address
  175. * @pa: physical address
  176. * @len: length (in bytes)
  177. * @flags: iommu protection flags
  178. * @reserved: reserved (must be zero)
  179. * @name: human-readable name of the requested region to be mapped
  180. *
  181. * This resource entry requests the host to iommu map a physically contiguous
  182. * memory region. This is needed in case the remote processor requires
  183. * access to certain memory-based peripherals; _never_ use it to access
  184. * regular memory.
  185. *
  186. * This is obviously only needed if the remote processor is accessing memory
  187. * via an iommu.
  188. *
  189. * @da should specify the required device address, @pa should specify
  190. * the physical address we want to map, @len should specify the size of
  191. * the mapping and @flags is the IOMMU protection flags. As always, @name may
  192. * (optionally) contain a human readable name of this mapping (mainly for
  193. * debugging purposes).
  194. *
  195. * Note: at this point we just "trust" those devmem entries to contain valid
  196. * physical addresses, but this isn't safe and will be changed: eventually we
  197. * want remoteproc implementations to provide us ranges of physical addresses
  198. * the firmware is allowed to request, and not allow firmwares to request
  199. * access to physical addresses that are outside those ranges.
  200. */
  201. struct fw_rsc_devmem {
  202. u32 da;
  203. u32 pa;
  204. u32 len;
  205. u32 flags;
  206. u32 reserved;
  207. u8 name[32];
  208. } __packed;
  209. /**
  210. * struct fw_rsc_trace - trace buffer declaration
  211. * @da: device address
  212. * @len: length (in bytes)
  213. * @reserved: reserved (must be zero)
  214. * @name: human-readable name of the trace buffer
  215. *
  216. * This resource entry provides the host information about a trace buffer
  217. * into which the remote processor will write log messages.
  218. *
  219. * @da specifies the device address of the buffer, @len specifies
  220. * its size, and @name may contain a human readable name of the trace buffer.
  221. *
  222. * After booting the remote processor, the trace buffers are exposed to the
  223. * user via debugfs entries (called trace0, trace1, etc..).
  224. */
  225. struct fw_rsc_trace {
  226. u32 da;
  227. u32 len;
  228. u32 reserved;
  229. u8 name[32];
  230. } __packed;
  231. /**
  232. * struct fw_rsc_vdev_vring - vring descriptor entry
  233. * @da: device address
  234. * @align: the alignment between the consumer and producer parts of the vring
  235. * @num: num of buffers supported by this vring (must be power of two)
  236. * @notifyid: a unique rproc-wide notify index for this vring. This notify
  237. * index is used when kicking a remote processor, to let it know that this
  238. * vring is triggered.
  239. * @pa: physical address
  240. *
  241. * This descriptor is not a resource entry by itself; it is part of the
  242. * vdev resource type (see below).
  243. *
  244. * Note that @da should either contain the device address where
  245. * the remote processor is expecting the vring, or indicate that
  246. * dynamically allocation of the vring's device address is supported.
  247. */
  248. struct fw_rsc_vdev_vring {
  249. u32 da;
  250. u32 align;
  251. u32 num;
  252. u32 notifyid;
  253. u32 pa;
  254. } __packed;
  255. /**
  256. * struct fw_rsc_vdev - virtio device header
  257. * @id: virtio device id (as in virtio_ids.h)
  258. * @notifyid: a unique rproc-wide notify index for this vdev. This notify
  259. * index is used when kicking a remote processor, to let it know that the
  260. * status/features of this vdev have changes.
  261. * @dfeatures: specifies the virtio device features supported by the firmware
  262. * @gfeatures: a place holder used by the host to write back the
  263. * negotiated features that are supported by both sides.
  264. * @config_len: the size of the virtio config space of this vdev. The config
  265. * space lies in the resource table immediate after this vdev header.
  266. * @status: a place holder where the host will indicate its virtio progress.
  267. * @num_of_vrings: indicates how many vrings are described in this vdev header
  268. * @reserved: reserved (must be zero)
  269. * @vring: an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'.
  270. *
  271. * This resource is a virtio device header: it provides information about
  272. * the vdev, and is then used by the host and its peer remote processors
  273. * to negotiate and share certain virtio properties.
  274. *
  275. * By providing this resource entry, the firmware essentially asks remoteproc
  276. * to statically allocate a vdev upon registration of the rproc (dynamic vdev
  277. * allocation is not yet supported).
  278. *
  279. * Note:
  280. * 1. unlike virtualization systems, the term 'host' here means
  281. * the Linux side which is running remoteproc to control the remote
  282. * processors. We use the name 'gfeatures' to comply with virtio's terms,
  283. * though there isn't really any virtualized guest OS here: it's the host
  284. * which is responsible for negotiating the final features.
  285. * Yeah, it's a bit confusing.
  286. *
  287. * 2. immediately following this structure is the virtio config space for
  288. * this vdev (which is specific to the vdev; for more info, read the virtio
  289. * spec). The size of the config space is specified by @config_len.
  290. */
  291. struct fw_rsc_vdev {
  292. u32 id;
  293. u32 notifyid;
  294. u32 dfeatures;
  295. u32 gfeatures;
  296. u32 config_len;
  297. u8 status;
  298. u8 num_of_vrings;
  299. u8 reserved[2];
  300. struct fw_rsc_vdev_vring vring[];
  301. } __packed;
  302. struct rproc;
  303. /**
  304. * struct rproc_mem_entry - memory entry descriptor
  305. * @va: virtual address
  306. * @is_iomem: io memory
  307. * @dma: dma address
  308. * @len: length, in bytes
  309. * @da: device address
  310. * @release: release associated memory
  311. * @priv: associated data
  312. * @name: associated memory region name (optional)
  313. * @node: list node
  314. * @rsc_offset: offset in resource table
  315. * @flags: iommu protection flags
  316. * @of_resm_idx: reserved memory phandle index
  317. * @alloc: specific memory allocator function
  318. */
  319. struct rproc_mem_entry {
  320. void *va;
  321. bool is_iomem;
  322. dma_addr_t dma;
  323. size_t len;
  324. u32 da;
  325. void *priv;
  326. char name[32];
  327. struct list_head node;
  328. u32 rsc_offset;
  329. u32 flags;
  330. u32 of_resm_idx;
  331. int (*alloc)(struct rproc *rproc, struct rproc_mem_entry *mem);
  332. int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem);
  333. };
  334. struct firmware;
  335. /**
  336. * enum rsc_handling_status - return status of rproc_ops handle_rsc hook
  337. * @RSC_HANDLED: resource was handled
  338. * @RSC_IGNORED: resource was ignored
  339. */
  340. enum rsc_handling_status {
  341. RSC_HANDLED = 0,
  342. RSC_IGNORED = 1,
  343. };
  344. /**
  345. * struct rproc_ops - platform-specific device handlers
  346. * @prepare: prepare device for code loading
  347. * @unprepare: unprepare device after stop
  348. * @start: power on the device and boot it
  349. * @stop: power off the device
  350. * @attach: attach to a device that his already powered up
  351. * @detach: detach from a device, leaving it powered up
  352. * @kick: kick a virtqueue (virtqueue id given as a parameter)
  353. * @da_to_va: optional platform hook to perform address translations
  354. * @parse_fw: parse firmware to extract information (e.g. resource table)
  355. * @handle_rsc: optional platform hook to handle vendor resources. Should return
  356. * RSC_HANDLED if resource was handled, RSC_IGNORED if not handled
  357. * and a negative value on error
  358. * @find_loaded_rsc_table: find the loaded resource table from firmware image
  359. * @get_loaded_rsc_table: get resource table installed in memory
  360. * by external entity
  361. * @load: load firmware to memory, where the remote processor
  362. * expects to find it
  363. * @sanity_check: sanity check the fw image
  364. * @get_boot_addr: get boot address to entry point specified in firmware
  365. * @panic: optional callback to react to system panic, core will delay
  366. * panic at least the returned number of milliseconds
  367. * @coredump: collect firmware dump after the subsystem is shutdown
  368. */
  369. struct rproc_ops {
  370. int (*prepare)(struct rproc *rproc);
  371. int (*unprepare)(struct rproc *rproc);
  372. int (*start)(struct rproc *rproc);
  373. int (*stop)(struct rproc *rproc);
  374. int (*attach)(struct rproc *rproc);
  375. int (*detach)(struct rproc *rproc);
  376. void (*kick)(struct rproc *rproc, int vqid);
  377. void * (*da_to_va)(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
  378. int (*parse_fw)(struct rproc *rproc, const struct firmware *fw);
  379. int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc,
  380. int offset, int avail);
  381. struct resource_table *(*find_loaded_rsc_table)(
  382. struct rproc *rproc, const struct firmware *fw);
  383. struct resource_table *(*get_loaded_rsc_table)(
  384. struct rproc *rproc, size_t *size);
  385. int (*load)(struct rproc *rproc, const struct firmware *fw);
  386. int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
  387. u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
  388. unsigned long (*panic)(struct rproc *rproc);
  389. void (*coredump)(struct rproc *rproc);
  390. };
  391. /**
  392. * enum rproc_state - remote processor states
  393. * @RPROC_OFFLINE: device is powered off
  394. * @RPROC_SUSPENDED: device is suspended; needs to be woken up to receive
  395. * a message.
  396. * @RPROC_RUNNING: device is up and running
  397. * @RPROC_CRASHED: device has crashed; need to start recovery
  398. * @RPROC_DELETED: device is deleted
  399. * @RPROC_ATTACHED: device has been booted by another entity and the core
  400. * has attached to it
  401. * @RPROC_DETACHED: device has been booted by another entity and waiting
  402. * for the core to attach to it
  403. * @RPROC_LAST: just keep this one at the end
  404. *
  405. * Please note that the values of these states are used as indices
  406. * to rproc_state_string, a state-to-name lookup table,
  407. * so please keep the two synchronized. @RPROC_LAST is used to check
  408. * the validity of an index before the lookup table is accessed, so
  409. * please update it as needed too.
  410. */
  411. enum rproc_state {
  412. RPROC_OFFLINE = 0,
  413. RPROC_SUSPENDED = 1,
  414. RPROC_RUNNING = 2,
  415. RPROC_CRASHED = 3,
  416. RPROC_DELETED = 4,
  417. RPROC_ATTACHED = 5,
  418. RPROC_DETACHED = 6,
  419. RPROC_LAST = 7,
  420. };
  421. /**
  422. * enum rproc_crash_type - remote processor crash types
  423. * @RPROC_MMUFAULT: iommu fault
  424. * @RPROC_WATCHDOG: watchdog bite
  425. * @RPROC_FATAL_ERROR: fatal error
  426. *
  427. * Each element of the enum is used as an array index. So that, the value of
  428. * the elements should be always something sane.
  429. *
  430. * Feel free to add more types when needed.
  431. */
  432. enum rproc_crash_type {
  433. RPROC_MMUFAULT,
  434. RPROC_WATCHDOG,
  435. RPROC_FATAL_ERROR,
  436. };
  437. /**
  438. * enum rproc_dump_mechanism - Coredump options for core
  439. * @RPROC_COREDUMP_DISABLED: Don't perform any dump
  440. * @RPROC_COREDUMP_ENABLED: Copy dump to separate buffer and carry on with
  441. * recovery
  442. * @RPROC_COREDUMP_INLINE: Read segments directly from device memory. Stall
  443. * recovery until all segments are read
  444. */
  445. enum rproc_dump_mechanism {
  446. RPROC_COREDUMP_DISABLED,
  447. RPROC_COREDUMP_ENABLED,
  448. RPROC_COREDUMP_INLINE,
  449. };
  450. /**
  451. * struct rproc_dump_segment - segment info from ELF header
  452. * @node: list node related to the rproc segment list
  453. * @da: device address of the segment
  454. * @size: size of the segment
  455. * @priv: private data associated with the dump_segment
  456. * @dump: custom dump function to fill device memory segment associated
  457. * with coredump
  458. * @offset: offset of the segment
  459. */
  460. struct rproc_dump_segment {
  461. struct list_head node;
  462. dma_addr_t da;
  463. size_t size;
  464. void *priv;
  465. void (*dump)(struct rproc *rproc, struct rproc_dump_segment *segment,
  466. void *dest, size_t offset, size_t size);
  467. loff_t offset;
  468. };
  469. /**
  470. * enum rproc_features - features supported
  471. *
  472. * @RPROC_FEAT_ATTACH_ON_RECOVERY: The remote processor does not need help
  473. * from Linux to recover, such as firmware
  474. * loading. Linux just needs to attach after
  475. * recovery.
  476. */
  477. enum rproc_features {
  478. RPROC_FEAT_ATTACH_ON_RECOVERY,
  479. RPROC_MAX_FEATURES,
  480. };
  481. /**
  482. * struct rproc - represents a physical remote processor device
  483. * @node: list node of this rproc object
  484. * @domain: iommu domain
  485. * @name: human readable name of the rproc
  486. * @firmware: name of firmware file to be loaded
  487. * @priv: private data which belongs to the platform-specific rproc module
  488. * @ops: platform-specific start/stop rproc handlers
  489. * @dev: virtual device for refcounting and common remoteproc behavior
  490. * @power: refcount of users who need this rproc powered up
  491. * @state: state of the device
  492. * @dump_conf: Currently selected coredump configuration
  493. * @lock: lock which protects concurrent manipulations of the rproc
  494. * @dbg_dir: debugfs directory of this rproc device
  495. * @traces: list of trace buffers
  496. * @num_traces: number of trace buffers
  497. * @carveouts: list of physically contiguous memory allocations
  498. * @mappings: list of iommu mappings we initiated, needed on shutdown
  499. * @bootaddr: address of first instruction to boot rproc with (optional)
  500. * @rvdevs: list of remote virtio devices
  501. * @subdevs: list of subdevices, to following the running state
  502. * @notifyids: idr for dynamically assigning rproc-wide unique notify ids
  503. * @index: index of this rproc device
  504. * @crash_handler: workqueue for handling a crash
  505. * @crash_cnt: crash counter
  506. * @recovery_disabled: flag that state if recovery was disabled
  507. * @max_notifyid: largest allocated notify id.
  508. * @table_ptr: pointer to the resource table in effect
  509. * @clean_table: copy of the resource table without modifications. Used
  510. * when a remote processor is attached or detached from the core
  511. * @cached_table: copy of the resource table
  512. * @table_sz: size of @cached_table
  513. * @has_iommu: flag to indicate if remote processor is behind an MMU
  514. * @auto_boot: flag to indicate if remote processor should be auto-started
  515. * @sysfs_read_only: flag to make remoteproc sysfs files read only
  516. * @dump_segments: list of segments in the firmware
  517. * @nb_vdev: number of vdev currently handled by rproc
  518. * @elf_class: firmware ELF class
  519. * @elf_machine: firmware ELF machine
  520. * @cdev: character device of the rproc
  521. * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release
  522. * @features: indicate remoteproc features
  523. */
  524. struct rproc {
  525. struct list_head node;
  526. struct iommu_domain *domain;
  527. const char *name;
  528. const char *firmware;
  529. void *priv;
  530. struct rproc_ops *ops;
  531. struct device dev;
  532. atomic_t power;
  533. unsigned int state;
  534. enum rproc_dump_mechanism dump_conf;
  535. struct mutex lock;
  536. struct dentry *dbg_dir;
  537. struct list_head traces;
  538. int num_traces;
  539. struct list_head carveouts;
  540. struct list_head mappings;
  541. u64 bootaddr;
  542. struct list_head rvdevs;
  543. struct list_head subdevs;
  544. struct idr notifyids;
  545. int index;
  546. struct work_struct crash_handler;
  547. unsigned int crash_cnt;
  548. bool recovery_disabled;
  549. int max_notifyid;
  550. struct resource_table *table_ptr;
  551. struct resource_table *clean_table;
  552. struct resource_table *cached_table;
  553. size_t table_sz;
  554. bool has_iommu;
  555. bool auto_boot;
  556. bool sysfs_read_only;
  557. struct list_head dump_segments;
  558. int nb_vdev;
  559. u8 elf_class;
  560. u16 elf_machine;
  561. struct cdev cdev;
  562. bool cdev_put_on_release;
  563. #if IS_ENABLED(CONFIG_SEC_SENSORS_SSC)
  564. bool prev_recovery_disabled;
  565. bool fssr;
  566. bool fssr_dump;
  567. #endif
  568. DECLARE_BITMAP(features, RPROC_MAX_FEATURES);
  569. };
  570. /**
  571. * struct rproc_subdev - subdevice tied to a remoteproc
  572. * @node: list node related to the rproc subdevs list
  573. * @prepare: prepare function, called before the rproc is started
  574. * @start: start function, called after the rproc has been started
  575. * @stop: stop function, called before the rproc is stopped; the @crashed
  576. * parameter indicates if this originates from a recovery
  577. * @unprepare: unprepare function, called after the rproc has been stopped
  578. */
  579. struct rproc_subdev {
  580. struct list_head node;
  581. int (*prepare)(struct rproc_subdev *subdev);
  582. int (*start)(struct rproc_subdev *subdev);
  583. void (*stop)(struct rproc_subdev *subdev, bool crashed);
  584. void (*unprepare)(struct rproc_subdev *subdev);
  585. };
  586. /* we currently support only two vrings per rvdev */
  587. #define RVDEV_NUM_VRINGS 2
  588. /**
  589. * struct rproc_vring - remoteproc vring state
  590. * @va: virtual address
  591. * @num: vring size
  592. * @da: device address
  593. * @align: vring alignment
  594. * @notifyid: rproc-specific unique vring index
  595. * @rvdev: remote vdev
  596. * @vq: the virtqueue of this vring
  597. */
  598. struct rproc_vring {
  599. void *va;
  600. int num;
  601. u32 da;
  602. u32 align;
  603. int notifyid;
  604. struct rproc_vdev *rvdev;
  605. struct virtqueue *vq;
  606. };
  607. /**
  608. * struct rproc_vdev - remoteproc state for a supported virtio device
  609. * @subdev: handle for registering the vdev as a rproc subdevice
  610. * @pdev: remoteproc virtio platform device
  611. * @id: virtio device id (as in virtio_ids.h)
  612. * @node: list node
  613. * @rproc: the rproc handle
  614. * @vring: the vrings for this vdev
  615. * @rsc_offset: offset of the vdev's resource entry
  616. * @index: vdev position versus other vdev declared in resource table
  617. */
  618. struct rproc_vdev {
  619. struct rproc_subdev subdev;
  620. struct platform_device *pdev;
  621. unsigned int id;
  622. struct list_head node;
  623. struct rproc *rproc;
  624. struct rproc_vring vring[RVDEV_NUM_VRINGS];
  625. u32 rsc_offset;
  626. u32 index;
  627. };
  628. struct rproc *rproc_get_by_phandle(phandle phandle);
  629. struct rproc *rproc_get_by_child(struct device *dev);
  630. struct rproc *rproc_alloc(struct device *dev, const char *name,
  631. const struct rproc_ops *ops,
  632. const char *firmware, int len);
  633. void rproc_put(struct rproc *rproc);
  634. int rproc_add(struct rproc *rproc);
  635. int rproc_del(struct rproc *rproc);
  636. void rproc_free(struct rproc *rproc);
  637. void rproc_resource_cleanup(struct rproc *rproc);
  638. struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
  639. const struct rproc_ops *ops,
  640. const char *firmware, int len);
  641. int devm_rproc_add(struct device *dev, struct rproc *rproc);
  642. void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
  643. struct rproc_mem_entry *
  644. rproc_mem_entry_init(struct device *dev,
  645. void *va, dma_addr_t dma, size_t len, u32 da,
  646. int (*alloc)(struct rproc *, struct rproc_mem_entry *),
  647. int (*release)(struct rproc *, struct rproc_mem_entry *),
  648. const char *name, ...);
  649. struct rproc_mem_entry *
  650. rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len,
  651. u32 da, const char *name, ...);
  652. int rproc_boot(struct rproc *rproc);
  653. int rproc_shutdown(struct rproc *rproc);
  654. int rproc_detach(struct rproc *rproc);
  655. int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
  656. void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
  657. void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
  658. void rproc_coredump_using_sections(struct rproc *rproc);
  659. int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size);
  660. int rproc_coredump_add_custom_segment(struct rproc *rproc,
  661. dma_addr_t da, size_t size,
  662. void (*dumpfn)(struct rproc *rproc,
  663. struct rproc_dump_segment *segment,
  664. void *dest, size_t offset,
  665. size_t size),
  666. void *priv);
  667. int rproc_coredump_set_elf_info(struct rproc *rproc, u8 class, u16 machine);
  668. void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
  669. void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
  670. #endif /* REMOTEPROC_H */