ps_sched.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2021 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <stdint.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <xtensa/corebits.h>
  23. #include <xtensa/xtruntime.h>
  24. #if HAVE_THREADS_XOS
  25. #include <xtensa/xos.h>
  26. #endif
  27. #include "xrp_api.h"
  28. #include "xrp_dsp_hw.h"
  29. #include "xrp_dsp_user.h"
  30. #include "dsp_ps_ns.h"
  31. #include "ialgo.h"
  32. #include "csi_dsp_task_defs.h"
  33. #include "csi_dsp_post_process_defs.h"
  34. #include "csi_dsp_types.h"
  35. #include "isp_common.h"
  36. #define PS_MAX_TASK_TYPE 16
  37. #define DSP_REPORT_TO_HOST_FLAG 0x10000000
  38. enum task_result
  39. {
  40. PS_TASK_SUCCESS = 0x0000000,
  41. PS_TASK_FAILURE = 0x0000001,
  42. PS_TASK_SUCCESS_WITH_REPORT = PS_TASK_SUCCESS|DSP_REPORT_TO_HOST_FLAG,
  43. PS_TASK_FAILURE_WITH_REPORT = PS_TASK_FAILURE|DSP_REPORT_TO_HOST_FLAG,
  44. };
  45. struct dsp_task_report{
  46. uint32_t report_id;
  47. uint32_t *buf;
  48. uint32_t buf_size;
  49. };
  50. typedef enum task_result (task_func)(void* context);
  51. typedef struct frame_struct
  52. {
  53. uint64_t pFrameBuff;
  54. uint32_t frameBuffSize;
  55. int32_t frameWidth;
  56. int32_t frameHeight;
  57. int32_t framePitch; // frame gaps base on byte
  58. int32_t pitch; //width pitch base on byte;
  59. uint8_t pixelRes;
  60. uint32_t fmt;
  61. uint8_t numChannels;
  62. uint8_t paddingType;
  63. uint32_t paddingVal;
  64. }frame_struct_t;
  65. typedef struct entry_struct{
  66. uint64_t pBuff;
  67. uint16_t x;
  68. uint16_t y;
  69. int16_t height;
  70. int16_t fmt;
  71. int16_t pitch;
  72. uint32_t frame_height;
  73. uint32_t width;
  74. csi_dsp_frame_meta_t meta;
  75. }entry_struct_t;
  76. typedef struct dsp_fe_handler{
  77. enum csi_dsp_fe_type type;
  78. int id;
  79. int (*get_state)(int id);
  80. void (*update_state)(int id);
  81. int (*get_next_entry)(int id,entry_struct_t *ctrl_info);
  82. int (*entry_done)(int id,entry_struct_t *ctrl_info);
  83. }dsp_fe_handler_t;
  84. typedef struct dsp_algo_handler{
  85. int algo_id;
  86. char* name;
  87. csi_dsp_algo_param_t *param;
  88. algo_func algo_process;
  89. }dsp_algo_handler_t;
  90. typedef struct dsp_be_handler{
  91. enum csi_dsp_be_type type;
  92. int id;
  93. int (*get_state)(int id);
  94. void (*update_state)(int id);
  95. int (*get_next_entry)(int id,void *ctrl_info);
  96. int (*entry_start)(int id,void *ctrl_info);
  97. }dsp_be_handler_t;
  98. typedef enum task_status{
  99. DSP_TASK_STATUS_FREE, // the task is not allocted
  100. DSP_TASK_STATUS_IDEL, // the task is allocted,but not config, not ready to run
  101. DSP_TASK_STATUS_READY, // the task is allocted and config, ready to run
  102. DSP_TASK_STATUS_RUNING,
  103. DSP_TASK_STATUS_INVALID
  104. }task_status_e;
  105. typedef struct dsp_task{
  106. uint16_t prio;
  107. csi_dsp_task_mode_e type;
  108. task_status_e status;
  109. dsp_fe_handler_t task_fe;
  110. dsp_be_handler_t task_be;
  111. dsp_algo_handler_t task_algo;
  112. task_func *task_pro;
  113. // xrp_command_handler *command_handler;
  114. unsigned char nsid[XRP_NAMESPACE_ID_SIZE];
  115. struct dsp_task_report report_info;
  116. bool (*task_empty_check)();
  117. int32_t irq_num;
  118. void (*intr_handler)(void * data);
  119. void * intr_arg;
  120. }dsp_task_t;
  121. typedef struct {
  122. struct xrp_device *device;
  123. uint16_t task_num;
  124. dsp_task_t *task_handler[PS_MAX_TASK_TYPE];
  125. }s_schduler_t;
  126. typedef enum buffer_status{
  127. DSP_BUF_STATUS_FREE = EHW_ERROR_SW_ERR_1, // the buf is not allocted
  128. DSP_BUF_STATUS_INVALID = EHW_ERROR_SW_ERR_2,
  129. DSP_BUF_STATUS_NO_MEMORY = EHW_ERROR_SW_ERR_3,
  130. DSP_BUF_STATUS_ALLOCTED = 0, // the buf is allocted,normal running
  131. }buffer_status_e;
  132. typedef struct _sw_be_handler{
  133. uint8_t id;
  134. uint8_t buf_num;
  135. uint8_t head_id;
  136. int8_t valid_buf_num;
  137. int status;
  138. uint32_t report_size;
  139. void * report;
  140. struct csi_dsp_buffer *bufs;
  141. }sw_be_handler_t;
  142. extern enum xrp_status ps_run_command(void *context,
  143. const void *in_data, size_t in_data_size,
  144. void *out_data, size_t out_data_size,
  145. struct xrp_buffer_group *buffer_group);
  146. extern enum xrp_status ps_run_isp_algo_command(void *context,
  147. const void *in_data, size_t in_data_size,
  148. void *out_data, size_t out_data_size,
  149. struct xrp_buffer_group *buffer_group);
  150. extern task_func ps_process_isp_task;
  151. extern int init_scheduler(struct xrp_device *device);
  152. extern int ps_task_shedule(struct xrp_device *device);
  153. extern enum xrp_status ps_common_command(void *context,
  154. const void *in_data, size_t in_data_size,
  155. void *out_data, size_t out_data_size,
  156. struct xrp_buffer_group *buffer_group);
  157. extern task_func ps_process_xrp_task;
  158. extern struct xrp_device * ps_xrp_device_int(int idx);
  159. extern int ps_register_cmd_handler(unsigned char * nsid,xrp_command_handler *cmd_handler,void * context);
  160. extern int ps_wait_host_sync();
  161. extern void ps_dsp_init_done();
  162. extern int ps_send_report(uint32_t id);
  163. extern int ps_report_avaiable();
  164. extern int ps_task_interrupt_unregister(int32_t pri,uint32_t intrnum);
  165. extern int ps_get_isp_irq(uint16_t id);
  166. extern int ps_task_interrupt_register_nsid(unsigned char* nsid);
  167. extern int ps_task_enable_common_task();
  168. extern int ps_get_vipre_irq();
  169. extern void sw_be_init();
  170. extern enum xrp_status ps_vipre_config_message_handler(void* in_data,void* out_data);
  171. extern enum xrp_status ps_sw_task_out_config_message_handler(void* in_data,void* out_data,void * report_buf,uint32_t report_buf_size);
  172. extern enum xrp_status ps_isp_config_message_handler(void* in_data,void* context);
  173. extern enum xrp_status sw_be_asgin_buf(int id ,sw_be_config_par* cfg);
  174. extern enum xrp_status ps_post_isp_config_message_handler(void* in_data,void* out_data);
  175. extern int ps_fill_report(void *buffer,csi_dsp_report_e type,void*payload,size_t size);
  176. extern int ps_exception_init();
  177. extern int csi_dsp_result_report(void* report_buf,void*result,size_t result_sz,void* extra,size_t extra_sz);
  178. extern bool ps_is_vipre_task_empty();