sde_plane.c 136 KB

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