sde_plane.c 130 KB

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