1 /** @file 2 3 Copyright (c) 2004 - 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 MiscPortInternalConnectorDesignatorFunction.c 27 28 Abstract: 29 30 Create the device path for the Port internal connector designator. 31 Port internal connector designator information is Misc. subclass type 6 32 and SMBIOS type 8. 33 34 35 **/ 36 37 38 #include "CommonHeader.h" 39 40 #include "MiscSubclassDriver.h" 41 42 43 /** 44 This is a macro defined function, in fact, the function is 45 MiscPortInternalConnectorDesignatorFunction (RecordType, RecordLen, RecordData, LogRecordData) 46 This function makes boot time changes to the contents of the 47 MiscPortConnectorInformation. 48 49 @param MiscPortInternalConnectorDesignator The string which is used to create 50 the function 51 The Arguments in fact: 52 @param RecordType Type of record to be processed from 53 the Data Table. 54 mMiscSubclassDataTable[].RecordType 55 @param RecordLen Size of static RecordData from the 56 Data Table. 57 mMiscSubclassDataTable[].RecordLen 58 @param RecordData Pointer to RecordData, which will be 59 written to the Data Hub 60 @param LogRecordData TRUE to log RecordData to Data Hub. 61 FALSE when there is no more data to 62 log. 63 MISC_SMBIOS_TABLE_FUNCTION(MiscPortInternalConnectorDesignator)64 @retval EFI_SUCCESS *RecordData and *LogRecordData have 65 been set. 66 @retval EFI_UNSUPPORTED Unexpected RecordType value. 67 @retval EFI_INVALID_PARAMETER One of the following parameter 68 conditions was true: RecordLen was 69 zero. RecordData was NULL. 70 LogRecordData was NULL. 71 72 **/ 73 MISC_SMBIOS_TABLE_FUNCTION ( 74 MiscPortInternalConnectorDesignator 75 ) 76 { 77 CHAR8 *OptionalStrStart; 78 UINTN InternalRefStrLen; 79 UINTN ExternalRefStrLen; 80 EFI_STRING InternalRef; 81 EFI_STRING ExternalRef; 82 STRING_REF TokenForInternal; 83 STRING_REF TokenForExternal; 84 EFI_STATUS Status; 85 SMBIOS_TABLE_TYPE8 *SmbiosRecord; 86 EFI_SMBIOS_HANDLE SmbiosHandle; 87 EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *ForType8InputData; 88 89 ForType8InputData = (EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR *)RecordData; 90 91 // 92 // First check for invalid parameters. 93 // 94 if (RecordData == NULL) { 95 return EFI_INVALID_PARAMETER; 96 } 97 98 TokenForInternal = 0; 99 TokenForExternal = 0; 100 101 switch (ForType8InputData->PortInternalConnectorDesignator) { 102 103 case STR_MISC_PORT_INTERNAL_IDE1: 104 TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_IDE1); 105 TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_IDE1); 106 break; 107 case STR_MISC_PORT_INTERNAL_IDE2: 108 TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_IDE2); 109 TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_IDE2); 110 break; 111 case STR_MISC_PORT_INTERNAL_ATX_POWER: 112 TokenForInternal = STRING_TOKEN (STR_MISC_PORT_INTERNAL_ATX_POWER); 113 TokenForExternal = STRING_TOKEN(STR_MISC_PORT_EXTERNAL_ATX_POWER); 114 break; 115 default: 116 break; 117 } 118 119 InternalRef = SmbiosMiscGetString (TokenForInternal); 120 InternalRefStrLen = StrLen(InternalRef); 121 if (InternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) { 122 return EFI_UNSUPPORTED; 123 } 124 125 ExternalRef = SmbiosMiscGetString (TokenForExternal); 126 ExternalRefStrLen = StrLen(ExternalRef); 127 if (ExternalRefStrLen > SMBIOS_STRING_MAX_LENGTH) { 128 return EFI_UNSUPPORTED; 129 } 130 131 // 132 // Two zeros following the last string. 133 // 134 SmbiosRecord = AllocatePool(sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1); 135 ZeroMem(SmbiosRecord, sizeof (SMBIOS_TABLE_TYPE8) + InternalRefStrLen + 1 + ExternalRefStrLen + 1 + 1); 136 137 SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PORT_CONNECTOR_INFORMATION; 138 SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE8); 139 140 // 141 // Make handle chosen by smbios protocol.add automatically. 142 // 143 SmbiosRecord->Hdr.Handle = 0; 144 SmbiosRecord->InternalReferenceDesignator = 1; 145 SmbiosRecord->InternalConnectorType = (UINT8)ForType8InputData->PortInternalConnectorType; 146 SmbiosRecord->ExternalReferenceDesignator = 2; 147 SmbiosRecord->ExternalConnectorType = (UINT8)ForType8InputData->PortExternalConnectorType; 148 SmbiosRecord->PortType = (UINT8)ForType8InputData->PortType; 149 150 OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1); 151 UnicodeStrToAsciiStr(InternalRef, OptionalStrStart); 152 UnicodeStrToAsciiStr(ExternalRef, OptionalStrStart + InternalRefStrLen + 1); 153 154 // 155 // Now we have got the full smbios record, call smbios protocol to add this record. 156 // 157 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; 158 Status = Smbios-> Add( 159 Smbios, 160 NULL, 161 &SmbiosHandle, 162 (EFI_SMBIOS_TABLE_HEADER *) SmbiosRecord 163 ); 164 FreePool(SmbiosRecord); 165 return Status; 166 } 167