]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/PciBusDxe/PciPowerManagement.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciPowerManagement.c
1 /** @file
2 Power management support functions implementation for PCI Bus module.
3
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PciBus.h"
10
11 /**
12 This function is intended to turn off PWE assertion and
13 put the device to D0 state if the device supports
14 PCI Power Management.
15
16 @param PciIoDevice PCI device instance.
17
18 @retval EFI_UNSUPPORTED PCI Device does not support power management.
19 @retval EFI_SUCCESS Turned off PWE successfully.
20
21 **/
22 EFI_STATUS
23 ResetPowerManagementFeature (
24 IN PCI_IO_DEVICE *PciIoDevice
25 )
26 {
27 EFI_STATUS Status;
28 UINT8 PowerManagementRegBlock;
29 UINT16 PowerManagementCSR;
30
31 PowerManagementRegBlock = 0;
32
33 Status = LocateCapabilityRegBlock (
34 PciIoDevice,
35 EFI_PCI_CAPABILITY_ID_PMI,
36 &PowerManagementRegBlock,
37 NULL
38 );
39
40 if (EFI_ERROR (Status)) {
41 return EFI_UNSUPPORTED;
42 }
43
44 //
45 // Turn off the PWE assertion and put the device into D0 State
46 //
47
48 //
49 // Read PMCSR
50 //
51 Status = PciIoDevice->PciIo.Pci.Read (
52 &PciIoDevice->PciIo,
53 EfiPciIoWidthUint16,
54 PowerManagementRegBlock + 4,
55 1,
56 &PowerManagementCSR
57 );
58
59 if (!EFI_ERROR (Status)) {
60 //
61 // Clear PME_Status bit
62 //
63 PowerManagementCSR |= BIT15;
64 //
65 // Clear PME_En bit. PowerState = D0.
66 //
67 PowerManagementCSR &= ~(BIT8 | BIT1 | BIT0);
68
69 //
70 // Write PMCSR
71 //
72 Status = PciIoDevice->PciIo.Pci.Write (
73 &PciIoDevice->PciIo,
74 EfiPciIoWidthUint16,
75 PowerManagementRegBlock + 4,
76 1,
77 &PowerManagementCSR
78 );
79 }
80
81 return Status;
82 }