Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Remote Processor Framework
0003  *
0004  * Copyright(c) 2011 Texas Instruments, Inc.
0005  * Copyright(c) 2011 Google, Inc.
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions
0010  * are met:
0011  *
0012  * * Redistributions of source code must retain the above copyright
0013  *   notice, this list of conditions and the following disclaimer.
0014  * * Redistributions in binary form must reproduce the above copyright
0015  *   notice, this list of conditions and the following disclaimer in
0016  *   the documentation and/or other materials provided with the
0017  *   distribution.
0018  * * Neither the name Texas Instruments nor the names of its
0019  *   contributors may be used to endorse or promote products derived
0020  *   from this software without specific prior written permission.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0026  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #ifndef REMOTEPROC_H
0036 #define REMOTEPROC_H
0037 
0038 #include <linux/types.h>
0039 #include <linux/mutex.h>
0040 #include <linux/virtio.h>
0041 #include <linux/cdev.h>
0042 #include <linux/completion.h>
0043 #include <linux/idr.h>
0044 #include <linux/of.h>
0045 
0046 /**
0047  * struct resource_table - firmware resource table header
0048  * @ver: version number
0049  * @num: number of resource entries
0050  * @reserved: reserved (must be zero)
0051  * @offset: array of offsets pointing at the various resource entries
0052  *
0053  * A resource table is essentially a list of system resources required
0054  * by the remote processor. It may also include configuration entries.
0055  * If needed, the remote processor firmware should contain this table
0056  * as a dedicated ".resource_table" ELF section.
0057  *
0058  * Some resources entries are mere announcements, where the host is informed
0059  * of specific remoteproc configuration. Other entries require the host to
0060  * do something (e.g. allocate a system resource). Sometimes a negotiation
0061  * is expected, where the firmware requests a resource, and once allocated,
0062  * the host should provide back its details (e.g. address of an allocated
0063  * memory region).
0064  *
0065  * The header of the resource table, as expressed by this structure,
0066  * contains a version number (should we need to change this format in the
0067  * future), the number of available resource entries, and their offsets
0068  * in the table.
0069  *
0070  * Immediately following this header are the resource entries themselves,
0071  * each of which begins with a resource entry header (as described below).
0072  */
0073 struct resource_table {
0074     u32 ver;
0075     u32 num;
0076     u32 reserved[2];
0077     u32 offset[];
0078 } __packed;
0079 
0080 /**
0081  * struct fw_rsc_hdr - firmware resource entry header
0082  * @type: resource type
0083  * @data: resource data
0084  *
0085  * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
0086  * its @type. The content of the entry itself will immediately follow
0087  * this header, and it should be parsed according to the resource type.
0088  */
0089 struct fw_rsc_hdr {
0090     u32 type;
0091     u8 data[];
0092 } __packed;
0093 
0094 /**
0095  * enum fw_resource_type - types of resource entries
0096  *
0097  * @RSC_CARVEOUT:   request for allocation of a physically contiguous
0098  *          memory region.
0099  * @RSC_DEVMEM:     request to iommu_map a memory-based peripheral.
0100  * @RSC_TRACE:      announces the availability of a trace buffer into which
0101  *          the remote processor will be writing logs.
0102  * @RSC_VDEV:       declare support for a virtio device, and serve as its
0103  *          virtio header.
0104  * @RSC_LAST:       just keep this one at the end of standard resources
0105  * @RSC_VENDOR_START:   start of the vendor specific resource types range
0106  * @RSC_VENDOR_END: end of the vendor specific resource types range
0107  *
0108  * For more details regarding a specific resource type, please see its
0109  * dedicated structure below.
0110  *
0111  * Please note that these values are used as indices to the rproc_handle_rsc
0112  * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
0113  * check the validity of an index before the lookup table is accessed, so
0114  * please update it as needed.
0115  */
0116 enum fw_resource_type {
0117     RSC_CARVEOUT        = 0,
0118     RSC_DEVMEM      = 1,
0119     RSC_TRACE       = 2,
0120     RSC_VDEV        = 3,
0121     RSC_LAST        = 4,
0122     RSC_VENDOR_START    = 128,
0123     RSC_VENDOR_END      = 512,
0124 };
0125 
0126 #define FW_RSC_ADDR_ANY (-1)
0127 
0128 /**
0129  * struct fw_rsc_carveout - physically contiguous memory request
0130  * @da: device address
0131  * @pa: physical address
0132  * @len: length (in bytes)
0133  * @flags: iommu protection flags
0134  * @reserved: reserved (must be zero)
0135  * @name: human-readable name of the requested memory region
0136  *
0137  * This resource entry requests the host to allocate a physically contiguous
0138  * memory region.
0139  *
0140  * These request entries should precede other firmware resource entries,
0141  * as other entries might request placing other data objects inside
0142  * these memory regions (e.g. data/code segments, trace resource entries, ...).
0143  *
0144  * Allocating memory this way helps utilizing the reserved physical memory
0145  * (e.g. CMA) more efficiently, and also minimizes the number of TLB entries
0146  * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
0147  * pressure is important; it may have a substantial impact on performance.
0148  *
0149  * If the firmware is compiled with static addresses, then @da should specify
0150  * the expected device address of this memory region. If @da is set to
0151  * FW_RSC_ADDR_ANY, then the host will dynamically allocate it, and then
0152  * overwrite @da with the dynamically allocated address.
0153  *
0154  * We will always use @da to negotiate the device addresses, even if it
0155  * isn't using an iommu. In that case, though, it will obviously contain
0156  * physical addresses.
0157  *
0158  * Some remote processors needs to know the allocated physical address
0159  * even if they do use an iommu. This is needed, e.g., if they control
0160  * hardware accelerators which access the physical memory directly (this
0161  * is the case with OMAP4 for instance). In that case, the host will
0162  * overwrite @pa with the dynamically allocated physical address.
0163  * Generally we don't want to expose physical addresses if we don't have to
0164  * (remote processors are generally _not_ trusted), so we might want to
0165  * change this to happen _only_ when explicitly required by the hardware.
0166  *
0167  * @flags is used to provide IOMMU protection flags, and @name should
0168  * (optionally) contain a human readable name of this carveout region
0169  * (mainly for debugging purposes).
0170  */
0171 struct fw_rsc_carveout {
0172     u32 da;
0173     u32 pa;
0174     u32 len;
0175     u32 flags;
0176     u32 reserved;
0177     u8 name[32];
0178 } __packed;
0179 
0180 /**
0181  * struct fw_rsc_devmem - iommu mapping request
0182  * @da: device address
0183  * @pa: physical address
0184  * @len: length (in bytes)
0185  * @flags: iommu protection flags
0186  * @reserved: reserved (must be zero)
0187  * @name: human-readable name of the requested region to be mapped
0188  *
0189  * This resource entry requests the host to iommu map a physically contiguous
0190  * memory region. This is needed in case the remote processor requires
0191  * access to certain memory-based peripherals; _never_ use it to access
0192  * regular memory.
0193  *
0194  * This is obviously only needed if the remote processor is accessing memory
0195  * via an iommu.
0196  *
0197  * @da should specify the required device address, @pa should specify
0198  * the physical address we want to map, @len should specify the size of
0199  * the mapping and @flags is the IOMMU protection flags. As always, @name may
0200  * (optionally) contain a human readable name of this mapping (mainly for
0201  * debugging purposes).
0202  *
0203  * Note: at this point we just "trust" those devmem entries to contain valid
0204  * physical addresses, but this isn't safe and will be changed: eventually we
0205  * want remoteproc implementations to provide us ranges of physical addresses
0206  * the firmware is allowed to request, and not allow firmwares to request
0207  * access to physical addresses that are outside those ranges.
0208  */
0209 struct fw_rsc_devmem {
0210     u32 da;
0211     u32 pa;
0212     u32 len;
0213     u32 flags;
0214     u32 reserved;
0215     u8 name[32];
0216 } __packed;
0217 
0218 /**
0219  * struct fw_rsc_trace - trace buffer declaration
0220  * @da: device address
0221  * @len: length (in bytes)
0222  * @reserved: reserved (must be zero)
0223  * @name: human-readable name of the trace buffer
0224  *
0225  * This resource entry provides the host information about a trace buffer
0226  * into which the remote processor will write log messages.
0227  *
0228  * @da specifies the device address of the buffer, @len specifies
0229  * its size, and @name may contain a human readable name of the trace buffer.
0230  *
0231  * After booting the remote processor, the trace buffers are exposed to the
0232  * user via debugfs entries (called trace0, trace1, etc..).
0233  */
0234 struct fw_rsc_trace {
0235     u32 da;
0236     u32 len;
0237     u32 reserved;
0238     u8 name[32];
0239 } __packed;
0240 
0241 /**
0242  * struct fw_rsc_vdev_vring - vring descriptor entry
0243  * @da: device address
0244  * @align: the alignment between the consumer and producer parts of the vring
0245  * @num: num of buffers supported by this vring (must be power of two)
0246  * @notifyid: a unique rproc-wide notify index for this vring. This notify
0247  * index is used when kicking a remote processor, to let it know that this
0248  * vring is triggered.
0249  * @pa: physical address
0250  *
0251  * This descriptor is not a resource entry by itself; it is part of the
0252  * vdev resource type (see below).
0253  *
0254  * Note that @da should either contain the device address where
0255  * the remote processor is expecting the vring, or indicate that
0256  * dynamically allocation of the vring's device address is supported.
0257  */
0258 struct fw_rsc_vdev_vring {
0259     u32 da;
0260     u32 align;
0261     u32 num;
0262     u32 notifyid;
0263     u32 pa;
0264 } __packed;
0265 
0266 /**
0267  * struct fw_rsc_vdev - virtio device header
0268  * @id: virtio device id (as in virtio_ids.h)
0269  * @notifyid: a unique rproc-wide notify index for this vdev. This notify
0270  * index is used when kicking a remote processor, to let it know that the
0271  * status/features of this vdev have changes.
0272  * @dfeatures: specifies the virtio device features supported by the firmware
0273  * @gfeatures: a place holder used by the host to write back the
0274  * negotiated features that are supported by both sides.
0275  * @config_len: the size of the virtio config space of this vdev. The config
0276  * space lies in the resource table immediate after this vdev header.
0277  * @status: a place holder where the host will indicate its virtio progress.
0278  * @num_of_vrings: indicates how many vrings are described in this vdev header
0279  * @reserved: reserved (must be zero)
0280  * @vring: an array of @num_of_vrings entries of 'struct fw_rsc_vdev_vring'.
0281  *
0282  * This resource is a virtio device header: it provides information about
0283  * the vdev, and is then used by the host and its peer remote processors
0284  * to negotiate and share certain virtio properties.
0285  *
0286  * By providing this resource entry, the firmware essentially asks remoteproc
0287  * to statically allocate a vdev upon registration of the rproc (dynamic vdev
0288  * allocation is not yet supported).
0289  *
0290  * Note:
0291  * 1. unlike virtualization systems, the term 'host' here means
0292  *    the Linux side which is running remoteproc to control the remote
0293  *    processors. We use the name 'gfeatures' to comply with virtio's terms,
0294  *    though there isn't really any virtualized guest OS here: it's the host
0295  *    which is responsible for negotiating the final features.
0296  *    Yeah, it's a bit confusing.
0297  *
0298  * 2. immediately following this structure is the virtio config space for
0299  *    this vdev (which is specific to the vdev; for more info, read the virtio
0300  *    spec). The size of the config space is specified by @config_len.
0301  */
0302 struct fw_rsc_vdev {
0303     u32 id;
0304     u32 notifyid;
0305     u32 dfeatures;
0306     u32 gfeatures;
0307     u32 config_len;
0308     u8 status;
0309     u8 num_of_vrings;
0310     u8 reserved[2];
0311     struct fw_rsc_vdev_vring vring[];
0312 } __packed;
0313 
0314 struct rproc;
0315 
0316 /**
0317  * struct rproc_mem_entry - memory entry descriptor
0318  * @va: virtual address
0319  * @is_iomem: io memory
0320  * @dma: dma address
0321  * @len: length, in bytes
0322  * @da: device address
0323  * @release: release associated memory
0324  * @priv: associated data
0325  * @name: associated memory region name (optional)
0326  * @node: list node
0327  * @rsc_offset: offset in resource table
0328  * @flags: iommu protection flags
0329  * @of_resm_idx: reserved memory phandle index
0330  * @alloc: specific memory allocator function
0331  */
0332 struct rproc_mem_entry {
0333     void *va;
0334     bool is_iomem;
0335     dma_addr_t dma;
0336     size_t len;
0337     u32 da;
0338     void *priv;
0339     char name[32];
0340     struct list_head node;
0341     u32 rsc_offset;
0342     u32 flags;
0343     u32 of_resm_idx;
0344     int (*alloc)(struct rproc *rproc, struct rproc_mem_entry *mem);
0345     int (*release)(struct rproc *rproc, struct rproc_mem_entry *mem);
0346 };
0347 
0348 struct firmware;
0349 
0350 /**
0351  * enum rsc_handling_status - return status of rproc_ops handle_rsc hook
0352  * @RSC_HANDLED:    resource was handled
0353  * @RSC_IGNORED:    resource was ignored
0354  */
0355 enum rsc_handling_status {
0356     RSC_HANDLED = 0,
0357     RSC_IGNORED = 1,
0358 };
0359 
0360 /**
0361  * struct rproc_ops - platform-specific device handlers
0362  * @prepare:    prepare device for code loading
0363  * @unprepare:  unprepare device after stop
0364  * @start:  power on the device and boot it
0365  * @stop:   power off the device
0366  * @attach: attach to a device that his already powered up
0367  * @detach: detach from a device, leaving it powered up
0368  * @kick:   kick a virtqueue (virtqueue id given as a parameter)
0369  * @da_to_va:   optional platform hook to perform address translations
0370  * @parse_fw:   parse firmware to extract information (e.g. resource table)
0371  * @handle_rsc: optional platform hook to handle vendor resources. Should return
0372  *      RSC_HANDLED if resource was handled, RSC_IGNORED if not handled
0373  *      and a negative value on error
0374  * @find_loaded_rsc_table: find the loaded resource table from firmware image
0375  * @get_loaded_rsc_table: get resource table installed in memory
0376  *            by external entity
0377  * @load:       load firmware to memory, where the remote processor
0378  *          expects to find it
0379  * @sanity_check:   sanity check the fw image
0380  * @get_boot_addr:  get boot address to entry point specified in firmware
0381  * @panic:  optional callback to react to system panic, core will delay
0382  *      panic at least the returned number of milliseconds
0383  * @coredump:     collect firmware dump after the subsystem is shutdown
0384  */
0385 struct rproc_ops {
0386     int (*prepare)(struct rproc *rproc);
0387     int (*unprepare)(struct rproc *rproc);
0388     int (*start)(struct rproc *rproc);
0389     int (*stop)(struct rproc *rproc);
0390     int (*attach)(struct rproc *rproc);
0391     int (*detach)(struct rproc *rproc);
0392     void (*kick)(struct rproc *rproc, int vqid);
0393     void * (*da_to_va)(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
0394     int (*parse_fw)(struct rproc *rproc, const struct firmware *fw);
0395     int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc,
0396               int offset, int avail);
0397     struct resource_table *(*find_loaded_rsc_table)(
0398                 struct rproc *rproc, const struct firmware *fw);
0399     struct resource_table *(*get_loaded_rsc_table)(
0400                 struct rproc *rproc, size_t *size);
0401     int (*load)(struct rproc *rproc, const struct firmware *fw);
0402     int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
0403     u64 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
0404     unsigned long (*panic)(struct rproc *rproc);
0405     void (*coredump)(struct rproc *rproc);
0406 };
0407 
0408 /**
0409  * enum rproc_state - remote processor states
0410  * @RPROC_OFFLINE:  device is powered off
0411  * @RPROC_SUSPENDED:    device is suspended; needs to be woken up to receive
0412  *          a message.
0413  * @RPROC_RUNNING:  device is up and running
0414  * @RPROC_CRASHED:  device has crashed; need to start recovery
0415  * @RPROC_DELETED:  device is deleted
0416  * @RPROC_ATTACHED: device has been booted by another entity and the core
0417  *          has attached to it
0418  * @RPROC_DETACHED: device has been booted by another entity and waiting
0419  *          for the core to attach to it
0420  * @RPROC_LAST:     just keep this one at the end
0421  *
0422  * Please note that the values of these states are used as indices
0423  * to rproc_state_string, a state-to-name lookup table,
0424  * so please keep the two synchronized. @RPROC_LAST is used to check
0425  * the validity of an index before the lookup table is accessed, so
0426  * please update it as needed too.
0427  */
0428 enum rproc_state {
0429     RPROC_OFFLINE   = 0,
0430     RPROC_SUSPENDED = 1,
0431     RPROC_RUNNING   = 2,
0432     RPROC_CRASHED   = 3,
0433     RPROC_DELETED   = 4,
0434     RPROC_ATTACHED  = 5,
0435     RPROC_DETACHED  = 6,
0436     RPROC_LAST  = 7,
0437 };
0438 
0439 /**
0440  * enum rproc_crash_type - remote processor crash types
0441  * @RPROC_MMUFAULT: iommu fault
0442  * @RPROC_WATCHDOG: watchdog bite
0443  * @RPROC_FATAL_ERROR:  fatal error
0444  *
0445  * Each element of the enum is used as an array index. So that, the value of
0446  * the elements should be always something sane.
0447  *
0448  * Feel free to add more types when needed.
0449  */
0450 enum rproc_crash_type {
0451     RPROC_MMUFAULT,
0452     RPROC_WATCHDOG,
0453     RPROC_FATAL_ERROR,
0454 };
0455 
0456 /**
0457  * enum rproc_dump_mechanism - Coredump options for core
0458  * @RPROC_COREDUMP_DISABLED:    Don't perform any dump
0459  * @RPROC_COREDUMP_ENABLED: Copy dump to separate buffer and carry on with
0460  *              recovery
0461  * @RPROC_COREDUMP_INLINE:  Read segments directly from device memory. Stall
0462  *              recovery until all segments are read
0463  */
0464 enum rproc_dump_mechanism {
0465     RPROC_COREDUMP_DISABLED,
0466     RPROC_COREDUMP_ENABLED,
0467     RPROC_COREDUMP_INLINE,
0468 };
0469 
0470 /**
0471  * struct rproc_dump_segment - segment info from ELF header
0472  * @node:   list node related to the rproc segment list
0473  * @da:     device address of the segment
0474  * @size:   size of the segment
0475  * @priv:   private data associated with the dump_segment
0476  * @dump:   custom dump function to fill device memory segment associated
0477  *      with coredump
0478  * @offset: offset of the segment
0479  */
0480 struct rproc_dump_segment {
0481     struct list_head node;
0482 
0483     dma_addr_t da;
0484     size_t size;
0485 
0486     void *priv;
0487     void (*dump)(struct rproc *rproc, struct rproc_dump_segment *segment,
0488              void *dest, size_t offset, size_t size);
0489     loff_t offset;
0490 };
0491 
0492 /**
0493  * struct rproc - represents a physical remote processor device
0494  * @node: list node of this rproc object
0495  * @domain: iommu domain
0496  * @name: human readable name of the rproc
0497  * @firmware: name of firmware file to be loaded
0498  * @priv: private data which belongs to the platform-specific rproc module
0499  * @ops: platform-specific start/stop rproc handlers
0500  * @dev: virtual device for refcounting and common remoteproc behavior
0501  * @power: refcount of users who need this rproc powered up
0502  * @state: state of the device
0503  * @dump_conf: Currently selected coredump configuration
0504  * @lock: lock which protects concurrent manipulations of the rproc
0505  * @dbg_dir: debugfs directory of this rproc device
0506  * @traces: list of trace buffers
0507  * @num_traces: number of trace buffers
0508  * @carveouts: list of physically contiguous memory allocations
0509  * @mappings: list of iommu mappings we initiated, needed on shutdown
0510  * @bootaddr: address of first instruction to boot rproc with (optional)
0511  * @rvdevs: list of remote virtio devices
0512  * @subdevs: list of subdevices, to following the running state
0513  * @notifyids: idr for dynamically assigning rproc-wide unique notify ids
0514  * @index: index of this rproc device
0515  * @crash_handler: workqueue for handling a crash
0516  * @crash_cnt: crash counter
0517  * @recovery_disabled: flag that state if recovery was disabled
0518  * @max_notifyid: largest allocated notify id.
0519  * @table_ptr: pointer to the resource table in effect
0520  * @clean_table: copy of the resource table without modifications.  Used
0521  *       when a remote processor is attached or detached from the core
0522  * @cached_table: copy of the resource table
0523  * @table_sz: size of @cached_table
0524  * @has_iommu: flag to indicate if remote processor is behind an MMU
0525  * @auto_boot: flag to indicate if remote processor should be auto-started
0526  * @sysfs_read_only: flag to make remoteproc sysfs files read only
0527  * @dump_segments: list of segments in the firmware
0528  * @nb_vdev: number of vdev currently handled by rproc
0529  * @elf_class: firmware ELF class
0530  * @elf_machine: firmware ELF machine
0531  * @cdev: character device of the rproc
0532  * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release
0533  */
0534 struct rproc {
0535     struct list_head node;
0536     struct iommu_domain *domain;
0537     const char *name;
0538     const char *firmware;
0539     void *priv;
0540     struct rproc_ops *ops;
0541     struct device dev;
0542     atomic_t power;
0543     unsigned int state;
0544     enum rproc_dump_mechanism dump_conf;
0545     struct mutex lock;
0546     struct dentry *dbg_dir;
0547     struct list_head traces;
0548     int num_traces;
0549     struct list_head carveouts;
0550     struct list_head mappings;
0551     u64 bootaddr;
0552     struct list_head rvdevs;
0553     struct list_head subdevs;
0554     struct idr notifyids;
0555     int index;
0556     struct work_struct crash_handler;
0557     unsigned int crash_cnt;
0558     bool recovery_disabled;
0559     int max_notifyid;
0560     struct resource_table *table_ptr;
0561     struct resource_table *clean_table;
0562     struct resource_table *cached_table;
0563     size_t table_sz;
0564     bool has_iommu;
0565     bool auto_boot;
0566     bool sysfs_read_only;
0567     struct list_head dump_segments;
0568     int nb_vdev;
0569     u8 elf_class;
0570     u16 elf_machine;
0571     struct cdev cdev;
0572     bool cdev_put_on_release;
0573 };
0574 
0575 /**
0576  * struct rproc_subdev - subdevice tied to a remoteproc
0577  * @node: list node related to the rproc subdevs list
0578  * @prepare: prepare function, called before the rproc is started
0579  * @start: start function, called after the rproc has been started
0580  * @stop: stop function, called before the rproc is stopped; the @crashed
0581  *      parameter indicates if this originates from a recovery
0582  * @unprepare: unprepare function, called after the rproc has been stopped
0583  */
0584 struct rproc_subdev {
0585     struct list_head node;
0586 
0587     int (*prepare)(struct rproc_subdev *subdev);
0588     int (*start)(struct rproc_subdev *subdev);
0589     void (*stop)(struct rproc_subdev *subdev, bool crashed);
0590     void (*unprepare)(struct rproc_subdev *subdev);
0591 };
0592 
0593 /* we currently support only two vrings per rvdev */
0594 
0595 #define RVDEV_NUM_VRINGS 2
0596 
0597 /**
0598  * struct rproc_vring - remoteproc vring state
0599  * @va: virtual address
0600  * @num: vring size
0601  * @da: device address
0602  * @align: vring alignment
0603  * @notifyid: rproc-specific unique vring index
0604  * @rvdev: remote vdev
0605  * @vq: the virtqueue of this vring
0606  */
0607 struct rproc_vring {
0608     void *va;
0609     int num;
0610     u32 da;
0611     u32 align;
0612     int notifyid;
0613     struct rproc_vdev *rvdev;
0614     struct virtqueue *vq;
0615 };
0616 
0617 /**
0618  * struct rproc_vdev - remoteproc state for a supported virtio device
0619  * @refcount: reference counter for the vdev and vring allocations
0620  * @subdev: handle for registering the vdev as a rproc subdevice
0621  * @dev: device struct used for reference count semantics
0622  * @id: virtio device id (as in virtio_ids.h)
0623  * @node: list node
0624  * @rproc: the rproc handle
0625  * @vring: the vrings for this vdev
0626  * @rsc_offset: offset of the vdev's resource entry
0627  * @index: vdev position versus other vdev declared in resource table
0628  */
0629 struct rproc_vdev {
0630     struct kref refcount;
0631 
0632     struct rproc_subdev subdev;
0633     struct device dev;
0634 
0635     unsigned int id;
0636     struct list_head node;
0637     struct rproc *rproc;
0638     struct rproc_vring vring[RVDEV_NUM_VRINGS];
0639     u32 rsc_offset;
0640     u32 index;
0641 };
0642 
0643 struct rproc *rproc_get_by_phandle(phandle phandle);
0644 struct rproc *rproc_get_by_child(struct device *dev);
0645 
0646 struct rproc *rproc_alloc(struct device *dev, const char *name,
0647               const struct rproc_ops *ops,
0648               const char *firmware, int len);
0649 void rproc_put(struct rproc *rproc);
0650 int rproc_add(struct rproc *rproc);
0651 int rproc_del(struct rproc *rproc);
0652 void rproc_free(struct rproc *rproc);
0653 void rproc_resource_cleanup(struct rproc *rproc);
0654 
0655 struct rproc *devm_rproc_alloc(struct device *dev, const char *name,
0656                    const struct rproc_ops *ops,
0657                    const char *firmware, int len);
0658 int devm_rproc_add(struct device *dev, struct rproc *rproc);
0659 
0660 void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem);
0661 
0662 struct rproc_mem_entry *
0663 rproc_mem_entry_init(struct device *dev,
0664              void *va, dma_addr_t dma, size_t len, u32 da,
0665              int (*alloc)(struct rproc *, struct rproc_mem_entry *),
0666              int (*release)(struct rproc *, struct rproc_mem_entry *),
0667              const char *name, ...);
0668 
0669 struct rproc_mem_entry *
0670 rproc_of_resm_mem_entry_init(struct device *dev, u32 of_resm_idx, size_t len,
0671                  u32 da, const char *name, ...);
0672 
0673 int rproc_boot(struct rproc *rproc);
0674 int rproc_shutdown(struct rproc *rproc);
0675 int rproc_detach(struct rproc *rproc);
0676 int rproc_set_firmware(struct rproc *rproc, const char *fw_name);
0677 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type);
0678 void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem);
0679 void rproc_coredump_using_sections(struct rproc *rproc);
0680 int rproc_coredump_add_segment(struct rproc *rproc, dma_addr_t da, size_t size);
0681 int rproc_coredump_add_custom_segment(struct rproc *rproc,
0682                       dma_addr_t da, size_t size,
0683                       void (*dumpfn)(struct rproc *rproc,
0684                              struct rproc_dump_segment *segment,
0685                              void *dest, size_t offset,
0686                              size_t size),
0687                       void *priv);
0688 int rproc_coredump_set_elf_info(struct rproc *rproc, u8 class, u16 machine);
0689 
0690 void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
0691 
0692 void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev);
0693 
0694 #endif /* REMOTEPROC_H */