blob: 91ac45af440033f71e31ffe6a283a870ae0524ce [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth3b2653b2013-02-24 10:46:11 -07002
3#include <device/pci_def.h>
4#include <device/device.h>
Elyes HAOUAS3b3d0852021-02-01 10:09:40 +01005#include <OEM.h>
Martin Roth3b2653b2013-02-24 10:46:11 -07006
7/* warning: Porting.h includes an open #pragma pack(1) */
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02008#include <Porting.h>
9#include <AGESA.h>
Martin Roth3b2653b2013-02-24 10:46:11 -070010#include "chip.h"
11
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030012#include <northbridge/amd/agesa/dimmSpd.h>
13
Martin Roth3b2653b2013-02-24 10:46:11 -070014/**
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110015 * Gets the SMBus address for an SPD from the array in devicetree.cb
Martin Roth3b2653b2013-02-24 10:46:11 -070016 * then read the SPD into the supplied buffer.
17 */
Elyes Haouasf63edd92022-07-16 09:36:50 +020018AGESA_STATUS AmdMemoryReadSPD(UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Martin Roth3b2653b2013-02-24 10:46:11 -070019{
20 UINT8 spdAddress;
Martin Roth3b2653b2013-02-24 10:46:11 -070021
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +030022 DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110023 if (dev == NULL)
Martin Roth3b2653b2013-02-24 10:46:11 -070024 return AGESA_ERROR;
25
Aaron Durbine4d7abc2017-04-16 22:05:36 -050026 DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110027 if (config == NULL)
28 return AGESA_ERROR;
29
Martin Roth3b2653b2013-02-24 10:46:11 -070030 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
31 return AGESA_ERROR;
32 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
33 return AGESA_ERROR;
34 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
35 return AGESA_ERROR;
36
37 spdAddress = config->spdAddrLookup
38 [info->SocketId][info->MemChannelId][info->DimmId];
39
40 if (spdAddress == 0)
41 return AGESA_ERROR;
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030042
Elyes Haouasf63edd92022-07-16 09:36:50 +020043 int err = smbus_readSpd(spdAddress, (void *)info->Buffer, DDR3_SPD_SIZE);
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030044 if (err)
45 return AGESA_ERROR;
46 return AGESA_SUCCESS;
Martin Roth3b2653b2013-02-24 10:46:11 -070047}