blob: 25771d1d2d7074970ebad0b051600e6563a90942 [file] [log] [blame]
Martin Roth3b2653b2013-02-24 10:46:11 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Martin Roth3b2653b2013-02-24 10:46:11 -070014 */
15
16#include <device/pci_def.h>
17#include <device/device.h>
18#include <stdlib.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020019#include <OEM.h> /* SMBUS0_BASE_ADDRESS */
Martin Roth3b2653b2013-02-24 10:46:11 -070020
21/* warning: Porting.h includes an open #pragma pack(1) */
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020022#include <Porting.h>
23#include <AGESA.h>
Martin Roth3b2653b2013-02-24 10:46:11 -070024#include "chip.h"
25
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030026#include <northbridge/amd/agesa/dimmSpd.h>
27
Martin Roth3b2653b2013-02-24 10:46:11 -070028/**
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110029 * Gets the SMBus address for an SPD from the array in devicetree.cb
Martin Roth3b2653b2013-02-24 10:46:11 -070030 * then read the SPD into the supplied buffer.
31 */
Stefan Reinauer8d29dd12017-06-26 14:30:39 -070032AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info)
Martin Roth3b2653b2013-02-24 10:46:11 -070033{
34 UINT8 spdAddress;
Martin Roth3b2653b2013-02-24 10:46:11 -070035
Aaron Durbine4d7abc2017-04-16 22:05:36 -050036 DEVTREE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2));
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110037 if (dev == NULL)
Martin Roth3b2653b2013-02-24 10:46:11 -070038 return AGESA_ERROR;
39
Aaron Durbine4d7abc2017-04-16 22:05:36 -050040 DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110041 if (config == NULL)
42 return AGESA_ERROR;
43
Martin Roth3b2653b2013-02-24 10:46:11 -070044 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
45 return AGESA_ERROR;
46 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
47 return AGESA_ERROR;
48 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
49 return AGESA_ERROR;
50
51 spdAddress = config->spdAddrLookup
52 [info->SocketId][info->MemChannelId][info->DimmId];
53
54 if (spdAddress == 0)
55 return AGESA_ERROR;
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030056
57 int err = smbus_readSpd(spdAddress, (void *) info->Buffer, 128);
58 if (err)
59 return AGESA_ERROR;
60 return AGESA_SUCCESS;
Martin Roth3b2653b2013-02-24 10:46:11 -070061}