Commit fd2c15ec authored by Ohad Ben-Cohen's avatar Ohad Ben-Cohen

remoteproc: resource table overhaul

The resource table is an array of 'struct fw_resource' members, where
each resource entry is expressed as a single member of that array.

This approach got us this far, but it has a few drawbacks:

1. Different resource entries end up overloading the same members of 'struct
   fw_resource' with different meanings. The resulting code is error prone
   and hard to read and maintain.

2. It's impossible to extend 'struct fw_resource' without breaking the
   existing firmware images (and we already want to: we can't introduce the
   new virito device resource entry with the current scheme).

3. It doesn't scale: 'struct fw_resource' must be as big as the largest
   resource entry type. As a result, smaller resource entries end up
   utilizing only small part of it.

This is fixed by defining a dedicated structure for every resource type,
and then converting the resource table to a list of type-value members.
Instead of a rigid array of homogeneous structs, the resource table
is turned into a collection of heterogeneous structures.

This way:
1. Resource entries consume exactly the amount of bytes they need.
2. It's easy to extend: just create a new resource entry structure, and assign
   it a new type.
3. The code is easier to read and maintain: the structures' members names are
   meaningful.

While we're at it, this patch has several other resource table changes:
1. The resource table gains a simple header which contains the
   number of entries in the table and their offsets within the table. This
   makes the parsing code simpler and easier to read.
2. A version member is added to the resource table. Should we change the
   format again, we'll bump up this version to prevent breakage with
   existing firmware images.
3. The VRING and VIRTIO_DEV resource entries are combined to a single
   VDEV entry. This paves the way to supporting multiple VDEV entries.
4. Since we don't really support 64-bit rprocs yet, convert two stray u64
   members to u32.
