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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
*
*  Copyright (C) 2021, Semihalf.
*
*  SPDX-License-Identifier: BSD-2-Clause-Patent
*
**/
 
#include <Uefi.h>
 
#include <Library/ArmadaBoardDescLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/MvGpioLib.h>
#include <Library/UefiBootServicesTableLib.h>
 
#include "BoardDescriptionLib.h"
 
STATIC
VOID
ConfigureIoWindow (
  UINT64 WinBaseAddress,
  UINT64 WinSize,
  UINTN  WinId,
  UINT32 WinTargetId
  )
{
  UINT32 AddressHigh;
  UINT32 AddressLow;
  UINT64 MaxAddress;
 
  /* Disable IO window. */
  MmioWrite32 (IO_WIN_ALR_OFFSET(WinId), 0);
 
  /* Calculate the end address. */
  MaxAddress = (WinBaseAddress + WinSize - 1);
 
  AddressLow = (UINT32)((WinBaseAddress >> IO_WIN_ADDRESS_SHIFT) & IO_WIN_ADDRESS_MASK);
  AddressLow |= IO_WIN_ENABLE_BIT;
  AddressHigh = (UINT32)((MaxAddress >> IO_WIN_ADDRESS_SHIFT) & IO_WIN_ADDRESS_MASK);
 
  /* Write start address and end address for IO window. */
  MmioWrite32 (IO_WIN_ALR_OFFSET(WinId), AddressLow);
  MmioWrite32 (IO_WIN_AHR_OFFSET(WinId), AddressHigh);
 
  /* Write window target. */
  MmioWrite32 (IO_WIN_CR_OFFSET(WinId), WinTargetId);
}
 
//
// General purpose routine for per-board initalization
//
EFI_STATUS
ArmadaBoardInit (
  VOID
  )
{
  /*
   * Due to lack of sufficient number of IO windows registers,
   * the CP1/CP2 PCIE configuration must be performed after the
   * early firmware stages. Replace the MCI 0/1 indirect
   * windows, which are no longer needed.
   */
  ConfigureIoWindow (
    CP1_PCIE_WIN64_BASE,
    CP1_PCIE_WIN64_SIZE,
    CP1_PCIE_WIN64_ID,
    MCI0_TARGET_ID
    );
 
  ConfigureIoWindow (
    CP2_PCIE_WIN64_BASE,
    CP2_PCIE_WIN64_SIZE,
    CP2_PCIE_WIN64_ID,
    MCI1_TARGET_ID
    );
 
  /* Enable FAN */
  MmioAnd32 (CP0_GPIO1_DATA_OUT_REG, ~CP0_GPIO1_PIN_MASK);
  MmioAnd32 (CP0_GPIO1_OUT_EN_REG, ~CP0_GPIO1_PIN_MASK);
 
  return EFI_SUCCESS;
}
 
//
// GPIO Expander
//
EFI_STATUS
EFIAPI
ArmadaBoardGpioExpanderGet (
  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
  IN OUT UINTN             *GpioExpanderCount
  )
{
  /* No GPIO expanders on board */
  *GpioExpanders = NULL;
  *GpioExpanderCount = 0;
 
  return EFI_SUCCESS;
}
 
