sde_plane.c 129 KB

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