DxeBoardInitLib.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /** @file
  2. Aspire VN7-572G Board Initialization DXE library
  3. Copyright (c) 2021, Baruch Binyamin Doron
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiDxe.h>
  7. #include <Library/UefiRuntimeServicesTableLib.h>
  8. #include <Library/BoardInitLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/EcLib.h>
  11. #include <Library/BoardEcLib.h>
  12. /**
  13. Update the EC's clock?
  14. **/
  15. VOID
  16. EcSendTime (
  17. VOID
  18. )
  19. {
  20. EFI_STATUS Status;
  21. EFI_TIME EfiTime;
  22. // TODO: Confirm this is really INTN and not UINTN
  23. INTN EcTime;
  24. UINT8 EcTimeByte;
  25. INTN Index;
  26. UINT8 EcResponse;
  27. Status = gRT->GetTime (&EfiTime, NULL);
  28. if (EFI_ERROR (Status)) {
  29. DEBUG ((DEBUG_INFO, "Failed to retrieve current time\n"));
  30. return;
  31. }
  32. // Time since year of release?
  33. EcTime = ((EfiTime.Year << 26) + (EfiTime.Month << 22) + (EfiTime.Day << 17)
  34. + (EfiTime.Hour << 12) + (EfiTime.Minute << 6) + (EfiTime.Second)
  35. /* 16 years */
  36. - 0x40000000);
  37. DEBUG ((DEBUG_INFO, "EC: reporting present time 0x%x\n", EcTime));
  38. SendEcCommand (0xE0);
  39. for (Index = 0; Index < 4; Index++) {
  40. EcTimeByte = EcTime >> Index;
  41. DEBUG ((DEBUG_INFO, "EC: Sending 0x%x (iteration %d)\n", EcTimeByte, Index));
  42. SendEcData (EcTimeByte);
  43. }
  44. Status = ReceiveEcData (&EcResponse);
  45. if (!EFI_ERROR (Status)) {
  46. DEBUG ((DEBUG_INFO, "EC: response 0x%x\n", EcResponse));
  47. }
  48. }
  49. /**
  50. Configure EC
  51. **/
  52. VOID
  53. EcInit (
  54. VOID
  55. )
  56. {
  57. UINT8 Dat;
  58. /* Vendor's UEFI modules "notify" this protocol in RtKbcDriver */
  59. EcCmd90Read (0x79, &Dat);
  60. if (Dat & BIT0) {
  61. EcSendTime ();
  62. }
  63. }
  64. /**
  65. A hook for board-specific initialization after PCI enumeration.
  66. @retval EFI_SUCCESS The board initialization was successful.
  67. @retval EFI_NOT_READY The board has not been detected yet.
  68. **/
  69. EFI_STATUS
  70. EFIAPI
  71. BoardInitAfterPciEnumeration (
  72. VOID
  73. )
  74. {
  75. EcInit ();
  76. return EFI_SUCCESS;
  77. }
  78. /**
  79. A hook for board-specific functionality for the ReadyToBoot event.
  80. @retval EFI_SUCCESS The board initialization was successful.
  81. @retval EFI_NOT_READY The board has not been detected yet.
  82. **/
  83. EFI_STATUS
  84. EFIAPI
  85. BoardInitReadyToBoot (
  86. VOID
  87. )
  88. {
  89. return EFI_SUCCESS;
  90. }
  91. /**
  92. A hook for board-specific functionality for the ExitBootServices event.
  93. @retval EFI_SUCCESS The board initialization was successful.
  94. @retval EFI_NOT_READY The board has not been detected yet.
  95. **/
  96. EFI_STATUS
  97. EFIAPI
  98. BoardInitEndOfFirmware (
  99. VOID
  100. )
  101. {
  102. return EFI_SUCCESS;
  103. }