mrc_util.h 3.4 KB

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