Commit Graph

2255 Commits

Author SHA1 Message Date
Jessica Clarke
4f7b3120bc arm64: Delete redundant badly formatted and capitalised comment
Fixes:	9729f076e4 ("arm64: Hyper-V: enablement for ARM64 in Hyper-V (Part 3, final)")
2023-03-14 04:15:03 +00:00
Jessica Clarke
aa39abd8e5 arm64: Move Azure-specific config from std.hyperv to std.azure
Hyper-V does not provide Mellanox hardware, some of Azure's instances
do, thus the configuration to enable them does not belong in the generic
std.hyperv config.

Fixes:	15e7fa83ef ("arm64: Hyper-V: Add vPCI and Mellanox driver modules into build")
2023-03-14 04:12:31 +00:00
Wei Hu
15e7fa83ef arm64: Hyper-V: Add vPCI and Mellanox driver modules into build
These changes in conf and std.hyperv files got missed in previous commit.
Reviewed by:	whu
Tested by:	whu
Obtained from:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D38529
2023-03-13 02:55:04 +00:00
Kyle Evans
1867702942 arm64: fix the LINT-ACPI build
This file uses VM_MEMATTR_DEVICE_NP, which it gets through header
pollution somewhere with FDT enabled.  Pull in vm/vm.h to make it
explicit.
2023-03-07 11:37:31 -06:00
Kyle Evans
d71a00e9f5 arm64: ofw: respect the nonposted-mmio prop in OF_decode_addr()
This is the only mapping remaining which needs to respect nonposted-mmio
to avoid breaking the boot on Apple silicon.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38920
2023-03-07 00:15:32 -06:00
Andrew Turner
5a91529479 Support non-posted MMIO on arm64 with FDT
To allow hardware to work around a broken memory bus where we need to
support the nonposted-mmio flag.

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D34333
2023-03-05 20:17:21 +00:00
Andrew Turner
cb894f746c Map arm64 pci config memory as non-posted
On arm64 PCI config memory is expected to be mapped with a non-posted
device type. To handle this use the new bus_map_resource support in
arm64 to map memory with the new VM_MEMATTR_DEVICE_NP attribute. This
memory has already been allocated and activated, it just needs to be
mapped.

Reviewed by:	kevans, mmel
Differential Revision:	https://reviews.freebsd.org/D30079
2023-03-05 20:17:21 +00:00
Dmitry Chagin
cabbfb60d0 linux(4): Reduce code duplication between MD files
Move struct ifnet definitions under compat/linux.

Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D38791
2023-03-04 12:11:38 +03:00
Kyle Evans
d2ae03bae2 arm64: disable the physical timer for now if HCR_EL2.E2H is set
On some hardware, we can't clear HCR_EL2.E2H so accesses to the physical
timer hopelessly trap to EL2.  Stash off the value of HCR_EL2 and use it
in has_hyp() to avoid this.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38884
2023-03-03 11:02:34 -06:00
John-Mark Gurney
2fee875629
abstract out the vm detection via smbios..
This makes the detection of VMs common between platforms that
have SMBios.

Reviewed by:		imp, kib
Differential Revision:	https://reviews.freebsd.org/D38800
2023-03-02 16:54:21 -08:00
John Baldwin
d90188eff5 hwpmc: Don't wrap entire files in #ifdef DEV_ACPI.
A subsequent commit will instead use existing infrastructure to
exclude the files from hwpmc.ko for non-ACPI builds.  Note that the
original commit left the files as optional in sys/conf/files.arm64.

This reverts commit 751d88119f.

Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38736
2023-03-01 10:31:53 -08:00
Dapeng Gao
281402e0a5 arm64: Shave off two instructions in exceptions
This patch shaves off up to two three instructions in
save_registers_head in exception.S for arm64, which would make more
space for instructions that could be added in CheriBSD.

This is done by:
 1. Combining pointer arithmetic with pre-incrementing STP instructions
 2. Removing the instruction that sets the frame pointer (x29) as its
    content is unused

Differential Revision:	https://reviews.freebsd.org/D34631
2023-03-01 14:43:43 +00:00
Kyle Evans
dc8616edc5 arm64: set FPEN if we're stuck with HCR_EL2.E2H
On Apple Silicon systems, E2H can't actually be cleared; we're stuck
with it.  Check it again when we're setting up CPTR_EL2 and set FPEN
appropriately to avoid later trapping to EL2 on writes to SIMD
registers.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38819
2023-02-28 16:16:14 -06:00
Mike Karels
f12907d01a arm64 kernel config: clean up whitespace
Most options in kernel config files use "options<space><tab>OPTION".
This allows the option to be commented out without shifting columns.
A few options had two tabs, and some had spaces.  Make them consistent.
2023-02-24 08:36:29 -06:00
Mateusz Guzik
6b9acd1bfb Exclude MMCCAM kernels from make universe
They don't provide any value and are quite arbitrary.

Note arm64 GENERIC-MMCCAM was already excluded, just not the NODEBUG
variant.

The option is already build-tested with arm64 LINT kernel.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D38458
2023-02-16 07:29:53 +00:00
Dmitry Chagin
c8a79231a5 linux(4): Rename linux_timer.h to linux_time.h
To avoid confusing people, rename linux_timer.h to linux_time.h,
as linux_timer.c is the implementation of timer syscalls only,
while linux_time.c contains implementation of all stuff declared
in linux_time.h.

MFC after:		2 weeks
2023-02-14 17:46:33 +03:00
Dmitry Chagin
55d3e181fc linux(4): Cleanup includes under arm64/linux
Cleanup unneeded includes, sort the rest according to style(9).
No functional changes.

MFC after:		2 weeks
2023-02-14 17:46:33 +03:00
Dmitry Chagin
31e938c531 linux(4): Cleanup vm includes from linux_util.h
Include vm headers directly where they needed. The linux_util.h included
in a most source files of the Linuxulator, avoid collecting a rarely used
includes here.

MFC after:		2 weeks
2023-02-14 17:46:30 +03:00
John Baldwin
18bb97b76b arm64 pmap: Fix a buffer overrun initializing per-superpage locks.
pmap_init_pv_table makes a first pass over the memory segments to
compute the amount of address space needed to allocate per-superpage
locks.  It then makes a second pass over each segment allocating
domain-local memory to back the pages for the locks belonging to each
segment.  This second pass rounds each segment's allocation up to a
page size since the domain-local allocation has to be a multiple of
pages.  However, the first pass was only doing a single round of the
total page counts up at the end not accounting for the padding present
in each segment.  To fix, apply the rounding in each segment in the
first pass instead of just at the end.

While here, tidy the second pass a bit by trimming some
not-quite-right logic copied from amd64.  In particular, compute pages
directly at the start of the loop iteration to more closely match the
first loop.  Then, drop an always-false condition as 'end' was
computed as 'start + pages' where 'start == highest + 1'.  Thus, the
actual condition being tested was 'if (highest >= highest + 1 +
pages)'.  Finally, remove 'highest' entirely by keep the result of the
'pvd' increment in the existing loop.

Reported by:	CHERI (overflow)
Reviewed by:	markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38377
2023-02-13 13:19:03 -08:00
Dmitry Chagin
10d16789a3 linux(4): Get rid of the opt_compat.h include.
Since e013e369 COMPAT_LINUX, COMPAT_LINUX32 build options are removed,
so include of opt_compat.h is no more needed.

MFC after:		2 weeks
2023-02-12 20:24:32 +03:00
Elliott Mitchell
f9bdaab95e ofwbus: remove handling of resources from ofwbus
The architecture nexus should handle allocation and release of memory and
interrupts. This is to ensure that system-wide resources such as these
are available to all devices, not just children of ofwbus0.

On powerpc this moves the ownership of these resources up one level,
from ofwbus0 to nexus0. Other architectures already have the required
logic in their nexus implementation, so this eliminates the duplication
of resources. An implementation of nexus_adjust_resource() is added for
arm, arm64, and riscv.

As noted by ian@ in the review, resource handling was the main bit of
logic distinguishing ofwbus from simplebus. With some attention to
detail, it should be possible to merge the two in the future.

Co-authored by:	mhorne
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D30554
2023-02-08 16:50:46 -04:00
Val Packett
4a1c4de232 Allow sysctl hw.machine/hw.machine_arch in capability mode
There's no harm in reading strings like 'amd64'.

Reviewed by: emaste, manu
Sponsored by: https://www.patreon.com/valpackett
Differential Revision: https://reviews.freebsd.org/D28703
2023-02-06 14:00:52 -05:00
Andrew Turner
f29942229d Read the arm64 far early in el0 exceptions
When handling userspace exceptions on arm64 we need to dereference the
current thread pointer. If this is being promoted/demoted there is a
small window where it will cause another exception to be hit. As this
second exception will set the fault address register we will read the
incorrect value in the userspace exception handler.

Fix this be always reading the fault address before dereferencing the
current thread pointer.

Reported by:	olivier@
Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38196
2023-02-02 16:43:15 +00:00
Andrew Turner
03d6e03851 Check for the IORT before adding the ITS driver
Before adding the ITS interrupt controller driver to handle MSI/MSI-X
interrupts check if it is present in the IO Remapping Table (IORT).
If not don't attach as devices expect to use this table to find the
correct MSI interrupt controller.

Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37772
2023-02-02 16:43:15 +00:00
Dmitry Chagin
95b8603427 linux(4): Deduplicate linux_trans_osrel().
MFC after:		1 week
2023-02-02 17:58:07 +03:00
Dmitry Chagin
6039e966ff linux(4): Deduplicate linux_copyout_strings().
It is still present in the 32-bit Linuxulator on amd64.

MFC after:		1 week
2023-02-02 17:58:07 +03:00
Dmitry Chagin
7446514533 linux(4): Microoptimize linux_elf.h for future use.
In order to reduce code duplication move coredump support definitions
into the appropriate header and hide private definitions.

MFC after:		1 week
2023-02-02 17:58:06 +03:00
Konstantin Belousov
83a49712af kstack_contains(): account for struct pcb on stack
for arm64, arm, powerpc, and riscv

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
2023-02-02 00:59:27 +02:00
Konstantin Belousov
2555f175b3 Move kstack_contains() and GET_STACK_USAGE() to MD machine/stack.h
Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
2023-02-02 00:59:26 +02:00
Dmitry Chagin
575e48f1c4 linux(4): Deduplicate MI futex structures.
MFC after:	1 week
2023-02-01 21:57:04 +03:00
Wei Hu
c75ae52216 arm64: Hyper-V: vPCI: Fix typo and some indentations
Fix a typo and some indentation errors in the previous commits.

