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