]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg.c
1) Add PcatSingleSegmentPciCfg2Pei in MdeModulePkg.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / PcatSingleSegmentPciCfgPei / PciCfg.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13
14 Module Name:
15
16 PciCfg.c
17
18 Abstract:
19
20 Single Segment Pci Configuration PPI
21
22 Revision History
23
24 --*/
25
26 #include "PciCfgInternal.h"
27
28
29 /**
30 PCI read operation.
31
32 @param PeiServices An indirect pointer to the PEI Services Table
33 published by the PEI Foundation.
34 @param This Pointer to local data for the interface.
35 @param Width The width of the access. Enumerated in bytes.
36 @param Address The physical address of the access.
37 @param Buffer A pointer to the buffer of data.
38
39 @retval EFI_SUCCESS The function completed successfully.
40 @retval EFI_INVALID_PARAMETER Unsupported width
41 enumeration.
42
43 **/
44 EFI_STATUS
45 EFIAPI
46 PciCfgRead (
47 IN EFI_PEI_SERVICES **PeiServices,
48 IN EFI_PEI_PCI_CFG_PPI *This,
49 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
50 IN UINT64 Address,
51 IN OUT VOID *Buffer
52 )
53 {
54 UINTN PciLibAddress;
55
56 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
57 switch (Width) {
58 case EfiPeiPciCfgWidthUint8:
59 * (UINT8 *) Buffer = PciRead8 (PciLibAddress);
60 break;
61
62 case EfiPeiPciCfgWidthUint16:
63 * (UINT16 *) Buffer = PciRead16 (PciLibAddress);
64 break;
65
66 case EfiPeiPciCfgWidthUint32:
67 * (UINT32 *) Buffer = PciRead32 (PciLibAddress);
68 break;
69
70 default:
71 return EFI_INVALID_PARAMETER;
72 }
73 return EFI_SUCCESS;
74 }
75
76
77 /**
78 PCI write operation.
79
80 @param PeiServices An indirect pointer to the PEI Services Table
81 published by the PEI Foundation.
82 @param This Pointer to local data for the interface.
83 @param Width The width of the access. Enumerated in bytes.
84 @param Address The physical address of the access.
85 @param Buffer A pointer to the buffer of data.
86
87 @retval EFI_SUCCESS The function completed successfully.
88
89
90 @retval EFI_INVALID_PARAMETER Unsupported width
91 enumeration.
92
93 **/
94 EFI_STATUS
95 EFIAPI
96 PciCfgWrite (
97 IN EFI_PEI_SERVICES **PeiServices,
98 IN EFI_PEI_PCI_CFG_PPI *This,
99 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
100 IN UINT64 Address,
101 IN OUT VOID *Buffer
102 )
103 {
104 UINTN PciLibAddress;
105
106 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
107 switch (Width) {
108 case EfiPeiPciCfgWidthUint8:
109 PciWrite8 (PciLibAddress, *(UINT8 *) Buffer);
110 break;
111
112 case EfiPeiPciCfgWidthUint16:
113 PciWrite16 (PciLibAddress, *(UINT16 *) Buffer);
114 break;
115
116 case EfiPeiPciCfgWidthUint32:
117 PciWrite32 (PciLibAddress, *(UINT32 *) Buffer);
118 break;
119
120 default:
121 return EFI_INVALID_PARAMETER;
122 }
123 return EFI_SUCCESS;
124 }
125
126
127 /**
128 PCI read-modify-write operation.
129
130 @param PeiServices An indirect pointer to the PEI Services Table
131 published by the PEI Foundation.
132 @param This Pointer to local data for the interface.
133 @param Width The width of the access. Enumerated in bytes.
134 @param Address The physical address of the access.
135 @param SetBits Value of the bits to set.
136 @param ClearBits Value of the bits to clear.
137
138 @retval EFI_SUCCESS The function completed successfully.
139 @retval EFI_INVALID_PARAMETER Unsupported width
140 enumeration.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 PciCfgModify (
146 IN EFI_PEI_SERVICES **PeiServices,
147 IN EFI_PEI_PCI_CFG_PPI *This,
148 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,
149 IN UINT64 Address,
150 IN UINTN SetBits,
151 IN UINTN ClearBits
152 )
153 {
154 UINTN PciLibAddress;
155
156 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);
157 switch (Width) {
158 case EfiPeiPciCfgWidthUint8:
159 PciAndThenOr8 (PciLibAddress, (UINT8)~ClearBits, (UINT8)SetBits);
160 break;
161
162 case EfiPeiPciCfgWidthUint16:
163 PciAndThenOr16 (PciLibAddress, (UINT16)~ClearBits, (UINT16)SetBits);
164 break;
165
166 case EfiPeiPciCfgWidthUint32:
167 PciAndThenOr32 (PciLibAddress, (UINT32)~ClearBits, (UINT32)SetBits);
168 break;
169
170 default:
171 return EFI_INVALID_PARAMETER;
172 }
173 return EFI_SUCCESS;
174 }