Signed-off-by: default avatarOhad Ben-Cohen <ohad@wizery.com>
Cc: Brian Swetland <swetland@google.com>
Cc: Iliyan Malchev <malchev@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Grant Likely <grant.likely@secretlab.ca>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Mark Grosen <mgrosen@ti.com>
Cc: John Williams <john.williams@petalogix.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Loic PALLARDY <loic.pallardy@stericsson.com>
Cc: Ludovic BARRE <ludovic.barre@stericsson.com>
Cc: Omar Ramirez Luna <omar.luna@linaro.org>
Cc: Guzman Lugo Fernando <fernando.lugo@ti.com>
Cc: Anna Suman <s-anna@ti.com>
Cc: Clark Rob <rob@ti.com>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Saravana Kannan <skannan@codeaurora.org>
Cc: David Brown <davidb@codeaurora.org>
Cc: Kieran Bingham <kieranbingham@gmail.com>
Cc: Tony Lindgren <tony@atomide.com>
parent 9d8ae5c2
...@@ -221,43 +221,52 @@ resource entries that publish the existence of supported features ...@@ -221,43 +221,52 @@ resource entries that publish the existence of supported features
or configurations by the remote processor, such as trace buffers and or configurations by the remote processor, such as trace buffers and
supported virtio devices (and their configurations). supported virtio devices (and their configurations).
Currently the resource table is just an array of: The resource table begins with this header:
/** /**
* struct fw_resource - describes an entry from the resource section * struct resource_table - firmware resource table header
* @ver: version number
* @num: number of resource entries
* @reserved: reserved (must be zero)
* @offset: array of offsets pointing at the various resource entries
*
* The header of the resource table, as expressed by this structure,
* contains a version number (should we need to change this format in the
* future), the number of available resource entries, and their offsets
* in the table.
*/
struct resource_table {
u32 ver;
u32 num;
u32 reserved[2];
u32 offset[0];
} __packed;
Immediately following this header are the resource entries themselves,
each of which begins with the following resource entry header:
/**
* struct fw_rsc_hdr - firmware resource entry header
* @type: resource type * @type: resource type
* @id: index number of the resource * @data: resource data
* @da: device address of the resource *
* @pa: physical address of the resource * Every resource entry begins with a 'struct fw_rsc_hdr' header providing
* @len: size, in bytes, of the resource * its @type. The content of the entry itself will immediately follow
* @flags: properties of the resource, e.g. iommu protection required * this header, and it should be parsed according to the resource type.
* @reserved: must be 0 atm
* @name: name of resource
*/ */
struct fw_resource { struct fw_rsc_hdr {
u32 type; u32 type;
u32 id; u8 data[0];
u64 da;
u64 pa;
u32 len;
u32 flags;
u8 reserved[16];
u8 name[48];
} __packed; } __packed;
Some resources entries are mere announcements, where the host is informed Some resources entries are mere announcements, where the host is informed
of specific remoteproc configuration. Other entries require the host to of specific remoteproc configuration. Other entries require the host to
do something (e.g. reserve a requested resource) and possibly also reply do something (e.g. allocate a system resource). Sometimes a negotiation
by overwriting a member inside 'struct fw_resource' with info about the is expected, where the firmware requests a resource, and once allocated,
allocated resource. the host should provide back its details (e.g. address of an allocated
memory region).
Different resource entries use different members of this struct,
with different meanings. This is pretty limiting and error-prone,
so the plan is to move to variable-length TLV-based resource entries,
where each resource will begin with a type and length fields, followed by
its own specific structure.
Here are the resource types that are currently being used: Here are the various resource types that are currently supported:
/** /**
* enum fw_resource_type - types of resource entries * enum fw_resource_type - types of resource entries
...@@ -266,59 +275,45 @@ Here are the resource types that are currently being used: ...@@ -266,59 +275,45 @@ Here are the resource types that are currently being used:
* memory region. * memory region.
* @RSC_DEVMEM: request to iommu_map a memory-based peripheral. * @RSC_DEVMEM: request to iommu_map a memory-based peripheral.
* @RSC_TRACE: announces the availability of a trace buffer into which * @RSC_TRACE: announces the availability of a trace buffer into which
* the remote processor will be writing logs. In this case, * the remote processor will be writing logs.
* 'da' indicates the device address where logs are written to, * @RSC_VDEV: declare support for a virtio device, and serve as its
* and 'len' is the size of the trace buffer. * virtio header.
* @RSC_VRING: request for allocation of a virtio vring (address should * @RSC_LAST: just keep this one at the end
* be indicated in 'da', and 'len' should contain the number *
* of buffers supported by the vring). * Please note that these values are used as indices to the rproc_handle_rsc
* @RSC_VIRTIO_DEV: announces support for a virtio device, and serves as * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
* the virtio header. 'da' contains the virtio device * check the validity of an index before the lookup table is accessed, so
* features, 'pa' holds the virtio guest features (host * please update it as needed.
* will write them here after they're negotiated), 'len'
* holds the virtio status, and 'flags' holds the virtio
* device id (currently only VIRTIO_ID_RPMSG is supported).
*/ */
enum fw_resource_type { enum fw_resource_type {
RSC_CARVEOUT = 0, RSC_CARVEOUT = 0,
RSC_DEVMEM = 1, RSC_DEVMEM = 1,
RSC_TRACE = 2, RSC_TRACE = 2,
RSC_VRING = 3, RSC_VDEV = 3,
RSC_VIRTIO_DEV = 4, RSC_LAST = 4,
RSC_VIRTIO_CFG = 5,
}; };
Most of the resource entries share the basic idea of address/length For more details regarding a specific resource type, please see its
negotiation with the host: the firmware usually asks for memory dedicated structure in include/linux/remoteproc.h.
of size 'len' bytes, and the host needs to allocate it and provide
the device/physical address (when relevant) in 'da'/'pa' respectively.
If the firmware is compiled with hard coded device addresses, and
can't handle dynamically allocated 'da' values, then the 'da' field
will contain the expected device addresses (today we actually only support
this scheme, as there aren't yet any use cases for dynamically allocated
device addresses).
We also expect that platform-specific resource entries will show up We also expect that platform-specific resource entries will show up
at some point. When that happens, we could easily add a new RSC_PLAFORM at some point. When that happens, we could easily add a new RSC_PLATFORM
type, and hand those resources to the platform-specific rproc driver to handle. type, and hand those resources to the platform-specific rproc driver to handle.
7. Virtio and remoteproc 7. Virtio and remoteproc
The firmware should provide remoteproc information about virtio devices The firmware should provide remoteproc information about virtio devices
that it supports, and their configurations: a RSC_VIRTIO_DEV resource entry that it supports, and their configurations: a RSC_VDEV resource entry
should specify the virtio device id, and subsequent RSC_VRING resource entries should specify the virtio device id (as in virtio_ids.h), virtio features,
should indicate the vring size (i.e. how many buffers do they support) and virtio config space, vrings information, etc.
where should they be mapped (i.e. which device address). Note: the alignment
between the consumer and producer parts of the vring is assumed to be 4096. When a new remote processor is registered, the remoteproc framework
will look for its resource table and will register the virtio devices
At this point we only support a single virtio rpmsg device per remote it supports. A firmware may support any number of virtio devices, and
processor, but the plan is to remove this limitation. In addition, once we of any type (a single remote processor can also easily support several
move to TLV-based resource table, the plan is to have a single RSC_VIRTIO rpmsg virtio devices this way, if desired).
entry per supported virtio device, which will include the virtio header,
the vrings information and the virtio config space. Of course, RSC_VDEV resource entries are only good enough for static
Of course, RSC_VIRTIO resource entries are only good enough for static
allocation of virtio devices. Dynamic allocations will also be made possible allocation of virtio devices. Dynamic allocations will also be made possible
using the rpmsg bus (similar to how we already do dynamic allocations of using the rpmsg bus (similar to how we already do dynamic allocations of
rpmsg channels; read more about it in rpmsg.txt). rpmsg channels; read more about it in rpmsg.txt).
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment