Commit Graph

41 Commits

Author SHA1 Message Date
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
Andrew Turner
7d0b915919 Add PSCI affinity info return values
These can be returned from the PSCI AFFINITY_INFO call. This is not
marked as optional so bhyve will need to implement it & can use these
macros.

Sponsored by:	Arm Ltd
2023-03-16 13:08:00 +00:00
Andrew Turner
e89be21854 Add a psci macro to build a version value
Add PSCI_VER that takes a major and minor version and builds the value
returned by the firmware. This will be used by bhyve.

Sponsored by:	Arm Ltd
2023-03-16 13:08:00 +00:00
Andrew Turner
473ab212dc Allow psci.h to be used by userspace
Wrap parts of psci.h that aren't usable by userspace in _KERNEL checks.
This allows it to be used to implement PSCI and SMCCC by bhyve in
userspace.

Sponsored by:	Arm Ltd
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
2023-03-16 13:08:00 +00:00
John Baldwin
6cc52efa13 arm_smcc_1_2_*: Don't trash SP and X19 if no return value structure.
Jumping direct to ret was not restoring the saved value of x19 and was
also not adjusting sp to discard the two saved registers.

Reviewed by:	andrew
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D37922
2023-02-01 13:54:09 -08:00
Andrew Turner
7ca55fcc54 Only call SMCCC init on arm64
We don't build the smccc code on arm so don't call into it there.
2023-01-29 19:33:41 +00:00
Andrew Turner
0600af1ff1 Make SMCCC usable by device drivers
To allow device drivers to call into SMCCC we need to initialise it
earlier. As it depends on PSCI, and that is detected via ACPI or FDT
move the call to smccc_init to the PSCI driver.

Add a function for drivers to read the smccc version, or 0 if smccc
is not present.
2023-01-29 14:58:24 +00:00
Kyle Evans
866beaa0aa psci: set psci_present as early as possible
psci_attach is way too late to provide the intended semantics for
psci_present.  psci calls can be made immediately after psci_init(),
called way earlier at SI_SUB_CPU + SI_ORDER_FIRST, and we need it to
be valid as early as we can possibly call a psci function.

This fixes booting RPi3+4 with the in-review spintable patch;
rpi3-psci-monitor patches the FDT to add a PSCI node, but it doesn't
patch each cpus' enable-method.  Because of this, we would stall the
boot while enabling CPU 1 as we saw a valid looking enable-method and
"no" functional PSCI and attempted to use the spintable rather than
simply not starting secondary APs.

Fixes:	2218070b2c ("psci: finish psci_present implementation")
Reported by:	karels
2022-10-26 23:22:23 -05:00
Wei Hu
7a58bf0443 arm64: Enabling new hypercalls using HvCallSetVpRegisters and HvCallGetVpRegisters
Enabling HvCallSetVpRegisters and HvCallGetVpRegisters for hypercalls to
read and write to specific MSRs. This is required for implementing wrmsr
and rdmsr, which is required for Hyper-V vmbus driver for ARM64.

Also we need to use arm smccc hvc 1.2 version as we need to access
registers beyond X0-X3 for HvCallGetVpRegisters. Currently scoping
it only for Hyper-V.

Reviewed by:	lwhsu, andrew, whu
Tested by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Signed-off-by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D36256
2022-09-26 06:30:37 +00:00
Andrew Turner
48a7e53db7 Merge the common parts of the SMCCC handlers
To simplify adding new handlers merge the common parts of the functions
used to call into the arm SMCCC firmware.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36297
2022-08-25 12:17:28 +01:00
John Baldwin
395bee1285 psci: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:46 -07:00
Kyle Evans
2218070b2c psci: finish psci_present implementation
This was already declared in psci.h, but it was never defined/set.  Do
this now, so we can use it to decide if enable-method in /cpus FDT nodes
should be inspected later on.  While we're here, convert it to a
boolean.

