1 /** @file
2 Platform Pcie Helper Lib.
3 
4 Copyright (c) 2013 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 #include "CommonHeader.h"
17 
18 //
19 // Routines local to this source module.
20 //
21 VOID
LegacyGpioSetLevel(IN CONST UINT32 LevelRegOffset,IN CONST UINT32 GpioNum,IN CONST BOOLEAN HighLevel)22 LegacyGpioSetLevel (
23   IN CONST UINT32                         LevelRegOffset,
24   IN CONST UINT32                         GpioNum,
25   IN CONST BOOLEAN                        HighLevel
26   )
27 {
28   UINT32                            RegValue;
29   UINT32                            GpioBaseAddress;
30   UINT32                            GpioNumMask;
31 
32   GpioBaseAddress =  LpcPciCfg32 (R_QNC_LPC_GBA_BASE) & B_QNC_LPC_GPA_BASE_MASK;
33   ASSERT (GpioBaseAddress > 0);
34 
35   RegValue = IoRead32 (GpioBaseAddress + LevelRegOffset);
36   GpioNumMask = (1 << GpioNum);
37   if (HighLevel) {
38     RegValue |= (GpioNumMask);
39   } else {
40     RegValue &= ~(GpioNumMask);
41   }
42   IoWrite32 (GpioBaseAddress + R_QNC_GPIO_RGLVL_RESUME_WELL, RegValue);
43 }
44 
45 //
46 // Routines exported by this component.
47 //
48 
49 /**
50   Platform assert PCI express PERST# signal.
51 
52   @param   PlatformType     See EFI_PLATFORM_TYPE enum definitions.
53 
54 **/
55 VOID
56 EFIAPI
PlatformPERSTAssert(IN CONST EFI_PLATFORM_TYPE PlatformType)57 PlatformPERSTAssert (
58   IN CONST EFI_PLATFORM_TYPE              PlatformType
59   )
60 {
61   if (PlatformType == GalileoGen2) {
62     LegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_GEN2_PCIEXP_PERST_RESUMEWELL_GPIO, FALSE);
63   } else {
64     LegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, PCIEXP_PERST_RESUMEWELL_GPIO, FALSE);
65   }
66 }
67 
68 /**
69   Platform de assert PCI express PERST# signal.
70 
71   @param   PlatformType     See EFI_PLATFORM_TYPE enum definitions.
72 
73 **/
74 VOID
75 EFIAPI
PlatformPERSTDeAssert(IN CONST EFI_PLATFORM_TYPE PlatformType)76 PlatformPERSTDeAssert (
77   IN CONST EFI_PLATFORM_TYPE              PlatformType
78   )
79 {
80   if (PlatformType == GalileoGen2) {
81     LegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, GALILEO_GEN2_PCIEXP_PERST_RESUMEWELL_GPIO, TRUE);
82   } else {
83     LegacyGpioSetLevel (R_QNC_GPIO_RGLVL_RESUME_WELL, PCIEXP_PERST_RESUMEWELL_GPIO, TRUE);
84   }
85 }
86 
87 /** Early initialisation of the PCIe controller.
88 
89   @param   PlatformType     See EFI_PLATFORM_TYPE enum definitions.
90 
91   @retval   EFI_SUCCESS               Operation success.
92 
93 **/
94 EFI_STATUS
95 EFIAPI
PlatformPciExpressEarlyInit(IN CONST EFI_PLATFORM_TYPE PlatformType)96 PlatformPciExpressEarlyInit (
97   IN CONST EFI_PLATFORM_TYPE              PlatformType
98   )
99 {
100 
101   //
102   // Release and wait for PCI controller to come out of reset.
103   //
104   SocUnitReleasePcieControllerPreWaitPllLock (PlatformType);
105   MicroSecondDelay (PCIEXP_DELAY_US_WAIT_PLL_LOCK);
106   SocUnitReleasePcieControllerPostPllLock (PlatformType);
107 
108   //
109   // Early PCIe initialisation
110   //
111   SocUnitEarlyInitialisation ();
112 
113   //
114   // Do North cluster early PCIe init.
115   //
116   PciExpressEarlyInit ();
117 
118   return EFI_SUCCESS;
119 }
120 
121