1 /** @file
2   Chassis specific functions common to all SOCs based on a specific Chessis
3 
4   Copyright 2020 NXP
5 
6   SPDX-License-Identifier: BSD-2-Clause-Patent
7 
8 **/
9 
10 #include <Chassis.h>
11 #include <Uefi.h>
12 #include <Library/IoAccessLib.h>
13 #include <Library/IoLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/SerialPortLib.h>
16 
17 /**
18   Or Scfg register
19 
20   @param  Address The MMIO register to read.
21 
22   @return The value read.
23 **/
24 UINT32
25 EFIAPI
ScfgOr32(IN UINTN Address,IN UINT32 Value)26 ScfgOr32 (
27   IN  UINTN     Address,
28   IN  UINT32    Value
29   )
30 {
31   MMIO_OPERATIONS *ScfgOps;
32 
33   ScfgOps = GetMmioOperations (FeaturePcdGet (PcdScfgBigEndian));
34 
35   return ScfgOps->Or32 (Address, Value);
36 }
37 
38 /**
39   Read Scfg register
40 
41   @param  Address The MMIO register to read.
42 
43   @return The value read.
44 **/
45 UINT32
46 EFIAPI
ScfgRead32(IN UINTN Address)47 ScfgRead32 (
48   IN  UINTN     Address
49   )
50 {
51   MMIO_OPERATIONS *ScfgOps;
52 
53   ScfgOps = GetMmioOperations (FeaturePcdGet (PcdScfgBigEndian));
54 
55   return ScfgOps->Read32 (Address);
56 }
57 
58 /**
59   Write Scfg register
60 
61   @param  Address The MMIO register to write.
62   @param  Value   The value to write to the MMIO register.
63 
64   @return Value.
65 **/
66 UINT32
67 EFIAPI
ScfgWrite32(IN UINTN Address,IN UINT32 Value)68 ScfgWrite32 (
69   IN  UINTN     Address,
70   IN  UINT32    Value
71   )
72 {
73   MMIO_OPERATIONS *ScfgOps;
74 
75   ScfgOps = GetMmioOperations (FeaturePcdGet (PcdScfgBigEndian));
76 
77   return ScfgOps->Write32 (Address, Value);
78 }
79 
80 /**
81   Read Dcfg register
82 
83   @param  Address The MMIO register to read.
84 
85   @return The value read.
86 **/
87 UINT32
88 EFIAPI
DcfgRead32(IN UINTN Address)89 DcfgRead32 (
90   IN  UINTN     Address
91   )
92 {
93   MMIO_OPERATIONS *DcfgOps;
94 
95   DcfgOps = GetMmioOperations (FeaturePcdGet (PcdDcfgBigEndian));
96 
97   return DcfgOps->Read32 (Address);
98 }
99 
100 /**
101   Write Dcfg register
102 
103   @param  Address The MMIO register to write.
104   @param  Value   The value to write to the MMIO register.
105 
106   @return Value.
107 **/
108 UINT32
109 EFIAPI
DcfgWrite32(IN UINTN Address,IN UINT32 Value)110 DcfgWrite32 (
111   IN      UINTN                     Address,
112   IN      UINT32                    Value
113   )
114 {
115   MMIO_OPERATIONS *DcfgOps;
116 
117   DcfgOps = GetMmioOperations (FeaturePcdGet (PcdDcfgBigEndian));
118 
119   return DcfgOps->Write32 (Address, Value);
120 }
121 
122 /*
123  * Setup SMMU in bypass mode
124  * and also set its pagesize
125  */
126 STATIC
127 VOID
SmmuInit(VOID)128 SmmuInit (
129   VOID
130   )
131 {
132   UINT32 Value;
133 
134   /* set pagesize as 64K and ssmu-500 in bypass mode */
135   Value = (MmioRead32 ((UINTN)SMMU_REG_SACR) | SACR_PAGESIZE_MASK);
136   MmioWrite32 ((UINTN)SMMU_REG_SACR, Value);
137 
138   Value = (MmioRead32 ((UINTN)SMMU_REG_SCR0) | SCR0_CLIENTPD_MASK);
139   Value &= ~SCR0_USFCFG_MASK;
140   MmioWrite32 ((UINTN)SMMU_REG_SCR0, Value);
141 
142   Value = (MmioRead32 ((UINTN)SMMU_REG_NSCR0) | SCR0_CLIENTPD_MASK);
143   Value &= ~SCR0_USFCFG_MASK;
144   MmioWrite32 ((UINTN)SMMU_REG_NSCR0, Value);
145 }
146 
147 /**
148   Function to initialize Chassis Specific functions
149  **/
150 VOID
ChassisInit(VOID)151 ChassisInit (
152   VOID
153   )
154 {
155   //
156   // Early init serial Port to get board information.
157   //
158   SerialPortInitialize ();
159 
160   SmmuInit ();
161 }
162