ps_sched.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #define PS_MAX_TASK_TYPE 16
  36. #define DSP_REPORT_TO_HOST_FLAG 0x10000000
  37. enum task_result
  38. {
  39. PS_TASK_SUCCESS = 0x0000000,
  40. PS_TASK_FAILURE = 0x0000001,
  41. PS_TASK_SUCCESS_WITH_REPORT = PS_TASK_SUCCESS|DSP_REPORT_TO_HOST_FLAG,
  42. PS_TASK_FAILURE_WITH_REPORT = PS_TASK_FAILURE|DSP_REPORT_TO_HOST_FLAG,
  43. };
  44. struct dsp_task_report{
  45. uint32_t report_id;
  46. uint32_t *buf;
  47. uint32_t buf_size;
  48. };
  49. typedef enum task_result (task_func)(void* context);
  50. typedef struct frame_struct
  51. {
  52. uint64_t pFrameBuff;
  53. uint32_t frameBuffSize;
  54. int32_t frameWidth;
  55. int32_t frameHeight;
  56. int32_t framePitch; // frame gaps base on byte
  57. int32_t pitch; //width pitch base on byte;
  58. uint8_t pixelRes;
  59. uint32_t fmt;
  60. uint8_t numChannels;
  61. uint8_t paddingType;
  62. uint32_t paddingVal;
  63. }frame_struct_t;
  64. typedef struct entry_struct{
  65. uint64_t pBuff;
  66. uint16_t x;
  67. uint16_t y;
  68. int16_t width;
  69. int16_t height;
  70. int16_t fmt;
  71. int16_t pitch;
  72. uint32_t frame_height;
  73. csi_dsp_frame_meta_t meta;
  74. }entry_struct_t;
  75. typedef struct dsp_fe_handler{
  76. enum csi_dsp_fe_type type;
  77. int id;
  78. int (*get_state)(int id);
  79. void (*update_state)(int id);
  80. int (*get_next_entry)(int id,entry_struct_t *ctrl_info);
  81. int (*entry_done)(int id,entry_struct_t *ctrl_info);
  82. }dsp_fe_handler_t;
  83. typedef struct dsp_algo_handler{
  84. int algo_id;
  85. char* name;
  86. csi_dsp_algo_param_t *param;
  87. algo_func algo_process;
  88. }dsp_algo_handler_t;
  89. typedef struct dsp_be_handler{
  90. enum csi_dsp_be_type type;
  91. int id;
  92. int (*get_state)(int id);
  93. void (*update_state)(int id);
  94. int (*get_next_entry)(int id,void *ctrl_info);
  95. int (*entry_start)(int id,void *ctrl_info);
  96. }dsp_be_handler_t;
  97. typedef enum task_status{
  98. DSP_TASK_STATUS_FREE, // the task is not allocted
  99. DSP_TASK_STATUS_IDEL, // the task is allocted,but not config, not ready to run
  100. DSP_TASK_STATUS_READY, // the task is allocted and config, ready to run
  101. DSP_TASK_STATUS_RUNING,
  102. DSP_TASK_STATUS_INVALID
  103. }task_status_e;
  104. typedef struct dsp_task{
  105. uint16_t prio;
  106. csi_dsp_task_mode_e type;
  107. task_status_e status;
  108. dsp_fe_handler_t task_fe;
  109. dsp_be_handler_t task_be;
  110. dsp_algo_handler_t task_algo;
  111. task_func *task_pro;
  112. // xrp_command_handler *command_handler;
  113. unsigned char nsid[XRP_NAMESPACE_ID_SIZE];
  114. struct dsp_task_report report_info;
  115. bool (*task_empty_check)();
  116. int32_t irq_num;
  117. void (*intr_handler)(void * data);
  118. void * intr_arg;
  119. }dsp_task_t;
  120. typedef struct {
  121. struct xrp_device *device;
  122. uint16_t task_num;
  123. dsp_task_t *task_handler[PS_MAX_TASK_TYPE];
  124. }s_schduler_t;
  125. typedef enum buffer_status{
  126. DSP_BUF_STATUS_FREE =-40, // the buf is not allocted
  127. DSP_BUF_STATUS_INVALID,
  128. DSP_BUF_STATUS_NO_MEMORY,
  129. DSP_BUF_STATUS_ALLOCTED = 0, // the buf is allocted,normal running
  130. }buffer_status_e;
  131. typedef struct _sw_be_handler{
  132. uint8_t id;
  133. uint8_t buf_num;
  134. uint8_t head_id;
  135. int8_t valid_buf_num;
  136. int status;
  137. uint32_t report_size;
  138. void * report;
  139. struct csi_dsp_buffer *bufs;
  140. }sw_be_handler_t;
  141. extern enum xrp_status ps_run_command(void *context,
  142. const void *in_data, size_t in_data_size,
  143. void *out_data, size_t out_data_size,
  144. struct xrp_buffer_group *buffer_group);
  145. extern enum xrp_status ps_run_isp_algo_command(void *context,
  146. const void *in_data, size_t in_data_size,
  147. void *out_data, size_t out_data_size,
  148. struct xrp_buffer_group *buffer_group);
  149. extern task_func ps_process_isp_task;
  150. extern int init_scheduler(struct xrp_device *device);
  151. extern int ps_task_shedule(struct xrp_device *device);
  152. extern enum xrp_status ps_common_command(void *context,
  153. const void *in_data, size_t in_data_size,
  154. void *out_data, size_t out_data_size,
  155. struct xrp_buffer_group *buffer_group);
  156. extern task_func ps_process_xrp_task;
  157. extern struct xrp_device * ps_xrp_device_int(int idx);
  158. extern int ps_register_cmd_handler(unsigned char * nsid,xrp_command_handler *cmd_handler,void * context);
  159. extern int ps_wait_host_sync();
  160. extern int ps_send_report(uint32_t id);
  161. extern int ps_report_avaiable();
  162. extern int ps_task_interrupt_unregister(int32_t pri,uint32_t intrnum);
  163. extern int ps_get_isp_irq(uint16_t id);
  164. extern int ps_task_interrupt_register_nsid(unsigned char* nsid);
  165. extern int ps_task_enable_common_task();
  166. extern int ps_get_vipre_irq();
  167. extern void sw_be_init();
  168. extern enum xrp_status ps_vipre_config_message_handler(void* in_data,void* out_data);
  169. 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);
  170. extern enum xrp_status ps_isp_config_message_handler(void* in_data,void* context);
  171. extern enum xrp_status sw_be_asgin_buf(int id ,sw_be_config_par* cfg);
  172. extern enum xrp_status ps_post_isp_config_message_handler(void* in_data,void* out_data);
  173. extern int ps_fill_report(void *buffer,csi_dsp_report_e type,void*payload,size_t size);
  174. extern int ps_exception_init();
  175. extern int csi_dsp_result_report(void* report_buf,void*result,size_t result_sz,void* extra,size_t extra_sz);
  176. extern bool ps_is_vipre_task_empty();