Commit graph

33 commits

Author SHA1 Message Date
Cristian Marussi
e6d0edd2fe scmi: Add sysctl transport properties
Expose as read-only the configured transport properties.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47428
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:27 +00:00
Cristian Marussi
984f9fb81a scmi: Add SDT traces to the core stack
Add a few basic traces to track SCMI messages lifecycle.

Tested on:      Arm Morello Board
Reviewed by:	Andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47427
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:27 +00:00
Cristian Marussi
b802926b7b scmi: Add optional asynchronous handling of replies
Add the core logic to handle the replies to pending command in an
asynchronous manner.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47426
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:27 +00:00
Cristian Marussi
341d8fd90f scmi: Refactor scmi_request internal logic
Split scmi_request internals into a TX and an RX phase, which will be
called, anyway, in sequence as before when a normal transmission is
requested.

No functional change.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47425
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:27 +00:00
Cristian Marussi
c508841dfc scmi: Add scmi_token_reserve helper
During normal operation, the SCMI stack, upon each transmission attempt,
takes care to automatically pick an appropriate, monotonically increasing,
sequence number to fill-in the token field in the egressing message.

This does not cope well with the alternative scenario in which, instead,
a complete and fully formed message is provided upfront: in such a case the
SCMI stack will have to use the already provided sequence number, embedded
in the message, to track such transaction.

Add a method to attempt to reserve a specific sequence number to be used
when a fully firmed (raw) message is handled.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Pull Request:	https://reviews.freebsd.org/D47424
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:27 +00:00
Cristian Marussi
e887179d4b scmi: Add helper to manipulate scmi_msg descriptors
Refactor allocation logic for scmi_req and introduce new helpers to be able
to obtain an scmi_msg reference to a freshly allocated request.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47423
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Cristian Marussi
103ea03e67 scmi: Add devicetree transport properties
SCMI transport characteristics can be optionally described in the
devicetree to override the default build-time values.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47422
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Cristian Marussi
f021623949 scmi: Redefine max message payload size
The defined maximum payload size should not include header and status
field. Fix the definition accordingly, so that it matches the
definitions as can be found in the Linux SCMI stack.
The semantic of this define is important since it will then be possible
to override such values from devicetree, like in Linux.

Tested on:	Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47421
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Cristian Marussi
9342829d57 scmi: Make transports report the effective length of the received messages
Once a message is received that fits into the RX buffer, update the
msg.rx_len field with the effective length of the message received.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Pull Request:	https://reviews.freebsd.org/D47420
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Cristian Marussi
c56e586f0f scmi: Fix race on timed out transmissions
When a waited-for outstanding request is determined to have timed out,
mark such request immediately as such, so as to avoid any possible race on
the IRQ path with code path evaluating that same timed out condition.

Tested on:      Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47419
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Cristian Marussi
00b77e631b scmi: Fix token bitmask
By the SCMI specification the message sequence number field is 10-bit long.
Fix accordingly the used bitmask.

Fixes: d220b1cf02 ("scmi: Extend and refactor SCMI shmem support")
Tested on:	Arm Morello Board
Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D47418
Signed-off-by:	Cristian Marussi <cristian.marussi@arm.com>
2025-01-23 17:26:26 +00:00
Andrew Turner
23f025e24b scmi: Fix the scmi_shmem module name
This fixes the "module scmi already present" message on boot.

Sponsored by:	Arm Ltd
2025-01-23 17:26:24 +00:00
John Baldwin
18250ec6c0 Replace calls to bus_generic_attach with bus_attach_children
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47675
2024-12-06 17:26:16 -05:00
John Baldwin
723da5d92f Replace calls to bus_generic_probe with bus_identify_children
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47674
2024-12-06 17:26:05 -05:00
Andrew Turner
b9cd72b06d sys: Use the new arm_smccc_invoke macros
Simplify the calls into the SMCCC firmware with the new
arm_smccc_invoke* macros.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D46987
2024-10-15 18:24:41 +01:00
Cristian Marussi
a87dd74125 scmi: Add an SCMI VirtIO transport driver
Add an SCMI transport driver based on the virtio-scmi backend.

