sde_plane.c 125 KB

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