summaryrefslogtreecommitdiff
path: root/src/vendorcode/amd/cimx/rd890/nbPcieAspm.c
blob: 38bc41fb1a5865d43ee266becff0a9b4ba2cde7c (plain)
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/**
 * @file
 *
 * ASPM support.
 *
 *
 *
 * @xrefitem bom "File Content Label" "Release Content"
 * @e project:      CIMx-NB
 * @e sub-project:
 * @e \$Revision:$   @e \$Date:$
 *
 */
/*****************************************************************************
 *
 * Copyright (C) 2012 Advanced Micro Devices, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
 *       its contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 ***************************************************************************/
/*----------------------------------------------------------------------------------------
 *                             M O D U L E S    U S E D
 *----------------------------------------------------------------------------------------
 */

#include "NbPlatform.h"
#include "amdDebugOutLib.h"
#include "amdSbLib.h"

/*----------------------------------------------------------------------------------------
 *                   D E F I N I T I O N S    A N D    M A C R O S
 *----------------------------------------------------------------------------------------
 */


/*----------------------------------------------------------------------------------------
 *                  T Y P E D E F S     A N D     S T R U C T U  R E S
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------
 *           P R O T O T Y P E S     O F     L O C A L     F U  N C T I O N S
 *----------------------------------------------------------------------------------------
 */



VOID
PcieAspmSetOnRc (
  IN      PCI_ADDR        Device,
  IN      UINT8           Lx,
  IN      AMD_NB_CONFIG   *pConfig
  );

SCAN_STATUS
PcieSetDeviceAspm (
  IN      PCI_SCAN_PROTOCOL   *This,
  IN      PCI_ADDR            Function
  );

/*----------------------------------------------------------------------------------------
 *                          E X P O R T E D    F U N C T I O N S
 *----------------------------------------------------------------------------------------
 */

/*----------------------------------------------------------------------------------------*/
/**
 * Init Port ASPM.
 * Enable ASPM states on RC and EP. Only states supported  by both RC and EP
 * will be enabled.
 *
 *
 * @param[in] PortId    Pcie Port ID
 * @param[in] AsmpState ASPM states to enable.
 * @param[in] pConfig   Northbridge configuration structure pointer.
 *
 */
/*----------------------------------------------------------------------------------------*/
VOID
PcieAsmpEnableOnPort (
  IN      PORT            PortId,
  IN      PCIE_LINK_ASPM  AsmpState,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  PCI_ADDR  Port;
  UINT8     Lx;
  PCI_ADDR  NbPciAddress;
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "PcieAsmpEnableOnPort Enter PortId [%d]\n", PortId));
  NbPciAddress.AddressValue = NB_SBDFO;
  switch (AsmpState) {
  case PcieLinkAspmDisabled:
    return ;
  case PcieLinkAspmL0s:
    Lx = ASPM_UPSTREAM_L0s | ASPM_DOWNSTREAM_L0s;
    break;
  case PcieLinkAspmL1:
    Lx = ASPM_L1;
    break;
  case PcieLinkAspmL0sAndL1:
    Lx = ASPM_UPSTREAM_L0s | ASPM_DOWNSTREAM_L0s | ASPM_L1;
    break;
  case PcieLinkAspmL0sDownstreamOnly:
    Lx = ASPM_DOWNSTREAM_L0s;
    break;
  case PcieLinkAspmL0sDownstreamOnlyAndL1:
    Lx = ASPM_DOWNSTREAM_L0s | ASPM_L1;
    break;
  default:
    CIMX_ASSERT (FALSE);
    return ;
  }
  Port = PcieLibGetPortPciAddress (PortId, pConfig);
//NB-SB link
  if (PortId == 8 && NbPciAddress.AddressValue == 0) {
    if (PcieSbInitAspm ((Lx & ASPM_L1) | ((Lx & ASPM_UPSTREAM_L0s)?ASPM_L0s:0), pConfig) == AGESA_SUCCESS) {
      PcieAspmEnableOnFunction (Port, (Lx & ASPM_L1) | ((Lx & ASPM_DOWNSTREAM_L0s)?ASPM_L0s:0), pConfig);
    }
    return ;
  }
  PcieAspmSetOnRc (Port, Lx, pConfig);
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "PcieAsmpEnableOnPort Exit. Lx[0x%x]\n", Lx));
  return ;
}

