Commit Graph

2128 Commits

Author SHA1 Message Date
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
Ruslan Bukin
59446e8ac0 Fix !INVARIANTS build.
Sponsored by:	UKRI
2022-05-07 10:45:33 +01:00
Ruslan Bukin
8b8e56dd5b Check if iommu ctx is valid before passing it to functions.
Differential Revision:	https://reviews.freebsd.org/D35130
Sponsored by:	UKRI
2022-05-07 10:27:17 +01:00
Ruslan Bukin
6ff004272a Return error code from IOMMU_MAP and fix build.
Sponsored by:	UKRI
2022-05-07 10:24:30 +01:00
John Baldwin
85447c525b Remove unused ofw_iicbus_devclass. 2022-05-06 15:39:30 -07:00
John Baldwin
3e38757d4c Remove unused miibus_devclass and miibus_fdt_devclass. 2022-05-06 15:39:28 -07:00
Dmitry Chagin
3245a2ecea linux(4): Implement semtimedop syscalls.
On i386 are two semtimedop. The old one is called via multiplexor and
uses 32-bit timespec, and new semtimedop_tim64, which is uses 64-bit
timespec.

MFC after:		2 weeks
2022-05-06 20:02:59 +03:00
Dmitry Chagin
430460d717 linux(4): Regen for semtimedop syscalls.
MFC after:		2 weeks
2022-05-06 20:02:16 +03:00
Dmitry Chagin
f19c4e2341 linux(4): Change semtimedop syscall definition to match Linux actual one.
MFC after:		2 weeks
2022-05-06 20:01:43 +03:00
Dmitry Chagin
cd875998dc linux(4): Regen for semop syscall.
MFC after:		2 weeks
2022-05-06 19:59:33 +03:00
Dmitry Chagin
f686092664 linux(4): Call semop directly.
As the Linux semop syscall is not defined in i386, and as it is equal
to the native semop syscall, call it directly.
Fix semop definition to match Linux actual one - nsops is size_t type.

MFC after:		2 weeks
2022-05-06 19:58:53 +03:00
Andrew Turner
5b651b501a Map the ACPI tables into the DMAP
When we try to load these tables via acpidump(8) we need them to be in
the DMAP for /dev/mem to access. Add the EFI ACPI reclaim memory type
to the list of memory we map into DMAP but not used by the kernel as
this is the recommended place to put these.

Sponsored by:	The FreeBSD Foundation
2022-04-29 13:11:02 +01:00
Dmitry Chagin
df377f1fb8 linux(4): Regen for epoll_pwait2 syscall. 2022-04-26 19:35:58 +03:00
Dmitry Chagin
81b0b7dc0c linux(4): Change epoll_pwait2 syscall definition to match Linux actual one.
MFC after:	2 weeks
2022-04-26 19:35:57 +03:00
Dmitry Chagin
75e409495f linux(4): Regen for rseq syscall. 2022-04-26 19:35:55 +03:00
Dmitry Chagin
f202f35db0 linux(4): Change rseq syscall definition to match Linux actual one.
MFC after:	2 weeks
2022-04-26 19:35:54 +03:00
John Baldwin
d4ab3a8d4f busdma_bounce: Add free_bounce_pages helper function.
Deduplicate code to iterate over the bpages list in a bus_dmamap_t
freeing bounce pages during bus_dmamap_unload.

Reviewed by:	imp
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D34967
2022-04-21 10:42:14 -07:00
Brooks Davis
c2f6aae007 machine/in_cksum.h: don't include sys/cdefs.h
All consumers already do it and it was required on amd64 and i386
until recently (1c1bf5bd7c).

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D34932
2022-04-18 21:02:19 +01:00
Mike Karels
8f45652b6b genet: fix problems with interface down/up
The genet interface did not resume operation correctly after doing
ifconfig down then up.  The down/reset procedure did not clear the
RUNNING flag, and did not reset enough of the hardware state.  This
patch is modeled on OpenBSD code, with a call to gen_reset added
to reset the controller completely.  Regularize the parameter to
gen_dma_disable() while here.

PR:             263091
Submitted by:	jiahali@blackberry.com
2022-04-14 14:10:13 -05:00
John Baldwin
8bf0d2d3e3 arm64 rk_pcie: Use __diagused for a variable only used in KASSERT(). 2022-04-13 16:08:23 -07:00
John Baldwin
56f5947a71 Remove checks for __GNUCLIKE_ASM assuming it is always true.
All supported compilers (modern versions of GCC and clang) support
this.

Many places didn't have an #else so would just silently do the wrong
thing.  Ancient versions of icc (the original motivation for this) are
no longer a compiler FreeBSD supports.

PR:		263102 (exp-run)
Reviewed by:	brooks, imp
Differential Revision:	https://reviews.freebsd.org/D34797
2022-04-12 10:05:45 -07:00
Andrew Turner
f3ef799f56 Only return a mapped address from efi_phys_to_kva
On some hardware the EFI system table is not in memory mapped in the
DMAP section. Rather than panic the kernel check if it is mapped and
return a failure if not from efi_phys_to_kva.

