mrc.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* SPDX-License-Identifier: Intel */
  2. /*
  3. * Copyright (C) 2013, Intel Corporation
  4. * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
  5. *
  6. * Ported from Intel released Quark UEFI BIOS
  7. * QuarkSocPkg/QuarkNorthCluster/MemoryInit/Pei
  8. */
  9. #ifndef _MRC_H_
  10. #define _MRC_H_
  11. #define MRC_VERSION 0x0111
  12. /* architectural definitions */
  13. #define NUM_CHANNELS 1 /* number of channels */
  14. #define NUM_RANKS 2 /* number of ranks per channel */
  15. #define NUM_BYTE_LANES 4 /* number of byte lanes per channel */
  16. /* software limitations */
  17. #define MAX_CHANNELS 1
  18. #define MAX_RANKS 2
  19. #define MAX_BYTE_LANES 4
  20. #define MAX_SOCKETS 1
  21. #define MAX_SIDES 1
  22. #define MAX_ROWS (MAX_SIDES * MAX_SOCKETS)
  23. /* Specify DRAM and channel width */
  24. enum {
  25. X8, /* DRAM width */
  26. X16, /* DRAM width & Channel Width */
  27. X32 /* Channel Width */
  28. };
  29. /* Specify DRAM speed */
  30. enum {
  31. DDRFREQ_800,
  32. DDRFREQ_1066
  33. };
  34. /* Specify DRAM type */
  35. enum {
  36. DDR3,
  37. DDR3L
  38. };
  39. /*
  40. * density: 0=512Mb, 1=Gb, 2=2Gb, 3=4Gb
  41. * cl: DRAM CAS Latency in clocks
  42. * ras: ACT to PRE command period
  43. * wtr: Delay from start of internal write transaction to internal read command
  44. * rrd: ACT to ACT command period (JESD79 specific to page size 1K/2K)
  45. * faw: Four activate window (JESD79 specific to page size 1K/2K)
  46. *
  47. * ras/wtr/rrd/faw timings are in picoseconds
  48. *
  49. * Refer to JEDEC spec (or DRAM datasheet) when changing these values.
  50. */
  51. struct dram_params {
  52. uint8_t density;
  53. uint8_t cl;
  54. uint32_t ras;
  55. uint32_t wtr;
  56. uint32_t rrd;
  57. uint32_t faw;
  58. };
  59. /*
  60. * Delay configuration for individual signals
  61. * Vref setting
  62. * Scrambler seed
  63. */
  64. struct mrc_timings {
  65. uint32_t rcvn[NUM_CHANNELS][NUM_RANKS][NUM_BYTE_LANES];
  66. uint32_t rdqs[NUM_CHANNELS][NUM_RANKS][NUM_BYTE_LANES];
  67. uint32_t wdqs[NUM_CHANNELS][NUM_RANKS][NUM_BYTE_LANES];
  68. uint32_t wdq[NUM_CHANNELS][NUM_RANKS][NUM_BYTE_LANES];
  69. uint32_t vref[NUM_CHANNELS][NUM_BYTE_LANES];
  70. uint32_t wctl[NUM_CHANNELS][NUM_RANKS];
  71. uint32_t wcmd[NUM_CHANNELS];
  72. uint32_t scrambler_seed;
  73. /* need to save for the case of frequency change */
  74. uint8_t ddr_speed;
  75. };
  76. /* Boot mode defined as bit mask (1<<n) */
  77. enum {
  78. BM_UNKNOWN,
  79. BM_COLD = 1, /* full training */
  80. BM_FAST = 2, /* restore timing parameters */
  81. BM_S3 = 4, /* resume from S3 */
  82. BM_WARM = 8
  83. };
  84. /* MRC execution status */
  85. #define MRC_SUCCESS 0 /* initialization ok */
  86. #define MRC_E_MEMTEST 1 /* memtest failed */
  87. /*
  88. * Memory Reference Code parameters
  89. *
  90. * It includes 3 parts:
  91. * - input parameters like boot mode and DRAM parameters
  92. * - context parameters for MRC internal state
  93. * - output parameters like initialization result and memory size
  94. */
  95. struct mrc_params {
  96. /* Input parameters */
  97. uint32_t boot_mode; /* BM_COLD, BM_FAST, BM_WARM, BM_S3 */
  98. /* DRAM parameters */
  99. uint8_t dram_width; /* x8, x16 */
  100. uint8_t ddr_speed; /* DDRFREQ_800, DDRFREQ_1066 */
  101. uint8_t ddr_type; /* DDR3, DDR3L */
  102. uint8_t ecc_enables; /* 0, 1 (memory size reduced to 7/8) */
  103. uint8_t scrambling_enables; /* 0, 1 */
  104. /* 1, 3 (1'st rank has to be populated if 2'nd rank present) */
  105. uint32_t rank_enables;
  106. uint32_t channel_enables; /* 1 only */
  107. uint32_t channel_width; /* x16 only */
  108. /* 0, 1, 2 (mode 2 forced if ecc enabled) */
  109. uint32_t address_mode;
  110. /* REFRESH_RATE: 1=1.95us, 2=3.9us, 3=7.8us, others=RESERVED */
  111. uint8_t refresh_rate;
  112. /* SR_TEMP_RANGE: 0=normal, 1=extended, others=RESERVED */
  113. uint8_t sr_temp_range;
  114. /*
  115. * RON_VALUE: 0=34ohm, 1=40ohm, others=RESERVED
  116. * (select MRS1.DIC driver impedance control)
  117. */
  118. uint8_t ron_value;
  119. /* RTT_NOM_VALUE: 0=40ohm, 1=60ohm, 2=120ohm, others=RESERVED */
  120. uint8_t rtt_nom_value;
  121. /* RD_ODT_VALUE: 0=off, 1=60ohm, 2=120ohm, 3=180ohm, others=RESERVED */
  122. uint8_t rd_odt_value;
  123. struct dram_params params;
  124. /* Internally used context parameters */
  125. uint32_t board_id; /* board layout (use x8 or x16 memory) */
  126. uint32_t hte_setup; /* when set hte reconfiguration requested */
  127. uint32_t menu_after_mrc;
  128. uint32_t power_down_disable;
  129. uint32_t tune_rcvn;
  130. uint32_t channel_size[NUM_CHANNELS];
  131. uint32_t column_bits[NUM_CHANNELS];
  132. uint32_t row_bits[NUM_CHANNELS];
  133. uint32_t mrs1; /* register content saved during training */
  134. uint8_t first_run;
  135. /* Output parameters */
  136. /* initialization result (non zero specifies error code) */
  137. uint32_t status;
  138. /* total memory size in bytes (excludes ECC banks) */
  139. uint32_t mem_size;
  140. /* training results (also used on input) */
  141. struct mrc_timings timings;
  142. };
  143. /*
  144. * MRC memory initialization structure
  145. *
  146. * post_code: a 16-bit post code of a specific initialization routine
  147. * boot_path: bitwise or of BM_COLD, BM_FAST, BM_WARM and BM_S3
  148. * init_fn: real memory initialization routine
  149. */
  150. struct mem_init {
  151. uint16_t post_code;
  152. uint16_t boot_path;
  153. void (*init_fn)(struct mrc_params *mrc_params);
  154. };
  155. /* MRC platform data flags */
  156. #define MRC_FLAG_ECC_EN 0x00000001
  157. #define MRC_FLAG_SCRAMBLE_EN 0x00000002
  158. #define MRC_FLAG_MEMTEST_EN 0x00000004
  159. /* 0b DDR "fly-by" topology else 1b DDR "tree" topology */
  160. #define MRC_FLAG_TOP_TREE_EN 0x00000008
  161. /* If set ODR signal is asserted to DRAM devices on writes */
  162. #define MRC_FLAG_WR_ODT_EN 0x00000010
  163. /**
  164. * mrc_init - Memory Reference Code initialization entry routine
  165. *
  166. * @mrc_params: parameters for MRC
  167. */
  168. void mrc_init(struct mrc_params *mrc_params);
  169. #endif /* _MRC_H_ */