sde_plane.c 149 KB

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