SmbiosPlatformDxe.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** @file
  2. This driver installs SMBIOS information for QSP
  3. Copyright (c) 2011, Bei Guan <gbtju85@gmail.com>
  4. Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "SmbiosPlatformDxe.h"
  8. /**
  9. Reads 8-bits of CMOS data.
  10. Reads the 8-bits of CMOS data at the location specified by Index.
  11. The 8-bit read value is returned.
  12. @param Index The CMOS location to read.
  13. @return The value read.
  14. **/
  15. UINT8
  16. EFIAPI
  17. CmosRead8(
  18. IN UINTN Index
  19. )
  20. {
  21. IoWrite8(0x70, (UINT8)Index);
  22. return IoRead8(0x71);
  23. }
  24. UINT32
  25. GetSystemMemorySizeBelow4gb(
  26. VOID
  27. )
  28. {
  29. UINT8 Cmos0x34;
  30. UINT8 Cmos0x35;
  31. //
  32. // CMOS 0x34/0x35 specifies the system memory above 16 MB.
  33. // * CMOS(0x35) is the high byte
  34. // * CMOS(0x34) is the low byte
  35. // * The size is specified in 64kb chunks
  36. // * Since this is memory above 16MB, the 16MB must be added
  37. // into the calculation to get the total memory size.
  38. //
  39. Cmos0x34 = (UINT8)CmosRead8(0x34);
  40. Cmos0x35 = (UINT8)CmosRead8(0x35);
  41. return (UINT32)(((UINTN)((Cmos0x35 << 8) + Cmos0x34) << 16) + SIZE_16MB);
  42. }
  43. STATIC
  44. UINT64
  45. GetSystemMemorySizeAbove4gb(
  46. VOID
  47. )
  48. {
  49. UINT32 Size;
  50. UINTN CmosIndex;
  51. //
  52. // CMOS 0x5b-0x5d specifies the system memory above 4GB MB.
  53. // * CMOS(0x5d) is the most significant size byte
  54. // * CMOS(0x5c) is the middle size byte
  55. // * CMOS(0x5b) is the least significant size byte
  56. // * The size is specified in 64kb chunks
  57. //
  58. Size = 0;
  59. for (CmosIndex = 0x5d; CmosIndex >= 0x5b; CmosIndex--) {
  60. Size = (UINT32)(Size << 8) + (UINT32)CmosRead8(CmosIndex);
  61. }
  62. return LShiftU64(Size, 16);
  63. }
  64. /**
  65. Installs SMBIOS information for SIMICS QSP
  66. @param ImageHandle Module's image handle
  67. @param SystemTable Pointer of EFI_SYSTEM_TABLE
  68. @retval EFI_SUCCESS Smbios data successfully installed
  69. @retval Other Smbios data was not installed
  70. **/
  71. EFI_STATUS
  72. EFIAPI
  73. SmbiosTablePublishEntry (
  74. IN EFI_HANDLE ImageHandle,
  75. IN EFI_SYSTEM_TABLE *SystemTable
  76. )
  77. {
  78. EFI_STATUS Status;
  79. EFI_SMBIOS_PROTOCOL *Smbios;
  80. SMBIOS_TABLE_TYPE19 *Type19Record;
  81. EFI_SMBIOS_HANDLE MemArrayMappedAddrSmbiosHandle;
  82. UINT8 NumSlots;
  83. UINT64 TotalMemorySize;
  84. //
  85. // Find the SMBIOS protocol
  86. //
  87. Status = gBS->LocateProtocol (
  88. &gEfiSmbiosProtocolGuid,
  89. NULL,
  90. (VOID**)&Smbios
  91. );
  92. if (EFI_ERROR (Status)) {
  93. return Status;
  94. }
  95. //
  96. // Generate Memory Array Mapped Address info
  97. //
  98. NumSlots = 2;
  99. TotalMemorySize = 0;
  100. TotalMemorySize = GetSystemMemorySizeBelow4gb();
  101. Type19Record = AllocatePool(sizeof(SMBIOS_TABLE_TYPE19));
  102. ZeroMem(Type19Record, sizeof(SMBIOS_TABLE_TYPE19));
  103. Type19Record->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS;
  104. Type19Record->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE19);
  105. Type19Record->Hdr.Handle = 0;
  106. Type19Record->StartingAddress = 0;
  107. Type19Record->EndingAddress = (UINT32)RShiftU64(TotalMemorySize, 10) - 1;
  108. Type19Record->MemoryArrayHandle = SMBIOS_HANDLE_PI_RESERVED;
  109. Type19Record->PartitionWidth = (UINT8)(NumSlots);
  110. MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  111. Status = Smbios->Add(Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*)Type19Record);
  112. ASSERT_EFI_ERROR(Status);
  113. TotalMemorySize = GetSystemMemorySizeAbove4gb();
  114. Type19Record->StartingAddress = 0xFFFFFFFF;
  115. Type19Record->ExtendedStartingAddress = 0xFFFFFFFF;
  116. Type19Record->ExtendedEndingAddress = TotalMemorySize + 0xFFFFFFFF - 1;
  117. MemArrayMappedAddrSmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
  118. Status = Smbios->Add(Smbios, NULL, &MemArrayMappedAddrSmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*)Type19Record);
  119. FreePool(Type19Record);
  120. ASSERT_EFI_ERROR(Status);
  121. return Status;
  122. }