sde_plane.c 130 KB

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