Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 1 | /* |
| 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 18 | */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 19 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 20 | #include "agesawrapper.h" |
| 21 | #include "amdlib.h" |
| 22 | #include "BiosCallOuts.h" |
| 23 | #include "heapManager.h" |
| 24 | #include "SB800.h" |
Jens Rottmann | db6c5bf | 2013-03-21 22:21:28 +0100 | [diff] [blame] | 25 | #include <northbridge/amd/agesa/family14/dimmSpd.h> |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 26 | |
Kyösti Mälkki | f1bb19a | 2014-05-04 17:23:49 +0300 | [diff] [blame] | 27 | /* 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 | |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame^] | 33 | static AGESA_STATUS board_BeforeDramInit (UINT32 Func, UINT32 Data, VOID *ConfigPtr); |
| 34 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 35 | CONST BIOS_CALLOUT_STRUCT BiosCallouts[] = |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 36 | { |
Kyösti Mälkki | 08df732 | 2014-05-04 14:53:36 +0300 | [diff] [blame] | 37 | {AGESA_ALLOCATE_BUFFER, BiosAllocateBuffer }, |
| 38 | {AGESA_DEALLOCATE_BUFFER, BiosDeallocateBuffer }, |
Kyösti Mälkki | 08df732 | 2014-05-04 14:53:36 +0300 | [diff] [blame] | 39 | {AGESA_LOCATE_BUFFER, BiosLocateBuffer }, |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 40 | {AGESA_DO_RESET, agesa_Reset }, |
Kyösti Mälkki | 08df732 | 2014-05-04 14:53:36 +0300 | [diff] [blame] | 41 | {AGESA_READ_SPD, BiosReadSpd }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 42 | {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 43 | {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 44 | {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess }, |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame^] | 45 | {AGESA_HOOKBEFORE_DRAM_INIT, board_BeforeDramInit }, |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 46 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess }, |
Kyösti Mälkki | f1bb19a | 2014-05-04 17:23:49 +0300 | [diff] [blame] | 47 | {AGESA_GNB_PCIE_SLOT_RESET, agesa_NoopUnsupported }, |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 50 | AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 51 | { |
| 52 | UINTN i; |
| 53 | AGESA_STATUS CalloutStatus; |
| 54 | UINTN CallOutCount = sizeof (BiosCallouts) / sizeof (BiosCallouts [0]); |
| 55 | |
| 56 | for (i = 0; i < CallOutCount; i++) |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 57 | { |
| 58 | if (BiosCallouts[i].CalloutName == Func) |
| 59 | { |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
Aladyshev Konstantin | 3d63b0a | 2012-12-19 00:58:35 +0400 | [diff] [blame] | 64 | if(i >= CallOutCount) |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 65 | { |
| 66 | return AGESA_UNSUPPORTED; |
| 67 | } |
| 68 | |
| 69 | CalloutStatus = BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr); |
| 70 | |
| 71 | return CalloutStatus; |
| 72 | } |
| 73 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 74 | /* Call the host environment interface to provide a user hook opportunity. */ |
Kyösti Mälkki | c009601 | 2014-05-05 18:56:33 +0300 | [diff] [blame^] | 75 | static AGESA_STATUS board_BeforeDramInit (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 76 | { |
| 77 | AGESA_STATUS Status; |
| 78 | UINTN FcnData; |
| 79 | MEM_DATA_STRUCT *MemData; |
| 80 | UINT32 AcpiMmioAddr; |
| 81 | UINT32 GpioMmioAddr; |
| 82 | UINT8 Data8; |
| 83 | UINT16 Data16; |
| 84 | UINT8 TempData8; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 85 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 86 | FcnData = Data; |
| 87 | MemData = ConfigPtr; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 88 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 89 | Status = AGESA_SUCCESS; |
| 90 | /* Get SB800 MMIO Base (AcpiMmioAddr) */ |
| 91 | WriteIo8 (0xCD6, 0x27); |
| 92 | Data8 = ReadIo8(0xCD7); |
| 93 | Data16 = Data8<<8; |
| 94 | WriteIo8 (0xCD6, 0x26); |
| 95 | Data8 = ReadIo8(0xCD7); |
| 96 | Data16 |= Data8; |
| 97 | AcpiMmioAddr = (UINT32)Data16 << 16; |
| 98 | GpioMmioAddr = AcpiMmioAddr + GPIO_BASE; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 99 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 100 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG178); |
| 101 | Data8 &= ~BIT5; |
| 102 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 103 | TempData8 &= 0x03; |
| 104 | TempData8 |= Data8; |
| 105 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 106 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 107 | Data8 |= BIT2+BIT3; |
| 108 | Data8 &= ~BIT4; |
| 109 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 110 | TempData8 &= 0x23; |
| 111 | TempData8 |= Data8; |
| 112 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, TempData8); |
| 113 | Data8 = Read64Mem8(GpioMmioAddr+SB_GPIO_REG179); |
| 114 | Data8 &= ~BIT5; |
| 115 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 116 | TempData8 &= 0x03; |
| 117 | TempData8 |= Data8; |
| 118 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8); |
| 119 | Data8 |= BIT2+BIT3; |
| 120 | Data8 &= ~BIT4; |
| 121 | TempData8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 122 | TempData8 &= 0x23; |
| 123 | TempData8 |= Data8; |
| 124 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, TempData8); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 125 | |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 126 | switch(MemData->ParameterListPtr->DDR3Voltage){ |
| 127 | case VOLT1_35: |
| 128 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 129 | Data8 &= ~(UINT8)BIT6; |
| 130 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 131 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 132 | Data8 |= (UINT8)BIT6; |
| 133 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 134 | break; |
| 135 | case VOLT1_25: |
| 136 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 137 | Data8 &= ~(UINT8)BIT6; |
| 138 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 139 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 140 | Data8 &= ~(UINT8)BIT6; |
| 141 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 142 | break; |
| 143 | case VOLT1_5: |
| 144 | default: |
| 145 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG178); |
| 146 | Data8 |= (UINT8)BIT6; |
| 147 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG178, Data8); |
| 148 | Data8 = Read64Mem8 (GpioMmioAddr+SB_GPIO_REG179); |
| 149 | Data8 &= ~(UINT8)BIT6; |
| 150 | Write64Mem8(GpioMmioAddr+SB_GPIO_REG179, Data8); |
| 151 | } |
Marshall Buschman | eab1db1 | 2011-06-10 21:16:41 -0500 | [diff] [blame] | 152 | // disable memory clear for boot time reduction |
| 153 | MemData->ParameterListPtr->EnableMemClr = FALSE; |
Scott Duplichan | a649a96 | 2011-02-24 05:00:33 +0000 | [diff] [blame] | 154 | return Status; |
| 155 | } |