//
// PCIE
//
STATIC
MV_PCIE_CONTROLLER mPcieController[] = {
  { /* CP0 PCIE0 @0xF2600000 */
    .PcieDbiAddress        = 0xF2600000,
    .ConfigSpaceAddress    = 0x800000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xFE,
    .PcieIoTranslation     = 0x80FF00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xC0000000,
    .PcieMmio32WinSize     = 0x20000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x810000000,
    .PcieMmio64WinSize     = 0x80000000,
  },
  { /* CP1 PCIE0 @0xF4600000 */
    .PcieDbiAddress        = 0xF4600000,
    .ConfigSpaceAddress    = 0xE2000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xE2F00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xE3000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x890000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
  { /* CP1 PCIE1 @0xF4620000 */
    .PcieDbiAddress        = 0xF4620000,
    .ConfigSpaceAddress    = 0xE4000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xE4F00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xE5000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x8A0000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
  { /* CP1 PCIE2 @0xF4640000 */
    .PcieDbiAddress        = 0xF4640000,
    .ConfigSpaceAddress    = 0xE6000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xE6F00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xE7000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x8B0000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
  { /* CP2 PCIE0 @0xF6600000 */
    .PcieDbiAddress        = 0xF6600000,
    .ConfigSpaceAddress    = 0xE9000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xE9F00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xEA000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x8C0000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
  { /* CP2 PCIE1 @0xF6620000 */
    .PcieDbiAddress        = 0xF6620000,
    .ConfigSpaceAddress    = 0xEB000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xEBF00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xEC000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x8D0000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
  { /* CP2 PCIE2 @0xF6640000 */
    .PcieDbiAddress        = 0xF6640000,
    .ConfigSpaceAddress    = 0xED000000,
    .HaveResetGpio         = FALSE,
    .PcieResetGpio         = { 0 },
    .PcieBusMin            = 0,
    .PcieBusMax            = 0xE,
    .PcieIoTranslation     = 0xEDF00000,
    .PcieIoWinBase         = 0x0,
    .PcieIoWinSize         = 0x10000,
    .PcieMmio32Translation = 0,
    .PcieMmio32WinBase     = 0xEE000000,
    .PcieMmio32WinSize     = 0x1000000,
    .PcieMmio64Translation = 0,
    .PcieMmio64WinBase     = 0x8E0000000,
    .PcieMmio64WinSize     = 0x10000000,
  },
};
 
/**
  Return the number and description of PCIE controllers used on the platform.
 
  @param[in out] **PcieControllers      Array containing PCIE controllers'
                                        description.
  @param[in out]  *PcieControllerCount  Amount of used PCIE controllers.
 
  @retval EFI_SUCCESS                   The data were obtained successfully.
  @retval other                         Return error status.
 
**/
EFI_STATUS
EFIAPI
ArmadaBoardPcieControllerGet (
  IN OUT MV_PCIE_CONTROLLER CONST **PcieControllers,
  IN OUT UINTN                     *PcieControllerCount
  )
{
  *PcieControllers = mPcieController;
  *PcieControllerCount = ARRAY_SIZE (mPcieController);
 
  return EFI_SUCCESS;
}
 
//
// Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
//
STATIC
MV_BOARD_SDMMC_DESC mSdMmcDescTemplate[] = {
  { /* eMMC 0xF06E0000 */
    0,     /* SOC will be filled by MvBoardDescDxe */
    0,     /* SdMmcDevCount will be filled by MvBoardDescDxe */
    TRUE,  /* Xenon1v8Enabled */
    /*
     * Force 4-bit bus width - work-around for non
     * functional HS400 mode.
     */
    FALSE, /* Xenon8BitBusEnabled */
    FALSE, /* XenonSlowModeEnabled */
    0x40,  /* XenonTuningStepDivisor */
    EmbeddedSlot /* SlotType */
  },
  { /* SD/MMC 0xF2780000 */
    0,     /* SOC will be filled by MvBoardDescDxe */
    0,     /* SdMmcDevCount will be filled by MvBoardDescDxe */
    FALSE, /* Xenon1v8Enabled */
    FALSE, /* Xenon8BitBusEnabled */
    FALSE, /* XenonSlowModeEnabled */
    0x19,  /* XenonTuningStepDivisor */
    EmbeddedSlot /* SlotType */
  },
};
 
EFI_STATUS
EFIAPI
ArmadaBoardDescSdMmcGet (
  OUT UINTN               *SdMmcDevCount,
  OUT MV_BOARD_SDMMC_DESC **SdMmcDesc
  )
{
  *SdMmcDesc = mSdMmcDescTemplate;
  *SdMmcDevCount = ARRAY_SIZE (mSdMmcDescTemplate);
 
  return EFI_SUCCESS;
}