/*----------------------------------------------------------------------------------------*/
/**
 * Enable Common Clock on PCIe Link
 *
 *
 *
 * @param[in] Downstream  Downstream PCIe port PCI address
 * @param[in] Upstream    Upstream PCIe port PCI address
 * @param[in] pConfig     Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/

VOID
PcieAspmEnableCommonClock (
  IN      PCI_ADDR        Downstream,
  IN      PCI_ADDR        Upstream,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT16  DownstreamCommonClockCap;
  UINT16  UpstreamCommonClockCap;
  UINT16  Value;
  UINT8   DownstreamPcieCapPtr;
  UINT8   UpstreamPcieCapPtr;
  DownstreamPcieCapPtr = LibNbFindPciCapability (Downstream.AddressValue, PCIE_CAP_ID, pConfig);
  UpstreamPcieCapPtr = LibNbFindPciCapability (Upstream.AddressValue, PCIE_CAP_ID, pConfig);
  if (DownstreamPcieCapPtr == 0 || UpstreamPcieCapPtr == 0) {
    return ;
  }
  LibNbPciRead (Downstream.AddressValue | (DownstreamPcieCapPtr + 0x10) , AccessWidth16, &DownstreamCommonClockCap, pConfig);
  if ((DownstreamCommonClockCap & BIT6) != 0) {
    //Aready enabled
    return ;
  }
  LibNbPciRead (Downstream.AddressValue | (DownstreamPcieCapPtr + 0x12) , AccessWidth16, &DownstreamCommonClockCap, pConfig);
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "    Downstream Common Clock Capability %d:%d:%d - %x\n", Downstream.Address.Bus, Downstream.Address.Device, Downstream.Address.Function,  DownstreamCommonClockCap));
  LibNbPciRead (Upstream.AddressValue | (UpstreamPcieCapPtr + 0x12) , AccessWidth16, &UpstreamCommonClockCap, pConfig);
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "    Upstream   Common Clock Capability %d:%d:%d - %x\n", Upstream.Address.Bus, Upstream.Address.Device, Upstream.Address.Function,  UpstreamCommonClockCap));
  if ((DownstreamCommonClockCap & UpstreamCommonClockCap & BIT12) != 0) {
    //Enable common clock
    PcieAspmCommonClockOnFunction (Downstream, pConfig);
    PcieAspmCommonClockOnDevice (Upstream, pConfig);
//    LibNbPciRMW (Downstream.AddressValue | (DownstreamPcieCapPtr + 0x10) , AccessS3SaveWidth8, 0xff, BIT6, pConfig);
//    LibNbPciRMW (Upstream.AddressValue | (UpstreamPcieCapPtr + 0x10) , AccessS3SaveWidth8, 0xff, BIT6, pConfig);
    //Reatrain link
    LibNbPciRMW (Downstream.AddressValue | (DownstreamPcieCapPtr + 0x10) , AccessS3SaveWidth8, 0xff, BIT5, pConfig);
    do {
      LibNbPciRead (Downstream.AddressValue | (DownstreamPcieCapPtr + 0x12) , AccessWidth16, (UINT16*)&Value, pConfig);
      STALL (GET_BLOCK_CONFIG_PTR (pConfig), 200, CIMX_S3_SAVE);
    } while ((Value & BIT11) != 0);
  }
}

/*----------------------------------------------------------------------------------------*/
/**
 * Set  "Common Clock" enable on function
 *
 *
 *
 * @param[in] Device      PCI address of function.
 * @param[in] pConfig     Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/
VOID
PcieAspmCommonClockOnDevice (
  IN      PCI_ADDR        Device,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT8 Value;
  UINT8 MaxFunc;
  UINT8 CurrentFunc;
  LibNbPciRead (Device.AddressValue | 0x0E , AccessWidth8, &Value, pConfig);
  MaxFunc = (Value & BIT7)?7:0;
  for (CurrentFunc = 0; CurrentFunc <= MaxFunc; CurrentFunc++) {
    Device.Address.Function = CurrentFunc;
    if (LibNbIsDevicePresent (Device, pConfig)) {
      PcieAspmCommonClockOnFunction (Device, pConfig);
    }
  }
}


/*----------------------------------------------------------------------------------------*/
/**
 * Set  "Common Clock" enable on function
 *
 *
 *
 * @param[in] Function    PCI address of function.
 * @param[in] pConfig     Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/
VOID
PcieAspmCommonClockOnFunction (
  IN      PCI_ADDR        Function,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT8       PcieCapPtr;
  PcieCapPtr = LibNbFindPciCapability (Function.AddressValue, PCIE_CAP_ID, pConfig);
  if (PcieCapPtr != 0) {
    LibNbPciRMW (Function.AddressValue | (PcieCapPtr + 0x10) , AccessS3SaveWidth8, (UINT32)~(BIT6), BIT6, pConfig);
  }
}
/*----------------------------------------------------------------------------------------*/
/**
 * Enable ASPM on PCIe Link
 *
 *
 *
 * @param[in] Downstream  Downstream PCIe port PCI address
 * @param[in] Upstream    Upstream PCIe port PCI address
 * @param[in] Lx          Lx ASPM bitmap.
 *                          Lx[0] - reserved
 *                          Lx[1] - L1 enable
 *                          Lx[2] - L0s enable for upstream ports
 *                          Lx[3] - L0s enable for downstream ports
 * @param[in] pConfig     Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/

VOID
PcieAspmEnableOnLink (
  IN      PCI_ADDR        Downstream,
  IN      PCI_ADDR        Upstream,
  IN      UINT8           Lx,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  ASPM_LINK_INFO AspmLinkInfo;
  AspmLinkInfo.UpstreamLxCap = PcieAspmGetPmCapability (Upstream, pConfig);
  AspmLinkInfo.DownstreamLxCap = PcieAspmGetPmCapability (Downstream, pConfig);
  AspmLinkInfo.DownstreamPort = Downstream;
  AspmLinkInfo.UpstreamPort = Upstream;
  AspmLinkInfo.RequestedLx = Lx;
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "   Downstream ASPM Capability %d:%d:%d - %x\n", Downstream.Address.Bus, Downstream.Address.Device, Downstream.Address.Function,  AspmLinkInfo.DownstreamLxCap));
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "   Upstream   ASPM Capability %d:%d:%d - %x\n", Upstream.Address.Bus, Upstream.Address.Device, Upstream.Address.Function,  AspmLinkInfo.UpstreamLxCap));
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "   Requested  ASPM State - %x\n", Lx));
  AspmLinkInfo.DownstreamLx = AspmLinkInfo.UpstreamLxCap & AspmLinkInfo.DownstreamLxCap & Lx & ASPM_L1;
  AspmLinkInfo.UpstreamLx = AspmLinkInfo.DownstreamLx;
  if ((AspmLinkInfo.UpstreamLxCap & ASPM_L0s) != 0 && (Lx & ASPM_UPSTREAM_L0s) != 0) {
    AspmLinkInfo.UpstreamLx |= ASPM_L0s;
  }
  if ((AspmLinkInfo.DownstreamLxCap & ASPM_L0s) != 0 && (Lx & ASPM_DOWNSTREAM_L0s) != 0) {
    AspmLinkInfo.DownstreamLx |= ASPM_L0s;
  }
#ifndef ASPM_WORKAROUND_DISABLE
  PcieAspmWorkarounds (&AspmLinkInfo, pConfig);
#endif
  LibNbCallBack (PHCB_AmdPcieAsmpInfo, (UINTN)&AspmLinkInfo, pConfig);
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "   Upstream   ASPM State - %x\n", AspmLinkInfo.UpstreamLx));
  PcieAspmEnableOnDevice (Upstream, AspmLinkInfo.UpstreamLx, pConfig);
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "   Downstream ASPM State - %x\n", AspmLinkInfo.DownstreamLx));
  PcieAspmEnableOnFunction (Downstream, AspmLinkInfo.DownstreamLx, pConfig);

}

/*----------------------------------------------------------------------------------------*/
/**
 * Set ASMP State on all function of PCI device
 *
 *
 *
 * @param[in] Device    PCI address of device.
 * @param[in] Lx        Lx ASPM bitmap.
 *                        Lx[0] = L0s enable
 *                        Lx[1] - L1 enable
 * @param[in] pConfig   Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/
VOID
PcieAspmEnableOnDevice (
  IN      PCI_ADDR        Device,
  IN      UINT8           Lx,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT8 Value;
  UINT8 MaxFunc;
  UINT8 CurrentFunc;

  LibNbPciRead (Device.AddressValue | 0x0E , AccessWidth8, &Value, pConfig);
  MaxFunc = (Value & BIT7)?7:0;
  for (CurrentFunc = 0; CurrentFunc <= MaxFunc; CurrentFunc++) {
    Device.Address.Function = CurrentFunc;
    if (LibNbIsDevicePresent (Device, pConfig)) {
      PcieAspmEnableOnFunction (Device, Lx, pConfig);
    }
  }
}
/*----------------------------------------------------------------------------------------*/
/**
 * Set  ASMP State on PCIe device function
 *
 *
 *
 * @param[in] Function    PCI address of function.
 * @param[in] Lx          Lx ASPM bitmap.
 *                          Lx[0] = L0s enable
 *                          Lx[1] - L1 enable
 * @param[in] pConfig     Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/
VOID
PcieAspmEnableOnFunction (
  IN      PCI_ADDR        Function,
  IN      UINT8           Lx,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT8       PcieCapPtr;
  PcieCapPtr = LibNbFindPciCapability (Function.AddressValue, PCIE_CAP_ID, pConfig);
  if (PcieCapPtr != 0) {
    LibNbPciRMW (Function.AddressValue | (PcieCapPtr + 0x10) , AccessS3SaveWidth8, (UINT32)~(BIT0 & BIT1), Lx, pConfig);
  }
}

/**----------------------------------------------------------------------------------------*/
/**
 * Port/Endpoint ASMP capability
 *
 *
 *
 * @param[in] Device    PCI address of downstream port.
 * @param[in] pConfig   Northbridge configuration structure pointer.
 *
 * @retval    Bitmap of actual supported Lx states
 */
 /*----------------------------------------------------------------------------------------*/
