]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/PciBusNoEnumerationDxe/PciPowerManagement.c
MdeModulePkg/BDS: Fix a buffer overflow bug
[mirror_edk2.git] / DuetPkg / PciBusNoEnumerationDxe / PciPowerManagement.c
index 5c2386c4bf17a85f98ec22889bc27fe15f6ce3bb..eaeaeb762dcac28ee5cb10cee1ea77e3c1722ef3 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2005 - 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -21,9 +21,10 @@ Revision History
 \r
 --*/\r
 \r
-#include "Pcibus.h"\r
+#include "PciBus.h"\r
 \r
 EFI_STATUS\r
+EFIAPI\r
 ResetPowerManagementFeature (\r
   IN PCI_IO_DEVICE *PciIoDevice\r
   )\r
@@ -45,7 +46,7 @@ Returns:
 {\r
   EFI_STATUS  Status;\r
   UINT8       PowerManagementRegBlock;\r
-  UINT16      PMCSR;\r
+  UINT16      PowerManagementCSR;\r
 \r
   PowerManagementRegBlock = 0;\r
 \r
@@ -63,18 +64,37 @@ Returns:
   //\r
   // Turn off the PWE assertion and put the device into D0 State\r
   //\r
-  PMCSR = 0x8000;\r
 \r
   //\r
-  // Write PMCSR\r
+  // Read PMCSR\r
   //\r
-  PciIoDevice->PciIo.Pci.Write (\r
-                          &PciIoDevice->PciIo,\r
-                          EfiPciIoWidthUint16,\r
-                          PowerManagementRegBlock + 4,\r
-                          1,\r
-                          &PMCSR\r
-                          );\r
-\r
-  return EFI_SUCCESS;\r
+  Status = PciIoDevice->PciIo.Pci.Read (\r
+                                    &PciIoDevice->PciIo,\r
+                                    EfiPciIoWidthUint16,\r
+                                    PowerManagementRegBlock + 4,\r
+                                    1,\r
+                                    &PowerManagementCSR\r
+                                    );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Clear PME_Status bit\r
+    //\r
+    PowerManagementCSR |= BIT15;\r
+    //\r
+    // Clear PME_En bit. PowerState = D0.\r
+    //\r
+    PowerManagementCSR &= ~(BIT8 | BIT1 | BIT0);\r
+\r
+    //\r
+    // Write PMCSR\r
+    //\r
+    Status = PciIoDevice->PciIo.Pci.Write (\r
+                                      &PciIoDevice->PciIo,\r
+                                      EfiPciIoWidthUint16,\r
+                                      PowerManagementRegBlock + 4,\r
+                                      1,\r
+                                      &PowerManagementCSR\r
+                                      );\r
+  }\r
+  return Status;\r
 }\r