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