remoteproc.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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/completion.h>
  40. #include <linux/idr.h>
  41. #include <linux/of.h>
  42. #include <linux/bitops.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[0];
  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[0];
  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_PRELOAD_VENDOR: a vendor resource type that needs to be handled by
  100. * remoteproc implementations before loading
  101. * @RSC_POSTLOAD_VENDOR: a vendor resource type that needs to be handled by
  102. * remoteproc implementations after loading
  103. * @RSC_LAST: just keep this one at the end
  104. *
  105. * For more details regarding a specific resource type, please see its
  106. * dedicated structure below.
  107. *
  108. * Please note that these values are used as indices to the rproc_handle_rsc
  109. * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
  110. * check the validity of an index before the lookup table is accessed, so
  111. * please update it as needed.
  112. */
  113. enum fw_resource_type {
  114. RSC_CARVEOUT = 0,
  115. RSC_DEVMEM = 1,
  116. RSC_TRACE = 2,
  117. RSC_VDEV = 3,
  118. RSC_PRELOAD_VENDOR = 4,
  119. RSC_POSTLOAD_VENDOR = 5,
  120. RSC_LAST = 6,
  121. };
  122. #define FW_RSC_ADDR_ANY (-1)
  123. /**
  124. * struct fw_rsc_carveout - physically contiguous memory request
  125. * @da: device address
  126. * @pa: physical address
  127. * @len: length (in bytes)
  128. * @flags: iommu protection flags
  129. * @reserved: reserved (must be zero)
  130. * @name: human-readable name of the requested memory region
  131. *
  132. * This resource entry requests the host to allocate a physically contiguous
  133. * memory region.
  134. *
  135. * These request entries should precede other firmware resource entries,
  136. * as other entries might request placing other data objects inside
  137. * these memory regions (e.g. data/code segments, trace resource entries, ...).
  138. *
  139. * Allocating memory this way helps utilizing the reserved physical memory
  140. * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
  141. * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
  142. * pressure is important; it may have a substantial impact on performance.
  143. *
  144. * If the firmware is compiled with static addresses, then @da should specify
  145. * the expected device address of this memory region. If @da is set to
  146. * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
  147. * overwrite @da with the dynamically allocated address.
  148. *
  149. * We will always use @da to negotiate the device addresses, even if it
  150. * isn't using an iommu. In that case, though, it will obviously contain
  151. * physical addresses.
  152. *
  153. * Some remote processors needs to know the allocated physical address
  154. * even if they do use an iommu. This is needed, e.g., if they control
  155. * hardware accelerators which access the physical memory directly (this
  156. * is the case with OMAP4 for instance). In that case, the host will
  157. * overwrite @pa with the dynamically allocated physical address.
  158. * Generally we don't want to expose physical addresses if we don't have to
  159. * (remote processors are generally _not_ trusted), so we might want to
  160. * change this to happen _only_ when explicitly required by the hardware.
  161. *
  162. * @flags is used to provide IOMMU protection flags, and @name should
  163. * (optionally) contain a human readable name of this carveout region
  164. * (mainly for debugging purposes).
  165. */
  166. struct fw_rsc_carveout {
  167. u32 da;
  168. u32 pa;
  169. u32 len;
  170. u32 flags;
  171. u32 reserved;
  172. u8 name[32];
  173. } __packed;
  174. /**
  175. * struct fw_rsc_devmem - iommu mapping request
  176. * @da: device address
  177. * @pa: physical address
  178. * @len: length (in bytes)
  179. * @flags: iommu protection flags
  180. * @reserved: reserved (must be zero)
  181. * @name: human-readable name of the requested region to be mapped
  182. *
  183. * This resource entry requests the host to iommu map a physically contiguous
  184. * memory region. This is needed in case the remote processor requires
  185. * access to certain memory-based peripherals; _never_ use it to access
  186. * regular memory.
  187. *
  188. * This is obviously only needed if the remote processor is accessing memory
  189. * via an iommu.
  190. *
  191. * @da should specify the required device address, @pa should specify
  192. * the physical address we want to map, @len should specify the size of
  193. * the mapping and @flags is the IOMMU protection flags. As always, @name may
  194. * (optionally) contain a human readable name of this mapping (mainly for
  195. * debugging purposes).
  196. *
  197. * Note: at this point we just "trust" those devmem entries to contain valid
  198. * physical addresses, but this isn't safe and will be changed: eventually we
  199. * want remoteproc implementations to provide us ranges of physical addresses
  200. * the firmware is allowed to request, and not allow firmwares to request
  201. * access to physical addresses that are outside those ranges.
  202. */
  203. struct fw_rsc_devmem {
  204. u32 da;
  205. u32 pa;
  206. u32 len;
  207. u32 flags;
  208. u32 reserved;
  209. u8 name[32];
  210. } __packed;
  211. /**
  212. * struct fw_rsc_trace - trace buffer declaration
  213. * @da: device address
  214. * @len: length (in bytes)
  215. * @reserved: reserved (must be zero)
  216. * @name: human-readable name of the trace buffer
  217. *
  218. * This resource entry provides the host information about a trace buffer
  219. * into which the remote processor will write log messages.
  220. *
  221. * @da specifies the device address of the buffer, @len specifies
  222. * its size, and @name may contain a human readable name of the trace buffer.
  223. *
  224. * After booting the remote processor, the trace buffers are exposed to the
  225. * user via debugfs entries (called trace0, trace1, etc..).
  226. */
  227. struct fw_rsc_trace {
  228. u32 da;
  229. u32 len;
  230. u32 reserved;
  231. u8 name[32];
  232. } __packed;
  233. /**
  234. * struct fw_rsc_vdev_vring - vring descriptor entry
  235. * @da: device address
  236. * @align: the alignment between the consumer and producer parts of the vring
  237. * @num: num of buffers supported by this vring (must be power of two)
  238. * @notifyid is a unique rproc-wide notify index for this vring. This notify
  239. * index is used when kicking a remote processor, to let it know that this
  240. * vring is triggered.
  241. * @pa: physical address
  242. *
  243. * This descriptor is not a resource entry by itself; it is part of the
  244. * vdev resource type (see below).
  245. *
  246. * Note that @da should either contain the device address where
  247. * the remote processor is expecting the vring, or indicate that
  248. * dynamically allocation of the vring's device address is supported.
  249. */
  250. struct fw_rsc_vdev_vring {
  251. u32 da;
  252. u32 align;
  253. u32 num;
  254. u32 notifyid;
  255. u32 pa;
  256. } __packed;
  257. /**
  258. * struct fw_rsc_vdev - virtio device header
  259. * @id: virtio device id (as in virtio_ids.h)
  260. * @notifyid is a unique rproc-wide notify index for this vdev. This notify
  261. * index is used when kicking a remote processor, to let it know that the
  262. * status/features of this vdev have changes.
  263. * @dfeatures specifies the virtio device features supported by the firmware
  264. * @gfeatures is a place holder used by the host to write back the
  265. * negotiated features that are supported by both sides.
  266. * @config_len is the size of the virtio config space of this vdev. The config
  267. * space lies in the resource table immediate after this vdev header.
  268. * @status is a place holder where the host will indicate its virtio progress.
  269. * @num_of_vrings indicates how many vrings are described in this vdev header
  270. * @reserved: reserved (must be zero)
  271. * @vring is an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'.
  272. *
  273. * This resource is a virtio device header: it provides information about
  274. * the vdev, and is then used by the host and its peer remote processors
  275. * to negotiate and share certain virtio properties.
  276. *
  277. * By providing this resource entry, the firmware essentially asks remoteproc
  278. * to statically allocate a vdev upon registration of the rproc (dynamic vdev
  279. * allocation is not yet supported).
  280. *
  281. * Note: unlike virtualization systems, the term 'host' here means
  282. * the Linux side which is running remoteproc to control the remote
  283. * processors. We use the name 'gfeatures' to comply with virtio's terms,
  284. * though there isn't really any virtualized guest OS here: it's the host
  285. * which is responsible for negotiating the final features.
  286. * Yeah, it's a bit confusing.
  287. *
  288. * Note: immediately following this structure is the virtio config space for
  289. * this vdev (which is specific to the vdev; for more info, read the virtio
  290. * spec). the size of the config space is specified by @config_len.
  291. */
  292. struct fw_rsc_vdev {
  293. u32 id;
  294. u32 notifyid;
  295. u32 dfeatures;
  296. u32 gfeatures;
  297. u32 config_len;
  298. u8 status;
  299. u8 num_of_vrings;
  300. u8 reserved[2];
  301. struct fw_rsc_vdev_vring vring[0];
  302. } __packed;
  303. /**
  304. * struct fw_rsc_vendor - vendor resource definition
  305. * @sub_type: implementation specific type including version field
  306. * @size: size of the vendor custom resource
  307. * @data: label for the start of the resource
  308. */
  309. struct fw_rsc_vendor {
  310. union {
  311. u32 sub_type;
  312. struct {
  313. u16 st_type;
  314. u16 st_ver;
  315. } st;
  316. } u;
  317. u32 size;
  318. u8 data[0];
  319. } __packed;
  320. /**
  321. * struct rproc_mem_entry - memory entry descriptor
  322. * @va: virtual address
  323. * @dma: dma address
  324. * @len: length, in bytes
  325. * @da: device address
  326. * @priv: associated data
  327. * @name: associated memory region name (optional)
  328. * @node: list node
  329. */
  330. struct rproc_mem_entry {
  331. void *va;
  332. dma_addr_t dma;
  333. int len;
  334. u32 da;
  335. void *priv;
  336. char name[32];
  337. struct list_head node;
  338. };
  339. struct rproc;
  340. struct firmware;
  341. /*
  342. * Macros to use with flags field in rproc_da_to_va API. Use
  343. * the upper 16 bits to dictate the flags type and the lower
  344. * 16 bits to pass on the value of the flags pertinent to that
  345. * type.
  346. *
  347. * Add any new flags type at a new bit-field position
  348. */
  349. #define RPROC_FLAGS_SHIFT 16
  350. #define RPROC_FLAGS_NONE 0
  351. #define RPROC_FLAGS_ELF_PHDR BIT(0 + RPROC_FLAGS_SHIFT)
  352. #define RPROC_FLAGS_ELF_SHDR BIT(1 + RPROC_FLAGS_SHIFT)
  353. /**
  354. * struct rproc_ops - platform-specific device handlers
  355. * @start: power on the device and boot it
  356. * @stop: power off the device
  357. * @kick: kick a virtqueue (virtqueue id given as a parameter)
  358. * @da_to_va: optional platform hook to perform address translations
  359. * @load_rsc_table: load resource table from firmware image
  360. * @find_loaded_rsc_table: find the loaded resouce table
  361. * @handle_vendor_rsc: hook to handle device specific resource table entries
  362. * @load: load firmeware to memory, where the remote processor
  363. * expects to find it
  364. * @sanity_check: sanity check the fw image
  365. * @get_boot_addr: get boot address to entry point specified in firmware
  366. */
  367. struct rproc_ops {
  368. int (*start)(struct rproc *rproc);
  369. int (*stop)(struct rproc *rproc);
  370. void (*kick)(struct rproc *rproc, int vqid);
  371. void * (*da_to_va)(struct rproc *rproc, u64 da, int len, u32 flags);
  372. int (*parse_fw)(struct rproc *rproc, const struct firmware *fw);
  373. struct resource_table *(*find_loaded_rsc_table)(
  374. struct rproc *rproc, const struct firmware *fw);
  375. int (*handle_vendor_rsc)(struct rproc *rproc,
  376. struct fw_rsc_vendor *rsc);
  377. int (*load)(struct rproc *rproc, const struct firmware *fw);
  378. int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
  379. u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
  380. };
  381. /**
  382. * enum rproc_state - remote processor states
  383. * @RPROC_OFFLINE: device is powered off
  384. * @RPROC_SUSPENDED: device is suspended; needs to be woken up to receive
  385. * a message.
  386. * @RPROC_RUNNING: device is up and running
  387. * @RPROC_CRASHED: device has crashed; need to start recovery
  388. * @RPROC_DELETED: device is deleted
  389. * @RPROC_LAST: just keep this one at the end
  390. *
  391. * Please note that the values of these states are used as indices
  392. * to rproc_state_string, a state-to-name lookup table,
  393. * so please keep the two synchronized. @RPROC_LAST is used to check
  394. * the validity of an index before the lookup table is accessed, so
  395. * please update it as needed too.
  396. */
  397. enum rproc_state {
  398. RPROC_OFFLINE = 0,
  399. RPROC_SUSPENDED = 1,
  400. RPROC_RUNNING = 2,
  401. RPROC_CRASHED = 3,
  402. RPROC_DELETED = 4,
  403. RPROC_LAST = 5,
  404. };
  405. /**
  406. * enum rproc_crash_type - remote processor crash types
  407. * @RPROC_MMUFAULT: iommu fault
  408. * @RPROC_WATCHDOG: watchdog bite
  409. * @RPROC_FATAL_ERROR fatal error
  410. *
  411. * Each element of the enum is used as an array index. So that, the value of
  412. * the elements should be always something sane.
  413. *
  414. * Feel free to add more types when needed.
  415. */
  416. enum rproc_crash_type {
  417. RPROC_MMUFAULT,
  418. RPROC_WATCHDOG,
  419. RPROC_FATAL_ERROR,
  420. };
  421. /**
  422. * struct rproc_dump_segment - segment info from ELF header
  423. * @node: list node related to the rproc segment list
  424. * @da: device address of the segment
  425. * @size: size of the segment
  426. */
  427. struct rproc_dump_segment {
  428. struct list_head node;
  429. dma_addr_t da;
  430. size_t size;
  431. loff_t offset;
  432. };
  433. /**
  434. * struct rproc - represents a physical remote processor device
  435. * @node: list node of this rproc object
  436. * @domain: iommu domain
  437. * @name: human readable name of the rproc
  438. * @firmware: name of firmware file to be loaded
  439. * @priv: private data which belongs to the platform-specific rproc module
  440. * @ops: platform-specific start/stop rproc handlers
  441. * @dev: virtual device for refcounting and common remoteproc behavior
  442. * @power: refcount of users who need this rproc powered up
  443. * @state: state of the device
  444. * @lock: lock which protects concurrent manipulations of the rproc
  445. * @dbg_dir: debugfs directory of this rproc device
  446. * @traces: list of trace buffers
  447. * @num_traces: number of trace buffers
  448. * @last_traces: list of last trace buffers
  449. * @num_last_traces: number of last trace buffers
  450. * @carveouts: list of physically contiguous memory allocations
  451. * @mappings: list of iommu mappings we initiated, needed on shutdown
  452. * @bootaddr: address of first instruction to boot rproc with (optional)
  453. * @rvdevs: list of remote virtio devices
  454. * @subdevs: list of subdevices, to following the running state
  455. * @notifyids: idr for dynamically assigning rproc-wide unique notify ids
  456. * @index: index of this rproc device
  457. * @crash_handler: workqueue for handling a crash
  458. * @crash_cnt: crash counter
  459. * @crash_comp: completion used to sync crash handler and the rproc reload
  460. * @recovery_disabled: flag that state if recovery was disabled
  461. * @max_notifyid: largest allocated notify id.
  462. * @table_ptr: pointer to the resource table in effect
  463. * @cached_table: copy of the resource table
  464. * @table_sz: size of @cached_table
  465. * @has_iommu: flag to indicate if remote processor is behind an MMU
  466. * @auto_boot: flag to indicate if remote processor should be auto-started
  467. * @deny_sysfs_ops: flag to not permit sysfs operations on state and firmware
  468. * @skip_firmware_request: flag to skip requesting the firmware
  469. * @skip_load: flag to skip the loading of firmware segments
  470. * @late_attach: flag indicating remote core has been externally pre-booted
  471. * @dump_segments: list of segments in the firmware
  472. */
  473. struct rproc {
  474. struct list_head node;
  475. struct iommu_domain *domain;
  476. const char *name;
  477. char *firmware;
  478. void *priv;
  479. struct rproc_ops *ops;
  480. struct device dev;
  481. atomic_t power;
  482. unsigned int state;
  483. struct mutex lock;
  484. struct dentry *dbg_dir;
  485. struct list_head traces;
  486. int num_traces;
  487. struct list_head last_traces;
  488. int num_last_traces;
  489. struct list_head carveouts;
  490. struct list_head mappings;
  491. u32 bootaddr;
  492. struct list_head rvdevs;
  493. struct list_head subdevs;
  494. struct idr notifyids;
  495. int index;
  496. struct work_struct crash_handler;
  497. unsigned int crash_cnt;
  498. struct completion crash_comp;
  499. bool recovery_disabled;
  500. int max_notifyid;
  501. struct resource_table *table_ptr;
  502. struct resource_table *cached_table;
  503. size_t table_sz;
  504. bool has_iommu;
  505. bool auto_boot;
  506. unsigned int deny_sysfs_ops : 1;
  507. unsigned int skip_firmware_request : 1;
  508. unsigned int skip_load : 1;
  509. unsigned int late_attach : 1;
  510. struct list_head dump_segments;
  511. };
  512. /**
  513. * struct rproc_subdev - subdevice tied to a remoteproc
  514. * @node: list node related to the rproc subdevs list
  515. * @prepare: prepare function, called before the rproc is started
  516. * @start: start function, called after the rproc has been started
  517. * @stop: stop function, called before the rproc is stopped; the @crashed
  518. * parameter indicates if this originates from a recovery
  519. * @unprepare: unprepare function, called after the rproc has been stopped
  520. */
  521. struct rproc_subdev {
  522. struct list_head node;
  523. int (*prepare)(struct rproc_subdev *subdev);
  524. int (*start)(struct rproc_subdev *subdev);
  525. void (*stop)(struct rproc_subdev *subdev, bool crashed);
  526. void (*unprepare)(struct rproc_subdev *subdev);
  527. };
  528. /* we currently support only two vrings per rvdev */
  529. #define RVDEV_NUM_VRINGS 2
  530. /**
  531. * struct rproc_vring - remoteproc vring state
  532. * @va: virtual address
  533. * @dma: dma address
  534. * @len: length, in bytes
  535. * @da: device address
  536. * @align: vring alignment
  537. * @notifyid: rproc-specific unique vring index
  538. * @rvdev: remote vdev
  539. * @vq: the virtqueue of this vring
  540. */
  541. struct rproc_vring {
  542. void *va;
  543. dma_addr_t dma;
  544. int len;
  545. u32 da;
  546. u32 align;
  547. int notifyid;
  548. struct rproc_vdev *rvdev;
  549. struct virtqueue *vq;
  550. };
  551. /**
  552. * struct rproc_vdev - remoteproc state for a supported virtio device
  553. * @refcount: reference counter for the vdev and vring allocations
  554. * @subdev: handle for registering the vdev as a rproc subdevice
  555. * @id: virtio device id (as in virtio_ids.h)
  556. * @node: list node
  557. * @rproc: the rproc handle
  558. * @vdev: the virio device
  559. * @vring: the vrings for this vdev
  560. * @rsc_offset: offset of the vdev's resource entry
  561. */
  562. struct rproc_vdev {
  563. struct kref refcount;
  564. struct rproc_subdev subdev;
  565. unsigned int id;
  566. struct list_head node;
  567. struct rproc *rproc;
  568. struct virtio_device vdev;
  569. struct rproc_vring vring[RVDEV_NUM_VRINGS];
  570. u32 rsc_offset;
  571. };
  572. struct rproc *rproc_get_by_phandle(phandle phandle);
  573. struct rproc *rproc_get_by_child(struct device *dev);
  574. struct rproc *rproc_alloc(struct device *dev, const char *name,
  575. const struct rproc_ops *ops,
  576. const char *firmware, int len);
  577. void rproc_put(struct rproc *rproc);
  578. int rproc_add(struct rproc *rproc);
  579. int rproc_del(struct rproc *rproc);
  580. void rproc_free(struct rproc *rproc);
  581. int rproc_boot(struct rproc *rproc);
  582. void rproc_shutdown(struct rproc *rproc);
  583. int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
  584. void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
  585. void *rproc_da_to_va(struct rproc *rproc, u64 da, int len, u32 flags);
  586. int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size);
  587. int rproc_get_id(struct rproc *rproc);
  588. int rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da);
  589. static inline struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev)
  590. {
  591. return container_of(vdev, struct rproc_vdev, vdev);
  592. }
  593. static inline struct rproc *vdev_to_rproc(struct virtio_device *vdev)
  594. {
  595. struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
  596. return rvdev->rproc;
  597. }
  598. void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
  599. void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
  600. #endif /* REMOTEPROC_H */