sde_plane.c 125 KB

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