Reviewed by:	andrew, bryanv
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43048
2024-04-11 09:58:57 +00:00
Cristian Marussi
35f9320396 scmi: Introduce a new SCMI API and port CLK SCMI driver to it
Expose new scmi_buf_get/put API methods to build and send messages;
command request descriptors are now pre-allocated when the SCMI core is
initialized and kept in a free list, instead of being allocated on the
stack of the caller of the SCMI request.

Dynamically allocated descriptors enable the SCMI core to keep around
and track outstanding transactions for as long as needed, outliving the
lifetime of the caller stack: this allows tracking of late or missing
replies and it will be needed when adding support for SCMI transports
that allows for more messages to be inflight concurrently.

Move the existing CLK SCMI driver to the new API.

Reviewed by:	andrew
Tested on:	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43046
2024-04-11 09:58:56 +00:00
Cristian Marussi
3595f18fc7 scmi: Add SCMI message tracking and centralize tx/rx logic
In order to be able to support also new, more parallel, SCMI transports
that by nature can allow multiple concurrent commands to be in-flight,
pending a reply, we must be able to use the sequence number provided in
the SCMI messages to track the message status, matching commands and
replies while keeping track of timeouts and duplicates.

Add the needed message tracking machinery in the core SCMI stack and
move the residual common tx/rx logic from the specific transports to
the core SCMI stack, while adding one more interface to let the
transports customize ther behaviour.

Reviewed by:	andrew
Tested on: 	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43045
2024-04-11 09:58:56 +00:00
Cristian Marussi
403ca28c28 scmi: Add new SCMI interfaces for init and message processing
Introduce a couple of new SCMI interface methods to allow centralized
initialization of transport-specific features and a couple of methods
to handle message reception from the SCMI core.

Move SCMI SMT related calls out of the core common SCMI code into the
transport specific layers Mailbox/SMC.

Make SCMI Mailbox/SMC transports use the new interface methods for
initialization and message reception.

Reviewed by:	andrew
Tested on:	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43044
2024-04-11 09:58:56 +00:00
Cristian Marussi
a0ba2a97fd scmi: Protect SCMI/SMT channels from concurrent transmissions
The SCMI/SMT memory areas are used from the agent and the platform as
channels to exchage commands and replies.

Once the platform has completed its processing and a reply is ready to
be read from the agent, the platform will relinquish the channel to the
agent by setting the CHANNEL_FREE bits in the related SMT area.

When this happens, though, the agent has still to effectively read back
the reply message and any other concurrent request happened to have been
issued in the meantime will have been to be hold back until the reply
is processed or risk to be overwritten by the new request.

The base->mtx lock that currently guards the whole scmi_request()
operation is released when sleeping waiting for a reply, so the above
mentioned race can still happen or, in a slightly different scenario,
the concurrent transmission could just fail, finding the channel busy,
after having sneaked through the mutex.

Adding a new mechanism to let the agent explicitly acquire/release the
channel paves the way, in the future, to remove such central commmon
lock in favour of new dedicated per-transport locking mechanisms, since
not all transports will necessarily need the same level of protection.

Add a flag, controlled by the agent, to mark when the channel has an
inflight command transaction still pending to be completed and make the
agent spin on it when queueing multiple concurrent messages on the same
SMT channel.

Reviewed by:	andrew
Tested on:	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43043
2024-04-11 09:58:56 +00:00
Cristian Marussi
cbcfdff056 scmi: Fix SCMI mailbox polling mechanism
When the system is cold, the SCMI stack processes commands in polling
mode with the current polling mechanism being a check of the status
register in the mailbox controller to see if there is any pending
doorbell request.

Anyway, the completion interrupt is optional by the SCMI specification
and a system could have been simply designed without it: for this
reason polling on the mailbox controller status registers is not going
to work in all situations.

