mrc.h 5.2 KB

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