Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/efidev/efirt.c
| Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | static int efi_status2err[25] = { | ||||
| EPROTO, /* EFI_ICMP_ERROR */ | EPROTO, /* EFI_ICMP_ERROR */ | ||||
| EPROTO, /* EFI_TFTP_ERROR */ | EPROTO, /* EFI_TFTP_ERROR */ | ||||
| EPROTO /* EFI_PROTOCOL_ERROR */ | EPROTO /* EFI_PROTOCOL_ERROR */ | ||||
| }; | }; | ||||
| static int efi_enter(void); | static int efi_enter(void); | ||||
| static void efi_leave(void); | static void efi_leave(void); | ||||
| static int | int | ||||
| efi_status_to_errno(efi_status status) | efi_status_to_errno(efi_status status) | ||||
| { | { | ||||
| u_long code; | u_long code; | ||||
| code = status & 0x3ffffffffffffffful; | code = status & 0x3ffffffffffffffful; | ||||
| return (code < nitems(efi_status2err) ? efi_status2err[code] : EDOOFUS); | return (code < nitems(efi_status2err) ? efi_status2err[code] : EDOOFUS); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | efi_uninit(void) | ||||
| efi_systbl = NULL; | efi_systbl = NULL; | ||||
| efi_cfgtbl = NULL; | efi_cfgtbl = NULL; | ||||
| efi_runtime = NULL; | efi_runtime = NULL; | ||||
| mtx_destroy(&efi_lock); | mtx_destroy(&efi_lock); | ||||
| } | } | ||||
| int | static int | ||||
| efi_rt_ok(void) | rt_ok(void) | ||||
| { | { | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| static int | static int | ||||
| Show All 29 Lines | efi_leave(void) | ||||
| curpmap = &curproc->p_vmspace->vm_pmap; | curpmap = &curproc->p_vmspace->vm_pmap; | ||||
| td = curthread; | td = curthread; | ||||
| fpu_kern_leave(td, NULL); | fpu_kern_leave(td, NULL); | ||||
| mtx_unlock(&efi_lock); | mtx_unlock(&efi_lock); | ||||
| PMAP_UNLOCK(curpmap); | PMAP_UNLOCK(curpmap); | ||||
| } | } | ||||
| int | static int | ||||
| efi_get_table(struct uuid *uuid, void **ptr) | get_table(struct uuid *uuid, void **ptr) | ||||
| { | { | ||||
| struct efi_cfgtbl *ct; | struct efi_cfgtbl *ct; | ||||
| u_long count; | u_long count; | ||||
| int error; | int error; | ||||
| if (efi_cfgtbl == NULL || efi_systbl == NULL) | if (efi_cfgtbl == NULL || efi_systbl == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| error = efi_enter(); | error = efi_enter(); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | efi_get_time_locked(struct efi_tm *tm, struct efi_tmcap *tmcap) | ||||
| ec.ec_name = "rt_gettime"; | ec.ec_name = "rt_gettime"; | ||||
| ec.ec_argcnt = 2; | ec.ec_argcnt = 2; | ||||
| ec.ec_arg1 = (uintptr_t)tm; | ec.ec_arg1 = (uintptr_t)tm; | ||||
| ec.ec_arg2 = (uintptr_t)tmcap; | ec.ec_arg2 = (uintptr_t)tmcap; | ||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_gettime); | ec.ec_fptr = EFI_RT_METHOD_PA(rt_gettime); | ||||
| return (efi_call(&ec)); | return (efi_call(&ec)); | ||||
| } | } | ||||
| int | static int | ||||
| efi_get_time(struct efi_tm *tm) | get_time(struct efi_tm *tm) | ||||
| { | { | ||||
| struct efi_tmcap dummy; | struct efi_tmcap dummy; | ||||
| int error; | int error; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| 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(); | EFI_TIME_UNLOCK(); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | static int | ||||
| efi_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; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| EFI_TIME_LOCK(); | EFI_TIME_LOCK(); | ||||
| error = efi_get_time_locked(&dummy, tmcap); | error = efi_get_time_locked(&dummy, tmcap); | ||||
| EFI_TIME_UNLOCK(); | EFI_TIME_UNLOCK(); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | static int | ||||
| efi_reset_system(enum efi_reset type) | reset_system(enum efi_reset type) | ||||
| { | { | ||||
| struct efirt_callinfo ec; | struct efirt_callinfo ec; | ||||
| switch (type) { | switch (type) { | ||||
| case EFI_RESET_COLD: | case EFI_RESET_COLD: | ||||
| case EFI_RESET_WARM: | case EFI_RESET_WARM: | ||||
| case EFI_RESET_SHUTDOWN: | case EFI_RESET_SHUTDOWN: | ||||
| break; | break; | ||||
| Show All 24 Lines | efi_set_time_locked(struct efi_tm *tm) | ||||
| bzero(&ec, sizeof(ec)); | bzero(&ec, sizeof(ec)); | ||||
| ec.ec_name = "rt_settime"; | ec.ec_name = "rt_settime"; | ||||
| ec.ec_argcnt = 1; | ec.ec_argcnt = 1; | ||||
| ec.ec_arg1 = (uintptr_t)tm; | ec.ec_arg1 = (uintptr_t)tm; | ||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_settime); | ec.ec_fptr = EFI_RT_METHOD_PA(rt_settime); | ||||
| return (efi_call(&ec)); | return (efi_call(&ec)); | ||||
| } | } | ||||
| int | static int | ||||
| efi_set_time(struct efi_tm *tm) | set_time(struct efi_tm *tm) | ||||
| { | { | ||||
| int error; | int error; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| EFI_TIME_LOCK(); | EFI_TIME_LOCK(); | ||||
| error = efi_set_time_locked(tm); | error = efi_set_time_locked(tm); | ||||
| EFI_TIME_UNLOCK(); | EFI_TIME_UNLOCK(); | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| int | static int | ||||
| efi_var_get(efi_char *name, struct uuid *vendor, uint32_t *attrib, | var_get(efi_char *name, struct uuid *vendor, uint32_t *attrib, | ||||
| size_t *datasize, void *data) | size_t *datasize, void *data) | ||||
| { | { | ||||
| struct efirt_callinfo ec; | struct efirt_callinfo ec; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| bzero(&ec, sizeof(ec)); | bzero(&ec, sizeof(ec)); | ||||
| ec.ec_argcnt = 5; | ec.ec_argcnt = 5; | ||||
| ec.ec_name = "rt_getvar"; | ec.ec_name = "rt_getvar"; | ||||
| ec.ec_arg1 = (uintptr_t)name; | ec.ec_arg1 = (uintptr_t)name; | ||||
| ec.ec_arg2 = (uintptr_t)vendor; | ec.ec_arg2 = (uintptr_t)vendor; | ||||
| ec.ec_arg3 = (uintptr_t)attrib; | ec.ec_arg3 = (uintptr_t)attrib; | ||||
| ec.ec_arg4 = (uintptr_t)datasize; | ec.ec_arg4 = (uintptr_t)datasize; | ||||
| ec.ec_arg5 = (uintptr_t)data; | ec.ec_arg5 = (uintptr_t)data; | ||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_getvar); | ec.ec_fptr = EFI_RT_METHOD_PA(rt_getvar); | ||||
| return (efi_call(&ec)); | return (efi_call(&ec)); | ||||
| } | } | ||||
| int | static int | ||||
| efi_var_nextname(size_t *namesize, efi_char *name, struct uuid *vendor) | var_nextname(size_t *namesize, efi_char *name, struct uuid *vendor) | ||||
| { | { | ||||
| struct efirt_callinfo ec; | struct efirt_callinfo ec; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| bzero(&ec, sizeof(ec)); | bzero(&ec, sizeof(ec)); | ||||
| ec.ec_argcnt = 3; | ec.ec_argcnt = 3; | ||||
| ec.ec_name = "rt_scanvar"; | ec.ec_name = "rt_scanvar"; | ||||
| ec.ec_arg1 = (uintptr_t)namesize; | ec.ec_arg1 = (uintptr_t)namesize; | ||||
| ec.ec_arg2 = (uintptr_t)name; | ec.ec_arg2 = (uintptr_t)name; | ||||
| ec.ec_arg3 = (uintptr_t)vendor; | ec.ec_arg3 = (uintptr_t)vendor; | ||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_scanvar); | ec.ec_fptr = EFI_RT_METHOD_PA(rt_scanvar); | ||||
| return (efi_call(&ec)); | return (efi_call(&ec)); | ||||
| } | } | ||||
| int | static int | ||||
| efi_var_set(efi_char *name, struct uuid *vendor, uint32_t attrib, | var_set(efi_char *name, struct uuid *vendor, uint32_t attrib, | ||||
| size_t datasize, void *data) | size_t datasize, void *data) | ||||
| { | { | ||||
| struct efirt_callinfo ec; | struct efirt_callinfo ec; | ||||
| if (efi_runtime == NULL) | if (efi_runtime == NULL) | ||||
| return (ENXIO); | return (ENXIO); | ||||
| bzero(&ec, sizeof(ec)); | bzero(&ec, sizeof(ec)); | ||||
| ec.ec_argcnt = 5; | ec.ec_argcnt = 5; | ||||
| ec.ec_name = "rt_setvar"; | ec.ec_name = "rt_setvar"; | ||||
| ec.ec_arg1 = (uintptr_t)name; | ec.ec_arg1 = (uintptr_t)name; | ||||
| ec.ec_arg2 = (uintptr_t)vendor; | ec.ec_arg2 = (uintptr_t)vendor; | ||||
| ec.ec_arg3 = (uintptr_t)attrib; | ec.ec_arg3 = (uintptr_t)attrib; | ||||
| ec.ec_arg4 = (uintptr_t)datasize; | ec.ec_arg4 = (uintptr_t)datasize; | ||||
| ec.ec_arg5 = (uintptr_t)data; | ec.ec_arg5 = (uintptr_t)data; | ||||
| ec.ec_fptr = EFI_RT_METHOD_PA(rt_setvar); | ec.ec_fptr = EFI_RT_METHOD_PA(rt_setvar); | ||||
| return (efi_call(&ec)); | return (efi_call(&ec)); | ||||
| } | } | ||||
| const static struct efi_ops efi_ops = { | |||||
kib: Should this be const.
I prefer to have this structure static, and use const struct efi_ops… | |||||
| .rt_ok = rt_ok, | |||||
| .get_table = get_table, | |||||
| .get_time = get_time, | |||||
| .get_time_capabilities = get_time_capabilities, | |||||
| .reset_system = reset_system, | |||||
| .set_time = set_time, | |||||
| .var_get = var_get, | |||||
| .var_nextname = var_nextname, | |||||
| .var_set = var_set, | |||||
| }; | |||||
| 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) | ||||
| { | { | ||||
| switch (event) { | switch (event) { | ||||
| case MOD_LOAD: | case MOD_LOAD: | ||||
| return (efi_init()); | return (efi_init()); | ||||
| Show All 20 Lines | |||||
Should this be const.
I prefer to have this structure static, and use const struct efi_ops *active_efi_ops or such for calls, initialized at boot or module load.