mrc_util.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_UTIL_H_
  11. #define _MRC_UTIL_H_
  12. /* Turn on this macro to enable MRC debugging output */
  13. #undef MRC_DEBUG
  14. /* MRC Debug Support */
  15. #define DPF debug_cond
  16. /* debug print type */
  17. #ifdef MRC_DEBUG
  18. #define D_ERROR 0x0001
  19. #define D_INFO 0x0002
  20. #define D_REGRD 0x0004
  21. #define D_REGWR 0x0008
  22. #define D_FCALL 0x0010
  23. #define D_TRN 0x0020
  24. #define D_TIME 0x0040
  25. #else
  26. #define D_ERROR 0
  27. #define D_INFO 0
  28. #define D_REGRD 0
  29. #define D_REGWR 0
  30. #define D_FCALL 0
  31. #define D_TRN 0
  32. #define D_TIME 0
  33. #endif
  34. #define ENTERFN(...) debug_cond(D_FCALL, "<%s>\n", __func__)
  35. #define LEAVEFN(...) debug_cond(D_FCALL, "</%s>\n", __func__)
  36. #define REPORTFN(...) debug_cond(D_FCALL, "<%s/>\n", __func__)
  37. /* Message Bus Port */
  38. #define MEM_CTLR 0x01
  39. #define HOST_BRIDGE 0x03
  40. #define MEM_MGR 0x05
  41. #define HTE 0x11
  42. #define DDRPHY 0x12
  43. /* number of sample points */
  44. #define SAMPLE_CNT 3
  45. /* number of PIs to increment per sample */
  46. #define SAMPLE_DLY 26
  47. enum {
  48. /* indicates to decrease delays when looking for edge */
  49. BACKWARD,
  50. /* indicates to increase delays when looking for edge */
  51. FORWARD
  52. };
  53. enum {
  54. RCVN,
  55. WDQS,
  56. WDQX,
  57. RDQS,
  58. VREF,
  59. WCMD,
  60. WCTL,
  61. WCLK,
  62. MAX_ALGOS,
  63. };
  64. void mrc_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
  65. void mrc_alt_write_mask(u32 unit, u32 addr, u32 data, u32 mask);
  66. void mrc_post_code(uint8_t major, uint8_t minor);
  67. void delay_n(uint32_t ns);
  68. void delay_u(uint32_t ms);
  69. void select_mem_mgr(void);
  70. void select_hte(void);
  71. void dram_init_command(uint32_t data);
  72. void dram_wake_command(void);
  73. void training_message(uint8_t channel, uint8_t rank, uint8_t byte_lane);
  74. void set_rcvn(uint8_t channel, uint8_t rank,
  75. uint8_t byte_lane, uint32_t pi_count);
  76. uint32_t get_rcvn(uint8_t channel, uint8_t rank, uint8_t byte_lane);
  77. void set_rdqs(uint8_t channel, uint8_t rank,
  78. uint8_t byte_lane, uint32_t pi_count);
  79. uint32_t get_rdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
  80. void set_wdqs(uint8_t channel, uint8_t rank,
  81. uint8_t byte_lane, uint32_t pi_count);
  82. uint32_t get_wdqs(uint8_t channel, uint8_t rank, uint8_t byte_lane);
  83. void set_wdq(uint8_t channel, uint8_t rank,
  84. uint8_t byte_lane, uint32_t pi_count);
  85. uint32_t get_wdq(uint8_t channel, uint8_t rank, uint8_t byte_lane);
  86. void set_wcmd(uint8_t channel, uint32_t pi_count);
  87. uint32_t get_wcmd(uint8_t channel);
  88. void set_wclk(uint8_t channel, uint8_t rank, uint32_t pi_count);
  89. uint32_t get_wclk(uint8_t channel, uint8_t rank);
  90. void set_wctl(uint8_t channel, uint8_t rank, uint32_t pi_count);
  91. uint32_t get_wctl(uint8_t channel, uint8_t rank);
  92. void set_vref(uint8_t channel, uint8_t byte_lane, uint32_t setting);
  93. uint32_t get_vref(uint8_t channel, uint8_t byte_lane);
  94. uint32_t get_addr(uint8_t channel, uint8_t rank);
  95. uint32_t sample_dqs(struct mrc_params *mrc_params, uint8_t channel,
  96. uint8_t rank, bool rcvn);
  97. void find_rising_edge(struct mrc_params *mrc_params, uint32_t delay[],
  98. uint8_t channel, uint8_t rank, bool rcvn);
  99. uint32_t byte_lane_mask(struct mrc_params *mrc_params);
  100. uint32_t check_rw_coarse(struct mrc_params *mrc_params, uint32_t address);
  101. uint32_t check_bls_ex(struct mrc_params *mrc_params, uint32_t address);
  102. void lfsr32(uint32_t *lfsr_ptr);
  103. void clear_pointers(void);
  104. void print_timings(struct mrc_params *mrc_params);
  105. #endif /* _MRC_UTIL_H_ */