sde_plane.c 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600
  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_helper(struct sde_plane *psde,
  2178. const struct sde_format *fmt,
  2179. struct sde_rect src, struct sde_rect dst,
  2180. u32 width, u32 height)
  2181. {
  2182. int ret = 0;
  2183. u32 min_src_size = SDE_FORMAT_IS_YUV(fmt) ? 2 : 1;
  2184. if (SDE_FORMAT_IS_YUV(fmt) &&
  2185. (!(psde->features & SDE_SSPP_SCALER) ||
  2186. !(psde->features & (BIT(SDE_SSPP_CSC)
  2187. | BIT(SDE_SSPP_CSC_10BIT))))) {
  2188. SDE_ERROR_PLANE(psde,
  2189. "plane doesn't have scaler/csc for yuv\n");
  2190. ret = -EINVAL;
  2191. /* check src bounds */
  2192. } else if (width > MAX_IMG_WIDTH || height > MAX_IMG_HEIGHT ||
  2193. src.w < min_src_size || src.h < min_src_size ||
  2194. CHECK_LAYER_BOUNDS(src.x, src.w, width) ||
  2195. CHECK_LAYER_BOUNDS(src.y, src.h, height)) {
  2196. SDE_ERROR_PLANE(psde, "invalid source %u, %u, %ux%u\n",
  2197. src.x, src.y, src.w, src.h);
  2198. ret = -E2BIG;
  2199. /* valid yuv image */
  2200. } else if (SDE_FORMAT_IS_YUV(fmt) && ((src.x & 0x1) || (src.y & 0x1) ||
  2201. (src.w & 0x1) || (src.h & 0x1))) {
  2202. SDE_ERROR_PLANE(psde, "invalid yuv source %u, %u, %ux%u\n",
  2203. src.x, src.y, src.w, src.h);
  2204. ret = -EINVAL;
  2205. /* min dst support */
  2206. } else if (dst.w < 0x1 || dst.h < 0x1) {
  2207. SDE_ERROR_PLANE(psde, "invalid dest rect %u, %u, %ux%u\n",
  2208. dst.x, dst.y, dst.w, dst.h);
  2209. ret = -EINVAL;
  2210. }
  2211. return ret;
  2212. }
  2213. static int sde_plane_sspp_atomic_check(struct drm_plane *plane,
  2214. struct drm_plane_state *state)
  2215. {
  2216. int ret = 0;
  2217. struct sde_plane *psde;
  2218. struct sde_plane_state *pstate;
  2219. const struct msm_format *msm_fmt;
  2220. const struct sde_format *fmt;
  2221. struct sde_rect src, dst;
  2222. bool q16_data = true;
  2223. struct drm_framebuffer *fb;
  2224. u32 width;
  2225. u32 height;
  2226. psde = to_sde_plane(plane);
  2227. pstate = to_sde_plane_state(state);
  2228. if (!psde->pipe_sblk) {
  2229. SDE_ERROR_PLANE(psde, "invalid catalog\n");
  2230. return -EINVAL;
  2231. }
  2232. /* src values are in Q16 fixed point, convert to integer */
  2233. POPULATE_RECT(&src, state->src_x, state->src_y,
  2234. state->src_w, state->src_h, q16_data);
  2235. POPULATE_RECT(&dst, state->crtc_x, state->crtc_y, state->crtc_w,
  2236. state->crtc_h, !q16_data);
  2237. SDE_DEBUG_PLANE(psde, "check %d -> %d\n",
  2238. sde_plane_enabled(plane->state), sde_plane_enabled(state));
  2239. if (!sde_plane_enabled(state))
  2240. goto modeset_update;
  2241. fb = state->fb;
  2242. width = fb ? state->fb->width : 0x0;
  2243. height = fb ? state->fb->height : 0x0;
  2244. SDE_DEBUG("plane%d sspp:%x/%dx%d/%4.4s/%llx\n",
  2245. plane->base.id,
  2246. pstate->rotation,
  2247. width, height,
  2248. fb ? (char *) &state->fb->format->format : 0x0,
  2249. fb ? state->fb->modifier : 0x0);
  2250. SDE_DEBUG("src:%dx%d %d,%d crtc:%dx%d+%d+%d\n",
  2251. state->src_w >> 16, state->src_h >> 16,
  2252. state->src_x >> 16, state->src_y >> 16,
  2253. state->crtc_w, state->crtc_h,
  2254. state->crtc_x, state->crtc_y);
  2255. msm_fmt = msm_framebuffer_format(fb);
  2256. fmt = to_sde_format(msm_fmt);
  2257. ret = _sde_plane_sspp_atomic_check_helper(psde, fmt, src, dst, width,
  2258. height);
  2259. if (ret)
  2260. return ret;
  2261. ret = _sde_atomic_check_decimation_scaler(state, psde, fmt, pstate,
  2262. &src, &dst, width, height);
  2263. if (ret)
  2264. return ret;
  2265. ret = _sde_atomic_check_excl_rect(psde, pstate,
  2266. &src, fmt, ret);
  2267. if (ret)
  2268. return ret;
  2269. ret = _sde_plane_validate_shared_crtc(psde, state);
  2270. if (ret)
  2271. return ret;
  2272. pstate->const_alpha_en = fmt->alpha_enable &&
  2273. (SDE_DRM_BLEND_OP_OPAQUE !=
  2274. sde_plane_get_property(pstate, PLANE_PROP_BLEND_OP)) &&
  2275. (pstate->stage != SDE_STAGE_0);
  2276. modeset_update:
  2277. if (!ret)
  2278. _sde_plane_sspp_atomic_check_mode_changed(psde,
  2279. state, plane->state);
  2280. return ret;
  2281. }
  2282. static int sde_plane_atomic_check(struct drm_plane *plane,
  2283. struct drm_plane_state *state)
  2284. {
  2285. int ret = 0;
  2286. struct sde_plane *psde;
  2287. struct sde_plane_state *pstate;
  2288. if (!plane || !state) {
  2289. SDE_ERROR("invalid arg(s), plane %d state %d\n",
  2290. !plane, !state);
  2291. ret = -EINVAL;
  2292. goto exit;
  2293. }
  2294. psde = to_sde_plane(plane);
  2295. pstate = to_sde_plane_state(state);
  2296. SDE_DEBUG_PLANE(psde, "\n");
  2297. ret = sde_plane_rot_atomic_check(plane, state);
  2298. if (ret)
  2299. goto exit;
  2300. ret = sde_plane_sspp_atomic_check(plane, state);
  2301. exit:
  2302. return ret;
  2303. }
  2304. void sde_plane_flush(struct drm_plane *plane)
  2305. {
  2306. struct sde_plane *psde;
  2307. struct sde_plane_state *pstate;
  2308. if (!plane || !plane->state) {
  2309. SDE_ERROR("invalid plane\n");
  2310. return;
  2311. }
  2312. psde = to_sde_plane(plane);
  2313. pstate = to_sde_plane_state(plane->state);
  2314. /*
  2315. * These updates have to be done immediately before the plane flush
  2316. * timing, and may not be moved to the atomic_update/mode_set functions.
  2317. */
  2318. if (psde->is_error)
  2319. /* force white frame with 100% alpha pipe output on error */
  2320. _sde_plane_color_fill(psde, 0xFFFFFF, 0xFF);
  2321. else if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG)
  2322. /* force 100% alpha */
  2323. _sde_plane_color_fill(psde, psde->color_fill, 0xFF);
  2324. else if (psde->pipe_hw && psde->csc_ptr && psde->pipe_hw->ops.setup_csc)
  2325. psde->pipe_hw->ops.setup_csc(psde->pipe_hw, psde->csc_ptr);
  2326. /* flag h/w flush complete */
  2327. if (plane->state)
  2328. pstate->pending = false;
  2329. }
  2330. /**
  2331. * sde_plane_set_error: enable/disable error condition
  2332. * @plane: pointer to drm_plane structure
  2333. */
  2334. void sde_plane_set_error(struct drm_plane *plane, bool error)
  2335. {
  2336. struct sde_plane *psde;
  2337. if (!plane)
  2338. return;
  2339. psde = to_sde_plane(plane);
  2340. psde->is_error = error;
  2341. }
  2342. static void _sde_plane_sspp_setup_sys_cache(struct sde_plane *psde,
  2343. struct sde_plane_state *pstate, const struct sde_format *fmt)
  2344. {
  2345. if (!psde->pipe_hw->ops.setup_sys_cache ||
  2346. !(psde->perf_features & BIT(SDE_PERF_SSPP_SYS_CACHE)))
  2347. return;
  2348. SDE_DEBUG("features:0x%x rotation:0x%x\n",
  2349. psde->features, pstate->rotation);
  2350. if ((pstate->rotation & DRM_MODE_ROTATE_90) &&
  2351. sde_format_is_tp10_ubwc(fmt)) {
  2352. pstate->sc_cfg.rd_en = true;
  2353. pstate->sc_cfg.rd_scid =
  2354. psde->pipe_sblk->llcc_scid;
  2355. pstate->sc_cfg.flags = SSPP_SYS_CACHE_EN_FLAG |
  2356. SSPP_SYS_CACHE_SCID;
  2357. } else {
  2358. pstate->sc_cfg.rd_en = false;
  2359. pstate->sc_cfg.rd_scid = 0x0;
  2360. pstate->sc_cfg.flags = SSPP_SYS_CACHE_EN_FLAG |
  2361. SSPP_SYS_CACHE_SCID;
  2362. }
  2363. psde->pipe_hw->ops.setup_sys_cache(
  2364. psde->pipe_hw, &pstate->sc_cfg);
  2365. }
  2366. static void _sde_plane_map_prop_to_dirty_bits(void)
  2367. {
  2368. plane_prop_array[PLANE_PROP_SCALER_V1] =
  2369. plane_prop_array[PLANE_PROP_SCALER_V2] =
  2370. plane_prop_array[PLANE_PROP_SCALER_LUT_ED] =
  2371. plane_prop_array[PLANE_PROP_SCALER_LUT_CIR] =
  2372. plane_prop_array[PLANE_PROP_SCALER_LUT_SEP] =
  2373. plane_prop_array[PLANE_PROP_H_DECIMATE] =
  2374. plane_prop_array[PLANE_PROP_V_DECIMATE] =
  2375. plane_prop_array[PLANE_PROP_SRC_CONFIG] =
  2376. plane_prop_array[PLANE_PROP_ZPOS] =
  2377. plane_prop_array[PLANE_PROP_EXCL_RECT_V1] =
  2378. SDE_PLANE_DIRTY_RECTS;
  2379. plane_prop_array[PLANE_PROP_CSC_V1] =
  2380. plane_prop_array[PLANE_PROP_CSC_DMA_V1] =
  2381. plane_prop_array[PLANE_PROP_INVERSE_PMA] =
  2382. SDE_PLANE_DIRTY_FORMAT;
  2383. plane_prop_array[PLANE_PROP_MULTIRECT_MODE] =
  2384. plane_prop_array[PLANE_PROP_COLOR_FILL] =
  2385. SDE_PLANE_DIRTY_ALL;
  2386. /* no special action required */
  2387. plane_prop_array[PLANE_PROP_INFO] =
  2388. plane_prop_array[PLANE_PROP_ALPHA] =
  2389. plane_prop_array[PLANE_PROP_INPUT_FENCE] =
  2390. plane_prop_array[PLANE_PROP_BLEND_OP] = 0;
  2391. plane_prop_array[PLANE_PROP_FB_TRANSLATION_MODE] =
  2392. SDE_PLANE_DIRTY_FB_TRANSLATION_MODE;
  2393. plane_prop_array[PLANE_PROP_PREFILL_SIZE] =
  2394. plane_prop_array[PLANE_PROP_PREFILL_TIME] =
  2395. SDE_PLANE_DIRTY_PERF;
  2396. plane_prop_array[PLANE_PROP_VIG_GAMUT] = SDE_PLANE_DIRTY_VIG_GAMUT;
  2397. plane_prop_array[PLANE_PROP_VIG_IGC] = SDE_PLANE_DIRTY_VIG_IGC;
  2398. plane_prop_array[PLANE_PROP_DMA_IGC] = SDE_PLANE_DIRTY_DMA_IGC;
  2399. plane_prop_array[PLANE_PROP_DMA_GC] = SDE_PLANE_DIRTY_DMA_GC;
  2400. plane_prop_array[PLANE_PROP_SKIN_COLOR] =
  2401. plane_prop_array[PLANE_PROP_SKY_COLOR] =
  2402. plane_prop_array[PLANE_PROP_FOLIAGE_COLOR] =
  2403. plane_prop_array[PLANE_PROP_HUE_ADJUST] =
  2404. plane_prop_array[PLANE_PROP_SATURATION_ADJUST] =
  2405. plane_prop_array[PLANE_PROP_VALUE_ADJUST] =
  2406. plane_prop_array[PLANE_PROP_CONTRAST_ADJUST] =
  2407. SDE_PLANE_DIRTY_ALL;
  2408. }
  2409. static inline bool _sde_plane_allow_uidle(struct sde_plane *psde,
  2410. struct sde_rect *src, struct sde_rect *dst)
  2411. {
  2412. u32 max_downscale = psde->catalog->uidle_cfg.max_dwnscale;
  2413. u32 downscale = (src->h * 1000)/dst->h;
  2414. return (downscale > max_downscale) ? false : true;
  2415. }
  2416. static void _sde_plane_setup_uidle(struct drm_crtc *crtc,
  2417. struct sde_plane *psde, struct sde_plane_state *pstate,
  2418. struct sde_rect *src, struct sde_rect *dst)
  2419. {
  2420. struct sde_hw_pipe_uidle_cfg cfg;
  2421. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  2422. u32 line_time = sde_get_linetime(&crtc->mode,
  2423. sde_crtc->src_bpp, sde_crtc->target_bpp); /* nS */
  2424. u32 fal1_target_idle_time_ns =
  2425. psde->catalog->uidle_cfg.fal1_target_idle_time * 1000; /* nS */
  2426. u32 fal10_target_idle_time_ns =
  2427. psde->catalog->uidle_cfg.fal10_target_idle_time * 1000; /* nS */
  2428. u32 fal10_threshold =
  2429. psde->catalog->uidle_cfg.fal10_threshold; /* uS */
  2430. if (line_time && fal10_threshold && fal10_target_idle_time_ns &&
  2431. fal1_target_idle_time_ns) {
  2432. cfg.enable = _sde_plane_allow_uidle(psde, src, dst);
  2433. cfg.fal10_threshold = fal10_threshold;
  2434. cfg.fal10_exit_threshold = fal10_threshold + 2;
  2435. cfg.fal1_threshold = 1 +
  2436. (fal1_target_idle_time_ns*1000/line_time*2)/1000;
  2437. cfg.fal_allowed_threshold = fal10_threshold +
  2438. (fal10_target_idle_time_ns*1000/line_time*2)/1000;
  2439. } else {
  2440. SDE_ERROR("invalid settings, will disable UIDLE %d %d %d %d\n",
  2441. line_time, fal10_threshold, fal10_target_idle_time_ns,
  2442. fal1_target_idle_time_ns);
  2443. memset(&cfg, 0, sizeof(struct sde_hw_pipe_uidle_cfg));
  2444. }
  2445. SDE_DEBUG_PLANE(psde,
  2446. "tholds: fal10=%d fal10_exit=%d fal1=%d fal_allowed=%d\n",
  2447. cfg.fal10_threshold, cfg.fal10_exit_threshold,
  2448. cfg.fal1_threshold, cfg.fal_allowed_threshold);
  2449. SDE_DEBUG_PLANE(psde,
  2450. "times: line:%d fal1_idle:%d fal10_idle:%d dwnscale:%d\n",
  2451. line_time, fal1_target_idle_time_ns,
  2452. fal10_target_idle_time_ns,
  2453. psde->catalog->uidle_cfg.max_dwnscale);
  2454. SDE_EVT32_VERBOSE(cfg.enable,
  2455. cfg.fal10_threshold, cfg.fal10_exit_threshold,
  2456. cfg.fal1_threshold, cfg.fal_allowed_threshold,
  2457. psde->catalog->uidle_cfg.max_dwnscale);
  2458. psde->pipe_hw->ops.setup_uidle(
  2459. psde->pipe_hw, &cfg,
  2460. pstate->multirect_index);
  2461. }
  2462. static void _sde_plane_update_secure_session(struct sde_plane *psde,
  2463. struct sde_plane_state *pstate)
  2464. {
  2465. bool enable = false;
  2466. int mode = sde_plane_get_property(pstate,
  2467. PLANE_PROP_FB_TRANSLATION_MODE);
  2468. if ((mode == SDE_DRM_FB_SEC) ||
  2469. (mode == SDE_DRM_FB_SEC_DIR_TRANS))
  2470. enable = true;
  2471. /* update secure session flag */
  2472. psde->pipe_hw->ops.setup_secure_address(psde->pipe_hw,
  2473. pstate->multirect_index,
  2474. enable);
  2475. }
  2476. static void _sde_plane_update_roi_config(struct drm_plane *plane,
  2477. struct drm_crtc *crtc, struct drm_framebuffer *fb)
  2478. {
  2479. const struct sde_format *fmt;
  2480. const struct msm_format *msm_fmt;
  2481. struct sde_plane *psde;
  2482. struct drm_plane_state *state;
  2483. struct sde_plane_state *pstate;
  2484. struct sde_rect src, dst;
  2485. const struct sde_rect *crtc_roi;
  2486. bool q16_data = true;
  2487. int idx;
  2488. psde = to_sde_plane(plane);
  2489. state = plane->state;
  2490. pstate = to_sde_plane_state(state);
  2491. msm_fmt = msm_framebuffer_format(fb);
  2492. if (!msm_fmt) {
  2493. SDE_ERROR("crtc%d plane%d: null format\n",
  2494. DRMID(crtc), DRMID(plane));
  2495. return;
  2496. }
  2497. fmt = to_sde_format(msm_fmt);
  2498. POPULATE_RECT(&src, state->src_x, state->src_y,
  2499. state->src_w, state->src_h, q16_data);
  2500. POPULATE_RECT(&dst, state->crtc_x, state->crtc_y,
  2501. state->crtc_w, state->crtc_h, !q16_data);
  2502. SDE_DEBUG_PLANE(psde,
  2503. "FB[%u] %u,%u,%ux%u->crtc%u %d,%d,%ux%u, %4.4s ubwc %d\n",
  2504. fb->base.id, src.x, src.y, src.w, src.h,
  2505. crtc->base.id, dst.x, dst.y, dst.w, dst.h,
  2506. (char *)&fmt->base.pixel_format,
  2507. SDE_FORMAT_IS_UBWC(fmt));
  2508. if (sde_plane_get_property(pstate, PLANE_PROP_SRC_CONFIG) &
  2509. BIT(SDE_DRM_DEINTERLACE)) {
  2510. SDE_DEBUG_PLANE(psde, "deinterlace\n");
  2511. for (idx = 0; idx < SDE_MAX_PLANES; ++idx)
  2512. psde->pipe_cfg.layout.plane_pitch[idx] <<= 1;
  2513. src.h /= 2;
  2514. src.y = DIV_ROUND_UP(src.y, 2);
  2515. src.y &= ~0x1;
  2516. }
  2517. /*
  2518. * adjust layer mixer position of the sspp in the presence
  2519. * of a partial update to the active lm origin
  2520. */
  2521. sde_crtc_get_crtc_roi(crtc->state, &crtc_roi);
  2522. dst.x -= crtc_roi->x;
  2523. dst.y -= crtc_roi->y;
  2524. /* check for UIDLE */
  2525. if (psde->pipe_hw->ops.setup_uidle)
  2526. _sde_plane_setup_uidle(crtc, psde, pstate, &src, &dst);
  2527. psde->pipe_cfg.src_rect = src;
  2528. psde->pipe_cfg.dst_rect = dst;
  2529. _sde_plane_setup_scaler(psde, pstate, fmt, false);
  2530. /* check for color fill */
  2531. psde->color_fill = (uint32_t)sde_plane_get_property(pstate,
  2532. PLANE_PROP_COLOR_FILL);
  2533. if (psde->color_fill & SDE_PLANE_COLOR_FILL_FLAG) {
  2534. /* skip remaining processing on color fill */
  2535. pstate->dirty = 0x0;
  2536. } else if (psde->pipe_hw->ops.setup_rects) {
  2537. psde->pipe_hw->ops.setup_rects(psde->pipe_hw,
  2538. &psde->pipe_cfg,
  2539. pstate->multirect_index);
  2540. }
  2541. if (psde->pipe_hw->ops.setup_pe &&
  2542. (pstate->multirect_index != SDE_SSPP_RECT_1))
  2543. psde->pipe_hw->ops.setup_pe(psde->pipe_hw,
  2544. &pstate->pixel_ext);
  2545. /**
  2546. * when programmed in multirect mode, scalar block will be
  2547. * bypassed. Still we need to update alpha and bitwidth
  2548. * ONLY for RECT0
  2549. */
  2550. if (psde->pipe_hw->ops.setup_scaler &&
  2551. pstate->multirect_index != SDE_SSPP_RECT_1) {
  2552. psde->pipe_hw->ctl = _sde_plane_get_hw_ctl(plane);
  2553. psde->pipe_hw->ops.setup_scaler(psde->pipe_hw,
  2554. &psde->pipe_cfg, &pstate->pixel_ext,
  2555. &pstate->scaler3_cfg);
  2556. }
  2557. /* update excl rect */
  2558. if (psde->pipe_hw->ops.setup_excl_rect)
  2559. psde->pipe_hw->ops.setup_excl_rect(psde->pipe_hw,
  2560. &pstate->excl_rect,
  2561. pstate->multirect_index);
  2562. if (psde->pipe_hw->ops.setup_multirect)
  2563. psde->pipe_hw->ops.setup_multirect(
  2564. psde->pipe_hw,
  2565. pstate->multirect_index,
  2566. pstate->multirect_mode);
  2567. }
  2568. static void _sde_plane_update_format_and_rects(struct sde_plane *psde,
  2569. struct sde_plane_state *pstate, const struct sde_format *fmt)
  2570. {
  2571. uint32_t src_flags = 0;
  2572. SDE_DEBUG_PLANE(psde, "rotation 0x%X\n", pstate->rotation);
  2573. if (pstate->rotation & DRM_MODE_REFLECT_X)
  2574. src_flags |= SDE_SSPP_FLIP_LR;
  2575. if (pstate->rotation & DRM_MODE_REFLECT_Y)
  2576. src_flags |= SDE_SSPP_FLIP_UD;
  2577. if (pstate->rotation & DRM_MODE_ROTATE_90)
  2578. src_flags |= SDE_SSPP_ROT_90;
  2579. /* update format */
  2580. psde->pipe_hw->ops.setup_format(psde->pipe_hw, fmt,
  2581. pstate->const_alpha_en, src_flags,
  2582. pstate->multirect_index);
  2583. if (psde->pipe_hw->ops.setup_cdp) {
  2584. struct sde_hw_pipe_cdp_cfg *cdp_cfg = &pstate->cdp_cfg;
  2585. memset(cdp_cfg, 0, sizeof(struct sde_hw_pipe_cdp_cfg));
  2586. cdp_cfg->enable = psde->catalog->perf.cdp_cfg
  2587. [SDE_PERF_CDP_USAGE_RT].rd_enable;
  2588. cdp_cfg->ubwc_meta_enable =
  2589. SDE_FORMAT_IS_UBWC(fmt);
  2590. cdp_cfg->tile_amortize_enable =
  2591. SDE_FORMAT_IS_UBWC(fmt) ||
  2592. SDE_FORMAT_IS_TILE(fmt);
  2593. cdp_cfg->preload_ahead = SDE_WB_CDP_PRELOAD_AHEAD_64;
  2594. psde->pipe_hw->ops.setup_cdp(psde->pipe_hw, cdp_cfg,
  2595. pstate->multirect_index);
  2596. }
  2597. _sde_plane_sspp_setup_sys_cache(psde, pstate, fmt);
  2598. /* update csc */
  2599. if (SDE_FORMAT_IS_YUV(fmt))
  2600. _sde_plane_setup_csc(psde);
  2601. else
  2602. psde->csc_ptr = 0;
  2603. if (psde->pipe_hw->ops.setup_inverse_pma) {
  2604. uint32_t pma_mode = 0;
  2605. if (fmt->alpha_enable)
  2606. pma_mode = (uint32_t) sde_plane_get_property(
  2607. pstate, PLANE_PROP_INVERSE_PMA);
  2608. psde->pipe_hw->ops.setup_inverse_pma(psde->pipe_hw,
  2609. pstate->multirect_index, pma_mode);
  2610. }
  2611. if (psde->pipe_hw->ops.setup_dgm_csc)
  2612. psde->pipe_hw->ops.setup_dgm_csc(psde->pipe_hw,
  2613. pstate->multirect_index, psde->csc_usr_ptr);
  2614. }
  2615. static void _sde_plane_update_sharpening(struct sde_plane *psde)
  2616. {
  2617. psde->sharp_cfg.strength = SHARP_STRENGTH_DEFAULT;
  2618. psde->sharp_cfg.edge_thr = SHARP_EDGE_THR_DEFAULT;
  2619. psde->sharp_cfg.smooth_thr = SHARP_SMOOTH_THR_DEFAULT;
  2620. psde->sharp_cfg.noise_thr = SHARP_NOISE_THR_DEFAULT;
  2621. psde->pipe_hw->ops.setup_sharpening(psde->pipe_hw,
  2622. &psde->sharp_cfg);
  2623. }
  2624. static void _sde_plane_update_properties(struct drm_plane *plane,
  2625. struct drm_crtc *crtc, struct drm_framebuffer *fb)
  2626. {
  2627. uint32_t nplanes;
  2628. const struct msm_format *msm_fmt;
  2629. const struct sde_format *fmt;
  2630. struct sde_plane *psde;
  2631. struct drm_plane_state *state;
  2632. struct sde_plane_state *pstate;
  2633. psde = to_sde_plane(plane);
  2634. state = plane->state;
  2635. pstate = to_sde_plane_state(state);
  2636. if (!pstate) {
  2637. SDE_ERROR("invalid plane state for plane%d\n", DRMID(plane));
  2638. return;
  2639. }
  2640. msm_fmt = msm_framebuffer_format(fb);
  2641. if (!msm_fmt) {
  2642. SDE_ERROR("crtc%d plane%d: null format\n",
  2643. DRMID(crtc), DRMID(plane));
  2644. return;
  2645. }
  2646. fmt = to_sde_format(msm_fmt);
  2647. nplanes = fmt->num_planes;
  2648. /* update secure session flag */
  2649. if (pstate->dirty & SDE_PLANE_DIRTY_FB_TRANSLATION_MODE)
  2650. _sde_plane_update_secure_session(psde, pstate);
  2651. /* update roi config */
  2652. if (pstate->dirty & SDE_PLANE_DIRTY_RECTS)
  2653. _sde_plane_update_roi_config(plane, crtc, fb);
  2654. if ((pstate->dirty & SDE_PLANE_DIRTY_FORMAT ||
  2655. pstate->dirty & SDE_PLANE_DIRTY_RECTS) &&
  2656. psde->pipe_hw->ops.setup_format)
  2657. _sde_plane_update_format_and_rects(psde, pstate, fmt);
  2658. sde_color_process_plane_setup(plane);
  2659. /* update sharpening */
  2660. if ((pstate->dirty & SDE_PLANE_DIRTY_SHARPEN) &&
  2661. psde->pipe_hw->ops.setup_sharpening)
  2662. _sde_plane_update_sharpening(psde);
  2663. _sde_plane_set_qos_lut(plane, crtc, fb);
  2664. if (plane->type != DRM_PLANE_TYPE_CURSOR) {
  2665. _sde_plane_set_qos_ctrl(plane, true, SDE_PLANE_QOS_PANIC_CTRL);
  2666. _sde_plane_set_ot_limit(plane, crtc);
  2667. if (pstate->dirty & SDE_PLANE_DIRTY_PERF)
  2668. _sde_plane_set_ts_prefill(plane, pstate);
  2669. }
  2670. _sde_plane_set_qos_remap(plane);
  2671. /* clear dirty */
  2672. pstate->dirty = 0x0;
  2673. }
  2674. static int sde_plane_sspp_atomic_update(struct drm_plane *plane,
  2675. struct drm_plane_state *old_state)
  2676. {
  2677. struct sde_plane *psde;
  2678. struct drm_plane_state *state;
  2679. struct sde_plane_state *pstate;
  2680. struct sde_plane_state *old_pstate;
  2681. struct drm_crtc *crtc;
  2682. struct drm_framebuffer *fb;
  2683. int idx;
  2684. int dirty_prop_flag;
  2685. if (!plane) {
  2686. SDE_ERROR("invalid plane\n");
  2687. return -EINVAL;
  2688. } else if (!plane->state) {
  2689. SDE_ERROR("invalid plane state\n");
  2690. return -EINVAL;
  2691. } else if (!old_state) {
  2692. SDE_ERROR("invalid old state\n");
  2693. return -EINVAL;
  2694. }
  2695. psde = to_sde_plane(plane);
  2696. state = plane->state;
  2697. pstate = to_sde_plane_state(state);
  2698. old_pstate = to_sde_plane_state(old_state);
  2699. crtc = state->crtc;
  2700. fb = state->fb;
  2701. if (!crtc || !fb) {
  2702. SDE_ERROR_PLANE(psde, "invalid crtc %d or fb %d\n",
  2703. !crtc, !fb);
  2704. return -EINVAL;
  2705. }
  2706. SDE_DEBUG(
  2707. "plane%d sspp:%dx%d/%4.4s/%llx/%dx%d+%d+%d/%x crtc:%dx%d+%d+%d\n",
  2708. plane->base.id,
  2709. state->fb->width, state->fb->height,
  2710. (char *) &state->fb->format->format,
  2711. state->fb->modifier,
  2712. state->src_w >> 16, state->src_h >> 16,
  2713. state->src_x >> 16, state->src_y >> 16,
  2714. pstate->rotation,
  2715. state->crtc_w, state->crtc_h,
  2716. state->crtc_x, state->crtc_y);
  2717. /* force reprogramming of all the parameters, if the flag is set */
  2718. if (psde->revalidate) {
  2719. SDE_DEBUG("plane:%d - reconfigure all the parameters\n",
  2720. plane->base.id);
  2721. pstate->dirty = SDE_PLANE_DIRTY_ALL | SDE_PLANE_DIRTY_CP;
  2722. psde->revalidate = false;
  2723. }
  2724. /* determine what needs to be refreshed */
  2725. mutex_lock(&psde->property_info.property_lock);
  2726. while ((idx = msm_property_pop_dirty(&psde->property_info,
  2727. &pstate->property_state)) >= 0) {
  2728. dirty_prop_flag = plane_prop_array[idx];
  2729. pstate->dirty |= dirty_prop_flag;
  2730. }
  2731. mutex_unlock(&psde->property_info.property_lock);
  2732. /**
  2733. * since plane_atomic_check is invoked before crtc_atomic_check
  2734. * in the commit sequence, all the parameters for updating the
  2735. * plane dirty flag will not be available during
  2736. * plane_atomic_check as some features params are updated
  2737. * in crtc_atomic_check (eg.:sDMA). So check for mode_change
  2738. * before sspp update.
  2739. */
  2740. _sde_plane_sspp_atomic_check_mode_changed(psde, state,
  2741. old_state);
  2742. /* re-program the output rects always if partial update roi changed */
  2743. if (sde_crtc_is_crtc_roi_dirty(crtc->state))
  2744. pstate->dirty |= SDE_PLANE_DIRTY_RECTS;
  2745. if (pstate->dirty & SDE_PLANE_DIRTY_RECTS)
  2746. memset(&(psde->pipe_cfg), 0, sizeof(struct sde_hw_pipe_cfg));
  2747. _sde_plane_set_scanout(plane, pstate, &psde->pipe_cfg, fb);
  2748. /* early out if nothing dirty */
  2749. if (!pstate->dirty)
  2750. return 0;
  2751. pstate->pending = true;
  2752. psde->is_rt_pipe = sde_crtc_is_rt_client(crtc, crtc->state);
  2753. _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL);
  2754. _sde_plane_update_properties(plane, crtc, fb);
  2755. return 0;
  2756. }
  2757. static void _sde_plane_atomic_disable(struct drm_plane *plane,
  2758. struct drm_plane_state *old_state)
  2759. {
  2760. struct sde_plane *psde;
  2761. struct drm_plane_state *state;
  2762. struct sde_plane_state *pstate;
  2763. if (!plane) {
  2764. SDE_ERROR("invalid plane\n");
  2765. return;
  2766. } else if (!plane->state) {
  2767. SDE_ERROR("invalid plane state\n");
  2768. return;
  2769. } else if (!old_state) {
  2770. SDE_ERROR("invalid old state\n");
  2771. return;
  2772. }
  2773. psde = to_sde_plane(plane);
  2774. state = plane->state;
  2775. pstate = to_sde_plane_state(state);
  2776. SDE_EVT32(DRMID(plane), is_sde_plane_virtual(plane),
  2777. pstate->multirect_mode);
  2778. pstate->pending = true;
  2779. if (is_sde_plane_virtual(plane) &&
  2780. psde->pipe_hw && psde->pipe_hw->ops.setup_multirect)
  2781. psde->pipe_hw->ops.setup_multirect(psde->pipe_hw,
  2782. SDE_SSPP_RECT_SOLO, SDE_SSPP_MULTIRECT_NONE);
  2783. }
  2784. static void sde_plane_atomic_update(struct drm_plane *plane,
  2785. struct drm_plane_state *old_state)
  2786. {
  2787. struct sde_plane *psde;
  2788. struct drm_plane_state *state;
  2789. if (!plane) {
  2790. SDE_ERROR("invalid plane\n");
  2791. return;
  2792. } else if (!plane->state) {
  2793. SDE_ERROR("invalid plane state\n");
  2794. return;
  2795. }
  2796. psde = to_sde_plane(plane);
  2797. psde->is_error = false;
  2798. state = plane->state;
  2799. SDE_DEBUG_PLANE(psde, "\n");
  2800. if (!sde_plane_enabled(state)) {
  2801. _sde_plane_atomic_disable(plane, old_state);
  2802. } else {
  2803. int ret;
  2804. ret = sde_plane_sspp_atomic_update(plane, old_state);
  2805. /* atomic_check should have ensured that this doesn't fail */
  2806. WARN_ON(ret < 0);
  2807. }
  2808. }
  2809. void sde_plane_restore(struct drm_plane *plane)
  2810. {
  2811. struct sde_plane *psde;
  2812. if (!plane || !plane->state) {
  2813. SDE_ERROR("invalid plane\n");
  2814. return;
  2815. }
  2816. psde = to_sde_plane(plane);
  2817. /*
  2818. * Revalidate is only true here if idle PC occurred and
  2819. * there is no plane state update in current commit cycle.
  2820. */
  2821. if (!psde->revalidate)
  2822. return;
  2823. SDE_DEBUG_PLANE(psde, "\n");
  2824. /* last plane state is same as current state */
  2825. sde_plane_atomic_update(plane, plane->state);
  2826. }
  2827. bool sde_plane_is_cache_required(struct drm_plane *plane)
  2828. {
  2829. struct sde_plane_state *pstate;
  2830. if (!plane || !plane->state) {
  2831. SDE_ERROR("invalid plane\n");
  2832. return false;
  2833. }
  2834. pstate = to_sde_plane_state(plane->state);
  2835. /* check if llcc is required for the plane */
  2836. if (pstate->sc_cfg.rd_en)
  2837. return true;
  2838. else
  2839. return false;
  2840. }
  2841. static void _sde_plane_install_master_only_properties(struct sde_plane *psde)
  2842. {
  2843. char feature_name[256];
  2844. if (psde->pipe_sblk->maxhdeciexp) {
  2845. msm_property_install_range(&psde->property_info,
  2846. "h_decimate", 0x0, 0,
  2847. psde->pipe_sblk->maxhdeciexp, 0,
  2848. PLANE_PROP_H_DECIMATE);
  2849. }
  2850. if (psde->pipe_sblk->maxvdeciexp) {
  2851. msm_property_install_range(&psde->property_info,
  2852. "v_decimate", 0x0, 0,
  2853. psde->pipe_sblk->maxvdeciexp, 0,
  2854. PLANE_PROP_V_DECIMATE);
  2855. }
  2856. if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3)) {
  2857. msm_property_install_range(
  2858. &psde->property_info, "scaler_v2",
  2859. 0x0, 0, ~0, 0, PLANE_PROP_SCALER_V2);
  2860. msm_property_install_blob(&psde->property_info,
  2861. "lut_ed", 0, PLANE_PROP_SCALER_LUT_ED);
  2862. msm_property_install_blob(&psde->property_info,
  2863. "lut_cir", 0,
  2864. PLANE_PROP_SCALER_LUT_CIR);
  2865. msm_property_install_blob(&psde->property_info,
  2866. "lut_sep", 0,
  2867. PLANE_PROP_SCALER_LUT_SEP);
  2868. } else if (psde->features & BIT(SDE_SSPP_SCALER_QSEED3LITE)) {
  2869. msm_property_install_range(
  2870. &psde->property_info, "scaler_v2",
  2871. 0x0, 0, ~0, 0, PLANE_PROP_SCALER_V2);
  2872. msm_property_install_blob(&psde->property_info,
  2873. "lut_sep", 0,
  2874. PLANE_PROP_SCALER_LUT_SEP);
  2875. } else if (psde->features & SDE_SSPP_SCALER) {
  2876. msm_property_install_range(
  2877. &psde->property_info, "scaler_v1", 0x0,
  2878. 0, ~0, 0, PLANE_PROP_SCALER_V1);
  2879. }
  2880. if (psde->features & BIT(SDE_SSPP_CSC) ||
  2881. psde->features & BIT(SDE_SSPP_CSC_10BIT))
  2882. msm_property_install_volatile_range(
  2883. &psde->property_info, "csc_v1", 0x0,
  2884. 0, ~0, 0, PLANE_PROP_CSC_V1);
  2885. if (psde->features & BIT(SDE_SSPP_HSIC)) {
  2886. snprintf(feature_name, sizeof(feature_name), "%s%d",
  2887. "SDE_SSPP_HUE_V",
  2888. psde->pipe_sblk->hsic_blk.version >> 16);
  2889. msm_property_install_range(&psde->property_info,
  2890. feature_name, 0, 0, 0xFFFFFFFF, 0,
  2891. PLANE_PROP_HUE_ADJUST);
  2892. snprintf(feature_name, sizeof(feature_name), "%s%d",
  2893. "SDE_SSPP_SATURATION_V",
  2894. psde->pipe_sblk->hsic_blk.version >> 16);
  2895. msm_property_install_range(&psde->property_info,
  2896. feature_name, 0, 0, 0xFFFFFFFF, 0,
  2897. PLANE_PROP_SATURATION_ADJUST);
  2898. snprintf(feature_name, sizeof(feature_name), "%s%d",
  2899. "SDE_SSPP_VALUE_V",
  2900. psde->pipe_sblk->hsic_blk.version >> 16);
  2901. msm_property_install_range(&psde->property_info,
  2902. feature_name, 0, 0, 0xFFFFFFFF, 0,
  2903. PLANE_PROP_VALUE_ADJUST);
  2904. snprintf(feature_name, sizeof(feature_name), "%s%d",
  2905. "SDE_SSPP_CONTRAST_V",
  2906. psde->pipe_sblk->hsic_blk.version >> 16);
  2907. msm_property_install_range(&psde->property_info,
  2908. feature_name, 0, 0, 0xFFFFFFFF, 0,
  2909. PLANE_PROP_CONTRAST_ADJUST);
  2910. }
  2911. }
  2912. /* helper to install properties which are common to planes and crtcs */
  2913. static void _sde_plane_install_properties(struct drm_plane *plane,
  2914. struct sde_mdss_cfg *catalog, u32 master_plane_id)
  2915. {
  2916. static const struct drm_prop_enum_list e_blend_op[] = {
  2917. {SDE_DRM_BLEND_OP_NOT_DEFINED, "not_defined"},
  2918. {SDE_DRM_BLEND_OP_OPAQUE, "opaque"},
  2919. {SDE_DRM_BLEND_OP_PREMULTIPLIED, "premultiplied"},
  2920. {SDE_DRM_BLEND_OP_COVERAGE, "coverage"},
  2921. {SDE_DRM_BLEND_OP_SKIP, "skip_blending"},
  2922. };
  2923. static const struct drm_prop_enum_list e_src_config[] = {
  2924. {SDE_DRM_DEINTERLACE, "deinterlace"}
  2925. };
  2926. static const struct drm_prop_enum_list e_fb_translation_mode[] = {
  2927. {SDE_DRM_FB_NON_SEC, "non_sec"},
  2928. {SDE_DRM_FB_SEC, "sec"},
  2929. {SDE_DRM_FB_NON_SEC_DIR_TRANS, "non_sec_direct_translation"},
  2930. {SDE_DRM_FB_SEC_DIR_TRANS, "sec_direct_translation"},
  2931. };
  2932. static const struct drm_prop_enum_list e_multirect_mode[] = {
  2933. {SDE_SSPP_MULTIRECT_NONE, "none"},
  2934. {SDE_SSPP_MULTIRECT_PARALLEL, "parallel"},
  2935. {SDE_SSPP_MULTIRECT_TIME_MX, "serial"},
  2936. };
  2937. const struct sde_format_extended *format_list;
  2938. struct sde_kms_info *info;
  2939. struct sde_plane *psde = to_sde_plane(plane);
  2940. bool is_master;
  2941. int zpos_max = 255;
  2942. int zpos_def = 0;
  2943. char feature_name[256];
  2944. uint32_t index;
  2945. if (!plane || !psde) {
  2946. SDE_ERROR("invalid plane\n");
  2947. return;
  2948. } else if (!psde->pipe_hw || !psde->pipe_sblk) {
  2949. SDE_ERROR("invalid plane, pipe_hw %d pipe_sblk %d\n",
  2950. !psde->pipe_hw, !psde->pipe_sblk);
  2951. return;
  2952. } else if (!catalog) {
  2953. SDE_ERROR("invalid catalog\n");
  2954. return;
  2955. }
  2956. psde->catalog = catalog;
  2957. is_master = !psde->is_virtual;
  2958. if (sde_is_custom_client()) {
  2959. if (catalog->mixer_count &&
  2960. catalog->mixer[0].sblk->maxblendstages) {
  2961. zpos_max = catalog->mixer[0].sblk->maxblendstages - 1;
  2962. if (catalog->has_base_layer &&
  2963. (zpos_max > SDE_STAGE_MAX - 1))
  2964. zpos_max = SDE_STAGE_MAX - 1;
  2965. else if (zpos_max > SDE_STAGE_MAX - SDE_STAGE_0 - 1)
  2966. zpos_max = SDE_STAGE_MAX - SDE_STAGE_0 - 1;
  2967. }
  2968. } else if (plane->type != DRM_PLANE_TYPE_PRIMARY) {
  2969. /* reserve zpos == 0 for primary planes */
  2970. zpos_def = drm_plane_index(plane) + 1;
  2971. }
  2972. msm_property_install_range(&psde->property_info, "zpos",
  2973. 0x0, 0, zpos_max, zpos_def, PLANE_PROP_ZPOS);
  2974. msm_property_install_range(&psde->property_info, "alpha",
  2975. 0x0, 0, 255, 255, PLANE_PROP_ALPHA);
  2976. /* linux default file descriptor range on each process */
  2977. msm_property_install_range(&psde->property_info, "input_fence",
  2978. 0x0, 0, INR_OPEN_MAX, 0, PLANE_PROP_INPUT_FENCE);
  2979. if (is_master)
  2980. _sde_plane_install_master_only_properties(psde);
  2981. if (psde->features & BIT(SDE_SSPP_EXCL_RECT))
  2982. msm_property_install_volatile_range(&psde->property_info,
  2983. "excl_rect_v1", 0x0, 0, ~0, 0, PLANE_PROP_EXCL_RECT_V1);
  2984. sde_plane_rot_install_properties(plane, catalog);
  2985. msm_property_install_enum(&psde->property_info, "blend_op", 0x0, 0,
  2986. e_blend_op, ARRAY_SIZE(e_blend_op), PLANE_PROP_BLEND_OP);
  2987. msm_property_install_enum(&psde->property_info, "src_config", 0x0, 1,
  2988. e_src_config, ARRAY_SIZE(e_src_config), PLANE_PROP_SRC_CONFIG);
  2989. if (psde->pipe_hw->ops.setup_solidfill)
  2990. msm_property_install_range(&psde->property_info, "color_fill",
  2991. 0, 0, 0xFFFFFFFF, 0, PLANE_PROP_COLOR_FILL);
  2992. msm_property_install_range(&psde->property_info,
  2993. "prefill_size", 0x0, 0, ~0, 0,
  2994. PLANE_PROP_PREFILL_SIZE);
  2995. msm_property_install_range(&psde->property_info,
  2996. "prefill_time", 0x0, 0, ~0, 0,
  2997. PLANE_PROP_PREFILL_TIME);
  2998. info = kzalloc(sizeof(struct sde_kms_info), GFP_KERNEL);
  2999. if (!info) {
  3000. SDE_ERROR("failed to allocate info memory\n");
  3001. return;
  3002. }
  3003. msm_property_install_blob(&psde->property_info, "capabilities",
  3004. DRM_MODE_PROP_IMMUTABLE, PLANE_PROP_INFO);
  3005. sde_kms_info_reset(info);
  3006. if (is_master) {
  3007. format_list = psde->pipe_sblk->format_list;
  3008. } else {
  3009. format_list = psde->pipe_sblk->virt_format_list;
  3010. sde_kms_info_add_keyint(info, "primary_smart_plane_id",
  3011. master_plane_id);
  3012. msm_property_install_enum(&psde->property_info,
  3013. "multirect_mode", 0x0, 0, e_multirect_mode,
  3014. ARRAY_SIZE(e_multirect_mode),
  3015. PLANE_PROP_MULTIRECT_MODE);
  3016. }
  3017. if (format_list) {
  3018. sde_kms_info_start(info, "pixel_formats");
  3019. while (format_list->fourcc_format) {
  3020. sde_kms_info_append_format(info,
  3021. format_list->fourcc_format,
  3022. format_list->modifier);
  3023. ++format_list;
  3024. }
  3025. sde_kms_info_stop(info);
  3026. }
  3027. if (psde->pipe_hw && psde->pipe_hw->ops.get_scaler_ver)
  3028. sde_kms_info_add_keyint(info, "scaler_step_ver",
  3029. psde->pipe_hw->ops.get_scaler_ver(psde->pipe_hw));
  3030. sde_kms_info_add_keyint(info, "max_linewidth",
  3031. psde->pipe_sblk->maxlinewidth);
  3032. sde_kms_info_add_keyint(info, "max_upscale",
  3033. psde->pipe_sblk->maxupscale);
  3034. sde_kms_info_add_keyint(info, "max_downscale",
  3035. psde->pipe_sblk->maxdwnscale);
  3036. sde_kms_info_add_keyint(info, "max_horizontal_deci",
  3037. psde->pipe_sblk->maxhdeciexp);
  3038. sde_kms_info_add_keyint(info, "max_vertical_deci",
  3039. psde->pipe_sblk->maxvdeciexp);
  3040. sde_kms_info_add_keyint(info, "max_per_pipe_bw",
  3041. psde->pipe_sblk->max_per_pipe_bw * 1000LL);
  3042. sde_kms_info_add_keyint(info, "max_per_pipe_bw_high",
  3043. psde->pipe_sblk->max_per_pipe_bw_high * 1000LL);
  3044. index = (master_plane_id == 0) ? 0 : 1;
  3045. if (catalog->has_demura &&
  3046. catalog->demura_supported[psde->pipe][index] != ~0x0) {
  3047. sde_kms_info_add_keyint(info, "demura_block", index);
  3048. sde_kms_info_add_keyint(info, "demura_pipe_id",
  3049. psde->pipe - SSPP_DMA0);
  3050. }
  3051. if ((is_master &&
  3052. (psde->features & BIT(SDE_SSPP_INVERSE_PMA))) ||
  3053. (psde->features & BIT(SDE_SSPP_DGM_INVERSE_PMA))) {
  3054. msm_property_install_range(&psde->property_info,
  3055. "inverse_pma", 0x0, 0, 1, 0, PLANE_PROP_INVERSE_PMA);
  3056. sde_kms_info_add_keyint(info, "inverse_pma", 1);
  3057. }
  3058. if (psde->features & BIT(SDE_SSPP_DGM_CSC)) {
  3059. msm_property_install_volatile_range(
  3060. &psde->property_info, "csc_dma_v1", 0x0,
  3061. 0, ~0, 0, PLANE_PROP_CSC_DMA_V1);
  3062. sde_kms_info_add_keyint(info, "csc_dma_v1", 1);
  3063. }
  3064. if (psde->features & BIT(SDE_SSPP_SEC_UI_ALLOWED))
  3065. sde_kms_info_add_keyint(info, "sec_ui_allowed", 1);
  3066. if (psde->features & BIT(SDE_SSPP_BLOCK_SEC_UI))
  3067. sde_kms_info_add_keyint(info, "block_sec_ui", 1);
  3068. if (psde->features & BIT(SDE_SSPP_TRUE_INLINE_ROT)) {
  3069. const struct sde_format_extended *inline_rot_fmt_list;
  3070. sde_kms_info_add_keyint(info, "true_inline_rot_rev",
  3071. catalog->true_inline_rot_rev);
  3072. sde_kms_info_add_keyint(info,
  3073. "true_inline_dwnscale_rt",
  3074. (int) (psde->pipe_sblk->in_rot_maxdwnscale_rt_num /
  3075. psde->pipe_sblk->in_rot_maxdwnscale_rt_denom));
  3076. sde_kms_info_add_keyint(info,
  3077. "true_inline_dwnscale_rt_numerator",
  3078. psde->pipe_sblk->in_rot_maxdwnscale_rt_num);
  3079. sde_kms_info_add_keyint(info,
  3080. "true_inline_dwnscale_rt_denominator",
  3081. psde->pipe_sblk->in_rot_maxdwnscale_rt_denom);
  3082. sde_kms_info_add_keyint(info, "true_inline_dwnscale_nrt",
  3083. psde->pipe_sblk->in_rot_maxdwnscale_nrt);
  3084. sde_kms_info_add_keyint(info, "true_inline_max_height",
  3085. psde->pipe_sblk->in_rot_maxheight);
  3086. inline_rot_fmt_list = psde->pipe_sblk->in_rot_format_list;
  3087. if (inline_rot_fmt_list) {
  3088. sde_kms_info_start(info, "inline_rot_pixel_formats");
  3089. while (inline_rot_fmt_list->fourcc_format) {
  3090. sde_kms_info_append_format(info,
  3091. inline_rot_fmt_list->fourcc_format,
  3092. inline_rot_fmt_list->modifier);
  3093. ++inline_rot_fmt_list;
  3094. }
  3095. sde_kms_info_stop(info);
  3096. }
  3097. }
  3098. msm_property_set_blob(&psde->property_info, &psde->blob_info,
  3099. info->data, SDE_KMS_INFO_DATALEN(info),
  3100. PLANE_PROP_INFO);
  3101. kfree(info);
  3102. if (psde->features & BIT(SDE_SSPP_MEMCOLOR)) {
  3103. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3104. "SDE_SSPP_SKIN_COLOR_V",
  3105. psde->pipe_sblk->memcolor_blk.version >> 16);
  3106. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3107. PLANE_PROP_SKIN_COLOR);
  3108. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3109. "SDE_SSPP_SKY_COLOR_V",
  3110. psde->pipe_sblk->memcolor_blk.version >> 16);
  3111. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3112. PLANE_PROP_SKY_COLOR);
  3113. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3114. "SDE_SSPP_FOLIAGE_COLOR_V",
  3115. psde->pipe_sblk->memcolor_blk.version >> 16);
  3116. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3117. PLANE_PROP_FOLIAGE_COLOR);
  3118. }
  3119. if (psde->features & BIT(SDE_SSPP_VIG_GAMUT)) {
  3120. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3121. "SDE_VIG_3D_LUT_GAMUT_V",
  3122. psde->pipe_sblk->gamut_blk.version >> 16);
  3123. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3124. PLANE_PROP_VIG_GAMUT);
  3125. }
  3126. if (psde->features & BIT(SDE_SSPP_VIG_IGC)) {
  3127. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3128. "SDE_VIG_1D_LUT_IGC_V",
  3129. psde->pipe_sblk->igc_blk[0].version >> 16);
  3130. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3131. PLANE_PROP_VIG_IGC);
  3132. }
  3133. if (psde->features & BIT(SDE_SSPP_DMA_IGC)) {
  3134. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3135. "SDE_DGM_1D_LUT_IGC_V",
  3136. psde->pipe_sblk->igc_blk[0].version >> 16);
  3137. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3138. PLANE_PROP_DMA_IGC);
  3139. }
  3140. if (psde->features & BIT(SDE_SSPP_DMA_GC)) {
  3141. snprintf(feature_name, sizeof(feature_name), "%s%d",
  3142. "SDE_DGM_1D_LUT_GC_V",
  3143. psde->pipe_sblk->gc_blk[0].version >> 16);
  3144. msm_property_install_blob(&psde->property_info, feature_name, 0,
  3145. PLANE_PROP_DMA_GC);
  3146. }
  3147. msm_property_install_enum(&psde->property_info, "fb_translation_mode",
  3148. 0x0,
  3149. 0, e_fb_translation_mode,
  3150. ARRAY_SIZE(e_fb_translation_mode),
  3151. PLANE_PROP_FB_TRANSLATION_MODE);
  3152. }
  3153. static inline void _sde_plane_set_csc_v1(struct sde_plane *psde,
  3154. void __user *usr_ptr)
  3155. {
  3156. struct sde_drm_csc_v1 csc_v1;
  3157. int i;
  3158. if (!psde) {
  3159. SDE_ERROR("invalid plane\n");
  3160. return;
  3161. }
  3162. psde->csc_usr_ptr = NULL;
  3163. if (!usr_ptr) {
  3164. SDE_DEBUG_PLANE(psde, "csc data removed\n");
  3165. return;
  3166. }
  3167. if (copy_from_user(&csc_v1, usr_ptr, sizeof(csc_v1))) {
  3168. SDE_ERROR_PLANE(psde, "failed to copy csc data\n");
  3169. return;
  3170. }
  3171. /* populate from user space */
  3172. for (i = 0; i < SDE_CSC_MATRIX_COEFF_SIZE; ++i)
  3173. psde->csc_cfg.csc_mv[i] = csc_v1.ctm_coeff[i] >> 16;
  3174. for (i = 0; i < SDE_CSC_BIAS_SIZE; ++i) {
  3175. psde->csc_cfg.csc_pre_bv[i] = csc_v1.pre_bias[i];
  3176. psde->csc_cfg.csc_post_bv[i] = csc_v1.post_bias[i];
  3177. }
  3178. for (i = 0; i < SDE_CSC_CLAMP_SIZE; ++i) {
  3179. psde->csc_cfg.csc_pre_lv[i] = csc_v1.pre_clamp[i];
  3180. psde->csc_cfg.csc_post_lv[i] = csc_v1.post_clamp[i];
  3181. }
  3182. psde->csc_usr_ptr = &psde->csc_cfg;
  3183. }
  3184. static inline void _sde_plane_set_scaler_v1(struct sde_plane *psde,
  3185. struct sde_plane_state *pstate, void __user *usr)
  3186. {
  3187. struct sde_drm_scaler_v1 scale_v1;
  3188. struct sde_hw_pixel_ext *pe;
  3189. int i;
  3190. if (!psde || !pstate) {
  3191. SDE_ERROR("invalid argument(s)\n");
  3192. return;
  3193. }
  3194. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_NONE;
  3195. if (!usr) {
  3196. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3197. return;
  3198. }
  3199. if (copy_from_user(&scale_v1, usr, sizeof(scale_v1))) {
  3200. SDE_ERROR_PLANE(psde, "failed to copy scale data\n");
  3201. return;
  3202. }
  3203. /* force property to be dirty, even if the pointer didn't change */
  3204. msm_property_set_dirty(&psde->property_info,
  3205. &pstate->property_state, PLANE_PROP_SCALER_V1);
  3206. /* populate from user space */
  3207. pe = &pstate->pixel_ext;
  3208. memset(pe, 0, sizeof(struct sde_hw_pixel_ext));
  3209. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3210. pe->init_phase_x[i] = scale_v1.init_phase_x[i];
  3211. pe->phase_step_x[i] = scale_v1.phase_step_x[i];
  3212. pe->init_phase_y[i] = scale_v1.init_phase_y[i];
  3213. pe->phase_step_y[i] = scale_v1.phase_step_y[i];
  3214. pe->horz_filter[i] = scale_v1.horz_filter[i];
  3215. pe->vert_filter[i] = scale_v1.vert_filter[i];
  3216. }
  3217. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3218. pe->left_ftch[i] = scale_v1.pe.left_ftch[i];
  3219. pe->right_ftch[i] = scale_v1.pe.right_ftch[i];
  3220. pe->left_rpt[i] = scale_v1.pe.left_rpt[i];
  3221. pe->right_rpt[i] = scale_v1.pe.right_rpt[i];
  3222. pe->roi_w[i] = scale_v1.pe.num_ext_pxls_lr[i];
  3223. pe->top_ftch[i] = scale_v1.pe.top_ftch[i];
  3224. pe->btm_ftch[i] = scale_v1.pe.btm_ftch[i];
  3225. pe->top_rpt[i] = scale_v1.pe.top_rpt[i];
  3226. pe->btm_rpt[i] = scale_v1.pe.btm_rpt[i];
  3227. pe->roi_h[i] = scale_v1.pe.num_ext_pxls_tb[i];
  3228. }
  3229. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_SCALER_V1;
  3230. SDE_EVT32_VERBOSE(DRMID(&psde->base));
  3231. SDE_DEBUG_PLANE(psde, "user property data copied\n");
  3232. }
  3233. static void _sde_plane_clear_predownscale_settings(
  3234. struct sde_plane_state *pstate)
  3235. {
  3236. pstate->pre_down.pre_downscale_x_0 = 0;
  3237. pstate->pre_down.pre_downscale_x_1 = 0;
  3238. pstate->pre_down.pre_downscale_y_0 = 0;
  3239. pstate->pre_down.pre_downscale_y_1 = 0;
  3240. }
  3241. static inline void _sde_plane_set_scaler_v2(struct sde_plane *psde,
  3242. struct sde_plane_state *pstate, void __user *usr)
  3243. {
  3244. struct sde_drm_scaler_v2 scale_v2;
  3245. struct sde_hw_pixel_ext *pe;
  3246. int i;
  3247. struct sde_hw_scaler3_cfg *cfg;
  3248. struct sde_hw_inline_pre_downscale_cfg *pd_cfg;
  3249. if (!psde || !pstate) {
  3250. SDE_ERROR("invalid argument(s)\n");
  3251. return;
  3252. }
  3253. cfg = &pstate->scaler3_cfg;
  3254. pd_cfg = &pstate->pre_down;
  3255. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_NONE;
  3256. if (!usr) {
  3257. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3258. cfg->enable = 0;
  3259. _sde_plane_clear_predownscale_settings(pstate);
  3260. goto end;
  3261. }
  3262. if (copy_from_user(&scale_v2, usr, sizeof(scale_v2))) {
  3263. SDE_ERROR_PLANE(psde, "failed to copy scale data\n");
  3264. return;
  3265. }
  3266. /* detach/ignore user data if 'disabled' */
  3267. if (!scale_v2.enable) {
  3268. SDE_DEBUG_PLANE(psde, "scale data removed\n");
  3269. cfg->enable = 0;
  3270. _sde_plane_clear_predownscale_settings(pstate);
  3271. goto end;
  3272. }
  3273. /* populate from user space */
  3274. sde_set_scaler_v2(cfg, &scale_v2);
  3275. if (_sde_plane_has_pre_downscale(psde)) {
  3276. pd_cfg->pre_downscale_x_0 = scale_v2.pre_downscale_x_0;
  3277. pd_cfg->pre_downscale_x_1 = scale_v2.pre_downscale_x_1;
  3278. pd_cfg->pre_downscale_y_0 = scale_v2.pre_downscale_y_0;
  3279. pd_cfg->pre_downscale_y_1 = scale_v2.pre_downscale_y_1;
  3280. }
  3281. pe = &pstate->pixel_ext;
  3282. memset(pe, 0, sizeof(struct sde_hw_pixel_ext));
  3283. for (i = 0; i < SDE_MAX_PLANES; i++) {
  3284. pe->left_ftch[i] = scale_v2.pe.left_ftch[i];
  3285. pe->right_ftch[i] = scale_v2.pe.right_ftch[i];
  3286. pe->left_rpt[i] = scale_v2.pe.left_rpt[i];
  3287. pe->right_rpt[i] = scale_v2.pe.right_rpt[i];
  3288. pe->roi_w[i] = scale_v2.pe.num_ext_pxls_lr[i];
  3289. pe->top_ftch[i] = scale_v2.pe.top_ftch[i];
  3290. pe->btm_ftch[i] = scale_v2.pe.btm_ftch[i];
  3291. pe->top_rpt[i] = scale_v2.pe.top_rpt[i];
  3292. pe->btm_rpt[i] = scale_v2.pe.btm_rpt[i];
  3293. pe->roi_h[i] = scale_v2.pe.num_ext_pxls_tb[i];
  3294. }
  3295. pstate->scaler_check_state = SDE_PLANE_SCLCHECK_SCALER_V2_CHECK;
  3296. end:
  3297. /* force property to be dirty, even if the pointer didn't change */
  3298. msm_property_set_dirty(&psde->property_info,
  3299. &pstate->property_state, PLANE_PROP_SCALER_V2);
  3300. SDE_EVT32_VERBOSE(DRMID(&psde->base), cfg->enable, cfg->de.enable,
  3301. cfg->src_width[0], cfg->src_height[0],
  3302. cfg->dst_width, cfg->dst_height);
  3303. SDE_DEBUG_PLANE(psde, "user property data copied\n");
  3304. }
  3305. static void _sde_plane_set_excl_rect_v1(struct sde_plane *psde,
  3306. struct sde_plane_state *pstate, void __user *usr_ptr)
  3307. {
  3308. struct drm_clip_rect excl_rect_v1;
  3309. if (!psde || !pstate) {
  3310. SDE_ERROR("invalid argument(s)\n");
  3311. return;
  3312. }
  3313. if (!usr_ptr) {
  3314. memset(&pstate->excl_rect, 0, sizeof(pstate->excl_rect));
  3315. SDE_DEBUG_PLANE(psde, "excl_rect data cleared\n");
  3316. return;
  3317. }
  3318. if (copy_from_user(&excl_rect_v1, usr_ptr, sizeof(excl_rect_v1))) {
  3319. SDE_ERROR_PLANE(psde, "failed to copy excl_rect data\n");
  3320. return;
  3321. }
  3322. /* populate from user space */
  3323. pstate->excl_rect.x = excl_rect_v1.x1;
  3324. pstate->excl_rect.y = excl_rect_v1.y1;
  3325. pstate->excl_rect.w = excl_rect_v1.x2 - excl_rect_v1.x1;
  3326. pstate->excl_rect.h = excl_rect_v1.y2 - excl_rect_v1.y1;
  3327. SDE_DEBUG_PLANE(psde, "excl_rect: {%d,%d,%d,%d}\n",
  3328. pstate->excl_rect.x, pstate->excl_rect.y,
  3329. pstate->excl_rect.w, pstate->excl_rect.h);
  3330. }
  3331. static int sde_plane_atomic_set_property(struct drm_plane *plane,
  3332. struct drm_plane_state *state, struct drm_property *property,
  3333. uint64_t val)
  3334. {
  3335. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3336. struct sde_plane_state *pstate;
  3337. int idx, ret = -EINVAL;
  3338. SDE_DEBUG_PLANE(psde, "\n");
  3339. if (!plane) {
  3340. SDE_ERROR("invalid plane\n");
  3341. } else if (!state) {
  3342. SDE_ERROR_PLANE(psde, "invalid state\n");
  3343. } else {
  3344. pstate = to_sde_plane_state(state);
  3345. ret = msm_property_atomic_set(&psde->property_info,
  3346. &pstate->property_state, property, val);
  3347. if (!ret) {
  3348. idx = msm_property_index(&psde->property_info,
  3349. property);
  3350. switch (idx) {
  3351. case PLANE_PROP_INPUT_FENCE:
  3352. _sde_plane_set_input_fence(psde, pstate, val);
  3353. break;
  3354. case PLANE_PROP_CSC_V1:
  3355. case PLANE_PROP_CSC_DMA_V1:
  3356. _sde_plane_set_csc_v1(psde, (void __user *)val);
  3357. break;
  3358. case PLANE_PROP_SCALER_V1:
  3359. _sde_plane_set_scaler_v1(psde, pstate,
  3360. (void *)(uintptr_t)val);
  3361. break;
  3362. case PLANE_PROP_SCALER_V2:
  3363. _sde_plane_set_scaler_v2(psde, pstate,
  3364. (void *)(uintptr_t)val);
  3365. break;
  3366. case PLANE_PROP_EXCL_RECT_V1:
  3367. _sde_plane_set_excl_rect_v1(psde, pstate,
  3368. (void *)(uintptr_t)val);
  3369. break;
  3370. default:
  3371. /* nothing to do */
  3372. break;
  3373. }
  3374. }
  3375. }
  3376. SDE_DEBUG_PLANE(psde, "%s[%d] <= 0x%llx ret=%d\n",
  3377. property->name, property->base.id, val, ret);
  3378. return ret;
  3379. }
  3380. static int sde_plane_atomic_get_property(struct drm_plane *plane,
  3381. const struct drm_plane_state *state,
  3382. struct drm_property *property, uint64_t *val)
  3383. {
  3384. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3385. struct sde_plane_state *pstate;
  3386. int ret = -EINVAL;
  3387. if (!plane) {
  3388. SDE_ERROR("invalid plane\n");
  3389. } else if (!state) {
  3390. SDE_ERROR("invalid state\n");
  3391. } else {
  3392. SDE_DEBUG_PLANE(psde, "\n");
  3393. pstate = to_sde_plane_state(state);
  3394. ret = msm_property_atomic_get(&psde->property_info,
  3395. &pstate->property_state, property, val);
  3396. }
  3397. return ret;
  3398. }
  3399. int sde_plane_helper_reset_custom_properties(struct drm_plane *plane,
  3400. struct drm_plane_state *plane_state)
  3401. {
  3402. struct sde_plane *psde;
  3403. struct sde_plane_state *pstate;
  3404. struct drm_property *drm_prop;
  3405. enum msm_mdp_plane_property prop_idx;
  3406. if (!plane || !plane_state) {
  3407. SDE_ERROR("invalid params\n");
  3408. return -EINVAL;
  3409. }
  3410. psde = to_sde_plane(plane);
  3411. pstate = to_sde_plane_state(plane_state);
  3412. for (prop_idx = 0; prop_idx < PLANE_PROP_COUNT; prop_idx++) {
  3413. uint64_t val = pstate->property_values[prop_idx].value;
  3414. uint64_t def;
  3415. int ret;
  3416. drm_prop = msm_property_index_to_drm_property(
  3417. &psde->property_info, prop_idx);
  3418. if (!drm_prop) {
  3419. /* not all props will be installed, based on caps */
  3420. SDE_DEBUG_PLANE(psde, "invalid property index %d\n",
  3421. prop_idx);
  3422. continue;
  3423. }
  3424. def = msm_property_get_default(&psde->property_info, prop_idx);
  3425. if (val == def)
  3426. continue;
  3427. SDE_DEBUG_PLANE(psde, "set prop %s idx %d from %llu to %llu\n",
  3428. drm_prop->name, prop_idx, val, def);
  3429. ret = sde_plane_atomic_set_property(plane, plane_state,
  3430. drm_prop, def);
  3431. if (ret) {
  3432. SDE_ERROR_PLANE(psde,
  3433. "set property failed, idx %d ret %d\n",
  3434. prop_idx, ret);
  3435. continue;
  3436. }
  3437. }
  3438. return 0;
  3439. }
  3440. static void sde_plane_destroy(struct drm_plane *plane)
  3441. {
  3442. struct sde_plane *psde = plane ? to_sde_plane(plane) : NULL;
  3443. SDE_DEBUG_PLANE(psde, "\n");
  3444. if (psde) {
  3445. _sde_plane_set_qos_ctrl(plane, false, SDE_PLANE_QOS_PANIC_CTRL);
  3446. if (psde->blob_info)
  3447. drm_property_blob_put(psde->blob_info);
  3448. msm_property_destroy(&psde->property_info);
  3449. mutex_destroy(&psde->lock);
  3450. /* this will destroy the states as well */
  3451. drm_plane_cleanup(plane);
  3452. if (psde->pipe_hw)
  3453. sde_hw_sspp_destroy(psde->pipe_hw);
  3454. kfree(psde);
  3455. }
  3456. }
  3457. void sde_plane_destroy_fb(struct drm_plane_state *state)
  3458. {
  3459. struct sde_plane_state *pstate;
  3460. if (!state) {
  3461. SDE_ERROR("invalid arg state %d\n", !state);
  3462. return;
  3463. }
  3464. pstate = to_sde_plane_state(state);
  3465. if (sde_plane_get_property(pstate, PLANE_PROP_FB_TRANSLATION_MODE) ==
  3466. SDE_DRM_FB_SEC) {
  3467. /* remove ref count for frame buffers */
  3468. if (state->fb) {
  3469. drm_framebuffer_put(state->fb);
  3470. state->fb = NULL;
  3471. }
  3472. }
  3473. }
  3474. static void sde_plane_destroy_state(struct drm_plane *plane,
  3475. struct drm_plane_state *state)
  3476. {
  3477. struct sde_plane *psde;
  3478. struct sde_plane_state *pstate;
  3479. if (!plane || !state) {
  3480. SDE_ERROR("invalid arg(s), plane %d state %d\n",
  3481. !plane, !state);
  3482. return;
  3483. }
  3484. psde = to_sde_plane(plane);
  3485. pstate = to_sde_plane_state(state);
  3486. SDE_DEBUG_PLANE(psde, "\n");
  3487. /* remove ref count for frame buffers */
  3488. if (state->fb)
  3489. drm_framebuffer_put(state->fb);
  3490. /* remove ref count for fence */
  3491. if (pstate->input_fence)
  3492. sde_sync_put(pstate->input_fence);
  3493. /* destroy value helper */
  3494. msm_property_destroy_state(&psde->property_info, pstate,
  3495. &pstate->property_state);
  3496. }
  3497. static struct drm_plane_state *
  3498. sde_plane_duplicate_state(struct drm_plane *plane)
  3499. {
  3500. struct sde_plane *psde;
  3501. struct sde_plane_state *pstate;
  3502. struct sde_plane_state *old_state;
  3503. struct drm_property *drm_prop;
  3504. uint64_t input_fence_default;
  3505. if (!plane) {
  3506. SDE_ERROR("invalid plane\n");
  3507. return NULL;
  3508. } else if (!plane->state) {
  3509. SDE_ERROR("invalid plane state\n");
  3510. return NULL;
  3511. }
  3512. old_state = to_sde_plane_state(plane->state);
  3513. psde = to_sde_plane(plane);
  3514. pstate = msm_property_alloc_state(&psde->property_info);
  3515. if (!pstate) {
  3516. SDE_ERROR_PLANE(psde, "failed to allocate state\n");
  3517. return NULL;
  3518. }
  3519. SDE_DEBUG_PLANE(psde, "\n");
  3520. /* duplicate value helper */
  3521. msm_property_duplicate_state(&psde->property_info, old_state, pstate,
  3522. &pstate->property_state, pstate->property_values);
  3523. /* clear out any input fence */
  3524. pstate->input_fence = 0;
  3525. input_fence_default = msm_property_get_default(
  3526. &psde->property_info, PLANE_PROP_INPUT_FENCE);
  3527. drm_prop = msm_property_index_to_drm_property(
  3528. &psde->property_info, PLANE_PROP_INPUT_FENCE);
  3529. if (msm_property_atomic_set(&psde->property_info,
  3530. &pstate->property_state, drm_prop,
  3531. input_fence_default))
  3532. SDE_DEBUG_PLANE(psde,
  3533. "error clearing duplicated input fence\n");
  3534. pstate->dirty = 0x0;
  3535. pstate->pending = false;
  3536. __drm_atomic_helper_plane_duplicate_state(plane, &pstate->base);
  3537. return &pstate->base;
  3538. }
  3539. static void sde_plane_reset(struct drm_plane *plane)
  3540. {
  3541. struct sde_plane *psde;
  3542. struct sde_plane_state *pstate;
  3543. if (!plane) {
  3544. SDE_ERROR("invalid plane\n");
  3545. return;
  3546. }
  3547. psde = to_sde_plane(plane);
  3548. SDE_DEBUG_PLANE(psde, "\n");
  3549. if (plane->state && !sde_crtc_is_reset_required(plane->state->crtc)) {
  3550. SDE_DEBUG_PLANE(psde, "avoid reset for plane\n");
  3551. return;
  3552. }
  3553. /* remove previous state, if present */
  3554. if (plane->state) {
  3555. sde_plane_destroy_state(plane, plane->state);
  3556. plane->state = 0;
  3557. }
  3558. pstate = msm_property_alloc_state(&psde->property_info);
  3559. if (!pstate) {
  3560. SDE_ERROR_PLANE(psde, "failed to allocate state\n");
  3561. return;
  3562. }
  3563. /* reset value helper */
  3564. msm_property_reset_state(&psde->property_info, pstate,
  3565. &pstate->property_state,
  3566. pstate->property_values);
  3567. pstate->base.plane = plane;
  3568. plane->state = &pstate->base;
  3569. }
  3570. u32 sde_plane_get_ubwc_error(struct drm_plane *plane)
  3571. {
  3572. u32 ubwc_error = 0;
  3573. struct sde_plane *psde;
  3574. if (!plane) {
  3575. SDE_ERROR("invalid plane\n");
  3576. return 0;
  3577. }
  3578. psde = to_sde_plane(plane);
  3579. if (!psde->is_virtual && psde->pipe_hw->ops.get_ubwc_error)
  3580. ubwc_error = psde->pipe_hw->ops.get_ubwc_error(psde->pipe_hw);
  3581. return ubwc_error;
  3582. }
  3583. void sde_plane_clear_ubwc_error(struct drm_plane *plane)
  3584. {
  3585. struct sde_plane *psde;
  3586. if (!plane) {
  3587. SDE_ERROR("invalid plane\n");
  3588. return;
  3589. }
  3590. psde = to_sde_plane(plane);
  3591. if (psde->pipe_hw->ops.clear_ubwc_error)
  3592. psde->pipe_hw->ops.clear_ubwc_error(psde->pipe_hw);
  3593. }
  3594. #ifdef CONFIG_DEBUG_FS
  3595. static ssize_t _sde_plane_danger_read(struct file *file,
  3596. char __user *buff, size_t count, loff_t *ppos)
  3597. {
  3598. struct sde_kms *kms = file->private_data;
  3599. struct sde_mdss_cfg *cfg = kms->catalog;
  3600. int len = 0;
  3601. char buf[40] = {'\0'};
  3602. if (!cfg)
  3603. return -ENODEV;
  3604. if (*ppos)
  3605. return 0; /* the end */
  3606. len = snprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl);
  3607. if (len < 0 || len >= sizeof(buf))
  3608. return 0;
  3609. if ((count < sizeof(buf)) || copy_to_user(buff, buf, len))
  3610. return -EFAULT;
  3611. *ppos += len; /* increase offset */
  3612. return len;
  3613. }
  3614. static void _sde_plane_set_danger_state(struct sde_kms *kms, bool enable)
  3615. {
  3616. struct drm_plane *plane;
  3617. drm_for_each_plane(plane, kms->dev) {
  3618. if (plane->fb && plane->state) {
  3619. sde_plane_danger_signal_ctrl(plane, enable);
  3620. SDE_DEBUG("plane:%d img:%dx%d ",
  3621. plane->base.id, plane->fb->width,
  3622. plane->fb->height);
  3623. SDE_DEBUG("src[%d,%d,%d,%d] dst[%d,%d,%d,%d]\n",
  3624. plane->state->src_x >> 16,
  3625. plane->state->src_y >> 16,
  3626. plane->state->src_w >> 16,
  3627. plane->state->src_h >> 16,
  3628. plane->state->crtc_x, plane->state->crtc_y,
  3629. plane->state->crtc_w, plane->state->crtc_h);
  3630. } else {
  3631. SDE_DEBUG("Inactive plane:%d\n", plane->base.id);
  3632. }
  3633. }
  3634. }
  3635. static ssize_t _sde_plane_danger_write(struct file *file,
  3636. const char __user *user_buf, size_t count, loff_t *ppos)
  3637. {
  3638. struct sde_kms *kms = file->private_data;
  3639. struct sde_mdss_cfg *cfg = kms->catalog;
  3640. int disable_panic;
  3641. char buf[10];
  3642. if (!cfg)
  3643. return -EFAULT;
  3644. if (count >= sizeof(buf))
  3645. return -EFAULT;
  3646. if (copy_from_user(buf, user_buf, count))
  3647. return -EFAULT;
  3648. buf[count] = 0; /* end of string */
  3649. if (kstrtoint(buf, 0, &disable_panic))
  3650. return -EFAULT;
  3651. if (disable_panic) {
  3652. /* Disable panic signal for all active pipes */
  3653. SDE_DEBUG("Disabling danger:\n");
  3654. _sde_plane_set_danger_state(kms, false);
  3655. kms->has_danger_ctrl = false;
  3656. } else {
  3657. /* Enable panic signal for all active pipes */
  3658. SDE_DEBUG("Enabling danger:\n");
  3659. kms->has_danger_ctrl = true;
  3660. _sde_plane_set_danger_state(kms, true);
  3661. }
  3662. return count;
  3663. }
  3664. static const struct file_operations sde_plane_danger_enable = {
  3665. .open = simple_open,
  3666. .read = _sde_plane_danger_read,
  3667. .write = _sde_plane_danger_write,
  3668. };
  3669. static int _sde_plane_init_debugfs(struct drm_plane *plane)
  3670. {
  3671. struct sde_plane *psde;
  3672. struct sde_kms *kms;
  3673. struct msm_drm_private *priv;
  3674. const struct sde_sspp_sub_blks *sblk = 0;
  3675. const struct sde_sspp_cfg *cfg = 0;
  3676. if (!plane || !plane->dev) {
  3677. SDE_ERROR("invalid arguments\n");
  3678. return -EINVAL;
  3679. }
  3680. priv = plane->dev->dev_private;
  3681. if (!priv || !priv->kms) {
  3682. SDE_ERROR("invalid KMS reference\n");
  3683. return -EINVAL;
  3684. }
  3685. kms = to_sde_kms(priv->kms);
  3686. psde = to_sde_plane(plane);
  3687. if (psde && psde->pipe_hw)
  3688. cfg = psde->pipe_hw->cap;
  3689. if (cfg)
  3690. sblk = cfg->sblk;
  3691. if (!sblk)
  3692. return 0;
  3693. /* create overall sub-directory for the pipe */
  3694. psde->debugfs_root =
  3695. debugfs_create_dir(psde->pipe_name,
  3696. plane->dev->primary->debugfs_root);
  3697. if (!psde->debugfs_root)
  3698. return -ENOMEM;
  3699. /* don't error check these */
  3700. debugfs_create_x32("features", 0400,
  3701. psde->debugfs_root, &psde->features);
  3702. if (cfg->features & BIT(SDE_SSPP_SCALER_QSEED3) ||
  3703. cfg->features & BIT(SDE_SSPP_SCALER_QSEED3LITE) ||
  3704. cfg->features & BIT(SDE_SSPP_SCALER_QSEED2))
  3705. debugfs_create_bool("default_scaling",
  3706. 0600,
  3707. psde->debugfs_root,
  3708. &psde->debugfs_default_scale);
  3709. if (cfg->features & BIT(SDE_SSPP_TRUE_INLINE_ROT)) {
  3710. debugfs_create_u32("in_rot_max_downscale_rt_num",
  3711. 0600,
  3712. psde->debugfs_root,
  3713. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_rt_num);
  3714. debugfs_create_u32("in_rot_max_downscale_rt_denom",
  3715. 0600,
  3716. psde->debugfs_root,
  3717. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_rt_denom);
  3718. debugfs_create_u32("in_rot_max_downscale_nrt",
  3719. 0600,
  3720. psde->debugfs_root,
  3721. (u32 *) &psde->pipe_sblk->in_rot_maxdwnscale_nrt);
  3722. debugfs_create_u32("in_rot_max_height",
  3723. 0600,
  3724. psde->debugfs_root,
  3725. (u32 *) &psde->pipe_sblk->in_rot_maxheight);
  3726. }
  3727. debugfs_create_u32("xin_id",
  3728. 0400,
  3729. psde->debugfs_root,
  3730. (u32 *) &cfg->xin_id);
  3731. debugfs_create_x32("creq_vblank",
  3732. 0600,
  3733. psde->debugfs_root,
  3734. (u32 *) &sblk->creq_vblank);
  3735. debugfs_create_x32("danger_vblank",
  3736. 0600,
  3737. psde->debugfs_root,
  3738. (u32 *) &sblk->danger_vblank);
  3739. debugfs_create_file("disable_danger",
  3740. 0600,
  3741. psde->debugfs_root,
  3742. kms, &sde_plane_danger_enable);
  3743. return 0;
  3744. }
  3745. static void _sde_plane_destroy_debugfs(struct drm_plane *plane)
  3746. {
  3747. struct sde_plane *psde;
  3748. if (!plane)
  3749. return;
  3750. psde = to_sde_plane(plane);
  3751. debugfs_remove_recursive(psde->debugfs_root);
  3752. }
  3753. #else
  3754. static int _sde_plane_init_debugfs(struct drm_plane *plane)
  3755. {
  3756. return 0;
  3757. }
  3758. static void _sde_plane_destroy_debugfs(struct drm_plane *plane)
  3759. {
  3760. }
  3761. #endif
  3762. static int sde_plane_late_register(struct drm_plane *plane)
  3763. {
  3764. return _sde_plane_init_debugfs(plane);
  3765. }
  3766. static void sde_plane_early_unregister(struct drm_plane *plane)
  3767. {
  3768. _sde_plane_destroy_debugfs(plane);
  3769. }
  3770. static const struct drm_plane_funcs sde_plane_funcs = {
  3771. .update_plane = drm_atomic_helper_update_plane,
  3772. .disable_plane = drm_atomic_helper_disable_plane,
  3773. .destroy = sde_plane_destroy,
  3774. .atomic_set_property = sde_plane_atomic_set_property,
  3775. .atomic_get_property = sde_plane_atomic_get_property,
  3776. .reset = sde_plane_reset,
  3777. .atomic_duplicate_state = sde_plane_duplicate_state,
  3778. .atomic_destroy_state = sde_plane_destroy_state,
  3779. .late_register = sde_plane_late_register,
  3780. .early_unregister = sde_plane_early_unregister,
  3781. };
  3782. static const struct drm_plane_helper_funcs sde_plane_helper_funcs = {
  3783. .prepare_fb = sde_plane_prepare_fb,
  3784. .cleanup_fb = sde_plane_cleanup_fb,
  3785. .atomic_check = sde_plane_atomic_check,
  3786. .atomic_update = sde_plane_atomic_update,
  3787. };
  3788. enum sde_sspp sde_plane_pipe(struct drm_plane *plane)
  3789. {
  3790. return plane ? to_sde_plane(plane)->pipe : SSPP_NONE;
  3791. }
  3792. bool is_sde_plane_virtual(struct drm_plane *plane)
  3793. {
  3794. return plane ? to_sde_plane(plane)->is_virtual : false;
  3795. }
  3796. /* initialize plane */
  3797. struct drm_plane *sde_plane_init(struct drm_device *dev,
  3798. uint32_t pipe, bool primary_plane,
  3799. unsigned long possible_crtcs, u32 master_plane_id)
  3800. {
  3801. struct drm_plane *plane = NULL, *master_plane = NULL;
  3802. const struct sde_format_extended *format_list;
  3803. struct sde_plane *psde;
  3804. struct msm_drm_private *priv;
  3805. struct sde_kms *kms;
  3806. enum drm_plane_type type;
  3807. int ret = -EINVAL;
  3808. if (!dev) {
  3809. SDE_ERROR("[%u]device is NULL\n", pipe);
  3810. goto exit;
  3811. }
  3812. priv = dev->dev_private;
  3813. if (!priv) {
  3814. SDE_ERROR("[%u]private data is NULL\n", pipe);
  3815. goto exit;
  3816. }
  3817. if (!priv->kms) {
  3818. SDE_ERROR("[%u]invalid KMS reference\n", pipe);
  3819. goto exit;
  3820. }
  3821. kms = to_sde_kms(priv->kms);
  3822. if (!kms->catalog) {
  3823. SDE_ERROR("[%u]invalid catalog reference\n", pipe);
  3824. goto exit;
  3825. }
  3826. /* create and zero local structure */
  3827. psde = kzalloc(sizeof(*psde), GFP_KERNEL);
  3828. if (!psde) {
  3829. SDE_ERROR("[%u]failed to allocate local plane struct\n", pipe);
  3830. ret = -ENOMEM;
  3831. goto exit;
  3832. }
  3833. /* cache local stuff for later */
  3834. plane = &psde->base;
  3835. psde->pipe = pipe;
  3836. psde->is_virtual = (master_plane_id != 0);
  3837. INIT_LIST_HEAD(&psde->mplane_list);
  3838. master_plane = drm_plane_find(dev, NULL, master_plane_id);
  3839. if (master_plane) {
  3840. struct sde_plane *mpsde = to_sde_plane(master_plane);
  3841. list_add_tail(&psde->mplane_list, &mpsde->mplane_list);
  3842. }
  3843. /* initialize underlying h/w driver */
  3844. psde->pipe_hw = sde_hw_sspp_init(pipe, kms->mmio, kms->catalog,
  3845. psde->is_virtual);
  3846. if (IS_ERR(psde->pipe_hw)) {
  3847. SDE_ERROR("[%u]SSPP init failed\n", pipe);
  3848. ret = PTR_ERR(psde->pipe_hw);
  3849. goto clean_plane;
  3850. } else if (!psde->pipe_hw->cap || !psde->pipe_hw->cap->sblk) {
  3851. SDE_ERROR("[%u]SSPP init returned invalid cfg\n", pipe);
  3852. goto clean_sspp;
  3853. }
  3854. /* cache features mask for later */
  3855. psde->features = psde->pipe_hw->cap->features;
  3856. psde->perf_features = psde->pipe_hw->cap->perf_features;
  3857. psde->pipe_sblk = psde->pipe_hw->cap->sblk;
  3858. if (!psde->pipe_sblk) {
  3859. SDE_ERROR("[%u]invalid sblk\n", pipe);
  3860. goto clean_sspp;
  3861. }
  3862. if (psde->is_virtual)
  3863. format_list = psde->pipe_sblk->virt_format_list;
  3864. else
  3865. format_list = psde->pipe_sblk->format_list;
  3866. psde->nformats = sde_populate_formats(format_list,
  3867. psde->formats,
  3868. 0,
  3869. ARRAY_SIZE(psde->formats));
  3870. if (!psde->nformats) {
  3871. SDE_ERROR("[%u]no valid formats for plane\n", pipe);
  3872. goto clean_sspp;
  3873. }
  3874. if (psde->features & BIT(SDE_SSPP_CURSOR))
  3875. type = DRM_PLANE_TYPE_CURSOR;
  3876. else if (primary_plane)
  3877. type = DRM_PLANE_TYPE_PRIMARY;
  3878. else
  3879. type = DRM_PLANE_TYPE_OVERLAY;
  3880. ret = drm_universal_plane_init(dev, plane, 0xff, &sde_plane_funcs,
  3881. psde->formats, psde->nformats,
  3882. NULL, type, NULL);
  3883. if (ret)
  3884. goto clean_sspp;
  3885. /* Populate static array of plane property flags */
  3886. _sde_plane_map_prop_to_dirty_bits();
  3887. /* success! finalize initialization */
  3888. drm_plane_helper_add(plane, &sde_plane_helper_funcs);
  3889. msm_property_init(&psde->property_info, &plane->base, dev,
  3890. priv->plane_property, psde->property_data,
  3891. PLANE_PROP_COUNT, PLANE_PROP_BLOBCOUNT,
  3892. sizeof(struct sde_plane_state));
  3893. _sde_plane_install_properties(plane, kms->catalog, master_plane_id);
  3894. /* save user friendly pipe name for later */
  3895. snprintf(psde->pipe_name, SDE_NAME_SIZE, "plane%u", plane->base.id);
  3896. mutex_init(&psde->lock);
  3897. SDE_DEBUG("%s created for pipe:%u id:%u master:%u\n", psde->pipe_name,
  3898. pipe, plane->base.id, master_plane_id);
  3899. return plane;
  3900. clean_sspp:
  3901. if (psde && psde->pipe_hw)
  3902. sde_hw_sspp_destroy(psde->pipe_hw);
  3903. clean_plane:
  3904. kfree(psde);
  3905. exit:
  3906. return ERR_PTR(ret);
  3907. }