sde_plane.c 124 KB

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