blob: 51081837a0344a5de653e231342509f23928212b [file] [log] [blame]
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001/*
2 * This file is part of the coreboot project.
3 *
Siyuan Wang3e32cc02013-07-09 17:16:20 +08004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Siyuan Wang3e32cc02013-07-09 17:16:20 +080013 */
14
15#include <device/pci_def.h>
16#include <device/device.h>
17
18/* warning: Porting.h includes an open #pragma pack(1) */
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020019#include <Porting.h>
20#include <AGESA.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080021#include "chip.h"
22
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110023#include <northbridge/amd/agesa/dimmSpd.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080024
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110025/**
26 * Gets the SMBus address for an SPD from the array in devicetree.cb
27 * then read the SPD into the supplied buffer.
28 */
Stefan Reinauer8d29dd12017-06-26 14:30:39 -070029AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080030{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110031 UINT8 spdAddress;
32
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +030033 DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2);
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110034 if (dev == NULL)
35 return AGESA_ERROR;
36
Aaron Durbine4d7abc2017-04-16 22:05:36 -050037 DEVTREE_CONST struct northbridge_amd_agesa_family16kb_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110038 if (config == NULL)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080039 return AGESA_ERROR;
40
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110041 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080042 return AGESA_ERROR;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110043 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080044 return AGESA_ERROR;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110045 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
Siyuan Wang3e32cc02013-07-09 17:16:20 +080046 return AGESA_ERROR;
47
48 spdAddress = config->spdAddrLookup
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110049 [info->SocketId][info->MemChannelId][info->DimmId];
Siyuan Wang3e32cc02013-07-09 17:16:20 +080050
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030051 if (spdAddress == 0)
52 return AGESA_ERROR;
53
54 int err = hudson_readSpd(spdAddress, (void *) info->Buffer, 128);
55 if (err)
56 return AGESA_ERROR;
57 return AGESA_SUCCESS;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080058}