]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/IoMmuDxe/AmdSevIoMmu.c
OvmfPkg/VirtioBlkDxe: negotiate VIRTIO_F_IOMMU_PLATFORM
[mirror_edk2.git] / OvmfPkg / IoMmuDxe / AmdSevIoMmu.c
1 /** @file
2
3 The protocol provides support to allocate, free, map and umap a DMA buffer
4 for bus master (e.g PciHostBridge). When SEV is enabled, the DMA operations
5 must be performed on unencrypted buffer hence we use a bounce buffer to map
6 the guest buffer into an unencrypted DMA buffer.
7
8 Copyright (c) 2017, AMD Inc. All rights reserved.<BR>
9 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
10
11 This program and the accompanying materials are licensed and made available
12 under the terms and conditions of the BSD License which accompanies this
13 distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
15
16 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.
18
19 **/
20
21 #include "AmdSevIoMmu.h"
22
23 #define MAP_INFO_SIG SIGNATURE_64 ('M', 'A', 'P', '_', 'I', 'N', 'F', 'O')
24
25 typedef struct {
26 UINT64 Signature;
27 LIST_ENTRY Link;
28 EDKII_IOMMU_OPERATION Operation;
29 UINTN NumberOfBytes;
30 UINTN NumberOfPages;
31 EFI_PHYSICAL_ADDRESS CryptedAddress;
32 EFI_PHYSICAL_ADDRESS PlainTextAddress;
33 } MAP_INFO;
34
35 //
36 // List of MAP_INFO structures recycled by Unmap().
37 //
38 // Recycled MAP_INFO structures are equally good for future recycling and
39 // freeing.
40 //
41 STATIC LIST_ENTRY mRecycledMapInfos = INITIALIZE_LIST_HEAD_VARIABLE (
42 mRecycledMapInfos
43 );
44
45 #define COMMON_BUFFER_SIG SIGNATURE_64 ('C', 'M', 'N', 'B', 'U', 'F', 'F', 'R')
46
47 //
48 // The following structure enables Map() and Unmap() to perform in-place
49 // decryption and encryption, respectively, for BusMasterCommonBuffer[64]
50 // operations, without dynamic memory allocation or release.
51 //
52 // Both COMMON_BUFFER_HEADER and COMMON_BUFFER_HEADER.StashBuffer are allocated
53 // by AllocateBuffer() and released by FreeBuffer().
54 //
55 #pragma pack (1)
56 typedef struct {
57 UINT64 Signature;
58
59 //
60 // Always allocated from EfiBootServicesData type memory, and always
61 // encrypted.
62 //
63 VOID *StashBuffer;
64
65 //
66 // Followed by the actual common buffer, starting at the next page.
67 //
68 } COMMON_BUFFER_HEADER;
69 #pragma pack ()
70
71 /**
72 Provides the controller-specific addresses required to access system memory
73 from a DMA bus master. On SEV guest, the DMA operations must be performed on
74 shared buffer hence we allocate a bounce buffer to map the HostAddress to a
75 DeviceAddress. The Encryption attribute is removed from the DeviceAddress
76 buffer.
77
78 @param This The protocol instance pointer.
79 @param Operation Indicates if the bus master is going to read or
80 write to system memory.
81 @param HostAddress The system memory address to map to the PCI
82 controller.
83 @param NumberOfBytes On input the number of bytes to map. On output
84 the number of bytes that were mapped.
85 @param DeviceAddress The resulting map address for the bus master
86 PCI controller to use to access the hosts
87 HostAddress.
88 @param Mapping A resulting value to pass to Unmap().
89
90 @retval EFI_SUCCESS The range was mapped for the returned
91 NumberOfBytes.
92 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common
93 buffer.
94 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
95 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
96 lack of resources.
97 @retval EFI_DEVICE_ERROR The system hardware could not map the requested
98 address.
99
100 **/
101 EFI_STATUS
102 EFIAPI
103 IoMmuMap (
104 IN EDKII_IOMMU_PROTOCOL *This,
105 IN EDKII_IOMMU_OPERATION Operation,
106 IN VOID *HostAddress,
107 IN OUT UINTN *NumberOfBytes,
108 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
109 OUT VOID **Mapping
110 )
111 {
112 EFI_STATUS Status;
113 LIST_ENTRY *RecycledMapInfo;
114 MAP_INFO *MapInfo;
115 EFI_ALLOCATE_TYPE AllocateType;
116 COMMON_BUFFER_HEADER *CommonBufferHeader;
117 VOID *DecryptionSource;
118
119 if (HostAddress == NULL || NumberOfBytes == NULL || DeviceAddress == NULL ||
120 Mapping == NULL) {
121 return EFI_INVALID_PARAMETER;
122 }
123
124 //
125 // Allocate a MAP_INFO structure to remember the mapping when Unmap() is
126 // called later.
127 //
128 RecycledMapInfo = GetFirstNode (&mRecycledMapInfos);
129 if (RecycledMapInfo == &mRecycledMapInfos) {
130 //
131 // No recycled MAP_INFO structure, allocate a new one.
132 //
133 MapInfo = AllocatePool (sizeof (MAP_INFO));
134 if (MapInfo == NULL) {
135 Status = EFI_OUT_OF_RESOURCES;
136 goto Failed;
137 }
138 } else {
139 MapInfo = CR (RecycledMapInfo, MAP_INFO, Link, MAP_INFO_SIG);
140 RemoveEntryList (RecycledMapInfo);
141 }
142
143 //
144 // Initialize the MAP_INFO structure, except the PlainTextAddress field
145 //
146 ZeroMem (&MapInfo->Link, sizeof MapInfo->Link);
147 MapInfo->Signature = MAP_INFO_SIG;
148 MapInfo->Operation = Operation;
149 MapInfo->NumberOfBytes = *NumberOfBytes;
150 MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (MapInfo->NumberOfBytes);
151 MapInfo->CryptedAddress = (UINTN)HostAddress;
152
153 //
154 // In the switch statement below, we point "MapInfo->PlainTextAddress" to the
155 // plaintext buffer, according to Operation. We also set "DecryptionSource".
156 //
157 MapInfo->PlainTextAddress = MAX_ADDRESS;
158 AllocateType = AllocateAnyPages;
159 DecryptionSource = (VOID *)(UINTN)MapInfo->CryptedAddress;
160 switch (Operation) {
161 //
162 // For BusMasterRead[64] and BusMasterWrite[64] operations, a bounce buffer
163 // is necessary regardless of whether the original (crypted) buffer crosses
164 // the 4GB limit or not -- we have to allocate a separate plaintext buffer.
165 // The only variable is whether the plaintext buffer should be under 4GB.
166 //
167 case EdkiiIoMmuOperationBusMasterRead:
168 case EdkiiIoMmuOperationBusMasterWrite:
169 MapInfo->PlainTextAddress = BASE_4GB - 1;
170 AllocateType = AllocateMaxAddress;
171 //
172 // fall through
173 //
174 case EdkiiIoMmuOperationBusMasterRead64:
175 case EdkiiIoMmuOperationBusMasterWrite64:
176 //
177 // Allocate the implicit plaintext bounce buffer.
178 //
179 Status = gBS->AllocatePages (
180 AllocateType,
181 EfiBootServicesData,
182 MapInfo->NumberOfPages,
183 &MapInfo->PlainTextAddress
184 );
185 if (EFI_ERROR (Status)) {
186 goto FreeMapInfo;
187 }
188 break;
189
190 //
191 // For BusMasterCommonBuffer[64] operations, a to-be-plaintext buffer and a
192 // stash buffer (for in-place decryption) have been allocated already, with
193 // AllocateBuffer(). We only check whether the address of the to-be-plaintext
194 // buffer is low enough for the requested operation.
195 //
196 case EdkiiIoMmuOperationBusMasterCommonBuffer:
197 if ((MapInfo->CryptedAddress > BASE_4GB) ||
198 (EFI_PAGES_TO_SIZE (MapInfo->NumberOfPages) >
199 BASE_4GB - MapInfo->CryptedAddress)) {
200 //
201 // CommonBuffer operations cannot be remapped. If the common buffer is
202 // above 4GB, then it is not possible to generate a mapping, so return an
203 // error.
204 //
205 Status = EFI_UNSUPPORTED;
206 goto FreeMapInfo;
207 }
208 //
209 // fall through
210 //
211 case EdkiiIoMmuOperationBusMasterCommonBuffer64:
212 //
213 // The buffer at MapInfo->CryptedAddress comes from AllocateBuffer().
214 //
215 MapInfo->PlainTextAddress = MapInfo->CryptedAddress;
216 //
217 // Stash the crypted data.
218 //
219 CommonBufferHeader = (COMMON_BUFFER_HEADER *)(
220 (UINTN)MapInfo->CryptedAddress - EFI_PAGE_SIZE
221 );
222 ASSERT (CommonBufferHeader->Signature == COMMON_BUFFER_SIG);
223 CopyMem (
224 CommonBufferHeader->StashBuffer,
225 (VOID *)(UINTN)MapInfo->CryptedAddress,
226 MapInfo->NumberOfBytes
227 );
228 //
229 // Point "DecryptionSource" to the stash buffer so that we decrypt
230 // it to the original location, after the switch statement.
231 //
232 DecryptionSource = CommonBufferHeader->StashBuffer;
233 break;
234
235 default:
236 //
237 // Operation is invalid
238 //
239 Status = EFI_INVALID_PARAMETER;
240 goto FreeMapInfo;
241 }
242
243 //
244 // Clear the memory encryption mask on the plaintext buffer.
245 //
246 Status = MemEncryptSevClearPageEncMask (
247 0,
248 MapInfo->PlainTextAddress,
249 MapInfo->NumberOfPages,
250 TRUE
251 );
252 ASSERT_EFI_ERROR (Status);
253 if (EFI_ERROR (Status)) {
254 CpuDeadLoop ();
255 }
256
257 //
258 // If this is a read operation from the Bus Master's point of view,
259 // then copy the contents of the real buffer into the mapped buffer
260 // so the Bus Master can read the contents of the real buffer.
261 //
262 // For BusMasterCommonBuffer[64] operations, the CopyMem() below will decrypt
263 // the original data (from the stash buffer) back to the original location.
264 //
265 if (Operation == EdkiiIoMmuOperationBusMasterRead ||
266 Operation == EdkiiIoMmuOperationBusMasterRead64 ||
267 Operation == EdkiiIoMmuOperationBusMasterCommonBuffer ||
268 Operation == EdkiiIoMmuOperationBusMasterCommonBuffer64) {
269 CopyMem (
270 (VOID *) (UINTN) MapInfo->PlainTextAddress,
271 DecryptionSource,
272 MapInfo->NumberOfBytes
273 );
274 }
275
276 //
277 // Populate output parameters.
278 //
279 *DeviceAddress = MapInfo->PlainTextAddress;
280 *Mapping = MapInfo;
281
282 DEBUG ((
283 DEBUG_VERBOSE,
284 "%a PlainText 0x%Lx Crypted 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",
285 __FUNCTION__,
286 MapInfo->PlainTextAddress,
287 MapInfo->CryptedAddress,
288 (UINT64)MapInfo->NumberOfPages,
289 (UINT64)MapInfo->NumberOfBytes
290 ));
291
292 return EFI_SUCCESS;
293
294 FreeMapInfo:
295 FreePool (MapInfo);
296
297 Failed:
298 *NumberOfBytes = 0;
299 return Status;
300 }
301
302 /**
303 Completes the Map() operation and releases any corresponding resources.
304
305 @param This The protocol instance pointer.
306 @param Mapping The mapping value returned from Map().
307
308 @retval EFI_SUCCESS The range was unmapped.
309 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by
310 Map().
311 @retval EFI_DEVICE_ERROR The data was not committed to the target system
312 memory.
313 **/
314 EFI_STATUS
315 EFIAPI
316 IoMmuUnmap (
317 IN EDKII_IOMMU_PROTOCOL *This,
318 IN VOID *Mapping
319 )
320 {
321 MAP_INFO *MapInfo;
322 EFI_STATUS Status;
323 COMMON_BUFFER_HEADER *CommonBufferHeader;
324 VOID *EncryptionTarget;
325
326 if (Mapping == NULL) {
327 return EFI_INVALID_PARAMETER;
328 }
329
330 MapInfo = (MAP_INFO *)Mapping;
331
332 //
333 // set CommonBufferHeader to suppress incorrect compiler/analyzer warnings
334 //
335 CommonBufferHeader = NULL;
336
337 //
338 // For BusMasterWrite[64] operations and BusMasterCommonBuffer[64] operations
339 // we have to encrypt the results, ultimately to the original place (i.e.,
340 // "MapInfo->CryptedAddress").
341 //
342 // For BusMasterCommonBuffer[64] operations however, this encryption has to
343 // land in-place, so divert the encryption to the stash buffer first.
344 //
345 EncryptionTarget = (VOID *)(UINTN)MapInfo->CryptedAddress;
346
347 switch (MapInfo->Operation) {
348 case EdkiiIoMmuOperationBusMasterCommonBuffer:
349 case EdkiiIoMmuOperationBusMasterCommonBuffer64:
350 ASSERT (MapInfo->PlainTextAddress == MapInfo->CryptedAddress);
351
352 CommonBufferHeader = (COMMON_BUFFER_HEADER *)(
353 (UINTN)MapInfo->PlainTextAddress - EFI_PAGE_SIZE
354 );
355 ASSERT (CommonBufferHeader->Signature == COMMON_BUFFER_SIG);
356 EncryptionTarget = CommonBufferHeader->StashBuffer;
357 //
358 // fall through
359 //
360
361 case EdkiiIoMmuOperationBusMasterWrite:
362 case EdkiiIoMmuOperationBusMasterWrite64:
363 CopyMem (
364 EncryptionTarget,
365 (VOID *) (UINTN) MapInfo->PlainTextAddress,
366 MapInfo->NumberOfBytes
367 );
368 break;
369
370 default:
371 //
372 // nothing to encrypt after BusMasterRead[64] operations
373 //
374 break;
375 }
376
377 DEBUG ((
378 DEBUG_VERBOSE,
379 "%a PlainText 0x%Lx Crypted 0x%Lx Pages 0x%Lx Bytes 0x%Lx\n",
380 __FUNCTION__,
381 MapInfo->PlainTextAddress,
382 MapInfo->CryptedAddress,
383 (UINT64)MapInfo->NumberOfPages,
384 (UINT64)MapInfo->NumberOfBytes
385 ));
386
387 //
388 // Restore the memory encryption mask on the area we used to hold the
389 // plaintext.
390 //
391 Status = MemEncryptSevSetPageEncMask (
392 0,
393 MapInfo->PlainTextAddress,
394 MapInfo->NumberOfPages,
395 TRUE
396 );
397 ASSERT_EFI_ERROR (Status);
398 if (EFI_ERROR (Status)) {
399 CpuDeadLoop ();
400 }
401
402 //
403 // For BusMasterCommonBuffer[64] operations, copy the stashed data to the
404 // original (now encrypted) location.
405 //
406 // For all other operations, fill the late bounce buffer (which existed as
407 // plaintext at some point) with zeros, and then release it.
408 //
409 if (MapInfo->Operation == EdkiiIoMmuOperationBusMasterCommonBuffer ||
410 MapInfo->Operation == EdkiiIoMmuOperationBusMasterCommonBuffer64) {
411 CopyMem (
412 (VOID *)(UINTN)MapInfo->CryptedAddress,
413 CommonBufferHeader->StashBuffer,
414 MapInfo->NumberOfBytes
415 );
416
417 //
418 // Recycle the MAP_INFO structure.
419 //
420 InsertTailList (&mRecycledMapInfos, &MapInfo->Link);
421 } else {
422 ZeroMem (
423 (VOID *)(UINTN)MapInfo->PlainTextAddress,
424 EFI_PAGES_TO_SIZE (MapInfo->NumberOfPages)
425 );
426 gBS->FreePages (MapInfo->PlainTextAddress, MapInfo->NumberOfPages);
427
428 //
429 // Free the MAP_INFO structure.
430 //
431 FreePool (MapInfo);
432 }
433
434 return EFI_SUCCESS;
435 }
436
437 /**
438 Allocates pages that are suitable for an OperationBusMasterCommonBuffer or
439 OperationBusMasterCommonBuffer64 mapping.
440
441 @param This The protocol instance pointer.
442 @param Type This parameter is not used and must be ignored.
443 @param MemoryType The type of memory to allocate,
444 EfiBootServicesData or EfiRuntimeServicesData.
445 @param Pages The number of pages to allocate.
446 @param HostAddress A pointer to store the base system memory
447 address of the allocated range.
448 @param Attributes The requested bit mask of attributes for the
449 allocated range.
450
451 @retval EFI_SUCCESS The requested memory pages were allocated.
452 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
453 attribute bits are MEMORY_WRITE_COMBINE and
454 MEMORY_CACHED.
455 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
456 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
457
458 **/
459 EFI_STATUS
460 EFIAPI
461 IoMmuAllocateBuffer (
462 IN EDKII_IOMMU_PROTOCOL *This,
463 IN EFI_ALLOCATE_TYPE Type,
464 IN EFI_MEMORY_TYPE MemoryType,
465 IN UINTN Pages,
466 IN OUT VOID **HostAddress,
467 IN UINT64 Attributes
468 )
469 {
470 EFI_STATUS Status;
471 EFI_PHYSICAL_ADDRESS PhysicalAddress;
472 VOID *StashBuffer;
473 UINTN CommonBufferPages;
474 COMMON_BUFFER_HEADER *CommonBufferHeader;
475
476 //
477 // Validate Attributes
478 //
479 if ((Attributes & EDKII_IOMMU_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) != 0) {
480 return EFI_UNSUPPORTED;
481 }
482
483 //
484 // Check for invalid inputs
485 //
486 if (HostAddress == NULL) {
487 return EFI_INVALID_PARAMETER;
488 }
489
490 //
491 // The only valid memory types are EfiBootServicesData and
492 // EfiRuntimeServicesData
493 //
494 if (MemoryType != EfiBootServicesData &&
495 MemoryType != EfiRuntimeServicesData) {
496 return EFI_INVALID_PARAMETER;
497 }
498
499 //
500 // We'll need a header page for the COMMON_BUFFER_HEADER structure.
501 //
502 if (Pages > MAX_UINTN - 1) {
503 return EFI_OUT_OF_RESOURCES;
504 }
505 CommonBufferPages = Pages + 1;
506
507 //
508 // Allocate the stash in EfiBootServicesData type memory.
509 //
510 // Map() will temporarily save encrypted data in the stash for
511 // BusMasterCommonBuffer[64] operations, so the data can be decrypted to the
512 // original location.
513 //
514 // Unmap() will temporarily save plaintext data in the stash for
515 // BusMasterCommonBuffer[64] operations, so the data can be encrypted to the
516 // original location.
517 //
518 // StashBuffer always resides in encrypted memory.
519 //
520 StashBuffer = AllocatePages (Pages);
521 if (StashBuffer == NULL) {
522 return EFI_OUT_OF_RESOURCES;
523 }
524
525 PhysicalAddress = (UINTN)-1;
526 if ((Attributes & EDKII_IOMMU_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0) {
527 //
528 // Limit allocations to memory below 4GB
529 //
530 PhysicalAddress = SIZE_4GB - 1;
531 }
532 Status = gBS->AllocatePages (
533 AllocateMaxAddress,
534 MemoryType,
535 CommonBufferPages,
536 &PhysicalAddress
537 );
538 if (EFI_ERROR (Status)) {
539 goto FreeStashBuffer;
540 }
541
542 CommonBufferHeader = (VOID *)(UINTN)PhysicalAddress;
543 PhysicalAddress += EFI_PAGE_SIZE;
544
545 CommonBufferHeader->Signature = COMMON_BUFFER_SIG;
546 CommonBufferHeader->StashBuffer = StashBuffer;
547
548 *HostAddress = (VOID *)(UINTN)PhysicalAddress;
549
550 DEBUG ((
551 DEBUG_VERBOSE,
552 "%a Address 0x%Lx Pages 0x%Lx\n",
553 __FUNCTION__,
554 PhysicalAddress,
555 (UINT64)Pages
556 ));
557 return EFI_SUCCESS;
558
559 FreeStashBuffer:
560 FreePages (StashBuffer, Pages);
561 return Status;
562 }
563
564 /**
565 Frees memory that was allocated with AllocateBuffer().
566
567 @param This The protocol instance pointer.
568 @param Pages The number of pages to free.
569 @param HostAddress The base system memory address of the allocated
570 range.
571
572 @retval EFI_SUCCESS The requested memory pages were freed.
573 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and
574 Pages was not allocated with AllocateBuffer().
575
576 **/
577 EFI_STATUS
578 EFIAPI
579 IoMmuFreeBuffer (
580 IN EDKII_IOMMU_PROTOCOL *This,
581 IN UINTN Pages,
582 IN VOID *HostAddress
583 )
584 {
585 UINTN CommonBufferPages;
586 COMMON_BUFFER_HEADER *CommonBufferHeader;
587
588 CommonBufferPages = Pages + 1;
589 CommonBufferHeader = (COMMON_BUFFER_HEADER *)(
590 (UINTN)HostAddress - EFI_PAGE_SIZE
591 );
592
593 //
594 // Check the signature.
595 //
596 ASSERT (CommonBufferHeader->Signature == COMMON_BUFFER_SIG);
597 if (CommonBufferHeader->Signature != COMMON_BUFFER_SIG) {
598 return EFI_INVALID_PARAMETER;
599 }
600
601 //
602 // Free the stash buffer. This buffer was always encrypted, so no need to
603 // zero it.
604 //
605 FreePages (CommonBufferHeader->StashBuffer, Pages);
606
607 DEBUG ((
608 DEBUG_VERBOSE,
609 "%a Address 0x%Lx Pages 0x%Lx\n",
610 __FUNCTION__,
611 (UINT64)(UINTN)HostAddress,
612 (UINT64)Pages
613 ));
614
615 //
616 // Release the common buffer itself. Unmap() has re-encrypted it in-place, so
617 // no need to zero it.
618 //
619 return gBS->FreePages ((UINTN)CommonBufferHeader, CommonBufferPages);
620 }
621
622
623 /**
624 Set IOMMU attribute for a system memory.
625
626 If the IOMMU protocol exists, the system memory cannot be used
627 for DMA by default.
628
629 When a device requests a DMA access for a system memory,
630 the device driver need use SetAttribute() to update the IOMMU
631 attribute to request DMA access (read and/or write).
632
633 The DeviceHandle is used to identify which device submits the request.
634 The IOMMU implementation need translate the device path to an IOMMU device
635 ID, and set IOMMU hardware register accordingly.
636 1) DeviceHandle can be a standard PCI device.
637 The memory for BusMasterRead need set EDKII_IOMMU_ACCESS_READ.
638 The memory for BusMasterWrite need set EDKII_IOMMU_ACCESS_WRITE.
639 The memory for BusMasterCommonBuffer need set
640 EDKII_IOMMU_ACCESS_READ|EDKII_IOMMU_ACCESS_WRITE.
641 After the memory is used, the memory need set 0 to keep it being
642 protected.
643 2) DeviceHandle can be an ACPI device (ISA, I2C, SPI, etc).
644 The memory for DMA access need set EDKII_IOMMU_ACCESS_READ and/or
645 EDKII_IOMMU_ACCESS_WRITE.
646
647 @param[in] This The protocol instance pointer.
648 @param[in] DeviceHandle The device who initiates the DMA access
649 request.
650 @param[in] Mapping The mapping value returned from Map().
651 @param[in] IoMmuAccess The IOMMU access.
652
653 @retval EFI_SUCCESS The IoMmuAccess is set for the memory range
654 specified by DeviceAddress and Length.
655 @retval EFI_INVALID_PARAMETER DeviceHandle is an invalid handle.
656 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by
657 Map().
658 @retval EFI_INVALID_PARAMETER IoMmuAccess specified an illegal combination
659 of access.
660 @retval EFI_UNSUPPORTED DeviceHandle is unknown by the IOMMU.
661 @retval EFI_UNSUPPORTED The bit mask of IoMmuAccess is not supported
662 by the IOMMU.
663 @retval EFI_UNSUPPORTED The IOMMU does not support the memory range
664 specified by Mapping.
665 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
666 modify the IOMMU access.
667 @retval EFI_DEVICE_ERROR The IOMMU device reported an error while
668 attempting the operation.
669
670 **/
671 EFI_STATUS
672 EFIAPI
673 IoMmuSetAttribute (
674 IN EDKII_IOMMU_PROTOCOL *This,
675 IN EFI_HANDLE DeviceHandle,
676 IN VOID *Mapping,
677 IN UINT64 IoMmuAccess
678 )
679 {
680 return EFI_UNSUPPORTED;
681 }
682
683 EDKII_IOMMU_PROTOCOL mAmdSev = {
684 EDKII_IOMMU_PROTOCOL_REVISION,
685 IoMmuSetAttribute,
686 IoMmuMap,
687 IoMmuUnmap,
688 IoMmuAllocateBuffer,
689 IoMmuFreeBuffer,
690 };
691
692 /**
693 Initialize Iommu Protocol.
694
695 **/
696 EFI_STATUS
697 EFIAPI
698 AmdSevInstallIoMmuProtocol (
699 VOID
700 )
701 {
702 EFI_STATUS Status;
703 EFI_HANDLE Handle;
704
705 Handle = NULL;
706 Status = gBS->InstallMultipleProtocolInterfaces (
707 &Handle,
708 &gEdkiiIoMmuProtocolGuid, &mAmdSev,
709 NULL
710 );
711 return Status;
712 }