summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/SystemAgent/MemoryInit/Pei/Source/Services/MrcMemoryMap.c
blob: 2fd1310ec4e562d7f8d81ee1360670c9aae60a40 (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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/** @file
  The functions in this file initializes the physical memory map.

@copyright
  Copyright (c) 1999 - 2012 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement.

**/

//
// Include files
//
#include "MrcMemoryMap.h"
#include "PttHciRegs.h"

/**
@brief
  After BIOS determines the total physical memory size.
  Determines TOM which is defined by the total physical memory size.
  Determines TOM minus the ME memory size. The ME memory size is calculated from MESEG_BASE and MESEG_MASK.
  Determines MMIO allocation, which is system configuration dependent.

  Determines TOLUD which is the minimum value by comparing between "4GB minus MMIO size" and "TOM minus ME size".
  Determines Graphics Stolen Base, BDSM by subtracting the graphics data stolen memory size from TOLUD.
  Graphics Data Stolen Memory size is given by GMS field in GGC register.  It must be define before this stage.
  Determines Graphics GTT Stolen Base, BGSM by subtracting the GTT graphics stolen memory size from BDSM.
  GTT Stolen Memory size is given by GGMS field in GGC register.  It must be define before this stage.
  Determines TSEG Base, TSEGMB by subtracting TSEG size from BGSM.
  TSEG should be defined.
  Remove the memory hole caused by aligning TSEG to a 8MB boundary.
  Determine whether Memory Reclaim is available.  If "TOM minus ME Stolem Memory Size" is greater than the value of TOLUD, then memory reclaim is available to enable.
  Determine REMAPBASE if reclaim is enabled.  This is the maximum value by comparing between 4GB and "TOM minus ME size".
  Determine REMAPLIMIT () if reclaim is enabled.  This is the value of REMAPBASE plus "the difference between the value in TOLUD register and the lower of either 4GB or 'TOM minus ME Stolen memory size", and then minus 1 boundary.
  Determine TOUUD. TOUUD indicates the address one byte above the maximum DRAM.  If relcaim is disabled, this value is calculated by "TOM minus ME stolen size".  Otherwise, this value is set to REMAPLIMIT plus 1MB.

  @param[in, out] MrcData - Include all MRC global data. include also the memory map data.

  @retval MrcStatus -  if the reset is succeded.
**/
MrcStatus
MrcSetMemoryMap (
  IN OUT MrcParameters *const MrcData
  )
{
  const MrcDebug          *Debug;
  const MrcInput          *Inputs;
  MrcOutput               *Outputs;
  MrcMemoryMap            *MemoryMap;
  MRC_PCI_000_GGC_STRUCT  Ggc;
  U32                     Offset;
  U32                     TsegBaseOrg;
  U32                     TsegBaseDelta;
  U32                     GdxcTop;
  U32                     FtpmTop;
  U32                     MmioSize;
#ifdef PTT_FLAG
  U32                     PttSts;
#endif

  Inputs    = &MrcData->SysIn.Inputs;
  Debug     = &Inputs->Debug;
  Outputs   = &MrcData->SysOut.Outputs;
  MemoryMap = &Outputs->MemoryMapData;

  //
  // Find the total memory size
  //
  MrcTotalMemory (MrcData);
  
  //
  // Set TOM register
  //
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TOM (Total physical memory size) = %u MB\n", MemoryMap->TotalPhysicalMemorySize);

  //
  // Find the TOM minus ME size only for internal calculations
  //
  MemoryMap->TomMinusMe = MemoryMap->TotalPhysicalMemorySize - Inputs->MeStolenSize;

  MmioSize = Inputs->MmioSize;
  if (Inputs->MemoryTrace) {
    if (MemoryMap->TotalPhysicalMemorySize <= MEM_4GB) {
      MmioSize = MAX (MmioSize, MEM_4GB - MemoryMap->TotalPhysicalMemorySize / 2);
      MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Adjusted MmioSize = %Xh\n", MmioSize);
    }
  }
  
  //
  // Find and set TOLUD.
  // TOLUD which is the minimum value by comparing between "4GB minus MMIO size" and "TOM minus ME size"
  //
  MemoryMap->ToludBase = MIN (MemoryMap->TomMinusMe, MEM_4GB - MmioSize);
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TOLUD base = %Xh\n", MemoryMap->ToludBase);

  //
  // Find and set BDSM Graphics Stolen Base.
  // Graphics Stolen Base, BDSM by subtracting the graphics data stolen memory size from TOLUD.
  //
  MemoryMap->BdsmBase = MemoryMap->ToludBase - Outputs->GraphicsStolenSize;
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "BDSM base = %Xh\n", MemoryMap->BdsmBase);

  //
  // Graphics GTT Stolen Base
  // Graphics GTT Stolen Base, BGSM by subtracting the GTT graphics stolen memory size from BDSM.
  //
  MemoryMap->GttBase = MemoryMap->BdsmBase - Outputs->GraphicsGttSize;
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "GTT base = %Xh\n", MemoryMap->GttBase);

  //
  // Graphics size register init.
  //
  Offset = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_GGC_REG);
  MrcOemMmioRead (Offset, &Ggc.Data, Inputs->PciEBaseAddress);
  Ggc.Bits.Vamen  = (Inputs->GfxIsVersatileAcceleration == TRUE) ? 1 : 0;
  Ggc.Bits.Ggms   = MIN (GGC_GGMS_MAX, Outputs->GraphicsGttSize);
  //
  // GMS limitation is 5 bits
  //
  if (Outputs->GraphicsStolenSize == 1024) {
    Ggc.Bits.Gms = 17;
  } else {
    Ggc.Bits.Gms = MIN (GGC_GMS_MAX, (Outputs->GraphicsStolenSize / 32));
  }

  MemoryMap->GraphicsControlRegister = Ggc.Data;
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "GGC value = %Xh\n", MemoryMap->GraphicsControlRegister);

  //
  // TSEG Base
  // TSEGMB by subtracting TSEG size from BGSM.
  //
  MemoryMap->TsegBase = MemoryMap->GttBase - Inputs->TsegSize;
  TsegBaseOrg         = MemoryMap->TsegBase;

  //
  // Dpr size to program DPR register in update MemoryMap
  //
  MemoryMap->DprSize = Inputs->DprSize;

  //
  // SMRR must be aligned at 8MB boundary.
  // according to this TSEG base need to be also aligned to 8MB boundary.
  // Round it down to the nearest 8MB boundary.
  //
  MemoryMap->TsegBase &= ~(Inputs->TsegSize - 1);
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TSEG base = %Xh\n", MemoryMap->TsegBase);

  //
  // Remove the hole between top of aligned TSEG and GTT Base:
  //  1. Calculate Delta = TsegMB - aligned_TsegMB
  //  2. Walk backwards and adjust BGSM_new = BGSM - DELTA, TOLUD_new = TOLUD - DELTA
  //
  TsegBaseDelta = TsegBaseOrg - MemoryMap->TsegBase;
  if (TsegBaseDelta != 0) {
    MemoryMap->GttBase   = MemoryMap->GttBase - TsegBaseDelta;
    MemoryMap->BdsmBase  = MemoryMap->BdsmBase - TsegBaseDelta;
    MemoryMap->ToludBase = MemoryMap->ToludBase - TsegBaseDelta;
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "GTT base = %Xh\n", MemoryMap->GttBase);
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "BDSM base = %Xh\n", MemoryMap->BdsmBase);
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TOLUD base = %Xh\n", MemoryMap->ToludBase);
  }
  //
  // test if Reclaim is available
  // If "TOM minus ME Stolem Memory Size" is greater than the value of TOLUD, then memory reclaim is available to enable
  //
  if (Inputs->RemapEnable && (MemoryMap->TomMinusMe > MemoryMap->ToludBase)) {
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Reclaim Enable\n");
    MemoryMap->ReclaimEnable = TRUE;
    //
    // Remap Base
    // This is the maximum value by comparing between 4GB and "TOM minus ME size".
    //
    MemoryMap->RemapBase = MAX (MEM_4GB, MemoryMap->TomMinusMe);
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Remap Base %Xh\n", MemoryMap->RemapBase);
    //
    // Remap Limit
    // This is the value of REMAPBASE plus "the difference between the value in TOLUD register and the lower of either 4GB or 'TOM minus ME Stolen memory size", and then minus 1MB boundary.
    //
    MemoryMap->RemapLimit = MemoryMap->RemapBase + (MIN (MEM_4GB, MemoryMap->TomMinusMe) - MemoryMap->ToludBase);

    MemoryMap->TouudBase = MemoryMap->RemapLimit;

    if (!((Inputs->CpuModel == cmHSW) && (Inputs->CpuStepping == csHswA0))) {
      MemoryMap->RemapLimit -= 0x1;
    }

    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Remap Limit %Xh\n", MemoryMap->RemapLimit);
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TOUUD Base %Xh\n", MemoryMap->TouudBase);
  } else {
    MemoryMap->ReclaimEnable = FALSE;
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Reclaim disable \n");
    //
    // TOUUD Base
    // If relcaim is disabled, this value is calculated by "TOM minus ME stolen size".
    //
    MemoryMap->TouudBase = MemoryMap->TomMinusMe;
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "TOUUD Base %Xh\n", MemoryMap->TouudBase);
  }
  //
  // GDXC must be aligned to 8MB boundary. But PSMI must be 16MB alligned
  // GdxcBase by subtracting Gdxc from BGSM.
  // @todo: GDXC is below DPRBASE if TXT is enabled, which is below TSEG. Maybe it will be required to be placed anywhere below TOLUD.
  //
  if (Outputs->Gdxc.GdxcEnable) {
    if (Inputs->MemoryTrace) {
      //
      // Put GDXC at the top of the second channel
      //
      if (MemoryMap->TotalPhysicalMemorySize <= MEM_4GB) {
        GdxcTop = MemoryMap->TouudBase;
      } else {
        GdxcTop = MemoryMap->TomMinusMe;
      }
    } else {
      //
      // Put GDXC below DPR stolen region.
      //
      GdxcTop = MemoryMap->TsegBase - Inputs->DprSize;
    }
    //
    // @todo For C-step we can remove the "minus 1MB" W/A
    //
    MemoryMap->GdxcMotSize = Outputs->Gdxc.GdxcMotSize << (23 - 20); // In MB
    MemoryMap->GdxcMotBase = GdxcTop - MemoryMap->GdxcMotSize - 1; // Minus 1 MB - WA for MOT overflow.
    MemoryMap->GdxcMotBase &= ~(MRC_BIT4 - 1);  // Round down to 16MB boundary
    
    MemoryMap->GdxcIotSize = Outputs->Gdxc.GdxcIotSize << (23 - 20); // In MB
    MemoryMap->GdxcIotBase = MemoryMap->GdxcMotBase - MemoryMap->GdxcIotSize;
    MemoryMap->GdxcIotBase -= 16; // 16MB for PSMI
    MRC_DEBUG_MSG (
      Debug,
      MSG_LEVEL_NOTE,
      "GDXC MOT base %Xh, size %d (%Xh) MB\n",
      MemoryMap->GdxcMotBase,
      MemoryMap->GdxcMotSize,
      MemoryMap->GdxcMotSize
      );
    MRC_DEBUG_MSG (
      Debug,
      MSG_LEVEL_NOTE,
      "GDXC IOT base %Xh, size %d (%Xh) MB\n",
      MemoryMap->GdxcIotBase,
      MemoryMap->GdxcIotSize,
      MemoryMap->GdxcIotSize
      );
    if (Inputs->MemoryTrace) {
      //
      // Put fTPM below DPR
      //
      FtpmTop = MemoryMap->TsegBase - Inputs->DprSize;
    } else {
      //
      // Put fTPM below GDXC.
      //
      FtpmTop = MemoryMap->GdxcIotBase;
    }
  } else {
    MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "GDXC DISABLED\n");
    FtpmTop = MemoryMap->TsegBase - Inputs->DprSize;
  }
  
