Changeset View
Standalone View
sys/dev/efidev/efirt.c
| Show All 26 Lines | ||||||||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||||||||
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||||||
| * SUCH DAMAGE. | * SUCH DAMAGE. | |||||||||
| */ | */ | |||||||||
| #include <sys/cdefs.h> | #include <sys/cdefs.h> | |||||||||
| __FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | |||||||||
| #include "opt_acpi.h" | ||||||||||
| #include <sys/param.h> | #include <sys/param.h> | |||||||||
| #include <sys/efi.h> | #include <sys/efi.h> | |||||||||
| #include <sys/eventhandler.h> | #include <sys/eventhandler.h> | |||||||||
| #include <sys/kernel.h> | #include <sys/kernel.h> | |||||||||
| #include <sys/linker.h> | #include <sys/linker.h> | |||||||||
| #include <sys/lock.h> | #include <sys/lock.h> | |||||||||
| #include <sys/malloc.h> | #include <sys/malloc.h> | |||||||||
| #include <sys/module.h> | #include <sys/module.h> | |||||||||
| Show All 13 Lines | ||||||||||
| #include <machine/efi.h> | #include <machine/efi.h> | |||||||||
| #include <machine/metadata.h> | #include <machine/metadata.h> | |||||||||
| #include <machine/vmparam.h> | #include <machine/vmparam.h> | |||||||||
| #include <vm/vm.h> | #include <vm/vm.h> | |||||||||
| #include <vm/pmap.h> | #include <vm/pmap.h> | |||||||||
| #include <vm/vm_map.h> | #include <vm/vm_map.h> | |||||||||
| #ifdef DEV_ACPI | ||||||||||
| #include <contrib/dev/acpica/include/acpi.h> | ||||||||||
| #endif | ||||||||||
| #define EFI_TABLE_ALLOC_MAX 0x800000 | #define EFI_TABLE_ALLOC_MAX 0x800000 | |||||||||
| static struct efi_systbl *efi_systbl; | static struct efi_systbl *efi_systbl; | |||||||||
| static eventhandler_tag efi_shutdown_tag; | static eventhandler_tag efi_shutdown_tag; | |||||||||
| /* | /* | |||||||||
| * The following pointers point to tables in the EFI runtime service data pages. | * The following pointers point to tables in the EFI runtime service data pages. | |||||||||
| * Care should be taken to make sure that we've properly entered the EFI runtime | * Care should be taken to make sure that we've properly entered the EFI runtime | |||||||||
| * environment (efi_enter()) before dereferencing them. | * environment (efi_enter()) before dereferencing them. | |||||||||
| ▲ Show 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | get_time(struct efi_tm *tm) | |||||||||
| EFI_TIME_LOCK(); | EFI_TIME_LOCK(); | |||||||||
| /* | /* | |||||||||
| * UEFI spec states that the Capabilities argument to GetTime is | * UEFI spec states that the Capabilities argument to GetTime is | |||||||||
| * optional, but some UEFI implementations choke when passed a NULL | * optional, but some UEFI implementations choke when passed a NULL | |||||||||
| * pointer. Pass a dummy efi_tmcap, even though we won't use it, | * pointer. Pass a dummy efi_tmcap, even though we won't use it, | |||||||||
| * to workaround such implementations. | * to workaround such implementations. | |||||||||
| */ | */ | |||||||||
| error = efi_get_time_locked(tm, &dummy); | error = efi_get_time_locked(tm, &dummy); | |||||||||
| EFI_TIME_UNLOCK(); | ||||||||||
| return (error); | ||||||||||
| } | ||||||||||
| static int | ||||||||||
| get_waketime(uint8_t *enabled, uint8_t *pending, struct efi_tm *tm) | ||||||||||
kibUnsubmitted Done Inline Actions
kib: | ||||||||||
| { | ||||||||||
| struct efirt_callinfo ec; | ||||||||||
| int error; | ||||||||||
| #ifdef DEV_ACPI | ||||||||||
| UINT32 acpiRtcEnabled; | ||||||||||
| #endif | ||||||||||
| if (efi_runtime == NULL) | ||||||||||
| return (ENXIO); | ||||||||||
| EFI_TIME_LOCK(); | ||||||||||
| bzero(&ec, sizeof(ec)); | ||||||||||
| ec.ec_name = "rt_getwaketime"; | ||||||||||
| ec.ec_argcnt = 3; | ||||||||||
| ec.ec_arg1 = (uintptr_t)enabled; | ||||||||||
| ec.ec_arg2 = (uintptr_t)pending; | ||||||||||
| ec.ec_arg3 = (uintptr_t)tm; | ||||||||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_getwaketime); | ||||||||||
| error = efi_call(&ec); | ||||||||||
| EFI_TIME_UNLOCK(); | ||||||||||
| #ifdef DEV_ACPI | ||||||||||
| if (error == 0) { | ||||||||||
| error = AcpiReadBitRegister(ACPI_BITREG_RT_CLOCK_ENABLE, | ||||||||||
Done Inline ActionsIf efi_call() returned error, the call to ReadBit seems to be useless. kib: If efi_call() returned error, the call to ReadBit seems to be useless. | ||||||||||
| &acpiRtcEnabled); | ||||||||||
| if (ACPI_SUCCESS(error)) { | ||||||||||
| *enabled = *enabled && acpiRtcEnabled; | ||||||||||
| } else | ||||||||||
Done Inline ActionsDon't you want to inform caller when ReadBit failed? kib: Don't you want to inform caller when ReadBit failed? | ||||||||||
Done Inline ActionsYou need to either translate ACPI error code to errno namespace, or just assign some error value there, in case of !ACPI_SUCCESS kib: You need to either translate ACPI error code to errno namespace, or just assign some error… | ||||||||||
Done Inline ActionsI would rather not try to translate error codes... how about fixing it to EOPNOTSUPP? There's a bit of a can of worms: if the EFI call succeeds but ACPI fails, do we need to undo the EFI call? jo_bruelltuete.com: I would rather not try to translate error codes... how about fixing it to EOPNOTSUPP?
There's… | ||||||||||
Done Inline ActionsAs I suggested above, single error code is fine too, e.g. EIO. You might printf something which would include raw value of the ACPI error. Also I do not think that we need to undo anything if ACPI call failed. If it is failed (i.e. the BIOS and hw are broken) so be it. We informed user about the situation. kib: As I suggested above, single error code is fine too, e.g. EIO. You might printf something… | ||||||||||
| error = EIO; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
| return (error); | ||||||||||
| } | ||||||||||
| static int | ||||||||||
| set_waketime(uint8_t enable, struct efi_tm *tm) | ||||||||||
| { | ||||||||||
| struct efirt_callinfo ec; | ||||||||||
| int error; | ||||||||||
Done Inline ActionsI put a AcpiWriteBitRegister(ACPI_BITREG_RT_CLOCK_ENABLE, 1) here and that made S3-wakeup work! Now question is: should that call to AcpiWriteBitRegister really live here? Feels out of place... jo_bruelltuete.com: I put a `AcpiWriteBitRegister(ACPI_BITREG_RT_CLOCK_ENABLE, 1)` here and that made S3-wakeup… | ||||||||||
Done Inline ActionsWhy not? Of course, it must be covered by the #ifdef DEV_ACPI guards. Also, you need to disable RT_CLOCK bit if the set_waketime got enable == false. kib: Why not? Of course, it must be covered by the #ifdef DEV_ACPI guards. Also, you need to… | ||||||||||
| if (efi_runtime == NULL) | ||||||||||
| return (ENXIO); | ||||||||||
| EFI_TIME_LOCK(); | ||||||||||
| bzero(&ec, sizeof(ec)); | ||||||||||
| ec.ec_name = "rt_setwaketime"; | ||||||||||
| ec.ec_argcnt = 2; | ||||||||||
| ec.ec_arg1 = (uintptr_t)enable; | ||||||||||
| ec.ec_arg2 = (uintptr_t)tm; | ||||||||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_setwaketime); | ||||||||||
| error = efi_call(&ec); | ||||||||||
| EFI_TIME_UNLOCK(); | EFI_TIME_UNLOCK(); | |||||||||
Done Inline ActionsSame note about efi_call() failing. kib: Same note about efi_call() failing. | ||||||||||
| #ifdef DEV_ACPI | ||||||||||
| if (error == 0) { | ||||||||||
| error = AcpiWriteBitRegister(ACPI_BITREG_RT_CLOCK_ENABLE, | ||||||||||
Done Inline ActionsSame. kib: Same. | ||||||||||
| (enable != 0) ? 1 : 0); | ||||||||||
| if (ACPI_FAILURE(error)) | ||||||||||
| error = EIO; | ||||||||||
| } | ||||||||||
| #endif | ||||||||||
| return (error); | return (error); | |||||||||
| } | } | |||||||||
| static int | static int | |||||||||
| get_time_capabilities(struct efi_tmcap *tmcap) | get_time_capabilities(struct efi_tmcap *tmcap) | |||||||||
| { | { | |||||||||
| struct efi_tm dummy; | struct efi_tm dummy; | |||||||||
| int error; | int error; | |||||||||
| ▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | ||||||||||
| const static struct efi_ops efi_ops = { | const static struct efi_ops efi_ops = { | |||||||||
| .rt_ok = rt_ok, | .rt_ok = rt_ok, | |||||||||
| .get_table = get_table, | .get_table = get_table, | |||||||||
| .copy_table = copy_table, | .copy_table = copy_table, | |||||||||
| .get_time = get_time, | .get_time = get_time, | |||||||||
| .get_time_capabilities = get_time_capabilities, | .get_time_capabilities = get_time_capabilities, | |||||||||
| .reset_system = reset_system, | .reset_system = reset_system, | |||||||||
| .set_time = set_time, | .set_time = set_time, | |||||||||
| .get_waketime = get_waketime, | ||||||||||
| .set_waketime = set_waketime, | ||||||||||
| .var_get = var_get, | .var_get = var_get, | |||||||||
| .var_nextname = var_nextname, | .var_nextname = var_nextname, | |||||||||
| .var_set = var_set, | .var_set = var_set, | |||||||||
| }; | }; | |||||||||
| const struct efi_ops *active_efi_ops = &efi_ops; | const struct efi_ops *active_efi_ops = &efi_ops; | |||||||||
| static int | static int | |||||||||
| efirt_modevents(module_t m, int event, void *arg __unused) | efirt_modevents(module_t m, int event, void *arg __unused) | |||||||||
| Show All 26 Lines | ||||||||||