blob: c24466efe9c54fc806bdf20bde170b034718f36a [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Bruce Griffith27ed80b2014-08-15 11:46:25 -06002
Elyes HAOUAS0afc41e2018-11-27 11:25:19 +01003#include <commonlib/helpers.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -06004#include <device/pci_def.h>
5#include <device/device.h>
6
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>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060010#include "chip.h"
11
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020012#include <northbridge/amd/pi/dimmSpd.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060013
Elyes Haouasf9b535e2022-07-16 09:47:42 +020014AGESA_STATUS AmdMemoryReadSPD(UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060015{
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030016 int spdAddress;
Kyösti Mälkki33ff44c2018-05-22 01:15:22 +030017 DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
Jacob Garber42660cd2019-03-21 14:20:21 -060018
19 if (dev == NULL)
20 return AGESA_ERROR;
21
Aaron Durbine4d7abc2017-04-16 22:05:36 -050022 DEVTREE_CONST struct northbridge_amd_pi_00730F01_config *config = dev->chip_info;
Bruce Griffith27ed80b2014-08-15 11:46:25 -060023
Jacob Garber42660cd2019-03-21 14:20:21 -060024 if (config == NULL)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060025 return AGESA_ERROR;
26
Elyes HAOUAS0afc41e2018-11-27 11:25:19 +010027 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
Bruce Griffith27ed80b2014-08-15 11:46:25 -060028 return AGESA_ERROR;
Elyes HAOUAS0afc41e2018-11-27 11:25:19 +010029 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
Bruce Griffith27ed80b2014-08-15 11:46:25 -060030 return AGESA_ERROR;
Elyes HAOUAS0afc41e2018-11-27 11:25:19 +010031 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
Bruce Griffith27ed80b2014-08-15 11:46:25 -060032 return AGESA_ERROR;
33
34 spdAddress = config->spdAddrLookup
35 [info->SocketId] [info->MemChannelId] [info->DimmId];
36
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030037 if (spdAddress == 0)
38 return AGESA_ERROR;
39
Elyes Haouasf9b535e2022-07-16 09:47:42 +020040 int err = hudson_readSpd(spdAddress, (void *)info->Buffer, 128);
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030041 if (err)
42 return AGESA_ERROR;
43 return AGESA_SUCCESS;
Bruce Griffith27ed80b2014-08-15 11:46:25 -060044}