3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PciEmulation.h"
18 PciRootBridgeMemAddressValid (
19 IN PCI_ROOT_BRIDGE
*Private
,
23 if ((Address
>= Private
->MemoryStart
) && (Address
< (Private
->MemoryStart
+ Private
->MemorySize
))) {
32 PciRootBridgeIoMemRW (
33 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
35 IN BOOLEAN InStrideFlag
,
37 IN BOOLEAN OutStrideFlag
,
45 Width
= (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
46 Stride
= (UINTN
)1 << Width
;
47 InStride
= InStrideFlag
? Stride
: 0;
48 OutStride
= OutStrideFlag
? Stride
: 0;
51 // Loop for each iteration and move the data
54 case EfiPciWidthUint8
:
55 for (;Count
> 0; Count
--, In
.Buffer
+= InStride
, Out
.Buffer
+= OutStride
) {
59 case EfiPciWidthUint16
:
60 for (;Count
> 0; Count
--, In
.Buffer
+= InStride
, Out
.Buffer
+= OutStride
) {
64 case EfiPciWidthUint32
:
65 for (;Count
> 0; Count
--, In
.Buffer
+= InStride
, Out
.Buffer
+= OutStride
) {
70 return EFI_INVALID_PARAMETER
;
77 PciRootBridgeIoPciRW (
78 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
80 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
81 IN UINT64 UserAddress
,
83 IN OUT VOID
*UserBuffer
90 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
92 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
93 @param Width Signifies the width of the memory operations.
94 @param Address The base address of the memory operations.
95 @param Count The number of memory operations to perform.
96 @param Buffer For read operations, the destination buffer to store the results. For write
97 operations, the source buffer to write data from.
99 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
100 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
101 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
106 PciRootBridgeIoMemRead (
107 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
108 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
114 PCI_ROOT_BRIDGE
*Private
;
119 if ( Buffer
== NULL
) {
120 return EFI_INVALID_PARAMETER
;
123 Private
= INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This
);
125 if (!PciRootBridgeMemAddressValid (Private
, Address
)) {
126 return EFI_INVALID_PARAMETER
;
129 AlignMask
= (1 << (Width
& 0x03)) - 1;
130 if (Address
& AlignMask
) {
131 return EFI_INVALID_PARAMETER
;
135 Out
.Buffer
= (VOID
*)(UINTN
) Address
;
138 case EfiPciWidthUint8
:
139 case EfiPciWidthUint16
:
140 case EfiPciWidthUint32
:
141 case EfiPciWidthUint64
:
142 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, TRUE
, Out
);
144 case EfiPciWidthFifoUint8
:
145 case EfiPciWidthFifoUint16
:
146 case EfiPciWidthFifoUint32
:
147 case EfiPciWidthFifoUint64
:
148 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, FALSE
, Out
);
150 case EfiPciWidthFillUint8
:
151 case EfiPciWidthFillUint16
:
152 case EfiPciWidthFillUint32
:
153 case EfiPciWidthFillUint64
:
154 return PciRootBridgeIoMemRW (Width
, Count
, FALSE
, In
, TRUE
, Out
);
160 return EFI_INVALID_PARAMETER
;
164 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
166 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
167 @param Width Signifies the width of the memory operations.
168 @param Address The base address of the memory operations.
169 @param Count The number of memory operations to perform.
170 @param Buffer For read operations, the destination buffer to store the results. For write
171 operations, the source buffer to write data from.
173 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
174 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
175 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
180 PciRootBridgeIoMemWrite (
181 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
182 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
188 PCI_ROOT_BRIDGE
*Private
;
193 if ( Buffer
== NULL
) {
194 return EFI_INVALID_PARAMETER
;
197 Private
= INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This
);
199 if (!PciRootBridgeMemAddressValid (Private
, Address
)) {
200 return EFI_INVALID_PARAMETER
;
203 AlignMask
= (1 << (Width
& 0x03)) - 1;
204 if (Address
& AlignMask
) {
205 return EFI_INVALID_PARAMETER
;
208 In
.Buffer
= (VOID
*)(UINTN
) Address
;
212 case EfiPciWidthUint8
:
213 case EfiPciWidthUint16
:
214 case EfiPciWidthUint32
:
215 case EfiPciWidthUint64
:
216 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, TRUE
, Out
);
218 case EfiPciWidthFifoUint8
:
219 case EfiPciWidthFifoUint16
:
220 case EfiPciWidthFifoUint32
:
221 case EfiPciWidthFifoUint64
:
222 return PciRootBridgeIoMemRW (Width
, Count
, FALSE
, In
, TRUE
, Out
);
224 case EfiPciWidthFillUint8
:
225 case EfiPciWidthFillUint16
:
226 case EfiPciWidthFillUint32
:
227 case EfiPciWidthFillUint64
:
228 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, FALSE
, Out
);
234 return EFI_INVALID_PARAMETER
;
238 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
240 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
241 @param Width Signifies the width of the memory operations.
242 @param Address The base address of the memory operations.
243 @param Count The number of memory operations to perform.
244 @param Buffer For read operations, the destination buffer to store the results. For write
245 operations, the source buffer to write data from.
247 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
248 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
249 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
254 PciRootBridgeIoPciRead (
255 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
256 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
262 if (Buffer
== NULL
) {
263 return EFI_INVALID_PARAMETER
;
266 return PciRootBridgeIoPciRW (This
, FALSE
, Width
, Address
, Count
, Buffer
);
270 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
272 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
273 @param Width Signifies the width of the memory operations.
274 @param Address The base address of the memory operations.
275 @param Count The number of memory operations to perform.
276 @param Buffer For read operations, the destination buffer to store the results. For write
277 operations, the source buffer to write data from.
279 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
280 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
281 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
286 PciRootBridgeIoPciWrite (
287 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
288 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
294 if (Buffer
== NULL
) {
295 return EFI_INVALID_PARAMETER
;
298 return PciRootBridgeIoPciRW (This
, TRUE
, Width
, Address
, Count
, Buffer
);