3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
5 All rights reserved. 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
,
46 Width
= (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH
) (Width
& 0x03);
47 Stride
= (UINTN
)1 << Width
;
48 InStride
= InStrideFlag
? Stride
: 0;
49 OutStride
= OutStrideFlag
? Stride
: 0;
52 // Loop for each iteration and move the data
55 case EfiPciWidthUint8
:
56 for (;Count
> 0; Count
--, In
.buf
+= InStride
, Out
.buf
+= OutStride
) {
60 case EfiPciWidthUint16
:
61 for (;Count
> 0; Count
--, In
.buf
+= InStride
, Out
.buf
+= OutStride
) {
65 case EfiPciWidthUint32
:
66 for (;Count
> 0; Count
--, In
.buf
+= InStride
, Out
.buf
+= OutStride
) {
71 return EFI_INVALID_PARAMETER
;
78 PciRootBridgeIoPciRW (
79 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
81 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
82 IN UINT64 UserAddress
,
84 IN OUT VOID
*UserBuffer
91 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
93 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
94 @param Width Signifies the width of the memory operations.
95 @param Address The base address of the memory operations.
96 @param Count The number of memory operations to perform.
97 @param Buffer For read operations, the destination buffer to store the results. For write
98 operations, the source buffer to write data from.
100 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
101 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
102 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
107 PciRootBridgeIoMemRead (
108 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
109 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
115 PCI_ROOT_BRIDGE
*Private
;
120 if ( Buffer
== NULL
) {
121 return EFI_INVALID_PARAMETER
;
124 Private
= INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This
);
126 if (!PciRootBridgeMemAddressValid (Private
, Address
)) {
127 return EFI_INVALID_PARAMETER
;
130 AlignMask
= (1 << (Width
& 0x03)) - 1;
131 if (Address
& AlignMask
) {
132 return EFI_INVALID_PARAMETER
;
136 Out
.buf
= (VOID
*)(UINTN
) Address
;
139 case EfiPciWidthUint8
:
140 case EfiPciWidthUint16
:
141 case EfiPciWidthUint32
:
142 case EfiPciWidthUint64
:
143 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, TRUE
, Out
);
145 case EfiPciWidthFifoUint8
:
146 case EfiPciWidthFifoUint16
:
147 case EfiPciWidthFifoUint32
:
148 case EfiPciWidthFifoUint64
:
149 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, FALSE
, Out
);
151 case EfiPciWidthFillUint8
:
152 case EfiPciWidthFillUint16
:
153 case EfiPciWidthFillUint32
:
154 case EfiPciWidthFillUint64
:
155 return PciRootBridgeIoMemRW (Width
, Count
, FALSE
, In
, TRUE
, Out
);
161 return EFI_INVALID_PARAMETER
;
167 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
169 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
170 @param Width Signifies the width of the memory operations.
171 @param Address The base address of the memory operations.
172 @param Count The number of memory operations to perform.
173 @param Buffer For read operations, the destination buffer to store the results. For write
174 operations, the source buffer to write data from.
176 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
177 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
178 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
183 PciRootBridgeIoMemWrite (
184 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
185 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
191 PCI_ROOT_BRIDGE
*Private
;
196 if ( Buffer
== NULL
) {
197 return EFI_INVALID_PARAMETER
;
200 Private
= INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This
);
202 if (!PciRootBridgeMemAddressValid (Private
, Address
)) {
203 return EFI_INVALID_PARAMETER
;
206 AlignMask
= (1 << (Width
& 0x03)) - 1;
207 if (Address
& AlignMask
) {
208 return EFI_INVALID_PARAMETER
;
211 In
.buf
= (VOID
*)(UINTN
) Address
;
215 case EfiPciWidthUint8
:
216 case EfiPciWidthUint16
:
217 case EfiPciWidthUint32
:
218 case EfiPciWidthUint64
:
219 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, TRUE
, Out
);
221 case EfiPciWidthFifoUint8
:
222 case EfiPciWidthFifoUint16
:
223 case EfiPciWidthFifoUint32
:
224 case EfiPciWidthFifoUint64
:
225 return PciRootBridgeIoMemRW (Width
, Count
, FALSE
, In
, TRUE
, Out
);
227 case EfiPciWidthFillUint8
:
228 case EfiPciWidthFillUint16
:
229 case EfiPciWidthFillUint32
:
230 case EfiPciWidthFillUint64
:
231 return PciRootBridgeIoMemRW (Width
, Count
, TRUE
, In
, FALSE
, Out
);
237 return EFI_INVALID_PARAMETER
;
241 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
243 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
244 @param Width Signifies the width of the memory operations.
245 @param Address The base address of the memory operations.
246 @param Count The number of memory operations to perform.
247 @param Buffer For read operations, the destination buffer to store the results. For write
248 operations, the source buffer to write data from.
250 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
251 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
252 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
257 PciRootBridgeIoPciRead (
258 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
259 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
265 if (Buffer
== NULL
) {
266 return EFI_INVALID_PARAMETER
;
269 return PciRootBridgeIoPciRW (This
, FALSE
, Width
, Address
, Count
, Buffer
);
275 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.
277 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
278 @param Width Signifies the width of the memory operations.
279 @param Address The base address of the memory operations.
280 @param Count The number of memory operations to perform.
281 @param Buffer For read operations, the destination buffer to store the results. For write
282 operations, the source buffer to write data from.
284 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.
285 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
286 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
291 PciRootBridgeIoPciWrite (
292 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*This
,
293 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width
,
299 if (Buffer
== NULL
) {
300 return EFI_INVALID_PARAMETER
;
303 return PciRootBridgeIoPciRW (This
, TRUE
, Width
, Address
, Count
, Buffer
);