Reviewed by:	andrew (slightly earlier version)
Differential Revision:	https://reviews.freebsd.org/D34553
2022-03-18 22:04:32 -05:00
Mateusz Guzik
0bc261868a psci: clean up empty lines in .c and .h files 2020-09-01 21:58:29 +00:00
Ruslan Bukin
7722d8c7c0 Add generic arm/arm64 secure-monitor SMCCC interface and switch
PSCI code to use it.

This interface will also be used by Intel Stratix 10 platform.

This was not tested on arm due to lack of PSCI-enabled arm hardware
lying around.

Reviewed by:	andrew
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D21439
2019-09-13 15:56:33 +00:00
Michal Meloun
91e4401364 PSCI: Don't take missing implementation of psci get_version() as fatal.
Minimalistic PSCI implementation in U-Boot doesn't implement get_version()
method for some SoC. In this case, use PSCI version declared by 'psci' node
in DT as fallback.

MFC after:	2 weeks
2019-03-19 15:42:11 +00:00
Luiz Otavio O Souza
217643e7da Fix a typo on the PSCI smc call wrapper.
Looks good from:	andrew
Sponsored by:	Rubicon Communications, LLC (Netgate)
2018-08-14 13:56:49 +00:00
Andrew Turner
100a6d1905 Use int for the pcpu_ssbd argument. This is included from userland and may
not include the needed headers to get the bool definition.

Reported by:	manu
Pointy hat to:	andrew
Sponsored by:	DARPA, AFRL
2018-07-31 15:08:02 +00:00
Andrew Turner
0594061ee6 Implement the SSBD (CVE-2018-3639) workaround on arm64
This calls into the Arm Trusted Firmware to enable and disable the
workaround for the Speculative Store Bypass Disable (SSBD) issue, also
known as Spectre Variant 4.

As this may have a large performance overhead, and how exploitable SSBD is
is unknown we follow the Linux lead of allowing the administrator to select
between always on, always off, or only enabled in the kernel, with the
latter being the default.

PR:		228955
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D15819
2018-07-31 12:53:27 +00:00
Emmanuel Vadot
85ab1415ff psci: Add \n at the end of printf
Add a \n at the end of the printf if no PSCI function was found otherwise
it mess up the console log.
2018-07-06 17:39:48 +00:00
Andrew Turner
1d802c646c Move the SMCCC SYSINIT later in the boot so the psci driver has attached.
Sponsored by:	DARPA, AFRL
2018-06-20 10:57:29 +00:00
Andrew Turner
95c4b3c735 Fix the SMCCC signatures, they are all 32-bit calls. This fixes SMCCC
version detection.

Sponsored by:	DARPA, AFRL
2018-06-20 10:02:50 +00:00
Andrew Turner
09d1a08ddc Add the SMCCC return codes from ARM DEN 0070A.
While here add a comment with the document the function IDs come from.

Sponsored by:	DARPA, AFRL
2018-06-13 15:41:22 +00:00
Andrew Turner
f651b52527 Add support for the ARM SMC Calling Convention (SMCCC). This is a method
to call into the firmware in a similar way to the existing PSCI, and used
PSCI to detect when SMCCC is enabled.

There is a function ID space we can use. Currently we only support 3
functions in the ARM Architecture Calls region, however it is expected we
will expend these in the future.

Sponsored by:	DARPA, AFRL
2018-06-13 15:32:00 +00:00
Andrew Turner
9e8cb3d226 Move psci_call to a header file so we can use it in other files to
communicate with the firmware.

Sponsored by:	DARPA, AFRL
2018-06-13 15:24:07 +00:00
Andrew Turner
5add83935a Add a handler for the PSCI_FEATURES function. This needs PSCI 1.0, so
check for this, returning an error if the version is too old.

Sponsored by:	DARPA, AFRL
2018-06-13 12:33:47 +00:00
Andrew Turner
4493861b9a Find and cache the PSCI version on driver attach.
Sponsored by:	DARPA, AFRL
2018-06-13 12:32:04 +00:00
Andrew Turner
811880f2a4 Add the PSCI_FEATURES function ID. This is found in PSCI 1.0 and is used
to query if a given function is implemented and its features.