UINT8
PcieAspmGetPmCapability (
  IN      PCI_ADDR        Device,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  UINT8 PcieCapPtr;
  UINT8 Value;
  PcieCapPtr = LibNbFindPciCapability (Device.AddressValue, PCIE_CAP_ID, pConfig);
  if (PcieCapPtr == 0) {
    return 0;
  }
  LibNbPciRead (Device.AddressValue | (PcieCapPtr + 0x0D) , AccessWidth8, &Value, pConfig);
  return (Value >> 2) & 3;
}


/**----------------------------------------------------------------------------------------*/
/**
 * Scan PCIe topology
 *
 *
 *
 * @param[in] This          Pointer to instance of scan protocol
 * @param[in] Function      PCI address of found device/function.
 *
 * @retval    SCAN_FINISHED Scan for device finished.
 */
 /*----------------------------------------------------------------------------------------*/
SCAN_STATUS
PcieSetDeviceAspm (
  IN      PCI_SCAN_PROTOCOL   *This,
  IN      PCI_ADDR            Function
  )
{
  PCIE_DEVICE_TYPE  DeviceType;
  UINT8             SecondaryBus;
  ASPM_WORKSPACE    *WorkspacePtr;
  WorkspacePtr =    (ASPM_WORKSPACE*)This;

  DeviceType = PcieGetDeviceType (Function, This->pConfig);
  if (DeviceType == PcieDeviceRootComplex || DeviceType == PcieDeviceDownstreamPort) {
    PCI_ADDR        UpstreamDevice;
    CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (This->pConfig), CIMX_NBPCIE_TRACE), "    Reached downstream port\n"));
    //Lets enable Common clock
    LibNbPciRead (Function.AddressValue | 0x19, AccessWidth8, &SecondaryBus, This->pConfig);
    LibNbPciRMW(Function.AddressValue | 0x18, AccessS3SaveWidth32, 0xffffffff, 0, This->pConfig);  //This done to help UEFI bootscript restore bud topology.
    if (SecondaryBus == 0) {
      return  SCAN_FINISHED;
    }
    //New Downstream Port
    WorkspacePtr->LinkCount++;
    if (WorkspacePtr->DownstreamPort.AddressValue == 0) {
      WorkspacePtr->DownstreamPort.AddressValue = Function.AddressValue;
    }
    //Lets enable Common clock
    UpstreamDevice.AddressValue = MAKE_SBDFO (0, SecondaryBus, 0, 0, 0);
    if (LibNbIsDevicePresent (UpstreamDevice, This->pConfig)) {
      PcieAspmEnableCommonClock (Function, UpstreamDevice, This->pConfig);
    }
    This->ScanBus (This, UpstreamDevice);
    if (WorkspacePtr->DownstreamPort.AddressValue == Function.AddressValue) {
      WorkspacePtr->DownstreamPort.AddressValue = 0;
      PcieAspmEnableOnLink (Function, UpstreamDevice, WorkspacePtr->Lx, This->pConfig);
    }
  } else if (DeviceType == PcieDeviceUpstreamPort ) {
    PCI_ADDR DownstreamDevice;

    if (WorkspacePtr->DownstreamPort.AddressValue == 0) {
      return  SCAN_FINISHED;
    }
    CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (This->pConfig), CIMX_NBPCIE_TRACE), "    Reached upstream port\n"));
    LibNbPciRead (Function.AddressValue | 0x19, AccessWidth8, &SecondaryBus, This->pConfig);
    LibNbPciRMW(Function.AddressValue | 0x18, AccessS3SaveWidth32, 0xffffffff, 0, This->pConfig); //This done to help UEFI bootscript restore bud topology.
    if (SecondaryBus == 0) {
      return  SCAN_FINISHED;
    }
    DownstreamDevice.AddressValue = MAKE_SBDFO (0, SecondaryBus, 0, 0, 0);
    This->ScanBus (This, DownstreamDevice);
  } else if (DeviceType < PcieDeviceLegacyEndPoint) {
    // We reach end of link @toDo code to check exit latency.
    CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (This->pConfig), CIMX_NBPCIE_TRACE), "    Reached endpoint \n"));
  }
  return  SCAN_FINISHED;
}

