blob: e9eeb49c82edf59fb8a265aaade4550f79c8bd4f [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Martin Roth3b2653b2013-02-24 10:46:11 -07003
4#include <device/pci_def.h>
5#include <device/device.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02006#include <OEM.h> /* SMBUS0_BASE_ADDRESS */
Martin Roth3b2653b2013-02-24 10:46:11 -07007
8/* warning: Porting.h includes an open #pragma pack(1) */
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02009#include <Porting.h>
10#include <AGESA.h>
Martin Roth3b2653b2013-02-24 10:46:11 -070011#include "chip.h"
12
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030013#include <northbridge/amd/agesa/dimmSpd.h>
14
Martin Roth3b2653b2013-02-24 10:46:11 -070015/**
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110016 * Gets the SMBus address for an SPD from the array in devicetree.cb
Martin Roth3b2653b2013-02-24 10:46:11 -070017 * then read the SPD into the supplied buffer.
18 */
Stefan Reinauer8d29dd12017-06-26 14:30:39 -070019AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Martin Roth3b2653b2013-02-24 10:46:11 -070020{
21 UINT8 spdAddress;
Martin Roth3b2653b2013-02-24 10:46:11 -070022
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +030023 DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110024 if (dev == NULL)
Martin Roth3b2653b2013-02-24 10:46:11 -070025 return AGESA_ERROR;
26
Aaron Durbine4d7abc2017-04-16 22:05:36 -050027 DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110028 if (config == NULL)
29 return AGESA_ERROR;
30
Martin Roth3b2653b2013-02-24 10:46:11 -070031 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älkkia1ebbc42014-10-17 22:33:22 +030043
44 int err = smbus_readSpd(spdAddress, (void *) info->Buffer, 128);
45 if (err)
46 return AGESA_ERROR;
47 return AGESA_SUCCESS;
Martin Roth3b2653b2013-02-24 10:46:11 -070048}