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