#ifdef PTT_FLAG
  if (Inputs->CpuModel == cmHSW_ULT) {
    MrcOemMmioRead (R_PTT_HCI_STS, (U32 *) &PttSts, R_PTT_HCI_BASE_ADDRESS);
    if ((PttSts & B_PTT_HCI_STS_ENABLED) == B_PTT_HCI_STS_ENABLED) {
      //
      // fTPM Stolen size is 4KB
      //
      MemoryMap->FtpmStolenBase = (FtpmTop << 20) - 0x1000;
      MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "Ftpm Stolen base = %Xh\n", MemoryMap->FtpmStolenBase);
    }
  }
#endif // PTT_FLAG

  MemoryMap->MeStolenBase = MemoryMap->TomMinusMe;
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "ME stolen base %Xh\n", MemoryMap->MeStolenBase);

  MemoryMap->MeStolenSize = Inputs->MeStolenSize;
  MRC_DEBUG_MSG (Debug, MSG_LEVEL_NOTE, "ME stolen size %Xh\n", MemoryMap->MeStolenSize);

  UpdateMemoryMapRegisters (Inputs->PciEBaseAddress, Inputs->GdxcBaseAddress, MemoryMap);
  return mrcSuccess;
}

/**
@brief
  This function find the total memory in the system.
  and write it to TotalPhysicalMemorySize in MrcData structure.

  @param[in, out] MrcData - Include all MRC global data.

  @retval Nothing
**/
void
MrcTotalMemory (
  IN OUT MrcParameters *const MrcData
  )
{
  MrcOutput         *Outputs;
  MrcControllerOut  *ControllerOut;
  MrcChannelOut     *ChannelOut;
  MrcDimmOut        *DimmOut;
  U8                Controller;
  U8                Channel;
  U8                Dimm;

  Outputs = &MrcData->SysOut.Outputs;
  Outputs->MemoryMapData.TotalPhysicalMemorySize = 0;
  for (Controller = 0; Controller < MAX_CONTROLLERS; Controller++) {
    ControllerOut = &Outputs->Controller[Controller];
    for (Channel = 0; Channel < MAX_CHANNEL; Channel++) {
      ChannelOut           = &ControllerOut->Channel[Channel];
      ChannelOut->Capacity = 0;
      if (MrcChannelExist (Outputs, Channel)) {
        for (Dimm = 0; Dimm < MAX_DIMMS_IN_CHANNEL; Dimm++) {
          DimmOut = &ChannelOut->Dimm[Dimm];
          if (DimmOut->Status == DIMM_PRESENT) {
            ChannelOut->Capacity += DimmOut->DimmCapacity;
          }
        }

        ChannelOut->Capacity = MIN (ChannelOut->Capacity, Outputs->MrcTotalChannelLimit);
        Outputs->MemoryMapData.TotalPhysicalMemorySize += ChannelOut->Capacity;
      }
    }
  }

  return;
}

