blob: 58b35e09fd6e062d08c807425afd0708e715ee46 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Siyuan Wang3e32cc02013-07-09 17:16:20 +08002
3#include <device/pci_def.h>
4#include <device/device.h>
5
6/* warning: Porting.h includes an open #pragma pack(1) */
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02007#include <Porting.h>
8#include <AGESA.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +08009#include "chip.h"
10
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110011#include <northbridge/amd/agesa/dimmSpd.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080012
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110013/**
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 Reinauer8d29dd12017-06-26 14:30:39 -070017AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080018{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110019 UINT8 spdAddress;
20
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +030021 DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110022 if (dev == NULL)
23 return AGESA_ERROR;
24
Aaron Durbine4d7abc2017-04-16 22:05:36 -050025 DEVTREE_CONST struct northbridge_amd_agesa_family16kb_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110026 if (config == NULL)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080027 return AGESA_ERROR;
28
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110029 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080030 return AGESA_ERROR;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110031 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080032 return AGESA_ERROR;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110033 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080034 return AGESA_ERROR;
35
36 spdAddress = config->spdAddrLookup
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110037 [info->SocketId][info->MemChannelId][info->DimmId];
Siyuan Wang3e32cc02013-07-09 17:16:20 +080038
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030039 if (spdAddress == 0)
40 return AGESA_ERROR;
41
Mike Banon8b7bda42020-08-15 10:30:19 +030042 int err = hudson_readSpd(spdAddress, (void *) info->Buffer, DDR3_SPD_SIZE);
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030043 if (err)
44 return AGESA_ERROR;
45 return AGESA_SUCCESS;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080046}