IntelSiliconPkg/PlatformVTdSample: update ExceptionDevice
authorJiewen Yao <jiewen.yao@intel.com>
Fri, 25 Aug 2017 06:36:41 +0000 (14:36 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Mon, 28 Aug 2017 08:28:46 +0000 (16:28 +0800)
Add sample for device scope based exception list
and PCI vendor id based exception list.

Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.c

index f181b94..07499c7 100644 (file)
@@ -27,6 +27,8 @@
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DevicePathLib.h>\r
 \r
+#include <IndustryStandard/DmaRemappingReportingTable.h>\r
+\r
 typedef struct {\r
   ACPI_EXTENDED_HID_DEVICE_PATH      I2cController;\r
   UINT8                              HidStr[8];\r
@@ -137,10 +139,57 @@ PLATFORM_PCI_BRIDGE_DEVICE_PATH mPlatformPciBridgeDevicePath = {
   PLATFORM_END_ENTIRE\r
 };\r
 \r
-EDKII_PLATFORM_VTD_DEVICE_INFO  mExceptionDeviceList[] = {\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  EDKII_PLATFORM_VTD_EXCEPTION_DEVICE_INFO     ExceptionDeviceInfo;\r
+  EDKII_PLATFORM_VTD_DEVICE_SCOPE              DeviceScope;\r
+  EFI_ACPI_DMAR_PCI_PATH                       PciBridge;\r
+  EFI_ACPI_DMAR_PCI_PATH                       PciDevice;\r
+} PLATFORM_EXCEPTION_DEVICE_SCOPE_STRUCT;\r
+\r
+typedef struct {\r
+  EDKII_PLATFORM_VTD_EXCEPTION_DEVICE_INFO     ExceptionDeviceInfo;\r
+  EDKII_PLATFORM_VTD_PCI_DEVICE_ID             PciDeviceId;\r
+} PLATFORM_EXCEPTION_PCI_DEVICE_ID_STRUCT;\r
+\r
+#pragma pack()\r
+\r
+PLATFORM_EXCEPTION_DEVICE_SCOPE_STRUCT  mExceptionDeviceScopeList[] = {\r
   {\r
-    0x0,                 // Segment\r
-    {{0x00, 0x00, 0x02}} // Function, Device, Bus\r
+    {\r
+      EDKII_PLATFORM_VTD_EXCEPTION_DEVICE_INFO_TYPE_DEVICE_SCOPE,\r
+      sizeof(PLATFORM_EXCEPTION_DEVICE_SCOPE_STRUCT)\r
+    },  // ExceptionDeviceInfo\r
+    {\r
+      0,                                                    // SegmentNumber\r
+      {\r
+        EFI_ACPI_DEVICE_SCOPE_ENTRY_TYPE_PCI_ENDPOINT,      // Type\r
+        sizeof(EFI_ACPI_DMAR_DEVICE_SCOPE_STRUCTURE_HEADER) +\r
+          2 * sizeof(EFI_ACPI_DMAR_PCI_PATH),               // Length\r
+        0,                                                  // Reserved2\r
+        0,                                                  // EnumerationId\r
+        0,                                                  // StartBusNumber\r
+      },\r
+    },                                                      // DeviceScope\r
+    { 0x1C, 1 },                                            // PciBridge\r
+    { 0x0,  0 },                                            // PciDevice\r
+  },\r
+};\r
+\r
+PLATFORM_EXCEPTION_PCI_DEVICE_ID_STRUCT  mExceptionPciDeviceIdList[] = {\r
+  {\r
+    {\r
+      EDKII_PLATFORM_VTD_EXCEPTION_DEVICE_INFO_TYPE_PCI_DEVICE_ID,\r
+      sizeof(PLATFORM_EXCEPTION_PCI_DEVICE_ID_STRUCT)\r
+    },  // ExceptionDeviceInfo\r
+    {\r
+      0x8086,                                               // VendorId\r
+      0x9D2F,                                               // DeviceId\r
+      0x21,                                                 // RevisionId\r
+      0x8086,                                               // SubsystemVendorId\r
+      0x7270,                                               // SubsystemDeviceId\r
+    },\r
   },\r
 };\r
 \r
@@ -269,6 +318,7 @@ PlatformVTdGetDeviceId (
   @param[in]  This                  The protocol instance pointer.\r
   @param[out] DeviceInfoCount       The count of the list of DeviceInfo.\r
   @param[out] DeviceInfo            A callee allocated buffer to hold a list of DeviceInfo.\r
+                                    Each DeviceInfo pointer points to EDKII_PLATFORM_VTD_EXCEPTION_DEVICE_INFO.\r
 \r
   @retval EFI_SUCCESS           The DeviceInfoCount and DeviceInfo are returned.\r
   @retval EFI_INVALID_PARAMETER DeviceInfoCount is NULL, or DeviceInfo is NULL.\r
@@ -280,7 +330,7 @@ EFIAPI
 PlatformVTdGetExceptionDeviceList (\r
   IN  EDKII_PLATFORM_VTD_POLICY_PROTOCOL       *This,\r
   OUT UINTN                                    *DeviceInfoCount,\r
-  OUT EDKII_PLATFORM_VTD_DEVICE_INFO           **DeviceInfo\r
+  OUT VOID                                     **DeviceInfo\r
   )\r
 {\r
   DEBUG ((DEBUG_VERBOSE, "PlatformVTdGetExceptionDeviceList\n"));\r
@@ -289,13 +339,23 @@ PlatformVTdGetExceptionDeviceList (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  *DeviceInfo = AllocateZeroPool (sizeof(mExceptionDeviceList));\r
-  if (*DeviceInfo == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  CopyMem (*DeviceInfo, mExceptionDeviceList, sizeof(mExceptionDeviceList));\r
+  if (0) {\r
+    *DeviceInfo = AllocateZeroPool (sizeof(mExceptionDeviceScopeList));\r
+    if (*DeviceInfo == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (*DeviceInfo, mExceptionDeviceScopeList, sizeof(mExceptionDeviceScopeList));\r
+\r
+    *DeviceInfoCount = ARRAY_SIZE(mExceptionDeviceScopeList);\r
+  } else {\r
+    *DeviceInfo = AllocateZeroPool (sizeof(mExceptionPciDeviceIdList));\r
+    if (*DeviceInfo == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    CopyMem (*DeviceInfo, mExceptionPciDeviceIdList, sizeof(mExceptionPciDeviceIdList));\r
 \r
-  *DeviceInfoCount = ARRAY_SIZE(mExceptionDeviceList);\r
+    *DeviceInfoCount = ARRAY_SIZE(mExceptionPciDeviceIdList);\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r