1/** @file
2  Power management support fucntions implementation for PCI Bus module.
3
4Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution.  The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#include "PciBus.h"
16
17/**
18  This function is intended to turn off PWE assertion and
19  put the device to D0 state if the device supports
20  PCI Power Management.
21
22  @param PciIoDevice      PCI device instance.
23
24  @retval EFI_UNSUPPORTED PCI Device does not support power management.
25  @retval EFI_SUCCESS     Turned off PWE successfully.
26
27**/
28EFI_STATUS
29ResetPowerManagementFeature (
30  IN PCI_IO_DEVICE *PciIoDevice
31  )
32{
33  EFI_STATUS  Status;
34  UINT8       PowerManagementRegBlock;
35  UINT16      PowerManagementCSR;
36
37  PowerManagementRegBlock = 0;
38
39  Status = LocateCapabilityRegBlock (
40            PciIoDevice,
41            EFI_PCI_CAPABILITY_ID_PMI,
42            &PowerManagementRegBlock,
43            NULL
44            );
45
46  if (EFI_ERROR (Status)) {
47    return EFI_UNSUPPORTED;
48  }
49
50  //
51  // Turn off the PWE assertion and put the device into D0 State
52  //
53
54  //
55  // Read PMCSR
56  //
57  Status = PciIoDevice->PciIo.Pci.Read (
58                                    &PciIoDevice->PciIo,
59                                    EfiPciIoWidthUint16,
60                                    PowerManagementRegBlock + 4,
61                                    1,
62                                    &PowerManagementCSR
63                                    );
64
65  if (!EFI_ERROR (Status)) {
66    //
67    // Clear PME_Status bit
68    //
69    PowerManagementCSR |= BIT15;
70    //
71    // Clear PME_En bit. PowerState = D0.
72    //
73    PowerManagementCSR &= ~(BIT8 | BIT1 | BIT0);
74
75    //
76    // Write PMCSR
77    //
78    Status = PciIoDevice->PciIo.Pci.Write (
79                                      &PciIoDevice->PciIo,
80                                      EfiPciIoWidthUint16,
81                                      PowerManagementRegBlock + 4,
82                                      1,
83                                      &PowerManagementCSR
84                                      );
85  }
86  return Status;
87}
88
89