Alexandru Gagniuc | f97ff3f | 2013-05-21 14:43:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com> |
| 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, either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef DEVICE_DRAM_DDR3L_H |
| 21 | #define DEVICE_DRAM_DDR3L_H |
| 22 | |
| 23 | /** |
| 24 | * @file ddr3.h |
| 25 | * |
| 26 | * \brief Utilities for decoding DDR3 SPDs |
| 27 | */ |
| 28 | |
| 29 | #include <stdint.h> |
| 30 | #include <spd.h> |
| 31 | |
| 32 | /** |
| 33 | * \brief Convenience definitions for TCK values |
| 34 | * |
| 35 | * Different values for tCK, representing standard DDR3 frequencies. |
| 36 | * These values are in 1/256 ns units. |
| 37 | * @{ |
| 38 | */ |
| 39 | #define TCK_1066MHZ 240 |
| 40 | #define TCK_800MHZ 320 |
| 41 | #define TCK_666MHZ 384 |
| 42 | #define TCK_533MHZ 480 |
| 43 | #define TCK_400MHZ 640 |
| 44 | #define TCK_333MHZ 768 |
| 45 | #define TCK_266MHZ 960 |
| 46 | #define TCK_200MHZ 1280 |
| 47 | /** @} */ |
| 48 | |
| 49 | /** |
| 50 | * \brief Convenience macro for enabling printk with CONFIG_DEBUG_RAM_SETUP |
| 51 | * |
| 52 | * Use this macro instead of printk(); for verbose RAM initialization messages. |
| 53 | * When CONFIG_DEBUG_RAM_SETUP is not selected, these messages are automatically |
| 54 | * disabled. |
| 55 | * @{ |
| 56 | */ |
| 57 | #if defined(CONFIG_DEBUG_RAM_SETUP) && (CONFIG_DEBUG_RAM_SETUP) |
| 58 | #define printram(x, ...) printk(BIOS_DEBUG, x, ##__VA_ARGS__) |
| 59 | #else |
| 60 | #define printram(x, ...) |
| 61 | #endif |
| 62 | /** @} */ |
| 63 | |
| 64 | /* |
| 65 | * Module type (byte 3, bits 3:0) of SPD |
| 66 | * This definition is specific to DDR3. DDR2 SPDs have a diferent structure. |
| 67 | */ |
| 68 | enum spd_dimm_type { |
| 69 | SPD_DIMM_TYPE_UNDEFINED = 0x00, |
| 70 | SPD_DIMM_TYPE_RDIMM = 0x01, |
| 71 | SPD_DIMM_TYPE_UDIMM = 0x02, |
| 72 | SPD_DIMM_TYPE_SO_DIMM = 0x03, |
| 73 | SPD_DIMM_TYPE_MICRO_DIMM = 0x04, |
| 74 | SPD_DIMM_TYPE_MINI_RDIMM = 0x05, |
| 75 | SPD_DIMM_TYPE_MINI_UDIMM = 0x06, |
| 76 | SPD_DIMM_TYPE_MINI_CDIMM = 0x07, |
| 77 | SPD_DIMM_TYPE_72B_SO_UDIMM = 0x08, |
| 78 | SPD_DIMM_TYPE_72B_SO_RDIMM = 0x09, |
| 79 | SPD_DIMM_TYPE_72B_SO_CDIMM = 0x0a, |
| 80 | SPD_DIMM_TYPE_LRDIMM = 0x0b, |
| 81 | SPD_DIMM_TYPE_16B_SO_DIMM = 0x0d, |
| 82 | SPD_DIMM_TYPE_32B_SO_DIMM = 0x0e, |
| 83 | /* Masks to bits 3:0 to give the dimm type */ |
| 84 | SPD_DIMM_TYPE_MASK = 0x0f, |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * \brief DIMM flags |
| 89 | * |
| 90 | * Characteristic flags for the DIMM, as presented by the SPD |
| 91 | */ |
| 92 | typedef union dimm_flags_st { |
| 93 | /* The whole point of the union/struct construct is to allow us to clear |
| 94 | * all the bits with one line: flags.raw = 0. |
| 95 | * We do not care how these bits are ordered */ |
| 96 | struct { |
| 97 | /* Indicates if rank 1 of DIMM uses a mirrored pin mapping. See: |
| 98 | * Annex K: Serial Presence Detect (SPD) for DDR3 SDRAM */ |
| 99 | unsigned pins_mirrored:1; |
| 100 | /* Module can work at 1.50V - All DIMMS must be 1.5V operable */ |
| 101 | unsigned operable_1_50V:1; |
| 102 | /* Module can work at 1.35V */ |
| 103 | unsigned operable_1_35V:1; |
| 104 | /* Module can work at 1.20V */ |
| 105 | unsigned operable_1_25V:1; |
| 106 | /* Has an 8-bit bus extension, meaning the DIMM supports ECC */ |
| 107 | unsigned is_ecc:1; |
| 108 | /* DLL-Off Mode Support */ |
| 109 | unsigned dll_off_mode:1; |
| 110 | /* Indicates a drive strength of RZQ/6 (40 Ohm) is supported */ |
| 111 | unsigned rzq6_supported:1; |
| 112 | /* Indicates a drive strength of RZQ/7 (35 Ohm) is supported */ |
| 113 | unsigned rzq7_supported:1; |
| 114 | /* Partial Array Self Refresh */ |
| 115 | unsigned pasr:1; |
| 116 | /* On-die Thermal Sensor Readout */ |
| 117 | unsigned odts:1; |
| 118 | /* Auto Self Refresh */ |
| 119 | unsigned asr:1; |
| 120 | /* Extended temperature range supported */ |
| 121 | unsigned ext_temp_range:1; |
| 122 | /* Operating at extended temperature requires 2X refresh rate */ |
| 123 | unsigned ext_temp_refresh:1; |
| 124 | /* Thermal sensor incorporated */ |
| 125 | unsigned therm_sensor:1; |
| 126 | }; |
| 127 | unsigned raw; |
| 128 | } dimm_flags_t; |
| 129 | |
| 130 | /** |
| 131 | * \brief DIMM characteristics |
| 132 | * |
| 133 | * The characteristics of each DIMM, as presented by the SPD |
| 134 | */ |
| 135 | typedef struct dimm_attr_st { |
| 136 | enum spd_memory_type dram_type; |
| 137 | u16 cas_supported; |
| 138 | /* Flags extracted from SPD */ |
| 139 | dimm_flags_t flags; |
| 140 | /* Number of ranks */ |
| 141 | u8 ranks; |
| 142 | /* Number or row address bits */ |
| 143 | u8 row_bits; |
| 144 | /* Number or column address bits */ |
| 145 | u8 col_bits; |
| 146 | /* Size of module in MiB */ |
| 147 | u32 size_mb; |
| 148 | /* Latencies are in units of 1/256 ns */ |
| 149 | u32 tCK; |
| 150 | u32 tAA; |
| 151 | u32 tWR; |
| 152 | u32 tRCD; |
| 153 | u32 tRRD; |
| 154 | u32 tRP; |
| 155 | u32 tRAS; |
| 156 | u32 tRC; |
| 157 | u32 tRFC; |
| 158 | u32 tWTR; |
| 159 | u32 tRTP; |
| 160 | u32 tFAW; |
| 161 | } dimm_attr; |
| 162 | |
| 163 | /** Result of the SPD decoding process */ |
| 164 | enum spd_status { |
| 165 | SPD_STATUS_OK = 0, |
| 166 | SPD_STATUS_INVALID, |
| 167 | SPD_STATUS_CRC_ERROR, |
| 168 | SPD_STATUS_INVALID_FIELD, |
| 169 | }; |
| 170 | |
| 171 | typedef u8 spd_raw_data[256]; |
| 172 | |
| 173 | int spd_decode_ddr3(dimm_attr * dimm, spd_raw_data spd_data); |
| 174 | int dimm_is_registered(enum spd_dimm_type type); |
| 175 | void dram_print_spd_ddr3(const dimm_attr * dimm); |
| 176 | |
| 177 | /** |
| 178 | * \brief Read double word from specified address |
| 179 | * |
| 180 | * Should be useful when doing an MRS to the DIMM |
| 181 | */ |
| 182 | static inline u32 volatile_read(volatile u32 addr) |
| 183 | { |
| 184 | volatile u32 result; |
| 185 | result = *(volatile u32 *)addr; |
| 186 | return result; |
| 187 | } |
| 188 | |
| 189 | #endif /* DEVICE_DRAM_DDR3_H */ |