Reported by:	kevans
Differential Revision: https://reviews.freebsd.org/D34858
2022-04-10 09:41:54 +01:00
Andrew Turner
57e47ae514 Include the EFI Runtime Code in the DMAP
Some UEFI implementations place the system table in a runtime code
memory region. Include it in the DMAP so we can read it later.

Reviewed by:	kevans
Differential Revision: https://reviews.freebsd.org/D34861
2022-04-10 09:41:54 +01:00
John Baldwin
f4bd36ba2a rk_usbphy: Remove unused variable. 2022-04-08 18:31:29 -07:00
John Baldwin
4b9b6a501a arm/arm64 nvidia: Remove unused variables. 2022-04-08 18:31:29 -07:00
John Baldwin
38b36a2004 imx_clk_sscg: Remove unused variable. 2022-04-08 17:25:15 -07:00
John Baldwin
888a602959 imx_clk_composite: Mark two variables only used in debug traces as unused.
While here, make best_post_div track the best value of post_div rather
than pre_div so that the debug trace doesn't just print the same value
twice.
2022-04-08 17:25:15 -07:00
John Baldwin
67f6cad3ab coresight: Mark a variable only used in a debug trace as unused. 2022-04-08 17:25:14 -07:00
Andrew Turner
3532bcd282 Fix a coherent bus check in the arm64 busdma
In the arm64 busdma we have an internal flag to signal when a tag is
for a cache-coherent device. In this case we don't need to adjust the
size and alignment of allocated buffers to be within a cache line.

The cache line adjustment was incorrectly using the coherent flag
passed in to bus_dma_tag_create and not the internal flag. Fix it to
use the latter to reduce the memory usage slightly.

Reviewed by:	bz
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34763
2022-04-06 14:11:12 +01:00
Andrew Turner
bcd763b642 Move the arm64 DMAP creation to C
To simplify the creation of the direct map (DMAP) region on arm64 move
it from the pre-C code into pmap. This simplifies the DMAP creation
as we can use the notmal index macros, and should reduce the number
of pages needed to hold the level 1 tables to just those needed.

Reviewed by:	alc, dch
Tested by:	dch, kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34568
2022-04-06 14:09:49 +01:00
Brooks Davis
8601fca789 sysent: regen for syscallarg_t 2022-03-28 19:43:03 +01:00
Brooks Davis
b1ad6a9000 syscallarg_t: Add a type for system call arguments
This more clearly differentiates system call arguments from integer
registers and return values. On current architectures it has no effect,
but on architectures where pointers are not integers (CHERI) and may
not even share registers (CHERI-MIPS) it is necessiary to differentiate
between system call arguments (syscallarg_t) and integer register values
(register_t).

Obtained from:	CheriBSD

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D33780
2022-03-28 19:43:03 +01:00
Andrew Turner
029c1c4828 Treat cache write as a read in arm64 data faults
On arm64 we can ask the hardware to perform cache operations from
userspace. These require read permission however when the memory is
unmapped the kernel will receive a write exception. Add a check to
see if the cause of the exception is from the cache and pass a memory
read fault type to the vm subsystem.

PR:		262836
Reported by:	dch
Sponsored by:	The FreeBSD Foundation
2022-03-28 10:10:15 +01:00
D Scott Phillips
220c48e2d9 Add the Ampere and Fujitsu arm64 implementer IDs
Reviewed By:	andrew, emaste
MFC after:	3 days
Sponsored by:	Ampere Computing
Differential Revision:	https://reviews.freebsd.org/D34666
2022-03-25 09:49:33 -07:00
D Scott Phillips
7be7bd6775 arm64: Add explicit barrier after address translation instruction
Following ARMARM sec D5.2.11, which says:

> Where an instruction results in an update to a System register,
> as is the case with the AT * address translation instructions,
> explicit synchronization must be performed before the result is
> guaranteed to be visible to subsequent direct reads of the
> PAR_EL1.

Reviewed By:	andrew
MFC after:	3 weeks
Sponsored by:	Ampere Computing
Differential Revision:	https://reviews.freebsd.org/D34665
2022-03-25 09:49:33 -07:00
D Scott Phillips
a693a30038 arm64: pmap: Mask VA operand in TLBI instructions
Bits 43:0 of the TLBI operand are bits 55:12 of the VA.  Leaving
bits 63:55 of the VA in bits 51:44 of the operand might wind up
setting the TTL field (47:44) and accidentally restricting which
translation levels are flushed in the TLB.

Reviewed By:	andrew
MFC after:	3 days
Sponsored by:	Ampere Computing
Differential Revision:	https://reviews.freebsd.org/D34664
2022-03-25 09:49:33 -07:00
John Baldwin
b2cb74c22c arm,arm64: Add a NT_ARM_TLS read-only register set.
This register set exposes the per-thread TLS register.  It matches the
layout used by Linux on arm64.  Linux does not implement this note for
32-bit arm.

Reviewed by:	andrew, markj
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34595
2022-03-23 13:33:06 -07:00
John Baldwin
add00c381e Use a regset for NT_ARM_VFP.
This includes adding support for NT_ARM_VFP for 32-bit binaries
running under aarch64 kernels both for ptrace(), and coredumps via the
kernel and gcore.