Reported by:	jrtc27
Fixes:	db247798c5 ("arm64: Hyper-V: vPCI: SPI MSI mapping for gic v3 acpi in arm64")
Fixes:	6e5b082cab ("arm64: Hyper-V: vPCI: Adding Hyper-V PCI protocol 1.4")
Sponsored by:	Microsoft
2023-02-01 17:34:19 +00:00
Wei Hu
db247798c5 arm64: Hyper-V: vPCI: SPI MSI mapping for gic v3 acpi in arm64
Microsoft Azure Hyper-V uses SPI to map MSI in ARM64, instead of
using LPI IDS. To enable that we need to have gic registered with
ACPI_MSI_XREF and gic acpi to map SPI for MSI.

This is the 1st of the three patchs to enable Hyper-V vPCI support
in arm64.

Reviewed by:	andrew, emaste, whu
Tested by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Obtained from:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D37763
2023-02-01 15:40:08 +00:00
Justin Hibbits
b7459fb0ad Mechanically convert genet(4) to IfAPI
Sponsored by:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37832
2023-01-31 16:26:34 -05:00
Alexander V. Chernikov
e80699a809 netlink: add NETLINK to GENERIC.
This is a followup of 692e19cf51 (add netlink to GENERIC@amd64).

Netlink is a communication protocol defined in RFC 3549. It is async,
TLV-based protocol, providing 1-1 and 1-many communications between kernel
and userland. Netlink is currently used in Linux kernel to modify, read and
subscribe for nearly all networking states. Interface state, addresses, routes,
firewall, rules, fibs, etc, are controlled via Netlink.

Netlink support was added in D36002. It has got a number of improvements and
first customers since then:
* net/bird2 got netlink support, enabling route multipath in FreeBSD
* netlink-based devd notifications are being worked on ( D37574 ).
* linux(4) fully supports and depends on Netlink

Enabling Netlink in GENERIC targets two goals.
The first one is to provide stability for the third-party userland applications,
so they can rely on the fact that netlink always exists since 14.0 and potentially 13.2.
Loadable module makes life of the app delepers harder. For example, `net/bird2` can be
either build with netlink or rtsock support, but not both.

The second goal is to enable gradual conversion of the base userland tools
to use netlink(4) interfaces. Converting tools like netstat (D36529), route,
ifconfig one-by-one simplifies testing and addressing the feedback.
Othewise, switching all base to use netlink at once may be too big of a leap.

MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D37783
2023-01-31 14:22:11 +00:00
Emmanuel Vadot
5a00612149 arm64: Move device scmi to std.arm
The scmi driver in its current form requires the arm_doorbell
driver to communicate with the firmware.
The arm_doorbell is only found in ARM Juno reference board (and
apparently on Morello too).
If we want to use scmi on other platform (like some rockchip or imx
soc), the driver needs to be updated to support svc/shmem communication
with the firmware.
For now since it can be only used with arm_doorbell move the device to
std.arm otherwise kernel configs like ALLWINNER or ROCKCHIP fails to build.

Reviewed by:	br, imp
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D37953
2023-01-25 08:28:22 +01:00
Warner Losh
34784d17eb elf: Catch up with defining EF_ARM_EABI_VERSION in elf_common.h
FreeBSD defines EF_ARM_EABI_VERSION in a non-standard way (at least
differently than everybody else). We use this only in elf*machdep.c to
make sure the image is new enough. Switch to the more standard way of
defining this and adjust other constants to match.

Fixes:			c52c98e69a
Sponsored by:		Netflix
2023-01-20 19:18:15 -07:00
Allan Jude
fd5e921059 Add CPU Ident for Qualcomm Kryo 400 (used in MS Dev Kit)
Reviewed by:	imp
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37767
2023-01-18 21:04:49 +00:00
Andrew Turner
a85cf421d1 Reduce an arm64 VFP critical section
In set_fpcontext we only need a critical section around vfp_discard.
The remainder of the code can run without it.

While here add an assert to check the passed in thread is the
current thread as the code already this.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38000
2023-01-18 09:31:50 +00:00
Andrew Turner
61f5462fde Always store the arm64 VFP context
If a thread enters a kernel FP context the PCB_FP_STARTED may be
unset when calling get_fpcontext even if the VFP unit has been used
by the current thread.

Reduce the use of this flag to just decide when to store the VFP state.

While here add an assert to check the assumption that the passed in
thread is the current thread and remove the unneeded critical section.
The latter is unneeded as the only place we would need it is in
vfp_save_state and this already has a critical section when needed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37998
2023-01-18 09:31:45 +00:00
Andrew Turner
95dd6974b5 Always read the VFP regs in the arm64 fill_fpregs
The PCB_FP_STARTED is used to indicate that the current VFP context
has been used since either 1. the start of the thread, or 2. exiting
a kernel FP context.

When case 2 was added to the kernel this could cause incorrect results
to be returned when a thread exits the kernel FP context and fill_fpregs
is called before it has restored the VFP state, e.g. by trappin on a
userspace VFP instruction.

In both of the cases the base save area is still valid so reduce the
use of the PCB_FP_STARTED flag check to help decide if we need to
store the current threads VFP state.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37994
2023-01-18 09:31:35 +00:00
Brooks Davis
e1b610f76c arm64: Fix thread0.td_kstack_pages init
Commit 86a994d653 initialized
thread0.td_kstack_pages to KSTACK_PAGES.  Due to the lack of an
include of opt_kstack_pages.h it used the fallback value of 4 from
machine/param.h.  This meant that increasing KSTACK_PAGES in the kernel
config resulted in a panic in _epoch_enter_preempt as the following
assertion was false during network stack setup:

        MPASS((vm_offset_t)et >= td->td_kstack &&
	    (vm_offset_t)et + sizeof(struct epoch_tracker) <=
	    td->td_kstack + td->td_kstack_pages * PAGE_SIZE);

Switch to initializing with kstack_pages following other architectures.

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D38048
2023-01-17 16:37:09 +00:00
Søren Schmidt
4ffe60e683 Add Combo PHY, RK817, Syr827, tcs4525 pmic devices to Rockchip specific config. 2023-01-08 03:07:18 +00:00
Søren Schmidt
11b5b9e8a5 Add delay to have things settle. 2023-01-07 07:42:44 +00:00
Ganbold Tsagaankhuu
9427c47de6 Remove unnecessary sys/cdefs.h includes. 2023-01-07 06:05:52 +00:00
Val Packett
0b4531511e copyright: chase my name and email change
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37945
2023-01-06 15:28:42 -05:00
Ganbold Tsagaankhuu
90737b632e Use BSD-2-Clause for the SPDX license id as -FreeBSD variant has been deprecated. 2023-01-06 08:15:44 +00:00
Ganbold Tsagaankhuu
7e2600ea7b Add SPDX-License-Identifier. 2023-01-06 04:14:49 +00:00
Ganbold Tsagaankhuu
0d4a240b0d Remove unnecessary $Id string from license.
While there add SPDX-License-Identifier.
2023-01-06 04:10:09 +00:00
Søren Schmidt
5723e5ac6d Add Naneng combo PHY support for RK3568 SoC.
It can be used as pcie-phy, usb3-phy, sata-phy or sgmii-phy.
2023-01-06 03:04:53 +00:00
Søren Schmidt
7daf96523b Add PCIe driver for RK3568 SoC.
PCIe3 ports work, however PCIe2x1 is not working yet in this case as it depends on Naneng Combo Phy driver.
2023-01-05 04:15:56 +00:00
Søren Schmidt
79c6e0b31f Improve and make it more general Rockchip USB2PHY driver.
Add support for Rockchip RK3568.
2022-12-28 03:48:48 +00:00
Søren Schmidt
355cb40c3a Set RK3568 specific pin mux for GMAC1. 2022-12-28 03:00:19 +00:00
Ganbold Tsagaankhuu
db6407438d Add eqos device to Rockchip specific config. 2022-12-28 02:32:06 +00:00
Andrew Turner
753c7fc9e6 Fix the SPDX-License-Identifier in CMN-600 files
The SPDX-License-Identifier was wrong in the Arm CoreLink CMN-600
driver files. It used the incorrect FreeBSD variant of the BSD-2-Clause
identifier. According to [1] all files should use BSD-2-Clause.

[1] https://tools.spdx.org/app/check_license/

Reported by:	emaste
Sponsored by:	Arm Ltd
2022-12-22 10:36:18 +00:00
Andrew Turner
751d88119f Fix loading the hwpmc module when ACPI is enabled
In 0a9a4d2cd6 a check for OPT_ACPI was added to the hwpmc Makefile
to fix loading the module in a kernel where ACPI has been disabled.
This broke loading the module when ACPI was enabled in the build as
OPT_ACPI isn't a Makefile macro so was always disabled.

Move this check to the C files where the DEV_ACPI macro does exist.

Reviewed by:	gnn
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37773
2022-12-22 10:36:18 +00:00
Jessica Clarke
c1a2798faa arm64: Don't include td_inhibitors when checking td_ast in do_ast
The td_ast member is an int so only 4 bytes, yet we were using an 8 byte
load and thus also got td_inhibitors in the upper bits. The code prior
to the commit that introduced td_ast did also do a bogus 8 byte load of
td_flags but masked the flags so arguably was correct, if dodgy. Now
that we're using the right width for the load we can also fold the
immediate offset back into the load; because td_ast is at an odd
multiple of 4 bytes from the start of struct thread the normal scaled
load couldn't be used with such an immediate offset when doing an 8 byte
load due to its limited immediate range, but we can use a scaled load
once more now that the offset is a multiple of the load width.

Reviewed by:	andrew, kib
Fixes:		c6d31b8306 ("AST: rework")
Differential Revision:	https://reviews.freebsd.org/D37751
2022-12-22 10:23:10 +00:00
Ruslan Bukin
dc08d52d1e smmu: fix FDT and !FDT builds.
Reviewed by:	andrew
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D37762
2022-12-21 15:53:09 +00:00
Ruslan Bukin
4b4e8cb53a smmu: set guest address space range to 48-bit, which is a hardware
limit in our configuration.

Reviewed by:	andrew
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D37756
2022-12-21 15:53:05 +00:00
Andrew Turner
7ebc4c9bf7 Use hwreset_array in the Rockchip tsadc driver
The order of asserting/deasserting the resets doesn't matter so use
the new hwreset_array to manage them all.

Reviewed by:	manu
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37358
2022-12-21 11:25:27 +00:00
Søren Schmidt
e7815784cc Add Rockchip RK3568 SoC
Attach its clock drivers and rk817 pmic driver to the build.
2022-12-20 03:01:41 +00: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
Søren Schmidt
a48301a5e0 Add initial clocks support for Rockchip RK3568 SoC.
Partially from:	https://reviews.freebsd.org/D36027

This can be eventually improved or simplified or fixed if necessary.

