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. |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <device/pci_def.h> |
| 17 | #include <device/device.h> |
| 18 | #include <stdlib.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame^] | 19 | #include <OEM.h> /* SMBUS0_BASE_ADDRESS */ |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 20 | |
| 21 | /* warning: Porting.h includes an open #pragma pack(1) */ |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame^] | 22 | #include <Porting.h> |
| 23 | #include <AGESA.h> |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 24 | #include "chip.h" |
| 25 | |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 26 | #include <northbridge/amd/agesa/dimmSpd.h> |
| 27 | |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 28 | /** |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 29 | * Gets the SMBus address for an SPD from the array in devicetree.cb |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 30 | * then read the SPD into the supplied buffer. |
| 31 | */ |
Stefan Reinauer | 8d29dd1 | 2017-06-26 14:30:39 -0700 | [diff] [blame] | 32 | AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info) |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 33 | { |
| 34 | UINT8 spdAddress; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 35 | |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 36 | DEVTREE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2)); |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 37 | if (dev == NULL) |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 38 | return AGESA_ERROR; |
| 39 | |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 40 | DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 41 | if (config == NULL) |
| 42 | return AGESA_ERROR; |
| 43 | |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 44 | if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup)) |
| 45 | return AGESA_ERROR; |
| 46 | if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0])) |
| 47 | return AGESA_ERROR; |
| 48 | if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0])) |
| 49 | return AGESA_ERROR; |
| 50 | |
| 51 | spdAddress = config->spdAddrLookup |
| 52 | [info->SocketId][info->MemChannelId][info->DimmId]; |
| 53 | |
| 54 | if (spdAddress == 0) |
| 55 | return AGESA_ERROR; |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 56 | |
| 57 | int err = smbus_readSpd(spdAddress, (void *) info->Buffer, 128); |
| 58 | if (err) |
| 59 | return AGESA_ERROR; |
| 60 | return AGESA_SUCCESS; |
Martin Roth | 3b2653b | 2013-02-24 10:46:11 -0700 | [diff] [blame] | 61 | } |