efi_riscv.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Defines APIs that allow an OS to interact with UEFI firmware to query
  4. * information about the boot hart ID.
  5. *
  6. * Copyright (c) 2022, Ventana Micro Systems Inc
  7. */
  8. #define LOG_CATEGORY LOGC_EFI
  9. #include <common.h>
  10. #include <efi_loader.h>
  11. #include <efi_variable.h>
  12. #include <log.h>
  13. #include <asm/global_data.h>
  14. #include <efi_riscv.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. static const efi_guid_t efi_guid_riscv_boot_protocol = RISCV_EFI_BOOT_PROTOCOL_GUID;
  17. /**
  18. * efi_riscv_get_boot_hartid() - return boot hart ID
  19. * @this: RISCV_EFI_BOOT_PROTOCOL instance
  20. * @boot_hartid: caller allocated memory to return boot hart id
  21. * Return: status code
  22. */
  23. static efi_status_t EFIAPI
  24. efi_riscv_get_boot_hartid(struct riscv_efi_boot_protocol *this,
  25. efi_uintn_t *boot_hartid)
  26. {
  27. EFI_ENTRY("%p, %p", this, boot_hartid);
  28. if (this != &riscv_efi_boot_prot || !boot_hartid)
  29. return EFI_INVALID_PARAMETER;
  30. *boot_hartid = gd->arch.boot_hart;
  31. return EFI_EXIT(EFI_SUCCESS);
  32. }
  33. struct riscv_efi_boot_protocol riscv_efi_boot_prot = {
  34. .revision = RISCV_EFI_BOOT_PROTOCOL_REVISION,
  35. .get_boot_hartid = efi_riscv_get_boot_hartid
  36. };
  37. /**
  38. * efi_riscv_register() - register RISCV_EFI_BOOT_PROTOCOL
  39. *
  40. * Return: status code
  41. */
  42. efi_status_t efi_riscv_register(void)
  43. {
  44. efi_status_t ret = EFI_SUCCESS;
  45. ret = efi_add_protocol(efi_root, &efi_guid_riscv_boot_protocol,
  46. (void *)&riscv_efi_boot_prot);
  47. if (ret != EFI_SUCCESS)
  48. log_err("Cannot install RISCV_EFI_BOOT_PROTOCOL\n");
  49. return ret;
  50. }