Sponsored by:	DARPA, AFRL
2018-06-13 12:26:37 +00:00
Andrew Turner
0c38b2d37c Rework PSCI so it only searches for the call function once.
This is in preperation for supporting newer smccc functions that also use
the same call method.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D15745
2018-06-12 14:54:17 +00:00
Andrew Turner
8ab09f8a4e Add a function to find the PSCI version the firmware implements from
outside the PSCI driver.

MFC after:	1 week
Sponsored by:	DARPA, AFRL
2018-01-09 15:57:09 +00:00
Ed Maste
a5c9ec376b psci: change bootverbose string to 'PSCI 0.2 compatible'
Prior to r324754 we treated PSCI 0.2 and 1.0 as identical, and r324754
extended that to include all PSCI 1.x revisions. Change the string
emitted under bootverbose to reference '0.2 compatible' to avoid
confusion when the system includes a later PSCI rev.

Discussed with:	andrew
Sponsored by:	The FreeBSD Foundation
2017-10-19 16:40:17 +00:00
Andrew Turner
833a983e5e Allow later PSCI revisions to also work. The latest ARM Trusted Firmware
reports version 1.1 so the check was failing. As thjis is a minor change
from 1.0, and future 1.x revisions are also expected to be backwards
compatible just ignore the minor revision in the init handler.

Sponsored by:	DARPA, AFRL
2017-10-19 13:22:52 +00:00
Andrew Turner
845ed71645 Also handle psci 1.0. This can be seen as a bug fix update for the 0.2
specification we already support, with the only changes in functions we
don't currently use.

Sponsored by:	DARPA, AFRL
2017-10-06 15:46:11 +00:00
Ed Maste
fa8d7c4417 arm: add .arch_extension sec for smc instruction
Clang 4.0 accepts the smc instruction with or without specifying
.arch_extension sec, but Clang 5.0 produces an error without it.

MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
2017-06-18 00:08:38 +00:00
Andrew Turner
574a7c6c47 Call the PSCI reset from cpu_reset on arm64. When rebooting from DDB the
kernel calls this directly so the event handler is not called, meaning
the computer fails to reboot.

Tested by:	cognet
MFC after:	1 week
Sponsored by:	DARPA, AFRL
2017-04-24 11:06:10 +00:00
Andrew Turner
2b5014f6fe Add ACPI support to the PSCI driver. This checks the Fixed ACPI Description
Table to find if the hardware supports PSCI, and if so what method the
kernel should use to interact with it.

Obtained from:	ABT Systems Ltd
Sponsored by:	The FreeBSD Foundation
2016-12-07 14:24:53 +00:00
Andrew Turner
c2dd354bf4 Create a new PSCI error code and use it to signal that starting the CPU is
impossible as the PSCI firmware is missing.

Sponsored by:	ABT Systmes Ltd
2016-10-25 14:18:27 +00:00
Andrew Turner
6e3244f594 Start to support PSCI 1.0. For all the functions we currently support this
can be seen as the same as 0.2. There are changes with the data passed to
CPU_SUSPEND, however we don't yet use this call.

Sponsored by:	ABT Systems Ltd
2015-08-11 13:42:58 +00:00
Andrew Turner
7ad1ac7d6a Rework the PSCI cpu on code to allow it to work before device drivers have
started. This allows this functions to be used with the regular ARM SMP
initialisation sequence.
2015-05-24 11:08:06 +00:00
Andrew Turner
7d9cff3d23 Add psci for arm64. This is currently used when rebooting and powering off
in qemu.

Sponsored by:	The FreeBSD Foundation
2015-04-13 16:41:33 +00:00
Andrew Turner
46b1fe9224 Add a driver for the ARM Power State Coordination Interface (PSCI). This
handles versions 0.1 and 0.2 of the standard on 32-bit ARM.

With this driver we can shutdown in QEMU. Further work is needed to
turn secondary cores on on boot and to support later revisions of the
specification.

Submitted by:	Robin Randhawa <Robin.Randhawa at ARM.com>
Sponsored by:	The FreeBSD Foundation
2015-04-12 13:00:58 +00:00