Following devices work with proper drivers and with the necessary clocks:
Native networking via eqos driver
USB3 and USB2
PCIe support is working but a bit picky about what hardware it supports (but so is Linux)
SD & (e)MMC
With the EDK2 loader video also works

Supported hardwares are Quartz64, NanoPI R5S and Firefly Station P2, more to come as DTS files gets done.
2022-12-18 12:05:29 +00:00
Søren Schmidt
0e3c99cbed Fix/add compat strings for Rockchip RK356x GRF. 2022-12-18 11:22:11 +00:00
Alan Cox
f0878da03b pmap: standardize promotion conditions between amd64 and arm64
On amd64, don't abort promotion due to a missing accessed bit in a
mapping before possibly write protecting that mapping.  Previously,
in some cases, we might not repromote after madvise(MADV_FREE) because
there was no write fault to trigger the repromotion.  Conversely, on
arm64, don't pointlessly, yet harmlessly, write protect physical pages
that aren't part of the physical superpage.

Don't count aborted promotions due to explicit promotion prohibition
(arm64) or hardware errata (amd64) as ordinary promotion failures.

Reviewed by:	kib, markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36916
2022-12-12 11:32:50 -06:00
Søren Schmidt
896d3e43b1 Add driver for Rockchip One Time Programmable (OTP) device.
This driver created the possibility to assign fixed MAC adresses to eqos devices.
2022-12-12 14:34:18 +00:00
Warner Losh
0dfc8a7c1c arm64/machdep: Reserve memory when we find Linux EFI reserved memory table
When Linux loads a new kernel via kexec, somtiems it must reserve memory
for devices that are still active (and typically can't be reset or
shutdown). When present, this table is a linked list of ranges that are
still in use that the OS must avoid using.

Mark these areas as reserved.

This is part of the GICv3 workaround code where we must use the PA
addresses already programmed into the GICv3 when we take over. This part
ensure we don't allocate the mmeory for anything else.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37440
2022-11-30 16:31:14 -07:00
Warner Losh
6849950da7 arm64/machdep: Add parameter to the EFI table walking code
It would be nice to be able to pass an arbitrary pointer to the callback
code. Add one, and pass NULL in all the places that we do that today.
As noted by andrew@, we should likely refactor this into MI code and use
it here and amd64, but for the future.

Sponsored by:		Netflix
Reviewed by:		rpokala
Differential Revision:	https://reviews.freebsd.org/D37439
2022-11-30 16:31:14 -07:00
Warner Losh
1a1fd76d0a arm64/pmap: freed only used for PV_STATS
When PV_STATS is defined, freed is used. Otherwise it isn't. Mark it as
__pvused and define __pvused appropriately.

Sponsored by:		Netflix
Reviewed by:		tsoome, rpokala, andrew
Differential Revision:	https://reviews.freebsd.org/D37438
2022-11-18 10:04:04 -07:00
Andrew Turner
c15085278c arm64 pmap: implement per-superpage locks
As with amd64 pmap introduce per-superpage locks backed by pages
allocated by their respective domains.

This significiantly reduces lock contantion from pmap when running
poudriere on a 160 core Ampere Altra server

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36310
2022-11-17 17:12:40 +00:00
Dapeng Gao
61b146ba43 Check alignment of fp in unwind_frame
A misaligned frame pointer is certainly not a valid frame pointer and
with strict alignment enabled (as on CHERI) can cause panics when it is
loaded from later in the code.

This is a recommit of 40e0fa10f5 with
is_aligned() corrected to __is_aligned().

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D34646
2022-11-16 18:29:28 +00:00
Emmanuel Vadot
dbd7bb7c89 arm64/rk_dwc3: Remove RK3328 support
The RK3328 dts doesn't have the glue node so we need the dwc3 driver
to attach directly.

Differential Revision:	https://reviews.freebsd.org/D37396
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-11-16 11:58:31 +01:00
Andrew Turner
8a2adde1e4 Split out the arm64 EL2 exception vectors
These were originally in locore.S as they are only needed so we have
a valid value to put into the vbar_el2 register. As these will soon
be used by bhyve so move them to a new file as we already have with
the EL1 exception vectors in exception.S.

Obtained from:	https://github.com/FreeBSD-UPB/freebsd-src (earlier version)
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
2022-11-15 17:26:52 +00:00
Andrew Turner
2468c61958 Add more arm64 hypervisor registers
These will be used by bhyve.

Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
2022-11-15 17:26:52 +00:00
Andrew Turner
ae43a817d3 Put the arm64 vttbr_el2 register into a state
Zero the vttbr_el2 register on each CPU so we can tell if we are
running the host or guest kernel from a hypervisor.

Obtained from:	https://github.com/FreeBSD-UPB/freebsd-src (earlier version)
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
2022-11-15 17:26:52 +00:00
Andrew Turner
80ba994bfa Add the arch field to the arm64 MIDR macros
For completeness add accessors for the MIDR field. As the field is
always 0xf on arm64 it is unneeded in the current MICR handling, but
will be used in the vmm module for bhyve.

Obtained from:	https://github.com/FreeBSD-UPB/freebsd-src (earlier version)
Sponsored by:	The FreeBSD Foundation
2022-11-15 17:26:52 +00:00
Andrew Turner
386a5e3ae6 Rename the arm64 pmap_invalidate_* functions
These all work on stage 1 tables. Rename them so we can add similar
functions that operate on stage 2 tables.

Reviewed by:	alc, markj, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37302
2022-11-15 12:33:39 +00:00
Andrew Turner
0b976be033 Disable superpage use for stage 2 arm64 mappings
When modifying a stage 2 mapping we may need to call into the
hypervisor to invalidate the TLB. Until it is known if the cost of
this operation is less than the performance gains superpages offers
disable their use.

Reviewed by:	kib. markj
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37299
2022-11-15 12:33:39 +00:00
Andrew Turner
ba2bbac4c1 Revert "Check alignment of fp in unwind_frame"
Fix the build as is_aligned doesn't exist in FreeBSD.

This reverts commit 40e0fa10f5.
2022-11-15 12:33:39 +00:00
Dapeng Gao
40e0fa10f5 Check alignment of fp in unwind_frame
A misaligned frame pointer is certainly not a valid frame pointer and
with strict alignment enabled (as on CHERI) can cause panics when it is
loaded from later in the code.

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D34646
2022-11-15 00:25:46 +00:00
Kyle Evans
753a23ac15 arm64: add a spin-table implementation for Apple Silicon
The M1 has no EL3, so we're limited to a spin-table implementation if we
want to eventually use bhyve on it.  Implement spin-table now, but note
that we still prefer PSCI where possible.

Reviewed by:	mmel
Differential Revision:	https://reviews.freebsd.org/D34661
2022-11-11 13:50:29 -06:00
Andrew Turner
9142f3a885 Fix a rk356x pinctrl register offset
The pull-up/pull-down register offset was wrong on the Rockchip rk356x.
It was set such that the driver would modify the IOMUX control registers.

This seems to work with the current device tree files, but fails with
upstream files. Fix the offset so the later calculation has the correct
offset for the pull-up/pull-down control register.

Sponsored by:	The FreeBSD Foundation
2022-11-11 08:34:48 +00:00
Mark Johnston
03bf40c5d8 arm64: Disable per-thread stack-smashing protection in data_abort()
With PERTHREAD_SSP configured, the compiler's stack-smashing protection
uses a per-thread canary value instead of a global value.  The value is
stored in td->td_md.md_canary; the sp_el0 register always contains a
pointer to that value, and certain functions selected by the compiler
will store the canary value on the stack as a part of the function
prologue (and will verify the copy as part of the epilogue).  In
particular, the thread structure may be accessed.

