ddp_manager.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. extern DDP_MODULE_DRIVER * ddp_modules_driver[DISP_MODULE_NUM];
  37. #define DDP_MAX_MANAGER_HANDLE (DISP_MUTEX_DDP_COUNT+DISP_MUTEX_DDP_FIRST)
  38. typedef struct {
  39. unsigned int init;
  40. DISP_PATH_EVENT event;
  41. unsigned long long data;
  42. } DPMGR_WQ_HANDLE;
  43. typedef struct {
  44. DDP_IRQ_BIT irq_bit;
  45. } DDP_IRQ_EVENT_MAPPING;
  46. typedef struct {
  47. cmdqRecHandle cmdqhandle;
  48. int hwmutexid;
  49. int power_sate;
  50. DDP_MODE mode;
  51. //struct mutex mutex_lock;
  52. DDP_IRQ_EVENT_MAPPING irq_event_map[DISP_PATH_EVENT_NUM];
  53. DPMGR_WQ_HANDLE wq_list[DISP_PATH_EVENT_NUM];
  54. DDP_SCENARIO_ENUM scenario;
  55. disp_ddp_path_config last_config;
  56. } ddp_path_handle_t, *ddp_path_handle;
  57. typedef struct {
  58. int handle_cnt;
  59. int mutex_idx;
  60. int power_sate;
  61. //struct mutex mutex_lock;
  62. DISP_MODULE_ENUM module_usage_table[DISP_MODULE_NUM];
  63. ddp_path_handle module_path_table[DISP_MODULE_NUM];
  64. ddp_path_handle handle_pool[DDP_MAX_MANAGER_HANDLE];
  65. } DDP_MANAGER_CONTEXT;
  66. static ddp_path_handle_t g_handle;
  67. #define DEFAULT_IRQ_EVENT_SCENARIO (3)
  68. static DDP_IRQ_EVENT_MAPPING ddp_irq_event_list[DEFAULT_IRQ_EVENT_SCENARIO][DISP_PATH_EVENT_NUM] = {
  69. {
  70. //ovl0 path
  71. {DDP_IRQ_RDMA0_START }, /*FRAME_START*/
  72. {DDP_IRQ_RDMA0_DONE }, /*FRAME_DONE*/
  73. {DDP_IRQ_RDMA0_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  74. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  75. {DDP_IRQ_WDMA0_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  76. {DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_STOP*/
  77. {DDP_IRQ_RDMA0_REG_UPDATE }, /*IF_CMD_DONE*/
  78. {DDP_IRQ_DSI0_EXT_TE }, /*IF_VSYNC*/
  79. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  80. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  81. },
  82. {
  83. //ovl1 path
  84. {DDP_IRQ_RDMA1_START }, /*FRAME_START*/
  85. {DDP_IRQ_RDMA1_DONE }, /*FRAME_DONE*/
  86. {DDP_IRQ_RDMA1_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  87. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  88. {DDP_IRQ_WDMA1_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
  89. {DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_STOP*/
  90. {DDP_IRQ_RDMA1_REG_UPDATE }, /*IF_CMD_DONE*/
  91. {DDP_IRQ_RDMA1_TARGET_LINE }, /*IF_VSYNC*/
  92. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  93. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  94. },
  95. {
  96. //rdma path
  97. {DDP_IRQ_RDMA2_START }, /*FRAME_START*/
  98. {DDP_IRQ_RDMA2_DONE }, /*FRAME_DONE*/
  99. {DDP_IRQ_RDMA2_REG_UPDATE }, /*FRAME_REG_UPDATE*/
  100. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_TARGET_LINE*/
  101. {DDP_IRQ_UNKNOW }, /*FRAME_COMPLETE*/
  102. {DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_STOP*/
  103. {DDP_IRQ_RDMA2_REG_UPDATE }, /*IF_CMD_DONE*/
  104. {DDP_IRQ_RDMA2_TARGET_LINE }, /*IF_VSYNC*/
  105. {DDP_IRQ_UNKNOW }, /*AAL_TRIGER*/
  106. {DDP_IRQ_UNKNOW }, /*COLOR_TRIGER*/
  107. },
  108. };
  109. static DDP_MANAGER_CONTEXT* _get_context(void)
  110. {
  111. static int is_context_inited = 0;
  112. static DDP_MANAGER_CONTEXT context;
  113. if (!is_context_inited) {
  114. memset((void*)&context, 0, sizeof(DDP_MANAGER_CONTEXT));
  115. context.mutex_idx = (1<<DISP_MUTEX_DDP_COUNT) - 1;
  116. //mutex_init(&context.mutex_lock);
  117. is_context_inited = 1;
  118. }
  119. return &context;
  120. }
  121. static int path_top_clock_off()
  122. {
  123. int i =0;
  124. DDP_MANAGER_CONTEXT * context = _get_context();
  125. if (context->power_sate) {
  126. for (i=0; i< DDP_MAX_MANAGER_HANDLE; i++) {
  127. if (context->handle_pool[i] != NULL && context->handle_pool[i]->power_sate !=0) {
  128. return 0;
  129. }
  130. }
  131. context->power_sate = 0;
  132. ddp_path_top_clock_off();
  133. }
  134. return 0;
  135. }
  136. static int path_top_clock_on()
  137. {
  138. DDP_MANAGER_CONTEXT * context = _get_context();
  139. if (!context->power_sate) {
  140. context->power_sate = 1;
  141. ddp_path_top_clock_on();
  142. }
  143. return 0;
  144. }
  145. static ddp_path_handle find_handle_by_module(DISP_MODULE_ENUM module)
  146. {
  147. return _get_context()->module_path_table[module];
  148. }
  149. static int dpmgr_module_notify(DISP_MODULE_ENUM module, DISP_PATH_EVENT event)
  150. {
  151. ddp_path_handle handle = find_handle_by_module(module);
  152. return dpmgr_signal_event(handle,event);
  153. }
  154. static int assign_default_irqs_table(DDP_SCENARIO_ENUM scenario,DDP_IRQ_EVENT_MAPPING * irq_events)
  155. {
  156. int idx = 0;
  157. switch (scenario) {
  158. case DDP_SCENARIO_PRIMARY_DISP:
  159. case DDP_SCENARIO_DISPLAY_INTERFACE:
  160. idx = 0;
  161. break;
  162. default:
  163. DISP_LOG_E("unknow scenario %d\n",scenario);
  164. }
  165. DISP_LOG_I("assign default irqs table index %d\n",idx);
  166. memcpy(irq_events,ddp_irq_event_list[idx],sizeof(ddp_irq_event_list[idx]));
  167. return 0;
  168. }
  169. static int acquire_free_bit(unsigned int total)
  170. {
  171. int free_id =0 ;
  172. while (total) {
  173. if (total & 0x1) {
  174. return free_id;
  175. }
  176. total>>=1;
  177. ++free_id;
  178. }
  179. return -1;
  180. }
  181. static int acquire_mutex(DDP_SCENARIO_ENUM scenario)
  182. {
  183. ///: primay use mutex 0
  184. int mutex_id =0 ;
  185. DDP_MANAGER_CONTEXT * content = _get_context();
  186. int mutex_idx_free = content->mutex_idx;
  187. ASSERT(scenario >= 0 && scenario < DDP_SCENARIO_MAX);
  188. while (mutex_idx_free) {
  189. if (mutex_idx_free & 0x1) {
  190. content->mutex_idx &= (~(0x1<<mutex_id));
  191. mutex_id += DISP_MUTEX_DDP_FIRST;
  192. break;
  193. }
  194. mutex_idx_free>>=1;
  195. ++mutex_id;
  196. }
  197. ASSERT(mutex_id < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  198. DISP_LOG_I("scenario %s acquire mutex %d , left mutex 0x%x!\n",
  199. ddp_get_scenario_name(scenario), mutex_id, content->mutex_idx);
  200. return mutex_id;
  201. }
  202. static int release_mutex(int mutex_idx)
  203. {
  204. DDP_MANAGER_CONTEXT * content = _get_context();
  205. ASSERT(mutex_idx < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
  206. content->mutex_idx |= 1<< (mutex_idx-DISP_MUTEX_DDP_FIRST);
  207. DISP_LOG_I("release mutex %d , left mutex 0x%x!\n",
  208. mutex_idx, content->mutex_idx);
  209. return 0;
  210. }
  211. int dpmgr_path_set_video_mode(disp_path_handle dp_handle, int is_vdo_mode)
  212. {
  213. ddp_path_handle handle = NULL;
  214. ASSERT(dp_handle != NULL);
  215. handle = (ddp_path_handle)dp_handle;
  216. handle->mode = is_vdo_mode ? DDP_VIDEO_MODE : DDP_CMD_MODE;
  217. DISP_LOG_I("set scenario %s mode %s\n",ddp_get_scenario_name(handle->scenario),
  218. is_vdo_mode ? "Video Mode":"Cmd Mode");
  219. return 0;
  220. }
  221. disp_path_handle dpmgr_create_path(DDP_SCENARIO_ENUM scenario, cmdqRecHandle cmdq_handle)
  222. {
  223. int i =0;
  224. int module_name ;
  225. ddp_path_handle path_handle = NULL;
  226. int * modules = ddp_get_scenario_list(scenario);
  227. int module_num = ddp_get_module_num(scenario);
  228. DDP_MANAGER_CONTEXT * content = _get_context();
  229. //path_handle = kzalloc(sizeof(uint8_t*) * sizeof(ddp_path_handle_t), GFP_KERNEL);
  230. memset((void*)(&g_handle), 0, sizeof(ddp_path_handle_t));
  231. path_handle = &g_handle;
  232. if (NULL != path_handle) {
  233. path_handle->cmdqhandle = cmdq_handle;
  234. path_handle->scenario = scenario;
  235. path_handle->hwmutexid = acquire_mutex(scenario);
  236. assign_default_irqs_table(scenario,path_handle->irq_event_map);
  237. DISP_LOG_I("create handle 0x%p on scenario %s\n",path_handle,ddp_get_scenario_name(scenario));
  238. for ( i=0; i< module_num; i++) {
  239. module_name = modules[i];
  240. DISP_LOG_V(" scenario %s include module %s\n",ddp_get_scenario_name(scenario),ddp_get_module_name(module_name));
  241. content->module_usage_table[module_name]++;
  242. content->module_path_table[module_name] = path_handle;
  243. }
  244. content->handle_cnt ++;
  245. content->handle_pool[path_handle->hwmutexid] = path_handle;
  246. } else {
  247. DISP_LOG_E("Fail to create handle on scenario %s\n",ddp_get_scenario_name(scenario));
  248. }
  249. return path_handle;
  250. }
  251. int dpmgr_destroy_path(disp_path_handle dp_handle)
  252. {
  253. int i =0;
  254. int module_name ;
  255. ASSERT(dp_handle != NULL);
  256. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  257. int * modules = ddp_get_scenario_list(handle->scenario);
  258. int module_num = ddp_get_module_num(handle->scenario);
  259. DDP_MANAGER_CONTEXT * content = _get_context();
  260. DISP_LOG_I("destroy path handle 0x%x on scenario %s\n",handle,ddp_get_scenario_name(handle->scenario));
  261. if (handle != NULL) {
  262. release_mutex(handle->hwmutexid);
  263. ddp_disconnect_path(handle->scenario,handle->cmdqhandle);
  264. for ( i=0; i< module_num; i++) {
  265. module_name = modules[i];
  266. content->module_usage_table[module_name]--;
  267. content->module_path_table[module_name] = NULL;
  268. }
  269. content->handle_cnt --;
  270. ASSERT(content->handle_cnt >=0);
  271. content->handle_pool[handle->hwmutexid] = NULL;
  272. // kfree(handle);
  273. }
  274. return 0;
  275. }
  276. int dpmgr_path_add_dump(disp_path_handle dp_handle, ENGINE_DUMP engine,int encmdq )
  277. {
  278. return 0;
  279. }
  280. int dpmgr_path_remove_dump(disp_path_handle dp_handle, int encmdq )
  281. {
  282. return 0;
  283. }
  284. int dpmgr_path_set_dst_module(disp_path_handle dp_handle,DISP_MODULE_ENUM dst_module)
  285. {
  286. ASSERT(dp_handle != NULL);
  287. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  288. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  289. DISP_LOG_I("set dst module on scenario %s, module %s\n",
  290. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  291. return ddp_set_dst_module(handle->scenario, dst_module);
  292. }
  293. DISP_MODULE_ENUM dpmgr_path_get_dst_module(disp_path_handle dp_handle)
  294. {
  295. ASSERT(dp_handle != NULL);
  296. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  297. ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
  298. DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
  299. DISP_LOG_I("get dst module on scenario %s, module %s\n",
  300. ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
  301. return dst_module;
  302. }
  303. int dpmgr_path_init(disp_path_handle dp_handle, int encmdq)
  304. {
  305. int i=0;
  306. int module_name ;
  307. ASSERT(dp_handle != NULL);
  308. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  309. int * modules = ddp_get_scenario_list(handle->scenario);
  310. int module_num = ddp_get_module_num(handle->scenario);
  311. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  312. DISP_LOG_I("path init on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  313. //turn off m4u
  314. ddp_path_m4u_off();
  315. //open top clock
  316. ddp_path_top_clock_on();
  317. //seting mutex
  318. ddp_mutex_set(handle->hwmutexid,
  319. handle->scenario,
  320. handle->mode,
  321. cmdqHandle);
  322. //connect path;
  323. ddp_connect_path(handle->scenario,cmdqHandle);
  324. // each module init
  325. for ( i=0; i< module_num; i++) {
  326. module_name = modules[i];
  327. if (ddp_modules_driver[module_name] != 0) {
  328. if (ddp_modules_driver[module_name]->init!= 0) {
  329. DISP_LOG_V("scenario %s init module %s\n",ddp_get_scenario_name(handle->scenario),
  330. ddp_get_module_name(module_name));
  331. ddp_modules_driver[module_name]->init(module_name, cmdqHandle);
  332. }
  333. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  334. ddp_modules_driver[module_name]->set_listener(module_name,dpmgr_module_notify);
  335. }
  336. }
  337. }
  338. //after init this path will power on;
  339. handle->power_sate = 1;
  340. return 0;
  341. }
  342. int dpmgr_path_deinit(disp_path_handle dp_handle, int encmdq)
  343. {
  344. int i=0;
  345. int module_name ;
  346. ASSERT(dp_handle != NULL);
  347. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  348. int * modules = ddp_get_scenario_list(handle->scenario);
  349. int module_num = ddp_get_module_num(handle->scenario);
  350. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  351. DISP_LOG_I("path deinit on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  352. ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
  353. ddp_disconnect_path(handle->scenario, cmdqHandle);
  354. for ( i=0; i< module_num; i++) {
  355. module_name = modules[i];
  356. if (ddp_modules_driver[module_name] != 0) {
  357. if (ddp_modules_driver[module_name]->deinit!= 0) {
  358. DISP_LOG_V("scenario %s deinit module %s\n",ddp_get_scenario_name(handle->scenario),
  359. ddp_get_module_name(module_name));
  360. ddp_modules_driver[module_name]->deinit(module_name, cmdqHandle);
  361. }
  362. if (ddp_modules_driver[module_name]->set_listener!= 0) {
  363. ddp_modules_driver[module_name]->set_listener(module_name,NULL);
  364. }
  365. }
  366. }
  367. handle->power_sate = 0;
  368. //close top clock when last path init
  369. path_top_clock_off();
  370. return 0;
  371. }
  372. int dpmgr_path_start(disp_path_handle dp_handle, int encmdq)
  373. {
  374. int i=0;
  375. int module_name ;
  376. ASSERT(dp_handle != NULL);
  377. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  378. int * modules = ddp_get_scenario_list(handle->scenario);
  379. int module_num = ddp_get_module_num(handle->scenario);
  380. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  381. DISP_LOG_V("path start on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  382. for ( i=0; i< module_num; i++) {
  383. module_name = modules[i];
  384. if (ddp_modules_driver[module_name] != 0) {
  385. if (ddp_modules_driver[module_name]->start!= 0) {
  386. DISP_LOG_V("scenario %s start module %s\n",ddp_get_scenario_name(handle->scenario),
  387. ddp_get_module_name(module_name));
  388. ddp_modules_driver[module_name]->start(module_name, cmdqHandle);
  389. }
  390. }
  391. }
  392. return 0;
  393. }
  394. int dpmgr_path_stop(disp_path_handle dp_handle, int encmdq)
  395. {
  396. int i=0;
  397. int module_name ;
  398. ASSERT(dp_handle != NULL);
  399. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  400. int * modules = ddp_get_scenario_list(handle->scenario);
  401. int module_num = ddp_get_module_num(handle->scenario);
  402. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  403. DISP_LOG_I("path stop on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  404. for ( i=0; i< module_num; i++) {
  405. module_name = modules[i];
  406. if (ddp_modules_driver[module_name] != 0) {
  407. if (ddp_modules_driver[module_name]->stop!= 0) {
  408. DISP_LOG_V("scenario %s stop module %s \n",ddp_get_scenario_name(handle->scenario),
  409. ddp_get_module_name(module_name));
  410. ddp_modules_driver[module_name]->stop(module_name, cmdqHandle);
  411. }
  412. }
  413. }
  414. return 0;
  415. }
  416. int dpmgr_path_reset(disp_path_handle dp_handle, int encmdq)
  417. {
  418. int i=0;
  419. int module_name ;
  420. ASSERT(dp_handle != NULL);
  421. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  422. int * modules = ddp_get_scenario_list(handle->scenario);
  423. int module_num = ddp_get_module_num(handle->scenario);
  424. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  425. DISP_LOG_I("path reset on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  426. for ( i=0; i< module_num; i++) {
  427. module_name = modules[i];
  428. if (ddp_modules_driver[module_name] != 0) {
  429. if (ddp_modules_driver[module_name]->reset != 0) {
  430. DISP_LOG_V("scenario %s reset module %s \n",ddp_get_scenario_name(handle->scenario),
  431. ddp_get_module_name(module_name));
  432. ddp_modules_driver[module_name]->reset(module_name, cmdqHandle);
  433. }
  434. }
  435. }
  436. return 0;
  437. }
  438. int dpmgr_path_config(disp_path_handle dp_handle, disp_ddp_path_config * config, int encmdq)
  439. {
  440. int i=0;
  441. int module_name ;
  442. ASSERT(dp_handle != NULL);
  443. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  444. int * modules = ddp_get_scenario_list(handle->scenario);
  445. int module_num = ddp_get_module_num(handle->scenario);
  446. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  447. DISP_LOG_V("path config ovl %d, rdma %d, wdma %d, dst %d on handle 0x%x scenario %s \n",
  448. config->ovl_dirty,
  449. config->rdma_dirty,
  450. config->wdma_dirty,
  451. config->dst_dirty,
  452. handle,
  453. ddp_get_scenario_name(handle->scenario));
  454. memcpy(&handle->last_config, config, sizeof(disp_ddp_path_config));
  455. for ( i=0; i< module_num; i++) {
  456. module_name = modules[i];
  457. if (ddp_modules_driver[module_name] != 0) {
  458. if (ddp_modules_driver[module_name]->config!= 0) {
  459. DISP_LOG_V("scenario %s config module %s \n",ddp_get_scenario_name(handle->scenario),
  460. ddp_get_module_name(module_name));
  461. ddp_modules_driver[module_name]->config(module_name, config, cmdqHandle);
  462. }
  463. }
  464. }
  465. return 0;
  466. }
  467. disp_ddp_path_config *dpmgr_path_get_last_config(disp_path_handle dp_handle)
  468. {
  469. ASSERT(dp_handle != NULL);
  470. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  471. handle->last_config.ovl_dirty =0;
  472. handle->last_config.rdma_dirty =0;
  473. handle->last_config.wdma_dirty =0;
  474. handle->last_config.dst_dirty =0;
  475. return &handle->last_config;
  476. }
  477. int dpmgr_path_build_cmdq(disp_path_handle dp_handle, void *trigger_loop_handle, CMDQ_STATE state)
  478. {
  479. int i=0;
  480. int module_name ;
  481. ASSERT(dp_handle != NULL);
  482. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  483. int * modules = ddp_get_scenario_list(handle->scenario);
  484. int module_num = ddp_get_module_num(handle->scenario);
  485. DISP_LOG_D("path build cmdq on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  486. for ( i=0; i< module_num; i++) {
  487. module_name = modules[i];
  488. if (ddp_modules_driver[module_name] != 0) {
  489. if (ddp_modules_driver[module_name]->build_cmdq!= 0) {
  490. DISP_LOG_D("%s build cmdq, state=%d\n",ddp_get_module_name(module_name), state);
  491. ddp_modules_driver[module_name]->build_cmdq(module_name, trigger_loop_handle, state); // now just 0;
  492. }
  493. }
  494. }
  495. return 0;
  496. }
  497. int dpmgr_path_trigger(disp_path_handle dp_handle, void *trigger_loop_handle, int encmdq)
  498. {
  499. ASSERT(dp_handle != NULL);
  500. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  501. DISP_LOG_V("dpmgr_path_trigger on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  502. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  503. // if(trigger_loop_handle)
  504. //{
  505. // ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  506. //}
  507. //else
  508. {
  509. int i=0;
  510. int * modules = ddp_get_scenario_list(handle->scenario);
  511. int module_num = ddp_get_module_num(handle->scenario);
  512. int module_name ;
  513. //if(encmdq == CMDQ_DISABLE)
  514. {
  515. ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
  516. }
  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]->trigger!= 0) {
  521. DISP_LOG_V("%s trigger\n",ddp_get_module_name(module_name));
  522. ddp_modules_driver[module_name]->trigger(module_name, trigger_loop_handle);
  523. }
  524. }
  525. }
  526. }
  527. return 0;
  528. }
  529. int dpmgr_path_flush(disp_path_handle dp_handle,int encmdq)
  530. {
  531. ASSERT(dp_handle != NULL);
  532. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  533. cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
  534. DISP_LOG_I("path flush on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  535. return ddp_mutex_enable(handle->hwmutexid,handle->scenario,cmdqHandle);
  536. }
  537. int dpmgr_path_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  538. {
  539. int i=0;
  540. int module_name ;
  541. ASSERT(dp_handle != NULL);
  542. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  543. int * modules = ddp_get_scenario_list(handle->scenario);
  544. int module_num = ddp_get_module_num(handle->scenario);
  545. DISP_LOG_I("path power off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  546. for ( i=0; i< module_num; i++) {
  547. module_name = modules[i];
  548. if (ddp_modules_driver[module_name] != 0) {
  549. if (ddp_modules_driver[module_name]->power_off!= 0) {
  550. DISP_LOG_I(" %s power off\n",ddp_get_module_name(module_name));
  551. ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  552. }
  553. }
  554. }
  555. handle->power_sate = 0;
  556. path_top_clock_off();
  557. return 0;
  558. }
  559. int dpmgr_path_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
  560. {
  561. int i=0;
  562. int module_name ;
  563. ASSERT(dp_handle != NULL);
  564. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  565. int * modules = ddp_get_scenario_list(handle->scenario);
  566. int module_num = ddp_get_module_num(handle->scenario);
  567. DISP_LOG_I("path power on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  568. path_top_clock_on();
  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]->power_on!= 0) {
  573. DISP_LOG_I("%s power on\n",ddp_get_module_name(module_name));
  574. ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
  575. }
  576. }
  577. }
  578. //modules on this path will resume power on;
  579. handle->power_sate = 1;
  580. return 0;
  581. }
  582. int dpmgr_path_set_parameter(disp_path_handle dp_handle, int io_evnet, void * data)
  583. {
  584. return 0;
  585. }
  586. int dpmgr_path_get_parameter(disp_path_handle dp_handle,int io_evnet, void * data )
  587. {
  588. return 0;
  589. }
  590. int dpmgr_path_is_idle(disp_path_handle dp_handle)
  591. {
  592. ASSERT(dp_handle != NULL);
  593. return !dpmgr_path_is_busy(dp_handle);
  594. }
  595. int dpmgr_path_is_busy(disp_path_handle dp_handle)
  596. {
  597. int i=0;
  598. int module_name ;
  599. ASSERT(dp_handle != NULL);
  600. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  601. int * modules = ddp_get_scenario_list(handle->scenario);
  602. int module_num = ddp_get_module_num(handle->scenario);
  603. DISP_LOG_V("path check busy on scenario %s\n",ddp_get_scenario_name(handle->scenario));
  604. for ( i=module_num-1; i>=0; i--) {
  605. module_name = modules[i];
  606. if (ddp_modules_driver[module_name] != 0) {
  607. if (ddp_modules_driver[module_name]->is_busy!= 0) {
  608. if (ddp_modules_driver[module_name]->is_busy(module_name)) {
  609. DISP_LOG_V("%s is busy\n", ddp_get_module_name(module_name));
  610. return 1;
  611. }
  612. }
  613. }
  614. }
  615. return 0;
  616. }
  617. int dpmgr_set_lcm_utils(disp_path_handle dp_handle, void *lcm_drv)
  618. {
  619. int i=0;
  620. int module_name ;
  621. ASSERT(dp_handle != NULL);
  622. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  623. int * modules = ddp_get_scenario_list(handle->scenario);
  624. int module_num = ddp_get_module_num(handle->scenario);
  625. DISP_LOG_V("path set lcm drv handle 0x%x\n",handle);
  626. for ( i=0; i< module_num; i++) {
  627. module_name = modules[i];
  628. if (ddp_modules_driver[module_name] != 0) {
  629. if ((ddp_modules_driver[module_name]->set_lcm_utils!= 0)&&lcm_drv) {
  630. DISP_LOG_I("%s set lcm utils\n",ddp_get_module_name(module_name));
  631. ddp_modules_driver[module_name]->set_lcm_utils(module_name, lcm_drv); // now just 0;
  632. }
  633. }
  634. }
  635. return 0;
  636. }
  637. int dpmgr_enable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  638. {
  639. ASSERT(dp_handle != NULL);
  640. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  641. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  642. DISP_LOG_I("enable event on scenario %s, event %d, irtbit 0x%x\n",
  643. ddp_get_scenario_name(handle->scenario),
  644. event,
  645. handle->irq_event_map[event].irq_bit);
  646. if (!wq_handle->init) {
  647. //init_waitqueue_head(&(wq_handle->wq));
  648. wq_handle->init = 1;
  649. wq_handle->data= 0;
  650. wq_handle->event = event;
  651. }
  652. return 0;
  653. }
  654. int dpmgr_map_event_to_irq(disp_path_handle dp_handle, DISP_PATH_EVENT event, DDP_IRQ_BIT irq_bit)
  655. {
  656. ASSERT(dp_handle != NULL);
  657. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  658. DDP_IRQ_EVENT_MAPPING *irq_table = handle->irq_event_map;
  659. if (event < DISP_PATH_EVENT_NUM) {
  660. DISP_LOG_I("map event %d to irq 0x%x on scenario %s\n",event,irq_bit,ddp_get_scenario_name(handle->scenario));
  661. irq_table[event].irq_bit= irq_bit;
  662. return 0;
  663. }
  664. 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));
  665. return -1;
  666. }
  667. int dpmgr_disable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  668. {
  669. ASSERT(dp_handle != NULL);
  670. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  671. DISP_LOG_I("disable event %d on scenario %s \n",event,ddp_get_scenario_name(handle->scenario));
  672. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  673. wq_handle->init = 0;
  674. wq_handle->data= 0;
  675. return 0;
  676. }
  677. int dpmgr_check_status(disp_path_handle dp_handle)
  678. {
  679. int i =0;
  680. int module_name ;
  681. ASSERT(dp_handle != NULL);
  682. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  683. int * modules = ddp_get_scenario_list(handle->scenario);
  684. int module_num = ddp_get_module_num(handle->scenario);
  685. DISP_LOG_I("check status on scenario %s, module_num %d \n",
  686. ddp_get_scenario_name(handle->scenario),module_num);
  687. ddp_check_path(handle->scenario);
  688. ddp_check_mutex(handle->hwmutexid,handle->scenario,
  689. handle->mode);
  690. //ddp_check_signal(handle->scenario);
  691. for ( i=0; i< module_num; i++) {
  692. module_name = modules[i];
  693. ddp_dump_analysis(module_name);
  694. if (i == DISP_MODULE_DSI0 || i == DISP_MODULE_DSI1 || i == DISP_MODULE_DSIDUAL) {
  695. if (ddp_modules_driver[i] != 0) {
  696. if (ddp_modules_driver[i]->dump_info!= 0) {
  697. ddp_modules_driver[i]->dump_info(i, 1);
  698. }
  699. }
  700. }
  701. }
  702. ddp_dump_analysis(DISP_MODULE_CONFIG);
  703. ddp_dump_analysis(DISP_MODULE_MUTEX);
  704. for ( i=0; i< module_num; i++) {
  705. module_name = modules[i];
  706. ddp_dump_reg(module_name);
  707. }
  708. ddp_dump_reg(DISP_MODULE_CONFIG);
  709. ddp_dump_reg(DISP_MODULE_MUTEX);
  710. return 0;
  711. }
  712. int dpmgr_wait_event_timeout(disp_path_handle dp_handle, DISP_PATH_EVENT event, int timeout)
  713. {
  714. int ret = -1;
  715. ASSERT(dp_handle != NULL);
  716. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  717. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  718. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  719. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  720. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  721. if (wq_handle->init) {
  722. //DISP_LOG_V("wait event %d timeout %d on scenario %s\n", event,timeout,ddp_get_scenario_name(handle->scenario));
  723. //should poling
  724. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  725. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,timeout);
  726. }
  727. if (ret > 0) {
  728. //DISP_LOG_V("received event %d left time %d on scenario %s \n", event, ret,ddp_get_scenario_name(handle->scenario));
  729. } else {
  730. DISP_LOG_E("wait %d timeout ret %d on scenario %d \n", event,ret,handle->scenario);
  731. dpmgr_check_status(handle);
  732. }
  733. return ret;
  734. }
  735. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  736. return ret;
  737. }
  738. int dpmgr_wait_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  739. {
  740. int ret = -1;
  741. ASSERT(dp_handle != NULL);
  742. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  743. DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
  744. DDP_IRQ_EVENT_MAPPING *irqmap = handle->irq_event_map;
  745. DISP_MODULE_ENUM module = IRQBIT_MODULE(irqmap[event].irq_bit);
  746. int q_bit = IRQBIT_BIT(irqmap[event].irq_bit);
  747. if (wq_handle->init) {
  748. DISP_LOG_V("wait event %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  749. if (ddp_modules_driver[module] !=0 && ddp_modules_driver[module]->polling_irq != 0) {
  750. ret = ddp_modules_driver[module]->polling_irq(module,q_bit,-1);
  751. }
  752. DISP_LOG_V("received event %d on scenario %s \n", event, ddp_get_scenario_name(handle->scenario));
  753. return ret;
  754. }
  755. DISP_LOG_E("wait event %d not initialized on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  756. return ret;
  757. }
  758. int dpmgr_signal_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
  759. {
  760. ASSERT(dp_handle != NULL);
  761. ddp_path_handle handle = (ddp_path_handle)dp_handle;
  762. DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
  763. if (handle->wq_list[event].init) {
  764. //wq_handle->data = sched_clock();
  765. DISP_LOG_V("wake up evnet %d on scenario %s\n", event,ddp_get_scenario_name(handle->scenario));
  766. //wake_up_interruptible(&(handle->wq_list[event].wq));
  767. }
  768. return 0;
  769. }
  770. static void dpmgr_irq_handler(DISP_MODULE_ENUM module,unsigned int regvalue)
  771. {
  772. int i = 0;
  773. int j = 0;
  774. int irq_bits_num =0;
  775. int irq_bit = 0;
  776. ddp_path_handle handle = NULL;
  777. DISP_PATH_EVENT event = DISP_PATH_EVENT_NONE;
  778. DISP_LOG_V("irq handler module %d, regvalue 0x%x\n", module,regvalue);
  779. handle = find_handle_by_module(module);
  780. if (handle == NULL) {
  781. return;
  782. }
  783. irq_bits_num = ddp_get_module_max_irq_bit(module);
  784. for (i = 0; i<=irq_bits_num; i++) {
  785. if (regvalue & (0x1<<i)) {
  786. irq_bit = (module<<16 | 0x1<<i);
  787. for (j = 0; j < DISP_PATH_EVENT_NUM; j++) {
  788. if (handle->wq_list[j].init && irq_bit == handle->irq_event_map[j].irq_bit) {
  789. //handle->wq_list[j].data =sched_clock();
  790. DISP_LOG_V("irq signal event %d on cycle %llu on scenario %s\n",
  791. event, handle->wq_list[j].data ,ddp_get_scenario_name(handle->scenario));
  792. //wake_up_interruptible(&(handle->wq_list[j].wq));
  793. }
  794. }
  795. }
  796. }
  797. return ;
  798. }
  799. int dpmgr_init(void)
  800. {
  801. DISP_LOG_I("ddp manager init\n");
  802. //return disp_register_irq_callback(dpmgr_irq_handler);
  803. return 0;
  804. }