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