1 /*++
2 
3 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
4 
5 
6   This program and the accompanying materials are licensed and made available under
7 
8   the terms and conditions of the BSD License that accompanies this distribution.
9 
10   The full text of the license may be found at
11 
12   http://opensource.org/licenses/bsd-license.php.
13 
14 
15 
16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 
18   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 
20 
21 
22 
23 
24 Module Name:
25 
26   MiscSystemSlotDesignatorFunction.c
27 
28 Abstract:
29 
30   BIOS system slot designator information boot time changes.
31   SMBIOS type 9.
32 
33 --*/
34 
35 #include "MiscSubclassDriver.h"
36 
37 /**
38   This function makes boot time changes to the contents of the
MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)39   MiscSystemSlotDesignator structure (Type 9).
40 
41   @param  RecordData                 Pointer to copy of RecordData from the Data Table.
42 
43   @retval EFI_SUCCESS                All parameters were valid.
44   @retval EFI_UNSUPPORTED            Unexpected RecordType value.
45   @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
46 
47 **/
48 MISC_SMBIOS_TABLE_FUNCTION(MiscSystemSlotDesignation)
49 {
50   CHAR8                              *OptionalStrStart;
51   UINTN                              SlotDesignationStrLen;
52   EFI_STATUS                         Status;
53   EFI_STRING                         SlotDesignation;
54   STRING_REF                         TokenToGet;
55   SMBIOS_TABLE_TYPE9                 *SmbiosRecord;
56   EFI_SMBIOS_HANDLE                  SmbiosHandle;
57   EFI_MISC_SYSTEM_SLOT_DESIGNATION*  ForType9InputData;
58 
59   ForType9InputData = (EFI_MISC_SYSTEM_SLOT_DESIGNATION *)RecordData;
60 
61   //
62   // First check for invalid parameters.
63   //
64   if (RecordData == NULL) {
65     return EFI_INVALID_PARAMETER;
66   }
67 
68   TokenToGet = 0;
69   switch (ForType9InputData->SlotDesignation) {
70     case STR_MISC_SYSTEM_SLOT_PCIEX16_1:
71       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX16_1);
72       break;
73     case STR_MISC_SYSTEM_SLOT_PCIEX16_2:
74       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX16_2);
75       break;
76     case STR_MISC_SYSTEM_SLOT_PCIEX4:
77       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX4);
78       break;
79     case STR_MISC_SYSTEM_SLOT_PCIEX1_1:
80       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_1);
81       break;
82     case STR_MISC_SYSTEM_SLOT_PCIEX1_2:
83       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_2);
84       break;
85     case STR_MISC_SYSTEM_SLOT_PCIEX1_3:
86       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCIEX1_3);
87       break;
88     case STR_MISC_SYSTEM_SLOT_PCI1:
89       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI1);
90       break;
91     case STR_MISC_SYSTEM_SLOT_PCI2:
92       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI2);
93       break;
94     case STR_MISC_SYSTEM_SLOT_PCI3:
95       TokenToGet = STRING_TOKEN (STR_MISC_SYSTEM_SLOT_PCI3);
96       break;
97     default:
98       break;
99   }
100 
101   SlotDesignation = SmbiosMiscGetString (TokenToGet);
102   SlotDesignationStrLen = StrLen(SlotDesignation);
103   if (SlotDesignationStrLen > SMBIOS_STRING_MAX_LENGTH) {
104     return EFI_UNSUPPORTED;
105   }
106 
107   //
108   // Two zeros following the last string.
109   //
110   SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE9) + SlotDesignationStrLen + 1 + 1);
111   ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE9) +SlotDesignationStrLen + 1 + 1);
112 
113   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_SYSTEM_SLOTS;
114   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9);
115   SmbiosRecord->Hdr.Handle = 0;
116   SmbiosRecord->SlotDesignation = 1;
117   SmbiosRecord->SlotType = (UINT8)ForType9InputData->SlotType;
118   SmbiosRecord->SlotDataBusWidth = (UINT8)ForType9InputData->SlotDataBusWidth;
119   SmbiosRecord->CurrentUsage = (UINT8)ForType9InputData->SlotUsage;
120   SmbiosRecord->SlotLength = (UINT8)ForType9InputData->SlotLength;
121   SmbiosRecord->SlotID = ForType9InputData->SlotId;
122 
123   //
124   // Slot Characteristics
125   //
126   CopyMem ((UINT8 *) &SmbiosRecord->SlotCharacteristics1,(UINT8 *) &ForType9InputData->SlotCharacteristics,2);
127   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
128   UnicodeStrToAsciiStr(SlotDesignation, OptionalStrStart);
129   //
130   // Now we have got the full smbios record, call smbios protocol to add this record.
131   //
132   SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
133   Status = Smbios-> Add(
134                       Smbios,
135                       NULL,
136                       &SmbiosHandle,
137                       (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
138                       );
139   FreePool(SmbiosRecord);
140   return Status;
141 }
142