Reviewed by:	andrew, markj
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34448
2022-03-23 13:33:06 -07:00
John Baldwin
a47fd6929f aarch64: Fix get_fpcontext32() to work on non-curthread.
Similar to fill_fpregs(), only invoke vfp_save_state() for curthread.

While here, zero the buffer if FP hasn't been started to avoid leaking
kernel stack memory.

Reviewed by:	andrew, markj
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34525
2022-03-23 13:33:06 -07:00
Andrew Turner
6e1f7b9b38 Remove L2_BLOCK_MASK from arm64
It's unneeded as it was just used to align KERNBASE to a level 2
block start address. KERNBASE was already aligned correctly.

Sponsored by:	The FreeBSD Foundation
2022-03-23 15:33:05 +00:00
Andrew Turner
863f3220d0 Support EFIRT on arm64 with a non 4k page size
When the page size the kernel is built for is not the same as
EFI_PAGE_SIZE we need to increment the page index at a faster rate.

Add this adjustment to the arm64 EFIRT support in preperation for
experimental 16k PAGE_SIZE support.

Sponsored by:	The FreeBSD Foundation
2022-03-23 15:18:30 +00:00
Andrew Turner
16d5f9a164 Add an implementation of .mcount on arm64
To support cc -pg on arm64 we need to implement .mcount. As clang and
gcc think it is function like it just needs to load the arguments
to _mcount and call it.

On gcc the first argument is passed in x0, however this is missing on
clang so we need to load it from the stack. As it's the caller return
address this will be at a known location.

