LegacyCmos.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /** @file
  2. This code fills in standard CMOS values and updates the standard CMOS
  3. checksum. The Legacy16 code or LegacyBiosPlatform.c is responsible for
  4. non-standard CMOS locations and non-standard checksums.
  5. Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include "LegacyBiosInterface.h"
  9. /**
  10. Read CMOS register through index/data port.
  11. @param[in] Index The index of the CMOS register to read.
  12. @return The data value from the CMOS register specified by Index.
  13. **/
  14. UINT8
  15. LegacyReadStandardCmos (
  16. IN UINT8 Index
  17. )
  18. {
  19. IoWrite8 (PORT_70, Index);
  20. return IoRead8 (PORT_71);
  21. }
  22. /**
  23. Write CMOS register through index/data port.
  24. @param[in] Index The index of the CMOS register to write.
  25. @param[in] Value The value of CMOS register to write.
  26. @return The value written to the CMOS register specified by Index.
  27. **/
  28. UINT8
  29. LegacyWriteStandardCmos (
  30. IN UINT8 Index,
  31. IN UINT8 Value
  32. )
  33. {
  34. IoWrite8 (PORT_70, Index);
  35. return IoWrite8 (PORT_71, Value);
  36. }
  37. /**
  38. Calculate the new standard CMOS checksum and write it.
  39. @param Private Legacy BIOS Instance data
  40. @retval EFI_SUCCESS Calculate 16-bit checksum successfully
  41. **/
  42. EFI_STATUS
  43. LegacyCalculateWriteStandardCmosChecksum (
  44. VOID
  45. )
  46. {
  47. UINT8 Register;
  48. UINT16 Checksum;
  49. for (Checksum = 0, Register = 0x10; Register < 0x2e; Register++) {
  50. Checksum = (UINT16)(Checksum + LegacyReadStandardCmos (Register));
  51. }
  52. LegacyWriteStandardCmos (CMOS_2E, (UINT8)(Checksum >> 8));
  53. LegacyWriteStandardCmos (CMOS_2F, (UINT8)(Checksum & 0xff));
  54. return EFI_SUCCESS;
  55. }
  56. /**
  57. Fill in the standard CMOS stuff before Legacy16 load
  58. @param Private Legacy BIOS Instance data
  59. @retval EFI_SUCCESS It should always work.
  60. **/
  61. EFI_STATUS
  62. LegacyBiosInitCmos (
  63. IN LEGACY_BIOS_INSTANCE *Private
  64. )
  65. {
  66. UINT32 Size;
  67. //
  68. // Clear all errors except RTC lost power
  69. //
  70. LegacyWriteStandardCmos (CMOS_0E, (UINT8)(LegacyReadStandardCmos (CMOS_0E) & BIT7));
  71. //
  72. // Update CMOS locations 15,16,17,18,30,31 and 32
  73. // CMOS 16,15 = 640Kb = 0x280
  74. // CMOS 18,17 = 31,30 = 15Mb max in 1Kb increments =0x3C00 max
  75. // CMOS 32 = 0x20
  76. //
  77. LegacyWriteStandardCmos (CMOS_15, 0x80);
  78. LegacyWriteStandardCmos (CMOS_16, 0x02);
  79. Size = 15 * SIZE_1MB;
  80. if (Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb < (15 * SIZE_1MB)) {
  81. Size = Private->IntThunk->EfiToLegacy16InitTable.OsMemoryAbove1Mb >> 10;
  82. }
  83. LegacyWriteStandardCmos (CMOS_17, (UINT8)(Size & 0xFF));
  84. LegacyWriteStandardCmos (CMOS_30, (UINT8)(Size & 0xFF));
  85. LegacyWriteStandardCmos (CMOS_18, (UINT8)(Size >> 8));
  86. LegacyWriteStandardCmos (CMOS_31, (UINT8)(Size >> 8));
  87. LegacyCalculateWriteStandardCmosChecksum ();
  88. return EFI_SUCCESS;
  89. }