]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelSiliconPkg/IntelVTdDxe/DmaProtection.h
IntelSiliconPkg/IntelVTd: update PlatformVtdPolicy
[mirror_edk2.git] / IntelSiliconPkg / IntelVTdDxe / DmaProtection.h
index c311b298d1d1d81593a178d6cbcbc4548ca85f71..f7b5292f23e83267e2997b11ae2a9433fee5a864 100644 (file)
 #define ALIGN_VALUE_LOW(Value, Alignment) ((Value) & (~((Alignment) - 1)))\r
 \r
 //\r
-// This is the initial max PCI descriptor.\r
+// This is the initial max PCI DATA number.\r
 // The number may be enlarged later.\r
 //\r
-#define MAX_PCI_DESCRIPTORS             0x100\r
+#define MAX_VTD_PCI_DATA_NUMBER             0x100\r
 \r
 typedef struct {\r
-  BOOLEAN                IncludeAllFlag;\r
-  UINTN                  PciDescriptorNumber;\r
-  UINTN                  PciDescriptorMaxNumber;\r
-  BOOLEAN                *IsRealPciDevice;\r
-  VTD_SOURCE_ID          *PciDescriptors;\r
+  UINT8                            DeviceType;\r
+  VTD_SOURCE_ID                    PciSourceId;\r
+  EDKII_PLATFORM_VTD_PCI_DEVICE_ID PciDeviceId;\r
   // for statistic analysis\r
-  UINTN                  *AccessCount;\r
+  UINTN                            AccessCount;\r
+} PCI_DEVICE_DATA;\r
+\r
+typedef struct {\r
+  BOOLEAN                          IncludeAllFlag;\r
+  UINTN                            PciDeviceDataNumber;\r
+  UINTN                            PciDeviceDataMaxNumber;\r
+  PCI_DEVICE_DATA                  *PciDeviceData;\r
 } PCI_DEVICE_INFORMATION;\r
 \r
 typedef struct {\r
@@ -78,6 +83,29 @@ typedef struct {
   PCI_DEVICE_INFORMATION           PciDeviceInfo;\r
 } VTD_UNIT_INFORMATION;\r
 \r
+/**\r
+  The scan bus callback function.\r
+\r
+  It is called in PCI bus scan for each PCI device under the bus.\r
+\r
+  @param[in]  Context               The context of the callback.\r
+  @param[in]  Segment               The segment of the source.\r
+  @param[in]  Bus                   The bus of the source.\r
+  @param[in]  Device                The device of the source.\r
+  @param[in]  Function              The function of the source.\r
+\r
+  @retval EFI_SUCCESS           The specific PCI device is processed in the callback.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *SCAN_BUS_FUNC_CALLBACK_FUNC) (\r
+  IN VOID           *Context,\r
+  IN UINT16         Segment,\r
+  IN UINT8          Bus,\r
+  IN UINT8          Device,\r
+  IN UINT8          Function\r
+  );\r
+\r
 extern EFI_ACPI_DMAR_HEADER  *mAcpiDmarTable;\r
 \r
 extern UINT64                           mVtdHostAddressWidthMask;\r
@@ -182,13 +210,12 @@ DumpVtdECapRegs (
   );\r
 \r
 /**\r
-  Register PCI device to VTd engine as PCI descriptor.\r
+  Register PCI device to VTd engine.\r
 \r
   @param[in]  VtdIndex              The index of VTd engine.\r
   @param[in]  Segment               The segment of the source.\r
   @param[in]  SourceId              The SourceId of the source.\r
-  @param[in]  IsRealPciDevice       TRUE: It is a real PCI device.\r
-                                    FALSE: It is not a real PCI device.\r
+  @param[in]  DeviceType            The DMAR device scope type.\r
   @param[in]  CheckExist            TRUE: ERROR will be returned if the PCI device is already registered.\r
                                     FALSE: SUCCESS will be returned if the PCI device is registered.\r
 \r
@@ -201,25 +228,47 @@ RegisterPciDevice (
   IN UINTN          VtdIndex,\r
   IN UINT16         Segment,\r
   IN VTD_SOURCE_ID  SourceId,\r
-  IN BOOLEAN        IsRealPciDevice,\r
+  IN UINT8          DeviceType,\r
   IN BOOLEAN        CheckExist\r
   );\r
 \r
 /**\r
-  Scan PCI bus and register PCI devices under the bus.\r
+  The scan bus callback function to always enable page attribute.\r
 \r
-  @param[in]  VtdIndex              The index of VTd engine.\r
+  @param[in]  Context               The context of the callback.\r
   @param[in]  Segment               The segment of the source.\r
   @param[in]  Bus                   The bus of the source.\r
+  @param[in]  Device                The device of the source.\r
+  @param[in]  Function              The function of the source.\r
 \r
-  @retval EFI_SUCCESS           The PCI devices under the bus are registered.\r
-  @retval EFI_OUT_OF_RESOURCES  No enough resource to register a new PCI device.\r
+  @retval EFI_SUCCESS           The VTd entry is updated to always enable all DMA access for the specific device.\r
 **/\r
 EFI_STATUS\r
-ScanPciBus (\r
-  IN UINTN          VtdIndex,\r
+EFIAPI\r
+ScanBusCallbackRegisterPciDevice (\r
+  IN VOID           *Context,\r
   IN UINT16         Segment,\r
-  IN UINT8          Bus\r
+  IN UINT8          Bus,\r
+  IN UINT8          Device,\r
+  IN UINT8          Function\r
+  );\r
+\r
+/**\r
+  Scan PCI bus and invoke callback function for each PCI devices under the bus.\r
+\r
+  @param[in]  Context               The context of the callback function.\r
+  @param[in]  Segment               The segment of the source.\r
+  @param[in]  Bus                   The bus of the source.\r
+  @param[in]  Callback              The callback function in PCI scan.\r
+\r
+  @retval EFI_SUCCESS           The PCI devices under the bus are scaned.\r
+**/\r
+EFI_STATUS\r
+ScanPciBus (\r
+  IN VOID                         *Context,\r
+  IN UINT16                       Segment,\r
+  IN UINT8                        Bus,\r
+  IN SCAN_BUS_FUNC_CALLBACK_FUNC  Callback\r
   );\r
 \r
 /**\r
@@ -240,8 +289,8 @@ DumpPciDeviceInfo (
   @param[out] ExtContextEntry       The ExtContextEntry of the source.\r
   @param[out] ContextEntry          The ContextEntry of the source.\r
 \r
-  @return The index of the PCI descriptor.\r
-  @retval (UINTN)-1  The PCI descriptor is not found.\r
+  @return The index of the VTd engine.\r
+  @retval (UINTN)-1  The VTd engine is not found.\r
 **/\r
 UINTN\r
 FindVtdIndexByPciDevice (\r
@@ -371,17 +420,17 @@ SetAccessAttribute (
   );\r
 \r
 /**\r
-  Return the index of PCI descriptor.\r
+  Return the index of PCI data.\r
 \r
   @param[in]  VtdIndex          The index used to identify a VTd engine.\r
   @param[in]  Segment           The Segment used to identify a VTd engine.\r
   @param[in]  SourceId          The SourceId used to identify a VTd engine and table entry.\r
 \r
-  @return The index of the PCI descriptor.\r
-  @retval (UINTN)-1  The PCI descriptor is not found.\r
+  @return The index of the PCI data.\r
+  @retval (UINTN)-1  The PCI data is not found.\r
 **/\r
 UINTN\r
-GetPciDescriptor (\r
+GetPciDataIndex (\r
   IN UINTN          VtdIndex,\r
   IN UINT16         Segment,\r
   IN VTD_SOURCE_ID  SourceId\r
@@ -490,4 +539,24 @@ FlushPageTableMemory (
   IN UINTN  Size\r
   );\r
 \r
+/**\r
+  Get PCI device information from DMAR DevScopeEntry.\r
+\r
+  @param[in]  Segment               The segment number.\r
+  @param[in]  DmarDevScopeEntry     DMAR DevScopeEntry\r
+  @param[out] Bus                   The bus number.\r
+  @param[out] Device                The device number.\r
+  @param[out] Function              The function number.\r
+\r
+  @retval EFI_SUCCESS  The PCI device information is returned.\r
+**/\r
+EFI_STATUS\r
+GetPciBusDeviceFunction (\r
+  IN  UINT16                                      Segment,\r
+  IN  EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER *DmarDevScopeEntry,\r
+  OUT UINT8                                       *Bus,\r
+  OUT UINT8                                       *Device,\r
+  OUT UINT8                                       *Function\r
+  );\r
+\r
 #endif\r