Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
zbao | 323a923 | 2012-07-19 16:39:01 +0800 | [diff] [blame] | 2 | |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 3 | #include <device/pci_def.h> |
| 4 | #include <device/device.h> |
| 5 | |
| 6 | /* warning: Porting.h includes an open #pragma pack(1) */ |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 7 | #include <Porting.h> |
| 8 | #include <AGESA.h> |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 9 | #include "chip.h" |
| 10 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 11 | #include <northbridge/amd/agesa/dimmSpd.h> |
zbao | 323a923 | 2012-07-19 16:39:01 +0800 | [diff] [blame] | 12 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 13 | /** |
| 14 | * Gets the SMBus address for an SPD from the array in devicetree.cb |
| 15 | * then read the SPD into the supplied buffer. |
| 16 | */ |
Stefan Reinauer | 8d29dd1 | 2017-06-26 14:30:39 -0700 | [diff] [blame] | 17 | AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info) |
zbao | 323a923 | 2012-07-19 16:39:01 +0800 | [diff] [blame] | 18 | { |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 19 | UINT8 spdAddress; |
| 20 | |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 21 | DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2); |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 22 | if (dev == NULL) |
| 23 | return AGESA_ERROR; |
| 24 | |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 25 | DEVTREE_CONST struct northbridge_amd_agesa_family15tn_config *config = dev->chip_info; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 26 | if (config == NULL) |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 27 | return AGESA_ERROR; |
zbao | 323a923 | 2012-07-19 16:39:01 +0800 | [diff] [blame] | 28 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 29 | if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup)) |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 30 | return AGESA_ERROR; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 31 | if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0])) |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 32 | return AGESA_ERROR; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 33 | if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0])) |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 34 | return AGESA_ERROR; |
| 35 | |
| 36 | spdAddress = config->spdAddrLookup |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 37 | [info->SocketId][info->MemChannelId][info->DimmId]; |
Martin Roth | 7fb692b | 2013-01-20 10:38:58 -0700 | [diff] [blame] | 38 | |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 39 | if (spdAddress == 0) |
| 40 | return AGESA_ERROR; |
| 41 | |
Mike Banon | 8b7bda4 | 2020-08-15 10:30:19 +0300 | [diff] [blame] | 42 | int err = hudson_readSpd(spdAddress, (void *) info->Buffer, DDR3_SPD_SIZE); |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 43 | if (err) |
| 44 | return AGESA_ERROR; |
| 45 | return AGESA_SUCCESS; |
zbao | 323a923 | 2012-07-19 16:39:01 +0800 | [diff] [blame] | 46 | } |