DxeBoardInitLib.c 2.8 KB

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