From: Jiewen Yao <jiewen.yao@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>
Subject: [PATCH 6/7] IntelSiliconPkg: Add PlatformVTdSample driver.
Date: Tue, 18 Jul 2017 15:51:36 +0800 [thread overview]
Message-ID: <1500364297-17072-7-git-send-email-jiewen.yao@intel.com> (raw)
In-Reply-To: <1500364297-17072-1-git-send-email-jiewen.yao@intel.com>
It provides sample on Platform VTd policy protocol.
This protocol is optional.
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
---
IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.c | 339 ++++++++++++++++++++
IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.inf | 59 ++++
IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.uni | 20 ++
| 20 ++
4 files changed, 438 insertions(+)
diff --git a/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.c b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.c
new file mode 100644
index 0000000..13b5feb
--- /dev/null
+++ b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.c
@@ -0,0 +1,339 @@
+/** @file
+ Platform VTd Sample driver.
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiDxe.h>
+
+#include <IndustryStandard/Vtd.h>
+#include <Protocol/PlatformVtdPolicy.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/DevicePath.h>
+
+#include <Library/IoLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+
+typedef struct {
+ ACPI_EXTENDED_HID_DEVICE_PATH I2cController;
+ UINT8 HidStr[8];
+ UINT8 UidStr[1];
+ UINT8 CidStr[8];
+} PLATFORM_I2C_CONTROLLER_DEVICE_PATH;
+
+typedef struct {
+ ACPI_EXTENDED_HID_DEVICE_PATH I2cDevice;
+ UINT8 HidStr[13];
+ UINT8 UidStr[1];
+ UINT8 CidStr[13];
+} PLATFORM_I2C_DEVICE_DEVICE_PATH;
+
+typedef struct {
+ PLATFORM_I2C_CONTROLLER_DEVICE_PATH I2cController;
+ PLATFORM_I2C_DEVICE_DEVICE_PATH I2cDevice;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} PLATFORM_I2C_DEVICE_PATH;
+
+typedef struct {
+ ACPI_HID_DEVICE_PATH PciRootBridge;
+ PCI_DEVICE_PATH PciDevice;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} PLATFORM_PCI_DEVICE_PATH;
+
+typedef struct {
+ ACPI_HID_DEVICE_PATH PciRootBridge;
+ PCI_DEVICE_PATH PciBridge;
+ PCI_DEVICE_PATH PciDevice;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} PLATFORM_PCI_BRIDGE_DEVICE_PATH;
+
+typedef struct {
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINT16 Segment;
+ VTD_SOURCE_ID SourceId;
+} PLATFORM_ACPI_DEVICE_MAPPING;
+
+#define PLATFORM_PCI_ROOT_BRIDGE \
+ { \
+ { \
+ ACPI_DEVICE_PATH, \
+ ACPI_DP, \
+ { \
+ (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), \
+ (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) \
+ }, \
+ }, \
+ EISA_PNP_ID (0x0A03), \
+ 0 \
+ }
+
+#define PLATFORM_END_ENTIRE \
+ { \
+ END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { END_DEVICE_PATH_LENGTH, 0 } \
+ }
+
+#define PLATFORM_PCI(Device, Function) \
+ { \
+ { \
+ HARDWARE_DEVICE_PATH, \
+ HW_PCI_DP, \
+ { \
+ (UINT8) (sizeof (PCI_DEVICE_PATH)), \
+ (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8) \
+ } \
+ }, \
+ (Function), \
+ (Device) \
+ }
+
+#define PLATFORM_I2C(Hid, Uid, Cid, HidStr, UidStr, CidStr) \
+ { \
+ { \
+ { \
+ ACPI_DEVICE_PATH, \
+ ACPI_EXTENDED_DP, \
+ {sizeof(ACPI_EXTENDED_HID_DEVICE_PATH) + sizeof(HidStr) + sizeof(UidStr) + sizeof(CidStr), 0} \
+ }, \
+ Hid, \
+ Uid, \
+ Cid \
+ }, \
+ HidStr, \
+ UidStr, \
+ CidStr \
+ }
+
+PLATFORM_I2C_DEVICE_PATH mPlatformI2CDevicePath = {
+ PLATFORM_I2C(0, 2, 0, "INT33C3", "", "INT33C3"),
+ PLATFORM_I2C(0, 1, 0, "I2C01\\TPANEL", "", "I2C01\\TPANEL"),
+ PLATFORM_END_ENTIRE
+};
+
+PLATFORM_ACPI_DEVICE_MAPPING mAcpiDeviceMapping[] = {
+ {
+ (EFI_DEVICE_PATH_PROTOCOL *)&mPlatformI2CDevicePath,
+ 0x0, // Segment
+ {{0x01, 0x15, 0x00}} // Function, Device, Bus
+ }
+};
+
+PLATFORM_PCI_BRIDGE_DEVICE_PATH mPlatformPciBridgeDevicePath = {
+ PLATFORM_PCI_ROOT_BRIDGE,
+ PLATFORM_PCI(0x1C, 1),
+ PLATFORM_PCI(0, 0),
+ PLATFORM_END_ENTIRE
+};
+
+EDKII_PLATFORM_VTD_DEVICE_INFO mExceptionDeviceList[] = {
+ {
+ 0x0, // Segment
+ {{0x00, 0x00, 0x02}} // Function, Device, Bus
+ },
+};
+
+/**
+ Compares 2 device path.
+
+ @param[in] DevicePath1 A device path with EndDevicePath node.
+ @param[in] DevicePath2 A device path with EndDevicePath node.
+
+ @retval TRUE 2 device path are identical.
+ @retval FALSE 2 device path are not identical.
+**/
+BOOLEAN
+CompareDevicePath (
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath1,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath2
+ )
+{
+ UINTN Size1;
+ UINTN Size2;
+
+ Size1 = GetDevicePathSize (DevicePath1);
+ Size2 = GetDevicePathSize (DevicePath2);
+ if (Size1 != Size2) {
+ return FALSE;
+ }
+ if (CompareMem (DevicePath1, DevicePath2, Size1) != 0) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ Get the VTD SourceId from the device handler.
+ This function is required for non PCI device handler.
+
+ Pseudo-algo in Intel VTd driver:
+ Status = PlatformGetVTdDeviceId ();
+ if (EFI_ERROR(Status)) {
+ if (DeviceHandle is PCI) {
+ Get SourceId from Bus/Device/Function
+ } else {
+ return EFI_UNSUPPORTED
+ }
+ }
+ Get VTd engine by Segment/Bus/Device/Function.
+
+ @param[in] This The protocol instance pointer.
+ @param[in] DeviceHandle Device Identifier in UEFI.
+ @param[out] DeviceInfo DeviceInfo for indentify the VTd engine in ACPI Table
+ and the VTd page entry.
+
+ @retval EFI_SUCCESS The VtdIndex and SourceId are returned.
+ @retval EFI_INVALID_PARAMETER DeviceHandle is not a valid handler.
+ @retval EFI_INVALID_PARAMETER DeviceInfo is NULL.
+ @retval EFI_NOT_FOUND The Segment or SourceId information is NOT found.
+ @retval EFI_UNSUPPORTED This function is not supported.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformVTdGetDeviceId (
+ IN EDKII_PLATFORM_VTD_POLICY_PROTOCOL *This,
+ IN EFI_HANDLE DeviceHandle,
+ OUT EDKII_PLATFORM_VTD_DEVICE_INFO *DeviceInfo
+ )
+{
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ UINTN Seg;
+ UINTN Bus;
+ UINTN Dev;
+ UINTN Func;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ UINTN Index;
+
+ DEBUG ((DEBUG_VERBOSE, "PlatformVTdGetDeviceId\n"));
+
+ if (DeviceInfo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (DeviceHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Handle PCI device
+ //
+ Status = gBS->HandleProtocol (DeviceHandle, &gEfiPciIoProtocolGuid, (VOID **)&PciIo);
+ if (!EFI_ERROR(Status)) {
+ Status = PciIo->GetLocation (PciIo, &Seg, &Bus, &Dev, &Func);
+ if (EFI_ERROR(Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ DeviceInfo->Segment = (UINT16)Seg;
+ DeviceInfo->SourceId.Bits.Bus = (UINT8)Bus;
+ DeviceInfo->SourceId.Bits.Device = (UINT8)Dev;
+ DeviceInfo->SourceId.Bits.Function = (UINT8)Func;
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Handle ACPI device
+ //
+ Status = gBS->HandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath);
+ if (!EFI_ERROR(Status)) {
+ for (Index = 0; Index < ARRAY_SIZE(mAcpiDeviceMapping); Index++) {
+ if (CompareDevicePath (mAcpiDeviceMapping[Index].DevicePath, DevicePath)) {
+ DeviceInfo->Segment = mAcpiDeviceMapping[Index].Segment;
+ DeviceInfo->SourceId = mAcpiDeviceMapping[Index].SourceId;
+ return EFI_SUCCESS;
+ }
+ }
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+/**
+ Get a list of handles for the exception devices.
+
+ The VTd driver should always set ALLOW for the device in this list.
+
+ @param[in] This The protocol instance pointer.
+ @param[out] DeviceInfoCount The count of the list of DeviceInfo.
+ @param[out] DeviceInfo A callee allocated buffer to hold a list of DeviceInfo.
+
+ @retval EFI_SUCCESS The DeviceInfoCount and DeviceInfo are returned.
+ @retval EFI_INVALID_PARAMETER DeviceInfoCount is NULL, or DeviceInfo is NULL.
+ @retval EFI_UNSUPPORTED This function is not supported.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformVTdGetExceptionDeviceList (
+ IN EDKII_PLATFORM_VTD_POLICY_PROTOCOL *This,
+ OUT UINTN *DeviceInfoCount,
+ OUT EDKII_PLATFORM_VTD_DEVICE_INFO **DeviceInfo
+ )
+{
+ DEBUG ((DEBUG_VERBOSE, "PlatformVTdGetExceptionDeviceList\n"));
+
+ if (DeviceInfoCount == NULL || DeviceInfo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *DeviceInfo = AllocateZeroPool (sizeof(mExceptionDeviceList));
+ if (*DeviceInfo == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ CopyMem (*DeviceInfo, mExceptionDeviceList, sizeof(mExceptionDeviceList));
+
+ *DeviceInfoCount = ARRAY_SIZE(mExceptionDeviceList);
+
+ return EFI_SUCCESS;
+}
+
+EDKII_PLATFORM_VTD_POLICY_PROTOCOL mPlatformVTdSample = {
+ EDKII_PLATFORM_VTD_POLICY_PROTOCOL_REVISION,
+ PlatformVTdGetDeviceId,
+ PlatformVTdGetExceptionDeviceList,
+};
+
+/**
+ Platform VTd sample driver.
+
+ @param[in] ImageHandle ImageHandle of the loaded driver
+ @param[in] SystemTable Pointer to the System Table
+
+ @retval EFI_SUCCESS The Protocol is installed.
+ @retval EFI_OUT_OF_RESOURCES Not enough resources available to initialize driver.
+ @retval EFI_DEVICE_ERROR A device error occurred attempting to initialize the driver.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformVTdSampleInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ Handle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Handle,
+ &gEdkiiPlatformVTdPolicyProtocolGuid, &mPlatformVTdSample,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
diff --git a/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.inf b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.inf
new file mode 100644
index 0000000..9895bc2
--- /dev/null
+++ b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.inf
@@ -0,0 +1,59 @@
+## @file
+# Platform VTd Sample driver.
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PlatformVTdSampleDxe
+ MODULE_UNI_FILE = PlatformVTdSampleDxe.uni
+ FILE_GUID = 5DFAE03E-9C19-4996-85BF-65297BD4137F
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = PlatformVTdSampleInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+#
+
+[Sources]
+ PlatformVTdSampleDxe.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ IntelSiliconPkg/IntelSiliconPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ UefiDriverEntryPoint
+ UefiBootServicesTableLib
+ BaseLib
+ IoLib
+ PciSegmentLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ DevicePathLib
+
+[Protocols]
+ gEdkiiPlatformVTdPolicyProtocolGuid ## PRODUCES
+ gEfiPciIoProtocolGuid ## CONSUMES
+
+[Depex]
+ gEfiPciRootBridgeIoProtocolGuid
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ PlatformVTdSampleDxeExtra.uni
+
diff --git a/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.uni b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.uni
new file mode 100644
index 0000000..231b98d
--- /dev/null
+++ b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxe.uni
@@ -0,0 +1,20 @@
+// /** @file
+// PlatformVTdSampleDxe Module Localized Abstract and Description Content
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials are
+// licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+//
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Platform VTd Sample DXE Driver."
+
+#string STR_MODULE_DESCRIPTION #language en-US "This driver provides sample on how to produce Platform VTd policy protocol."
+
--git a/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxeExtra.uni b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxeExtra.uni
new file mode 100644
index 0000000..fd29c26
--- /dev/null
+++ b/IntelSiliconPkg/PlatformVTdSampleDxe/PlatformVTdSampleDxeExtra.uni
@@ -0,0 +1,20 @@
+// /** @file
+// PlatformVTdSampleDxe Localized Strings and Content
+//
+// Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials are
+// licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+//
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"Platform VTd Sample DXE Driver"
+
+
--
2.7.4.windows.1
next prev parent reply other threads:[~2017-07-18 7:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-18 7:51 [PATCH 0/7] Add VTd as IOMMU for UEFI Jiewen Yao
2017-07-18 7:51 ` [PATCH 1/7] IntelSiliconPkg/Include: Add VTD industry standard Jiewen Yao
2017-07-18 7:51 ` [PATCH 2/7] IntelSiliconPkg/Include: Add PlatformVtdPolicy Protocol Jiewen Yao
2017-07-26 8:36 ` Zeng, Star
2017-07-18 7:51 ` [PATCH 3/7] IntelSiliconPkg/Dec: Add ProtocolGuid Jiewen Yao
2017-07-18 7:51 ` [PATCH 4/7] IntelSiliconPkg: Add VTd driver Jiewen Yao
2017-07-18 7:51 ` [PATCH 5/7] IntelSiliconPkg/dsc: Add Vtd driver Jiewen Yao
2017-07-18 7:51 ` Jiewen Yao [this message]
2017-07-18 7:51 ` [PATCH 7/7] IntelSiliconPkg/dsc: Add PlatformVtd sample driver Jiewen Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1500364297-17072-7-git-send-email-jiewen.yao@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox