Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 4 | * |
| 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 Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <device/pci_def.h> |
| 16 | #include <device/device.h> |
| 17 | |
| 18 | /* warning: Porting.h includes an open #pragma pack(1) */ |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 19 | #include <Porting.h> |
| 20 | #include <AGESA.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 21 | #include "chip.h" |
| 22 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 23 | #include <northbridge/amd/agesa/dimmSpd.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 24 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 25 | /** |
| 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 Reinauer | 8d29dd1 | 2017-06-26 14:30:39 -0700 | [diff] [blame] | 29 | AGESA_STATUS AmdMemoryReadSPD (UINT32 unused1, UINTN unused2, AGESA_READ_SPD_PARAMS *info) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 30 | { |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 31 | UINT8 spdAddress; |
| 32 | |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 33 | DEVTREE_CONST struct device *dev = pcidev_on_root(0x18, 2); |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 34 | if (dev == NULL) |
| 35 | return AGESA_ERROR; |
| 36 | |
Aaron Durbin | e4d7abc | 2017-04-16 22:05:36 -0500 | [diff] [blame] | 37 | DEVTREE_CONST struct northbridge_amd_agesa_family16kb_config *config = dev->chip_info; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 38 | if (config == NULL) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 39 | return AGESA_ERROR; |
| 40 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 41 | if (info->SocketId >= ARRAY_SIZE(config->spdAddrLookup)) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 42 | return AGESA_ERROR; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 43 | if (info->MemChannelId >= ARRAY_SIZE(config->spdAddrLookup[0])) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 44 | return AGESA_ERROR; |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 45 | if (info->DimmId >= ARRAY_SIZE(config->spdAddrLookup[0][0])) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 46 | return AGESA_ERROR; |
| 47 | |
| 48 | spdAddress = config->spdAddrLookup |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 49 | [info->SocketId][info->MemChannelId][info->DimmId]; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 50 | |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 51 | 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 Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 58 | } |