blob: a199152ffc4ad48efa23b8a886e150c72326e135 [file] [log] [blame]
Scott Duplichana649a962011-02-24 05:00:33 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Scott Duplichana649a962011-02-24 05:00:33 +000018 */
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070019
Scott Duplichana649a962011-02-24 05:00:33 +000020#include "agesawrapper.h"
21#include "amdlib.h"
22#include "BiosCallOuts.h"
23#include "heapManager.h"
24#include "SB800.h"
Jens Rottmanndb6c5bf2013-03-21 22:21:28 +010025#include <northbridge/amd/agesa/family14/dimmSpd.h>
Scott Duplichana649a962011-02-24 05:00:33 +000026
Kyösti Mälkkif1bb19a2014-05-04 17:23:49 +030027/* Should AGESA_GNB_PCIE_SLOT_RESET use agesa_NoopSuccess?
28 *
29 * Board is known to have some issues with integrated NIC and
30 * might need implementation to drive some GPIOs.
31 */
32
Aladyshev Konstantin3d63b0a2012-12-19 00:58:35 +040033CONST BIOS_CALLOUT_STRUCT BiosCallouts[] =
Scott Duplichana649a962011-02-24 05:00:33 +000034{
Kyösti Mälkki08df7322014-05-04 14:53:36 +030035 {AGESA_ALLOCATE_BUFFER, BiosAllocateBuffer },
36 {AGESA_DEALLOCATE_BUFFER, BiosDeallocateBuffer },
Kyösti Mälkki08df7322014-05-04 14:53:36 +030037 {AGESA_LOCATE_BUFFER, BiosLocateBuffer },
Kyösti Mälkki5e19fa42014-05-04 23:13:54 +030038 {AGESA_DO_RESET, agesa_Reset },
Kyösti Mälkki08df7322014-05-04 14:53:36 +030039 {AGESA_READ_SPD, BiosReadSpd },
Kyösti Mälkkic459f962014-05-04 17:07:45 +030040 {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
Kyösti Mälkki6b4b1512014-05-05 12:05:53 +030041 {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
Kyösti Mälkkic459f962014-05-04 17:07:45 +030042 {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess },
Kyösti Mälkki08df7322014-05-04 14:53:36 +030043 {AGESA_HOOKBEFORE_DRAM_INIT, BiosHookBeforeDramInit },
Kyösti Mälkkic459f962014-05-04 17:07:45 +030044 {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess },
Kyösti Mälkkif1bb19a2014-05-04 17:23:49 +030045 {AGESA_GNB_PCIE_SLOT_RESET, agesa_NoopUnsupported },
Scott Duplichana649a962011-02-24 05:00:33 +000046};
47
Aladyshev Konstantin3d63b0a2012-12-19 00:58:35 +040048AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
49{
50 UINTN i;
51 AGESA_STATUS CalloutStatus;
52 UINTN CallOutCount = sizeof (BiosCallouts) / sizeof (BiosCallouts [0]);
53
54 for (i = 0; i < CallOutCount; i++)
Scott Duplichana649a962011-02-24 05:00:33 +000055 {
56 if (BiosCallouts[i].CalloutName == Func)
57 {
58 break;
59 }
60 }
61
Aladyshev Konstantin3d63b0a2012-12-19 00:58:35 +040062 if(i >= CallOutCount)
Scott Duplichana649a962011-02-24 05:00:33 +000063 {
64 return AGESA_UNSUPPORTED;
65 }
66
67 CalloutStatus = BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr);
68
69 return CalloutStatus;
70}
71
Scott Duplichana649a962011-02-24 05:00:33 +000072/* Call the host environment interface to provide a user hook opportunity. */
Scott Duplichana649a962011-02-24 05:00:33 +000073AGESA_STATUS BiosHookBeforeDramInit (UINT32 Func, UINT32 Data, VOID *ConfigPtr)
74{
75 AGESA_STATUS Status;
76 UINTN FcnData;
77 MEM_DATA_STRUCT *MemData;
78 UINT32 AcpiMmioAddr;
79 UINT32 GpioMmioAddr;
80 UINT8 Data8;
81 UINT16 Data16;
82 UINT8 TempData8;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070083
Scott Duplichana649a962011-02-24 05:00:33 +000084 FcnData = Data;
85 MemData = ConfigPtr;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070086
Scott Duplichana649a962011-02-24 05:00:33 +000087 Status = AGESA_SUCCESS;
88 /* Get SB800 MMIO Base (AcpiMmioAddr) */
89 WriteIo8 (0xCD6, 0x27);
90 Data8 = ReadIo8(0xCD7);
91 Data16 = Data8<<8;
92 WriteIo8 (0xCD6, 0x26);
93 Data8 = ReadIo8(0xCD7);
94 Data16 |= Data8;
95 AcpiMmioAddr = (UINT32)Data16 << 16;
96 GpioMmioAddr = AcpiMmioAddr + GPIO_BASE;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070097
Scott Duplichana649a962011-02-24 05:00:33 +000098 Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG178);
99 Data8 &= ~BIT5;
100 TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178);
101 TempData8 &= 0x03;
102 TempData8 |= Data8;
103 Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700104
Scott Duplichana649a962011-02-24 05:00:33 +0000105 Data8 |= BIT2+BIT3;
106 Data8 &= ~BIT4;
107 TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178);
108 TempData8 &= 0x23;
109 TempData8 |= Data8;
110 Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8);
111 Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG179);
112 Data8 &= ~BIT5;
113 TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179);
114 TempData8 &= 0x03;
115 TempData8 |= Data8;
116 Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8);
117 Data8 |= BIT2+BIT3;
118 Data8 &= ~BIT4;
119 TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179);
120 TempData8 &= 0x23;
121 TempData8 |= Data8;
122 Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8);
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700123
Scott Duplichana649a962011-02-24 05:00:33 +0000124 switch(MemData->ParameterListPtr->DDR3Voltage){
125 case VOLT1_35:
126 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178);
127 Data8 &= ~(UINT8)BIT6;
128 Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8);
129 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179);
130 Data8 |= (UINT8)BIT6;
131 Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8);
132 break;
133 case VOLT1_25:
134 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178);
135 Data8 &= ~(UINT8)BIT6;
136 Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8);
137 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179);
138 Data8 &= ~(UINT8)BIT6;
139 Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8);
140 break;
141 case VOLT1_5:
142 default:
143 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178);
144 Data8 |= (UINT8)BIT6;
145 Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8);
146 Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179);
147 Data8 &= ~(UINT8)BIT6;
148 Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8);
149 }
Marshall Buschmaneab1db12011-06-10 21:16:41 -0500150 // disable memory clear for boot time reduction
151 MemData->ParameterListPtr->EnableMemClr = FALSE;
Scott Duplichana649a962011-02-24 05:00:33 +0000152 return Status;
153}