blob: d992414bb5a9e78eebac53151b546b867e39e058 [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>
19#include "OEM.h" /* SMBUS0_BASE_ADDRESS */
20
21/* warning: Porting.h includes an open #pragma pack(1) */
22#include "Porting.h"
23#include "AGESA.h"
24#include "amdlib.h"
Martin Roth3b2653b2013-02-24 10:46:11 -070025#include "chip.h"
26
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030027#include <northbridge/amd/agesa/dimmSpd.h>
28
Martin Roth3b2653b2013-02-24 10:46:11 -070029/**
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110030 * Gets the SMBus address for an SPD from the array in devicetree.cb
Martin Roth3b2653b2013-02-24 10:46:11 -070031 * then read the SPD into the supplied buffer.
32 */
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030033AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINT32 unused2, AGESA_READ_SPD_PARAMS *info)
Martin Roth3b2653b2013-02-24 10:46:11 -070034{
35 UINT8 spdAddress;
Martin Roth3b2653b2013-02-24 10:46:11 -070036
Aaron Durbine4d7abc2017-04-16 22:05:36 -050037 DEVTREE_CONST struct device *dev = dev_find_slot(0, PCI_DEVFN(0x18, 2));
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110038 if (dev == NULL)
Martin Roth3b2653b2013-02-24 10:46:11 -070039 return AGESA_ERROR;
40
Aaron Durbine4d7abc2017-04-16 22:05:36 -050041 DEVTREE_CONST struct northbridge_amd_agesa_family14_config *config = dev->chip_info;
Edward O'Callaghanae5fd342014-11-20 19:58:09 +110042 if (config == NULL)
43 return AGESA_ERROR;
44
Martin Roth3b2653b2013-02-24 10:46:11 -070045 if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup))
46 return AGESA_ERROR;
47 if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0]))
48 return AGESA_ERROR;
49 if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0]))
50 return AGESA_ERROR;
51
52 spdAddress = config->spdAddrLookup
53 [info->SocketId][info->MemChannelId][info->DimmId];
54
55 if (spdAddress == 0)
56 return AGESA_ERROR;
Kyösti Mälkkia1ebbc42014-10-17 22:33:22 +030057
58 int err = smbus_readSpd(spdAddress, (void *) info->Buffer, 128);
59 if (err)
60 return AGESA_ERROR;
61 return AGESA_SUCCESS;
Martin Roth3b2653b2013-02-24 10:46:11 -070062}