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