]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c
MdeModulePkg/NonDiscoverablePciDeviceDxe: expose unique B/D/F identifiers
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NonDiscoverablePciDeviceDxe / NonDiscoverablePciDeviceDxe.c
index ee765d7a5d9c2422eb48ef0f26c2242c853bc03d..2483c7296912ea5d87044e2b52a9f4c345b9d0c2 100644 (file)
 \r
 #include <Protocol/DriverBinding.h>\r
 \r
+#define MAX_NON_DISCOVERABLE_PCI_DEVICE_ID   (32 * 256)\r
+\r
+STATIC UINTN               mUniqueIdCounter = 0;\r
+EFI_CPU_ARCH_PROTOCOL      *mCpu;\r
+\r
 //\r
 // We only support the following device types\r
 //\r
 STATIC\r
 CONST EFI_GUID * CONST\r
-SupportedNonDiscoverableDevices [] = {\r
+SupportedNonDiscoverableDevices[] = {\r
   &gEdkiiNonDiscoverableAhciDeviceGuid,\r
   &gEdkiiNonDiscoverableEhciDeviceGuid,\r
   &gEdkiiNonDiscoverableNvmeDeviceGuid,\r
@@ -47,6 +52,19 @@ SupportedNonDiscoverableDevices [] = {
 //   -  6.3 Protocol Handler Services\r
 //\r
 \r
+/**\r
+  Supported function of Driver Binding protocol for this driver.\r
+  Test to see if this driver supports ControllerHandle.\r
+\r
+  @param This                   Protocol instance pointer.\r
+  @param DeviceHandle           Handle of device to test.\r
+  @param RemainingDevicePath    A pointer to the device path.\r
+                                it should be ignored by device driver.\r
+\r
+  @retval EFI_SUCCESS           This driver supports this device.\r
+  @retval other                 This driver does not support this device.\r
+\r
+**/\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -69,14 +87,7 @@ NonDiscoverablePciDeviceSupported (
     return Status;\r
   }\r
 \r
-  //\r
-  // Restricted to DMA coherent for now\r
-  //\r
   Status = EFI_UNSUPPORTED;\r
-  if (Device->DmaType != NonDiscoverableDeviceDmaTypeCoherent) {\r
-    goto CloseProtocol;\r
-  }\r
-\r
   for (Idx = 0; Idx < ARRAY_SIZE (SupportedNonDiscoverableDevices); Idx++) {\r
     if (CompareGuid (Device->Type, SupportedNonDiscoverableDevices [Idx])) {\r
       Status = EFI_SUCCESS;\r
@@ -108,6 +119,19 @@ CloseProtocol:
   return Status;\r
 }\r
 \r
+/**\r
+  This routine is called right after the .Supported() called and\r
+  Start this driver on ControllerHandle.\r
+\r
+  @param This                   Protocol instance pointer.\r
+  @param DeviceHandle           Handle of device to bind driver to.\r
+  @param RemainingDevicePath    A pointer to the device path.\r
+                                it should be ignored by device driver.\r
+\r
+  @retval EFI_SUCCESS           This driver is added to this device.\r
+  @retval other                 Some error occurs when binding this driver to this device.\r
+\r
+**/\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -120,6 +144,11 @@ NonDiscoverablePciDeviceStart (
   NON_DISCOVERABLE_PCI_DEVICE   *Dev;\r
   EFI_STATUS                    Status;\r
 \r
+  ASSERT (mUniqueIdCounter < MAX_NON_DISCOVERABLE_PCI_DEVICE_ID);\r
+  if (mUniqueIdCounter >= MAX_NON_DISCOVERABLE_PCI_DEVICE_ID) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
   Dev = AllocateZeroPool (sizeof *Dev);\r
   if (Dev == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -146,6 +175,8 @@ NonDiscoverablePciDeviceStart (
     goto CloseProtocol;\r
   }\r
 \r
+  Dev->UniqueId = mUniqueIdCounter++;\r
+\r
   return EFI_SUCCESS;\r
 \r
 CloseProtocol:\r
@@ -158,7 +189,18 @@ FreeDev:
   return Status;\r
 }\r
 \r
+/**\r
+  Stop this driver on ControllerHandle.\r
 \r
+  @param This               Protocol instance pointer.\r
+  @param DeviceHandle       Handle of device to stop driver on.\r
+  @param NumberOfChildren   Not used.\r
+  @param ChildHandleBuffer  Not used.\r
+\r
+  @retval EFI_SUCCESS   This driver is removed from this device.\r
+  @retval other         Some error occurs when removing this driver from this device.\r
+\r
+**/\r
 STATIC\r
 EFI_STATUS\r
 EFIAPI\r
@@ -214,9 +256,16 @@ STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {
   NULL\r
 };\r
 \r
-//\r
-// Entry point of this driver.\r
-//\r
+/**\r
+  Entry point of this driver.\r
+\r
+  @param  ImageHandle     Image handle this driver.\r
+  @param  SystemTable     Pointer to the System Table.\r
+\r
+  @retval EFI_SUCCESS     The entry point is executed successfully.\r
+  @retval other           Some error occurred when executing this entry point.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 NonDiscoverablePciDeviceDxeEntryPoint (\r
@@ -224,6 +273,11 @@ NonDiscoverablePciDeviceDxeEntryPoint (
   IN EFI_SYSTEM_TABLE *SystemTable\r
   )\r
 {\r
+  EFI_STATUS      Status;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu);\r
+  ASSERT_EFI_ERROR(Status);\r
+\r
   return EfiLibInstallDriverBindingComponentName2 (\r
            ImageHandle,\r
            SystemTable,\r