aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/efidev/efirt.c
Commit message (Collapse)AuthorAgeFilesLines
* efidev: add support for memory attributeShengYi Hung2025-07-221-2/+40
| | | | | | | | | | | The EFI_PROPERTIES_TABLE has been deprecated in the UEFI specification. It is now replaced by the EFI_MEMORY_ATTRIBUTES_TABLE, which provides a new header and data format for describing memory region attributes. Reviewed by: imp Approved by: markj (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49998
* efi: Move to using efi_guid_t in ioctl definitionsWarner Losh2025-05-011-3/+3
| | | | | | | | | | | | | | | | | Start using efi_guid_t instead of struct uuid in the ioctl definitions. These are binarily the same, but have different structure definitions. EFI prefers this form, and to allow more sharing with EDK2, make this slight addition. I've not really defined new IOCTLs for this. They are the same size, but I have defined new function. Also fix in-kernel uses of uuid to efi_guid_t for anything related to ioctl. Sponsored by: Netflix Reviewed by: tsoome, kib Differential Revision: https://reviews.freebsd.org/D50057
* efi: Use EDK2 EFI_GUID instead of sturct uuidWarner Losh2025-05-011-9/+9
| | | | | | | | | | | | | So, while struct uuid and EFI_GUID are quite similar (they are the same size, they have the same binary representation, etc), they aren not identical. Speciifcally, the UUID and GUID defines are slightly different and can't be swapped one for the other. Start to use EFI_GUID for all EFI tables. This will allow increased sharing with the boot laoder that already uses EDK2 variants as well as using the possibility to use the EDK2 headers we've already imported more easily. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D50037
* efirt: add a tunable to disable printing faults during EFIRT callsKonstantin Belousov2025-04-021-1/+10
| | | | | | | | | PR: 285797 Reported and tested by: Bakul Shah <bakul@iitbombay.org> Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D49592
* sys: make the kernel metadata pointer globalAhmad Khalifa2025-01-241-5/+1
| | | | | | | | | | | | | | | | | The way we got the kernel metadata pointer was by calling preload_search_by_type with one of the following three: "elf kernel", "elf32 kernel" and "elf64 kernel". Which one(s) we used wasn't consistent though. Sometimes we would only try "elf kernel", and other times we would try one of the latter two if the first failed. However, the loader only ever sets "elf kernel" as the kernel type. Now, the kmdp is a global, preload_kmdp, and it's initialized using preload_initkmdp in machdep.c (or machdep_boot.c on arm/64). preload_initkmdp takes a single boolean argument that tells us whether not finding the kmdp is fatal or not. Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394
* efirt: use correct ABI for runtime EFI functionsAhmad Khalifa2024-12-251-15/+16
| | | | | | When calling EFI RT methods through no fault path. MFC after: 1 week
* efirt: Fix the TDP_EFIRT assertionMark Johnston2024-11-221-1/+1
| | | | Fixes: a03957a706a0 ("efirt: mark dynamic region executing the RT code with the TDP_EFIRT flag")
* efirt: mark dynamic region executing the RT code with the TDP_EFIRT flagKonstantin Belousov2024-11-211-1/+7
| | | | | | | Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47694
* efirt: Move comment about fpu_kern_enter to where it is calledJohn Baldwin2023-08-251-0/+5
| | | | | Reviewed by: imp, kib, andrew, markj Differential Revision: https://reviews.freebsd.org/D41576
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Expose EFI wake time APIJohannes Totz2023-04-281-0/+76
| | | | | | Reviewed by: kib MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36714
* Use the correct size when checking an EFI addressAndrew Turner2022-09-091-1/+1
| | | | | | | | | | Use the correct page size macro when checking if an address is with the EFI runtime map. This would previously work correctly when the page size is 4k. With a larger page size it may incorrectly detect memory as within the map when it's not. Reported by: imp Sponsored by: Innovate UK
* efirt: Mark buffers filled out by EFI firmware as initializedMark Johnston2021-09-071-3/+16
| | | | | | Otherwise KMSAN may report false positives. Sponsored by: The FreeBSD Foundation
* EFI RT: resurrect EFIIOC_GET_TABLEPavel Balaev2021-07-031-0/+128
| | | | | | | | | | | | | | | | | | | | | | Make it work, but change the interface to be safe for non-root users. In particular, right now interface only works for the tables which can be minimally parsed by kernel to determine the table size. Then, userspace can query the table size, after that it provides a buffer of needed size and kernel copies out just table to userspace. Main advantage is that user no longer need to be able to read /dev/mem, the disadvantage is the need to have minimal parsers aware of the table types. Right now the parsers are implemented for ESRT and PROP tables. Future extension of the present interface might be a return of only the table physical address, in case kernel does not have suitable parser yet. Then, a privileged user could read the table from /dev/mem. This extension, which logically equivalent to the old (non-worked) EFIIOC_GET_TABLE variant, is not implemented until needed. Submitted by: Pavel Balaev <pavel.balaev@3mdeb.com> MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D30104
* Switch the EFI virtual address to a uint64_tAndrew Turner2021-05-011-2/+2
| | | | | | | | | | It is defined as a uint64_t in the UEFI spec. As it's not used as a pointer by the kernel follow this and define it as the same in the kernel. Reviewed by: kib, manu, imp Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D29759
* efirt: add hooks for diverging EFI implementationsRoger Pau Monné2021-02-161-19/+32
| | | | | | | | | | | | | | Introduce a set of hooks for MI EFI public functions, so that a new implementation can be done. This will be used to implement the Xen PV EFI interface that's used when running FreeBSD as a Xen dom0 from UEFI firmware. Also make the efi_status_to_errno non-static since it will be used to evaluate status return values from the PV interface. No functional change indented. Sponsored by: Citrix Systems R&D Reviewed by: kib, imp Differential revision: https://reviews.freebsd.org/D28620
* kern: efirt: correct configuration table entry sizeKyle Evans2020-12-291-1/+1
| | | | | | | | | | | | | Each entry actually stores a native pointer, not a uint64_t quantity. While we're here, go ahead and export the pointer as-is rather than converting it to KVA. This may be more useful as consumers can map /dev/mem and observe the entry. For reference, see: sys/contrib/edk2/Include/Uefi/UefiSpec.h Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D27669
* kern: efirt: enter runtime environment to deref efi_cfgtblKyle Evans2020-12-291-0/+7
| | | | | | | | This fixes an insta-panic when EFIIOC_GET_TABLE is used. Reviewed by: imp (earlier version), kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D27669
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-1/+2
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* efirt efi_enter(): Release acquired locks and restore FPU ownership ifKonstantin Belousov2019-06-031-1/+8
| | | | | | | | | | efi_arch_enter() returned an error. Submitted: Jan Martin Mikkelsen <janm@transactionware.com> MFC after: 1 week Notes: svn path=/head/; revision=348541
* efirt: When present, attempt to use EFI runtime services to shutdownConrad Meyer2018-12-151-2/+38
| | | | | | | | | | PR: maybe related to 233998 (inconclusive at this time) Submitted by: byuu <byuu AT tutanota.com> (previous version) Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D18506 Notes: svn path=/head/; revision=342108
* Assign to correct structure members.Konstantin Belousov2018-09-041-3/+3
| | | | | | | | | | Reported by: cem from Coverity Sponsored by: The FreeBSD Foundation MFC after: 6 days Approved by: re (gjb) Notes: svn path=/head/; revision=338461
* Catch exceptions during EFI RT calls on amd64.Konstantin Belousov2018-09-021-49/+131
| | | | | | | | | | | | | | | | This appeared to be required to have EFI RT support and EFI RTC enabled by default, because there are too many reports of faulting calls on many different machines. The knob is added to leave the exceptions unhandled to allow to debug the actual bugs. Reviewed by: kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (rgrimes) Differential revision: https://reviews.freebsd.org/D16972 Notes: svn path=/head/; revision=338437
* Normalize use of semicolon with EFI_TIME_LOCK macros.Konstantin Belousov2018-09-021-7/+7
| | | | | | | | | | | Reviewed by: kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Approved by: re (rgrimes) Differential revision: https://reviews.freebsd.org/D16972 Notes: svn path=/head/; revision=338433
* efirt: Don't enter EFI context early, convert addrs to KVA insteadKyle Evans2018-08-041-19/+13
| | | | | | | | | | | | | | | | | efi_enter here was needed because efi_runtime dereference causes a fault outside of EFI context, due to runtime table living in runtime service space. This may cause problems early in boot, though, so instead access it by converting paddr to KVA for access. While here, remove the other direct PHYS_TO_DMAP calls and the explicit DMAP requirement from efidev. Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D16591 Notes: svn path=/head/; revision=337331
* Follow up to r336919 and r336921: s/efi.rt_disabled/efi.rt.disabled/Kyle Evans2018-07-301-1/+1
| | | | | | | | | | | The latter matches the rest of the tree better [0]. The UPDATING entry has been updated to reflect this, and the new tunable is now documented in loader(8) [1]. Reported by: imp [0], Shawn Webb [1] Notes: svn path=/head/; revision=336924
* efirt: Add tunable to allow disabling EFI Runtime ServicesKyle Evans2018-07-301-0/+8
| | | | | | | | | | | | | Leading up to enabling EFIRT in GENERIC, allow runtime services to be disabled with a new tunable: efi.rt_disabled. This makes it so that EFIRT can be disabled easily in case we run into some buggy UEFI implementation and fail to boot. Discussed with: imp, kib MFC after: 1 week Notes: svn path=/head/; revision=336919
* efidev: Drop a quick note in about efi_cfgtbl/efi_runtimeKyle Evans2018-03-231-0/+5
| | | | | | | | | There's no real annotation for it, so it's not immediately obvious to the unfamiliar that these pointers are to locations in the EFI runtime map unlike the system table pointer immediately above them. Notes: svn path=/head/; revision=331413
* Re-work efidev ordering to fix efirt preloaded by loader on amd64Kyle Evans2018-03-221-1/+2
| | | | | | | | | | | | | | | | | | | | | On amd64, efi_enter calls fpu_kern_enter(). This may not be called until fpuinitstate has been invoked, resulting in a kernel panic with efirt_load="YES" in loader.conf(5). Move fpuinitstate a little earlier in SI_SUB_DRIVERS so that we can squeeze efirt between it and efirtc at SI_SUB_DRIVERS, SI_ORDER_ANY. efidev must be after efirt and doesn't really need to be at SI_SUB_DEVFS, so drop it at SI_SUB_DRIVER, SI_ORDER_ANY. The not immediately obvious dependency of fpuinitstate by efirt has been noted in both places. Discussed with: kib, andrew Reported by: Jakob Alvermark <jakob@alvermark.net> X-MFC-With: r330868 Notes: svn path=/head/; revision=331365
* Enter into the EFI environment before dereferencing the runtime servicesAndrew Turner2018-03-221-0/+9
| | | | | | | | | | | pointer. This may be within the EFI address space and not the FreeBSD kernel address space. X-MFC-With: r330868 Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=331361
* Check if the gettime runtime service is valid.Andrew Turner2018-03-201-0/+37
| | | | | | | | | | | | | | | | | | The U-Boot efi runtime service expects us to set the address map before calling any runtime services. It will then remap a few functions to their runtime version. One of these is the gettime function. If we call into this without having set a runtime map we get a page fault. Add a check to see if this is valid in efi_init() so we don't try to use the possibly invalid pointer. Reviewed by: imp, kevans (both previous version) X-MFC-With: r330868 Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D14759 Notes: svn path=/head/; revision=331241
* Correct minor typo in comment, efi_dmcap -> efi_tmcapKyle Evans2018-03-131-1/+1
| | | | Notes: svn path=/head/; revision=330844
* efirtc: Pass a dummy tmcap pointer to efi_get_time_lockedKyle Evans2018-03-131-1/+8
| | | | | | | | | | As noted in the comment, UEFI spec claims the capabilities pointer is optional, but some implementations will choke and attempt to dereference it without checking. This specific problem was found on a Lenovo Thinkpad X220 that would panic in efirtc_identify. Notes: svn path=/head/; revision=330843
* Add a function to retrieve the EFI realtime clock capabilities.Ian Lepore2018-03-011-3/+17
| | | | Notes: svn path=/head/; revision=330257
* Remove unused error return from API that cannot failConrad Meyer2018-02-231-7/+1
| | | | | | | | | | | | | | | | | | | No implementation of fpu_kern_enter() can fail, and it was causing needless error checking boilerplate and confusion. Change the return code to void to match reality. (This trivial change took nine days to land because of the commit hook on sys/dev/random. Please consider removing the hook or otherwise lowering the bar -- secteam never seems to have free time to review patches.) Reported by: Lachlan McIlroy <Lachlan.McIlroy AT isilon.com> Reviewed by: delphij Approved by: secteam (delphij) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14380 Notes: svn path=/head/; revision=329878
* Remove SFBUF_OPTIONAL_DIRECT_MAP and such hacks, replacing them across theNathan Whitehorn2018-01-191-0/+5
| | | | | | | | | | | | | | | | | | | kernel by PHYS_TO_DMAP() as previously present on amd64, arm64, riscv, and powerpc64. This introduces a new MI macro (PMAP_HAS_DMAP) that can be evaluated at runtime to determine if the architecture has a direct map; if it does not (or does) unconditionally and PMAP_HAS_DMAP is either 0 or 1, the compiler can remove the conditional logic. As part of this, implement PHYS_TO_DMAP() on sparc64 and mips64, which had similar things but spelled differently. 32-bit MIPS has a partial direct-map that maps poorly to this concept and is unchanged. Reviewed by: kib Suggestions from: marius, alc, kib Runtime tested on: amd64, powerpc64, powerpc, mips64 Notes: svn path=/head/; revision=328168
* To prepare for adding EFI runtime services support on arm64 move theAndrew Turner2017-10-011-0/+388
machine independent parts of the existing code to a new file that can be shared between amd64 and arm64. Reviewed by: kib (previous version), imp Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D12434 Notes: svn path=/head/; revision=324177