/**----------------------------------------------------------------------------------------*/
/**
 * Scan RC PCIe topology to setup ASPM
 *
 *
 *
 * @param[in] Device    PCI address of downstream port.
 * @param[in] Lx        Lx ASPM bitmap.
 *                        Lx[0] - reserved
 *                        Lx[1] - L1 enable
 *                        Lx[2] - L0s enable for upstream ports
 *                        Lx[3] - L0s enable for downstream ports
 * @param[in] pConfig   Northbridge configuration structure pointer.
 *
 */
 /*----------------------------------------------------------------------------------------*/
VOID
PcieAspmSetOnRc (
  IN      PCI_ADDR        Device,
  IN      UINT8           Lx,
  IN      AMD_NB_CONFIG   *pConfig
  )
{
  ASPM_WORKSPACE AspmWorkspace;

  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "[NBPCIE]PcieSetPortAspm Enter\n"));
  LibAmdMemFill (&AspmWorkspace, 0, sizeof (AspmWorkspace), (AMD_CONFIG_PARAMS *)&(pConfig->sHeader));
  AspmWorkspace.ScanPciePort.pConfig = pConfig;
  AspmWorkspace.ScanPciePort.ScanBus = LibNbScanPciBus;
  AspmWorkspace.ScanPciePort.ScanDevice = LibNbScanPciDevice;
  AspmWorkspace.ScanPciePort.ScanFunction = PcieSetDeviceAspm;
  AspmWorkspace.Lx = Lx;
  AspmWorkspace.ScanPciePort.ScanFunction (&AspmWorkspace.ScanPciePort, Device);
  if (AspmWorkspace.LinkCount > 1) {
    LibNbScanPciBridgeBuses (&AspmWorkspace.ScanPciePort, Device);
  }
  CIMX_TRACE ((TRACE_DATA (GET_BLOCK_CONFIG_PTR (pConfig), CIMX_NBPCIE_TRACE), "[NBPCIE]PcieSetPortAspm Exit\n"));
}