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