1 /** @file
2 Onboard device information boot time changes.
3 SMBIOS type 10.
4 
5 Copyright (c) 2013-2015 Intel Corporation.
6 
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 
16 **/
17 
18 
19 #include "CommonHeader.h"
20 
21 #include "SmbiosMisc.h"
22 
23 
24 /**
25   This function makes boot time changes to the contents of the
26   MiscOnboardDevice (Type 10).
27 
28   @param  RecordData                 Pointer to copy of RecordData from the Data Table.
29 
30   @retval EFI_SUCCESS                All parameters were valid.
31   @retval EFI_UNSUPPORTED            Unexpected RecordType value.
32   @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
33 
34 **/
MISC_SMBIOS_TABLE_FUNCTION(MiscOnboardDevice)35 MISC_SMBIOS_TABLE_FUNCTION(MiscOnboardDevice)
36 {
37   CHAR8                         *OptionalStrStart;
38   UINT8                         StatusAndType;
39   UINTN                         DescriptionStrLen;
40   EFI_STRING                    DeviceDescription;
41   STRING_REF                    TokenToGet;
42   EFI_STATUS                    Status;
43   EFI_SMBIOS_HANDLE             SmbiosHandle;
44   SMBIOS_TABLE_TYPE10           *SmbiosRecord;
45   EFI_MISC_ONBOARD_DEVICE       *ForType10InputData;
46 
47   ForType10InputData = (EFI_MISC_ONBOARD_DEVICE *)RecordData;
48   //
49   // First check for invalid parameters.
50   //
51   if (RecordData == NULL) {
52     return EFI_INVALID_PARAMETER;
53   }
54 
55   TokenToGet = 0;
56   switch (ForType10InputData->OnBoardDeviceDescription) {
57     case STR_MISC_ONBOARD_DEVICE_VIDEO:
58       TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_VIDEO);
59       break;
60     case STR_MISC_ONBOARD_DEVICE_AUDIO:
61       TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_AUDIO);
62       break;
63   }
64 
65   DeviceDescription = HiiGetPackageString(&gEfiCallerIdGuid, TokenToGet, NULL);
66   DescriptionStrLen = StrLen(DeviceDescription);
67   if (DescriptionStrLen > SMBIOS_STRING_MAX_LENGTH) {
68     return EFI_UNSUPPORTED;
69   }
70 
71   //
72   // Two zeros following the last string.
73   //
74   SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1);
75   ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1);
76 
77   SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_ONBOARD_DEVICE_INFORMATION;
78   SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE10);
79   //
80   // Make handle chosen by smbios protocol.add automatically.
81   //
82   SmbiosRecord->Hdr.Handle = 0;
83 
84   //
85   // Status & Type: Bit 7 Devicen Status, Bits 6:0 Type of Device
86   //
87   StatusAndType = (UINT8) ForType10InputData->OnBoardDeviceStatus.DeviceType;
88   if (ForType10InputData->OnBoardDeviceStatus.DeviceEnabled != 0) {
89     StatusAndType |= 0x80;
90   } else {
91     StatusAndType &= 0x7F;
92   }
93 
94   SmbiosRecord->Device[0].DeviceType = StatusAndType;
95   SmbiosRecord->Device[0].DescriptionString = 1;
96   OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
97   UnicodeStrToAsciiStr(DeviceDescription, OptionalStrStart);
98 
99   //
100   // Now we have got the full smbios record, call smbios protocol to add this record.
101   //
102   SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
103   Status = Smbios-> Add(
104                       Smbios,
105                       NULL,
106                       &SmbiosHandle,
107                       (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord
108                       );
109   FreePool(SmbiosRecord);
110   return Status;
111 }
112