| // SPDX-License-Identifier: BSD-3-Clause | |
| // | |
| // Copyright 2025 Google LLC | |
| #include <common.h> | |
| #include <efi_loader.h> | |
| #include <malloc.h> | |
| #define EFI_TIMESTAMP_PROTOCOL_GUID \ | |
| EFI_GUID(0xafbfde41, 0x2e6e, 0x4262, 0xba, 0x65, 0x62, 0xb9, 0x23, \ | |
| 0x6e, 0x54, 0x95) | |
| static const efi_guid_t efi_timestamp_guid = EFI_TIMESTAMP_PROTOCOL_GUID; | |
| typedef struct { | |
| uint64_t frequency; | |
| uint64_t end_value; | |
| } efi_timestamp_properties_t; | |
| struct efi_timestamp { | |
| uint64_t (*get_timestamp)(void); | |
| efi_status_t (*get_properties)(efi_timestamp_properties_t *); | |
| }; | |
| static uint64_t get_timestamp(void) | |
| { | |
| return get_timer(0); | |
| } | |
| static efi_status_t get_properties(efi_timestamp_properties_t *out) | |
| { | |
| if (!out) { | |
| return EFI_INVALID_PARAMETER; | |
| } | |
| out->frequency = CONFIG_SYS_HZ; | |
| out->end_value = (unsigned long)-1; | |
| return EFI_SUCCESS; | |
| } | |
| static struct efi_timestamp protocol = { | |
| .get_timestamp = get_timestamp, | |
| .get_properties = get_properties, | |
| }; | |
| static efi_handle_t handle = NULL; | |
| efi_status_t efi_timestamp_register(void) | |
| { | |
| if (handle) { | |
| return EFI_ALREADY_STARTED; | |
| } | |
| return efi_install_multiple_protocol_interfaces( | |
| &handle, &efi_timestamp_guid, &protocol, NULL); | |
| } |