PR:		262709
Reviewed by:	emaste (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34634
2022-03-23 15:16:59 +00:00
Andrew Turner
83961b7ede Remove the unused arm64 kernel profiling code
It's unused. Remove it in preperation for userspace support.

Sponsored by:	The FreeBSD Foundation
2022-03-22 16:07:54 +00:00
Kyle Evans
1236b04bb7 arm64: gic: disable the ITS if it's enabled prior to configuration
The ITS is defined to be disabled on a warm reset, but we may be coming
in via another kernel/hypervisor type setup where the ITS has been
previously configured then relinquished to the next kernel in the chain.

If it's enabled, the later configuration of GITS_BASER will almost
certainly fail -- clear it to prevent that.

Reviewed by:	andrew
Sponsored by:	Ampere Computing
Submitted by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D34546
2022-03-18 22:03:44 -05:00
Andrew Turner
813738faba Fix arm64 TLB invalidation with non-4k pages
When using 16k or 64k pages atop will shift the address by more than
the needed amount for a tlbi instruction. Replace this with a new macro
to shift the address by 12 and use PAGE_SIZE in the for loop to let the
code work with any page size.

Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34516
2022-03-15 17:25:28 +00:00
Andrew Turner
51f5cafcdc Remove a redundant L1_BLOCK == L2_BLOCK check
We have two checks for L1_BLOCK == L2_BLOCK. Remove one.

Sponsored by:	The FreeBSD Foundation
2022-03-15 17:25:28 +00:00
Andrew Turner
f2e36d47e3 Make page size dynamic in libkvm for arm64
To allow for a future 16k or 64k page size we need to tell libkvm which
is being used. Add a flag field in unused space in minidumphdr and use
it to signal between the different options.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34548
2022-03-15 09:52:15 +00:00
Andrew Turner
5e2f304cb4 Fix calculating l0index in _pmap_alloc_l3 on arm64
When moving from the l1 index to l0 index we need to use the l1 shift
value not the l0 shift value. With 4k pages they are identical, however
with 16k pages we only have 2 l0 entries so the shift value is incorrect.

Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34517
2022-03-15 09:51:41 +00:00
John Baldwin
456d57a66d aarch64: Add constants for fields in the PMEVTYPERn_EL0 event registers.
Reviewed by:	andrew
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34526
2022-03-11 11:29:45 -08:00
Andrew Turner
7e35f7834c Revert "Add the PMCR_EL0.N arm64 register field"
This reverts commit b6fd96ed0b.
2022-03-11 17:52:08 +00:00
Andrew Turner
4dc815608e Add more arm64 register op* and CR* values
These will be used by bhyve/arm64.

Sponsored by:	Innovate UK
2022-03-11 11:21:09 +00:00
Andrew Turner
b6fd96ed0b Add the PMCR_EL0.N arm64 register field
Sponsored by:	Innovate UK
2022-03-11 11:21:09 +00:00
Andrew Turner
a1b4e4fa9a Correct the location of the arm64 PMCR register
This was one of the last registers to not be in alphabetical order in
armreg.h. Fix this to make it easier to find.

Sponsored by:	Innovate UK
2022-03-11 11:21:09 +00:00
Andrew Turner
2abeef7300 Sort the M* and P* arm64 registers
Sponsored by:	Innovate UK
2022-03-11 11:21:09 +00:00
John Baldwin
6b71405bfe Store core dump notes for all valid register sets for FreeBSD processes.
In particular, use a generic wrapper around struct regset rather than
requiring per-regset helpers.  This helper replaces the MI
__elfN(note_prstatus) and __elfN(note_fpregset) helpers.  It also
removes the need to explicitly dump NT_ARM_ADDR_MASK in the arm64
__elfN(dump_thread).

Reviewed by:	markj, emaste
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34446
2022-03-10 15:40:19 -08:00
Andrew Turner
5055ffaeba Remove an unneeded memset from the arm64 pmap
There is no need to zero pagetable_dmap as we already did it when
creating the page tables in locore.S

Sponsored by:	The FreeBSD Foundation
2022-03-10 19:13:49 +00:00
Andrew Turner
ba3b602001 Split out creating the arm64 L2 dmap entries
When creating the DMAP region we may need to create level 2 page table
entries at the start and end of a block of memory. The code to do this
was almost identical so we can merge into a single function.

Sponsored by:	The FreeBSD Foundation
2022-03-10 18:17:06 +00:00
Andrew Turner
854d5a4f72 Remove l1ptfrom pmap_early_vtophys on arm64
The first argument was unused as we use an address translation
instruction to get the physical address.

Sponsored by:	The FreeBSD Foundation
2022-03-10 18:17:06 +00:00
Andrew Turner
a19acfd56c Fix the arm64 DMAP start address in a comment
Sponsored by:	The FreeBSD Foundation
2022-03-10 11:00:44 +00:00
Andrew Turner
f62e099ed5 Fix the TCR_TG0 values
They are in a different order to the TCR_TG1 values but appear to have
been copied incorrectly.

While here use TCR_TG0_4K in locore.S to make it explicit the userspace
page size is 4K.

Sponsored by:	The FreeBSD Foundation
2022-03-10 10:54:39 +00:00
Andrew Turner
9cf15aefb9 Fix the spelling of EFI_PAGE_SIZE
We assume EFI_PAGE_SIZE is the same as PAGE_SIZE, however this may not
be the case. Use the former when working with a list of pages from the
UEFI firmware so the correct size is used.

This will be needed on arm64 where PAGE_SIZE could be 16k or 64k in the
future. The other architectures have been updated to be consistent.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34510
2022-03-10 10:43:54 +00:00
Andrew Turner
e3f7087489 Add more arm64 PAC identification fields
Sponsored by:	The FreeBSD Foundation
2022-03-10 10:43:48 +00:00
Andrew Turner
ed30663426 Make the arm64 get_pcpu a function again
We assume the pointer returned from get_pcpu will be consistent even
if the thread is moved to a new CPU. Fix this by partially reverting
63c858a04d to make get_pcpu a function again.

Sponsored by:	The FreeBSD Foundation
2022-03-08 11:54:58 +00:00
Andrew Turner
e793a55a74 Print the instruction for the unknown exception
The arm64 unknown exception will be raised when we execute an
instruction that id invalid or disabled. To help debug these print
the instruction that failed.

Sponsored by:	The FreeBSD Foundation
2022-03-08 11:54:58 +00:00
Andrew Turner
db3a1eec37 Rework the arm64 sigtramp code to be a trampoline
To help with switching to a vdso sigtramp switch to passing through the
sigcode function when entering a signal. This ensures the return address
is within the function.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33690
2022-03-07 10:03:07 +00:00
Andrew Turner
d8da59ddf8 Fix the sanitizer header checks on arm64
We need to not include the MI _san.h files when builing some parts of
the kernel. Fix these checks in the arm64 header files.

Sponsored by:	The FreeBSD Foundation
2022-02-23 14:50:56 +00:00
Andrew Turner
ec1ecf78ae Add the char and short atomic operations on arm64
Sponsored by:	The FreeBSD Foundation
2022-02-23 14:45:28 +00:00
Andrew Turner
6713be3159 Add NT_ARM_ADDR_MASK
This can be used by debuggers to find which bits in a virtual address
should be masked off to get a canonical address. This is currently used
by the Pointer Authentication Code support to get its mask. It could also
be used if we support Top Byte Ignore for the same purpose.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34302
2022-02-22 17:10:35 +00:00
Emmanuel Vadot
90288dcb4c arm64: conf: Remove options EXT_RESOURCES
It is now unused in kernel code.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D33836
2022-02-21 17:29:09 +01:00
Michal Meloun
a534b50e24 tegra: Improve the detection of the secondary function (RTC) of the MAX77620.
Use the new ofw_iicbus_set_devinfo() method to implant an OFW compatibility
string for a manually created RTC sub-device.

MFC after:	4 weeks
Reported by:	archimedes.gaviola_at_gmail.com
		bscott_at_bunyatech.com.au
2022-02-20 12:26:04 +01:00
Warner Losh
3988ca5aab aarch64: Add static asssert for context size
Add a static assert for the siginfo{,32}_t, mcontext{,32}_t and
ucontext{,32}_t sizes. These are de-facto ABI options and cannot change
size ever.

Reviewed by:		kib, andrew, jhb
Differential Revision:	https://reviews.freebsd.org/D32958
2022-02-10 14:32:20 -07:00
Andrew Turner
31cf95cec7 Stop single stepping in signal handers on arm64
We should clear the single step flag when entering a signal hander and
set it when returning. This fixes the ptrace__PT_STEP_with_signal test.

While here add support for userspace to set the single step bit as on
x86. This can be used by userspace for self tracing.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34170
2022-02-07 15:03:23 +00:00
Andrew Turner
67dc576bae Fix the signal code on 32-bit breakpoints on arm64
When debugging 32-bit programs a debugger may insert a instruction that
will raise the undefined instruction trap. The kernel handles these
by raising a SIGTRAP, however the code was incorrect.

Fix this by using the expected TRAP_BRKPT signal code.

Sponsored by:	The FreeBSD Foundation
2022-02-07 11:56:04 +00:00
Gordon Bergling
b6724f7004 tegra: Fix a common typo in source code comments
- s/ajusted/adjusted/

MFC after:	3 days
2022-02-06 17:31:05 +01:00
Andrew Turner
664640ba6c Sort the names of the arm64 debug registers
While here clean up the names for the naming convention of the other
registers in this file.

Reviewed by:	kib, mhorne (earlier version)
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34060
2022-02-04 10:49:27 +00:00
Jesper Schmitz Mouridsen
ea07ba1170 sys/arm64/iommu/iommu_pmap.c readd sys/systm.h
after d950c5898a UINT64_C and bzero were no longer defined

Approved by:	kib
Differential Revision:	https://reviews.freebsd.org/D34155
2022-02-03 20:03:29 +01:00
Mitchell Horne
4e1bc961bb arm64, riscv: handle RB_KDB
This allows entering the debugger at the earliest possible time, if
the '-d' argument is passed to the kernel.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D34120
2022-02-01 13:59:54 -04:00
Andrew Turner
548a2ec49b Add PT_GETREGSET
This adds the PT_GETREGSET and PT_SETREGSET ptrace types. These can be
used to access all the registers from a specified core dump note type.
The NT_PRSTATUS and NT_FPREGSET notes are initially supported. Other
machine-dependant types are expected to be added in the future.

The ptrace addr points to a struct iovec pointing at memory to hold the
registers along with its length. On success the length in the iovec is
updated to tell userspace the actual length the kernel wrote or, if the
base address is NULL, the length the kernel would have written.

Because the data field is an int the arguments are backwards when
compared to the Linux PTRACE_GETREGSET call.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19831
2022-01-27 11:40:34 +00:00
Andrew Turner
2ad1999722 Add the Armv8.3-SPE registers 2022-01-19 12:07:35 +00:00
Mark Johnston
758d98debe exec: Remove the stack gap implementation
ASLR stack randomization will reappear in a forthcoming commit.  Rather
than inserting a random gap into the stack mapping, the entire stack
mapping itself will be randomized in the same way that other mappings
are when ASLR is enabled.

No functional change intended, as the stack gap implementation is
currently disabled by default.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 16:11:54 -05:00
Mark Johnston
706f4a81a8 exec: Introduce the PROC_PS_STRINGS() macro
Rather than fetching the ps_strings address directly from a process'
sysentvec, use this macro.  With stack address randomization the
ps_strings address is no longer fixed.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 16:11:54 -05:00
Mark Johnston
3fc21fdd5f sysent: Add a sv_psstringssz field to struct sysentvec
The size of the ps_strings structure varies between ABIs, so this is
useful for computing the address of the ps_strings structure relative to
the top of the stack when stack address randomization is enabled.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33704
2022-01-17 11:42:07 -05:00
Brooks Davis
0910a41ef3 Revert "syscallarg_t: Add a type for system call arguments"
Missed issues in truss on at least armv7 and powerpcspe need to be
resolved before recommit.

This reverts commit 3889fb8af0.
This reverts commit 1544e0f5d1.
2022-01-12 23:29:20 +00:00
Brooks Davis
3889fb8af0 sysent: regen for syscallarg_t 2022-01-12 22:51:25 +00:00
Brooks Davis
1544e0f5d1 syscallarg_t: Add a type for system call arguments
This more clearly differentiates system call arguments from integer
registers and return values. On current architectures it has no effect,
but on architectures where pointers are not integers (CHERI) and may
not even share registers (CHERI-MIPS) it is necessiary to differentiate
between system call arguments (syscallarg_t) and integer register values
(register_t).

Obtained from:	CheriBSD

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D33780
2022-01-12 22:51:25 +00:00
Andrew Turner
85b7c566f1 Add arm64 pointer authentication support
Pointer authentication allows userspace to add instructions to insert
a Pointer Authentication Code (PAC) into a register based on an address
and modifier and check if the PAC is correct. If the check fails it will
either return an invalid address or fault to the kernel.

As many of these instructions are a NOP when disabled and in earlier
revisions of the architecture this can be used, for example, to sign
the return address before pushing it to the stack making Return-oriented
programming (ROP) attack more difficult on hardware that supports them.

The kernel manages five 128 bit signing keys: 2 instruction keys, 2 data
keys, and a generic key. The instructions then use one of these when
signing the registers. Instructions that use the first four store the
PAC in the register being signed, however the instructions that use the
generic key store the PAC in a separate register.

Currently all userspace threads share all the keys within a process
with a new set of userspace keys being generated when executing a new
process. This means a forked child will share its keys with its parent
until it calls an appropriate exec system call.

In the kernel we allow the use of one of the instruction keys, the ia
key. This will be used to sign return addresses in function calls.
Unlike userspace each kernel thread has its own randomly generated.

Thread0 has a static key as does the early code on secondary CPUs.
This should be safe as there is minimal user interaction with these
threads, however we could generate random keys when the Armv8.5
Random number generation instructions are present.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D31261
2022-01-12 15:27:17 +00:00
Andrew Turner
78c347d9f3 Fix a typo in an arm64 comment
This was pointed out by markj in the review, but I missed it and forgot
to fix before pushing.

Reported by:	markj
Sponsored by:	The FreeBSD Foundation
2022-01-10 14:08:15 +00:00
Andrew Turner
77402d2834 Move instructions into the arm64 exception vectors
We have 32 instructions in each exception vector on arm64. Previously
only one was used to branch to the handler function. We can split the
start of these functions and move some of the instructions into the
vectors.

Reviewed by:	kib, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33751
2022-01-10 10:51:16 +00:00
John Baldwin
7def1e10b3 bus_dma: Deduplicate locking helper functions.
- Move busdma_lock_mutex to subr_bus_dma.c.

- Move _busdma_lock_dflt to subr_bus_dma.c.  This function was named a
  couple of different things previously.  It is not a public API but
  an internal helper used in place of a NULL pointer.  The prototype
  is in <sys/bus_dma.h> as not all backends include
  <sys/bus_dma_internal.h>.

Reviewed by:	kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33694
2022-01-05 13:50:40 -08:00
John Baldwin
85b4607324 Deduplicate bus_dma bounce code.
Move mostly duplicated code in various MD bus_dma backends to support
bounce pages into sys/kern/subr_busdma_bounce.c.  This file is
currently #include'd into the backends rather than compiled standalone
since it requires access to internal members of opaque bus_dma
structures such as bus_dmamap_t and bus_dma_tag_t.

Reviewed by:	kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33684
2022-01-05 13:50:40 -08:00
Andrew Turner
459e0b92e8 Use the arm64 ttbr macro to define the ASID shift
Now we have a macro to descrive the arm64 TTBR registers use it in the
ASID_TO_OPERAND pmap macro.

Sponsored by:	The FreeBSD Foundation
2022-01-05 14:56:25 +00:00
Andrew Turner
0accd72674 Add the arm64 TTBR fields to armreg.h
Sponsored by:	The FreeBSD Foundation
2022-01-05 14:56:25 +00:00
Andrew Turner
ce1e5d0d5e Add a missing space in the arm64 sendsig
Sponsored by:	The FreeBSD Foundation
2022-01-05 12:38:54 +00:00
Andrew Turner
fbdca14953 Remove the sigcode base check on arm64
This was added with the shared page support. It is unused as we always
enable the shared page on FreeBSD executables on arm64.
2022-01-05 11:57:38 +00:00
Hubert Mazur
f21c469dbc Add driver for marvell, a37x0 peripheral clocks
Add driver for Marvell, Armada-37xx peripheral clock.
Register clocks for various peripheral devices in
north bridge or south bridge domain. Dump clock's
domain while verbose boot.

Reviewed by:
Obtained from:		Semihalf
Differential revision:	https://reviews.freebsd.org/D32294
2022-01-04 13:26:35 +01:00
Hubert Mazur
127e4d9524 Add driver for armada, 37x0-tbg-clock
Driver for tbg clocks. Read reference frequency from parent
and modify it depending on parameters read from register.

Reviewed by:		manu
Obtained from:		Semihalf
Differential revision:	https://reviews.freebsd.org/D32293
2022-01-04 13:26:34 +01:00
Hubert Mazur
01b9c59fd2 Add driver for marvell, armada-3700 oscillator
Driver registers new clock device. Clock frequency is set depending
on tenth bit's value obtained from syscon register. Full information
about the clock is dumped if bootverbose is enabled.

Driver was tested on EspressoBin.

Reviewed by:		manu
Obtained from:		Semihalf
Differential revision:	https://reviews.freebsd.org/D32292
2022-01-04 13:26:34 +01:00
Alan Cox
4ccd6c137f arm64: Implement final level only TLB invalidations
A feature of arm64's instruction for TLB invalidation is the ability
to determine whether cached intermediate entries, i.e., L{0,1,2}_TABLE
entries, are invalidated in addition to the final entry, e.g., an
L3_PAGE entry.

Update pmap_invalidate_{page,range}() to support both types of
invalidation, allowing the caller to determine which type of
invalidation is performed.

Update the callers to request the appropriate type of invalidation.

Eliminate redundant TLB invalidations in pmap_abort_ptp() and
pmap_remove_l3_range().

Add a comment to pmap_invalidate_all() making clear that it always
invalidates entries at all levels.

As expected, these changes result in a tiny yet measurable
performance improvement.

Reviewed by:	kib, markj
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D33705
2022-01-03 13:14:18 -06:00
Jessica Clarke
3582b9e372 arm64: Check for intrng-reported errors in gicv3_its
Currently, any errors when adding a PIC child handler are ignored,
instead just continuing on to registering that PIC as an MSI, and
ignoring any errors that occur for that too.

Reviewed by:	andrew
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33342
2022-01-03 17:09:42 +00:00
Doug Moore
f1e7a532d1 busdma: _bus_dmamap_addseg repaired
A recent change introduced a one-off error into a test allowing
coalescing chunks into segments.  This fixes that error.

broke a check in _bus_dmamap_addseg on many architectures. This change makes it clear that it is not a particular range that is being boundary-checked, but the proposed union of the two adjacent ranges.
Reported by:	se
Reviewed by:	se
Fixes:	c606ab59e7 vm_extern: use standard address checkers everywhere
Differential Revision:	https://reviews.freebsd.org/D33715
2022-01-02 12:37:05 -06:00
Mark Johnston
f04a096049 exec: Simplify sv_copyout_strings implementations a bit
Simplify control flow around handling of the execpath length and signal
trampoline.  Cache the sysentvec pointer in a local variable.

No functional change intended.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33703
2021-12-31 12:50:15 -05:00
Doug Moore
c606ab59e7 vm_extern: use standard address checkers everywhere
Define simple functions for alignment and boundary checks and use them
everywhere instead of having slightly different implementations
scattered about. Define them in vm_extern.h and use them where
possible where vm_extern.h is included.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D33685
2021-12-30 22:09:08 -06:00
Alan Cox
24b82aa0c5 arm64: Simplify pmap_ts_referenced
Use pmap_pte_exists() in place of multiple KASSERT()s.

Eliminate an unnecessary NULL check.

MFC after:	1 week
2021-12-28 17:59:39 -06:00
Alan Cox
3c2ee7b28c arm64: Enhance pmap_pte_exists()'s error reporting
Report the descriptor type and level at which the page table does not
match the caller's expectations.

MFC after:	1 week
2021-12-28 17:46:21 -06:00
John Baldwin
254e4e5b77 Simplify swi for bus_dma.
When a DMA request using bounce pages completes, a swi is triggered to
schedule pending DMA requests using the just-freed bounce pages.  For
a long time this bus_dma swi has been tied to a "virtual memory" swi
(swi_vm).  However, all of the swi_vm implementations are the same and
consist of checking a flag (busdma_swi_pending) which is always true
and if set calling busdma_swi.  I suspect this dates back to the
pre-SMPng days and that the intention was for swi_vm to serve as a
mux.  However, in the current scheme there's no need for the mux.

Instead, remove swi_vm and vm_ih.  Each bus_dma implementation that
uses bounce pages is responsible for creating its own swi (busdma_ih)
which it now schedules directly.  This swi invokes busdma_swi directly
removing the need for busdma_swi_pending.

One consequence is that the swi now works on RISC-V which had previously
failed to invoke busdma_swi from swi_vm.

Reviewed by:	imp, kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D33447
2021-12-28 13:51:25 -08:00
Alan Cox
e161dfa918 Fix pmap_is_prefaultable() on arm64 and riscv
The current implementations never correctly return TRUE. In all cases,
when they currently return TRUE, they should have returned FALSE.  And,
in some cases, when they currently return FALSE, they should have
returned TRUE.  Except for its effects on performance, specifically,
additional page faults and pointless calls to pmap_enter_quick() that
abort, this error is harmless.  That is why it has gone unnoticed.

Add a comment to the amd64, arm64, and riscv implementations
describing how their return values are computed.

Reviewed by:	kib, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33659
2021-12-27 19:17:14 -06:00
Alan Cox
03f9cc89e1 arm64: Fix "set-but-not-used" warnings in the pmap
MFC after:	1 week
2021-12-27 11:48:15 -06:00
Michal Meloun
7c0ec66385 tegra210: Implement new get_gate method for tegra210 clocks.
MFC after:	1 week
2021-12-24 19:43:48 +01:00
Andrew Turner
8ddb4b9b66 Extract the arm64 signal code to a new file
This will be used by the vdso signal trampoline on arm64.

While here fix the license as this part of locore.S to correct the
copyright owner.

Sponsored by:	The FreeBSD Foundation
2021-12-24 11:59:43 +00:00
Alan Cox
b7ec0d268b arm64: Introduce and use pmap_pte_exists()
Use pmap_pte_exists() instead of pmap_pte() when the caller expects a
mapping to exist at a particular level.  The caller benefits in two
ways from using pmap_pte_exists().  First, because the level is
specified to pmap_pte_exists() as a constant, rather than returned, the
compiler can specialize the implementation of pmap_pte_exists() to the
caller's exact needs, i.e., generate fewer instructions.  Consequently,
within a GENERIC-NODEBUG kernel, 704 bytes worth of instructions are
eliminated from the inner loops of various pmap functions.  Second,
suppose that the mapping doesn't exist.  Rather than requiring every
caller to implement its own KASSERT()s to report missing mappings, the
caller can optionally have pmap_pte_exists() provide the KASSERT().

Reviewed by:	andrew, kib
Tested by:	andrew (an earlier version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33597
2021-12-23 22:56:02 -06:00
Andrew Turner
02c16e2174 Add atomic_testandset_acq_* on arm64
We only need to include sys/_atomic_subword.h on arm64 to provide
atomic_testandset_acq_long. Add an implementation in the arm64 atomic.h
based on the existing atomic_testandset macro.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33587
2021-12-21 13:06:27 +00:00
Andrew Turner
69cfbd669e Don't fail changing props for unmapped DMAP memory
When recursing in pmap_change_props_locked we may fail because there is
no pte. This shouldn't be considered a fail as it may happen in a few
cases, e.g. there are multiple normal memory ranges with device memory
between them.

Reported by:	cperciva
Tested by:	cperciva
Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33459
2021-12-21 13:06:27 +00:00
Edward Tomasz Napierala
a15c591899 linux(4): Remove unused arm64 SDT declarations
Those tracepoints have been removed somewhere in the past.

Sponsored By:	EPSRC
2021-12-21 12:32:35 +00:00
Kyle Evans
e6f760f0e8 sysent: regenerate 2021-12-16 20:56:28 -06:00
Kyle Evans
8494666658 sysent: move away from allowing all compat options for other ABIs
Notably, the current compat_options only makes sense for native and
freebsd32 ABIs.  For the others, it just adds cruft. Switch to having
sets of compat options, and default to the native set.  Setup the other
ABIs where it doesn't make sense to opt-out of the native set.

This removes some redundant COMPAT_FREEBSD* stuff from Linuxolator bits.

line_expr in makesyscalls.lua is fixed to allow empty strings to be
specified, since they're harmless.

Reviewed by:	brooks, kib (both earlier version)
Differential Revision:	https://reviews.freebsd.org/D33356
2021-12-16 20:56:28 -06:00
Andriy Gapon
b7bcd21d2d rk_i2c_fill_tx: fixup previous commit
I forgot to amend the previous commit where i was uninitialized.

Fixes:		c663545951 rk_i2c_fill_tx: fix a number of issues
MFC after:	1 week
2021-12-15 13:21:16 +02:00
Andriy Gapon
c663545951 rk_i2c_fill_tx: fix a number of issues
- maximum number of bytes that can be sent is 32, not 8;
- previous interface required callers to bump sc->msg->len in addition
  to setting sc->tx_slave_addr;
- because of the above there was an issue with writing one too many bytes
  because sc->cnt is not advanced when the slave address is written;
- the inetraction between outer and inner loops was confusing as the former
  was bounded on the number of bytes to write and the counter was
  incremented by one, but the inner loop advanced four bytes at a time;
- the return value was incorrect in the tx_slave_addr case; one call place
  had to use its own (and incorrect in some cases) notion of the write
  lenth.

All of the above issues should be fixed.
Some sanity asserts are added.
All callers use the return value to program RK_I2C_MTXCNT.
iic_msg::len no longer needs to be hacked.
A constant is added to reflect the maximum number of octets that can be
sent or received in one go (they are the same).

MFC after:	1 week
2021-12-15 13:16:14 +02:00
Andriy Gapon
25e92673b5 rk_i2c_transfer: minor improvement to bit twiddling
No need to mask a uint8_t with 0xff, the mask covers the whole type.
Explcitly cast to uint32_t before bit shifting instead of relying on
the implicit promotion to signed int.

MFC after:	1 week
2021-12-15 13:16:09 +02:00
Andriy Gapon
4501b07071 rk_i2c: do not hide NACK condition from consumers
Previously the driver would happily talk to addresses with no device
returning some garbage for reads and sending bits into the void for writes.

MFC after:	1 week
2021-12-15 13:16:04 +02:00
Andriy Gapon
7dc8a0e5df rk_i2c: keep sending bytes until all bytes are sent
Previously the code would decalre the transfer complete after sending
first 31 bytes (plus the slave address) of a larger I2C write transfer.

That was tested using a large write to an EEPROM with 32-byte write page
size and a 2-byte address type.  Such a transaction needed to send 34
bytes, 2 bytes for an offset and 32 bytes of actual data.

MFC after:	1 week
2021-12-15 13:15:58 +02:00
Andriy Gapon
b6a2aba959 rk_i2c_transfer: fix off-by-one in check for last message
This also fixes an access beyond msgs array.

MFC after:	1 week
2021-12-15 13:15:50 +02:00
Andriy Gapon
ede576831b rk_i2c_drain_rx: remove useless arithmetic manipulations
When i % 4 == 0 the result of (i / 4) * 4 is always i.

MFC after:	1 week
2021-12-15 13:15:45 +02:00
Andriy Gapon
1da04ae8fb rk_i2c: consistently treat booleans as such
MFC after:	1 week
2021-12-15 13:15:23 +02:00
Andriy Gapon
552503aca9 rk_i2c_transfer: use iicbus error codes instead of generic ones
MFC after:	1 week
2021-12-15 13:14:56 +02:00
Andriy Gapon
5f863d7e13 rk_i2c: remove write-only softc field
MFC after:	1 week
2021-12-15 13:14:29 +02:00
Andrew Turner
6238905c5b Only change DMAP props on DMAP covered memory
When changing memory properties in the arm64 pmap we need to keep both
the kernel address and DMAP mappings in sync.

To keep the kernel and DMAP memory in sync we recurse when updating the
former to also update the latter. There was insuffucuent checking around
this recursion. It would check if the virtual address is not within the
DMAP region, but not if the physical address is covered.

Add the missing check as without it the recursion may return an error.

Sponsored by:	The FreeBSD Foundation
2021-12-14 10:38:19 +00:00
Andrew Turner
2b556942cc Fix set but not used warnings in arm64 rockchip
Reviewed by:	manu, mmel
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33372
2021-12-10 13:29:11 +00:00
Andrew Turner
5b616dafac Fix set but not used warnings in arm64 core code 2021-12-10 12:10:30 +00:00