1 /** @file 2 3 Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR> 4 Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR> 5 6 SPDX-License-Identifier: BSD-2-Clause-Patent 7 8 **/ 9 10 #ifndef _GASKET_H_ 11 #define _GASKET_H_ 12 13 // 14 // EMU_THUNK_PROTOCOL gaskets (EFIAPI to UNIX ABI) 15 // 16 17 UINTN 18 EFIAPI 19 GasketSecWriteStdErr ( 20 IN UINT8 *Buffer, 21 IN UINTN NumberOfBytes 22 ); 23 24 EFI_STATUS 25 EFIAPI 26 GasketSecConfigStdIn ( 27 VOID 28 ); 29 30 UINTN 31 EFIAPI 32 GasketSecWriteStdOut ( 33 IN UINT8 *Buffer, 34 IN UINTN NumberOfBytes 35 ); 36 37 UINTN 38 EFIAPI 39 GasketSecReadStdIn ( 40 IN UINT8 *Buffer, 41 IN UINTN NumberOfBytes 42 ); 43 44 BOOLEAN 45 EFIAPI 46 GasketSecPollStdIn ( 47 VOID 48 ); 49 50 VOID * 51 EFIAPI 52 GasketSecMalloc ( 53 IN UINTN Size 54 ); 55 56 VOID * 57 EFIAPI 58 GasketSecValloc ( 59 IN UINTN Size 60 ); 61 62 BOOLEAN 63 EFIAPI 64 GasketSecFree ( 65 IN VOID *Ptr 66 ); 67 68 69 RETURN_STATUS 70 EFIAPI 71 GasketSecPeCoffGetEntryPoint ( 72 IN VOID *Pe32Data, 73 IN OUT VOID **EntryPoint 74 ); 75 76 VOID 77 EFIAPI 78 GasketSecPeCoffRelocateImageExtraAction ( 79 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext 80 ); 81 82 VOID 83 EFIAPI 84 GasketSecPeCoffUnloadImageExtraAction ( 85 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext 86 ); 87 88 VOID 89 EFIAPI 90 GasketSecSetTimer ( 91 IN UINT64 PeriodMs, 92 IN EMU_SET_TIMER_CALLBACK CallBack 93 ); 94 95 VOID 96 EFIAPI 97 GasketSecEnableInterrupt ( 98 VOID 99 ); 100 101 VOID 102 EFIAPI 103 GasketSecDisableInterrupt ( 104 VOID 105 ); 106 107 UINT64 108 EFIAPI 109 GasketQueryPerformanceFrequency ( 110 VOID 111 ); 112 113 UINT64 114 EFIAPI 115 GasketQueryPerformanceCounter ( 116 VOID 117 ); 118 119 120 VOID 121 EFIAPI 122 GasketSecSleep ( 123 IN UINT64 Nanoseconds 124 ); 125 126 VOID 127 EFIAPI 128 GasketSecCpuSleep ( 129 VOID 130 ); 131 132 VOID 133 EFIAPI 134 GasketSecExit ( 135 UINTN Status 136 ); 137 138 VOID 139 EFIAPI 140 GasketSecGetTime ( 141 OUT EFI_TIME *Time, 142 OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL 143 ); 144 145 VOID 146 EFIAPI 147 GasketSecSetTime ( 148 IN EFI_TIME *Time 149 ); 150 151 EFI_STATUS 152 EFIAPI 153 GasketSecGetNextProtocol ( 154 IN BOOLEAN EmuBusDriver, 155 OUT EMU_IO_THUNK_PROTOCOL **Instance OPTIONAL 156 ); 157 158 159 // PPIs produced by SEC 160 161 162 EFI_STATUS 163 EFIAPI 164 GasketSecUnixPeiAutoScan ( 165 IN UINTN Index, 166 OUT EFI_PHYSICAL_ADDRESS *MemoryBase, 167 OUT UINT64 *MemorySize 168 ); 169 170 VOID * 171 EFIAPI 172 GasketSecEmuThunkAddress ( 173 VOID 174 ); 175 176 177 EFI_STATUS 178 EFIAPI 179 GasketSecUnixUnixFwhAddress ( 180 IN OUT UINT64 *FwhSize, 181 IN OUT EFI_PHYSICAL_ADDRESS *FwhBase 182 ); 183 184 185 186 // 187 // Reverse (UNIX to EFIAPI) gaskets 188 // 189 190 typedef 191 void 192 (EFIAPI *CALL_BACK) ( 193 UINT64 Delta 194 ); 195 196 UINTN 197 ReverseGasketUint64 ( 198 UINTN CallBack, 199 UINT64 a 200 ); 201 202 UINTN 203 ReverseGasketUint64Uint64 ( 204 VOID *CallBack, 205 VOID *Context, 206 VOID *Key 207 ); 208 209 // 210 // Gasket functions for EFI_EMU_UGA_IO_PROTOCOL 211 // 212 213 214 EFI_STATUS 215 EFIAPI 216 GasketX11Size ( 217 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, 218 UINT32 Width, 219 UINT32 Height 220 ); 221 222 EFI_STATUS 223 EFIAPI 224 GasketX11CheckKey ( 225 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo 226 ); 227 228 EFI_STATUS 229 EFIAPI 230 GasketX11GetKey ( 231 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, 232 EFI_KEY_DATA *key 233 ); 234 235 EFI_STATUS 236 EFIAPI 237 GasketX11KeySetState ( 238 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, 239 EFI_KEY_TOGGLE_STATE *KeyToggleState 240 ); 241 242 EFI_STATUS 243 EFIAPI 244 GasketX11RegisterKeyNotify ( 245 IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, 246 IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK MakeCallBack, 247 IN EMU_GRAPHICS_WINDOW_REGISTER_KEY_NOTIFY_CALLBACK BreakCallBack, 248 IN VOID *Context 249 ); 250 251 252 EFI_STATUS 253 EFIAPI 254 GasketX11Blt ( 255 IN EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindows, 256 IN EFI_UGA_PIXEL *BltBuffer OPTIONAL, 257 IN EFI_UGA_BLT_OPERATION BltOperation, 258 IN EMU_GRAPHICS_WINDOWS__BLT_ARGS *Args 259 ); 260 261 EFI_STATUS 262 EFIAPI 263 GasketX11CheckPointer ( 264 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo 265 ); 266 267 EFI_STATUS 268 EFIAPI 269 GasketX11GetPointerState ( 270 EMU_GRAPHICS_WINDOW_PROTOCOL *GraphicsWindowsIo, 271 EFI_SIMPLE_POINTER_STATE *state 272 ); 273 274 EFI_STATUS 275 EFIAPI 276 GasketX11GraphicsWindowOpen ( 277 IN EMU_IO_THUNK_PROTOCOL *This 278 ); 279 280 EFI_STATUS 281 EFIAPI 282 GasketX11GraphicsWindowClose ( 283 IN EMU_IO_THUNK_PROTOCOL *This 284 ); 285 286 // Pthreads 287 288 UINTN 289 EFIAPI 290 GasketPthreadMutexLock ( 291 IN VOID *Mutex 292 ); 293 294 295 296 UINTN 297 EFIAPI 298 GasketPthreadMutexUnLock ( 299 IN VOID *Mutex 300 ); 301 302 303 UINTN 304 EFIAPI 305 GasketPthreadMutexTryLock ( 306 IN VOID *Mutex 307 ); 308 309 310 VOID * 311 EFIAPI 312 GasketPthreadMutexInit ( 313 IN VOID 314 ); 315 316 317 UINTN 318 EFIAPI 319 GasketPthreadMutexDestroy ( 320 IN VOID *Mutex 321 ); 322 323 324 UINTN 325 EFIAPI 326 GasketPthreadCreate ( 327 IN VOID *Thread, 328 IN VOID *Attribute, 329 IN THREAD_THUNK_THREAD_ENTRY Start, 330 IN VOID *Context 331 ); 332 333 VOID 334 EFIAPI 335 GasketPthreadExit ( 336 IN VOID *ValuePtr 337 ); 338 339 340 UINTN 341 EFIAPI 342 GasketPthreadSelf ( 343 VOID 344 ); 345 346 EFI_STATUS 347 EFIAPI 348 GasketPthreadOpen ( 349 IN EMU_IO_THUNK_PROTOCOL *This 350 ); 351 352 EFI_STATUS 353 EFIAPI 354 GasketPthreadClose ( 355 IN EMU_IO_THUNK_PROTOCOL *This 356 ); 357 358 359 // PosixFileSystem 360 361 EFI_STATUS 362 EFIAPI 363 GasketPosixOpenVolume ( 364 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, 365 OUT EFI_FILE_PROTOCOL **Root 366 ); 367 368 EFI_STATUS 369 EFIAPI 370 GasketPosixFileOpen ( 371 IN EFI_FILE_PROTOCOL *This, 372 OUT EFI_FILE_PROTOCOL **NewHandle, 373 IN CHAR16 *FileName, 374 IN UINT64 OpenMode, 375 IN UINT64 Attributes 376 ); 377 378 EFI_STATUS 379 EFIAPI 380 GasketPosixFileCLose ( 381 IN EFI_FILE_PROTOCOL *This 382 ); 383 384 EFI_STATUS 385 EFIAPI 386 GasketPosixFileDelete ( 387 IN EFI_FILE_PROTOCOL *This 388 ); 389 390 EFI_STATUS 391 EFIAPI 392 GasketPosixFileRead ( 393 IN EFI_FILE_PROTOCOL *This, 394 IN OUT UINTN *BufferSize, 395 OUT VOID *Buffer 396 ); 397 398 EFI_STATUS 399 EFIAPI 400 GasketPosixFileWrite ( 401 IN EFI_FILE_PROTOCOL *This, 402 IN OUT UINTN *BufferSize, 403 IN VOID *Buffer 404 ); 405 406 EFI_STATUS 407 EFIAPI 408 GasketPosixFileSetPossition ( 409 IN EFI_FILE_PROTOCOL *This, 410 IN UINT64 Position 411 ); 412 413 EFI_STATUS 414 EFIAPI 415 GasketPosixFileGetPossition ( 416 IN EFI_FILE_PROTOCOL *This, 417 OUT UINT64 *Position 418 ); 419 420 EFI_STATUS 421 EFIAPI 422 GasketPosixFileGetInfo ( 423 IN EFI_FILE_PROTOCOL *This, 424 IN EFI_GUID *InformationType, 425 IN OUT UINTN *BufferSize, 426 OUT VOID *Buffer 427 ); 428 429 EFI_STATUS 430 EFIAPI 431 GasketPosixFileSetInfo ( 432 IN EFI_FILE_PROTOCOL *This, 433 IN EFI_GUID *InformationType, 434 IN UINTN BufferSize, 435 IN VOID *Buffer 436 ); 437 438 EFI_STATUS 439 EFIAPI 440 GasketPosixFileFlush ( 441 IN EFI_FILE_PROTOCOL *This 442 ); 443 444 EFI_STATUS 445 EFIAPI 446 GasketPosixFileSystmeThunkOpen ( 447 IN EMU_IO_THUNK_PROTOCOL *This 448 ); 449 450 EFI_STATUS 451 EFIAPI 452 GasketPosixFileSystmeThunkClose ( 453 IN EMU_IO_THUNK_PROTOCOL *This 454 ); 455 456 EFI_STATUS 457 EFIAPI 458 GasketEmuBlockIoReset ( 459 IN EMU_BLOCK_IO_PROTOCOL *This, 460 IN BOOLEAN ExtendedVerification 461 ); 462 463 EFI_STATUS 464 EFIAPI 465 GasketEmuBlockIoReadBlocks ( 466 IN EMU_BLOCK_IO_PROTOCOL *This, 467 IN UINT32 MediaId, 468 IN EFI_LBA LBA, 469 IN OUT EFI_BLOCK_IO2_TOKEN *Token, 470 IN UINTN BufferSize, 471 OUT VOID *Buffer 472 ); 473 474 EFI_STATUS 475 EFIAPI 476 GasketEmuBlockIoWriteBlocks ( 477 IN EMU_BLOCK_IO_PROTOCOL *This, 478 IN UINT32 MediaId, 479 IN EFI_LBA LBA, 480 IN OUT EFI_BLOCK_IO2_TOKEN *Token, 481 IN UINTN BufferSize, 482 IN VOID *Buffer 483 ); 484 485 EFI_STATUS 486 EFIAPI 487 GasketEmuBlockIoFlushBlocks ( 488 IN EMU_BLOCK_IO_PROTOCOL *This, 489 IN OUT EFI_BLOCK_IO2_TOKEN *Token 490 ); 491 492 EFI_STATUS 493 EFIAPI 494 GasketEmuBlockIoCreateMapping ( 495 IN EMU_BLOCK_IO_PROTOCOL *This, 496 IN EFI_BLOCK_IO_MEDIA *Media 497 ); 498 499 EFI_STATUS 500 EFIAPI 501 GasketBlockIoThunkOpen ( 502 IN EMU_IO_THUNK_PROTOCOL *This 503 ); 504 505 EFI_STATUS 506 EFIAPI 507 GasketBlockIoThunkClose ( 508 IN EMU_IO_THUNK_PROTOCOL *This 509 ); 510 511 EFI_STATUS 512 EFIAPI 513 GasketSnpThunkOpen ( 514 IN EMU_IO_THUNK_PROTOCOL *This 515 ); 516 517 EFI_STATUS 518 EFIAPI 519 GasketSnpThunkClose ( 520 IN EMU_IO_THUNK_PROTOCOL *This 521 ); 522 523 EFI_STATUS 524 EFIAPI 525 GasketSnpCreateMapping ( 526 IN EMU_SNP_PROTOCOL *This, 527 IN EFI_SIMPLE_NETWORK_MODE *Media 528 ); 529 530 EFI_STATUS 531 EFIAPI 532 GasketSnpStart ( 533 IN EMU_SNP_PROTOCOL *This 534 ); 535 536 EFI_STATUS 537 EFIAPI 538 GasketSnpStop ( 539 IN EMU_SNP_PROTOCOL *This 540 ); 541 542 EFI_STATUS 543 EFIAPI 544 GasketSnpInitialize ( 545 IN EMU_SNP_PROTOCOL *This, 546 IN UINTN ExtraRxBufferSize OPTIONAL, 547 IN UINTN ExtraTxBufferSize OPTIONAL 548 ); 549 550 EFI_STATUS 551 EFIAPI 552 GasketSnpReset ( 553 IN EMU_SNP_PROTOCOL *This, 554 IN BOOLEAN ExtendedVerification 555 ); 556 557 EFI_STATUS 558 EFIAPI 559 GasketSnpShutdown ( 560 IN EMU_SNP_PROTOCOL *This 561 ); 562 563 EFI_STATUS 564 EFIAPI 565 GasketSnpReceiveFilters ( 566 IN EMU_SNP_PROTOCOL *This, 567 IN UINT32 Enable, 568 IN UINT32 Disable, 569 IN BOOLEAN ResetMCastFilter, 570 IN UINTN MCastFilterCnt OPTIONAL, 571 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL 572 ); 573 574 EFI_STATUS 575 EFIAPI 576 GasketSnpStationAddress ( 577 IN EMU_SNP_PROTOCOL *This, 578 IN BOOLEAN Reset, 579 IN EFI_MAC_ADDRESS *New OPTIONAL 580 ); 581 582 EFI_STATUS 583 EFIAPI 584 GasketSnpStatistics ( 585 IN EMU_SNP_PROTOCOL *This, 586 IN BOOLEAN Reset, 587 IN OUT UINTN *StatisticsSize OPTIONAL, 588 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL 589 ); 590 591 EFI_STATUS 592 EFIAPI 593 GasketSnpMCastIpToMac ( 594 IN EMU_SNP_PROTOCOL *This, 595 IN BOOLEAN IPv6, 596 IN EFI_IP_ADDRESS *IP, 597 OUT EFI_MAC_ADDRESS *MAC 598 ); 599 600 EFI_STATUS 601 EFIAPI 602 GasketSnpNvData ( 603 IN EMU_SNP_PROTOCOL *This, 604 IN BOOLEAN ReadWrite, 605 IN UINTN Offset, 606 IN UINTN BufferSize, 607 IN OUT VOID *Buffer 608 ); 609 610 EFI_STATUS 611 EFIAPI 612 GasketSnpGetStatus ( 613 IN EMU_SNP_PROTOCOL *This, 614 OUT UINT32 *InterruptStatus OPTIONAL, 615 OUT VOID **TxBuf OPTIONAL 616 ); 617 618 EFI_STATUS 619 EFIAPI 620 GasketSnpTransmit ( 621 IN EMU_SNP_PROTOCOL *This, 622 IN UINTN HeaderSize, 623 IN UINTN BufferSize, 624 IN VOID *Buffer, 625 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL, 626 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL, 627 IN UINT16 *Protocol OPTIONAL 628 ); 629 630 EFI_STATUS 631 EFIAPI 632 GasketSnpReceive ( 633 IN EMU_SNP_PROTOCOL *This, 634 OUT UINTN *HeaderSize OPTIONAL, 635 IN OUT UINTN *BufferSize, 636 OUT VOID *Buffer, 637 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, 638 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, 639 OUT UINT16 *Protocol OPTIONAL 640 ); 641 642 643 #endif 644 645 646