ddp_manager.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2015. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #define LOG_TAG "ddp_manager"
  32. #include <platform/ddp_reg.h>
  33. #include <platform/ddp_path.h>
  34. #include <platform/ddp_manager.h>
  35. #include <platform/ddp_log.h>
  36. #include <string.h>
  37. #define DDP_MAX_MANAGER_HANDLE (DISP_MUTEX_DDP_COUNT+DISP_MUTEX_DDP_FIRST)
  38. #define DEFAULT_IRQ_EVENT_SCENARIO (3)
  39. typedef struct {
  40. unsigned int init;
  41. DISP_PATH_EVENT event;
  42. //wait_queue_head_t wq;
  43. unsigned long long data;
  44. } DPMGR_WQ_HANDLE;
  45. typedef struct {
  46. DDP_IRQ_BIT irq_bit;
  47. } DDP_IRQ_EVENT_MAPPING;
  48. typedef struct {
  49. cmdqRecHandle cmdqhandle;
  50. int hwmutexid;
  51. int power_sate;
  52. DDP_MODE mode;
  53. //struct mutex mutex_lock;
  54. DDP_IRQ_EVENT_MAPPING irq_event_map[DISP_PATH_EVENT_NUM];
  55. DPMGR_WQ_HANDLE wq_list[DISP_PATH_EVENT_NUM];
  56. DDP_SCENARIO_ENUM scenario;
  57. disp_ddp_path_config last_config;
  58. } ddp_path_handle_t, *ddp_path_handle;
  59. typedef struct {
  60. int handle_cnt;
  61. int mutex_idx;
  62. int power_sate;
  63. //struct mutex mutex_lock;
  64. DISP_MODULE_ENUM module_usage_table[DISP_MODULE_NUM];
  65. ddp_path_handle module_path_table[DISP_MODULE_NUM];
  66. ddp_path_handle handle_pool[DDP_MAX_MANAGER_HANDLE];
  67. } DDP_MANAGER_CONTEXT;
  68. extern DDP_MODULE_DRIVER * ddp_modules_driver[DISP_MODULE_NUM];
  69. static ddp_path_handle_t g_handle;
  70. static DDP_IRQ_EVENT_MAPPING ddp_irq_event_list[DEFAULT_IRQ_EVENT_SCENARIO][DISP_PATH_EVENT_NUM] = {
  71. {
  72. //ovl0 path
  73. {DDP_IRQ_RDMA0_START }, /*FRAME_START*/
  74. {DDP_IRQ_RDMA0_DONE }, /*FRAME_DONE*/
  75. {DDP_IRQ_RDMA0_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  76. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  77. {DDP_IRQ_WDMA0_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  78. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_STOP*/
  79. {DDP_IRQ_RDMA0_REG_UPDATE }, /*IF_CMD_DONE*/
  80. {DDP_IRQ_DSI0_EXT_TE }, /*IF_VSYNC*/
  81. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  82. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  83. },
  84. {
  85. //ovl1 path
  86. {DDP_IRQ_RDMA1_START }, /*FRAME_START*/
  87. {DDP_IRQ_RDMA1_DONE }, /*FRAME_DONE*/
  88. {DDP_IRQ_RDMA1_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  89. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  90. {DDP_IRQ_WDMA1_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  91. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_STOP*/
  92. {DDP_IRQ_RDMA1_REG_UPDATE }, /*IF_CMD_DONE*/
  93. {DDP_IRQ_RDMA1_TARGET_LINE }, /*IF_VSYNC*/
  94. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  95. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  96. },
  97. {
  98. // rdma path
  99. {DDP_IRQ_RDMA2_START }, /*FRAME_START*/
  100. {DDP_IRQ_RDMA2_DONE }, /*FRAME_DONE*/
  101. {DDP_IRQ_RDMA2_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  102. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  103. {DDP_IRQ_UNKNOW }, /*FRAME_COMPLETE*/
  104. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_STOP*/
  105. {DDP_IRQ_RDMA2_REG_UPDATE }, /*IF_CMD_DONE*/
  106. {DDP_IRQ_RDMA2_TARGET_LINE }, /*IF_VSYNC*/
  107. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  108. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  109. },
  110. };
  111. static DDP_MANAGER_CONTEXT* _get_context(void)
  112. {
  113. static int is_context_inited = 0;
  114. static DDP_MANAGER_CONTEXT context;
  115. if (!is_context_inited) {
  116. memset((void*)&context, 0, sizeof(DDP_MANAGER_CONTEXT));
  117. context.mutex_idx = (1<<DISP_MUTEX_DDP_COUNT) - 1;
  118. //mutex_init(&context.mutex_lock);
  119. is_context_inited = 1;
  120. }
  121. return &context;
  122. }
  123. static int path_top_clock_off()
  124. {
  125. int i =0;
  126. DDP_MANAGER_CONTEXT * context = _get_context();
  127. if (context->power_sate) {
  128. for (i=0; i< DDP_MAX_MANAGER_HANDLE; i++) {
  129. if (context->handle_pool[i] != NULL && context->handle_pool[i]->power_sate !=0) {
  130. return 0;
  131. }
  132. }
  133. context->power_sate = 0;
  134. ddp_path_top_clock_off();
  135. }
  136. return 0;
  137. }
  138. static int path_top_clock_on()
  139. {
  140. DDP_MANAGER_CONTEXT * context = _get_context();
  141. if (!context->power_sate) {
  142. context->power_sate = 1;
  143. ddp_path_top_clock_on();
  144. }
  145. return 0;
  146. }
  147. static ddp_path_handle find_handle_by_module(DISP_MODULE_ENUM module)
  148. {
  149. return _get_context()->module_path_table[module];
  150. }
  151. static int dpmgr_module_notify(DISP_MODULE_ENUM module, DISP_PATH_EVENT event)
  152. {
  153. ddp_path_handle handle = find_handle_by_module(module);
  154. return dpmgr_signal_event(handle,event);
  155. }
  156. static int assign_default_irqs_table(DDP_SCENARIO_ENUM scenario,DDP_IRQ_EVENT_MAPPING * irq_events)
  157. {
  158. int idx = 0;
  159. switch (scenario) {
  160. case DDP_SCENARIO_PRIMARY_DISP:
  161. case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
  162. case DDP_SCENARIO_PRIMARY_ALL:
  163. case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP:
  164. case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
  165. case DDP_SCENARIO_DISPLAY_INTERFACE:
  166. idx = 0;
  167. break;
  168. case DDP_SCENARIO_SUB_DISP:
  169. case DDP_SCENARIO_SUB_OVL_MEMOUT:
  170. case DDP_SCENARIO_SUB_ALL:
  171. case DDP_SCENARIO_SUB_RDMA1_DISP:
  172. idx = 1;
  173. break;
  174. default:
  175. DISP_LOG_E("unknow scenario %d\n",scenario);
  176. }
  177. DISP_LOG_I("assign default irqs table index %d\n",idx);
  178. memcpy(irq_events,ddp_irq_event_list[idx],sizeof(ddp_irq_event_list[idx]));
  179. return 0;
  180. }
  181. static int acquire_free_bit(unsigned int total)
  182. {
  183. int free_id =0 ;
  184. while (total) {
  185. if (total & 0x1) {
  186. return free_id;
  187. }
  188. total>>=1;
  189. ++free_id;
  190. }
  191. return -1;
  192. }
  193. static int acquire_mutex(DDP_SCENARIO_ENUM scenario)
  194. {
  195. ///: primay use mutex 0
  196. int mutex_id =0 ;
  197. DDP_MANAGER_CONTEXT * content = _get_context();
  198. int mutex_idx_free = content->mutex_idx;
  199. ASSERT(scenario >= 0 && scenario < DDP_SCENARIO_MAX);
  200. while (mutex_idx_free) {
  201. if (mutex_idx_free & 0x1) {
  202. content->mutex_idx &= (~(0x1<<mutex_id));
  203. mutex_id += DISP_MUTEX_DDP_FIRST;
  204. break;
  205. }
  206. mutex_idx_free>>=1;
  207. ++mutex_id;
  208. }
  209. ASSERT(mutex_id < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  210. DISP_LOG_I("scenario %s acquire mutex %d , left mutex 0x%x!\n",
  211. ddp_get_scenario_name(scenario), mutex_id, content->mutex_idx);
  212. return mutex_id;
  213. }
  214. static int release_mutex(int mutex_idx)
  215. {
  216. DDP_MANAGER_CONTEXT * content = _get_context();
  217. ASSERT(mutex_idx < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  218. content->mutex_idx |= 1<< (mutex_idx-DISP_MUTEX_DDP_FIRST);
  219. DISP_LOG_I("release mutex %d , left mutex 0x%x!\n",
  220. mutex_idx, content->mutex_idx);
  221. return 0;
  222. }
  223. int dpmgr_path_set_video_mode(disp_path_handle dp_handle, int is_vdo_mode)
  224. {
  225. ddp_path_handle handle = NULL;
  226. ASSERT(dp_handle != NULL);
  227. handle = (ddp_path_handle)dp_handle;
  228. handle->mode = is_vdo_mode ? DDP_VIDEO_MODE : DDP_CMD_MODE;
  229. DISP_LOG_I("set scenario %s mode %s\n",ddp_get_scenario_name(handle->scenario),
  230. is_vdo_mode ? "Video Mode":"Cmd Mode");
  231. return 0;
  232. }
  233. disp_path_handle dpmgr_create_path(DDP_SCENARIO_ENUM scenario, cmdqRecHandle cmdq_handle)
  234. {
  235. int i =0;
  236. int module_name ;
  237. ddp_path_handle path_handle = NULL;
  238. int * modules = ddp_get_scenario_list(scenario);
  239. int module_num = ddp_get_module_num(scenario);
  240. DDP_MANAGER_CONTEXT * content = _get_context();
  241. //path_handle = kzalloc(sizeof(uint8_t*) * sizeof(ddp_path_handle_t), GFP_KERNEL);
  242. memset((void*)(&g_handle), 0, sizeof(ddp_path_handle_t));
  243. path_handle = &g_handle;
  244. if (NULL != path_handle) {
  245. path_handle->cmdqhandle = cmdq_handle;
  246. path_handle->scenario = scenario;
  247. path_handle->hwmutexid = acquire_mutex(scenario);
  248. assign_default_irqs_table(scenario,path_handle->irq_event_map);
  249. DISP_LOG_I("create handle 0x%p on scenario %s\n",path_handle,ddp_get_scenario_name(scenario));
  250. for ( i=0; i< module_num; i++) {
  251. module_name = modules[i];
  252. DISP_LOG_V(" scenario %s include module %s\n",ddp_get_scenario_name(scenario),ddp_get_module_name(module_name));
  253. content->module_usage_table[module_name]++;
  254. content->module_path_table[module_name] = path_handle;
  255. }
  256. content->handle_cnt ++;
  257. content->handle_pool[path_handle->hwmutexid] = path_handle;
  258. } else {
  259. DISP_LOG_E("Fail to create handle on scenario %s\n",ddp_get_scenario_name(scenario));
  260. }
  261. return path_handle;
  262. }
  263. int dpmgr_destroy_path(disp_path_handle dp_handle)
  264. {
  265. int i = 0;
  266. int module_name = 0;
  267. ddp_path_handle handle = NULL;
  268. int *modules = NULL;
  269. int module_num = 0;
  270. DDP_MANAGER_CONTEXT *content = NULL;
  271. ASSERT(dp_handle != NULL);
  272. handle = (ddp_path_handle) dp_handle;
  273. if (handle != NULL) {
  274. modules = ddp_get_scenario_list(handle->scenario);
  275. module_num = ddp_get_module_num(handle->scenario);
  276. content = _get_context();
  277. DISP_LOG_I("destroy path handle 0x%p on scenario %s\n",handle,ddp_get_scenario_name(handle->scenario));
  278. release_mutex(handle->hwmutexid);
  279. ddp_disconnect_path(handle->scenario,handle->cmdqhandle);
  280. for ( i=0; i< module_num; i++) {
  281. module_name = modules[i];
  282. content->module_usage_table[module_name]--;
  283. content->module_path_table[module_name] = NULL;
  284. }
  285. content->handle_cnt --;
  286. ASSERT(content->handle_cnt >=0);
  287. content->handle_pool[handle->hwmutexid] = NULL;
  288. // kfree(handle);
  289. }
  290. return 0;
  291. }
  292. int dpmgr_path_add_dump(disp_path_handle dp_handle, ENGINE_DUMP engine,int encmdq )
  293. {
  294. ASSERT(dp_handle != NULL);
  295. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  296. ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_SUB_DISP);
  297. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  298. DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
  299. // update contxt
  300. DDP_MANAGER_CONTEXT * context = _get_context();
  301. context->module_usage_table[wdma]++;
  302. context->module_path_table[wdma] = handle;
  303. handle->scenario = DDP_SCENARIO_PRIMARY_ALL;
  304. // update connected
  305. ddp_connect_path(handle->scenario,cmdqHandle);
  306. ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdqHandle);
  307. //wdma just need start.
  308. if (ddp_modules_driver[wdma] != 0) {
  309. if (ddp_modules_driver[wdma]->init!= 0) {
  310. ddp_modules_driver[wdma]->init(wdma, cmdqHandle);
  311. }
  312. if (ddp_modules_driver[wdma]->start!= 0) {
  313. ddp_modules_driver[wdma]->start(wdma, cmdqHandle);
  314. }
  315. }
  316. return 0;
  317. }
  318. int dpmgr_path_remove_dump(disp_path_handle dp_handle, int encmdq )
  319. {
  320. ASSERT(dp_handle != NULL);
  321. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  322. ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_PRIMARY_ALL
  323. || handle->scenario ==DDP_SCENARIO_SUB_DISP || handle->scenario ==DDP_SCENARIO_SUB_ALL);
  324. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  325. DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
  326. // update contxt
  327. DDP_MANAGER_CONTEXT * context = _get_context();
  328. context->module_usage_table[wdma]--;
  329. context->module_path_table[wdma] = 0;
  330. //wdma just need stop
  331. if (ddp_modules_driver[wdma] != 0) {
  332. if (ddp_modules_driver[wdma]->stop!= 0) {
  333. ddp_modules_driver[wdma]->stop(wdma, cmdqHandle);
  334. }
  335. if (ddp_modules_driver[wdma]->deinit!= 0) {
  336. ddp_modules_driver[wdma]->deinit(wdma, cmdqHandle);
  337. }
  338. }
  339. ddp_disconnect_path(DDP_SCENARIO_PRIMARY_OVL_MEMOUT,cmdqHandle);
  340. handle->scenario = DDP_SCENARIO_PRIMARY_DISP;
  341. // update connected
  342. ddp_connect_path(handle->scenario,cmdqHandle);
  343. ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdqHandle);
  344. return 0;
  345. }
  346. int dpmgr_path_set_dst_module(disp_path_handle dp_handle,DISP_MODULE_ENUM dst_module)
  347. {
  348. ASSERT(dp_handle != NULL);
  349. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  350. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  351. DISP_LOG_I("set dst module on scenario %s, module %s\n",
  352. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  353. return ddp_set_dst_module(handle->scenario, dst_module);
  354. }
  355. DISP_MODULE_ENUM dpmgr_path_get_dst_module(disp_path_handle dp_handle)
  356. {
  357. ASSERT(dp_handle != NULL);
  358. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  359. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  360. DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
  361. DISP_LOG_I("get dst module on scenario %s, module %s\n",
  362. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  363. return dst_module;
  364. }
  365. int dpmgr_path_init(disp_path_handle dp_handle, int encmdq)
  366. {
  367. int i=0;
  368. int module_name ;
  369. ASSERT(dp_handle != NULL);
  370. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  371. int * modules = ddp_get_scenario_list(handle->scenario);
  372. int module_num = ddp_get_module_num(handle->scenario);
  373. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  374. DISP_LOG_I("path init on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  375. //turn off m4u
  376. ddp_path_m4u_off();
  377. //open top clock
  378. ddp_path_top_clock_on();
  379. //seting mutex
  380. ddp_mutex_set(handle->hwmutexid,
  381. handle->scenario,
  382. handle->mode,
  383. cmdqHandle);
  384. //connect path;
  385. ddp_connect_path(handle->scenario,cmdqHandle);
  386. // each module init
  387. for ( i=0; i< module_num; i++) {
  388. module_name = modules[i];
  389. if (ddp_modules_driver[module_name] != 0) {
  390. if (ddp_modules_driver[module_name]->init!= 0) {
  391. DISP_LOG_V("scenario %s init module %s\n",ddp_get_scenario_name(handle->scenario),
  392. ddp_get_module_name(module_name));
  393. ddp_modules_driver[module_name]->init(module_name, cmdqHandle);
  394. }
  395. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  396. ddp_modules_driver[module_name]->set_listener(module_name,dpmgr_module_notify);
  397. }
  398. }
  399. }
  400. //after init this path will power on;
  401. handle->power_sate = 1;
  402. return 0;
  403. }
  404. int dpmgr_path_deinit(disp_path_handle dp_handle, int encmdq)
  405. {
  406. int i=0;
  407. int module_name ;
  408. ASSERT(dp_handle != NULL);
  409. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  410. int * modules = ddp_get_scenario_list(handle->scenario);
  411. int module_num = ddp_get_module_num(handle->scenario);
  412. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  413. DISP_LOG_I("path deinit on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  414. ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
  415. ddp_disconnect_path(handle->scenario, cmdqHandle);
  416. for ( i=0; i< module_num; i++) {
  417. module_name = modules[i];
  418. if (ddp_modules_driver[module_name] != 0) {
  419. if (ddp_modules_driver[module_name]->deinit!= 0) {
  420. DISP_LOG_V("scenario %s deinit module %s\n",ddp_get_scenario_name(handle->scenario),
  421. ddp_get_module_name(module_name));
  422. ddp_modules_driver[module_name]->deinit(module_name, cmdqHandle);
  423. }
  424. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  425. ddp_modules_driver[module_name]->set_listener(module_name,NULL);
  426. }
  427. }
  428. }
  429. handle->power_sate = 0;
  430. //close top clock when last path init
  431. path_top_clock_off();
  432. return 0;
  433. }
  434. int dpmgr_path_start(disp_path_handle dp_handle, int encmdq)
  435. {
  436. int i=0;
  437. int module_name ;
  438. ASSERT(dp_handle != NULL);
  439. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  440. int * modules = ddp_get_scenario_list(handle->scenario);
  441. int module_num = ddp_get_module_num(handle->scenario);
  442. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  443. DISP_LOG_V("path start on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  444. for ( i=0; i< module_num; i++) {
  445. module_name = modules[i];
  446. if (ddp_modules_driver[module_name] != 0) {
  447. if (ddp_modules_driver[module_name]->start!= 0) {
  448. DISP_LOG_V("scenario %s start module %s\n",ddp_get_scenario_name(handle->scenario),
  449. ddp_get_module_name(module_name));
  450. ddp_modules_driver[module_name]->start(module_name, cmdqHandle);
  451. }
  452. }
  453. }
  454. return 0;
  455. }
  456. int dpmgr_path_stop(disp_path_handle dp_handle, int encmdq)
  457. {
  458. int i=0;
  459. int module_name ;
  460. ASSERT(dp_handle != NULL);
  461. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  462. int * modules = ddp_get_scenario_list(handle->scenario);
  463. int module_num = ddp_get_module_num(handle->scenario);
  464. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  465. DISP_LOG_I("path stop on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  466. for ( i=0; i< module_num; i++) {
  467. module_name = modules[i];
  468. if (ddp_modules_driver[module_name] != 0) {
  469. if (ddp_modules_driver[module_name]->stop!= 0) {
  470. DISP_LOG_V("scenario %s stop module %s \n",ddp_get_scenario_name(handle->scenario),
  471. ddp_get_module_name(module_name));
  472. ddp_modules_driver[module_name]->stop(module_name, cmdqHandle);
  473. }
  474. }
  475. }
  476. return 0;
  477. }
  478. int dpmgr_path_reset(disp_path_handle dp_handle, int encmdq)
  479. {
  480. int i=0;
  481. int module_name ;
  482. ASSERT(dp_handle != NULL);
  483. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  484. int * modules = ddp_get_scenario_list(handle->scenario);
  485. int module_num = ddp_get_module_num(handle->scenario);
  486. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  487. DISP_LOG_I("path reset on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  488. for ( i=0; i< module_num; i++) {
  489. module_name = modules[i];
  490. if (ddp_modules_driver[module_name] != 0) {
  491. if (ddp_modules_driver[module_name]->reset != 0) {
  492. DISP_LOG_V("scenario %s reset module %s \n",ddp_get_scenario_name(handle->scenario),
  493. ddp_get_module_name(module_name));
  494. ddp_modules_driver[module_name]->reset(module_name, cmdqHandle);
  495. }
  496. }
  497. }
  498. return 0;
  499. }
  500. int dpmgr_path_config(disp_path_handle dp_handle, disp_ddp_path_config * config, int encmdq)
  501. {
  502. int i=0;
  503. int module_name ;
  504. ASSERT(dp_handle != NULL);
  505. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  506. int * modules = ddp_get_scenario_list(handle->scenario);
  507. int module_num = ddp_get_module_num(handle->scenario);
  508. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  509. DISP_LOG_V("path config ovl %d, rdma %d, wdma %d, dst %d on handle 0x%p scenario %s \n",
  510. config->ovl_dirty,
  511. config->rdma_dirty,
  512. config->wdma_dirty,
  513. config->dst_dirty,
  514. handle,
  515. ddp_get_scenario_name(handle->scenario));
  516. memcpy(&handle->last_config, config, sizeof(disp_ddp_path_config));
  517. for ( i=0; i< module_num; i++) {
  518. module_name = modules[i];
  519. if (ddp_modules_driver[module_name] != 0) {
  520. if (ddp_modules_driver[module_name]->config!= 0) {
  521. DISP_LOG_V("scenario %s config module %s \n",ddp_get_scenario_name(handle->scenario),
  522. ddp_get_module_name(module_name));
  523. ddp_modules_driver[module_name]->config(module_name, config, cmdqHandle);
  524. }
  525. }
  526. }
  527. return 0;
  528. }
  529. disp_ddp_path_config *dpmgr_path_get_last_config(disp_path_handle dp_handle)
  530. {
  531. ASSERT(dp_handle != NULL);
  532. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  533. handle->last_config.ovl_dirty =0;
  534. handle->last_config.rdma_dirty =0;
  535. handle->last_config.wdma_dirty =0;
  536. handle->last_config.dst_dirty =0;
  537. return &handle->last_config;
  538. }
  539. int dpmgr_path_build_cmdq(disp_path_handle dp_handle, void *trigger_loop_handle, CMDQ_STATE state)
  540. {
  541. int i=0;
  542. int module_name ;
  543. ASSERT(dp_handle != NULL);
  544. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  545. int * modules = ddp_get_scenario_list(handle->scenario);
  546. int module_num = ddp_get_module_num(handle->scenario);
  547. DISP_LOG_D("path build cmdq on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  548. for ( i=0; i< module_num; i++) {
  549. module_name = modules[i];
  550. if (ddp_modules_driver[module_name] != 0) {
  551. if (ddp_modules_driver[module_name]->build_cmdq!= 0) {
  552. DISP_LOG_D("%s build cmdq, state=%d\n",ddp_get_module_name(module_name), state);
  553. ddp_modules_driver[module_name]->build_cmdq(module_name, trigger_loop_handle, state); // now just 0;
  554. }
  555. }
  556. }
  557. return 0;
  558. }
  559. int dpmgr_path_trigger(disp_path_handle dp_handle, void *trigger_loop_handle, int encmdq)
  560. {
  561. ASSERT(dp_handle != NULL);
  562. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  563. DISP_LOG_V("dpmgr_path_trigger on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  564. int i=0;
  565. int * modules = ddp_get_scenario_list(handle->scenario);
  566. int module_num = ddp_get_module_num(handle->scenario);
  567. int module_name ;
  568. ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  569. for ( i=0; i< module_num; i++) {
  570. module_name = modules[i];
  571. if (ddp_modules_driver[module_name] != 0) {
  572. if (ddp_modules_driver[module_name]->trigger!= 0) {
  573. DISP_LOG_V("%s trigger\n",ddp_get_module_name(module_name));
  574. ddp_modules_driver[module_name]->trigger(module_name, trigger_loop_handle);
  575. }
  576. }
  577. }
  578. return 0;
  579. }
  580. int dpmgr_path_flush(disp_path_handle dp_handle,int encmdq)
  581. {
  582. ASSERT(dp_handle != NULL);
  583. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  584. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  585. DISP_LOG_I("path flush on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  586. return ddp_mutex_enable(handle->hwmutexid,handle->scenario,cmdqHandle);
  587. }
  588. int dpmgr_path_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  589. {
  590. int i=0;
  591. int module_name ;
  592. ASSERT(dp_handle != NULL);
  593. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  594. int * modules = ddp_get_scenario_list(handle->scenario);
  595. int module_num = ddp_get_module_num(handle->scenario);
  596. DISP_LOG_I("path power off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  597. for ( i=0; i< module_num; i++) {
  598. module_name = modules[i];
  599. if (ddp_modules_driver[module_name] != 0) {
  600. if (ddp_modules_driver[module_name]->power_off!= 0) {
  601. DISP_LOG_I(" %s power off\n",ddp_get_module_name(module_name));
  602. ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  603. }
  604. }
  605. }
  606. handle->power_sate = 0;
  607. path_top_clock_off();
  608. return 0;
  609. }
  610. int dpmgr_path_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  611. {
  612. int i=0;
  613. int module_name ;
  614. ASSERT(dp_handle != NULL);
  615. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  616. int * modules = ddp_get_scenario_list(handle->scenario);
  617. int module_num = ddp_get_module_num(handle->scenario);
  618. DISP_LOG_I("path power on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  619. path_top_clock_on();
  620. for ( i=0; i< module_num; i++) {
  621. module_name = modules[i];
  622. if (ddp_modules_driver[module_name] != 0) {
  623. if (ddp_modules_driver[module_name]->power_on!= 0) {
  624. DISP_LOG_I("%s power on\n",ddp_get_module_name(module_name));
  625. ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  626. }
  627. }
  628. }
  629. //modules on this path will resume power on;
  630. handle->power_sate = 1;
  631. return 0;
  632. }
  633. int dpmgr_path_set_parameter(disp_path_handle dp_handle, int io_evnet, void * data)
  634. {
  635. return 0;
  636. }
  637. int dpmgr_path_get_parameter(disp_path_handle dp_handle,int io_evnet, void * data )
  638. {
  639. return 0;
  640. }
  641. int dpmgr_path_is_idle(disp_path_handle dp_handle)
  642. {
  643. ASSERT(dp_handle != NULL);
  644. return !dpmgr_path_is_busy(dp_handle);
  645. }
  646. int dpmgr_path_is_busy(disp_path_handle dp_handle)
  647. {
  648. int i=0;
  649. int module_name ;
  650. ASSERT(dp_handle != NULL);
  651. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  652. int * modules = ddp_get_scenario_list(handle->scenario);
  653. int module_num = ddp_get_module_num(handle->scenario);
  654. DISP_LOG_V("path check busy on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  655. for ( i=module_num-1; i>=0; i--) {
  656. module_name = modules[i];
  657. if (ddp_modules_driver[module_name] != 0) {
  658. if (ddp_modules_driver[module_name]->is_busy!= 0) {
  659. if (ddp_modules_driver[module_name]->is_busy(module_name)) {
  660. DISP_LOG_V("%s is busy\n", ddp_get_module_name(module_name));
  661. return 1;
  662. }
  663. }
  664. }
  665. }
  666. return 0;
  667. }
  668. int dpmgr_set_lcm_utils(disp_path_handle dp_handle, void *lcm_drv)
  669. {
  670. int i=0;
  671. int module_name ;
  672. ASSERT(dp_handle != NULL);
  673. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  674. int * modules = ddp_get_scenario_list(handle->scenario);
  675. int module_num = ddp_get_module_num(handle->scenario);
  676. DISP_LOG_V("path set lcm drv handle 0x%p\n",handle);
  677. for ( i=0; i< module_num; i++) {
  678. module_name = modules[i];
  679. if (ddp_modules_driver[module_name] != 0) {
  680. if ((ddp_modules_driver[module_name]->set_lcm_utils!= 0)&&lcm_drv) {
  681. DISP_LOG_I("%s set lcm utils\n",ddp_get_module_name(module_name));
  682. ddp_modules_driver[module_name]->set_lcm_utils(module_name, lcm_drv); // now just 0;
  683. }
  684. }
  685. }
  686. return 0;
  687. }
  688. int dpmgr_enable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  689. {
  690. ASSERT(dp_handle != NULL);
  691. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  692. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  693. DISP_LOG_I("enable event on scenario %s, event %d, irtbit 0x%x\n",
  694. ddp_get_scenario_name(handle->scenario),
  695. event,
  696. handle->irq_event_map[event].irq_bit);
  697. if (!wq_handle->init) {
  698. //init_waitqueue_head(&(wq_handle->wq));
  699. wq_handle->init = 1;
  700. wq_handle->data= 0;
  701. wq_handle->event = event;
  702. }
  703. return 0;
  704. }
  705. int dpmgr_map_event_to_irq(disp_path_handle dp_handle, DISP_PATH_EVENT event, DDP_IRQ_BIT irq_bit)
  706. {
  707. ASSERT(dp_handle != NULL);
  708. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  709. DDP_IRQ_EVENT_MAPPING *irq_table = handle->irq_event_map;
  710. if (event < DISP_PATH_EVENT_NUM) {
  711. DISP_LOG_I("map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  712. irq_table[event].irq_bit= irq_bit;
  713. return 0;
  714. }
  715. DISP_LOG_E("fail to map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  716. return -1;
  717. }
  718. int dpmgr_disable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  719. {
  720. ASSERT(dp_handle != NULL);
  721. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  722. DISP_LOG_I("disable event %d on scenario %s \n",event,ddp_get_scenario_name(handle->scenario));
  723. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  724. wq_handle->init = 0;
  725. wq_handle->data= 0;
  726. return 0;
  727. }
  728. int dpmgr_check_status(disp_path_handle dp_handle)
  729. {
  730. int i =0;
  731. int module_name ;
  732. ASSERT(dp_handle != NULL);
  733. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  734. int * modules = ddp_get_scenario_list(handle->scenario);
  735. int module_num = ddp_get_module_num(handle->scenario);
  736. DISP_LOG_I("check status on scenario %s, module_num %d \n",
  737. ddp_get_scenario_name(handle->scenario),module_num);
  738. ddp_check_path(handle->scenario);
  739. ddp_check_mutex(handle->hwmutexid,handle->scenario,
  740. handle->mode);
  741. //ddp_check_signal(handle->scenario);
  742. for ( i=0; i< module_num; i++) {
  743. module_name = modules[i];
  744. ddp_dump_analysis(module_name);
  745. if (i == DISP_MODULE_DSI0 || i == DISP_MODULE_DSI1 || i == DISP_MODULE_DSIDUAL) {
  746. if (ddp_modules_driver[i] != 0) {
  747. if (ddp_modules_driver[i]->dump_info!= 0) {
  748. ddp_modules_driver[i]->dump_info(i, 1);
  749. }
  750. }
  751. }
  752. }
  753. ddp_dump_analysis(DISP_MODULE_CONFIG);
  754. ddp_dump_analysis(DISP_MODULE_MUTEX);
  755. for ( i=0; i< module_num; i++) {
  756. module_name = modules[i];
  757. ddp_dump_reg(module_name);
  758. }
  759. ddp_dump_reg(DISP_MODULE_CONFIG);
  760. ddp_dump_reg(DISP_MODULE_MUTEX);
  761. return 0;
  762. }
  763. int dpmgr_wait_event_timeout(disp_path_handle dp_handle, DISP_PATH_EVENT event, int timeout)
  764. {
  765. int ret = -1;
  766. ASSERT(dp_handle != NULL);
  767. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  768. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  769. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  770. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  771. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  772. if (wq_handle->init) {
  773. //DISP_LOG_V("wait event %d timeout %d on scenario %s\n", event,timeout,ddp_get_scenario_name(handle->scenario));
  774. //should poling
  775. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  776. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,timeout);
  777. }
  778. if (ret > 0) {
  779. //DISP_LOG_V("received event %d left time %d on scenario %s \n", event, ret,ddp_get_scenario_name(handle->scenario));
  780. } else {
  781. DISP_LOG_E("wait %d timeout ret %d on scenario %d \n", event,ret,handle->scenario);
  782. dpmgr_check_status(handle);
  783. }
  784. return ret;
  785. }
  786. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  787. return ret;
  788. }
  789. int dpmgr_wait_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  790. {
  791. int ret = -1;
  792. ASSERT(dp_handle != NULL);
  793. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  794. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  795. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  796. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  797. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  798. if (wq_handle->init) {
  799. DISP_LOG_V("wait event %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  800. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  801. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,-1);
  802. }
  803. DISP_LOG_V("received event %d on scenario %s \n", event, ddp_get_scenario_name(handle->scenario));
  804. return ret;
  805. }
  806. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  807. return ret;
  808. }
  809. int dpmgr_signal_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  810. {
  811. ASSERT(dp_handle != NULL);
  812. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  813. if (handle->wq_list[event].init) {
  814. //wq_handle->data = sched_clock();
  815. DISP_LOG_V("wake up evnet %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  816. //wake_up_interruptible(&(handle->wq_list[event].wq));
  817. }
  818. return 0;
  819. }
  820. int dpmgr_init(void)
  821. {
  822. DISP_LOG_I("ddp manager init\n");
  823. return 0;
  824. }
  825. /*
  826. static void dpmgr_irq_handler(DISP_MODULE_ENUM module,unsigned int regvalue)
  827. {
  828. int i = 0;
  829. int j = 0;
  830. int irq_bits_num =0;
  831. int irq_bit = 0;
  832. ddp_path_handle handle = NULL;
  833. DISP_PATH_EVENT event = DISP_PATH_EVENT_NONE;
  834. DISP_LOG_V("irq handler module %d, regvalue 0x%x\n", module,regvalue);
  835. handle = find_handle_by_module(module);
  836. if(handle == NULL)
  837. {
  838. return;
  839. }
  840. irq_bits_num = ddp_get_module_max_irq_bit(module);
  841. for(i = 0; i<=irq_bits_num; i++)
  842. {
  843. if(regvalue & (0x1<<i))
  844. {
  845. irq_bit = (module<<16 | 0x1<<i);
  846. for(j = 0; j < DISP_PATH_EVENT_NUM; j++)
  847. {
  848. if(handle->wq_list[j].init && irq_bit == handle->irq_event_map[j].irq_bit)
  849. {
  850. //handle->wq_list[j].data =sched_clock();
  851. DISP_LOG_V("irq signal event %d on cycle %llu on scenario %s\n",
  852. event, handle->wq_list[j].data ,ddp_get_scenario_name(handle->scenario));
  853. //wake_up_interruptible(&(handle->wq_list[j].wq));
  854. }
  855. }
  856. }
  857. }
  858. return ;
  859. }
  860. */