sde_rotator_r3.c 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #define pr_fmt(fmt) "%s:%d: " fmt, __func__, __LINE__
  7. #include <linux/platform_device.h>
  8. #include <linux/version.h>
  9. #include <linux/module.h>
  10. #include <linux/fs.h>
  11. #include <linux/file.h>
  12. #include <linux/delay.h>
  13. #include <linux/debugfs.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/dma-buf.h>
  17. #include <linux/clk.h>
  18. #include <linux/clk/qcom.h>
  19. #include "sde_rotator_core.h"
  20. #include "sde_rotator_util.h"
  21. #include "sde_rotator_smmu.h"
  22. #include "sde_rotator_r3.h"
  23. #include "sde_rotator_r3_internal.h"
  24. #include "sde_rotator_r3_hwio.h"
  25. #include "sde_rotator_r3_debug.h"
  26. #include "sde_rotator_trace.h"
  27. #include "sde_rotator_debug.h"
  28. #include "sde_rotator_vbif.h"
  29. #define RES_UHD (3840*2160)
  30. #define MS_TO_US(t) ((t) * USEC_PER_MSEC)
  31. /* traffic shaping clock ticks = finish_time x 19.2MHz */
  32. #define TRAFFIC_SHAPE_CLKTICK_14MS 268800
  33. #define TRAFFIC_SHAPE_CLKTICK_12MS 230400
  34. #define TRAFFIC_SHAPE_VSYNC_CLK 19200000
  35. /* wait for at most 2 vsync for lowest refresh rate (24hz) */
  36. #define KOFF_TIMEOUT (42 * 8)
  37. /*
  38. * When in sbuf mode, select a much longer wait, to allow the other driver
  39. * to detect timeouts and abort if necessary.
  40. */
  41. #define KOFF_TIMEOUT_SBUF (10000)
  42. /* default stream buffer headroom in lines */
  43. #define DEFAULT_SBUF_HEADROOM 20
  44. #define DEFAULT_UBWC_MALSIZE 0
  45. #define DEFAULT_UBWC_SWIZZLE 0
  46. #define DEFAULT_MAXLINEWIDTH 4096
  47. /* stride alignment requirement for avoiding partial writes */
  48. #define PARTIAL_WRITE_ALIGNMENT 0x1F
  49. /* Macro for constructing the REGDMA command */
  50. #define SDE_REGDMA_WRITE(p, off, data) \
  51. do { \
  52. SDEROT_DBG("SDEREG.W:[%s:0x%X] <= 0x%X\n", #off, (off),\
  53. (u32)(data));\
  54. writel_relaxed( \
  55. (REGDMA_OP_REGWRITE | \
  56. ((off) & REGDMA_ADDR_OFFSET_MASK)), \
  57. p); \
  58. p += sizeof(u32); \
  59. writel_relaxed(data, p); \
  60. p += sizeof(u32); \
  61. } while (0)
  62. #define SDE_REGDMA_MODIFY(p, off, mask, data) \
  63. do { \
  64. SDEROT_DBG("SDEREG.M:[%s:0x%X] <= 0x%X\n", #off, (off),\
  65. (u32)(data));\
  66. writel_relaxed( \
  67. (REGDMA_OP_REGMODIFY | \
  68. ((off) & REGDMA_ADDR_OFFSET_MASK)), \
  69. p); \
  70. p += sizeof(u32); \
  71. writel_relaxed(mask, p); \
  72. p += sizeof(u32); \
  73. writel_relaxed(data, p); \
  74. p += sizeof(u32); \
  75. } while (0)
  76. #define SDE_REGDMA_BLKWRITE_INC(p, off, len) \
  77. do { \
  78. SDEROT_DBG("SDEREG.B:[%s:0x%X:0x%X]\n", #off, (off),\
  79. (u32)(len));\
  80. writel_relaxed( \
  81. (REGDMA_OP_BLKWRITE_INC | \
  82. ((off) & REGDMA_ADDR_OFFSET_MASK)), \
  83. p); \
  84. p += sizeof(u32); \
  85. writel_relaxed(len, p); \
  86. p += sizeof(u32); \
  87. } while (0)
  88. #define SDE_REGDMA_BLKWRITE_DATA(p, data) \
  89. do { \
  90. SDEROT_DBG("SDEREG.I:[:] <= 0x%X\n", (u32)(data));\
  91. writel_relaxed(data, p); \
  92. p += sizeof(u32); \
  93. } while (0)
  94. #define SDE_REGDMA_READ(p, data) \
  95. do { \
  96. data = readl_relaxed(p); \
  97. p += sizeof(u32); \
  98. } while (0)
  99. /* Macro for directly accessing mapped registers */
  100. #define SDE_ROTREG_WRITE(base, off, data) \
  101. do { \
  102. SDEROT_DBG("SDEREG.D:[%s:0x%X] <= 0x%X\n", #off, (off)\
  103. , (u32)(data));\
  104. writel_relaxed(data, (base + (off))); \
  105. } while (0)
  106. #define SDE_ROTREG_READ(base, off) \
  107. readl_relaxed(base + (off))
  108. #define SDE_ROTTOP_IN_OFFLINE_MODE(_rottop_op_mode_) \
  109. (((_rottop_op_mode_) & ROTTOP_OP_MODE_ROT_OUT_MASK) == 0)
  110. static const u32 sde_hw_rotator_v3_inpixfmts[] = {
  111. SDE_PIX_FMT_XRGB_8888,
  112. SDE_PIX_FMT_ARGB_8888,
  113. SDE_PIX_FMT_ABGR_8888,
  114. SDE_PIX_FMT_RGBA_8888,
  115. SDE_PIX_FMT_BGRA_8888,
  116. SDE_PIX_FMT_RGBX_8888,
  117. SDE_PIX_FMT_BGRX_8888,
  118. SDE_PIX_FMT_XBGR_8888,
  119. SDE_PIX_FMT_RGBA_5551,
  120. SDE_PIX_FMT_ARGB_1555,
  121. SDE_PIX_FMT_ABGR_1555,
  122. SDE_PIX_FMT_BGRA_5551,
  123. SDE_PIX_FMT_BGRX_5551,
  124. SDE_PIX_FMT_RGBX_5551,
  125. SDE_PIX_FMT_XBGR_1555,
  126. SDE_PIX_FMT_XRGB_1555,
  127. SDE_PIX_FMT_ARGB_4444,
  128. SDE_PIX_FMT_RGBA_4444,
  129. SDE_PIX_FMT_BGRA_4444,
  130. SDE_PIX_FMT_ABGR_4444,
  131. SDE_PIX_FMT_RGBX_4444,
  132. SDE_PIX_FMT_XRGB_4444,
  133. SDE_PIX_FMT_BGRX_4444,
  134. SDE_PIX_FMT_XBGR_4444,
  135. SDE_PIX_FMT_RGB_888,
  136. SDE_PIX_FMT_BGR_888,
  137. SDE_PIX_FMT_RGB_565,
  138. SDE_PIX_FMT_BGR_565,
  139. SDE_PIX_FMT_Y_CB_CR_H2V2,
  140. SDE_PIX_FMT_Y_CR_CB_H2V2,
  141. SDE_PIX_FMT_Y_CR_CB_GH2V2,
  142. SDE_PIX_FMT_Y_CBCR_H2V2,
  143. SDE_PIX_FMT_Y_CRCB_H2V2,
  144. SDE_PIX_FMT_Y_CBCR_H1V2,
  145. SDE_PIX_FMT_Y_CRCB_H1V2,
  146. SDE_PIX_FMT_Y_CBCR_H2V1,
  147. SDE_PIX_FMT_Y_CRCB_H2V1,
  148. SDE_PIX_FMT_YCBYCR_H2V1,
  149. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  150. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  151. SDE_PIX_FMT_RGBA_8888_UBWC,
  152. SDE_PIX_FMT_RGBX_8888_UBWC,
  153. SDE_PIX_FMT_RGB_565_UBWC,
  154. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  155. SDE_PIX_FMT_RGBA_1010102,
  156. SDE_PIX_FMT_RGBX_1010102,
  157. SDE_PIX_FMT_ARGB_2101010,
  158. SDE_PIX_FMT_XRGB_2101010,
  159. SDE_PIX_FMT_BGRA_1010102,
  160. SDE_PIX_FMT_BGRX_1010102,
  161. SDE_PIX_FMT_ABGR_2101010,
  162. SDE_PIX_FMT_XBGR_2101010,
  163. SDE_PIX_FMT_RGBA_1010102_UBWC,
  164. SDE_PIX_FMT_RGBX_1010102_UBWC,
  165. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  166. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  167. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  168. };
  169. static const u32 sde_hw_rotator_v3_outpixfmts[] = {
  170. SDE_PIX_FMT_XRGB_8888,
  171. SDE_PIX_FMT_ARGB_8888,
  172. SDE_PIX_FMT_ABGR_8888,
  173. SDE_PIX_FMT_RGBA_8888,
  174. SDE_PIX_FMT_BGRA_8888,
  175. SDE_PIX_FMT_RGBX_8888,
  176. SDE_PIX_FMT_BGRX_8888,
  177. SDE_PIX_FMT_XBGR_8888,
  178. SDE_PIX_FMT_RGBA_5551,
  179. SDE_PIX_FMT_ARGB_1555,
  180. SDE_PIX_FMT_ABGR_1555,
  181. SDE_PIX_FMT_BGRA_5551,
  182. SDE_PIX_FMT_BGRX_5551,
  183. SDE_PIX_FMT_RGBX_5551,
  184. SDE_PIX_FMT_XBGR_1555,
  185. SDE_PIX_FMT_XRGB_1555,
  186. SDE_PIX_FMT_ARGB_4444,
  187. SDE_PIX_FMT_RGBA_4444,
  188. SDE_PIX_FMT_BGRA_4444,
  189. SDE_PIX_FMT_ABGR_4444,
  190. SDE_PIX_FMT_RGBX_4444,
  191. SDE_PIX_FMT_XRGB_4444,
  192. SDE_PIX_FMT_BGRX_4444,
  193. SDE_PIX_FMT_XBGR_4444,
  194. SDE_PIX_FMT_RGB_888,
  195. SDE_PIX_FMT_BGR_888,
  196. SDE_PIX_FMT_RGB_565,
  197. SDE_PIX_FMT_BGR_565,
  198. /* SDE_PIX_FMT_Y_CB_CR_H2V2 */
  199. /* SDE_PIX_FMT_Y_CR_CB_H2V2 */
  200. /* SDE_PIX_FMT_Y_CR_CB_GH2V2 */
  201. SDE_PIX_FMT_Y_CBCR_H2V2,
  202. SDE_PIX_FMT_Y_CRCB_H2V2,
  203. SDE_PIX_FMT_Y_CBCR_H1V2,
  204. SDE_PIX_FMT_Y_CRCB_H1V2,
  205. SDE_PIX_FMT_Y_CBCR_H2V1,
  206. SDE_PIX_FMT_Y_CRCB_H2V1,
  207. /* SDE_PIX_FMT_YCBYCR_H2V1 */
  208. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  209. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  210. SDE_PIX_FMT_RGBA_8888_UBWC,
  211. SDE_PIX_FMT_RGBX_8888_UBWC,
  212. SDE_PIX_FMT_RGB_565_UBWC,
  213. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  214. SDE_PIX_FMT_RGBA_1010102,
  215. SDE_PIX_FMT_RGBX_1010102,
  216. /* SDE_PIX_FMT_ARGB_2101010 */
  217. /* SDE_PIX_FMT_XRGB_2101010 */
  218. SDE_PIX_FMT_BGRA_1010102,
  219. SDE_PIX_FMT_BGRX_1010102,
  220. /* SDE_PIX_FMT_ABGR_2101010 */
  221. /* SDE_PIX_FMT_XBGR_2101010 */
  222. SDE_PIX_FMT_RGBA_1010102_UBWC,
  223. SDE_PIX_FMT_RGBX_1010102_UBWC,
  224. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  225. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  226. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  227. };
  228. static const u32 sde_hw_rotator_v4_inpixfmts[] = {
  229. SDE_PIX_FMT_XRGB_8888,
  230. SDE_PIX_FMT_ARGB_8888,
  231. SDE_PIX_FMT_ABGR_8888,
  232. SDE_PIX_FMT_RGBA_8888,
  233. SDE_PIX_FMT_BGRA_8888,
  234. SDE_PIX_FMT_RGBX_8888,
  235. SDE_PIX_FMT_BGRX_8888,
  236. SDE_PIX_FMT_XBGR_8888,
  237. SDE_PIX_FMT_RGBA_5551,
  238. SDE_PIX_FMT_ARGB_1555,
  239. SDE_PIX_FMT_ABGR_1555,
  240. SDE_PIX_FMT_BGRA_5551,
  241. SDE_PIX_FMT_BGRX_5551,
  242. SDE_PIX_FMT_RGBX_5551,
  243. SDE_PIX_FMT_XBGR_1555,
  244. SDE_PIX_FMT_XRGB_1555,
  245. SDE_PIX_FMT_ARGB_4444,
  246. SDE_PIX_FMT_RGBA_4444,
  247. SDE_PIX_FMT_BGRA_4444,
  248. SDE_PIX_FMT_ABGR_4444,
  249. SDE_PIX_FMT_RGBX_4444,
  250. SDE_PIX_FMT_XRGB_4444,
  251. SDE_PIX_FMT_BGRX_4444,
  252. SDE_PIX_FMT_XBGR_4444,
  253. SDE_PIX_FMT_RGB_888,
  254. SDE_PIX_FMT_BGR_888,
  255. SDE_PIX_FMT_RGB_565,
  256. SDE_PIX_FMT_BGR_565,
  257. SDE_PIX_FMT_Y_CB_CR_H2V2,
  258. SDE_PIX_FMT_Y_CR_CB_H2V2,
  259. SDE_PIX_FMT_Y_CR_CB_GH2V2,
  260. SDE_PIX_FMT_Y_CBCR_H2V2,
  261. SDE_PIX_FMT_Y_CRCB_H2V2,
  262. SDE_PIX_FMT_Y_CBCR_H1V2,
  263. SDE_PIX_FMT_Y_CRCB_H1V2,
  264. SDE_PIX_FMT_Y_CBCR_H2V1,
  265. SDE_PIX_FMT_Y_CRCB_H2V1,
  266. SDE_PIX_FMT_YCBYCR_H2V1,
  267. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  268. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  269. SDE_PIX_FMT_RGBA_8888_UBWC,
  270. SDE_PIX_FMT_RGBX_8888_UBWC,
  271. SDE_PIX_FMT_RGB_565_UBWC,
  272. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  273. SDE_PIX_FMT_RGBA_1010102,
  274. SDE_PIX_FMT_RGBX_1010102,
  275. SDE_PIX_FMT_ARGB_2101010,
  276. SDE_PIX_FMT_XRGB_2101010,
  277. SDE_PIX_FMT_BGRA_1010102,
  278. SDE_PIX_FMT_BGRX_1010102,
  279. SDE_PIX_FMT_ABGR_2101010,
  280. SDE_PIX_FMT_XBGR_2101010,
  281. SDE_PIX_FMT_RGBA_1010102_UBWC,
  282. SDE_PIX_FMT_RGBX_1010102_UBWC,
  283. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  284. SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS,
  285. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  286. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  287. SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC,
  288. SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE,
  289. SDE_PIX_FMT_Y_CBCR_H2V2_TILE,
  290. SDE_PIX_FMT_Y_CRCB_H2V2_TILE,
  291. SDE_PIX_FMT_XRGB_8888_TILE,
  292. SDE_PIX_FMT_ARGB_8888_TILE,
  293. SDE_PIX_FMT_ABGR_8888_TILE,
  294. SDE_PIX_FMT_XBGR_8888_TILE,
  295. SDE_PIX_FMT_RGBA_8888_TILE,
  296. SDE_PIX_FMT_BGRA_8888_TILE,
  297. SDE_PIX_FMT_RGBX_8888_TILE,
  298. SDE_PIX_FMT_BGRX_8888_TILE,
  299. SDE_PIX_FMT_RGBA_1010102_TILE,
  300. SDE_PIX_FMT_RGBX_1010102_TILE,
  301. SDE_PIX_FMT_ARGB_2101010_TILE,
  302. SDE_PIX_FMT_XRGB_2101010_TILE,
  303. SDE_PIX_FMT_BGRA_1010102_TILE,
  304. SDE_PIX_FMT_BGRX_1010102_TILE,
  305. SDE_PIX_FMT_ABGR_2101010_TILE,
  306. SDE_PIX_FMT_XBGR_2101010_TILE,
  307. };
  308. static const u32 sde_hw_rotator_v4_outpixfmts[] = {
  309. SDE_PIX_FMT_XRGB_8888,
  310. SDE_PIX_FMT_ARGB_8888,
  311. SDE_PIX_FMT_ABGR_8888,
  312. SDE_PIX_FMT_RGBA_8888,
  313. SDE_PIX_FMT_BGRA_8888,
  314. SDE_PIX_FMT_RGBX_8888,
  315. SDE_PIX_FMT_BGRX_8888,
  316. SDE_PIX_FMT_XBGR_8888,
  317. SDE_PIX_FMT_RGBA_5551,
  318. SDE_PIX_FMT_ARGB_1555,
  319. SDE_PIX_FMT_ABGR_1555,
  320. SDE_PIX_FMT_BGRA_5551,
  321. SDE_PIX_FMT_BGRX_5551,
  322. SDE_PIX_FMT_RGBX_5551,
  323. SDE_PIX_FMT_XBGR_1555,
  324. SDE_PIX_FMT_XRGB_1555,
  325. SDE_PIX_FMT_ARGB_4444,
  326. SDE_PIX_FMT_RGBA_4444,
  327. SDE_PIX_FMT_BGRA_4444,
  328. SDE_PIX_FMT_ABGR_4444,
  329. SDE_PIX_FMT_RGBX_4444,
  330. SDE_PIX_FMT_XRGB_4444,
  331. SDE_PIX_FMT_BGRX_4444,
  332. SDE_PIX_FMT_XBGR_4444,
  333. SDE_PIX_FMT_RGB_888,
  334. SDE_PIX_FMT_BGR_888,
  335. SDE_PIX_FMT_RGB_565,
  336. SDE_PIX_FMT_BGR_565,
  337. /* SDE_PIX_FMT_Y_CB_CR_H2V2 */
  338. /* SDE_PIX_FMT_Y_CR_CB_H2V2 */
  339. /* SDE_PIX_FMT_Y_CR_CB_GH2V2 */
  340. SDE_PIX_FMT_Y_CBCR_H2V2,
  341. SDE_PIX_FMT_Y_CRCB_H2V2,
  342. SDE_PIX_FMT_Y_CBCR_H1V2,
  343. SDE_PIX_FMT_Y_CRCB_H1V2,
  344. SDE_PIX_FMT_Y_CBCR_H2V1,
  345. SDE_PIX_FMT_Y_CRCB_H2V1,
  346. /* SDE_PIX_FMT_YCBYCR_H2V1 */
  347. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  348. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  349. SDE_PIX_FMT_RGBA_8888_UBWC,
  350. SDE_PIX_FMT_RGBX_8888_UBWC,
  351. SDE_PIX_FMT_RGB_565_UBWC,
  352. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  353. SDE_PIX_FMT_RGBA_1010102,
  354. SDE_PIX_FMT_RGBX_1010102,
  355. SDE_PIX_FMT_ARGB_2101010,
  356. SDE_PIX_FMT_XRGB_2101010,
  357. SDE_PIX_FMT_BGRA_1010102,
  358. SDE_PIX_FMT_BGRX_1010102,
  359. SDE_PIX_FMT_ABGR_2101010,
  360. SDE_PIX_FMT_XBGR_2101010,
  361. SDE_PIX_FMT_RGBA_1010102_UBWC,
  362. SDE_PIX_FMT_RGBX_1010102_UBWC,
  363. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  364. SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS,
  365. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  366. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  367. SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC,
  368. SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE,
  369. SDE_PIX_FMT_Y_CBCR_H2V2_TILE,
  370. SDE_PIX_FMT_Y_CRCB_H2V2_TILE,
  371. SDE_PIX_FMT_XRGB_8888_TILE,
  372. SDE_PIX_FMT_ARGB_8888_TILE,
  373. SDE_PIX_FMT_ABGR_8888_TILE,
  374. SDE_PIX_FMT_XBGR_8888_TILE,
  375. SDE_PIX_FMT_RGBA_8888_TILE,
  376. SDE_PIX_FMT_BGRA_8888_TILE,
  377. SDE_PIX_FMT_RGBX_8888_TILE,
  378. SDE_PIX_FMT_BGRX_8888_TILE,
  379. SDE_PIX_FMT_RGBA_1010102_TILE,
  380. SDE_PIX_FMT_RGBX_1010102_TILE,
  381. SDE_PIX_FMT_ARGB_2101010_TILE,
  382. SDE_PIX_FMT_XRGB_2101010_TILE,
  383. SDE_PIX_FMT_BGRA_1010102_TILE,
  384. SDE_PIX_FMT_BGRX_1010102_TILE,
  385. SDE_PIX_FMT_ABGR_2101010_TILE,
  386. SDE_PIX_FMT_XBGR_2101010_TILE,
  387. };
  388. static const u32 sde_hw_rotator_v5_inpixfmts[] = {
  389. SDE_PIX_FMT_XRGB_8888,
  390. SDE_PIX_FMT_ARGB_8888,
  391. SDE_PIX_FMT_ABGR_8888,
  392. SDE_PIX_FMT_RGBA_8888,
  393. SDE_PIX_FMT_BGRA_8888,
  394. SDE_PIX_FMT_RGBX_8888,
  395. SDE_PIX_FMT_BGRX_8888,
  396. SDE_PIX_FMT_XBGR_8888,
  397. SDE_PIX_FMT_RGBA_5551,
  398. SDE_PIX_FMT_ARGB_1555,
  399. SDE_PIX_FMT_ABGR_1555,
  400. SDE_PIX_FMT_BGRA_5551,
  401. SDE_PIX_FMT_BGRX_5551,
  402. SDE_PIX_FMT_RGBX_5551,
  403. SDE_PIX_FMT_XBGR_1555,
  404. SDE_PIX_FMT_XRGB_1555,
  405. SDE_PIX_FMT_ARGB_4444,
  406. SDE_PIX_FMT_RGBA_4444,
  407. SDE_PIX_FMT_BGRA_4444,
  408. SDE_PIX_FMT_ABGR_4444,
  409. SDE_PIX_FMT_RGBX_4444,
  410. SDE_PIX_FMT_XRGB_4444,
  411. SDE_PIX_FMT_BGRX_4444,
  412. SDE_PIX_FMT_XBGR_4444,
  413. SDE_PIX_FMT_RGB_888,
  414. SDE_PIX_FMT_BGR_888,
  415. SDE_PIX_FMT_RGB_565,
  416. SDE_PIX_FMT_BGR_565,
  417. SDE_PIX_FMT_Y_CB_CR_H2V2,
  418. SDE_PIX_FMT_Y_CR_CB_H2V2,
  419. /* SDE_PIX_FMT_Y_CR_CB_GH2V2, */
  420. SDE_PIX_FMT_Y_CBCR_H2V2,
  421. SDE_PIX_FMT_Y_CRCB_H2V2,
  422. /* SDE_PIX_FMT_Y_CBCR_H1V2, */
  423. /* SDE_PIX_FMT_Y_CRCB_H1V2, */
  424. /* SDE_PIX_FMT_Y_CBCR_H2V1, */
  425. /* SDE_PIX_FMT_Y_CRCB_H2V1, */
  426. /* SDE_PIX_FMT_YCBYCR_H2V1, */
  427. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  428. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  429. /* SDE_PIX_FMT_RGBA_8888_UBWC, */
  430. /* SDE_PIX_FMT_RGBX_8888_UBWC, */
  431. /* SDE_PIX_FMT_RGB_565_UBWC, */
  432. /* SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, */
  433. SDE_PIX_FMT_RGBA_1010102,
  434. SDE_PIX_FMT_RGBX_1010102,
  435. SDE_PIX_FMT_ARGB_2101010,
  436. SDE_PIX_FMT_XRGB_2101010,
  437. SDE_PIX_FMT_BGRA_1010102,
  438. SDE_PIX_FMT_BGRX_1010102,
  439. SDE_PIX_FMT_ABGR_2101010,
  440. SDE_PIX_FMT_XBGR_2101010,
  441. /* SDE_PIX_FMT_RGBA_1010102_UBWC, */
  442. /* SDE_PIX_FMT_RGBX_1010102_UBWC */
  443. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  444. SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS,
  445. /* SDE_PIX_FMT_Y_CBCR_H2V2_TP10 */
  446. /* SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, */
  447. /* SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC, */
  448. /* SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE, */
  449. /*SDE_PIX_FMT_Y_CBCR_H2V2_TILE, */
  450. /* SDE_PIX_FMT_Y_CRCB_H2V2_TILE, */
  451. /* SDE_PIX_FMT_XRGB_8888_TILE, */
  452. /* SDE_PIX_FMT_ARGB_8888_TILE, */
  453. /* SDE_PIX_FMT_ABGR_8888_TILE, */
  454. /* SDE_PIX_FMT_XBGR_8888_TILE, */
  455. /* SDE_PIX_FMT_RGBA_8888_TILE, */
  456. /* SDE_PIX_FMT_BGRA_8888_TILE, */
  457. /* SDE_PIX_FMT_RGBX_8888_TILE, */
  458. /* SDE_PIX_FMT_BGRX_8888_TILE, */
  459. /* SDE_PIX_FMT_RGBA_1010102_TILE, */
  460. /* SDE_PIX_FMT_RGBX_1010102_TILE, */
  461. /* SDE_PIX_FMT_ARGB_2101010_TILE, */
  462. /* SDE_PIX_FMT_XRGB_2101010_TILE, */
  463. /* SDE_PIX_FMT_BGRA_1010102_TILE, */
  464. /* SDE_PIX_FMT_BGRX_1010102_TILE, */
  465. /* SDE_PIX_FMT_ABGR_2101010_TILE, */
  466. /* SDE_PIX_FMT_XBGR_2101010_TILE, */
  467. };
  468. static const u32 sde_hw_rotator_v5_outpixfmts[] = {
  469. SDE_PIX_FMT_XRGB_8888,
  470. SDE_PIX_FMT_ARGB_8888,
  471. SDE_PIX_FMT_ABGR_8888,
  472. SDE_PIX_FMT_RGBA_8888,
  473. SDE_PIX_FMT_BGRA_8888,
  474. SDE_PIX_FMT_RGBX_8888,
  475. SDE_PIX_FMT_BGRX_8888,
  476. SDE_PIX_FMT_XBGR_8888,
  477. SDE_PIX_FMT_RGBA_5551,
  478. SDE_PIX_FMT_ARGB_1555,
  479. SDE_PIX_FMT_ABGR_1555,
  480. SDE_PIX_FMT_BGRA_5551,
  481. SDE_PIX_FMT_BGRX_5551,
  482. SDE_PIX_FMT_RGBX_5551,
  483. SDE_PIX_FMT_XBGR_1555,
  484. SDE_PIX_FMT_XRGB_1555,
  485. SDE_PIX_FMT_ARGB_4444,
  486. SDE_PIX_FMT_RGBA_4444,
  487. SDE_PIX_FMT_BGRA_4444,
  488. SDE_PIX_FMT_ABGR_4444,
  489. SDE_PIX_FMT_RGBX_4444,
  490. SDE_PIX_FMT_XRGB_4444,
  491. SDE_PIX_FMT_BGRX_4444,
  492. SDE_PIX_FMT_XBGR_4444,
  493. SDE_PIX_FMT_RGB_888,
  494. SDE_PIX_FMT_BGR_888,
  495. SDE_PIX_FMT_RGB_565,
  496. SDE_PIX_FMT_BGR_565,
  497. SDE_PIX_FMT_Y_CB_CR_H2V2,
  498. SDE_PIX_FMT_Y_CR_CB_H2V2,
  499. /* SDE_PIX_FMT_Y_CR_CB_GH2V2 */
  500. SDE_PIX_FMT_Y_CBCR_H2V2,
  501. SDE_PIX_FMT_Y_CRCB_H2V2,
  502. /* SDE_PIX_FMT_Y_CBCR_H1V2, */
  503. /* SDE_PIX_FMT_Y_CRCB_H1V2, */
  504. /* SDE_PIX_FMT_Y_CBCR_H2V1, */
  505. /* SDE_PIX_FMT_Y_CRCB_H2V1, */
  506. /* SDE_PIX_FMT_YCBYCR_H2V1, */
  507. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  508. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  509. /* SDE_PIX_FMT_RGBA_8888_UBWC, */
  510. /* SDE_PIX_FMT_RGBX_8888_UBWC */
  511. /* SDE_PIX_FMT_RGB_565_UBWC, */
  512. /* SDE_PIX_FMT_Y_CBCR_H2V2_UBWC, */
  513. SDE_PIX_FMT_RGBA_1010102,
  514. SDE_PIX_FMT_RGBX_1010102,
  515. SDE_PIX_FMT_ARGB_2101010,
  516. SDE_PIX_FMT_XRGB_2101010,
  517. SDE_PIX_FMT_BGRA_1010102,
  518. SDE_PIX_FMT_BGRX_1010102,
  519. SDE_PIX_FMT_ABGR_2101010,
  520. SDE_PIX_FMT_XBGR_2101010,
  521. /* SDE_PIX_FMT_RGBA_1010102_UBWC, */
  522. /* SDE_PIX_FMT_RGBX_1010102_UBWC */
  523. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  524. SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS,
  525. /* SDE_PIX_FMT_Y_CBCR_H2V2_TP10 */
  526. /* SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC, */
  527. /* SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC, */
  528. /* SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE */
  529. /* SDE_PIX_FMT_Y_CBCR_H2V2_TILE, */
  530. /* SDE_PIX_FMT_Y_CRCB_H2V2_TILE, */
  531. /* SDE_PIX_FMT_XRGB_8888_TILE, */
  532. /* SDE_PIX_FMT_ARGB_8888_TILE, */
  533. /* SDE_PIX_FMT_ABGR_8888_TILE, */
  534. /* SDE_PIX_FMT_XBGR_8888_TILE, */
  535. /* SDE_PIX_FMT_RGBA_8888_TILE, */
  536. /* SDE_PIX_FMT_BGRA_8888_TILE, */
  537. /* SDE_PIX_FMT_RGBX_8888_TILE, */
  538. /* SDE_PIX_FMT_BGRX_8888_TILE, */
  539. /* SDE_PIX_FMT_RGBA_1010102_TILE, */
  540. /* SDE_PIX_FMT_RGBX_1010102_TILE, */
  541. /* SDE_PIX_FMT_ARGB_2101010_TILE, */
  542. /* SDE_PIX_FMT_XRGB_2101010_TILE, */
  543. /* SDE_PIX_FMT_BGRA_1010102_TILE, */
  544. /* SDE_PIX_FMT_BGRX_1010102_TILE, */
  545. /* SDE_PIX_FMT_ABGR_2101010_TILE, */
  546. /* SDE_PIX_FMT_XBGR_2101010_TILE,*/
  547. };
  548. static const u32 sde_hw_rotator_v6_inpixfmts[] = {
  549. SDE_PIX_FMT_XRGB_8888,
  550. SDE_PIX_FMT_ARGB_8888,
  551. SDE_PIX_FMT_ABGR_8888,
  552. SDE_PIX_FMT_RGBA_8888,
  553. SDE_PIX_FMT_BGRA_8888,
  554. SDE_PIX_FMT_RGBX_8888,
  555. SDE_PIX_FMT_BGRX_8888,
  556. SDE_PIX_FMT_XBGR_8888,
  557. SDE_PIX_FMT_RGBA_5551,
  558. SDE_PIX_FMT_ARGB_1555,
  559. SDE_PIX_FMT_ABGR_1555,
  560. SDE_PIX_FMT_BGRA_5551,
  561. SDE_PIX_FMT_BGRX_5551,
  562. SDE_PIX_FMT_RGBX_5551,
  563. SDE_PIX_FMT_XBGR_1555,
  564. SDE_PIX_FMT_XRGB_1555,
  565. SDE_PIX_FMT_ARGB_4444,
  566. SDE_PIX_FMT_RGBA_4444,
  567. SDE_PIX_FMT_BGRA_4444,
  568. SDE_PIX_FMT_ABGR_4444,
  569. SDE_PIX_FMT_RGBX_4444,
  570. SDE_PIX_FMT_XRGB_4444,
  571. SDE_PIX_FMT_BGRX_4444,
  572. SDE_PIX_FMT_XBGR_4444,
  573. SDE_PIX_FMT_RGB_888,
  574. SDE_PIX_FMT_BGR_888,
  575. SDE_PIX_FMT_RGB_565,
  576. SDE_PIX_FMT_BGR_565,
  577. SDE_PIX_FMT_Y_CB_CR_H2V2,
  578. SDE_PIX_FMT_Y_CR_CB_H2V2,
  579. /* SDE_PIX_FMT_Y_CR_CB_GH2V2, */
  580. SDE_PIX_FMT_Y_CBCR_H2V2,
  581. SDE_PIX_FMT_Y_CRCB_H2V2,
  582. /* SDE_PIX_FMT_Y_CBCR_H1V2, */
  583. /* SDE_PIX_FMT_Y_CRCB_H1V2, */
  584. /* SDE_PIX_FMT_Y_CBCR_H2V1, */
  585. /* SDE_PIX_FMT_Y_CRCB_H2V1, */
  586. /* SDE_PIX_FMT_YCBYCR_H2V1, */
  587. SDE_PIX_FMT_Y_CBCR_H2V2_VENUS,
  588. SDE_PIX_FMT_Y_CRCB_H2V2_VENUS,
  589. SDE_PIX_FMT_RGBA_8888_UBWC,
  590. /* SDE_PIX_FMT_RGBX_8888_UBWC, */
  591. SDE_PIX_FMT_RGB_565_UBWC,
  592. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  593. SDE_PIX_FMT_RGBA_1010102,
  594. SDE_PIX_FMT_RGBX_1010102,
  595. SDE_PIX_FMT_ARGB_2101010,
  596. SDE_PIX_FMT_XRGB_2101010,
  597. SDE_PIX_FMT_BGRA_1010102,
  598. SDE_PIX_FMT_BGRX_1010102,
  599. SDE_PIX_FMT_ABGR_2101010,
  600. SDE_PIX_FMT_XBGR_2101010,
  601. SDE_PIX_FMT_RGBA_1010102_UBWC,
  602. /* SDE_PIX_FMT_RGBX_1010102_UBWC */
  603. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  604. SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS,
  605. /* SDE_PIX_FMT_Y_CBCR_H2V2_TP10 */
  606. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  607. SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC,
  608. /* SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE, */
  609. /*SDE_PIX_FMT_Y_CBCR_H2V2_TILE, */
  610. /* SDE_PIX_FMT_Y_CRCB_H2V2_TILE, */
  611. /* SDE_PIX_FMT_XRGB_8888_TILE, */
  612. /* SDE_PIX_FMT_ARGB_8888_TILE, */
  613. /* SDE_PIX_FMT_ABGR_8888_TILE, */
  614. /* SDE_PIX_FMT_XBGR_8888_TILE, */
  615. /* SDE_PIX_FMT_RGBA_8888_TILE, */
  616. /* SDE_PIX_FMT_BGRA_8888_TILE, */
  617. /* SDE_PIX_FMT_RGBX_8888_TILE, */
  618. /* SDE_PIX_FMT_BGRX_8888_TILE, */
  619. /* SDE_PIX_FMT_RGBA_1010102_TILE, */
  620. /* SDE_PIX_FMT_RGBX_1010102_TILE, */
  621. /* SDE_PIX_FMT_ARGB_2101010_TILE, */
  622. /* SDE_PIX_FMT_XRGB_2101010_TILE, */
  623. /* SDE_PIX_FMT_BGRA_1010102_TILE, */
  624. /* SDE_PIX_FMT_BGRX_1010102_TILE, */
  625. /* SDE_PIX_FMT_ABGR_2101010_TILE, */
  626. /* SDE_PIX_FMT_XBGR_2101010_TILE, */
  627. };
  628. static const u32 sde_hw_rotator_v4_inpixfmts_sbuf[] = {
  629. SDE_PIX_FMT_Y_CBCR_H2V2_P010,
  630. SDE_PIX_FMT_Y_CBCR_H2V2,
  631. SDE_PIX_FMT_Y_CRCB_H2V2,
  632. SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC,
  633. SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC,
  634. SDE_PIX_FMT_Y_CBCR_H2V2_UBWC,
  635. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  636. SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE,
  637. SDE_PIX_FMT_Y_CBCR_H2V2_TILE,
  638. };
  639. static const u32 sde_hw_rotator_v4_outpixfmts_sbuf[] = {
  640. SDE_PIX_FMT_Y_CBCR_H2V2_TP10,
  641. SDE_PIX_FMT_Y_CBCR_H2V2_P010_TILE,
  642. SDE_PIX_FMT_Y_CBCR_H2V2_TILE,
  643. };
  644. static struct sde_rot_vbif_debug_bus nrt_vbif_dbg_bus_r3[] = {
  645. {0x214, 0x21c, 16, 1, 0x200}, /* arb clients main */
  646. {0x214, 0x21c, 0, 12, 0x13}, /* xin blocks - axi side */
  647. {0x21c, 0x214, 0, 12, 0xc}, /* xin blocks - clock side */
  648. };
  649. static struct sde_rot_debug_bus rot_dbgbus_r3[] = {
  650. /*
  651. * rottop - 0xA8850
  652. */
  653. /* REGDMA */
  654. { 0XA8850, 0, 0 },
  655. { 0XA8850, 0, 1 },
  656. { 0XA8850, 0, 2 },
  657. { 0XA8850, 0, 3 },
  658. { 0XA8850, 0, 4 },
  659. /* ROT_WB */
  660. { 0XA8850, 1, 0 },
  661. { 0XA8850, 1, 1 },
  662. { 0XA8850, 1, 2 },
  663. { 0XA8850, 1, 3 },
  664. { 0XA8850, 1, 4 },
  665. { 0XA8850, 1, 5 },
  666. { 0XA8850, 1, 6 },
  667. { 0XA8850, 1, 7 },
  668. /* UBWC_DEC */
  669. { 0XA8850, 2, 0 },
  670. /* UBWC_ENC */
  671. { 0XA8850, 3, 0 },
  672. /* ROT_FETCH_0 */
  673. { 0XA8850, 4, 0 },
  674. { 0XA8850, 4, 1 },
  675. { 0XA8850, 4, 2 },
  676. { 0XA8850, 4, 3 },
  677. { 0XA8850, 4, 4 },
  678. { 0XA8850, 4, 5 },
  679. { 0XA8850, 4, 6 },
  680. { 0XA8850, 4, 7 },
  681. /* ROT_FETCH_1 */
  682. { 0XA8850, 5, 0 },
  683. { 0XA8850, 5, 1 },
  684. { 0XA8850, 5, 2 },
  685. { 0XA8850, 5, 3 },
  686. { 0XA8850, 5, 4 },
  687. { 0XA8850, 5, 5 },
  688. { 0XA8850, 5, 6 },
  689. { 0XA8850, 5, 7 },
  690. /* ROT_FETCH_2 */
  691. { 0XA8850, 6, 0 },
  692. { 0XA8850, 6, 1 },
  693. { 0XA8850, 6, 2 },
  694. { 0XA8850, 6, 3 },
  695. { 0XA8850, 6, 4 },
  696. { 0XA8850, 6, 5 },
  697. { 0XA8850, 6, 6 },
  698. { 0XA8850, 6, 7 },
  699. /* ROT_FETCH_3 */
  700. { 0XA8850, 7, 0 },
  701. { 0XA8850, 7, 1 },
  702. { 0XA8850, 7, 2 },
  703. { 0XA8850, 7, 3 },
  704. { 0XA8850, 7, 4 },
  705. { 0XA8850, 7, 5 },
  706. { 0XA8850, 7, 6 },
  707. { 0XA8850, 7, 7 },
  708. /* ROT_FETCH_4 */
  709. { 0XA8850, 8, 0 },
  710. { 0XA8850, 8, 1 },
  711. { 0XA8850, 8, 2 },
  712. { 0XA8850, 8, 3 },
  713. { 0XA8850, 8, 4 },
  714. { 0XA8850, 8, 5 },
  715. { 0XA8850, 8, 6 },
  716. { 0XA8850, 8, 7 },
  717. /* ROT_UNPACK_0*/
  718. { 0XA8850, 9, 0 },
  719. { 0XA8850, 9, 1 },
  720. { 0XA8850, 9, 2 },
  721. { 0XA8850, 9, 3 },
  722. };
  723. static struct sde_rot_regdump sde_rot_r3_regdump[] = {
  724. { "SDEROT_ROTTOP", SDE_ROT_ROTTOP_OFFSET, 0x100, SDE_ROT_REGDUMP_READ },
  725. { "SDEROT_SSPP", SDE_ROT_SSPP_OFFSET, 0x200, SDE_ROT_REGDUMP_READ },
  726. { "SDEROT_WB", SDE_ROT_WB_OFFSET, 0x300, SDE_ROT_REGDUMP_READ },
  727. { "SDEROT_REGDMA_CSR", SDE_ROT_REGDMA_OFFSET, 0x100,
  728. SDE_ROT_REGDUMP_READ },
  729. /*
  730. * Need to perform a SW reset to REGDMA in order to access the
  731. * REGDMA RAM especially if REGDMA is waiting for Rotator IDLE.
  732. * REGDMA RAM should be dump at last.
  733. */
  734. { "SDEROT_REGDMA_RESET", ROTTOP_SW_RESET_OVERRIDE, 1,
  735. SDE_ROT_REGDUMP_WRITE, 1 },
  736. { "SDEROT_REGDMA_RAM", SDE_ROT_REGDMA_RAM_OFFSET, 0x2000,
  737. SDE_ROT_REGDUMP_READ },
  738. { "SDEROT_VBIF_NRT", SDE_ROT_VBIF_NRT_OFFSET, 0x590,
  739. SDE_ROT_REGDUMP_VBIF },
  740. { "SDEROT_REGDMA_RESET", ROTTOP_SW_RESET_OVERRIDE, 1,
  741. SDE_ROT_REGDUMP_WRITE, 0 },
  742. };
  743. struct sde_rot_cdp_params {
  744. bool enable;
  745. struct sde_mdp_format_params *fmt;
  746. u32 offset;
  747. };
  748. /* Invalid software timestamp value for initialization */
  749. #define SDE_REGDMA_SWTS_INVALID (~0)
  750. /**
  751. * __sde_hw_rotator_get_timestamp - obtain rotator current timestamp
  752. * @rot: rotator context
  753. * @q_id: regdma queue id (low/high)
  754. * @return: current timestmap
  755. */
  756. static u32 __sde_hw_rotator_get_timestamp(struct sde_hw_rotator *rot, u32 q_id)
  757. {
  758. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  759. u32 ts;
  760. if (test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map)) {
  761. if (q_id == ROT_QUEUE_HIGH_PRIORITY)
  762. ts = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_ROT_CNTR_0);
  763. else
  764. ts = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_ROT_CNTR_1);
  765. } else {
  766. ts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG);
  767. if (q_id == ROT_QUEUE_LOW_PRIORITY)
  768. ts >>= SDE_REGDMA_SWTS_SHIFT;
  769. }
  770. return ts & SDE_REGDMA_SWTS_MASK;
  771. }
  772. /**
  773. * sde_hw_rotator_disable_irq - Disable hw rotator interrupt with ref. count
  774. * Also, clear rotator/regdma irq enable masks.
  775. * @rot: Pointer to hw rotator
  776. */
  777. static void sde_hw_rotator_disable_irq(struct sde_hw_rotator *rot)
  778. {
  779. SDEROT_DBG("irq_num:%d enabled:%d\n", rot->irq_num,
  780. atomic_read(&rot->irq_enabled));
  781. if (!atomic_read(&rot->irq_enabled)) {
  782. SDEROT_ERR("irq %d is already disabled\n", rot->irq_num);
  783. return;
  784. }
  785. if (!atomic_dec_return(&rot->irq_enabled)) {
  786. if (rot->mode == ROT_REGDMA_OFF)
  787. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_EN, 0);
  788. else
  789. SDE_ROTREG_WRITE(rot->mdss_base,
  790. REGDMA_CSR_REGDMA_INT_EN, 0);
  791. /* disable irq after last pending irq is handled, if any */
  792. synchronize_irq(rot->irq_num);
  793. disable_irq_nosync(rot->irq_num);
  794. }
  795. }
  796. /**
  797. * sde_hw_rotator_elapsed_swts - Find difference of 2 software timestamps
  798. * @ts_curr: current software timestamp
  799. * @ts_prev: previous software timestamp
  800. * @return: the amount ts_curr is ahead of ts_prev
  801. */
  802. static int sde_hw_rotator_elapsed_swts(u32 ts_curr, u32 ts_prev)
  803. {
  804. u32 diff = (ts_curr - ts_prev) & SDE_REGDMA_SWTS_MASK;
  805. return sign_extend32(diff, (SDE_REGDMA_SWTS_SHIFT - 1));
  806. }
  807. /*
  808. * sde_hw_rotator_rotirq_handler - non-regdma interrupt handler
  809. * @irq: Interrupt number
  810. * @ptr: Pointer to private handle provided during registration
  811. *
  812. * This function services rotator interrupt and wakes up waiting client
  813. * with pending rotation requests already submitted to h/w.
  814. */
  815. static irqreturn_t sde_hw_rotator_rotirq_handler(int irq, void *ptr)
  816. {
  817. struct sde_hw_rotator *rot = ptr;
  818. struct sde_hw_rotator_context *ctx;
  819. irqreturn_t ret = IRQ_NONE;
  820. u32 isr;
  821. isr = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_INTR_STATUS);
  822. SDEROT_DBG("intr_status = %8.8x\n", isr);
  823. if (isr & ROT_DONE_MASK) {
  824. sde_hw_rotator_disable_irq(rot);
  825. SDEROT_DBG("Notify rotator complete\n");
  826. /* Normal rotator only 1 session, no need to lookup */
  827. ctx = rot->rotCtx[0][0];
  828. WARN_ON(ctx == NULL);
  829. complete_all(&ctx->rot_comp);
  830. spin_lock(&rot->rotisr_lock);
  831. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR,
  832. ROT_DONE_CLEAR);
  833. spin_unlock(&rot->rotisr_lock);
  834. ret = IRQ_HANDLED;
  835. }
  836. return ret;
  837. }
  838. /*
  839. * sde_hw_rotator_regdmairq_handler - regdma interrupt handler
  840. * @irq: Interrupt number
  841. * @ptr: Pointer to private handle provided during registration
  842. *
  843. * This function services rotator interrupt, decoding the source of
  844. * events (high/low priority queue), and wakes up all waiting clients
  845. * with pending rotation requests already submitted to h/w.
  846. */
  847. static irqreturn_t sde_hw_rotator_regdmairq_handler(int irq, void *ptr)
  848. {
  849. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  850. struct sde_hw_rotator *rot = ptr;
  851. struct sde_hw_rotator_context *ctx, *tmp;
  852. irqreturn_t ret = IRQ_NONE;
  853. u32 isr, isr_tmp;
  854. u32 ts;
  855. u32 q_id;
  856. isr = SDE_ROTREG_READ(rot->mdss_base, REGDMA_CSR_REGDMA_INT_STATUS);
  857. /* acknowledge interrupt before reading latest timestamp */
  858. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_INT_CLEAR, isr);
  859. SDEROT_DBG("intr_status = %8.8x\n", isr);
  860. /* Any REGDMA status, including error and watchdog timer, should
  861. * trigger and wake up waiting thread
  862. */
  863. if (isr & (REGDMA_INT_HIGH_MASK | REGDMA_INT_LOW_MASK)) {
  864. spin_lock(&rot->rotisr_lock);
  865. /*
  866. * Obtain rotator context based on timestamp from regdma
  867. * and low/high interrupt status
  868. */
  869. if (isr & REGDMA_INT_HIGH_MASK) {
  870. q_id = ROT_QUEUE_HIGH_PRIORITY;
  871. } else if (isr & REGDMA_INT_LOW_MASK) {
  872. q_id = ROT_QUEUE_LOW_PRIORITY;
  873. } else {
  874. SDEROT_ERR("unknown ISR status: isr=0x%X\n", isr);
  875. goto done_isr_handle;
  876. }
  877. ts = __sde_hw_rotator_get_timestamp(rot, q_id);
  878. /*
  879. * Timestamp packet is not available in sbuf mode.
  880. * Simulate timestamp update in the handler instead.
  881. */
  882. if (test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map) ||
  883. list_empty(&rot->sbuf_ctx[q_id]))
  884. goto skip_sbuf;
  885. ctx = NULL;
  886. isr_tmp = isr;
  887. list_for_each_entry(tmp, &rot->sbuf_ctx[q_id], list) {
  888. u32 mask;
  889. mask = tmp->timestamp & 0x1 ? REGDMA_INT_1_MASK :
  890. REGDMA_INT_0_MASK;
  891. if (isr_tmp & mask) {
  892. isr_tmp &= ~mask;
  893. ctx = tmp;
  894. ts = ctx->timestamp;
  895. rot->ops.update_ts(rot, ctx->q_id, ts);
  896. SDEROT_DBG("update swts:0x%X\n", ts);
  897. }
  898. SDEROT_EVTLOG(isr, tmp->timestamp);
  899. }
  900. if (ctx == NULL)
  901. SDEROT_ERR("invalid swts ctx\n");
  902. skip_sbuf:
  903. ctx = rot->rotCtx[q_id][ts & SDE_HW_ROT_REGDMA_SEG_MASK];
  904. /*
  905. * Wake up all waiting context from the current and previous
  906. * SW Timestamp.
  907. */
  908. while (ctx &&
  909. sde_hw_rotator_elapsed_swts(ctx->timestamp, ts) >= 0) {
  910. ctx->last_regdma_isr_status = isr;
  911. ctx->last_regdma_timestamp = ts;
  912. SDEROT_DBG(
  913. "regdma complete: ctx:%pK, ts:%X\n", ctx, ts);
  914. wake_up_all(&ctx->regdma_waitq);
  915. ts = (ts - 1) & SDE_REGDMA_SWTS_MASK;
  916. ctx = rot->rotCtx[q_id]
  917. [ts & SDE_HW_ROT_REGDMA_SEG_MASK];
  918. };
  919. done_isr_handle:
  920. spin_unlock(&rot->rotisr_lock);
  921. ret = IRQ_HANDLED;
  922. } else if (isr & REGDMA_INT_ERR_MASK) {
  923. /*
  924. * For REGDMA Err, we save the isr info and wake up
  925. * all waiting contexts
  926. */
  927. int i, j;
  928. SDEROT_ERR(
  929. "regdma err isr:%X, wake up all waiting contexts\n",
  930. isr);
  931. spin_lock(&rot->rotisr_lock);
  932. for (i = 0; i < ROT_QUEUE_MAX; i++) {
  933. for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX; j++) {
  934. ctx = rot->rotCtx[i][j];
  935. if (ctx && ctx->last_regdma_isr_status == 0) {
  936. ts = __sde_hw_rotator_get_timestamp(
  937. rot, i);
  938. ctx->last_regdma_isr_status = isr;
  939. ctx->last_regdma_timestamp = ts;
  940. wake_up_all(&ctx->regdma_waitq);
  941. SDEROT_DBG("Wake rotctx[%d][%d]:%pK\n",
  942. i, j, ctx);
  943. }
  944. }
  945. }
  946. spin_unlock(&rot->rotisr_lock);
  947. ret = IRQ_HANDLED;
  948. }
  949. return ret;
  950. }
  951. /**
  952. * sde_hw_rotator_pending_hwts - Check if the given context is still pending
  953. * @rot: Pointer to hw rotator
  954. * @ctx: Pointer to rotator context
  955. * @phwts: Pointer to returned reference hw timestamp, optional
  956. * @return: true if context has pending requests
  957. */
  958. static int sde_hw_rotator_pending_hwts(struct sde_hw_rotator *rot,
  959. struct sde_hw_rotator_context *ctx, u32 *phwts)
  960. {
  961. u32 hwts;
  962. int ts_diff;
  963. bool pending;
  964. if (ctx->last_regdma_timestamp == SDE_REGDMA_SWTS_INVALID) {
  965. if (ctx->q_id == ROT_QUEUE_LOW_PRIORITY)
  966. hwts = SDE_ROTREG_READ(rot->mdss_base,
  967. ROTTOP_ROT_CNTR_1);
  968. else
  969. hwts = SDE_ROTREG_READ(rot->mdss_base,
  970. ROTTOP_ROT_CNTR_0);
  971. } else {
  972. hwts = ctx->last_regdma_timestamp;
  973. }
  974. hwts &= SDE_REGDMA_SWTS_MASK;
  975. ts_diff = sde_hw_rotator_elapsed_swts(ctx->timestamp, hwts);
  976. if (phwts)
  977. *phwts = hwts;
  978. pending = (ts_diff > 0) ? true : false;
  979. SDEROT_DBG("ts:0x%x, queue_id:%d, hwts:0x%x, pending:%d\n",
  980. ctx->timestamp, ctx->q_id, hwts, pending);
  981. SDEROT_EVTLOG(ctx->timestamp, hwts, ctx->q_id, ts_diff);
  982. return pending;
  983. }
  984. /**
  985. * sde_hw_rotator_update_hwts - update hw timestamp with given value
  986. * @rot: Pointer to hw rotator
  987. * @q_id: rotator queue id
  988. * @hwts: new hw timestamp
  989. */
  990. static void sde_hw_rotator_update_hwts(struct sde_hw_rotator *rot,
  991. u32 q_id, u32 hwts)
  992. {
  993. if (q_id == ROT_QUEUE_LOW_PRIORITY)
  994. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_ROT_CNTR_1, hwts);
  995. else
  996. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_ROT_CNTR_0, hwts);
  997. }
  998. /**
  999. * sde_hw_rotator_pending_swts - Check if the given context is still pending
  1000. * @rot: Pointer to hw rotator
  1001. * @ctx: Pointer to rotator context
  1002. * @pswts: Pointer to returned reference software timestamp, optional
  1003. * @return: true if context has pending requests
  1004. */
  1005. static int sde_hw_rotator_pending_swts(struct sde_hw_rotator *rot,
  1006. struct sde_hw_rotator_context *ctx, u32 *pswts)
  1007. {
  1008. u32 swts;
  1009. int ts_diff;
  1010. bool pending;
  1011. if (ctx->last_regdma_timestamp == SDE_REGDMA_SWTS_INVALID)
  1012. swts = SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG);
  1013. else
  1014. swts = ctx->last_regdma_timestamp;
  1015. if (ctx->q_id == ROT_QUEUE_LOW_PRIORITY)
  1016. swts >>= SDE_REGDMA_SWTS_SHIFT;
  1017. swts &= SDE_REGDMA_SWTS_MASK;
  1018. ts_diff = sde_hw_rotator_elapsed_swts(ctx->timestamp, swts);
  1019. if (pswts)
  1020. *pswts = swts;
  1021. pending = (ts_diff > 0) ? true : false;
  1022. SDEROT_DBG("ts:0x%x, queue_id:%d, swts:0x%x, pending:%d\n",
  1023. ctx->timestamp, ctx->q_id, swts, pending);
  1024. SDEROT_EVTLOG(ctx->timestamp, swts, ctx->q_id, ts_diff);
  1025. return pending;
  1026. }
  1027. /**
  1028. * sde_hw_rotator_update_swts - update software timestamp with given value
  1029. * @rot: Pointer to hw rotator
  1030. * @q_id: rotator queue id
  1031. * @swts: new software timestamp
  1032. */
  1033. static void sde_hw_rotator_update_swts(struct sde_hw_rotator *rot,
  1034. u32 q_id, u32 swts)
  1035. {
  1036. u32 mask = SDE_REGDMA_SWTS_MASK;
  1037. swts &= SDE_REGDMA_SWTS_MASK;
  1038. if (q_id == ROT_QUEUE_LOW_PRIORITY) {
  1039. swts <<= SDE_REGDMA_SWTS_SHIFT;
  1040. mask <<= SDE_REGDMA_SWTS_SHIFT;
  1041. }
  1042. swts |= (SDE_ROTREG_READ(rot->mdss_base, REGDMA_TIMESTAMP_REG) & ~mask);
  1043. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, swts);
  1044. }
  1045. /*
  1046. * sde_hw_rotator_irq_setup - setup rotator irq
  1047. * @mgr: Pointer to rotator manager
  1048. * return: none
  1049. */
  1050. static int sde_hw_rotator_irq_setup(struct sde_hw_rotator *rot)
  1051. {
  1052. int rc = 0;
  1053. /* return early if irq is already setup */
  1054. if (rot->irq_num >= 0)
  1055. return 0;
  1056. rot->irq_num = platform_get_irq(rot->pdev, 0);
  1057. if (rot->irq_num < 0) {
  1058. rc = rot->irq_num;
  1059. SDEROT_ERR("fail to get rot irq, fallback to poll %d\n", rc);
  1060. } else {
  1061. if (rot->mode == ROT_REGDMA_OFF)
  1062. rc = devm_request_threaded_irq(&rot->pdev->dev,
  1063. rot->irq_num,
  1064. sde_hw_rotator_rotirq_handler,
  1065. NULL, 0, "sde_rotator_r3", rot);
  1066. else
  1067. rc = devm_request_threaded_irq(&rot->pdev->dev,
  1068. rot->irq_num,
  1069. sde_hw_rotator_regdmairq_handler,
  1070. NULL, 0, "sde_rotator_r3", rot);
  1071. if (rc) {
  1072. SDEROT_ERR("fail to request irq r:%d\n", rc);
  1073. rot->irq_num = -1;
  1074. } else {
  1075. disable_irq(rot->irq_num);
  1076. }
  1077. }
  1078. return rc;
  1079. }
  1080. /**
  1081. * sde_hw_rotator_enable_irq - Enable hw rotator interrupt with ref. count
  1082. * Also, clear rotator/regdma irq status.
  1083. * @rot: Pointer to hw rotator
  1084. */
  1085. static int sde_hw_rotator_enable_irq(struct sde_hw_rotator *rot)
  1086. {
  1087. int ret = 0;
  1088. SDEROT_DBG("irq_num:%d enabled:%d\n", rot->irq_num,
  1089. atomic_read(&rot->irq_enabled));
  1090. ret = sde_hw_rotator_irq_setup(rot);
  1091. if (ret < 0) {
  1092. SDEROT_ERR("Rotator irq setup failed %d\n", ret);
  1093. return ret;
  1094. }
  1095. if (!atomic_read(&rot->irq_enabled)) {
  1096. if (rot->mode == ROT_REGDMA_OFF)
  1097. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR,
  1098. ROT_DONE_MASK);
  1099. else
  1100. SDE_ROTREG_WRITE(rot->mdss_base,
  1101. REGDMA_CSR_REGDMA_INT_CLEAR, REGDMA_INT_MASK);
  1102. enable_irq(rot->irq_num);
  1103. }
  1104. atomic_inc(&rot->irq_enabled);
  1105. return ret;
  1106. }
  1107. static int sde_hw_rotator_halt_vbif_xin_client(void)
  1108. {
  1109. struct sde_mdp_vbif_halt_params halt_params;
  1110. int rc = 0;
  1111. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1112. memset(&halt_params, 0, sizeof(struct sde_mdp_vbif_halt_params));
  1113. halt_params.xin_id = mdata->vbif_xin_id[XIN_SSPP];
  1114. halt_params.reg_off_mdp_clk_ctrl = MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0;
  1115. halt_params.bit_off_mdp_clk_ctrl =
  1116. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN0;
  1117. sde_mdp_halt_vbif_xin(&halt_params);
  1118. rc |= halt_params.xin_timeout;
  1119. memset(&halt_params, 0, sizeof(struct sde_mdp_vbif_halt_params));
  1120. halt_params.xin_id = mdata->vbif_xin_id[XIN_WRITEBACK];
  1121. halt_params.reg_off_mdp_clk_ctrl = MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0;
  1122. halt_params.bit_off_mdp_clk_ctrl =
  1123. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN1;
  1124. sde_mdp_halt_vbif_xin(&halt_params);
  1125. rc |= halt_params.xin_timeout;
  1126. return rc;
  1127. }
  1128. /**
  1129. * sde_hw_rotator_reset - Reset rotator hardware
  1130. * @rot: pointer to hw rotator
  1131. * @ctx: pointer to current rotator context during the hw hang (optional)
  1132. */
  1133. static int sde_hw_rotator_reset(struct sde_hw_rotator *rot,
  1134. struct sde_hw_rotator_context *ctx)
  1135. {
  1136. struct sde_hw_rotator_context *rctx = NULL;
  1137. u32 int_mask = (REGDMA_INT_0_MASK | REGDMA_INT_1_MASK |
  1138. REGDMA_INT_2_MASK);
  1139. u32 last_ts[ROT_QUEUE_MAX] = {0,};
  1140. u32 latest_ts, opmode;
  1141. int elapsed_time, t;
  1142. int i, j;
  1143. unsigned long flags;
  1144. if (!rot) {
  1145. SDEROT_ERR("NULL rotator\n");
  1146. return -EINVAL;
  1147. }
  1148. /* sw reset the hw rotator */
  1149. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_SW_RESET_OVERRIDE, 1);
  1150. /* ensure write is issued to the rotator HW */
  1151. wmb();
  1152. usleep_range(MS_TO_US(10), MS_TO_US(20));
  1153. /* force rotator into offline mode */
  1154. opmode = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_OP_MODE);
  1155. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_OP_MODE,
  1156. opmode & ~(BIT(5) | BIT(4) | BIT(1) | BIT(0)));
  1157. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_SW_RESET_OVERRIDE, 0);
  1158. /* halt vbif xin client to ensure no pending transaction */
  1159. sde_hw_rotator_halt_vbif_xin_client();
  1160. /* if no ctx is specified, skip ctx wake up */
  1161. if (!ctx)
  1162. return 0;
  1163. if (ctx->q_id >= ROT_QUEUE_MAX) {
  1164. SDEROT_ERR("context q_id out of range: %d\n", ctx->q_id);
  1165. return -EINVAL;
  1166. }
  1167. spin_lock_irqsave(&rot->rotisr_lock, flags);
  1168. /* update timestamp register with current context */
  1169. last_ts[ctx->q_id] = ctx->timestamp;
  1170. rot->ops.update_ts(rot, ctx->q_id, ctx->timestamp);
  1171. SDEROT_EVTLOG(ctx->timestamp);
  1172. /*
  1173. * Search for any pending rot session, and look for last timestamp
  1174. * per hw queue.
  1175. */
  1176. for (i = 0; i < ROT_QUEUE_MAX; i++) {
  1177. latest_ts = atomic_read(&rot->timestamp[i]);
  1178. latest_ts &= SDE_REGDMA_SWTS_MASK;
  1179. elapsed_time = sde_hw_rotator_elapsed_swts(latest_ts,
  1180. last_ts[i]);
  1181. for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX; j++) {
  1182. rctx = rot->rotCtx[i][j];
  1183. if (rctx && rctx != ctx) {
  1184. rctx->last_regdma_isr_status = int_mask;
  1185. rctx->last_regdma_timestamp = rctx->timestamp;
  1186. t = sde_hw_rotator_elapsed_swts(latest_ts,
  1187. rctx->timestamp);
  1188. if (t < elapsed_time) {
  1189. elapsed_time = t;
  1190. last_ts[i] = rctx->timestamp;
  1191. rot->ops.update_ts(rot, i, last_ts[i]);
  1192. }
  1193. SDEROT_DBG("rotctx[%d][%d], ts:%d\n",
  1194. i, j, rctx->timestamp);
  1195. SDEROT_EVTLOG(i, j, rctx->timestamp,
  1196. last_ts[i]);
  1197. }
  1198. }
  1199. }
  1200. /* Finally wakeup all pending rotator context in queue */
  1201. for (i = 0; i < ROT_QUEUE_MAX; i++) {
  1202. for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX; j++) {
  1203. rctx = rot->rotCtx[i][j];
  1204. if (rctx && rctx != ctx)
  1205. wake_up_all(&rctx->regdma_waitq);
  1206. }
  1207. }
  1208. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  1209. return 0;
  1210. }
  1211. /**
  1212. * _sde_hw_rotator_dump_status - Dump hw rotator status on error
  1213. * @rot: Pointer to hw rotator
  1214. */
  1215. static void _sde_hw_rotator_dump_status(struct sde_hw_rotator *rot,
  1216. u32 *ubwcerr)
  1217. {
  1218. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1219. u32 reg = 0;
  1220. SDEROT_ERR(
  1221. "op_mode = %x, int_en = %x, int_status = %x\n",
  1222. SDE_ROTREG_READ(rot->mdss_base,
  1223. REGDMA_CSR_REGDMA_OP_MODE),
  1224. SDE_ROTREG_READ(rot->mdss_base,
  1225. REGDMA_CSR_REGDMA_INT_EN),
  1226. SDE_ROTREG_READ(rot->mdss_base,
  1227. REGDMA_CSR_REGDMA_INT_STATUS));
  1228. SDEROT_ERR(
  1229. "ts0/ts1 = %x/%x, q0_status = %x, q1_status = %x, block_status = %x\n",
  1230. __sde_hw_rotator_get_timestamp(rot, ROT_QUEUE_HIGH_PRIORITY),
  1231. __sde_hw_rotator_get_timestamp(rot, ROT_QUEUE_LOW_PRIORITY),
  1232. SDE_ROTREG_READ(rot->mdss_base,
  1233. REGDMA_CSR_REGDMA_QUEUE_0_STATUS),
  1234. SDE_ROTREG_READ(rot->mdss_base,
  1235. REGDMA_CSR_REGDMA_QUEUE_1_STATUS),
  1236. SDE_ROTREG_READ(rot->mdss_base,
  1237. REGDMA_CSR_REGDMA_BLOCK_STATUS));
  1238. SDEROT_ERR(
  1239. "invalid_cmd_offset = %x, fsm_state = %x\n",
  1240. SDE_ROTREG_READ(rot->mdss_base,
  1241. REGDMA_CSR_REGDMA_INVALID_CMD_RAM_OFFSET),
  1242. SDE_ROTREG_READ(rot->mdss_base,
  1243. REGDMA_CSR_REGDMA_FSM_STATE));
  1244. SDEROT_ERR("rottop: op_mode = %x, status = %x, clk_status = %x\n",
  1245. SDE_ROTREG_READ(rot->mdss_base, ROTTOP_OP_MODE),
  1246. SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS),
  1247. SDE_ROTREG_READ(rot->mdss_base, ROTTOP_CLK_STATUS));
  1248. reg = SDE_ROTREG_READ(rot->mdss_base, ROT_SSPP_UBWC_ERROR_STATUS);
  1249. if (ubwcerr)
  1250. *ubwcerr = reg;
  1251. SDEROT_ERR(
  1252. "UBWC decode status = %x, UBWC encode status = %x\n", reg,
  1253. SDE_ROTREG_READ(rot->mdss_base, ROT_WB_UBWC_ERROR_STATUS));
  1254. SDEROT_ERR("VBIF XIN HALT status = %x VBIF AXI HALT status = %x\n",
  1255. SDE_VBIF_READ(mdata, MMSS_VBIF_XIN_HALT_CTRL1),
  1256. SDE_VBIF_READ(mdata, MMSS_VBIF_AXI_HALT_CTRL1));
  1257. SDEROT_ERR("sspp unpack wr: plane0 = %x, plane1 = %x, plane2 = %x\n",
  1258. SDE_ROTREG_READ(rot->mdss_base,
  1259. ROT_SSPP_FETCH_SMP_WR_PLANE0),
  1260. SDE_ROTREG_READ(rot->mdss_base,
  1261. ROT_SSPP_FETCH_SMP_WR_PLANE1),
  1262. SDE_ROTREG_READ(rot->mdss_base,
  1263. ROT_SSPP_FETCH_SMP_WR_PLANE2));
  1264. SDEROT_ERR("sspp unpack rd: plane0 = %x, plane1 = %x, plane2 = %x\n",
  1265. SDE_ROTREG_READ(rot->mdss_base,
  1266. ROT_SSPP_SMP_UNPACK_RD_PLANE0),
  1267. SDE_ROTREG_READ(rot->mdss_base,
  1268. ROT_SSPP_SMP_UNPACK_RD_PLANE1),
  1269. SDE_ROTREG_READ(rot->mdss_base,
  1270. ROT_SSPP_SMP_UNPACK_RD_PLANE2));
  1271. SDEROT_ERR("sspp: unpack_ln = %x, unpack_blk = %x, fill_lvl = %x\n",
  1272. SDE_ROTREG_READ(rot->mdss_base,
  1273. ROT_SSPP_UNPACK_LINE_COUNT),
  1274. SDE_ROTREG_READ(rot->mdss_base,
  1275. ROT_SSPP_UNPACK_BLK_COUNT),
  1276. SDE_ROTREG_READ(rot->mdss_base,
  1277. ROT_SSPP_FILL_LEVELS));
  1278. SDEROT_ERR("wb: sbuf0 = %x, sbuf1 = %x, sys_cache = %x\n",
  1279. SDE_ROTREG_READ(rot->mdss_base,
  1280. ROT_WB_SBUF_STATUS_PLANE0),
  1281. SDE_ROTREG_READ(rot->mdss_base,
  1282. ROT_WB_SBUF_STATUS_PLANE1),
  1283. SDE_ROTREG_READ(rot->mdss_base,
  1284. ROT_WB_SYS_CACHE_MODE));
  1285. }
  1286. /**
  1287. * sde_hw_rotator_get_ctx(): Retrieve rotator context from rotator HW based
  1288. * on provided session_id. Each rotator has a different session_id.
  1289. * @rot: Pointer to rotator hw
  1290. * @session_id: Identifier for rotator session
  1291. * @sequence_id: Identifier for rotation request within the session
  1292. * @q_id: Rotator queue identifier
  1293. */
  1294. static struct sde_hw_rotator_context *sde_hw_rotator_get_ctx(
  1295. struct sde_hw_rotator *rot, u32 session_id, u32 sequence_id,
  1296. enum sde_rot_queue_prio q_id)
  1297. {
  1298. int i;
  1299. struct sde_hw_rotator_context *ctx = NULL;
  1300. for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++) {
  1301. ctx = rot->rotCtx[q_id][i];
  1302. if (ctx && (ctx->session_id == session_id) &&
  1303. (ctx->sequence_id == sequence_id)) {
  1304. SDEROT_DBG(
  1305. "rotCtx sloti[%d][%d] ==> ctx:%pK | session-id:%d | sequence-id:%d\n",
  1306. q_id, i, ctx, ctx->session_id,
  1307. ctx->sequence_id);
  1308. return ctx;
  1309. }
  1310. }
  1311. return NULL;
  1312. }
  1313. /*
  1314. * sde_hw_rotator_map_vaddr - map the debug buffer to kernel space
  1315. * @dbgbuf: Pointer to debug buffer
  1316. * @buf: Pointer to layer buffer structure
  1317. * @data: Pointer to h/w mapped buffer structure
  1318. */
  1319. static void sde_hw_rotator_map_vaddr(struct sde_dbg_buf *dbgbuf,
  1320. struct sde_layer_buffer *buf, struct sde_mdp_data *data)
  1321. {
  1322. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
  1323. struct iosys_map map;
  1324. #else
  1325. struct dma_buf_map map;
  1326. #endif
  1327. dbgbuf->dmabuf = data->p[0].srcp_dma_buf;
  1328. dbgbuf->buflen = data->p[0].srcp_dma_buf->size;
  1329. dbgbuf->vaddr = NULL;
  1330. dbgbuf->width = buf->width;
  1331. dbgbuf->height = buf->height;
  1332. if (dbgbuf->dmabuf && (dbgbuf->buflen > 0)) {
  1333. dma_buf_begin_cpu_access(dbgbuf->dmabuf, DMA_FROM_DEVICE);
  1334. dma_buf_vmap(dbgbuf->dmabuf, &map);
  1335. dbgbuf->vaddr = map.vaddr;
  1336. SDEROT_DBG("vaddr mapping: 0x%pK/%ld w:%d/h:%d\n",
  1337. dbgbuf->vaddr, dbgbuf->buflen,
  1338. dbgbuf->width, dbgbuf->height);
  1339. }
  1340. }
  1341. /*
  1342. * sde_hw_rotator_unmap_vaddr - unmap the debug buffer from kernel space
  1343. * @dbgbuf: Pointer to debug buffer
  1344. */
  1345. static void sde_hw_rotator_unmap_vaddr(struct sde_dbg_buf *dbgbuf)
  1346. {
  1347. if (dbgbuf->vaddr) {
  1348. dma_buf_vunmap(dbgbuf->dmabuf, dbgbuf->vaddr);
  1349. dma_buf_end_cpu_access(dbgbuf->dmabuf, DMA_FROM_DEVICE);
  1350. }
  1351. dbgbuf->vaddr = NULL;
  1352. dbgbuf->dmabuf = NULL;
  1353. dbgbuf->buflen = 0;
  1354. dbgbuf->width = 0;
  1355. dbgbuf->height = 0;
  1356. }
  1357. static void sde_hw_rotator_vbif_rt_setting(void)
  1358. {
  1359. u32 reg_high, reg_shift, reg_val, reg_val_lvl, mask, vbif_qos;
  1360. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1361. int i, j;
  1362. vbif_lock(mdata->parent_pdev);
  1363. for (i = 0; i < mdata->npriority_lvl; i++) {
  1364. for (j = 0; j < MAX_XIN; j++) {
  1365. reg_high = ((mdata->vbif_xin_id[j]
  1366. & 0x8) >> 3) * 4 + (i * 8);
  1367. reg_shift = mdata->vbif_xin_id[j] * 4;
  1368. reg_val = SDE_VBIF_READ(mdata,
  1369. MMSS_VBIF_NRT_VBIF_QOS_RP_REMAP_000 + reg_high);
  1370. reg_val_lvl = SDE_VBIF_READ(mdata,
  1371. MMSS_VBIF_NRT_VBIF_QOS_LVL_REMAP_000 + reg_high);
  1372. mask = 0x7 << (mdata->vbif_xin_id[j] * 4);
  1373. vbif_qos = mdata->vbif_nrt_qos[i];
  1374. reg_val &= ~mask;
  1375. reg_val |= (vbif_qos << reg_shift) & mask;
  1376. reg_val_lvl &= ~mask;
  1377. reg_val_lvl |= (vbif_qos << reg_shift) & mask;
  1378. SDE_VBIF_WRITE(mdata,
  1379. MMSS_VBIF_NRT_VBIF_QOS_RP_REMAP_000 + reg_high,
  1380. reg_val);
  1381. SDE_VBIF_WRITE(mdata,
  1382. MMSS_VBIF_NRT_VBIF_QOS_LVL_REMAP_000 + reg_high,
  1383. reg_val_lvl);
  1384. }
  1385. }
  1386. vbif_unlock(mdata->parent_pdev);
  1387. }
  1388. /*
  1389. * sde_hw_rotator_vbif_setting - helper function to set vbif QoS remapper
  1390. * levels, enable write gather enable and avoid clk gating setting for
  1391. * debug purpose.
  1392. *
  1393. * @rot: Pointer to rotator hw
  1394. */
  1395. static void sde_hw_rotator_vbif_setting(struct sde_hw_rotator *rot)
  1396. {
  1397. u32 i, mask, vbif_qos, reg_val = 0;
  1398. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1399. /* VBIF_ROT QoS remapper setting */
  1400. switch (mdata->npriority_lvl) {
  1401. case SDE_MDP_VBIF_4_LEVEL_REMAPPER:
  1402. for (i = 0; i < mdata->npriority_lvl; i++) {
  1403. reg_val = SDE_VBIF_READ(mdata,
  1404. MMSS_VBIF_NRT_VBIF_QOS_REMAP_00 + i*4);
  1405. mask = 0x3 << (XIN_SSPP * 2);
  1406. vbif_qos = mdata->vbif_nrt_qos[i];
  1407. reg_val |= vbif_qos << (XIN_SSPP * 2);
  1408. /* ensure write is issued after the read operation */
  1409. mb();
  1410. SDE_VBIF_WRITE(mdata,
  1411. MMSS_VBIF_NRT_VBIF_QOS_REMAP_00 + i*4,
  1412. reg_val);
  1413. }
  1414. break;
  1415. case SDE_MDP_VBIF_8_LEVEL_REMAPPER:
  1416. mask = mdata->npriority_lvl - 1;
  1417. for (i = 0; i < mdata->npriority_lvl; i++) {
  1418. /* RD and WR client */
  1419. reg_val |= (mdata->vbif_nrt_qos[i] & mask)
  1420. << (XIN_SSPP * 4);
  1421. reg_val |= (mdata->vbif_nrt_qos[i] & mask)
  1422. << (XIN_WRITEBACK * 4);
  1423. SDE_VBIF_WRITE(mdata,
  1424. MMSS_VBIF_NRT_VBIF_QOS_RP_REMAP_000 + i*8,
  1425. reg_val);
  1426. SDE_VBIF_WRITE(mdata,
  1427. MMSS_VBIF_NRT_VBIF_QOS_LVL_REMAP_000 + i*8,
  1428. reg_val);
  1429. }
  1430. break;
  1431. default:
  1432. SDEROT_DBG("invalid vbif remapper levels\n");
  1433. }
  1434. /* Enable write gather for writeback to remove write gaps, which
  1435. * may hang AXI/BIMC/SDE.
  1436. */
  1437. SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_WRITE_GATHTER_EN,
  1438. BIT(XIN_WRITEBACK));
  1439. /*
  1440. * For debug purpose, disable clock gating, i.e. Clocks always on
  1441. */
  1442. if (mdata->clk_always_on) {
  1443. SDE_VBIF_WRITE(mdata, MMSS_VBIF_CLKON, 0x3);
  1444. SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0, 0x3);
  1445. SDE_VBIF_WRITE(mdata, MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL1,
  1446. 0xFFFF);
  1447. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_CLK_CTRL, 1);
  1448. }
  1449. }
  1450. /*
  1451. * sde_hw_rotator_setup_timestamp_packet - setup timestamp writeback command
  1452. * @ctx: Pointer to rotator context
  1453. * @mask: Bit mask location of the timestamp
  1454. * @swts: Software timestamp
  1455. */
  1456. static void sde_hw_rotator_setup_timestamp_packet(
  1457. struct sde_hw_rotator_context *ctx, u32 mask, u32 swts)
  1458. {
  1459. char __iomem *wrptr;
  1460. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1461. /*
  1462. * Create a dummy packet write out to 1 location for timestamp
  1463. * generation.
  1464. */
  1465. SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_SIZE, 6);
  1466. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x00010001);
  1467. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1468. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1469. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x00010001);
  1470. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1471. SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->ts_addr);
  1472. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_YSTRIDE0, 4);
  1473. SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_FORMAT, 4);
  1474. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x004037FF);
  1475. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x03020100);
  1476. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x80000000);
  1477. SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->timestamp);
  1478. /*
  1479. * Must clear secure buffer setting for SW timestamp because
  1480. * SW timstamp buffer allocation is always non-secure region.
  1481. */
  1482. if (ctx->is_secure) {
  1483. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0);
  1484. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0);
  1485. }
  1486. SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_WB_DST_FORMAT, 4);
  1487. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x000037FF);
  1488. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1489. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0x03020100);
  1490. SDE_REGDMA_BLKWRITE_DATA(wrptr, ctx->ts_addr);
  1491. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_YSTRIDE0, 4);
  1492. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_SIZE, 0x00010001);
  1493. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_IMG_SIZE, 0x00010001);
  1494. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_XY, 0);
  1495. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_WRITE_CONFIG,
  1496. (ctx->rot->highest_bank & 0x3) << 8);
  1497. SDE_REGDMA_WRITE(wrptr, ROTTOP_DNSC, 0);
  1498. SDE_REGDMA_WRITE(wrptr, ROTTOP_OP_MODE, 1);
  1499. SDE_REGDMA_MODIFY(wrptr, REGDMA_TIMESTAMP_REG, mask, swts);
  1500. SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, 1);
  1501. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1502. }
  1503. /*
  1504. * sde_hw_rotator_cdp_configs - configures the CDP registers
  1505. * @ctx: Pointer to rotator context
  1506. * @params: Pointer to parameters needed for CDP configs
  1507. */
  1508. static void sde_hw_rotator_cdp_configs(struct sde_hw_rotator_context *ctx,
  1509. struct sde_rot_cdp_params *params)
  1510. {
  1511. int reg_val;
  1512. char __iomem *wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1513. if (!params->enable) {
  1514. SDE_REGDMA_WRITE(wrptr, params->offset, 0x0);
  1515. goto end;
  1516. }
  1517. reg_val = BIT(0); /* enable cdp */
  1518. if (sde_mdp_is_ubwc_format(params->fmt))
  1519. reg_val |= BIT(1); /* enable UBWC meta cdp */
  1520. if (sde_mdp_is_ubwc_format(params->fmt)
  1521. || sde_mdp_is_tilea4x_format(params->fmt)
  1522. || sde_mdp_is_tilea5x_format(params->fmt))
  1523. reg_val |= BIT(2); /* enable tile amortize */
  1524. reg_val |= BIT(3); /* enable preload addr ahead cnt 64 */
  1525. SDE_REGDMA_WRITE(wrptr, params->offset, reg_val);
  1526. end:
  1527. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1528. }
  1529. /*
  1530. * sde_hw_rotator_setup_qos_lut_wr - Set QoS LUT/Danger LUT/Safe LUT configs
  1531. * for the WRITEBACK rotator for inline and offline rotation.
  1532. *
  1533. * @ctx: Pointer to rotator context
  1534. */
  1535. static void sde_hw_rotator_setup_qos_lut_wr(struct sde_hw_rotator_context *ctx)
  1536. {
  1537. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1538. char __iomem *wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1539. /* Offline rotation setting */
  1540. if (!ctx->sbuf_mode) {
  1541. /* QOS LUT WR setting */
  1542. if (test_bit(SDE_QOS_LUT, mdata->sde_qos_map)) {
  1543. SDE_REGDMA_WRITE(wrptr, ROT_WB_CREQ_LUT_0,
  1544. mdata->lut_cfg[SDE_ROT_WR].creq_lut_0);
  1545. SDE_REGDMA_WRITE(wrptr, ROT_WB_CREQ_LUT_1,
  1546. mdata->lut_cfg[SDE_ROT_WR].creq_lut_1);
  1547. }
  1548. /* Danger LUT WR setting */
  1549. if (test_bit(SDE_QOS_DANGER_LUT, mdata->sde_qos_map))
  1550. SDE_REGDMA_WRITE(wrptr, ROT_WB_DANGER_LUT,
  1551. mdata->lut_cfg[SDE_ROT_WR].danger_lut);
  1552. /* Safe LUT WR setting */
  1553. if (test_bit(SDE_QOS_SAFE_LUT, mdata->sde_qos_map))
  1554. SDE_REGDMA_WRITE(wrptr, ROT_WB_SAFE_LUT,
  1555. mdata->lut_cfg[SDE_ROT_WR].safe_lut);
  1556. /* Inline rotation setting */
  1557. } else {
  1558. /* QOS LUT WR setting */
  1559. if (test_bit(SDE_INLINE_QOS_LUT, mdata->sde_inline_qos_map)) {
  1560. SDE_REGDMA_WRITE(wrptr, ROT_WB_CREQ_LUT_0,
  1561. mdata->inline_lut_cfg[SDE_ROT_WR].creq_lut_0);
  1562. SDE_REGDMA_WRITE(wrptr, ROT_WB_CREQ_LUT_1,
  1563. mdata->inline_lut_cfg[SDE_ROT_WR].creq_lut_1);
  1564. }
  1565. /* Danger LUT WR setting */
  1566. if (test_bit(SDE_INLINE_QOS_DANGER_LUT,
  1567. mdata->sde_inline_qos_map))
  1568. SDE_REGDMA_WRITE(wrptr, ROT_WB_DANGER_LUT,
  1569. mdata->inline_lut_cfg[SDE_ROT_WR].danger_lut);
  1570. /* Safe LUT WR setting */
  1571. if (test_bit(SDE_INLINE_QOS_SAFE_LUT,
  1572. mdata->sde_inline_qos_map))
  1573. SDE_REGDMA_WRITE(wrptr, ROT_WB_SAFE_LUT,
  1574. mdata->inline_lut_cfg[SDE_ROT_WR].safe_lut);
  1575. }
  1576. /* Update command queue write ptr */
  1577. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1578. }
  1579. /*
  1580. * sde_hw_rotator_setup_qos_lut_rd - Set QoS LUT/Danger LUT/Safe LUT configs
  1581. * for the SSPP rotator for inline and offline rotation.
  1582. *
  1583. * @ctx: Pointer to rotator context
  1584. */
  1585. static void sde_hw_rotator_setup_qos_lut_rd(struct sde_hw_rotator_context *ctx)
  1586. {
  1587. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1588. char __iomem *wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1589. /* Offline rotation setting */
  1590. if (!ctx->sbuf_mode) {
  1591. /* QOS LUT RD setting */
  1592. if (test_bit(SDE_QOS_LUT, mdata->sde_qos_map)) {
  1593. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_CREQ_LUT_0,
  1594. mdata->lut_cfg[SDE_ROT_RD].creq_lut_0);
  1595. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_CREQ_LUT_1,
  1596. mdata->lut_cfg[SDE_ROT_RD].creq_lut_1);
  1597. }
  1598. /* Danger LUT RD setting */
  1599. if (test_bit(SDE_QOS_DANGER_LUT, mdata->sde_qos_map))
  1600. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_DANGER_LUT,
  1601. mdata->lut_cfg[SDE_ROT_RD].danger_lut);
  1602. /* Safe LUT RD setting */
  1603. if (test_bit(SDE_QOS_SAFE_LUT, mdata->sde_qos_map))
  1604. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SAFE_LUT,
  1605. mdata->lut_cfg[SDE_ROT_RD].safe_lut);
  1606. /* inline rotation setting */
  1607. } else {
  1608. /* QOS LUT RD setting */
  1609. if (test_bit(SDE_INLINE_QOS_LUT, mdata->sde_inline_qos_map)) {
  1610. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_CREQ_LUT_0,
  1611. mdata->inline_lut_cfg[SDE_ROT_RD].creq_lut_0);
  1612. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_CREQ_LUT_1,
  1613. mdata->inline_lut_cfg[SDE_ROT_RD].creq_lut_1);
  1614. }
  1615. /* Danger LUT RD setting */
  1616. if (test_bit(SDE_INLINE_QOS_DANGER_LUT,
  1617. mdata->sde_inline_qos_map))
  1618. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_DANGER_LUT,
  1619. mdata->inline_lut_cfg[SDE_ROT_RD].danger_lut);
  1620. /* Safe LUT RD setting */
  1621. if (test_bit(SDE_INLINE_QOS_SAFE_LUT,
  1622. mdata->sde_inline_qos_map))
  1623. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SAFE_LUT,
  1624. mdata->inline_lut_cfg[SDE_ROT_RD].safe_lut);
  1625. }
  1626. /* Update command queue write ptr */
  1627. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1628. }
  1629. static void sde_hw_rotator_setup_fetchengine_helper(
  1630. struct sde_hw_rot_sspp_cfg *cfg,
  1631. struct sde_rot_data_type *mdata,
  1632. struct sde_hw_rotator_context *ctx, char __iomem *wrptr,
  1633. u32 flags, u32 *width, u32 *height)
  1634. {
  1635. int i;
  1636. /*
  1637. * initialize start control trigger selection first
  1638. */
  1639. if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) {
  1640. if (ctx->sbuf_mode)
  1641. SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL,
  1642. ctx->start_ctrl);
  1643. else
  1644. SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, 0);
  1645. }
  1646. /* source image setup */
  1647. if ((flags & SDE_ROT_FLAG_DEINTERLACE)
  1648. && !(flags & SDE_ROT_FLAG_SOURCE_ROTATED_90)) {
  1649. for (i = 0; i < cfg->src_plane.num_planes; i++)
  1650. cfg->src_plane.ystride[i] *= 2;
  1651. *width *= 2;
  1652. *height /= 2;
  1653. }
  1654. }
  1655. /*
  1656. * sde_hw_rotator_setup_fetchengine - setup fetch engine
  1657. * @ctx: Pointer to rotator context
  1658. * @queue_id: Priority queue identifier
  1659. * @cfg: Fetch configuration
  1660. * @danger_lut: real-time QoS LUT for danger setting (not used)
  1661. * @safe_lut: real-time QoS LUT for safe setting (not used)
  1662. * @dnsc_factor_w: downscale factor for width
  1663. * @dnsc_factor_h: downscale factor for height
  1664. * @flags: Control flag
  1665. */
  1666. static void sde_hw_rotator_setup_fetchengine(struct sde_hw_rotator_context *ctx,
  1667. enum sde_rot_queue_prio queue_id,
  1668. struct sde_hw_rot_sspp_cfg *cfg, u32 danger_lut, u32 safe_lut,
  1669. u32 dnsc_factor_w, u32 dnsc_factor_h, u32 flags)
  1670. {
  1671. struct sde_hw_rotator *rot = ctx->rot;
  1672. struct sde_mdp_format_params *fmt;
  1673. struct sde_mdp_data *data;
  1674. struct sde_rot_cdp_params cdp_params = {0};
  1675. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1676. char __iomem *wrptr;
  1677. u32 opmode = 0;
  1678. u32 chroma_samp = 0;
  1679. u32 src_format = 0;
  1680. u32 unpack = 0;
  1681. u32 width = cfg->img_width;
  1682. u32 height = cfg->img_height;
  1683. u32 fetch_blocksize = 0;
  1684. int i;
  1685. if (ctx->rot->mode == ROT_REGDMA_ON) {
  1686. if (rot->irq_num >= 0)
  1687. SDE_ROTREG_WRITE(rot->mdss_base,
  1688. REGDMA_CSR_REGDMA_INT_EN,
  1689. REGDMA_INT_MASK);
  1690. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_OP_MODE,
  1691. REGDMA_EN);
  1692. }
  1693. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1694. sde_hw_rotator_setup_fetchengine_helper(cfg, mdata, ctx, wrptr,
  1695. flags, &width, &height);
  1696. /*
  1697. * REGDMA BLK write from SRC_SIZE to OP_MODE, total 15 registers
  1698. */
  1699. SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_SSPP_SRC_SIZE, 15);
  1700. /* SRC_SIZE, SRC_IMG_SIZE, SRC_XY, OUT_SIZE, OUT_XY */
  1701. SDE_REGDMA_BLKWRITE_DATA(wrptr,
  1702. cfg->src_rect->w | (cfg->src_rect->h << 16));
  1703. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0); /* SRC_IMG_SIZE unused */
  1704. SDE_REGDMA_BLKWRITE_DATA(wrptr,
  1705. cfg->src_rect->x | (cfg->src_rect->y << 16));
  1706. SDE_REGDMA_BLKWRITE_DATA(wrptr,
  1707. cfg->src_rect->w | (cfg->src_rect->h << 16));
  1708. SDE_REGDMA_BLKWRITE_DATA(wrptr,
  1709. cfg->src_rect->x | (cfg->src_rect->y << 16));
  1710. /* SRC_ADDR [0-3], SRC_YSTRIDE [0-1] */
  1711. data = cfg->data;
  1712. for (i = 0; i < SDE_ROT_MAX_PLANES; i++)
  1713. SDE_REGDMA_BLKWRITE_DATA(wrptr, data->p[i].addr);
  1714. SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->src_plane.ystride[0] |
  1715. (cfg->src_plane.ystride[1] << 16));
  1716. SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->src_plane.ystride[2] |
  1717. (cfg->src_plane.ystride[3] << 16));
  1718. /* UNUSED, write 0 */
  1719. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1720. /* setup source format */
  1721. fmt = cfg->fmt;
  1722. chroma_samp = fmt->chroma_sample;
  1723. if (flags & SDE_ROT_FLAG_SOURCE_ROTATED_90) {
  1724. if (chroma_samp == SDE_MDP_CHROMA_H2V1)
  1725. chroma_samp = SDE_MDP_CHROMA_H1V2;
  1726. else if (chroma_samp == SDE_MDP_CHROMA_H1V2)
  1727. chroma_samp = SDE_MDP_CHROMA_H2V1;
  1728. }
  1729. src_format = (chroma_samp << 23) |
  1730. (fmt->fetch_planes << 19) |
  1731. (fmt->bits[C3_ALPHA] << 6) |
  1732. (fmt->bits[C2_R_Cr] << 4) |
  1733. (fmt->bits[C1_B_Cb] << 2) |
  1734. (fmt->bits[C0_G_Y] << 0);
  1735. if (fmt->alpha_enable &&
  1736. (fmt->fetch_planes == SDE_MDP_PLANE_INTERLEAVED))
  1737. src_format |= BIT(8); /* SRCC3_EN */
  1738. src_format |= ((fmt->unpack_count - 1) << 12) |
  1739. (fmt->unpack_tight << 17) |
  1740. (fmt->unpack_align_msb << 18) |
  1741. ((fmt->bpp - 1) << 9) |
  1742. ((fmt->frame_format & 3) << 30);
  1743. if (flags & SDE_ROT_FLAG_ROT_90)
  1744. src_format |= BIT(11); /* ROT90 */
  1745. if (sde_mdp_is_ubwc_format(fmt))
  1746. opmode |= BIT(0); /* BWC_DEC_EN */
  1747. /* if this is YUV pixel format, enable CSC */
  1748. if (sde_mdp_is_yuv_format(fmt))
  1749. src_format |= BIT(15); /* SRC_COLOR_SPACE */
  1750. if (fmt->pixel_mode == SDE_MDP_PIXEL_10BIT)
  1751. src_format |= BIT(14); /* UNPACK_DX_FORMAT */
  1752. if (rot->solid_fill)
  1753. src_format |= BIT(22); /* SOLID_FILL */
  1754. /* SRC_FORMAT */
  1755. SDE_REGDMA_BLKWRITE_DATA(wrptr, src_format);
  1756. /* setup source unpack pattern */
  1757. unpack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  1758. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  1759. /* SRC_UNPACK_PATTERN */
  1760. SDE_REGDMA_BLKWRITE_DATA(wrptr, unpack);
  1761. /* setup source op mode */
  1762. if (flags & SDE_ROT_FLAG_FLIP_LR)
  1763. opmode |= BIT(13); /* FLIP_MODE L/R horizontal flip */
  1764. if (flags & SDE_ROT_FLAG_FLIP_UD)
  1765. opmode |= BIT(14); /* FLIP_MODE U/D vertical flip */
  1766. opmode |= BIT(31); /* MDSS_MDP_OP_PE_OVERRIDE */
  1767. /* SRC_OP_MODE */
  1768. SDE_REGDMA_BLKWRITE_DATA(wrptr, opmode);
  1769. /* setup source fetch config, TP10 uses different block size */
  1770. if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map) &&
  1771. (dnsc_factor_w == 1) && (dnsc_factor_h == 1)) {
  1772. if (sde_mdp_is_tp10_format(fmt))
  1773. fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_144_EXT;
  1774. else
  1775. fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_192_EXT;
  1776. } else {
  1777. if (sde_mdp_is_tp10_format(fmt))
  1778. fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_96;
  1779. else
  1780. fetch_blocksize = SDE_ROT_SSPP_FETCH_BLOCKSIZE_128;
  1781. }
  1782. if (rot->solid_fill)
  1783. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_CONSTANT_COLOR,
  1784. rot->constant_color);
  1785. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_FETCH_CONFIG,
  1786. fetch_blocksize |
  1787. SDE_ROT_SSPP_FETCH_CONFIG_RESET_VALUE |
  1788. ((rot->highest_bank & 0x3) << 18));
  1789. if (test_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map))
  1790. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_UBWC_STATIC_CTRL,
  1791. ((ctx->rot->ubwc_malsize & 0x3) << 8) |
  1792. ((ctx->rot->highest_bank & 0x3) << 4) |
  1793. ((ctx->rot->ubwc_swizzle & 0x1) << 0));
  1794. else if (test_bit(SDE_CAPS_UBWC_3, mdata->sde_caps_map) ||
  1795. test_bit(SDE_CAPS_UBWC_4, mdata->sde_caps_map))
  1796. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_UBWC_STATIC_CTRL, BIT(30));
  1797. /* setup source buffer plane security status */
  1798. if (flags & (SDE_ROT_FLAG_SECURE_OVERLAY_SESSION |
  1799. SDE_ROT_FLAG_SECURE_CAMERA_SESSION)) {
  1800. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0xF);
  1801. ctx->is_secure = true;
  1802. } else {
  1803. SDE_REGDMA_WRITE(wrptr, ROT_SSPP_SRC_ADDR_SW_STATUS, 0);
  1804. ctx->is_secure = false;
  1805. }
  1806. /* Update command queue write ptr */
  1807. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1808. /* CDP register RD setting */
  1809. cdp_params.enable = test_bit(SDE_QOS_CDP, mdata->sde_qos_map) ?
  1810. mdata->enable_cdp[SDE_ROT_RD] : false;
  1811. cdp_params.fmt = fmt;
  1812. cdp_params.offset = ROT_SSPP_CDP_CNTL;
  1813. sde_hw_rotator_cdp_configs(ctx, &cdp_params);
  1814. /* QOS LUT/ Danger LUT/ Safe Lut WR setting */
  1815. sde_hw_rotator_setup_qos_lut_rd(ctx);
  1816. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1817. /*
  1818. * Determine if traffic shaping is required. Only enable traffic
  1819. * shaping when content is 4k@30fps. The actual traffic shaping
  1820. * bandwidth calculation is done in output setup.
  1821. */
  1822. if (((!ctx->sbuf_mode)
  1823. && (cfg->src_rect->w * cfg->src_rect->h) >= RES_UHD)
  1824. && (cfg->fps <= 30)) {
  1825. SDEROT_DBG("Enable Traffic Shaper\n");
  1826. ctx->is_traffic_shaping = true;
  1827. } else {
  1828. SDEROT_DBG("Disable Traffic Shaper\n");
  1829. ctx->is_traffic_shaping = false;
  1830. }
  1831. /* Update command queue write ptr */
  1832. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1833. }
  1834. /*
  1835. * sde_hw_rotator_setup_wbengine - setup writeback engine
  1836. * @ctx: Pointer to rotator context
  1837. * @queue_id: Priority queue identifier
  1838. * @cfg: Writeback configuration
  1839. * @flags: Control flag
  1840. */
  1841. static void sde_hw_rotator_setup_wbengine(struct sde_hw_rotator_context *ctx,
  1842. enum sde_rot_queue_prio queue_id,
  1843. struct sde_hw_rot_wb_cfg *cfg,
  1844. u32 flags)
  1845. {
  1846. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  1847. struct sde_mdp_format_params *fmt;
  1848. struct sde_rot_cdp_params cdp_params = {0};
  1849. char __iomem *wrptr;
  1850. u32 pack = 0;
  1851. u32 dst_format = 0;
  1852. u32 no_partial_writes = 0;
  1853. int i;
  1854. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1855. fmt = cfg->fmt;
  1856. /* setup WB DST format */
  1857. dst_format |= (fmt->chroma_sample << 23) |
  1858. (fmt->fetch_planes << 19) |
  1859. (fmt->bits[C3_ALPHA] << 6) |
  1860. (fmt->bits[C2_R_Cr] << 4) |
  1861. (fmt->bits[C1_B_Cb] << 2) |
  1862. (fmt->bits[C0_G_Y] << 0);
  1863. /* alpha control */
  1864. if (fmt->alpha_enable || (!fmt->is_yuv && (fmt->unpack_count == 4))) {
  1865. dst_format |= BIT(8);
  1866. if (!fmt->alpha_enable) {
  1867. dst_format |= BIT(14);
  1868. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ALPHA_X_VALUE, 0);
  1869. }
  1870. }
  1871. dst_format |= ((fmt->unpack_count - 1) << 12) |
  1872. (fmt->unpack_tight << 17) |
  1873. (fmt->unpack_align_msb << 18) |
  1874. ((fmt->bpp - 1) << 9) |
  1875. ((fmt->frame_format & 3) << 30);
  1876. if (sde_mdp_is_yuv_format(fmt))
  1877. dst_format |= BIT(15);
  1878. if (fmt->pixel_mode == SDE_MDP_PIXEL_10BIT)
  1879. dst_format |= BIT(21); /* PACK_DX_FORMAT */
  1880. /*
  1881. * REGDMA BLK write, from DST_FORMAT to DST_YSTRIDE 1, total 9 regs
  1882. */
  1883. SDE_REGDMA_BLKWRITE_INC(wrptr, ROT_WB_DST_FORMAT, 9);
  1884. /* DST_FORMAT */
  1885. SDE_REGDMA_BLKWRITE_DATA(wrptr, dst_format);
  1886. /* DST_OP_MODE */
  1887. if (sde_mdp_is_ubwc_format(fmt))
  1888. SDE_REGDMA_BLKWRITE_DATA(wrptr, BIT(0));
  1889. else
  1890. SDE_REGDMA_BLKWRITE_DATA(wrptr, 0);
  1891. /* DST_PACK_PATTERN */
  1892. pack = (fmt->element[3] << 24) | (fmt->element[2] << 16) |
  1893. (fmt->element[1] << 8) | (fmt->element[0] << 0);
  1894. SDE_REGDMA_BLKWRITE_DATA(wrptr, pack);
  1895. /* DST_ADDR [0-3], DST_YSTRIDE [0-1] */
  1896. for (i = 0; i < SDE_ROT_MAX_PLANES; i++)
  1897. SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->data->p[i].addr);
  1898. SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->dst_plane.ystride[0] |
  1899. (cfg->dst_plane.ystride[1] << 16));
  1900. SDE_REGDMA_BLKWRITE_DATA(wrptr, cfg->dst_plane.ystride[2] |
  1901. (cfg->dst_plane.ystride[3] << 16));
  1902. /* setup WB out image size and ROI */
  1903. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_IMG_SIZE,
  1904. cfg->img_width | (cfg->img_height << 16));
  1905. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_SIZE,
  1906. cfg->dst_rect->w | (cfg->dst_rect->h << 16));
  1907. SDE_REGDMA_WRITE(wrptr, ROT_WB_OUT_XY,
  1908. cfg->dst_rect->x | (cfg->dst_rect->y << 16));
  1909. if (flags & (SDE_ROT_FLAG_SECURE_OVERLAY_SESSION |
  1910. SDE_ROT_FLAG_SECURE_CAMERA_SESSION))
  1911. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0x1);
  1912. else
  1913. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_ADDR_SW_STATUS, 0);
  1914. /*
  1915. * setup Downscale factor
  1916. */
  1917. SDE_REGDMA_WRITE(wrptr, ROTTOP_DNSC,
  1918. cfg->v_downscale_factor |
  1919. (cfg->h_downscale_factor << 16));
  1920. /* partial write check */
  1921. if (test_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map)) {
  1922. no_partial_writes = BIT(10);
  1923. /*
  1924. * For simplicity, don't disable partial writes if
  1925. * the ROI does not span the entire width of the
  1926. * output image, and require the total stride to
  1927. * also be properly aligned.
  1928. *
  1929. * This avoids having to determine the memory access
  1930. * alignment of the actual horizontal ROI on a per
  1931. * color format basis.
  1932. */
  1933. if (sde_mdp_is_ubwc_format(fmt)) {
  1934. no_partial_writes = 0x0;
  1935. } else if (cfg->dst_rect->x ||
  1936. cfg->dst_rect->w != cfg->img_width) {
  1937. no_partial_writes = 0x0;
  1938. } else {
  1939. for (i = 0; i < SDE_ROT_MAX_PLANES; i++)
  1940. if (cfg->dst_plane.ystride[i] &
  1941. PARTIAL_WRITE_ALIGNMENT)
  1942. no_partial_writes = 0x0;
  1943. }
  1944. }
  1945. /* write config setup for bank configuration */
  1946. SDE_REGDMA_WRITE(wrptr, ROT_WB_DST_WRITE_CONFIG, no_partial_writes |
  1947. (ctx->rot->highest_bank & 0x3) << 8);
  1948. if (test_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map))
  1949. SDE_REGDMA_WRITE(wrptr, ROT_WB_UBWC_STATIC_CTRL,
  1950. ((ctx->rot->ubwc_malsize & 0x3) << 8) |
  1951. ((ctx->rot->highest_bank & 0x3) << 4) |
  1952. ((ctx->rot->ubwc_swizzle & 0x1) << 0));
  1953. if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map))
  1954. SDE_REGDMA_WRITE(wrptr, ROT_WB_SYS_CACHE_MODE,
  1955. ctx->sys_cache_mode);
  1956. SDE_REGDMA_WRITE(wrptr, ROTTOP_OP_MODE, ctx->op_mode |
  1957. (flags & SDE_ROT_FLAG_ROT_90 ? BIT(1) : 0) | BIT(0));
  1958. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  1959. /* CDP register WR setting */
  1960. cdp_params.enable = test_bit(SDE_QOS_CDP, mdata->sde_qos_map) ?
  1961. mdata->enable_cdp[SDE_ROT_WR] : false;
  1962. cdp_params.fmt = fmt;
  1963. cdp_params.offset = ROT_WB_CDP_CNTL;
  1964. sde_hw_rotator_cdp_configs(ctx, &cdp_params);
  1965. /* QOS LUT/ Danger LUT/ Safe LUT WR setting */
  1966. sde_hw_rotator_setup_qos_lut_wr(ctx);
  1967. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  1968. /* setup traffic shaper for 4k 30fps content or if prefill_bw is set */
  1969. if (ctx->is_traffic_shaping || cfg->prefill_bw) {
  1970. u32 bw;
  1971. /*
  1972. * Target to finish in 12ms, and we need to set number of bytes
  1973. * per clock tick for traffic shaping.
  1974. * Each clock tick run @ 19.2MHz, so we need we know total of
  1975. * clock ticks in 14ms, i.e. 12ms/(1/19.2MHz) ==> 23040
  1976. * Finally, calcualte the byte count per clock tick based on
  1977. * resolution, bpp and compression ratio.
  1978. */
  1979. bw = cfg->dst_rect->w * cfg->dst_rect->h;
  1980. if (fmt->chroma_sample == SDE_MDP_CHROMA_420)
  1981. bw = (bw * 3) / 2;
  1982. else
  1983. bw *= fmt->bpp;
  1984. bw /= TRAFFIC_SHAPE_CLKTICK_12MS;
  1985. /* use prefill bandwidth instead if specified */
  1986. if (cfg->prefill_bw)
  1987. bw = DIV_ROUND_UP_SECTOR_T(cfg->prefill_bw,
  1988. TRAFFIC_SHAPE_VSYNC_CLK);
  1989. if (bw > 0xFF)
  1990. bw = 0xFF;
  1991. else if (bw == 0)
  1992. bw = 1;
  1993. SDE_REGDMA_WRITE(wrptr, ROT_WB_TRAFFIC_SHAPER_WR_CLIENT,
  1994. BIT(31) | (cfg->prefill_bw ? BIT(27) : 0) | bw);
  1995. SDEROT_DBG("Enable ROT_WB Traffic Shaper:%d\n", bw);
  1996. } else {
  1997. SDE_REGDMA_WRITE(wrptr, ROT_WB_TRAFFIC_SHAPER_WR_CLIENT, 0);
  1998. SDEROT_DBG("Disable ROT_WB Traffic Shaper\n");
  1999. }
  2000. /* Update command queue write ptr */
  2001. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  2002. }
  2003. /*
  2004. * sde_hw_rotator_start_no_regdma - start non-regdma operation
  2005. * @ctx: Pointer to rotator context
  2006. * @queue_id: Priority queue identifier
  2007. */
  2008. static u32 sde_hw_rotator_start_no_regdma(struct sde_hw_rotator_context *ctx,
  2009. enum sde_rot_queue_prio queue_id)
  2010. {
  2011. struct sde_hw_rotator *rot = ctx->rot;
  2012. char __iomem *wrptr;
  2013. char __iomem *mem_rdptr;
  2014. char __iomem *addr;
  2015. u32 mask;
  2016. u32 cmd0, cmd1, cmd2;
  2017. u32 blksize;
  2018. /*
  2019. * when regdma is not using, the regdma segment is just a normal
  2020. * DRAM, and not an iomem.
  2021. */
  2022. mem_rdptr = sde_hw_rotator_get_regdma_segment_base(ctx);
  2023. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  2024. if (!sde_hw_rotator_enable_irq(rot)) {
  2025. SDE_REGDMA_WRITE(wrptr, ROTTOP_INTR_EN, 1);
  2026. SDE_REGDMA_WRITE(wrptr, ROTTOP_INTR_CLEAR, 1);
  2027. reinit_completion(&ctx->rot_comp);
  2028. }
  2029. SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, ctx->start_ctrl);
  2030. /* Update command queue write ptr */
  2031. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  2032. SDEROT_DBG("BEGIN %d\n", ctx->timestamp);
  2033. /* Write all command stream to Rotator blocks */
  2034. /* Rotator will start right away after command stream finish writing */
  2035. while (mem_rdptr < wrptr) {
  2036. u32 op = REGDMA_OP_MASK & readl_relaxed(mem_rdptr);
  2037. switch (op) {
  2038. case REGDMA_OP_NOP:
  2039. SDEROT_DBG("NOP\n");
  2040. mem_rdptr += sizeof(u32);
  2041. break;
  2042. case REGDMA_OP_REGWRITE:
  2043. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2044. SDE_REGDMA_READ(mem_rdptr, cmd1);
  2045. SDEROT_DBG("REGW %6.6x %8.8x\n",
  2046. cmd0 & REGDMA_ADDR_OFFSET_MASK,
  2047. cmd1);
  2048. addr = rot->mdss_base +
  2049. (cmd0 & REGDMA_ADDR_OFFSET_MASK);
  2050. writel_relaxed(cmd1, addr);
  2051. break;
  2052. case REGDMA_OP_REGMODIFY:
  2053. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2054. SDE_REGDMA_READ(mem_rdptr, cmd1);
  2055. SDE_REGDMA_READ(mem_rdptr, cmd2);
  2056. SDEROT_DBG("REGM %6.6x %8.8x %8.8x\n",
  2057. cmd0 & REGDMA_ADDR_OFFSET_MASK,
  2058. cmd1, cmd2);
  2059. addr = rot->mdss_base +
  2060. (cmd0 & REGDMA_ADDR_OFFSET_MASK);
  2061. mask = cmd1;
  2062. writel_relaxed((readl_relaxed(addr) & mask) | cmd2,
  2063. addr);
  2064. break;
  2065. case REGDMA_OP_BLKWRITE_SINGLE:
  2066. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2067. SDE_REGDMA_READ(mem_rdptr, cmd1);
  2068. SDEROT_DBG("BLKWS %6.6x %6.6x\n",
  2069. cmd0 & REGDMA_ADDR_OFFSET_MASK,
  2070. cmd1);
  2071. addr = rot->mdss_base +
  2072. (cmd0 & REGDMA_ADDR_OFFSET_MASK);
  2073. blksize = cmd1;
  2074. while (blksize--) {
  2075. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2076. SDEROT_DBG("DATA %8.8x\n", cmd0);
  2077. writel_relaxed(cmd0, addr);
  2078. }
  2079. break;
  2080. case REGDMA_OP_BLKWRITE_INC:
  2081. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2082. SDE_REGDMA_READ(mem_rdptr, cmd1);
  2083. SDEROT_DBG("BLKWI %6.6x %6.6x\n",
  2084. cmd0 & REGDMA_ADDR_OFFSET_MASK,
  2085. cmd1);
  2086. addr = rot->mdss_base +
  2087. (cmd0 & REGDMA_ADDR_OFFSET_MASK);
  2088. blksize = cmd1;
  2089. while (blksize--) {
  2090. SDE_REGDMA_READ(mem_rdptr, cmd0);
  2091. SDEROT_DBG("DATA %8.8x\n", cmd0);
  2092. writel_relaxed(cmd0, addr);
  2093. addr += 4;
  2094. }
  2095. break;
  2096. default:
  2097. /* Other not supported OP mode
  2098. * Skip data for now for unregonized OP mode
  2099. */
  2100. SDEROT_DBG("UNDEFINED\n");
  2101. mem_rdptr += sizeof(u32);
  2102. break;
  2103. }
  2104. }
  2105. SDEROT_DBG("END %d\n", ctx->timestamp);
  2106. return ctx->timestamp;
  2107. }
  2108. /*
  2109. * sde_hw_rotator_start_regdma - start regdma operation
  2110. * @ctx: Pointer to rotator context
  2111. * @queue_id: Priority queue identifier
  2112. */
  2113. static u32 sde_hw_rotator_start_regdma(struct sde_hw_rotator_context *ctx,
  2114. enum sde_rot_queue_prio queue_id)
  2115. {
  2116. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  2117. struct sde_hw_rotator *rot = ctx->rot;
  2118. char __iomem *wrptr;
  2119. u32 regdmaSlot;
  2120. u32 offset;
  2121. u32 length;
  2122. u32 ts_length;
  2123. u32 enableInt;
  2124. u32 swts = 0;
  2125. u32 mask = 0;
  2126. u32 trig_sel;
  2127. bool int_trigger = false;
  2128. wrptr = sde_hw_rotator_get_regdma_segment(ctx);
  2129. /* Enable HW timestamp if supported in rotator */
  2130. if (test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map)) {
  2131. SDE_REGDMA_MODIFY(wrptr, ROTTOP_ROT_CNTR_CTRL,
  2132. ~BIT(queue_id), BIT(queue_id));
  2133. int_trigger = true;
  2134. } else if (ctx->sbuf_mode) {
  2135. int_trigger = true;
  2136. }
  2137. /*
  2138. * Last ROT command must be ROT_START before REGDMA start
  2139. */
  2140. SDE_REGDMA_WRITE(wrptr, ROTTOP_START_CTRL, ctx->start_ctrl);
  2141. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  2142. /*
  2143. * Start REGDMA with command offset and size
  2144. */
  2145. regdmaSlot = sde_hw_rotator_get_regdma_ctxidx(ctx);
  2146. length = (wrptr - ctx->regdma_base) / 4;
  2147. offset = (ctx->regdma_base - (rot->mdss_base +
  2148. REGDMA_RAM_REGDMA_CMD_RAM)) / sizeof(u32);
  2149. enableInt = ((ctx->timestamp & 1) + 1) << 30;
  2150. trig_sel = ctx->sbuf_mode ? REGDMA_CMD_TRIG_SEL_MDP_FLUSH :
  2151. REGDMA_CMD_TRIG_SEL_SW_START;
  2152. SDEROT_DBG(
  2153. "regdma(%d)[%d] <== INT:0x%X|length:%d|offset:0x%X, ts:%X\n",
  2154. queue_id, regdmaSlot, enableInt, length, offset,
  2155. ctx->timestamp);
  2156. /* ensure the command packet is issued before the submit command */
  2157. wmb();
  2158. /* REGDMA submission for current context */
  2159. if (queue_id == ROT_QUEUE_HIGH_PRIORITY) {
  2160. SDE_ROTREG_WRITE(rot->mdss_base,
  2161. REGDMA_CSR_REGDMA_QUEUE_0_SUBMIT,
  2162. (int_trigger ? enableInt : 0) | trig_sel |
  2163. ((length & 0x3ff) << 14) | offset);
  2164. swts = ctx->timestamp;
  2165. mask = ~SDE_REGDMA_SWTS_MASK;
  2166. } else {
  2167. SDE_ROTREG_WRITE(rot->mdss_base,
  2168. REGDMA_CSR_REGDMA_QUEUE_1_SUBMIT,
  2169. (int_trigger ? enableInt : 0) | trig_sel |
  2170. ((length & 0x3ff) << 14) | offset);
  2171. swts = ctx->timestamp << SDE_REGDMA_SWTS_SHIFT;
  2172. mask = ~(SDE_REGDMA_SWTS_MASK << SDE_REGDMA_SWTS_SHIFT);
  2173. }
  2174. SDEROT_EVTLOG(ctx->timestamp, queue_id, length, offset, ctx->sbuf_mode);
  2175. /* sw timestamp update can only be used in offline multi-context mode */
  2176. if (!int_trigger) {
  2177. /* Write timestamp after previous rotator job finished */
  2178. sde_hw_rotator_setup_timestamp_packet(ctx, mask, swts);
  2179. offset += length;
  2180. ts_length = sde_hw_rotator_get_regdma_segment(ctx) - wrptr;
  2181. ts_length /= sizeof(u32);
  2182. WARN_ON((length + ts_length) > SDE_HW_ROT_REGDMA_SEG_SIZE);
  2183. /* ensure command packet is issue before the submit command */
  2184. wmb();
  2185. SDEROT_EVTLOG(queue_id, enableInt, ts_length, offset);
  2186. if (queue_id == ROT_QUEUE_HIGH_PRIORITY) {
  2187. SDE_ROTREG_WRITE(rot->mdss_base,
  2188. REGDMA_CSR_REGDMA_QUEUE_0_SUBMIT,
  2189. enableInt | (ts_length << 14) | offset);
  2190. } else {
  2191. SDE_ROTREG_WRITE(rot->mdss_base,
  2192. REGDMA_CSR_REGDMA_QUEUE_1_SUBMIT,
  2193. enableInt | (ts_length << 14) | offset);
  2194. }
  2195. }
  2196. /* Update command queue write ptr */
  2197. sde_hw_rotator_put_regdma_segment(ctx, wrptr);
  2198. return ctx->timestamp;
  2199. }
  2200. /*
  2201. * sde_hw_rotator_wait_done_no_regdma - wait for non-regdma completion
  2202. * @ctx: Pointer to rotator context
  2203. * @queue_id: Priority queue identifier
  2204. * @flags: Option flag
  2205. */
  2206. static u32 sde_hw_rotator_wait_done_no_regdma(
  2207. struct sde_hw_rotator_context *ctx,
  2208. enum sde_rot_queue_prio queue_id, u32 flag)
  2209. {
  2210. struct sde_hw_rotator *rot = ctx->rot;
  2211. int rc = 0;
  2212. u32 sts = 0;
  2213. u32 status;
  2214. unsigned long flags;
  2215. if (rot->irq_num >= 0) {
  2216. SDEROT_DBG("Wait for Rotator completion\n");
  2217. rc = wait_for_completion_timeout(&ctx->rot_comp,
  2218. ctx->sbuf_mode ?
  2219. msecs_to_jiffies(KOFF_TIMEOUT_SBUF) :
  2220. msecs_to_jiffies(rot->koff_timeout));
  2221. spin_lock_irqsave(&rot->rotisr_lock, flags);
  2222. status = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS);
  2223. if (rc == 0) {
  2224. /*
  2225. * Timeout, there might be error,
  2226. * or rotator still busy
  2227. */
  2228. if (status & ROT_BUSY_BIT)
  2229. SDEROT_ERR(
  2230. "Timeout waiting for rotator done\n");
  2231. else if (status & ROT_ERROR_BIT)
  2232. SDEROT_ERR(
  2233. "Rotator report error status\n");
  2234. else
  2235. SDEROT_WARN(
  2236. "Timeout waiting, but rotator job is done!!\n");
  2237. sde_hw_rotator_disable_irq(rot);
  2238. }
  2239. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  2240. } else {
  2241. int cnt = 200;
  2242. do {
  2243. udelay(500);
  2244. status = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS);
  2245. cnt--;
  2246. } while ((cnt > 0) && (status & ROT_BUSY_BIT)
  2247. && ((status & ROT_ERROR_BIT) == 0));
  2248. if (status & ROT_ERROR_BIT)
  2249. SDEROT_ERR("Rotator error\n");
  2250. else if (status & ROT_BUSY_BIT)
  2251. SDEROT_ERR("Rotator busy\n");
  2252. SDE_ROTREG_WRITE(rot->mdss_base, ROTTOP_INTR_CLEAR,
  2253. ROT_DONE_CLEAR);
  2254. }
  2255. sts = (status & ROT_ERROR_BIT) ? -ENODEV : 0;
  2256. return sts;
  2257. }
  2258. /*
  2259. * sde_hw_rotator_wait_done_regdma - wait for regdma completion
  2260. * @ctx: Pointer to rotator context
  2261. * @queue_id: Priority queue identifier
  2262. * @flags: Option flag
  2263. */
  2264. static u32 sde_hw_rotator_wait_done_regdma(
  2265. struct sde_hw_rotator_context *ctx,
  2266. enum sde_rot_queue_prio queue_id, u32 flag)
  2267. {
  2268. struct sde_hw_rotator *rot = ctx->rot;
  2269. int rc = 0;
  2270. bool timeout = false;
  2271. bool pending;
  2272. bool abort;
  2273. u32 status;
  2274. u32 last_isr;
  2275. u32 last_ts;
  2276. u32 int_id;
  2277. u32 swts;
  2278. u32 sts = 0;
  2279. u32 ubwcerr;
  2280. u32 hwts[ROT_QUEUE_MAX];
  2281. unsigned long flags;
  2282. if (rot->irq_num >= 0) {
  2283. SDEROT_DBG("Wait for REGDMA completion, ctx:%pK, ts:%X\n",
  2284. ctx, ctx->timestamp);
  2285. rc = wait_event_timeout(ctx->regdma_waitq,
  2286. !rot->ops.get_pending_ts(rot, ctx, &swts),
  2287. ctx->sbuf_mode ?
  2288. msecs_to_jiffies(KOFF_TIMEOUT_SBUF) :
  2289. msecs_to_jiffies(rot->koff_timeout));
  2290. ATRACE_INT("sde_rot_done", 0);
  2291. spin_lock_irqsave(&rot->rotisr_lock, flags);
  2292. last_isr = ctx->last_regdma_isr_status;
  2293. last_ts = ctx->last_regdma_timestamp;
  2294. abort = ctx->abort;
  2295. status = last_isr & REGDMA_INT_MASK;
  2296. int_id = last_ts & 1;
  2297. SDEROT_DBG("INT status:0x%X, INT id:%d, timestamp:0x%X\n",
  2298. status, int_id, last_ts);
  2299. if (rc == 0 || (status & REGDMA_INT_ERR_MASK) || abort) {
  2300. timeout = true;
  2301. pending = rot->ops.get_pending_ts(rot, ctx, &swts);
  2302. /* cache ubwcerr and hw timestamps while locked */
  2303. ubwcerr = SDE_ROTREG_READ(rot->mdss_base,
  2304. ROT_SSPP_UBWC_ERROR_STATUS);
  2305. hwts[ROT_QUEUE_HIGH_PRIORITY] =
  2306. __sde_hw_rotator_get_timestamp(rot,
  2307. ROT_QUEUE_HIGH_PRIORITY);
  2308. hwts[ROT_QUEUE_LOW_PRIORITY] =
  2309. __sde_hw_rotator_get_timestamp(rot,
  2310. ROT_QUEUE_LOW_PRIORITY);
  2311. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  2312. if (ubwcerr || abort ||
  2313. sde_hw_rotator_halt_vbif_xin_client()) {
  2314. /*
  2315. * Perform recovery for ROT SSPP UBWC decode
  2316. * error.
  2317. * - SW reset rotator hw block
  2318. * - reset TS logic so all pending rotation
  2319. * in hw queue got done signalled
  2320. */
  2321. if (!sde_hw_rotator_reset(rot, ctx))
  2322. status = REGDMA_INCOMPLETE_CMD;
  2323. else
  2324. status = ROT_ERROR_BIT;
  2325. } else {
  2326. status = ROT_ERROR_BIT;
  2327. }
  2328. spin_lock_irqsave(&rot->rotisr_lock, flags);
  2329. } else {
  2330. if (rc == 1)
  2331. SDEROT_WARN(
  2332. "REGDMA done but no irq, ts:0x%X/0x%X\n",
  2333. ctx->timestamp, swts);
  2334. status = 0;
  2335. }
  2336. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  2337. /* dump rot status after releasing lock if timeout occurred */
  2338. if (timeout) {
  2339. SDEROT_ERR(
  2340. "TIMEOUT, ts:0x%X/0x%X, pending:%d, abort:%d\n",
  2341. ctx->timestamp, swts, pending, abort);
  2342. SDEROT_ERR(
  2343. "Cached: HW ts0/ts1 = %x/%x, ubwcerr = %x\n",
  2344. hwts[ROT_QUEUE_HIGH_PRIORITY],
  2345. hwts[ROT_QUEUE_LOW_PRIORITY], ubwcerr);
  2346. if (status & REGDMA_WATCHDOG_INT)
  2347. SDEROT_ERR("REGDMA watchdog interrupt\n");
  2348. else if (status & REGDMA_INVALID_DESCRIPTOR)
  2349. SDEROT_ERR("REGDMA invalid descriptor\n");
  2350. else if (status & REGDMA_INCOMPLETE_CMD)
  2351. SDEROT_ERR("REGDMA incomplete command\n");
  2352. else if (status & REGDMA_INVALID_CMD)
  2353. SDEROT_ERR("REGDMA invalid command\n");
  2354. _sde_hw_rotator_dump_status(rot, &ubwcerr);
  2355. }
  2356. } else {
  2357. int cnt = 200;
  2358. bool pending;
  2359. do {
  2360. udelay(500);
  2361. last_isr = SDE_ROTREG_READ(rot->mdss_base,
  2362. REGDMA_CSR_REGDMA_INT_STATUS);
  2363. pending = rot->ops.get_pending_ts(rot, ctx, &swts);
  2364. cnt--;
  2365. } while ((cnt > 0) && pending &&
  2366. ((last_isr & REGDMA_INT_ERR_MASK) == 0));
  2367. if (last_isr & REGDMA_INT_ERR_MASK) {
  2368. SDEROT_ERR("Rotator error, ts:0x%X/0x%X status:%x\n",
  2369. ctx->timestamp, swts, last_isr);
  2370. _sde_hw_rotator_dump_status(rot, NULL);
  2371. status = ROT_ERROR_BIT;
  2372. } else if (pending) {
  2373. SDEROT_ERR("Rotator timeout, ts:0x%X/0x%X status:%x\n",
  2374. ctx->timestamp, swts, last_isr);
  2375. _sde_hw_rotator_dump_status(rot, NULL);
  2376. status = ROT_ERROR_BIT;
  2377. } else {
  2378. status = 0;
  2379. }
  2380. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_CSR_REGDMA_INT_CLEAR,
  2381. last_isr);
  2382. }
  2383. sts = (status & (ROT_ERROR_BIT | REGDMA_INCOMPLETE_CMD)) ? -ENODEV : 0;
  2384. if (status & ROT_ERROR_BIT)
  2385. SDEROT_EVTLOG_TOUT_HANDLER("rot", "rot_dbg_bus",
  2386. "vbif_dbg_bus", "panic");
  2387. return sts;
  2388. }
  2389. /*
  2390. * setup_rotator_ops - setup callback functions for the low-level HAL
  2391. * @ops: Pointer to low-level ops callback
  2392. * @mode: Operation mode (non-regdma or regdma)
  2393. * @use_hwts: HW timestamp support mode
  2394. */
  2395. static void setup_rotator_ops(struct sde_hw_rotator_ops *ops,
  2396. enum sde_rotator_regdma_mode mode,
  2397. bool use_hwts)
  2398. {
  2399. ops->setup_rotator_fetchengine = sde_hw_rotator_setup_fetchengine;
  2400. ops->setup_rotator_wbengine = sde_hw_rotator_setup_wbengine;
  2401. if (mode == ROT_REGDMA_ON) {
  2402. ops->start_rotator = sde_hw_rotator_start_regdma;
  2403. ops->wait_rotator_done = sde_hw_rotator_wait_done_regdma;
  2404. } else {
  2405. ops->start_rotator = sde_hw_rotator_start_no_regdma;
  2406. ops->wait_rotator_done = sde_hw_rotator_wait_done_no_regdma;
  2407. }
  2408. if (use_hwts) {
  2409. ops->get_pending_ts = sde_hw_rotator_pending_hwts;
  2410. ops->update_ts = sde_hw_rotator_update_hwts;
  2411. } else {
  2412. ops->get_pending_ts = sde_hw_rotator_pending_swts;
  2413. ops->update_ts = sde_hw_rotator_update_swts;
  2414. }
  2415. }
  2416. /*
  2417. * sde_hw_rotator_swts_create - create software timestamp buffer
  2418. * @rot: Pointer to rotator hw
  2419. *
  2420. * This buffer is used by regdma to keep track of last completed command.
  2421. */
  2422. static int sde_hw_rotator_swts_create(struct sde_hw_rotator *rot)
  2423. {
  2424. int rc = 0;
  2425. struct sde_mdp_img_data *data;
  2426. u32 bufsize = sizeof(int) * SDE_HW_ROT_REGDMA_TOTAL_CTX * 2;
  2427. if (bufsize < SZ_4K)
  2428. bufsize = SZ_4K;
  2429. data = &rot->swts_buf;
  2430. data->len = bufsize;
  2431. data->srcp_dma_buf = sde_rot_get_dmabuf(data);
  2432. if (!data->srcp_dma_buf) {
  2433. SDEROT_ERR("Fail dmabuf create\n");
  2434. return -ENOMEM;
  2435. }
  2436. sde_smmu_ctrl(1);
  2437. data->srcp_attachment = sde_smmu_dma_buf_attach(data->srcp_dma_buf,
  2438. &rot->pdev->dev, SDE_IOMMU_DOMAIN_ROT_UNSECURE);
  2439. if (IS_ERR_OR_NULL(data->srcp_attachment)) {
  2440. SDEROT_ERR("sde_smmu_dma_buf_attach error\n");
  2441. rc = -ENOMEM;
  2442. goto err_put;
  2443. }
  2444. data->srcp_table = dma_buf_map_attachment(data->srcp_attachment,
  2445. DMA_BIDIRECTIONAL);
  2446. if (IS_ERR_OR_NULL(data->srcp_table)) {
  2447. SDEROT_ERR("dma_buf_map_attachment error\n");
  2448. rc = -ENOMEM;
  2449. goto err_detach;
  2450. }
  2451. rc = sde_smmu_map_dma_buf(data->srcp_dma_buf, data->srcp_table,
  2452. SDE_IOMMU_DOMAIN_ROT_UNSECURE, &data->addr,
  2453. &data->len, DMA_BIDIRECTIONAL);
  2454. if (rc < 0) {
  2455. SDEROT_ERR("smmu_map_dma_buf failed: (%d)\n", rc);
  2456. goto err_unmap;
  2457. }
  2458. data->mapped = true;
  2459. SDEROT_DBG("swts buffer mapped: %pad/%lx va:%pK\n", &data->addr,
  2460. data->len, rot->swts_buffer);
  2461. sde_smmu_ctrl(0);
  2462. return rc;
  2463. err_unmap:
  2464. dma_buf_unmap_attachment(data->srcp_attachment, data->srcp_table,
  2465. DMA_FROM_DEVICE);
  2466. err_detach:
  2467. dma_buf_detach(data->srcp_dma_buf, data->srcp_attachment);
  2468. err_put:
  2469. data->srcp_dma_buf = NULL;
  2470. sde_smmu_ctrl(0);
  2471. return rc;
  2472. }
  2473. /*
  2474. * sde_hw_rotator_swts_destroy - destroy software timestamp buffer
  2475. * @rot: Pointer to rotator hw
  2476. */
  2477. static void sde_hw_rotator_swts_destroy(struct sde_hw_rotator *rot)
  2478. {
  2479. struct sde_mdp_img_data *data;
  2480. data = &rot->swts_buf;
  2481. sde_smmu_unmap_dma_buf(data->srcp_table, SDE_IOMMU_DOMAIN_ROT_UNSECURE,
  2482. DMA_FROM_DEVICE, data->srcp_dma_buf);
  2483. dma_buf_unmap_attachment(data->srcp_attachment, data->srcp_table,
  2484. DMA_FROM_DEVICE);
  2485. dma_buf_detach(data->srcp_dma_buf, data->srcp_attachment);
  2486. dma_buf_put(data->srcp_dma_buf);
  2487. data->addr = 0;
  2488. data->srcp_dma_buf = NULL;
  2489. data->srcp_attachment = NULL;
  2490. data->mapped = false;
  2491. }
  2492. /*
  2493. * sde_hw_rotator_pre_pmevent - SDE rotator core will call this before a
  2494. * PM event occurs
  2495. * @mgr: Pointer to rotator manager
  2496. * @pmon: Boolean indicate an on/off power event
  2497. */
  2498. void sde_hw_rotator_pre_pmevent(struct sde_rot_mgr *mgr, bool pmon)
  2499. {
  2500. struct sde_hw_rotator *rot;
  2501. u32 l_ts, h_ts, l_hwts, h_hwts;
  2502. u32 rotsts, regdmasts, rotopmode;
  2503. /*
  2504. * Check last HW timestamp with SW timestamp before power off event.
  2505. * If there is a mismatch, that will be quite possible the rotator HW
  2506. * is either hang or not finishing last submitted job. In that case,
  2507. * it is best to do a timeout eventlog to capture some good events
  2508. * log data for analysis.
  2509. */
  2510. if (!pmon && mgr && mgr->hw_data) {
  2511. rot = mgr->hw_data;
  2512. h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]) &
  2513. SDE_REGDMA_SWTS_MASK;
  2514. l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]) &
  2515. SDE_REGDMA_SWTS_MASK;
  2516. /* Need to turn on clock to access rotator register */
  2517. sde_rotator_clk_ctrl(mgr, true);
  2518. l_hwts = __sde_hw_rotator_get_timestamp(rot,
  2519. ROT_QUEUE_LOW_PRIORITY);
  2520. h_hwts = __sde_hw_rotator_get_timestamp(rot,
  2521. ROT_QUEUE_HIGH_PRIORITY);
  2522. regdmasts = SDE_ROTREG_READ(rot->mdss_base,
  2523. REGDMA_CSR_REGDMA_BLOCK_STATUS);
  2524. rotsts = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_STATUS);
  2525. rotopmode = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_OP_MODE);
  2526. SDEROT_DBG(
  2527. "swts(l/h):0x%x/0x%x, hwts(l/h):0x%x/0x%x, regdma-sts:0x%x, rottop-sts:0x%x\n",
  2528. l_ts, h_ts, l_hwts, h_hwts,
  2529. regdmasts, rotsts);
  2530. SDEROT_EVTLOG(l_ts, h_ts, l_hwts, h_hwts, regdmasts, rotsts);
  2531. if (((l_ts != l_hwts) || (h_ts != h_hwts)) &&
  2532. ((regdmasts & REGDMA_BUSY) ||
  2533. (rotsts & ROT_STATUS_MASK))) {
  2534. SDEROT_ERR(
  2535. "Mismatch SWTS with HWTS: swts(l/h):0x%x/0x%x, hwts(l/h):0x%x/0x%x, regdma-sts:0x%x, rottop-sts:0x%x\n",
  2536. l_ts, h_ts, l_hwts, h_hwts,
  2537. regdmasts, rotsts);
  2538. _sde_hw_rotator_dump_status(rot, NULL);
  2539. SDEROT_EVTLOG_TOUT_HANDLER("rot", "rot_dbg_bus",
  2540. "vbif_dbg_bus", "panic");
  2541. } else if (!SDE_ROTTOP_IN_OFFLINE_MODE(rotopmode) &&
  2542. ((regdmasts & REGDMA_BUSY) ||
  2543. (rotsts & ROT_BUSY_BIT))) {
  2544. /*
  2545. * rotator can stuck in inline while mdp is detached
  2546. */
  2547. SDEROT_WARN(
  2548. "Inline Rot busy: regdma-sts:0x%x, rottop-sts:0x%x, rottop-opmode:0x%x\n",
  2549. regdmasts, rotsts, rotopmode);
  2550. sde_hw_rotator_reset(rot, NULL);
  2551. } else if ((regdmasts & REGDMA_BUSY) ||
  2552. (rotsts & ROT_BUSY_BIT)) {
  2553. _sde_hw_rotator_dump_status(rot, NULL);
  2554. SDEROT_EVTLOG_TOUT_HANDLER("rot", "rot_dbg_bus",
  2555. "vbif_dbg_bus", "panic");
  2556. sde_hw_rotator_reset(rot, NULL);
  2557. }
  2558. /* Turn off rotator clock after checking rotator registers */
  2559. sde_rotator_clk_ctrl(mgr, false);
  2560. }
  2561. }
  2562. /*
  2563. * sde_hw_rotator_post_pmevent - SDE rotator core will call this after a
  2564. * PM event occurs
  2565. * @mgr: Pointer to rotator manager
  2566. * @pmon: Boolean indicate an on/off power event
  2567. */
  2568. void sde_hw_rotator_post_pmevent(struct sde_rot_mgr *mgr, bool pmon)
  2569. {
  2570. struct sde_hw_rotator *rot;
  2571. u32 l_ts, h_ts;
  2572. /*
  2573. * After a power on event, the rotator HW is reset to default setting.
  2574. * It is necessary to synchronize the SW timestamp with the HW.
  2575. */
  2576. if (pmon && mgr && mgr->hw_data) {
  2577. rot = mgr->hw_data;
  2578. h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]);
  2579. l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]);
  2580. SDEROT_DBG("h_ts:0x%x, l_ts;0x%x\n", h_ts, l_ts);
  2581. SDEROT_EVTLOG(h_ts, l_ts);
  2582. rot->reset_hw_ts = true;
  2583. rot->last_hwts[ROT_QUEUE_LOW_PRIORITY] =
  2584. l_ts & SDE_REGDMA_SWTS_MASK;
  2585. rot->last_hwts[ROT_QUEUE_HIGH_PRIORITY] =
  2586. h_ts & SDE_REGDMA_SWTS_MASK;
  2587. }
  2588. }
  2589. /*
  2590. * sde_hw_rotator_destroy - Destroy hw rotator and free allocated resources
  2591. * @mgr: Pointer to rotator manager
  2592. */
  2593. static void sde_hw_rotator_destroy(struct sde_rot_mgr *mgr)
  2594. {
  2595. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  2596. struct sde_hw_rotator *rot;
  2597. if (!mgr || !mgr->pdev || !mgr->hw_data) {
  2598. SDEROT_ERR("null parameters\n");
  2599. return;
  2600. }
  2601. rot = mgr->hw_data;
  2602. if (rot->irq_num >= 0)
  2603. devm_free_irq(&mgr->pdev->dev, rot->irq_num, mdata);
  2604. if (!test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map) &&
  2605. rot->mode == ROT_REGDMA_ON)
  2606. sde_hw_rotator_swts_destroy(rot);
  2607. devm_kfree(&mgr->pdev->dev, mgr->hw_data);
  2608. mgr->hw_data = NULL;
  2609. }
  2610. /*
  2611. * sde_hw_rotator_alloc_ext - allocate rotator resource from rotator hw
  2612. * @mgr: Pointer to rotator manager
  2613. * @pipe_id: pipe identifier (not used)
  2614. * @wb_id: writeback identifier/priority queue identifier
  2615. *
  2616. * This function allocates a new hw rotator resource for the given priority.
  2617. */
  2618. static struct sde_rot_hw_resource *sde_hw_rotator_alloc_ext(
  2619. struct sde_rot_mgr *mgr, u32 pipe_id, u32 wb_id)
  2620. {
  2621. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  2622. struct sde_hw_rotator_resource_info *resinfo;
  2623. if (!mgr || !mgr->hw_data) {
  2624. SDEROT_ERR("null parameters\n");
  2625. return NULL;
  2626. }
  2627. /*
  2628. * Allocate rotator resource info. Each allocation is per
  2629. * HW priority queue
  2630. */
  2631. resinfo = devm_kzalloc(&mgr->pdev->dev, sizeof(*resinfo), GFP_KERNEL);
  2632. if (!resinfo) {
  2633. SDEROT_ERR("Failed allocation HW rotator resource info\n");
  2634. return NULL;
  2635. }
  2636. resinfo->rot = mgr->hw_data;
  2637. resinfo->hw.wb_id = wb_id;
  2638. atomic_set(&resinfo->hw.num_active, 0);
  2639. init_waitqueue_head(&resinfo->hw.wait_queue);
  2640. /* For non-regdma, only support one active session */
  2641. if (resinfo->rot->mode == ROT_REGDMA_OFF)
  2642. resinfo->hw.max_active = 1;
  2643. else {
  2644. resinfo->hw.max_active = SDE_HW_ROT_REGDMA_TOTAL_CTX - 1;
  2645. if (!test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map) &&
  2646. (!resinfo->rot->swts_buf.mapped))
  2647. sde_hw_rotator_swts_create(resinfo->rot);
  2648. }
  2649. sde_hw_rotator_enable_irq(resinfo->rot);
  2650. SDEROT_DBG("New rotator resource:%pK, priority:%d\n",
  2651. resinfo, wb_id);
  2652. return &resinfo->hw;
  2653. }
  2654. /*
  2655. * sde_hw_rotator_free_ext - free the given rotator resource
  2656. * @mgr: Pointer to rotator manager
  2657. * @hw: Pointer to rotator resource
  2658. */
  2659. static void sde_hw_rotator_free_ext(struct sde_rot_mgr *mgr,
  2660. struct sde_rot_hw_resource *hw)
  2661. {
  2662. struct sde_hw_rotator_resource_info *resinfo;
  2663. if (!mgr || !mgr->hw_data)
  2664. return;
  2665. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  2666. SDEROT_DBG(
  2667. "Free rotator resource:%pK, priority:%d, active:%d, pending:%d\n",
  2668. resinfo, hw->wb_id, atomic_read(&hw->num_active),
  2669. hw->pending_count);
  2670. sde_hw_rotator_disable_irq(resinfo->rot);
  2671. devm_kfree(&mgr->pdev->dev, resinfo);
  2672. }
  2673. /*
  2674. * sde_hw_rotator_alloc_rotctx - allocate rotator context
  2675. * @rot: Pointer to rotator hw
  2676. * @hw: Pointer to rotator resource
  2677. * @session_id: Session identifier of this context
  2678. * @sequence_id: Sequence identifier of this request
  2679. * @sbuf_mode: true if stream buffer is requested
  2680. *
  2681. * This function allocates a new rotator context for the given session id.
  2682. */
  2683. static struct sde_hw_rotator_context *sde_hw_rotator_alloc_rotctx(
  2684. struct sde_hw_rotator *rot,
  2685. struct sde_rot_hw_resource *hw,
  2686. u32 session_id,
  2687. u32 sequence_id,
  2688. bool sbuf_mode)
  2689. {
  2690. struct sde_hw_rotator_context *ctx;
  2691. /* Allocate rotator context */
  2692. ctx = devm_kzalloc(&rot->pdev->dev, sizeof(*ctx), GFP_KERNEL);
  2693. if (!ctx) {
  2694. SDEROT_ERR("Failed allocation HW rotator context\n");
  2695. return NULL;
  2696. }
  2697. ctx->rot = rot;
  2698. ctx->q_id = hw->wb_id;
  2699. ctx->session_id = session_id;
  2700. ctx->sequence_id = sequence_id;
  2701. ctx->hwres = hw;
  2702. ctx->timestamp = atomic_add_return(1, &rot->timestamp[ctx->q_id]);
  2703. ctx->timestamp &= SDE_REGDMA_SWTS_MASK;
  2704. ctx->is_secure = false;
  2705. ctx->sbuf_mode = sbuf_mode;
  2706. INIT_LIST_HEAD(&ctx->list);
  2707. ctx->regdma_base = rot->cmd_wr_ptr[ctx->q_id]
  2708. [sde_hw_rotator_get_regdma_ctxidx(ctx)];
  2709. ctx->regdma_wrptr = ctx->regdma_base;
  2710. ctx->ts_addr = (dma_addr_t)((u32 *)rot->swts_buf.addr +
  2711. ctx->q_id * SDE_HW_ROT_REGDMA_TOTAL_CTX +
  2712. sde_hw_rotator_get_regdma_ctxidx(ctx));
  2713. ctx->last_regdma_timestamp = SDE_REGDMA_SWTS_INVALID;
  2714. init_completion(&ctx->rot_comp);
  2715. init_waitqueue_head(&ctx->regdma_waitq);
  2716. /* Store rotator context for lookup purpose */
  2717. sde_hw_rotator_put_ctx(ctx);
  2718. SDEROT_DBG(
  2719. "New rot CTX:%pK, ctxidx:%d, session-id:%d, prio:%d, timestamp:%X, active:%d sbuf:%d\n",
  2720. ctx, sde_hw_rotator_get_regdma_ctxidx(ctx), ctx->session_id,
  2721. ctx->q_id, ctx->timestamp,
  2722. atomic_read(&ctx->hwres->num_active),
  2723. ctx->sbuf_mode);
  2724. return ctx;
  2725. }
  2726. /*
  2727. * sde_hw_rotator_free_rotctx - free the given rotator context
  2728. * @rot: Pointer to rotator hw
  2729. * @ctx: Pointer to rotator context
  2730. */
  2731. static void sde_hw_rotator_free_rotctx(struct sde_hw_rotator *rot,
  2732. struct sde_hw_rotator_context *ctx)
  2733. {
  2734. if (!rot || !ctx)
  2735. return;
  2736. SDEROT_DBG(
  2737. "Free rot CTX:%pK, ctxidx:%d, session-id:%d, prio:%d, timestamp:%X, active:%d sbuf:%d\n",
  2738. ctx, sde_hw_rotator_get_regdma_ctxidx(ctx), ctx->session_id,
  2739. ctx->q_id, ctx->timestamp,
  2740. atomic_read(&ctx->hwres->num_active),
  2741. ctx->sbuf_mode);
  2742. /* Clear rotator context from lookup purpose */
  2743. sde_hw_rotator_clr_ctx(ctx);
  2744. devm_kfree(&rot->pdev->dev, ctx);
  2745. }
  2746. /*
  2747. * sde_hw_rotator_config - configure hw for the given rotation entry
  2748. * @hw: Pointer to rotator resource
  2749. * @entry: Pointer to rotation entry
  2750. *
  2751. * This function setup the fetch/writeback/rotator blocks, as well as VBIF
  2752. * based on the given rotation entry.
  2753. */
  2754. static int sde_hw_rotator_config(struct sde_rot_hw_resource *hw,
  2755. struct sde_rot_entry *entry)
  2756. {
  2757. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  2758. struct sde_hw_rotator *rot;
  2759. struct sde_hw_rotator_resource_info *resinfo;
  2760. struct sde_hw_rotator_context *ctx;
  2761. struct sde_hw_rot_sspp_cfg sspp_cfg;
  2762. struct sde_hw_rot_wb_cfg wb_cfg;
  2763. u32 danger_lut = 0; /* applicable for realtime client only */
  2764. u32 safe_lut = 0; /* applicable for realtime client only */
  2765. u32 flags = 0;
  2766. u32 rststs = 0;
  2767. struct sde_rotation_item *item;
  2768. int ret;
  2769. if (!hw || !entry) {
  2770. SDEROT_ERR("null hw resource/entry\n");
  2771. return -EINVAL;
  2772. }
  2773. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  2774. rot = resinfo->rot;
  2775. item = &entry->item;
  2776. ctx = sde_hw_rotator_alloc_rotctx(rot, hw, item->session_id,
  2777. item->sequence_id, item->output.sbuf);
  2778. if (!ctx) {
  2779. SDEROT_ERR("Failed allocating rotator context!!\n");
  2780. return -EINVAL;
  2781. }
  2782. /* save entry for debugging purposes */
  2783. ctx->last_entry = entry;
  2784. if (test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) {
  2785. if (entry->dst_buf.sbuf) {
  2786. u32 op_mode;
  2787. if (entry->item.trigger ==
  2788. SDE_ROTATOR_TRIGGER_COMMAND)
  2789. ctx->start_ctrl = (rot->cmd_trigger << 4);
  2790. else if (entry->item.trigger ==
  2791. SDE_ROTATOR_TRIGGER_VIDEO)
  2792. ctx->start_ctrl = (rot->vid_trigger << 4);
  2793. else
  2794. ctx->start_ctrl = 0;
  2795. ctx->sys_cache_mode = BIT(15) |
  2796. ((item->output.scid & 0x1f) << 8) |
  2797. (item->output.writeback ? 0x5 : 0);
  2798. ctx->op_mode = BIT(4) |
  2799. ((ctx->rot->sbuf_headroom & 0xff) << 8);
  2800. /* detect transition to inline mode */
  2801. op_mode = (SDE_ROTREG_READ(rot->mdss_base,
  2802. ROTTOP_OP_MODE) >> 4) & 0x3;
  2803. if (!op_mode) {
  2804. u32 status;
  2805. status = SDE_ROTREG_READ(rot->mdss_base,
  2806. ROTTOP_STATUS);
  2807. if (status & BIT(0)) {
  2808. SDEROT_ERR("rotator busy 0x%x\n",
  2809. status);
  2810. _sde_hw_rotator_dump_status(rot, NULL);
  2811. SDEROT_EVTLOG_TOUT_HANDLER("rot",
  2812. "vbif_dbg_bus",
  2813. "panic");
  2814. }
  2815. }
  2816. } else {
  2817. ctx->start_ctrl = BIT(0);
  2818. ctx->sys_cache_mode = 0;
  2819. ctx->op_mode = 0;
  2820. }
  2821. } else {
  2822. ctx->start_ctrl = BIT(0);
  2823. }
  2824. SDEROT_EVTLOG(ctx->start_ctrl, ctx->sys_cache_mode, ctx->op_mode);
  2825. /*
  2826. * if Rotator HW is reset, but missing PM event notification, we
  2827. * need to init the SW timestamp automatically.
  2828. */
  2829. rststs = SDE_ROTREG_READ(rot->mdss_base, REGDMA_RESET_STATUS_REG);
  2830. if (!rot->reset_hw_ts && rststs) {
  2831. u32 l_ts, h_ts, l_hwts, h_hwts;
  2832. h_hwts = __sde_hw_rotator_get_timestamp(rot,
  2833. ROT_QUEUE_HIGH_PRIORITY);
  2834. l_hwts = __sde_hw_rotator_get_timestamp(rot,
  2835. ROT_QUEUE_LOW_PRIORITY);
  2836. h_ts = atomic_read(&rot->timestamp[ROT_QUEUE_HIGH_PRIORITY]);
  2837. l_ts = atomic_read(&rot->timestamp[ROT_QUEUE_LOW_PRIORITY]);
  2838. SDEROT_EVTLOG(0xbad0, rststs, l_hwts, h_hwts, l_ts, h_ts);
  2839. if (ctx->q_id == ROT_QUEUE_HIGH_PRIORITY) {
  2840. h_ts = (h_ts - 1) & SDE_REGDMA_SWTS_MASK;
  2841. l_ts &= SDE_REGDMA_SWTS_MASK;
  2842. } else {
  2843. l_ts = (l_ts - 1) & SDE_REGDMA_SWTS_MASK;
  2844. h_ts &= SDE_REGDMA_SWTS_MASK;
  2845. }
  2846. SDEROT_DBG("h_ts:0x%x, l_ts;0x%x\n", h_ts, l_ts);
  2847. SDEROT_EVTLOG(0x900d, h_ts, l_ts);
  2848. rot->last_hwts[ROT_QUEUE_LOW_PRIORITY] = l_ts;
  2849. rot->last_hwts[ROT_QUEUE_HIGH_PRIORITY] = h_ts;
  2850. rot->ops.update_ts(rot, ROT_QUEUE_HIGH_PRIORITY, h_ts);
  2851. rot->ops.update_ts(rot, ROT_QUEUE_LOW_PRIORITY, l_ts);
  2852. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_RESET_STATUS_REG, 0);
  2853. /* ensure write is issued to the rotator HW */
  2854. wmb();
  2855. }
  2856. if (rot->reset_hw_ts) {
  2857. SDEROT_EVTLOG(rot->last_hwts[ROT_QUEUE_LOW_PRIORITY],
  2858. rot->last_hwts[ROT_QUEUE_HIGH_PRIORITY]);
  2859. rot->ops.update_ts(rot, ROT_QUEUE_HIGH_PRIORITY,
  2860. rot->last_hwts[ROT_QUEUE_HIGH_PRIORITY]);
  2861. rot->ops.update_ts(rot, ROT_QUEUE_LOW_PRIORITY,
  2862. rot->last_hwts[ROT_QUEUE_LOW_PRIORITY]);
  2863. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_RESET_STATUS_REG, 0);
  2864. /* ensure write is issued to the rotator HW */
  2865. wmb();
  2866. rot->reset_hw_ts = false;
  2867. }
  2868. flags = (item->flags & SDE_ROTATION_FLIP_LR) ?
  2869. SDE_ROT_FLAG_FLIP_LR : 0;
  2870. flags |= (item->flags & SDE_ROTATION_FLIP_UD) ?
  2871. SDE_ROT_FLAG_FLIP_UD : 0;
  2872. flags |= (item->flags & SDE_ROTATION_90) ?
  2873. SDE_ROT_FLAG_ROT_90 : 0;
  2874. flags |= (item->flags & SDE_ROTATION_DEINTERLACE) ?
  2875. SDE_ROT_FLAG_DEINTERLACE : 0;
  2876. flags |= (item->flags & SDE_ROTATION_SECURE) ?
  2877. SDE_ROT_FLAG_SECURE_OVERLAY_SESSION : 0;
  2878. flags |= (item->flags & SDE_ROTATION_SECURE_CAMERA) ?
  2879. SDE_ROT_FLAG_SECURE_CAMERA_SESSION : 0;
  2880. sspp_cfg.img_width = item->input.width;
  2881. sspp_cfg.img_height = item->input.height;
  2882. sspp_cfg.fps = entry->perf->config.frame_rate;
  2883. sspp_cfg.bw = entry->perf->bw;
  2884. sspp_cfg.fmt = sde_get_format_params(item->input.format);
  2885. if (!sspp_cfg.fmt) {
  2886. SDEROT_ERR("null format\n");
  2887. ret = -EINVAL;
  2888. goto error;
  2889. }
  2890. sspp_cfg.src_rect = &item->src_rect;
  2891. sspp_cfg.data = &entry->src_buf;
  2892. sde_mdp_get_plane_sizes(sspp_cfg.fmt, item->input.width,
  2893. item->input.height, &sspp_cfg.src_plane,
  2894. 0, /* No bwc_mode */
  2895. (flags & SDE_ROT_FLAG_SOURCE_ROTATED_90) ?
  2896. true : false);
  2897. rot->ops.setup_rotator_fetchengine(ctx, ctx->q_id,
  2898. &sspp_cfg, danger_lut, safe_lut,
  2899. entry->dnsc_factor_w, entry->dnsc_factor_h, flags);
  2900. wb_cfg.img_width = item->output.width;
  2901. wb_cfg.img_height = item->output.height;
  2902. wb_cfg.fps = entry->perf->config.frame_rate;
  2903. wb_cfg.bw = entry->perf->bw;
  2904. wb_cfg.fmt = sde_get_format_params(item->output.format);
  2905. if (!wb_cfg.fmt) {
  2906. SDEROT_ERR("null format\n");
  2907. ret = -EINVAL;
  2908. goto error;
  2909. }
  2910. wb_cfg.dst_rect = &item->dst_rect;
  2911. wb_cfg.data = &entry->dst_buf;
  2912. sde_mdp_get_plane_sizes(wb_cfg.fmt, item->output.width,
  2913. item->output.height, &wb_cfg.dst_plane,
  2914. 0, /* No bwc_mode */
  2915. (flags & SDE_ROT_FLAG_ROT_90) ? true : false);
  2916. wb_cfg.v_downscale_factor = entry->dnsc_factor_h;
  2917. wb_cfg.h_downscale_factor = entry->dnsc_factor_w;
  2918. wb_cfg.prefill_bw = item->prefill_bw;
  2919. rot->ops.setup_rotator_wbengine(ctx, ctx->q_id, &wb_cfg, flags);
  2920. /* setup VA mapping for debugfs */
  2921. if (rot->dbgmem) {
  2922. sde_hw_rotator_map_vaddr(&ctx->src_dbgbuf,
  2923. &item->input,
  2924. &entry->src_buf);
  2925. sde_hw_rotator_map_vaddr(&ctx->dst_dbgbuf,
  2926. &item->output,
  2927. &entry->dst_buf);
  2928. }
  2929. SDEROT_EVTLOG(ctx->timestamp, flags,
  2930. item->input.width, item->input.height,
  2931. item->output.width, item->output.height,
  2932. entry->src_buf.p[0].addr, entry->dst_buf.p[0].addr,
  2933. item->input.format, item->output.format,
  2934. entry->perf->config.frame_rate);
  2935. /* initialize static vbif setting */
  2936. sde_mdp_init_vbif();
  2937. if (!ctx->sbuf_mode && mdata->default_ot_rd_limit) {
  2938. struct sde_mdp_set_ot_params ot_params;
  2939. memset(&ot_params, 0, sizeof(struct sde_mdp_set_ot_params));
  2940. ot_params.xin_id = mdata->vbif_xin_id[XIN_SSPP];
  2941. ot_params.num = 0; /* not used */
  2942. ot_params.width = entry->perf->config.input.width;
  2943. ot_params.height = entry->perf->config.input.height;
  2944. ot_params.fps = entry->perf->config.frame_rate;
  2945. ot_params.reg_off_vbif_lim_conf = MMSS_VBIF_RD_LIM_CONF;
  2946. ot_params.reg_off_mdp_clk_ctrl =
  2947. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0;
  2948. ot_params.bit_off_mdp_clk_ctrl =
  2949. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN0;
  2950. ot_params.fmt = ctx->is_traffic_shaping ?
  2951. SDE_PIX_FMT_ABGR_8888 :
  2952. entry->perf->config.input.format;
  2953. ot_params.rotsts_base = rot->mdss_base + ROTTOP_STATUS;
  2954. ot_params.rotsts_busy_mask = ROT_BUSY_BIT;
  2955. sde_mdp_set_ot_limit(&ot_params);
  2956. }
  2957. if (!ctx->sbuf_mode && mdata->default_ot_wr_limit) {
  2958. struct sde_mdp_set_ot_params ot_params;
  2959. memset(&ot_params, 0, sizeof(struct sde_mdp_set_ot_params));
  2960. ot_params.xin_id = mdata->vbif_xin_id[XIN_WRITEBACK];
  2961. ot_params.num = 0; /* not used */
  2962. ot_params.width = entry->perf->config.input.width;
  2963. ot_params.height = entry->perf->config.input.height;
  2964. ot_params.fps = entry->perf->config.frame_rate;
  2965. ot_params.reg_off_vbif_lim_conf = MMSS_VBIF_WR_LIM_CONF;
  2966. ot_params.reg_off_mdp_clk_ctrl =
  2967. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0;
  2968. ot_params.bit_off_mdp_clk_ctrl =
  2969. MMSS_VBIF_NRT_VBIF_CLK_FORCE_CTRL0_XIN1;
  2970. ot_params.fmt = ctx->is_traffic_shaping ?
  2971. SDE_PIX_FMT_ABGR_8888 :
  2972. entry->perf->config.input.format;
  2973. ot_params.rotsts_base = rot->mdss_base + ROTTOP_STATUS;
  2974. ot_params.rotsts_busy_mask = ROT_BUSY_BIT;
  2975. sde_mdp_set_ot_limit(&ot_params);
  2976. }
  2977. if (test_bit(SDE_QOS_PER_PIPE_LUT, mdata->sde_qos_map)) {
  2978. u32 qos_lut = 0; /* low priority for nrt read client */
  2979. trace_rot_perf_set_qos_luts(mdata->vbif_xin_id[XIN_SSPP],
  2980. sspp_cfg.fmt->format, qos_lut,
  2981. sde_mdp_is_linear_format(sspp_cfg.fmt));
  2982. SDE_ROTREG_WRITE(rot->mdss_base, ROT_SSPP_CREQ_LUT, qos_lut);
  2983. }
  2984. /* VBIF QoS and other settings */
  2985. if (!ctx->sbuf_mode) {
  2986. if (mdata->parent_pdev)
  2987. sde_hw_rotator_vbif_rt_setting();
  2988. else
  2989. sde_hw_rotator_vbif_setting(rot);
  2990. }
  2991. return 0;
  2992. error:
  2993. sde_hw_rotator_free_rotctx(rot, ctx);
  2994. return ret;
  2995. }
  2996. /*
  2997. * sde_hw_rotator_cancel - cancel hw configuration for the given rotation entry
  2998. * @hw: Pointer to rotator resource
  2999. * @entry: Pointer to rotation entry
  3000. *
  3001. * This function cancels a previously configured rotation entry.
  3002. */
  3003. static int sde_hw_rotator_cancel(struct sde_rot_hw_resource *hw,
  3004. struct sde_rot_entry *entry)
  3005. {
  3006. struct sde_hw_rotator *rot;
  3007. struct sde_hw_rotator_resource_info *resinfo;
  3008. struct sde_hw_rotator_context *ctx;
  3009. unsigned long flags;
  3010. if (!hw || !entry) {
  3011. SDEROT_ERR("null hw resource/entry\n");
  3012. return -EINVAL;
  3013. }
  3014. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  3015. rot = resinfo->rot;
  3016. /* Lookup rotator context from session-id */
  3017. ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id,
  3018. entry->item.sequence_id, hw->wb_id);
  3019. if (!ctx) {
  3020. SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n",
  3021. entry->item.session_id);
  3022. return -EINVAL;
  3023. }
  3024. spin_lock_irqsave(&rot->rotisr_lock, flags);
  3025. rot->ops.update_ts(rot, ctx->q_id, ctx->timestamp);
  3026. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  3027. SDEROT_EVTLOG(entry->item.session_id, ctx->timestamp);
  3028. if (rot->dbgmem) {
  3029. sde_hw_rotator_unmap_vaddr(&ctx->src_dbgbuf);
  3030. sde_hw_rotator_unmap_vaddr(&ctx->dst_dbgbuf);
  3031. }
  3032. /* Current rotator context job is finished, time to free up */
  3033. sde_hw_rotator_free_rotctx(rot, ctx);
  3034. return 0;
  3035. }
  3036. /*
  3037. * sde_hw_rotator_kickoff - kickoff processing on the given entry
  3038. * @hw: Pointer to rotator resource
  3039. * @entry: Pointer to rotation entry
  3040. */
  3041. static int sde_hw_rotator_kickoff(struct sde_rot_hw_resource *hw,
  3042. struct sde_rot_entry *entry)
  3043. {
  3044. struct sde_hw_rotator *rot;
  3045. struct sde_hw_rotator_resource_info *resinfo;
  3046. struct sde_hw_rotator_context *ctx;
  3047. if (!hw || !entry) {
  3048. SDEROT_ERR("null hw resource/entry\n");
  3049. return -EINVAL;
  3050. }
  3051. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  3052. rot = resinfo->rot;
  3053. /* Lookup rotator context from session-id */
  3054. ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id,
  3055. entry->item.sequence_id, hw->wb_id);
  3056. if (!ctx) {
  3057. SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n",
  3058. entry->item.session_id);
  3059. return -EINVAL;
  3060. }
  3061. rot->ops.start_rotator(ctx, ctx->q_id);
  3062. return 0;
  3063. }
  3064. static int sde_hw_rotator_abort_kickoff(struct sde_rot_hw_resource *hw,
  3065. struct sde_rot_entry *entry)
  3066. {
  3067. struct sde_hw_rotator *rot;
  3068. struct sde_hw_rotator_resource_info *resinfo;
  3069. struct sde_hw_rotator_context *ctx;
  3070. unsigned long flags;
  3071. if (!hw || !entry) {
  3072. SDEROT_ERR("null hw resource/entry\n");
  3073. return -EINVAL;
  3074. }
  3075. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  3076. rot = resinfo->rot;
  3077. /* Lookup rotator context from session-id */
  3078. ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id,
  3079. entry->item.sequence_id, hw->wb_id);
  3080. if (!ctx) {
  3081. SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n",
  3082. entry->item.session_id);
  3083. return -EINVAL;
  3084. }
  3085. spin_lock_irqsave(&rot->rotisr_lock, flags);
  3086. rot->ops.update_ts(rot, ctx->q_id, ctx->timestamp);
  3087. ctx->abort = true;
  3088. wake_up_all(&ctx->regdma_waitq);
  3089. spin_unlock_irqrestore(&rot->rotisr_lock, flags);
  3090. SDEROT_EVTLOG(entry->item.session_id, ctx->timestamp);
  3091. return 0;
  3092. }
  3093. /*
  3094. * sde_hw_rotator_wait4done - wait for completion notification
  3095. * @hw: Pointer to rotator resource
  3096. * @entry: Pointer to rotation entry
  3097. *
  3098. * This function blocks until the given entry is complete, error
  3099. * is detected, or timeout.
  3100. */
  3101. static int sde_hw_rotator_wait4done(struct sde_rot_hw_resource *hw,
  3102. struct sde_rot_entry *entry)
  3103. {
  3104. struct sde_hw_rotator *rot;
  3105. struct sde_hw_rotator_resource_info *resinfo;
  3106. struct sde_hw_rotator_context *ctx;
  3107. int ret;
  3108. if (!hw || !entry) {
  3109. SDEROT_ERR("null hw resource/entry\n");
  3110. return -EINVAL;
  3111. }
  3112. resinfo = container_of(hw, struct sde_hw_rotator_resource_info, hw);
  3113. rot = resinfo->rot;
  3114. /* Lookup rotator context from session-id */
  3115. ctx = sde_hw_rotator_get_ctx(rot, entry->item.session_id,
  3116. entry->item.sequence_id, hw->wb_id);
  3117. if (!ctx) {
  3118. SDEROT_ERR("Cannot locate rotator ctx from sesison id:%d\n",
  3119. entry->item.session_id);
  3120. return -EINVAL;
  3121. }
  3122. ret = rot->ops.wait_rotator_done(ctx, ctx->q_id, 0);
  3123. if (rot->dbgmem) {
  3124. sde_hw_rotator_unmap_vaddr(&ctx->src_dbgbuf);
  3125. sde_hw_rotator_unmap_vaddr(&ctx->dst_dbgbuf);
  3126. }
  3127. /* Current rotator context job is finished, time to free up*/
  3128. sde_hw_rotator_free_rotctx(rot, ctx);
  3129. return ret;
  3130. }
  3131. /*
  3132. * sde_rotator_hw_rev_init - setup feature and/or capability bitmask
  3133. * @rot: Pointer to hw rotator
  3134. *
  3135. * This function initializes feature and/or capability bitmask based on
  3136. * h/w version read from the device.
  3137. */
  3138. static int sde_rotator_hw_rev_init(struct sde_hw_rotator *rot)
  3139. {
  3140. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  3141. u32 hw_version;
  3142. if (!mdata) {
  3143. SDEROT_ERR("null rotator data\n");
  3144. return -EINVAL;
  3145. }
  3146. hw_version = SDE_ROTREG_READ(rot->mdss_base, ROTTOP_HW_VERSION);
  3147. SDEROT_DBG("hw version %8.8x\n", hw_version);
  3148. clear_bit(SDE_QOS_PER_PIPE_IB, mdata->sde_qos_map);
  3149. set_bit(SDE_QOS_OVERHEAD_FACTOR, mdata->sde_qos_map);
  3150. set_bit(SDE_QOS_OTLIM, mdata->sde_qos_map);
  3151. set_bit(SDE_QOS_PER_PIPE_LUT, mdata->sde_qos_map);
  3152. clear_bit(SDE_QOS_SIMPLIFIED_PREFILL, mdata->sde_qos_map);
  3153. set_bit(SDE_CAPS_R3_WB, mdata->sde_caps_map);
  3154. /* features exposed via rotator top h/w version */
  3155. if (hw_version != SDE_ROT_TYPE_V1_0) {
  3156. SDEROT_DBG("Supporting 1.5 downscale for SDE Rotator\n");
  3157. set_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map);
  3158. }
  3159. set_bit(SDE_CAPS_SEC_ATTACH_DETACH_SMMU, mdata->sde_caps_map);
  3160. mdata->nrt_vbif_dbg_bus = nrt_vbif_dbg_bus_r3;
  3161. mdata->nrt_vbif_dbg_bus_size =
  3162. ARRAY_SIZE(nrt_vbif_dbg_bus_r3);
  3163. mdata->rot_dbg_bus = rot_dbgbus_r3;
  3164. mdata->rot_dbg_bus_size = ARRAY_SIZE(rot_dbgbus_r3);
  3165. mdata->regdump = sde_rot_r3_regdump;
  3166. mdata->regdump_size = ARRAY_SIZE(sde_rot_r3_regdump);
  3167. SDE_ROTREG_WRITE(rot->mdss_base, REGDMA_TIMESTAMP_REG, 0);
  3168. /* features exposed via mdss h/w version */
  3169. if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version, SDE_MDP_HW_REV_600)) {
  3170. SDEROT_DBG("Supporting sys cache inline rotation\n");
  3171. set_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map);
  3172. set_bit(SDE_CAPS_UBWC_4, mdata->sde_caps_map);
  3173. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3174. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3175. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3176. sde_hw_rotator_v4_inpixfmts;
  3177. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3178. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3179. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3180. sde_hw_rotator_v4_outpixfmts;
  3181. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3182. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3183. rot->inpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3184. sde_hw_rotator_v4_inpixfmts_sbuf;
  3185. rot->num_inpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3186. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts_sbuf);
  3187. rot->outpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3188. sde_hw_rotator_v4_outpixfmts_sbuf;
  3189. rot->num_outpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3190. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts_sbuf);
  3191. rot->downscale_caps =
  3192. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3193. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3194. SDE_MDP_HW_REV_500)) {
  3195. SDEROT_DBG("Supporting sys cache inline rotation\n");
  3196. set_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map);
  3197. set_bit(SDE_CAPS_UBWC_3, mdata->sde_caps_map);
  3198. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3199. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3200. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3201. sde_hw_rotator_v4_inpixfmts;
  3202. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3203. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3204. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3205. sde_hw_rotator_v4_outpixfmts;
  3206. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3207. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3208. rot->inpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3209. sde_hw_rotator_v4_inpixfmts_sbuf;
  3210. rot->num_inpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3211. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts_sbuf);
  3212. rot->outpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3213. sde_hw_rotator_v4_outpixfmts_sbuf;
  3214. rot->num_outpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3215. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts_sbuf);
  3216. rot->downscale_caps =
  3217. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3218. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3219. SDE_MDP_HW_REV_530) ||
  3220. IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3221. SDE_MDP_HW_REV_520)) {
  3222. SDEROT_DBG("Supporting sys cache inline rotation\n");
  3223. set_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map);
  3224. set_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map);
  3225. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3226. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3227. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3228. sde_hw_rotator_v4_inpixfmts;
  3229. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3230. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3231. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3232. sde_hw_rotator_v4_outpixfmts;
  3233. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3234. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3235. rot->inpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3236. sde_hw_rotator_v4_inpixfmts_sbuf;
  3237. rot->num_inpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3238. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts_sbuf);
  3239. rot->outpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3240. sde_hw_rotator_v4_outpixfmts_sbuf;
  3241. rot->num_outpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3242. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts_sbuf);
  3243. rot->downscale_caps =
  3244. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3245. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3246. SDE_MDP_HW_REV_540)) {
  3247. SDEROT_DBG("Sys cache inline rotation not supported\n");
  3248. set_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map);
  3249. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3250. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3251. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3252. sde_hw_rotator_v4_inpixfmts;
  3253. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3254. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3255. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3256. sde_hw_rotator_v4_outpixfmts;
  3257. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3258. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3259. rot->downscale_caps =
  3260. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3261. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3262. SDE_MDP_HW_REV_400) ||
  3263. IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3264. SDE_MDP_HW_REV_410)) {
  3265. SDEROT_DBG("Supporting sys cache inline rotation\n");
  3266. set_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map);
  3267. set_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map);
  3268. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3269. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3270. sde_hw_rotator_v4_inpixfmts;
  3271. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3272. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3273. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3274. sde_hw_rotator_v4_outpixfmts;
  3275. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3276. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3277. rot->inpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3278. sde_hw_rotator_v4_inpixfmts_sbuf;
  3279. rot->num_inpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3280. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts_sbuf);
  3281. rot->outpixfmts[SDE_ROTATOR_MODE_SBUF] =
  3282. sde_hw_rotator_v4_outpixfmts_sbuf;
  3283. rot->num_outpixfmt[SDE_ROTATOR_MODE_SBUF] =
  3284. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts_sbuf);
  3285. rot->downscale_caps =
  3286. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3287. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3288. SDE_MDP_HW_REV_630)) {
  3289. SDEROT_DBG("Sys cache inline rotation not supported\n");
  3290. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3291. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3292. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3293. sde_hw_rotator_v4_inpixfmts;
  3294. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3295. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3296. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3297. sde_hw_rotator_v4_outpixfmts;
  3298. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3299. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3300. rot->downscale_caps =
  3301. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3302. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3303. SDE_MDP_HW_REV_660)) {
  3304. SDEROT_DBG("Sys cache inline rotation not supported\n");
  3305. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3306. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3307. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3308. sde_hw_rotator_v4_inpixfmts;
  3309. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3310. ARRAY_SIZE(sde_hw_rotator_v4_inpixfmts);
  3311. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3312. sde_hw_rotator_v4_outpixfmts;
  3313. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3314. ARRAY_SIZE(sde_hw_rotator_v4_outpixfmts);
  3315. rot->downscale_caps =
  3316. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3317. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3318. SDE_MDP_HW_REV_690)) {
  3319. SDEROT_DBG("Sys cache inline rotation not supported\n");
  3320. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3321. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3322. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3323. sde_hw_rotator_v5_inpixfmts;
  3324. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3325. ARRAY_SIZE(sde_hw_rotator_v5_inpixfmts);
  3326. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3327. sde_hw_rotator_v5_outpixfmts;
  3328. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3329. ARRAY_SIZE(sde_hw_rotator_v5_outpixfmts);
  3330. rot->downscale_caps =
  3331. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3332. } else if (IS_SDE_MAJOR_MINOR_SAME(mdata->mdss_version,
  3333. SDE_MDP_HW_REV_870)) {
  3334. SDEROT_DBG("Sys cache inline rotation not supported\n");
  3335. set_bit(SDE_CAPS_UBWC_2, mdata->sde_caps_map);
  3336. set_bit(SDE_CAPS_PARTIALWR, mdata->sde_caps_map);
  3337. set_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map);
  3338. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3339. sde_hw_rotator_v6_inpixfmts;
  3340. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3341. ARRAY_SIZE(sde_hw_rotator_v6_inpixfmts);
  3342. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3343. sde_hw_rotator_v5_outpixfmts;
  3344. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3345. ARRAY_SIZE(sde_hw_rotator_v5_outpixfmts);
  3346. rot->downscale_caps =
  3347. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3348. } else {
  3349. rot->inpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3350. sde_hw_rotator_v3_inpixfmts;
  3351. rot->num_inpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3352. ARRAY_SIZE(sde_hw_rotator_v3_inpixfmts);
  3353. rot->outpixfmts[SDE_ROTATOR_MODE_OFFLINE] =
  3354. sde_hw_rotator_v3_outpixfmts;
  3355. rot->num_outpixfmt[SDE_ROTATOR_MODE_OFFLINE] =
  3356. ARRAY_SIZE(sde_hw_rotator_v3_outpixfmts);
  3357. rot->downscale_caps = (hw_version == SDE_ROT_TYPE_V1_0) ?
  3358. "LINEAR/2/4/8/16/32/64 TILE/2/4 TP10/2" :
  3359. "LINEAR/1.5/2/4/8/16/32/64 TILE/1.5/2/4 TP10/1.5/2";
  3360. }
  3361. return 0;
  3362. }
  3363. /*
  3364. * sde_hw_rotator_validate_entry - validate rotation entry
  3365. * @mgr: Pointer to rotator manager
  3366. * @entry: Pointer to rotation entry
  3367. *
  3368. * This function validates the given rotation entry and provides possible
  3369. * fixup (future improvement) if available. This function returns 0 if
  3370. * the entry is valid, and returns error code otherwise.
  3371. */
  3372. static int sde_hw_rotator_validate_entry(struct sde_rot_mgr *mgr,
  3373. struct sde_rot_entry *entry)
  3374. {
  3375. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  3376. struct sde_hw_rotator *hw_data;
  3377. int ret = 0;
  3378. u16 src_w, src_h, dst_w, dst_h;
  3379. struct sde_rotation_item *item = &entry->item;
  3380. struct sde_mdp_format_params *fmt;
  3381. if (!mgr || !entry || !mgr->hw_data) {
  3382. SDEROT_ERR("invalid parameters\n");
  3383. return -EINVAL;
  3384. }
  3385. hw_data = mgr->hw_data;
  3386. if (hw_data->maxlinewidth < item->src_rect.w) {
  3387. SDEROT_ERR("invalid src width %u\n", item->src_rect.w);
  3388. return -EINVAL;
  3389. }
  3390. src_w = item->src_rect.w;
  3391. src_h = item->src_rect.h;
  3392. if (item->flags & SDE_ROTATION_90) {
  3393. dst_w = item->dst_rect.h;
  3394. dst_h = item->dst_rect.w;
  3395. } else {
  3396. dst_w = item->dst_rect.w;
  3397. dst_h = item->dst_rect.h;
  3398. }
  3399. entry->dnsc_factor_w = 0;
  3400. entry->dnsc_factor_h = 0;
  3401. if (item->output.sbuf &&
  3402. !test_bit(SDE_CAPS_SBUF_1, mdata->sde_caps_map)) {
  3403. SDEROT_ERR("stream buffer not supported\n");
  3404. return -EINVAL;
  3405. }
  3406. if ((src_w != dst_w) || (src_h != dst_h)) {
  3407. if (!dst_w || !dst_h) {
  3408. SDEROT_DBG("zero output width/height not support\n");
  3409. ret = -EINVAL;
  3410. goto dnsc_err;
  3411. }
  3412. if ((src_w % dst_w) || (src_h % dst_h)) {
  3413. SDEROT_DBG("non integral scale not support\n");
  3414. ret = -EINVAL;
  3415. goto dnsc_1p5_check;
  3416. }
  3417. entry->dnsc_factor_w = src_w / dst_w;
  3418. if ((entry->dnsc_factor_w & (entry->dnsc_factor_w - 1)) ||
  3419. (entry->dnsc_factor_w > 64)) {
  3420. SDEROT_DBG("non power-of-2 w_scale not support\n");
  3421. ret = -EINVAL;
  3422. goto dnsc_err;
  3423. }
  3424. entry->dnsc_factor_h = src_h / dst_h;
  3425. if ((entry->dnsc_factor_h & (entry->dnsc_factor_h - 1)) ||
  3426. (entry->dnsc_factor_h > 64)) {
  3427. SDEROT_DBG("non power-of-2 h_scale not support\n");
  3428. ret = -EINVAL;
  3429. goto dnsc_err;
  3430. }
  3431. }
  3432. fmt = sde_get_format_params(item->output.format);
  3433. /*
  3434. * Rotator downscale support max 4 times for UBWC format and
  3435. * max 2 times for TP10/TP10_UBWC format
  3436. */
  3437. if (sde_mdp_is_ubwc_format(fmt) && (entry->dnsc_factor_h > 4)) {
  3438. SDEROT_DBG("max downscale for UBWC format is 4\n");
  3439. ret = -EINVAL;
  3440. goto dnsc_err;
  3441. }
  3442. if (sde_mdp_is_tp10_format(fmt) && (entry->dnsc_factor_h > 2)) {
  3443. SDEROT_DBG("downscale with TP10 cannot be more than 2\n");
  3444. ret = -EINVAL;
  3445. }
  3446. goto dnsc_err;
  3447. dnsc_1p5_check:
  3448. /* Check for 1.5 downscale that only applies to V2 HW */
  3449. if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map)) {
  3450. entry->dnsc_factor_w = src_w / dst_w;
  3451. if ((entry->dnsc_factor_w != 1) ||
  3452. ((dst_w * 3) != (src_w * 2))) {
  3453. SDEROT_DBG(
  3454. "No supporting non 1.5 downscale width ratio, src_w:%d, dst_w:%d\n",
  3455. src_w, dst_w);
  3456. ret = -EINVAL;
  3457. goto dnsc_err;
  3458. }
  3459. entry->dnsc_factor_h = src_h / dst_h;
  3460. if ((entry->dnsc_factor_h != 1) ||
  3461. ((dst_h * 3) != (src_h * 2))) {
  3462. SDEROT_DBG(
  3463. "Not supporting non 1.5 downscale height ratio, src_h:%d, dst_h:%d\n",
  3464. src_h, dst_h);
  3465. ret = -EINVAL;
  3466. goto dnsc_err;
  3467. }
  3468. ret = 0;
  3469. }
  3470. dnsc_err:
  3471. /* Downscaler does not support asymmetrical dnsc */
  3472. if (entry->dnsc_factor_w != entry->dnsc_factor_h) {
  3473. SDEROT_DBG("asymmetric downscale not support\n");
  3474. ret = -EINVAL;
  3475. }
  3476. if (ret) {
  3477. entry->dnsc_factor_w = 0;
  3478. entry->dnsc_factor_h = 0;
  3479. }
  3480. return ret;
  3481. }
  3482. /*
  3483. * sde_hw_rotator_show_caps - output capability info to sysfs 'caps' file
  3484. * @mgr: Pointer to rotator manager
  3485. * @attr: Pointer to device attribute interface
  3486. * @buf: Pointer to output buffer
  3487. * @len: Length of output buffer
  3488. */
  3489. static ssize_t sde_hw_rotator_show_caps(struct sde_rot_mgr *mgr,
  3490. struct device_attribute *attr, char *buf, ssize_t len)
  3491. {
  3492. struct sde_hw_rotator *hw_data;
  3493. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  3494. int cnt = 0;
  3495. if (!mgr || !buf)
  3496. return 0;
  3497. hw_data = mgr->hw_data;
  3498. #define SPRINT(fmt, ...) \
  3499. (cnt += scnprintf(buf + cnt, len - cnt, fmt, ##__VA_ARGS__))
  3500. /* insert capabilities here */
  3501. if (test_bit(SDE_CAPS_R3_1P5_DOWNSCALE, mdata->sde_caps_map))
  3502. SPRINT("min_downscale=1.5\n");
  3503. else
  3504. SPRINT("min_downscale=2.0\n");
  3505. SPRINT("downscale_compression=1\n");
  3506. if (hw_data->downscale_caps)
  3507. SPRINT("downscale_ratios=%s\n", hw_data->downscale_caps);
  3508. SPRINT("max_line_width=%d\n", sde_rotator_get_maxlinewidth(mgr));
  3509. #undef SPRINT
  3510. return cnt;
  3511. }
  3512. /*
  3513. * sde_hw_rotator_show_state - output state info to sysfs 'state' file
  3514. * @mgr: Pointer to rotator manager
  3515. * @attr: Pointer to device attribute interface
  3516. * @buf: Pointer to output buffer
  3517. * @len: Length of output buffer
  3518. */
  3519. static ssize_t sde_hw_rotator_show_state(struct sde_rot_mgr *mgr,
  3520. struct device_attribute *attr, char *buf, ssize_t len)
  3521. {
  3522. struct sde_hw_rotator *rot;
  3523. struct sde_hw_rotator_context *ctx;
  3524. int cnt = 0;
  3525. int num_active = 0;
  3526. int i, j;
  3527. if (!mgr || !buf) {
  3528. SDEROT_ERR("null parameters\n");
  3529. return 0;
  3530. }
  3531. rot = mgr->hw_data;
  3532. #define SPRINT(fmt, ...) \
  3533. (cnt += scnprintf(buf + cnt, len - cnt, fmt, ##__VA_ARGS__))
  3534. if (rot) {
  3535. SPRINT("rot_mode=%d\n", rot->mode);
  3536. SPRINT("irq_num=%d\n", rot->irq_num);
  3537. if (rot->mode == ROT_REGDMA_OFF) {
  3538. SPRINT("max_active=1\n");
  3539. SPRINT("num_active=%d\n", rot->rotCtx[0][0] ? 1 : 0);
  3540. } else {
  3541. for (i = 0; i < ROT_QUEUE_MAX; i++) {
  3542. for (j = 0; j < SDE_HW_ROT_REGDMA_TOTAL_CTX;
  3543. j++) {
  3544. ctx = rot->rotCtx[i][j];
  3545. if (ctx) {
  3546. SPRINT(
  3547. "rotCtx[%d][%d]:%pK\n",
  3548. i, j, ctx);
  3549. ++num_active;
  3550. }
  3551. }
  3552. }
  3553. SPRINT("max_active=%d\n", SDE_HW_ROT_REGDMA_TOTAL_CTX);
  3554. SPRINT("num_active=%d\n", num_active);
  3555. }
  3556. }
  3557. #undef SPRINT
  3558. return cnt;
  3559. }
  3560. /*
  3561. * sde_hw_rotator_get_pixfmt - get the indexed pixel format
  3562. * @mgr: Pointer to rotator manager
  3563. * @index: index of pixel format
  3564. * @input: true for input port; false for output port
  3565. * @mode: operating mode
  3566. */
  3567. static u32 sde_hw_rotator_get_pixfmt(struct sde_rot_mgr *mgr,
  3568. int index, bool input, u32 mode)
  3569. {
  3570. struct sde_hw_rotator *rot;
  3571. if (!mgr || !mgr->hw_data) {
  3572. SDEROT_ERR("null parameters\n");
  3573. return 0;
  3574. }
  3575. rot = mgr->hw_data;
  3576. if (mode >= SDE_ROTATOR_MODE_MAX) {
  3577. SDEROT_ERR("invalid rotator mode %d\n", mode);
  3578. return 0;
  3579. }
  3580. if (input) {
  3581. if ((index < rot->num_inpixfmt[mode]) && rot->inpixfmts[mode])
  3582. return rot->inpixfmts[mode][index];
  3583. else
  3584. return 0;
  3585. } else {
  3586. if ((index < rot->num_outpixfmt[mode]) && rot->outpixfmts[mode])
  3587. return rot->outpixfmts[mode][index];
  3588. else
  3589. return 0;
  3590. }
  3591. }
  3592. /*
  3593. * sde_hw_rotator_is_valid_pixfmt - verify if the given pixel format is valid
  3594. * @mgr: Pointer to rotator manager
  3595. * @pixfmt: pixel format to be verified
  3596. * @input: true for input port; false for output port
  3597. * @mode: operating mode
  3598. */
  3599. static int sde_hw_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr, u32 pixfmt,
  3600. bool input, u32 mode)
  3601. {
  3602. struct sde_hw_rotator *rot;
  3603. const u32 *pixfmts;
  3604. u32 num_pixfmt;
  3605. int i;
  3606. if (!mgr || !mgr->hw_data) {
  3607. SDEROT_ERR("null parameters\n");
  3608. return false;
  3609. }
  3610. rot = mgr->hw_data;
  3611. if (mode >= SDE_ROTATOR_MODE_MAX) {
  3612. SDEROT_ERR("invalid rotator mode %d\n", mode);
  3613. return false;
  3614. }
  3615. if (input) {
  3616. pixfmts = rot->inpixfmts[mode];
  3617. num_pixfmt = rot->num_inpixfmt[mode];
  3618. } else {
  3619. pixfmts = rot->outpixfmts[mode];
  3620. num_pixfmt = rot->num_outpixfmt[mode];
  3621. }
  3622. if (!pixfmts || !num_pixfmt) {
  3623. SDEROT_ERR("invalid pixel format tables\n");
  3624. return false;
  3625. }
  3626. for (i = 0; i < num_pixfmt; i++)
  3627. if (pixfmts[i] == pixfmt)
  3628. return true;
  3629. return false;
  3630. }
  3631. /*
  3632. * sde_hw_rotator_get_downscale_caps - get scaling capability string
  3633. * @mgr: Pointer to rotator manager
  3634. * @caps: Pointer to capability string buffer; NULL to return maximum length
  3635. * @len: length of capability string buffer
  3636. * return: length of capability string
  3637. */
  3638. static int sde_hw_rotator_get_downscale_caps(struct sde_rot_mgr *mgr,
  3639. char *caps, int len)
  3640. {
  3641. struct sde_hw_rotator *rot;
  3642. int rc = 0;
  3643. if (!mgr || !mgr->hw_data) {
  3644. SDEROT_ERR("null parameters\n");
  3645. return -EINVAL;
  3646. }
  3647. rot = mgr->hw_data;
  3648. if (rot->downscale_caps) {
  3649. if (caps)
  3650. rc = snprintf(caps, len, "%s", rot->downscale_caps);
  3651. else
  3652. rc = strlen(rot->downscale_caps);
  3653. }
  3654. return rc;
  3655. }
  3656. /*
  3657. * sde_hw_rotator_get_maxlinewidth - get maximum line width supported
  3658. * @mgr: Pointer to rotator manager
  3659. * return: maximum line width supported by hardware
  3660. */
  3661. static int sde_hw_rotator_get_maxlinewidth(struct sde_rot_mgr *mgr)
  3662. {
  3663. struct sde_hw_rotator *rot;
  3664. if (!mgr || !mgr->hw_data) {
  3665. SDEROT_ERR("null parameters\n");
  3666. return -EINVAL;
  3667. }
  3668. rot = mgr->hw_data;
  3669. return rot->maxlinewidth;
  3670. }
  3671. /*
  3672. * sde_hw_rotator_dump_status - dump status to debug output
  3673. * @mgr: Pointer to rotator manager
  3674. * return: none
  3675. */
  3676. static void sde_hw_rotator_dump_status(struct sde_rot_mgr *mgr)
  3677. {
  3678. if (!mgr || !mgr->hw_data) {
  3679. SDEROT_ERR("null parameters\n");
  3680. return;
  3681. }
  3682. _sde_hw_rotator_dump_status(mgr->hw_data, NULL);
  3683. }
  3684. /*
  3685. * sde_hw_rotator_parse_dt - parse r3 specific device tree settings
  3686. * @hw_data: Pointer to rotator hw
  3687. * @dev: Pointer to platform device
  3688. */
  3689. static int sde_hw_rotator_parse_dt(struct sde_hw_rotator *hw_data,
  3690. struct platform_device *dev)
  3691. {
  3692. int ret = 0;
  3693. u32 data;
  3694. if (!hw_data || !dev)
  3695. return -EINVAL;
  3696. ret = of_property_read_u32(dev->dev.of_node, "qcom,mdss-rot-mode",
  3697. &data);
  3698. if (ret) {
  3699. SDEROT_DBG("default to regdma off\n");
  3700. ret = 0;
  3701. hw_data->mode = ROT_REGDMA_OFF;
  3702. } else if (data < ROT_REGDMA_MAX) {
  3703. SDEROT_DBG("set to regdma mode %d\n", data);
  3704. hw_data->mode = data;
  3705. } else {
  3706. SDEROT_ERR("regdma mode out of range. default to regdma off\n");
  3707. hw_data->mode = ROT_REGDMA_OFF;
  3708. }
  3709. ret = of_property_read_u32(dev->dev.of_node,
  3710. "qcom,mdss-highest-bank-bit", &data);
  3711. if (ret) {
  3712. SDEROT_DBG("default to A5X bank\n");
  3713. ret = 0;
  3714. hw_data->highest_bank = 2;
  3715. } else {
  3716. SDEROT_DBG("set highest bank bit to %d\n", data);
  3717. hw_data->highest_bank = data;
  3718. }
  3719. ret = of_property_read_u32(dev->dev.of_node,
  3720. "qcom,sde-ubwc-malsize", &data);
  3721. if (ret) {
  3722. ret = 0;
  3723. hw_data->ubwc_malsize = DEFAULT_UBWC_MALSIZE;
  3724. } else {
  3725. SDEROT_DBG("set ubwc malsize to %d\n", data);
  3726. hw_data->ubwc_malsize = data;
  3727. }
  3728. ret = of_property_read_u32(dev->dev.of_node,
  3729. "qcom,sde-ubwc_swizzle", &data);
  3730. if (ret) {
  3731. ret = 0;
  3732. hw_data->ubwc_swizzle = DEFAULT_UBWC_SWIZZLE;
  3733. } else {
  3734. SDEROT_DBG("set ubwc swizzle to %d\n", data);
  3735. hw_data->ubwc_swizzle = data;
  3736. }
  3737. ret = of_property_read_u32(dev->dev.of_node,
  3738. "qcom,mdss-sbuf-headroom", &data);
  3739. if (ret) {
  3740. ret = 0;
  3741. hw_data->sbuf_headroom = DEFAULT_SBUF_HEADROOM;
  3742. } else {
  3743. SDEROT_DBG("set sbuf headroom to %d\n", data);
  3744. hw_data->sbuf_headroom = data;
  3745. }
  3746. ret = of_property_read_u32(dev->dev.of_node,
  3747. "qcom,mdss-rot-linewidth", &data);
  3748. if (ret) {
  3749. ret = 0;
  3750. hw_data->maxlinewidth = DEFAULT_MAXLINEWIDTH;
  3751. } else {
  3752. SDEROT_DBG("set mdss-rot-linewidth to %d\n", data);
  3753. hw_data->maxlinewidth = data;
  3754. }
  3755. return ret;
  3756. }
  3757. /*
  3758. * sde_rotator_r3_init - initialize the r3 module
  3759. * @mgr: Pointer to rotator manager
  3760. *
  3761. * This function setup r3 callback functions, parses r3 specific
  3762. * device tree settings, installs r3 specific interrupt handler,
  3763. * as well as initializes r3 internal data structure.
  3764. */
  3765. int sde_rotator_r3_init(struct sde_rot_mgr *mgr)
  3766. {
  3767. struct sde_hw_rotator *rot;
  3768. struct sde_rot_data_type *mdata = sde_rot_get_mdata();
  3769. int i;
  3770. int ret;
  3771. rot = devm_kzalloc(&mgr->pdev->dev, sizeof(*rot), GFP_KERNEL);
  3772. if (!rot)
  3773. return -ENOMEM;
  3774. mgr->hw_data = rot;
  3775. mgr->queue_count = ROT_QUEUE_MAX;
  3776. rot->mdss_base = mdata->sde_io.base;
  3777. rot->pdev = mgr->pdev;
  3778. rot->koff_timeout = KOFF_TIMEOUT;
  3779. rot->vid_trigger = ROTTOP_START_CTRL_TRIG_SEL_MDP;
  3780. rot->cmd_trigger = ROTTOP_START_CTRL_TRIG_SEL_MDP;
  3781. /* Assign ops */
  3782. mgr->ops_hw_destroy = sde_hw_rotator_destroy;
  3783. mgr->ops_hw_alloc = sde_hw_rotator_alloc_ext;
  3784. mgr->ops_hw_free = sde_hw_rotator_free_ext;
  3785. mgr->ops_config_hw = sde_hw_rotator_config;
  3786. mgr->ops_cancel_hw = sde_hw_rotator_cancel;
  3787. mgr->ops_abort_hw = sde_hw_rotator_abort_kickoff;
  3788. mgr->ops_kickoff_entry = sde_hw_rotator_kickoff;
  3789. mgr->ops_wait_for_entry = sde_hw_rotator_wait4done;
  3790. mgr->ops_hw_validate_entry = sde_hw_rotator_validate_entry;
  3791. mgr->ops_hw_show_caps = sde_hw_rotator_show_caps;
  3792. mgr->ops_hw_show_state = sde_hw_rotator_show_state;
  3793. mgr->ops_hw_create_debugfs = sde_rotator_r3_create_debugfs;
  3794. mgr->ops_hw_get_pixfmt = sde_hw_rotator_get_pixfmt;
  3795. mgr->ops_hw_is_valid_pixfmt = sde_hw_rotator_is_valid_pixfmt;
  3796. mgr->ops_hw_pre_pmevent = sde_hw_rotator_pre_pmevent;
  3797. mgr->ops_hw_post_pmevent = sde_hw_rotator_post_pmevent;
  3798. mgr->ops_hw_get_downscale_caps = sde_hw_rotator_get_downscale_caps;
  3799. mgr->ops_hw_get_maxlinewidth = sde_hw_rotator_get_maxlinewidth;
  3800. mgr->ops_hw_dump_status = sde_hw_rotator_dump_status;
  3801. ret = sde_hw_rotator_parse_dt(mgr->hw_data, mgr->pdev);
  3802. if (ret)
  3803. goto error_parse_dt;
  3804. rot->irq_num = -EINVAL;
  3805. atomic_set(&rot->irq_enabled, 0);
  3806. ret = sde_rotator_hw_rev_init(rot);
  3807. if (ret)
  3808. goto error_hw_rev_init;
  3809. setup_rotator_ops(&rot->ops, rot->mode,
  3810. test_bit(SDE_CAPS_HW_TIMESTAMP, mdata->sde_caps_map));
  3811. spin_lock_init(&rot->rotctx_lock);
  3812. spin_lock_init(&rot->rotisr_lock);
  3813. /* REGDMA initialization */
  3814. if (rot->mode == ROT_REGDMA_OFF) {
  3815. for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++)
  3816. rot->cmd_wr_ptr[0][i] = (char __iomem *)(
  3817. &rot->cmd_queue[
  3818. SDE_HW_ROT_REGDMA_SEG_SIZE * i]);
  3819. } else {
  3820. for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++)
  3821. rot->cmd_wr_ptr[ROT_QUEUE_HIGH_PRIORITY][i] =
  3822. rot->mdss_base +
  3823. REGDMA_RAM_REGDMA_CMD_RAM +
  3824. SDE_HW_ROT_REGDMA_SEG_SIZE * 4 * i;
  3825. for (i = 0; i < SDE_HW_ROT_REGDMA_TOTAL_CTX; i++)
  3826. rot->cmd_wr_ptr[ROT_QUEUE_LOW_PRIORITY][i] =
  3827. rot->mdss_base +
  3828. REGDMA_RAM_REGDMA_CMD_RAM +
  3829. SDE_HW_ROT_REGDMA_SEG_SIZE * 4 *
  3830. (i + SDE_HW_ROT_REGDMA_TOTAL_CTX);
  3831. }
  3832. for (i = 0; i < ROT_QUEUE_MAX; i++) {
  3833. atomic_set(&rot->timestamp[i], 0);
  3834. INIT_LIST_HEAD(&rot->sbuf_ctx[i]);
  3835. }
  3836. mdata->sde_rot_hw = rot;
  3837. return 0;
  3838. error_hw_rev_init:
  3839. devm_kfree(&mgr->pdev->dev, mgr->hw_data);
  3840. error_parse_dt:
  3841. return ret;
  3842. }
  3843. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
  3844. MODULE_IMPORT_NS(DMA_BUF);
  3845. #endif