hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** @file
*
*  Copyright 2020 NXP
*
*  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/SocLib.h>
#include <Soc.h>
 
/**
  Set PCDs for PCIe controller based on SoC version.
  LX2160-Rev1 and LX2160-Rev2 has different PCIe controller. This function
  check the SoC version and set PCDs for PCIe controller which will be
  used by PciHostBridgeLib and PciSegmentLib for controller initialization.
 
  @return EFI_SUCCESS            PCDs were set successfully
  @return EFI_INVALID_PARAMETER  Invalid major version number
**/
EFI_STATUS
SetPciControllerPcdOptions (
  VOID
  )
{
  UINT32 Svr;
 
  Svr = SocGetSvr ();
  if (SVR_SOC_VER(Svr) == SVR_LX2160A) {
    switch (SVR_MAJOR(Svr)) {
    case 0x1:
      //
      // LX2160-Rev1 and LX2160-Rev2 has different PCIe controllers.
      // Set PcdPciLsGen4Ctrl to TRUE for LX2160-Rev1, which will be used
      // by PciHostBridgeLib and PciSegmentLib to differentiate both controllers
      // and perform controller specific initialization.
      //
      PcdSetBoolS (PcdPciLsGen4Ctrl, TRUE);
      break;
    case 0x2:
      //
      // PCIe controller in LX2160-Rev2 supports two methods for config
      // transactions.
      // 1 - Default (Non ECAM compliant): PCIe controller
      // requires target BDF to be written to bit[31:16] of type0/type1
      // outbound window.
      // 2 - CFG SHIFT: PCIe controller shifts BDF from bits[27:12] to
      // bits[31:16] and supports Enhanced Configuration Address Mapping (ECAM)
      // mechanism.
      //
      // Set PcdPciCfgShiftEnable to TRUE for LX2160-Rev2, which will be used by
      // PciHostBridgeLib and PciSegmentLib to enable CFG SHIFT feature on
      // PCIe controller and program the iATU windows accordingly.
      //
      PcdSetBoolS (PcdPciCfgShiftEnable, TRUE);
 
      //
      // PCIe controller in LX2160-Rev2 is not ECAM-compliant for bus0.
      // Set PcdPciHideRootPort for LX2160-Rev2, which will be used by
      // PciHostBridgeLib and PciSegmentLib to program iATU windows accordingly.
      //
      PcdSetBoolS (PcdPciHideRootPort, TRUE);
      break;
    default:
      DEBUG ((DEBUG_ERROR, "%a: Invalid SoC Version 0x%x \n", __FUNCTION__,
              SVR_MAJOR(Svr)));
      return EFI_INVALID_PARAMETER;
    }
  }
 
  return EFI_SUCCESS;
}
 
/**
  The entry point for PlatformDxe driver. This driver
  intends to perform platform specific initialization.
 
  @param[in] ImageHandle     The image handle of the driver.
  @param[in] SystemTable     The system table.
 
  @retval EFI_SUCCESS         Driver initialization success.
 
**/
EFI_STATUS
EFIAPI
PlatformDxeEntryPoint (
  IN EFI_HANDLE                   ImageHandle,
  IN EFI_SYSTEM_TABLE             *SystemTable
  )
{
  EFI_STATUS Status;
 
  // Set PCDs for PCIe controller
  Status = SetPciControllerPcdOptions ();
 
  return Status;
}