Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Marc Jones | afd03d8 | 2017-11-16 10:01:08 -0700 | [diff] [blame] | 4 | * Copyright (C) 2012, 2017 Advanced Micro Devices, Inc. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 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. |
| 14 | */ |
| 15 | |
Richard Spiegel | 0ad74ac | 2017-12-08 16:53:29 -0700 | [diff] [blame] | 16 | #include <amdblocks/agesawrapper.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 17 | #include <console/console.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 18 | #include <device/pci_def.h> |
| 19 | #include <device/device.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 20 | #include <soc/southbridge.h> |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 21 | #include <soc/smbus.h> |
Marc Jones | afd03d8 | 2017-11-16 10:01:08 -0700 | [diff] [blame] | 22 | #include <amdblocks/dimm_spd.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 23 | |
Richard Spiegel | c5ecd3e | 2017-09-29 10:05:35 -0700 | [diff] [blame] | 24 | /* |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 25 | * readspd - Read one or more SPD bytes from a DIMM. |
| 26 | * Start with offset zero and read sequentially. |
| 27 | * Optimization relies on autoincrement to avoid |
| 28 | * sending offset for every byte. |
| 29 | * Reads 128 bytes in 7-8 ms at 400 KHz. |
| 30 | */ |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 31 | static int readspd(uint8_t SmbusSlaveAddress, char *buffer, size_t count) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 32 | { |
Richard Spiegel | 77fee09 | 2017-11-10 08:33:57 -0700 | [diff] [blame] | 33 | uint8_t dev_addr; |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 34 | size_t index; |
| 35 | int error; |
| 36 | char *pbuf = buffer; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 37 | |
| 38 | printk(BIOS_SPEW, "-------------READING SPD-----------\n"); |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 39 | printk(BIOS_SPEW, "SmbusSlave: 0x%08X, count: %zd\n", |
| 40 | SmbusSlaveAddress, count); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 41 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 42 | /* |
| 43 | * Convert received device address to the format accepted by |
| 44 | * do_smbus_read_byte and do_smbus_recv_byte. |
| 45 | */ |
| 46 | dev_addr = (SmbusSlaveAddress >> 1); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 47 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 48 | /* Read the first SPD byte */ |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 49 | error = do_smbus_read_byte(SMBUS_MMIO_BASE, dev_addr, 0); |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 50 | if (error < 0) { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 51 | printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 52 | return error; |
| 53 | } |
Richard Spiegel | d46bb6b | 2018-10-16 13:44:03 -0700 | [diff] [blame] | 54 | *pbuf = (char) error; |
| 55 | pbuf++; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 56 | |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 57 | /* Read the remaining SPD bytes using do_smbus_recv_byte for speed */ |
| 58 | for (index = 1 ; index < count ; index++) { |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 59 | error = do_smbus_recv_byte(SMBUS_MMIO_BASE, dev_addr); |
Richard Spiegel | cd04e31 | 2017-11-08 14:58:30 -0700 | [diff] [blame] | 60 | if (error < 0) { |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 61 | printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); |
| 62 | return error; |
| 63 | } |
Richard Spiegel | d46bb6b | 2018-10-16 13:44:03 -0700 | [diff] [blame] | 64 | *pbuf = (char) error; |
| 65 | pbuf++; |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 66 | } |
| 67 | printk(BIOS_SPEW, "\n"); |
| 68 | printk(BIOS_SPEW, "-------------FINISHED READING SPD-----------\n"); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Marc Jones | afd03d8 | 2017-11-16 10:01:08 -0700 | [diff] [blame] | 73 | int sb_read_spd(uint8_t spdAddress, char *buf, size_t len) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 74 | { |
Richard Spiegel | b40e193 | 2018-10-24 12:51:21 -0700 | [diff] [blame] | 75 | return readspd(spdAddress, buf, len); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 76 | } |