aboutsummaryrefslogtreecommitdiff
path: root/sys/riscv
Commit message (Collapse)AuthorAgeFilesLines
* random: allow disabling of entropy harvesting from keyboard & miceDavid E. O'Brien34 hours1-0/+4
| | | | | | Reviewed by: jmg Sponsored by: Juniper Networks Differential Revision: https://reviews.freebsd.org/D53390
* random: TPM_HARVEST should have been named RANDOM_ENABLE_TPMDavid E. O'Brien40 hours1-0/+4
| | | | | | | | | | | * Enable RANDOM_ENABLE_TPM by default * The commit of TPM_HARVEST failed to add it to NOTES so that the LINT kernel would build the code. Fixes: 4ee7d3b0118c82e651712bb65da53d08e78cd7b1 Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53460
* vmm: Move vm_maxcpu handling into MI codeMark Johnston8 days1-22/+0
| | | | | | | | | | No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53477
* vmm: Consolidate VM name length checkingMark Johnston8 days3-7/+3
| | | | | | | | | | | | | | | | | | | vm_create() is only called from one place. Rather than having similar checks everywhere, move them to vmmdev_create(). We can safely assume that the name is nul-terminated, the vmmctl ioctl handler and the legacy sysctl handler ensure this. So, don't bother with strnlen(). Finally, make sure that the name buffers are the same size on all platforms. VM_MAX_NAMELEN is supposed to be the maximum, not including the nul terminator. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53422
* vmm: Move the module load handler to vmm_dev.cMark Johnston8 days1-60/+5
| | | | | | | | | | | | | | | | | Move the vmm_initialized check out of vm_create() and into the legacy sysctl handler. If vmm_initialized is false, /dev/vmmctl will not be available and so cannot be used to create VMs. Introduce new MD vmm_modinit() and vmm_modcleanup() routines which handle MD (de)initialization. No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53421
* riscv/vmm: Remove a redundant maxcpu check in vm_alloc_vcpu()Mark Johnston12 days3-15/+0
| | | | | | | | | | | | | | | | | aplic_max_cpu_count() just returns the VM's max vCPU count, and vm_alloc_vcpu() already checks that. Just remove this check so that it's easier to merge vm_alloc_vcpu() into MI code. If the APLIC really does require us to lower the limit, we should instead adjust vm->maxcpu in vm_create(). No functional change intended. Reviewed by: br MFC after: 1 week Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53496
* riscv: Treat pointer register as an input in fpe_storeJohn Baldwin13 days1-33/+33
| | | | | | | | | | | | | | The contents of the memory is an output, but the pointer to that memory is an input. This was correct in the original version of D45697, but when adding appropriate clobbers, the pointer operand was incorrectly switched to an output rather than left an input for fpe_store. Reviewed by: jrtc27 Obtained from: CheriBSD Fixes: 44d4ee7f3dad ("riscv: add FPE code.") MFC after: 1 day Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D53441
* kexec: Add dummy headers for arm, i386, powerpc, and riscvJustin Hibbits2025-10-271-0/+39
| | | | | | | | kexec hasn't been ported to these architectures, yet, so appease the build with dummy headers. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51625
* vmm: Move local variables into ioctl handlersMark Johnston2025-10-211-12/+25
| | | | | | | | | | | Make the ioctl handlers easy to read by moving local variables into per-ioctl blocks. No functional change intended. Reviewed by: corvink, emaste MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53145
* vmm: Improve register get/set handling a bitMark Johnston2025-10-211-3/+2
| | | | | | | | | | | | | | | | | On non-amd64 platforms, check for negative register indices. This isn't required today since we match against individual register indices, but we might as well check it. On amd64, add a comment explaining why we permit negative register indices. Use mallocarray() for allocating register arrays in the ioctl layer. No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53143
* riscv: build allwinner DTBsMitchell Horne2025-10-201-0/+3
| | | | | | | | | | These are known to work if loaded manually by loader(8) (for the Nezha board at least). If nothing else, it is useful to provide a DTB closely tied to the kernel version. MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53118
* riscv: build starfive JH7110 DTBsMitchell Horne2025-10-201-0/+3
| | | | | | | | | | These are known to work if loaded manually by loader(8) (for VF2 at least). If nothing else, it is useful to provide a DTB closely tied to the kernel version. MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D53117
* imgact: Mark brandinfo and note structures as constZhenlei Huang2025-10-181-2/+2
| | | | | | | | | No functional change intended. Reviewed by: kib MFC after: 10 days MFC with: 80336636b6b9f7a3bdad007c400e85eae017d2a2 Differential Revision: https://reviews.freebsd.org/D53173
* vmm: Fix a deadlock between vm_smp_rendezvous() and vcpu_lock_all()Mark Johnston2025-10-172-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | vm_smp_rendezvous() invokes a callback on all vCPUs, blocking the initiator until all vCPUs have responded. vcpu_lock_all() blocks each vCPU by waiting for it to go idle and setting the vCPU state to frozen. These two operations can deadlock on each other, particularly when booting a Windows guest, when vcpu_lock_all() blocks waiting for a rendezvous initiator, and the initiator is blocked waiting for the vCPU thread which called vcpu_lock_all() to invoke the rendezvous callback. Implement vcpu_lock_all() in a way that avoids deadlocks with vm_smp_rendezvous(). In particular, when traversing vCPUs, invoke the rendezvous callback on the vCPU's behalf to help the initiator finish. We can only safely do so when the vCPU is IDLE or we have already locked it, otherwise we may be racing with the target vCPU thread. Thus: - Use an exclusive lock to serialize vcpu_lock_all() callers, which lets us lock vCPUs out of order without fear of deadlock with parallel vcpu_lock_all() callers. - If a rendezvous is pending, lock all idle vCPUs and invoke the callback on their behalf. If the vcpu_lock_all() caller is itself a vCPU thread, this will handle that thread. - Block waiting for all non-idle vCPUs to idle, or until one of them initiates a rendezvous, in which case we go back and invoke callbacks on behalf of already-locked vCPUs. Note that on !amd64 no changes are needed since there is no rendezvous mechanism, so there is a separate vcpu_set_state_all() for them based on the previous vcpu_lock_all(). These will be merged together once vcpu state handling is consolidated into sys/dev/vmm. Reviewed by: corvink (previous version) MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D52968
* vmm: Remove some unused macrosMark Johnston2025-10-101-1/+0
| | | | | | | | | | No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53013
* vmm: Move the guest vmspace into the generic vm_mem structureMark Johnston2025-10-102-22/+10
| | | | | | | | | | | | | This further consolidates handling of guest memory into MI code in sys/dev/vmm. No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53012
* vmm: Make vmmops declarations more consistentMark Johnston2025-10-102-23/+23
| | | | | | | | | | | | | | | | | | | - On amd64, make vmmops_* functions globally visible, as some will be called from machine-independent code in the future. - On arm64 and riscv, move declarations to vmm.h, since they're supposed to be generic across different VMM backends (only amd64 has more than one backend). - Make the declaration macros consistent with each other. - On amd64, make the function typedef names consistent with the corresponding ifunc names. No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53011
* vmm: Unify implementations of vcpu_cleanup()Mark Johnston2025-10-101-2/+1
| | | | | | | | | | | | Different vmm implementations were freeing the per-vCPU structure in different places. Make the implementations consistent. No functional change intended. Reviewed by: corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D53010
* u2f(4): Invert U2F_MAKE_UHID_ALIAS kernel build optionVladimir Kondratyev2025-09-251-1/+0
| | | | | | | This makes non-GENERIC kernel configs easier to maintain. Requested by: glebius MFC after: 2 days
* arm, powerpc, riscv: implement atomic_set/clear_16Konstantin Belousov2025-09-201-0/+3
| | | | | | | Reviewed by: jrtc27, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D52626
* riscv: Provide prototypes for fpgetmask/fpsetmaskAlex Richardson2025-09-151-0/+5
| | | | | | | | | | These functions are stubs that do nothing but are called by some software and not providing them results in implicit function declaration errors. This was missed in D25740. Reviewed by: #riscv, mhorne MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D52035
* vmm: Suspend the VM before destroying itMark Johnston2025-09-102-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Otherwise we don't do anything to kick vcpu threads out of a sleep state when destroying a VM. For instance, suppose a guest executes hlt on amd64 or wfi on arm64 with interrupts disabled. Then, bhyvectl --destroy will hang until the vcpu thread somehow comes out of vm_handle_hlt()/vm_handle_wfi() since destroy_dev() is waiting for vCPU threads to drain. Note that on amd64, if hw.vmm.halt_detection is set to 1 (the default), the guest will automatically exit in this case since it's treated as a shutdown. But, the above should not hang if halt_detection is set to 0. Here, vm_suspend() wakes up vcpu threads, and a subsequent attempt to run the vCPU will result in an error which gets propagated to userspace, allowing destroy_dev() to proceed. Add a new suspend code for this purpose. Modify bhyve to exit with status 4 ("exited due to an error") when it's received, since that's what'll happen generally when the VM is destroyed asynchronously. Reported by: def MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D51761
* jh7110_pcie.c: add empty PIC methods to conform conventionsJari Sihvola2025-08-201-0/+12
| | | | | | | | | | | This commit updates the driver code to conform with an undocumented convention which says that certain functions need always be implemented together regardless of their content (or lack of). It's been said that unimplemented KOBJ methods become stubs which return ENXIO so this commit does not imply a functional change. Reviewed by: mhorne Differential Revision: https://reviews.freebsd.org/D52042
* u2f(4): a HID driver for FIDO/U2F security keysVladimir Kondratyev2025-08-171-0/+1
| | | | | | | | | | | | | | | | | While FIDO/U2F keys were already supported by the generic uhid(4) and hidraw(4) drivers, this driver adds some additional features an does steps to tighten the security of FIDO/U2F access. - It automatically loads through devd. - Automatically enables HQ_NO_READAHEAD for FIDO/U2F devices. - Implements only miminum set of features. - Do not requires external devfs configuration to set character device permissions. - Names character device as u2f/# to make possible capsicum or any other pledge()-style sandboxing. PR: 265528 Differential Revision: https://reviews.freebsd.org/D51612
* gpio: remove gpiobus_attach_busAhmad Khalifa2025-08-132-2/+4
| | | | | | | | | | | | Since gpiobus_attach_bus can attach the gpiobus child along with its children in the same bus pass, the parent controller's reference to gpiobus might not be set by the time the children need it. Instead, drivers should use gpiobus_add_bus and explicitly call bus_attach_children. Reviewed by: mmel, imp (older version) Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D51578
* busdma: another fix for small bounce transfersMitchell Horne2025-08-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | More fallout from a77e1f0f81df. When the tag has an alignment requirement but a small (remaining) transfer size, the transfer will be rounded up to exceed its bounds, resulting in memory corruption. The issue is observed on powerpc as noted in the pull request: https://github.com/freebsd/freebsd-src/pull/1415 I also observe the issue locally on riscv hardware, with an 8-byte transfer having 64-byte alignment. There is some uncertainty about the purpose/need for the alignment roundup; both its original intention and present effect. Notably, it is no longer present at all in arm/arm64 implementations. Possibly, this roundup can be removed altogether, but this requires more careful analysis of the edge-cases and history of the property. For now, simply clamp sgsize to be no larger than the remaining buflen, as this is certain to be correct within the current scheme and fixes the affected transfers. Discussed with: jhb, markj MFC after: 3 weeks Fixes: a77e1f0f81df ("busdma: better handling of small segment bouncing") Sponsored by: The FreeBSD Foundation Pull Request: https://github.com/freebsd/freebsd-src/pull/1415 Signed-off-by: Chattrapat Sangmanee <aomsin27@hotmail.co.th> Co-authored-by: Chattrapat Sangmanee <aomsin27@hotmail.co.th> Differential Revision: https://reviews.freebsd.org/D47807
* jh7110_pcie: Add StarFive JH7110 PCIe controller driverJari Sihvola2025-08-072-0/+1026
| | | | | | | | | | | | | | | | | | | | | | JH7110 has two PCIE controller devices. First one is used by board's integrated USB which has no driver. Switching PHY to USB mode is not currently implemented. This functionality could be added in a form of a separate PCIE PHY driver if needed. PHY is on by default and there's no need to switch it on. Pre/post_ithread and post_filter methods are not used for interrupt masking since they are meant for level-triggered interrupts whereas JH7110's MSI interrupts are edge triggered (and INTx interrupts do not use this irqsrc scheme at all). Pre_ithread method is nevertheless used for MSI bottom acking. The driver has been tested with Kingston SNV2S NVME SSD The functionality of INTx and MSI interrupts (as opposed to default MSIx) has been tested by forcing NVME to use them. Reviewed by: mhorne MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47919
* jh7110_gpio: Add StarFive JH7110 GPIO controller driverJari Sihvola2025-08-072-0/+368
| | | | | | | | | Basic functionality implemented; fdt_pinctrl interface to be added in the future. Reviewed by: mhorne MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43034
* riscv: Add cvitek SoC files to the buildBojan Novković2025-08-013-0/+19
| | | | | Reviewed by: br, jrtc27 Differential Revision: https://reviews.freebsd.org/D48533
* riscv: Add driver for the cvitek reboot controllerBojan Novković2025-08-011-0/+158
| | | | | | | | This patch adds support for the cvitek reboot controller. This controller is present on the Milk-V riscv SoCs. Reviewed by: br, mhorne, jrtc27 Differential review: https://reviews.freebsd.org/D48532
* riscv: Add driver for cvitek reset controllerBojan Novković2025-08-011-0/+132
| | | | | | | | | This patch adds support for the cvitek reset controller. This controller is present on the Milk-V riscv SoCs. The controller is currently only used by the if_dwc driver. Differential Revision: https://reviews.freebsd.org/D48531 Reviewed by: jrtc27, br
* vmm: Add support for guest NUMA emulationBojan Novković2025-07-271-0/+5
| | | | | | | | | | | | | This change adds the necessary kernelspace bits required for supporting NUMA domains in bhyve VMs. The layout of system memory segments and how they're created has been reworked. Each guest NUMA domain will now have its own memory segment. Furthermore, this change allows users to tweak the domain's backing vm_object domainset(9) policy. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44565
* riscv: enable aw_mmc driverMitchell Horne2025-07-222-0/+2
| | | | | | | For the Allwinner D1. MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D51198
* pmap: Degrade pmap_page_set_attr*() into a no-op on same attributeOlivier Certner2025-07-131-0/+2
| | | | | | | | | | | | For 32-bit arm, move the no-op test that was already in place at start of the function so that it stays first even if the '#if 0' block around the call to sf_buf_invalidate_cache() is uncommented at some point (if ever). Reviewed by: jeffpc_josefsipek.net, kib MFC after: 10 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51253
* riscv: add aw_rtc device to configMitchell Horne2025-07-042-0/+2
| | | | | | | Somehow dropped during a rebase. This actually enables the driver. Fixes: d88bc5f943a9 ("riscv: enable allwinner RTC") Sponsored by: The FreeBSD Foundation
* nexus: Add device_shutdown where missingJustin Hibbits2025-06-251-0/+1
| | | | | | | | | | | | | At shutdown devices may need to do extra work to clean up state, etc. This is done in a device_shutdown kobj method on a driver, with the default being a `do nothing` method. Only x86's nexus driver includes the device_shutdown method to propagate down to its children, so on other architectures the device_shutdown stops at the root, and thus device_shutdown is never called for any real devices. Add this missing method to the nexus drivers of the other architectures so devices have a chance to properly shutdown. Sponsored by: Juniper Networks, Inc.
* newbus: replace leftover device unit wildcardsAhmad Khalifa2025-06-212-4/+4
| | | | | | Reviewed by: imp, jhb Approved by: imp (mentor) Differential Revision: https://reviews.freebsd.org/D50913
* pmap_growkernel(): do not panic immediately, optionally return the errorKonstantin Belousov2025-06-191-4/+23
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47935
* runq: Deduce most parameters, remove machine headersOlivier Certner2025-06-181-44/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'runq' machinery now depends on only two settable parameters, RQ_MAX_PRIO, the maximum priority number that can be accepted, the minimum being 0, and RQ_PPQ, the number of priorities per queue (to reduce the number of queues). All other parameters are deduced from these ones. Also, all architectures automatically get a runq word that is their natural word. RQB_FFS() always was 'ffsl() - 1' except for amd64 where it was 'bsfq()'. Now that all these finally call compiler builtins, the resulting assembly code is the same, so there is no cost to removing this special case. After all these changes, <machine/runq.h> headers have no more purpose, so remove them. While here, fix potentially confusing parameter name for RQB_WORD() and RQB_BIT(). While here, include all necessary headers so that <sys/runq.h> can be included standalone. No functional change (intended). Reviewed by: kib MFC after: 1 month Event: Kitchener-Waterloo Hackathon 202506 Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45387
* vm: remove pa_index from the machine-independent layerAlan Cox2025-06-131-1/+2
| | | | | | | | | | | After the demise of vm_page_lock(), the only remaining uses of pa_index() are in various pmap implementations. In many cases, e.g., amd64, the pmap implementations already provided their own definitions, often identical to the machine-independent one. For those that didn't provide one, this change adds it. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D50823
* thr_new: pass params.flags to cpu_set_user_tls()Konstantin Belousov2025-05-311-1/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* subr_devmap: Reduce the use of the static devmapAndrew Turner2025-05-021-6/+0
| | | | | | | | | We only create the static devmap on arm. Stop building this code on other architectures. Reviewed by: mhorne, imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D50016
* riscv: add Sifive p550/p650 identificationMeng Zhuo2025-04-222-0/+2
| | | | | Reviewed-by: Warner Losh <imp@FreeBSD.org> Pull-Request: https://github.com/freebsd/freebsd-src/pull/1674
* riscv: support for Cache-Block Operations (CBO).Ruslan Bukin2025-04-223-2/+191
| | | | | | | | | | | | CBO represents a subset of Cache-Management Operations (CMO) spec. While the CMO spec encompasses all operations on caches, the CBO subset operates on cache blocks only. Detect Zicbom, Zicboz and Zicbop extensions and provide cache invalidation handlers based on Zicbom instructions. Sponsored by: UKRI Differential Revision: https://reviews.freebsd.org/D49852
* riscv: replace tailq pointers with iteratorsDoug Moore2025-04-211-9/+11
| | | | | | | | Change architecture-specific code to use iterators rather than tailq pointers. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49928
* riscv: Fix handling of interrupts during kernel page faultsMark Johnston2025-04-191-1/+1
| | | | | | | | | | We were checking the wrong status bit when deciding whether to enable interrupts. Reviewed by: jrtc27 Fixes: c226f193515c ("riscv: Permit spurious faults in kernel mode") MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D49897
* riscv: Exclude OpenSBI memory regions when booting with EFIBojan Novković2025-04-161-2/+30
| | | | | | | | | | | | | | | | | | | OpenSBI uses the first PMP entry to prevent buggy supervisor software from overwriting the firmware [1]. However, this region may not be properly marked as reserved in the EFI map, leading to an access violation exception whenever the kernel attempts to write to a page from that region. Fix this by preemptively excluding first EFI memory map entry if it is marked as "BootServicesData". [1] https://github.com/riscv-non-isa/riscv-sbi-doc/pull/37 Reported by: tuexen Tested by: tuexen Fixes: a2e2178402af Reviewed by: imp, jrtc27 Differential Revision: https://reviews.freebsd.org/D49839
* efi/metadata: Make a note that efi_map_header isn't standardWarner Losh2025-04-091-3/+8
| | | | | | | | | | efi_map_header is similar to, but not at all the same as the UEFI EFI_MEMORY_ATTRIBUTES_TABLE (we could easily have used the latter though, with one fewer non-standard types, but we can't change it easily now due to the last 10 years of boot loaders passing this in). Sponsored by: Netflix
* sys: Use fdt_foreach on arm, arm64, and riscvAndrew Turner2025-04-081-22/+41
| | | | | | | | This means we can remove the fixed mem_regions array. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49700
* eqos: Add StarFive JH7110 variantJari Sihvola2025-04-022-0/+6
| | | | | | | | | Found on the VisionFive v2 SBC, and similar. Reviewed by: mhorne Tested by: mhorne Discussed with: sos Differential Revision: https://reviews.freebsd.org/D45600