Moreover even alternative SCMI transports based on shared memory, like
SMC, will not have at all a mailbox controller to poll for.

On the other side, the associated SCMI Shared Memory Transport defines
dedicated channel flags and status bits that can be used by the agent to
explicitly request a polling-based transaction, even if the completion
interrupt was available, and to check afterwards when the platform has
completed its processing on the outstanding command.

Use SCMI/SMT specific mechanism to process transactions in polling mode.

Reviewed by:	andrew
Tested on:	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43042
2024-04-11 09:58:56 +00:00
Cristian Marussi
d220b1cf02 scmi: Extend and refactor SCMI shmem support
Add a few new common public scmi_shmem methods to be used to handle SCMI
shared memory areas from multiple transports; while doing that review
the shared memory accesses to read only the SMT header fields strictly
relevant to the SCMI message processing.

Move all the SCMI shmem related code to the existing scmi_shmem.c file
and add a new dedicated scmi_shmem.h header.

Introduce some commonly needed message header manipulation macros.

Reviewed by:	andrew
Tested on:	Arm Morello Board
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43041
2024-04-11 09:58:56 +00:00
Andrew Turner
5ea251c4ed scmi: Add an SCMI SMC transport driver
Using the SCMI transport interface add a new SMC transport to the
SCMI stack.

Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43040
2024-04-11 09:58:56 +00:00
Andrew Turner
d46f01fd59 scmi: Split out the SCMI mailbox to a new file
Add a new SCMI interface file to allow for multiple kind of transports
and move the mailbox transport to its own file, using the new interface.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43039
2024-04-11 09:58:56 +00:00
Cristian Marussi
ecd8cc84dc scmi: Implement scmi_clknode_recalc_freq method
Allow the SCMI clock frequency to be queried back, useful for testing
the IRQ path via sysctl access.

Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43038
2024-04-11 09:58:56 +00:00
Emmanuel Vadot
be82b3a0bf clk: Move clock code in dev/clk
We've removed kernel option EXT_RESOURCES almost two years ago.
While it was ok to have some code under a common 'extres' subdirectory
at first, we now have a lot of consumer of it and we made it mandatory
so no need to have it under a cryptic name.

Reviewed by:	mhorne
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D43191
2024-01-10 19:20:26 +01:00
Warner Losh
fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
John Baldwin
f53355131f Trim various $FreeBSD$
Approved by:	markj (cddl/contrib changes)
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41961
2023-10-10 10:34:43 -07:00
Emmanuel Vadot
9e88711f28 arm64: zynqmp: Add firmware driver
The ZynqMP SoC have a MCU running a firmware to control clocks, resets,
fpga loading etc ...
Add a driver that can be use to communicate with it.
For now only the clock and reset part are implemented.

Differential Revision:	https://reviews.freebsd.org/D41811
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2023-09-18 15:23:26 +02:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Mark Johnston
19a7cf0ce8 scmi: Suppress a couple of -Wunused-function warnings
No functional change intended.

Sponsored by:	Klara, Inc.
2023-02-24 13:44:52 -05:00
Ruslan Bukin
54b96380f5 Add support for ARM System Control and Management Interface (SCMI) v3.1.
The SCMI specification describes a set of standard interfaces for power,
performance and system management.

SCMI is extensible and provides interfaces to access functions which are
often implemented in firmwares in the System Control Processor (SCP).

This implements Shared Memory-based transfer, which is one of the ways on
how messages are exchanged between agents and the platform.

This includes a driver for ARM Message Handling Unit (MHU) Doorbell, which
is a mechanism that the caller can use to alert the callee of the presence
of a message.

The support implements clock management interface. For instance this allows
us to control HDMI pixel clock on ARM Morello Board.

Tested on ARM Morello Board.

Obtained from: CheriBSD
Differential Revision:	https://reviews.freebsd.org/D37316
Reviewed by:	manu
Sponsored by:	UKRI
2022-12-19 22:28:21 +00:00