hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/** @file
  BIOS system slot designator information boot time changes.
  SMBIOS type 9.
 
  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
  Copyright (c) 2016, Hisilicon Limited. All rights reserved.<BR>
  Copyright (c) 2016, Linaro Limited. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
 
**/
 
#include "SmbiosMisc.h"
 
#include <Library/OemMiscLib.h>
 
extern SMBIOS_TABLE_TYPE9 MiscSystemSlotDesignationPcie0Data;
extern SMBIOS_TABLE_TYPE9 MiscSystemSlotDesignationPcie1Data;
extern SMBIOS_TABLE_TYPE9 MiscSystemSlotDesignationPcie2Data;
extern SMBIOS_TABLE_TYPE9 MiscSystemSlotDesignationPcie3Data;
 
VOID
UpdateSlotDesignation (
  IN SMBIOS_TABLE_TYPE9 *InputData
  )
{
    EFI_STRING_ID                   TokenToUpdate;
    CHAR16                          *SlotDesignation;
    UINTN                           DesignationStrLen;
 
    SlotDesignation = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
    if (NULL == SlotDesignation)
    {
        return;
    }
 
    if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie0Data)
    {
        UnicodeSPrint(SlotDesignation, SMBIOS_STRING_MAX_LENGTH - 1, L"PCIE0");
    }
    else if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie1Data)
    {
        UnicodeSPrint(SlotDesignation, SMBIOS_STRING_MAX_LENGTH - 1, L"PCIE1");
    }
    else if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie2Data)
    {
        UnicodeSPrint(SlotDesignation, SMBIOS_STRING_MAX_LENGTH - 1, L"PCIE2");
    }
    else if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie3Data)
    {
        UnicodeSPrint(SlotDesignation, SMBIOS_STRING_MAX_LENGTH - 1, L"PCIE3");
    }
 
    DesignationStrLen = StrLen (SlotDesignation);
 
    if (DesignationStrLen > 0 )
    {
        TokenToUpdate = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_DESIGNATION);
        HiiSetString (mHiiHandle, TokenToUpdate, SlotDesignation, NULL);
    }
 
    FreePool (SlotDesignation);
}
 
VOID
UpdateSlotUsage(
  IN OUT SMBIOS_TABLE_TYPE9 *InputData
  )
{
    EFI_STATUS        Status;
    SERDES_PARAM    SerdesParamA;
    SERDES_PARAM    SerdesParamB;
 
    Status = OemGetSerdesParam (&SerdesParamA, &SerdesParamB, 0);
    if(EFI_ERROR(Status))
    {
        DEBUG((EFI_D_ERROR, "[%a]:[%dL] OemGetSerdesParam failed %r\n", __FUNCTION__, __LINE__, Status));
        return;
    }
 
    //
    // PCIE0
    //
    if (((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie0Data)
        && SerdesParamA.Hilink1Mode == EmHilink1Pcie0X8) {
        InputData->CurrentUsage = SlotUsageAvailable;
    }
 
    //
    // PCIE1
    //
    if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie1Data)
    {
        if (SerdesParamA.Hilink0Mode == EmHilink0Pcie1X4Pcie2X4) {
            InputData->SlotDataBusWidth = SlotDataBusWidth4X;
        }
    }
 
    //
    // PCIE2
    //
    if ((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie2Data)
    {
        if (SerdesParamA.Hilink0Mode == EmHilink0Pcie1X4Pcie2X4) {
            InputData->SlotDataBusWidth = SlotDataBusWidth4X;
            InputData->CurrentUsage = SlotUsageAvailable;
        } else if (SerdesParamA.Hilink2Mode == EmHilink2Pcie2X8) {
            InputData->CurrentUsage = SlotUsageAvailable;
        }
    }
 
    //
    // PCIE3
    //
    if (((UINTN)InputData == (UINTN)&MiscSystemSlotDesignationPcie3Data)
        && SerdesParamA.Hilink5Mode == EmHilink5Pcie3X4) {
        InputData->CurrentUsage = SlotUsageAvailable;
    }
}
 
/**
  This function makes boot time changes to the contents of the
  MiscSystemSlotDesignator structure (Type 9).
 
  @param  RecordData                 Pointer to copy of RecordData from the Data Table.
 
  @retval EFI_SUCCESS                All parameters were valid.
  @retval EFI_UNSUPPORTED            Unexpected RecordType value.
  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
 
**/
MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)
{
    CHAR8                              *OptionalStrStart;
    UINTN                              SlotDesignationStrLen;
    EFI_STATUS                         Status;
    EFI_STRING                         SlotDesignation;
    EFI_STRING_ID                      TokenToGet;
    SMBIOS_TABLE_TYPE9                 *SmbiosRecord;
    EFI_SMBIOS_HANDLE                  SmbiosHandle;
    SMBIOS_TABLE_TYPE9                 *InputData = NULL;
 
    //
    // First check for invalid parameters.
    //
    if (RecordData == NULL)
    {
        return EFI_INVALID_PARAMETER;
    }
 
    InputData = (SMBIOS_TABLE_TYPE9 *)RecordData;
 
    UpdateSlotUsage (InputData);
 
    UpdateSlotDesignation (InputData);
 
    TokenToGet   = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_DESIGNATION);
    SlotDesignation = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
    SlotDesignationStrLen = StrLen(SlotDesignation);
 
    //
    // Two zeros following the last string.
    //
    SmbiosRecord = AllocateZeroPool(sizeof (SMBIOS_TABLE_TYPE9) + SlotDesignationStrLen + 1 + 1);
    if(NULL == SmbiosRecord)
    {
        Status = EFI_OUT_OF_RESOURCES;
        goto Exit;
    }
 
    (VOID)CopyMem(SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE9));
 
    SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);
 
    OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
    Status = UnicodeStrToAsciiStrS (SlotDesignation, OptionalStrStart, SlotDesignationStrLen + 1);
    ASSERT_EFI_ERROR (Status);
    //
    // Now we have got the full smbios record, call smbios protocol to add this record.
    //
 
    Status = LogSmbiosData( (UINT8*)SmbiosRecord, &SmbiosHandle);
    if(EFI_ERROR(Status))
    {
      DEBUG((EFI_D_ERROR, "[%a]:[%dL] Smbios Type09 Table Log Failed! %r \n", __FUNCTION__, __LINE__, Status));
    }
 
    FreePool(SmbiosRecord);
 
Exit:
    if(SlotDesignation != NULL)
    {
      FreePool(SlotDesignation);
    }
 
    return Status;
}