1 /** @file 2 3 Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved.<BR> 4 5 This program and the accompanying materials are licensed and made available under 7 the terms and conditions of the BSD License that accompanies this distribution. 9 The full text of the license may be found at 11 http://opensource.org/licenses/bsd-license.php. 13 15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 19 21 23 24 Module Name: 25 26 MiscOnboardDeviceFunction.c 27 28 Abstract: 29 30 Create the device path for the Onboard device. 31 The Onboard device information is Misc. subclass type 8 and SMBIOS type 10. 32 33 34 **/ 35 36 37 #include "CommonHeader.h" 38 39 #include "MiscSubclassDriver.h" 40 41 42 43 /** 44 This is a macro defined function, in fact, the function is 45 MiscOnboardDeviceFunction (RecordType, RecordLen, RecordData, LogRecordData) 46 This function makes boot time changes to the contents of the 47 MiscOnboardDevice structure. 48 49 @param MiscOnboardDevice The string which is used to create the function 50 The Arguments in fact: 51 @param RecordType Type of record to be processed from the Data 52 Table. mMiscSubclassDataTable[].RecordType 53 @param RecordLen Size of static RecordData from the Data Table. 54 mMiscSubclassDataTable[].RecordLen 55 @param RecordData Pointer to RecordData, which will be written to 56 the Data Hub 57 @param LogRecordData TRUE to log RecordData to Data Hub. FALSE when 58 there is no more data to log. 59 60 @retval EFI_SUCCESS *RecordData and *LogRecordData have been set. 61 @retval EFI_UNSUPPORTED Unexpected RecordType value. 62 @retval EFI_INVALID_PARAMETER One of the following parameter conditions was 63 true: RecordLen was zero. RecordData was NULL. 64 LogRecordData was NULL. 65 66 **/ 67 MISC_SMBIOS_TABLE_FUNCTION ( 68 MiscOnboardDevice 69 ) 70 { 71 CHAR8 *OptionalStrStart; 72 UINT8 StatusAndType; 73 UINTN DescriptionStrLen; 74 EFI_STRING DeviceDescription; 75 STRING_REF TokenToGet; 76 EFI_STATUS Status; 77 EFI_SMBIOS_HANDLE SmbiosHandle; 78 SMBIOS_TABLE_TYPE10 *SmbiosRecord; 79 EFI_MISC_ONBOARD_DEVICE *ForType10InputData; 80 81 ForType10InputData = (EFI_MISC_ONBOARD_DEVICE *)RecordData; 82 83 // 84 // First check for invalid parameters. 85 // 86 if (RecordData == NULL) { 87 return EFI_INVALID_PARAMETER; 88 } 89 90 TokenToGet = 0; 91 switch (ForType10InputData->OnBoardDeviceDescription) { 92 case STR_MISC_ONBOARD_DEVICE_VIDEO: 93 TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_VIDEO); 94 break; 95 case STR_MISC_ONBOARD_DEVICE_AUDIO: 96 TokenToGet = STRING_TOKEN (STR_MISC_ONBOARD_DEVICE_AUDIO); 97 break; 98 default: 99 break; 100 } 101 102 DeviceDescription = SmbiosMiscGetString (TokenToGet); 103 DescriptionStrLen = StrLen(DeviceDescription); 104 if (DescriptionStrLen > SMBIOS_STRING_MAX_LENGTH) { 105 return EFI_UNSUPPORTED; 106 } 107 108 // 109 // Two zeros following the last string. 110 // 111 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1); 112 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE10) + DescriptionStrLen + 1 + 1); 113 114 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_ONBOARD_DEVICE_INFORMATION; 115 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE10); 116 117 // 118 // Make handle chosen by smbios protocol.add automatically. 119 // 120 SmbiosRecord->Hdr.Handle = 0; 121 122 // 123 // Status & Type: Bit 7 Devicen Status, Bits 6:0 Type of Device 124 // 125 StatusAndType = (UINT8) ForType10InputData->OnBoardDeviceStatus.DeviceType; 126 if (ForType10InputData->OnBoardDeviceStatus.DeviceEnabled != 0) { 127 StatusAndType |= 0x80; 128 } else { 129 StatusAndType &= 0x7F; 130 } 131 132 SmbiosRecord->Device[0].DeviceType = StatusAndType; 133 SmbiosRecord->Device[0].DescriptionString = 1; 134 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1); 135 UnicodeStrToAsciiStr(DeviceDescription, OptionalStrStart); 136 137 // 138 // Now we have got the full smbios record, call smbios protocol to add this record. 139 // 140 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; 141 Status = Smbios-> Add( 142 Smbios, 143 NULL, 144 &SmbiosHandle, 145 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord 146 ); 147 FreePool(SmbiosRecord); 148 return Status; 149 } 150