sde_plane.c 127 KB

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