sde_plane.c 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998
  1. /*
  2. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  3. * Copyright (C) 2014-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (C) 2013 Red Hat
  5. * Author: Rob Clark <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
  20. #include <linux/debugfs.h>
  21. #include <linux/dma-buf.h>
  22. #include <drm/sde_drm.h>
  23. #include <drm/msm_drm_pp.h>
  24. #include <linux/version.h>
  25. #include "msm_prop.h"
  26. #include "msm_drv.h"
  27. #include "sde_kms.h"
  28. #include "sde_fence.h"
  29. #include "sde_formats.h"
  30. #include "sde_hw_sspp.h"
  31. #include "sde_hw_catalog_format.h"
  32. #include "sde_trace.h"
  33. #include "sde_crtc.h"
  34. #include "sde_vbif.h"
  35. #include "sde_plane.h"
  36. #include "sde_color_processing.h"
  37. #define SDE_DEBUG_PLANE(pl, fmt, ...) SDE_DEBUG("plane%d " fmt,\
  38. (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
  39. #define SDE_ERROR_PLANE(pl, fmt, ...) SDE_ERROR("plane%d " fmt,\
  40. (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
  41. #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci))
  42. #define PHASE_STEP_SHIFT 21
  43. #define PHASE_STEP_UNIT_SCALE ((int) (1 << PHASE_STEP_SHIFT))
  44. #define PHASE_RESIDUAL 15
  45. #define SHARP_STRENGTH_DEFAULT 32
  46. #define SHARP_EDGE_THR_DEFAULT 112
  47. #define SHARP_SMOOTH_THR_DEFAULT 8
  48. #define SHARP_NOISE_THR_DEFAULT 2
  49. #define SDE_NAME_SIZE 12
  50. #define SDE_PLANE_COLOR_FILL_FLAG BIT(31)
  51. #define TIME_MULTIPLEX_RECT(r0, r1, buffer_lines) \
  52. ((r0).y >= ((r1).y + (r1).h + buffer_lines))
  53. #define SDE_QSEED_DEFAULT_DYN_EXP 0x0
  54. /**
  55. * enum sde_plane_qos - Different qos configurations for each pipe
  56. *
  57. * @SDE_PLANE_QOS_VBLANK_CTRL: Setup VBLANK qos for the pipe.
  58. * @SDE_PLANE_QOS_VBLANK_AMORTIZE: Enables Amortization within pipe.
  59. * this configuration is mutually exclusive from VBLANK_CTRL.
  60. * @SDE_PLANE_QOS_PANIC_CTRL: Setup panic for the pipe.
  61. */
  62. enum sde_plane_qos {
  63. SDE_PLANE_QOS_VBLANK_CTRL = BIT(0),
  64. SDE_PLANE_QOS_VBLANK_AMORTIZE = BIT(1),
  65. SDE_PLANE_QOS_PANIC_CTRL = BIT(2),
  66. };
  67. static int plane_prop_array[PLANE_PROP_COUNT] = {SDE_PLANE_DIRTY_ALL};
  68. static struct sde_kms *_sde_plane_get_kms(struct drm_plane *plane)
  69. {
  70. struct msm_drm_private *priv;
  71. if (!plane || !plane->dev)
  72. return NULL;
  73. priv = plane->dev->dev_private;
  74. if (!priv)
  75. return NULL;
  76. return to_sde_kms(priv->kms);
  77. }
  78. static struct sde_hw_ctl *_sde_plane_get_hw_ctl(const struct drm_plane *plane)
  79. {
  80. struct drm_plane_state *pstate = NULL;
  81. struct drm_crtc *drm_crtc = NULL;
  82. struct sde_crtc *sde_crtc = NULL;
  83. struct sde_crtc_mixer *mixer = NULL;
  84. struct sde_hw_ctl *ctl = NULL;
  85. if (!plane) {
  86. DRM_ERROR("Invalid plane %pK\n", plane);
  87. return NULL;
  88. }
  89. pstate = plane->state;
  90. if (!pstate) {
  91. DRM_ERROR("Invalid plane state %pK\n", pstate);
  92. return NULL;
  93. }
  94. drm_crtc = pstate->crtc;
  95. if (!drm_crtc) {
  96. DRM_ERROR("Invalid drm_crtc %pK\n", drm_crtc);
  97. return NULL;
  98. }
  99. sde_crtc = to_sde_crtc(drm_crtc);
  100. if (!sde_crtc) {
  101. DRM_ERROR("invalid sde_crtc %pK\n", sde_crtc);
  102. return NULL;
  103. }
  104. /* it will always return the first mixer and single CTL */
  105. mixer = sde_crtc->mixers;
  106. if (!mixer) {
  107. DRM_ERROR("invalid mixer %pK\n", mixer);
  108. return NULL;
  109. }
  110. ctl = mixer->hw_ctl;
  111. if (!mixer) {
  112. DRM_ERROR("invalid ctl %pK\n", ctl);
  113. return NULL;
  114. }
  115. return ctl;
  116. }
  117. static void _sde_plane_setup_panel_stacking(struct sde_plane *psde,
  118. struct sde_plane_state *pstate)
  119. {
  120. struct sde_hw_pipe_line_insertion_cfg *cfg;
  121. struct sde_crtc_state *cstate;
  122. u32 h_start = 0, h_total = 0, y_start = 0;
  123. struct drm_plane_state *dpstate = NULL;
  124. struct drm_crtc *drm_crtc = NULL;
  125. if (!psde || !psde->base.state || !psde->base.state->crtc) {
  126. SDE_ERROR("Invalid plane psde %p or drm plane state or drm crtc\n", psde);
  127. return;
  128. }
  129. dpstate = psde->base.state;
  130. drm_crtc = dpstate->crtc;
  131. cstate = to_sde_crtc_state(drm_crtc->state);
  132. pstate->lineinsertion_feature = cstate->line_insertion.panel_line_insertion_enable;
  133. if ((!test_bit(SDE_SSPP_LINE_INSERTION, (unsigned long *)&psde->features)) ||
  134. !cstate->line_insertion.panel_line_insertion_enable)
  135. return;
  136. cfg = &pstate->line_insertion_cfg;
  137. memset(cfg, 0, sizeof(*cfg));
  138. if (!cstate->line_insertion.padding_height)
  139. return;
  140. sde_crtc_calc_vpadding_param(psde->base.state->crtc->state,
  141. pstate->base.crtc_y, pstate->base.crtc_h,
  142. &y_start, &h_start, &h_total);
  143. cfg->enable = true;
  144. cfg->dummy_lines = cstate->line_insertion.padding_dummy;
  145. cfg->active_lines = cstate->line_insertion.padding_active;
  146. cfg->first_active_lines = h_start;
  147. cfg->dst_h = h_total;
  148. psde->pipe_cfg.dst_rect.y += y_start - pstate->base.crtc_y;
  149. }
  150. static bool sde_plane_enabled(const struct drm_plane_state *state)
  151. {
  152. return state && state->fb && state->crtc;
  153. }
  154. bool sde_plane_is_sec_ui_allowed(struct drm_plane *plane)
  155. {
  156. struct sde_plane *psde;
  157. if (!plane)
  158. return false;
  159. psde = to_sde_plane(plane);
  160. return !(psde->features & BIT(SDE_SSPP_BLOCK_SEC_UI));
  161. }
  162. void sde_plane_setup_src_split_order(struct drm_plane *plane,
  163. enum sde_sspp_multirect_index rect_mode, bool enable)
  164. {
  165. struct sde_plane *psde;
  166. if (!plane)
  167. return;
  168. psde = to_sde_plane(plane);
  169. if (psde->pipe_hw->ops.set_src_split_order)
  170. psde->pipe_hw->ops.set_src_split_order(psde->pipe_hw,
  171. rect_mode, enable);
  172. }
  173. void sde_plane_set_sid(struct drm_plane *plane, u32 vm)
  174. {
  175. struct sde_plane *psde;
  176. struct sde_kms *sde_kms;
  177. struct msm_drm_private *priv;
  178. if (!plane || !plane->dev) {
  179. SDE_ERROR("invalid plane\n");
  180. return;
  181. }
  182. priv = plane->dev->dev_private;
  183. if (!priv || !priv->kms) {
  184. SDE_ERROR("invalid KMS reference\n");
  185. return;
  186. }
  187. sde_kms = to_sde_kms(priv->kms);
  188. psde = to_sde_plane(plane);
  189. sde_hw_set_sspp_sid(sde_kms->hw_sid, psde->pipe, vm, sde_kms->catalog);
  190. }
  191. static void _sde_plane_set_qos_lut(struct drm_plane *plane,
  192. struct drm_crtc *crtc,
  193. struct drm_framebuffer *fb)
  194. {
  195. struct sde_plane *psde;
  196. const struct sde_format *fmt = NULL;
  197. u32 frame_rate, qos_count, fps_index = 0, lut_index, creq_lut_index, ds_lut_index;
  198. struct sde_perf_cfg *perf;
  199. struct sde_plane_state *pstate;
  200. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  201. bool inline_rot = false, landscape = false;
  202. struct drm_display_mode *mode;
  203. u32 fl_require0 = 0;
  204. if (!plane || !fb) {
  205. SDE_ERROR("invalid arguments\n");
  206. return;
  207. }
  208. psde = to_sde_plane(plane);
  209. pstate = to_sde_plane_state(plane->state);
  210. if (!psde->pipe_hw || !psde->pipe_sblk || !psde->catalog) {
  211. SDE_ERROR("invalid arguments\n");
  212. return;
  213. } else if (!psde->pipe_hw->ops.setup_qos_lut) {
  214. return;
  215. }
  216. mode = &crtc->state->adjusted_mode;
  217. landscape = mode->hdisplay > mode->vdisplay ? true : false;
  218. frame_rate = drm_mode_vrefresh(&crtc->mode);
  219. perf = &psde->catalog->perf;
  220. qos_count = perf->qos_refresh_count;
  221. while ((fps_index < qos_count) && perf->qos_refresh_rate) {
  222. if ((frame_rate <= perf->qos_refresh_rate[fps_index]) ||
  223. (fps_index == qos_count - 1))
  224. break;
  225. fps_index++;
  226. }
  227. if (psde->is_rt_pipe) {
  228. fmt = sde_get_sde_format_ext(fb->format->format, fb->modifier);
  229. inline_rot = (pstate->rotation & DRM_MODE_ROTATE_90);
  230. if (inline_rot && SDE_IS_IN_ROT_RESTRICTED_FMT(psde->catalog, fmt))
  231. lut_index = SDE_QOS_LUT_USAGE_INLINE_RESTRICTED_FMTS;
  232. else if (inline_rot)
  233. lut_index = SDE_QOS_LUT_USAGE_INLINE;
  234. else if (fmt && SDE_FORMAT_IS_LINEAR(fmt))
  235. lut_index = SDE_QOS_LUT_USAGE_LINEAR;
  236. else
  237. lut_index = SDE_QOS_LUT_USAGE_MACROTILE;
  238. } else {
  239. lut_index = (psde->wb_usage_type == WB_USAGE_OFFLINE_WB) ?
  240. SDE_QOS_LUT_USAGE_OFFLINE_WB : SDE_QOS_LUT_USAGE_NRT;
  241. }
  242. creq_lut_index = lut_index * SDE_CREQ_LUT_TYPE_MAX;
  243. if (psde->scaler3_cfg.enable)
  244. creq_lut_index += SDE_CREQ_LUT_TYPE_QSEED;
  245. creq_lut_index += (fps_index * SDE_QOS_LUT_USAGE_MAX * SDE_CREQ_LUT_TYPE_MAX);
  246. psde->pipe_qos_cfg.creq_lut = perf->creq_lut[creq_lut_index];
  247. ds_lut_index = lut_index * SDE_DANGER_SAFE_LUT_TYPE_MAX;
  248. if (landscape) {
  249. if (psde->catalog->qos_target_time_ns && sde_crtc->line_time_in_ns)
  250. fl_require0 = psde->catalog->qos_target_time_ns /
  251. (sde_crtc->line_time_in_ns * 2);
  252. if (!fl_require0 || fl_require0 < 4.5)
  253. ds_lut_index += SDE_DANGER_SAFE_LUT_TYPE_LANDSCAPE;
  254. }
  255. ds_lut_index += (fps_index * SDE_QOS_LUT_USAGE_MAX * SDE_DANGER_SAFE_LUT_TYPE_MAX);
  256. psde->pipe_qos_cfg.danger_lut = perf->danger_lut[ds_lut_index];
  257. psde->pipe_qos_cfg.safe_lut = perf->safe_lut[ds_lut_index];
  258. trace_sde_perf_set_qos_luts(psde->pipe - SSPP_VIG0, (fmt) ? fmt->base.pixel_format : 0,
  259. (fmt) ? fmt->fetch_mode : 0, psde->pipe_qos_cfg.danger_lut,
  260. psde->pipe_qos_cfg.safe_lut, psde->pipe_qos_cfg.creq_lut);
  261. SDE_DEBUG("plane%u: pnum:%d fmt:%4.4s fps:%d mode:%d lut[0x%x,0x%x 0x%llx] rt:%d type:%d\n",
  262. plane->base.id, psde->pipe - SSPP_VIG0,
  263. fmt ? (char *)&fmt->base.pixel_format : NULL, frame_rate,
  264. fmt ? fmt->fetch_mode : -1, psde->pipe_qos_cfg.danger_lut,
  265. psde->pipe_qos_cfg.safe_lut, psde->pipe_qos_cfg.creq_lut,
  266. psde->is_rt_pipe, psde->wb_usage_type);
  267. psde->pipe_hw->ops.setup_qos_lut(psde->pipe_hw, &psde->pipe_qos_cfg);
  268. }
  269. /**
  270. * _sde_plane_set_qos_ctrl - set QoS control of the given plane
  271. * @plane: Pointer to drm plane
  272. * @enable: true to enable QoS control
  273. * @flags: QoS control mode (enum sde_plane_qos)
  274. */
  275. static void _sde_plane_set_qos_ctrl(struct drm_plane *plane,
  276. bool enable, u32 flags)
  277. {
  278. struct sde_plane *psde;
  279. if (!plane) {
  280. SDE_ERROR("invalid arguments\n");
  281. return;
  282. }
  283. psde = to_sde_plane(plane);
  284. if (!psde->pipe_hw || !psde->pipe_sblk) {
  285. SDE_ERROR("invalid arguments\n");
  286. return;
  287. } else if (!psde->pipe_hw->ops.setup_qos_ctrl) {
  288. return;
  289. }
  290. if (flags & SDE_PLANE_QOS_VBLANK_CTRL) {
  291. psde->pipe_qos_cfg.creq_vblank = psde->pipe_sblk->creq_vblank;
  292. psde->pipe_qos_cfg.danger_vblank =
  293. psde->pipe_sblk->danger_vblank;
  294. psde->pipe_qos_cfg.vblank_en = enable;
  295. }
  296. if (flags & SDE_PLANE_QOS_VBLANK_AMORTIZE) {
  297. /* this feature overrules previous VBLANK_CTRL */
  298. psde->pipe_qos_cfg.vblank_en = false;
  299. psde->pipe_qos_cfg.creq_vblank = 0; /* clear vblank bits */
  300. psde->pipe_qos_cfg.danger_vblank = 0;
  301. }
  302. if (flags & SDE_PLANE_QOS_PANIC_CTRL)
  303. psde->pipe_qos_cfg.danger_safe_en = enable;
  304. if (!psde->is_rt_pipe) {
  305. psde->pipe_qos_cfg.vblank_en = false;
  306. psde->pipe_qos_cfg.danger_safe_en = false;
  307. }
  308. SDE_DEBUG("plane%u: pnum:%d ds:%d vb:%d pri[0x%x, 0x%x] is_rt:%d\n",
  309. plane->base.id,
  310. psde->pipe - SSPP_VIG0,
  311. psde->pipe_qos_cfg.danger_safe_en,
  312. psde->pipe_qos_cfg.vblank_en,
  313. psde->pipe_qos_cfg.creq_vblank,
  314. psde->pipe_qos_cfg.danger_vblank,
  315. psde->is_rt_pipe);
  316. psde->pipe_hw->ops.setup_qos_ctrl(psde->pipe_hw,
  317. &psde->pipe_qos_cfg);
  318. }
  319. void sde_plane_set_revalidate(struct drm_plane *plane, bool enable)
  320. {
  321. struct sde_plane *psde;
  322. if (!plane)
  323. return;
  324. psde = to_sde_plane(plane);
  325. psde->revalidate = enable;
  326. }
  327. int sde_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable)
  328. {
  329. struct sde_plane *psde;
  330. int rc;
  331. if (!plane) {
  332. SDE_ERROR("invalid arguments\n");
  333. return -EINVAL;
  334. }
  335. psde = to_sde_plane(plane);
  336. if (!psde->is_rt_pipe)
  337. goto end;
  338. rc = pm_runtime_resume_and_get(plane->dev->dev);
  339. if (rc < 0) {
  340. SDE_ERROR("failed to enable power resource %d\n", rc);
  341. SDE_EVT32(rc, SDE_EVTLOG_ERROR);
  342. return rc;
  343. }
  344. _sde_plane_set_qos_ctrl(plane, enable, SDE_PLANE_QOS_PANIC_CTRL);
  345. pm_runtime_put_sync(plane->dev->dev);
  346. end:
  347. return 0;
  348. }
  349. /**
  350. * _sde_plane_set_ot_limit - set OT limit for the given plane
  351. * @plane: Pointer to drm plane
  352. * @crtc: Pointer to drm crtc
  353. */
  354. static void _sde_plane_set_ot_limit(struct drm_plane *plane,
  355. struct drm_crtc *crtc)
  356. {
  357. struct sde_plane *psde;
  358. struct sde_vbif_set_ot_params ot_params;
  359. struct msm_drm_private *priv;
  360. struct sde_kms *sde_kms;
  361. if (!plane || !plane->dev || !crtc) {
  362. SDE_ERROR("invalid arguments plane %d crtc %d\n",
  363. !plane, !crtc);
  364. return;
  365. }
  366. priv = plane->dev->dev_private;
  367. if (!priv || !priv->kms) {
  368. SDE_ERROR("invalid KMS reference\n");
  369. return;
  370. }
  371. sde_kms = to_sde_kms(priv->kms);
  372. psde = to_sde_plane(plane);
  373. if (!psde->pipe_hw) {
  374. SDE_ERROR("invalid pipe reference\n");
  375. return;
  376. }
  377. memset(&ot_params, 0, sizeof(ot_params));
  378. ot_params.xin_id = psde->pipe_hw->cap->xin_id;
  379. ot_params.num = psde->pipe_hw->idx - SSPP_NONE;
  380. ot_params.width = psde->pipe_cfg.src_rect.w;
  381. ot_params.height = psde->pipe_cfg.src_rect.h;
  382. ot_params.is_wfd = ((psde->is_rt_pipe)
  383. || (psde->wb_usage_type == WB_USAGE_OFFLINE_WB)) ? false : true;
  384. ot_params.frame_rate = drm_mode_vrefresh(&crtc->mode);
  385. ot_params.vbif_idx = VBIF_RT;
  386. ot_params.clk_ctrl = psde->pipe_hw->cap->clk_ctrl;
  387. ot_params.rd = true;
  388. sde_vbif_set_ot_limit(sde_kms, &ot_params);
  389. }
  390. /**
  391. * _sde_plane_set_vbif_qos - set vbif QoS for the given plane
  392. * @plane: Pointer to drm plane
  393. */
  394. static void _sde_plane_set_qos_remap(struct drm_plane *plane)
  395. {
  396. struct sde_plane *psde;
  397. struct sde_vbif_set_qos_params qos_params;
  398. struct msm_drm_private *priv;
  399. struct sde_kms *sde_kms;
  400. if (!plane || !plane->dev) {
  401. SDE_ERROR("invalid arguments\n");
  402. return;
  403. }
  404. priv = plane->dev->dev_private;
  405. if (!priv || !priv->kms) {
  406. SDE_ERROR("invalid KMS reference\n");
  407. return;
  408. }
  409. sde_kms = to_sde_kms(priv->kms);
  410. psde = to_sde_plane(plane);
  411. if (!psde->pipe_hw) {
  412. SDE_ERROR("invalid pipe reference\n");
  413. return;
  414. }
  415. memset(&qos_params, 0, sizeof(qos_params));
  416. qos_params.vbif_idx = VBIF_RT;
  417. qos_params.clk_ctrl = psde->pipe_hw->cap->clk_ctrl;
  418. qos_params.xin_id = psde->pipe_hw->cap->xin_id;
  419. qos_params.num = psde->pipe_hw->idx - SSPP_VIG0;
  420. if (psde->is_rt_pipe)
  421. qos_params.client_type = VBIF_RT_CLIENT;
  422. else
  423. qos_params.client_type = (psde->wb_usage_type == WB_USAGE_OFFLINE_WB) ?
  424. VBIF_OFFLINE_WB_CLIENT : VBIF_NRT_CLIENT;
  425. SDE_DEBUG("plane%d pipe:%d vbif:%d xin:%d rt:%d, clk_ctrl:%d\n",
  426. plane->base.id, qos_params.num,
  427. qos_params.vbif_idx,
  428. qos_params.xin_id, qos_params.client_type,
  429. qos_params.clk_ctrl);
  430. sde_vbif_set_qos_remap(sde_kms, &qos_params);
  431. }
  432. /**
  433. * _sde_plane_set_ts_prefill - set prefill with traffic shaper
  434. * @plane: Pointer to drm plane
  435. * @pstate: Pointer to sde plane state
  436. */
  437. static void _sde_plane_set_ts_prefill(struct drm_plane *plane,
  438. struct sde_plane_state *pstate)
  439. {
  440. struct sde_plane *psde;
  441. struct sde_hw_pipe_ts_cfg cfg;
  442. struct msm_drm_private *priv;
  443. struct sde_kms *sde_kms;
  444. if (!plane || !plane->dev) {
  445. SDE_ERROR("invalid arguments");
  446. return;
  447. }
  448. priv = plane->dev->dev_private;
  449. if (!priv || !priv->kms) {
  450. SDE_ERROR("invalid KMS reference\n");
  451. return;
  452. }
  453. sde_kms = to_sde_kms(priv->kms);
  454. psde = to_sde_plane(plane);
  455. if (!psde->pipe_hw) {
  456. SDE_ERROR("invalid pipe reference\n");
  457. return;
  458. }
  459. if (!psde->pipe_hw || !psde->pipe_hw->ops.setup_ts_prefill)
  460. return;
  461. _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_VBLANK_AMORTIZE);
  462. memset(&cfg, 0, sizeof(cfg));
  463. cfg.size = sde_plane_get_property(pstate,
  464. PLANE_PROP_PREFILL_SIZE);
  465. cfg.time = sde_plane_get_property(pstate,
  466. PLANE_PROP_PREFILL_TIME);
  467. SDE_DEBUG("plane%d size:%llu time:%llu\n",
  468. plane->base.id, cfg.size, cfg.time);
  469. SDE_EVT32_VERBOSE(DRMID(plane), cfg.size, cfg.time);
  470. psde->pipe_hw->ops.setup_ts_prefill(psde->pipe_hw, &cfg,
  471. pstate->multirect_index);
  472. }
  473. /* helper to update a state's input fence pointer from the property */
  474. static void _sde_plane_set_input_fence(struct sde_plane *psde,
  475. struct sde_plane_state *pstate, uint64_t fd)
  476. {
  477. if (!psde || !pstate) {
  478. SDE_ERROR("invalid arg(s), plane %d state %d\n",
  479. !psde, !pstate);
  480. return;
  481. }
  482. /* clear previous reference */
  483. if (pstate->input_fence)
  484. sde_sync_put(pstate->input_fence);
  485. /* get fence pointer for later */
  486. if (fd == 0)
  487. pstate->input_fence = NULL;
  488. else
  489. pstate->input_fence = sde_sync_get(fd);
  490. SDE_DEBUG_PLANE(psde, "0x%llX\n", fd);
  491. }
  492. int sde_plane_wait_input_fence(struct drm_plane *plane, uint32_t wait_ms)
  493. {
  494. struct sde_plane *psde;
  495. struct sde_plane_state *pstate;
  496. uint32_t prefix;
  497. void *input_fence;
  498. int ret = -EINVAL;
  499. signed long rc;
  500. if (!plane) {
  501. SDE_ERROR("invalid plane\n");
  502. } else if (!plane->state) {
  503. SDE_ERROR_PLANE(to_sde_plane(plane), "invalid state\n");
  504. } else {
  505. psde = to_sde_plane(plane);
  506. pstate = to_sde_plane_state(plane->state);
  507. input_fence = pstate->input_fence;
  508. if (input_fence) {
  509. prefix = sde_sync_get_name_prefix(input_fence);
  510. rc = sde_sync_wait(input_fence, wait_ms);
  511. switch (rc) {
  512. case 0:
  513. SDE_ERROR_PLANE(psde, "%ums timeout on %08X fd %lld\n",
  514. wait_ms, prefix, sde_plane_get_property(pstate,
  515. PLANE_PROP_INPUT_FENCE));
  516. psde->is_error = true;
  517. sde_kms_timeline_status(plane->dev);
  518. ret = -ETIMEDOUT;
  519. break;
  520. case -ERESTARTSYS:
  521. SDE_ERROR_PLANE(psde,
  522. "%ums wait interrupted on %08X\n",
  523. wait_ms, prefix);
  524. psde->is_error = true;
  525. ret = -ERESTARTSYS;
  526. break;
  527. case -EINVAL:
  528. SDE_ERROR_PLANE(psde,
  529. "invalid fence param for %08X\n",
  530. prefix);
  531. psde->is_error = true;
  532. ret = -EINVAL;
  533. break;
  534. case -EBADF:
  535. SDE_INFO("plane%d spec fd signaled on bind failure fd %lld\n",
  536. plane->base.id,
  537. sde_plane_get_property(pstate, PLANE_PROP_INPUT_FENCE));
  538. psde->is_error = true;
  539. ret = 0;
  540. break;
  541. default:
  542. SDE_DEBUG_PLANE(psde, "signaled\n");
  543. ret = 0;
  544. break;
  545. }
  546. if (ret)
  547. SDE_EVT32(DRMID(plane), -ret, prefix, SDE_EVTLOG_ERROR);
  548. else
  549. SDE_EVT32_VERBOSE(DRMID(plane), -ret, prefix);
  550. } else {
  551. ret = 0;
  552. }
  553. }
  554. return ret;
  555. }
  556. /**
  557. * _sde_plane_get_aspace: gets the address space based on the
  558. * fb_translation mode property
  559. */
  560. static int _sde_plane_get_aspace(
  561. struct sde_plane *psde,
  562. struct sde_plane_state *pstate,
  563. struct msm_gem_address_space **aspace)
  564. {
  565. struct sde_kms *kms;
  566. int mode;
  567. if (!psde || !pstate || !aspace) {
  568. SDE_ERROR("invalid parameters\n");
  569. return -EINVAL;
  570. }
  571. kms = _sde_plane_get_kms(&psde->base);
  572. if (!kms) {
  573. SDE_ERROR("invalid kms\n");
  574. return -EINVAL;
  575. }
  576. mode = sde_plane_get_property(pstate,
  577. PLANE_PROP_FB_TRANSLATION_MODE);
  578. switch (mode) {
  579. case SDE_DRM_FB_NON_SEC:
  580. *aspace = kms->aspace[MSM_SMMU_DOMAIN_UNSECURE];
  581. if (!aspace)
  582. return -EINVAL;
  583. break;
  584. case SDE_DRM_FB_SEC:
  585. *aspace = kms->aspace[MSM_SMMU_DOMAIN_SECURE];
  586. if (!aspace)
  587. return -EINVAL;
  588. break;
  589. case SDE_DRM_FB_NON_SEC_DIR_TRANS:
  590. case SDE_DRM_FB_SEC_DIR_TRANS:
  591. *aspace = NULL;
  592. break;
  593. default:
  594. SDE_ERROR("invalid fb_translation mode:%d\n", mode);
  595. return -EFAULT;
  596. }
  597. return 0;
  598. }
  599. static inline void _sde_plane_set_scanout(struct drm_plane *plane,
  600. struct sde_plane_state *pstate,
  601. struct sde_hw_pipe_cfg *pipe_cfg,
  602. struct drm_framebuffer *fb)
  603. {
  604. struct sde_plane *psde;
  605. struct msm_gem_address_space *aspace = NULL;
  606. int ret, mode;
  607. bool secure = false;
  608. if (!plane || !pstate || !pipe_cfg || !fb) {
  609. SDE_ERROR(
  610. "invalid arg(s), plane %d state %d cfg %d fb %d\n",
  611. !plane, !pstate, !pipe_cfg, !fb);
  612. return;
  613. }
  614. psde = to_sde_plane(plane);
  615. if (!psde->pipe_hw) {
  616. SDE_ERROR_PLANE(psde, "invalid pipe_hw\n");
  617. return;
  618. }
  619. ret = _sde_plane_get_aspace(psde, pstate, &aspace);
  620. if (ret) {
  621. SDE_ERROR_PLANE(psde, "Failed to get aspace %d\n", ret);
  622. return;
  623. }
  624. /*
  625. * framebuffer prepare is deferred for prepare_fb calls that
  626. * happen during the transition from secure to non-secure.
  627. * Handle the prepare at this point for such cases. This can be
  628. * expected for one or two frames during the transition.
  629. */
  630. if (aspace && pstate->defer_prepare_fb) {
  631. SDE_EVT32(DRMID(plane), psde->pipe, aspace->domain_attached);
  632. ret = msm_framebuffer_prepare(fb, pstate->aspace);
  633. if (ret) {
  634. SDE_ERROR_PLANE(psde,
  635. "failed to prepare framebuffer %d\n", ret);
  636. return;
  637. }
  638. pstate->defer_prepare_fb = false;
  639. }
  640. mode = sde_plane_get_property(pstate, PLANE_PROP_FB_TRANSLATION_MODE);
  641. if ((mode == SDE_DRM_FB_SEC) || (mode == SDE_DRM_FB_SEC_DIR_TRANS))
  642. secure = true;
  643. ret = sde_format_populate_layout(aspace, fb, &pipe_cfg->layout);
  644. if (ret == -EAGAIN)
  645. SDE_DEBUG_PLANE(psde, "not updating same src addrs\n");
  646. else if (ret) {
  647. SDE_ERROR_PLANE(psde, "failed to get format layout, %d\n", ret);
  648. /*
  649. * Force solid fill color on error. This is to prevent
  650. * smmu faults during secure session transition.
  651. */
  652. psde->is_error = true;
  653. } else if (psde->pipe_hw->ops.setup_sourceaddress) {
  654. SDE_EVT32_VERBOSE(psde->pipe_hw->idx,
  655. pipe_cfg->layout.width,
  656. pipe_cfg->layout.height,
  657. pipe_cfg->layout.plane_addr[0],
  658. pipe_cfg->layout.plane_size[0],
  659. pipe_cfg->layout.plane_addr[1],
  660. pipe_cfg->layout.plane_size[1],
  661. pipe_cfg->layout.plane_addr[2],
  662. pipe_cfg->layout.plane_size[2],
  663. pipe_cfg->layout.plane_addr[3],
  664. pipe_cfg->layout.plane_size[3],
  665. pstate->multirect_index,
  666. secure);
  667. psde->pipe_hw->ops.setup_sourceaddress(psde->pipe_hw, pipe_cfg,
  668. pstate->multirect_index);
  669. }
  670. }
  671. static int _sde_plane_setup_scaler3_lut(struct sde_plane *psde,
  672. struct sde_plane_state *pstate)
  673. {
  674. struct sde_hw_scaler3_cfg *cfg;
  675. int ret = 0;
  676. if (!psde || !pstate) {
  677. SDE_ERROR("invalid args\n");
  678. return -EINVAL;
  679. }
  680. cfg = &psde->scaler3_cfg;
  681. cfg->dir_lut = msm_property_get_blob(
  682. &psde->property_info,
  683. &pstate->property_state, &cfg->dir_len,
  684. PLANE_PROP_SCALER_LUT_ED);
  685. cfg->cir_lut = msm_property_get_blob(
  686. &psde->property_info,
  687. &pstate->property_state, &cfg->cir_len,
  688. PLANE_PROP_SCALER_LUT_CIR);
  689. cfg->sep_lut = msm_property_get_blob(
  690. &psde->property_info,
  691. &pstate->property_state, &cfg->sep_len,
  692. PLANE_PROP_SCALER_LUT_SEP);
  693. if (!cfg->dir_lut || !cfg->cir_lut || !cfg->sep_lut)
  694. ret = -ENODATA;
  695. return ret;
  696. }
  697. static int _sde_plane_setup_scaler3lite_lut(struct sde_plane *psde,
  698. struct sde_plane_state *pstate)
  699. {
  700. struct sde_hw_scaler3_cfg *cfg;
  701. cfg = &psde->scaler3_cfg;
  702. cfg->sep_lut = msm_property_get_blob(
  703. &psde->property_info,
  704. &pstate->property_state, &cfg->sep_len,
  705. PLANE_PROP_SCALER_LUT_SEP);
  706. return cfg->sep_lut ? 0 : -ENODATA;
  707. }
  708. static void _sde_plane_setup_scaler3(struct sde_plane *psde,
  709. struct sde_plane_state *pstate, const struct sde_format *fmt,
  710. uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v)
  711. {
  712. uint32_t decimated, i, src_w, src_h, dst_w, dst_h, src_h_pre_down;
  713. struct sde_hw_scaler3_cfg *scale_cfg;
  714. bool pre_down_supported = (psde->features & BIT(SDE_SSPP_PREDOWNSCALE));
  715. bool inline_rotation = (pstate->rotation & DRM_MODE_ROTATE_90);
  716. if (!fmt || !chroma_subsmpl_h || !chroma_subsmpl_v) {
  717. SDE_ERROR("fmt %d smp_h %d smp_v %d\n", !fmt,
  718. chroma_subsmpl_h, chroma_subsmpl_v);
  719. return;
  720. }
  721. scale_cfg = &psde->scaler3_cfg;
  722. src_w = psde->pipe_cfg.src_rect.w;
  723. src_h = psde->pipe_cfg.src_rect.h;
  724. dst_w = psde->pipe_cfg.dst_rect.w;
  725. dst_h = psde->pipe_cfg.dst_rect.h;
  726. memset(scale_cfg, 0, sizeof(*scale_cfg));
  727. memset(&psde->pixel_ext, 0, sizeof(struct sde_hw_pixel_ext));
  728. /*
  729. * For inline rotation cases, scaler config is post-rotation,
  730. * so swap the dimensions here. However, pixel extension will
  731. * need pre-rotation settings, this will be corrected below
  732. * when calculating pixel extension settings.
  733. */
  734. if (inline_rotation)
  735. swap(src_w, src_h);
  736. decimated = DECIMATED_DIMENSION(src_w,
  737. psde->pipe_cfg.horz_decimation);
  738. scale_cfg->phase_step_x[SDE_SSPP_COMP_0] =
  739. mult_frac((1 << PHASE_STEP_SHIFT), decimated, dst_w);
  740. decimated = DECIMATED_DIMENSION(src_h,
  741. psde->pipe_cfg.vert_decimation);
  742. scale_cfg->phase_step_y[SDE_SSPP_COMP_0] =
  743. mult_frac((1 << PHASE_STEP_SHIFT), decimated, dst_h);
  744. scale_cfg->phase_step_y[SDE_SSPP_COMP_1_2] =
  745. scale_cfg->phase_step_y[SDE_SSPP_COMP_0] / chroma_subsmpl_v;
  746. scale_cfg->phase_step_x[SDE_SSPP_COMP_1_2] =
  747. scale_cfg->phase_step_x[SDE_SSPP_COMP_0] / chroma_subsmpl_h;
  748. scale_cfg->phase_step_x[SDE_SSPP_COMP_2] =
  749. scale_cfg->phase_step_x[SDE_SSPP_COMP_1_2];
  750. scale_cfg->phase_step_y[SDE_SSPP_COMP_2] =
  751. scale_cfg->phase_step_y[SDE_SSPP_COMP_1_2];
  752. scale_cfg->phase_step_x[SDE_SSPP_COMP_3] =
  753. scale_cfg->phase_step_x[SDE_SSPP_COMP_0];
  754. scale_cfg->phase_step_y[SDE_SSPP_COMP_3] =
  755. scale_cfg->phase_step_y[SDE_SSPP_COMP_0];
  756. for (i = 0; i < SDE_MAX_PLANES; i++) {
  757. /*
  758. * For inline rotation cases with pre-downscaling enabled
  759. * set x pre-downscale value if required. Only x direction
  760. * is currently supported. Use src_h as values have been swapped
  761. * and x direction corresponds to height value.
  762. */
  763. src_h_pre_down = src_h;
  764. if (pre_down_supported && inline_rotation) {
  765. if (i == 0 && (src_h > mult_frac(dst_h, 11, 5)))
  766. src_h_pre_down = src_h / 2;
  767. }
  768. scale_cfg->src_width[i] = DECIMATED_DIMENSION(src_w,
  769. psde->pipe_cfg.horz_decimation);
  770. scale_cfg->src_height[i] = DECIMATED_DIMENSION(src_h_pre_down,
  771. psde->pipe_cfg.vert_decimation);
  772. if (i == SDE_SSPP_COMP_1_2 || i == SDE_SSPP_COMP_2) {
  773. scale_cfg->src_width[i] /= chroma_subsmpl_h;
  774. scale_cfg->src_height[i] /= chroma_subsmpl_v;
  775. }
  776. scale_cfg->preload_x[i] = psde->pipe_sblk->scaler_blk.h_preload;
  777. scale_cfg->preload_y[i] = psde->pipe_sblk->scaler_blk.v_preload;
  778. /* For pixel extension we need the pre-rotated orientation */
  779. if (inline_rotation) {
  780. psde->pixel_ext.num_ext_pxls_top[i] =
  781. scale_cfg->src_width[i];
  782. psde->pixel_ext.num_ext_pxls_left[i] =
  783. scale_cfg->src_height[i];
  784. } else {
  785. psde->pixel_ext.num_ext_pxls_top[i] =
  786. scale_cfg->src_height[i];
  787. psde->pixel_ext.num_ext_pxls_left[i] =
  788. scale_cfg->src_width[i];
  789. }
  790. }
  791. if ((!(SDE_FORMAT_IS_YUV(fmt)) && (src_h == dst_h)
  792. && (src_w == dst_w) && !inline_rotation) ||
  793. pstate->multirect_mode)
  794. return;
  795. SDE_DEBUG_PLANE(psde,
  796. "setting bilinear: src:%dx%d dst:%dx%d chroma:%dx%d fmt:%x\n",
  797. src_w, src_h, dst_w, dst_h,
  798. chroma_subsmpl_v, chroma_subsmpl_h,
  799. fmt->base.pixel_format);
  800. scale_cfg->dst_width = dst_w;
  801. scale_cfg->dst_height = dst_h;
  802. scale_cfg->y_rgb_filter_cfg = SDE_SCALE_BIL;
  803. scale_cfg->uv_filter_cfg = SDE_SCALE_BIL;
  804. scale_cfg->alpha_filter_cfg = SDE_SCALE_ALPHA_BIL;
  805. scale_cfg->lut_flag = 0;
  806. scale_cfg->blend_cfg = 1;
  807. scale_cfg->enable = 1;
  808. scale_cfg->dyn_exp_disabled = SDE_QSEED_DEFAULT_DYN_EXP;
  809. }
  810. /**
  811. * _sde_plane_setup_scaler2 - determine default scaler phase steps/filter type
  812. * @psde: Pointer to SDE plane object
  813. * @src: Source size
  814. * @dst: Destination size
  815. * @phase_steps: Pointer to output array for phase steps
  816. * @filter: Pointer to output array for filter type
  817. * @fmt: Pointer to format definition
  818. * @chroma_subsampling: Subsampling amount for chroma channel
  819. *
  820. * Returns: 0 on success
  821. */
  822. static int _sde_plane_setup_scaler2(struct sde_plane *psde,
  823. uint32_t src, uint32_t dst, uint32_t *phase_steps,
  824. enum sde_hw_filter *filter, const struct sde_format *fmt,
  825. uint32_t chroma_subsampling)
  826. {
  827. if (!psde || !phase_steps || !filter || !fmt) {
  828. SDE_ERROR(
  829. "invalid arg(s), plane %d phase %d filter %d fmt %d\n",
  830. !psde, !phase_steps, !filter, !fmt);
  831. return -EINVAL;
  832. }
  833. /* calculate phase steps, leave init phase as zero */
  834. phase_steps[SDE_SSPP_COMP_0] =
  835. mult_frac(1 << PHASE_STEP_SHIFT, src, dst);
  836. phase_steps[SDE_SSPP_COMP_1_2] =
  837. phase_steps[SDE_SSPP_COMP_0] / chroma_subsampling;
  838. phase_steps[SDE_SSPP_COMP_2] = phase_steps[SDE_SSPP_COMP_1_2];
  839. phase_steps[SDE_SSPP_COMP_3] = phase_steps[SDE_SSPP_COMP_0];
  840. /* calculate scaler config, if necessary */
  841. if (SDE_FORMAT_IS_YUV(fmt) || src != dst) {
  842. filter[SDE_SSPP_COMP_3] =
  843. (src <= dst) ? SDE_SCALE_FILTER_BIL :
  844. SDE_SCALE_FILTER_PCMN;
  845. if (SDE_FORMAT_IS_YUV(fmt)) {
  846. filter[SDE_SSPP_COMP_0] = SDE_SCALE_FILTER_CA;
  847. filter[SDE_SSPP_COMP_1_2] = filter[SDE_SSPP_COMP_3];
  848. } else {
  849. filter[SDE_SSPP_COMP_0] = filter[SDE_SSPP_COMP_3];
  850. filter[SDE_SSPP_COMP_1_2] =
  851. SDE_SCALE_FILTER_NEAREST;
  852. }
  853. } else {
  854. /* disable scaler */
  855. filter[SDE_SSPP_COMP_0] = SDE_SCALE_FILTER_MAX;
  856. filter[SDE_SSPP_COMP_1_2] = SDE_SCALE_FILTER_MAX;
  857. filter[SDE_SSPP_COMP_3] = SDE_SCALE_FILTER_MAX;
  858. }
  859. return 0;
  860. }
  861. /**
  862. * _sde_plane_setup_pixel_ext - determine default pixel extension values
  863. * @psde: Pointer to SDE plane object
  864. * @src: Source size
  865. * @dst: Destination size
  866. * @decimated_src: Source size after decimation, if any
  867. * @phase_steps: Pointer to output array for phase steps
  868. * @out_src: Output array for pixel extension values
  869. * @out_edge1: Output array for pixel extension first edge
  870. * @out_edge2: Output array for pixel extension second edge
  871. * @filter: Pointer to array for filter type
  872. * @fmt: Pointer to format definition
  873. * @chroma_subsampling: Subsampling amount for chroma channel
  874. * @post_compare: Whether to chroma subsampled source size for comparisions
  875. */
  876. static void _sde_plane_setup_pixel_ext(struct sde_plane *psde,
  877. uint32_t src, uint32_t dst, uint32_t decimated_src,
  878. uint32_t *phase_steps, uint32_t *out_src, int *out_edge1,
  879. int *out_edge2, enum sde_hw_filter *filter,
  880. const struct sde_format *fmt, uint32_t chroma_subsampling,
  881. bool post_compare)
  882. {
  883. int64_t edge1, edge2, caf;
  884. uint32_t src_work;
  885. int i, tmp;
  886. if (psde && phase_steps && out_src && out_edge1 &&
  887. out_edge2 && filter && fmt) {
  888. /* handle CAF for YUV formats */
  889. if (SDE_FORMAT_IS_YUV(fmt) && *filter == SDE_SCALE_FILTER_CA)
  890. caf = PHASE_STEP_UNIT_SCALE;
  891. else
  892. caf = 0;
  893. for (i = 0; i < SDE_MAX_PLANES; i++) {
  894. src_work = decimated_src;
  895. if (i == SDE_SSPP_COMP_1_2 || i == SDE_SSPP_COMP_2)
  896. src_work /= chroma_subsampling;
  897. if (post_compare)
  898. src = src_work;
  899. if (!SDE_FORMAT_IS_YUV(fmt) && (src == dst)) {
  900. /* unity */
  901. edge1 = 0;
  902. edge2 = 0;
  903. } else if (dst >= src) {
  904. /* upscale */
  905. edge1 = (1 << PHASE_RESIDUAL);
  906. edge1 -= caf;
  907. edge2 = (1 << PHASE_RESIDUAL);
  908. edge2 += (dst - 1) * *(phase_steps + i);
  909. edge2 -= (src_work - 1) * PHASE_STEP_UNIT_SCALE;
  910. edge2 += caf;
  911. edge2 = -(edge2);
  912. } else {
  913. /* downscale */
  914. edge1 = 0;
  915. edge2 = (dst - 1) * *(phase_steps + i);
  916. edge2 -= (src_work - 1) * PHASE_STEP_UNIT_SCALE;
  917. edge2 += *(phase_steps + i);
  918. edge2 = -(edge2);
  919. }
  920. /* only enable CAF for luma plane */
  921. caf = 0;
  922. /* populate output arrays */
  923. *(out_src + i) = src_work;
  924. /* edge updates taken from __pxl_extn_helper */
  925. if (edge1 >= 0) {
  926. tmp = (uint32_t)edge1;
  927. tmp >>= PHASE_STEP_SHIFT;
  928. *(out_edge1 + i) = -tmp;
  929. } else {
  930. tmp = (uint32_t)(-edge1);
  931. *(out_edge1 + i) =
  932. (tmp + PHASE_STEP_UNIT_SCALE - 1) >>
  933. PHASE_STEP_SHIFT;
  934. }
  935. if (edge2 >= 0) {
  936. tmp = (uint32_t)edge2;
  937. tmp >>= PHASE_STEP_SHIFT;
  938. *(out_edge2 + i) = -tmp;
  939. } else {
  940. tmp = (uint32_t)(-edge2);
  941. *(out_edge2 + i) =
  942. (tmp + PHASE_STEP_UNIT_SCALE - 1) >>
  943. PHASE_STEP_SHIFT;
  944. }
  945. }
  946. }
  947. }
  948. static inline void _sde_plane_setup_csc(struct sde_plane *psde)
  949. {
  950. static const struct sde_csc_cfg sde_csc_YUV2RGB_601L = {
  951. {
  952. /* S15.16 format */
  953. 0x00012A00, 0x00000000, 0x00019880,
  954. 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
  955. 0x00012A00, 0x00020480, 0x00000000,
  956. },
  957. /* signed bias */
  958. { 0xfff0, 0xff80, 0xff80,},
  959. { 0x0, 0x0, 0x0,},
  960. /* unsigned clamp */
  961. { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0,},
  962. { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,},
  963. };
  964. static const struct sde_csc_cfg sde_csc10_YUV2RGB_601L = {
  965. {
  966. /* S15.16 format */
  967. 0x00012A00, 0x00000000, 0x00019880,
  968. 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
  969. 0x00012A00, 0x00020480, 0x00000000,
  970. },
  971. /* signed bias */
  972. { 0xffc0, 0xfe00, 0xfe00,},
  973. { 0x0, 0x0, 0x0,},
  974. /* unsigned clamp */
  975. { 0x40, 0x3ac, 0x40, 0x3c0, 0x40, 0x3c0,},
  976. { 0x00, 0x3ff, 0x00, 0x3ff, 0x00, 0x3ff,},
  977. };
  978. if (!psde) {
  979. SDE_ERROR("invalid plane\n");
  980. return;
  981. }
  982. /* revert to kernel default if override not available */
  983. if (psde->csc_usr_ptr)
  984. psde->csc_ptr = psde->csc_usr_ptr;
  985. else if (BIT(SDE_SSPP_CSC_10BIT) & psde->features)
  986. psde->csc_ptr = (struct sde_csc_cfg *)&sde_csc10_YUV2RGB_601L;
  987. else
  988. psde->csc_ptr = (struct sde_csc_cfg *)&sde_csc_YUV2RGB_601L;
  989. SDE_DEBUG_PLANE(psde, "using 0x%X 0x%X 0x%X...\n",
  990. psde->csc_ptr->csc_mv[0],
  991. psde->csc_ptr->csc_mv[1],
  992. psde->csc_ptr->csc_mv[2]);
  993. }
  994. static void sde_color_process_plane_setup(struct drm_plane *plane)
  995. {
  996. struct sde_plane *psde;
  997. struct sde_plane_state *pstate;
  998. uint32_t hue, saturation, value, contrast;
  999. struct drm_msm_memcol *memcol = NULL;
  1000. struct drm_msm_3d_gamut *vig_gamut = NULL;
  1001. struct drm_msm_igc_lut *igc = NULL;
  1002. struct drm_msm_pgc_lut *gc = NULL;
  1003. size_t memcol_sz = 0, size = 0;
  1004. struct sde_hw_cp_cfg hw_cfg = {};
  1005. struct sde_hw_ctl *ctl = _sde_plane_get_hw_ctl(plane);
  1006. bool fp16_igc, fp16_unmult;
  1007. struct drm_msm_fp16_gc *fp16_gc = NULL;
  1008. struct drm_msm_fp16_csc *fp16_csc = NULL;
  1009. psde = to_sde_plane(plane);
  1010. pstate = to_sde_plane_state(plane->state);
  1011. hue = (uint32_t) sde_plane_get_property(pstate, PLANE_PROP_HUE_ADJUST);
  1012. if (psde->pipe_hw->ops.setup_pa_hue)
  1013. psde->pipe_hw->ops.setup_pa_hue(psde->pipe_hw, &hue);
  1014. saturation = (uint32_t) sde_plane_get_property(pstate,
  1015. PLANE_PROP_SATURATION_ADJUST);
  1016. if (psde->pipe_hw->ops.setup_pa_sat)
  1017. psde->pipe_hw->ops.setup_pa_sat(psde->pipe_hw, &saturation);
  1018. value = (uint32_t) sde_plane_get_property(pstate,
  1019. PLANE_PROP_VALUE_ADJUST);
  1020. if (psde->pipe_hw->ops.setup_pa_val)
  1021. psde->pipe_hw->ops.setup_pa_val(psde->pipe_hw, &value);
  1022. contrast = (uint32_t) sde_plane_get_property(pstate,
  1023. PLANE_PROP_CONTRAST_ADJUST);
  1024. if (psde->pipe_hw->ops.setup_pa_cont)
  1025. psde->pipe_hw->ops.setup_pa_cont(psde->pipe_hw, &contrast);
  1026. if (psde->pipe_hw->ops.setup_pa_memcolor) {
  1027. /* Skin memory color setup */
  1028. memcol = msm_property_get_blob(&psde->property_info,
  1029. &pstate->property_state,
  1030. &memcol_sz,
  1031. PLANE_PROP_SKIN_COLOR);
  1032. psde->pipe_hw->ops.setup_pa_memcolor(psde->pipe_hw,
  1033. MEMCOLOR_SKIN, memcol);
  1034. /* Sky memory color setup */
  1035. memcol = msm_property_get_blob(&psde->property_info,
  1036. &pstate->property_state,
  1037. &memcol_sz,
  1038. PLANE_PROP_SKY_COLOR);
  1039. psde->pipe_hw->ops.setup_pa_memcolor(psde->pipe_hw,
  1040. MEMCOLOR_SKY, memcol);
  1041. /* Foliage memory color setup */
  1042. memcol = msm_property_get_blob(&psde->property_info,
  1043. &pstate->property_state,
  1044. &memcol_sz,
  1045. PLANE_PROP_FOLIAGE_COLOR);
  1046. psde->pipe_hw->ops.setup_pa_memcolor(psde->pipe_hw,
  1047. MEMCOLOR_FOLIAGE, memcol);
  1048. }
  1049. if (pstate->dirty & SDE_PLANE_DIRTY_VIG_GAMUT &&
  1050. psde->pipe_hw->ops.setup_vig_gamut) {
  1051. vig_gamut = msm_property_get_blob(&psde->property_info,
  1052. &pstate->property_state,
  1053. &size,
  1054. PLANE_PROP_VIG_GAMUT);
  1055. hw_cfg.last_feature = 0;
  1056. hw_cfg.ctl = ctl;
  1057. hw_cfg.len = size;
  1058. hw_cfg.payload = vig_gamut;
  1059. psde->pipe_hw->ops.setup_vig_gamut(psde->pipe_hw, &hw_cfg);
  1060. }
  1061. if (pstate->dirty & SDE_PLANE_DIRTY_VIG_IGC &&
  1062. psde->pipe_hw->ops.setup_vig_igc) {
  1063. igc = msm_property_get_blob(&psde->property_info,
  1064. &pstate->property_state,
  1065. &size,
  1066. PLANE_PROP_VIG_IGC);
  1067. hw_cfg.last_feature = 0;
  1068. hw_cfg.ctl = ctl;
  1069. hw_cfg.len = size;
  1070. hw_cfg.payload = igc;
  1071. psde->pipe_hw->ops.setup_vig_igc(psde->pipe_hw, &hw_cfg);
  1072. }
  1073. if (pstate->dirty & SDE_PLANE_DIRTY_DMA_IGC &&
  1074. psde->pipe_hw->ops.setup_dma_igc) {
  1075. igc = msm_property_get_blob(&psde->property_info,
  1076. &pstate->property_state,
  1077. &size,
  1078. PLANE_PROP_DMA_IGC);
  1079. hw_cfg.last_feature = 0;
  1080. hw_cfg.ctl = ctl;
  1081. hw_cfg.len = size;
  1082. hw_cfg.payload = igc;
  1083. psde->pipe_hw->ops.setup_dma_igc(psde->pipe_hw, &hw_cfg,
  1084. pstate->multirect_index);
  1085. }
  1086. if (pstate->dirty & SDE_PLANE_DIRTY_DMA_GC &&
  1087. psde->pipe_hw->ops.setup_dma_gc) {
  1088. gc = msm_property_get_blob(&psde->property_info,
  1089. &pstate->property_state,
  1090. &size,
  1091. PLANE_PROP_DMA_GC);
  1092. hw_cfg.last_feature = 0;
  1093. hw_cfg.ctl = ctl;
  1094. hw_cfg.len = size;
  1095. hw_cfg.payload = gc;
  1096. psde->pipe_hw->ops.setup_dma_gc(psde->pipe_hw, &hw_cfg,
  1097. pstate->multirect_index);
  1098. }
  1099. if (pstate->dirty & SDE_PLANE_DIRTY_FP16_IGC &&
  1100. psde->pipe_hw->ops.setup_fp16_igc) {
  1101. fp16_igc = !!sde_plane_get_property(pstate,
  1102. PLANE_PROP_FP16_IGC);
  1103. hw_cfg.last_feature = 0;
  1104. hw_cfg.ctl = ctl;
  1105. hw_cfg.len = sizeof(bool);
  1106. hw_cfg.payload = &fp16_igc;
  1107. psde->pipe_hw->ops.setup_fp16_igc(psde->pipe_hw,
  1108. pstate->multirect_index, &hw_cfg);
  1109. }
  1110. if (pstate->dirty & SDE_PLANE_DIRTY_FP16_GC &&
  1111. psde->pipe_hw->ops.setup_fp16_gc) {
  1112. fp16_gc = msm_property_get_blob(&psde->property_info,
  1113. &pstate->property_state,
  1114. &size,
  1115. PLANE_PROP_FP16_GC);
  1116. hw_cfg.last_feature = 0;
  1117. hw_cfg.ctl = ctl;
  1118. hw_cfg.len = size;
  1119. hw_cfg.payload = fp16_gc;
  1120. psde->pipe_hw->ops.setup_fp16_gc(psde->pipe_hw,
  1121. pstate->multirect_index, &hw_cfg);
  1122. }
  1123. if (pstate->dirty & SDE_PLANE_DIRTY_FP16_CSC &&
  1124. psde->pipe_hw->ops.setup_fp16_csc) {
  1125. fp16_csc = msm_property_get_blob(&psde->property_info,
  1126. &pstate->property_state,
  1127. &size,
  1128. PLANE_PROP_FP16_CSC);
  1129. hw_cfg.last_feature = 0;
  1130. hw_cfg.ctl = ctl;
  1131. hw_cfg.len = size;
  1132. hw_cfg.payload = fp16_csc;
  1133. psde->pipe_hw->ops.setup_fp16_csc(psde->pipe_hw,
  1134. pstate->multirect_index, &hw_cfg);
  1135. }
  1136. if (pstate->dirty & SDE_PLANE_DIRTY_FP16_UNMULT &&
  1137. psde->pipe_hw->ops.setup_fp16_unmult) {
  1138. fp16_unmult = !!sde_plane_get_property(pstate,
  1139. PLANE_PROP_FP16_UNMULT);
  1140. hw_cfg.last_feature = 0;
  1141. hw_cfg.ctl = ctl;
  1142. hw_cfg.len = sizeof(bool);
  1143. hw_cfg.payload = &fp16_unmult;
  1144. psde->pipe_hw->ops.setup_fp16_unmult(psde->pipe_hw,
  1145. pstate->multirect_index, &hw_cfg);
  1146. }
  1147. }
  1148. static void _sde_plane_setup_scaler(struct sde_plane *psde,
  1149. struct sde_plane_state *pstate,
  1150. const struct sde_format *fmt, bool color_fill)
  1151. {
  1152. struct sde_hw_pixel_ext *pe;
  1153. uint32_t chroma_subsmpl_h, chroma_subsmpl_v;
  1154. const struct drm_format_info *info = NULL;
  1155. if (!psde || !fmt || !pstate) {
  1156. SDE_ERROR("invalid arg(s), plane %d fmt %d state %d\n",
  1157. !psde, !fmt, !pstate);
  1158. return;
  1159. }
  1160. memcpy(&psde->scaler3_cfg, &pstate->scaler3_cfg,
  1161. sizeof(psde->scaler3_cfg));
  1162. memcpy(&psde->pixel_ext, &pstate->pixel_ext,
  1163. sizeof(psde->pixel_ext));
  1164. info = drm_format_info(fmt->base.pixel_format);
  1165. pe = &psde->pixel_ext;
  1166. psde->pipe_cfg.horz_decimation =
  1167. sde_plane_get_property(pstate, PLANE_PROP_H_DECIMATE);
  1168. psde->pipe_cfg.vert_decimation =
  1169. sde_plane_get_property(pstate, PLANE_PROP_V_DECIMATE);
  1170. /* don't chroma subsample if decimating */
  1171. chroma_subsmpl_h = psde->pipe_cfg.horz_decimation ? 1 : info->hsub;
  1172. chroma_subsmpl_v = psde->pipe_cfg.vert_decimation ? 1 : info->vsub;
  1173. /* update scaler */
  1174. if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3) ||
  1175. (psde->features & BIT(SDE_SSPP_SCALER_QSEED3LITE))) {
  1176. int rc = -EINVAL;
  1177. if (!color_fill && !psde->debugfs_default_scale)
  1178. rc = is_qseed3_rev_qseed3lite(psde->pipe_hw->catalog) ?
  1179. _sde_plane_setup_scaler3lite_lut(psde, pstate) :
  1180. _sde_plane_setup_scaler3_lut(psde, pstate);
  1181. if (rc || pstate->scaler_check_state !=
  1182. SDE_PLANE_SCLCHECK_SCALER_V2) {
  1183. SDE_EVT32_VERBOSE(DRMID(&psde->base), color_fill,
  1184. pstate->scaler_check_state,
  1185. psde->debugfs_default_scale, rc,
  1186. psde->pipe_cfg.src_rect.w,
  1187. psde->pipe_cfg.src_rect.h,
  1188. psde->pipe_cfg.dst_rect.w,
  1189. psde->pipe_cfg.dst_rect.h,
  1190. pstate->multirect_mode);
  1191. /* calculate default config for QSEED3 */
  1192. _sde_plane_setup_scaler3(psde, pstate, fmt,
  1193. chroma_subsmpl_h, chroma_subsmpl_v);
  1194. }
  1195. } else if (pstate->scaler_check_state != SDE_PLANE_SCLCHECK_SCALER_V1 ||
  1196. color_fill || psde->debugfs_default_scale) {
  1197. uint32_t deci_dim, i;
  1198. /* calculate default configuration for QSEED2 */
  1199. memset(pe, 0, sizeof(struct sde_hw_pixel_ext));
  1200. SDE_DEBUG_PLANE(psde, "default config\n");
  1201. deci_dim = DECIMATED_DIMENSION(psde->pipe_cfg.src_rect.w,
  1202. psde->pipe_cfg.horz_decimation);
  1203. _sde_plane_setup_scaler2(psde,
  1204. deci_dim,
  1205. psde->pipe_cfg.dst_rect.w,
  1206. pe->phase_step_x,
  1207. pe->horz_filter, fmt, chroma_subsmpl_h);
  1208. if (SDE_FORMAT_IS_YUV(fmt))
  1209. deci_dim &= ~0x1;
  1210. _sde_plane_setup_pixel_ext(psde, psde->pipe_cfg.src_rect.w,
  1211. psde->pipe_cfg.dst_rect.w, deci_dim,
  1212. pe->phase_step_x,
  1213. pe->roi_w,
  1214. pe->num_ext_pxls_left,
  1215. pe->num_ext_pxls_right, pe->horz_filter, fmt,
  1216. chroma_subsmpl_h, 0);
  1217. deci_dim = DECIMATED_DIMENSION(psde->pipe_cfg.src_rect.h,
  1218. psde->pipe_cfg.vert_decimation);
  1219. _sde_plane_setup_scaler2(psde,
  1220. deci_dim,
  1221. psde->pipe_cfg.dst_rect.h,
  1222. pe->phase_step_y,
  1223. pe->vert_filter, fmt, chroma_subsmpl_v);
  1224. _sde_plane_setup_pixel_ext(psde, psde->pipe_cfg.src_rect.h,
  1225. psde->pipe_cfg.dst_rect.h, deci_dim,
  1226. pe->phase_step_y,
  1227. pe->roi_h,
  1228. pe->num_ext_pxls_top,
  1229. pe->num_ext_pxls_btm, pe->vert_filter, fmt,
  1230. chroma_subsmpl_v, 1);
  1231. for (i = 0; i < SDE_MAX_PLANES; i++) {
  1232. if (pe->num_ext_pxls_left[i] >= 0)
  1233. pe->left_rpt[i] = pe->num_ext_pxls_left[i];
  1234. else
  1235. pe->left_ftch[i] = pe->num_ext_pxls_left[i];
  1236. if (pe->num_ext_pxls_right[i] >= 0)
  1237. pe->right_rpt[i] = pe->num_ext_pxls_right[i];
  1238. else
  1239. pe->right_ftch[i] = pe->num_ext_pxls_right[i];
  1240. if (pe->num_ext_pxls_top[i] >= 0)
  1241. pe->top_rpt[i] = pe->num_ext_pxls_top[i];
  1242. else
  1243. pe->top_ftch[i] = pe->num_ext_pxls_top[i];
  1244. if (pe->num_ext_pxls_btm[i] >= 0)
  1245. pe->btm_rpt[i] = pe->num_ext_pxls_btm[i];
  1246. else
  1247. pe->btm_ftch[i] = pe->num_ext_pxls_btm[i];
  1248. }
  1249. }
  1250. if (psde->pipe_hw->ops.setup_pre_downscale)
  1251. psde->pipe_hw->ops.setup_pre_downscale(psde->pipe_hw,
  1252. &pstate->pre_down);
  1253. }
  1254. /**
  1255. * _sde_plane_color_fill - enables color fill on plane
  1256. * @psde: Pointer to SDE plane object
  1257. * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
  1258. * @alpha: 8-bit fill alpha value, 255 selects 100% alpha
  1259. * Returns: 0 on success
  1260. */
  1261. static int _sde_plane_color_fill(struct sde_plane *psde,
  1262. uint32_t color, uint32_t alpha)
  1263. {
  1264. const struct sde_format *fmt;
  1265. const struct drm_plane *plane;
  1266. struct sde_plane_state *pstate;
  1267. bool blend_enable = true;
  1268. if (!psde || !psde->base.state) {
  1269. SDE_ERROR("invalid plane\n");
  1270. return -EINVAL;
  1271. }
  1272. if (!psde->pipe_hw) {
  1273. SDE_ERROR_PLANE(psde, "invalid plane h/w pointer\n");
  1274. return -EINVAL;
  1275. }
  1276. plane = &psde->base;
  1277. pstate = to_sde_plane_state(plane->state);
  1278. SDE_DEBUG_PLANE(psde, "\n");
  1279. /*
  1280. * select fill format to match user property expectation,
  1281. * h/w only supports RGB variants
  1282. */
  1283. fmt = sde_get_sde_format(DRM_FORMAT_ABGR8888);
  1284. blend_enable = (SDE_DRM_BLEND_OP_OPAQUE !=
  1285. sde_plane_get_property(pstate, PLANE_PROP_BLEND_OP));
  1286. /* update sspp */
  1287. if (fmt && psde->pipe_hw->ops.setup_solidfill) {
  1288. psde->pipe_hw->ops.setup_solidfill(psde->pipe_hw,
  1289. (color & 0xFFFFFF) | ((alpha & 0xFF) << 24),
  1290. pstate->multirect_index);
  1291. /* override scaler/decimation if solid fill */
  1292. psde->pipe_cfg.src_rect.x = 0;
  1293. psde->pipe_cfg.src_rect.y = 0;
  1294. psde->pipe_cfg.src_rect.w = psde->pipe_cfg.dst_rect.w;
  1295. psde->pipe_cfg.src_rect.h = psde->pipe_cfg.dst_rect.h;
  1296. _sde_plane_setup_scaler(psde, pstate, fmt, true);
  1297. if (psde->pipe_hw->ops.setup_format)
  1298. psde->pipe_hw->ops.setup_format(psde->pipe_hw,
  1299. fmt, blend_enable,
  1300. SDE_SSPP_SOLID_FILL,
  1301. pstate->multirect_index);
  1302. if (psde->pipe_hw->ops.setup_rects)
  1303. psde->pipe_hw->ops.setup_rects(psde->pipe_hw,
  1304. &psde->pipe_cfg,
  1305. pstate->multirect_index);
  1306. if (psde->pipe_hw->ops.setup_pe)
  1307. psde->pipe_hw->ops.setup_pe(psde->pipe_hw,
  1308. &psde->pixel_ext);
  1309. if (psde->pipe_hw->ops.setup_scaler &&
  1310. pstate->multirect_index != SDE_SSPP_RECT_1) {
  1311. psde->pipe_hw->ctl = _sde_plane_get_hw_ctl(plane);
  1312. psde->pipe_hw->ops.setup_scaler(psde->pipe_hw,
  1313. &psde->pipe_cfg, &psde->pixel_ext,
  1314. &psde->scaler3_cfg);
  1315. }
  1316. }
  1317. return 0;
  1318. }
  1319. /**
  1320. * sde_plane_rot_atomic_check - verify rotator update of the given state
  1321. * @plane: Pointer to drm plane
  1322. * @state: Pointer to drm plane state to be validated
  1323. * return: 0 if success; error code otherwise
  1324. */
  1325. static int sde_plane_rot_atomic_check(struct drm_plane *plane,
  1326. struct drm_plane_state *state)
  1327. {
  1328. struct sde_plane *psde;
  1329. struct sde_plane_state *pstate, *old_pstate;
  1330. int ret = 0;
  1331. u32 rotation;
  1332. if (!plane || !state) {
  1333. SDE_ERROR("invalid plane/state\n");
  1334. return -EINVAL;
  1335. }
  1336. psde = to_sde_plane(plane);
  1337. pstate = to_sde_plane_state(state);
  1338. old_pstate = to_sde_plane_state(plane->state);
  1339. /* check inline rotation and simplify the transform */
  1340. rotation = drm_rotation_simplify(
  1341. state->rotation,
  1342. DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
  1343. DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y);
  1344. if ((rotation & DRM_MODE_ROTATE_180) ||
  1345. (rotation & DRM_MODE_ROTATE_270)) {
  1346. SDE_ERROR_PLANE(psde,
  1347. "invalid rotation transform must be simplified 0x%x\n",
  1348. rotation);
  1349. ret = -EINVAL;
  1350. goto exit;
  1351. }
  1352. if (rotation & DRM_MODE_ROTATE_90) {
  1353. struct msm_drm_private *priv = plane->dev->dev_private;
  1354. struct sde_kms *sde_kms;
  1355. const struct msm_format *msm_fmt;
  1356. const struct sde_format *fmt;
  1357. struct sde_rect src;
  1358. bool q16_data = true;
  1359. POPULATE_RECT(&src, state->src_x, state->src_y,
  1360. state->src_w, state->src_h, q16_data);
  1361. /*
  1362. * DRM framework expects rotation flag in counter-clockwise
  1363. * direction and the HW expects in clockwise direction.
  1364. * Flip the flags to match with HW.
  1365. */
  1366. rotation ^= (DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y);
  1367. if (!psde->pipe_sblk->in_rot_maxdwnscale_rt_num ||
  1368. !psde->pipe_sblk->in_rot_maxdwnscale_rt_denom ||
  1369. !psde->pipe_sblk->in_rot_maxdwnscale_nrt ||
  1370. !psde->pipe_sblk->in_rot_maxheight ||
  1371. !psde->pipe_sblk->in_rot_format_list ||
  1372. !(psde->features & BIT(SDE_SSPP_TRUE_INLINE_ROT))) {
  1373. SDE_ERROR_PLANE(psde,
  1374. "wrong config rt:%d/%d nrt:%d fmt:%d h:%d 0x%x\n",
  1375. !psde->pipe_sblk->in_rot_maxdwnscale_rt_num,
  1376. !psde->pipe_sblk->in_rot_maxdwnscale_rt_denom,
  1377. !psde->pipe_sblk->in_rot_maxdwnscale_nrt,
  1378. !psde->pipe_sblk->in_rot_format_list,
  1379. !psde->pipe_sblk->in_rot_maxheight,
  1380. psde->features);
  1381. ret = -EINVAL;
  1382. goto exit;
  1383. }
  1384. /* check for valid height */
  1385. if (src.h > psde->pipe_sblk->in_rot_maxheight) {
  1386. SDE_ERROR_PLANE(psde,
  1387. "invalid height for inline rot:%d max:%d\n",
  1388. src.h, psde->pipe_sblk->in_rot_maxheight);
  1389. ret = -EINVAL;
  1390. goto exit;
  1391. }
  1392. if (!sde_plane_enabled(state))
  1393. goto exit;
  1394. /* check for valid formats supported by inline rot */
  1395. sde_kms = to_sde_kms(priv->kms);
  1396. msm_fmt = msm_framebuffer_format(state->fb);
  1397. fmt = to_sde_format(msm_fmt);
  1398. ret = sde_format_validate_fmt(&sde_kms->base, fmt,
  1399. psde->pipe_sblk->in_rot_format_list);
  1400. }
  1401. exit:
  1402. pstate->rotation = rotation;
  1403. return ret;
  1404. }
  1405. static bool _sde_plane_halt_requests(struct drm_plane *plane,
  1406. uint32_t xin_id, bool halt_forced_clk, bool enable)
  1407. {
  1408. struct sde_plane *psde;
  1409. struct msm_drm_private *priv;
  1410. struct sde_vbif_set_xin_halt_params halt_params;
  1411. if (!plane || !plane->dev) {
  1412. SDE_ERROR("invalid arguments\n");
  1413. return false;
  1414. }
  1415. psde = to_sde_plane(plane);
  1416. if (!psde->pipe_hw || !psde->pipe_hw->cap) {
  1417. SDE_ERROR("invalid pipe reference\n");
  1418. return false;
  1419. }
  1420. priv = plane->dev->dev_private;
  1421. if (!priv || !priv->kms) {
  1422. SDE_ERROR("invalid KMS reference\n");
  1423. return false;
  1424. }
  1425. memset(&halt_params, 0, sizeof(halt_params));
  1426. halt_params.vbif_idx = VBIF_RT;
  1427. halt_params.xin_id = xin_id;
  1428. halt_params.clk_ctrl = psde->pipe_hw->cap->clk_ctrl;
  1429. halt_params.forced_on = halt_forced_clk;
  1430. halt_params.enable = enable;
  1431. return sde_vbif_set_xin_halt(to_sde_kms(priv->kms), &halt_params);
  1432. }
  1433. void sde_plane_halt_requests(struct drm_plane *plane, bool enable)
  1434. {
  1435. struct sde_plane *psde;
  1436. if (!plane) {
  1437. SDE_ERROR("invalid plane\n");
  1438. return;
  1439. }
  1440. psde = to_sde_plane(plane);
  1441. if (!psde->pipe_hw || !psde->pipe_hw->cap) {
  1442. SDE_ERROR("invalid pipe reference\n");
  1443. return;
  1444. }
  1445. SDE_EVT32(DRMID(plane), psde->xin_halt_forced_clk, enable);
  1446. psde->xin_halt_forced_clk =
  1447. _sde_plane_halt_requests(plane, psde->pipe_hw->cap->xin_id,
  1448. psde->xin_halt_forced_clk, enable);
  1449. }
  1450. void sde_plane_secure_ctrl_xin_client(struct drm_plane *plane,
  1451. struct drm_crtc *crtc)
  1452. {
  1453. struct sde_plane *psde;
  1454. if (!plane || !crtc) {
  1455. SDE_ERROR("invalid plane/crtc\n");
  1456. return;
  1457. }
  1458. psde = to_sde_plane(plane);
  1459. if (psde->features & BIT(SDE_SSPP_BLOCK_SEC_UI))
  1460. return;
  1461. /* do all VBIF programming for the sec-ui allowed SSPP */
  1462. _sde_plane_set_qos_remap(plane);
  1463. _sde_plane_set_ot_limit(plane, crtc);
  1464. }
  1465. /**
  1466. * sde_plane_rot_install_properties - install plane rotator properties
  1467. * @plane: Pointer to drm plane
  1468. * @catalog: Pointer to mdss configuration
  1469. * return: none
  1470. */
  1471. static void sde_plane_rot_install_properties(struct drm_plane *plane,
  1472. struct sde_mdss_cfg *catalog)
  1473. {
  1474. struct sde_plane *psde = to_sde_plane(plane);
  1475. unsigned int supported_rotations = DRM_MODE_ROTATE_0 |
  1476. DRM_MODE_ROTATE_180 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y;
  1477. int ret = 0;
  1478. if (!plane || !psde) {
  1479. SDE_ERROR("invalid plane\n");
  1480. return;
  1481. } else if (!catalog) {
  1482. SDE_ERROR("invalid catalog\n");
  1483. return;
  1484. }
  1485. if (!psde->is_virtual && psde->features & BIT(SDE_SSPP_TRUE_INLINE_ROT))
  1486. supported_rotations |= DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270;
  1487. ret = drm_plane_create_rotation_property(plane,
  1488. DRM_MODE_ROTATE_0, supported_rotations);
  1489. if (ret) {
  1490. DRM_ERROR("create rotation property failed: %d\n", ret);
  1491. return;
  1492. }
  1493. }
  1494. void sde_plane_clear_multirect(const struct drm_plane_state *drm_state)
  1495. {
  1496. struct sde_plane_state *pstate;
  1497. if (!drm_state)
  1498. return;
  1499. pstate = to_sde_plane_state(drm_state);
  1500. pstate->multirect_index = SDE_SSPP_RECT_SOLO;
  1501. pstate->multirect_mode = SDE_SSPP_MULTIRECT_NONE;
  1502. }
  1503. /**
  1504. * multi_rect validate API allows to validate only R0 and R1 RECT
  1505. * passing for each plane. Client of this API must not pass multiple
  1506. * plane which are not sharing same XIN client. Such calls will fail
  1507. * even though kernel client is passing valid multirect configuration.
  1508. */
  1509. int sde_plane_validate_multirect_v2(struct sde_multirect_plane_states *plane)
  1510. {
  1511. struct sde_plane_state *pstate[R_MAX];
  1512. const struct drm_plane_state *drm_state[R_MAX];
  1513. struct sde_rect src[R_MAX], dst[R_MAX];
  1514. struct sde_plane *sde_plane[R_MAX];
  1515. const struct sde_format *fmt[R_MAX];
  1516. int xin_id[R_MAX];
  1517. bool q16_data = true;
  1518. int i, j, buffer_lines, width_threshold[R_MAX];
  1519. unsigned int max_tile_height = 1;
  1520. bool parallel_fetch_qualified = true;
  1521. enum sde_sspp_multirect_mode mode = SDE_SSPP_MULTIRECT_NONE;
  1522. const struct msm_format *msm_fmt;
  1523. bool const_alpha_enable = true;
  1524. for (i = 0; i < R_MAX; i++) {
  1525. drm_state[i] = i ? plane->r1 : plane->r0;
  1526. if (!drm_state[i]) {
  1527. SDE_ERROR("drm plane state is NULL\n");
  1528. return -EINVAL;
  1529. }
  1530. pstate[i] = to_sde_plane_state(drm_state[i]);
  1531. sde_plane[i] = to_sde_plane(drm_state[i]->plane);
  1532. xin_id[i] = sde_plane[i]->pipe_hw->cap->xin_id;
  1533. for (j = 0; j < i; j++) {
  1534. if (xin_id[i] != xin_id[j]) {
  1535. SDE_ERROR_PLANE(sde_plane[i],
  1536. "invalid multirect validate call base:%d xin_id:%d curr:%d xin:%d\n",
  1537. j, xin_id[j], i, xin_id[i]);
  1538. return -EINVAL;
  1539. }
  1540. }
  1541. msm_fmt = msm_framebuffer_format(drm_state[i]->fb);
  1542. if (!msm_fmt) {
  1543. SDE_ERROR_PLANE(sde_plane[i], "null fb\n");
  1544. return -EINVAL;
  1545. }
  1546. fmt[i] = to_sde_format(msm_fmt);
  1547. if (SDE_FORMAT_IS_UBWC(fmt[i]) &&
  1548. (fmt[i]->tile_height > max_tile_height))
  1549. max_tile_height = fmt[i]->tile_height;
  1550. POPULATE_RECT(&src[i], drm_state[i]->src_x, drm_state[i]->src_y,
  1551. drm_state[i]->src_w, drm_state[i]->src_h, q16_data);
  1552. POPULATE_RECT(&dst[i], drm_state[i]->crtc_x,
  1553. drm_state[i]->crtc_y, drm_state[i]->crtc_w,
  1554. drm_state[i]->crtc_h, !q16_data);
  1555. if (src[i].w != dst[i].w || src[i].h != dst[i].h) {
  1556. SDE_ERROR_PLANE(sde_plane[i],
  1557. "scaling is not supported in multirect mode\n");
  1558. return -EINVAL;
  1559. }
  1560. if (pstate[i]->rotation & DRM_MODE_ROTATE_90) {
  1561. SDE_ERROR_PLANE(sde_plane[i],
  1562. "inline rotation is not supported in mulirect mode\n");
  1563. return -EINVAL;
  1564. }
  1565. if (SDE_FORMAT_IS_YUV(fmt[i])) {
  1566. SDE_ERROR_PLANE(sde_plane[i],
  1567. "Unsupported format for multirect mode\n");
  1568. return -EINVAL;
  1569. }
  1570. /**
  1571. * SSPP PD_MEM is split half - one for each RECT.
  1572. * Tiled formats need 5 lines of buffering while fetching
  1573. * whereas linear formats need only 2 lines.
  1574. * So we cannot support more than half of the supported SSPP
  1575. * width for tiled formats.
  1576. */
  1577. width_threshold[i] = sde_plane[i]->pipe_sblk->maxlinewidth;
  1578. if (SDE_FORMAT_IS_UBWC(fmt[i]))
  1579. width_threshold[i] /= 2;
  1580. if (parallel_fetch_qualified && src[i].w > width_threshold[i])
  1581. parallel_fetch_qualified = false;
  1582. if (sde_plane[i]->is_virtual)
  1583. mode = sde_plane_get_property(pstate[i],
  1584. PLANE_PROP_MULTIRECT_MODE);
  1585. if (pstate[i]->const_alpha_en != const_alpha_enable)
  1586. const_alpha_enable = false;
  1587. }
  1588. buffer_lines = 2 * max_tile_height;
  1589. /**
  1590. * fallback to driver mode selection logic if client is using
  1591. * multirect plane without setting property.
  1592. *
  1593. * validate multirect mode configuration based on rectangle
  1594. */
  1595. switch (mode) {
  1596. case SDE_SSPP_MULTIRECT_NONE:
  1597. if (parallel_fetch_qualified)
  1598. mode = SDE_SSPP_MULTIRECT_PARALLEL;
  1599. else if (TIME_MULTIPLEX_RECT(dst[R1], dst[R0], buffer_lines) ||
  1600. TIME_MULTIPLEX_RECT(dst[R0], dst[R1], buffer_lines))
  1601. mode = SDE_SSPP_MULTIRECT_TIME_MX;
  1602. else
  1603. SDE_ERROR(
  1604. "planes(%d - %d) multirect mode selection fail\n",
  1605. drm_state[R0]->plane->base.id,
  1606. drm_state[R1]->plane->base.id);
  1607. break;
  1608. case SDE_SSPP_MULTIRECT_PARALLEL:
  1609. if (!parallel_fetch_qualified) {
  1610. SDE_ERROR("R0 plane:%d width_threshold:%d src_w:%d\n",
  1611. drm_state[R0]->plane->base.id,
  1612. width_threshold[R0], src[R0].w);
  1613. SDE_ERROR("R1 plane:%d width_threshold:%d src_w:%d\n",
  1614. drm_state[R1]->plane->base.id,
  1615. width_threshold[R1], src[R1].w);
  1616. SDE_ERROR("parallel fetch not qualified\n");
  1617. mode = SDE_SSPP_MULTIRECT_NONE;
  1618. }
  1619. break;
  1620. case SDE_SSPP_MULTIRECT_TIME_MX:
  1621. if (!TIME_MULTIPLEX_RECT(dst[R1], dst[R0], buffer_lines) &&
  1622. !TIME_MULTIPLEX_RECT(dst[R0], dst[R1], buffer_lines)) {
  1623. SDE_ERROR(
  1624. "buffer_lines:%d R0 plane:%d dst_y:%d dst_h:%d\n",
  1625. buffer_lines, drm_state[R0]->plane->base.id,
  1626. dst[R0].y, dst[R0].h);
  1627. SDE_ERROR(
  1628. "buffer_lines:%d R1 plane:%d dst_y:%d dst_h:%d\n",
  1629. buffer_lines, drm_state[R1]->plane->base.id,
  1630. dst[R1].y, dst[R1].h);
  1631. SDE_ERROR("time multiplexed fetch not qualified\n");
  1632. mode = SDE_SSPP_MULTIRECT_NONE;
  1633. }
  1634. break;
  1635. default:
  1636. SDE_ERROR("bad mode:%d selection\n", mode);
  1637. mode = SDE_SSPP_MULTIRECT_NONE;
  1638. break;
  1639. }
  1640. for (i = 0; i < R_MAX; i++) {
  1641. pstate[i]->multirect_mode = mode;
  1642. pstate[i]->const_alpha_en = const_alpha_enable;
  1643. }
  1644. if (mode == SDE_SSPP_MULTIRECT_NONE)
  1645. return -EINVAL;
  1646. if (sde_plane[R0]->is_virtual) {
  1647. pstate[R0]->multirect_index = SDE_SSPP_RECT_1;
  1648. pstate[R1]->multirect_index = SDE_SSPP_RECT_0;
  1649. } else {
  1650. pstate[R0]->multirect_index = SDE_SSPP_RECT_0;
  1651. pstate[R1]->multirect_index = SDE_SSPP_RECT_1;
  1652. }
  1653. SDE_DEBUG_PLANE(sde_plane[R0], "R0: %d - %d\n",
  1654. pstate[R0]->multirect_mode, pstate[R0]->multirect_index);
  1655. SDE_DEBUG_PLANE(sde_plane[R1], "R1: %d - %d\n",
  1656. pstate[R1]->multirect_mode, pstate[R1]->multirect_index);
  1657. return 0;
  1658. }
  1659. /**
  1660. * sde_plane_ctl_flush - set/clear control flush bitmask for the given plane
  1661. * @plane: Pointer to drm plane structure
  1662. * @ctl: Pointer to hardware control driver
  1663. * @set: set if true else clear
  1664. */
  1665. void sde_plane_ctl_flush(struct drm_plane *plane, struct sde_hw_ctl *ctl,
  1666. bool set)
  1667. {
  1668. if (!plane || !ctl) {
  1669. SDE_ERROR("invalid parameters\n");
  1670. return;
  1671. }
  1672. if (!ctl->ops.update_bitmask_sspp) {
  1673. SDE_ERROR("invalid ops\n");
  1674. return;
  1675. }
  1676. ctl->ops.update_bitmask_sspp(ctl, sde_plane_pipe(plane), set);
  1677. }
  1678. static int sde_plane_prepare_fb(struct drm_plane *plane,
  1679. struct drm_plane_state *new_state)
  1680. {
  1681. struct drm_framebuffer *fb = new_state->fb;
  1682. struct sde_plane *psde = to_sde_plane(plane);
  1683. struct sde_plane_state *pstate = to_sde_plane_state(new_state);
  1684. struct sde_hw_fmt_layout layout;
  1685. struct msm_gem_address_space *aspace;
  1686. int ret;
  1687. if (!fb)
  1688. return 0;
  1689. SDE_DEBUG_PLANE(psde, "FB[%u]\n", fb->base.id);
  1690. ret = _sde_plane_get_aspace(psde, pstate, &aspace);
  1691. if (ret) {
  1692. SDE_ERROR_PLANE(psde, "Failed to get aspace\n");
  1693. return ret;
  1694. }
  1695. /* cache aspace */
  1696. pstate->aspace = aspace;
  1697. /*
  1698. * when transitioning from secure to non-secure,
  1699. * plane->prepare_fb happens before the commit. In such case,
  1700. * defer the prepare_fb and handled it late, during the commit
  1701. * after attaching the domains as part of the transition
  1702. */
  1703. pstate->defer_prepare_fb = (aspace && !aspace->domain_attached) ?
  1704. true : false;
  1705. if (pstate->defer_prepare_fb) {
  1706. SDE_EVT32(DRMID(plane), psde->pipe);
  1707. SDE_DEBUG_PLANE(psde,
  1708. "domain not attached, prepare_fb handled later\n");
  1709. return 0;
  1710. }
  1711. if (pstate->aspace && fb) {
  1712. ret = msm_framebuffer_prepare(fb,
  1713. pstate->aspace);
  1714. if (ret) {
  1715. SDE_ERROR("failed to prepare framebuffer fb:%d plane:%d pipe:%d ret:%d\n",
  1716. fb->base.id, plane->base.id, psde->pipe, ret);
  1717. SDE_EVT32(fb->base.id, plane->base.id, psde->pipe, ret, SDE_EVTLOG_ERROR);
  1718. return ret;
  1719. }
  1720. }
  1721. /* validate framebuffer layout before commit */
  1722. ret = sde_format_populate_layout(pstate->aspace,
  1723. fb, &layout);
  1724. if (ret) {
  1725. SDE_ERROR_PLANE(psde, "failed to get format layout, %d\n", ret);
  1726. return ret;
  1727. }
  1728. return 0;
  1729. }
  1730. static void sde_plane_cleanup_fb(struct drm_plane *plane,
  1731. struct drm_plane_state *old_state)
  1732. {
  1733. struct sde_plane *psde = to_sde_plane(plane);
  1734. struct sde_plane_state *old_pstate;
  1735. if (!old_state || !old_state->fb || !plane)
  1736. return;
  1737. old_pstate = to_sde_plane_state(old_state);
  1738. SDE_DEBUG_PLANE(psde, "FB[%u]\n", old_state->fb->base.id);
  1739. msm_framebuffer_cleanup(old_state->fb, old_pstate->aspace);
  1740. }
  1741. static void _sde_plane_sspp_atomic_check_mode_changed(struct sde_plane *psde,
  1742. struct drm_plane_state *state,
  1743. struct drm_plane_state *old_state)
  1744. {
  1745. struct sde_plane_state *pstate = to_sde_plane_state(state);
  1746. struct sde_plane_state *old_pstate = to_sde_plane_state(old_state);
  1747. struct drm_framebuffer *fb, *old_fb;
  1748. /* no need to check it again */
  1749. if (pstate->dirty == SDE_PLANE_DIRTY_ALL)
  1750. return;
  1751. if (!sde_plane_enabled(state) || !sde_plane_enabled(old_state)
  1752. || psde->is_error) {
  1753. SDE_DEBUG_PLANE(psde,
  1754. "enabling/disabling full modeset required\n");
  1755. pstate->dirty |= SDE_PLANE_DIRTY_ALL;
  1756. } else if (to_sde_plane_state(old_state)->pending) {
  1757. SDE_DEBUG_PLANE(psde, "still pending\n");
  1758. pstate->dirty |= SDE_PLANE_DIRTY_ALL;
  1759. } else if (pstate->multirect_index != old_pstate->multirect_index ||
  1760. pstate->multirect_mode != old_pstate->multirect_mode) {
  1761. SDE_DEBUG_PLANE(psde, "multirect config updated\n");
  1762. pstate->dirty |= SDE_PLANE_DIRTY_ALL;
  1763. } else if (state->src_w != old_state->src_w ||
  1764. state->src_h != old_state->src_h ||
  1765. state->src_x != old_state->src_x ||
  1766. state->src_y != old_state->src_y) {
  1767. SDE_DEBUG_PLANE(psde, "src rect updated\n");
  1768. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  1769. } else if (state->crtc_w != old_state->crtc_w ||
  1770. state->crtc_h != old_state->crtc_h ||
  1771. state->crtc_x != old_state->crtc_x ||
  1772. state->crtc_y != old_state->crtc_y) {
  1773. SDE_DEBUG_PLANE(psde, "crtc rect updated\n");
  1774. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  1775. } else if (pstate->excl_rect.w != old_pstate->excl_rect.w ||
  1776. pstate->excl_rect.h != old_pstate->excl_rect.h ||
  1777. pstate->excl_rect.x != old_pstate->excl_rect.x ||
  1778. pstate->excl_rect.y != old_pstate->excl_rect.y) {
  1779. SDE_DEBUG_PLANE(psde, "excl_rect updated\n");
  1780. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  1781. } else if (pstate->rotation != old_pstate->rotation) {
  1782. SDE_DEBUG_PLANE(psde, "rotation updated 0x%x->0x%x\n",
  1783. pstate->rotation, old_pstate->rotation);
  1784. pstate->dirty |= SDE_PLANE_DIRTY_FORMAT;
  1785. }
  1786. fb = state->fb;
  1787. old_fb = old_state->fb;
  1788. if (!fb || !old_fb) {
  1789. SDE_DEBUG_PLANE(psde, "can't compare fb handles\n");
  1790. } else if ((fb->format->format != old_fb->format->format) ||
  1791. pstate->const_alpha_en != old_pstate->const_alpha_en) {
  1792. SDE_DEBUG_PLANE(psde, "format change\n");
  1793. pstate->dirty |= SDE_PLANE_DIRTY_FORMAT | SDE_PLANE_DIRTY_RECTS;
  1794. } else {
  1795. uint64_t new_mod = fb->modifier;
  1796. uint64_t old_mod = old_fb->modifier;
  1797. uint32_t *new_pitches = fb->pitches;
  1798. uint32_t *old_pitches = old_fb->pitches;
  1799. uint32_t *new_offset = fb->offsets;
  1800. uint32_t *old_offset = old_fb->offsets;
  1801. int i;
  1802. if (new_mod != old_mod) {
  1803. SDE_DEBUG_PLANE(psde,
  1804. "format modifiers change new_mode:%llu old_mode:%llu\n",
  1805. new_mod, old_mod);
  1806. pstate->dirty |= SDE_PLANE_DIRTY_FORMAT |
  1807. SDE_PLANE_DIRTY_RECTS;
  1808. }
  1809. for (i = 0; i < ARRAY_SIZE(fb->pitches); i++) {
  1810. if (new_pitches[i] != old_pitches[i]) {
  1811. SDE_DEBUG_PLANE(psde,
  1812. "pitches change plane:%d old_pitches:%u new_pitches:%u\n",
  1813. i, old_pitches[i], new_pitches[i]);
  1814. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  1815. break;
  1816. }
  1817. }
  1818. for (i = 0; i < ARRAY_SIZE(fb->offsets); i++) {
  1819. if (new_offset[i] != old_offset[i]) {
  1820. SDE_DEBUG_PLANE(psde,
  1821. "offset change plane:%d old_offset:%u new_offset:%u\n",
  1822. i, old_offset[i], new_offset[i]);
  1823. pstate->dirty |= SDE_PLANE_DIRTY_FORMAT |
  1824. SDE_PLANE_DIRTY_RECTS;
  1825. break;
  1826. }
  1827. }
  1828. }
  1829. }
  1830. int sde_plane_validate_src_addr(struct drm_plane *plane,
  1831. unsigned long base_addr, u32 size)
  1832. {
  1833. int ret = -EINVAL;
  1834. u32 addr;
  1835. struct sde_plane *psde = to_sde_plane(plane);
  1836. if (!psde || !base_addr || !size) {
  1837. SDE_ERROR_PLANE(psde, "invalid arguments\n");
  1838. return ret;
  1839. }
  1840. if (psde->pipe_hw && psde->pipe_hw->ops.get_sourceaddress) {
  1841. addr = psde->pipe_hw->ops.get_sourceaddress(psde->pipe_hw,
  1842. is_sde_plane_virtual(plane));
  1843. if ((addr >= base_addr) && (addr < (base_addr + size)))
  1844. ret = 0;
  1845. }
  1846. return ret;
  1847. }
  1848. static inline bool _sde_plane_is_pre_downscale_enabled(
  1849. struct sde_hw_inline_pre_downscale_cfg *pre_down)
  1850. {
  1851. return pre_down->pre_downscale_x_0 || pre_down->pre_downscale_y_0;
  1852. }
  1853. static int _sde_plane_validate_scaler_v2(struct sde_plane *psde,
  1854. struct sde_plane_state *pstate,
  1855. const struct sde_format *fmt,
  1856. uint32_t img_w, uint32_t img_h,
  1857. uint32_t src_w, uint32_t src_h,
  1858. uint32_t deci_w, uint32_t deci_h)
  1859. {
  1860. struct sde_hw_inline_pre_downscale_cfg *pd_cfg;
  1861. bool pre_down_en;
  1862. int i;
  1863. if (!psde || !pstate || !fmt) {
  1864. SDE_ERROR_PLANE(psde, "invalid arguments\n");
  1865. return -EINVAL;
  1866. }
  1867. if (psde->debugfs_default_scale ||
  1868. (pstate->scaler_check_state != SDE_PLANE_SCLCHECK_SCALER_V2 &&
  1869. pstate->scaler_check_state != SDE_PLANE_SCLCHECK_SCALER_V2_CHECK))
  1870. return 0;
  1871. pd_cfg = &pstate->pre_down;
  1872. pre_down_en = _sde_plane_is_pre_downscale_enabled(pd_cfg);
  1873. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_INVALID;
  1874. for (i = 0; i < SDE_MAX_PLANES; i++) {
  1875. uint32_t hor_req_pixels, hor_fetch_pixels;
  1876. uint32_t vert_req_pixels, vert_fetch_pixels;
  1877. uint32_t src_w_tmp, src_h_tmp;
  1878. uint32_t scaler_w, scaler_h;
  1879. uint32_t pre_down_ratio_x = 1, pre_down_ratio_y = 1;
  1880. bool rot;
  1881. /* re-use color plane 1's config for plane 2 */
  1882. if (i == 2)
  1883. continue;
  1884. if (pre_down_en) {
  1885. if (i == 0 && pd_cfg->pre_downscale_x_0)
  1886. pre_down_ratio_x = pd_cfg->pre_downscale_x_0;
  1887. if (i == 0 && pd_cfg->pre_downscale_y_0)
  1888. pre_down_ratio_y = pd_cfg->pre_downscale_y_0;
  1889. if ((i == 1 || i == 2) && pd_cfg->pre_downscale_x_1)
  1890. pre_down_ratio_x = pd_cfg->pre_downscale_x_1;
  1891. if ((i == 1 || i == 2) && pd_cfg->pre_downscale_y_1)
  1892. pre_down_ratio_y = pd_cfg->pre_downscale_y_1;
  1893. SDE_DEBUG_PLANE(psde, "pre_down[%d]: x:%d, y:%d\n",
  1894. i, pre_down_ratio_x, pre_down_ratio_y);
  1895. }
  1896. src_w_tmp = src_w;
  1897. src_h_tmp = src_h;
  1898. /*
  1899. * For chroma plane, width is half for the following sub sampled
  1900. * formats. Except in case of decimation, where hardware avoids
  1901. * 1 line of decimation instead of downsampling.
  1902. */
  1903. if (i == 1) {
  1904. if (!deci_w &&
  1905. (fmt->chroma_sample == SDE_CHROMA_420 ||
  1906. fmt->chroma_sample == SDE_CHROMA_H2V1))
  1907. src_w_tmp >>= 1;
  1908. if (!deci_h &&
  1909. (fmt->chroma_sample == SDE_CHROMA_420 ||
  1910. fmt->chroma_sample == SDE_CHROMA_H1V2))
  1911. src_h_tmp >>= 1;
  1912. }
  1913. hor_req_pixels = pstate->pixel_ext.roi_w[i];
  1914. vert_req_pixels = pstate->pixel_ext.roi_h[i];
  1915. hor_fetch_pixels = DECIMATED_DIMENSION(src_w_tmp +
  1916. (int8_t)(pstate->pixel_ext.left_ftch[i] & 0xFF) +
  1917. (int8_t)(pstate->pixel_ext.right_ftch[i] & 0xFF),
  1918. deci_w);
  1919. vert_fetch_pixels = DECIMATED_DIMENSION(src_h_tmp +
  1920. (int8_t)(pstate->pixel_ext.top_ftch[i] & 0xFF) +
  1921. (int8_t)(pstate->pixel_ext.btm_ftch[i] & 0xFF),
  1922. deci_h);
  1923. if ((hor_req_pixels != hor_fetch_pixels) ||
  1924. (hor_fetch_pixels > img_w) ||
  1925. (vert_req_pixels != vert_fetch_pixels) ||
  1926. (vert_fetch_pixels > img_h)) {
  1927. SDE_ERROR_PLANE(psde,
  1928. "req %d/%d, fetch %d/%d, src %dx%d\n",
  1929. hor_req_pixels, vert_req_pixels,
  1930. hor_fetch_pixels, vert_fetch_pixels,
  1931. img_w, img_h);
  1932. return -EINVAL;
  1933. }
  1934. /*
  1935. * swap the scaler src width & height for inline-rotation 90
  1936. * comparison with Pixel-Extension, as PE is based on
  1937. * pre-rotation and QSEED is based on post-rotation
  1938. */
  1939. rot = pstate->rotation & DRM_MODE_ROTATE_90;
  1940. scaler_w = rot ? pstate->scaler3_cfg.src_height[i]
  1941. : pstate->scaler3_cfg.src_width[i];
  1942. scaler_h = rot ? pstate->scaler3_cfg.src_width[i]
  1943. : pstate->scaler3_cfg.src_height[i];
  1944. /*
  1945. * Alpha plane can only be scaled using bilinear or pixel
  1946. * repeat/drop, src_width and src_height are only specified
  1947. * for Y and UV plane
  1948. */
  1949. if (i != 3 && (hor_req_pixels / pre_down_ratio_x != scaler_w ||
  1950. vert_req_pixels / pre_down_ratio_y !=
  1951. scaler_h)) {
  1952. SDE_ERROR_PLANE(psde,
  1953. "roi[%d] roi:%dx%d scaler:%dx%d src:%dx%d rot:%d pd:%d/%d\n",
  1954. i, pstate->pixel_ext.roi_w[i],
  1955. pstate->pixel_ext.roi_h[i], scaler_w, scaler_h,
  1956. src_w, src_h, rot, pre_down_ratio_x, pre_down_ratio_y);
  1957. return -EINVAL;
  1958. }
  1959. /*
  1960. * SSPP fetch , unpack output and QSEED3 input lines need
  1961. * to match for Y plane
  1962. */
  1963. if (i == 0 &&
  1964. (sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG) &
  1965. BIT(SDE_DRM_DEINTERLACE)) &&
  1966. ((pstate->scaler3_cfg.src_height[i] != (src_h/2)) ||
  1967. (pstate->pixel_ext.roi_h[i] != (src_h/2)))) {
  1968. SDE_ERROR_PLANE(psde,
  1969. "de-interlace fail roi[%d] %d/%d, src %dx%d, src %dx%d\n",
  1970. i, pstate->pixel_ext.roi_w[i],
  1971. pstate->pixel_ext.roi_h[i],
  1972. pstate->scaler3_cfg.src_width[i],
  1973. pstate->scaler3_cfg.src_height[i],
  1974. src_w, src_h);
  1975. return -EINVAL;
  1976. }
  1977. }
  1978. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_SCALER_V2;
  1979. return 0;
  1980. }
  1981. static inline bool _sde_plane_has_pre_downscale(struct sde_plane *psde)
  1982. {
  1983. return (psde->features & BIT(SDE_SSPP_PREDOWNSCALE));
  1984. }
  1985. static int _sde_atomic_check_pre_downscale(struct sde_plane *psde,
  1986. struct sde_plane_state *pstate, struct sde_rect *dst,
  1987. u32 src_w, u32 src_h)
  1988. {
  1989. int ret = 0;
  1990. u32 min_ratio_numer, min_ratio_denom;
  1991. struct sde_hw_inline_pre_downscale_cfg *pd_cfg = &pstate->pre_down;
  1992. bool pd_x;
  1993. bool pd_y;
  1994. if (!_sde_plane_is_pre_downscale_enabled(pd_cfg))
  1995. return ret;
  1996. pd_x = pd_cfg->pre_downscale_x_0 > 1;
  1997. pd_y = pd_cfg->pre_downscale_y_0 > 1;
  1998. min_ratio_numer = psde->pipe_sblk->in_rot_maxdwnscale_rt_nopd_num;
  1999. min_ratio_denom = psde->pipe_sblk->in_rot_maxdwnscale_rt_nopd_denom;
  2000. if (pd_x && !_sde_plane_has_pre_downscale(psde)) {
  2001. SDE_ERROR_PLANE(psde,
  2002. "hw does not support pre-downscale X: 0x%x\n",
  2003. psde->features);
  2004. ret = -EINVAL;
  2005. } else if (pd_y && !(psde->features & BIT(SDE_SSPP_PREDOWNSCALE_Y))) {
  2006. SDE_ERROR_PLANE(psde,
  2007. "hw does not support pre-downscale Y: 0x%x\n",
  2008. psde->features);
  2009. ret = -EINVAL;
  2010. } else if (!min_ratio_numer || !min_ratio_denom) {
  2011. SDE_ERROR_PLANE(psde,
  2012. "min downscale ratio not set! %u / %u\n",
  2013. min_ratio_numer, min_ratio_denom);
  2014. ret = -EINVAL;
  2015. /* compare pre-rotated src w/h with post-rotated dst h/w resp. */
  2016. } else if (pd_x && (src_w < mult_frac(dst->h, min_ratio_numer,
  2017. min_ratio_denom))) {
  2018. SDE_ERROR_PLANE(psde,
  2019. "failed min downscale-x check %u->%u, %u/%u\n",
  2020. src_w, dst->h, min_ratio_numer, min_ratio_denom);
  2021. ret = -EINVAL;
  2022. } else if (pd_y && (src_h < mult_frac(dst->w, min_ratio_numer,
  2023. min_ratio_denom))) {
  2024. SDE_ERROR_PLANE(psde,
  2025. "failed min downscale-y check %u->%u, %u/%u\n",
  2026. src_h, dst->w, min_ratio_numer, min_ratio_denom);
  2027. ret = -EINVAL;
  2028. }
  2029. return ret;
  2030. }
  2031. static void _sde_plane_get_max_downscale_limits(struct sde_plane *psde,
  2032. struct sde_plane_state *pstate, bool rt_client, u32 dst_h,
  2033. u32 src_h, u32 *max_numer_w, u32 *max_denom_w,
  2034. u32 *max_numer_h, u32 *max_denom_h)
  2035. {
  2036. bool rotated, has_predown, default_scale;
  2037. const struct sde_sspp_sub_blks *sblk;
  2038. struct sde_hw_inline_pre_downscale_cfg *pd = NULL;
  2039. rotated = pstate->rotation & DRM_MODE_ROTATE_90;
  2040. sblk = psde->pipe_sblk;
  2041. *max_numer_w = sblk->maxdwnscale;
  2042. *max_denom_w = 1;
  2043. *max_numer_h = sblk->maxdwnscale;
  2044. *max_denom_h = 1;
  2045. has_predown = _sde_plane_has_pre_downscale(psde);
  2046. if (has_predown)
  2047. pd = &pstate->pre_down;
  2048. default_scale = psde->debugfs_default_scale ||
  2049. (pstate->scaler_check_state != SDE_PLANE_SCLCHECK_SCALER_V2 &&
  2050. pstate->scaler_check_state != SDE_PLANE_SCLCHECK_SCALER_V2_CHECK);
  2051. /**
  2052. * Inline rotation has different max vertical downscaling limits since
  2053. * the source-width becomes the scaler's pre-downscaled source-height.
  2054. **/
  2055. if (rotated) {
  2056. if (pd != NULL && rt_client && has_predown) {
  2057. if (default_scale)
  2058. pd->pre_downscale_x_0 = (src_h >
  2059. mult_frac(dst_h, 11, 5)) ? 2 : 0;
  2060. *max_numer_h = pd->pre_downscale_x_0 ?
  2061. sblk->in_rot_maxdwnscale_rt_num :
  2062. sblk->in_rot_maxdwnscale_rt_nopd_num;
  2063. *max_denom_h = pd->pre_downscale_x_0 ?
  2064. sblk->in_rot_maxdwnscale_rt_denom :
  2065. sblk->in_rot_maxdwnscale_rt_nopd_denom;
  2066. } else if (rt_client) {
  2067. *max_numer_h = sblk->in_rot_maxdwnscale_rt_num;
  2068. *max_denom_h = sblk->in_rot_maxdwnscale_rt_denom;
  2069. } else {
  2070. *max_numer_h = sblk->in_rot_maxdwnscale_nrt;
  2071. }
  2072. }
  2073. }
  2074. static int _sde_atomic_check_decimation_scaler(struct drm_plane_state *state,
  2075. struct sde_plane *psde, const struct sde_format *fmt,
  2076. struct sde_plane_state *pstate, struct sde_rect *src,
  2077. struct sde_rect *dst, u32 width, u32 height)
  2078. {
  2079. int ret = 0;
  2080. uint32_t deci_w, deci_h, src_deci_w, src_deci_h;
  2081. uint32_t scaler_src_w, scaler_src_h;
  2082. uint32_t max_downscale_num_w, max_downscale_denom_w;
  2083. uint32_t max_downscale_num_h, max_downscale_denom_h;
  2084. uint32_t max_upscale, max_linewidth;
  2085. bool inline_rotation, rt_client;
  2086. struct drm_crtc *crtc;
  2087. struct drm_crtc_state *new_cstate;
  2088. const struct sde_sspp_sub_blks *sblk;
  2089. if (!state || !state->state || !state->crtc) {
  2090. SDE_ERROR_PLANE(psde, "invalid arguments\n");
  2091. return -EINVAL;
  2092. }
  2093. deci_w = sde_plane_get_property(pstate, PLANE_PROP_H_DECIMATE);
  2094. deci_h = sde_plane_get_property(pstate, PLANE_PROP_V_DECIMATE);
  2095. src_deci_w = DECIMATED_DIMENSION(src->w, deci_w);
  2096. src_deci_h = DECIMATED_DIMENSION(src->h, deci_h);
  2097. /* with inline rotator, the source of the scaler is post-rotated */
  2098. inline_rotation = pstate->rotation & DRM_MODE_ROTATE_90 ? true : false;
  2099. if (inline_rotation) {
  2100. scaler_src_w = src_deci_h;
  2101. scaler_src_h = src_deci_w;
  2102. } else {
  2103. scaler_src_w = src_deci_w;
  2104. scaler_src_h = src_deci_h;
  2105. }
  2106. sblk = psde->pipe_sblk;
  2107. max_upscale = sblk->maxupscale;
  2108. if (inline_rotation)
  2109. max_linewidth = sblk->in_rot_maxheight;
  2110. else if (scaler_src_w != state->crtc_w || scaler_src_h != state->crtc_h)
  2111. max_linewidth = sblk->scaling_linewidth;
  2112. else
  2113. max_linewidth = sblk->maxlinewidth;
  2114. crtc = state->crtc;
  2115. new_cstate = drm_atomic_get_new_crtc_state(state->state, crtc);
  2116. rt_client = sde_crtc_is_rt_client(crtc, new_cstate);
  2117. _sde_plane_get_max_downscale_limits(psde, pstate, rt_client, dst->h,
  2118. scaler_src_h, &max_downscale_num_w, &max_downscale_denom_w,
  2119. &max_downscale_num_h, &max_downscale_denom_h);
  2120. /* decimation validation */
  2121. if ((deci_w || deci_h)
  2122. && ((deci_w > sblk->maxhdeciexp)
  2123. || (deci_h > sblk->maxvdeciexp))) {
  2124. SDE_ERROR_PLANE(psde, "too much decimation requested\n");
  2125. ret = -EINVAL;
  2126. } else if ((deci_w || deci_h)
  2127. && (fmt->fetch_mode != SDE_FETCH_LINEAR)) {
  2128. SDE_ERROR_PLANE(psde, "decimation requires linear fetch\n");
  2129. ret = -EINVAL;
  2130. } else if (!(psde->features & SDE_SSPP_SCALER) &&
  2131. ((src->w != dst->w) || (src->h != dst->h))) {
  2132. SDE_ERROR_PLANE(psde,
  2133. "pipe doesn't support scaling %ux%u->%ux%u\n",
  2134. src->w, src->h, dst->w, dst->h);
  2135. ret = -EINVAL;
  2136. /* check scaler source width */
  2137. } else if (scaler_src_w > max_linewidth) {
  2138. SDE_ERROR_PLANE(psde,
  2139. "invalid src w:%u, scaler w:%u, line w:%u, rot: %d\n",
  2140. src->w, scaler_src_w, max_linewidth, inline_rotation);
  2141. ret = -E2BIG;
  2142. /* check max scaler capability */
  2143. } else if (((scaler_src_w * max_upscale) < dst->w) ||
  2144. ((scaler_src_h * max_upscale) < dst->h) ||
  2145. (mult_frac(dst->w, max_downscale_num_w, max_downscale_denom_w)
  2146. < scaler_src_w) ||
  2147. (mult_frac(dst->h, max_downscale_num_h, max_downscale_denom_h)
  2148. < scaler_src_h)) {
  2149. SDE_ERROR_PLANE(psde,
  2150. "too much scaling %ux%u->%ux%u rot:%d dwn:%d/%d %d/%d\n",
  2151. scaler_src_w, scaler_src_h, dst->w, dst->h,
  2152. inline_rotation, max_downscale_num_w,
  2153. max_downscale_denom_w, max_downscale_num_h,
  2154. max_downscale_denom_h);
  2155. ret = -E2BIG;
  2156. /* check inline pre-downscale support */
  2157. } else if (inline_rotation && _sde_atomic_check_pre_downscale(psde,
  2158. pstate, dst, src_deci_w, src_deci_h)) {
  2159. ret = -EINVAL;
  2160. /* QSEED validation */
  2161. } else if (_sde_plane_validate_scaler_v2(psde, pstate, fmt,
  2162. width, height, src->w, src->h,
  2163. deci_w, deci_h)) {
  2164. ret = -EINVAL;
  2165. }
  2166. return ret;
  2167. }
  2168. static int _sde_atomic_check_excl_rect(struct sde_plane *psde,
  2169. struct sde_plane_state *pstate, struct sde_rect *src,
  2170. const struct sde_format *fmt, int ret)
  2171. {
  2172. /* check excl rect configs */
  2173. if (!ret && pstate->excl_rect.w && pstate->excl_rect.h) {
  2174. struct sde_rect intersect;
  2175. /*
  2176. * Check exclusion rect against src rect.
  2177. * it must intersect with source rect.
  2178. */
  2179. sde_kms_rect_intersect(src, &pstate->excl_rect, &intersect);
  2180. if (intersect.w != pstate->excl_rect.w ||
  2181. intersect.h != pstate->excl_rect.h ||
  2182. SDE_FORMAT_IS_YUV(fmt)) {
  2183. SDE_ERROR_PLANE(psde,
  2184. "invalid excl_rect:{%d,%d,%d,%d} src:{%d,%d,%d,%d}, fmt: %4.4s\n",
  2185. pstate->excl_rect.x, pstate->excl_rect.y,
  2186. pstate->excl_rect.w, pstate->excl_rect.h,
  2187. src->x, src->y, src->w, src->h,
  2188. (char *)&fmt->base.pixel_format);
  2189. ret = -EINVAL;
  2190. }
  2191. SDE_DEBUG_PLANE(psde, "excl_rect: {%d,%d,%d,%d}\n",
  2192. pstate->excl_rect.x, pstate->excl_rect.y,
  2193. pstate->excl_rect.w, pstate->excl_rect.h);
  2194. }
  2195. return ret;
  2196. }
  2197. static int _sde_plane_validate_shared_crtc(struct sde_plane *psde,
  2198. struct drm_plane_state *state)
  2199. {
  2200. struct sde_kms *sde_kms;
  2201. struct sde_splash_display *splash_display;
  2202. int i;
  2203. sde_kms = _sde_plane_get_kms(&psde->base);
  2204. if (!sde_kms || !state->crtc)
  2205. return 0;
  2206. for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
  2207. splash_display = &sde_kms->splash_data.splash_display[i];
  2208. if (splash_display && splash_display->cont_splash_enabled &&
  2209. splash_display->encoder &&
  2210. state->crtc != splash_display->encoder->crtc) {
  2211. struct sde_sspp_index_info *pipe_info = &splash_display->pipe_info;
  2212. if (test_bit(psde->pipe, pipe_info->pipes) ||
  2213. test_bit(psde->pipe, pipe_info->virt_pipes)) {
  2214. SDE_ERROR_PLANE(psde, "pipe:%d used in cont-splash on crtc:%d\n",
  2215. psde->pipe,
  2216. splash_display->encoder->crtc->base.id);
  2217. return -EINVAL;
  2218. }
  2219. }
  2220. }
  2221. return 0;
  2222. }
  2223. static int _sde_plane_sspp_atomic_check_helper(struct sde_plane *psde,
  2224. const struct sde_format *fmt,
  2225. struct sde_rect src, struct sde_rect dst,
  2226. u32 width, u32 height)
  2227. {
  2228. int ret = 0;
  2229. u32 min_src_size = SDE_FORMAT_IS_YUV(fmt) ? 2 : 1;
  2230. if (SDE_FORMAT_IS_YUV(fmt) &&
  2231. (!(psde->features & SDE_SSPP_SCALER) ||
  2232. !(psde->features & (BIT(SDE_SSPP_CSC)
  2233. | BIT(SDE_SSPP_CSC_10BIT))))) {
  2234. SDE_ERROR_PLANE(psde,
  2235. "plane doesn't have scaler/csc for yuv\n");
  2236. ret = -EINVAL;
  2237. /* check src bounds */
  2238. } else if (width > MAX_IMG_WIDTH || height > MAX_IMG_HEIGHT ||
  2239. src.w < min_src_size || src.h < min_src_size ||
  2240. CHECK_LAYER_BOUNDS(src.x, src.w, width) ||
  2241. CHECK_LAYER_BOUNDS(src.y, src.h, height)) {
  2242. SDE_ERROR_PLANE(psde, "invalid source %u, %u, %ux%u\n",
  2243. src.x, src.y, src.w, src.h);
  2244. ret = -E2BIG;
  2245. /* valid yuv image */
  2246. } else if (SDE_FORMAT_IS_YUV(fmt) && ((src.x & 0x1) || (src.y & 0x1) ||
  2247. (src.w & 0x1) || (src.h & 0x1))) {
  2248. SDE_ERROR_PLANE(psde, "invalid yuv source %u, %u, %ux%u\n",
  2249. src.x, src.y, src.w, src.h);
  2250. ret = -EINVAL;
  2251. /* min dst support */
  2252. } else if (dst.w < 0x1 || dst.h < 0x1) {
  2253. SDE_ERROR_PLANE(psde, "invalid dest rect %u, %u, %ux%u\n",
  2254. dst.x, dst.y, dst.w, dst.h);
  2255. ret = -EINVAL;
  2256. } else if (SDE_FORMAT_IS_UBWC(fmt) &&
  2257. !psde->catalog->ubwc_rev) {
  2258. SDE_ERROR_PLANE(psde, "ubwc not supported\n");
  2259. ret = -EINVAL;
  2260. }
  2261. return ret;
  2262. }
  2263. static int sde_plane_sspp_atomic_check(struct drm_plane *plane,
  2264. struct drm_plane_state *state)
  2265. {
  2266. int ret = 0;
  2267. struct sde_plane *psde;
  2268. struct sde_plane_state *pstate;
  2269. const struct msm_format *msm_fmt;
  2270. const struct sde_format *fmt;
  2271. struct sde_rect src, dst;
  2272. bool q16_data = true;
  2273. struct drm_framebuffer *fb;
  2274. u32 width;
  2275. u32 height;
  2276. psde = to_sde_plane(plane);
  2277. pstate = to_sde_plane_state(state);
  2278. if (!psde->pipe_sblk) {
  2279. SDE_ERROR_PLANE(psde, "invalid catalog\n");
  2280. return -EINVAL;
  2281. }
  2282. /* src values are in Q16 fixed point, convert to integer */
  2283. POPULATE_RECT(&src, state->src_x, state->src_y,
  2284. state->src_w, state->src_h, q16_data);
  2285. POPULATE_RECT(&dst, state->crtc_x, state->crtc_y, state->crtc_w,
  2286. state->crtc_h, !q16_data);
  2287. SDE_DEBUG_PLANE(psde, "check %d -> %d\n",
  2288. sde_plane_enabled(plane->state), sde_plane_enabled(state));
  2289. if (!sde_plane_enabled(state))
  2290. goto modeset_update;
  2291. fb = state->fb;
  2292. width = fb ? state->fb->width : 0x0;
  2293. height = fb ? state->fb->height : 0x0;
  2294. SDE_DEBUG("plane%d sspp:%x/%dx%d/%4.4s/%llx\n",
  2295. plane->base.id,
  2296. pstate->rotation,
  2297. width, height,
  2298. fb ? (char *) &state->fb->format->format : 0x0,
  2299. fb ? state->fb->modifier : 0x0);
  2300. SDE_DEBUG("src:%dx%d %d,%d crtc:%dx%d+%d+%d\n",
  2301. state->src_w >> 16, state->src_h >> 16,
  2302. state->src_x >> 16, state->src_y >> 16,
  2303. state->crtc_w, state->crtc_h,
  2304. state->crtc_x, state->crtc_y);
  2305. msm_fmt = msm_framebuffer_format(fb);
  2306. fmt = to_sde_format(msm_fmt);
  2307. ret = _sde_plane_sspp_atomic_check_helper(psde, fmt, src, dst, width,
  2308. height);
  2309. if (ret)
  2310. return ret;
  2311. ret = _sde_atomic_check_decimation_scaler(state, psde, fmt, pstate,
  2312. &src, &dst, width, height);
  2313. if (ret)
  2314. return ret;
  2315. ret = _sde_atomic_check_excl_rect(psde, pstate,
  2316. &src, fmt, ret);
  2317. if (ret)
  2318. return ret;
  2319. ret = _sde_plane_validate_shared_crtc(psde, state);
  2320. if (ret)
  2321. return ret;
  2322. pstate->const_alpha_en = fmt->alpha_enable &&
  2323. (SDE_DRM_BLEND_OP_OPAQUE !=
  2324. sde_plane_get_property(pstate, PLANE_PROP_BLEND_OP)) &&
  2325. (pstate->stage != SDE_STAGE_0);
  2326. modeset_update:
  2327. if (!ret)
  2328. _sde_plane_sspp_atomic_check_mode_changed(psde,
  2329. state, plane->state);
  2330. return ret;
  2331. }
  2332. static int _sde_plane_atomic_check(struct drm_plane *plane,
  2333. struct drm_plane_state *state)
  2334. {
  2335. int ret = 0;
  2336. struct sde_plane *psde;
  2337. struct sde_plane_state *pstate;
  2338. psde = to_sde_plane(plane);
  2339. pstate = to_sde_plane_state(state);
  2340. SDE_DEBUG_PLANE(psde, "\n");
  2341. ret = sde_plane_rot_atomic_check(plane, state);
  2342. if (ret)
  2343. goto exit;
  2344. ret = sde_plane_sspp_atomic_check(plane, state);
  2345. exit:
  2346. return ret;
  2347. }
  2348. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  2349. static int sde_plane_atomic_check(struct drm_plane *plane,
  2350. struct drm_atomic_state *atomic_state)
  2351. {
  2352. struct drm_plane_state *state = NULL;
  2353. if (!plane || !atomic_state) {
  2354. SDE_ERROR("invalid arg(s), plane %d atomic_state %d\n",
  2355. !plane, !atomic_state);
  2356. return -EINVAL;
  2357. }
  2358. state = drm_atomic_get_new_plane_state(atomic_state, plane);
  2359. return _sde_plane_atomic_check(plane, state);
  2360. }
  2361. #else
  2362. static int sde_plane_atomic_check(struct drm_plane *plane,
  2363. struct drm_plane_state *state)
  2364. {
  2365. if (!plane || !state) {
  2366. SDE_ERROR("invalid arg(s), plane %d state %d\n",
  2367. !plane, !state);
  2368. return -EINVAL;
  2369. }
  2370. return _sde_plane_atomic_check(plane, state);
  2371. }
  2372. #endif
  2373. void sde_plane_flush(struct drm_plane *plane)
  2374. {
  2375. struct sde_plane *psde;
  2376. struct sde_plane_state *pstate;
  2377. if (!plane || !plane->state) {
  2378. SDE_ERROR("invalid plane\n");
  2379. return;
  2380. }
  2381. psde = to_sde_plane(plane);
  2382. pstate = to_sde_plane_state(plane->state);
  2383. /*
  2384. * These updates have to be done immediately before the plane flush
  2385. * timing, and may not be moved to the atomic_update/mode_set functions.
  2386. */
  2387. if (psde->is_error)
  2388. /* force white frame with 100% alpha pipe output on error */
  2389. _sde_plane_color_fill(psde, 0xFFFFFF, 0xFF);
  2390. else if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG)
  2391. /* force 100% alpha */
  2392. _sde_plane_color_fill(psde, psde->color_fill, 0xFF);
  2393. else if (psde->pipe_hw && psde->csc_ptr && psde->pipe_hw->ops.setup_csc)
  2394. psde->pipe_hw->ops.setup_csc(psde->pipe_hw, psde->csc_ptr);
  2395. /* flag h/w flush complete */
  2396. if (plane->state)
  2397. pstate->pending = false;
  2398. }
  2399. /**
  2400. * sde_plane_set_error: enable/disable error condition
  2401. * @plane: pointer to drm_plane structure
  2402. */
  2403. void sde_plane_set_error(struct drm_plane *plane, bool error)
  2404. {
  2405. struct sde_plane *psde;
  2406. if (!plane)
  2407. return;
  2408. psde = to_sde_plane(plane);
  2409. psde->is_error = error;
  2410. }
  2411. static void _sde_plane_sspp_setup_sys_cache(struct sde_plane *psde,
  2412. struct sde_plane_state *pstate)
  2413. {
  2414. struct drm_plane_state *state = psde->base.state;
  2415. struct sde_sc_cfg *sc_cfg = psde->catalog->sc_cfg;
  2416. struct sde_hw_pipe_sc_cfg *cfg = &pstate->sc_cfg;
  2417. bool prev_rd_en = cfg->rd_en;
  2418. u32 cache_flag, cache_rd_type, cache_wr_type;
  2419. enum sde_sys_cache_state cache_state;
  2420. if (!state->fb) {
  2421. SDE_ERROR("invalid fb on plane %d\n", DRMID(&psde->base));
  2422. return;
  2423. }
  2424. cache_state = pstate->static_cache_state;
  2425. msm_framebuffer_get_cache_hint(state->fb, &cache_flag, &cache_rd_type, &cache_wr_type);
  2426. cfg->rd_en = false;
  2427. cfg->rd_scid = 0x0;
  2428. cfg->flags = SYS_CACHE_EN_FLAG | SYS_CACHE_SCID;
  2429. /*
  2430. * if condition handles static display legacy path, where internal state machine is
  2431. * transitioning the "cache_state" variable to program the LLCC cache through
  2432. * SSPP hardware using SDE_SYS_CACHE_DISP SCID.
  2433. * else condition handles static display and IWE path, were the frame is programmed to
  2434. * LLCC cache through WB/CWB path and read back by SSPP hardware. The FB cache hints are
  2435. * used to pass information on which SCID to use during read path and LLCC cache to
  2436. * keep active.
  2437. */
  2438. if (test_bit(SDE_SYS_CACHE_DISP, psde->catalog->sde_sys_cache_type_map)
  2439. && ((cache_state == CACHE_STATE_FRAME_WRITE)
  2440. || (cache_state == CACHE_STATE_FRAME_READ))) {
  2441. cfg->type = pstate->static_cache_type;
  2442. cfg->rd_en = true;
  2443. cfg->rd_scid = sc_cfg[cfg->type].llcc_scid;
  2444. if (test_bit(SDE_FEATURE_SYS_CACHE_NSE, psde->catalog->features)) {
  2445. cfg->rd_noallocate = false;
  2446. pstate->static_cache_state = CACHE_STATE_NORMAL;
  2447. } else {
  2448. cfg->rd_noallocate = (cache_state == CACHE_STATE_FRAME_READ);
  2449. }
  2450. cfg->flags |= SYS_CACHE_NO_ALLOC;
  2451. } else if (test_bit(cache_rd_type, psde->catalog->sde_sys_cache_type_map) && cache_flag) {
  2452. cfg->rd_en = true;
  2453. cfg->type = cache_rd_type;
  2454. cfg->rd_scid = sc_cfg[cache_rd_type].llcc_scid;
  2455. cfg->rd_noallocate = false;
  2456. cfg->flags |= SYS_CACHE_NO_ALLOC;
  2457. cache_flag = MSM_FB_CACHE_READ_EN;
  2458. msm_framebuffer_set_cache_hint(state->fb, cache_flag, cache_rd_type, cache_wr_type);
  2459. }
  2460. if (!cfg->rd_en && !prev_rd_en)
  2461. return;
  2462. SDE_EVT32(DRMID(&psde->base), cfg->type, cfg->rd_scid, cfg->rd_en, cfg->rd_noallocate,
  2463. cfg->flags, cache_state, cache_flag, cache_rd_type, cache_wr_type,
  2464. state->fb->base.id);
  2465. psde->pipe_hw->ops.setup_sys_cache(psde->pipe_hw, cfg);
  2466. }
  2467. void sde_plane_static_img_control(struct drm_plane *plane,
  2468. enum sde_sys_cache_state state, enum sde_sys_cache_type type)
  2469. {
  2470. struct sde_plane *psde;
  2471. struct sde_plane_state *pstate;
  2472. if (!plane || !plane->state) {
  2473. SDE_ERROR("invalid plane\n");
  2474. return;
  2475. }
  2476. psde = to_sde_plane(plane);
  2477. pstate = to_sde_plane_state(plane->state);
  2478. pstate->static_cache_state = state;
  2479. pstate->static_cache_type = type;
  2480. if (state == CACHE_STATE_FRAME_WRITE || state == CACHE_STATE_FRAME_READ)
  2481. _sde_plane_sspp_setup_sys_cache(psde, pstate);
  2482. }
  2483. static void _sde_plane_map_prop_to_dirty_bits(void)
  2484. {
  2485. plane_prop_array[PLANE_PROP_SCALER_V1] =
  2486. plane_prop_array[PLANE_PROP_SCALER_V2] =
  2487. plane_prop_array[PLANE_PROP_SCALER_LUT_ED] =
  2488. plane_prop_array[PLANE_PROP_SCALER_LUT_CIR] =
  2489. plane_prop_array[PLANE_PROP_SCALER_LUT_SEP] =
  2490. plane_prop_array[PLANE_PROP_H_DECIMATE] =
  2491. plane_prop_array[PLANE_PROP_V_DECIMATE] =
  2492. plane_prop_array[PLANE_PROP_SRC_CONFIG] =
  2493. plane_prop_array[PLANE_PROP_ZPOS] =
  2494. plane_prop_array[PLANE_PROP_EXCL_RECT_V1] =
  2495. plane_prop_array[PLANE_PROP_UBWC_STATS_ROI] =
  2496. SDE_PLANE_DIRTY_RECTS;
  2497. plane_prop_array[PLANE_PROP_CSC_V1] =
  2498. plane_prop_array[PLANE_PROP_CSC_DMA_V1] =
  2499. plane_prop_array[PLANE_PROP_INVERSE_PMA] =
  2500. SDE_PLANE_DIRTY_FORMAT;
  2501. plane_prop_array[PLANE_PROP_MULTIRECT_MODE] =
  2502. plane_prop_array[PLANE_PROP_COLOR_FILL] =
  2503. SDE_PLANE_DIRTY_ALL;
  2504. /* no special action required */
  2505. plane_prop_array[PLANE_PROP_INFO] =
  2506. plane_prop_array[PLANE_PROP_ALPHA] =
  2507. plane_prop_array[PLANE_PROP_INPUT_FENCE] =
  2508. plane_prop_array[PLANE_PROP_BLEND_OP] = 0;
  2509. plane_prop_array[PLANE_PROP_FB_TRANSLATION_MODE] =
  2510. SDE_PLANE_DIRTY_FB_TRANSLATION_MODE;
  2511. plane_prop_array[PLANE_PROP_PREFILL_SIZE] =
  2512. plane_prop_array[PLANE_PROP_PREFILL_TIME] =
  2513. SDE_PLANE_DIRTY_PERF;
  2514. plane_prop_array[PLANE_PROP_VIG_GAMUT] = SDE_PLANE_DIRTY_VIG_GAMUT;
  2515. plane_prop_array[PLANE_PROP_VIG_IGC] = SDE_PLANE_DIRTY_VIG_IGC;
  2516. plane_prop_array[PLANE_PROP_DMA_IGC] = SDE_PLANE_DIRTY_DMA_IGC;
  2517. plane_prop_array[PLANE_PROP_DMA_GC] = SDE_PLANE_DIRTY_DMA_GC;
  2518. plane_prop_array[PLANE_PROP_SKIN_COLOR] =
  2519. plane_prop_array[PLANE_PROP_SKY_COLOR] =
  2520. plane_prop_array[PLANE_PROP_FOLIAGE_COLOR] =
  2521. plane_prop_array[PLANE_PROP_HUE_ADJUST] =
  2522. plane_prop_array[PLANE_PROP_SATURATION_ADJUST] =
  2523. plane_prop_array[PLANE_PROP_VALUE_ADJUST] =
  2524. plane_prop_array[PLANE_PROP_CONTRAST_ADJUST] =
  2525. SDE_PLANE_DIRTY_ALL;
  2526. plane_prop_array[PLANE_PROP_FP16_IGC] = SDE_PLANE_DIRTY_FP16_IGC;
  2527. plane_prop_array[PLANE_PROP_FP16_GC] = SDE_PLANE_DIRTY_FP16_GC;
  2528. plane_prop_array[PLANE_PROP_FP16_CSC] = SDE_PLANE_DIRTY_FP16_CSC;
  2529. plane_prop_array[PLANE_PROP_FP16_UNMULT] = SDE_PLANE_DIRTY_FP16_UNMULT;
  2530. }
  2531. static inline bool _sde_plane_allow_uidle(struct sde_plane *psde,
  2532. struct sde_rect *src, struct sde_rect *dst)
  2533. {
  2534. u32 max_downscale = psde->catalog->uidle_cfg.max_dwnscale;
  2535. u32 downscale = (src->h * 1000)/dst->h;
  2536. return (downscale > max_downscale) ? false : true;
  2537. }
  2538. static void _sde_plane_setup_uidle(struct drm_crtc *crtc,
  2539. struct sde_plane *psde, struct sde_plane_state *pstate,
  2540. struct sde_rect *src, struct sde_rect *dst)
  2541. {
  2542. struct sde_hw_pipe_uidle_cfg cfg;
  2543. u32 line_time = sde_crtc_get_line_time(crtc);
  2544. u32 fal1_target_idle_time_ns =
  2545. psde->catalog->uidle_cfg.fal1_target_idle_time * 1000; /* nS */
  2546. u32 fal10_target_idle_time_ns =
  2547. psde->catalog->uidle_cfg.fal10_target_idle_time * 1000; /* nS */
  2548. u32 fal10_threshold =
  2549. psde->catalog->uidle_cfg.fal10_threshold; /* uS */
  2550. if (line_time && fal10_threshold && fal10_target_idle_time_ns &&
  2551. fal1_target_idle_time_ns) {
  2552. cfg.enable = _sde_plane_allow_uidle(psde, src, dst);
  2553. cfg.fal10_threshold = fal10_threshold;
  2554. cfg.fal10_exit_threshold = fal10_threshold + 2;
  2555. cfg.fal1_threshold = min(1 +
  2556. (fal1_target_idle_time_ns*1000/line_time*2)/1000,
  2557. psde->catalog->uidle_cfg.fal1_max_threshold);
  2558. cfg.fal_allowed_threshold = fal10_threshold +
  2559. (fal10_target_idle_time_ns*1000/line_time*2)/1000;
  2560. cfg.fill_level_scale = 0;
  2561. /*
  2562. * if uidle fill scale is supported, determing the scale value
  2563. * and adjust fal10 thresholds to their scaled values.
  2564. * fal1 thresholds and fal_allowed are not scaled.
  2565. */
  2566. if (psde->pipe_hw->ops.setup_uidle_fill_scale) {
  2567. u32 fl_require0 = psde->catalog->qos_target_time_ns / line_time * 2;
  2568. u32 fl_require = max(fal10_threshold * 1000, fl_require0);
  2569. u32 fl_scale = fl_require / fal10_threshold;
  2570. u32 fal10_threshold_noscale;
  2571. cfg.fill_level_scale = (fl_scale <= 1) ? 0 : (32 / fl_scale);
  2572. if (cfg.fill_level_scale) {
  2573. fal10_threshold_noscale = fal10_threshold *
  2574. 32/cfg.fill_level_scale;
  2575. cfg.fal_allowed_threshold = fal10_threshold_noscale +
  2576. (fal10_target_idle_time_ns * 1000 / line_time * 2) / 1000;
  2577. }
  2578. }
  2579. } else {
  2580. SDE_ERROR("invalid settings, will disable UIDLE %d %d %d %d\n",
  2581. line_time, fal10_threshold, fal10_target_idle_time_ns,
  2582. fal1_target_idle_time_ns);
  2583. memset(&cfg, 0, sizeof(struct sde_hw_pipe_uidle_cfg));
  2584. }
  2585. SDE_DEBUG_PLANE(psde,
  2586. "tholds: fal10=%d fal10_exit=%d fal1=%d fal_allowed=%d fill_scale=%d\n",
  2587. cfg.fal10_threshold, cfg.fal10_exit_threshold,
  2588. cfg.fal1_threshold, cfg.fal_allowed_threshold,
  2589. cfg.fill_level_scale);
  2590. SDE_DEBUG_PLANE(psde,
  2591. "times: line:%d fal1_idle:%d fal10_idle:%d dwnscale:%d\n",
  2592. line_time, fal1_target_idle_time_ns,
  2593. fal10_target_idle_time_ns,
  2594. psde->catalog->uidle_cfg.max_dwnscale);
  2595. SDE_EVT32_VERBOSE(cfg.enable,
  2596. cfg.fal10_threshold, cfg.fal10_exit_threshold,
  2597. cfg.fal1_threshold, cfg.fal_allowed_threshold,
  2598. cfg.fill_level_scale, psde->catalog->uidle_cfg.max_dwnscale);
  2599. if (psde->pipe_hw->ops.setup_uidle_fill_scale)
  2600. psde->pipe_hw->ops.setup_uidle_fill_scale(psde->pipe_hw, &cfg);
  2601. psde->pipe_hw->ops.setup_uidle(
  2602. psde->pipe_hw, &cfg,
  2603. pstate->multirect_index);
  2604. }
  2605. static void _sde_plane_update_secure_session(struct sde_plane *psde,
  2606. struct sde_plane_state *pstate)
  2607. {
  2608. bool enable = false;
  2609. int mode = sde_plane_get_property(pstate,
  2610. PLANE_PROP_FB_TRANSLATION_MODE);
  2611. if ((mode == SDE_DRM_FB_SEC) ||
  2612. (mode == SDE_DRM_FB_SEC_DIR_TRANS))
  2613. enable = true;
  2614. /* update secure session flag */
  2615. psde->pipe_hw->ops.setup_secure_address(psde->pipe_hw,
  2616. pstate->multirect_index,
  2617. enable);
  2618. }
  2619. static void _sde_plane_update_roi_config(struct drm_plane *plane,
  2620. struct drm_crtc *crtc, struct drm_framebuffer *fb)
  2621. {
  2622. const struct sde_format *fmt;
  2623. const struct msm_format *msm_fmt;
  2624. struct sde_plane *psde;
  2625. struct drm_plane_state *state;
  2626. struct sde_plane_state *pstate;
  2627. struct sde_rect src, dst;
  2628. const struct sde_rect *crtc_roi;
  2629. bool q16_data = true;
  2630. int idx;
  2631. psde = to_sde_plane(plane);
  2632. state = plane->state;
  2633. pstate = to_sde_plane_state(state);
  2634. msm_fmt = msm_framebuffer_format(fb);
  2635. if (!msm_fmt) {
  2636. SDE_ERROR("crtc%d plane%d: null format\n",
  2637. DRMID(crtc), DRMID(plane));
  2638. return;
  2639. }
  2640. fmt = to_sde_format(msm_fmt);
  2641. POPULATE_RECT(&src, state->src_x, state->src_y,
  2642. state->src_w, state->src_h, q16_data);
  2643. POPULATE_RECT(&dst, state->crtc_x, state->crtc_y,
  2644. state->crtc_w, state->crtc_h, !q16_data);
  2645. SDE_DEBUG_PLANE(psde,
  2646. "FB[%u] %u,%u,%ux%u->crtc%u %d,%d,%ux%u, %4.4s ubwc %d\n",
  2647. fb->base.id, src.x, src.y, src.w, src.h,
  2648. crtc->base.id, dst.x, dst.y, dst.w, dst.h,
  2649. (char *)&fmt->base.pixel_format,
  2650. SDE_FORMAT_IS_UBWC(fmt));
  2651. if (sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG) &
  2652. BIT(SDE_DRM_DEINTERLACE)) {
  2653. SDE_DEBUG_PLANE(psde, "deinterlace\n");
  2654. for (idx = 0; idx < SDE_MAX_PLANES; ++idx)
  2655. psde->pipe_cfg.layout.plane_pitch[idx] <<= 1;
  2656. src.h /= 2;
  2657. src.y = DIV_ROUND_UP(src.y, 2);
  2658. src.y &= ~0x1;
  2659. }
  2660. /*
  2661. * adjust layer mixer position of the sspp in the presence
  2662. * of a partial update to the active lm origin
  2663. */
  2664. sde_crtc_get_crtc_roi(crtc->state, &crtc_roi);
  2665. dst.x -= crtc_roi->x;
  2666. dst.y -= crtc_roi->y;
  2667. /* check for UIDLE */
  2668. if (psde->pipe_hw->ops.setup_uidle)
  2669. _sde_plane_setup_uidle(crtc, psde, pstate, &src, &dst);
  2670. psde->pipe_cfg.src_rect = src;
  2671. psde->pipe_cfg.dst_rect = dst;
  2672. _sde_plane_setup_scaler(psde, pstate, fmt, false);
  2673. _sde_plane_setup_panel_stacking(psde, pstate);
  2674. /* check for color fill */
  2675. psde->color_fill = (uint32_t)sde_plane_get_property(pstate,
  2676. PLANE_PROP_COLOR_FILL);
  2677. if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG) {
  2678. /* skip remaining processing on color fill */
  2679. pstate->dirty = 0x0;
  2680. } else if (psde->pipe_hw->ops.setup_rects) {
  2681. psde->pipe_hw->ops.setup_rects(psde->pipe_hw,
  2682. &psde->pipe_cfg,
  2683. pstate->multirect_index);
  2684. }
  2685. if (psde->pipe_hw->ops.setup_pe &&
  2686. (pstate->multirect_index != SDE_SSPP_RECT_1))
  2687. psde->pipe_hw->ops.setup_pe(psde->pipe_hw,
  2688. &psde->pixel_ext);
  2689. /**
  2690. * when programmed in multirect mode, scalar block will be
  2691. * bypassed. Still we need to update alpha and bitwidth
  2692. * ONLY for RECT0
  2693. */
  2694. if (psde->pipe_hw->ops.setup_scaler &&
  2695. pstate->multirect_index != SDE_SSPP_RECT_1) {
  2696. psde->pipe_hw->ctl = _sde_plane_get_hw_ctl(plane);
  2697. psde->pipe_hw->ops.setup_scaler(psde->pipe_hw,
  2698. &psde->pipe_cfg, &psde->pixel_ext,
  2699. &psde->scaler3_cfg);
  2700. }
  2701. /* update excl rect */
  2702. if (psde->pipe_hw->ops.setup_excl_rect)
  2703. psde->pipe_hw->ops.setup_excl_rect(psde->pipe_hw,
  2704. &pstate->excl_rect,
  2705. pstate->multirect_index);
  2706. /* enable multirect config of corresponding rect */
  2707. if (psde->pipe_hw->ops.update_multirect)
  2708. psde->pipe_hw->ops.update_multirect(
  2709. psde->pipe_hw,
  2710. true,
  2711. pstate->multirect_index,
  2712. pstate->multirect_mode);
  2713. /* update line insertion */
  2714. if (pstate->lineinsertion_feature && psde->pipe_hw->ops.setup_line_insertion)
  2715. psde->pipe_hw->ops.setup_line_insertion(psde->pipe_hw,
  2716. pstate->multirect_index,
  2717. &pstate->line_insertion_cfg);
  2718. }
  2719. static void _sde_plane_update_format_and_rects(struct sde_plane *psde,
  2720. struct sde_plane_state *pstate, const struct sde_format *fmt)
  2721. {
  2722. uint32_t src_flags = 0;
  2723. SDE_DEBUG_PLANE(psde, "rotation 0x%X\n", pstate->rotation);
  2724. if (pstate->rotation & DRM_MODE_REFLECT_X)
  2725. src_flags |= SDE_SSPP_FLIP_LR;
  2726. if (pstate->rotation & DRM_MODE_REFLECT_Y)
  2727. src_flags |= SDE_SSPP_FLIP_UD;
  2728. if (pstate->rotation & DRM_MODE_ROTATE_90)
  2729. src_flags |= SDE_SSPP_ROT_90;
  2730. /* update format */
  2731. psde->pipe_hw->ops.setup_format(psde->pipe_hw, fmt,
  2732. pstate->const_alpha_en, src_flags,
  2733. pstate->multirect_index);
  2734. if (psde->pipe_hw->ops.setup_cdp) {
  2735. struct sde_hw_pipe_cdp_cfg *cdp_cfg = &pstate->cdp_cfg;
  2736. memset(cdp_cfg, 0, sizeof(struct sde_hw_pipe_cdp_cfg));
  2737. cdp_cfg->enable = psde->catalog->perf.cdp_cfg
  2738. [SDE_PERF_CDP_USAGE_RT].rd_enable;
  2739. cdp_cfg->ubwc_meta_enable =
  2740. SDE_FORMAT_IS_UBWC(fmt);
  2741. cdp_cfg->tile_amortize_enable =
  2742. SDE_FORMAT_IS_UBWC(fmt) ||
  2743. SDE_FORMAT_IS_TILE(fmt);
  2744. cdp_cfg->preload_ahead = SDE_WB_CDP_PRELOAD_AHEAD_64;
  2745. psde->pipe_hw->ops.setup_cdp(psde->pipe_hw, cdp_cfg,
  2746. pstate->multirect_index);
  2747. }
  2748. _sde_plane_sspp_setup_sys_cache(psde, pstate);
  2749. /* update csc */
  2750. if (SDE_FORMAT_IS_YUV(fmt))
  2751. _sde_plane_setup_csc(psde);
  2752. else
  2753. psde->csc_ptr = 0;
  2754. if (psde->pipe_hw->ops.setup_inverse_pma) {
  2755. uint32_t pma_mode = 0;
  2756. if (fmt->alpha_enable)
  2757. pma_mode = (uint32_t) sde_plane_get_property(
  2758. pstate, PLANE_PROP_INVERSE_PMA);
  2759. psde->pipe_hw->ops.setup_inverse_pma(psde->pipe_hw,
  2760. pstate->multirect_index, pma_mode);
  2761. }
  2762. if (psde->pipe_hw->ops.setup_dgm_csc)
  2763. psde->pipe_hw->ops.setup_dgm_csc(psde->pipe_hw,
  2764. pstate->multirect_index, psde->csc_usr_ptr);
  2765. if (psde->pipe_hw->ops.set_ubwc_stats_roi) {
  2766. if (SDE_FORMAT_IS_UBWC(fmt) && !SDE_FORMAT_IS_YUV(fmt))
  2767. psde->pipe_hw->ops.set_ubwc_stats_roi(psde->pipe_hw,
  2768. pstate->multirect_index, &pstate->ubwc_stats_roi);
  2769. else
  2770. psde->pipe_hw->ops.set_ubwc_stats_roi(psde->pipe_hw,
  2771. pstate->multirect_index, NULL);
  2772. }
  2773. }
  2774. static void _sde_plane_update_sharpening(struct sde_plane *psde)
  2775. {
  2776. psde->sharp_cfg.strength = SHARP_STRENGTH_DEFAULT;
  2777. psde->sharp_cfg.edge_thr = SHARP_EDGE_THR_DEFAULT;
  2778. psde->sharp_cfg.smooth_thr = SHARP_SMOOTH_THR_DEFAULT;
  2779. psde->sharp_cfg.noise_thr = SHARP_NOISE_THR_DEFAULT;
  2780. psde->pipe_hw->ops.setup_sharpening(psde->pipe_hw,
  2781. &psde->sharp_cfg);
  2782. }
  2783. static void _sde_plane_update_properties(struct drm_plane *plane,
  2784. struct drm_crtc *crtc, struct drm_framebuffer *fb)
  2785. {
  2786. uint32_t nplanes;
  2787. const struct msm_format *msm_fmt;
  2788. const struct sde_format *fmt;
  2789. struct sde_plane *psde;
  2790. struct drm_plane_state *state;
  2791. struct sde_plane_state *pstate;
  2792. psde = to_sde_plane(plane);
  2793. state = plane->state;
  2794. pstate = to_sde_plane_state(state);
  2795. if (!pstate) {
  2796. SDE_ERROR("invalid plane state for plane%d\n", DRMID(plane));
  2797. return;
  2798. }
  2799. msm_fmt = msm_framebuffer_format(fb);
  2800. if (!msm_fmt) {
  2801. SDE_ERROR("crtc%d plane%d: null format\n",
  2802. DRMID(crtc), DRMID(plane));
  2803. return;
  2804. }
  2805. fmt = to_sde_format(msm_fmt);
  2806. nplanes = fmt->num_planes;
  2807. /* update secure session flag */
  2808. if (pstate->dirty & SDE_PLANE_DIRTY_FB_TRANSLATION_MODE)
  2809. _sde_plane_update_secure_session(psde, pstate);
  2810. /* update roi config */
  2811. if (pstate->dirty & SDE_PLANE_DIRTY_RECTS)
  2812. _sde_plane_update_roi_config(plane, crtc, fb);
  2813. if ((pstate->dirty & SDE_PLANE_DIRTY_FORMAT ||
  2814. pstate->dirty & SDE_PLANE_DIRTY_RECTS) &&
  2815. psde->pipe_hw->ops.setup_format)
  2816. _sde_plane_update_format_and_rects(psde, pstate, fmt);
  2817. sde_color_process_plane_setup(plane);
  2818. /* update sharpening */
  2819. if ((pstate->dirty & SDE_PLANE_DIRTY_SHARPEN) &&
  2820. psde->pipe_hw->ops.setup_sharpening)
  2821. _sde_plane_update_sharpening(psde);
  2822. if (pstate->dirty & (SDE_PLANE_DIRTY_QOS | SDE_PLANE_DIRTY_RECTS |
  2823. SDE_PLANE_DIRTY_FORMAT))
  2824. _sde_plane_set_qos_lut(plane, crtc, fb);
  2825. _sde_plane_set_qos_ctrl(plane, true, SDE_PLANE_QOS_PANIC_CTRL);
  2826. _sde_plane_set_ot_limit(plane, crtc);
  2827. if (pstate->dirty & SDE_PLANE_DIRTY_PERF)
  2828. _sde_plane_set_ts_prefill(plane, pstate);
  2829. if (pstate->dirty & SDE_PLANE_DIRTY_QOS)
  2830. _sde_plane_set_qos_remap(plane);
  2831. /* clear dirty */
  2832. pstate->dirty = 0x0;
  2833. }
  2834. static void _sde_plane_check_lut_dirty(struct sde_plane *psde,
  2835. struct sde_plane_state *pstate)
  2836. {
  2837. /**
  2838. * Valid configuration if scaler is not enabled or
  2839. * lut flag is set
  2840. */
  2841. if (pstate->scaler3_cfg.lut_flag || !pstate->scaler3_cfg.enable)
  2842. return;
  2843. pstate->scaler3_cfg.lut_flag = psde->cached_lut_flag;
  2844. SDE_EVT32(DRMID(&psde->base), pstate->scaler3_cfg.lut_flag, SDE_EVTLOG_ERROR);
  2845. }
  2846. static int sde_plane_sspp_atomic_update(struct drm_plane *plane,
  2847. struct drm_plane_state *old_state)
  2848. {
  2849. struct sde_plane *psde;
  2850. struct drm_plane_state *state;
  2851. struct sde_plane_state *pstate;
  2852. struct sde_plane_state *old_pstate;
  2853. struct drm_crtc *crtc;
  2854. struct drm_framebuffer *fb;
  2855. int idx;
  2856. int dirty_prop_flag;
  2857. bool is_rt;
  2858. if (!plane) {
  2859. SDE_ERROR("invalid plane\n");
  2860. return -EINVAL;
  2861. } else if (!plane->state) {
  2862. SDE_ERROR("invalid plane state\n");
  2863. return -EINVAL;
  2864. } else if (!old_state) {
  2865. SDE_ERROR("invalid old state\n");
  2866. return -EINVAL;
  2867. }
  2868. psde = to_sde_plane(plane);
  2869. state = plane->state;
  2870. pstate = to_sde_plane_state(state);
  2871. old_pstate = to_sde_plane_state(old_state);
  2872. crtc = state->crtc;
  2873. fb = state->fb;
  2874. if (!crtc || !fb) {
  2875. SDE_ERROR_PLANE(psde, "invalid crtc %d or fb %d\n",
  2876. !crtc, !fb);
  2877. return -EINVAL;
  2878. }
  2879. SDE_DEBUG(
  2880. "plane%d sspp:%dx%d/%4.4s/%llx/%dx%d+%d+%d/%x crtc:%dx%d+%d+%d\n",
  2881. plane->base.id,
  2882. state->fb->width, state->fb->height,
  2883. (char *) &state->fb->format->format,
  2884. state->fb->modifier,
  2885. state->src_w >> 16, state->src_h >> 16,
  2886. state->src_x >> 16, state->src_y >> 16,
  2887. pstate->rotation,
  2888. state->crtc_w, state->crtc_h,
  2889. state->crtc_x, state->crtc_y);
  2890. /* Caching the valid lut flag in sde plane */
  2891. if (pstate->scaler3_cfg.enable && pstate->scaler3_cfg.lut_flag)
  2892. psde->cached_lut_flag = pstate->scaler3_cfg.lut_flag;
  2893. /* force reprogramming of all the parameters, if the flag is set */
  2894. if (psde->revalidate) {
  2895. SDE_DEBUG("plane:%d - reconfigure all the parameters\n",
  2896. plane->base.id);
  2897. _sde_plane_check_lut_dirty(psde, pstate);
  2898. pstate->dirty = SDE_PLANE_DIRTY_ALL | SDE_PLANE_DIRTY_CP;
  2899. psde->revalidate = false;
  2900. }
  2901. /* determine what needs to be refreshed */
  2902. mutex_lock(&psde->property_info.property_lock);
  2903. while ((idx = msm_property_pop_dirty(&psde->property_info,
  2904. &pstate->property_state)) >= 0) {
  2905. dirty_prop_flag = plane_prop_array[idx];
  2906. pstate->dirty |= dirty_prop_flag;
  2907. }
  2908. mutex_unlock(&psde->property_info.property_lock);
  2909. /**
  2910. * since plane_atomic_check is invoked before crtc_atomic_check
  2911. * in the commit sequence, all the parameters for updating the
  2912. * plane dirty flag will not be available during
  2913. * plane_atomic_check as some features params are updated
  2914. * in crtc_atomic_check (eg.:sDMA). So check for mode_change
  2915. * before sspp update.
  2916. */
  2917. _sde_plane_sspp_atomic_check_mode_changed(psde, state,
  2918. old_state);
  2919. /* re-program the output rects always if partial update roi changed */
  2920. if (sde_crtc_is_crtc_roi_dirty(crtc->state))
  2921. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  2922. if (pstate->dirty & SDE_PLANE_DIRTY_RECTS)
  2923. memset(&(psde->pipe_cfg), 0, sizeof(struct sde_hw_pipe_cfg));
  2924. _sde_plane_set_scanout(plane, pstate, &psde->pipe_cfg, fb);
  2925. is_rt = sde_crtc_is_rt_client(crtc, crtc->state);
  2926. if (is_rt != psde->is_rt_pipe || crtc->state->mode_changed) {
  2927. psde->is_rt_pipe = is_rt;
  2928. psde->wb_usage_type = psde->is_rt_pipe ? 0 : sde_crtc_get_wb_usage_type(crtc);
  2929. pstate->dirty |= SDE_PLANE_DIRTY_QOS;
  2930. }
  2931. /* early out if nothing dirty */
  2932. if (!pstate->dirty)
  2933. return 0;
  2934. pstate->pending = true;
  2935. _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL);
  2936. _sde_plane_update_properties(plane, crtc, fb);
  2937. return 0;
  2938. }
  2939. static void _sde_plane_atomic_disable(struct drm_plane *plane,
  2940. struct drm_plane_state *old_state)
  2941. {
  2942. struct sde_plane *psde;
  2943. struct drm_plane_state *state;
  2944. struct sde_plane_state *pstate;
  2945. u32 multirect_index = SDE_SSPP_RECT_0;
  2946. struct sde_cp_crtc_skip_blend_plane skip_blend_plane;
  2947. u32 blend_type;
  2948. if (!plane) {
  2949. SDE_ERROR("invalid plane\n");
  2950. return;
  2951. } else if (!plane->state) {
  2952. SDE_ERROR("invalid plane state\n");
  2953. return;
  2954. } else if (!old_state) {
  2955. SDE_ERROR("invalid old state\n");
  2956. return;
  2957. }
  2958. psde = to_sde_plane(plane);
  2959. state = plane->state;
  2960. pstate = to_sde_plane_state(state);
  2961. blend_type = sde_plane_get_property(pstate,
  2962. PLANE_PROP_BLEND_OP);
  2963. /* some of the color features are dependent on plane with skip blend.
  2964. * if skip blend plane is being disabled, we need to disable color properties.
  2965. */
  2966. if (blend_type == SDE_DRM_BLEND_OP_SKIP && old_state->crtc) {
  2967. skip_blend_plane.valid_plane = false;
  2968. skip_blend_plane.plane = SSPP_NONE;
  2969. sde_cp_set_skip_blend_plane_info(old_state->crtc, &skip_blend_plane);
  2970. sde_crtc_disable_cp_features(old_state->crtc);
  2971. }
  2972. SDE_EVT32(DRMID(plane), is_sde_plane_virtual(plane),
  2973. pstate->multirect_mode);
  2974. pstate->pending = true;
  2975. pstate->static_cache_state = CACHE_STATE_DISABLED;
  2976. if (is_sde_plane_virtual(plane))
  2977. multirect_index = SDE_SSPP_RECT_1;
  2978. /* disable multirect config of corresponding rect */
  2979. if (psde->pipe_hw && psde->pipe_hw->ops.update_multirect)
  2980. psde->pipe_hw->ops.update_multirect(psde->pipe_hw, false,
  2981. multirect_index, SDE_SSPP_MULTIRECT_TIME_MX);
  2982. }
  2983. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  2984. static void _sde_plane_atomic_update(struct drm_plane *plane,
  2985. struct drm_plane_state *old_state)
  2986. #else
  2987. static void sde_plane_atomic_update(struct drm_plane *plane,
  2988. struct drm_plane_state *old_state)
  2989. #endif
  2990. {
  2991. struct sde_plane *psde;
  2992. struct drm_plane_state *state;
  2993. if (!plane) {
  2994. SDE_ERROR("invalid plane\n");
  2995. return;
  2996. } else if (!plane->state) {
  2997. SDE_ERROR("invalid plane state\n");
  2998. return;
  2999. }
  3000. psde = to_sde_plane(plane);
  3001. psde->is_error = false;
  3002. state = plane->state;
  3003. SDE_DEBUG_PLANE(psde, "\n");
  3004. if (!sde_plane_enabled(state)) {
  3005. _sde_plane_atomic_disable(plane, old_state);
  3006. } else {
  3007. int ret;
  3008. ret = sde_plane_sspp_atomic_update(plane, old_state);
  3009. /* atomic_check should have ensured that this doesn't fail */
  3010. WARN_ON(ret < 0);
  3011. }
  3012. }
  3013. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  3014. static void sde_plane_atomic_update(struct drm_plane *plane,
  3015. struct drm_atomic_state *atomic_state)
  3016. {
  3017. struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(atomic_state, plane);
  3018. _sde_plane_atomic_update(plane, old_state);
  3019. }
  3020. #endif
  3021. void sde_plane_restore(struct drm_plane *plane)
  3022. {
  3023. struct sde_plane *psde;
  3024. if (!plane || !plane->state) {
  3025. SDE_ERROR("invalid plane\n");
  3026. return;
  3027. }
  3028. psde = to_sde_plane(plane);
  3029. /*
  3030. * Revalidate is only true here if idle PC occurred and
  3031. * there is no plane state update in current commit cycle.
  3032. */
  3033. if (!psde->revalidate)
  3034. return;
  3035. SDE_DEBUG_PLANE(psde, "\n");
  3036. /* last plane state is same as current state */
  3037. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  3038. _sde_plane_atomic_update(plane, plane->state);
  3039. #else
  3040. sde_plane_atomic_update(plane, plane->state);
  3041. #endif
  3042. }
  3043. bool sde_plane_is_cache_required(struct drm_plane *plane,
  3044. enum sde_sys_cache_type type)
  3045. {
  3046. struct sde_plane_state *pstate;
  3047. u32 cache_flag, cache_rd_type, cache_wr_type;
  3048. if (!plane || !plane->state) {
  3049. SDE_ERROR("invalid plane\n");
  3050. return false;
  3051. }
  3052. pstate = to_sde_plane_state(plane->state);
  3053. msm_framebuffer_get_cache_hint(plane->state->fb, &cache_flag, &cache_rd_type,
  3054. &cache_wr_type);
  3055. /* check if llcc is required for the plane */
  3056. if (pstate->sc_cfg.rd_en && ((pstate->sc_cfg.type == type)
  3057. || (cache_flag && (cache_rd_type == type))
  3058. || (cache_flag && (cache_wr_type == type)))) {
  3059. SDE_EVT32_VERBOSE(DRMID(plane), type, pstate->sc_cfg.rd_en, pstate->sc_cfg.type,
  3060. cache_flag, cache_rd_type, cache_wr_type,
  3061. plane->state->fb->base.id);
  3062. return true;
  3063. }
  3064. return false;
  3065. }
  3066. static void _sde_plane_install_master_only_properties(struct sde_plane *psde)
  3067. {
  3068. char feature_name[256];
  3069. if (psde->pipe_sblk->maxhdeciexp) {
  3070. msm_property_install_range(&psde->property_info,
  3071. "h_decimate", 0x0, 0,
  3072. psde->pipe_sblk->maxhdeciexp, 0,
  3073. PLANE_PROP_H_DECIMATE);
  3074. }
  3075. if (psde->pipe_sblk->maxvdeciexp) {
  3076. msm_property_install_range(&psde->property_info,
  3077. "v_decimate", 0x0, 0,
  3078. psde->pipe_sblk->maxvdeciexp, 0,
  3079. PLANE_PROP_V_DECIMATE);
  3080. }
  3081. if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3)) {
  3082. msm_property_install_range(
  3083. &psde->property_info, "scaler_v2",
  3084. 0x0, 0, ~0, 0, PLANE_PROP_SCALER_V2);
  3085. msm_property_install_blob(&psde->property_info,
  3086. "lut_ed", 0, PLANE_PROP_SCALER_LUT_ED);
  3087. msm_property_install_blob(&psde->property_info,
  3088. "lut_cir", 0,
  3089. PLANE_PROP_SCALER_LUT_CIR);
  3090. msm_property_install_blob(&psde->property_info,
  3091. "lut_sep", 0,
  3092. PLANE_PROP_SCALER_LUT_SEP);
  3093. } else if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3LITE)) {
  3094. msm_property_install_range(
  3095. &psde->property_info, "scaler_v2",
  3096. 0x0, 0, ~0, 0, PLANE_PROP_SCALER_V2);
  3097. msm_property_install_blob(&psde->property_info,
  3098. "lut_sep", 0,
  3099. PLANE_PROP_SCALER_LUT_SEP);
  3100. } else if (psde->features & SDE_SSPP_SCALER) {
  3101. msm_property_install_range(
  3102. &psde->property_info, "scaler_v1", 0x0,
  3103. 0, ~0, 0, PLANE_PROP_SCALER_V1);
  3104. }
  3105. if (psde->features & BIT(SDE_SSPP_CSC) ||
  3106. psde->features & BIT(SDE_SSPP_CSC_10BIT))
  3107. msm_property_install_volatile_range(
  3108. &psde->property_info, "csc_v1", 0x0,
  3109. 0, ~0, 0, PLANE_PROP_CSC_V1);
  3110. if (psde->features & BIT(SDE_SSPP_HSIC)) {
  3111. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3112. "SDE_SSPP_HUE_V",
  3113. psde->pipe_sblk->hsic_blk.version >> 16);
  3114. msm_property_install_range(&psde->property_info,
  3115. feature_name, 0, 0, 0xFFFFFFFF, 0,
  3116. PLANE_PROP_HUE_ADJUST);
  3117. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3118. "SDE_SSPP_SATURATION_V",
  3119. psde->pipe_sblk->hsic_blk.version >> 16);
  3120. msm_property_install_range(&psde->property_info,
  3121. feature_name, 0, 0, 0xFFFFFFFF, 0,
  3122. PLANE_PROP_SATURATION_ADJUST);
  3123. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3124. "SDE_SSPP_VALUE_V",
  3125. psde->pipe_sblk->hsic_blk.version >> 16);
  3126. msm_property_install_range(&psde->property_info,
  3127. feature_name, 0, 0, 0xFFFFFFFF, 0,
  3128. PLANE_PROP_VALUE_ADJUST);
  3129. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3130. "SDE_SSPP_CONTRAST_V",
  3131. psde->pipe_sblk->hsic_blk.version >> 16);
  3132. msm_property_install_range(&psde->property_info,
  3133. feature_name, 0, 0, 0xFFFFFFFF, 0,
  3134. PLANE_PROP_CONTRAST_ADJUST);
  3135. }
  3136. }
  3137. static void _sde_plane_install_colorproc_properties(struct sde_plane *psde,
  3138. struct sde_kms_info *info)
  3139. {
  3140. char feature_name[256];
  3141. bool is_master = !psde->is_virtual;
  3142. if ((is_master &&
  3143. (psde->features & BIT(SDE_SSPP_INVERSE_PMA))) ||
  3144. (psde->features & BIT(SDE_SSPP_DGM_INVERSE_PMA))) {
  3145. msm_property_install_range(&psde->property_info,
  3146. "inverse_pma", 0x0, 0, 1, 0, PLANE_PROP_INVERSE_PMA);
  3147. sde_kms_info_add_keyint(info, "inverse_pma", 1);
  3148. }
  3149. if (psde->features & BIT(SDE_SSPP_DGM_CSC)) {
  3150. msm_property_install_volatile_range(
  3151. &psde->property_info, "csc_dma_v1", 0x0,
  3152. 0, ~0, 0, PLANE_PROP_CSC_DMA_V1);
  3153. sde_kms_info_add_keyint(info, "csc_dma_v1", 1);
  3154. }
  3155. if (psde->features & BIT(SDE_SSPP_MEMCOLOR)) {
  3156. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3157. "SDE_SSPP_SKIN_COLOR_V",
  3158. psde->pipe_sblk->memcolor_blk.version >> 16);
  3159. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3160. PLANE_PROP_SKIN_COLOR);
  3161. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3162. "SDE_SSPP_SKY_COLOR_V",
  3163. psde->pipe_sblk->memcolor_blk.version >> 16);
  3164. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3165. PLANE_PROP_SKY_COLOR);
  3166. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3167. "SDE_SSPP_FOLIAGE_COLOR_V",
  3168. psde->pipe_sblk->memcolor_blk.version >> 16);
  3169. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3170. PLANE_PROP_FOLIAGE_COLOR);
  3171. }
  3172. if (psde->features & BIT(SDE_SSPP_VIG_GAMUT)) {
  3173. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3174. "SDE_VIG_3D_LUT_GAMUT_V",
  3175. psde->pipe_sblk->gamut_blk.version >> 16);
  3176. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3177. PLANE_PROP_VIG_GAMUT);
  3178. }
  3179. if (psde->features & BIT(SDE_SSPP_VIG_IGC)) {
  3180. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3181. "SDE_VIG_1D_LUT_IGC_V",
  3182. psde->pipe_sblk->igc_blk[0].version >> 16);
  3183. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3184. PLANE_PROP_VIG_IGC);
  3185. }
  3186. if (psde->features & BIT(SDE_SSPP_DMA_IGC)) {
  3187. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3188. "SDE_DGM_1D_LUT_IGC_V",
  3189. psde->pipe_sblk->igc_blk[0].version >> 16);
  3190. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3191. PLANE_PROP_DMA_IGC);
  3192. }
  3193. if (psde->features & BIT(SDE_SSPP_DMA_GC)) {
  3194. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3195. "SDE_DGM_1D_LUT_GC_V",
  3196. psde->pipe_sblk->gc_blk[0].version >> 16);
  3197. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3198. PLANE_PROP_DMA_GC);
  3199. }
  3200. if (psde->features & BIT(SDE_SSPP_FP16_IGC)) {
  3201. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3202. "SDE_SSPP_FP16_IGC_V",
  3203. psde->pipe_sblk->fp16_igc_blk[0].version >> 16);
  3204. msm_property_install_range(&psde->property_info, feature_name,
  3205. 0x0, 0, 1, 0, PLANE_PROP_FP16_IGC);
  3206. }
  3207. if (psde->features & BIT(SDE_SSPP_FP16_GC)) {
  3208. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3209. "SDE_SSPP_FP16_GC_V",
  3210. psde->pipe_sblk->fp16_gc_blk[0].version >> 16);
  3211. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3212. PLANE_PROP_FP16_GC);
  3213. }
  3214. if (psde->features & BIT(SDE_SSPP_FP16_CSC)) {
  3215. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3216. "SDE_SSPP_FP16_CSC_V",
  3217. psde->pipe_sblk->fp16_csc_blk[0].version >> 16);
  3218. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3219. PLANE_PROP_FP16_CSC);
  3220. }
  3221. if (psde->features & BIT(SDE_SSPP_FP16_UNMULT)) {
  3222. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3223. "SDE_SSPP_FP16_UNMULT_V",
  3224. psde->pipe_sblk->fp16_unmult_blk[0].version >> 16);
  3225. msm_property_install_range(&psde->property_info, feature_name,
  3226. 0x0, 0, 1, 0, PLANE_PROP_FP16_UNMULT);
  3227. }
  3228. }
  3229. static void _sde_plane_setup_capabilities_blob(struct sde_plane *psde,
  3230. u32 master_plane_id, struct sde_kms_info *info,
  3231. struct sde_mdss_cfg *catalog)
  3232. {
  3233. bool is_master = !psde->is_virtual;
  3234. const struct sde_format_extended *format_list;
  3235. u32 index;
  3236. int pipe_id;
  3237. if (is_master) {
  3238. format_list = psde->pipe_sblk->format_list;
  3239. } else {
  3240. format_list = psde->pipe_sblk->virt_format_list;
  3241. sde_kms_info_add_keyint(info, "primary_smart_plane_id",
  3242. master_plane_id);
  3243. }
  3244. if (format_list) {
  3245. sde_kms_info_start(info, "pixel_formats");
  3246. while (format_list->fourcc_format) {
  3247. sde_kms_info_append_format(info,
  3248. format_list->fourcc_format,
  3249. format_list->modifier);
  3250. ++format_list;
  3251. }
  3252. sde_kms_info_stop(info);
  3253. }
  3254. if (psde->pipe_hw && catalog->qseed_hw_rev)
  3255. sde_kms_info_add_keyint(info, "scaler_step_ver", catalog->qseed_hw_rev);
  3256. sde_kms_info_add_keyint(info, "max_linewidth",
  3257. psde->pipe_sblk->maxlinewidth);
  3258. sde_kms_info_add_keyint(info, "max_upscale",
  3259. psde->pipe_sblk->maxupscale);
  3260. sde_kms_info_add_keyint(info, "max_downscale",
  3261. psde->pipe_sblk->maxdwnscale);
  3262. sde_kms_info_add_keyint(info, "max_horizontal_deci",
  3263. psde->pipe_sblk->maxhdeciexp);
  3264. sde_kms_info_add_keyint(info, "max_vertical_deci",
  3265. psde->pipe_sblk->maxvdeciexp);
  3266. sde_kms_info_add_keyint(info, "max_per_pipe_bw",
  3267. psde->pipe_sblk->max_per_pipe_bw * 1000LL);
  3268. sde_kms_info_add_keyint(info, "max_per_pipe_bw_high",
  3269. psde->pipe_sblk->max_per_pipe_bw_high * 1000LL);
  3270. if (SDE_SSPP_VALID_VIG(psde->pipe))
  3271. pipe_id = psde->pipe - SSPP_VIG0;
  3272. else if (SDE_SSPP_VALID_DMA(psde->pipe))
  3273. pipe_id = psde->pipe - SSPP_DMA0;
  3274. else
  3275. pipe_id = -1;
  3276. sde_kms_info_add_keyint(info, "pipe_idx", pipe_id);
  3277. index = (master_plane_id == 0) ? 0 : 1;
  3278. if (test_bit(SDE_FEATURE_DEMURA, catalog->features) &&
  3279. catalog->demura_supported[psde->pipe][index] != ~0x0)
  3280. sde_kms_info_add_keyint(info, "demura_block", index);
  3281. if (psde->features & BIT(SDE_SSPP_SEC_UI_ALLOWED))
  3282. sde_kms_info_add_keyint(info, "sec_ui_allowed", 1);
  3283. if (psde->features & BIT(SDE_SSPP_BLOCK_SEC_UI))
  3284. sde_kms_info_add_keyint(info, "block_sec_ui", 1);
  3285. if (psde->features & BIT(SDE_SSPP_TRUE_INLINE_ROT)) {
  3286. const struct sde_format_extended *inline_rot_fmt_list;
  3287. sde_kms_info_add_keyint(info, "true_inline_rot_rev",
  3288. catalog->true_inline_rot_rev);
  3289. sde_kms_info_add_keyint(info,
  3290. "true_inline_dwnscale_rt",
  3291. (int) (psde->pipe_sblk->in_rot_maxdwnscale_rt_num /
  3292. psde->pipe_sblk->in_rot_maxdwnscale_rt_denom));
  3293. sde_kms_info_add_keyint(info,
  3294. "true_inline_dwnscale_rt_numerator",
  3295. psde->pipe_sblk->in_rot_maxdwnscale_rt_num);
  3296. sde_kms_info_add_keyint(info,
  3297. "true_inline_dwnscale_rt_denominator",
  3298. psde->pipe_sblk->in_rot_maxdwnscale_rt_denom);
  3299. sde_kms_info_add_keyint(info, "true_inline_dwnscale_nrt",
  3300. psde->pipe_sblk->in_rot_maxdwnscale_nrt);
  3301. sde_kms_info_add_keyint(info, "true_inline_max_height",
  3302. psde->pipe_sblk->in_rot_maxheight);
  3303. inline_rot_fmt_list = psde->pipe_sblk->in_rot_format_list;
  3304. if (inline_rot_fmt_list) {
  3305. sde_kms_info_start(info, "inline_rot_pixel_formats");
  3306. while (inline_rot_fmt_list->fourcc_format) {
  3307. sde_kms_info_append_format(info,
  3308. inline_rot_fmt_list->fourcc_format,
  3309. inline_rot_fmt_list->modifier);
  3310. ++inline_rot_fmt_list;
  3311. }
  3312. sde_kms_info_stop(info);
  3313. }
  3314. }
  3315. }
  3316. /* helper to install properties which are common to planes and crtcs */
  3317. static void _sde_plane_install_properties(struct drm_plane *plane,
  3318. struct sde_mdss_cfg *catalog, u32 master_plane_id)
  3319. {
  3320. static const struct drm_prop_enum_list e_blend_op[] = {
  3321. {SDE_DRM_BLEND_OP_NOT_DEFINED, "not_defined"},
  3322. {SDE_DRM_BLEND_OP_OPAQUE, "opaque"},
  3323. {SDE_DRM_BLEND_OP_PREMULTIPLIED, "premultiplied"},
  3324. {SDE_DRM_BLEND_OP_COVERAGE, "coverage"},
  3325. {SDE_DRM_BLEND_OP_SKIP, "skip_blending"},
  3326. };
  3327. static const struct drm_prop_enum_list e_src_config[] = {
  3328. {SDE_DRM_DEINTERLACE, "deinterlace"}
  3329. };
  3330. static const struct drm_prop_enum_list e_fb_translation_mode[] = {
  3331. {SDE_DRM_FB_NON_SEC, "non_sec"},
  3332. {SDE_DRM_FB_SEC, "sec"},
  3333. {SDE_DRM_FB_NON_SEC_DIR_TRANS, "non_sec_direct_translation"},
  3334. {SDE_DRM_FB_SEC_DIR_TRANS, "sec_direct_translation"},
  3335. };
  3336. static const struct drm_prop_enum_list e_multirect_mode[] = {
  3337. {SDE_SSPP_MULTIRECT_NONE, "none"},
  3338. {SDE_SSPP_MULTIRECT_PARALLEL, "parallel"},
  3339. {SDE_SSPP_MULTIRECT_TIME_MX, "serial"},
  3340. };
  3341. struct sde_kms_info *info;
  3342. struct sde_plane *psde = to_sde_plane(plane);
  3343. bool is_master;
  3344. int zpos_max = 255;
  3345. int zpos_def = 0;
  3346. if (!plane || !psde) {
  3347. SDE_ERROR("invalid plane\n");
  3348. return;
  3349. } else if (!psde->pipe_hw || !psde->pipe_sblk) {
  3350. SDE_ERROR("invalid plane, pipe_hw %d pipe_sblk %d\n",
  3351. !psde->pipe_hw, !psde->pipe_sblk);
  3352. return;
  3353. } else if (!catalog) {
  3354. SDE_ERROR("invalid catalog\n");
  3355. return;
  3356. }
  3357. psde->catalog = catalog;
  3358. is_master = !psde->is_virtual;
  3359. info = vzalloc(sizeof(struct sde_kms_info));
  3360. if (!info) {
  3361. SDE_ERROR("failed to allocate info memory\n");
  3362. return;
  3363. }
  3364. if (sde_is_custom_client()) {
  3365. if (catalog->mixer_count &&
  3366. catalog->mixer[0].sblk->maxblendstages) {
  3367. zpos_max = catalog->mixer[0].sblk->maxblendstages - 1;
  3368. if (test_bit(SDE_FEATURE_BASE_LAYER, catalog->features) &&
  3369. (zpos_max > SDE_STAGE_MAX - 1))
  3370. zpos_max = SDE_STAGE_MAX - 1;
  3371. else if (zpos_max > SDE_STAGE_MAX - SDE_STAGE_0 - 1)
  3372. zpos_max = SDE_STAGE_MAX - SDE_STAGE_0 - 1;
  3373. }
  3374. } else if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
  3375. /* reserve zpos == 0 for primary planes */
  3376. zpos_def = drm_plane_index(plane) + 1;
  3377. }
  3378. msm_property_install_range(&psde->property_info, "zpos",
  3379. 0x0, 0, zpos_max, zpos_def, PLANE_PROP_ZPOS);
  3380. msm_property_install_range(&psde->property_info, "alpha",
  3381. 0x0, 0, 255, 255, PLANE_PROP_ALPHA);
  3382. /* linux default file descriptor range on each process */
  3383. msm_property_install_range(&psde->property_info, "input_fence",
  3384. 0x0, 0, INR_OPEN_MAX, 0, PLANE_PROP_INPUT_FENCE);
  3385. if (is_master)
  3386. _sde_plane_install_master_only_properties(psde);
  3387. else
  3388. msm_property_install_enum(&psde->property_info,
  3389. "multirect_mode", 0x0, 0, e_multirect_mode,
  3390. ARRAY_SIZE(e_multirect_mode), 0,
  3391. PLANE_PROP_MULTIRECT_MODE);
  3392. if (psde->features & BIT(SDE_SSPP_EXCL_RECT))
  3393. msm_property_install_volatile_range(&psde->property_info,
  3394. "excl_rect_v1", 0x0, 0, ~0, 0, PLANE_PROP_EXCL_RECT_V1);
  3395. sde_plane_rot_install_properties(plane, catalog);
  3396. msm_property_install_enum(&psde->property_info, "blend_op", 0x0, 0,
  3397. e_blend_op, ARRAY_SIZE(e_blend_op), 0, PLANE_PROP_BLEND_OP);
  3398. msm_property_install_enum(&psde->property_info, "src_config", 0x0, 1,
  3399. e_src_config, ARRAY_SIZE(e_src_config), 0,
  3400. PLANE_PROP_SRC_CONFIG);
  3401. if (psde->pipe_hw->ops.setup_solidfill)
  3402. msm_property_install_range(&psde->property_info, "color_fill",
  3403. 0, 0, 0xFFFFFFFF, 0, PLANE_PROP_COLOR_FILL);
  3404. msm_property_install_range(&psde->property_info, "prefill_size", 0x0,
  3405. 0, ~0, 0, PLANE_PROP_PREFILL_SIZE);
  3406. msm_property_install_range(&psde->property_info, "prefill_time", 0x0,
  3407. 0, ~0, 0, PLANE_PROP_PREFILL_TIME);
  3408. msm_property_install_blob(&psde->property_info, "capabilities",
  3409. DRM_MODE_PROP_IMMUTABLE, PLANE_PROP_INFO);
  3410. sde_kms_info_reset(info);
  3411. _sde_plane_setup_capabilities_blob(psde, master_plane_id, info,
  3412. catalog);
  3413. _sde_plane_install_colorproc_properties(psde, info);
  3414. msm_property_set_blob(&psde->property_info, &psde->blob_info,
  3415. info->data, SDE_KMS_INFO_DATALEN(info),
  3416. PLANE_PROP_INFO);
  3417. msm_property_install_enum(&psde->property_info, "fb_translation_mode",
  3418. 0x0, 0, e_fb_translation_mode,
  3419. ARRAY_SIZE(e_fb_translation_mode), 0,
  3420. PLANE_PROP_FB_TRANSLATION_MODE);
  3421. if (psde->pipe_hw->ops.set_ubwc_stats_roi)
  3422. msm_property_install_range(&psde->property_info, "ubwc_stats_roi",
  3423. 0, 0, 0xFFFFFFFF, 0, PLANE_PROP_UBWC_STATS_ROI);
  3424. vfree(info);
  3425. }
  3426. static inline void _sde_plane_set_csc_v1(struct sde_plane *psde,
  3427. void __user *usr_ptr)
  3428. {
  3429. struct sde_drm_csc_v1 csc_v1;
  3430. int i;
  3431. if (!psde) {
  3432. SDE_ERROR("invalid plane\n");
  3433. return;
  3434. }
  3435. psde->csc_usr_ptr = NULL;
  3436. if (!usr_ptr) {
  3437. SDE_DEBUG_PLANE(psde, "csc data removed\n");
  3438. return;
  3439. }
  3440. if (copy_from_user(&csc_v1, usr_ptr, sizeof(csc_v1))) {
  3441. SDE_ERROR_PLANE(psde, "failed to copy csc data\n");
  3442. return;
  3443. }
  3444. /* populate from user space */
  3445. for (i = 0; i < SDE_CSC_MATRIX_COEFF_SIZE; ++i)
  3446. psde->csc_cfg.csc_mv[i] = csc_v1.ctm_coeff[i] >> 16;
  3447. for (i = 0; i < SDE_CSC_BIAS_SIZE; ++i) {
  3448. psde->csc_cfg.csc_pre_bv[i] = csc_v1.pre_bias[i];
  3449. psde->csc_cfg.csc_post_bv[i] = csc_v1.post_bias[i];
  3450. }
  3451. for (i = 0; i < SDE_CSC_CLAMP_SIZE; ++i) {
  3452. psde->csc_cfg.csc_pre_lv[i] = csc_v1.pre_clamp[i];
  3453. psde->csc_cfg.csc_post_lv[i] = csc_v1.post_clamp[i];
  3454. }
  3455. psde->csc_usr_ptr = &psde->csc_cfg;
  3456. }
  3457. static inline void _sde_plane_set_scaler_v1(struct sde_plane *psde,
  3458. struct sde_plane_state *pstate, void __user *usr)
  3459. {
  3460. struct sde_drm_scaler_v1 scale_v1;
  3461. struct sde_hw_pixel_ext *pe;
  3462. int i;
  3463. if (!psde || !pstate) {
  3464. SDE_ERROR("invalid argument(s)\n");
  3465. return;
  3466. }
  3467. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_NONE;
  3468. if (!usr) {
  3469. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3470. return;
  3471. }
  3472. if (copy_from_user(&scale_v1, usr, sizeof(scale_v1))) {
  3473. SDE_ERROR_PLANE(psde, "failed to copy scale data\n");
  3474. return;
  3475. }
  3476. /* force property to be dirty, even if the pointer didn't change */
  3477. msm_property_set_dirty(&psde->property_info,
  3478. &pstate->property_state, PLANE_PROP_SCALER_V1);
  3479. /* populate from user space */
  3480. pe = &pstate->pixel_ext;
  3481. memset(pe, 0, sizeof(struct sde_hw_pixel_ext));
  3482. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3483. pe->init_phase_x[i] = scale_v1.init_phase_x[i];
  3484. pe->phase_step_x[i] = scale_v1.phase_step_x[i];
  3485. pe->init_phase_y[i] = scale_v1.init_phase_y[i];
  3486. pe->phase_step_y[i] = scale_v1.phase_step_y[i];
  3487. pe->horz_filter[i] = scale_v1.horz_filter[i];
  3488. pe->vert_filter[i] = scale_v1.vert_filter[i];
  3489. }
  3490. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3491. pe->left_ftch[i] = scale_v1.pe.left_ftch[i];
  3492. pe->right_ftch[i] = scale_v1.pe.right_ftch[i];
  3493. pe->left_rpt[i] = scale_v1.pe.left_rpt[i];
  3494. pe->right_rpt[i] = scale_v1.pe.right_rpt[i];
  3495. pe->roi_w[i] = scale_v1.pe.num_ext_pxls_lr[i];
  3496. pe->top_ftch[i] = scale_v1.pe.top_ftch[i];
  3497. pe->btm_ftch[i] = scale_v1.pe.btm_ftch[i];
  3498. pe->top_rpt[i] = scale_v1.pe.top_rpt[i];
  3499. pe->btm_rpt[i] = scale_v1.pe.btm_rpt[i];
  3500. pe->roi_h[i] = scale_v1.pe.num_ext_pxls_tb[i];
  3501. }
  3502. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_SCALER_V1;
  3503. SDE_EVT32_VERBOSE(DRMID(&psde->base));
  3504. SDE_DEBUG_PLANE(psde, "user property data copied\n");
  3505. }
  3506. static void _sde_plane_clear_predownscale_settings(
  3507. struct sde_plane_state *pstate)
  3508. {
  3509. pstate->pre_down.pre_downscale_x_0 = 0;
  3510. pstate->pre_down.pre_downscale_x_1 = 0;
  3511. pstate->pre_down.pre_downscale_y_0 = 0;
  3512. pstate->pre_down.pre_downscale_y_1 = 0;
  3513. }
  3514. static inline void _sde_plane_set_scaler_v2(struct sde_plane *psde,
  3515. struct sde_plane_state *pstate, void __user *usr)
  3516. {
  3517. struct sde_drm_scaler_v2 scale_v2;
  3518. struct sde_hw_pixel_ext *pe;
  3519. int i;
  3520. struct sde_hw_scaler3_cfg *cfg;
  3521. struct sde_hw_inline_pre_downscale_cfg *pd_cfg;
  3522. if (!psde || !pstate) {
  3523. SDE_ERROR("invalid argument(s)\n");
  3524. return;
  3525. }
  3526. cfg = &pstate->scaler3_cfg;
  3527. pd_cfg = &pstate->pre_down;
  3528. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_NONE;
  3529. if (!usr) {
  3530. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3531. cfg->enable = 0;
  3532. _sde_plane_clear_predownscale_settings(pstate);
  3533. goto end;
  3534. }
  3535. if (copy_from_user(&scale_v2, usr, sizeof(scale_v2))) {
  3536. SDE_ERROR_PLANE(psde, "failed to copy scale data\n");
  3537. return;
  3538. }
  3539. /* detach/ignore user data if 'disabled' */
  3540. if (!scale_v2.enable) {
  3541. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3542. cfg->enable = 0;
  3543. _sde_plane_clear_predownscale_settings(pstate);
  3544. goto end;
  3545. }
  3546. /* populate from user space */
  3547. sde_set_scaler_v2(cfg, &scale_v2);
  3548. if (_sde_plane_has_pre_downscale(psde)) {
  3549. pd_cfg->pre_downscale_x_0 = scale_v2.pre_downscale_x_0;
  3550. pd_cfg->pre_downscale_x_1 = scale_v2.pre_downscale_x_1;
  3551. pd_cfg->pre_downscale_y_0 = scale_v2.pre_downscale_y_0;
  3552. pd_cfg->pre_downscale_y_1 = scale_v2.pre_downscale_y_1;
  3553. }
  3554. pe = &pstate->pixel_ext;
  3555. memset(pe, 0, sizeof(struct sde_hw_pixel_ext));
  3556. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3557. pe->left_ftch[i] = scale_v2.pe.left_ftch[i];
  3558. pe->right_ftch[i] = scale_v2.pe.right_ftch[i];
  3559. pe->left_rpt[i] = scale_v2.pe.left_rpt[i];
  3560. pe->right_rpt[i] = scale_v2.pe.right_rpt[i];
  3561. pe->roi_w[i] = scale_v2.pe.num_ext_pxls_lr[i];
  3562. pe->top_ftch[i] = scale_v2.pe.top_ftch[i];
  3563. pe->btm_ftch[i] = scale_v2.pe.btm_ftch[i];
  3564. pe->top_rpt[i] = scale_v2.pe.top_rpt[i];
  3565. pe->btm_rpt[i] = scale_v2.pe.btm_rpt[i];
  3566. pe->roi_h[i] = scale_v2.pe.num_ext_pxls_tb[i];
  3567. }
  3568. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_SCALER_V2_CHECK;
  3569. end:
  3570. /* force property to be dirty, even if the pointer didn't change */
  3571. msm_property_set_dirty(&psde->property_info,
  3572. &pstate->property_state, PLANE_PROP_SCALER_V2);
  3573. SDE_EVT32_VERBOSE(DRMID(&psde->base), cfg->enable, cfg->de.enable,
  3574. cfg->src_width[0], cfg->src_height[0],
  3575. cfg->dst_width, cfg->dst_height);
  3576. SDE_DEBUG_PLANE(psde, "user property data copied\n");
  3577. }
  3578. static void _sde_plane_set_excl_rect_v1(struct sde_plane *psde,
  3579. struct sde_plane_state *pstate, void __user *usr_ptr)
  3580. {
  3581. struct drm_clip_rect excl_rect_v1;
  3582. if (!psde || !pstate) {
  3583. SDE_ERROR("invalid argument(s)\n");
  3584. return;
  3585. }
  3586. if (!usr_ptr) {
  3587. memset(&pstate->excl_rect, 0, sizeof(pstate->excl_rect));
  3588. SDE_DEBUG_PLANE(psde, "excl_rect data cleared\n");
  3589. return;
  3590. }
  3591. if (copy_from_user(&excl_rect_v1, usr_ptr, sizeof(excl_rect_v1))) {
  3592. SDE_ERROR_PLANE(psde, "failed to copy excl_rect data\n");
  3593. return;
  3594. }
  3595. /* populate from user space */
  3596. pstate->excl_rect.x = excl_rect_v1.x1;
  3597. pstate->excl_rect.y = excl_rect_v1.y1;
  3598. pstate->excl_rect.w = excl_rect_v1.x2 - excl_rect_v1.x1;
  3599. pstate->excl_rect.h = excl_rect_v1.y2 - excl_rect_v1.y1;
  3600. SDE_DEBUG_PLANE(psde, "excl_rect: {%d,%d,%d,%d}\n",
  3601. pstate->excl_rect.x, pstate->excl_rect.y,
  3602. pstate->excl_rect.w, pstate->excl_rect.h);
  3603. }
  3604. static void _sde_plane_set_ubwc_stats_roi(struct sde_plane *psde,
  3605. struct sde_plane_state *pstate, void __user *usr_ptr)
  3606. {
  3607. struct sde_drm_ubwc_stats_roi roi = {0};
  3608. if (!psde || !pstate) {
  3609. SDE_ERROR("invalid argument(s)\n");
  3610. return;
  3611. }
  3612. if (!usr_ptr) {
  3613. SDE_DEBUG_PLANE(psde, "ubwc roi disabled");
  3614. goto end;
  3615. }
  3616. if (copy_from_user(&roi, usr_ptr, sizeof(roi))) {
  3617. SDE_ERROR_PLANE(psde, "failed to copy ubwc stats roi");
  3618. return;
  3619. }
  3620. if (roi.y_coord0 > psde->pipe_cfg.src_rect.h || roi.y_coord1 > psde->pipe_cfg.src_rect.h) {
  3621. SDE_ERROR_PLANE(psde, "invalid ubwc roi y0 0x%x, y1 0x%x, src height 0x%x",
  3622. roi.y_coord0, roi.y_coord1, psde->pipe_cfg.src_rect.h);
  3623. memset(&roi, 0, sizeof(roi));
  3624. }
  3625. end:
  3626. SDE_EVT32(psde, roi.y_coord0, roi.y_coord1);
  3627. memcpy(&pstate->ubwc_stats_roi, &roi, sizeof(struct sde_drm_ubwc_stats_roi));
  3628. }
  3629. static int sde_plane_atomic_set_property(struct drm_plane *plane,
  3630. struct drm_plane_state *state, struct drm_property *property,
  3631. uint64_t val)
  3632. {
  3633. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3634. struct sde_plane_state *pstate;
  3635. int idx, ret = -EINVAL;
  3636. SDE_DEBUG_PLANE(psde, "\n");
  3637. if (!plane) {
  3638. SDE_ERROR("invalid plane\n");
  3639. } else if (!state) {
  3640. SDE_ERROR_PLANE(psde, "invalid state\n");
  3641. } else {
  3642. pstate = to_sde_plane_state(state);
  3643. ret = msm_property_atomic_set(&psde->property_info,
  3644. &pstate->property_state, property, val);
  3645. if (!ret) {
  3646. idx = msm_property_index(&psde->property_info,
  3647. property);
  3648. switch (idx) {
  3649. case PLANE_PROP_INPUT_FENCE:
  3650. _sde_plane_set_input_fence(psde, pstate, val);
  3651. break;
  3652. case PLANE_PROP_CSC_V1:
  3653. case PLANE_PROP_CSC_DMA_V1:
  3654. _sde_plane_set_csc_v1(psde, (void __user *)val);
  3655. break;
  3656. case PLANE_PROP_SCALER_V1:
  3657. _sde_plane_set_scaler_v1(psde, pstate,
  3658. (void *)(uintptr_t)val);
  3659. break;
  3660. case PLANE_PROP_SCALER_V2:
  3661. _sde_plane_set_scaler_v2(psde, pstate,
  3662. (void *)(uintptr_t)val);
  3663. break;
  3664. case PLANE_PROP_EXCL_RECT_V1:
  3665. _sde_plane_set_excl_rect_v1(psde, pstate,
  3666. (void *)(uintptr_t)val);
  3667. break;
  3668. case PLANE_PROP_UBWC_STATS_ROI:
  3669. _sde_plane_set_ubwc_stats_roi(psde, pstate,
  3670. (void __user *)(uintptr_t)val);
  3671. break;
  3672. default:
  3673. /* nothing to do */
  3674. break;
  3675. }
  3676. }
  3677. }
  3678. SDE_DEBUG_PLANE(psde, "%s[%d] <= 0x%llx ret=%d\n",
  3679. property->name, property->base.id, val, ret);
  3680. return ret;
  3681. }
  3682. static int sde_plane_atomic_get_property(struct drm_plane *plane,
  3683. const struct drm_plane_state *state,
  3684. struct drm_property *property, uint64_t *val)
  3685. {
  3686. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3687. struct sde_plane_state *pstate;
  3688. int ret = -EINVAL;
  3689. if (!plane) {
  3690. SDE_ERROR("invalid plane\n");
  3691. } else if (!state) {
  3692. SDE_ERROR("invalid state\n");
  3693. } else {
  3694. SDE_DEBUG_PLANE(psde, "\n");
  3695. pstate = to_sde_plane_state(state);
  3696. ret = msm_property_atomic_get(&psde->property_info,
  3697. &pstate->property_state, property, val);
  3698. }
  3699. return ret;
  3700. }
  3701. int sde_plane_helper_reset_custom_properties(struct drm_plane *plane,
  3702. struct drm_plane_state *plane_state)
  3703. {
  3704. struct sde_plane *psde;
  3705. struct sde_plane_state *pstate;
  3706. struct drm_property *drm_prop;
  3707. enum msm_mdp_plane_property prop_idx;
  3708. if (!plane || !plane_state) {
  3709. SDE_ERROR("invalid params\n");
  3710. return -EINVAL;
  3711. }
  3712. psde = to_sde_plane(plane);
  3713. pstate = to_sde_plane_state(plane_state);
  3714. pstate->static_cache_state = CACHE_STATE_DISABLED;
  3715. for (prop_idx = 0; prop_idx < PLANE_PROP_COUNT; prop_idx++) {
  3716. uint64_t val = pstate->property_values[prop_idx].value;
  3717. uint64_t def;
  3718. int ret;
  3719. drm_prop = msm_property_index_to_drm_property(
  3720. &psde->property_info, prop_idx);
  3721. if (!drm_prop) {
  3722. /* not all props will be installed, based on caps */
  3723. SDE_DEBUG_PLANE(psde, "invalid property index %d\n",
  3724. prop_idx);
  3725. continue;
  3726. }
  3727. def = msm_property_get_default(&psde->property_info, prop_idx);
  3728. if (val == def)
  3729. continue;
  3730. SDE_DEBUG_PLANE(psde, "set prop %s idx %d from %llu to %llu\n",
  3731. drm_prop->name, prop_idx, val, def);
  3732. ret = sde_plane_atomic_set_property(plane, plane_state,
  3733. drm_prop, def);
  3734. if (ret) {
  3735. SDE_ERROR_PLANE(psde,
  3736. "set property failed, idx %d ret %d\n",
  3737. prop_idx, ret);
  3738. continue;
  3739. }
  3740. }
  3741. return 0;
  3742. }
  3743. static void sde_plane_destroy(struct drm_plane *plane)
  3744. {
  3745. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3746. SDE_DEBUG_PLANE(psde, "\n");
  3747. if (psde) {
  3748. _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL);
  3749. if (psde->blob_info)
  3750. drm_property_blob_put(psde->blob_info);
  3751. msm_property_destroy(&psde->property_info);
  3752. mutex_destroy(&psde->lock);
  3753. /* this will destroy the states as well */
  3754. drm_plane_cleanup(plane);
  3755. if (psde->pipe_hw)
  3756. sde_hw_sspp_destroy(psde->pipe_hw);
  3757. kfree(psde);
  3758. }
  3759. }
  3760. void sde_plane_destroy_fb(struct drm_plane_state *state)
  3761. {
  3762. struct sde_plane_state *pstate;
  3763. if (!state) {
  3764. SDE_ERROR("invalid arg state %d\n", !state);
  3765. return;
  3766. }
  3767. pstate = to_sde_plane_state(state);
  3768. if (sde_plane_get_property(pstate, PLANE_PROP_FB_TRANSLATION_MODE) ==
  3769. SDE_DRM_FB_SEC) {
  3770. /* remove ref count for frame buffers */
  3771. if (state->fb) {
  3772. drm_framebuffer_put(state->fb);
  3773. state->fb = NULL;
  3774. }
  3775. }
  3776. }
  3777. static void sde_plane_destroy_state(struct drm_plane *plane,
  3778. struct drm_plane_state *state)
  3779. {
  3780. struct sde_plane *psde;
  3781. struct sde_plane_state *pstate;
  3782. if (!plane || !state) {
  3783. SDE_ERROR("invalid arg(s), plane %d state %d\n",
  3784. !plane, !state);
  3785. return;
  3786. }
  3787. psde = to_sde_plane(plane);
  3788. pstate = to_sde_plane_state(state);
  3789. SDE_DEBUG_PLANE(psde, "\n");
  3790. /* remove ref count for frame buffers */
  3791. if (state->fb)
  3792. drm_framebuffer_put(state->fb);
  3793. /* remove ref count for fence */
  3794. if (pstate->input_fence)
  3795. sde_sync_put(pstate->input_fence);
  3796. pstate->input_fence = 0;
  3797. /* destroy value helper */
  3798. msm_property_destroy_state(&psde->property_info, pstate,
  3799. &pstate->property_state);
  3800. }
  3801. static struct drm_plane_state *
  3802. sde_plane_duplicate_state(struct drm_plane *plane)
  3803. {
  3804. struct sde_plane *psde;
  3805. struct sde_plane_state *pstate;
  3806. struct sde_plane_state *old_state;
  3807. struct drm_property *drm_prop;
  3808. uint64_t input_fence_default;
  3809. if (!plane) {
  3810. SDE_ERROR("invalid plane\n");
  3811. return NULL;
  3812. } else if (!plane->state) {
  3813. SDE_ERROR("invalid plane state\n");
  3814. return NULL;
  3815. }
  3816. old_state = to_sde_plane_state(plane->state);
  3817. psde = to_sde_plane(plane);
  3818. if (old_state->cont_splash_populated) {
  3819. plane->state->crtc = NULL;
  3820. old_state->cont_splash_populated = false;
  3821. }
  3822. pstate = msm_property_alloc_state(&psde->property_info);
  3823. if (!pstate) {
  3824. SDE_ERROR_PLANE(psde, "failed to allocate state\n");
  3825. return NULL;
  3826. }
  3827. SDE_DEBUG_PLANE(psde, "\n");
  3828. /* duplicate value helper */
  3829. msm_property_duplicate_state(&psde->property_info, old_state, pstate,
  3830. &pstate->property_state, pstate->property_values);
  3831. /* clear out any input fence */
  3832. pstate->input_fence = 0;
  3833. input_fence_default = msm_property_get_default(
  3834. &psde->property_info, PLANE_PROP_INPUT_FENCE);
  3835. drm_prop = msm_property_index_to_drm_property(
  3836. &psde->property_info, PLANE_PROP_INPUT_FENCE);
  3837. if (msm_property_atomic_set(&psde->property_info,
  3838. &pstate->property_state, drm_prop,
  3839. input_fence_default))
  3840. SDE_DEBUG_PLANE(psde,
  3841. "error clearing duplicated input fence\n");
  3842. pstate->dirty = 0x0;
  3843. pstate->pending = false;
  3844. __drm_atomic_helper_plane_duplicate_state(plane, &pstate->base);
  3845. /* reset layout offset */
  3846. if (pstate->layout_offset) {
  3847. if (pstate->layout_offset > 0)
  3848. pstate->base.crtc_x += pstate->layout_offset;
  3849. pstate->layout = SDE_LAYOUT_NONE;
  3850. pstate->layout_offset = 0;
  3851. }
  3852. return &pstate->base;
  3853. }
  3854. static void sde_plane_reset(struct drm_plane *plane)
  3855. {
  3856. struct sde_plane *psde;
  3857. struct sde_plane_state *pstate;
  3858. if (!plane) {
  3859. SDE_ERROR("invalid plane\n");
  3860. return;
  3861. }
  3862. psde = to_sde_plane(plane);
  3863. SDE_DEBUG_PLANE(psde, "\n");
  3864. if (plane->state && !sde_crtc_is_reset_required(plane->state->crtc)) {
  3865. SDE_DEBUG_PLANE(psde, "avoid reset for plane\n");
  3866. return;
  3867. }
  3868. /* remove previous state, if present */
  3869. if (plane->state) {
  3870. sde_plane_destroy_state(plane, plane->state);
  3871. plane->state = 0;
  3872. }
  3873. pstate = msm_property_alloc_state(&psde->property_info);
  3874. if (!pstate) {
  3875. SDE_ERROR_PLANE(psde, "failed to allocate state\n");
  3876. return;
  3877. }
  3878. /* reset value helper */
  3879. msm_property_reset_state(&psde->property_info, pstate,
  3880. &pstate->property_state,
  3881. pstate->property_values);
  3882. pstate->base.plane = plane;
  3883. plane->state = &pstate->base;
  3884. }
  3885. void sde_plane_get_frame_data(struct drm_plane *plane,
  3886. struct sde_drm_plane_frame_data *data)
  3887. {
  3888. struct sde_plane *psde;
  3889. struct sde_plane_state *pstate;
  3890. struct sde_drm_ubwc_stats_data *ubwc_stats;
  3891. if (!plane) {
  3892. SDE_ERROR("invalid plane\n");
  3893. return;
  3894. }
  3895. psde = to_sde_plane(plane);
  3896. pstate = to_sde_plane_state(plane->state);
  3897. ubwc_stats = &data->ubwc_stats;
  3898. data->plane_id = DRMID(plane);
  3899. if (psde->pipe_hw->ops.get_ubwc_stats_data) {
  3900. memcpy(&ubwc_stats->roi, &pstate->ubwc_stats_roi,
  3901. sizeof(struct sde_drm_ubwc_stats_roi));
  3902. psde->pipe_hw->ops.get_ubwc_stats_data(psde->pipe_hw,
  3903. pstate->multirect_index, ubwc_stats);
  3904. }
  3905. if (psde->pipe_hw->ops.get_ubwc_error)
  3906. ubwc_stats->error = psde->pipe_hw->ops.get_ubwc_error(psde->pipe_hw,
  3907. pstate->multirect_index);
  3908. if (psde->pipe_hw->ops.clear_ubwc_error && ubwc_stats->error)
  3909. psde->pipe_hw->ops.clear_ubwc_error(psde->pipe_hw, pstate->multirect_index);
  3910. if (psde->pipe_hw->ops.get_meta_error)
  3911. ubwc_stats->meta_error = psde->pipe_hw->ops.get_meta_error(psde->pipe_hw,
  3912. pstate->multirect_index);
  3913. if (psde->pipe_hw->ops.clear_meta_error && ubwc_stats->meta_error)
  3914. psde->pipe_hw->ops.clear_meta_error(psde->pipe_hw, pstate->multirect_index);
  3915. if (ubwc_stats->error || ubwc_stats->meta_error) {
  3916. SDE_EVT32(DRMID(plane), ubwc_stats->error, ubwc_stats->meta_error,
  3917. SDE_EVTLOG_ERROR);
  3918. SDE_DEBUG_PLANE(psde, "ubwc_error:0x%x meta_error:0x%x\n",
  3919. ubwc_stats->error, ubwc_stats->meta_error);
  3920. }
  3921. }
  3922. #if IS_ENABLED(CONFIG_DEBUG_FS)
  3923. static ssize_t _sde_plane_danger_read(struct file *file,
  3924. char __user *buff, size_t count, loff_t *ppos)
  3925. {
  3926. struct sde_kms *kms = file->private_data;
  3927. struct sde_mdss_cfg *cfg = kms->catalog;
  3928. int len = 0;
  3929. char buf[40] = {'\0'};
  3930. if (!cfg)
  3931. return -ENODEV;
  3932. if (*ppos)
  3933. return 0; /* the end */
  3934. len = snprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl);
  3935. if (len < 0 || len >= sizeof(buf))
  3936. return 0;
  3937. if ((count < sizeof(buf)) || copy_to_user(buff, buf, len))
  3938. return -EFAULT;
  3939. *ppos += len; /* increase offset */
  3940. return len;
  3941. }
  3942. static void _sde_plane_set_danger_state(struct sde_kms *kms, bool enable)
  3943. {
  3944. struct drm_plane *plane;
  3945. drm_for_each_plane(plane, kms->dev) {
  3946. if (plane->fb && plane->state) {
  3947. sde_plane_danger_signal_ctrl(plane, enable);
  3948. SDE_DEBUG("plane:%d img:%dx%d ",
  3949. plane->base.id, plane->fb->width,
  3950. plane->fb->height);
  3951. SDE_DEBUG("src[%d,%d,%d,%d] dst[%d,%d,%d,%d]\n",
  3952. plane->state->src_x >> 16,
  3953. plane->state->src_y >> 16,
  3954. plane->state->src_w >> 16,
  3955. plane->state->src_h >> 16,
  3956. plane->state->crtc_x, plane->state->crtc_y,
  3957. plane->state->crtc_w, plane->state->crtc_h);
  3958. } else {
  3959. SDE_DEBUG("Inactive plane:%d\n", plane->base.id);
  3960. }
  3961. }
  3962. }
  3963. static ssize_t _sde_plane_danger_write(struct file *file,
  3964. const char __user *user_buf, size_t count, loff_t *ppos)
  3965. {
  3966. struct sde_kms *kms = file->private_data;
  3967. struct sde_mdss_cfg *cfg = kms->catalog;
  3968. int disable_panic;
  3969. char buf[10];
  3970. if (!cfg)
  3971. return -EFAULT;
  3972. if (count >= sizeof(buf))
  3973. return -EFAULT;
  3974. if (copy_from_user(buf, user_buf, count))
  3975. return -EFAULT;
  3976. buf[count] = 0; /* end of string */
  3977. if (kstrtoint(buf, 0, &disable_panic))
  3978. return -EFAULT;
  3979. if (disable_panic) {
  3980. /* Disable panic signal for all active pipes */
  3981. SDE_DEBUG("Disabling danger:\n");
  3982. _sde_plane_set_danger_state(kms, false);
  3983. kms->has_danger_ctrl = false;
  3984. } else {
  3985. /* Enable panic signal for all active pipes */
  3986. SDE_DEBUG("Enabling danger:\n");
  3987. kms->has_danger_ctrl = true;
  3988. _sde_plane_set_danger_state(kms, true);
  3989. }
  3990. return count;
  3991. }
  3992. static const struct file_operations sde_plane_danger_enable = {
  3993. .open = simple_open,
  3994. .read = _sde_plane_danger_read,
  3995. .write = _sde_plane_danger_write,
  3996. };
  3997. static int _sde_plane_init_debugfs(struct drm_plane *plane)
  3998. {
  3999. struct sde_plane *psde;
  4000. struct sde_kms *kms;
  4001. struct msm_drm_private *priv;
  4002. const struct sde_sspp_sub_blks *sblk = 0;
  4003. const struct sde_sspp_cfg *cfg = 0;
  4004. if (!plane || !plane->dev) {
  4005. SDE_ERROR("invalid arguments\n");
  4006. return -EINVAL;
  4007. }
  4008. priv = plane->dev->dev_private;
  4009. if (!priv || !priv->kms) {
  4010. SDE_ERROR("invalid KMS reference\n");
  4011. return -EINVAL;
  4012. }
  4013. kms = to_sde_kms(priv->kms);
  4014. psde = to_sde_plane(plane);
  4015. if (psde && psde->pipe_hw)
  4016. cfg = psde->pipe_hw->cap;
  4017. if (cfg)
  4018. sblk = cfg->sblk;
  4019. if (!sblk)
  4020. return 0;
  4021. /* create overall sub-directory for the pipe */
  4022. psde->debugfs_root =
  4023. debugfs_create_dir(psde->pipe_name,
  4024. plane->dev->primary->debugfs_root);
  4025. if (!psde->debugfs_root)
  4026. return -ENOMEM;
  4027. /* don't error check these */
  4028. debugfs_create_x64("features", 0400,
  4029. psde->debugfs_root, &psde->features);
  4030. if (cfg->features & BIT(SDE_SSPP_SCALER_QSEED3) ||
  4031. cfg->features & BIT(SDE_SSPP_SCALER_QSEED3LITE) ||
  4032. cfg->features & BIT(SDE_SSPP_SCALER_QSEED2))
  4033. debugfs_create_bool("default_scaling",
  4034. 0600,
  4035. psde->debugfs_root,
  4036. &psde->debugfs_default_scale);
  4037. if (cfg->features & BIT(SDE_SSPP_TRUE_INLINE_ROT)) {
  4038. debugfs_create_u32("in_rot_max_downscale_rt_num",
  4039. 0600,
  4040. psde->debugfs_root,
  4041. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_rt_num);
  4042. debugfs_create_u32("in_rot_max_downscale_rt_denom",
  4043. 0600,
  4044. psde->debugfs_root,
  4045. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_rt_denom);
  4046. debugfs_create_u32("in_rot_max_downscale_nrt",
  4047. 0600,
  4048. psde->debugfs_root,
  4049. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_nrt);
  4050. debugfs_create_u32("in_rot_max_height",
  4051. 0600,
  4052. psde->debugfs_root,
  4053. (u32 *) &psde->pipe_sblk->in_rot_maxheight);
  4054. }
  4055. debugfs_create_u32("xin_id",
  4056. 0400,
  4057. psde->debugfs_root,
  4058. (u32 *) &cfg->xin_id);
  4059. debugfs_create_x32("creq_vblank",
  4060. 0600,
  4061. psde->debugfs_root,
  4062. (u32 *) &sblk->creq_vblank);
  4063. debugfs_create_x32("danger_vblank",
  4064. 0600,
  4065. psde->debugfs_root,
  4066. (u32 *) &sblk->danger_vblank);
  4067. debugfs_create_file("disable_danger",
  4068. 0600,
  4069. psde->debugfs_root,
  4070. kms, &sde_plane_danger_enable);
  4071. return 0;
  4072. }
  4073. static void _sde_plane_destroy_debugfs(struct drm_plane *plane)
  4074. {
  4075. struct sde_plane *psde;
  4076. if (!plane)
  4077. return;
  4078. psde = to_sde_plane(plane);
  4079. debugfs_remove_recursive(psde->debugfs_root);
  4080. }
  4081. #else
  4082. static int _sde_plane_init_debugfs(struct drm_plane *plane)
  4083. {
  4084. return 0;
  4085. }
  4086. static void _sde_plane_destroy_debugfs(struct drm_plane *plane)
  4087. {
  4088. }
  4089. #endif /* CONFIG_DEBUG_FS */
  4090. static int sde_plane_late_register(struct drm_plane *plane)
  4091. {
  4092. return _sde_plane_init_debugfs(plane);
  4093. }
  4094. static void sde_plane_early_unregister(struct drm_plane *plane)
  4095. {
  4096. _sde_plane_destroy_debugfs(plane);
  4097. }
  4098. static const struct drm_plane_funcs sde_plane_funcs = {
  4099. .update_plane = drm_atomic_helper_update_plane,
  4100. .disable_plane = drm_atomic_helper_disable_plane,
  4101. .destroy = sde_plane_destroy,
  4102. .atomic_set_property = sde_plane_atomic_set_property,
  4103. .atomic_get_property = sde_plane_atomic_get_property,
  4104. .reset = sde_plane_reset,
  4105. .atomic_duplicate_state = sde_plane_duplicate_state,
  4106. .atomic_destroy_state = sde_plane_destroy_state,
  4107. .late_register = sde_plane_late_register,
  4108. .early_unregister = sde_plane_early_unregister,
  4109. };
  4110. static const struct drm_plane_helper_funcs sde_plane_helper_funcs = {
  4111. .prepare_fb = sde_plane_prepare_fb,
  4112. .cleanup_fb = sde_plane_cleanup_fb,
  4113. .atomic_check = sde_plane_atomic_check,
  4114. .atomic_update = sde_plane_atomic_update,
  4115. };
  4116. enum sde_sspp sde_plane_pipe(struct drm_plane *plane)
  4117. {
  4118. return plane ? to_sde_plane(plane)->pipe : SSPP_NONE;
  4119. }
  4120. bool is_sde_plane_virtual(struct drm_plane *plane)
  4121. {
  4122. return plane ? to_sde_plane(plane)->is_virtual : false;
  4123. }
  4124. /* initialize plane */
  4125. struct drm_plane *sde_plane_init(struct drm_device *dev,
  4126. uint32_t pipe, bool primary_plane,
  4127. unsigned long possible_crtcs, u32 master_plane_id)
  4128. {
  4129. struct drm_plane *plane = NULL, *master_plane = NULL;
  4130. const struct sde_format_extended *format_list;
  4131. struct sde_plane *psde;
  4132. struct msm_drm_private *priv;
  4133. struct sde_kms *kms;
  4134. enum drm_plane_type type;
  4135. struct sde_vbif_clk_client clk_client;
  4136. int ret = -EINVAL;
  4137. if (!dev) {
  4138. SDE_ERROR("[%u]device is NULL\n", pipe);
  4139. goto exit;
  4140. }
  4141. priv = dev->dev_private;
  4142. if (!priv) {
  4143. SDE_ERROR("[%u]private data is NULL\n", pipe);
  4144. goto exit;
  4145. }
  4146. if (!priv->kms) {
  4147. SDE_ERROR("[%u]invalid KMS reference\n", pipe);
  4148. goto exit;
  4149. }
  4150. kms = to_sde_kms(priv->kms);
  4151. if (!kms->catalog) {
  4152. SDE_ERROR("[%u]invalid catalog reference\n", pipe);
  4153. goto exit;
  4154. }
  4155. /* create and zero local structure */
  4156. psde = kzalloc(sizeof(*psde), GFP_KERNEL);
  4157. if (!psde) {
  4158. SDE_ERROR("[%u]failed to allocate local plane struct\n", pipe);
  4159. ret = -ENOMEM;
  4160. goto exit;
  4161. }
  4162. /* cache local stuff for later */
  4163. plane = &psde->base;
  4164. psde->pipe = pipe;
  4165. psde->is_virtual = (master_plane_id != 0);
  4166. INIT_LIST_HEAD(&psde->mplane_list);
  4167. master_plane = drm_plane_find(dev, NULL, master_plane_id);
  4168. if (master_plane) {
  4169. struct sde_plane *mpsde = to_sde_plane(master_plane);
  4170. list_add_tail(&psde->mplane_list, &mpsde->mplane_list);
  4171. }
  4172. /* initialize underlying h/w driver */
  4173. psde->pipe_hw = sde_hw_sspp_init(pipe, kms->mmio, kms->catalog, psde->is_virtual,
  4174. &clk_client);
  4175. if (IS_ERR(psde->pipe_hw)) {
  4176. SDE_ERROR("[%u]SSPP init failed\n", pipe);
  4177. ret = PTR_ERR(psde->pipe_hw);
  4178. goto clean_plane;
  4179. } else if (!psde->pipe_hw->cap || !psde->pipe_hw->cap->sblk) {
  4180. SDE_ERROR("[%u]SSPP init returned invalid cfg\n", pipe);
  4181. goto clean_sspp;
  4182. }
  4183. if (test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, kms->catalog->features)) {
  4184. ret = sde_vbif_clk_register(kms, &clk_client);
  4185. if (ret) {
  4186. SDE_ERROR("failed to register vbif client %d\n",
  4187. clk_client.clk_ctrl);
  4188. goto clean_sspp;
  4189. }
  4190. }
  4191. /* cache features mask for later */
  4192. psde->features = psde->pipe_hw->cap->features_ext;
  4193. psde->perf_features = psde->pipe_hw->cap->perf_features;
  4194. psde->pipe_sblk = psde->pipe_hw->cap->sblk;
  4195. if (!psde->pipe_sblk) {
  4196. SDE_ERROR("[%u]invalid sblk\n", pipe);
  4197. goto clean_sspp;
  4198. }
  4199. if (psde->is_virtual)
  4200. format_list = psde->pipe_sblk->virt_format_list;
  4201. else
  4202. format_list = psde->pipe_sblk->format_list;
  4203. psde->nformats = sde_populate_formats(format_list,
  4204. psde->formats,
  4205. 0,
  4206. ARRAY_SIZE(psde->formats));
  4207. if (!psde->nformats) {
  4208. SDE_ERROR("[%u]no valid formats for plane\n", pipe);
  4209. goto clean_sspp;
  4210. }
  4211. if (primary_plane)
  4212. type = DRM_PLANE_TYPE_PRIMARY;
  4213. else
  4214. type = DRM_PLANE_TYPE_OVERLAY;
  4215. ret = drm_universal_plane_init(dev, plane, 0xff, &sde_plane_funcs,
  4216. psde->formats, psde->nformats,
  4217. NULL, type, NULL);
  4218. if (ret)
  4219. goto clean_sspp;
  4220. /* Populate static array of plane property flags */
  4221. _sde_plane_map_prop_to_dirty_bits();
  4222. /* success! finalize initialization */
  4223. drm_plane_helper_add(plane, &sde_plane_helper_funcs);
  4224. msm_property_init(&psde->property_info, &plane->base, dev,
  4225. priv->plane_property, psde->property_data,
  4226. PLANE_PROP_COUNT, PLANE_PROP_BLOBCOUNT,
  4227. sizeof(struct sde_plane_state));
  4228. _sde_plane_install_properties(plane, kms->catalog, master_plane_id);
  4229. /* save user friendly pipe name for later */
  4230. snprintf(psde->pipe_name, SDE_NAME_SIZE, "plane%u", plane->base.id);
  4231. mutex_init(&psde->lock);
  4232. SDE_DEBUG("%s created for pipe:%u id:%u master:%u\n", psde->pipe_name,
  4233. pipe, plane->base.id, master_plane_id);
  4234. return plane;
  4235. clean_sspp:
  4236. if (psde && psde->pipe_hw)
  4237. sde_hw_sspp_destroy(psde->pipe_hw);
  4238. clean_plane:
  4239. kfree(psde);
  4240. exit:
  4241. return ERR_PTR(ret);
  4242. }
  4243. void sde_plane_add_data_to_minidump_va(struct drm_plane *plane)
  4244. {
  4245. struct sde_plane *sde_plane;
  4246. struct sde_plane_state *pstate;
  4247. sde_plane = to_sde_plane(plane);
  4248. pstate = to_sde_plane_state(plane->state);
  4249. sde_mini_dump_add_va_region("sde_plane", sizeof(*sde_plane), sde_plane);
  4250. sde_mini_dump_add_va_region("plane_state", sizeof(*pstate), pstate);
  4251. }