cmdq_test.c 71 KB

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