aie2_solver.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2023-2024, Advanced Micro Devices, Inc.
  4. */
  5. #ifndef _AIE2_SOLVER_H
  6. #define _AIE2_SOLVER_H
  7. #define XRS_MAX_COL 128
  8. /*
  9. * Structure used to describe a partition. A partition is column based
  10. * allocation unit described by its start column and number of columns.
  11. */
  12. struct aie_part {
  13. u32 start_col;
  14. u32 ncols;
  15. };
  16. /*
  17. * The QoS capabilities of a given AIE partition.
  18. */
  19. struct aie_qos_cap {
  20. u32 opc; /* operations per cycle */
  21. u32 dma_bw; /* DMA bandwidth */
  22. };
  23. /*
  24. * QoS requirement of a resource allocation.
  25. */
  26. struct aie_qos {
  27. u32 gops; /* Giga operations */
  28. u32 fps; /* Frames per second */
  29. u32 dma_bw; /* DMA bandwidth */
  30. u32 latency; /* Frame response latency */
  31. u32 exec_time; /* Frame execution time */
  32. u32 priority; /* Request priority */
  33. };
  34. /*
  35. * Structure used to describe a relocatable CDO (Configuration Data Object).
  36. */
  37. struct cdo_parts {
  38. u32 *start_cols; /* Start column array */
  39. u32 cols_len; /* Length of start column array */
  40. u32 ncols; /* # of column */
  41. struct aie_qos_cap qos_cap; /* CDO QoS capabilities */
  42. };
  43. /*
  44. * Structure used to describe a request to allocate.
  45. */
  46. struct alloc_requests {
  47. u64 rid;
  48. struct cdo_parts cdo;
  49. struct aie_qos rqos; /* Requested QoS */
  50. };
  51. /*
  52. * Load callback argument
  53. */
  54. struct xrs_action_load {
  55. u32 rid;
  56. struct aie_part part;
  57. };
  58. /*
  59. * Define the power level available
  60. *
  61. * POWER_LEVEL_MIN:
  62. * Lowest power level. Usually set when all actions are unloaded.
  63. *
  64. * POWER_LEVEL_n
  65. * Power levels 0 - n, is a step increase in system frequencies
  66. */
  67. enum power_level {
  68. POWER_LEVEL_MIN = 0x0,
  69. POWER_LEVEL_0 = 0x1,
  70. POWER_LEVEL_1 = 0x2,
  71. POWER_LEVEL_2 = 0x3,
  72. POWER_LEVEL_3 = 0x4,
  73. POWER_LEVEL_4 = 0x5,
  74. POWER_LEVEL_5 = 0x6,
  75. POWER_LEVEL_6 = 0x7,
  76. POWER_LEVEL_7 = 0x8,
  77. POWER_LEVEL_NUM,
  78. };
  79. /*
  80. * Structure used to describe the frequency table.
  81. * Resource solver chooses the frequency from the table
  82. * to meet the QOS requirements.
  83. */
  84. struct clk_list_info {
  85. u32 num_levels; /* available power levels */
  86. u32 cu_clk_list[POWER_LEVEL_NUM]; /* available aie clock frequencies in Mhz*/
  87. };
  88. struct xrs_action_ops {
  89. int (*load)(void *cb_arg, struct xrs_action_load *action);
  90. int (*unload)(void *cb_arg);
  91. int (*set_dft_dpm_level)(struct drm_device *ddev, u32 level);
  92. };
  93. /*
  94. * Structure used to describe information for solver during initialization.
  95. */
  96. struct init_config {
  97. u32 total_col;
  98. u32 sys_eff_factor; /* system efficiency factor */
  99. u32 latency_adj; /* latency adjustment in ms */
  100. struct clk_list_info clk_list; /* List of frequencies available in system */
  101. struct drm_device *ddev;
  102. struct xrs_action_ops *actions;
  103. };
  104. /*
  105. * xrsm_init() - Register resource solver. Resource solver client needs
  106. * to call this function to register itself.
  107. *
  108. * @cfg: The system metrics for resource solver to use
  109. *
  110. * Return: A resource solver handle
  111. *
  112. * Note: We should only create one handle per AIE array to be managed.
  113. */
  114. void *xrsm_init(struct init_config *cfg);
  115. /*
  116. * xrs_allocate_resource() - Request to allocate resources for a given context
  117. * and a partition metadata. (See struct part_meta)
  118. *
  119. * @hdl: Resource solver handle obtained from xrs_init()
  120. * @req: Input to the Resource solver including request id
  121. * and partition metadata.
  122. * @cb_arg: callback argument pointer
  123. *
  124. * Return: 0 when successful.
  125. * Or standard error number when failing
  126. *
  127. * Note:
  128. * There is no lock mechanism inside resource solver. So it is
  129. * the caller's responsibility to lock down XCLBINs and grab
  130. * necessary lock.
  131. */
  132. int xrs_allocate_resource(void *hdl, struct alloc_requests *req, void *cb_arg);
  133. /*
  134. * xrs_release_resource() - Request to free resources for a given context.
  135. *
  136. * @hdl: Resource solver handle obtained from xrs_init()
  137. * @rid: The Request ID to identify the requesting context
  138. */
  139. int xrs_release_resource(void *hdl, u64 rid);
  140. #endif /* _AIE2_SOLVER_H */