]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridge.h
MdeModulePkg/PciHostBridge: Refine function header comments.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciHostBridgeDxe / PciRootBridge.h
1 /** @file
2
3 The PCI Root Bridge header file.
4
5 Copyright (c) 1999 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _PCI_ROOT_BRIDGE_H_
17 #define _PCI_ROOT_BRIDGE_H_
18
19 #include <PiDxe.h>
20 #include <IndustryStandard/Acpi.h>
21 #include <IndustryStandard/Pci.h>
22
23 //
24 // Driver Consumed Protocol Prototypes
25 //
26 #include <Protocol/Metronome.h>
27 #include <Protocol/CpuIo2.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/PciRootBridgeIo.h>
30 #include <Library/DebugLib.h>
31 #include <Library/DevicePathLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/DxeServicesTableLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/BaseLib.h>
36 #include <Library/PciSegmentLib.h>
37 #include "PciHostResource.h"
38
39
40 typedef enum {
41 IoOperation,
42 MemOperation,
43 PciOperation
44 } OPERATION_TYPE;
45
46 #define MAP_INFO_SIGNATURE SIGNATURE_32 ('_', 'm', 'a', 'p')
47 typedef struct {
48 UINT32 Signature;
49 LIST_ENTRY Link;
50 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation;
51 UINTN NumberOfBytes;
52 UINTN NumberOfPages;
53 EFI_PHYSICAL_ADDRESS HostAddress;
54 EFI_PHYSICAL_ADDRESS MappedHostAddress;
55 } MAP_INFO;
56 #define MAP_INFO_FROM_LINK(a) CR (a, MAP_INFO, Link, MAP_INFO_SIGNATURE)
57
58 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('_', 'p', 'r', 'b')
59
60 typedef struct {
61 UINT32 Signature;
62 LIST_ENTRY Link;
63 EFI_HANDLE Handle;
64 UINT64 AllocationAttributes;
65 UINT64 Attributes;
66 UINT64 Supports;
67 PCI_RES_NODE ResAllocNode[TypeMax];
68 PCI_ROOT_BRIDGE_APERTURE Bus;
69 PCI_ROOT_BRIDGE_APERTURE Io;
70 PCI_ROOT_BRIDGE_APERTURE Mem;
71 PCI_ROOT_BRIDGE_APERTURE PMem;
72 PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
73 PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;
74 BOOLEAN DmaAbove4G;
75 VOID *ConfigBuffer;
76 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
77 CHAR16 *DevicePathStr;
78 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL RootBridgeIo;
79
80 BOOLEAN ResourceSubmitted;
81 LIST_ENTRY Maps;
82 } PCI_ROOT_BRIDGE_INSTANCE;
83
84 #define ROOT_BRIDGE_FROM_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, RootBridgeIo, PCI_ROOT_BRIDGE_SIGNATURE)
85
86 #define ROOT_BRIDGE_FROM_LINK(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
87
88 /**
89 Construct the Pci Root Bridge instance.
90
91 @param Bridge The root bridge instance.
92 @param HostBridgeHandle Handle to the HostBridge.
93
94 @return The pointer to PCI_ROOT_BRIDGE_INSTANCE just created
95 or NULL if creation fails.
96 **/
97 PCI_ROOT_BRIDGE_INSTANCE *
98 CreateRootBridge (
99 IN PCI_ROOT_BRIDGE *Bridge,
100 IN EFI_HANDLE HostBridgeHandle
101 );
102
103 //
104 // Protocol Member Function Prototypes
105 //
106 /**
107
108 Poll an address in memory mapped space until an exit condition is met
109 or a timeout occurs.
110
111 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
112 @param Width - Width of the memory operation.
113 @param Address - The base address of the memory operation.
114 @param Mask - Mask used for polling criteria.
115 @param Value - Comparison value used for polling exit criteria.
116 @param Delay - Number of 100ns units to poll.
117 @param Result - Pointer to the last value read from memory location.
118
119 @retval EFI_SUCCESS - Success.
120 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
121 @retval EFI_TIMEOUT - Delay expired before a match occurred.
122 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
123
124 **/
125 EFI_STATUS
126 EFIAPI
127 RootBridgeIoPollMem (
128 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
129 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
130 IN UINT64 Address,
131 IN UINT64 Mask,
132 IN UINT64 Value,
133 IN UINT64 Delay,
134 OUT UINT64 *Result
135 )
136 ;
137
138 /**
139
140 Poll an address in I/O space until an exit condition is met
141 or a timeout occurs.
142
143 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
144 @param Width - Width of I/O operation.
145 @param Address - The base address of the I/O operation.
146 @param Mask - Mask used for polling criteria.
147 @param Value - Comparison value used for polling exit criteria.
148 @param Delay - Number of 100ns units to poll.
149 @param Result - Pointer to the last value read from memory location.
150
151 @retval EFI_SUCCESS - Success.
152 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
153 @retval EFI_TIMEOUT - Delay expired before a match occurred.
154 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 RootBridgeIoPollIo (
160 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
161 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
162 IN UINT64 Address,
163 IN UINT64 Mask,
164 IN UINT64 Value,
165 IN UINT64 Delay,
166 OUT UINT64 *Result
167 )
168 ;
169
170 /**
171
172 Allow read from memory mapped I/O space.
173
174 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
175 @param Width - The width of memory operation.
176 @param Address - Base address of the memory operation.
177 @param Count - Number of memory opeartion to perform.
178 @param Buffer - The destination buffer to store data.
179
180 @retval EFI_SUCCESS - Success.
181 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
182 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
183
184 **/
185 EFI_STATUS
186 EFIAPI
187 RootBridgeIoMemRead (
188 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
189 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
190 IN UINT64 Address,
191 IN UINTN Count,
192 IN OUT VOID *Buffer
193 )
194 ;
195
196 /**
197
198 Allow write to memory mapped I/O space.
199
200 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
201 @param Width - The width of memory operation.
202 @param Address - Base address of the memory operation.
203 @param Count - Number of memory opeartion to perform.
204 @param Buffer - The source buffer to write data from.
205
206 @retval EFI_SUCCESS - Success.
207 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
208 @retval EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
209
210 **/
211 EFI_STATUS
212 EFIAPI
213 RootBridgeIoMemWrite (
214 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
215 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
216 IN UINT64 Address,
217 IN UINTN Count,
218 IN OUT VOID *Buffer
219 )
220 ;
221
222 /**
223
224 Enable a PCI driver to read PCI controller registers in the
225 PCI root bridge I/O space.
226
227 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
228 @param Width - Signifies the width of the memory operation.
229 @param UserAddress - The base address of the I/O operation.
230 @param Count - The number of I/O operations to perform.
231 @param UserBuffer - The destination buffer to store the results.
232
233 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
234 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
235 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
236 @retval resources.
237 **/
238 EFI_STATUS
239 EFIAPI
240 RootBridgeIoIoRead (
241 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
242 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
243 IN UINT64 UserAddress,
244 IN UINTN Count,
245 IN OUT VOID *UserBuffer
246 )
247 ;
248
249 /**
250
251 Enable a PCI driver to write to PCI controller registers in the
252 PCI root bridge I/O space.
253
254 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
255 @param Width - Signifies the width of the memory operation.
256 @param UserAddress - The base address of the I/O operation.
257 @param Count - The number of I/O operations to perform.
258 @param UserBuffer - The source buffer to write data from.
259
260 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
261 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
262 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
263 @retval resources.
264 **/
265 EFI_STATUS
266 EFIAPI
267 RootBridgeIoIoWrite (
268 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
269 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
270 IN UINT64 UserAddress,
271 IN UINTN Count,
272 IN OUT VOID *UserBuffer
273 )
274 ;
275
276 /**
277
278 Copy one region of PCI root bridge memory space to be copied to
279 another region of PCI root bridge memory space.
280
281 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
282 @param Width - Signifies the width of the memory operation.
283 @param DestAddress - Destination address of the memory operation.
284 @param SrcAddress - Source address of the memory operation.
285 @param Count - Number of memory operations to perform.
286
287 @retval EFI_SUCCESS - The data was copied successfully.
288 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
289 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
290 @retval resources.
291 **/
292 EFI_STATUS
293 EFIAPI
294 RootBridgeIoCopyMem (
295 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
296 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
297 IN UINT64 DestAddress,
298 IN UINT64 SrcAddress,
299 IN UINTN Count
300 )
301 ;
302
303 /**
304
305 Allows read from PCI configuration space.
306
307 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
308 @param Width - Signifies the width of the memory operation.
309 @param Address - The address within the PCI configuration space
310 for the PCI controller.
311 @param Count - The number of PCI configuration operations
312 to perform.
313 @param Buffer - The destination buffer to store the results.
314
315 @retval EFI_SUCCESS - The data was read from the PCI root bridge.
316 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
317 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
318 @retval resources.
319 **/
320 EFI_STATUS
321 EFIAPI
322 RootBridgeIoPciRead (
323 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
324 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
325 IN UINT64 Address,
326 IN UINTN Count,
327 IN OUT VOID *Buffer
328 )
329 ;
330
331 /**
332
333 Allows write to PCI configuration space.
334
335 @param This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
336 @param Width - Signifies the width of the memory operation.
337 @param Address - The address within the PCI configuration space
338 for the PCI controller.
339 @param Count - The number of PCI configuration operations
340 to perform.
341 @param Buffer - The source buffer to get the results.
342
343 @retval EFI_SUCCESS - The data was written to the PCI root bridge.
344 @retval EFI_INVALID_PARAMETER - Invalid parameters found.
345 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
346 @retval resources.
347 **/
348 EFI_STATUS
349 EFIAPI
350 RootBridgeIoPciWrite (
351 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
352 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
353 IN UINT64 Address,
354 IN UINTN Count,
355 IN OUT VOID *Buffer
356 )
357 ;
358
359 /**
360 Provides the PCI controller-specific address needed to access
361 system memory for DMA.
362
363 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
364 @param Operation Indicate if the bus master is going to read or write
365 to system memory.
366 @param HostAddress The system memory address to map on the PCI controller.
367 @param NumberOfBytes On input the number of bytes to map.
368 On output the number of bytes that were mapped.
369 @param DeviceAddress The resulting map address for the bus master PCI
370 controller to use to access the system memory's HostAddress.
371 @param Mapping The value to pass to Unmap() when the bus master DMA
372 operation is complete.
373
374 @retval EFI_SUCCESS Success.
375 @retval EFI_INVALID_PARAMETER Invalid parameters found.
376 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
377 @retval EFI_DEVICE_ERROR The System hardware could not map the requested address.
378 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to lack of resources.
379 **/
380 EFI_STATUS
381 EFIAPI
382 RootBridgeIoMap (
383 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
384 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,
385 IN VOID *HostAddress,
386 IN OUT UINTN *NumberOfBytes,
387 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
388 OUT VOID **Mapping
389 )
390 ;
391
392 /**
393 Completes the Map() operation and releases any corresponding resources.
394
395 The Unmap() function completes the Map() operation and releases any
396 corresponding resources.
397 If the operation was an EfiPciOperationBusMasterWrite or
398 EfiPciOperationBusMasterWrite64, the data is committed to the target system
399 memory.
400 Any resources used for the mapping are freed.
401
402 @param[in] This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
403 @param[in] Mapping The mapping value returned from Map().
404
405 @retval EFI_SUCCESS The range was unmapped.
406 @retval EFI_INVALID_PARAMETER Mapping is not a value that was returned by Map().
407 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
408 **/
409 EFI_STATUS
410 EFIAPI
411 RootBridgeIoUnmap (
412 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
413 IN VOID *Mapping
414 )
415 ;
416
417 /**
418 Allocates pages that are suitable for an EfiPciOperationBusMasterCommonBuffer
419 or EfiPciOperationBusMasterCommonBuffer64 mapping.
420
421 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
422 @param Type This parameter is not used and must be ignored.
423 @param MemoryType The type of memory to allocate, EfiBootServicesData or
424 EfiRuntimeServicesData.
425 @param Pages The number of pages to allocate.
426 @param HostAddress A pointer to store the base system memory address of the
427 allocated range.
428 @param Attributes The requested bit mask of attributes for the allocated
429 range. Only the attributes
430 EFI_PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE,
431 EFI_PCI_ATTRIBUTE_MEMORY_CACHED, and
432 EFI_PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE may be used with this
433 function.
434
435 @retval EFI_SUCCESS The requested memory pages were allocated.
436 @retval EFI_INVALID_PARAMETER MemoryType is invalid.
437 @retval EFI_INVALID_PARAMETER HostAddress is NULL.
438 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal
439 attribute bits are MEMORY_WRITE_COMBINE,
440 MEMORY_CACHED, and DUAL_ADDRESS_CYCLE.
441 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
442 **/
443 EFI_STATUS
444 EFIAPI
445 RootBridgeIoAllocateBuffer (
446 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
447 IN EFI_ALLOCATE_TYPE Type,
448 IN EFI_MEMORY_TYPE MemoryType,
449 IN UINTN Pages,
450 OUT VOID **HostAddress,
451 IN UINT64 Attributes
452 )
453 ;
454
455 /**
456
457 Free memory allocated in AllocateBuffer.
458
459 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
460 instance.
461 @param Pages - Number of pages to free.
462 @param HostAddress - The base system memory address of the
463 allocated range.
464
465 @retval EFI_SUCCESS - Requested memory pages were freed.
466 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
467
468 **/
469 EFI_STATUS
470 EFIAPI
471 RootBridgeIoFreeBuffer (
472 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
473 IN UINTN Pages,
474 OUT VOID *HostAddress
475 )
476 ;
477
478 /**
479
480 Flushes all PCI posted write transactions from a PCI host
481 bridge to system memory.
482
483 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
484
485 @retval EFI_SUCCESS - PCI posted write transactions were flushed
486 @retval from PCI host bridge to system memory.
487 @retval EFI_DEVICE_ERROR - Fail due to hardware error.
488
489 **/
490 EFI_STATUS
491 EFIAPI
492 RootBridgeIoFlush (
493 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This
494 )
495 ;
496
497 /**
498 Gets the attributes that a PCI root bridge supports setting with
499 SetAttributes(), and the attributes that a PCI root bridge is currently
500 using.
501
502 The GetAttributes() function returns the mask of attributes that this PCI
503 root bridge supports and the mask of attributes that the PCI root bridge is
504 currently using.
505
506 @param This A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
507 @param Supported A pointer to the mask of attributes that this PCI root
508 bridge supports setting with SetAttributes().
509 @param Attributes A pointer to the mask of attributes that this PCI root
510 bridge is currently using.
511
512 @retval EFI_SUCCESS If Supports is not NULL, then the attributes
513 that the PCI root bridge supports is returned
514 in Supports. If Attributes is not NULL, then
515 the attributes that the PCI root bridge is
516 currently using is returned in Attributes.
517 @retval EFI_INVALID_PARAMETER Both Supports and Attributes are NULL.
518 **/
519 EFI_STATUS
520 EFIAPI
521 RootBridgeIoGetAttributes (
522 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
523 OUT UINT64 *Supported,
524 OUT UINT64 *Attributes
525 )
526 ;
527
528 /**
529
530 Sets the attributes for a resource range on a PCI root bridge.
531
532 @param This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
533 @param Attributes - The mask of attributes to set.
534 @param ResourceBase - Pointer to the base address of the resource range
535 to be modified by the attributes specified by Attributes.
536 @param ResourceLength - Pointer to the length of the resource range to be modified.
537
538 @retval EFI_SUCCESS - Success.
539 @retval EFI_INVALID_PARAMETER - Invalid parameter found.
540 @retval EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
541
542 **/
543 EFI_STATUS
544 EFIAPI
545 RootBridgeIoSetAttributes (
546 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
547 IN UINT64 Attributes,
548 IN OUT UINT64 *ResourceBase,
549 IN OUT UINT64 *ResourceLength
550 )
551 ;
552
553 /**
554
555 Retrieves the current resource settings of this PCI root bridge
556 in the form of a set of ACPI 2.0 resource descriptor.
557
558 @param This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
559 @param Resources - Pointer to the ACPI 2.0 resource descriptor that
560 describe the current configuration of this PCI root
561 bridge.
562
563 @retval EFI_SUCCESS - Success.
564 @retval EFI_UNSUPPORTED - Current configuration of the PCI root bridge
565 @retval could not be retrieved.
566
567 **/
568 EFI_STATUS
569 EFIAPI
570 RootBridgeIoConfiguration (
571 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
572 OUT VOID **Resources
573 )
574 ;
575
576
577 extern EFI_METRONOME_ARCH_PROTOCOL *mMetronome;
578 extern EFI_CPU_IO2_PROTOCOL *mCpuIo;
579 #endif