Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <device/pci_def.h> |
| 21 | #include <device/device.h> |
| 22 | #include <stdlib.h> |
| 23 | #include "OEM.h" /* SMBUS0_BASE_ADDRESS */ |
| 24 | |
| 25 | /* warning: Porting.h includes an open #pragma pack(1) */ |
| 26 | #include "Porting.h" |
| 27 | #include "AGESA.h" |
| 28 | #include "amdlib.h" |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 29 | #include "chip.h" |
| 30 | |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame^] | 31 | #include <northbridge/amd/agesa/dimmSpd.h> |
| 32 | |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 33 | /* uncomment for source level debug - GDB gets really confused otherwise. */ |
| 34 | //#pragma optimize ("", off) |
| 35 | |
| 36 | /** |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 37 | * Gets the SMBUS address for an SPD from the array in devicetree.cb |
| 38 | * then read the SPD into the supplied buffer. |
| 39 | */ |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame^] | 40 | AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PARAMS *info) |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 41 | { |
| 42 | UINT8 spdAddress; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 43 | ROMSTAGE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2)); |
| 44 | ROMSTAGE_CONST struct northbridge_amd_agesa_family14_config *config = NULL; |
| 45 | |
| 46 | if ((dev == 0) || (dev->chip_info == 0)) |
| 47 | return AGESA_ERROR; |
| 48 | |
| 49 | config = dev->chip_info; |
| 50 | if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup)) |
| 51 | return AGESA_ERROR; |
| 52 | if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0])) |
| 53 | return AGESA_ERROR; |
| 54 | if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0])) |
| 55 | return AGESA_ERROR; |
| 56 | |
| 57 | spdAddress = config->spdAddrLookup |
| 58 | [info->SocketId][info->MemChannelId][info->DimmId]; |
| 59 | |
| 60 | if (spdAddress == 0) |
| 61 | return AGESA_ERROR; |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame^] | 62 | |
| 63 | int err = smbus_readSpd(spdAddress, (void *) info->Buffer, 128); |
| 64 | if (err) |
| 65 | return AGESA_ERROR; |
| 66 | return AGESA_SUCCESS; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 67 | } |