1/** @file
2Platform Pcie Helper Lib.
3
4Copyright (c) 2013 Intel Corporation.
5
6This program and the accompanying materials
7are licensed and made available under the terms and conditions of the BSD License
8which accompanies this distribution.  The full text of the license may be found at
9http://opensource.org/licenses/bsd-license.php
10
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12WITHOUT 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//
21VOID
22LegacyGpioSetLevel (
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**/
55VOID
56EFIAPI
57PlatformPERSTAssert (
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**/
74VOID
75EFIAPI
76PlatformPERSTDeAssert (
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**/
94EFI_STATUS
95EFIAPI
96PlatformPciExpressEarlyInit (
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