]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkPlatformPkg/Pci/Dxe/PciHostBridge/PciRootBridge.h
613265d2fff15a8f8013e422c090edda70642722
[mirror_edk2.git] / QuarkPlatformPkg / Pci / Dxe / PciHostBridge / PciRootBridge.h
1 /** @file
2 The PCI Root Bridge header file.
3
4 Copyright (c) 2013-2015 Intel Corporation.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8
9 **/
10
11 #ifndef _PCI_ROOT_BRIDGE_H_
12 #define _PCI_ROOT_BRIDGE_H_
13
14 #include <PiDxe.h>
15 #include <IndustryStandard/Acpi.h>
16 #include <IndustryStandard/Pci.h>
17 #include <PciHostResource.h>
18
19 //
20 // Driver Consumed Protocol Prototypes
21 //
22 #include <Protocol/Metronome.h>
23 #include <Protocol/CpuIo2.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/Runtime.h>
26 #include <Protocol/PciRootBridgeIo.h>
27 #include <Library/UefiLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/DevicePathLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/DxeServicesTableLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/BaseLib.h>
34
35
36 //
37 // Define the region of memory used for DMA memory
38 //
39 #define DMA_MEMORY_TOP 0x0000000001FFFFFFULL
40
41 //
42 // The number of PCI root bridges
43 //
44 #define ROOT_BRIDGE_COUNT 1
45
46 //
47 // The default latency for controllers
48 //
49 #define DEFAULT_PCI_LATENCY 0x20
50
51 //
52 // Define resource status constant
53 //
54 typedef struct {
55 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation;
56 UINTN NumberOfBytes;
57 UINTN NumberOfPages;
58 EFI_PHYSICAL_ADDRESS HostAddress;
59 EFI_PHYSICAL_ADDRESS MappedHostAddress;
60 } MAP_INFO;
61
62 typedef struct {
63 ACPI_HID_DEVICE_PATH AcpiDevicePath;
64 EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
65 } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
66
67 #define PCI_ROOT_BRIDGE_SIGNATURE SIGNATURE_32 ('e', '2', 'p', 'b')
68
69 typedef struct {
70 UINT32 Signature;
71 EFI_LIST_ENTRY Link;
72 EFI_HANDLE Handle;
73 UINT64 RootBridgeAllocAttrib;
74 UINT64 Attributes;
75 UINT64 Supports;
76 PCI_RES_NODE ResAllocNode[6];
77 PCI_ROOT_BRIDGE_RESOURCE_APERTURE Aperture;
78 EFI_LOCK PciLock;
79 UINTN PciAddress;
80 UINTN PciData;
81 UINT32 HecBase;
82 UINT32 HecLen;
83 UINTN BusScanCount;
84 BOOLEAN BusNumberAssigned;
85 VOID *ConfigBuffer;
86 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
87 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL Io;
88 } PCI_ROOT_BRIDGE_INSTANCE;
89
90 //
91 // Driver Instance Data Macros
92 //
93 #define DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Io, PCI_ROOT_BRIDGE_SIGNATURE)
94
95 #define DRIVER_INSTANCE_FROM_LIST_ENTRY(a) CR (a, PCI_ROOT_BRIDGE_INSTANCE, Link, PCI_ROOT_BRIDGE_SIGNATURE)
96
97 EFI_STATUS
98 SimpleIioRootBridgeConstructor (
99 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *Protocol,
100 IN EFI_HANDLE HostBridgeHandle,
101 IN PCI_ROOT_BRIDGE_RESOURCE_APERTURE *ResAppeture,
102 IN UINT64 AllocAttributes
103 )
104 /*++
105
106 Routine Description:
107
108 Construct the Pci Root Bridge Io protocol.
109
110 Arguments:
111
112 Protocol - Protocol to initialize.
113 HostBridgeHandle - Handle to the HostBridge.
114 ResAppeture - Resource apperture of the root bridge.
115 AllocAttributes - Attribute of resouce allocated.
116
117 Returns:
118
119 EFI_SUCCESS - Success.
120 Others - Fail.
121
122 --*/
123 ;
124
125 //
126 // Protocol Member Function Prototypes
127 //
128 EFI_STATUS
129 EFIAPI
130 RootBridgeIoPollMem (
131 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
132 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
133 IN UINT64 Address,
134 IN UINT64 Mask,
135 IN UINT64 Value,
136 IN UINT64 Delay,
137 OUT UINT64 *Result
138 )
139 /*++
140
141 Routine Description:
142
143 Poll an address in memory mapped space until an exit condition is met
144 or a timeout occurs.
145
146 Arguments:
147
148 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
149 Width - Width of the memory operation.
150 Address - The base address of the memory operation.
151 Mask - Mask used for polling criteria.
152 Value - Comparison value used for polling exit criteria.
153 Delay - Number of 100ns units to poll.
154 Result - Pointer to the last value read from memory location.
155
156 Returns:
157
158 EFI_SUCCESS - Success.
159 EFI_INVALID_PARAMETER - Invalid parameter found.
160 EFI_TIMEOUT - Delay expired before a match occurred.
161 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
162
163 --*/
164 ;
165
166 EFI_STATUS
167 EFIAPI
168 RootBridgeIoPollIo (
169 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
170 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
171 IN UINT64 Address,
172 IN UINT64 Mask,
173 IN UINT64 Value,
174 IN UINT64 Delay,
175 OUT UINT64 *Result
176 )
177 /*++
178
179 Routine Description:
180
181 Poll an address in I/O space until an exit condition is met
182 or a timeout occurs.
183
184 Arguments:
185
186 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
187 Width - Width of I/O operation.
188 Address - The base address of the I/O operation.
189 Mask - Mask used for polling criteria.
190 Value - Comparison value used for polling exit criteria.
191 Delay - Number of 100ns units to poll.
192 Result - Pointer to the last value read from memory location.
193
194 Returns:
195
196 EFI_SUCCESS - Success.
197 EFI_INVALID_PARAMETER - Invalid parameter found.
198 EFI_TIMEOUT - Delay expired before a match occurred.
199 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
200
201 --*/
202 ;
203
204 EFI_STATUS
205 EFIAPI
206 RootBridgeIoMemRead (
207 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
208 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
209 IN UINT64 Address,
210 IN UINTN Count,
211 IN OUT VOID *Buffer
212 )
213 /*++
214
215 Routine Description:
216
217 Allow read from memory mapped I/O space.
218
219 Arguments:
220
221 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
222 Width - The width of memory operation.
223 Address - Base address of the memory operation.
224 Count - Number of memory opeartion to perform.
225 Buffer - The destination buffer to store data.
226
227 Returns:
228
229 EFI_SUCCESS - Success.
230 EFI_INVALID_PARAMETER - Invalid parameter found.
231 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
232
233 --*/
234 ;
235
236 EFI_STATUS
237 EFIAPI
238 RootBridgeIoMemWrite (
239 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
240 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
241 IN UINT64 Address,
242 IN UINTN Count,
243 IN OUT VOID *Buffer
244 )
245 /*++
246
247 Routine Description:
248
249 Allow write to memory mapped I/O space.
250
251 Arguments:
252
253 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
254 Width - The width of memory operation.
255 Address - Base address of the memory operation.
256 Count - Number of memory opeartion to perform.
257 Buffer - The source buffer to write data from.
258
259 Returns:
260
261 EFI_SUCCESS - Success.
262 EFI_INVALID_PARAMETER - Invalid parameter found.
263 EFI_OUT_OF_RESOURCES - Fail due to lack of resources.
264
265 --*/
266 ;
267
268 EFI_STATUS
269 EFIAPI
270 RootBridgeIoIoRead (
271 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
272 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
273 IN UINT64 UserAddress,
274 IN UINTN Count,
275 IN OUT VOID *UserBuffer
276 )
277 /*++
278
279 Routine Description:
280
281 Enable a PCI driver to read PCI controller registers in the
282 PCI root bridge I/O space.
283
284 Arguments:
285
286 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
287 Width - Signifies the width of the memory operation.
288 UserAddress - The base address of the I/O operation.
289 Count - The number of I/O operations to perform.
290 UserBuffer - The destination buffer to store the results.
291
292 Returns:
293
294 EFI_SUCCESS - The data was read from the PCI root bridge.
295 EFI_INVALID_PARAMETER - Invalid parameters found.
296 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
297 resources.
298 --*/
299 ;
300
301 EFI_STATUS
302 EFIAPI
303 RootBridgeIoIoWrite (
304 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
305 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
306 IN UINT64 UserAddress,
307 IN UINTN Count,
308 IN OUT VOID *UserBuffer
309 )
310 /*++
311
312 Routine Description:
313
314 Enable a PCI driver to write to PCI controller registers in the
315 PCI root bridge I/O space.
316
317 Arguments:
318
319 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
320 Width - Signifies the width of the memory operation.
321 UserAddress - The base address of the I/O operation.
322 Count - The number of I/O operations to perform.
323 UserBuffer - The source buffer to write data from.
324
325 Returns:
326
327 EFI_SUCCESS - The data was written to the PCI root bridge.
328 EFI_INVALID_PARAMETER - Invalid parameters found.
329 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
330 resources.
331 --*/
332 ;
333
334 EFI_STATUS
335 EFIAPI
336 RootBridgeIoCopyMem (
337 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
338 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
339 IN UINT64 DestAddress,
340 IN UINT64 SrcAddress,
341 IN UINTN Count
342 )
343 /*++
344
345 Routine Description:
346
347 Copy one region of PCI root bridge memory space to be copied to
348 another region of PCI root bridge memory space.
349
350 Arguments:
351
352 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
353 Width - Signifies the width of the memory operation.
354 DestAddress - Destination address of the memory operation.
355 SrcAddress - Source address of the memory operation.
356 Count - Number of memory operations to perform.
357
358 Returns:
359
360 EFI_SUCCESS - The data was copied successfully.
361 EFI_INVALID_PARAMETER - Invalid parameters found.
362 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
363 resources.
364 --*/
365 ;
366
367 EFI_STATUS
368 EFIAPI
369 RootBridgeIoPciRead (
370 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
371 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
372 IN UINT64 Address,
373 IN UINTN Count,
374 IN OUT VOID *Buffer
375 )
376 /*++
377
378 Routine Description:
379
380 Allows read from PCI configuration space.
381
382 Arguments:
383
384 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
385 Width - Signifies the width of the memory operation.
386 Address - The address within the PCI configuration space
387 for the PCI controller.
388 Count - The number of PCI configuration operations
389 to perform.
390 Buffer - The destination buffer to store the results.
391
392 Returns:
393
394 EFI_SUCCESS - The data was read from the PCI root bridge.
395 EFI_INVALID_PARAMETER - Invalid parameters found.
396 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
397 resources.
398 --*/
399 ;
400
401 EFI_STATUS
402 EFIAPI
403 RootBridgeIoPciWrite (
404 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
405 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
406 IN UINT64 Address,
407 IN UINTN Count,
408 IN OUT VOID *Buffer
409 )
410 /*++
411
412 Routine Description:
413
414 Allows write to PCI configuration space.
415
416 Arguments:
417
418 This - A pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
419 Width - Signifies the width of the memory operation.
420 Address - The address within the PCI configuration space
421 for the PCI controller.
422 Count - The number of PCI configuration operations
423 to perform.
424 Buffer - The source buffer to get the results.
425
426 Returns:
427
428 EFI_SUCCESS - The data was written to the PCI root bridge.
429 EFI_INVALID_PARAMETER - Invalid parameters found.
430 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
431 resources.
432 --*/
433 ;
434
435 EFI_STATUS
436 EFIAPI
437 RootBridgeIoMap (
438 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
439 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION Operation,
440 IN VOID *HostAddress,
441 IN OUT UINTN *NumberOfBytes,
442 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
443 OUT VOID **Mapping
444 )
445 /*++
446
447 Routine Description:
448
449 Provides the PCI controller-specific address needed to access
450 system memory for DMA.
451
452 Arguments:
453
454 This - A pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.
455 Operation - Indicate if the bus master is going to read or write
456 to system memory.
457 HostAddress - The system memory address to map on the PCI controller.
458 NumberOfBytes - On input the number of bytes to map.
459 On output the number of bytes that were mapped.
460 DeviceAddress - The resulting map address for the bus master PCI
461 controller to use to access the system memory's HostAddress.
462 Mapping - The value to pass to Unmap() when the bus master DMA
463 operation is complete.
464
465 Returns:
466
467 EFI_SUCCESS - Success.
468 EFI_INVALID_PARAMETER - Invalid parameters found.
469 EFI_UNSUPPORTED - The HostAddress cannot be mapped as a common
470 buffer.
471 EFI_DEVICE_ERROR - The System hardware could not map the requested
472 address.
473 EFI_OUT_OF_RESOURCES - The request could not be completed due to
474 lack of resources.
475
476 --*/
477 ;
478
479 EFI_STATUS
480 EFIAPI
481 RootBridgeIoUnmap (
482 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
483 IN VOID *Mapping
484 )
485 /*++
486
487 Routine Description:
488
489 Completes the Map() operation and releases any corresponding resources.
490
491 Arguments:
492
493 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
494 Mapping - The value returned from Map() operation.
495
496 Returns:
497
498 EFI_SUCCESS - The range was unmapped successfully.
499 EFI_INVALID_PARAMETER - Mapping is not a value that was returned
500 by Map operation.
501 EFI_DEVICE_ERROR - The data was not committed to the target
502 system memory.
503
504 --*/
505 ;
506
507 EFI_STATUS
508 EFIAPI
509 RootBridgeIoAllocateBuffer (
510 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
511 IN EFI_ALLOCATE_TYPE Type,
512 IN EFI_MEMORY_TYPE MemoryType,
513 IN UINTN Pages,
514 OUT VOID **HostAddress,
515 IN UINT64 Attributes
516 )
517 /*++
518
519 Routine Description:
520
521 Allocates pages that are suitable for a common buffer mapping.
522
523 Arguments:
524
525 This - Pointer to EFI_ROOT_BRIDGE_IO_PROTOCOL instance.
526 Type - Not used and can be ignored.
527 MemoryType - Type of memory to allocate.
528 Pages - Number of pages to allocate.
529 HostAddress - Pointer to store the base system memory address
530 of the allocated range.
531 Attributes - Requested bit mask of attributes of the allocated
532 range.
533
534 Returns:
535
536 EFI_SUCCESS - The requested memory range were allocated.
537 EFI_INVALID_PARAMETER - Invalid parameter found.
538 EFI_UNSUPPORTED - Attributes is unsupported.
539
540 --*/
541 ;
542
543 EFI_STATUS
544 EFIAPI
545 RootBridgeIoFreeBuffer (
546 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
547 IN UINTN Pages,
548 OUT VOID *HostAddress
549 )
550 /*++
551
552 Routine Description:
553
554 Free memory allocated in AllocateBuffer.
555
556 Arguments:
557
558 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
559 instance.
560 Pages - Number of pages to free.
561 HostAddress - The base system memory address of the
562 allocated range.
563
564 Returns:
565
566 EFI_SUCCESS - Requested memory pages were freed.
567 EFI_INVALID_PARAMETER - Invalid parameter found.
568
569 --*/
570 ;
571
572 EFI_STATUS
573 EFIAPI
574 RootBridgeIoFlush (
575 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This
576 )
577 /*++
578
579 Routine Description:
580
581 Flushes all PCI posted write transactions from a PCI host
582 bridge to system memory.
583
584 Arguments:
585
586 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
587
588 Returns:
589
590 EFI_SUCCESS - PCI posted write transactions were flushed
591 from PCI host bridge to system memory.
592 EFI_DEVICE_ERROR - Fail due to hardware error.
593
594 --*/
595 ;
596
597 EFI_STATUS
598 EFIAPI
599 RootBridgeIoGetAttributes (
600 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
601 OUT UINT64 *Supported,
602 OUT UINT64 *Attributes
603 )
604 /*++
605
606 Routine Description:
607
608 Get the attributes that a PCI root bridge supports and
609 the attributes the PCI root bridge is currently using.
610
611 Arguments:
612
613 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
614 instance.
615 Supports - A pointer to the mask of attributes that
616 this PCI root bridge supports.
617 Attributes - A pointer to the mask of attributes that
618 this PCI root bridge is currently using.
619 Returns:
620
621 EFI_SUCCESS - Success.
622 EFI_INVALID_PARAMETER - Invalid parameter found.
623
624 --*/
625
626 // GC_TODO: Supported - add argument and description to function comment
627 //
628 // GC_TODO: Supported - add argument and description to function comment
629 //
630 // GC_TODO: Supported - add argument and description to function comment
631 //
632 ;
633
634 EFI_STATUS
635 EFIAPI
636 RootBridgeIoSetAttributes (
637 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
638 IN UINT64 Attributes,
639 IN OUT UINT64 *ResourceBase,
640 IN OUT UINT64 *ResourceLength
641 )
642 /*++
643
644 Routine Description:
645
646 Sets the attributes for a resource range on a PCI root bridge.
647
648 Arguments:
649
650 This - Pointer to EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
651 Attributes - The mask of attributes to set.
652 ResourceBase - Pointer to the base address of the resource range
653 to be modified by the attributes specified by Attributes.
654 ResourceLength - Pointer to the length of the resource range to be modified.
655
656 Returns:
657 EFI_SUCCESS - Success.
658 EFI_INVALID_PARAMETER - Invalid parameter found.
659 EFI_OUT_OF_RESOURCES - Not enough resources to set the attributes upon.
660
661 --*/
662 ;
663
664 EFI_STATUS
665 EFIAPI
666 RootBridgeIoConfiguration (
667 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
668 OUT VOID **Resources
669 )
670 /*++
671
672 Routine Description:
673
674 Retrieves the current resource settings of this PCI root bridge
675 in the form of a set of ACPI 2.0 resource descriptor.
676
677 Arguments:
678
679 This - Pointer to the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL instance.
680 Resources - Pointer to the ACPI 2.0 resource descriptor that
681 describe the current configuration of this PCI root
682 bridge.
683
684 Returns:
685
686 EFI_SUCCESS - Success.
687 EFI_UNSUPPORTED - Current configuration of the PCI root bridge
688 could not be retrieved.
689
690 --*/
691 ;
692
693 #endif