SmbiosInternal.h 7.0 KB
Newer Older
V
vit9696 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/** @file
  Copyright (C) 2016 - 2017, The HermitCrabs Lab. All rights reserved.

  All rights reserved.

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

15 16
#ifndef SMBIOS_INTERNAL_H
#define SMBIOS_INTERNAL_H
V
vit9696 已提交
17 18

#include <IndustryStandard/AppleSmBios.h>
V
vit9696 已提交
19
#include <Library/OcGuardLib.h>
20
#include <Library/OcSmbiosLib.h>
V
vit9696 已提交
21

22 23 24
//
// 2 zero bytes required in the end of each table.
//
V
vit9696 已提交
25 26
#define SMBIOS_STRUCTURE_TERMINATOR_SIZE 2

V
vit9696 已提交
27 28 29 30 31
//
// Max memory mapping slots
//
#define OC_SMBIOS_MAX_MAPPING 512

V
vit9696 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
//
// According to SMBIOS spec (3.2.0, page 26) SMBIOS handle is a number from 0 to 0xFF00.
// SMBIOS spec does not require handles to be contiguous or remain valid across SMBIOS.
// The only requirements is uniqueness and range conformance, so we reserve select handles
// for dedicated tables here for easier assignment. Automatic handle assignment starts with
// OcSmbiosAutomaticHandle.
//
enum {
  OcSmbiosInvalidHandle,
  OcSmbiosBiosInformationHandle,
  OcSmbiosSystemInformationHandle,
  OcSmbiosBaseboardInformationHandle,
  OcSmbiosSystemEnclosureHandle,
  OcSmbiosProcessorInformationHandle,
  OcSmbiosMemoryControllerInformationHandle,
  OcSmbiosMemoryModuleInformatonHandle,
  /* OcSmbiosCacheInformationHandle, */
  OcSmbiosL1CacheHandle,
  OcSmbiosL2CacheHandle,
  OcSmbiosL3CacheHandle,
  /* OcSmbiosPortConnectorInformationHandle, */
  /* OcSmbiosSystemSlotsHandle, */
  OcSmbiosOnboardDeviceInformationHandle,
  OcSmbiosOemStringsHandle,
  OcSmbiosSystemConfigurationOptionsHandle,
  OcSmbiosBiosLanguageInformationHandle,
  OcSmbiosGroupAssociationsHandle,
  OcSmbiosSystemEventLogHandle,
  OcSmbiosPhysicalMemoryArrayHandle,
  /* OcSmbiosMemoryDeviceHandle, */
  OcSmbios32BitMemoryErrorInformationHandle,
  /* OcSmbiosMemoryArrayMappedAddressHandle, */
  /* OcSmbiosMemoryDeviceMappedAddressHandle, */
  OcSmbiosBuiltInPointingDeviceHandle,
  OcSmbiosPortableBatteryHandle,
  OcSmbiosSystemResetHandle,
  OcSmbiosHardwareSecurityHandle,
  OcSmbiosSystemPowerControlsHandle,
  OcSmbiosVoltageProbeHandle,
  OcSmbiosCoolingDeviceHandle,
  OcSmbiosTemperatureProbeHandle,
  OcSmbiosElectricalCurrentProbeHandle,
  OcSmbiosOutOfBandRemoteAccessHandle,
  OcSmbiosBootIntegrityServiceHandle,
  OcSmbiosSystemBootInformationHandle,
  OcSmbios64BitMemoryErrorInformationHandle,
  OcSmbiosManagementDeviceHandle,
  OcSmbiosManagementDeviceComponentHandle,
  OcSmbiosManagementDeviceThresholdDataHandle,
  OcSmbiosMemoryChannelHandle,
  OcSmbiosIpmiDeviceInformationHandle,
  OcSmbiosSystemPowerSupplyHandle,
  OcSmbiosAdditionalInformationHandle,
  OcSmbiosOnboardDevicesExtendedInformationHandle,
  OcSmbiosManagementControllerHostInterfaceHandle,
  OcSmbiosTpmDeviceHandle,
  OcSmbiosInactiveHandle,
  OcSmbiosEndOfTableHandle,
  OcAppleSmbiosFirmwareInformationHandle,
  OcAppleSmbiosMemorySpdDataHandle,
  OcAppleSmbiosProcessorTypeHandle,
  OcAppleSmbiosProcessorBusSpeedHandle,
  OcAppleSmbiosPlatformFeatureHandle,
  OcAppleSmbiosSmcInformationHandle,

  OcSmbiosLastReservedHandle,
  OcSmbiosAutomaticHandle = 128,
};

V
vit9696 已提交
101
STATIC_ASSERT (OcSmbiosAutomaticHandle > OcSmbiosLastReservedHandle, "Inconsistent handle IDs");
V
vit9696 已提交
102

V
vit9696 已提交
103 104 105 106 107 108 109 110
//
// Map old handles to new ones.
//
typedef struct OC_SMBIOS_MAPPING_ {
  SMBIOS_HANDLE  Old;
  SMBIOS_HANDLE  New;
} OC_SMBIOS_MAPPING;

