Changeset 58189 in vbox for trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
- Timestamp:
- Oct 12, 2015 2:02:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
r48674 r58189 18 18 19 19 EFI_EVENT mVirtualAddressChangeEvent = NULL; 20 21 #ifdef VBOX 22 # include <Library/PrintLib.h> 23 # include <Library/TimerLib.h> 24 # include "VBoxPkg.h" 25 # include "DevEFI.h" 26 # include "iprt/asm.h" 27 28 29 static UINT32 VBoxReadNVRAM(UINT8 *pu8Buffer, UINT32 cbBuffer) 30 { 31 UINT32 idxBuffer = 0; 32 for (idxBuffer = 0; idxBuffer < cbBuffer; ++idxBuffer) 33 pu8Buffer[idxBuffer] = ASMInU8(EFI_PORT_VARIABLE_OP); 34 return idxBuffer; 35 } 36 37 DECLINLINE(void) VBoxWriteNVRAMU32Param(UINT32 u32CodeParam, UINT32 u32Param) 38 { 39 ASMOutU32(EFI_PORT_VARIABLE_OP, u32CodeParam); 40 ASMOutU32(EFI_PORT_VARIABLE_PARAM, u32Param); 41 } 42 43 static UINT32 VBoxWriteNVRAMByteArrayParam(const UINT8 *pbParam, UINT32 cbParam) 44 { 45 UINT32 idxParam = 0; 46 for (idxParam = 0; idxParam < cbParam; ++idxParam) 47 ASMOutU8(EFI_PORT_VARIABLE_PARAM, pbParam[idxParam]); 48 return idxParam; 49 } 50 51 static void VBoxWriteNVRAMNameParam(const CHAR16 *pwszName) 52 { 53 UINTN i; 54 UINTN cwcName = StrLen(pwszName); 55 56 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_NAME_UTF16); 57 for (i = 0; i <= cwcName; i++) 58 ASMOutU16(EFI_PORT_VARIABLE_PARAM, pwszName[i]); 59 } 60 61 DECLINLINE(UINT32) VBoxWriteNVRAMGuidParam(const EFI_GUID *pGuid) 62 { 63 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_GUID); 64 return VBoxWriteNVRAMByteArrayParam((UINT8 *)pGuid, sizeof(EFI_GUID)); 65 } 66 67 static UINT32 VBoxWriteNVRAMDoOp(UINT32 u32Operation) 68 { 69 UINT32 u32Rc; 70 VBoxLogFlowFuncEnter(); 71 VBoxLogFlowFuncMarkVar(u32Operation, "%x"); 72 VBoxWriteNVRAMU32Param(EFI_VM_VARIABLE_OP_START, u32Operation); 73 74 while ((u32Rc = ASMInU32(EFI_PORT_VARIABLE_OP)) == EFI_VARIABLE_OP_STATUS_BSY) 75 { 76 #if 0 77 MicroSecondDelay (400); 78 #endif 79 /* @todo: sleep here. bird: won't ever happen, so don't bother. */ 80 } 81 VBoxLogFlowFuncMarkVar(u32Rc, "%x"); 82 VBoxLogFlowFuncLeave(); 83 return u32Rc; 84 } 85 #endif 20 86 21 87 /** … … 46 112 ) 47 113 { 114 #ifndef VBOX 48 115 return EmuGetVariable ( 49 116 VariableName, … … 54 121 &mVariableModuleGlobal->VariableGlobal[Physical] 55 122 ); 123 #else 124 EFI_STATUS rc; 125 UINT32 u32Rc; 126 127 VBoxLogFlowFuncEnter(); 128 129 /* 130 * Tell DevEFI to look for the specified variable. 131 */ 132 VBoxWriteNVRAMGuidParam(VendorGuid); 133 VBoxWriteNVRAMNameParam(VariableName); 134 u32Rc = VBoxWriteNVRAMDoOp(EFI_VARIABLE_OP_QUERY); 135 if (u32Rc == EFI_VARIABLE_OP_STATUS_OK) 136 { 137 /* 138 * Check if we got enought space for the value. 139 */ 140 UINT32 VarLen; 141 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_VALUE_LENGTH); 142 VarLen = ASMInU32(EFI_PORT_VARIABLE_OP); 143 VBoxLogFlowFuncMarkVar(*DataSize, "%d"); 144 VBoxLogFlowFuncMarkVar(VarLen, "%d"); 145 if ( VarLen <= *DataSize 146 && Data) 147 { 148 /* 149 * We do, then read it and, if requrest, the attribute. 150 */ 151 *DataSize = VarLen; 152 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_VALUE); 153 VBoxReadNVRAM((UINT8 *)Data, VarLen); 154 155 if (Attributes) 156 { 157 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_ATTRIBUTE); 158 *Attributes = ASMInU32(EFI_PORT_VARIABLE_OP); 159 VBoxLogFlowFuncMarkVar(Attributes, "%x"); 160 } 161 162 rc = EFI_SUCCESS; 163 } 164 else 165 { 166 *DataSize = VarLen; 167 rc = EFI_BUFFER_TOO_SMALL; 168 } 169 } 170 else 171 { 172 rc = EFI_NOT_FOUND; 173 } 174 175 VBoxLogFlowFuncLeaveRC(rc); 176 return rc; 177 #endif 56 178 } 57 179 … … 78 200 ) 79 201 { 202 #ifndef VBOX 80 203 return EmuGetNextVariableName ( 81 204 VariableNameSize, … … 84 207 &mVariableModuleGlobal->VariableGlobal[Physical] 85 208 ); 209 #else 210 uint32_t u32Rc; 211 EFI_STATUS rc; 212 VBoxLogFlowFuncEnter(); 213 214 /* 215 * Validate inputs. 216 */ 217 if (!VariableNameSize || !VariableName || !VendorGuid) 218 { 219 VBoxLogFlowFuncLeaveRC(EFI_INVALID_PARAMETER); 220 return EFI_INVALID_PARAMETER; 221 } 222 223 /* 224 * Tell DevEFI which the current variable is, then ask for the next one. 225 */ 226 if (!VariableName[0]) 227 u32Rc = VBoxWriteNVRAMDoOp(EFI_VARIABLE_OP_QUERY_REWIND); 228 else 229 { 230 VBoxWriteNVRAMGuidParam(VendorGuid); 231 VBoxWriteNVRAMNameParam(VariableName); 232 u32Rc = VBoxWriteNVRAMDoOp(EFI_VARIABLE_OP_QUERY); 233 } 234 if (u32Rc == EFI_VARIABLE_OP_STATUS_OK) 235 u32Rc = VBoxWriteNVRAMDoOp(EFI_VARIABLE_OP_QUERY_NEXT); 236 /** @todo We're supposed to skip stuff depending on attributes and 237 * runtime/boottime, at least if EmuGetNextVariableName is something 238 * to go by... */ 239 240 if (u32Rc == EFI_VARIABLE_OP_STATUS_OK) 241 { 242 /* 243 * Output buffer check. 244 */ 245 UINT32 cwcName; 246 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_NAME_LENGTH_UTF16); 247 cwcName = ASMInU32(EFI_PORT_VARIABLE_OP); 248 if ((cwcName + 1) * 2 <= *VariableNameSize) /* ASSUMES byte size is specified */ 249 { 250 UINT32 i; 251 252 /* 253 * Read back the result. 254 */ 255 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_GUID); 256 VBoxReadNVRAM((UINT8 *)VendorGuid, sizeof(EFI_GUID)); 257 258 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_NAME_UTF16); 259 for (i = 0; i < cwcName; i++) 260 VariableName[i] = ASMInU16(EFI_PORT_VARIABLE_OP); 261 VariableName[i] = '\0'; 262 263 rc = EFI_SUCCESS; 264 } 265 else 266 rc = EFI_BUFFER_TOO_SMALL; 267 *VariableNameSize = (cwcName + 1) * 2; 268 } 269 else 270 rc = EFI_NOT_FOUND; /* whatever */ 271 272 VBoxLogFlowFuncLeaveRC(rc); 273 return rc; 274 #endif 86 275 } 87 276 … … 114 303 ) 115 304 { 305 #ifndef VBOX 116 306 return EmuSetVariable ( 117 307 VariableName, … … 124 314 &mVariableModuleGlobal->NonVolatileLastVariableOffset 125 315 ); 316 #else 317 UINT32 u32Rc; 318 VBoxLogFlowFuncEnter(); 319 VBoxLogFlowFuncMarkVar(VendorGuid, "%g"); 320 VBoxLogFlowFuncMarkVar(VariableName, "%s"); 321 VBoxLogFlowFuncMarkVar(DataSize, "%d"); 322 /* set guid */ 323 VBoxWriteNVRAMGuidParam(VendorGuid); 324 /* set name */ 325 VBoxWriteNVRAMNameParam(VariableName); 326 /* set attribute */ 327 VBoxWriteNVRAMU32Param(EFI_VM_VARIABLE_OP_ATTRIBUTE, Attributes); 328 /* set value length */ 329 VBoxWriteNVRAMU32Param(EFI_VM_VARIABLE_OP_VALUE_LENGTH, (UINT32)DataSize); 330 /* fill value bytes */ 331 ASMOutU32(EFI_PORT_VARIABLE_OP, EFI_VM_VARIABLE_OP_VALUE); 332 VBoxWriteNVRAMByteArrayParam(Data, (UINT32)DataSize); 333 /* start fetch operation */ 334 u32Rc = VBoxWriteNVRAMDoOp(EFI_VARIABLE_OP_ADD); 335 /* process errors */ 336 VBoxLogFlowFuncLeave(); 337 switch (u32Rc) 338 { 339 case EFI_VARIABLE_OP_STATUS_OK: 340 return EFI_SUCCESS; 341 case EFI_VARIABLE_OP_STATUS_NOT_WP: 342 default: 343 return EFI_WRITE_PROTECTED; 344 } 345 #endif 126 346 } 127 347 … … 153 373 ) 154 374 { 375 #ifndef VBOX 155 376 return EmuQueryVariableInfo ( 156 377 Attributes, … … 160 381 &mVariableModuleGlobal->VariableGlobal[Physical] 161 382 ); 383 #else 384 *MaximumVariableStorageSize = 64 * 1024 * 1024; 385 *MaximumVariableSize = 1024; 386 *RemainingVariableStorageSize = 32 * 1024 * 1024; 387 return EFI_SUCCESS; 388 #endif 162 389 } 163 390 … … 179 406 ) 180 407 { 408 #ifndef VBOX 181 409 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes); 182 410 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes); … … 191 419 ); 192 420 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal); 421 #endif 193 422 } 194 423 … … 247 476 ASSERT_EFI_ERROR (Status); 248 477 478 #ifdef VBOX 479 /* Self Test */ 480 { 481 EFI_GUID TestUUID = {0xe660597e, 0xb94d, 0x4209, {0x9c, 0x80, 0x18, 0x05, 0xb5, 0xd1, 0x9b, 0x69}}; 482 const char *pszVariable0 = "This is test!!!"; 483 const CHAR16 *pszVariable1 = L"This is test!!!"; 484 char szTestVariable[512]; 485 #if 0 486 rc = runtime->SetVariable(&TestUUID, 487 NULL , 488 (EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS| EFI_VARIABLE_RUNTIME_ACCESS), 489 0, 490 NULL ); 491 ASSERT(rc == EFI_INVALID_PARAMETER); 492 #endif 493 UINTN size = sizeof(szTestVariable), 494 rc = RuntimeServiceSetVariable( 495 L"Test0" , 496 &TestUUID, 497 (EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS| EFI_VARIABLE_RUNTIME_ACCESS), 498 AsciiStrSize(pszVariable0), 499 (void *)pszVariable0); 500 ASSERT_EFI_ERROR(rc); 501 SetMem(szTestVariable, 512, 0); 502 rc = RuntimeServiceGetVariable( 503 L"Test0" , 504 &TestUUID, 505 NULL, 506 &size, 507 (void *)szTestVariable); 508 VBoxLogFlowFuncMarkVar(szTestVariable, "%a"); 509 510 ASSERT(CompareMem(szTestVariable, pszVariable0, size) == 0); 511 512 rc = RuntimeServiceSetVariable( 513 L"Test1" , 514 &TestUUID, 515 (EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS| EFI_VARIABLE_RUNTIME_ACCESS), 516 StrSize(pszVariable1), 517 (void *)pszVariable1); 518 ASSERT_EFI_ERROR(rc); 519 SetMem(szTestVariable, 512, 0); 520 size = StrSize(pszVariable1); 521 rc = RuntimeServiceGetVariable( 522 L"Test1" , 523 &TestUUID, 524 NULL, 525 &size, 526 (void *)szTestVariable); 527 VBoxLogFlowFuncMarkVar((CHAR16 *)szTestVariable, "%s"); 528 ASSERT(CompareMem(szTestVariable, pszVariable1, size) == 0); 529 } 530 #endif 531 249 532 return EFI_SUCCESS; 250 533 }
Note:
See TracChangeset
for help on using the changeset viewer.