agilex5_iossm_mailbox.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2024, Altera Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef AGILEX5_IOSSM_MAILBOX_H
  7. #define AGILEX5_IOSSM_MAILBOX_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. #include <stdlib.h>
  11. #include "lib/mmio.h"
  12. #include "agilex5_ddr.h"
  13. #define TIMEOUT_5000MS 5000
  14. #define TIMEOUT TIMEOUT_5000MS
  15. #define IOSSM_STATUS_CAL_SUCCESS BIT(0)
  16. #define IOSSM_STATUS_CAL_FAIL BIT(1)
  17. #define IOSSM_STATUS_CAL_BUSY BIT(2)
  18. #define IOSSM_STATUS_COMMAND_RESPONSE_READY 1
  19. #define IOSSM_CMD_RESPONSE_STATUS_OFFSET 0x45C
  20. #define IOSSM_CMD_RESPONSE_DATA_0_OFFSET 0x458
  21. #define IOSSM_CMD_RESPONSE_DATA_1_OFFSET 0x454
  22. #define IOSSM_CMD_RESPONSE_DATA_2_OFFSET 0x450
  23. #define IOSSM_CMD_REQ_OFFSET 0x43C
  24. #define IOSSM_CMD_PARAM_0_OFFSET 0x438
  25. #define IOSSM_CMD_PARAM_1_OFFSET 0x434
  26. #define IOSSM_CMD_PARAM_2_OFFSET 0x430
  27. #define IOSSM_CMD_PARAM_3_OFFSET 0x42C
  28. #define IOSSM_CMD_PARAM_4_OFFSET 0x428
  29. #define IOSSM_CMD_PARAM_5_OFFSET 0x424
  30. #define IOSSM_CMD_PARAM_6_OFFSET 0x420
  31. #define IOSSM_STATUS_OFFSET 0x400
  32. #define IOSSM_CMD_RESPONSE_DATA_SHORT_MASK GENMASK(31, 16)
  33. #define IOSSM_CMD_RESPONSE_DATA_SHORT(data) (((data) & \
  34. IOSSM_CMD_RESPONSE_DATA_SHORT_MASK) >> 16)
  35. #define MAX_IO96B_SUPPORTED 2
  36. #define MAX_MEM_INTERFACES_SUPPORTED 2
  37. /* supported mailbox command type */
  38. enum iossm_mailbox_cmd_type {
  39. CMD_NOP,
  40. CMD_GET_SYS_INFO,
  41. CMD_GET_MEM_INFO,
  42. CMD_GET_MEM_CAL_INFO,
  43. CMD_TRIG_CONTROLLER_OP,
  44. CMD_TRIG_MEM_CAL_OP
  45. };
  46. /* supported mailbox command opcode */
  47. enum iossm_mailbox_cmd_opcode {
  48. GET_MEM_INTF_INFO = 0x0001,
  49. GET_MEM_TECHNOLOGY,
  50. GET_MEMCLK_FREQ_KHZ,
  51. GET_MEM_WIDTH_INFO,
  52. ECC_ENABLE_SET = 0x0101,
  53. ECC_ENABLE_STATUS,
  54. ECC_INTERRUPT_STATUS,
  55. ECC_INTERRUPT_ACK,
  56. ECC_INTERRUPT_MASK,
  57. ECC_WRITEBACK_ENABLE,
  58. ECC_SCRUB_IN_PROGRESS_STATUS = 0x0201,
  59. ECC_SCRUB_MODE_0_START,
  60. ECC_SCRUB_MODE_1_START,
  61. BIST_STANDARD_MODE_START = 0x0301,
  62. BIST_RESULTS_STATUS,
  63. BIST_MEM_INIT_START,
  64. BIST_MEM_INIT_STATUS,
  65. BIST_SET_DATA_PATTERN_UPPER,
  66. BIST_SET_DATA_PATTERN_LOWER,
  67. TRIG_MEM_CAL = 0x000a,
  68. GET_MEM_CAL_STATUS
  69. };
  70. /*
  71. * IOSSM mailbox required information
  72. *
  73. * @num_mem_interface: Number of memory interfaces instantiated
  74. * @ip_type: IP type implemented on the IO96B
  75. * @ip_instance_id: IP identifier for every IP instance implemented on the IO96B
  76. */
  77. struct io96b_mb_ctrl {
  78. uint32_t num_mem_interface;
  79. uint32_t ip_type[2];
  80. uint32_t ip_instance_id[2];
  81. };
  82. /*
  83. * IOSSM mailbox response outputs
  84. *
  85. * @cmd_resp_status: Command Interface status
  86. * @cmd_resp_data_*: More spaces for command response
  87. */
  88. struct io96b_mb_resp {
  89. uint32_t cmd_resp_status;
  90. uint32_t cmd_resp_data_0;
  91. uint32_t cmd_resp_data_1;
  92. uint32_t cmd_resp_data_2;
  93. };
  94. /*
  95. * IO96B instance specific information
  96. *
  97. * @size: Memory size
  98. * @io96b_csr_addr: IO96B instance CSR address
  99. * @cal_status: IO96B instance calibration status
  100. * @mb_ctrl: IOSSM mailbox required information
  101. */
  102. struct io96b_instance {
  103. uint16_t size;
  104. phys_addr_t io96b_csr_addr;
  105. bool cal_status;
  106. struct io96b_mb_ctrl mb_ctrl;
  107. };
  108. /*
  109. * Overall IO96B instance(s) information
  110. *
  111. * @num_instance: Number of instance(s) assigned to HPS
  112. * @overall_cal_status: Overall calibration status for all IO96B instance(s)
  113. * @ddr_type: DDR memory type
  114. * @ecc_status: ECC enable status (false = disabled, true = enabled)
  115. * @overall_size: Total DDR memory size
  116. * @io96b_0: IO96B 0 instance specific information
  117. * @io96b_1: IO96B 1 instance specific information
  118. */
  119. struct io96b_info {
  120. uint8_t num_instance;
  121. bool overall_cal_status;
  122. const char *ddr_type;
  123. bool ecc_status;
  124. uint16_t overall_size;
  125. struct io96b_instance io96b_0;
  126. struct io96b_instance io96b_1;
  127. };
  128. int io96b_mb_req(phys_addr_t io96b_csr_addr, uint32_t ip_type, uint32_t instance_id,
  129. uint32_t usr_cmd_type, uint32_t usr_cmd_opcode, uint32_t cmd_param_0,
  130. uint32_t cmd_param_1, uint32_t cmd_param_2, uint32_t cmd_param_3,
  131. uint32_t cmd_param_4, uint32_t cmd_param_5, uint32_t cmd_param_6,
  132. uint32_t resp_data_len, struct io96b_mb_resp *resp);
  133. /* Supported IOSSM mailbox function */
  134. void io96b_mb_init(struct io96b_info *io96b_ctrl);
  135. int io96b_cal_status(phys_addr_t addr);
  136. void init_mem_cal(struct io96b_info *io96b_ctrl);
  137. int trig_mem_cal(struct io96b_info *io96b_ctrl);
  138. int get_mem_technology(struct io96b_info *io96b_ctrl);
  139. int get_mem_width_info(struct io96b_info *io96b_ctrl);
  140. int ecc_enable_status(struct io96b_info *io96b_ctrl);
  141. int bist_mem_init_start(struct io96b_info *io96b_ctrl);
  142. #endif /* AGILEX5_IOSSM_MAILBOX_H */