summaryrefslogtreecommitdiffstats
path: root/drivers/firmware/arm_scmi/base.c
Commit message (Collapse)AuthorAgeFilesLines
* firmware: arm_scmi: Add protocol versioning checksCristian Marussi2023-12-011-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | Platform and agent supported protocols versions do not necessarily match. When talking to an older SCMI platform, supporting only older protocol versions, the kernel SCMI agent will downgrade the version of the used protocol to match the platform and avoid compatibility issues. In the case where the kernel/OSPM agent happens to communicate with a newer platform which can support newer protocol versions unknown to the agent, and potentially backward incompatible, the agent currently carries on, silently, in a best-effort approach. Note that the SCMI specification doesn't provide means to explicitly detect the protocol versions used by the agents, neither it is required to support multiple, older, protocol versions. Add an explicit protocol version check to let the agent detect when this version mismatch happens and warn the user about this condition. Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Link: https://lore.kernel.org/r/20231201135858.2367651-1-cristian.marussi@arm.com Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Avoid using extended string-buffers sizes if not necessaryCristian Marussi2022-06-101-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit b260fccaebdc2 ("firmware: arm_scmi: Add SCMI v3.1 protocol extended names support") moved all the name string buffers to use the extended buffer size of 64 instead of the required 16 bytes. While that should be fine if the firmware terminates the string before 16 bytes, there is possibility of copying random data if the name is not NULL terminated by the firmware. SCMI base protocol agent_name/vendor_id/sub_vendor_id are defined by the specification as NULL-terminated ASCII strings up to 16-bytes in length. The underlying buffers and message descriptors are currently bigger than needed; resize them to fit only the strictly needed 16 bytes to avoid any possible leaks when reading data from the firmware. Change the size argument of strlcpy to use SCMI_SHORT_NAME_MAX_SIZE always when dealing with short domain names, so as to limit the possibility that an ill-formed non-NULL terminated short reply from the SCMI platform firmware can leak stale content laying in the underlying transport shared memory area. While at that, convert all strings handling routines to use the preferred strscpy. Link: https://lore.kernel.org/r/20220608095530.497879-1-cristian.marussi@arm.com Fixes: b260fccaebdc2 ("firmware: arm_scmi: Add SCMI v3.1 protocol extended names support") Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Relax base protocol sanity checks on the protocol listCristian Marussi2022-06-061-5/+11
| | | | | | | | | | | | | | | | | | | | | Even though malformed replies from firmware must be treated carefully to avoid memory corruption in the kernel, some out-of-spec SCMI replies can be tolerated to avoid breaking existing deployed system, as long as they won't cause memory issues. Relax the sanity checks on the recieved protocol list in the base protocol to avoid breaking one of the deployed platform whose firmware is not easily upgradable currently. Link: https://lore.kernel.org/r/20220523171559.472112-1-cristian.marussi@arm.com Cc: Etienne Carriere <etienne.carriere@linaro.org> Cc: Sudeep Holla <sudeep.holla@arm.com> Reported-by: Nicolas Frattaroli <frattaroli.nicolas@gmail.com> Tested-By: Frank Wunderlich <frank-w@public-files.de> Acked-by: Michael Riesch <michael.riesch@wolfvision.net> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Dynamically allocate implemented protocols arrayCristian Marussi2022-04-281-7/+10
| | | | | | | | | | | | | | | | | | Move away from a statically allocated array for holding the current set of protocols implemented by the platform in favour of allocating it dynamically based on the number of protocols effectively advertised by the platform via BASE protocol exchanges. While at that, rectify the BASE_DISCOVER_LIST_PROTOCOLS loop iterations to terminate only when a number of protocols equal to the advertised ones has been received, instead of looping till the platform returns no more protocols descriptors. This new behaviour is better compliant with the specification and it has been tested to work equally well against an SCMI stack running on top of an official SCP firmware on a JUNO board. Link: https://lore.kernel.org/r/20220330150551.2573938-6-cristian.marussi@arm.com Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Validate BASE_DISCOVER_LIST_PROTOCOLS responseCristian Marussi2022-04-281-0/+24
| | | | | | | | | | | | | Do not blindly trust SCMI platform response about list of implemented protocols, instead validate the reported length of the list of protocols against the real payload size of the message reply. Link: https://lore.kernel.org/r/20220330150551.2573938-5-cristian.marussi@arm.com Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol") Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> [sudeep.holla: Added early break if loop_num_ret = 0 and simplified calc_list_sz calculation] Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Fix list protocols enumeration in the base protocolCristian Marussi2022-04-281-1/+1
| | | | | | | | | | | | | | | | While enumerating protocols implemented by the SCMI platform using BASE_DISCOVER_LIST_PROTOCOLS, the number of returned protocols is currently validated in an improper way since the check employs a sum between unsigned integers that could overflow and cause the check itself to be silently bypassed if the returned value 'loop_num_ret' is big enough. Fix the validation avoiding the addition. Link: https://lore.kernel.org/r/20220330150551.2573938-4-cristian.marussi@arm.com Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol") Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Make protocols initialisation fail on basic errorsCristian Marussi2022-04-281-1/+4
| | | | | | | | | | | Bail out of protocol initialisation routine early when basic information about protocol version and attributes could not be retrieved. Failing to act this way can lead to a successfully initialized SCMI protocol which is in fact not fully functional. Link: https://lore.kernel.org/r/20220330150551.2573938-3-cristian.marussi@arm.com Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Fix base agent discover responseVincent Guittot2021-11-171-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | According to scmi specification, the response of the discover agent request is made of: - int32 status - uint32 agent_id - uint8 name[16] but the current implementation doesn't take into account the agent_id field and only allocates a rx buffer of SCMI_MAX_STR_SIZE length Allocate the correct length for rx buffer and copy the name from the correct offset in the response. While no error were returned until v5.15, v5.16-rc1 fails with virtio_scmi transport channel: | arm-scmi firmware:scmi0: SCMI Notifications - Core Enabled. | arm-scmi firmware:scmi0: SCMI Protocol v2.0 'Linaro:PMWG' Firmware version 0x2090000 | scmi-virtio virtio0: tx:used len 28 is larger than in buflen 24 Link: https://lore.kernel.org/r/20211117081856.9932-1-vincent.guittot@linaro.org Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol") Tested-by: Cristian Marussi <cristian.marussi@arm.com> Reviewed-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Add protocol modularization supportCristian Marussi2021-03-301-0/+2
| | | | | | | | | | | | | Extend SCMI protocols accounting mechanism to address possible module usage and add the support to possibly define new protocols as loadable modules. Keep the standard protocols built into the SCMI core. Link: https://lore.kernel.org/r/20210316124903.35011-38-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Cleanup events registration transient codeCristian Marussi2021-03-301-2/+2
| | | | | | | | | | Remove all the events registration code used to ease the transition to the new interface based on protocol handles. Link: https://lore.kernel.org/r/20210316124903.35011-35-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Port base protocol to new interfaceCristian Marussi2021-03-291-57/+60
| | | | | | | | | Port the SCMI base protocol to new protocol handles based interface. Link: https://lore.kernel.org/r/20210316124903.35011-11-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Convert events registration to protocol handlesCristian Marussi2021-03-291-2/+2
| | | | | | | | | | | | | | | Convert all refactored events registration routines to use protocol handles. In order to maintain bisectability and to allow protocols and drivers to be later ported to the new protocol handle interface one by one, introduce here also some transient code that will be removed later in order to ease such transition. Link: https://lore.kernel.org/r/20210316124903.35011-8-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Refactor events registrationCristian Marussi2021-03-291-6/+9
| | | | | | | | | | | | | | | Add a new refactored protocol events registration helper and invoke it from the centralized initialization process triggered by get_ops() and friends. Also add a `get_num_sources` as a new optional callback amongst protocol events operations. Finally remove events registration call-sites from within the legacy protocol init routines. Link: https://lore.kernel.org/r/20210316124903.35011-7-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Extend protocol registration interfacesCristian Marussi2021-03-291-1/+9
| | | | | | | | | | | | | | | | Extend common protocol registration routines and provide some new generic protocols get/put helpers that can track protocols usage and automatically perform the proper initialization and de-initialization on demand when required. Convert all standard protocols to use this new registration scheme while keeping them all still using the usual initialization logic bound to SCMI devices probing. Link: https://lore.kernel.org/r/20210316124903.35011-2-cristian.marussi@arm.com Tested-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Add missing Rx size re-initialisationSudeep Holla2020-10-131-0/+2
| | | | | | | | | | | | | | | | | | | | | Few commands provide the list of description partially and require to be called consecutively until all the descriptors are fetched completely. In such cases, we don't release the buffers and reuse them for consecutive transmits. However, currently we don't reset the Rx size which will be set as per the response for the last transmit. This may result in incorrect response size being interpretted as the firmware may repond with size greater than the one set but we read only upto the size set by previous response. Let us reset the receive buffer size to max possible in such cases as we don't know the exact size of the response. Link: https://lore.kernel.org/r/20201012141746.32575-1-sudeep.holla@arm.com Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol") Reported-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Remove fixed size fields from reports/scmi_event_headerCristian Marussi2020-07-131-1/+1
| | | | | | | | | | | | | | | | | | | | Event reports are used to convey information describing events to the registered user-callbacks: they are necessarily derived from the underlying raw SCMI events' messages but they are not meant to expose or directly mirror any of those messages data layout, which belong to the protocol layer. Using fixed size types for report fields, mirroring messages structure, is at odd with this: get rid of them using more generic, equivalent, typing. Substitute scmi_event_header fixed size fields with generic types too and shuffle around fields definitions to minimize implicit padding while adapting involved functions. Link: https://lore.kernel.org/r/20200710133919.39792-3-cristian.marussi@arm.com Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Add base notifications supportCristian Marussi2020-07-011-4/+104
| | | | | | | | | Make SCMI base protocol register with the notification core. Link: https://lore.kernel.org/r/20200701155348.52864-10-cristian.marussi@arm.com Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Update protocol commands and notification listSudeep Holla2020-04-141-0/+7
| | | | | | | | | Add commands' enumerations and messages definitions for all existing notify-enable commands across all protocols. Link: https://lore.kernel.org/r/20200327143438.5382-3-cristian.marussi@arm.com Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: Use {get,put}_unaligned_le{32,64} accessorsSudeep Holla2019-08-121-1/+1
| | | | | | | | | | | Instead of type-casting the {tx,rx}.buf all over the place while accessing them to read/write __le{32,64} from/to the firmware, let's use the existing {get,put}_unaligned_le{32,64} accessors to hide all the type cast ugliness. Suggested-by: Philipp Zabel <p.zabel@pengutronix.de> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: use strlcpy to ensure NULL-terminated stringsSudeep Holla2018-09-101-1/+1
| | | | | | | | | | | | | Replace all the memcpy() for copying name strings from the firmware with strlcpy() to make sure we are bounded by the source buffer size and we also always have NULL-terminated strings. This is needed to avoid out of bounds accesses if the firmware returns a non-terminated string. Reported-by: Olof Johansson <olof@lixom.net> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: rename scmi_xfer_{init,get,put}Sudeep Holla2018-05-101-10/+13
| | | | | | | | | | | | | | | | | Just after the initial patches were queued, Jonathan Cameron mentioned that scmi_one_xfer_{get_put} were not very clear and suggested to use scmi_xfer_{alloc,free}. While I agree to some extent, the reason not to have alloc/free as these are preallocated buffers and these functions just returns a reference to free slot in that preallocated array. However it was agreed to drop "_one" as it's implicit that we are always dealing with one slot anyways. This patch updates the name accordingly dropping "_one" in both {get,put} functions. Also scmi_one_xfer_init is renamed as scmi_xfer_get_init to reflect the fact that it gets the free slots and then initialise it. Reported-by: Jonathan Cameron <jonathan.cameron@huawei.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: fix kernel-docs documentationSudeep Holla2018-05-091-9/+11
| | | | | | | | | | | There are few missing descriptions for function parameters and structure members along with certain instances where excessive function parameters or structure members are described. This patch fixes all of those warnings. Reported-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
* firmware: arm_scmi: add common infrastructure and support for base protocolSudeep Holla2018-02-281-0/+253
The base protocol describes the properties of the implementation and provide generic error management. The base protocol provides commands to describe protocol version, discover implementation specific attributes and vendor/sub-vendor identification, list of protocols implemented and the various agents are in the system including OSPM and the platform. It also supports registering for notifications of platform errors. This protocol is mandatory. This patch adds support for the same along with some basic infrastructure to add support for other protocols. Cc: Arnd Bergmann <arnd@arndb.de> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>