]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/PciHostBridgeDxe/PciRootBridgeIo.c
NetworkPkg: Update package DSC file.
[mirror_edk2.git] / PcAtChipsetPkg / PciHostBridgeDxe / PciRootBridgeIo.c
CommitLineData
21b404d1 1/** @file\r
2 PCI Root Bridge Io Protocol implementation\r
3\r
3d78c020 4Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
18c97f53 5This program and the accompanying materials are\r
6licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
21b404d1 12\r
13**/ \r
14\r
15#include "PciHostBridge.h"\r
1fd376d9 16#include "IoFifo.h"\r
21b404d1 17\r
18typedef struct {\r
19 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR SpaceDesp[TypeMax];\r
20 EFI_ACPI_END_TAG_DESCRIPTOR EndDesp;\r
21} RESOURCE_CONFIGURATION;\r
22\r
23RESOURCE_CONFIGURATION Configuration = {\r
24 {{0x8A, 0x2B, 1, 0, 0, 0, 0, 0, 0, 0},\r
25 {0x8A, 0x2B, 0, 0, 0, 32, 0, 0, 0, 0}, \r
26 {0x8A, 0x2B, 0, 0, 6, 32, 0, 0, 0, 0},\r
27 {0x8A, 0x2B, 0, 0, 0, 64, 0, 0, 0, 0},\r
28 {0x8A, 0x2B, 0, 0, 6, 64, 0, 0, 0, 0},\r
29 {0x8A, 0x2B, 2, 0, 0, 0, 0, 0, 0, 0}},\r
30 {0x79, 0}\r
31};\r
32\r
33//\r
34// Protocol Member Function Prototypes\r
35//\r
36\r
18c97f53 37/**\r
38 Polls an address in memory mapped I/O space until an exit condition is met, or \r
39 a timeout occurs. \r
40\r
41 This function provides a standard way to poll a PCI memory location. A PCI memory read\r
42 operation is performed at the PCI memory address specified by Address for the width specified\r
43 by Width. The result of this PCI memory read operation is stored in Result. This PCI memory\r
44 read operation is repeated until either a timeout of Delay 100 ns units has expired, or (Result &\r
45 Mask) is equal to Value.\r
46\r
47 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
48 @param[in] Width Signifies the width of the memory operations.\r
49 @param[in] Address The base address of the memory operations. The caller is\r
50 responsible for aligning Address if required.\r
51 @param[in] Mask Mask used for the polling criteria. Bytes above Width in Mask\r
52 are ignored. The bits in the bytes below Width which are zero in\r
53 Mask are ignored when polling the memory address.\r
54 @param[in] Value The comparison value used for the polling exit criteria.\r
55 @param[in] Delay The number of 100 ns units to poll. Note that timer available may\r
56 be of poorer granularity.\r
57 @param[out] Result Pointer to the last value read from the memory location.\r
58 \r
59 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.\r
60 @retval EFI_INVALID_PARAMETER Width is invalid.\r
61 @retval EFI_INVALID_PARAMETER Result is NULL.\r
62 @retval EFI_TIMEOUT Delay expired before a match occurred.\r
63 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
64\r
65**/\r
21b404d1 66EFI_STATUS\r
67EFIAPI\r
68RootBridgeIoPollMem ( \r
69 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
70 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
71 IN UINT64 Address,\r
72 IN UINT64 Mask,\r
73 IN UINT64 Value,\r
74 IN UINT64 Delay,\r
75 OUT UINT64 *Result\r
76 );\r
77 \r
18c97f53 78/**\r
79 Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is\r
80 satisfied or after a defined duration.\r
81\r
82 This function provides a standard way to poll a PCI I/O location. A PCI I/O read operation is\r
83 performed at the PCI I/O address specified by Address for the width specified by Width.\r
84 The result of this PCI I/O read operation is stored in Result. This PCI I/O read operation is\r
85 repeated until either a timeout of Delay 100 ns units has expired, or (Result & Mask) is equal\r
86 to Value.\r
87\r
88 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
89 @param[in] Width Signifies the width of the I/O operations.\r
90 @param[in] Address The base address of the I/O operations. The caller is responsible\r
91 for aligning Address if required.\r
92 @param[in] Mask Mask used for the polling criteria. Bytes above Width in Mask\r
93 are ignored. The bits in the bytes below Width which are zero in\r
94 Mask are ignored when polling the I/O address.\r
95 @param[in] Value The comparison value used for the polling exit criteria.\r
96 @param[in] Delay The number of 100 ns units to poll. Note that timer available may\r
97 be of poorer granularity.\r
98 @param[out] Result Pointer to the last value read from the memory location.\r
99 \r
100 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.\r
101 @retval EFI_INVALID_PARAMETER Width is invalid.\r
102 @retval EFI_INVALID_PARAMETER Result is NULL.\r
103 @retval EFI_TIMEOUT Delay expired before a match occurred.\r
104 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
105\r
106**/\r
21b404d1 107EFI_STATUS\r
108EFIAPI\r
109RootBridgeIoPollIo ( \r
110 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
111 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
112 IN UINT64 Address,\r
113 IN UINT64 Mask,\r
114 IN UINT64 Value,\r
115 IN UINT64 Delay,\r
116 OUT UINT64 *Result\r
117 );\r
118 \r
18c97f53 119/**\r
120 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.\r
121\r
122 The Mem.Read(), and Mem.Write() functions enable a driver to access PCI controller\r
123 registers in the PCI root bridge memory space.\r
124 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
125 any alignment and memory width restrictions that a PCI Root Bridge on a platform might require.\r
126\r
127 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
128 @param[in] Width Signifies the width of the memory operation.\r
129 @param[in] Address The base address of the memory operation. The caller is\r
130 responsible for aligning the Address if required.\r
131 @param[in] Count The number of memory operations to perform. Bytes moved is\r
132 Width size * Count, starting at Address.\r
133 @param[out] Buffer For read operations, the destination buffer to store the results. For\r
134 write operations, the source buffer to write data from.\r
135 \r
136 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
137 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
138 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
139 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
140\r
141**/\r
21b404d1 142EFI_STATUS\r
143EFIAPI\r
144RootBridgeIoMemRead (\r
145 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
146 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
147 IN UINT64 Address,\r
148 IN UINTN Count,\r
24115e44 149 OUT VOID *Buffer\r
21b404d1 150 );\r
151\r
18c97f53 152/**\r
153 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.\r
154\r
155 The Mem.Read(), and Mem.Write() functions enable a driver to access PCI controller\r
156 registers in the PCI root bridge memory space.\r
157 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
158 any alignment and memory width restrictions that a PCI Root Bridge on a platform might require.\r
159\r
160 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
161 @param[in] Width Signifies the width of the memory operation.\r
162 @param[in] Address The base address of the memory operation. The caller is\r
163 responsible for aligning the Address if required.\r
164 @param[in] Count The number of memory operations to perform. Bytes moved is\r
165 Width size * Count, starting at Address.\r
24115e44 166 @param[in] Buffer For read operations, the destination buffer to store the results. For\r
18c97f53 167 write operations, the source buffer to write data from.\r
168 \r
169 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
170 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
171 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
172 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
173**/\r
21b404d1 174EFI_STATUS\r
175EFIAPI\r
176RootBridgeIoMemWrite (\r
177 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
178 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
179 IN UINT64 Address,\r
180 IN UINTN Count,\r
24115e44 181 IN VOID *Buffer\r
21b404d1 182 );\r
183\r
18c97f53 184/**\r
185 Enables a PCI driver to access PCI controller registers in the PCI root bridge I/O space.\r
186\r
187 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
188 @param[in] Width Signifies the width of the memory operations.\r
24115e44 189 @param[in] UserAddress The base address of the I/O operation. The caller is responsible for\r
18c97f53 190 aligning the Address if required.\r
191 @param[in] Count The number of I/O operations to perform. Bytes moved is Width\r
192 size * Count, starting at Address.\r
24115e44 193 @param[out] UserBuffer For read operations, the destination buffer to store the results. For\r
18c97f53 194 write operations, the source buffer to write data from.\r
195 \r
196 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
197 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
198 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
199 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
200\r
201**/\r
21b404d1 202EFI_STATUS\r
203EFIAPI\r
204RootBridgeIoIoRead (\r
205 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
206 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
207 IN UINT64 UserAddress,\r
208 IN UINTN Count,\r
24115e44 209 OUT VOID *UserBuffer\r
21b404d1 210 );\r
211\r
18c97f53 212/**\r
213 Enables a PCI driver to access PCI controller registers in the PCI root bridge I/O space.\r
214\r
215 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
216 @param[in] Width Signifies the width of the memory operations.\r
24115e44 217 @param[in] UserAddress The base address of the I/O operation. The caller is responsible for\r
18c97f53 218 aligning the Address if required.\r
219 @param[in] Count The number of I/O operations to perform. Bytes moved is Width\r
220 size * Count, starting at Address.\r
24115e44 221 @param[in] UserBuffer For read operations, the destination buffer to store the results. For\r
18c97f53 222 write operations, the source buffer to write data from.\r
223 \r
224 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
225 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
226 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
227 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
228\r
229**/\r
21b404d1 230EFI_STATUS\r
231EFIAPI\r
232RootBridgeIoIoWrite (\r
233 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
234 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
235 IN UINT64 UserAddress,\r
236 IN UINTN Count,\r
24115e44 237 IN VOID *UserBuffer\r
21b404d1 238 );\r
239\r
18c97f53 240/**\r
241 Enables a PCI driver to copy one region of PCI root bridge memory space to another region of PCI\r
242 root bridge memory space.\r
243\r
244 The CopyMem() function enables a PCI driver to copy one region of PCI root bridge memory\r
245 space to another region of PCI root bridge memory space. This is especially useful for video scroll\r
246 operation on a memory mapped video buffer.\r
247 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
248 any alignment and memory width restrictions that a PCI root bridge on a platform might require.\r
249\r
250 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.\r
251 @param[in] Width Signifies the width of the memory operations.\r
252 @param[in] DestAddress The destination address of the memory operation. The caller is\r
253 responsible for aligning the DestAddress if required.\r
254 @param[in] SrcAddress The source address of the memory operation. The caller is\r
255 responsible for aligning the SrcAddress if required.\r
256 @param[in] Count The number of memory operations to perform. Bytes moved is\r
257 Width size * Count, starting at DestAddress and SrcAddress.\r
258 \r
259 @retval EFI_SUCCESS The data was copied from one memory region to another memory region.\r
260 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
261 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
262\r
263**/\r
21b404d1 264EFI_STATUS\r
265EFIAPI\r
266RootBridgeIoCopyMem (\r
267 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
268 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
269 IN UINT64 DestAddress,\r
270 IN UINT64 SrcAddress,\r
271 IN UINTN Count\r
272 );\r
273\r
18c97f53 274/**\r
275 Enables a PCI driver to access PCI controller registers in a PCI root bridge's configuration space.\r
276\r
277 The Pci.Read() and Pci.Write() functions enable a driver to access PCI configuration\r
278 registers for a PCI controller.\r
279 The PCI Configuration operations are carried out exactly as requested. The caller is responsible for\r
280 any alignment and PCI configuration width issues that a PCI Root Bridge on a platform might\r
281 require.\r
282\r
283 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
284 @param[in] Width Signifies the width of the memory operations.\r
285 @param[in] Address The address within the PCI configuration space for the PCI controller.\r
286 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
287 moved is Width size * Count, starting at Address.\r
288 @param[out] Buffer For read operations, the destination buffer to store the results. For\r
289 write operations, the source buffer to write data from.\r
290 \r
291 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
292 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
293 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
294 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
295\r
296**/\r
21b404d1 297EFI_STATUS\r
298EFIAPI\r
299RootBridgeIoPciRead (\r
300 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
301 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
302 IN UINT64 Address,\r
303 IN UINTN Count,\r
24115e44 304 OUT VOID *Buffer\r
21b404d1 305 );\r
306\r
18c97f53 307/**\r
308 Enables a PCI driver to access PCI controller registers in a PCI root bridge's configuration space.\r
309\r
310 The Pci.Read() and Pci.Write() functions enable a driver to access PCI configuration\r
311 registers for a PCI controller.\r
312 The PCI Configuration operations are carried out exactly as requested. The caller is responsible for\r
313 any alignment and PCI configuration width issues that a PCI Root Bridge on a platform might\r
314 require.\r
315\r
316 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
317 @param[in] Width Signifies the width of the memory operations.\r
318 @param[in] Address The address within the PCI configuration space for the PCI controller.\r
319 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
320 moved is Width size * Count, starting at Address.\r
24115e44 321 @param[in] Buffer For read operations, the destination buffer to store the results. For\r
18c97f53 322 write operations, the source buffer to write data from.\r
323 \r
324 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
325 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
326 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
327 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
328\r
329**/\r
21b404d1 330EFI_STATUS\r
331EFIAPI\r
332RootBridgeIoPciWrite (\r
333 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
334 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
335 IN UINT64 Address,\r
336 IN UINTN Count,\r
24115e44 337 IN VOID *Buffer\r
21b404d1 338 );\r
339\r
18c97f53 340/**\r
341 Provides the PCI controller-specific addresses required to access system memory from a\r
342 DMA bus master.\r
343\r
344 The Map() function provides the PCI controller specific addresses needed to access system\r
345 memory. This function is used to map system memory for PCI bus master DMA accesses.\r
346\r
347 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
348 @param[in] Operation Indicates if the bus master is going to read or write to system memory.\r
349 @param[in] HostAddress The system memory address to map to the PCI controller.\r
24115e44 350 @param[in, out] NumberOfBytes On input the number of bytes to map. On output the number of bytes that were mapped.\r
18c97f53 351 @param[out] DeviceAddress The resulting map address for the bus master PCI controller to use\r
352 to access the system memory's HostAddress.\r
353 @param[out] Mapping The value to pass to Unmap() when the bus master DMA operation is complete.\r
354 \r
355 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
356 @retval EFI_INVALID_PARAMETER Operation is invalid.\r
357 @retval EFI_INVALID_PARAMETER HostAddress is NULL.\r
358 @retval EFI_INVALID_PARAMETER NumberOfBytes is NULL.\r
359 @retval EFI_INVALID_PARAMETER DeviceAddress is NULL.\r
360 @retval EFI_INVALID_PARAMETER Mapping is NULL.\r
361 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
362 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
363 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
364\r
365**/\r
21b404d1 366EFI_STATUS\r
367EFIAPI\r
368RootBridgeIoMap (\r
369 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
370 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,\r
371 IN VOID *HostAddress,\r
372 IN OUT UINTN *NumberOfBytes,\r
373 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
374 OUT VOID **Mapping\r
375 );\r
376\r
18c97f53 377/**\r
378 Completes the Map() operation and releases any corresponding resources.\r
379\r
380 The Unmap() function completes the Map() operation and releases any corresponding resources.\r
381 If the operation was an EfiPciOperationBusMasterWrite or\r
382 EfiPciOperationBusMasterWrite64, the data is committed to the target system memory.\r
383 Any resources used for the mapping are freed. \r
384\r
385 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
386 @param[in] Mapping The mapping value returned from Map().\r
387 \r
388 @retval EFI_SUCCESS The range was unmapped.\r
389 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
390 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
391\r
392**/\r
21b404d1 393EFI_STATUS\r
394EFIAPI\r
395RootBridgeIoUnmap (\r
396 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
397 IN VOID *Mapping\r
398 );\r
399\r
18c97f53 400/**\r
401 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer or\r
402 EfiPciOperationBusMasterCommonBuffer64 mapping.\r
403 \r
404 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
405 @param Type This parameter is not used and must be ignored.\r
406 @param MemoryType The type of memory to allocate, EfiBootServicesData or EfiRuntimeServicesData.\r
407 @param Pages The number of pages to allocate.\r
408 @param HostAddress A pointer to store the base system memory address of the allocated range.\r
409 @param Attributes The requested bit mask of attributes for the allocated range. Only\r
410 the attributes EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE, EFI_PCI_ATTRIBUTE_MEMORY_CACHED, \r
411 and EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this function.\r
412 \r
413 @retval EFI_SUCCESS The requested memory pages were allocated.\r
414 @retval EFI_INVALID_PARAMETER MemoryType is invalid.\r
415 @retval EFI_INVALID_PARAMETER HostAddress is NULL.\r
416 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
417 MEMORY_WRITE_COMBINE, MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.\r
418 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
419\r
420**/\r
21b404d1 421EFI_STATUS\r
422EFIAPI\r
423RootBridgeIoAllocateBuffer (\r
424 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
425 IN EFI_ALLOCATE_TYPE Type,\r
426 IN EFI_MEMORY_TYPE MemoryType,\r
427 IN UINTN Pages,\r
428 OUT VOID **HostAddress,\r
429 IN UINT64 Attributes\r
430 );\r
431\r
18c97f53 432/**\r
433 Frees memory that was allocated with AllocateBuffer().\r
434\r
435 The FreeBuffer() function frees memory that was allocated with AllocateBuffer().\r
436\r
437 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
438 @param Pages The number of pages to free.\r
439 @param HostAddress The base system memory address of the allocated range.\r
440 \r
441 @retval EFI_SUCCESS The requested memory pages were freed.\r
442 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
443 was not allocated with AllocateBuffer().\r
444\r
445**/\r
21b404d1 446EFI_STATUS\r
447EFIAPI\r
448RootBridgeIoFreeBuffer (\r
449 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
450 IN UINTN Pages,\r
451 OUT VOID *HostAddress\r
452 );\r
453\r
18c97f53 454/**\r
455 Flushes all PCI posted write transactions from a PCI host bridge to system memory.\r
456\r
457 The Flush() function flushes any PCI posted write transactions from a PCI host bridge to system\r
458 memory. Posted write transactions are generated by PCI bus masters when they perform write\r
459 transactions to target addresses in system memory.\r
460 This function does not flush posted write transactions from any PCI bridges. A PCI controller\r
461 specific action must be taken to guarantee that the posted write transactions have been flushed from\r
462 the PCI controller and from all the PCI bridges into the PCI host bridge. This is typically done with\r
463 a PCI read transaction from the PCI controller prior to calling Flush().\r
464\r
465 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
466 \r
467 @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host\r
468 bridge to system memory.\r
469 @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI\r
470 host bridge due to a hardware error.\r
471\r
472**/\r
21b404d1 473EFI_STATUS\r
474EFIAPI\r
475RootBridgeIoFlush (\r
476 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This\r
477 );\r
478\r
18c97f53 479/**\r
480 Gets the attributes that a PCI root bridge supports setting with SetAttributes(), and the\r
481 attributes that a PCI root bridge is currently using. \r
482\r
483 The GetAttributes() function returns the mask of attributes that this PCI root bridge supports\r
484 and the mask of attributes that the PCI root bridge is currently using.\r
485\r
486 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
487 @param Supported A pointer to the mask of attributes that this PCI root bridge\r
488 supports setting with SetAttributes().\r
489 @param Attributes A pointer to the mask of attributes that this PCI root bridge is\r
490 currently using.\r
491 \r
492 @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI root\r
493 bridge supports is returned in Supports. If Attributes is\r
494 not NULL, then the attributes that the PCI root bridge is currently\r
495 using is returned in Attributes.\r
496 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.\r
497\r
498**/\r
21b404d1 499EFI_STATUS\r
500EFIAPI\r
501RootBridgeIoGetAttributes (\r
502 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
503 OUT UINT64 *Supported,\r
504 OUT UINT64 *Attributes\r
505 );\r
506\r
18c97f53 507/**\r
508 Sets attributes for a resource range on a PCI root bridge.\r
509\r
510 The SetAttributes() function sets the attributes specified in Attributes for the PCI root\r
511 bridge on the resource range specified by ResourceBase and ResourceLength. Since the\r
512 granularity of setting these attributes may vary from resource type to resource type, and from\r
513 platform to platform, the actual resource range and the one passed in by the caller may differ. As a\r
514 result, this function may set the attributes specified by Attributes on a larger resource range\r
515 than the caller requested. The actual range is returned in ResourceBase and\r
516 ResourceLength. The caller is responsible for verifying that the actual range for which the\r
517 attributes were set is acceptable.\r
518\r
519 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
520 @param[in] Attributes The mask of attributes to set. If the attribute bit\r
521 MEMORY_WRITE_COMBINE, MEMORY_CACHED, or\r
522 MEMORY_DISABLE is set, then the resource range is specified by\r
523 ResourceBase and ResourceLength. If\r
524 MEMORY_WRITE_COMBINE, MEMORY_CACHED, and\r
525 MEMORY_DISABLE are not set, then ResourceBase and\r
526 ResourceLength are ignored, and may be NULL.\r
24115e44 527 @param[in, out] ResourceBase A pointer to the base address of the resource range to be modified\r
18c97f53 528 by the attributes specified by Attributes.\r
24115e44 529 @param[in, out] ResourceLength A pointer to the length of the resource range to be modified by the\r
18c97f53 530 attributes specified by Attributes.\r
531 \r
532 @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in Resources.\r
533 @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be retrieved.\r
534 @retval EFI_INVALID_PARAMETER Invalid pointer of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r
535\r
536**/\r
21b404d1 537EFI_STATUS\r
538EFIAPI\r
539RootBridgeIoSetAttributes (\r
540 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
541 IN UINT64 Attributes,\r
542 IN OUT UINT64 *ResourceBase,\r
543 IN OUT UINT64 *ResourceLength \r
544 ); \r
545\r
18c97f53 546/**\r
547 Retrieves the current resource settings of this PCI root bridge in the form of a set of ACPI 2.0\r
548 resource descriptors.\r
549\r
550 There are only two resource descriptor types from the ACPI Specification that may be used to\r
551 describe the current resources allocated to a PCI root bridge. These are the QWORD Address\r
552 Space Descriptor (ACPI 2.0 Section 6.4.3.5.1), and the End Tag (ACPI 2.0 Section 6.4.2.8). The\r
553 QWORD Address Space Descriptor can describe memory, I/O, and bus number ranges for dynamic\r
554 or fixed resources. The configuration of a PCI root bridge is described with one or more QWORD\r
555 Address Space Descriptors followed by an End Tag.\r
556\r
557 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
558 @param[out] Resources A pointer to the ACPI 2.0 resource descriptors that describe the\r
559 current configuration of this PCI root bridge. The storage for the\r
560 ACPI 2.0 resource descriptors is allocated by this function. The\r
561 caller must treat the return buffer as read-only data, and the buffer\r
562 must not be freed by the caller.\r
563 \r
564 @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in Resources.\r
565 @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be retrieved.\r
566 @retval EFI_INVALID_PARAMETER Invalid pointer of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r
567\r
568**/\r
21b404d1 569EFI_STATUS\r
570EFIAPI\r
571RootBridgeIoConfiguration (\r
572 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
573 OUT VOID **Resources\r
574 );\r
575\r
576//\r
cac2ab95 577// Memory Controller Pci Root Bridge Io Module Variables\r
21b404d1 578//\r
cac2ab95 579EFI_METRONOME_ARCH_PROTOCOL *mMetronome;\r
18c97f53 580\r
cac2ab95 581//\r
582// Lookup table for increment values based on transfer widths\r
583//\r
584UINT8 mInStride[] = {\r
585 1, // EfiPciWidthUint8\r
586 2, // EfiPciWidthUint16\r
587 4, // EfiPciWidthUint32\r
588 8, // EfiPciWidthUint64\r
589 0, // EfiPciWidthFifoUint8\r
590 0, // EfiPciWidthFifoUint16\r
591 0, // EfiPciWidthFifoUint32\r
592 0, // EfiPciWidthFifoUint64\r
593 1, // EfiPciWidthFillUint8\r
594 2, // EfiPciWidthFillUint16\r
595 4, // EfiPciWidthFillUint32\r
596 8 // EfiPciWidthFillUint64\r
597};\r
21b404d1 598\r
599//\r
cac2ab95 600// Lookup table for increment values based on transfer widths\r
21b404d1 601//\r
cac2ab95 602UINT8 mOutStride[] = {\r
603 1, // EfiPciWidthUint8\r
604 2, // EfiPciWidthUint16\r
605 4, // EfiPciWidthUint32\r
606 8, // EfiPciWidthUint64\r
607 1, // EfiPciWidthFifoUint8\r
608 2, // EfiPciWidthFifoUint16\r
609 4, // EfiPciWidthFifoUint32\r
610 8, // EfiPciWidthFifoUint64\r
611 0, // EfiPciWidthFillUint8\r
612 0, // EfiPciWidthFillUint16\r
613 0, // EfiPciWidthFillUint32\r
614 0 // EfiPciWidthFillUint64\r
615};\r
21b404d1 616\r
18c97f53 617/**\r
618\r
619 Construct the Pci Root Bridge Io protocol\r
620\r
621 @param Protocol Point to protocol instance\r
622 @param HostBridgeHandle Handle of host bridge\r
623 @param Attri Attribute of host bridge\r
0b7c6cd4 624 @param ResAperture ResourceAperture for host bridge\r
18c97f53 625\r
626 @retval EFI_SUCCESS Success to initialize the Pci Root Bridge.\r
627\r
628**/\r
21b404d1 629EFI_STATUS\r
630RootBridgeConstructor (\r
631 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *Protocol,\r
632 IN EFI_HANDLE HostBridgeHandle,\r
633 IN UINT64 Attri,\r
0b7c6cd4 634 IN PCI_ROOT_BRIDGE_RESOURCE_APERTURE *ResAperture\r
21b404d1 635 )\r
21b404d1 636{\r
637 EFI_STATUS Status;\r
638 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
639 PCI_RESOURCE_TYPE Index;\r
640\r
641 PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (Protocol);\r
642\r
643 //\r
644 // The host to pci bridge, the host memory and io addresses are\r
645 // direct mapped to pci addresses, so no need translate, set bases to 0.\r
646 //\r
0b7c6cd4
LE
647 PrivateData->MemBase = ResAperture->MemBase;\r
648 PrivateData->IoBase = ResAperture->IoBase;\r
21b404d1 649\r
650 //\r
651 // The host bridge only supports 32bit addressing for memory\r
652 // and standard IA32 16bit io\r
653 //\r
0b7c6cd4
LE
654 PrivateData->MemLimit = ResAperture->MemLimit;\r
655 PrivateData->IoLimit = ResAperture->IoLimit;\r
21b404d1 656\r
657 //\r
0b7c6cd4 658 // Bus Aperture for this Root Bridge (Possible Range)\r
21b404d1 659 //\r
0b7c6cd4
LE
660 PrivateData->BusBase = ResAperture->BusBase;\r
661 PrivateData->BusLimit = ResAperture->BusLimit;\r
21b404d1 662 \r
663 //\r
664 // Specific for this chipset\r
665 //\r
666 for (Index = TypeIo; Index < TypeMax; Index++) {\r
667 PrivateData->ResAllocNode[Index].Type = Index;\r
668 PrivateData->ResAllocNode[Index].Base = 0;\r
669 PrivateData->ResAllocNode[Index].Length = 0;\r
670 PrivateData->ResAllocNode[Index].Status = ResNone;\r
671 }\r
672 \r
21b404d1 673 PrivateData->RootBridgeAttrib = Attri;\r
674 \r
e0ee9d93 675 PrivateData->Supports = EFI_PCI_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_ATTRIBUTE_IDE_SECONDARY_IO | \\r
676 EFI_PCI_ATTRIBUTE_ISA_IO_16 | EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO | \\r
677 EFI_PCI_ATTRIBUTE_VGA_MEMORY | \\r
678 EFI_PCI_ATTRIBUTE_VGA_IO_16 | EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16;\r
679 PrivateData->Attributes = PrivateData->Supports;\r
21b404d1 680\r
681 Protocol->ParentHandle = HostBridgeHandle;\r
682 \r
683 Protocol->PollMem = RootBridgeIoPollMem;\r
684 Protocol->PollIo = RootBridgeIoPollIo;\r
685\r
686 Protocol->Mem.Read = RootBridgeIoMemRead;\r
687 Protocol->Mem.Write = RootBridgeIoMemWrite;\r
688\r
689 Protocol->Io.Read = RootBridgeIoIoRead;\r
690 Protocol->Io.Write = RootBridgeIoIoWrite;\r
691\r
692 Protocol->CopyMem = RootBridgeIoCopyMem;\r
693\r
694 Protocol->Pci.Read = RootBridgeIoPciRead;\r
695 Protocol->Pci.Write = RootBridgeIoPciWrite;\r
696\r
697 Protocol->Map = RootBridgeIoMap;\r
698 Protocol->Unmap = RootBridgeIoUnmap;\r
699\r
700 Protocol->AllocateBuffer = RootBridgeIoAllocateBuffer;\r
701 Protocol->FreeBuffer = RootBridgeIoFreeBuffer;\r
702\r
703 Protocol->Flush = RootBridgeIoFlush;\r
704\r
705 Protocol->GetAttributes = RootBridgeIoGetAttributes;\r
706 Protocol->SetAttributes = RootBridgeIoSetAttributes;\r
707\r
708 Protocol->Configuration = RootBridgeIoConfiguration;\r
709\r
710 Protocol->SegmentNumber = 0;\r
711\r
21b404d1 712 Status = gBS->LocateProtocol (&gEfiMetronomeArchProtocolGuid, NULL, (VOID **)&mMetronome);\r
713 ASSERT_EFI_ERROR (Status);\r
714\r
715 return EFI_SUCCESS;\r
716}\r
717\r
cac2ab95 718/**\r
719 Check parameters for IO,MMIO,PCI read/write services of PCI Root Bridge IO.\r
720\r
721 The I/O operations are carried out exactly as requested. The caller is responsible \r
722 for satisfying any alignment and I/O width restrictions that a PI System on a \r
723 platform might require. For example on some platforms, width requests of \r
724 EfiCpuIoWidthUint64 do not work. Misaligned buffers, on the other hand, will \r
725 be handled by the driver.\r
726 \r
727 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
728 @param[in] OperationType I/O operation type: IO/MMIO/PCI.\r
729 @param[in] Width Signifies the width of the I/O or Memory operation.\r
730 @param[in] Address The base address of the I/O operation. \r
731 @param[in] Count The number of I/O operations to perform. The number of \r
732 bytes moved is Width size * Count, starting at Address.\r
733 @param[in] Buffer For read operations, the destination buffer to store the results.\r
734 For write operations, the source buffer from which to write data.\r
735\r
736 @retval EFI_SUCCESS The parameters for this request pass the checks.\r
737 @retval EFI_INVALID_PARAMETER Width is invalid for this PI system.\r
738 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
739 @retval EFI_UNSUPPORTED The Buffer is not aligned for the given Width.\r
740 @retval EFI_UNSUPPORTED The address range specified by Address, Width, \r
741 and Count is not valid for this PI system.\r
742\r
743**/\r
744EFI_STATUS\r
745RootBridgeIoCheckParameter (\r
746 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
747 IN OPERATION_TYPE OperationType,\r
748 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
749 IN UINT64 Address,\r
750 IN UINTN Count,\r
751 IN VOID *Buffer\r
752 )\r
753{\r
754 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
755 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *PciRbAddr;\r
756 UINT64 MaxCount;\r
757 UINT64 Base;\r
758 UINT64 Limit;\r
759\r
760 //\r
761 // Check to see if Buffer is NULL\r
762 //\r
763 if (Buffer == NULL) {\r
764 return EFI_INVALID_PARAMETER;\r
765 }\r
766\r
767 //\r
768 // Check to see if Width is in the valid range\r
769 //\r
3d78c020 770 if ((UINT32)Width >= EfiPciWidthMaximum) {\r
cac2ab95 771 return EFI_INVALID_PARAMETER;\r
772 }\r
773\r
774 //\r
775 // For FIFO type, the target address won't increase during the access,\r
776 // so treat Count as 1\r
777 //\r
778 if (Width >= EfiPciWidthFifoUint8 && Width <= EfiPciWidthFifoUint64) {\r
779 Count = 1;\r
780 }\r
781\r
782 //\r
783 // Check to see if Width is in the valid range for I/O Port operations\r
784 //\r
785 Width = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
786 if ((OperationType != MemOperation) && (Width == EfiPciWidthUint64)) {\r
787 ASSERT (FALSE);\r
788 return EFI_INVALID_PARAMETER;\r
789 }\r
790\r
791 //\r
792 // Check to see if Address is aligned\r
793 //\r
794 if ((Address & (UINT64)(mInStride[Width] - 1)) != 0) {\r
795 return EFI_UNSUPPORTED;\r
796 }\r
797\r
798 PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);\r
799\r
800 //\r
801 // Check to see if any address associated with this transfer exceeds the maximum \r
802 // allowed address. The maximum address implied by the parameters passed in is\r
803 // Address + Size * Count. If the following condition is met, then the transfer\r
804 // is not supported.\r
805 //\r
806 // Address + Size * Count > Limit + 1\r
807 //\r
808 // Since Limit can be the maximum integer value supported by the CPU and Count \r
809 // can also be the maximum integer value supported by the CPU, this range\r
810 // check must be adjusted to avoid all oveflow conditions.\r
811 // \r
812 // The following form of the range check is equivalent but assumes that \r
813 // Limit is of the form (2^n - 1).\r
814 //\r
815 if (OperationType == IoOperation) {\r
816 Base = PrivateData->IoBase;\r
817 Limit = PrivateData->IoLimit;\r
818 } else if (OperationType == MemOperation) {\r
819 Base = PrivateData->MemBase;\r
820 Limit = PrivateData->MemLimit;\r
821 } else {\r
822 PciRbAddr = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS*) &Address;\r
823 if (PciRbAddr->Bus < PrivateData->BusBase || PciRbAddr->Bus > PrivateData->BusLimit) {\r
824 return EFI_INVALID_PARAMETER;\r
825 }\r
826\r
827 if (PciRbAddr->Device > MAX_PCI_DEVICE_NUMBER || PciRbAddr->Function > MAX_PCI_FUNCTION_NUMBER) {\r
828 return EFI_INVALID_PARAMETER;\r
829 }\r
830\r
831 if (PciRbAddr->ExtendedRegister != 0) {\r
832 Address = PciRbAddr->ExtendedRegister;\r
833 } else {\r
834 Address = PciRbAddr->Register;\r
835 }\r
836 Base = 0;\r
837 Limit = MAX_PCI_REG_ADDRESS;\r
838 }\r
839\r
840 if (Address < Base) {\r
841 return EFI_INVALID_PARAMETER;\r
842 }\r
843\r
844 if (Count == 0) {\r
845 if (Address > Limit) {\r
846 return EFI_UNSUPPORTED;\r
847 }\r
848 } else { \r
849 MaxCount = RShiftU64 (Limit, Width);\r
850 if (MaxCount < (Count - 1)) {\r
851 return EFI_UNSUPPORTED;\r
852 }\r
853 if (Address > LShiftU64 (MaxCount - Count + 1, Width)) {\r
854 return EFI_UNSUPPORTED;\r
855 }\r
856 }\r
857\r
858 return EFI_SUCCESS;\r
859}\r
860\r
861/**\r
862 Internal help function for read and write memory space.\r
863\r
864 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
865 @param[in] Write Switch value for Read or Write.\r
866 @param[in] Width Signifies the width of the memory operations.\r
867 @param[in] UserAddress The address within the PCI configuration space for the PCI controller.\r
868 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
869 moved is Width size * Count, starting at Address.\r
24115e44 870 @param[in, out] UserBuffer For read operations, the destination buffer to store the results. For\r
cac2ab95 871 write operations, the source buffer to write data from.\r
872 \r
873 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
874 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
875 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
876 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
877\r
878**/\r
879EFI_STATUS\r
880RootBridgeIoMemRW (\r
881 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
882 IN BOOLEAN Write,\r
883 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
884 IN UINT64 Address,\r
885 IN UINTN Count,\r
886 IN OUT VOID *Buffer\r
887 )\r
888{\r
889 EFI_STATUS Status;\r
890 UINT8 InStride;\r
891 UINT8 OutStride;\r
892 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH OperationWidth;\r
893 UINT8 *Uint8Buffer;\r
894\r
895 Status = RootBridgeIoCheckParameter (This, MemOperation, Width, Address, Count, Buffer);\r
896 if (EFI_ERROR (Status)) {\r
897 return Status;\r
898 }\r
899\r
900 InStride = mInStride[Width];\r
901 OutStride = mOutStride[Width];\r
902 OperationWidth = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
903 for (Uint8Buffer = Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
904 if (Write) {\r
905 switch (OperationWidth) {\r
906 case EfiPciWidthUint8:\r
907 MmioWrite8 ((UINTN)Address, *Uint8Buffer);\r
908 break;\r
909 case EfiPciWidthUint16:\r
910 MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));\r
911 break;\r
912 case EfiPciWidthUint32:\r
913 MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));\r
914 break;\r
915 case EfiPciWidthUint64:\r
916 MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer));\r
917 break;\r
daaad270 918 default:\r
919 //\r
920 // The RootBridgeIoCheckParameter call above will ensure that this\r
921 // path is not taken.\r
922 //\r
923 ASSERT (FALSE);\r
924 break;\r
cac2ab95 925 }\r
926 } else {\r
927 switch (OperationWidth) {\r
928 case EfiPciWidthUint8:\r
929 *Uint8Buffer = MmioRead8 ((UINTN)Address);\r
930 break;\r
931 case EfiPciWidthUint16:\r
932 *((UINT16 *)Uint8Buffer) = MmioRead16 ((UINTN)Address);\r
933 break;\r
934 case EfiPciWidthUint32:\r
935 *((UINT32 *)Uint8Buffer) = MmioRead32 ((UINTN)Address);\r
936 break;\r
937 case EfiPciWidthUint64:\r
938 *((UINT64 *)Uint8Buffer) = MmioRead64 ((UINTN)Address);\r
939 break;\r
daaad270 940 default:\r
941 //\r
942 // The RootBridgeIoCheckParameter call above will ensure that this\r
943 // path is not taken.\r
944 //\r
945 ASSERT (FALSE);\r
946 break;\r
cac2ab95 947 }\r
948 }\r
949 }\r
950 return EFI_SUCCESS; \r
951}\r
952\r
953/**\r
954 Internal help function for read and write IO space.\r
955\r
956 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
957 @param[in] Write Switch value for Read or Write.\r
958 @param[in] Width Signifies the width of the memory operations.\r
959 @param[in] UserAddress The address within the PCI configuration space for the PCI controller.\r
960 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
961 moved is Width size * Count, starting at Address.\r
24115e44 962 @param[in, out] UserBuffer For read operations, the destination buffer to store the results. For\r
cac2ab95 963 write operations, the source buffer to write data from.\r
964 \r
965 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
966 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
967 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
968 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
969\r
970**/\r
971EFI_STATUS\r
972RootBridgeIoIoRW (\r
973 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
974 IN BOOLEAN Write,\r
975 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
976 IN UINT64 Address,\r
977 IN UINTN Count,\r
978 IN OUT VOID *Buffer\r
979 )\r
980{\r
981 EFI_STATUS Status;\r
982 UINT8 InStride;\r
983 UINT8 OutStride;\r
984 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH OperationWidth;\r
985 UINT8 *Uint8Buffer;\r
986\r
987 Status = RootBridgeIoCheckParameter (This, IoOperation, Width, Address, Count, Buffer);\r
988 if (EFI_ERROR (Status)) {\r
989 return Status;\r
990 }\r
991\r
992 InStride = mInStride[Width];\r
993 OutStride = mOutStride[Width];\r
994 OperationWidth = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
1fd376d9 995\r
996#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r
997 if (InStride == 0) {\r
998 if (Write) {\r
999 switch (OperationWidth) {\r
1000 case EfiPciWidthUint8:\r
1001 IoWriteFifo8 ((UINTN) Address, Count, Buffer);\r
1002 return EFI_SUCCESS;\r
1003 case EfiPciWidthUint16:\r
1004 IoWriteFifo16 ((UINTN) Address, Count, Buffer);\r
1005 return EFI_SUCCESS;\r
1006 case EfiPciWidthUint32:\r
1007 IoWriteFifo32 ((UINTN) Address, Count, Buffer);\r
1008 return EFI_SUCCESS;\r
1009 default:\r
1010 //\r
1011 // The RootBridgeIoCheckParameter call above will ensure that this\r
1012 // path is not taken.\r
1013 //\r
1014 ASSERT (FALSE);\r
1015 break;\r
1016 }\r
1017 } else {\r
1018 switch (OperationWidth) {\r
1019 case EfiPciWidthUint8:\r
1020 IoReadFifo8 ((UINTN) Address, Count, Buffer);\r
1021 return EFI_SUCCESS;\r
1022 case EfiPciWidthUint16:\r
1023 IoReadFifo16 ((UINTN) Address, Count, Buffer);\r
1024 return EFI_SUCCESS;\r
1025 case EfiPciWidthUint32:\r
1026 IoReadFifo32 ((UINTN) Address, Count, Buffer);\r
1027 return EFI_SUCCESS;\r
1028 default:\r
1029 //\r
1030 // The RootBridgeIoCheckParameter call above will ensure that this\r
1031 // path is not taken.\r
1032 //\r
1033 ASSERT (FALSE);\r
1034 break;\r
1035 }\r
1036 }\r
1037 }\r
1038#endif\r
1039\r
cac2ab95 1040 for (Uint8Buffer = Buffer; Count > 0; Address += InStride, Uint8Buffer += OutStride, Count--) {\r
1041 if (Write) {\r
1042 switch (OperationWidth) {\r
1043 case EfiPciWidthUint8:\r
1044 IoWrite8 ((UINTN)Address, *Uint8Buffer);\r
1045 break;\r
1046 case EfiPciWidthUint16:\r
1047 IoWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));\r
1048 break;\r
1049 case EfiPciWidthUint32:\r
1050 IoWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));\r
1051 break;\r
daaad270 1052 default:\r
1053 //\r
1054 // The RootBridgeIoCheckParameter call above will ensure that this\r
1055 // path is not taken.\r
1056 //\r
1057 ASSERT (FALSE);\r
1058 break;\r
cac2ab95 1059 }\r
1060 } else {\r
1061 switch (OperationWidth) {\r
1062 case EfiPciWidthUint8:\r
1063 *Uint8Buffer = IoRead8 ((UINTN)Address);\r
1064 break;\r
1065 case EfiPciWidthUint16:\r
1066 *((UINT16 *)Uint8Buffer) = IoRead16 ((UINTN)Address);\r
1067 break;\r
1068 case EfiPciWidthUint32:\r
1069 *((UINT32 *)Uint8Buffer) = IoRead32 ((UINTN)Address);\r
1070 break;\r
daaad270 1071 default:\r
1072 //\r
1073 // The RootBridgeIoCheckParameter call above will ensure that this\r
1074 // path is not taken.\r
1075 //\r
1076 ASSERT (FALSE);\r
1077 break;\r
cac2ab95 1078 }\r
1079 }\r
1080 }\r
1081 return EFI_SUCCESS;\r
1082}\r
1083\r
1084/**\r
1085 Internal help function for read and write PCI configuration space.\r
1086\r
1087 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1088 @param[in] Write Switch value for Read or Write.\r
1089 @param[in] Width Signifies the width of the memory operations.\r
1090 @param[in] UserAddress The address within the PCI configuration space for the PCI controller.\r
1091 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
1092 moved is Width size * Count, starting at Address.\r
24115e44 1093 @param[in, out] UserBuffer For read operations, the destination buffer to store the results. For\r
cac2ab95 1094 write operations, the source buffer to write data from.\r
1095 \r
1096 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1097 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1098 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1099 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1100\r
1101**/\r
1102EFI_STATUS\r
1103RootBridgeIoPciRW (\r
1104 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1105 IN BOOLEAN Write,\r
1106 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1107 IN UINT64 Address,\r
1108 IN UINTN Count,\r
1109 IN OUT VOID *Buffer\r
1110 )\r
1111{\r
1112 EFI_STATUS Status;\r
1113 UINT8 InStride;\r
1114 UINT8 OutStride;\r
1115 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH OperationWidth;\r
1116 UINT8 *Uint8Buffer;\r
1117 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *PciRbAddr;\r
1118 UINTN PcieRegAddr;\r
1119\r
1120 Status = RootBridgeIoCheckParameter (This, PciOperation, Width, Address, Count, Buffer);\r
1121 if (EFI_ERROR (Status)) {\r
1122 return Status;\r
1123 }\r
1124\r
1125 PciRbAddr = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS*) &Address;\r
1126\r
1127 PcieRegAddr = (UINTN) PCI_LIB_ADDRESS (\r
1128 PciRbAddr->Bus,\r
1129 PciRbAddr->Device,\r
1130 PciRbAddr->Function,\r
1131 (PciRbAddr->ExtendedRegister != 0) ? \\r
1132 PciRbAddr->ExtendedRegister :\r
1133 PciRbAddr->Register\r
1134 );\r
1135\r
1136 InStride = mInStride[Width];\r
1137 OutStride = mOutStride[Width];\r
1138 OperationWidth = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
1139 for (Uint8Buffer = Buffer; Count > 0; PcieRegAddr += InStride, Uint8Buffer += OutStride, Count--) {\r
1140 if (Write) {\r
1141 switch (OperationWidth) {\r
1142 case EfiPciWidthUint8:\r
1143 PciWrite8 (PcieRegAddr, *Uint8Buffer);\r
1144 break;\r
1145 case EfiPciWidthUint16:\r
1146 PciWrite16 (PcieRegAddr, *((UINT16 *)Uint8Buffer));\r
1147 break;\r
1148 case EfiPciWidthUint32:\r
1149 PciWrite32 (PcieRegAddr, *((UINT32 *)Uint8Buffer));\r
1150 break;\r
daaad270 1151 default:\r
1152 //\r
1153 // The RootBridgeIoCheckParameter call above will ensure that this\r
1154 // path is not taken.\r
1155 //\r
1156 ASSERT (FALSE);\r
1157 break;\r
cac2ab95 1158 }\r
1159 } else {\r
1160 switch (OperationWidth) {\r
1161 case EfiPciWidthUint8:\r
1162 *Uint8Buffer = PciRead8 (PcieRegAddr);\r
1163 break;\r
1164 case EfiPciWidthUint16:\r
1165 *((UINT16 *)Uint8Buffer) = PciRead16 (PcieRegAddr);\r
1166 break;\r
1167 case EfiPciWidthUint32:\r
1168 *((UINT32 *)Uint8Buffer) = PciRead32 (PcieRegAddr);\r
1169 break;\r
daaad270 1170 default:\r
1171 //\r
1172 // The RootBridgeIoCheckParameter call above will ensure that this\r
1173 // path is not taken.\r
1174 //\r
1175 ASSERT (FALSE);\r
1176 break;\r
cac2ab95 1177 }\r
1178 }\r
1179 }\r
1180\r
1181 return EFI_SUCCESS;\r
1182}\r
1183\r
18c97f53 1184/**\r
1185 Polls an address in memory mapped I/O space until an exit condition is met, or \r
1186 a timeout occurs. \r
1187\r
1188 This function provides a standard way to poll a PCI memory location. A PCI memory read\r
1189 operation is performed at the PCI memory address specified by Address for the width specified\r
1190 by Width. The result of this PCI memory read operation is stored in Result. This PCI memory\r
1191 read operation is repeated until either a timeout of Delay 100 ns units has expired, or (Result &\r
1192 Mask) is equal to Value.\r
1193\r
1194 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1195 @param[in] Width Signifies the width of the memory operations.\r
1196 @param[in] Address The base address of the memory operations. The caller is\r
1197 responsible for aligning Address if required.\r
1198 @param[in] Mask Mask used for the polling criteria. Bytes above Width in Mask\r
1199 are ignored. The bits in the bytes below Width which are zero in\r
1200 Mask are ignored when polling the memory address.\r
1201 @param[in] Value The comparison value used for the polling exit criteria.\r
1202 @param[in] Delay The number of 100 ns units to poll. Note that timer available may\r
1203 be of poorer granularity.\r
1204 @param[out] Result Pointer to the last value read from the memory location.\r
1205 \r
1206 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.\r
1207 @retval EFI_INVALID_PARAMETER Width is invalid.\r
1208 @retval EFI_INVALID_PARAMETER Result is NULL.\r
1209 @retval EFI_TIMEOUT Delay expired before a match occurred.\r
1210 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1211\r
1212**/\r
21b404d1 1213EFI_STATUS\r
1214EFIAPI\r
1215RootBridgeIoPollMem ( \r
1216 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1217 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1218 IN UINT64 Address,\r
1219 IN UINT64 Mask,\r
1220 IN UINT64 Value,\r
1221 IN UINT64 Delay,\r
1222 OUT UINT64 *Result\r
1223 )\r
21b404d1 1224{\r
1225 EFI_STATUS Status;\r
1226 UINT64 NumberOfTicks;\r
1227 UINT32 Remainder;\r
1228\r
1229 if (Result == NULL) {\r
1230 return EFI_INVALID_PARAMETER;\r
1231 }\r
1232\r
3d78c020 1233 if ((UINT32)Width > EfiPciWidthUint64) {\r
21b404d1 1234 return EFI_INVALID_PARAMETER;\r
1235 }\r
1236\r
1237 //\r
1238 // No matter what, always do a single poll.\r
1239 //\r
1240 Status = This->Mem.Read (This, Width, Address, 1, Result);\r
1241 if (EFI_ERROR (Status)) {\r
1242 return Status;\r
1243 } \r
1244 if ((*Result & Mask) == Value) {\r
1245 return EFI_SUCCESS;\r
1246 }\r
1247\r
1248 if (Delay == 0) {\r
1249 return EFI_SUCCESS;\r
1250 \r
1251 } else {\r
1252\r
1253 //\r
1254 // Determine the proper # of metronome ticks to wait for polling the\r
1255 // location. The nuber of ticks is Roundup (Delay / mMetronome->TickPeriod)+1\r
1256 // The "+1" to account for the possibility of the first tick being short\r
1257 // because we started in the middle of a tick.\r
1258 //\r
1259 // BugBug: overriding mMetronome->TickPeriod with UINT32 until Metronome\r
1260 // protocol definition is updated.\r
1261 //\r
1262 NumberOfTicks = DivU64x32Remainder (Delay, (UINT32) mMetronome->TickPeriod, &Remainder);\r
1263 if (Remainder != 0) {\r
1264 NumberOfTicks += 1;\r
1265 }\r
1266 NumberOfTicks += 1;\r
1267 \r
24115e44 1268 while (NumberOfTicks != 0) {\r
21b404d1 1269\r
1270 mMetronome->WaitForTick (mMetronome, 1);\r
1271 \r
1272 Status = This->Mem.Read (This, Width, Address, 1, Result);\r
1273 if (EFI_ERROR (Status)) {\r
1274 return Status;\r
1275 }\r
1276 \r
1277 if ((*Result & Mask) == Value) {\r
1278 return EFI_SUCCESS;\r
1279 }\r
1280\r
1281 NumberOfTicks -= 1;\r
1282 }\r
1283 }\r
1284 return EFI_TIMEOUT;\r
1285}\r
1286 \r
18c97f53 1287/**\r
1288 Reads from the I/O space of a PCI Root Bridge. Returns when either the polling exit criteria is\r
1289 satisfied or after a defined duration.\r
1290\r
1291 This function provides a standard way to poll a PCI I/O location. A PCI I/O read operation is\r
1292 performed at the PCI I/O address specified by Address for the width specified by Width.\r
1293 The result of this PCI I/O read operation is stored in Result. This PCI I/O read operation is\r
1294 repeated until either a timeout of Delay 100 ns units has expired, or (Result & Mask) is equal\r
1295 to Value.\r
1296\r
1297 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1298 @param[in] Width Signifies the width of the I/O operations.\r
1299 @param[in] Address The base address of the I/O operations. The caller is responsible\r
1300 for aligning Address if required.\r
1301 @param[in] Mask Mask used for the polling criteria. Bytes above Width in Mask\r
1302 are ignored. The bits in the bytes below Width which are zero in\r
1303 Mask are ignored when polling the I/O address.\r
1304 @param[in] Value The comparison value used for the polling exit criteria.\r
1305 @param[in] Delay The number of 100 ns units to poll. Note that timer available may\r
1306 be of poorer granularity.\r
1307 @param[out] Result Pointer to the last value read from the memory location.\r
1308 \r
1309 @retval EFI_SUCCESS The last data returned from the access matched the poll exit criteria.\r
1310 @retval EFI_INVALID_PARAMETER Width is invalid.\r
1311 @retval EFI_INVALID_PARAMETER Result is NULL.\r
1312 @retval EFI_TIMEOUT Delay expired before a match occurred.\r
1313 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1314\r
1315**/\r
21b404d1 1316EFI_STATUS\r
1317EFIAPI\r
1318RootBridgeIoPollIo ( \r
1319 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1320 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1321 IN UINT64 Address,\r
1322 IN UINT64 Mask,\r
1323 IN UINT64 Value,\r
1324 IN UINT64 Delay,\r
1325 OUT UINT64 *Result\r
1326 )\r
21b404d1 1327{\r
1328 EFI_STATUS Status;\r
1329 UINT64 NumberOfTicks;\r
1330 UINT32 Remainder;\r
1331\r
1332 //\r
1333 // No matter what, always do a single poll.\r
1334 //\r
1335\r
1336 if (Result == NULL) {\r
1337 return EFI_INVALID_PARAMETER;\r
1338 }\r
1339\r
3d78c020 1340 if ((UINT32)Width > EfiPciWidthUint64) {\r
21b404d1 1341 return EFI_INVALID_PARAMETER;\r
1342 }\r
1343 \r
1344 Status = This->Io.Read (This, Width, Address, 1, Result);\r
1345 if (EFI_ERROR (Status)) {\r
1346 return Status;\r
1347 } \r
1348 if ((*Result & Mask) == Value) {\r
1349 return EFI_SUCCESS;\r
1350 }\r
1351\r
1352 if (Delay == 0) {\r
1353 return EFI_SUCCESS;\r
1354 \r
1355 } else {\r
1356\r
1357 //\r
1358 // Determine the proper # of metronome ticks to wait for polling the\r
1359 // location. The number of ticks is Roundup (Delay / mMetronome->TickPeriod)+1\r
1360 // The "+1" to account for the possibility of the first tick being short\r
1361 // because we started in the middle of a tick.\r
1362 //\r
1363 NumberOfTicks = DivU64x32Remainder (Delay, (UINT32)mMetronome->TickPeriod, &Remainder);\r
1364 if (Remainder != 0) {\r
1365 NumberOfTicks += 1;\r
1366 }\r
1367 NumberOfTicks += 1;\r
1368 \r
24115e44 1369 while (NumberOfTicks != 0) {\r
21b404d1 1370\r
1371 mMetronome->WaitForTick (mMetronome, 1);\r
1372 \r
1373 Status = This->Io.Read (This, Width, Address, 1, Result);\r
1374 if (EFI_ERROR (Status)) {\r
1375 return Status;\r
1376 }\r
1377 \r
1378 if ((*Result & Mask) == Value) {\r
1379 return EFI_SUCCESS;\r
1380 }\r
1381\r
1382 NumberOfTicks -= 1;\r
1383 }\r
1384 }\r
1385 return EFI_TIMEOUT;\r
1386}\r
1387\r
18c97f53 1388/**\r
1389 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.\r
1390\r
1391 The Mem.Read(), and Mem.Write() functions enable a driver to access PCI controller\r
1392 registers in the PCI root bridge memory space.\r
1393 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
1394 any alignment and memory width restrictions that a PCI Root Bridge on a platform might require.\r
1395\r
1396 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1397 @param[in] Width Signifies the width of the memory operation.\r
1398 @param[in] Address The base address of the memory operation. The caller is\r
1399 responsible for aligning the Address if required.\r
1400 @param[in] Count The number of memory operations to perform. Bytes moved is\r
1401 Width size * Count, starting at Address.\r
1402 @param[out] Buffer For read operations, the destination buffer to store the results. For\r
1403 write operations, the source buffer to write data from.\r
1404 \r
1405 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1406 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1407 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1408 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1409\r
1410**/\r
21b404d1 1411EFI_STATUS\r
1412EFIAPI\r
1413RootBridgeIoMemRead (\r
1414 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1415 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1416 IN UINT64 Address,\r
1417 IN UINTN Count,\r
24115e44 1418 OUT VOID *Buffer\r
21b404d1 1419 )\r
21b404d1 1420{\r
cac2ab95 1421 return RootBridgeIoMemRW (This, FALSE, Width, Address, Count, Buffer);\r
21b404d1 1422}\r
1423\r
18c97f53 1424/**\r
1425 Enables a PCI driver to access PCI controller registers in the PCI root bridge memory space.\r
1426\r
1427 The Mem.Read(), and Mem.Write() functions enable a driver to access PCI controller\r
1428 registers in the PCI root bridge memory space.\r
1429 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
1430 any alignment and memory width restrictions that a PCI Root Bridge on a platform might require.\r
1431\r
1432 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1433 @param[in] Width Signifies the width of the memory operation.\r
1434 @param[in] Address The base address of the memory operation. The caller is\r
1435 responsible for aligning the Address if required.\r
1436 @param[in] Count The number of memory operations to perform. Bytes moved is\r
1437 Width size * Count, starting at Address.\r
24115e44 1438 @param[in] Buffer For read operations, the destination buffer to store the results. For\r
18c97f53 1439 write operations, the source buffer to write data from.\r
1440 \r
1441 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1442 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1443 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1444 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1445**/\r
21b404d1 1446EFI_STATUS\r
1447EFIAPI\r
1448RootBridgeIoMemWrite (\r
1449 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1450 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1451 IN UINT64 Address,\r
1452 IN UINTN Count,\r
24115e44 1453 IN VOID *Buffer\r
21b404d1 1454 )\r
21b404d1 1455{\r
cac2ab95 1456 return RootBridgeIoMemRW (This, TRUE, Width, Address, Count, Buffer); \r
21b404d1 1457}\r
1458\r
18c97f53 1459/**\r
1460 Enables a PCI driver to access PCI controller registers in the PCI root bridge I/O space.\r
1461\r
1462 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1463 @param[in] Width Signifies the width of the memory operations.\r
1464 @param[in] Address The base address of the I/O operation. The caller is responsible for\r
1465 aligning the Address if required.\r
1466 @param[in] Count The number of I/O operations to perform. Bytes moved is Width\r
1467 size * Count, starting at Address.\r
1468 @param[out] Buffer For read operations, the destination buffer to store the results. For\r
1469 write operations, the source buffer to write data from.\r
1470 \r
1471 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1472 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1473 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1474 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1475\r
1476**/\r
21b404d1 1477EFI_STATUS\r
1478EFIAPI\r
1479RootBridgeIoIoRead (\r
1480 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1481 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1482 IN UINT64 Address,\r
1483 IN UINTN Count,\r
24115e44 1484 OUT VOID *Buffer\r
21b404d1 1485 )\r
21b404d1 1486{\r
cac2ab95 1487 return RootBridgeIoIoRW (This, FALSE, Width, Address, Count, Buffer); \r
21b404d1 1488}\r
1489\r
18c97f53 1490/**\r
1491 Enables a PCI driver to access PCI controller registers in the PCI root bridge I/O space.\r
1492\r
1493 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1494 @param[in] Width Signifies the width of the memory operations.\r
1495 @param[in] Address The base address of the I/O operation. The caller is responsible for\r
1496 aligning the Address if required.\r
1497 @param[in] Count The number of I/O operations to perform. Bytes moved is Width\r
1498 size * Count, starting at Address.\r
24115e44 1499 @param[in] Buffer For read operations, the destination buffer to store the results. For\r
18c97f53 1500 write operations, the source buffer to write data from.\r
1501 \r
1502 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1503 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1504 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1505 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1506\r
1507**/\r
21b404d1 1508EFI_STATUS\r
1509EFIAPI\r
1510RootBridgeIoIoWrite (\r
1511 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1512 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1513 IN UINT64 Address,\r
1514 IN UINTN Count,\r
24115e44 1515 IN VOID *Buffer\r
21b404d1 1516 )\r
21b404d1 1517{\r
cac2ab95 1518 return RootBridgeIoIoRW (This, TRUE, Width, Address, Count, Buffer); \r
21b404d1 1519}\r
1520\r
18c97f53 1521/**\r
1522 Enables a PCI driver to copy one region of PCI root bridge memory space to another region of PCI\r
1523 root bridge memory space.\r
1524\r
1525 The CopyMem() function enables a PCI driver to copy one region of PCI root bridge memory\r
1526 space to another region of PCI root bridge memory space. This is especially useful for video scroll\r
1527 operation on a memory mapped video buffer.\r
1528 The memory operations are carried out exactly as requested. The caller is responsible for satisfying\r
1529 any alignment and memory width restrictions that a PCI root bridge on a platform might require.\r
1530\r
1531 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.\r
1532 @param[in] Width Signifies the width of the memory operations.\r
1533 @param[in] DestAddress The destination address of the memory operation. The caller is\r
1534 responsible for aligning the DestAddress if required.\r
1535 @param[in] SrcAddress The source address of the memory operation. The caller is\r
1536 responsible for aligning the SrcAddress if required.\r
1537 @param[in] Count The number of memory operations to perform. Bytes moved is\r
1538 Width size * Count, starting at DestAddress and SrcAddress.\r
1539 \r
1540 @retval EFI_SUCCESS The data was copied from one memory region to another memory region.\r
1541 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1542 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1543\r
1544**/\r
21b404d1 1545EFI_STATUS\r
1546EFIAPI\r
1547RootBridgeIoCopyMem (\r
24115e44 1548 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
21b404d1 1549 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1550 IN UINT64 DestAddress,\r
1551 IN UINT64 SrcAddress,\r
1552 IN UINTN Count\r
1553 )\r
21b404d1 1554{\r
1555 EFI_STATUS Status;\r
1556 BOOLEAN Direction;\r
1557 UINTN Stride;\r
1558 UINTN Index;\r
1559 UINT64 Result;\r
1560\r
3d78c020 1561 if ((UINT32)Width > EfiPciWidthUint64) {\r
21b404d1 1562 return EFI_INVALID_PARAMETER;\r
1563 } \r
1564\r
1565 if (DestAddress == SrcAddress) {\r
1566 return EFI_SUCCESS;\r
1567 }\r
1568\r
1569 Stride = (UINTN)(1 << Width);\r
1570\r
1571 Direction = TRUE;\r
1572 if ((DestAddress > SrcAddress) && (DestAddress < (SrcAddress + Count * Stride))) {\r
1573 Direction = FALSE;\r
1574 SrcAddress = SrcAddress + (Count-1) * Stride;\r
1575 DestAddress = DestAddress + (Count-1) * Stride;\r
1576 }\r
1577\r
1578 for (Index = 0;Index < Count;Index++) {\r
1579 Status = RootBridgeIoMemRead (\r
1580 This,\r
1581 Width,\r
1582 SrcAddress,\r
1583 1,\r
1584 &Result\r
1585 );\r
1586 if (EFI_ERROR (Status)) {\r
1587 return Status;\r
1588 }\r
1589 Status = RootBridgeIoMemWrite (\r
1590 This,\r
1591 Width,\r
1592 DestAddress,\r
1593 1,\r
1594 &Result\r
1595 );\r
1596 if (EFI_ERROR (Status)) {\r
1597 return Status;\r
1598 }\r
1599 if (Direction) {\r
1600 SrcAddress += Stride;\r
1601 DestAddress += Stride;\r
1602 } else {\r
1603 SrcAddress -= Stride;\r
1604 DestAddress -= Stride;\r
1605 }\r
1606 }\r
1607 return EFI_SUCCESS;\r
1608}\r
1609\r
18c97f53 1610/**\r
1611 Enables a PCI driver to access PCI controller registers in a PCI root bridge's configuration space.\r
1612\r
1613 The Pci.Read() and Pci.Write() functions enable a driver to access PCI configuration\r
1614 registers for a PCI controller.\r
1615 The PCI Configuration operations are carried out exactly as requested. The caller is responsible for\r
1616 any alignment and PCI configuration width issues that a PCI Root Bridge on a platform might\r
1617 require.\r
1618\r
1619 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1620 @param[in] Width Signifies the width of the memory operations.\r
1621 @param[in] Address The address within the PCI configuration space for the PCI controller.\r
1622 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
1623 moved is Width size * Count, starting at Address.\r
1624 @param[out] Buffer For read operations, the destination buffer to store the results. For\r
1625 write operations, the source buffer to write data from.\r
1626 \r
1627 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1628 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1629 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1630 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1631\r
1632**/\r
21b404d1 1633EFI_STATUS\r
1634EFIAPI\r
1635RootBridgeIoPciRead (\r
1636 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1637 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1638 IN UINT64 Address,\r
1639 IN UINTN Count,\r
24115e44 1640 OUT VOID *Buffer\r
21b404d1 1641 )\r
21b404d1 1642{\r
21b404d1 1643 return RootBridgeIoPciRW (This, FALSE, Width, Address, Count, Buffer);\r
1644}\r
1645\r
18c97f53 1646/**\r
1647 Enables a PCI driver to access PCI controller registers in a PCI root bridge's configuration space.\r
1648\r
1649 The Pci.Read() and Pci.Write() functions enable a driver to access PCI configuration\r
1650 registers for a PCI controller.\r
1651 The PCI Configuration operations are carried out exactly as requested. The caller is responsible for\r
1652 any alignment and PCI configuration width issues that a PCI Root Bridge on a platform might\r
1653 require.\r
1654\r
1655 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1656 @param[in] Width Signifies the width of the memory operations.\r
1657 @param[in] Address The address within the PCI configuration space for the PCI controller.\r
1658 @param[in] Count The number of PCI configuration operations to perform. Bytes\r
1659 moved is Width size * Count, starting at Address.\r
24115e44 1660 @param[in] Buffer For read operations, the destination buffer to store the results. For\r
18c97f53 1661 write operations, the source buffer to write data from.\r
1662 \r
1663 @retval EFI_SUCCESS The data was read from or written to the PCI root bridge.\r
1664 @retval EFI_INVALID_PARAMETER Width is invalid for this PCI root bridge.\r
1665 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
1666 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1667\r
1668**/\r
21b404d1 1669EFI_STATUS\r
1670EFIAPI\r
1671RootBridgeIoPciWrite (\r
1672 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1673 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,\r
1674 IN UINT64 Address,\r
1675 IN UINTN Count,\r
24115e44 1676 IN VOID *Buffer\r
21b404d1 1677 )\r
21b404d1 1678{\r
21b404d1 1679 return RootBridgeIoPciRW (This, TRUE, Width, Address, Count, Buffer);\r
1680}\r
1681\r
18c97f53 1682/**\r
1683 Provides the PCI controller-specific addresses required to access system memory from a\r
1684 DMA bus master.\r
1685\r
1686 The Map() function provides the PCI controller specific addresses needed to access system\r
1687 memory. This function is used to map system memory for PCI bus master DMA accesses.\r
1688\r
1689 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1690 @param[in] Operation Indicates if the bus master is going to read or write to system memory.\r
1691 @param[in] HostAddress The system memory address to map to the PCI controller.\r
24115e44 1692 @param[in, out] NumberOfBytes On input the number of bytes to map. On output the number of bytes that were mapped.\r
18c97f53 1693 @param[out] DeviceAddress The resulting map address for the bus master PCI controller to use\r
1694 to access the system memory's HostAddress.\r
1695 @param[out] Mapping The value to pass to Unmap() when the bus master DMA operation is complete.\r
1696 \r
1697 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.\r
1698 @retval EFI_INVALID_PARAMETER Operation is invalid.\r
1699 @retval EFI_INVALID_PARAMETER HostAddress is NULL.\r
1700 @retval EFI_INVALID_PARAMETER NumberOfBytes is NULL.\r
1701 @retval EFI_INVALID_PARAMETER DeviceAddress is NULL.\r
1702 @retval EFI_INVALID_PARAMETER Mapping is NULL.\r
1703 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.\r
1704 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.\r
1705 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
1706\r
1707**/\r
21b404d1 1708EFI_STATUS\r
1709EFIAPI\r
1710RootBridgeIoMap (\r
1711 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1712 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,\r
1713 IN VOID *HostAddress,\r
1714 IN OUT UINTN *NumberOfBytes,\r
1715 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
1716 OUT VOID **Mapping\r
1717 )\r
21b404d1 1718{\r
1719 EFI_STATUS Status;\r
1720 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1721 MAP_INFO *MapInfo;\r
1722\r
1723 if (HostAddress == NULL || NumberOfBytes == NULL || DeviceAddress == NULL || Mapping == NULL) {\r
1724 return EFI_INVALID_PARAMETER;\r
1725 }\r
1726 \r
1727 //\r
1728 // Initialize the return values to their defaults\r
1729 //\r
1730 *Mapping = NULL;\r
1731\r
1732 //\r
1733 // Make sure that Operation is valid\r
1734 //\r
3d78c020 1735 if ((UINT32)Operation >= EfiPciOperationMaximum) {\r
21b404d1 1736 return EFI_INVALID_PARAMETER;\r
1737 }\r
1738\r
1739 //\r
1740 // Most PCAT like chipsets can not handle performing DMA above 4GB.\r
1741 // If any part of the DMA transfer being mapped is above 4GB, then\r
1742 // map the DMA transfer to a buffer below 4GB.\r
1743 //\r
1744 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
1745 if ((PhysicalAddress + *NumberOfBytes) > 0x100000000ULL) {\r
1746\r
1747 //\r
1748 // Common Buffer operations can not be remapped. If the common buffer\r
1749 // if above 4GB, then it is not possible to generate a mapping, so return \r
1750 // an error.\r
1751 //\r
1752 if (Operation == EfiPciOperationBusMasterCommonBuffer || Operation == EfiPciOperationBusMasterCommonBuffer64) {\r
1753 return EFI_UNSUPPORTED;\r
1754 }\r
1755\r
1756 //\r
1757 // Allocate a MAP_INFO structure to remember the mapping when Unmap() is\r
1758 // called later.\r
1759 //\r
1760 Status = gBS->AllocatePool (\r
1761 EfiBootServicesData, \r
1762 sizeof(MAP_INFO), \r
1763 (VOID **)&MapInfo\r
1764 );\r
1765 if (EFI_ERROR (Status)) {\r
1766 *NumberOfBytes = 0;\r
1767 return Status;\r
1768 }\r
1769\r
1770 //\r
1771 // Return a pointer to the MAP_INFO structure in Mapping\r
1772 //\r
1773 *Mapping = MapInfo;\r
1774\r
1775 //\r
1776 // Initialize the MAP_INFO structure\r
1777 //\r
1778 MapInfo->Operation = Operation;\r
1779 MapInfo->NumberOfBytes = *NumberOfBytes;\r
1780 MapInfo->NumberOfPages = EFI_SIZE_TO_PAGES(*NumberOfBytes);\r
1781 MapInfo->HostAddress = PhysicalAddress;\r
1782 MapInfo->MappedHostAddress = 0x00000000ffffffff;\r
1783\r
1784 //\r
1785 // Allocate a buffer below 4GB to map the transfer to.\r
1786 //\r
1787 Status = gBS->AllocatePages (\r
1788 AllocateMaxAddress, \r
1789 EfiBootServicesData, \r
1790 MapInfo->NumberOfPages,\r
1791 &MapInfo->MappedHostAddress\r
1792 );\r
1793 if (EFI_ERROR (Status)) {\r
1794 gBS->FreePool (MapInfo);\r
1795 *NumberOfBytes = 0;\r
1796 return Status;\r
1797 }\r
1798\r
1799 //\r
1800 // If this is a read operation from the Bus Master's point of view,\r
1801 // then copy the contents of the real buffer into the mapped buffer\r
1802 // so the Bus Master can read the contents of the real buffer.\r
1803 //\r
1804 if (Operation == EfiPciOperationBusMasterRead || Operation == EfiPciOperationBusMasterRead64) {\r
1805 CopyMem (\r
1806 (VOID *)(UINTN)MapInfo->MappedHostAddress, \r
1807 (VOID *)(UINTN)MapInfo->HostAddress,\r
1808 MapInfo->NumberOfBytes\r
1809 );\r
1810 }\r
1811\r
1812 //\r
1813 // The DeviceAddress is the address of the maped buffer below 4GB\r
1814 //\r
1815 *DeviceAddress = MapInfo->MappedHostAddress;\r
1816 } else {\r
1817 //\r
1818 // The transfer is below 4GB, so the DeviceAddress is simply the HostAddress\r
1819 //\r
1820 *DeviceAddress = PhysicalAddress;\r
1821 }\r
1822\r
1823 return EFI_SUCCESS;\r
1824}\r
1825\r
18c97f53 1826/**\r
1827 Completes the Map() operation and releases any corresponding resources.\r
1828\r
1829 The Unmap() function completes the Map() operation and releases any corresponding resources.\r
1830 If the operation was an EfiPciOperationBusMasterWrite or\r
1831 EfiPciOperationBusMasterWrite64, the data is committed to the target system memory.\r
1832 Any resources used for the mapping are freed. \r
1833\r
1834 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1835 @param[in] Mapping The mapping value returned from Map().\r
1836 \r
1837 @retval EFI_SUCCESS The range was unmapped.\r
1838 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().\r
1839 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.\r
1840\r
1841**/\r
21b404d1 1842EFI_STATUS\r
1843EFIAPI\r
1844RootBridgeIoUnmap (\r
1845 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1846 IN VOID *Mapping\r
1847 )\r
21b404d1 1848{\r
1849 MAP_INFO *MapInfo;\r
1850\r
1851 //\r
1852 // See if the Map() operation associated with this Unmap() required a mapping buffer.\r
1853 // If a mapping buffer was not required, then this function simply returns EFI_SUCCESS.\r
1854 //\r
1855 if (Mapping != NULL) {\r
1856 //\r
1857 // Get the MAP_INFO structure from Mapping\r
1858 //\r
1859 MapInfo = (MAP_INFO *)Mapping;\r
1860\r
1861 //\r
1862 // If this is a write operation from the Bus Master's point of view,\r
1863 // then copy the contents of the mapped buffer into the real buffer\r
1864 // so the processor can read the contents of the real buffer.\r
1865 //\r
1866 if (MapInfo->Operation == EfiPciOperationBusMasterWrite || MapInfo->Operation == EfiPciOperationBusMasterWrite64) {\r
1867 CopyMem (\r
1868 (VOID *)(UINTN)MapInfo->HostAddress, \r
1869 (VOID *)(UINTN)MapInfo->MappedHostAddress,\r
1870 MapInfo->NumberOfBytes\r
1871 );\r
1872 }\r
1873\r
1874 //\r
1875 // Free the mapped buffer and the MAP_INFO structure.\r
1876 //\r
1877 gBS->FreePages (MapInfo->MappedHostAddress, MapInfo->NumberOfPages);\r
1878 gBS->FreePool (Mapping);\r
1879 }\r
1880 return EFI_SUCCESS;\r
1881}\r
1882\r
18c97f53 1883/**\r
1884 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer or\r
1885 EfiPciOperationBusMasterCommonBuffer64 mapping.\r
1886 \r
1887 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1888 @param Type This parameter is not used and must be ignored.\r
1889 @param MemoryType The type of memory to allocate, EfiBootServicesData or EfiRuntimeServicesData.\r
1890 @param Pages The number of pages to allocate.\r
1891 @param HostAddress A pointer to store the base system memory address of the allocated range.\r
1892 @param Attributes The requested bit mask of attributes for the allocated range. Only\r
1893 the attributes EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE, EFI_PCI_ATTRIBUTE_MEMORY_CACHED, \r
1894 and EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this function.\r
1895 \r
1896 @retval EFI_SUCCESS The requested memory pages were allocated.\r
1897 @retval EFI_INVALID_PARAMETER MemoryType is invalid.\r
1898 @retval EFI_INVALID_PARAMETER HostAddress is NULL.\r
1899 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are\r
1900 MEMORY_WRITE_COMBINE, MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.\r
1901 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.\r
1902\r
1903**/\r
21b404d1 1904EFI_STATUS\r
1905EFIAPI\r
1906RootBridgeIoAllocateBuffer (\r
1907 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1908 IN EFI_ALLOCATE_TYPE Type,\r
1909 IN EFI_MEMORY_TYPE MemoryType,\r
1910 IN UINTN Pages,\r
1911 OUT VOID **HostAddress,\r
1912 IN UINT64 Attributes\r
1913 )\r
21b404d1 1914{\r
1915 EFI_STATUS Status;\r
1916 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1917\r
1918 //\r
1919 // Validate Attributes\r
1920 //\r
24115e44 1921 if ((Attributes & EFI_PCI_ATTRIBUTE_INVALID_FOR_ALLOCATE_BUFFER) != 0) {\r
21b404d1 1922 return EFI_UNSUPPORTED;\r
1923 }\r
1924\r
1925 //\r
1926 // Check for invalid inputs\r
1927 //\r
1928 if (HostAddress == NULL) {\r
1929 return EFI_INVALID_PARAMETER;\r
1930 }\r
1931 \r
1932 //\r
1933 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
1934 //\r
1935 if (MemoryType != EfiBootServicesData && MemoryType != EfiRuntimeServicesData) {\r
1936 return EFI_INVALID_PARAMETER;\r
1937 }\r
1938\r
1939 //\r
1940 // Limit allocations to memory below 4GB\r
1941 //\r
1942 PhysicalAddress = (EFI_PHYSICAL_ADDRESS)(0xffffffff);\r
1943\r
1944 Status = gBS->AllocatePages (AllocateMaxAddress, MemoryType, Pages, &PhysicalAddress);\r
1945 if (EFI_ERROR (Status)) {\r
1946 return Status;\r
1947 }\r
1948\r
1949 *HostAddress = (VOID *)(UINTN)PhysicalAddress;\r
1950\r
1951 return EFI_SUCCESS;\r
1952}\r
1953\r
18c97f53 1954/**\r
1955 Frees memory that was allocated with AllocateBuffer().\r
1956\r
1957 The FreeBuffer() function frees memory that was allocated with AllocateBuffer().\r
1958\r
1959 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1960 @param Pages The number of pages to free.\r
1961 @param HostAddress The base system memory address of the allocated range.\r
1962 \r
1963 @retval EFI_SUCCESS The requested memory pages were freed.\r
1964 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages\r
1965 was not allocated with AllocateBuffer().\r
1966\r
1967**/\r
21b404d1 1968EFI_STATUS\r
1969EFIAPI\r
1970RootBridgeIoFreeBuffer (\r
1971 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
1972 IN UINTN Pages,\r
1973 OUT VOID *HostAddress\r
1974 )\r
21b404d1 1975{\r
1976 return gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress, Pages);\r
1977}\r
1978\r
18c97f53 1979/**\r
1980 Flushes all PCI posted write transactions from a PCI host bridge to system memory.\r
1981\r
1982 The Flush() function flushes any PCI posted write transactions from a PCI host bridge to system\r
1983 memory. Posted write transactions are generated by PCI bus masters when they perform write\r
1984 transactions to target addresses in system memory.\r
1985 This function does not flush posted write transactions from any PCI bridges. A PCI controller\r
1986 specific action must be taken to guarantee that the posted write transactions have been flushed from\r
1987 the PCI controller and from all the PCI bridges into the PCI host bridge. This is typically done with\r
1988 a PCI read transaction from the PCI controller prior to calling Flush().\r
1989\r
1990 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
1991 \r
1992 @retval EFI_SUCCESS The PCI posted write transactions were flushed from the PCI host\r
1993 bridge to system memory.\r
1994 @retval EFI_DEVICE_ERROR The PCI posted write transactions were not flushed from the PCI\r
1995 host bridge due to a hardware error.\r
1996\r
1997**/\r
21b404d1 1998EFI_STATUS\r
1999EFIAPI\r
2000RootBridgeIoFlush (\r
2001 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This\r
2002 )\r
21b404d1 2003{\r
2004 //\r
2005 // not supported yet\r
2006 //\r
2007 return EFI_SUCCESS;\r
2008}\r
2009\r
18c97f53 2010/**\r
2011 Gets the attributes that a PCI root bridge supports setting with SetAttributes(), and the\r
2012 attributes that a PCI root bridge is currently using. \r
2013\r
2014 The GetAttributes() function returns the mask of attributes that this PCI root bridge supports\r
2015 and the mask of attributes that the PCI root bridge is currently using.\r
2016\r
2017 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
2018 @param Supported A pointer to the mask of attributes that this PCI root bridge\r
2019 supports setting with SetAttributes().\r
2020 @param Attributes A pointer to the mask of attributes that this PCI root bridge is\r
2021 currently using.\r
2022 \r
2023 @retval EFI_SUCCESS If Supports is not NULL, then the attributes that the PCI root\r
2024 bridge supports is returned in Supports. If Attributes is\r
2025 not NULL, then the attributes that the PCI root bridge is currently\r
2026 using is returned in Attributes.\r
2027 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.\r
2028\r
2029**/\r
21b404d1 2030EFI_STATUS\r
2031EFIAPI\r
2032RootBridgeIoGetAttributes (\r
2033 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
2034 OUT UINT64 *Supported,\r
2035 OUT UINT64 *Attributes\r
2036 )\r
21b404d1 2037{\r
2038 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
2039\r
2040 PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(This);\r
2041\r
2042 if (Attributes == NULL && Supported == NULL) {\r
2043 return EFI_INVALID_PARAMETER;\r
2044 }\r
2045\r
2046 //\r
2047 // Set the return value for Supported and Attributes\r
2048 //\r
24115e44 2049 if (Supported != NULL) {\r
21b404d1 2050 *Supported = PrivateData->Supports; \r
2051 }\r
2052\r
24115e44 2053 if (Attributes != NULL) {\r
21b404d1 2054 *Attributes = PrivateData->Attributes;\r
2055 }\r
2056 \r
2057 return EFI_SUCCESS;\r
2058}\r
2059\r
18c97f53 2060/**\r
2061 Sets attributes for a resource range on a PCI root bridge.\r
2062\r
2063 The SetAttributes() function sets the attributes specified in Attributes for the PCI root\r
2064 bridge on the resource range specified by ResourceBase and ResourceLength. Since the\r
2065 granularity of setting these attributes may vary from resource type to resource type, and from\r
2066 platform to platform, the actual resource range and the one passed in by the caller may differ. As a\r
2067 result, this function may set the attributes specified by Attributes on a larger resource range\r
2068 than the caller requested. The actual range is returned in ResourceBase and\r
2069 ResourceLength. The caller is responsible for verifying that the actual range for which the\r
2070 attributes were set is acceptable.\r
2071\r
2072 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
2073 @param[in] Attributes The mask of attributes to set. If the attribute bit\r
2074 MEMORY_WRITE_COMBINE, MEMORY_CACHED, or\r
2075 MEMORY_DISABLE is set, then the resource range is specified by\r
2076 ResourceBase and ResourceLength. If\r
2077 MEMORY_WRITE_COMBINE, MEMORY_CACHED, and\r
2078 MEMORY_DISABLE are not set, then ResourceBase and\r
2079 ResourceLength are ignored, and may be NULL.\r
24115e44 2080 @param[in, out] ResourceBase A pointer to the base address of the resource range to be modified\r
18c97f53 2081 by the attributes specified by Attributes.\r
24115e44 2082 @param[in, out] ResourceLength A pointer to the length of the resource range to be modified by the\r
18c97f53 2083 attributes specified by Attributes.\r
2084 \r
2085 @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in Resources.\r
2086 @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be retrieved.\r
2087 @retval EFI_INVALID_PARAMETER Invalid pointer of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r
2088\r
2089**/\r
21b404d1 2090EFI_STATUS\r
2091EFIAPI\r
2092RootBridgeIoSetAttributes (\r
2093 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
2094 IN UINT64 Attributes,\r
2095 IN OUT UINT64 *ResourceBase,\r
2096 IN OUT UINT64 *ResourceLength \r
2097 )\r
21b404d1 2098{\r
2099 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
2100 \r
2101 PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(This);\r
2102 \r
24115e44 2103 if (Attributes != 0) {\r
21b404d1 2104 if ((Attributes & (~(PrivateData->Supports))) != 0) {\r
2105 return EFI_UNSUPPORTED;\r
2106 }\r
2107 }\r
2108 \r
2109 //\r
2110 // This is a generic driver for a PC-AT class system. It does not have any\r
2111 // chipset specific knowlegde, so none of the attributes can be set or \r
2112 // cleared. Any attempt to set attribute that are already set will succeed, \r
2113 // and any attempt to set an attribute that is not supported will fail.\r
2114 //\r
2115 if (Attributes & (~PrivateData->Attributes)) {\r
2116 return EFI_UNSUPPORTED;\r
2117 }\r
2118\r
2119 return EFI_SUCCESS;\r
2120}\r
2121\r
18c97f53 2122/**\r
2123 Retrieves the current resource settings of this PCI root bridge in the form of a set of ACPI 2.0\r
2124 resource descriptors.\r
2125\r
2126 There are only two resource descriptor types from the ACPI Specification that may be used to\r
2127 describe the current resources allocated to a PCI root bridge. These are the QWORD Address\r
2128 Space Descriptor (ACPI 2.0 Section 6.4.3.5.1), and the End Tag (ACPI 2.0 Section 6.4.2.8). The\r
2129 QWORD Address Space Descriptor can describe memory, I/O, and bus number ranges for dynamic\r
2130 or fixed resources. The configuration of a PCI root bridge is described with one or more QWORD\r
2131 Address Space Descriptors followed by an End Tag.\r
2132\r
2133 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.\r
2134 @param[out] Resources A pointer to the ACPI 2.0 resource descriptors that describe the\r
2135 current configuration of this PCI root bridge. The storage for the\r
2136 ACPI 2.0 resource descriptors is allocated by this function. The\r
2137 caller must treat the return buffer as read-only data, and the buffer\r
2138 must not be freed by the caller.\r
2139 \r
2140 @retval EFI_SUCCESS The current configuration of this PCI root bridge was returned in Resources.\r
2141 @retval EFI_UNSUPPORTED The current configuration of this PCI root bridge could not be retrieved.\r
2142 @retval EFI_INVALID_PARAMETER Invalid pointer of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r
2143\r
2144**/\r
21b404d1 2145EFI_STATUS\r
2146EFIAPI\r
2147RootBridgeIoConfiguration (\r
2148 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,\r
2149 OUT VOID **Resources\r
2150 )\r
21b404d1 2151{\r
2152 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
2153 UINTN Index;\r
2154\r
2155 PrivateData = DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS (This);\r
2156 \r
2157 for (Index = 0; Index < TypeMax; Index++) {\r
2158 if (PrivateData->ResAllocNode[Index].Status == ResAllocated) {\r
2159 Configuration.SpaceDesp[Index].AddrRangeMin = PrivateData->ResAllocNode[Index].Base;\r
2160 Configuration.SpaceDesp[Index].AddrRangeMax = PrivateData->ResAllocNode[Index].Base + PrivateData->ResAllocNode[Index].Length - 1;\r
2161 Configuration.SpaceDesp[Index].AddrLen = PrivateData->ResAllocNode[Index].Length;\r
2162 } \r
2163 } \r
2164 \r
2165 *Resources = &Configuration; \r
2166 return EFI_SUCCESS;\r
2167}\r
2168\r