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