/**
@brief
  this function write to the memory init registers.

  @param[in] PciEBaseAddress - Address of the PCI Express BAR
  @param[in] GdxcBaseAddress - Address of the GDXC BAR
  @param[in] MemoryMap       - Include all the memory map definitions

  @retval Nothing
**/
void
UpdateMemoryMapRegisters (
  IN const U32                 PciEBaseAddress,
  IN const U32                 GdxcBaseAddress,
  IN const MrcMemoryMap *const MemoryMap
  )
{
  MRC_PCI_000_TOM_STRUCT        Tom;
  MRC_PCI_000_TOLUD_STRUCT      Tolud;
  MRC_PCI_000_TOUUD_STRUCT      Touud;
  MRC_PCI_000_REMAPBASE_STRUCT  RemapBase;
  MRC_PCI_000_REMAPLIMIT_STRUCT RemapLimit;
  MRC_PCI_000_TSEGMB_STRUCT     Tsegmb;
  MRC_PCI_000_BDSM_STRUCT       Bdsm;
  MRC_PCI_000_BGSM_STRUCT       Bgsm;
  MRC_PCI_000_MESEG_BASE_STRUCT MeSegBase;
  MRC_PCI_000_MESEG_MASK_STRUCT MeSegMask;
  MRC_PCI_000_DPR_STRUCT        Dpr;
  U32                           Offset;

  //
  // Write TOM register
  //
  Tom.Data                   = 0;
  Tom.Data32.Low.Bits.Value  = MemoryMap->TotalPhysicalMemorySize;
  Tom.Data32.High.Bits.Value = MemoryMap->TotalPhysicalMemorySize >> (32 - TOM_TOM_OFF);
  Offset                     = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_TOM_REG);
  MrcOemMmioWrite (Offset, Tom.Data32.Low.Data, PciEBaseAddress);
  MrcOemMmioWrite (Offset + 4, Tom.Data32.High.Data, PciEBaseAddress);

  //
  // Write TOLUD register
  //
  Tolud.Data       = 0;
  Tolud.Bits.Value = MemoryMap->ToludBase;
  Offset           = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_TOLUD_REG);
  MrcOemMmioWrite (Offset, Tolud.Data, PciEBaseAddress);

  //
  // Write TOUUD register
  //
  Touud.Data                   = 0;
  Touud.Data32.Low.Bits.Value  = MemoryMap->TouudBase;
  Touud.Data32.High.Bits.Value = MemoryMap->TouudBase >> (32 - TOUUD_TOUUD_OFF);
  Offset                       = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_TOUUD_REG);
  MrcOemMmioWrite (Offset, Touud.Data32.Low.Data, PciEBaseAddress);
  MrcOemMmioWrite (Offset + 4, Touud.Data32.High.Data, PciEBaseAddress);

  if (MemoryMap->ReclaimEnable) {
    //
    // Write REMAPBASE register.
    //
    RemapBase.Data                   = 0;
    RemapBase.Data32.Low.Bits.Value  = MemoryMap->RemapBase;
    RemapBase.Data32.High.Bits.Value = MemoryMap->RemapBase >> (32 - REMAPBASE_REMAPBASE_OFF);
    Offset                           = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_REMAPBASE_REG);
    MrcOemMmioWrite (Offset, RemapBase.Data32.Low.Data, PciEBaseAddress);
    MrcOemMmioWrite (Offset + 4, RemapBase.Data32.High.Data, PciEBaseAddress);

    //
    // Write REMAPLIMIT register.
    //
    RemapLimit.Data                   = 0;
    RemapLimit.Data32.Low.Bits.Value  = MemoryMap->RemapLimit;
    RemapLimit.Data32.High.Bits.Value = MemoryMap->RemapLimit >> (32 - REMAPLIMIT_REMAPLMT_OFF);
    Offset                            = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_REMAPLIMIT_REG);
    MrcOemMmioWrite (Offset, RemapLimit.Data32.Low.Data, PciEBaseAddress);
    MrcOemMmioWrite (Offset + 4, RemapLimit.Data32.High.Data, PciEBaseAddress);
  }
  //
  // Write TSEGMB register
  //
  Offset            = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_TSEGMB_REG);
  Tsegmb.Data       = 0;
  Tsegmb.Bits.Value = MemoryMap->TsegBase;
  MrcOemMmioWrite (Offset, Tsegmb.Data, PciEBaseAddress);

  //
  // Program DPR Register with DPR size & DMA Protection Enabled
  //
  if(MemoryMap->DprSize != 0){
    Offset = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_DPR_REG);
    MrcOemMmioRead (Offset, &Dpr.Data, PciEBaseAddress);
    Dpr.Bits.Dprsize = MemoryMap->DprSize;
    Dpr.Bits.Epm     = 1;
    MrcOemMmioWrite (Offset, Dpr.Data, PciEBaseAddress);
  }
  //
  // Write BDSM register
  //
  Offset          = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_BDSM_REG);
  Bdsm.Data       = 0;
  Bdsm.Bits.Value = MemoryMap->BdsmBase;
  MrcOemMmioWrite (Offset, Bdsm.Data, PciEBaseAddress);

  //
  // Write BGSM register
  //
  Offset          = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_BGSM_REG);
  Bgsm.Data       = 0;
  Bgsm.Bits.Value = MemoryMap->GttBase;
  MrcOemMmioWrite (Offset, Bgsm.Data, PciEBaseAddress);

  //
  // Enable ME Stolen Memory if the size is not zero
  //
  if (MemoryMap->MeStolenSize != 0) {
    //
    // Write MESEG_MASK register. Must be written before MESEG_BASE.
    //
    MeSegMask.Data                   = 0;
    MeSegMask.Data32.Low.Bits.Enable = 1;
    Offset                           = 0x80000 - MemoryMap->MeStolenSize;
    MeSegMask.Data32.Low.Bits.Value  = Offset;
    MeSegMask.Data32.High.Bits.Value = Offset >> (32 - MESEG_MASK_MEMASK_OFF);
    Offset                           = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_MESEG_MASK_REG);
    MrcOemMmioWrite (Offset, MeSegMask.Data32.Low.Data, PciEBaseAddress);
    MrcOemMmioWrite (Offset + 4, MeSegMask.Data32.High.Data, PciEBaseAddress);

    //
    // Write MESEG_BASE register
    //
    MeSegBase.Data                   = 0;
    MeSegBase.Data32.Low.Bits.Value  = MemoryMap->MeStolenBase;
    MeSegBase.Data32.High.Bits.Value = MemoryMap->MeStolenBase >> (32 - MESEG_BASE_MEBASE_OFF);
    Offset                           = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_MESEG_BASE_REG);
    MrcOemMmioWrite (Offset, MeSegBase.Data32.Low.Data, PciEBaseAddress);
    MrcOemMmioWrite (Offset + 4, MeSegBase.Data32.High.Data, PciEBaseAddress);
  }
  //
  // Write graphics control register
  //
  Offset = MrcOemGetPcieDeviceAddress (0, 0, 0, MRC_PCI_000_GGC_REG);
  MrcOemMmioWrite (Offset, MemoryMap->GraphicsControlRegister, PciEBaseAddress);

  //
  // Program GDXC Registers
  // 1st MOT: 0x10, 0x14 and 0x18 (Address Low, Address High and Region)
  // 2nd IOT: 0x20, 0x24 and 0x28 (Address Low, Address High and Region)
  //
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_MOT_ADDRESS_LO_REG,
    MemoryMap->GdxcMotBase << 14,   // (GdxcMotBase << 20) >> 6, Current Pointer in cache line units
    GdxcBaseAddress
    );
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_MOT_ADDRESS_HI_REG,
    (MemoryMap->GdxcMotBase & MRC_BIT18) >> 18, // Bit [18] will be bit [32], so it goes to MOT_ADDRESS_HI.MEM_PTR
    GdxcBaseAddress
    );
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_MOT_REGION_REG,
    MemoryMap->GdxcMotBase >> 3 |  // (GdxcMotBase << 20) >> 23, MOT_REGION.START_ADDRESS is bits [38:23]
    (((MemoryMap->GdxcMotBase + MemoryMap->GdxcMotSize) >> 3) << 16),
    GdxcBaseAddress
    );
    
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_OCLA_ADDRESS_LO_REG,
    MemoryMap->GdxcIotBase << 14,   // (GdxcIotBase << 20) >> 6, Current Pointer in cache line units
    GdxcBaseAddress
    );
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_OCLA_ADDRESS_HI_REG,
    MPCOHTRK_CR_GDXC_OCLA_ADDRESS_HI_LOCK_MSK | (MemoryMap->GdxcIotBase & MRC_BIT18) >> 18, // Bit [18] will be bit [32], goes to IOT_ADDRESS_HI.MEM_PTR
    GdxcBaseAddress
    );
  MrcOemMmioWrite (
    MPCOHTRK_CR_GDXC_OCLA_REGION_REG,
    MemoryMap->GdxcIotBase >> 3 |  // (GdxcIotBase << 20) >> 23, OCLA_REGION.START_ADDRESS is bits [38:23]
    (((MemoryMap->GdxcIotBase + MemoryMap->GdxcIotSize) >> 3) << 16),
    GdxcBaseAddress
    );
  return;
}