sde_plane.c 131 KB

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