Lee Leahy | c421041 | 2015-06-29 11:37:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * Copyright (C) 2015 Intel Corporation. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 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. |
Lee Leahy | c421041 | 2015-06-29 11:37:56 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/byteorder.h> |
| 18 | #include <cbfs.h> |
| 19 | #include <console/console.h> |
Lee Leahy | c421041 | 2015-06-29 11:37:56 -0700 | [diff] [blame] | 20 | #include <soc/pei_data.h> |
| 21 | #include <soc/romstage.h> |
Duncan Laurie | 74b964e | 2015-09-04 10:41:02 -0700 | [diff] [blame] | 22 | #include <string.h> |
| 23 | |
Duncan Laurie | 74b964e | 2015-09-04 10:41:02 -0700 | [diff] [blame] | 24 | #include "spd.h" |
Lee Leahy | c421041 | 2015-06-29 11:37:56 -0700 | [diff] [blame] | 25 | |
| 26 | static void mainboard_print_spd_info(uint8_t spd[]) |
| 27 | { |
| 28 | const int spd_banks[8] = { 8, 16, 32, 64, -1, -1, -1, -1 }; |
| 29 | const int spd_capmb[8] = { 1, 2, 4, 8, 16, 32, 64, 0 }; |
| 30 | const int spd_rows[8] = { 12, 13, 14, 15, 16, -1, -1, -1 }; |
| 31 | const int spd_cols[8] = { 9, 10, 11, 12, -1, -1, -1, -1 }; |
| 32 | const int spd_ranks[8] = { 1, 2, 3, 4, -1, -1, -1, -1 }; |
| 33 | const int spd_devw[8] = { 4, 8, 16, 32, -1, -1, -1, -1 }; |
| 34 | const int spd_busw[8] = { 8, 16, 32, 64, -1, -1, -1, -1 }; |
| 35 | char spd_name[SPD_PART_LEN+1] = { 0 }; |
| 36 | |
| 37 | int banks = spd_banks[(spd[SPD_DENSITY_BANKS] >> 4) & 7]; |
| 38 | int capmb = spd_capmb[spd[SPD_DENSITY_BANKS] & 7] * 256; |
| 39 | int rows = spd_rows[(spd[SPD_ADDRESSING] >> 3) & 7]; |
| 40 | int cols = spd_cols[spd[SPD_ADDRESSING] & 7]; |
| 41 | int ranks = spd_ranks[(spd[SPD_ORGANIZATION] >> 3) & 7]; |
| 42 | int devw = spd_devw[spd[SPD_ORGANIZATION] & 7]; |
| 43 | int busw = spd_busw[spd[SPD_BUS_DEV_WIDTH] & 7]; |
| 44 | |
| 45 | /* Module type */ |
| 46 | printk(BIOS_INFO, "SPD: module type is "); |
| 47 | switch (spd[SPD_DRAM_TYPE]) { |
| 48 | case SPD_DRAM_DDR3: |
| 49 | printk(BIOS_INFO, "DDR3\n"); |
| 50 | break; |
| 51 | case SPD_DRAM_LPDDR3: |
| 52 | printk(BIOS_INFO, "LPDDR3\n"); |
| 53 | break; |
| 54 | default: |
| 55 | printk(BIOS_INFO, "Unknown (%02x)\n", spd[SPD_DRAM_TYPE]); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | /* Module Part Number */ |
| 60 | memcpy(spd_name, &spd[SPD_PART_OFF], SPD_PART_LEN); |
| 61 | spd_name[SPD_PART_LEN] = 0; |
| 62 | printk(BIOS_INFO, "SPD: module part is %s\n", spd_name); |
| 63 | |
| 64 | printk(BIOS_INFO, |
| 65 | "SPD: banks %d, ranks %d, rows %d, columns %d, density %d Mb\n", |
| 66 | banks, ranks, rows, cols, capmb); |
| 67 | printk(BIOS_INFO, "SPD: device width %d bits, bus width %d bits\n", |
| 68 | devw, busw); |
| 69 | |
| 70 | if (capmb > 0 && busw > 0 && devw > 0 && ranks > 0) { |
| 71 | /* SIZE = DENSITY / 8 * BUS_WIDTH / SDRAM_WIDTH * RANKS */ |
| 72 | printk(BIOS_INFO, "SPD: module size is %u MB (per channel)\n", |
| 73 | capmb / 8 * busw / devw * ranks); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /* Copy SPD data for on-board memory */ |
| 78 | void mainboard_fill_spd_data(struct pei_data *pei_data) |
| 79 | { |
Rizwan Qureshi | 5ff7390 | 2016-08-24 20:50:54 +0530 | [diff] [blame] | 80 | uintptr_t spd_data; |
| 81 | spd_data = mainboard_get_spd_data(); |
pchandri | 415022a | 2015-08-14 12:18:31 -0700 | [diff] [blame] | 82 | |
Rizwan Qureshi | 5ff7390 | 2016-08-24 20:50:54 +0530 | [diff] [blame] | 83 | memcpy(pei_data->spd_data[0][0], (void *)spd_data, SPD_LEN); |
pchandri | 415022a | 2015-08-14 12:18:31 -0700 | [diff] [blame] | 84 | |
Rizwan Qureshi | 5ff7390 | 2016-08-24 20:50:54 +0530 | [diff] [blame] | 85 | if (mainboard_has_dual_channel_mem()) |
| 86 | memcpy(pei_data->spd_data[1][0], (void *)spd_data, SPD_LEN); |
Lee Leahy | c421041 | 2015-06-29 11:37:56 -0700 | [diff] [blame] | 87 | |
| 88 | /* Make sure a valid SPD was found */ |
| 89 | if (pei_data->spd_data[0][0][0] == 0) |
| 90 | die("Invalid SPD data."); |
| 91 | |
| 92 | mainboard_print_spd_info(pei_data->spd_data[0][0]); |
| 93 | } |