cmdq_test.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/fs.h>
  4. #include <linux/proc_fs.h>
  5. #include <linux/timer.h>
  6. #include <linux/workqueue.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/kthread.h>
  10. #include <linux/delay.h>
  11. /* #include <mach/mt_clkmgr.h> */
  12. #include <linux/memory.h>
  13. #include "cmdq_record.h"
  14. #include "cmdq_reg.h"
  15. #include "cmdq_core.h"
  16. #include "cmdq_device.h"
  17. #include "cmdq_platform.h"
  18. #include "cmdq_mdp.h"
  19. #include "cmdq_test.h"
  20. #include "cmdq_def.h"
  21. #ifdef CMDQ_SECURE_PATH_SUPPORT
  22. #include "cmdq_sec.h"
  23. #include "cmdq_iwc_sec.h"
  24. #include "cmdq_sec_iwc_common.h"
  25. /* int32_t cmdq_sec_submit_to_secure_world_async_unlocked(uint32_t iwcCommand, */
  26. /* struct TaskStruct *pTask, int32_t thread, CmdqSecFillIwcCB iwcFillCB, void *data); */
  27. #endif
  28. /* test register*/
  29. /* test configuration*/
  30. static DEFINE_MUTEX(gCmdqTestProcLock);
  31. static int32_t gCmdqTestConfig[3] = { 0, 0, 0 }; /* {normal, secure},configData, paraData */
  32. static bool gCmdqTestSecure;
  33. static uint32_t gThreadRunFlag = 1;
  34. #ifdef _CMDQ_TEST_PROC_
  35. static struct proc_dir_entry *gCmdqTestProcEntry;
  36. #endif
  37. /*
  38. fix coding style
  39. the following statements are removed and put in #inlcude"cmdq_test.h"
  40. */
  41. /*extern unsigned long msleep_interruptible(unsigned int msecs);*/
  42. /*extern int32_t cmdq_core_suspend_HW_thread(int32_t thread);*/
  43. /*extern int32_t cmdq_append_command(cmdqRecHandle handle,
  44. enum CMDQ_CODE_ENUM code,
  45. uint32_t argA,
  46. uint32_t argB);*/
  47. /*extern int32_t cmdq_rec_finalize_command(cmdqRecHandle handle, bool loop);*/
  48. static int32_t _test_submit_async(cmdqRecHandle handle, struct TaskStruct **ppTask)
  49. {
  50. struct cmdqCommandStruct desc = {
  51. .scenario = handle->scenario,
  52. .priority = handle->priority,
  53. .engineFlag = handle->engineFlag,
  54. .pVABase = (cmdqU32Ptr_t) (unsigned long)handle->pBuffer,
  55. .blockSize = handle->blockSize,
  56. /* secure path init */
  57. .secData.isSecure = handle->secData.isSecure,
  58. .secData.addrMetadataCount = handle->secData.addrMetadataCount,
  59. .secData.addrMetadataMaxCount = handle->secData.addrMetadataMaxCount,
  60. .secData.addrMetadatas = handle->secData.addrMetadatas,
  61. .secData.waitCookie = handle->secData.waitCookie,
  62. .secData.resetExecCnt = handle->secData.resetExecCnt,
  63. };
  64. return cmdqCoreSubmitTaskAsync(&desc, NULL, 0, ppTask);
  65. }
  66. static void testcase_scenario(void)
  67. {
  68. cmdqRecHandle hRec;
  69. int32_t ret;
  70. int i = 0;
  71. /* make sure each scenario runs properly with empty commands */
  72. for (i = 0; i < CMDQ_MAX_SCENARIO_COUNT; ++i) {
  73. if (cmdq_core_is_request_from_user_space(i))
  74. continue;
  75. CMDQ_LOG("testcase_scenario id:%d\n", i);
  76. cmdqRecCreate((enum CMDQ_SCENARIO_ENUM)i, &hRec);
  77. cmdqRecReset(hRec);
  78. cmdqRecSetSecure(hRec, false);
  79. ret = cmdqRecFlush(hRec);
  80. cmdqRecDestroy(hRec);
  81. }
  82. }
  83. static struct timer_list timer;
  84. static void _testcase_sync_token_timer_func(unsigned long data)
  85. {
  86. CMDQ_MSG("%s\n", __func__);
  87. /* trigger sync event */
  88. CMDQ_MSG("trigger event=0x%08lx\n", (1L << 16) | data);
  89. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | data);
  90. }
  91. #if 0
  92. static void _testcase_sync_token_timer_loop_func(unsigned long data)
  93. {
  94. CMDQ_MSG("%s\n", __func__);
  95. /* trigger sync event */
  96. CMDQ_MSG("trigger event=0x%08lx\n", (1L << 16) | data);
  97. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | data);
  98. /* repeate timeout until user delete it */
  99. mod_timer(&timer, jiffies + msecs_to_jiffies(10));
  100. }
  101. #endif
  102. static void testcase_sync_token(void)
  103. {
  104. cmdqRecHandle hRec;
  105. int32_t ret = 0;
  106. CMDQ_LOG("%s\n", __func__);
  107. do {
  108. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hRec);
  109. cmdqRecReset(hRec);
  110. cmdqRecSetSecure(hRec, gCmdqTestSecure);
  111. /* setup timer to trigger sync token */
  112. setup_timer(&timer, &_testcase_sync_token_timer_func, CMDQ_SYNC_TOKEN_USER_0);
  113. mod_timer(&timer, jiffies + msecs_to_jiffies(1000));
  114. /* wait for sync token */
  115. cmdqRecWait(hRec, CMDQ_SYNC_TOKEN_USER_0);
  116. CMDQ_LOG("start waiting\n");
  117. ret = cmdqRecFlush(hRec);
  118. cmdqRecDestroy(hRec);
  119. CMDQ_LOG("waiting done\n");
  120. /* clear token */
  121. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  122. del_timer(&timer);
  123. } while (0);
  124. CMDQ_LOG("%s, timeout case\n", __func__);
  125. /*
  126. test for timeout
  127. */
  128. do {
  129. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hRec);
  130. cmdqRecReset(hRec);
  131. cmdqRecSetSecure(hRec, gCmdqTestSecure);
  132. /* wait for sync token */
  133. cmdqRecWait(hRec, CMDQ_SYNC_TOKEN_USER_0);
  134. CMDQ_LOG("start waiting which will fail\n");
  135. ret = cmdqRecFlush(hRec);
  136. cmdqRecDestroy(hRec);
  137. CMDQ_LOG("waiting done\n");
  138. /* clear token */
  139. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  140. BUG_ON(ret >= 0);
  141. } while (0);
  142. CMDQ_LOG("%s END\n", __func__);
  143. }
  144. static struct timer_list timer_reqA;
  145. static struct timer_list timer_reqB;
  146. static void testcase_async_suspend_resume(void)
  147. {
  148. cmdqRecHandle hReqA;
  149. struct TaskStruct *pTaskA;
  150. int32_t ret = 0;
  151. CMDQ_MSG("%s\n", __func__);
  152. /* setup timer to trigger sync token */
  153. /*setup_timer(&timer_reqA, &_testcase_sync_token_timer_func, CMDQ_SYNC_TOKEN_USER_0); */
  154. /*mod_timer(&timer_reqA, jiffies + msecs_to_jiffies(300)); */
  155. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  156. do {
  157. /* let this thread wait for user token, then finish */
  158. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hReqA);
  159. cmdqRecReset(hReqA);
  160. cmdqRecSetSecure(hReqA, gCmdqTestSecure);
  161. cmdqRecWait(hReqA, CMDQ_SYNC_TOKEN_USER_0);
  162. cmdq_append_command(hReqA, CMDQ_CODE_EOC, 0, 1);
  163. cmdq_append_command(hReqA, CMDQ_CODE_JUMP, 0, 8);
  164. ret = _test_submit_async(hReqA, &pTaskA);
  165. CMDQ_MSG("%s pTask %p, engine:0x%llx, scenario:%d\n",
  166. __func__, pTaskA, pTaskA->engineFlag, pTaskA->scenario);
  167. CMDQ_MSG("%s start suspend+resume thread 0========\n", __func__);
  168. cmdq_core_suspend_HW_thread(0);
  169. CMDQ_REG_SET32(CMDQ_THR_SUSPEND_TASK(0), 0x00);
  170. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_SYNC_TOKEN_USER_0);
  171. msleep_interruptible(500);
  172. CMDQ_MSG("%s start wait A========\n", __func__);
  173. ret = cmdqCoreWaitAndReleaseTask(pTaskA, 500);
  174. } while (0);
  175. /* clear token */
  176. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  177. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_1);
  178. cmdqRecDestroy(hReqA);
  179. /*del_timer(&timer_reqA); */
  180. CMDQ_MSG("%s END\n", __func__);
  181. }
  182. static void testcase_errors(void)
  183. {
  184. cmdqRecHandle hReq;
  185. cmdqRecHandle hLoop;
  186. struct TaskStruct *pTask;
  187. int32_t ret;
  188. const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  189. const uint32_t UNKNOWN_OP = 0x50;
  190. uint32_t *pCommand;
  191. ret = 0;
  192. do {
  193. /* SW timeout */
  194. CMDQ_MSG("%s line:%d\n", __func__, __LINE__);
  195. cmdqRecCreate(CMDQ_SCENARIO_TRIGGER_LOOP, &hLoop);
  196. cmdqRecReset(hLoop);
  197. cmdqRecSetSecure(hLoop, false);
  198. cmdqRecPoll(hLoop, CMDQ_TEST_DISP_PWM0_DUMMY_PA, 1, 0xFFFFFFFF);
  199. cmdqRecStartLoop(hLoop);
  200. CMDQ_MSG("=============== INIFINITE Wait ===================\n");
  201. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_ENG_MDP_TDSHP0);
  202. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &hReq);
  203. /* turn on ALL engine flag to test dump */
  204. for (ret = 0; ret < CMDQ_MAX_ENGINE_COUNT; ++ret)
  205. hReq->engineFlag |= 1LL << ret;
  206. cmdqRecReset(hReq);
  207. cmdqRecSetSecure(hReq, gCmdqTestSecure);
  208. cmdqRecWait(hReq, CMDQ_ENG_MDP_TDSHP0);
  209. cmdqRecFlush(hReq);
  210. CMDQ_MSG("=============== INIFINITE JUMP ===================\n");
  211. /* HW timeout */
  212. CMDQ_MSG("%s line:%d\n", __func__, __LINE__);
  213. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_ENG_MDP_TDSHP0);
  214. cmdqRecReset(hReq);
  215. cmdqRecSetSecure(hReq, gCmdqTestSecure);
  216. cmdqRecWait(hReq, CMDQ_ENG_MDP_TDSHP0);
  217. cmdq_append_command(hReq, CMDQ_CODE_JUMP, 0, 8); /* JUMP to connect tasks */
  218. ret = _test_submit_async(hReq, &pTask);
  219. msleep_interruptible(500);
  220. ret = cmdqCoreWaitAndReleaseTask(pTask, 8000);
  221. CMDQ_MSG("================POLL INIFINITE====================\n");
  222. CMDQ_MSG("testReg: %lx\n", MMSYS_DUMMY_REG);
  223. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0x0);
  224. cmdqRecReset(hReq);
  225. cmdqRecSetSecure(hReq, gCmdqTestSecure);
  226. cmdqRecPoll(hReq, CMDQ_TEST_DISP_PWM0_DUMMY_PA, 1, 0xFFFFFFFF);
  227. cmdqRecFlush(hReq);
  228. CMDQ_MSG("=================INVALID INSTR=================\n");
  229. /* invalid instruction */
  230. CMDQ_MSG("%s line:%d\n", __func__, __LINE__);
  231. cmdqRecReset(hReq);
  232. cmdqRecSetSecure(hReq, gCmdqTestSecure);
  233. cmdq_append_command(hReq, CMDQ_CODE_JUMP, -1, 0);
  234. cmdqRecFlush(hReq);
  235. CMDQ_MSG("=================INVALID INSTR: UNKNOWN OP(0x%x)=================\n",
  236. UNKNOWN_OP);
  237. CMDQ_MSG("%s line:%d\n", __func__, __LINE__);
  238. /* invalid instruction is asserted when unknown OP */
  239. cmdqRecReset(hReq);
  240. cmdqRecSetSecure(hReq, gCmdqTestSecure);
  241. {
  242. pCommand = (uint32_t *) ((uint8_t *) hReq->pBuffer + hReq->blockSize);
  243. *pCommand++ = 0x0;
  244. *pCommand++ = (UNKNOWN_OP << 24);
  245. hReq->blockSize += 8;
  246. }
  247. cmdqRecFlush(hReq);
  248. } while (0);
  249. cmdqRecDestroy(hReq);
  250. cmdqRecDestroy(hLoop);
  251. CMDQ_MSG("%s END\n", __func__);
  252. }
  253. static int32_t finishCallback(unsigned long data)
  254. {
  255. CMDQ_LOG("callback() with data=0x%08lx\n", data);
  256. return 0;
  257. }
  258. static void testcase_fire_and_forget(void)
  259. {
  260. cmdqRecHandle hReqA, hReqB;
  261. CMDQ_MSG("%s BEGIN\n", __func__);
  262. do {
  263. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &hReqA);
  264. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &hReqB);
  265. cmdqRecReset(hReqA);
  266. cmdqRecReset(hReqB);
  267. cmdqRecSetSecure(hReqA, gCmdqTestSecure);
  268. cmdqRecSetSecure(hReqB, gCmdqTestSecure);
  269. CMDQ_MSG("%s %d\n", __func__, __LINE__);
  270. cmdqRecFlushAsync(hReqA);
  271. CMDQ_MSG("%s %d\n", __func__, __LINE__);
  272. cmdqRecFlushAsyncCallback(hReqB, finishCallback, 443);
  273. CMDQ_MSG("%s %d\n", __func__, __LINE__);
  274. } while (0);
  275. cmdqRecDestroy(hReqA);
  276. cmdqRecDestroy(hReqB);
  277. CMDQ_MSG("%s END\n", __func__);
  278. }
  279. static struct timer_list timer_reqA;
  280. static struct timer_list timer_reqB;
  281. static void testcase_async_request(void)
  282. {
  283. cmdqRecHandle hReqA, hReqB;
  284. struct TaskStruct *pTaskA, *pTaskB;
  285. int32_t ret = 0;
  286. CMDQ_MSG("%s\n", __func__);
  287. /* setup timer to trigger sync token */
  288. setup_timer(&timer_reqA, &_testcase_sync_token_timer_func, CMDQ_SYNC_TOKEN_USER_0);
  289. mod_timer(&timer_reqA, jiffies + msecs_to_jiffies(1000));
  290. setup_timer(&timer_reqB, &_testcase_sync_token_timer_func, CMDQ_SYNC_TOKEN_USER_1);
  291. /* mod_timer(&timer_reqB, jiffies + msecs_to_jiffies(1300)); */
  292. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  293. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_1);
  294. do {
  295. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hReqA);
  296. cmdqRecReset(hReqA);
  297. cmdqRecSetSecure(hReqA, gCmdqTestSecure);
  298. cmdqRecWait(hReqA, CMDQ_SYNC_TOKEN_USER_0);
  299. cmdq_append_command(hReqA, CMDQ_CODE_EOC, 0, 1);
  300. cmdq_append_command(hReqA, CMDQ_CODE_JUMP, 0, 8); /* JUMP to connect tasks */
  301. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hReqB);
  302. cmdqRecReset(hReqB);
  303. cmdqRecSetSecure(hReqB, gCmdqTestSecure);
  304. cmdqRecWait(hReqB, CMDQ_SYNC_TOKEN_USER_1);
  305. cmdq_append_command(hReqB, CMDQ_CODE_EOC, 0, 1);
  306. cmdq_append_command(hReqB, CMDQ_CODE_JUMP, 0, 8); /* JUMP to connect tasks */
  307. ret = _test_submit_async(hReqA, &pTaskA);
  308. ret = _test_submit_async(hReqB, &pTaskB);
  309. CMDQ_MSG("%s start wait sleep========\n", __func__);
  310. msleep_interruptible(500);
  311. CMDQ_MSG("%s start wait A========\n", __func__);
  312. ret = cmdqCoreWaitAndReleaseTask(pTaskA, 500);
  313. CMDQ_MSG("%s start wait B, this should timeout========\n", __func__);
  314. ret = cmdqCoreWaitAndReleaseTask(pTaskB, 600);
  315. CMDQ_MSG("%s wait B get %d ========\n", __func__, ret);
  316. } while (0);
  317. /* clear token */
  318. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  319. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_1);
  320. cmdqRecDestroy(hReqA);
  321. cmdqRecDestroy(hReqB);
  322. del_timer(&timer_reqA);
  323. del_timer(&timer_reqB);
  324. CMDQ_MSG("%s END\n", __func__);
  325. }
  326. static void testcase_multiple_async_request(void)
  327. {
  328. #define TEST_REQ_COUNT 30
  329. cmdqRecHandle hReq[TEST_REQ_COUNT] = { 0 };
  330. struct TaskStruct *pTask[TEST_REQ_COUNT] = { 0 };
  331. int32_t ret = 0;
  332. int i;
  333. CMDQ_MSG("%s\n", __func__);
  334. /* setup timer to trigger sync token */
  335. setup_timer(&timer_reqA, &_testcase_sync_token_timer_func, CMDQ_SYNC_TOKEN_USER_0);
  336. mod_timer(&timer_reqA, jiffies + msecs_to_jiffies(10));
  337. /* Queue multiple async request */
  338. /* to test dynamic task allocation */
  339. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  340. for (i = 0; i < TEST_REQ_COUNT; ++i) {
  341. ret = cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &hReq[i]);
  342. if (0 > ret) {
  343. CMDQ_ERR("%s cmdqRecCreate failed:%d, i:%d\n ", __func__, ret, i);
  344. continue;
  345. }
  346. cmdqRecReset(hReq[i]);
  347. cmdqRecSetSecure(hReq[i], gCmdqTestSecure);
  348. cmdqRecWait(hReq[i], CMDQ_SYNC_TOKEN_USER_0);
  349. cmdq_rec_finalize_command(hReq[i], false);
  350. /* higher priority for later tasks */
  351. hReq[i]->priority = i;
  352. ret = _test_submit_async(hReq[i], &pTask[i]);
  353. CMDQ_MSG("create task[%2d]=0x%p done\n", i, pTask[i]);
  354. }
  355. /* release token and wait them */
  356. for (i = 0; i < TEST_REQ_COUNT; ++i) {
  357. if (NULL == pTask[i]) {
  358. CMDQ_ERR("%s pTask[%d] is NULL\n ", __func__, i);
  359. continue;
  360. }
  361. #if 0
  362. mod_timer(&timer_reqA, jiffies + msecs_to_jiffies(10));
  363. msleep_interruptible(100);
  364. #else
  365. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_SYNC_TOKEN_USER_0);
  366. #endif
  367. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_SYNC_TOKEN_USER_0);
  368. CMDQ_MSG("wait 0x%p========\n", pTask[i]);
  369. ret = cmdqCoreWaitAndReleaseTask(pTask[i], 3000);
  370. cmdqRecDestroy(hReq[i]);
  371. }
  372. /* clear token */
  373. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  374. del_timer(&timer_reqA);
  375. CMDQ_MSG("%s END\n", __func__);
  376. }
  377. static void testcase_async_request_partial_engine(void)
  378. {
  379. int32_t ret = 0;
  380. int i;
  381. enum CMDQ_SCENARIO_ENUM scn[] = { CMDQ_SCENARIO_PRIMARY_DISP,
  382. CMDQ_SCENARIO_JPEG_DEC,
  383. CMDQ_SCENARIO_PRIMARY_MEMOUT,
  384. CMDQ_SCENARIO_SUB_DISP,
  385. CMDQ_SCENARIO_DEBUG,
  386. };
  387. struct timer_list timers[sizeof(scn) / sizeof(scn[0])];
  388. cmdqRecHandle hReq[(sizeof(scn) / sizeof(scn[0]))] = { 0 };
  389. struct TaskStruct *pTasks[(sizeof(scn) / sizeof(scn[0]))] = { 0 };
  390. CMDQ_MSG("%s\n", __func__);
  391. /* setup timer to trigger sync token */
  392. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i) {
  393. setup_timer(&timers[i], &_testcase_sync_token_timer_func,
  394. CMDQ_SYNC_TOKEN_USER_0 + i);
  395. mod_timer(&timers[i], jiffies + msecs_to_jiffies(400 * (1 + i)));
  396. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0 + i);
  397. cmdqRecCreate(scn[i], &hReq[i]);
  398. cmdqRecReset(hReq[i]);
  399. cmdqRecSetSecure(hReq[i], false);
  400. cmdqRecWait(hReq[i], CMDQ_SYNC_TOKEN_USER_0 + i);
  401. cmdq_rec_finalize_command(hReq[i], false);
  402. CMDQ_MSG("TEST: SUBMIT scneario %d\n", scn[i]);
  403. ret = _test_submit_async(hReq[i], &pTasks[i]);
  404. }
  405. /* wait for task completion */
  406. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i)
  407. ret = cmdqCoreWaitAndReleaseTask(pTasks[i], msecs_to_jiffies(3000));
  408. /* clear token */
  409. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i) {
  410. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0 + i);
  411. cmdqRecDestroy(hReq[i]);
  412. del_timer(&timers[i]);
  413. }
  414. CMDQ_MSG("%s END\n", __func__);
  415. }
  416. static void _testcase_unlock_all_event_timer_func(unsigned long data)
  417. {
  418. uint32_t token = 0;
  419. CMDQ_MSG("%s\n", __func__);
  420. /* trigger sync event */
  421. CMDQ_MSG("trigger events\n");
  422. for (token = 0; token < CMDQ_SYNC_TOKEN_MAX; ++token) {
  423. /* 3 threads waiting, so update 3 times */
  424. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | token);
  425. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | token);
  426. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | token);
  427. }
  428. }
  429. static void testcase_sync_token_threaded(void)
  430. {
  431. enum CMDQ_SCENARIO_ENUM scn[] = { CMDQ_SCENARIO_PRIMARY_DISP, /* high prio */
  432. CMDQ_SCENARIO_JPEG_DEC, /* normal prio */
  433. CMDQ_SCENARIO_TRIGGER_LOOP /* normal prio */
  434. };
  435. int32_t ret = 0;
  436. int i = 0;
  437. uint32_t token = 0;
  438. struct timer_list eventTimer;
  439. cmdqRecHandle hReq[(sizeof(scn) / sizeof(scn[0]))] = { 0 };
  440. struct TaskStruct *pTasks[(sizeof(scn) / sizeof(scn[0]))] = { 0 };
  441. CMDQ_MSG("%s\n", __func__);
  442. /* setup timer to trigger sync token */
  443. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i) {
  444. setup_timer(&eventTimer, &_testcase_unlock_all_event_timer_func, 0);
  445. mod_timer(&eventTimer, jiffies + msecs_to_jiffies(500));
  446. /*
  447. 3 threads, all wait & clear 511 events
  448. */
  449. cmdqRecCreate(scn[i], &hReq[i]);
  450. cmdqRecReset(hReq[i]);
  451. cmdqRecSetSecure(hReq[i], false);
  452. for (token = 0; token < CMDQ_SYNC_TOKEN_MAX; ++token)
  453. cmdqRecWait(hReq[i], (enum CMDQ_EVENT_ENUM)token);
  454. cmdq_rec_finalize_command(hReq[i], false);
  455. CMDQ_MSG("TEST: SUBMIT scneario %d\n", scn[i]);
  456. ret = _test_submit_async(hReq[i], &pTasks[i]);
  457. }
  458. /* wait for task completion */
  459. msleep_interruptible(1000);
  460. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i)
  461. ret = cmdqCoreWaitAndReleaseTask(pTasks[i], msecs_to_jiffies(5000));
  462. /* clear token */
  463. for (i = 0; i < (sizeof(scn) / sizeof(scn[0])); ++i)
  464. cmdqRecDestroy(hReq[i]);
  465. del_timer(&eventTimer);
  466. CMDQ_MSG("%s END\n", __func__);
  467. }
  468. static struct timer_list g_loopTimer;
  469. static int g_loopIter;
  470. static cmdqRecHandle hLoopReq;
  471. static void _testcase_loop_timer_func(unsigned long data)
  472. {
  473. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | data);
  474. mod_timer(&g_loopTimer, jiffies + msecs_to_jiffies(300));
  475. g_loopIter++;
  476. }
  477. static void testcase_loop(void)
  478. {
  479. int status = 0;
  480. CMDQ_MSG("%s\n", __func__);
  481. cmdqRecCreate(CMDQ_SCENARIO_TRIGGER_LOOP, &hLoopReq);
  482. cmdqRecReset(hLoopReq);
  483. cmdqRecSetSecure(hLoopReq, false);
  484. cmdqRecWait(hLoopReq, CMDQ_SYNC_TOKEN_USER_0);
  485. setup_timer(&g_loopTimer, &_testcase_loop_timer_func, CMDQ_SYNC_TOKEN_USER_0);
  486. mod_timer(&g_loopTimer, jiffies + msecs_to_jiffies(300));
  487. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  488. g_loopIter = 0;
  489. /* should success */
  490. status = cmdqRecStartLoop(hLoopReq);
  491. BUG_ON(status != 0);
  492. /* should fail because already started */
  493. CMDQ_MSG("============testcase_loop start loop\n");
  494. status = cmdqRecStartLoop(hLoopReq);
  495. BUG_ON(status >= 0);
  496. cmdqRecDumpCommand(hLoopReq);
  497. /* WAIT */
  498. while (g_loopIter < 20)
  499. msleep_interruptible(2000);
  500. msleep_interruptible(2000);
  501. CMDQ_MSG("============testcase_loop stop timer\n");
  502. cmdqRecDestroy(hLoopReq);
  503. del_timer(&g_loopTimer);
  504. CMDQ_MSG("%s\n", __func__);
  505. }
  506. static unsigned long gLoopCount = 0L;
  507. static void _testcase_trigger_func(unsigned long data)
  508. {
  509. /* trigger sync event */
  510. CMDQ_MSG("_testcase_trigger_func");
  511. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_SYNC_TOKEN_USER_0);
  512. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_SYNC_TOKEN_USER_1);
  513. /* start again */
  514. mod_timer(&timer, jiffies + msecs_to_jiffies(1000));
  515. gLoopCount++;
  516. }
  517. #if 0
  518. static void leave_loop_func(struct work_struct *w)
  519. {
  520. CMDQ_MSG("leave_loop_func: cancel loop");
  521. cmdqRecStopLoop(hLoopConfig);
  522. hLoopConfig = NULL;
  523. }
  524. DECLARE_WORK(leave_loop, leave_loop_func);
  525. int32_t my_irq_callback(unsigned long data)
  526. {
  527. CMDQ_MSG("%s data=%d\n", __func__, data);
  528. ++gLoopCount;
  529. switch (data) {
  530. case 1:
  531. if (gLoopCount < 20)
  532. return 0;
  533. else
  534. return -1;
  535. break;
  536. case 2:
  537. if (gLoopCount > 40) {
  538. /* insert stopping cal */
  539. schedule_work(&leave_loop);
  540. }
  541. break;
  542. }
  543. return 0;
  544. }
  545. #endif
  546. static void testcase_trigger_thread(void)
  547. {
  548. cmdqRecHandle hTrigger, hConfig;
  549. int32_t ret = 0;
  550. int index = 0;
  551. CMDQ_MSG("%s\n", __func__);
  552. /* setup timer to trigger sync token for every 1 sec */
  553. setup_timer(&timer, &_testcase_trigger_func, 0);
  554. mod_timer(&timer, jiffies + msecs_to_jiffies(1000));
  555. do {
  556. /* THREAD 1, trigger loop */
  557. cmdqRecCreate(CMDQ_SCENARIO_TRIGGER_LOOP, &hTrigger);
  558. cmdqRecReset(hTrigger);
  559. /* * WAIT and CLEAR config dirty */
  560. /*cmdqRecWait(hTrigger, CMDQ_SYNC_TOKEN_CONFIG_DIRTY); */
  561. /* * WAIT and CLEAR TE */
  562. /*cmdqRecWait(hTrigger, CMDQ_EVENT_MDP_DSI0_TE_SOF); */
  563. /* * WAIT and CLEAR stream done */
  564. /*cmdqRecWait(hTrigger, CMDQ_EVENT_MUTEX0_STREAM_EOF); */
  565. /* * WRITE mutex enable */
  566. /*cmdqRecWait(hTrigger, MM_MUTEX_BASE_PA + 0x20); */
  567. cmdqRecWait(hTrigger, CMDQ_SYNC_TOKEN_USER_0);
  568. /* * RUN forever but each IRQ trigger is bypass to my_irq_callback */
  569. ret = cmdqRecStartLoop(hTrigger);
  570. /* THREAD 2, config thread */
  571. cmdqRecCreate(CMDQ_SCENARIO_JPEG_DEC, &hConfig);
  572. hConfig->priority = CMDQ_THR_PRIO_NORMAL;
  573. cmdqRecReset(hConfig);
  574. /* insert tons of instructions */
  575. for (index = 0; index < 10; ++index)
  576. cmdq_append_command(hConfig, CMDQ_CODE_MOVE, 0, 0x1);
  577. ret = cmdqRecFlush(hConfig);
  578. CMDQ_MSG("flush 0\n");
  579. hConfig->priority = CMDQ_THR_PRIO_DISPLAY_CONFIG;
  580. cmdqRecReset(hConfig);
  581. /* insert tons of instructions */
  582. for (index = 0; index < 10; ++index)
  583. cmdq_append_command(hConfig, CMDQ_CODE_MOVE, 0, 0x1);
  584. ret = cmdqRecFlush(hConfig);
  585. CMDQ_MSG("flush 1\n");
  586. cmdqRecReset(hConfig);
  587. /* insert tons of instructions */
  588. for (index = 0; index < 500; ++index)
  589. cmdq_append_command(hConfig, CMDQ_CODE_MOVE, 0, 0x1);
  590. ret = cmdqRecFlush(hConfig);
  591. CMDQ_MSG("flush 2\n");
  592. /* WAIT */
  593. while (gLoopCount < 20)
  594. msleep_interruptible(2000);
  595. } while (0);
  596. del_timer(&timer);
  597. cmdqRecDestroy(hTrigger);
  598. cmdqRecDestroy(hConfig);
  599. CMDQ_MSG("%s END\n", __func__);
  600. }
  601. static void testcase_prefetch_scenarios(void)
  602. {
  603. /* make sure both prefetch and non-prefetch cases */
  604. /* handle 248+ instructions properly */
  605. cmdqRecHandle hConfig;
  606. int32_t ret = 0;
  607. int index = 0, scn = 0;
  608. const int INSTRUCTION_COUNT = 500;
  609. CMDQ_MSG("%s\n", __func__);
  610. /* make sure each scenario runs properly with 248+ commands */
  611. for (scn = 0; scn < CMDQ_MAX_SCENARIO_COUNT; ++scn) {
  612. if (cmdq_core_is_request_from_user_space(scn))
  613. continue;
  614. CMDQ_MSG("testcase_prefetch_scenarios scenario:%d\n", scn);
  615. cmdqRecCreate((enum CMDQ_SCENARIO_ENUM)scn, &hConfig);
  616. cmdqRecReset(hConfig);
  617. /* insert tons of instructions */
  618. for (index = 0; index < INSTRUCTION_COUNT; ++index)
  619. cmdq_append_command(hConfig, CMDQ_CODE_MOVE, 0, 0x1);
  620. ret = cmdqRecFlush(hConfig);
  621. BUG_ON(ret < 0);
  622. cmdqRecDestroy(hConfig);
  623. }
  624. CMDQ_MSG("%s END\n", __func__);
  625. }
  626. /*extern void cmdq_core_reset_hw_events(void);*/
  627. void testcase_clkmgr_impl(enum CMDQ_CLK_ENUM gateId,
  628. char *name,
  629. const unsigned long testWriteReg,
  630. const uint32_t testWriteValue,
  631. const unsigned long testReadReg, const bool verifyWriteResult)
  632. {
  633. /* clkmgr is not available on FPGA */
  634. #ifndef CONFIG_MTK_FPGA
  635. uint32_t value = 0;
  636. CMDQ_MSG("====== %s:%s ======\n", __func__, name);
  637. CMDQ_VERBOSE("clk:%d, name:%s\n", gateId, name);
  638. CMDQ_VERBOSE("write reg(0x%lx) to 0x%08x, read reg(0x%lx), verify write result:%d\n",
  639. testWriteReg, testWriteValue, testReadReg, verifyWriteResult);
  640. /* turn on CLK, function should work */
  641. CMDQ_MSG("enable_clock\n");
  642. /* CCF */
  643. /* enable_clock(MT_CG_INFRA_GCE, "CMDQ_TEST"); */
  644. cmdq_core_enable_ccf_clk(CMDQ_CLK_INFRA_GCE);
  645. CMDQ_REG_SET32(testWriteReg, testWriteValue);
  646. value = CMDQ_REG_GET32(testReadReg);
  647. if ((true == verifyWriteResult) && (testWriteValue != value)) {
  648. CMDQ_ERR("when enable clock reg(0x%lx) = 0x%08x\n", testReadReg, value);
  649. /* BUG(); */
  650. }
  651. /* turn off CLK, function should not work and access register should not cause hang */
  652. CMDQ_MSG("disable_clock\n");
  653. /* CCF */
  654. /* disable_clock(MT_CG_INFRA_GCE, "CMDQ_TEST"); */
  655. cmdq_core_disable_ccf_clk(CMDQ_CLK_INFRA_GCE);
  656. CMDQ_REG_SET32(testWriteReg, testWriteValue);
  657. value = CMDQ_REG_GET32(testReadReg);
  658. if (0 != value) {
  659. CMDQ_ERR("when disable clock reg(0x%lx) = 0x%08x\n", testReadReg, value);
  660. /* BUG(); */
  661. }
  662. #endif
  663. }
  664. static void testcase_clkmgr(void)
  665. {
  666. CMDQ_MSG("%s\n", __func__);
  667. testcase_clkmgr_impl(CMDQ_CLK_INFRA_GCE,
  668. "CMDQ_TEST",
  669. CMDQ_GPR_R32(CMDQ_DATA_REG_DEBUG),
  670. 0xFFFFDEAD, CMDQ_GPR_R32(CMDQ_DATA_REG_DEBUG), true);
  671. testcase_clkmgr_mdp();
  672. CMDQ_MSG("%s END\n", __func__);
  673. }
  674. static void testcase_dram_access(void)
  675. {
  676. #ifdef CMDQ_GPR_SUPPORT
  677. cmdqRecHandle handle;
  678. uint32_t *regResults;
  679. dma_addr_t regResultsMVA;
  680. dma_addr_t dstMVA;
  681. uint32_t argA;
  682. uint32_t subsysCode;
  683. uint32_t *pCmdEnd = NULL;
  684. unsigned long long data64;
  685. CMDQ_MSG("%s\n", __func__);
  686. regResults = dma_alloc_coherent(cmdq_dev_get(),
  687. sizeof(uint32_t) * 2, &regResultsMVA, GFP_KERNEL);
  688. /* set up intput */
  689. regResults[0] = 0xdeaddead; /* this is read-from */
  690. regResults[1] = 0xffffffff; /* this is write-to */
  691. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  692. cmdqRecReset(handle);
  693. cmdqRecSetSecure(handle, gCmdqTestSecure);
  694. /*
  695. READ from DRAME: register to read from
  696. note that we force convert to physical reg address.
  697. if it is already physical address, it won't be affected (at least on this platform) */
  698. argA = CMDQ_TEST_DISP_PWM0_DUMMY_PA;
  699. subsysCode = cmdq_subsys_from_phys_addr(argA);
  700. pCmdEnd = (uint32_t *) (((char *)handle->pBuffer) + handle->blockSize);
  701. CMDQ_MSG("pCmdEnd initial=0x%p, reg MVA=%pa, size=%d\n",
  702. pCmdEnd, &regResultsMVA, handle->blockSize);
  703. /* Move &(regResults[0]) to CMDQ_DATA_REG_DEBUG_DST */
  704. *pCmdEnd = (uint32_t) CMDQ_PHYS_TO_AREG(regResultsMVA);
  705. pCmdEnd += 1;
  706. *pCmdEnd = (CMDQ_CODE_MOVE << 24) |
  707. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  708. ((regResultsMVA >> 32) & 0xffff) |
  709. #endif
  710. ((CMDQ_DATA_REG_DEBUG_DST & 0x1f) << 16) | (4 << 21);
  711. pCmdEnd += 1;
  712. /* WRITE to DRAME: */
  713. /* from src_addr(CMDQ_DATA_REG_DEBUG_DST) to external RAM (regResults[1]) */
  714. /* Read data from *CMDQ_DATA_REG_DEBUG_DST to CMDQ_DATA_REG_DEBUG */
  715. *pCmdEnd = CMDQ_DATA_REG_DEBUG;
  716. pCmdEnd += 1;
  717. /*1 1 0 */
  718. *pCmdEnd =
  719. (CMDQ_CODE_READ << 24) | (0 & 0xffff) | ((CMDQ_DATA_REG_DEBUG_DST & 0x1f) << 16) | (6 <<
  720. 21);
  721. pCmdEnd += 1;
  722. /* Load ddst_addr to GPR: Move &(regResults[1]) to CMDQ_DATA_REG_DEBUG_DST */
  723. dstMVA = regResultsMVA + 4; /* note regResults is a uint32_t array */
  724. *pCmdEnd = ((uint32_t) dstMVA);
  725. pCmdEnd += 1;
  726. *pCmdEnd = (CMDQ_CODE_MOVE << 24) |
  727. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  728. ((dstMVA >> 32) & 0xffff) |
  729. #endif
  730. ((CMDQ_DATA_REG_DEBUG_DST & 0x1f) << 16) | (4 << 21);
  731. pCmdEnd += 1;
  732. /* Write from CMDQ_DATA_REG_DEBUG to *CMDQ_DATA_REG_DEBUG_DST */
  733. *pCmdEnd = CMDQ_DATA_REG_DEBUG;
  734. pCmdEnd += 1;
  735. /*1 1 0 */
  736. *pCmdEnd =
  737. (CMDQ_CODE_WRITE << 24) | (0 & 0xffff) | ((CMDQ_DATA_REG_DEBUG_DST & 0x1f) << 16) | (6
  738. <<
  739. 21);
  740. pCmdEnd += 1;
  741. handle->blockSize += 4 * 8; /* 4 * 64-bit instructions */
  742. cmdqRecDumpCommand(handle);
  743. cmdqRecFlush(handle);
  744. cmdqRecDumpCommand(handle);
  745. cmdqRecDestroy(handle);
  746. data64 = 0LL;
  747. data64 = CMDQ_REG_GET64_GPR_PX(CMDQ_DATA_REG_DEBUG_DST);
  748. CMDQ_MSG("regResults=[0x%08x, 0x%08x]\n", regResults[0], regResults[1]);
  749. CMDQ_MSG("CMDQ_DATA_REG_DEBUG=0x%08x, CMDQ_DATA_REG_DEBUG_DST=0x%llx\n",
  750. CMDQ_REG_GET32(CMDQ_GPR_R32(CMDQ_DATA_REG_DEBUG)), data64);
  751. if (regResults[1] != regResults[0])
  752. CMDQ_ERR("ERROR!!!!!!\n");
  753. else
  754. CMDQ_MSG("OK!!!!!!\n");
  755. dma_free_coherent(cmdq_dev_get(), 2 * sizeof(uint32_t), regResults, regResultsMVA);
  756. CMDQ_MSG("%s END\n", __func__);
  757. #else
  758. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  759. #endif
  760. }
  761. static void testcase_long_command(void)
  762. {
  763. int i;
  764. cmdqRecHandle handle;
  765. uint32_t data;
  766. const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  767. CMDQ_MSG("%s\n", __func__);
  768. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0xdeaddead);
  769. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  770. cmdqRecReset(handle);
  771. cmdqRecSetSecure(handle, gCmdqTestSecure);
  772. /* build a 64KB instruction buffer */
  773. for (i = 0; i < 64 * 1024 / 8; ++i)
  774. cmdqRecReadToDataRegister(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA,
  775. CMDQ_DATA_REG_PQ_COLOR);
  776. cmdqRecFlush(handle);
  777. cmdqRecDestroy(handle);
  778. /* verify data */
  779. do {
  780. if (true == gCmdqTestSecure) {
  781. CMDQ_LOG("%s, timeout case in secure path\n", __func__);
  782. break;
  783. }
  784. data = CMDQ_REG_GET32(CMDQ_GPR_R32(CMDQ_DATA_REG_PQ_COLOR));
  785. if (data != 0xdeaddead)
  786. CMDQ_ERR("TEST FAIL: reg value is 0x%08x\n", data);
  787. } while (0);
  788. CMDQ_MSG("%s END\n", __func__);
  789. }
  790. static void testcase_perisys_apb(void)
  791. {
  792. #ifdef CMDQ_GPR_SUPPORT
  793. /* write value to PERISYS register
  794. we use MSDC debug to test:
  795. write SEL, read OUT. */
  796. const uint32_t MSDC_SW_DBG_SEL_PA = 0x11230000 + 0xA0;
  797. const uint32_t MSDC_SW_DBG_OUT_PA = 0x11230000 + 0xA4;
  798. const uint32_t AUDIO_TOP_CONF0_PA = 0x11220000;
  799. const uint32_t AUDIO_TOP_MASK = ~0 & ~(1 << 28 |
  800. 1 << 21 |
  801. 1 << 17 |
  802. 1 << 16 |
  803. 1 << 15 |
  804. 1 << 11 |
  805. 1 << 10 |
  806. 1 << 7 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 1 | 1 << 0);
  807. cmdqRecHandle handle = NULL;
  808. uint32_t data = 0;
  809. uint32_t dataRead = 0;
  810. #ifdef CMDQ_OF_SUPPORT
  811. const unsigned long MSDC_VA_BASE = cmdq_dev_alloc_module_base_VA_by_name("mediatek,MSDC0");
  812. const unsigned long AUDIO_VA_BASE = cmdq_dev_alloc_module_base_VA_by_name("mediatek,AUDIO");
  813. const unsigned long MSDC_SW_DBG_OUT = MSDC_VA_BASE + 0xA4;
  814. const unsigned long AUDIO_TOP_CONF0 = AUDIO_VA_BASE;
  815. CMDQ_LOG("MSDC_VA_BASE: VA:%lx, PA: 0x%08x\n", MSDC_VA_BASE, 0x11230000);
  816. CMDQ_LOG("AUDIO_VA_BASE: VA:%x, PA: 0x%08x\n", AUDIO_TOP_CONF0_PA, 0x11220000);
  817. #else
  818. const uint32_t MSDC_SW_DBG_OUT = 0xF1230000 + 0xA4;
  819. const uint32_t AUDIO_TOP_CONF0 = 0xF1220000;
  820. #endif
  821. CMDQ_MSG("%s\n", __func__);
  822. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  823. cmdqRecReset(handle);
  824. cmdqRecSetSecure(handle, false);
  825. cmdqRecWrite(handle, MSDC_SW_DBG_SEL_PA, 1, ~0);
  826. cmdqRecFlush(handle);
  827. /* verify data */
  828. data = CMDQ_REG_GET32(MSDC_SW_DBG_OUT);
  829. CMDQ_MSG("MSDC_SW_DBG_OUT = 0x%08x=====\n", data);
  830. /* test read from AP_DMA_GLOBAL_SLOW_DOWN to CMDQ GPR */
  831. cmdqRecReset(handle);
  832. cmdqRecSetSecure(handle, false);
  833. cmdqRecReadToDataRegister(handle, MSDC_SW_DBG_OUT_PA, CMDQ_DATA_REG_PQ_COLOR);
  834. cmdqRecFlush(handle);
  835. /* verify data */
  836. dataRead = CMDQ_REG_GET32(CMDQ_GPR_R32(CMDQ_DATA_REG_PQ_COLOR));
  837. if (data != dataRead)
  838. CMDQ_ERR("TEST FAIL: CMDQ_DATA_REG_PQ_COLOR is 0x%08x, different=====\n", dataRead);
  839. CMDQ_REG_SET32(AUDIO_TOP_CONF0, ~0);
  840. data = CMDQ_REG_GET32(AUDIO_TOP_CONF0);
  841. CMDQ_MSG("write 0xFFFFFFFF to AUDIO_TOP_CONF0 = 0x%08x=====\n", data);
  842. CMDQ_REG_SET32(AUDIO_TOP_CONF0, 0);
  843. data = CMDQ_REG_GET32(AUDIO_TOP_CONF0);
  844. CMDQ_MSG("Before AUDIO_TOP_CONF0 = 0x%08x=====\n", data);
  845. cmdqRecReset(handle);
  846. cmdqRecWrite(handle, AUDIO_TOP_CONF0_PA, ~0, AUDIO_TOP_MASK);
  847. cmdqRecFlush(handle);
  848. /* verify data */
  849. data = CMDQ_REG_GET32(AUDIO_TOP_CONF0);
  850. CMDQ_MSG("after AUDIO_TOP_CONF0 = 0x%08x=====\n", data);
  851. if (data != AUDIO_TOP_MASK)
  852. CMDQ_ERR("TEST FAIL: AUDIO_TOP_CONF0 is 0x%08x=====\n", data);
  853. cmdqRecDestroy(handle);
  854. #ifdef CMDQ_OF_SUPPORT
  855. /* release registers map */
  856. cmdq_dev_free_module_base_VA(MSDC_VA_BASE);
  857. cmdq_dev_free_module_base_VA(AUDIO_VA_BASE);
  858. #endif
  859. CMDQ_MSG("%s END\n", __func__);
  860. return;
  861. #else
  862. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  863. #endif /* CMDQ_GPR_SUPPORT */
  864. }
  865. static void testcase_write_address(void)
  866. {
  867. dma_addr_t pa = 0;
  868. uint32_t value = 0;
  869. CMDQ_MSG("%s\n", __func__);
  870. cmdqCoreAllocWriteAddress(3, &pa);
  871. CMDQ_LOG("ALLOC: 0x%pa\n", &pa);
  872. value = cmdqCoreReadWriteAddress(pa);
  873. CMDQ_LOG("value 0: 0x%08x\n", value);
  874. value = cmdqCoreReadWriteAddress(pa + 1);
  875. CMDQ_LOG("value 1: 0x%08x\n", value);
  876. value = cmdqCoreReadWriteAddress(pa + 2);
  877. CMDQ_LOG("value 2: 0x%08x\n", value);
  878. value = cmdqCoreReadWriteAddress(pa + 3);
  879. CMDQ_LOG("value 3: 0x%08x\n", value);
  880. value = cmdqCoreReadWriteAddress(pa + 4);
  881. CMDQ_LOG("value 4: 0x%08x\n", value);
  882. value = cmdqCoreReadWriteAddress(pa + (4 * 20));
  883. CMDQ_LOG("value 80: 0x%08x\n", value);
  884. cmdqCoreFreeWriteAddress(pa);
  885. cmdqCoreFreeWriteAddress(0);
  886. CMDQ_MSG("%s END\n", __func__);
  887. }
  888. static void testcase_write_from_data_reg(void)
  889. {
  890. #ifdef CMDQ_GPR_SUPPORT
  891. cmdqRecHandle handle;
  892. uint32_t value;
  893. const uint32_t PATTERN = 0xFFFFDEAD;
  894. const uint32_t srcGprId = CMDQ_DATA_REG_DEBUG;
  895. const uint32_t dstRegPA = CMDQ_TEST_DISP_PWM0_DUMMY_PA;
  896. const unsigned long dstRegVA = CMDQ_TEST_MMSYS_DUMMY_VA;
  897. CMDQ_MSG("%s\n", __func__);
  898. /* clean dst register value */
  899. CMDQ_REG_SET32(dstRegVA, 0x0);
  900. /* init GPR as value 0xFFFFDEAD */
  901. CMDQ_REG_SET32(CMDQ_GPR_R32(srcGprId), PATTERN);
  902. value = CMDQ_REG_GET32(CMDQ_GPR_R32(srcGprId));
  903. if (PATTERN != value) {
  904. CMDQ_ERR("init CMDQ_DATA_REG_DEBUG to 0x%08x failed, value: 0x%08x\n", PATTERN,
  905. value);
  906. }
  907. /* write GPR data reg to hw register */
  908. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  909. cmdqRecReset(handle);
  910. cmdqRecSetSecure(handle, gCmdqTestSecure);
  911. cmdqRecWriteFromDataRegister(handle, srcGprId, dstRegPA);
  912. cmdqRecFlush(handle);
  913. cmdqRecDumpCommand(handle);
  914. cmdqRecDestroy(handle);
  915. /* verify */
  916. value = CMDQ_REG_GET32(dstRegVA);
  917. if (PATTERN != value) {
  918. CMDQ_ERR("%s failed, dstReg value is not 0x%08x, value: 0x%08x\n", __func__,
  919. PATTERN, value);
  920. }
  921. CMDQ_MSG("%s END\n", __func__);
  922. #else
  923. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  924. #endif
  925. }
  926. static void testcase_read_to_data_reg(void)
  927. {
  928. #ifdef CMDQ_GPR_SUPPORT
  929. cmdqRecHandle handle;
  930. uint32_t data;
  931. unsigned long long data64;
  932. unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  933. CMDQ_MSG("%s\n", __func__);
  934. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  935. cmdqRecReset(handle);
  936. cmdqRecSetSecure(handle, gCmdqTestSecure);
  937. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0xdeaddead);
  938. CMDQ_REG_SET32(CMDQ_GPR_R32(CMDQ_DATA_REG_PQ_COLOR), 0xbeefbeef);
  939. /* move data from GPR to GPR_Px: COLOR to COLOR_DST (64 bit) */
  940. cmdqRecReadToDataRegister(handle, CMDQ_GPR_R32_PA(CMDQ_DATA_REG_PQ_COLOR),
  941. CMDQ_DATA_REG_PQ_COLOR_DST);
  942. /* move data from register value to GPR_Rx: MM_DUMMY_REG to COLOR(32 bit) */
  943. cmdqRecReadToDataRegister(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA, CMDQ_DATA_REG_PQ_COLOR);
  944. cmdqRecFlush(handle);
  945. cmdqRecDestroy(handle);
  946. /* verify data */
  947. data = CMDQ_REG_GET32(CMDQ_GPR_R32(CMDQ_DATA_REG_PQ_COLOR));
  948. if (data != 0xdeaddead)
  949. CMDQ_ERR("[Read from GPR_Rx]TEST FAIL: PQ reg value is 0x%08x\n", data);
  950. data64 = 0LL;
  951. data64 = CMDQ_REG_GET64_GPR_PX(CMDQ_DATA_REG_PQ_COLOR_DST);
  952. if (0xbeefbeef != data64)
  953. CMDQ_ERR("[Read from GPR_Px]TEST FAIL: PQ_DST reg value is 0x%llx\n", data64);
  954. CMDQ_MSG("%s END\n", __func__);
  955. return;
  956. #else
  957. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  958. return;
  959. #endif
  960. }
  961. static void testcase_write_reg_from_slot(void)
  962. {
  963. const uint32_t PATTEN = 0xBCBCBCBC;
  964. cmdqRecHandle handle;
  965. cmdqBackupSlotHandle hSlot = 0;
  966. uint32_t value = 0;
  967. long long value64 = 0LL;
  968. const enum CMDQ_DATA_REGISTER_ENUM dstRegId = CMDQ_DATA_REG_DEBUG;
  969. const enum CMDQ_DATA_REGISTER_ENUM srcRegId = CMDQ_DATA_REG_DEBUG_DST;
  970. CMDQ_MSG("%s\n", __func__);
  971. /* init */
  972. CMDQ_REG_SET32(CMDQ_TEST_MMSYS_DUMMY_VA, 0xdeaddead);
  973. CMDQ_REG_SET32(CMDQ_GPR_R32(dstRegId), 0xdeaddead);
  974. CMDQ_REG_SET64_GPR_PX(srcRegId, 0xdeaddeaddeaddead);
  975. cmdqBackupAllocateSlot(&hSlot, 1);
  976. cmdqBackupWriteSlot(hSlot, 0, PATTEN);
  977. cmdqBackupReadSlot(hSlot, 0, &value);
  978. if (PATTEN != value)
  979. CMDQ_ERR("%s, slot init failed\n", __func__);
  980. /* Create cmdqRec */
  981. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  982. /* Reset command buffer */
  983. cmdqRecReset(handle);
  984. cmdqRecSetSecure(handle, gCmdqTestSecure);
  985. /* Insert commands to write register with slot's value */
  986. cmdqRecBackupWriteRegisterFromSlot(handle, hSlot, 0, CMDQ_TEST_DISP_PWM0_DUMMY_PA);
  987. /* Execute commands */
  988. cmdqRecFlush(handle);
  989. /* debug dump command instructions */
  990. cmdqRecDumpCommand(handle);
  991. /* we can destroy cmdqRec handle after flush. */
  992. cmdqRecDestroy(handle);
  993. /* verify */
  994. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  995. if (PATTEN != value)
  996. CMDQ_ERR("%s failed, value:0x%x\n", __func__, value);
  997. value = CMDQ_REG_GET32(CMDQ_GPR_R32(dstRegId));
  998. value64 = CMDQ_REG_GET64_GPR_PX(srcRegId);
  999. CMDQ_LOG("srcGPR(%x):0x%llx\n", srcRegId, value64);
  1000. CMDQ_LOG("dstGPR(%x):0x%08x\n", dstRegId, value);
  1001. /* release result free slot */
  1002. cmdqBackupFreeSlot(hSlot);
  1003. CMDQ_MSG("%s END\n", __func__);
  1004. }
  1005. static void testcase_backup_reg_to_slot(void)
  1006. {
  1007. cmdqRecHandle handle;
  1008. unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  1009. cmdqBackupSlotHandle hSlot = 0;
  1010. int i;
  1011. uint32_t value = 0;
  1012. CMDQ_MSG("%s\n", __func__);
  1013. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0xdeaddead);
  1014. /* Create cmdqRec */
  1015. cmdqRecCreate(CMDQ_SCENARIO_DISP_ESD_CHECK, &handle);
  1016. /* Create Slot */
  1017. cmdqBackupAllocateSlot(&hSlot, 5);
  1018. for (i = 0; i < 5; ++i)
  1019. cmdqBackupWriteSlot(hSlot, i, i);
  1020. for (i = 0; i < 5; ++i) {
  1021. cmdqBackupReadSlot(hSlot, i, &value);
  1022. if (value != i)
  1023. CMDQ_ERR("testcase_cmdqBackupWriteSlot FAILED!!!!!\n");
  1024. CMDQ_LOG("testcase_cmdqBackupWriteSlot OK!!!!!\n");
  1025. }
  1026. /* Reset command buffer */
  1027. cmdqRecReset(handle);
  1028. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1029. /* Insert commands to backup registers */
  1030. for (i = 0; i < 5; ++i)
  1031. cmdqRecBackupRegisterToSlot(handle, hSlot, i, CMDQ_TEST_DISP_PWM0_DUMMY_PA);
  1032. /* Execute commands */
  1033. cmdqRecFlush(handle);
  1034. /* debug dump command instructions */
  1035. cmdqRecDumpCommand(handle);
  1036. /* we can destroy cmdqRec handle after flush. */
  1037. cmdqRecDestroy(handle);
  1038. /* verify data by reading it back from slot */
  1039. for (i = 0; i < 5; ++i) {
  1040. cmdqBackupReadSlot(hSlot, i, &value);
  1041. CMDQ_LOG("backup slot %d = 0x%08x\n", i, value);
  1042. if (value != 0xdeaddead)
  1043. CMDQ_ERR("content error!!!!!!!!!!!!!!!!!!!!\n");
  1044. }
  1045. /* release result free slot */
  1046. cmdqBackupFreeSlot(hSlot);
  1047. CMDQ_MSG("%s END\n", __func__);
  1048. }
  1049. static void testcase_update_value_to_slot(void)
  1050. {
  1051. int32_t i;
  1052. uint32_t value;
  1053. cmdqRecHandle handle;
  1054. cmdqBackupSlotHandle hSlot = 0;
  1055. const uint32_t PATTERNS[] = {
  1056. 0xDEAD0000, 0xDEAD0001, 0xDEAD0002, 0xDEAD0003, 0xDEAD0004
  1057. };
  1058. CMDQ_MSG("%s\n", __func__);
  1059. /* Create Slot */
  1060. cmdqBackupAllocateSlot(&hSlot, 5);
  1061. /*use CMDQ to update slot value */
  1062. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1063. cmdqRecReset(handle);
  1064. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1065. for (i = 0; i < 5; ++i)
  1066. cmdqRecBackupUpdateSlot(handle, hSlot, i, PATTERNS[i]);
  1067. cmdqRecFlush(handle);
  1068. cmdqRecDumpCommand(handle);
  1069. cmdqRecDestroy(handle);
  1070. /* CPU verify value by reading it back from slot */
  1071. for (i = 0; i < 5; ++i) {
  1072. cmdqBackupReadSlot(hSlot, i, &value);
  1073. if (PATTERNS[i] != value) {
  1074. CMDQ_ERR("slot[%d] = 0x%08x...content error! It should be 0x%08x\n",
  1075. i, value, PATTERNS[i]);
  1076. } else {
  1077. CMDQ_LOG("slot[%d] = 0x%08x\n", i, value);
  1078. }
  1079. }
  1080. /* release result free slot */
  1081. cmdqBackupFreeSlot(hSlot);
  1082. CMDQ_MSG("%s END\n", __func__);
  1083. }
  1084. static void testcase_poll(void)
  1085. {
  1086. cmdqRecHandle handle;
  1087. const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  1088. uint32_t value = 0;
  1089. uint32_t testReg = MMSYS_DUMMY_REG;
  1090. uint32_t pollingVal = 0x00003001;
  1091. CMDQ_MSG("%s\n", __func__);
  1092. CMDQ_REG_SET32(MMSYS_DUMMY_REG, ~0);
  1093. /* it's too slow that set value after enable CMDQ */
  1094. /* sw timeout will be hanppened before CPU schedule to set value..., so we set value here */
  1095. CMDQ_REG_SET32(MMSYS_DUMMY_REG, pollingVal);
  1096. value = CMDQ_REG_GET32(testReg);
  1097. CMDQ_MSG("target value is 0x%08x\n", value);
  1098. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1099. cmdqRecReset(handle);
  1100. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1101. cmdqRecPoll(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA, pollingVal, ~0);
  1102. cmdqRecFlush(handle);
  1103. cmdqRecDestroy(handle);
  1104. /* value check */
  1105. value = CMDQ_REG_GET32(testReg);
  1106. if (pollingVal != value)
  1107. CMDQ_ERR("polling target value is 0x%08x\n", value);
  1108. CMDQ_MSG("%s END\n", __func__);
  1109. }
  1110. static int32_t _thread_poll_reg_value(void *data)
  1111. {
  1112. uint32_t value = 0;
  1113. while (1) {
  1114. if (gThreadRunFlag) {
  1115. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1116. CMDQ_LOG("Get Test Value:0x%08x\n", value);
  1117. msleep(500);
  1118. }
  1119. }
  1120. return 0;
  1121. }
  1122. static void ctrolThreadRunning(void)
  1123. {
  1124. if (0 == gThreadRunFlag)
  1125. gThreadRunFlag = 1;
  1126. else
  1127. gThreadRunFlag = 0;
  1128. }
  1129. static void start_poll_register(void)
  1130. {
  1131. /* start a thread to poll CMDQ_TEST_VA register */
  1132. struct task_struct *pThread = kthread_run(_thread_poll_reg_value, NULL, "cmq_thread_poll");
  1133. if (IS_ERR(pThread))
  1134. CMDQ_ERR("create pThread failed\n");
  1135. else
  1136. CMDQ_MSG("create pThread success,start to poll\n");
  1137. }
  1138. static void testcase_write_with_mask(void)
  1139. {
  1140. cmdqRecHandle handle;
  1141. const uint32_t PATTERN = (1 << 0) | (1 << 2) | (1 << 16);
  1142. const uint32_t MASK = (1 << 16);
  1143. const uint32_t EXPECT_RESULT = PATTERN & MASK;
  1144. uint32_t value = 0;
  1145. CMDQ_MSG("%s\n", __func__);
  1146. /* set to 0x0 */
  1147. CMDQ_REG_SET32(CMDQ_TEST_MMSYS_DUMMY_VA, 0x0);
  1148. /* use CMDQ to set to PATTERN */
  1149. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1150. cmdqRecReset(handle);
  1151. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1152. cmdqRecWrite(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA, PATTERN, MASK);
  1153. cmdqRecFlush(handle);
  1154. cmdqRecDestroy(handle);
  1155. /* value check */
  1156. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1157. if (EXPECT_RESULT != value)
  1158. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", value, EXPECT_RESULT);
  1159. CMDQ_MSG("%s END\n", __func__);
  1160. }
  1161. enum {
  1162. WAIT_OVL0_EOF_NORMAL = 0 << 1 | 0,
  1163. WAIT_OVL0_EOF_SECURE = 0 << 1 | 1,
  1164. WAIT_RDMA0_EOF_NORMAL = 1 << 1 | 0,
  1165. WAIT_RDMA0_EOF_SECURE = 1 << 1 | 1,
  1166. WAIT_MUTEX0_EOF_NORMAL = 2 << 1 | 0,
  1167. WAIT_MUTEX0_EOF_SECURE = 2 << 1 | 1,
  1168. };
  1169. int32_t callback_func(unsigned long data)
  1170. {
  1171. switch (data) {
  1172. case WAIT_OVL0_EOF_NORMAL:
  1173. CMDQ_LOG("testcase_wait_ovl0_eof execute done in normal world\n");
  1174. break;
  1175. case WAIT_OVL0_EOF_SECURE:
  1176. CMDQ_LOG("testcase_wait_ovl0_eof execute done in secure world\n");
  1177. break;
  1178. case WAIT_RDMA0_EOF_NORMAL:
  1179. CMDQ_LOG("testcase_wait_rdma0_eof execute done in normal world\n");
  1180. break;
  1181. case WAIT_RDMA0_EOF_SECURE:
  1182. CMDQ_LOG("testcase_wait_rdma0_eof execute done in secure world\n");
  1183. break;
  1184. case WAIT_MUTEX0_EOF_NORMAL:
  1185. CMDQ_LOG("testcase_wait_mutex0_stream_eof execute done in normal world\n");
  1186. break;
  1187. case WAIT_MUTEX0_EOF_SECURE:
  1188. CMDQ_LOG("testcase_wait_mutex0_stream_eof execute done in secure world\n");
  1189. break;
  1190. default:
  1191. CMDQ_LOG("testcase wait event error\n");
  1192. break;
  1193. }
  1194. return 0;
  1195. }
  1196. static void testcase_wait_disp_rdma0_eof(void)
  1197. {
  1198. cmdqRecHandle handle;
  1199. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &handle);
  1200. cmdqRecReset(handle);
  1201. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1202. CMDQ_LOG("wait RDMA0_EOF for four times\n");
  1203. cmdqRecWait(handle, CMDQ_EVENT_DISP_RDMA0_EOF);
  1204. cmdqRecWait(handle, CMDQ_EVENT_DISP_RDMA0_EOF);
  1205. cmdqRecWait(handle, CMDQ_EVENT_DISP_RDMA0_EOF);
  1206. cmdqRecWait(handle, CMDQ_EVENT_DISP_RDMA0_EOF);
  1207. cmdqRecFlushAsyncCallback(handle, callback_func,
  1208. gCmdqTestSecure ? WAIT_RDMA0_EOF_SECURE : WAIT_RDMA0_EOF_NORMAL);
  1209. cmdqRecDestroy(handle);
  1210. }
  1211. static void testcase_wait_disp_ovl0_eof(void)
  1212. {
  1213. cmdqRecHandle handle;
  1214. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &handle);
  1215. cmdqRecReset(handle);
  1216. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1217. CMDQ_LOG("wait OVL0_EOF for four times\n");
  1218. cmdqRecWait(handle, CMDQ_EVENT_DISP_OVL0_EOF);
  1219. cmdqRecWait(handle, CMDQ_EVENT_DISP_OVL0_EOF);
  1220. cmdqRecWait(handle, CMDQ_EVENT_DISP_OVL0_EOF);
  1221. cmdqRecWait(handle, CMDQ_EVENT_DISP_OVL0_EOF);
  1222. cmdqRecFlushAsyncCallback(handle, callback_func,
  1223. gCmdqTestSecure ? WAIT_OVL0_EOF_SECURE : WAIT_OVL0_EOF_NORMAL);
  1224. cmdqRecDestroy(handle);
  1225. }
  1226. static void testcase_wait_mutex0_stream_eof(void)
  1227. {
  1228. cmdqRecHandle handle;
  1229. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &handle);
  1230. /* wait mutex0_stream_eof in secure world */
  1231. cmdqRecReset(handle);
  1232. cmdqRecSetSecure(handle, true);
  1233. cmdqRecWait(handle, CMDQ_EVENT_MUTEX0_STREAM_EOF);
  1234. cmdqRecFlushAsyncCallback(handle, callback_func, WAIT_MUTEX0_EOF_SECURE);
  1235. #if 0
  1236. /* wait mutex0_stream_eof in normal world */
  1237. cmdqRecReset(handle);
  1238. cmdqRecSetSecure(handle, false);
  1239. cmdqRecWaitNoClear(handle, CMDQ_EVENT_MUTEX0_STREAM_EOF);
  1240. cmdqRecFlushAsyncCallback(handle, callback_func, WAIT_MUTEX0_EOF_NORMAL);
  1241. #endif
  1242. cmdqRecDestroy(handle);
  1243. }
  1244. int32_t flush_callback(unsigned long PATTERN)
  1245. {
  1246. CMDQ_LOG("flush callback execute over(%lu)\n", PATTERN);
  1247. return 0;
  1248. }
  1249. static void testcase_cmdqRecFlushAsyncCallback(void)
  1250. {
  1251. cmdqRecHandle handle;
  1252. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &handle);
  1253. cmdqRecReset(handle);
  1254. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1255. cmdqRecWait(handle, CMDQ_SYNC_TOKEN_USER_0);
  1256. cmdqRecFlushAsyncCallback(handle, flush_callback, 111);
  1257. cmdqRecDestroy(handle);
  1258. }
  1259. static void testcase_write(void)
  1260. {
  1261. uint32_t value = 0;
  1262. cmdqRecHandle handle;
  1263. /* const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA; */
  1264. /* const uint32_t PATTERN = (1<<0) | (1<<2) | (1<<16); */
  1265. const uint32_t PATTERN = 0x10;
  1266. const int32_t loopCount = gCmdqTestConfig[2];
  1267. int32_t count = 0;
  1268. CMDQ_MSG("%s\n", __func__);
  1269. CMDQ_LOG("ready to write data 0x%08x for %d times\n", PATTERN, loopCount);
  1270. /* use CMDQ to set to PATTERN */
  1271. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &handle);
  1272. for (count = 0; count < loopCount; count++) {
  1273. cmdqRecReset(handle);
  1274. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1275. cmdqRecWrite(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA, PATTERN, ~0);
  1276. cmdqRecFlushAsyncCallback(handle, flush_callback, PATTERN);
  1277. }
  1278. cmdqRecDestroy(handle);
  1279. #if 1
  1280. /* value check */
  1281. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1282. if (value != PATTERN)
  1283. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", value, PATTERN);
  1284. else
  1285. CMDQ_ERR("TEST SUCCESS: wrote value is 0x%08x, read value is 0x%08x\n", value,
  1286. PATTERN);
  1287. #endif
  1288. }
  1289. static void testcase_prefetch(void)
  1290. {
  1291. cmdqRecHandle handle;
  1292. int i;
  1293. uint32_t value = 0;
  1294. const uint32_t PATTERN = (1 << 0) | (1 << 2) | (1 << 16); /* 0xDEADDEAD; */
  1295. const uint32_t testRegPA = CMDQ_TEST_MMSYS_DUMMY_PA;
  1296. const unsigned long testRegVA = CMDQ_TEST_MMSYS_DUMMY_VA;
  1297. const uint32_t REP_COUNT = 500;
  1298. CMDQ_MSG("%s\n", __func__);
  1299. /* set to 0xFFFFFFFF */
  1300. CMDQ_REG_SET32(testRegVA, ~0);
  1301. /* No prefetch. */
  1302. /* use CMDQ to set to PATTERN */
  1303. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1304. cmdqRecReset(handle);
  1305. cmdqRecSetSecure(handle, false);
  1306. for (i = 0; i < REP_COUNT; ++i)
  1307. cmdqRecWrite(handle, testRegPA, PATTERN, ~0);
  1308. cmdqRecFlushAsync(handle);
  1309. cmdqRecFlushAsync(handle);
  1310. cmdqRecFlushAsync(handle);
  1311. msleep_interruptible(1000);
  1312. cmdqRecDestroy(handle);
  1313. /* use prefetch */
  1314. cmdqRecCreate(CMDQ_SCENARIO_DEBUG_PREFETCH, &handle);
  1315. cmdqRecReset(handle);
  1316. cmdqRecSetSecure(handle, false);
  1317. for (i = 0; i < REP_COUNT; ++i)
  1318. cmdqRecWrite(handle, testRegPA, PATTERN, ~0);
  1319. cmdqRecFlushAsync(handle);
  1320. cmdqRecFlushAsync(handle);
  1321. cmdqRecFlushAsync(handle);
  1322. msleep_interruptible(1000);
  1323. cmdqRecDestroy(handle);
  1324. /* value check */
  1325. value = CMDQ_REG_GET32(testRegVA);
  1326. if (value != PATTERN) {
  1327. /* test fail */
  1328. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", value, PATTERN);
  1329. }
  1330. CMDQ_MSG("%s END\n", __func__);
  1331. }
  1332. static void testcase_backup_register(void)
  1333. {
  1334. #ifdef CMDQ_GPR_SUPPORT
  1335. const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  1336. cmdqRecHandle handle;
  1337. int ret = 0;
  1338. uint32_t regAddr[3] = { CMDQ_TEST_DISP_PWM0_DUMMY_PA,
  1339. CMDQ_GPR_R32_PA(CMDQ_DATA_REG_PQ_COLOR),
  1340. CMDQ_GPR_R32_PA(CMDQ_DATA_REG_2D_SHARPNESS_0)
  1341. };
  1342. uint32_t regValue[3] = { 0 };
  1343. CMDQ_MSG("%s\n", __func__);
  1344. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0xAAAAAAAA);
  1345. CMDQ_REG_SET32(CMDQ_GPR_R32(CMDQ_DATA_REG_PQ_COLOR), 0xBBBBBBBB);
  1346. CMDQ_REG_SET32(CMDQ_GPR_R32(CMDQ_DATA_REG_2D_SHARPNESS_0), 0xCCCCCCCC);
  1347. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1348. cmdqRecReset(handle);
  1349. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1350. ret = cmdqRecFlushAndReadRegister(handle, 3, regAddr, regValue);
  1351. cmdqRecDestroy(handle);
  1352. if (regValue[0] != 0xAAAAAAAA)
  1353. CMDQ_ERR("regValue[0] is 0x%08x, wrong!\n", regValue[0]);
  1354. if (regValue[1] != 0xBBBBBBBB)
  1355. CMDQ_ERR("regValue[1] is 0x%08x, wrong!\n", regValue[1]);
  1356. if (regValue[2] != 0xCCCCCCCC)
  1357. CMDQ_ERR("regValue[2] is 0x%08x, wrong!\n", regValue[2]);
  1358. CMDQ_MSG("%s END\n", __func__);
  1359. #else
  1360. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  1361. #endif
  1362. }
  1363. static void testcase_get_result(void)
  1364. {
  1365. #ifdef CMDQ_GPR_SUPPORT
  1366. const unsigned long MMSYS_DUMMY_REG = CMDQ_TEST_MMSYS_DUMMY_VA;
  1367. int i;
  1368. cmdqRecHandle handle;
  1369. int ret = 0;
  1370. struct cmdqCommandStruct desc = { 0 };
  1371. int registers[1] = { CMDQ_TEST_MMSYS_DUMMY_VA };
  1372. int result[1] = { 0 };
  1373. CMDQ_MSG("%s\n", __func__);
  1374. /* make sure each scenario runs properly with empty commands
  1375. use CMDQ_SCENARIO_PRIMARY_ALL to test
  1376. because it has COLOR0 HW flag */
  1377. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_ALL, &handle);
  1378. cmdqRecReset(handle);
  1379. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1380. /* insert dummy commands */
  1381. cmdq_rec_finalize_command(handle, false);
  1382. /* init desc attributes after finalize command to ensure correct size and buffer addr */
  1383. desc.scenario = handle->scenario;
  1384. desc.priority = handle->priority;
  1385. desc.engineFlag = handle->engineFlag;
  1386. desc.pVABase = (cmdqU32Ptr_t) (unsigned long)handle->pBuffer;
  1387. desc.blockSize = handle->blockSize;
  1388. desc.regRequest.count = 1;
  1389. desc.regRequest.regAddresses = (cmdqU32Ptr_t) (unsigned long)registers;
  1390. desc.regValue.count = 1;
  1391. desc.regValue.regValues = (cmdqU32Ptr_t) (unsigned long)result;
  1392. desc.secData.isSecure = handle->secData.isSecure;
  1393. desc.secData.addrMetadataCount = 0;
  1394. desc.secData.addrMetadataMaxCount = 0;
  1395. desc.secData.waitCookie = 0;
  1396. desc.secData.resetExecCnt = false;
  1397. CMDQ_REG_SET32(MMSYS_DUMMY_REG, 0xdeaddead);
  1398. /* manually raise the dirty flag */
  1399. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_EVENT_MUTEX0_STREAM_EOF);
  1400. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_EVENT_MUTEX1_STREAM_EOF);
  1401. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_EVENT_MUTEX2_STREAM_EOF);
  1402. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, (1L << 16) | CMDQ_EVENT_MUTEX3_STREAM_EOF);
  1403. for (i = 0; i < 1; ++i) {
  1404. ret = cmdqCoreSubmitTask(&desc);
  1405. if (CMDQ_U32_PTR(desc.regValue.regValues)[0] != 0xdeaddead) {
  1406. CMDQ_ERR("TEST FAIL: reg value is 0x%08x\n",
  1407. CMDQ_U32_PTR(desc.regValue.regValues)[0]);
  1408. }
  1409. }
  1410. cmdqRecDestroy(handle);
  1411. CMDQ_MSG("%s END\n", __func__);
  1412. return;
  1413. #else
  1414. CMDQ_ERR("func:%s failed since CMDQ doesn't support GPR\n", __func__);
  1415. #endif
  1416. }
  1417. static void testcase_emergency_buffer(void)
  1418. {
  1419. /* ensure to define CMDQ_TEST_EMERGENCY_BUFFER in cmdq_core.c */
  1420. const uint32_t longCommandSize = 160 * 1024;
  1421. const uint32_t submitTaskCount = 4;
  1422. cmdqRecHandle handle;
  1423. int32_t i;
  1424. CMDQ_MSG("%s\n", __func__);
  1425. /* force to use emergency buffer */
  1426. if (0 > cmdq_core_enable_emergency_buffer_test(true))
  1427. return;
  1428. /* prepare long command */
  1429. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1430. cmdqRecReset(handle);
  1431. cmdqRecSetSecure(handle, false);
  1432. for (i = 0; i < (longCommandSize / CMDQ_INST_SIZE); i++) {
  1433. cmdqRecReadToDataRegister(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA,
  1434. CMDQ_DATA_REG_PQ_COLOR);
  1435. }
  1436. /* submit */
  1437. for (i = 0; i < submitTaskCount; i++) {
  1438. CMDQ_LOG("async submit large command(size: %d), count:%d\n", longCommandSize, i);
  1439. cmdqRecFlushAsync(handle);
  1440. }
  1441. msleep_interruptible(1000);
  1442. /* reset to apply normal memory allocation flow */
  1443. cmdq_core_enable_emergency_buffer_test(false);
  1444. cmdqRecDestroy(handle);
  1445. CMDQ_MSG("%s END\n", __func__);
  1446. }
  1447. static int _testcase_simplest_command_loop_submit(const uint32_t loop,
  1448. enum CMDQ_SCENARIO_ENUM scenario,
  1449. const long long engineFlag,
  1450. const bool isSecureTask)
  1451. {
  1452. cmdqRecHandle handle;
  1453. int32_t i;
  1454. CMDQ_MSG("%s\n", __func__);
  1455. cmdqRecCreate(scenario, &handle);
  1456. for (i = 0; i < loop; i++) {
  1457. CMDQ_LOG("pid: %d, flush:%4d, engineFlag:0x%llx\n", current->pid, i, engineFlag);
  1458. cmdqRecReset(handle);
  1459. cmdqRecSetSecure(handle, isSecureTask);
  1460. handle->engineFlag = engineFlag;
  1461. cmdqRecFlush(handle);
  1462. }
  1463. cmdqRecDestroy(handle);
  1464. CMDQ_MSG("%s END\n", __func__);
  1465. return 0;
  1466. }
  1467. /* threadfn: int (*threadfn)(void *data) */
  1468. static int _testcase_thread_dispatch(void *data)
  1469. {
  1470. long long engineFlag;
  1471. engineFlag = *((long long *)data);
  1472. _testcase_simplest_command_loop_submit(1000, CMDQ_SCENARIO_DEBUG, engineFlag, false);
  1473. return 0;
  1474. }
  1475. static void testcase_thread_dispatch(void)
  1476. {
  1477. char threadName[20];
  1478. const long long engineFlag1 = (0x1 << CMDQ_ENG_ISP_IMGI) | (0x1 << CMDQ_ENG_ISP_IMGO);
  1479. const long long engineFlag2 = (0x1 << CMDQ_ENG_MDP_RDMA0) | (0x1 << CMDQ_ENG_MDP_WDMA);
  1480. struct task_struct *pKThread1;
  1481. struct task_struct *pKThread2;
  1482. CMDQ_MSG("%s\n", __func__);
  1483. CMDQ_MSG("=============== 2 THREAD with different engines ===============\n");
  1484. sprintf(threadName, "cmdqKTHR_%llx", engineFlag1);
  1485. pKThread1 = kthread_run(_testcase_thread_dispatch, (void *)(&engineFlag1), threadName);
  1486. if (IS_ERR(pKThread1)) {
  1487. CMDQ_ERR("create thread failed, thread:%s\n", threadName);
  1488. return;
  1489. }
  1490. sprintf(threadName, "cmdqKTHR_%llx", engineFlag2);
  1491. pKThread2 = kthread_run(_testcase_thread_dispatch, (void *)(&engineFlag2), threadName);
  1492. if (IS_ERR(pKThread2)) {
  1493. CMDQ_ERR("create thread failed, thread:%s\n", threadName);
  1494. return;
  1495. }
  1496. msleep_interruptible(5 * 1000);
  1497. /* ensure both thread execute all command */
  1498. _testcase_simplest_command_loop_submit(1, CMDQ_SCENARIO_DEBUG, engineFlag1, false);
  1499. _testcase_simplest_command_loop_submit(1, CMDQ_SCENARIO_DEBUG, engineFlag2, false);
  1500. CMDQ_MSG("%s END\n", __func__);
  1501. }
  1502. static int _testcase_full_thread_array(void *data)
  1503. {
  1504. cmdqRecHandle handle;
  1505. int32_t i;
  1506. /* clearn event first */
  1507. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  1508. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1509. /* specify engine flag in order to dispatch all tasks to the same HW thread */
  1510. handle->engineFlag = (1LL << CMDQ_ENG_MDP_RDMA0);
  1511. cmdqRecReset(handle);
  1512. cmdqRecSetSecure(handle, gCmdqTestSecure);
  1513. cmdqRecWaitNoClear(handle, CMDQ_SYNC_TOKEN_USER_0);
  1514. for (i = 0; i < 50; i++) {
  1515. CMDQ_LOG("pid: %d, flush:%6d\n", current->pid, i);
  1516. if (40 == i) {
  1517. CMDQ_LOG("set token: %d to 1\n", CMDQ_SYNC_TOKEN_USER_0);
  1518. cmdqCoreSetEvent(CMDQ_SYNC_TOKEN_USER_0);
  1519. }
  1520. cmdqRecFlushAsync(handle);
  1521. }
  1522. cmdqRecDestroy(handle);
  1523. return 0;
  1524. }
  1525. static void testcase_full_thread_array(void)
  1526. {
  1527. char threadName[20];
  1528. struct task_struct *pKThread;
  1529. CMDQ_MSG("%s\n", __func__);
  1530. sprintf(threadName, "cmdqKTHR");
  1531. pKThread = kthread_run(_testcase_full_thread_array, NULL, threadName);
  1532. if (IS_ERR(pKThread))
  1533. CMDQ_ERR("create thread failed, thread:%s\n", threadName);
  1534. msleep_interruptible(5 * 1000);
  1535. CMDQ_MSG("%s END\n", __func__);
  1536. }
  1537. static void testcase_module_full_dump(void)
  1538. {
  1539. cmdqRecHandle handle;
  1540. const bool alreadyEnableLog = cmdq_core_should_print_msg(LOG_LEVEL_MSG);
  1541. CMDQ_MSG("%s\n", __func__);
  1542. /* enable full dump */
  1543. if (false == alreadyEnableLog)
  1544. cmdq_core_set_log_level(LOG_LEVEL_MSG);
  1545. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1546. /* clean SW token to invoke SW timeout latter */
  1547. CMDQ_REG_SET32(CMDQ_SYNC_TOKEN_UPD, CMDQ_SYNC_TOKEN_USER_0);
  1548. /* turn on ALL except DISP engine flag to test dump */
  1549. handle->engineFlag = ~(CMDQ_ENG_DISP_GROUP_BITS);
  1550. CMDQ_LOG("%s, engine: 0x%llx, it's a timeout case\n", __func__, handle->engineFlag);
  1551. cmdqRecReset(handle);
  1552. cmdqRecSetSecure(handle, false);
  1553. cmdqRecWaitNoClear(handle, CMDQ_SYNC_TOKEN_USER_0);
  1554. cmdqRecFlush(handle);
  1555. /* disable full dump */
  1556. if (false == alreadyEnableLog)
  1557. cmdq_core_set_log_level(LOG_LEVEL_LOG);
  1558. CMDQ_MSG("%s END\n", __func__);
  1559. }
  1560. void testcase_secure_basic(void)
  1561. {
  1562. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1563. int32_t status = 0;
  1564. CMDQ_LOG("enter testcase_secure_basic\n");
  1565. CMDQ_LOG("%s\n", __func__);
  1566. do {
  1567. CMDQ_LOG("====== Hello cmdqSecTl ======\n ");
  1568. status =
  1569. cmdq_sec_submit_to_secure_world_async_unlocked(CMD_CMDQ_TL_TEST_HELLO_TL, NULL,
  1570. -1, NULL, NULL);
  1571. if (0 > status)
  1572. CMDQ_ERR("entry cmdqSecTL failed, status:%d\n", status);
  1573. CMDQ_LOG("====== Hello cmdqSecDr ======\n ");
  1574. status =
  1575. cmdq_sec_submit_to_secure_world_async_unlocked(CMD_CMDQ_TL_TEST_DUMMY, NULL, -1,
  1576. NULL, NULL);
  1577. if (0 > status)
  1578. CMDQ_ERR("entry cmdqSecDr failed, status:%d\n", status);
  1579. } while (0);
  1580. CMDQ_LOG("%s END\n", __func__);
  1581. #endif
  1582. }
  1583. static void testcase_use_backup_slot_to_debug(void)
  1584. {
  1585. uint32_t value = 0;
  1586. cmdqRecHandle handle;
  1587. cmdqBackupSlotHandle hSlot = 0;
  1588. CMDQ_REG_SET32(CMDQ_TEST_MMSYS_DUMMY_VA, gCmdqTestConfig[2]);
  1589. CMDQ_LOG("set TESTREG to %d", gCmdqTestConfig[2]);
  1590. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &handle);
  1591. cmdqBackupAllocateSlot(&hSlot, 3);
  1592. cmdqRecReset(handle);
  1593. cmdqRecSetSecure(handle, false);
  1594. if ((gCmdqTestConfig[2] % 2) != 0) {
  1595. CMDQ_LOG("set TESTREG to %d with CPU", gCmdqTestConfig[2]);
  1596. CMDQ_REG_SET32(CMDQ_TEST_MMSYS_DUMMY_VA, gCmdqTestConfig[2]);
  1597. } else {
  1598. CMDQ_LOG("set TESTREG to %d with CMDQ", gCmdqTestConfig[2]);
  1599. cmdqRecWrite(handle, CMDQ_TEST_DISP_PWM0_DUMMY_PA, gCmdqTestConfig[2], ~0);
  1600. }
  1601. cmdqRecBackupRegisterToSlot(handle, hSlot, 0, CMDQ_TEST_DISP_PWM0_DUMMY_PA);
  1602. cmdqRecFlush(handle);
  1603. cmdqBackupReadSlot(hSlot, 0, &value);
  1604. CMDQ_LOG("get slot value:%d\n", value);
  1605. cmdqRecDestroy(handle);
  1606. }
  1607. void testcase_read_init_memory(void)
  1608. {
  1609. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1610. int32_t status = 0;
  1611. uint32_t cookie = 55;
  1612. CMDQ_MSG("enter %s\n", __func__);
  1613. #if 0
  1614. /* write data in Normal world */
  1615. ((int32_t *) (gCmdqContext.hSecSharedMem->pVABase))[0] = 123;
  1616. CMDQ_ERR("write to share buffer data:%d",
  1617. ((int32_t *) (gCmdqContext.hSecSharedMem->pVABase))[0]);
  1618. #endif
  1619. /* read data in Secure world */
  1620. do {
  1621. status =
  1622. cmdq_sec_submit_to_secure_world_async_unlocked(CMD_CMDQ_TL_DUMP, NULL, -1, NULL,
  1623. NULL);
  1624. if (0 > status)
  1625. CMDQ_ERR("entry testcase_read_init_memory failed, status:%d\n", status);
  1626. } while (0);
  1627. cmdq_core_get_secure_thread_exec_counter(12, &cookie);
  1628. CMDQ_LOG("get secure thread cookie:%d\n", cookie);
  1629. CMDQ_MSG("%s END\n", __func__);
  1630. #endif
  1631. }
  1632. void testcase_secure_disp_scenario(void)
  1633. {
  1634. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1635. /* note: this case used to verify command compose in secure world. */
  1636. /* It must test when DISP driver has switched primary DISP to secure path, */
  1637. /* otherwise we should disable "enable GCE" in SWd in order to prevent phone hang */
  1638. cmdqRecHandle hDISP;
  1639. cmdqRecHandle hDisableDISP;
  1640. uint32_t value;
  1641. const uint32_t PATTERN = (1 << 0) | (1 << 2) | (1 << 16);
  1642. CMDQ_MSG("%s\n", __func__);
  1643. CMDQ_LOG("=========== secure primary path ===========\n");
  1644. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_DISP, &hDISP);
  1645. cmdqRecReset(hDISP);
  1646. cmdqRecSetSecure(hDISP, true);
  1647. cmdqRecWrite(hDISP, CMDQ_TEST_DISP_PWM0_DUMMY_PA, PATTERN, ~0);
  1648. cmdqRecFlush(hDISP);
  1649. cmdqRecDestroy(hDISP);
  1650. /* value check */
  1651. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1652. if (value != PATTERN)
  1653. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", PATTERN, value);
  1654. else
  1655. CMDQ_LOG("TEST SUCCESS: wrote value is 0x%08x, read value is 0x%08x\n", PATTERN,
  1656. value);
  1657. CMDQ_LOG("=========== disp secure primary path ===========\n");
  1658. cmdqRecCreate(CMDQ_SCENARIO_DISP_PRIMARY_DISABLE_SECURE_PATH, &hDisableDISP);
  1659. cmdqRecReset(hDisableDISP);
  1660. cmdqRecSetSecure(hDisableDISP, true);
  1661. cmdqRecWrite(hDisableDISP, CMDQ_TEST_DISP_PWM0_DUMMY_PA, PATTERN, ~0);
  1662. cmdqRecFlush(hDisableDISP);
  1663. cmdqRecDestroy(hDisableDISP);
  1664. /* value check */
  1665. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1666. if (value != PATTERN)
  1667. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", PATTERN, value);
  1668. else
  1669. CMDQ_LOG("TEST SUCCESS: wrote value is 0x%08x, read value is 0x%08x\n", PATTERN,
  1670. value);
  1671. CMDQ_MSG("%s END\n", __func__);
  1672. #endif
  1673. }
  1674. void test_cmdq_sec_write(void)
  1675. {
  1676. cmdqRecHandle hTestDISP;
  1677. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &hTestDISP);
  1678. cmdqRecReset(hTestDISP);
  1679. cmdqRecSetSecure(hTestDISP, true);
  1680. /* cmdqRecWriteSecure(hTestDISP,0x1400cf40,CMDQ_SAM_H_2_MVA,0x12345678,0,0,0); */
  1681. cmdqRecWrite(hTestDISP, 0x1401e030, 0x88888888, ~0);
  1682. cmdqRecFlush(hTestDISP);
  1683. cmdqRecDestroy(hTestDISP);
  1684. }
  1685. void testcase_secure_meta_data(void)
  1686. {
  1687. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1688. cmdqRecHandle hReqMDP;
  1689. /* const uint32_t PATTERN_MDP = (1 << 0) | (1 << 2) | (1 << 16); */
  1690. /* const uint32_t PATTERN_MDP = 0xBCBCBCBC; */
  1691. const uint32_t PATTERN_MDP = gCmdqTestConfig[2];
  1692. uint32_t value = 0;
  1693. CMDQ_LOG("%s\n", __func__);
  1694. /* set to 0xFFFFFFFF */
  1695. CMDQ_REG_SET32(CMDQ_TEST_MMSYS_DUMMY_VA, ~0);
  1696. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1697. CMDQ_LOG("CMDQ_TEST_REG init data is 0x%08x\n", value);
  1698. CMDQ_LOG("=============== MDP case ===================\n");
  1699. CMDQ_LOG("CMDQ_TEST_REG going to write data:0x%08x,secure:%d\n", PATTERN_MDP,
  1700. gCmdqTestSecure);
  1701. cmdqRecCreate(CMDQ_SCENARIO_DEBUG, &hReqMDP);
  1702. cmdqRecReset(hReqMDP);
  1703. cmdqRecSetSecure(hReqMDP, gCmdqTestSecure);
  1704. #if 1
  1705. /* specify use MDP engine */
  1706. hReqMDP->engineFlag =
  1707. (1LL << CMDQ_ENG_MDP_RDMA0) | (1LL << CMDQ_ENG_MDP_WDMA) | (1LL << CMDQ_ENG_MDP_WROT0);
  1708. /* enable secure test */
  1709. cmdqRecSecureEnableDAPC(hReqMDP,
  1710. (1LL << CMDQ_ENG_MDP_RDMA0) | (1LL << CMDQ_ENG_MDP_WDMA) | (1LL <<
  1711. CMDQ_ENG_MDP_WROT0));
  1712. cmdqRecSecureEnablePortSecurity(hReqMDP,
  1713. (1LL << CMDQ_ENG_MDP_RDMA0) | (1LL << CMDQ_ENG_MDP_WDMA) |
  1714. (1LL << CMDQ_ENG_MDP_WROT0));
  1715. #endif
  1716. /* record command */
  1717. cmdqRecWrite(hReqMDP, CMDQ_TEST_DISP_PWM0_DUMMY_PA, PATTERN_MDP, ~0);
  1718. cmdqRecFlush(hReqMDP);
  1719. cmdqRecDestroy(hReqMDP);
  1720. /* value check */
  1721. value = CMDQ_REG_GET32(CMDQ_TEST_MMSYS_DUMMY_VA);
  1722. if (value != PATTERN_MDP)
  1723. CMDQ_ERR("TEST FAIL: wrote value is 0x%08x, not 0x%08x\n", PATTERN_MDP, value);
  1724. else
  1725. CMDQ_LOG("TEST SUCCESS: wrote value is 0x%08x, read value is 0x%08x\n", PATTERN_MDP,
  1726. value);
  1727. CMDQ_MSG("%s END\n", __func__);
  1728. #else
  1729. CMDQ_ERR("%s failed since not support secure path\n", __func__);
  1730. return;
  1731. #endif
  1732. }
  1733. #if 0
  1734. static void testcase_DSI_command_mode(void)
  1735. {
  1736. int32_t status = 0;
  1737. cmdqRecHandle hTrigger;
  1738. cmdqRecHandle hSetting;
  1739. struct TaskStruct *pTask = NULL;
  1740. /*
  1741. build the trigger thread (normal priority)
  1742. WRITE to query TE signal
  1743. WFE wait for TE(CMDQ_EVENT_MDP_DSI0_TE_SOF)
  1744. WFE wait stream done (CMDQ_EVENT_MUTEX0_STREAM_EOF? TODO: which stream done??
  1745. and clear (CMDQ_EVENT_MUTEX0_STREAM_EOF)
  1746. WRITE enable mutex to start engine (DISP_MUTEX0_EN in disp_mutex_coda.xls)
  1747. EOC (to issue interrupt, may need callback??? why need this one???)
  1748. JUMP to loopback to start */
  1749. /* TODO: use a special repeat mode in cmdqRecRepeatFlush() */
  1750. /* use CMDQ_SCENARIO_JPEG_DEC just to use another thread */
  1751. cmdqRecCreate(CMDQ_SCENARIO_JPEG_DEC, &hTrigger);
  1752. /* cmdqRecWrite(hTrigger, */
  1753. /*
  1754. build the setting thread (high priority)
  1755. */
  1756. cmdqRecCreate(CMDQ_SCENARIO_PRIMARY_MEMOUT, &hSetting);
  1757. cmdqRecWait(hSetting, CMDQ_EVENT_MUTEX0_STREAM_EOF);
  1758. cmdqRecMark(hSetting);
  1759. int i = 0;
  1760. for (i = 0; i < 200; ++i) {
  1761. /* increase cmd count but do not raise irq */
  1762. cmdq_append_command(hSetting, CMDQ_CODE_EOC, 0, 0);
  1763. }
  1764. cmdqRecMark(hSetting);
  1765. /* Jump back to head */
  1766. cmdq_append_command(hSetting, CMDQ_CODE_JUMP, 0, /* bit 32: is_absolute */
  1767. -hSetting->blockSize);
  1768. hSetting->priority = 1;
  1769. /* Both are inifinte loop
  1770. so we call async then sync */
  1771. ret = _test_submit_async(hTrigger, &pTask);
  1772. status = cmdqCoreSubmitTask(hSetting->scenario,
  1773. hSetting->priority,
  1774. hSetting->engineFlag, hSetting->pBuffer, hSetting->blockSize);
  1775. }
  1776. #endif
  1777. void testcase_alloc_path(void)
  1778. {
  1779. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1780. CMDQ_MSG("%s begin\n", __func__);
  1781. cmdq_sec_allocate_path_resource_unlocked();
  1782. CMDQ_MSG("%s end\n", __func__);
  1783. #else
  1784. CMDQ_ERR("SVP feature not supported\n");
  1785. return;
  1786. #endif
  1787. }
  1788. void testcase_write_stress_test(void)
  1789. {
  1790. int32_t loop;
  1791. CMDQ_LOG("%s\n", __func__);
  1792. loop = 1;
  1793. CMDQ_LOG("=============== loop x %d ===============\n", loop);
  1794. _testcase_simplest_command_loop_submit(loop, CMDQ_SCENARIO_DEBUG, 0, gCmdqTestSecure);
  1795. loop = 100;
  1796. CMDQ_LOG("=============== loop x %d ===============\n", loop);
  1797. _testcase_simplest_command_loop_submit(loop, CMDQ_SCENARIO_DEBUG, 0, gCmdqTestSecure);
  1798. CMDQ_LOG("%s END\n", __func__);
  1799. }
  1800. void testcase_read_smi_larb(void)
  1801. {
  1802. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1803. uint32_t larb = 0;
  1804. struct transmitBufferStruct secureData;
  1805. CMDQ_LOG("harry >>> read smi larb0 & larb4 register\n");
  1806. memset(&secureData, 0, sizeof(secureData));
  1807. secureData.pBuffer = &larb;
  1808. secureData.size = sizeof(larb);
  1809. /* 2 register secure buffer */
  1810. if (0 != cmdqSecRegisterSecureBuffer(&secureData))
  1811. return;
  1812. /* 3 service call */
  1813. cmdqSecServiceCall(&secureData, CMD_CMDQ_TL_DUMP_SMI_LARB);
  1814. /* 4 unregister secure buffer */
  1815. cmdqSecUnRegisterSecureBuffer(&secureData);
  1816. #else
  1817. CMDQ_ERR("sorry, SVP config is not enabled\n");
  1818. #endif
  1819. }
  1820. enum CMDQ_TESTCASE_ENUM {
  1821. CMDQ_TESTCASE_ALL = 0,
  1822. CMDQ_TESTCASE_BASIC = 1,
  1823. CMDQ_TESTCASE_ERROR = 2,
  1824. CMDQ_TESTCASE_READ_REG_REQUEST, /*user request get some registers' value when task execution */
  1825. CMDQ_TESTCASE_GPR,
  1826. CMDQ_TESTCASE_SW_TIMEOUT_HANDLE,
  1827. CMDQ_TESTCASE_END, /* always at the end */
  1828. };
  1829. ssize_t cmdq_test_proc(struct file *fp, char __user *u, size_t s, loff_t *l)
  1830. {
  1831. uint32_t testId = 0;
  1832. bool isSecureTest;
  1833. mutex_lock(&gCmdqTestProcLock);
  1834. smp_mb(); /*coding style requires to comment after smb_mb to explain why need memory_barrier */
  1835. /* CMDQ_LOG("[TESTCASE]CONFIG: normal: %d, secure: %d\n", gCmdqTestConfig[0], gCmdqTestConfig[1]); */
  1836. testId = gCmdqTestConfig[0];
  1837. isSecureTest = (0 < gCmdqTestConfig[1]) ? (true) : (false);
  1838. mutex_unlock(&gCmdqTestProcLock);
  1839. /* trigger test case here */
  1840. CMDQ_LOG("cmdq_test_proc run test config test type:%d,test data:%d\n", gCmdqTestConfig[1],
  1841. gCmdqTestConfig[0]);
  1842. /* unconditionally set CMDQ_SYNC_TOKEN_CONFIG_ALLOW and mutex STREAM_DONE
  1843. so that DISPSYS scenarios may pass check. */
  1844. cmdqCoreSetEvent(CMDQ_SYNC_TOKEN_STREAM_EOF);
  1845. cmdqCoreSetEvent(CMDQ_EVENT_MUTEX0_STREAM_EOF);
  1846. cmdqCoreSetEvent(CMDQ_EVENT_MUTEX1_STREAM_EOF);
  1847. cmdqCoreSetEvent(CMDQ_EVENT_MUTEX2_STREAM_EOF);
  1848. cmdqCoreSetEvent(CMDQ_EVENT_MUTEX3_STREAM_EOF);
  1849. switch (gCmdqTestConfig[0]) {
  1850. case 10:
  1851. #ifdef CMDQ_SECURE_PATH_SUPPORT
  1852. CMDQ_LOG("enter testcase 10\n");
  1853. cmdq_sec_init_share_memory();
  1854. #else
  1855. CMDQ_ERR("SVP feature not supported\n");
  1856. #endif
  1857. break;
  1858. case 11:
  1859. CMDQ_LOG("enter testcase 11\n");
  1860. testcase_read_init_memory();
  1861. break;
  1862. case 12:
  1863. CMDQ_LOG("enter testcase 12\n");
  1864. testcase_alloc_path();
  1865. break;
  1866. case 13:
  1867. CMDQ_LOG("enter testcase 13\n");
  1868. testcase_write_with_mask();
  1869. break;
  1870. /*
  1871. ** testcase 112 is to test CMDQ loglevel
  1872. ** you can use echo 0/1/2/3 > /proc/mtk_cmdq_debug/log_level to set log level
  1873. ** and use echo "0 112">/proc/cmdq_test/test to run this testcase
  1874. */
  1875. case 112:
  1876. #if 0
  1877. CMDQ_MSG("CMDQ_MSG log\n");
  1878. CMDQ_LOG("CMDQ_LOG log\n");
  1879. CMDQ_ERR("CMDQ_ERR log\n");
  1880. #endif
  1881. testcase_read_smi_larb();
  1882. break;
  1883. case 111:
  1884. CMDQ_LOG("enter testcase 111\n");
  1885. testcase_cmdqRecFlushAsyncCallback();
  1886. break;
  1887. /* testcase for wait hardware event */
  1888. case 110:
  1889. CMDQ_LOG("enter testcase 110\n");
  1890. testcase_wait_disp_ovl0_eof();
  1891. break;
  1892. case 109:
  1893. CMDQ_LOG("enter testcase 109\n");
  1894. testcase_wait_disp_rdma0_eof();
  1895. break;
  1896. case 108:
  1897. CMDQ_LOG("enter testcase 108\n");
  1898. testcase_wait_mutex0_stream_eof();
  1899. break;
  1900. case 107:
  1901. CMDQ_LOG("enter testcase 107\n");
  1902. test_cmdq_sec_write();
  1903. break;
  1904. case 106:
  1905. CMDQ_LOG("enter testcase 106\n");
  1906. testcase_use_backup_slot_to_debug();
  1907. break;
  1908. case 105:
  1909. CMDQ_LOG("enter testcase 105\n");
  1910. ctrolThreadRunning();
  1911. break;
  1912. case 104:
  1913. CMDQ_LOG("enter testcase 104\n");
  1914. start_poll_register();
  1915. break;
  1916. case 103:
  1917. CMDQ_LOG("enter testcase 103\n");
  1918. testcase_secure_meta_data();
  1919. break;
  1920. case 102:
  1921. CMDQ_LOG("enter testcase 102\n");
  1922. testcase_secure_disp_scenario();
  1923. break;
  1924. case 101:
  1925. CMDQ_LOG("enter testcase 101\n");
  1926. testcase_write_stress_test();
  1927. break;
  1928. case 100:
  1929. CMDQ_LOG("enter testcase 100\n");
  1930. testcase_secure_basic();
  1931. break;
  1932. case 99:
  1933. CMDQ_LOG("enter testcase 99\n");
  1934. testcase_write();
  1935. break;
  1936. case 98:
  1937. CMDQ_LOG("enter testcase 98\n");
  1938. testcase_errors();
  1939. break;
  1940. case 97:
  1941. testcase_scenario();
  1942. break;
  1943. case 96:
  1944. testcase_sync_token();
  1945. break;
  1946. case 95:
  1947. testcase_write_address();
  1948. break;
  1949. case 94:
  1950. testcase_async_request();
  1951. break;
  1952. case 93:
  1953. testcase_async_suspend_resume();
  1954. break;
  1955. case 92:
  1956. testcase_async_request_partial_engine();
  1957. break;
  1958. case 91:
  1959. testcase_prefetch_scenarios();
  1960. break;
  1961. case 90:
  1962. testcase_loop();
  1963. break;
  1964. case 89:
  1965. testcase_trigger_thread();
  1966. break;
  1967. case 88:
  1968. testcase_multiple_async_request();
  1969. break;
  1970. case 87:
  1971. testcase_get_result();
  1972. break;
  1973. case 86:
  1974. testcase_read_to_data_reg();
  1975. break;
  1976. case 85:
  1977. testcase_dram_access();
  1978. break;
  1979. case 84:
  1980. testcase_backup_register();
  1981. break;
  1982. case 83:
  1983. testcase_fire_and_forget();
  1984. break;
  1985. case 82:
  1986. testcase_sync_token_threaded();
  1987. break;
  1988. case 81:
  1989. testcase_long_command();
  1990. break;
  1991. case 80:
  1992. testcase_clkmgr();
  1993. break;
  1994. case 79:
  1995. testcase_perisys_apb();
  1996. break;
  1997. case 78:
  1998. testcase_backup_reg_to_slot();
  1999. break;
  2000. case 77:
  2001. testcase_thread_dispatch();
  2002. break;
  2003. case 76:
  2004. testcase_emergency_buffer();
  2005. break;
  2006. case 75:
  2007. testcase_full_thread_array();
  2008. break;
  2009. case 74:
  2010. testcase_module_full_dump();
  2011. break;
  2012. case 73:
  2013. testcase_write_from_data_reg();
  2014. break;
  2015. case 72:
  2016. testcase_update_value_to_slot();
  2017. break;
  2018. case 71:
  2019. testcase_poll();
  2020. break;
  2021. case 70:
  2022. testcase_write_reg_from_slot();
  2023. break;
  2024. case CMDQ_TESTCASE_ERROR:
  2025. testcase_errors();
  2026. break;
  2027. case CMDQ_TESTCASE_BASIC:
  2028. testcase_write();
  2029. testcase_poll();
  2030. testcase_scenario();
  2031. break;
  2032. case CMDQ_TESTCASE_READ_REG_REQUEST:
  2033. testcase_get_result();
  2034. break;
  2035. case CMDQ_TESTCASE_GPR:
  2036. testcase_read_to_data_reg(); /* must verify! */
  2037. testcase_dram_access();
  2038. break;
  2039. case CMDQ_TESTCASE_ALL:
  2040. default:
  2041. testcase_multiple_async_request();
  2042. testcase_read_to_data_reg();
  2043. testcase_get_result();
  2044. testcase_errors();
  2045. testcase_scenario();
  2046. testcase_sync_token();
  2047. testcase_write();
  2048. testcase_write_address();
  2049. testcase_async_request();
  2050. testcase_async_suspend_resume();
  2051. testcase_errors();
  2052. testcase_async_request_partial_engine();
  2053. testcase_prefetch_scenarios();
  2054. testcase_loop();
  2055. testcase_trigger_thread();
  2056. testcase_prefetch();
  2057. testcase_multiple_async_request();
  2058. /*testcase_sync_token_threaded(); */
  2059. testcase_read_to_data_reg();
  2060. testcase_get_result();
  2061. testcase_long_command();
  2062. testcase_loop();
  2063. /* testcase_clkmgr(); */
  2064. testcase_dram_access();
  2065. testcase_write();
  2066. testcase_perisys_apb();
  2067. testcase_errors();
  2068. testcase_backup_register();
  2069. testcase_fire_and_forget();
  2070. testcase_backup_reg_to_slot();
  2071. testcase_thread_dispatch();
  2072. break;
  2073. }
  2074. CMDQ_MSG("cmdq_test_proc ended\n");
  2075. return 0;
  2076. }
  2077. static ssize_t cmdq_write_test_proc_config(struct file *file,
  2078. const char __user *userBuf, size_t count, loff_t *data)
  2079. {
  2080. char desc[MAXLINESIZE];
  2081. int testType = -1;
  2082. int newTestSuit = -1;
  2083. int32_t paramData = 0;
  2084. int32_t len = 0;
  2085. /* copy user input */
  2086. len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
  2087. if (copy_from_user(desc, userBuf, count)) {
  2088. CMDQ_ERR("TEST_CONFIG: data fail\n");
  2089. return 0;
  2090. }
  2091. desc[len] = '\0';
  2092. if (0 >= sscanf(desc, "%d %d %d", &testType, &newTestSuit, &paramData)) {
  2093. /* sscanf returns the number of items in argument list successfully filled. */
  2094. CMDQ_ERR("TEST_CONFIG: sscanf failed\n");
  2095. return count;
  2096. }
  2097. if ((0 > testType) || (2 <= testType) || (-1 == newTestSuit)) {
  2098. CMDQ_ERR("TEST_CONFIG: testType:%d, newTestSuit:%d\n", testType, newTestSuit);
  2099. return count;
  2100. }
  2101. mutex_lock(&gCmdqTestProcLock);
  2102. smp_mb(); /*coding style requires to comment after smb_mb to explain why need memory_barrier */
  2103. gCmdqTestConfig[0] = newTestSuit;
  2104. gCmdqTestConfig[1] = testType;
  2105. gCmdqTestConfig[2] = paramData;
  2106. gCmdqTestSecure = (testType == 1) ? (true) : (false);
  2107. CMDQ_LOG("set write_config test type:%d,test data:%d, param data:%d\n", gCmdqTestConfig[1],
  2108. gCmdqTestConfig[0], gCmdqTestConfig[2]);
  2109. mutex_unlock(&gCmdqTestProcLock);
  2110. return count;
  2111. }
  2112. static int cmdq_test_open(struct inode *pInode, struct file *pFile)
  2113. {
  2114. return 0;
  2115. }
  2116. static const struct file_operations cmdq_fops = {
  2117. .owner = THIS_MODULE,
  2118. .open = cmdq_test_open,
  2119. .read = cmdq_test_proc,
  2120. .write = cmdq_write_test_proc_config,
  2121. };
  2122. static int __init cmdq_test_init(void)
  2123. {
  2124. #ifdef _CMDQ_TEST_PROC_
  2125. CMDQ_MSG("cmdq_test_init\n");
  2126. /* Mout proc entry for debug */
  2127. gCmdqTestProcEntry = proc_mkdir("cmdq_test", NULL);
  2128. if (NULL != gCmdqTestProcEntry) {
  2129. if (NULL == proc_create("test", 0660, gCmdqTestProcEntry, &cmdq_fops))
  2130. CMDQ_MSG("cmdq_test_init failed\n");
  2131. }
  2132. #endif
  2133. return 0;
  2134. }
  2135. static void __exit cmdq_test_exit(void)
  2136. {
  2137. #ifdef _CMDQ_TEST_PROC_
  2138. CMDQ_MSG("cmdq_test_exit\n");
  2139. if (NULL != gCmdqTestProcEntry) {
  2140. proc_remove(gCmdqTestProcEntry);
  2141. gCmdqTestProcEntry = NULL;
  2142. }
  2143. #endif
  2144. }
  2145. module_init(cmdq_test_init);
  2146. module_exit(cmdq_test_exit);
  2147. MODULE_LICENSE("GPL");