This happens to occur in data_abort(), which leads to the same problem
addressed by commit 2c10be9e06 ("arm64: Handle translation faults for
thread structures").  This commit fixes that directly, by disabling SSP
in data_abort() and a couple of related functions by using a function
attribute.  It also moves the update of sp_el0 out of C code in case
the compiler decides to start checking the canary in pmap_switch()
someday.

A different solution might be to move the canary value to the PCB, which
currently lives on the kernel stack and isn't subject to the same
problem as thread structures (if only because guard pages inhibit
superpage promotion).  However, there isn't any particular reason the
PCB has to live on the stack today; on amd64 it is embedded in struct
thread, reintroducing the same problem.  Keeping the reference canary
value at the top of the stack is also rather dubious since it could be
clobbered by a sufficiently large stack overflow.

A third solution could be to go back to the approach of commit
5aa5420ff2, and modify UMA to use the direct map for thread structures
even if KASAN is enabled.  But, transient promotions and demotions in
the direct map are possible too.

Reviewed by:	alc, kib, andrew
MFC after:	1 month
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37255
2022-11-07 16:05:58 -05:00
Andrew Turner
b6a72a9f90 Enable hyperv in the arm64 NOTES
It now builds with all arm64 LINT kernels.

Sponsored by:	The FreeBSD Foundation
2022-11-03 15:49:49 +00:00
Andrew Turner
7046ff4974 Revert "Disable Hyper-V on arm64"
This reverts commit fe36346a89.

The arm64 Hyper-v code now checks it is running under Hyper-v before
calling into the hypervisor.

Sponsored by:	The FreeBSD Foundation
2022-11-03 14:59:31 +00:00
Andrew Turner
402c04af1b Add more SOC options to the arm64 NOTES file
These are found in other config files. Include them in NOTES so they
are used in the LINT configs.
2022-11-03 09:45:47 +00:00
Andrew Turner
81bdc9ebe3 Include sys/malloc.h directly in the qoriq clock
We depend on header pollution to include sys/malloc.h. Include it
directly to fix the no-FDT build.
2022-11-03 09:45:47 +00:00
Andrew Turner
2222b0e713 Sort the SOC options in the arm64 NOTES config 2022-11-03 09:45:47 +00:00
Mark Johnston
2c10be9e06 arm64: Handle translation faults for thread structures
The break-before-make requirement poses a problem when promoting or
demoting mappings containing thread structures: a CPU may raise a
translation fault while accessing curthread, and data_abort() accesses
the thread again before pmap_fault() can translate the address and
return.

Normally this isn't a problem because we have a hack to ensure that
slabs used by the thread zone are always accessed via the direct map,
where promotions and demotions are rare.  However, this hack doesn't
work properly with UMA_MD_SMALL_ALLOC disabled, as is the case with
KASAN configured (since our KASAN implementation does not shadow the
direct map and so tries to force the use of the kernel map wherever
possible).

Fix the problem by modifying data_abort() to handle translation faults
in the kernel map without dereferencing "td", i.e., curthread, and
without enabling interrupts.  pmap_klookup() has special handling for
translation faults which makes it safe to call in this context.  Then,
revert the aforementioned hack.

Reviewed by:	kevans, alc, kib, andrew
MFC after:	1 month
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37231
2022-11-02 13:46:25 -04:00
Elliott Mitchell
21cc0918c7 sys: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, rrs
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31716
2022-11-02 09:34:20 -06:00
Elliott Mitchell
ccd9b49f20 sys: use .S for assembly language files that use the preprocessor
Reviewed by:	imp
Pull Request:	https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D35908
2022-11-02 10:29:00 -04:00
Mike Karels
234c1463a7 genet: add another case where headers need pullup
Wake On LAN packets sent by wake(8) via BPF are lost if txcsum is
enabled.  These fall into the "other protocol" case where gen_parse_tx
did nothing.  Add code to shift up to gen_tx_hdr_min bytes of the
packet along with the Ethernet header in this case.
2022-10-29 07:52:57 -05:00
Mitchell Horne
1da65dcb1c linux: populate sv_syscallnames in each sysentvec
This allows the syscallname() function to give a usable result for Linux
ABIs.

Reported by:	jrtc27
Reviewed by:	jrtc27, markj, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37199
2022-10-28 18:21:08 -03:00
Andrew Turner
fe36346a89 Disable Hyper-V on arm64
It unconditionally calls into the Hyper-V firmware. As most arm64
boards don't have said firmware disable it for now.
2022-10-28 22:17:00 +01:00
Andrew Turner
16c10e99b8 Remove the hyperv option from std.dev
It's already in std.hyperv and we don't need to repeat it here.
2022-10-28 22:17:00 +01:00
Jung-uk Kim
19ee8335c5 acpica: Merge ACPICA 20221020 2022-10-27 22:04:32 -04:00
Olivier Houchard
d78c2cd831 arm64: Implement cpu_ptrace().
Add a minimal implementation of cpu_ptrace() for arm64. It is only used to
get/set VFP registers for 32bits binaries, as it is apparently what we use
there, instead of the MI PT_GETFPREGS/PT_SETFPREGS.

PR:	267361
MFC After: 1 week
2022-10-27 23:25:56 +02:00
Andrew Turner
49750143c1 Add a LINT-ACPI arm64 config
To ensure a kernel with only ACPI builds add a LINT file with FDT
disabled.

Sponsored by:	The FreeBSD Foundation
2022-10-27 18:59:33 +01:00
Andrew Turner
7ddba690f8 Remove an unneeded cpu_dcache_wb_range from arm64
The cpu_dcache_wb_range function is an expensive function that is
unneeded in ddb. It is used when the cache needs to be written to RAM,
e.g. when working with a non-cache coherent device.

Remove it as cpu_icache_sync_range already has the needed d-cache
handling to ensure any changed memory is visible to the i-cache.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37037
2022-10-27 17:05:46 +01:00
Kyle Evans
60c96dbf20 arm64: add a std.ec2 config
Mostly to document basic harware present on the platform; knowing that
Graviton exposes an ns8250 uart alone is quite helpful.

Reviewed by:	andrew, imp, manu
Seems accurate:	cperciva
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36776
2022-10-27 10:39:55 -05:00
Souradeep Chakrabarti
9729f076e4 arm64: Hyper-V: enablement for ARM64 in Hyper-V (Part 3, final)
This is the last part for ARM64 Hyper-V enablement. This includes
commone files and make file changes to enable the ARM64 FreeBSD
guest on Hyper-V. With this patch, it should be able to build
the ARM64 image and install it on Hyper-V.

Reviewed by:	emaste, andrew, whu
Tested by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D36744
2022-10-27 13:53:22 +00:00
Warner Losh
91f45a3cf3 intrng: Remove from NOTES file
INTRNG is required on these platforms. Remove it from the NOTES file
since it is now in the DEFAULTS file.

Suggested by:		mhorne
Sponsored by:		Netflix
2022-10-25 10:57:29 -06:00
Warner Losh
b66e766d57 genet: cnt here is write only and can be removed
Sponsored by:		Netflix
2022-10-25 10:57:29 -06:00
Konstantin Belousov
ca18304ea4 arm, arm64: tweak hard-coded load addresses for PIE binaries
They are used when ASLR is not applied.
The need for adjusting is due to rtld direct exec mode puts ld-elf.so.1
at the PIE load address, and this address must not conflict with the
default linker' load address for non-PIE binaries.  Otherwise rtld in
direct mode cannot activate image.  Example of implicit failure is ldd(1)
refusing to run.

Reported by:	kp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D37085
2022-10-25 19:00:44 +03:00
Warner Losh
d4f6b11f66 DEFAULTS: move intrng to DEFAULTS for its platforms.
Sponsored by:		Netflix
Reviewed by:		manu, kevans
Differential Revision:	https://reviews.freebsd.org/D37107
2022-10-24 12:13:03 -06:00
Takanori Watanabe
a9880bfe11 acpi_ged: New driver to ACPI generic event device
New driver to ACPI generic event device, defined in ACPI spec.
Some ACPI power button may not work without this.

In qemu arm64 with "virt" machine, with ACPI firmware,
enable devd check devd message by
and invoke following command in qemu monitor
(qemu) system_powerdown
and make sure some power button input event appear.
(setting sysctl hw.acpi.power_button_state=S5 is not work,
because ACPI tree does not have \_S5 object.)

Reviewed by: andrew, hrs
Differential Revision: https://reviews.freebsd.org/D37032
2022-10-24 18:57:36 +09:00
Takanori Watanabe
7b5d62bb73 ofw: add BUS_GET_DEVICE_PATH interface to openfirm/fdt, somewhat incomplete.
This add BUS_GET_DEVICE_PATH interface,
which shows device tree of openfirm/fdt.

In qemu-system-arm64 with "virt" machine with device-tree firmware,
% devctl getpath OFW cpu0

Reviewed by: andrew
Differential Revision: https://reviews.freebsd.org/D37031
2022-10-18 16:55:47 +09:00
Dmitry Salychev
ba7319e909
Add initial DPAA2 support
DPAA2 is a hardware-level networking architecture found in some NXP
SoCs which contain hardware blocks including Management Complex
(MC, a command interface to manipulate DPAA2 objects), Wire Rate I/O
processor (WRIOP, packets distribution, queuing, drop decisions),
Queues and Buffers Manager (QBMan, Rx/Tx queues control, Rx buffer
pools) and the others.

The Management Complex runs NXP-supplied firmware which provides DPAA2
objects as an abstraction layer over those blocks to simplify an
access to the underlying hardware. Each DPAA2 object has its own
driver (to perform an initialization at least) and will be visible
as a separate device in the device tree.

Two new drivers (dpaa2_mc and dpaa2_rc) act like firmware buses in
order to form a hierarchy of the DPAA2 devices:

	acpiX (or simplebusX)
	  dpaa2_mcX
	    dpaa2_rcX
	      dpaa2_mcp0
	      ...
	      dpaa2_mcpN
	      dpaa2_bpX
	      dpaa2_macX
	      dpaa2_io0
	      ...
	      dpaa2_ioM
	      dpaa2_niX

dpaa2_mc is suppossed to be a root of the hierarchy, comes in ACPI
and FDT flavours and implements helper interfaces to allocate and
assign bus resources, MSI and "managed" DPAA2 devices (NXP treats some
of the objects as resources for the other DPAA2 objects to let them
function properly). Almost all of the DPAA2 objects are assigned to
the resource containers (dpaa2_rc) to implement isolation.

The initial implementation focuses on the DPAA2 network interface
to be operational. It is the most complex object in terms of
dependencies which uses I/O objects to transmit/receive packets.

Approved by:		bz (mentor)
Tested by:		manu, bz
MFC after:		3 months
Differential Revision:	https://reviews.freebsd.org/D36638
2022-10-14 22:49:09 +02:00
Andrew Turner
82860bcb64 Add more Arm CPUs to the arm64 cpu ident
These are based on CPUs found in https://github.com/ARM-software/data

Sponsored by:	The FreeBSD Foundation
2022-10-11 14:01:16 +01:00
Andrew Turner
12c1c65d8a Mark 64-bit arm64 hypervisor registers with UL
These are 64-bit. Mark them as unsigned long so we don't rely on
undefined behaviour or shift a 32-bit value more than 32 bits.

Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
2022-10-11 14:01:16 +01:00
Michael Tuexen
ad20efdde2 Sync TCP related kernel config options
Add TCP_BLACKBOX to the remaining platforms (arm64, RISC-V) and add
TCP_RFC7413 to the remaining platform (RISC-V).

Reviewed by:		rscheff@
MFC after:		1 week
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D36918
2022-10-10 15:40:26 +02:00
John Baldwin
4d90a5afc5 sys: Consolidate common implementation details of PV entries.
Add a <sys/_pv_entry.h> intended for use in <machine/pmap.h> to
define struct pv_entry, pv_chunk, and related macros and inline
functions.

Note that powerpc does not yet use this as while the mmu_radix pmap
in powerpc uses the new scheme (albeit with fewer PV entries in a
chunk than normal due to an used pv_pmap field in struct pv_entry),
the Book-E pmaps for powerpc use the older style PV entries without
chunks (and thus require the pv_pmap field).

Suggested by:	kib
Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36685
2022-10-07 10:14:03 -07:00
Mitchell Horne
b05b1ecbef amd64, arm64 pmap: fix a comment typo
There is no such error code.

Fixes:	1d5ebad06c ("pmap: optimize MADV_WILLNEED on existing superpages")
2022-10-06 19:04:54 -03:00
Warner Losh
7466f157f3 arm64/machdep: Delete trailing whitespace
No functional change.

Sponsored by:		Netflix
2022-10-06 12:08:55 -06:00
John Baldwin
c1ae7841d4 arm64: Simplify initialization of pc_freemask.
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36502
2022-10-05 16:20:55 -07:00
Andrew Turner
a0a4f5cf17 Clear the indirect flag in the GICv3 ITS driver
Summary:
The indirect flag tells the hardware to use a flat or two level table.
As we only support using the flat table ensure the flag that marks
which is in use is set correctly.

We can't rely on this being set correctly as some firmware may set the
indirect flag, e.g. booting from LinuxBoot.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36873
2022-10-04 17:14:16 +01:00
Ganbold Tsagaankhuu
8eb94b238f Set denominator to 1 if it is 0 in the init phase.
This prevents panic and also helps when the clocks
become available later.
This is based on comment from manu@ on
https://reviews.freebsd.org/D31299
2022-10-01 02:01:59 +00:00
Alan Cox
1d5ebad06c pmap: optimize MADV_WILLNEED on existing superpages
Specifically, avoid pointless calls to pmap_enter_quick_locked() when
madvise(MADV_WILLNEED) is applied to an existing superpage mapping.

Reported by:	mhorne
Reviewed by:	kib, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36801
2022-09-30 12:14:05 -05:00
Kyle Evans
78f3c734a5 arm64: fix build without FDT
static_kenv is only used under `FDT`, and `try_load_dtb` is only defined
with `FDT`.

Reviewed by:	andrew, imp, manu
Differential Revision:	https://reviews.freebsd.org/D36791
2022-09-29 14:33:33 -05:00
Kyle Evans
b4c2a5b689 arm64: coresight: fix the build without FDT
coresight_cpu_debug only has an FDT attachment, so let's not build it
for kernels without FDT.

coresight.h includes sys/malloc.h via header pollution
dev/ofw/openfirm.h; include it directly in case we're building without
FDT.

Reviewed by:	andrew, manu
Differential Revision:	https://reviews.freebsd.org/D36789
2022-09-29 14:33:33 -05:00
Andrew Turner
09f715df7f Add a LINT-FDT arm64 config
To ensure a kernel with only FDT builds add a LINT file with ACPI
disabled.

Sponsored by:	The FreeBSD Foundation
2022-09-29 16:35:03 +01:00
Andrew Turner
a42206a7ca Reduce the arm64 ID registers we print
On systems with different CPUs we may print all the ID registers for
all CPUs. Reduce this to just print them when they change from the
previous CPU.

Sponsored by:	The FreeBSD Foundation
2022-09-28 10:53:00 +01:00
Andrew Turner
3247bc7cd6 arm64 pmap: per-domain pv chunk list
As with amd64 use a per-domain pv chunk lock to reduce contention as
chunks get created and removed all the time.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36307
2022-09-27 16:05:52 +01:00
Andrew Turner
92d73b0b25 arm64 pmap: batch chunk removal in pmap_remove_pages
As with amd64 batch chunk removal in pmap_remove_pages to move it out
of the pv list lock. This is one of the main contested locks when
running poudriere on a 160 core Ampere Altra server.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36305
2022-09-27 16:03:08 +01:00
Andrew Turner
78aeba26e8 Reorder pmap_bootstrap_state to reduce holes
Reduce holes in pmap_bootstrap_state by moving freemempos after the
pointers as they are more likely to change size in any future ABI.

Sponsored by:	The FreeBSD Foundation
2022-09-27 14:47:30 +01:00
Andrew Turner
8da1273234 Remove unneeded variables in the arm64 pmap bootstrap
These are now unneeded after cleaning up the pmap bootstrap process.
Remove them and the variables that set them.

Sponsored by:	The FreeBSD Foundation
2022-09-27 14:47:30 +01:00
Andrew Turner
ca7e6d7c29 Remove duplicate arm64 pmap bootstrap code
The table bootstrap functions can now be used for non-DMAP uses. Use
them for all early page table creation.

Sponsored by:	The FreeBSD Foundation
2022-09-27 13:26:29 +01:00
Andrew Turner
dc39b2dc64 Allow changing arm64 table attributes when bootstrapping pmap
Only the DMAP region can be mapped with PXN. Allow the table attributes
to be changed for other mappings.

Sponsored by:	The FreeBSD Foundation
2022-09-27 13:26:29 +01:00
Andrew Turner
aa4740c8a1 Allow the arm64 pmap table bootstrap to work in more places
Rework the pmap_bootstrap table generation so we can use it with
partially filled out page tables after the DMAP has been bootstrapped.
This allows it to be reused by the later bootstrap code.

Sponsored by:	The FreeBSD Foundation
2022-09-27 13:26:29 +01:00
Andrew Turner
9404d22f05 Make the arm64 pmap bootstrap state global
So it can be reused by KASAN

Sponsored by:	The FreeBSD Foundation
2022-09-27 13:26:29 +01:00
Andrew Turner
90ba897b91 Rename arm64 pmap bootstrap to not be dmap specific
This will be used by KASAN and possibly the kernel in general, rename
so we aren't confused by it.

Sponsored by:	The FreeBSD Foundation
2022-09-27 13:26:29 +01:00
Mitchell Horne
f8e38b421b arm64: bus: provide bus_space_set_{multi,region}_stream definitions
Reviewed by:	andrew
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36719
2022-09-26 14:24:37 -05:00
Mitchell Horne
c5500a01c7 arm64: bus: unhide bus_space definition with sanitizers included
We'll only be redefining the various bus_* macros, not the definition of
struct bus_space.

Reviewed by:	andrew
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36718
2022-09-26 14:24:37 -05:00
Mark Johnston
0fd27bcab2 arm64: Fix an assertion in pmap_enter_largepage()
The intent is to assert that either no mapping exists at the given VA,
or that the existing L1 block mapping maps the same PA.

Fixes:		36f1526a59 ("Add experimental 16k page support on arm64")
Reviewed by:	alc
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36698
2022-09-26 08:56:11 -04:00
Mark Johnston
7533062ae1 arm64: Handle 1GB mappings in pmap_enter_quick_locked()
Reviewed by:	alc, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36697
2022-09-26 08:54:35 -04:00
Mark Johnston
89a2ef4d52 arm64: Ignore 1GB mappings in pmap_advise()
For the same reason as commit 4c224f8e5f36cfad5a9af8db7c7acdecc3d4c7b5.

MFC after:	1 week
2022-09-24 09:28:41 -04:00
Warner Losh
d4accf60d9 arm64: don't loop forever if first option in kern.cfg.order not available
strchr returns a pointer to the ',', so if the first option in the list
isn't available, we need to step over the , to look at the next
option. So if kern.cfg.order="acpi,fdt" and we have no acpi, we'd loop
forever with order=',fdt'.

Sponsored by:		Netflix
Reviewed by:		andrew, jhb
Differential Revision:	https://reviews.freebsd.org/D36682
2022-09-23 15:07:23 -06:00
Andrew Turner
9ba957e40a Fix the spelling of interrupt in the GICv3 driver
Reported by:	jrtc27
Sponsored by:	Innovate UK
2022-09-23 15:28:45 +01:00
Andrew Turner
7a5d47de97 Make adding children consistant in the GICv3 drivers
Reorder statements to make them consistant between the ACPI and FDT
GICv3 attachments.

Reported by:	jrtc27
Sponsored by:	Innovate UK
2022-09-23 15:28:45 +01:00
Andrew Turner
839374bbfe Teach the GICv3 driver to translate memory ranges
As with the GICv1/2 driver teach the GICv3 driver to translate memory
ranges of children. This allows us to create a common
bus_alloc_resource implementation for bot hACPI and FDT attachments.

Sponsored by:	The FreeBSD Foundation
2022-09-23 15:28:45 +01:00
Andrew Turner
bdc9ece97b Move the GICv3 bus_print_child function to the parent
This should be common for both ACPI and FDT. Move this to the common
part of the driver.

Sponsored by:	The FreeBSD Foundation
2022-09-23 15:28:45 +01:00
Andrew Turner
6fc6896c47 Add bus_get_resource_list functions to the GICv3 driver
This will be used to reduce code duplication between the ACPI and FDT
attachments.

Sponsored by:	The FreeBSD Foundation
2022-09-23 15:28:45 +01:00
John Baldwin
f49fd63a6a kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36549
2022-09-22 15:09:19 -07:00
John Baldwin
7ae99f80b6 pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.
This matches the return type of pmap_mapdev/bios.

Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36548
2022-09-22 15:08:52 -07:00
Andrew Turner
e13c6a6fca Teach the GICv3 driver about a vgic child
This will be used by bhyve to attach a virtual GIC driver.

Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36590
2022-09-21 10:59:13 +01:00
Jakub Kołodziej
b8a083ea32 gpio: Merge TCA6416 & TCA6408 drivers into TCA64XX
This merges TCA6416, TCA6408 drivers and adds PCA9555 support.
They handle 8 pin and 16 pin ICs with basic INPUT/OUTPUT functionality.
The register map is fairly similar so there is no point in having two
separate drivers.

Reviewed by:	kd
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36559
2022-09-19 09:18:08 +02:00
Richard Scheffenegger
bb1d472d79 tcp: make CUBIC the default congestion control mechanism.
This changes the default TCP Congestion Control (CC) to CUBIC.
For small, transactional exchanges (e.g. web objects <15kB), this
will not have a material effect. However, for long duration data
transfers, CUBIC allocates a slightly higher fraction of the
available bandwidth, when competing against NewReno CC.

Reviewed By: tuexen, mav, #transport, guest-ccui, emaste
Relnotes: Yes
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D36537
2022-09-13 12:09:21 +02:00
Alan Cox
8d7ee2047c pmap: don't recompute mpte during promotion
When attempting to promote 4KB user-space mappings to a 2MB user-space
mapping, the address of the struct vm_page representing the page table
page that contains the 4KB mappings is already known to the caller.
Pass that address to the promotion function rather than making the
promotion function recompute it, which on arm64 entails iteration over
the vm_phys_segs array by PHYS_TO_VM_PAGE().  And, while I'm here,
eliminate unnecessary arithmetic from the calculation of the first PTE's
address on arm64.

MFC after:	1 week
2022-09-11 01:19:22 -05:00
Warner Losh
c73d20c831 gicv3_its: Fix typo
Sponsored by:		Netflix
2022-09-09 09:23:08 -06:00
Andrew Turner
7d90ce7cae Use the cached dc zva length in arm64 memset
On boot we cache the length the 'dc zva' instruction will zero. Use
this in the memset function to decide when to use it. As the cached
value is in .bss it will be zero on boot so memset is safe to use
before the value has been read.

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:30:11 +01:00
Andrew Turner
949bc17cf2 Import the arm64 Cortex Strings memset into the kernel
Bring in the last version of the optimized memset from the Cortex
Strings library that didn't use the VFP registers. While here clean up
to use the ENTRY/EDIT macros.

This is imported from:
https://git.linaro.org/toolchain/cortex-strings.git/tree/src/aarch64/memset.S?id=bc654e7a594385071b42db3c9c94bd0fd5fe0da5

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:30:09 +01:00
Andrew Turner
51a1bf7ba7 Import an optimized arm64 memcmp into the kernel
Bring in a version of the Arm Optimized Routines memcpy from before
the VFP registers were used.

Imported with modification from:
https://github.com/ARM-software/optimized-routines/blob/e823e3abf5f89ecb/string/aarch64/memcmp.S

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:29:37 +01:00
Andrew Turner
8c6e5d8cf1 Import an optimized str{n}cmp on arm64
These are from the Arm Optimized Routines and don't use the VFP so are
safe to use in the kernel.

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:23:20 +01:00
Andrew Turner
01e478d955 Update the arm64 kernel memcpy/memmove
Bring in the latest Arm Optimized Routines memcpy/memmove into the
arm64 kernel. As these functions have been merged in the current
version remove the now unneeded memmove.S.

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:23:20 +01:00
Andrew Turner
376025cfb1 Move the non-exported PCB_FP_* flags to the upper bits
To make way for a flag for SVE move the PCB_FP_* flags we don't export
to userspace to the upper bits.

Sponsored by:	The FreeBSD Foundation
2022-09-08 14:23:20 +01:00
Kyle Evans
bab32a8029 arm64, riscv: size boot stacks appropriately
In 8db2e8fd16 ("Remove the secondary_stacks array in arm64 [...]"),
bootstacks was setup to be allocated dynamically.  While this is
generally how x86 does it, it inadvertently shrunk each boot stack from
KSTACK_PAGES pages to a single page.

Resize these back up to the expected size using the kstack_pages
tunable, as we'll need larger stacks with upcoming sanitizer work.

Reviewed by:	andrew, imp, markj
Fixes:	8db2e8fd16 ("Remove the secondary_stacks array [...]")
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36475
2022-09-08 00:03:05 -05:00
Warner Losh
0fddee6d1f arm64: machdep.c fix two typos
Sponsored by:		Netflix
2022-09-06 18:09:43 -06:00
Andrew Turner
a8fac0ce78 Decode the arm64 ID_AA64ISAR1_EL1 register
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35627
2022-09-06 16:49:36 +01:00
Gordon Bergling
160d76986e arm64: Remove a double word in a source code comment
- s/the the/the/

MFC after:	3 days
2022-09-04 13:40:15 +02:00
Warner Losh
281a6ff273 acpi: Fix error message
Fix a formatting error from 195f794318

Fixes:		195f794318
Sponsored by:	Netflix
2022-09-01 11:35:45 -06:00
Warner Losh
991aef9795 acpi: Move some errors with RSDP and XSLT out from under bootverbose
Failure to map RSDP, XSLT and checksum failures are events that can't
happen unless something has gone wrong. As such, they should be reported
always, and not in bootverbose. This has been this way since it was
originally brought in to parse APIC tables.

Sponsored by:		Netflix
Reviewed by:		andrew
Differential Revision:	https://reviews.freebsd.org/D36406
2022-09-01 10:40:15 -06:00
Warner Losh
a14b26a6bd acpi: Unmap RSDP in more error cases
Add missing pmap_unmapbios() calls for when we return 0. Otherwise we
can leave the table mapped when it is of no use.

Sponsored by:		Netflix
Reviewed by:		andrew
Differential Revision:	https://reviews.freebsd.org/D36405
2022-09-01 10:39:20 -06:00
Warner Losh
195f794318 acpi: arm64 doesn't support ACPI 1.0 RSDP, report when we see one
arm64 requires ACPI RSDP Revision 2.0 since it requires 64-bit physical
addresses. It is an error worth reporting if we have a RSDP pointer, but
it points to the wrong version.

Sponsored by:		Netflix
Reviewed by:		andrew
Differential Revision:	https://reviews.freebsd.org/D36404
2022-09-01 10:38:53 -06:00
Ganbold Tsagaankhuu
48551d3240 Fix problem getting gpio version during attach.
Both RK3328 and RK3399 don't have GPIO_VER_ID register.
Set gpio version depending on compat string of the parent.
2022-09-01 07:21:56 +00:00
Andrew Turner
544f047f89 Store mpidr as a 64-bit value on arm64
The mpidr register is 64 bit on arm64 and 32 bit on arm. Fix this by
extending the arm64 definition to include the top 32 bits.

To preserve KBI when MFCing split the value into two 32 bit values.
This will be cleaned up later only on main.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36346
2022-08-31 11:48:31 +01:00
Andrew Turner
7a060a8895 Add an IDC only arm64 icache sync function
When the IDC flag is set in the cache type register we don't need to
clean the data cache to the point of unification. Previously we
supported this flag being set only when the DIC flags was also set.
Add a new handler for when this is not the case.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation, Ampere (hardware)
Differential Revision: https://reviews.freebsd.org/D36296
2022-08-25 12:17:28 +01:00
Warner Losh
211053f952 arm64: Remove unused typedef
We don't use EFI_MEMORY_DESCRIPTOR that's typedef'd here. We use the one
from sys/efi.h instead. Remove the clutter here as these two are subtly
different (though wind up with the same layout due to alignment rules).

Sponsored by:		Netflix
2022-08-24 06:35:41 -06:00
John Baldwin
9a777495df cmn600: Remove unused devclass from DRIVER_MODULE. 2022-08-23 09:36:11 -07:00
Søren Schmidt
ec556724d7 Add interrupt handling to rk_gpio driver. 2022-08-20 11:30:54 +00:00
Søren Schmidt
901df07a47 Code refactoring for existing rk_gpio driver.
It supports gpio type checking. Depending on gpio type some
register addresses are different.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D36262
2022-08-19 13:22:01 +00:00
John Baldwin
3499df29c2 arm64 pmap: Convert PC_IS_FREE into an inline function.
This permits inlining the comparisons even in the 16K page case.
Note that since PC_FREEN is -1, values can be compared efficiently
without having to fetch words of pc_freemask from memory via the
'cmn <reg>, #0x1' instruction.

Reviewed by:	markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36218
2022-08-17 12:10:35 -07:00
John Baldwin
5567d6b441 arm64 pmap: Simplify logic around pv_chunk sizes.
- Define PC_FREEL and _NPCM in terms of _NPCPV rather than via magic
  numbers.

- Remove assertions about _NPC* values from pmap.c.  This is less
  relevant now that PC_FREEL and _NPCM are derived from _NPCPV.

- Add a helper inline function pc_is_full() which uses a loop to check
  if pc_map is all zeroes.  Use this to replace three places that
  check for a full mask assuming there are only 3 entries in pc_map.

Reviewed by:	markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36217
2022-08-17 12:10:12 -07:00
Andrew Turner
e3917bb256 Disable promotion on pcpu memory on arm64
We need to be careful to not promote or demote the memory containing
the per-CPU structures as the exception handlers will dereference it
so any time it's invalid may cause recursive exceptions.

Add a new pmap function to set a flag in the pte marking memory that
cannot be promoted or demoted and use it to mark pcpu memory.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35434
2022-08-16 15:41:24 +01:00
Søren Schmidt
1331c0f44b Add support for RockChip RK356X to DWC3 driver.
For RK356x platform, we can set bit 26 of DWC3_GUCTL1 register
for usb 2.0 device.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D36211
2022-08-16 12:24:44 +00:00
Dimitry Andric
9407408915 Adjust function definition in arm64's db_trace.c to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/arm64/arm64/db_trace.c:53:23: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    db_md_list_watchpoints()
                          ^
                           void

This is because db_md_list_watchpoints() is declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

MFC after:	3 days
2022-08-15 20:48:33 +02:00
Søren Schmidt
530d5f8338 Add RockChip RK356X support to existing RockChip iodomain driver. 2022-08-15 12:03:28 +00:00
Dimitry Andric
0fe8ab6851 Fix unused variable warning in rockchip's rk_spi.c
With clang 15, the following -Werror warning is produced:

    sys/arm64/rockchip/rk_spi.c:229:6: error: variable 'cnt' set but not used [-Werror,-Wunused-but-set-variable]
            int cnt = 0;
                ^

The 'cnt' variable was in rk_spi.c when it was first added, but it
appears to have been a debugging aid that has never been used, so remove
it.

MFC after:	3 days
2022-08-14 21:27:34 +02:00
Søren Schmidt
0b6d133c08 Add RockChip RK356X support to existing RockChip thermal driver. 2022-08-11 08:26:39 +00:00
Ganbold Tsagaankhuu
ace8bb34ce Add support for RK3568 to RockChip GRF and SPI drivers.
Partially from https://reviews.freebsd.org/D36027

Submitted by:	sos
2022-08-11 05:32:48 +00:00
Emmanuel Vadot
87f642ac03 arm64: rockchip: rk_gpio: Improve mode switching
Changing mode on a pin (input/output/pullup/pulldown) is a bit slow.
Improve this by caching what we can.
We need to check if the pin is in gpio mode, do that the first time
that we have a request for this pin and cache the result. We can't do
that at attach as we are a child of rk_pinctrl and it didn't finished
its attach then.
Cache also the flags specific to the pinctrl (pullup or pulldown) if the
pin is in input mode.
Cache the registers that deals with input/output mode and output value. Also
remove some register reads when we change the direction of a pin or when we
change the output value since the bit changed in the registers only affect output
pins.
2022-08-10 19:22:31 +02:00
Andrew Turner
abc7a4a0c1 Simplify setting a non-4k PAGE_SIZE on arm64
Define PAGE_SIZE and PAGE_MASK based on PAGE_SHIFT. With this we only
need to set one value to change one value to change the page size.

While here remove the unused PAGE_MASK_* macros.

Sponsored by:	The FreeBSD Foundation
2022-08-10 17:02:00 +01:00
Emmanuel Vadot
8d6b3a8570 arm64: rockchip: pinctrl: Do not rely on the node name
Node names for gpio bank were made generic in Linux 5.16 so stop
using them to map the gpio controller to the pin controller bank unit.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-08-10 15:47:22 +02:00
Ganbold Tsagaankhuu
5db5bd5f39 Add drive strength setting for RK3568 pinctrl driver.
Partially from https://reviews.freebsd.org/D36027

Submitted by:	sos
2022-08-08 04:42:22 +00:00
Konstantin Belousov
c6d31b8306 AST: rework
Make most AST handlers dynamically registered.  This allows to have
subsystem-specific handler source located in the subsystem files,
instead of making subr_trap.c aware of it.  For instance, signal
delivery code on return to userspace is now moved to kern_sig.c.

Also, it allows to have some handlers designated as the cleanup (kclear)
type, which are called both at AST and on thread/process exit.  For
instance, ast(), exit1(), and NFS server no longer need to be aware
about UFS softdep processing.

The dynamic registration also allows third-party modules to register AST
handlers if needed.  There is one caveat with loadable modules: the
code does not make any effort to ensure that the module is not unloaded
before all threads processed through AST handler in it.  In fact, this
is already present behavior for hwpmc.ko and ufs.ko.  I do not think it
is worth the efforts and the runtime overhead to try to fix it.

Reviewed by:	markj
Tested by:	emaste (arm64), pho
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D35888
2022-08-02 21:11:09 +03:00
Alan Cox
4670f90846 iommu_gas: Eliminate redundant parameters and push down lock acquisition
Since IOMMU map entries store a reference to the domain in which they
reside, there is no need to pass the domain to iommu_gas_free_entry(),
iommu_gas_free_space(), and iommu_gas_free_region().

Push down the acquisition and release of the IOMMU domain lock into
iommu_gas_free_space() and iommu_gas_free_region().

Both of these changes allow for simplifications in the callers of the
functions without really complicating the functions themselves.
Moreover, the latter change eliminates the direct use of the IOMMU
domain lock from the x86-specific DMAR code.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35995
2022-07-30 14:28:48 -05:00
John Baldwin
ea8f128c7c pmap_mapdev: Consistently use vm_paddr_t for the first argument.
The devmap variants used vm_offset_t for some reason, and a few places
explicitly cast bus addresses to vm_offset_t.  (Probably those casts
along with similar casts for vm_size_t should just be removed and
instead permit the compiler to DTRT.)

Reviewed by:	markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D35961
2022-07-28 15:55:10 -07:00
Alan Cox
8bc3673847 iommu_gas: Eliminate a possible case of use-after-free
Eliminate a possible case of use-after-free in an error handling path
after a mapping failure.  Specifically, eliminate IOMMU_MAP_ENTRY_QI_NF
and instead perform the IOTLB invalidation synchronously.  Otherwise,
when iommu_domain_unload_entry() is called and told not to free the
IOMMU map entry, the caller could free the entry before dmar_qi_task()
is finished with it.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35878
2022-07-25 11:14:58 -05:00
Andrew Turner
36f1526a59 Add experimental 16k page support on arm64
Add initial 16k page support on arm64. It is considered experimental,
with no guarantee of compatibility with a userspace or kernel modules
built with the current a 4k page size as code will likely try to pass
in a too small size when working with APIs that take a multiple of a
page, e.g. mmap.

As this is experimental, and because userspace and the kernel need to
have the PAGE_SIZE macro kept in sync there is no kernel option to
enable this. To test a new image should be built with the
PAGE_{SIZE,SHIFT,MASK} macros changed to the 16k versions.

There are currently known issues with loading modules from an old
loader as it can misalign them to load on a non-16k boundary.

Testing has shown good results in kernel workloads that allocate and
free large amounts of memory as only a quarter of the number of calls
into the VM subsystem are needed in the best case.

Reviewed by:	markj
Tested by:	gallatin
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34793
2022-07-19 10:57:03 +01:00
Kornel Dulęba
361971fbca Rework how shared page related data is stored
Store the shared page address in struct vmspace.
Also instead of storing absolute addresses of various shared page
segments save their offsets with respect to the shared page address.
This will be more useful when the shared page address is randomized.

Approved by:	mw(mentor)
Sponsored by:	Stormshield
Obtained from:	Semihalf
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D35393
2022-07-18 16:27:32 +02:00
Kornel Dulęba
f6ac79fb12 Introduce the PROC_SIGCODE() macro
Use a getter macro instead of fetching the sigcode address directly
from a sysent of a given process. It assumes that the sigcode is stored
in the shared page, which is true in all cases, except for a.out
binaries. This will be later useful when the shared page address
randomization is introduced.
No functional change intended.

Approved by:	mw(mentor)
Sponsored by:	Stormshield
Obtained from:	Semihalf
Reviewed by:	kib
Differential Revision: https://reviews.freebsd.org/D35392
2022-07-18 16:27:26 +02:00
Bjoern A. Zeeb
fe88072dc6 arm64, qoriq_therm: fix handling sites on version 1 and 2
For version 2 extend the TMUV2_TMSAR() write loop over all site_ids
registered for a particular SoC and actually use the site_id rather
than always just the first [0] (which for the LX2080 would be a
problem given there is no site0).

Later, while version 2 adds the SITEs to enable to TMSR in bits 0..<n>,
version 1 (e.g., LS1028, LS1046, LS1088) add MSITEs to TMR
bits 16..31 or rather 15..0(16-<n>).  Adjust the loops to only enable
the site_ids listed for the particular SoC for monitoring.  This now
also deals with sparse site_ids (not starting at 0, or not being
contiguous).

MFC after:	1 week
Sponsored by:	Traverse Technologies (providing Ten64 HW for testing)
Reviewed by:	mmel
Differential Revision: https://reviews.freebsd.org/D35764
2022-07-18 11:51:03 +00:00
Bjoern A. Zeeb
394453302b arm64, qoriq_therm: configure the number of sites base don SoC
Configure the number of sites (sensors) based on SoC.
This avoids timeouts reading non-existent sensors.

The changes are based on mmel's initial work at:
914e3f0098

MFC after:	1 week
Sponsored by:	Traverse Technologies (providing Ten64 HW for testing)
Reviewed by:	mmel
Differential Revision: https://reviews.freebsd.org/D35759
2022-07-18 11:47:16 +00:00
Ganbold Tsagaankhuu
eec3290266 Add RK3568 SoC support to pinctrl driver.
Submitted by:	sos
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D31330
2022-07-09 13:06:52 +00:00
Andrew Turner
92f692fd24 Only add gicv3 fdt children with a compatible property
Not all gicv3 fdt children have a compatible property. Those that don't
are configuration data rather than something that should have a driver
attach.

Sponsored by:	The FreeBSD Foundation
2022-07-07 10:29:10 +01:00
Bjoern A. Zeeb
97dbd37753 pca954x: harmonize pca9547 and pca954x and add pca9540 support
The two implementations for the pca9548 switch and the pca9547 mux
seemed close enough so we can put them together and with a bit more
abstraction add pca9540 support.

While here apply a bit of consistency in variable and driver naming and
use device_has_property instead of the FDT-only OF_ variant.

This disconnects pca9547 from the build but does not yet delete it.

MFC after:	2 weeks
Reviewed by:	mmel (earlier version), avg
Differential Revision: https://reviews.freebsd.org/D35701
2022-07-04 19:12:01 +00:00
Andrew Turner
ee2324aaf6 Add Rockchip PCIe cleanup on attach faulure
We should clean up on failure as it may panic the kernel later, e.g.
if we crate the rman, but fail to destroy it on attach faulure.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35682
2022-07-04 15:27:01 +01:00
Andrew Turner
1c799a6f29 Support decoding mem32 memory in the rk pcie driver
This is needed with some dtb files.

While here use a switch statement as the two options are mutually
exclusive in any iteration of the loop.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35680
2022-07-04 15:27:00 +01:00
Warner Losh
cf72911158 acpi: add sys/kernel.h
sys/kernel.h is needed for tunable fetching.

Sponsored by:		Netflix
2022-07-02 10:35:49 -06:00
Bjoern A. Zeeb
8154df37a5 arm64: NXP add LS1088a clockgen support
Add a driver for NXP LS1088a clockgen support which passes
configuration information to QorIQ clockgen class.
The implementaiton started off as copy of ls1028 support and was
adjusted accordingly.

Reviewed by:	dgr_semihalf.com (earlier), mmel
MFC after:	1 week
Sponsored by:	Traverse Technologies (providing Ten64 HW for testing)
Differential Revision: https://reviews.freebsd.org/D35617
2022-07-02 16:27:23 +00:00
Warner Losh
064f00ec27 arm64: Grab the RSDP from acpi.rsdp like x86
arm64 wasn't updated to grab this from acpi.rsdp when x86 was
update. belatedly update the kernel to grab this information from the
preferred kenv.

Sponsored by:		Netflix
Reviewed by:		andrew, jhb
Differential Revision:	https://reviews.freebsd.org/D35631
2022-07-02 08:02:12 -06:00
Andrew Turner
cb91f112a3 Decode the arm64 SVE ID register
The field values are only valid when the ID_AA64PFR0_EL1.SVE or
ID_AA64PFR1_EL1.SME vields are non-zero. When this is not the case
the register is reserved as zero so is safe to read, but the SVEver
field will be incorrect so only print the decoded register when
the SVE or SME fields indicate it is valid.

Sponsored by:	The FreeBSD Foundation
2022-06-29 17:50:04 +01:00
Andrew Turner
66ba742d2e Allow use of the arm64 unnamed register form
On arm64 all registers have a name that encodes op0, op1, CRn, CRm, and
op2 that are used to encode the register in the instruction. As some
registers we need to access may not be supportedby older compilers, or
are only supported when specific extensions are enabled support this
alternative form.

Sponsored by:	The FreeBSD Foundation
2022-06-29 17:50:04 +01:00
Andrew Turner
baf8f20a4a Split out vfp_new_thread
To keep the vfp thread creation code in one place move into vfp.c. This
will also help with adding SVE support as it depends on VFP.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35615
2022-06-29 15:15:43 +01:00
Aleksandr Rybalko
59191f3573 Add support of ARM CMN-600 controller, PMU access functions only. Add support of PMU counters of ARM CMN-600 controller.
Add support of ARM CMN-600 controller, PMU access functions only.
Add support of PMU counters of ARM CMN-600 controller.

Reviewed by: mhorne
Sponsored By: ARM
Differential Revision: https://reviews.freebsd.org/D32321
2022-06-26 22:03:04 +03:00
Aleksandr Rybalko
e3572eb654 Allocate event for DMC-620 and CMN-600 controllers PMU. Add events supported by DMC-620 and CMN-600 controllers PMU.
Allocate event for DMC-620 and CMN-600 controllers PMU.
Add events supported by DMC-620 and CMN-600 controllers PMU.

Reviewed by: bz
Sponsored By: ARM
Sponsored By: Ampere Computing
Differential Revision: https://reviews.freebsd.org/D35609
2022-06-26 21:52:26 +03:00
Andrew Turner
2f317e7312 Add the SVE reigster definitions
Sponsored by:	The FreeBSD Foundation
2022-06-24 14:52:06 +01:00
Andrew Turner
ffa5bf8b60 Trap SVE instructions until we have SVE support
When running on hardware that supports SVE send the correct signal when
an SVE instruction is run.

Sponsored by:	The FreeBSD Foundation
2022-06-24 14:51:18 +01:00
Dmitry Chagin
d416ee86c7 linux(4): To reuse MD linux.h hide kernel dependencies unde _KERNEL constraint
MFC after:		2 weeks
2022-06-22 14:28:24 +03:00
Mark Johnston
f6b799a86b Fix the test used to wait for AP startup on x86, arm64, riscv
On arm64, testing pc_curpcb != NULL is not correct since pc_curpcb is
set in pmap_switch() while the bootstrap stack is still in use.  As a
result, smp_after_idle_runnable() can free the boot stack prematurely.

Take a different approach: use smp_rendezvous() to wait for all APs to
acknowledge an interrupt.  Since APs must not enable interrupts until
they've entered the scheduler, i.e., switched off the boot stack, this
provides the right guarantee without depending as much on the
implementation of cpu_throw().  And, this approach applies to all
platforms, so convert x86 and riscv as well.

Reported by:	mmel
Tested by:	mmel
Reviewed by:	kib
Fixes:		8db2e8fd16 ("Remove the secondary_stacks array in arm64 and riscv kernels.")
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35435
2022-06-15 11:38:04 -04:00
Doug Moore
19bb5a7244 iommu_gas: pass size to iommu_map without rounding
Let the caller to iommu_map pass the size parameter without rounding
it up to a multiple of page size.  Let iommu_map round it up when
necessary, which is not all of the time, so that in some cases less
space is reserved.

Reviewed by:	alc, kib (previous version)
Tested by:	pho, br
Discussed with:	andrew
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D35424
2022-06-10 13:56:54 -05:00
Justin Hibbits
139ba152c9 arm64: Print per-CPU cache summary
Summary:
It can be useful to see a summary of CPU caches on bootup.  This is done
for most platforms already, so add this to arm64, in the form of (taken
from Apple M1 pro test):

  L1 cache: 192KB (instruction), 128KB (data)
  L2 cache: 12288KB (unified)

This is printed out per-CPU, only under bootverbose.

Future refinements could instead determine if a cache level is shared
with other cores (L2 is shared among cores on some SoCs, for instance),
and perform a better calculation to the full true cache sizes.  For
instance, it's known that the M1 pro, on which this test was done, has 2
12MB L2 clusters, for a total of 24MB.  Seeing each CPU with 12288KB L2
would make one think that there's 12MB * NCPUs, for possibly 120MB
cache, which is incorrect.

Sponsored by:	Juniper Networks, Inc.
Reviewed by:	#arm64, andrew
Differential Revision: https://reviews.freebsd.org/D35366
2022-06-06 10:23:10 -05:00
Dmitry Chagin
109fd18ad9 linux(4): Properly build argument list for the signal handler
Provide arguments 2 and 3 if signal handler installed with SA_SIGINFO.

MFC after:		2 weeks
2022-05-30 19:53:12 +03:00
Dmitry Chagin
2ca34847e7 linux(4): Reduce duplication between MD parts of the Linuxulator
Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after:		2 weeks
2022-05-30 19:47:26 +03:00
Dapeng Gao
e605b87a9e Save only callee-saved registers in pcb
On AArch64, registers x9-x18 are not callee-saved, yet they are
preserved at many placed in swtch.S. This patch removes code that
preserves these registers.
2022-05-25 11:26:30 +01:00
Andrew Turner
9e0716f461 Add arm64 CnP support
Set the Common not Private bit in the ttbr registers when supported on
arm64. This tells the hardware it can share the translation table
entries on multiple CPUs.

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation
2022-05-25 10:56:13 +01:00
Andrew Turner
477204e70b Decode all Arm GIC feature ID bits
The AWS Graviton3 CPU features a GIC 4.1 CPU Interface. Teach the CPU
identift code to decode it.

Sponsored by:	The FreeBSD Foundation
2022-05-24 11:04:57 +01:00
Andrew Turner
969da7c749 Add more Arm CPU IDs
Add more CPU main ID register values for Arm Cortex and Neoverse CPUs

Sponsored by:	The FreeBSD Foundation
2022-05-24 11:04:56 +01:00
Andrew Turner
ad52fba11e Add fdt to name of a fdt specific function
Rename pci_host_generic_attach to pci_host_generic_fdt_attach to be
consistant with the acpi attachment.

Sponsored by:	The FreeBSD Foundation
2022-05-23 15:24:35 +01:00
Dmitry Chagin
26700ac0c4 linux(4): Deduplicate execve
As linux_execve is common across archs, except amd64 32-bit Linuxulator,
move it under compat/linux.

Noted by:		andrew@
MFC after:		2 weeks
2022-05-23 13:18:41 +03:00
Dmitry Chagin
eca368ecb6 Retire sv_transtrap
Call translate_traps directly from sendsig().

MFC after:		2 weeks
2022-05-20 14:54:03 +03:00
Dmitry Chagin
f34a9180ae linux(4): Retire unneeded translate_traps from arm64
MFC after:	2 weeks
2022-05-20 14:19:51 +03:00
Dmitry Chagin
6e2caba7a1 arm64: Enable the floating-point exception traps
To enable it user-space needs to call feenableexcept().

FPE_FLTIDO has been added as the IDF bit can't be mapped to any existing
FPE code.

Reviewed by:		andrew@
Differential revision:	https://reviews.freebsd.org/D35247
MFC after:		2 weeks
2022-05-19 19:53:56 +03:00
Andrew Turner
88ac318759 Support LSE atomics in the arm64 casue* functions
As with atomic(9) use the ARMv8.1 Large System Extension atomic
instructions to implement the userspace compare and swap functions.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35234
2022-05-19 11:30:21 +01:00
Ruslan Bukin
41ce5498f8 Add OFW support to arm64's IOMMU framework.
This is needed to support non-PCI devices like memory-mapped
display controllers.
Split-out some initialization code from iommu_ctx_alloc() into
iommu_ctx_init() method so we could pass controller's MD-data
obtained from DTS to the driver prior to a CTX initialization.

Tested on Morello SoC.

Sponsored by:	UKRI
2022-05-18 14:11:23 +01:00
Ruslan Bukin
182a69328d Fix stream table entry (STE) initialization and removal.
For PCI devices we have entire L1 descriptor for every session ID (SID),
but for non-PCI (e.g. Display Processing Unit DPU), a single L1
descriptor serves multiple SIDs.
So prevent re-initialization of L1 descriptor if already initialized.
Don't free entire L1 descriptor on every STE removal.

Sponsored by:	UKRI
2022-05-18 13:42:37 +01:00
Dmitry Chagin
3020bfe1b8 linux(4): Fix arm64 syscalls.master layout
MFC after:		2 weeks
2022-05-16 22:53:38 +03:00
Dmitry Chagin
390c9ea029 linux(4): Add AT_MINSIGSTKSZ to arm64 port
MFC after:	2 weeks
2022-05-15 21:12:03 +03:00
Dmitry Chagin
c56480a832 linux(4): Implement signal trampoline for arm64 in a FreeBSD-way
The implemenation differs from others Linuxulators.
For unwinders Linux ucontext_t is stored, however native machine context
is used to store/restore process state to avoid code duplication.

As DWARF Aarch64 does not define a register number for PC and provides no
direct way to encode the PC of the previous frame, CFI cannot describe a
signal trampoline frame. So, modified the vdso linker script to discard
unused sections.

Extensions are not implemented.

MFC after:		2 weeks
2022-05-15 21:10:50 +03:00
Dmitry Chagin
af557e649c linux(4): Rework the definition of struct siginfo to match Linux actual one
Rework the defintion of struct siginfo so that the array padding
struct siginfo to SI_MAX_SIZE can be placed in a union along side of the
rest of the struct siginfo members.  The result is that we no longer need
the __ARCH_SI_PREAMBLE_SIZE or SI_PAD_SIZE definitions.

Move struct siginfo definition under /compat/linux to reduce MD part.
To avoid headers polution include linux_siginfo.h in the MD linux.h

MFC after:		2 weeks
2022-05-15 21:05:01 +03:00
Dmitry Chagin
21f2461741 linux(4): Move sigframe definitions to separate headers
The signal trampoine-related definitions are used only in the MD part
of code, wherefore moved from everywhere used linux.h to separate MD
headers.

MFC after:		2 weeks
2022-05-15 21:03:01 +03:00
Dmitry Chagin
3bae1cd68a linux(4): Implement futex_op for arm64.
It's mostly modeled like the Linux does.

Differential revision:	https://reviews.freebsd.org/D35154
MFC after:		2 weeks
2022-05-15 20:49:42 +03:00
Mitchell Horne
db71383b88 kerneldump: remove physical from dump routines
It is unused, especially now that the underlying d_dumper methods do not
accept the argument.

Reviewed by:	markj
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D35174
2022-05-13 10:43:19 -03:00
Kyle Evans
51adf913e8 arm64: disable the EL2 MMU before dropping to EL1
An earlier stage may have set HCR_EL2.E2H, the clearing of which may
break address translation.  We don't need the EL2 MMU at this point, so
we can avoid re-enabling it for now and just drop to EL1 as usual.

Suggested by:	andrew
Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D34644
2022-05-12 22:04:24 -05:00
Ruslan Bukin
1cb8e38e4b Code deduplication: use SID-getting functions in smmu_find().
Sponsored by:	UKRI
2022-05-10 16:20:15 +01:00
John Baldwin
b2c1681aa1 arm64 rockchip: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
d782704278 arm64 qoriq: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
3d2549ce8a arm64 intel: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
d99a98d54f arm64 cavium: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
589aa3d595 arm64 coresight: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
bb62bc2284 arm64: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
9978ade498 arm/arm64 qualcomm: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
289f133bd7 arm/arm64 nvidia: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
John Baldwin
ea538dab84 arm/arm64 freescale: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:44 -07:00
John Baldwin
82d4dc0621 arm/arm64 broadcom: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:44 -07:00
John Baldwin
5f31d14a92 Remove unused spibus_devclass and ofw_spibus_devclass. 2022-05-09 12:22:00 -07:00
Ruslan Bukin
b7fca06bbf Split-out SID-getting code to a separate functions.
Also ensure we are dealing with PCI-class devices.

Sponsored by:	UKRI
2022-05-09 20:13:57 +01:00
Mike Karels
1de9aa4d4f genet: fix output packet corruption in uncommon case
The code for the "shift" block in the COPY macro set the pointer for
the next copy block to the wrong value.  In this case, the link-layer
header would be overwritten by the network-layer header.  This case is
difficult or impossible to exercise in the current driver without
changing the value of the hw.genet.tx_hdr_min sysctl.  Correct the
pointer.  While here, remove a line in the macro that was marked
"unneeded", which was actually wrong.

PR:		263824
Submitted by:	jiahali@blackberry.com
MFC after:	2 weeks
2022-05-09 08:46:06 -05:00
Ruslan Bukin
f224006fe1 Allocate resources selectively.
One of the SMMU interrupt lines (priq) is optional and may be ommited in FDT.

Tested on ARM Morello Board, which has three SMMU units: first two have four
interrupt lines, last one has three interrupt lines.

Sponsored by: UKRI
2022-05-09 13:30:37 +01:00
Ruslan Bukin
0a8e88fa73 Change __unused to __diagused.
Pointed out by:	jhb
Sponsored by:	UKRI
2022-05-09 11:24:47 +01:00
Ruslan Bukin
a5ec261a7c Add FDT attachment driver for ARM System MMU v3.2 controller.
Tested on ARM Morello Board.

Sponsored by:	UKRI
2022-05-07 11:18:35 +01:00
Ruslan Bukin
7d0bbf43fd Change iommu list lock to SX as we need a sleepable lock so we
can call to ofw_bus_iommu_map().

Sponsored by:	UKRI
2022-05-07 11:15:07 +01:00