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