V
vit9696 已提交
111 112 113
/**
  Allocate bytes in SMBIOS table if necessary

114
  @param[in,out]   Table  Current table buffer.
115 116
  @param[in]       Size   Amount of free bytes needed.

V
vit9696 已提交
117 118 119 120 121
  @retval EFI_SUCCESS on success
**/
EFI_STATUS
SmbiosExtendTable (
  IN OUT OC_SMBIOS_TABLE  *Table,
122 123 124 125 126 127
  IN     UINT32           Size
  );

/**
  Write override string to SMBIOS table

128
  @param[in,out]   Table     Current table buffer.
129
  @param[in]       Override  String data override.
130
  @param[in,out]   Index     Pointer to current string index, incremented on success.
131 132 133 134 135 136 137

  @retval assigned string index or 0
**/
UINT8
SmbiosOverrideString (
  IN OUT  OC_SMBIOS_TABLE  *Table,
  IN      CONST CHAR8      *Override OPTIONAL,
138
  IN OUT  UINT8            *Index
V
vit9696 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  );

/**
  Initialise SMBIOS structure

  @param[in] Table             Pointer to location containing the current address within the buffer.
  @param[in] Type              Table type.
  @param[in] MinLength         Initial length of the table.
  @param[in] Index             Table index, normally 1.

  @retval
**/
EFI_STATUS
SmbiosInitialiseStruct (
  IN OUT OC_SMBIOS_TABLE  *Table,
V
vit9696 已提交
154 155
  IN     SMBIOS_TYPE      Type,
  IN     UINT8            MinLength,
V
vit9696 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169
  IN     UINT16           Index
  );

/**
  Finalise SMBIOS structure

  @param[in] Table                  Pointer to location containing the current address within the buffer.

  @retval
**/
VOID
SmbiosFinaliseStruct (
  IN OUT OC_SMBIOS_TABLE  *Table
  );
V
vit9696 已提交
170

171

V
vit9696 已提交
172
/**
173 174 175 176
  Obtain string from previously validated structure.

  @param[in] SmbiosTable
  @param[in] StringIndex  String Index to retrieve
V
vit9696 已提交
177 178 179 180 181 182

  @retval
**/
CHAR8 *
SmbiosGetString (
  IN APPLE_SMBIOS_STRUCTURE_POINTER  SmbiosTable,
183
  IN SMBIOS_TABLE_STRING             StringIndex
V
vit9696 已提交
184 185 186
  );

/**
187
  Write string to SMBIOS structure
V
vit9696 已提交
188

189
  @param[in,out]  Buffer        Pointer to location containing the current address within the buffer.
190 191
  @param[in]      String        Buffer containing the null terminated ascii string.
  @param[in]      Length        String length to write.
192
  @param[in,out]  Index         Pointer to current string index, incremented on success.
V
vit9696 已提交
193

194
  @retval assigned string index or 0
V
vit9696 已提交
195 196 197
**/
UINT8
SmbiosSetString (
198 199 200 201
  IN OUT  CHAR8        **Buffer,
  IN      CONST CHAR8  *String,
  IN      UINT32       Length,
  IN OUT  UINT8        *Index
V
vit9696 已提交
202 203 204
  );

/**
205
  Obtain and validate structure length.
V
vit9696 已提交
206

207 208
  @param[in] SmbiosTable
  @param[in] SmbiosTableSize  SMBIOS table size
V
vit9696 已提交
209

210
  @retval table length or 0 for invalid
V
vit9696 已提交
211 212
**/
UINT32
213 214 215
SmbiosGetStructureLength (
  IN  APPLE_SMBIOS_STRUCTURE_POINTER  SmbiosTable,
  IN  UINT32                          SmbiosTableSize
V
vit9696 已提交
216 217
  );

V
vit9696 已提交
218
/**
219
  Obtain and validate Nth structure of specified type.
V
vit9696 已提交
220

221 222 223 224 225 226
  @param[in] SmbiosTable      Pointer to SMBIOS table.
  @param[in] SmbiosTableSize  SMBIOS table size
  @param[in] Type             SMBIOS table type
  @param[in] Index            SMBIOS table index starting from 1

  @retval found table or NULL
V
vit9696 已提交
227 228
**/
APPLE_SMBIOS_STRUCTURE_POINTER
229
SmbiosGetStructureOfType (
V
vit9696 已提交
230 231 232 233
  IN  APPLE_SMBIOS_STRUCTURE_POINTER  SmbiosTable,
  IN  UINT32                          SmbiosTableSize,
  IN  SMBIOS_TYPE                     Type,
  IN  UINT16                          Index
V
vit9696 已提交
234 235 236
  );

/**
237
  Obtain structure count of specified type.
V
vit9696 已提交
238

239 240
  @param[in] SmbiosTable      Pointer to SMBIOS table.
  @param[in] SmbiosTableSize  SMBIOS table size
V
vit9696 已提交
241

242
  @retval structure count or 0
V
vit9696 已提交
243
**/
V
vit9696 已提交
244
UINT16
245
SmbiosGetStructureCount (
V
vit9696 已提交
246 247 248
  IN  APPLE_SMBIOS_STRUCTURE_POINTER  SmbiosTable,
  IN  UINT32                          SmbiosTableSize,
  IN  SMBIOS_TYPE                     Type
V
vit9696 已提交
249 250
  );

251
#endif // SMBIOS_INTERNAL_H