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