12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
- * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
- */
- #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
- #include "sde_kms.h"
- #include "sde_hw_lm.h"
- #include "sde_hw_ctl.h"
- #include "sde_hw_cdm.h"
- #include "sde_hw_dspp.h"
- #include "sde_hw_ds.h"
- #include "sde_hw_pingpong.h"
- #include "sde_hw_intf.h"
- #include "sde_hw_wb.h"
- #include "sde_encoder.h"
- #include "sde_connector.h"
- #include "sde_hw_dsc.h"
- #include "sde_hw_vdc.h"
- #include "sde_crtc.h"
- #include "sde_hw_qdss.h"
- #include "sde_vbif.h"
- #include "sde_hw_dnsc_blur.h"
- #define RESERVED_BY_OTHER(h, r) \
- (((h)->rsvp && ((h)->rsvp->enc_id != (r)->enc_id)) ||\
- ((h)->rsvp_nxt && ((h)->rsvp_nxt->enc_id != (r)->enc_id)))
- #define RESERVED_BY_CURRENT(h, r) \
- (((h)->rsvp && ((h)->rsvp->enc_id == (r)->enc_id)))
- #define RM_RQ_LOCK(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK))
- #define RM_RQ_CLEAR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_CLEAR))
- #define RM_RQ_DSPP(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DSPP))
- #define RM_RQ_DS(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DS))
- #define RM_RQ_CWB(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_CWB))
- #define RM_RQ_DCWB(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DCWB))
- #define RM_RQ_DNSC_BLUR(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_DNSC_BLUR))
- #define RM_RQ_CDM(r) ((r)->top_ctrl & BIT(SDE_RM_TOPCTL_CDM))
- #define RM_IS_TOPOLOGY_MATCH(t, r) ((t).num_lm == (r).num_lm && \
- (t).num_comp_enc == (r).num_enc && \
- (t).num_intf == (r).num_intf && \
- (t).comp_type == (r).comp_type)
- #define IS_COMPATIBLE_PP_DSC(p, d) (p % 2 == d % 2)
- /* ~one vsync poll time for rsvp_nxt to cleared by modeset from commit thread */
- #define RM_NXT_CLEAR_POLL_TIMEOUT_US 33000
- /**
- * toplogy information to be used when ctl path version does not
- * support driving more than one interface per ctl_path
- */
- static const struct sde_rm_topology_def g_top_table[SDE_RM_TOPOLOGY_MAX] = {
- { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 2, true,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 2, true,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, true,
- MSM_DISPLAY_COMPRESSION_NONE },
- };
- /**
- * topology information to be used when the ctl path version
- * is SDE_CTL_CFG_VERSION_1_0_0
- */
- static const struct sde_rm_topology_def g_top_table_v1[SDE_RM_TOPOLOGY_MAX] = {
- { SDE_RM_TOPOLOGY_NONE, 0, 0, 0, 0, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_SINGLEPIPE, 1, 0, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_SINGLEPIPE_DSC, 1, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_SINGLEPIPE_VDC, 1, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_VDC },
- { SDE_RM_TOPOLOGY_DUALPIPE, 2, 0, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_DUALPIPE_DSC, 2, 2, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE, 2, 0, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_DSC, 2, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE_VDC, 2, 1, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_VDC },
- { SDE_RM_TOPOLOGY_DUALPIPE_DSCMERGE, 2, 2, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_PPSPLIT, 1, 0, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE, 4, 0, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_NONE },
- { SDE_RM_TOPOLOGY_QUADPIPE_3DMERGE_DSC, 4, 3, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_QUADPIPE_DSCMERGE, 4, 4, 2, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- { SDE_RM_TOPOLOGY_QUADPIPE_DSC4HSMERGE, 4, 4, 1, 1, false,
- MSM_DISPLAY_COMPRESSION_DSC },
- };
- char sde_hw_blk_str[SDE_HW_BLK_MAX][SDE_HW_BLK_NAME_LEN] = {
- "top",
- "sspp",
- "lm",
- "dspp",
- "ds",
- "ctl",
- "cdm",
- "pingpong",
- "intf",
- "wb",
- "dsc",
- "vdc",
- "merge_3d",
- "qdss",
- "dnsc_blur"
- };
- /**
- * struct sde_rm_requirements - Reservation requirements parameter bundle
- * @top_ctrl: topology control preference from kernel client
- * @top: selected topology for the display
- * @hw_res: Hardware resources required as reported by the encoders
- * @conn_lm_mask: preferred LM mask of cwb requested display
- */
- struct sde_rm_requirements {
- uint64_t top_ctrl;
- const struct sde_rm_topology_def *topology;
- struct sde_encoder_hw_resources hw_res;
- u32 conn_lm_mask;
- };
- /**
- * struct sde_rm_rsvp - Use Case Reservation tagging structure
- * Used to tag HW blocks as reserved by a CRTC->Encoder->Connector chain
- * By using as a tag, rather than lists of pointers to HW blocks used
- * we can avoid some list management since we don't know how many blocks
- * of each type a given use case may require.
- * @list: List head for list of all reservations
- * @seq: Global RSVP sequence number for debugging, especially for
- * differentiating differenct allocations for same encoder.
- * @enc_id: Reservations are tracked by Encoder DRM object ID.
- * CRTCs may be connected to multiple Encoders.
- * An encoder or connector id identifies the display path.
- * @topology: DRM<->HW topology use case
- * @pending: True for pending rsvp-nxt, cleared when the rsvp is committed
- */
- struct sde_rm_rsvp {
- struct list_head list;
- uint32_t seq;
- uint32_t enc_id;
- enum sde_rm_topology_name topology;
- bool pending;
- };
- /**
- * struct sde_rm_hw_blk - hardware block tracking list member
- * @list: List head for list of all hardware blocks tracking items
- * @rsvp: Pointer to use case reservation if reserved by a client
- * @rsvp_nxt: Temporary pointer used during reservation to the incoming
- * request. Will be swapped into rsvp if proposal is accepted
- * @type: Type of hardware block this structure tracks
- * @id: Hardware ID number, within it's own space, ie. LM_X
- * @catalog: Pointer to the hardware catalog entry for this block
- * @hw: Pointer to the hardware register access object for this block
- */
- struct sde_rm_hw_blk {
- struct list_head list;
- struct sde_rm_rsvp *rsvp;
- struct sde_rm_rsvp *rsvp_nxt;
- enum sde_hw_blk_type type;
- uint32_t id;
- struct sde_hw_blk_reg_map *hw;
- };
- /**
- * sde_rm_dbg_rsvp_stage - enum of steps in making reservation for event logging
- */
- enum sde_rm_dbg_rsvp_stage {
- SDE_RM_STAGE_BEGIN,
- SDE_RM_STAGE_AFTER_CLEAR,
- SDE_RM_STAGE_AFTER_RSVPNEXT,
- SDE_RM_STAGE_FINAL
- };
- static void _sde_rm_inc_resource_info_lm(struct sde_rm *rm,
- struct msm_resource_caps_info *avail_res,
- struct sde_rm_hw_blk *blk)
- {
- struct sde_rm_hw_blk *blk2;
- const struct sde_lm_cfg *lm_cfg, *lm_cfg2;
- lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
- /* Do not track & expose dummy mixers */
- if (lm_cfg->dummy_mixer)
- return;
- avail_res->num_lm++;
- /* Check for 3d muxes by comparing paired lms */
- list_for_each_entry(blk2, &rm->hw_blks[SDE_HW_BLK_LM], list) {
- lm_cfg2 = to_sde_hw_mixer(blk2->hw)->cap;
- /*
- * If the paired lm is free, or is reserved by the same encoder
- * set the bit for the 3d mux associated with the lm
- * counting these set bits will give an accurate count of available 3dmux
- */
- if ((!blk2->rsvp || (blk->rsvp && blk2->rsvp->enc_id == blk->rsvp->enc_id)) &&
- test_bit(lm_cfg->id, &lm_cfg2->lm_pair_mask))
- set_bit(lm_cfg->merge_3d, &avail_res->merge_3d_mask);
- }
- avail_res->num_3dmux = hweight_long(avail_res->merge_3d_mask);
- }
- static void _sde_rm_dec_resource_info_lm(struct sde_rm *rm,
- struct msm_resource_caps_info *avail_res,
- struct sde_rm_hw_blk *blk)
- {
- const struct sde_lm_cfg *lm_cfg;
- lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
- /* Do not track & expose dummy mixers */
- if (lm_cfg->dummy_mixer)
- return;
- avail_res->num_lm--;
- /*
- * Clear the bit for the 3d mux associated with the lm
- * counting these set bits will give an accurate count of available 3dmux
- */
- clear_bit(lm_cfg->merge_3d, &avail_res->merge_3d_mask);
- avail_res->num_3dmux = hweight_long(avail_res->merge_3d_mask);
- }
- static void _sde_rm_inc_resource_info(struct sde_rm *rm,
- struct msm_resource_caps_info *avail_res,
- struct sde_rm_hw_blk *blk)
- {
- enum sde_hw_blk_type type = blk->type;
- if (type == SDE_HW_BLK_LM)
- _sde_rm_inc_resource_info_lm(rm, avail_res, blk);
- else if (type == SDE_HW_BLK_CTL)
- avail_res->num_ctl++;
- else if (type == SDE_HW_BLK_DSC)
- avail_res->num_dsc++;
- else if (type == SDE_HW_BLK_VDC)
- avail_res->num_vdc++;
- }
- static void _sde_rm_dec_resource_info(struct sde_rm *rm,
- struct msm_resource_caps_info *avail_res,
- struct sde_rm_hw_blk *blk)
- {
- enum sde_hw_blk_type type = blk->type;
- if (type == SDE_HW_BLK_LM)
- _sde_rm_dec_resource_info_lm(rm, avail_res, blk);
- else if (type == SDE_HW_BLK_CTL)
- avail_res->num_ctl--;
- else if (type == SDE_HW_BLK_DSC)
- avail_res->num_dsc--;
- else if (type == SDE_HW_BLK_VDC)
- avail_res->num_vdc--;
- }
- void sde_rm_get_resource_info(struct sde_rm *rm,
- struct drm_encoder *drm_enc,
- struct msm_resource_caps_info *avail_res)
- {
- struct sde_rm_hw_blk *blk;
- enum sde_hw_blk_type type;
- const struct sde_lm_cfg *lm_cfg;
- bool is_built_in, is_pref;
- u32 lm_pref = (BIT(SDE_DISP_PRIMARY_PREF) | BIT(SDE_DISP_SECONDARY_PREF));
- mutex_lock(&rm->rm_lock);
- /* Get all currently available resources */
- memcpy(avail_res, &rm->avail_res,
- sizeof(rm->avail_res));
- /**
- * When the encoder is null, assume display is external in order to return the count of
- * availalbe non-preferred LMs
- */
- if (!drm_enc)
- is_built_in = false;
- else
- is_built_in = sde_encoder_is_built_in_display(drm_enc);
- for (type = 0; type < SDE_HW_BLK_MAX; type++) {
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- /* Add back resources allocated to the given encoder */
- if (blk->rsvp && drm_enc && blk->rsvp->enc_id == drm_enc->base.id) {
- _sde_rm_inc_resource_info(rm, avail_res, blk);
- if (type == SDE_HW_BLK_LM)
- avail_res->num_lm_in_use++;
- }
- /**
- * Remove unallocated preferred lms that cannot reserved
- * by non built-in displays.
- */
- if (type == SDE_HW_BLK_LM) {
- lm_cfg = to_sde_hw_mixer(blk->hw)->cap;
- is_pref = lm_cfg->features & lm_pref;
- if (!blk->rsvp && !blk->rsvp_nxt && !is_built_in && is_pref)
- _sde_rm_dec_resource_info(rm, avail_res, blk);
- }
- }
- }
- mutex_unlock(&rm->rm_lock);
- }
- static void _sde_rm_print_rsvps(
- struct sde_rm *rm,
- enum sde_rm_dbg_rsvp_stage stage)
- {
- struct sde_rm_rsvp *rsvp;
- struct sde_rm_hw_blk *blk;
- enum sde_hw_blk_type type;
- SDE_DEBUG("%d\n", stage);
- list_for_each_entry(rsvp, &rm->rsvps, list) {
- SDE_DEBUG("%d rsvp%s[s%ue%u] topology %d\n", stage, rsvp->pending ? "_nxt" : "",
- rsvp->seq, rsvp->enc_id, rsvp->topology);
- SDE_EVT32(stage, rsvp->seq, rsvp->enc_id, rsvp->topology, rsvp->pending);
- }
- for (type = 0; type < SDE_HW_BLK_MAX; type++) {
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (!blk->rsvp && !blk->rsvp_nxt)
- continue;
- SDE_DEBUG("%d rsvp[s%ue%u->s%ue%u] %d %d\n", stage,
- (blk->rsvp) ? blk->rsvp->seq : 0,
- (blk->rsvp) ? blk->rsvp->enc_id : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
- blk->type, blk->id);
- SDE_EVT32(stage,
- (blk->rsvp) ? blk->rsvp->seq : 0,
- (blk->rsvp) ? blk->rsvp->enc_id : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
- blk->type, blk->id);
- }
- }
- }
- static void _sde_rm_print_rsvps_by_type(
- struct sde_rm *rm,
- enum sde_hw_blk_type type)
- {
- struct sde_rm_hw_blk *blk;
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (!blk->rsvp && !blk->rsvp_nxt)
- continue;
- SDE_ERROR("rsvp[s%ue%u->s%ue%u] %d %d\n",
- (blk->rsvp) ? blk->rsvp->seq : 0,
- (blk->rsvp) ? blk->rsvp->enc_id : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
- blk->type, blk->id);
- SDE_EVT32((blk->rsvp) ? blk->rsvp->seq : 0,
- (blk->rsvp) ? blk->rsvp->enc_id : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->seq : 0,
- (blk->rsvp_nxt) ? blk->rsvp_nxt->enc_id : 0,
- blk->type, blk->id);
- }
- }
- struct sde_hw_mdp *sde_rm_get_mdp(struct sde_rm *rm)
- {
- return rm->hw_mdp;
- }
- void sde_rm_init_hw_iter(
- struct sde_rm_hw_iter *iter,
- uint32_t enc_id,
- enum sde_hw_blk_type type)
- {
- memset(iter, 0, sizeof(*iter));
- iter->enc_id = enc_id;
- iter->type = type;
- }
- enum sde_rm_topology_name sde_rm_get_topology_name(struct sde_rm *rm,
- struct msm_display_topology topology)
- {
- int i;
- for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
- if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
- topology))
- return rm->topology_tbl[i].top_name;
- return SDE_RM_TOPOLOGY_NONE;
- }
- static bool _sde_rm_get_hw_locked(struct sde_rm *rm, struct sde_rm_hw_iter *i)
- {
- struct list_head *blk_list;
- if (!rm || !i || i->type >= SDE_HW_BLK_MAX) {
- SDE_ERROR("invalid rm\n");
- return false;
- }
- i->hw = NULL;
- blk_list = &rm->hw_blks[i->type];
- if (i->blk && (&i->blk->list == blk_list)) {
- SDE_DEBUG("attempt resume iteration past last\n");
- return false;
- }
- i->blk = list_prepare_entry(i->blk, blk_list, list);
- list_for_each_entry_continue(i->blk, blk_list, list) {
- struct sde_rm_rsvp *rsvp = i->blk->rsvp;
- if (i->blk->type != i->type) {
- SDE_ERROR("found incorrect block type %d on %d list\n",
- i->blk->type, i->type);
- return false;
- }
- if ((i->enc_id == 0) || (rsvp && rsvp->enc_id == i->enc_id)) {
- i->hw = i->blk->hw;
- SDE_DEBUG("found type %d id %d for enc %d\n",
- i->type, i->blk->id, i->enc_id);
- return true;
- }
- }
- SDE_DEBUG("no match, type %d for enc %d\n", i->type, i->enc_id);
- return false;
- }
- static bool _sde_rm_request_hw_blk_locked(struct sde_rm *rm,
- struct sde_rm_hw_request *hw_blk_info)
- {
- struct list_head *blk_list;
- struct sde_rm_hw_blk *blk = NULL;
- if (!rm || !hw_blk_info || hw_blk_info->type >= SDE_HW_BLK_MAX) {
- SDE_ERROR("invalid rm\n");
- return false;
- }
- hw_blk_info->hw = NULL;
- blk_list = &rm->hw_blks[hw_blk_info->type];
- blk = list_prepare_entry(blk, blk_list, list);
- list_for_each_entry_continue(blk, blk_list, list) {
- if (blk->type != hw_blk_info->type) {
- SDE_ERROR("found incorrect block type %d on %d list\n",
- blk->type, hw_blk_info->type);
- return false;
- }
- if (blk->id == hw_blk_info->id) {
- hw_blk_info->hw = blk->hw;
- SDE_DEBUG("found type %d id %d\n",
- blk->type, blk->id);
- return true;
- }
- }
- SDE_DEBUG("no match, type %d id %d\n", hw_blk_info->type,
- hw_blk_info->id);
- return false;
- }
- bool sde_rm_get_hw(struct sde_rm *rm, struct sde_rm_hw_iter *i)
- {
- bool ret;
- mutex_lock(&rm->rm_lock);
- ret = _sde_rm_get_hw_locked(rm, i);
- mutex_unlock(&rm->rm_lock);
- return ret;
- }
- bool sde_rm_request_hw_blk(struct sde_rm *rm, struct sde_rm_hw_request *hw)
- {
- bool ret;
- mutex_lock(&rm->rm_lock);
- ret = _sde_rm_request_hw_blk_locked(rm, hw);
- mutex_unlock(&rm->rm_lock);
- return ret;
- }
- static void _sde_rm_hw_destroy(enum sde_hw_blk_type type, struct sde_hw_blk_reg_map *hw)
- {
- switch (type) {
- case SDE_HW_BLK_LM:
- sde_hw_lm_destroy(hw);
- break;
- case SDE_HW_BLK_DSPP:
- sde_hw_dspp_destroy(hw);
- break;
- case SDE_HW_BLK_DS:
- sde_hw_ds_destroy(hw);
- break;
- case SDE_HW_BLK_CTL:
- sde_hw_ctl_destroy(hw);
- break;
- case SDE_HW_BLK_CDM:
- sde_hw_cdm_destroy(hw);
- break;
- case SDE_HW_BLK_PINGPONG:
- sde_hw_pingpong_destroy(hw);
- break;
- case SDE_HW_BLK_INTF:
- sde_hw_intf_destroy(hw);
- break;
- case SDE_HW_BLK_WB:
- sde_hw_wb_destroy(hw);
- break;
- case SDE_HW_BLK_DSC:
- sde_hw_dsc_destroy(hw);
- break;
- case SDE_HW_BLK_VDC:
- sde_hw_vdc_destroy(hw);
- break;
- case SDE_HW_BLK_QDSS:
- sde_hw_qdss_destroy(hw);
- break;
- case SDE_HW_BLK_DNSC_BLUR:
- sde_hw_dnsc_blur_destroy(hw);
- break;
- case SDE_HW_BLK_SSPP:
- /* SSPPs are not managed by the resource manager */
- case SDE_HW_BLK_TOP:
- /* Top is a singleton, not managed in hw_blks list */
- case SDE_HW_BLK_MAX:
- default:
- SDE_ERROR("unsupported block type %d\n", type);
- break;
- }
- }
- static void _deinit_hw_fences(struct sde_rm *rm)
- {
- struct sde_rm_hw_iter iter;
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
- sde_hw_fence_deinit(ctl);
- }
- }
- int sde_rm_destroy(struct sde_rm *rm)
- {
- struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
- struct sde_rm_hw_blk *hw_cur, *hw_nxt;
- enum sde_hw_blk_type type;
- if (!rm) {
- SDE_ERROR("invalid rm\n");
- return -EINVAL;
- }
- _deinit_hw_fences(rm);
- list_for_each_entry_safe(rsvp_cur, rsvp_nxt, &rm->rsvps, list) {
- list_del(&rsvp_cur->list);
- kfree(rsvp_cur);
- }
- for (type = 0; type < SDE_HW_BLK_MAX; type++) {
- list_for_each_entry_safe(hw_cur, hw_nxt, &rm->hw_blks[type],
- list) {
- list_del(&hw_cur->list);
- _sde_rm_hw_destroy(hw_cur->type, hw_cur->hw);
- kfree(hw_cur);
- }
- }
- sde_hw_mdp_destroy(rm->hw_mdp);
- rm->hw_mdp = NULL;
- mutex_destroy(&rm->rm_lock);
- return 0;
- }
- static int _sde_rm_hw_blk_create(
- struct sde_rm *rm,
- struct sde_mdss_cfg *cat,
- void __iomem *mmio,
- enum sde_hw_blk_type type,
- uint32_t id,
- void *hw_catalog_info)
- {
- int rc;
- struct sde_rm_hw_blk *blk;
- struct sde_hw_mdp *hw_mdp;
- struct sde_hw_blk_reg_map *hw;
- struct sde_kms *sde_kms = to_sde_kms(ddev_to_msm_kms(rm->dev));
- struct sde_vbif_clk_client clk_client = {0};
- hw_mdp = rm->hw_mdp;
- switch (type) {
- case SDE_HW_BLK_LM:
- hw = sde_hw_lm_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_DSPP:
- hw = sde_hw_dspp_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_DS:
- hw = sde_hw_ds_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_CTL:
- hw = sde_hw_ctl_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_CDM:
- hw = sde_hw_cdm_init(id, mmio, cat, hw_mdp);
- break;
- case SDE_HW_BLK_PINGPONG:
- hw = sde_hw_pingpong_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_INTF:
- hw = sde_hw_intf_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_WB:
- hw = sde_hw_wb_init(id, mmio, cat, hw_mdp, &clk_client);
- break;
- case SDE_HW_BLK_DSC:
- hw = sde_hw_dsc_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_VDC:
- hw = sde_hw_vdc_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_QDSS:
- hw = sde_hw_qdss_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_DNSC_BLUR:
- hw = sde_hw_dnsc_blur_init(id, mmio, cat);
- break;
- case SDE_HW_BLK_SSPP:
- /* SSPPs are not managed by the resource manager */
- case SDE_HW_BLK_TOP:
- /* Top is a singleton, not managed in hw_blks list */
- case SDE_HW_BLK_MAX:
- default:
- SDE_ERROR("unsupported block type %d\n", type);
- return -EINVAL;
- }
- if (IS_ERR_OR_NULL(hw)) {
- SDE_ERROR("failed hw object creation: type %d, err %ld\n",
- type, PTR_ERR(hw));
- return -EFAULT;
- }
- blk = kzalloc(sizeof(*blk), GFP_KERNEL);
- if (!blk) {
- _sde_rm_hw_destroy(type, hw);
- return -ENOMEM;
- }
- blk->type = type;
- blk->id = id;
- blk->hw = hw;
- list_add_tail(&blk->list, &rm->hw_blks[type]);
- _sde_rm_inc_resource_info(rm, &rm->avail_res, blk);
- if (sde_kms && sde_kms->catalog &&
- test_bit(SDE_FEATURE_VBIF_CLK_SPLIT, sde_kms->catalog->features) &&
- SDE_CLK_CTRL_VALID(clk_client.clk_ctrl)) {
- rc = sde_vbif_clk_register(sde_kms, &clk_client);
- if (rc) {
- SDE_ERROR("failed to register vbif client %d\n", clk_client.clk_ctrl);
- return -EFAULT;
- }
- }
- return 0;
- }
- static int _init_hw_fences(struct sde_rm *rm, bool use_ipcc, struct sde_kms *sde_kms)
- {
- struct sde_rm_hw_iter iter;
- int ret = 0;
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
- if (sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE] &&
- sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE]->mmu) {
- if (sde_hw_fence_init(ctl, sde_kms, use_ipcc,
- sde_kms->aspace[MSM_SMMU_DOMAIN_UNSECURE]->mmu)) {
- SDE_DEBUG("failed to init hw_fence idx:%d\n", ctl->idx);
- ret = -EINVAL;
- break;
- }
- } else {
- SDE_DEBUG("failed to init hw_fence idx:%d, no aspace to map memory\n",
- ctl->idx);
- ret = -EINVAL;
- break;
- }
- SDE_DEBUG("init hw-fence for ctl %d", iter.blk->id);
- }
- if (ret)
- _deinit_hw_fences(rm);
- return ret;
- }
- static int _sde_rm_hw_blk_create_new(struct sde_rm *rm,
- struct sde_mdss_cfg *cat,
- void __iomem *mmio, struct sde_kms *sde_kms)
- {
- int i, rc = 0;
- for (i = 0; i < cat->dspp_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSPP,
- cat->dspp[i].id, &cat->dspp[i]);
- if (rc) {
- SDE_ERROR("failed: dspp hw not available\n");
- goto fail;
- }
- }
- if (cat->mdp[0].has_dest_scaler) {
- for (i = 0; i < cat->ds_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DS,
- cat->ds[i].id, &cat->ds[i]);
- if (rc) {
- SDE_ERROR("failed: ds hw not available\n");
- goto fail;
- }
- }
- }
- for (i = 0; i < cat->pingpong_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_PINGPONG,
- cat->pingpong[i].id, &cat->pingpong[i]);
- if (rc) {
- SDE_ERROR("failed: pp hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->dsc_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DSC,
- cat->dsc[i].id, &cat->dsc[i]);
- if (rc) {
- SDE_ERROR("failed: dsc hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->vdc_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_VDC,
- cat->vdc[i].id, &cat->vdc[i]);
- if (rc) {
- SDE_ERROR("failed: vdc hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->intf_count; i++) {
- if (cat->intf[i].type == INTF_NONE) {
- SDE_DEBUG("skip intf %d with type none\n", i);
- continue;
- }
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_INTF,
- cat->intf[i].id, &cat->intf[i]);
- if (rc) {
- SDE_ERROR("failed: intf hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->wb_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_WB,
- cat->wb[i].id, &cat->wb[i]);
- if (rc) {
- SDE_ERROR("failed: wb hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->ctl_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CTL,
- cat->ctl[i].id, &cat->ctl[i]);
- if (rc) {
- SDE_ERROR("failed: ctl hw not available\n");
- goto fail;
- }
- }
- if (cat->hw_fence_rev) {
- if (_init_hw_fences(rm, test_bit(SDE_FEATURE_HW_FENCE_IPCC, cat->features),
- sde_kms)) {
- SDE_INFO("failed to init hw-fences, disabling hw-fences\n");
- cat->hw_fence_rev = 0;
- }
- }
- for (i = 0; i < cat->cdm_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_CDM,
- cat->cdm[i].id, &cat->cdm[i]);
- if (rc) {
- SDE_ERROR("failed: cdm hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->dnsc_blur_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_DNSC_BLUR,
- cat->dnsc_blur[i].id, &cat->dnsc_blur[i]);
- if (rc) {
- SDE_ERROR("failed: dnsc_blur hw not available\n");
- goto fail;
- }
- }
- for (i = 0; i < cat->qdss_count; i++) {
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_QDSS,
- cat->qdss[i].id, &cat->qdss[i]);
- if (rc) {
- SDE_ERROR("failed: qdss hw not available\n");
- goto fail;
- }
- }
- fail:
- return rc;
- }
- #if IS_ENABLED(CONFIG_DEBUG_FS)
- static int _sde_rm_status_show(struct seq_file *s, void *data)
- {
- struct sde_rm *rm;
- struct sde_rm_hw_blk *blk;
- u32 type, allocated, unallocated;
- if (!s || !s->private)
- return -EINVAL;
- rm = s->private;
- for (type = SDE_HW_BLK_LM; type < SDE_HW_BLK_MAX; type++) {
- allocated = 0;
- unallocated = 0;
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (!blk->rsvp && !blk->rsvp_nxt)
- unallocated++;
- else
- allocated++;
- }
- seq_printf(s, "type:%d blk:%s allocated:%d unallocated:%d\n",
- type, sde_hw_blk_str[type], allocated, unallocated);
- }
- return 0;
- }
- static int _sde_rm_debugfs_status_open(struct inode *inode,
- struct file *file)
- {
- return single_open(file, _sde_rm_status_show, inode->i_private);
- }
- void sde_rm_debugfs_init(struct sde_rm *sde_rm, struct dentry *parent)
- {
- static const struct file_operations debugfs_rm_status_fops = {
- .open = _sde_rm_debugfs_status_open,
- .read = seq_read,
- };
- debugfs_create_file("rm_status", 0400, parent, sde_rm, &debugfs_rm_status_fops);
- }
- #else
- void sde_rm_debugfs_init(struct sde_rm *rm, struct dentry *parent)
- {
- }
- #endif /* CONFIG_DEBUG_FS */
- int sde_rm_init(struct sde_rm *rm)
- {
- struct sde_kms *sde_kms = container_of(rm, struct sde_kms, rm);
- struct sde_mdss_cfg *cat = sde_kms->catalog;
- void __iomem *mmio = sde_kms->mmio;
- struct drm_device *dev = sde_kms->dev;
- int i, rc = 0;
- enum sde_hw_blk_type type;
- if (!rm || !cat || !mmio || !dev) {
- SDE_ERROR("invalid input params\n");
- return -EINVAL;
- }
- /* Clear, setup lists */
- memset(rm, 0, sizeof(*rm));
- mutex_init(&rm->rm_lock);
- INIT_LIST_HEAD(&rm->rsvps);
- for (type = 0; type < SDE_HW_BLK_MAX; type++)
- INIT_LIST_HEAD(&rm->hw_blks[type]);
- rm->dev = dev;
- if (IS_SDE_CTL_REV_100(cat->ctl_rev))
- rm->topology_tbl = g_top_table_v1;
- else
- rm->topology_tbl = g_top_table;
- /* Some of the sub-blocks require an mdptop to be created */
- rm->hw_mdp = sde_hw_mdptop_init(MDP_TOP, mmio, cat);
- if (IS_ERR_OR_NULL(rm->hw_mdp)) {
- rc = PTR_ERR(rm->hw_mdp);
- rm->hw_mdp = NULL;
- SDE_ERROR("failed: mdp hw not available\n");
- goto fail;
- }
- /* Interrogate HW catalog and create tracking items for hw blocks */
- for (i = 0; i < cat->mixer_count; i++) {
- struct sde_lm_cfg *lm = &cat->mixer[i];
- if (lm->pingpong == PINGPONG_MAX) {
- SDE_ERROR("mixer %d without pingpong\n", lm->id);
- goto fail;
- }
- rc = _sde_rm_hw_blk_create(rm, cat, mmio, SDE_HW_BLK_LM,
- cat->mixer[i].id, &cat->mixer[i]);
- if (rc) {
- SDE_ERROR("failed: lm hw not available\n");
- goto fail;
- }
- if (!rm->lm_max_width) {
- rm->lm_max_width = lm->sblk->maxwidth;
- } else if (rm->lm_max_width != lm->sblk->maxwidth) {
- /*
- * Don't expect to have hw where lm max widths differ.
- * If found, take the min.
- */
- SDE_ERROR("unsupported: lm maxwidth differs\n");
- if (rm->lm_max_width > lm->sblk->maxwidth)
- rm->lm_max_width = lm->sblk->maxwidth;
- }
- }
- rc = _sde_rm_hw_blk_create_new(rm, cat, mmio, sde_kms);
- if (!rc)
- return 0;
- fail:
- sde_rm_destroy(rm);
- return rc;
- }
- static bool _sde_rm_check_lm(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- const struct sde_lm_cfg *lm_cfg,
- struct sde_rm_hw_blk *lm,
- struct sde_rm_hw_blk **dspp,
- struct sde_rm_hw_blk **ds,
- struct sde_rm_hw_blk **pp)
- {
- bool is_valid_dspp, is_valid_ds, ret = true;
- is_valid_dspp = (lm_cfg->dspp != DSPP_MAX) ? true : false;
- is_valid_ds = (lm_cfg->ds != DS_MAX) ? true : false;
- /**
- * RM_RQ_X: specification of which LMs to choose
- * is_valid_X: indicates whether LM is tied with block X
- * ret: true if given LM matches the user requirement,
- * false otherwise
- */
- if (RM_RQ_DSPP(reqs) && RM_RQ_DS(reqs))
- ret = (is_valid_dspp && is_valid_ds);
- else if (RM_RQ_DSPP(reqs))
- ret = is_valid_dspp;
- else if (RM_RQ_DS(reqs))
- ret = is_valid_ds;
- if (!ret) {
- SDE_DEBUG(
- "fail:lm(%d)req_dspp(%d)dspp(%d)req_ds(%d)ds(%d)\n",
- lm_cfg->id, (bool)(RM_RQ_DSPP(reqs)),
- lm_cfg->dspp, (bool)(RM_RQ_DS(reqs)),
- lm_cfg->ds);
- return ret;
- }
- return true;
- }
- static bool _sde_rm_reserve_dspp(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- const struct sde_lm_cfg *lm_cfg,
- struct sde_rm_hw_blk *lm,
- struct sde_rm_hw_blk **dspp)
- {
- struct sde_rm_hw_iter iter;
- if (lm_cfg->dspp != DSPP_MAX) {
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DSPP);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- if (iter.blk->id == lm_cfg->dspp) {
- *dspp = iter.blk;
- break;
- }
- }
- if (!*dspp) {
- SDE_DEBUG("lm %d failed to retrieve dspp %d\n", lm->id,
- lm_cfg->dspp);
- return false;
- }
- if (RESERVED_BY_OTHER(*dspp, rsvp)) {
- SDE_DEBUG("lm %d dspp %d already reserved\n",
- lm->id, (*dspp)->id);
- return false;
- }
- }
- return true;
- }
- static bool _sde_rm_reserve_ds(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- const struct sde_lm_cfg *lm_cfg,
- struct sde_rm_hw_blk *lm,
- struct sde_rm_hw_blk **ds)
- {
- struct sde_rm_hw_iter iter;
- if (lm_cfg->ds != DS_MAX) {
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DS);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- if (iter.blk->id == lm_cfg->ds) {
- *ds = iter.blk;
- break;
- }
- }
- if (!*ds) {
- SDE_DEBUG("lm %d failed to retrieve ds %d\n", lm->id,
- lm_cfg->ds);
- return false;
- }
- if (RESERVED_BY_OTHER(*ds, rsvp)) {
- SDE_DEBUG("lm %d ds %d already reserved\n",
- lm->id, (*ds)->id);
- return false;
- }
- }
- return true;
- }
- static bool _sde_rm_reserve_pp(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- const struct sde_lm_cfg *lm_cfg,
- const struct sde_pingpong_cfg *pp_cfg,
- struct sde_rm_hw_blk *lm,
- struct sde_rm_hw_blk **dspp,
- struct sde_rm_hw_blk **ds,
- struct sde_rm_hw_blk **pp)
- {
- struct sde_rm_hw_iter iter;
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_PINGPONG);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- if (iter.blk->id == lm_cfg->pingpong) {
- *pp = iter.blk;
- break;
- }
- }
- if (!*pp) {
- SDE_ERROR("failed to get pp on lm %d\n", lm_cfg->pingpong);
- return false;
- }
- if (RESERVED_BY_OTHER(*pp, rsvp)) {
- SDE_DEBUG("lm %d pp %d already reserved\n", lm->id,
- (*pp)->id);
- *dspp = NULL;
- *ds = NULL;
- return false;
- }
- pp_cfg = to_sde_hw_pingpong((*pp)->hw)->caps;
- if ((reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) &&
- !(test_bit(SDE_PINGPONG_SPLIT, &pp_cfg->features))) {
- SDE_DEBUG("pp %d doesn't support ppsplit\n", pp_cfg->id);
- *dspp = NULL;
- *ds = NULL;
- return false;
- }
- return true;
- }
- /**
- * _sde_rm_check_lm_and_get_connected_blks - check if proposed layer mixer meets
- * proposed use case requirements, incl. hardwired dependent blocks like
- * pingpong, and dspp.
- * @rm: sde resource manager handle
- * @rsvp: reservation currently being created
- * @reqs: proposed use case requirements
- * @lm: proposed layer mixer, function checks if lm, and all other hardwired
- * blocks connected to the lm (pp, dspp) are available and appropriate
- * @dspp: output parameter, dspp block attached to the layer mixer.
- * NULL if dspp was not available, or not matching requirements.
- * @pp: output parameter, pingpong block attached to the layer mixer.
- * NULL if dspp was not available, or not matching requirements.
- * @primary_lm: if non-null, this function check if lm is compatible primary_lm
- * as well as satisfying all other requirements
- * @Return: true if lm matches all requirements, false otherwise
- */
- static bool _sde_rm_check_lm_and_get_connected_blks(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- struct sde_rm_hw_blk *lm,
- struct sde_rm_hw_blk **dspp,
- struct sde_rm_hw_blk **ds,
- struct sde_rm_hw_blk **pp,
- struct sde_rm_hw_blk *primary_lm,
- u32 conn_lm_mask)
- {
- const struct sde_lm_cfg *lm_cfg = to_sde_hw_mixer(lm->hw)->cap;
- const struct sde_pingpong_cfg *pp_cfg;
- bool ret, is_conn_primary, is_conn_secondary;
- u32 lm_primary_pref, lm_secondary_pref, cwb_pref, dcwb_pref;
- *dspp = NULL;
- *ds = NULL;
- *pp = NULL;
- lm_primary_pref = lm_cfg->features & BIT(SDE_DISP_PRIMARY_PREF);
- lm_secondary_pref = lm_cfg->features & BIT(SDE_DISP_SECONDARY_PREF);
- cwb_pref = lm_cfg->features & BIT(SDE_DISP_CWB_PREF);
- dcwb_pref = lm_cfg->features & BIT(SDE_DISP_DCWB_PREF);
- is_conn_primary = (reqs->hw_res.display_type ==
- SDE_CONNECTOR_PRIMARY) ? true : false;
- is_conn_secondary = (reqs->hw_res.display_type ==
- SDE_CONNECTOR_SECONDARY) ? true : false;
- SDE_DEBUG("check lm %d: dspp %d ds %d pp %d features %ld disp type %d\n",
- lm_cfg->id, lm_cfg->dspp, lm_cfg->ds, lm_cfg->pingpong,
- lm_cfg->features, (int)reqs->hw_res.display_type);
- /* Check if this layer mixer is a peer of the proposed primary LM */
- if (primary_lm) {
- const struct sde_lm_cfg *prim_lm_cfg =
- to_sde_hw_mixer(primary_lm->hw)->cap;
- if (!test_bit(lm_cfg->id, &prim_lm_cfg->lm_pair_mask)) {
- SDE_DEBUG("lm %d not peer of lm %d\n", lm_cfg->id,
- prim_lm_cfg->id);
- return false;
- }
- }
- /* bypass rest of the checks if LM for primary display is found */
- if (!lm_primary_pref && !lm_secondary_pref) {
- /* Check lm for valid requirements */
- ret = _sde_rm_check_lm(rm, rsvp, reqs, lm_cfg, lm,
- dspp, ds, pp);
- if (!ret)
- return ret;
- /**
- * If CWB is enabled and LM is not CWB supported
- * then return false.
- */
- if ((RM_RQ_CWB(reqs) && !cwb_pref) ||
- (RM_RQ_DCWB(reqs) && !dcwb_pref)) {
- SDE_DEBUG("fail: cwb/dcwb supported lm not allocated\n");
- return false;
- } else if (!RM_RQ_DCWB(reqs) && dcwb_pref) {
- SDE_DEBUG("fail: dcwb supported dummy lm incorrectly allocated\n");
- return false;
- } else if (RM_RQ_DCWB(reqs) && dcwb_pref && conn_lm_mask &&
- ((ffs(conn_lm_mask) % 2) == ((lm_cfg->id + 1) % 2))) {
- SDE_DEBUG("fail: dcwb:%d trying to match lm:%d\n",
- lm_cfg->id, ffs(conn_lm_mask));
- return false;
- }
- } else if ((!is_conn_primary && lm_primary_pref) ||
- (!is_conn_secondary && lm_secondary_pref)) {
- SDE_DEBUG(
- "display preference is not met. display_type: %d lm_features: %lx\n",
- (int)reqs->hw_res.display_type, lm_cfg->features);
- return false;
- }
- /* Already reserved? */
- if (RESERVED_BY_OTHER(lm, rsvp)) {
- SDE_DEBUG("lm %d already reserved\n", lm_cfg->id);
- return false;
- }
- /* Reserve dspp */
- ret = _sde_rm_reserve_dspp(rm, rsvp, lm_cfg, lm, dspp);
- if (!ret)
- return ret;
- /* Reserve ds */
- ret = _sde_rm_reserve_ds(rm, rsvp, lm_cfg, lm, ds);
- if (!ret)
- return ret;
- /* Reserve pp */
- ret = _sde_rm_reserve_pp(rm, rsvp, reqs, lm_cfg, pp_cfg, lm,
- dspp, ds, pp);
- if (!ret)
- return ret;
- return true;
- }
- static int _sde_rm_reserve_lms(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- u8 *_lm_ids)
- {
- struct sde_rm_hw_blk *lm[MAX_BLOCKS];
- struct sde_rm_hw_blk *dspp[MAX_BLOCKS];
- struct sde_rm_hw_blk *ds[MAX_BLOCKS];
- struct sde_rm_hw_blk *pp[MAX_BLOCKS];
- struct sde_rm_hw_iter iter_i, iter_j;
- u32 lm_mask = 0, conn_lm_mask = 0;
- int lm_count = 0;
- int i, rc = 0;
- if (!reqs->topology->num_lm) {
- SDE_DEBUG("invalid number of lm: %d\n", reqs->topology->num_lm);
- return 0;
- }
- if (RM_RQ_DCWB(reqs))
- conn_lm_mask = reqs->conn_lm_mask;
- /* Find a primary mixer */
- sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_LM);
- while (lm_count != reqs->topology->num_lm &&
- _sde_rm_get_hw_locked(rm, &iter_i)) {
- if (lm_mask & (1 << iter_i.blk->id))
- continue;
- lm[lm_count] = iter_i.blk;
- dspp[lm_count] = NULL;
- ds[lm_count] = NULL;
- pp[lm_count] = NULL;
- SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
- iter_i.blk->id,
- lm_count,
- _lm_ids ? _lm_ids[lm_count] : -1);
- if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
- continue;
- if (!_sde_rm_check_lm_and_get_connected_blks(
- rm, rsvp, reqs, lm[lm_count],
- &dspp[lm_count], &ds[lm_count],
- &pp[lm_count], NULL, conn_lm_mask))
- continue;
- lm_mask |= (1 << iter_i.blk->id);
- ++lm_count;
- /* Return if peer is not needed */
- if (lm_count == reqs->topology->num_lm)
- break;
- if (RM_RQ_DCWB(reqs))
- conn_lm_mask = conn_lm_mask & ~BIT(ffs(conn_lm_mask) - 1);
- /* Valid primary mixer found, find matching peers */
- sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_LM);
- while (_sde_rm_get_hw_locked(rm, &iter_j)) {
- if (lm_mask & (1 << iter_j.blk->id))
- continue;
- lm[lm_count] = iter_j.blk;
- dspp[lm_count] = NULL;
- ds[lm_count] = NULL;
- pp[lm_count] = NULL;
- if (!_sde_rm_check_lm_and_get_connected_blks(
- rm, rsvp, reqs, iter_j.blk,
- &dspp[lm_count], &ds[lm_count],
- &pp[lm_count], iter_i.blk,
- conn_lm_mask))
- continue;
- SDE_DEBUG("blk id = %d, _lm_ids[%d] = %d\n",
- iter_j.blk->id,
- lm_count,
- _lm_ids ? _lm_ids[lm_count] : -1);
- if (_lm_ids && (lm[lm_count])->id != _lm_ids[lm_count])
- continue;
- lm_mask |= (1 << iter_j.blk->id);
- ++lm_count;
- if (RM_RQ_DCWB(reqs))
- conn_lm_mask = conn_lm_mask & ~BIT(ffs(conn_lm_mask) - 1);
- break;
- }
- /* Rollback primary LM if peer is not found */
- if (!iter_j.hw) {
- lm_mask &= ~(1 << iter_i.blk->id);
- --lm_count;
- }
- }
- if (lm_count != reqs->topology->num_lm) {
- SDE_DEBUG("unable to find appropriate mixers\n");
- return -ENAVAIL;
- }
- for (i = 0; i < lm_count; i++) {
- lm[i]->rsvp_nxt = rsvp;
- pp[i]->rsvp_nxt = rsvp;
- if (dspp[i])
- dspp[i]->rsvp_nxt = rsvp;
- if (ds[i])
- ds[i]->rsvp_nxt = rsvp;
- SDE_EVT32(lm[i]->type, rsvp->enc_id, lm[i]->id, pp[i]->id,
- dspp[i] ? dspp[i]->id : 0,
- ds[i] ? ds[i]->id : 0);
- }
- if (reqs->topology->top_name == SDE_RM_TOPOLOGY_PPSPLIT) {
- /* reserve a free PINGPONG_SLAVE block */
- rc = -ENAVAIL;
- sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_PINGPONG);
- while (_sde_rm_get_hw_locked(rm, &iter_i)) {
- const struct sde_hw_pingpong *pp =
- to_sde_hw_pingpong(iter_i.blk->hw);
- const struct sde_pingpong_cfg *pp_cfg = pp->caps;
- if (!(test_bit(SDE_PINGPONG_SLAVE, &pp_cfg->features)))
- continue;
- if (RESERVED_BY_OTHER(iter_i.blk, rsvp))
- continue;
- iter_i.blk->rsvp_nxt = rsvp;
- rc = 0;
- break;
- }
- }
- return rc;
- }
- static int _sde_rm_reserve_ctls(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- const struct sde_rm_topology_def *top,
- u8 *_ctl_ids)
- {
- struct sde_rm_hw_blk *ctls[MAX_BLOCKS];
- struct sde_rm_hw_iter iter, curr;
- int i = 0;
- if (!top->num_ctl) {
- SDE_DEBUG("invalid number of ctl: %d\n", top->num_ctl);
- return 0;
- }
- memset(&ctls, 0, sizeof(ctls));
- sde_rm_init_hw_iter(&curr, rsvp->enc_id, SDE_HW_BLK_CTL);
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CTL);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- const struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter.blk->hw);
- unsigned long features = ctl->caps->features;
- bool has_split_display, has_ppsplit, primary_pref;
- if (RESERVED_BY_OTHER(iter.blk, rsvp))
- continue;
- has_split_display = BIT(SDE_CTL_SPLIT_DISPLAY) & features;
- has_ppsplit = BIT(SDE_CTL_PINGPONG_SPLIT) & features;
- primary_pref = BIT(SDE_CTL_PRIMARY_PREF) & features;
- SDE_DEBUG("ctl %d caps 0x%lX\n", iter.blk->id, features);
- /*
- * bypass rest feature checks on finding CTL preferred
- * for primary displays.
- */
- if (!primary_pref && !_ctl_ids) {
- if (top->needs_split_display != has_split_display)
- continue;
- if (top->top_name == SDE_RM_TOPOLOGY_PPSPLIT &&
- !has_ppsplit)
- continue;
- } else if (!(reqs->hw_res.display_type ==
- SDE_CONNECTOR_PRIMARY && primary_pref) && !_ctl_ids) {
- SDE_DEBUG(
- "display pref not met. display_type: %d primary_pref: %d\n",
- reqs->hw_res.display_type, primary_pref);
- continue;
- }
- if (_sde_rm_get_hw_locked(rm, &curr) && (curr.blk->id != iter.blk->id)) {
- SDE_EVT32(curr.blk->id, iter.blk->id, SDE_EVTLOG_FUNC_CASE1);
- SDE_DEBUG("ctl in use:%d avoiding new:%d\n", curr.blk->id, iter.blk->id);
- continue;
- }
- ctls[i] = iter.blk;
- SDE_DEBUG("blk id = %d, _ctl_ids[%d] = %d\n",
- iter.blk->id, i,
- _ctl_ids ? _ctl_ids[i] : -1);
- if (_ctl_ids && (ctls[i]->id != _ctl_ids[i]))
- continue;
- SDE_DEBUG("ctl %d match\n", iter.blk->id);
- if (++i == top->num_ctl)
- break;
- }
- if (i != top->num_ctl)
- return -ENAVAIL;
- for (i = 0; i < ARRAY_SIZE(ctls) && i < top->num_ctl; i++) {
- ctls[i]->rsvp_nxt = rsvp;
- SDE_EVT32(ctls[i]->type, rsvp->enc_id, ctls[i]->id);
- }
- return 0;
- }
- static bool _sde_rm_check_dsc(struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_hw_blk *dsc,
- struct sde_rm_hw_blk *paired_dsc,
- struct sde_rm_hw_blk *pp_blk)
- {
- const struct sde_dsc_cfg *dsc_cfg = to_sde_hw_dsc(dsc->hw)->caps;
- /* Already reserved? */
- if (RESERVED_BY_OTHER(dsc, rsvp)) {
- SDE_DEBUG("dsc %d already reserved\n", dsc_cfg->id);
- return false;
- }
- /**
- * This check is required for routing even numbered DSC
- * blks to any of the even numbered PP blks and odd numbered
- * DSC blks to any of the odd numbered PP blks.
- */
- if (!pp_blk || !IS_COMPATIBLE_PP_DSC(pp_blk->id, dsc->id))
- return false;
- /* Check if this dsc is a peer of the proposed paired DSC */
- if (paired_dsc) {
- const struct sde_dsc_cfg *paired_dsc_cfg =
- to_sde_hw_dsc(paired_dsc->hw)->caps;
- if (!test_bit(dsc_cfg->id, paired_dsc_cfg->dsc_pair_mask)) {
- SDE_DEBUG("dsc %d not peer of dsc %d\n", dsc_cfg->id,
- paired_dsc_cfg->id);
- return false;
- }
- }
- return true;
- }
- static bool _sde_rm_check_vdc(struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_hw_blk *vdc)
- {
- const struct sde_vdc_cfg *vdc_cfg = to_sde_hw_vdc(vdc->hw)->caps;
- /* Already reserved? */
- if (RESERVED_BY_OTHER(vdc, rsvp)) {
- SDE_DEBUG("vdc %d already reserved\n", vdc_cfg->id);
- return false;
- }
- return true;
- }
- static void sde_rm_get_rsvp_nxt_hw_blks(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- int type,
- struct sde_rm_hw_blk **blk_arr)
- {
- struct sde_rm_hw_blk *blk;
- int i = 0;
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (blk->rsvp_nxt && blk->rsvp_nxt->seq ==
- rsvp->seq)
- blk_arr[i++] = blk;
- }
- }
- static int _sde_rm_reserve_dsc(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- u8 *_dsc_ids)
- {
- struct sde_rm_hw_iter iter_i, iter_j;
- struct sde_rm_hw_blk *dsc[MAX_BLOCKS];
- u32 reserve_mask = 0;
- struct sde_rm_hw_blk *pp[MAX_BLOCKS];
- int alloc_count = 0;
- int num_dsc_enc;
- struct msm_display_dsc_info *dsc_info;
- int i;
- if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_DSC) {
- SDE_DEBUG("compression blk dsc not required\n");
- return 0;
- }
- num_dsc_enc = reqs->topology->num_comp_enc;
- dsc_info = &reqs->hw_res.comp_info->dsc_info;
- if ((!num_dsc_enc) || !dsc_info) {
- SDE_DEBUG("invalid topoplogy params: %d, %d\n",
- num_dsc_enc, !(dsc_info == NULL));
- return 0;
- }
- sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_DSC);
- sde_rm_get_rsvp_nxt_hw_blks(rm, rsvp, SDE_HW_BLK_PINGPONG, pp);
- /* Find a first DSC */
- while (alloc_count != num_dsc_enc &&
- _sde_rm_get_hw_locked(rm, &iter_i)) {
- const struct sde_hw_dsc *hw_dsc = to_sde_hw_dsc(
- iter_i.blk->hw);
- unsigned long features = hw_dsc->caps->features;
- bool has_422_420_support =
- BIT(SDE_DSC_NATIVE_422_EN) & features;
- if (reserve_mask & (1 << iter_i.blk->id))
- continue;
- if (_dsc_ids && (iter_i.blk->id != _dsc_ids[alloc_count]))
- continue;
- /* if this hw block does not support required feature */
- if (!_dsc_ids && (dsc_info->config.native_422 ||
- dsc_info->config.native_420) && !has_422_420_support)
- continue;
- if (!_sde_rm_check_dsc(rm, rsvp, iter_i.blk, NULL,
- pp[alloc_count]))
- continue;
- SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
- iter_i.blk->id,
- alloc_count,
- _dsc_ids ? _dsc_ids[alloc_count] : -1);
- reserve_mask |= (1 << iter_i.blk->id);
- dsc[alloc_count++] = iter_i.blk;
- /* Return if peer is not needed */
- if (alloc_count == num_dsc_enc)
- break;
- /* Valid first dsc found, find matching peers */
- sde_rm_init_hw_iter(&iter_j, 0, SDE_HW_BLK_DSC);
- while (_sde_rm_get_hw_locked(rm, &iter_j)) {
- if (reserve_mask & (1 << iter_j.blk->id))
- continue;
- if (_dsc_ids && (iter_j.blk->id !=
- _dsc_ids[alloc_count]))
- continue;
- if (!_sde_rm_check_dsc(rm, rsvp, iter_j.blk,
- iter_i.blk, pp[alloc_count]))
- continue;
- SDE_DEBUG("blk id = %d, _dsc_ids[%d] = %d\n",
- iter_j.blk->id,
- alloc_count,
- _dsc_ids ? _dsc_ids[alloc_count] : -1);
- reserve_mask |= (1 << iter_j.blk->id);
- dsc[alloc_count++] = iter_j.blk;
- break;
- }
- /* Rollback primary DSC if peer is not found */
- if (!iter_j.hw) {
- reserve_mask &= ~(1 << iter_i.blk->id);
- --alloc_count;
- }
- }
- if (alloc_count != num_dsc_enc) {
- SDE_ERROR("couldn't reserve %d dsc blocks for enc id %d\n",
- num_dsc_enc, rsvp->enc_id);
- return -EINVAL;
- }
- for (i = 0; i < alloc_count; i++) {
- if (!dsc[i])
- break;
- dsc[i]->rsvp_nxt = rsvp;
- SDE_EVT32(dsc[i]->type, rsvp->enc_id, dsc[i]->id);
- }
- return 0;
- }
- static int _sde_rm_reserve_vdc(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- const struct sde_rm_topology_def *top,
- u8 *_vdc_ids)
- {
- struct sde_rm_hw_iter iter_i;
- struct sde_rm_hw_blk *vdc[MAX_BLOCKS];
- int alloc_count = 0;
- int num_vdc_enc = top->num_comp_enc;
- int i;
- if (!top->num_comp_enc)
- return 0;
- if (reqs->hw_res.comp_info->comp_type != MSM_DISPLAY_COMPRESSION_VDC)
- return 0;
- sde_rm_init_hw_iter(&iter_i, 0, SDE_HW_BLK_VDC);
- /* Find a VDC */
- while (alloc_count != num_vdc_enc &&
- _sde_rm_get_hw_locked(rm, &iter_i)) {
- memset(&vdc, 0, sizeof(vdc));
- alloc_count = 0;
- if (_vdc_ids && (iter_i.blk->id != _vdc_ids[alloc_count]))
- continue;
- if (!_sde_rm_check_vdc(rm, rsvp, iter_i.blk))
- continue;
- SDE_DEBUG("blk id = %d, _vdc_ids[%d] = %d\n",
- iter_i.blk->id,
- alloc_count,
- _vdc_ids ? _vdc_ids[alloc_count] : -1);
- vdc[alloc_count++] = iter_i.blk;
- }
- if (alloc_count != num_vdc_enc) {
- SDE_ERROR("couldn't reserve %d vdc blocks for enc id %d\n",
- num_vdc_enc, rsvp->enc_id);
- return -EINVAL;
- }
- for (i = 0; i < ARRAY_SIZE(vdc); i++) {
- if (!vdc[i])
- break;
- vdc[i]->rsvp_nxt = rsvp;
- SDE_EVT32(vdc[i]->type, rsvp->enc_id, vdc[i]->id);
- }
- return 0;
- }
- static int _sde_rm_reserve_qdss(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- const struct sde_rm_topology_def *top,
- u8 *_qdss_ids)
- {
- struct sde_rm_hw_iter iter;
- struct msm_drm_private *priv = rm->dev->dev_private;
- struct sde_kms *sde_kms;
- if (!priv->kms) {
- SDE_ERROR("invalid kms\n");
- return -EINVAL;
- }
- sde_kms = to_sde_kms(priv->kms);
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_QDSS);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- if (RESERVED_BY_OTHER(iter.blk, rsvp))
- continue;
- SDE_DEBUG("blk id = %d\n", iter.blk->id);
- iter.blk->rsvp_nxt = rsvp;
- SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
- return 0;
- }
- if (!iter.hw && sde_kms->catalog->qdss_count) {
- SDE_DEBUG("couldn't reserve qdss for type %d id %d\n",
- SDE_HW_BLK_QDSS, iter.blk->id);
- return -ENAVAIL;
- }
- return 0;
- }
- static int _sde_rm_reserve_dnsc_blur(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- uint32_t id, enum sde_hw_blk_type type)
- {
- struct sde_rm_hw_iter iter;
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_DNSC_BLUR);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- struct sde_hw_dnsc_blur *dnsc_blur = to_sde_hw_dnsc_blur(iter.blk->hw);
- bool match = false;
- if (RESERVED_BY_OTHER(iter.blk, rsvp))
- continue;
- if ((type == SDE_HW_BLK_WB) && (id != WB_MAX))
- match = test_bit(id, &dnsc_blur->caps->wb_connect);
- SDE_DEBUG("type %d id %d, dnsc_blur wbs %lu match %d\n",
- type, id, dnsc_blur->caps->wb_connect, match);
- if (!match)
- continue;
- iter.blk->rsvp_nxt = rsvp;
- SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
- break;
- }
- if (!iter.hw) {
- SDE_ERROR("couldn't reserve dnsc_blur for type %d id %d\n", type, id);
- return -ENAVAIL;
- }
- return 0;
- }
- static int _sde_rm_reserve_cdm(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- uint32_t id,
- enum sde_hw_blk_type type)
- {
- struct sde_rm_hw_iter iter;
- sde_rm_init_hw_iter(&iter, 0, SDE_HW_BLK_CDM);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- const struct sde_hw_cdm *cdm = to_sde_hw_cdm(iter.blk->hw);
- const struct sde_cdm_cfg *caps = cdm->caps;
- bool match = false;
- if (RESERVED_BY_OTHER(iter.blk, rsvp))
- continue;
- if (type == SDE_HW_BLK_INTF && id != INTF_MAX)
- match = test_bit(id, &caps->intf_connect);
- else if (type == SDE_HW_BLK_WB && id != WB_MAX)
- match = test_bit(id, &caps->wb_connect);
- SDE_DEBUG("type %d id %d, cdm intfs %lu wbs %lu match %d\n",
- type, id, caps->intf_connect, caps->wb_connect,
- match);
- if (!match)
- continue;
- iter.blk->rsvp_nxt = rsvp;
- SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
- break;
- }
- if (!iter.hw) {
- SDE_ERROR("couldn't reserve cdm for type %d id %d\n", type, id);
- return -ENAVAIL;
- }
- return 0;
- }
- static int _sde_rm_reserve_intf_or_wb(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- uint32_t id, enum sde_hw_blk_type type, struct sde_rm_requirements *reqs)
- {
- struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
- struct sde_rm_hw_iter iter;
- int ret = 0;
- /* Find the block entry in the rm, and note the reservation */
- sde_rm_init_hw_iter(&iter, 0, type);
- while (_sde_rm_get_hw_locked(rm, &iter)) {
- if (iter.blk->id != id)
- continue;
- if (RESERVED_BY_OTHER(iter.blk, rsvp)) {
- SDE_ERROR("type %d id %d already reserved\n", type, id);
- return -ENAVAIL;
- }
- iter.blk->rsvp_nxt = rsvp;
- SDE_EVT32(iter.blk->type, rsvp->enc_id, iter.blk->id);
- break;
- }
- /* Shouldn't happen since wbs / intfs are fixed at probe */
- if (!iter.hw) {
- SDE_ERROR("couldn't find type %d id %d\n", type, id);
- return -EINVAL;
- }
- /* Expected only one intf or wb will request cdm */
- if (hw_res->needs_cdm || RM_RQ_CDM(reqs)) {
- ret = _sde_rm_reserve_cdm(rm, rsvp, id, type);
- if (ret)
- return ret;
- }
- if (RM_RQ_DNSC_BLUR(reqs))
- ret = _sde_rm_reserve_dnsc_blur(rm, rsvp, id, type);
- return ret;
- }
- static int _sde_rm_reserve_intf_related_hw(struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp, struct sde_rm_requirements *reqs)
- {
- struct sde_encoder_hw_resources *hw_res = &reqs->hw_res;
- int i, ret = 0;
- u32 id;
- for (i = 0; i < ARRAY_SIZE(hw_res->intfs); i++) {
- if (hw_res->intfs[i] == INTF_MODE_NONE)
- continue;
- id = i + INTF_0;
- ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_INTF, reqs);
- if (ret)
- return ret;
- }
- for (i = 0; i < ARRAY_SIZE(hw_res->wbs); i++) {
- if (hw_res->wbs[i] == INTF_MODE_NONE)
- continue;
- id = i + WB_0;
- ret = _sde_rm_reserve_intf_or_wb(rm, rsvp, id, SDE_HW_BLK_WB, reqs);
- if (ret)
- return ret;
- }
- return ret;
- }
- static bool _sde_rm_is_display_in_cont_splash(struct sde_kms *sde_kms,
- struct drm_encoder *enc)
- {
- int i;
- struct sde_splash_display *splash_dpy;
- for (i = 0; i < MAX_DSI_DISPLAYS; i++) {
- splash_dpy = &sde_kms->splash_data.splash_display[i];
- if (splash_dpy->encoder == enc)
- return splash_dpy->cont_splash_enabled;
- }
- return false;
- }
- static int _sde_rm_make_lm_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- struct sde_splash_display *splash_display)
- {
- int ret, i;
- u8 *hw_ids = NULL;
- /* Check if splash data provided lm_ids */
- if (splash_display) {
- hw_ids = splash_display->lm_ids;
- for (i = 0; i < splash_display->lm_cnt; i++)
- SDE_DEBUG("splash_display->lm_ids[%d] = %d\n",
- i, splash_display->lm_ids[i]);
- if (splash_display->lm_cnt != reqs->topology->num_lm)
- SDE_DEBUG("Configured splash LMs != needed LM cnt\n");
- }
- /*
- * Assign LMs and blocks whose usage is tied to them:
- * DSPP & Pingpong.
- */
- ret = _sde_rm_reserve_lms(rm, rsvp, reqs, hw_ids);
- return ret;
- }
- static int _sde_rm_make_ctl_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- struct sde_splash_display *splash_display)
- {
- int ret, i;
- u8 *hw_ids = NULL;
- struct sde_rm_topology_def topology;
- /* Check if splash data provided ctl_ids */
- if (splash_display) {
- hw_ids = splash_display->ctl_ids;
- for (i = 0; i < splash_display->ctl_cnt; i++)
- SDE_DEBUG("splash_display->ctl_ids[%d] = %d\n",
- i, splash_display->ctl_ids[i]);
- }
- /*
- * Do assignment preferring to give away low-resource CTLs first:
- * - Check mixers without Split Display
- * - Only then allow to grab from CTLs with split display capability
- */
- ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, reqs->topology, hw_ids);
- if (ret && !reqs->topology->needs_split_display &&
- reqs->topology->num_ctl > SINGLE_CTL) {
- memcpy(&topology, reqs->topology, sizeof(topology));
- topology.needs_split_display = true;
- ret = _sde_rm_reserve_ctls(rm, rsvp, reqs, &topology, hw_ids);
- }
- return ret;
- }
- /*
- * Returns number of dsc hw blocks previously owned by this encoder.
- * Returns 0 if not found or error
- */
- static int _sde_rm_find_prev_dsc(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- u8 *prev_dsc, u32 max_cnt)
- {
- int i = 0;
- struct sde_rm_hw_iter iter_dsc;
- if ((!prev_dsc) || (max_cnt < MAX_DATA_PATH_PER_DSIPLAY))
- return 0;
- sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
- while (_sde_rm_get_hw_locked(rm, &iter_dsc)) {
- if (RESERVED_BY_CURRENT(iter_dsc.blk, rsvp))
- prev_dsc[i++] = iter_dsc.blk->id;
- if (i >= MAX_DATA_PATH_PER_DSIPLAY)
- return 0;
- }
- return i;
- }
- static int _sde_rm_make_dsc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- struct sde_splash_display *splash_display)
- {
- int i;
- u8 *hw_ids = NULL;
- u8 prev_dsc[MAX_DATA_PATH_PER_DSIPLAY] = {0,};
- /* Check if splash data provided dsc_ids */
- if (splash_display) {
- hw_ids = splash_display->dsc_ids;
- if (splash_display->dsc_cnt)
- reqs->hw_res.comp_info->comp_type =
- MSM_DISPLAY_COMPRESSION_DSC;
- for (i = 0; i < splash_display->dsc_cnt; i++)
- SDE_DEBUG("splash_data.dsc_ids[%d] = %d\n",
- i, splash_display->dsc_ids[i]);
- }
- /*
- * find if this encoder has previously allocated dsc hw blocks, use same dsc blocks
- * if found to avoid switching dsc encoders during each modeset, as currently we
- * dont have feasible way of decoupling previously owned dsc blocks by resetting
- * respective dsc encoders mux control and flush them from commit path
- */
- if (!hw_ids && _sde_rm_find_prev_dsc(rm, rsvp, prev_dsc, MAX_DATA_PATH_PER_DSIPLAY))
- return _sde_rm_reserve_dsc(rm, rsvp, reqs, prev_dsc);
- else
- return _sde_rm_reserve_dsc(rm, rsvp, reqs, hw_ids);
- }
- static int _sde_rm_make_vdc_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs,
- struct sde_splash_display *splash_display)
- {
- int ret, i;
- u8 *hw_ids = NULL;
- /* Check if splash data provided vdc_ids */
- if (splash_display) {
- hw_ids = splash_display->vdc_ids;
- for (i = 0; i < splash_display->vdc_cnt; i++)
- SDE_DEBUG("splash_data.vdc_ids[%d] = %d\n",
- i, splash_display->vdc_ids[i]);
- }
- ret = _sde_rm_reserve_vdc(rm, rsvp, reqs, reqs->topology, hw_ids);
- return ret;
- }
- static int _sde_rm_make_next_rsvp(struct sde_rm *rm, struct drm_encoder *enc,
- struct drm_crtc_state *crtc_state,
- struct drm_connector_state *conn_state,
- struct sde_rm_rsvp *rsvp,
- struct sde_rm_requirements *reqs)
- {
- struct msm_drm_private *priv;
- struct sde_kms *sde_kms;
- struct sde_splash_display *splash_display = NULL;
- struct sde_splash_data *splash_data;
- int i, ret;
- priv = enc->dev->dev_private;
- sde_kms = to_sde_kms(priv->kms);
- splash_data = &sde_kms->splash_data;
- if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
- for (i = 0; i < ARRAY_SIZE(splash_data->splash_display); i++) {
- if (enc == splash_data->splash_display[i].encoder)
- splash_display =
- &splash_data->splash_display[i];
- }
- if (!splash_display) {
- SDE_ERROR("rm is in cont_splash but data not found\n");
- return -EINVAL;
- }
- }
- /* Create reservation info, tag reserved blocks with it as we go */
- rsvp->seq = ++rm->rsvp_next_seq;
- rsvp->enc_id = enc->base.id;
- rsvp->topology = reqs->topology->top_name;
- rsvp->pending = true;
- list_add_tail(&rsvp->list, &rm->rsvps);
- ret = _sde_rm_make_lm_rsvp(rm, rsvp, reqs, splash_display);
- if (ret) {
- SDE_ERROR("unable to find appropriate mixers\n");
- _sde_rm_print_rsvps_by_type(rm, SDE_HW_BLK_LM);
- return ret;
- }
- ret = _sde_rm_make_ctl_rsvp(rm, rsvp, reqs, splash_display);
- if (ret) {
- SDE_ERROR("unable to find appropriate CTL\n");
- return ret;
- }
- /* Assign INTFs, WBs, and blks whose usage is tied to them: CTL & CDM */
- ret = _sde_rm_reserve_intf_related_hw(rm, rsvp, reqs);
- if (ret)
- return ret;
- ret = _sde_rm_make_dsc_rsvp(rm, rsvp, reqs, splash_display);
- if (ret)
- return ret;
- ret = _sde_rm_make_vdc_rsvp(rm, rsvp, reqs, splash_display);
- if (ret)
- return ret;
- ret = _sde_rm_reserve_qdss(rm, rsvp, reqs->topology, NULL);
- if (ret)
- return ret;
- return ret;
- }
- static int _sde_rm_update_active_only_pipes(
- struct sde_splash_display *splash_display,
- u32 active_pipes_mask)
- {
- struct sde_sspp_index_info *pipe_info;
- int i;
- if (!active_pipes_mask) {
- return 0;
- } else if (!splash_display) {
- SDE_ERROR("invalid splash display provided\n");
- return -EINVAL;
- }
- pipe_info = &splash_display->pipe_info;
- for (i = SSPP_VIG0; i < SSPP_MAX; i++) {
- if (!(active_pipes_mask & BIT(i)))
- continue;
- if (test_bit(i, pipe_info->pipes) || test_bit(i, pipe_info->virt_pipes))
- continue;
- /*
- * A pipe is active but not staged indicates a non-pixel
- * plane. Register both rectangles as we can't differentiate
- */
- set_bit(i, pipe_info->pipes);
- set_bit(i, pipe_info->virt_pipes);
- SDE_DEBUG("pipe %d is active:0x%x but not staged\n", i, active_pipes_mask);
- }
- return 0;
- }
- /**
- * _sde_rm_get_hw_blk_for_cont_splash - retrieve the LM blocks on given CTL
- * and populate the connected HW blk ids in sde_splash_display
- * @rm: Pointer to resource manager structure
- * @ctl: Pointer to CTL hardware block
- * @splash_display: Pointer to struct sde_splash_display
- * return: number of active LM blocks for this CTL block
- */
- static int _sde_rm_get_hw_blk_for_cont_splash(struct sde_rm *rm,
- struct sde_hw_ctl *ctl,
- struct sde_splash_display *splash_display)
- {
- u32 active_pipes_mask = 0;
- struct sde_rm_hw_iter iter_lm, iter_dsc;
- struct sde_kms *sde_kms;
- size_t pipes_per_lm;
- if (!rm || !ctl || !splash_display) {
- SDE_ERROR("invalid input parameters\n");
- return 0;
- }
- sde_kms = container_of(rm, struct sde_kms, rm);
- sde_rm_init_hw_iter(&iter_lm, 0, SDE_HW_BLK_LM);
- sde_rm_init_hw_iter(&iter_dsc, 0, SDE_HW_BLK_DSC);
- while (_sde_rm_get_hw_locked(rm, &iter_lm)) {
- if (splash_display->lm_cnt >= MAX_DATA_PATH_PER_DSIPLAY)
- break;
- if (ctl->ops.get_staged_sspp) {
- // reset bordercolor from previous LM
- splash_display->pipe_info.bordercolor = false;
- pipes_per_lm = ctl->ops.get_staged_sspp(
- ctl, iter_lm.blk->id,
- &splash_display->pipe_info);
- if (pipes_per_lm ||
- splash_display->pipe_info.bordercolor) {
- splash_display->lm_ids[splash_display->lm_cnt++] =
- iter_lm.blk->id;
- SDE_DEBUG("lm_cnt=%d lm_id %d pipe_cnt%d\n",
- splash_display->lm_cnt,
- iter_lm.blk->id - LM_0,
- pipes_per_lm);
- }
- }
- }
- if (ctl->ops.get_active_pipes)
- active_pipes_mask = ctl->ops.get_active_pipes(ctl);
- if (_sde_rm_update_active_only_pipes(splash_display, active_pipes_mask))
- return 0;
- while (_sde_rm_get_hw_locked(rm, &iter_dsc)) {
- if (ctl->ops.read_active_status &&
- !(ctl->ops.read_active_status(ctl,
- SDE_HW_BLK_DSC,
- iter_dsc.blk->id)))
- continue;
- splash_display->dsc_ids[splash_display->dsc_cnt++] =
- iter_dsc.blk->id;
- SDE_DEBUG("CTL[%d] path, using dsc[%d]\n",
- ctl->idx,
- iter_dsc.blk->id - DSC_0);
- }
- return splash_display->lm_cnt;
- }
- int sde_rm_cont_splash_res_init(struct msm_drm_private *priv,
- struct sde_rm *rm,
- struct sde_splash_data *splash_data,
- struct sde_mdss_cfg *cat)
- {
- struct sde_rm_hw_iter iter_c;
- int index = 0, ctl_top_cnt;
- struct sde_kms *sde_kms = NULL;
- struct sde_hw_mdp *hw_mdp;
- struct sde_splash_display *splash_display;
- u8 intf_sel;
- if (!priv || !rm || !cat || !splash_data) {
- SDE_ERROR("invalid input parameters\n");
- return -EINVAL;
- }
- SDE_DEBUG("mixer_count=%d, ctl_count=%d, dsc_count=%d\n",
- cat->mixer_count,
- cat->ctl_count,
- cat->dsc_count);
- ctl_top_cnt = cat->ctl_count;
- if (!priv->kms) {
- SDE_ERROR("invalid kms\n");
- return -EINVAL;
- }
- sde_kms = to_sde_kms(priv->kms);
- hw_mdp = sde_rm_get_mdp(rm);
- sde_rm_init_hw_iter(&iter_c, 0, SDE_HW_BLK_CTL);
- while (_sde_rm_get_hw_locked(rm, &iter_c)
- && (index < splash_data->num_splash_displays)) {
- struct sde_hw_ctl *ctl = to_sde_hw_ctl(iter_c.blk->hw);
- if (!ctl->ops.get_ctl_intf) {
- SDE_ERROR("get_ctl_intf not initialized\n");
- return -EINVAL;
- }
- intf_sel = ctl->ops.get_ctl_intf(ctl);
- if (intf_sel) {
- splash_display = &splash_data->splash_display[index];
- SDE_DEBUG("finding resources for display=%d ctl=%d\n",
- index, iter_c.blk->id - CTL_0);
- _sde_rm_get_hw_blk_for_cont_splash(rm,
- ctl, splash_display);
- splash_display->cont_splash_enabled = true;
- splash_display->ctl_ids[splash_display->ctl_cnt++] =
- iter_c.blk->id;
- }
- index++;
- }
- return 0;
- }
- static struct drm_connector *_sde_rm_get_connector(
- struct drm_encoder *enc)
- {
- struct drm_connector *conn = NULL, *conn_search;
- struct sde_connector *c_conn = NULL;
- struct drm_connector_list_iter conn_iter;
- drm_connector_list_iter_begin(enc->dev, &conn_iter);
- drm_for_each_connector_iter(conn_search, &conn_iter) {
- c_conn = to_sde_connector(conn_search);
- if (c_conn->encoder == enc) {
- conn = conn_search;
- break;
- }
- }
- drm_connector_list_iter_end(&conn_iter);
- return conn;
- }
- static int _sde_rm_populate_requirements(
- struct sde_rm *rm,
- struct drm_encoder *enc,
- struct drm_crtc_state *crtc_state,
- struct drm_connector_state *conn_state,
- struct sde_mdss_cfg *cfg,
- struct sde_rm_requirements *reqs)
- {
- const struct drm_display_mode *mode = &crtc_state->mode;
- struct drm_encoder *encoder_iter;
- struct drm_connector *conn;
- int i, num_lm;
- reqs->top_ctrl = sde_connector_get_property(conn_state,
- CONNECTOR_PROP_TOPOLOGY_CONTROL);
- sde_encoder_get_hw_resources(enc, &reqs->hw_res, conn_state);
- for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++) {
- if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i],
- reqs->hw_res.topology)) {
- reqs->topology = &rm->topology_tbl[i];
- break;
- }
- }
- if (!reqs->topology) {
- SDE_ERROR("invalid topology for the display\n");
- return -EINVAL;
- }
- /*
- * select dspp HW block for all dsi displays and ds for only
- * primary dsi display.
- */
- if (conn_state->connector->connector_type == DRM_MODE_CONNECTOR_DSI) {
- if (!RM_RQ_DSPP(reqs))
- reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DSPP);
- if (!RM_RQ_DS(reqs) && rm->hw_mdp->caps->has_dest_scaler &&
- sde_encoder_is_primary_display(enc))
- reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DS);
- }
- /**
- * Set the requirement for LM which has CWB support if CWB is
- * found enabled.
- */
- if ((!RM_RQ_CWB(reqs) || !RM_RQ_DCWB(reqs))
- && sde_crtc_state_in_clone_mode(enc, crtc_state)) {
- if (test_bit(SDE_FEATURE_DEDICATED_CWB, cfg->features))
- reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_DCWB);
- else
- reqs->top_ctrl |= BIT(SDE_RM_TOPCTL_CWB);
- /*
- * topology selection based on conn mode is not valid for CWB
- * as WB conn populates modes based on max_mixer_width check
- * but primary can be using dual LMs. This topology override for
- * CWB is to check number of datapath active in primary and
- * allocate same number of LM/PP blocks reserved for CWB
- */
- reqs->topology =
- &rm->topology_tbl[SDE_RM_TOPOLOGY_DUALPIPE_3DMERGE];
- num_lm = sde_crtc_get_num_datapath(crtc_state->crtc,
- conn_state->connector, crtc_state);
- if (num_lm == 1)
- reqs->topology =
- &rm->topology_tbl[SDE_RM_TOPOLOGY_SINGLEPIPE];
- else if (num_lm == 0)
- SDE_ERROR("Primary layer mixer is not set\n");
- SDE_EVT32(num_lm, reqs->topology->num_lm,
- reqs->topology->top_name, reqs->topology->num_ctl);
- }
- if (RM_RQ_DCWB(reqs)) {
- drm_for_each_encoder_mask(encoder_iter, enc->dev,
- crtc_state->encoder_mask) {
- if (drm_encoder_mask(encoder_iter) == drm_encoder_mask(enc))
- continue;
- conn = _sde_rm_get_connector(encoder_iter);
- if (conn)
- reqs->conn_lm_mask = to_sde_connector(conn)->lm_mask;
- break;
- }
- }
- SDE_DEBUG("top_ctrl: 0x%llX num_h_tiles: %d\n", reqs->top_ctrl,
- reqs->hw_res.display_num_of_h_tiles);
- SDE_DEBUG("num_lm: %d num_ctl: %d topology: %d split_display: %d mask: 0x%llX\n",
- reqs->topology->num_lm, reqs->topology->num_ctl,
- reqs->topology->top_name,
- reqs->topology->needs_split_display, reqs->conn_lm_mask);
- SDE_EVT32(mode->hdisplay, rm->lm_max_width, reqs->topology->num_lm,
- reqs->top_ctrl, reqs->topology->top_name,
- reqs->topology->num_ctl, reqs->conn_lm_mask);
- return 0;
- }
- static struct sde_rm_rsvp *_sde_rm_get_rsvp(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
- {
- struct sde_rm_rsvp *i;
- if (!rm || !enc) {
- SDE_ERROR("invalid params\n");
- return NULL;
- }
- if (list_empty(&rm->rsvps))
- return NULL;
- list_for_each_entry(i, &rm->rsvps, list)
- if (i->pending == nxt && i->enc_id == enc->base.id)
- return i;
- return NULL;
- }
- static struct sde_rm_rsvp *_sde_rm_get_rsvp_nxt(struct sde_rm *rm, struct drm_encoder *enc)
- {
- return _sde_rm_get_rsvp(rm, enc, true);
- }
- static struct sde_rm_rsvp *_sde_rm_get_rsvp_cur(struct sde_rm *rm, struct drm_encoder *enc)
- {
- return _sde_rm_get_rsvp(rm, enc, false);
- }
- int sde_rm_update_topology(struct sde_rm *rm,
- struct drm_connector_state *conn_state,
- struct msm_display_topology *topology)
- {
- int i, ret = 0;
- struct msm_display_topology top;
- enum sde_rm_topology_name top_name = SDE_RM_TOPOLOGY_NONE;
- if (!conn_state)
- return -EINVAL;
- if (topology) {
- top = *topology;
- for (i = 0; i < SDE_RM_TOPOLOGY_MAX; i++)
- if (RM_IS_TOPOLOGY_MATCH(rm->topology_tbl[i], top)) {
- top_name = rm->topology_tbl[i].top_name;
- break;
- }
- }
- ret = msm_property_set_property(
- sde_connector_get_propinfo(conn_state->connector),
- sde_connector_get_property_state(conn_state),
- CONNECTOR_PROP_TOPOLOGY_NAME, top_name);
- return ret;
- }
- bool sde_rm_topology_is_group(struct sde_rm *rm,
- struct drm_crtc_state *state,
- enum sde_rm_topology_group group)
- {
- int i, ret = 0;
- struct sde_crtc_state *cstate;
- struct drm_connector *conn;
- struct drm_connector_state *conn_state;
- struct msm_display_topology topology;
- enum sde_rm_topology_name name;
- if ((!rm) || (!state) || (!state->state)) {
- pr_err("invalid arguments: rm:%d state:%d atomic state:%d\n",
- !rm, !state, state ? (!state->state) : 0);
- return false;
- }
- cstate = to_sde_crtc_state(state);
- for (i = 0; i < cstate->num_connectors; i++) {
- conn = cstate->connectors[i];
- if (!conn) {
- SDE_DEBUG("invalid connector\n");
- continue;
- }
- conn_state = drm_atomic_get_new_connector_state(state->state,
- conn);
- if (!conn_state) {
- SDE_DEBUG("%s invalid connector state\n", conn->name);
- continue;
- }
- ret = sde_connector_state_get_topology(conn_state, &topology);
- if (ret) {
- SDE_DEBUG("%s invalid topology\n", conn->name);
- continue;
- }
- name = sde_rm_get_topology_name(rm, topology);
- switch (group) {
- case SDE_RM_TOPOLOGY_GROUP_SINGLEPIPE:
- if (TOPOLOGY_SINGLEPIPE_MODE(name))
- return true;
- break;
- case SDE_RM_TOPOLOGY_GROUP_DUALPIPE:
- if (TOPOLOGY_DUALPIPE_MODE(name))
- return true;
- break;
- case SDE_RM_TOPOLOGY_GROUP_QUADPIPE:
- if (TOPOLOGY_QUADPIPE_MODE(name))
- return true;
- break;
- case SDE_RM_TOPOLOGY_GROUP_3DMERGE:
- if (topology.num_lm > topology.num_intf &&
- !topology.num_enc)
- return true;
- break;
- case SDE_RM_TOPOLOGY_GROUP_3DMERGE_DSC:
- if (topology.num_lm > topology.num_enc &&
- topology.num_enc)
- return true;
- break;
- case SDE_RM_TOPOLOGY_GROUP_DSCMERGE:
- if (topology.num_lm == topology.num_enc &&
- topology.num_enc)
- return true;
- break;
- default:
- SDE_ERROR("invalid topology group\n");
- return false;
- }
- }
- return false;
- }
- /**
- * _sde_rm_release_rsvp - release resources and release a reservation
- * @rm: KMS handle
- * @rsvp: RSVP pointer to release and release resources for
- */
- static void _sde_rm_release_rsvp(
- struct sde_rm *rm,
- struct sde_rm_rsvp *rsvp,
- struct drm_connector *conn)
- {
- struct sde_rm_rsvp *rsvp_c, *rsvp_n;
- struct sde_rm_hw_blk *blk;
- enum sde_hw_blk_type type;
- if (!rsvp)
- return;
- SDE_DEBUG("rel rsvp %d enc %d\n", rsvp->seq, rsvp->enc_id);
- list_for_each_entry_safe(rsvp_c, rsvp_n, &rm->rsvps, list) {
- if (rsvp == rsvp_c) {
- list_del(&rsvp_c->list);
- break;
- }
- }
- for (type = 0; type < SDE_HW_BLK_MAX; type++) {
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (blk->rsvp == rsvp) {
- blk->rsvp = NULL;
- SDE_DEBUG("rel rsvp %d enc %d %d %d\n",
- rsvp->seq, rsvp->enc_id,
- blk->type, blk->id);
- _sde_rm_inc_resource_info(rm,
- &rm->avail_res, blk);
- }
- if (blk->rsvp_nxt == rsvp) {
- blk->rsvp_nxt = NULL;
- SDE_DEBUG("rel rsvp_nxt %d enc %d %d %d\n",
- rsvp->seq, rsvp->enc_id,
- blk->type, blk->id);
- }
- }
- }
- kfree(rsvp);
- }
- void sde_rm_release(struct sde_rm *rm, struct drm_encoder *enc, bool nxt)
- {
- struct sde_rm_rsvp *rsvp;
- struct drm_connector *conn = NULL;
- struct msm_drm_private *priv;
- struct sde_kms *sde_kms;
- uint64_t top_ctrl = 0;
- if (!rm || !enc) {
- SDE_ERROR("invalid params\n");
- return;
- }
- priv = enc->dev->dev_private;
- if (!priv->kms) {
- SDE_ERROR("invalid kms\n");
- return;
- }
- sde_kms = to_sde_kms(priv->kms);
- mutex_lock(&rm->rm_lock);
- rsvp = _sde_rm_get_rsvp(rm, enc, nxt);
- if (!rsvp) {
- SDE_DEBUG("failed to find rsvp for enc %d, nxt %d",
- enc->base.id, nxt);
- goto end;
- }
- if (_sde_rm_is_display_in_cont_splash(sde_kms, enc)) {
- _sde_rm_release_rsvp(rm, rsvp, conn);
- goto end;
- }
- conn = _sde_rm_get_connector(enc);
- if (!conn) {
- SDE_EVT32(enc->base.id, 0x0, 0xffffffff);
- _sde_rm_release_rsvp(rm, rsvp, conn);
- SDE_DEBUG("failed to get conn for enc %d nxt %d\n",
- enc->base.id, nxt);
- goto end;
- }
- top_ctrl = sde_connector_get_property(conn->state,
- CONNECTOR_PROP_TOPOLOGY_CONTROL);
- SDE_EVT32(enc->base.id, conn->base.id, rsvp->seq, top_ctrl, nxt);
- if (top_ctrl & BIT(SDE_RM_TOPCTL_RESERVE_LOCK)) {
- SDE_DEBUG("rsvp[s%de%d] not releasing locked resources\n",
- rsvp->seq, rsvp->enc_id);
- } else {
- SDE_DEBUG("release rsvp[s%de%d]\n", rsvp->seq,
- rsvp->enc_id);
- _sde_rm_release_rsvp(rm, rsvp, conn);
- }
- end:
- mutex_unlock(&rm->rm_lock);
- }
- static void _sde_rm_commit_rsvp(struct sde_rm *rm, struct sde_rm_rsvp *rsvp,
- struct drm_connector_state *conn_state)
- {
- struct sde_rm_hw_blk *blk;
- enum sde_hw_blk_type type;
- /* Swap next rsvp to be the active */
- for (type = 0; type < SDE_HW_BLK_MAX; type++) {
- list_for_each_entry(blk, &rm->hw_blks[type], list) {
- if (blk->rsvp_nxt && conn_state->best_encoder->base.id
- == blk->rsvp_nxt->enc_id) {
- blk->rsvp = blk->rsvp_nxt;
- blk->rsvp_nxt = NULL;
- _sde_rm_dec_resource_info(rm,
- &rm->avail_res, blk);
- }
- }
- }
- rsvp->pending = false;
- SDE_DEBUG("rsrv enc %d topology %d\n", rsvp->enc_id, rsvp->topology);
- SDE_EVT32(rsvp->enc_id, rsvp->topology);
- }
- static void _sde_rm_populate_dp_lm_mask(struct sde_rm *rm,
- struct drm_connector *conn)
- {
- struct sde_connector *c_conn = NULL;
- struct sde_rm_hw_blk *blk;
- if (!rm || !conn) {
- SDE_ERROR("invalid arguments\n");
- return;
- }
- if (conn->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
- return;
- c_conn = to_sde_connector(conn);
- if (!c_conn || !c_conn->encoder)
- return;
- list_for_each_entry(blk, &rm->hw_blks[SDE_HW_BLK_LM], list) {
- if (!blk->rsvp)
- continue;
- if (blk->rsvp->enc_id == c_conn->encoder->base.id)
- c_conn->lm_mask |= BIT(blk->id - 1);
- }
- SDE_DEBUG("conn lm_mask %d for conn %d enc %d\n", c_conn->lm_mask,
- conn->base.id, c_conn->encoder->base.id);
- SDE_EVT32(c_conn->encoder->base.id, conn->base.id, c_conn->lm_mask);
- }
- /* call this only after rm_mutex held */
- struct sde_rm_rsvp *_sde_rm_poll_get_rsvp_nxt_locked(struct sde_rm *rm,
- struct drm_encoder *enc)
- {
- int i;
- u32 loop_count = 20;
- struct sde_rm_rsvp *rsvp_nxt = NULL;
- u32 sleep = RM_NXT_CLEAR_POLL_TIMEOUT_US / loop_count;
- for (i = 0; i < loop_count; i++) {
- rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
- if (!rsvp_nxt)
- return rsvp_nxt;
- mutex_unlock(&rm->rm_lock);
- SDE_DEBUG("iteration i:%d sleep range:%uus to %uus\n",
- i, sleep, sleep * 2);
- usleep_range(sleep, sleep * 2);
- mutex_lock(&rm->rm_lock);
- }
- /* make sure to get latest rsvp_next to avoid use after free issues */
- return _sde_rm_get_rsvp_nxt(rm, enc);
- }
- int sde_rm_reserve(
- struct sde_rm *rm,
- struct drm_encoder *enc,
- struct drm_crtc_state *crtc_state,
- struct drm_connector_state *conn_state,
- bool test_only)
- {
- struct sde_rm_rsvp *rsvp_cur, *rsvp_nxt;
- struct sde_rm_requirements reqs = {0,};
- struct msm_drm_private *priv;
- struct sde_kms *sde_kms;
- struct msm_compression_info *comp_info;
- int ret = 0;
- if (!rm || !enc || !crtc_state || !conn_state) {
- SDE_ERROR("invalid arguments\n");
- return -EINVAL;
- }
- if (!enc->dev || !enc->dev->dev_private) {
- SDE_ERROR("drm device invalid\n");
- return -EINVAL;
- }
- priv = enc->dev->dev_private;
- if (!priv->kms) {
- SDE_ERROR("invalid kms\n");
- return -EINVAL;
- }
- sde_kms = to_sde_kms(priv->kms);
- /* Check if this is just a page-flip */
- if (!_sde_rm_is_display_in_cont_splash(sde_kms, enc) &&
- !msm_atomic_needs_modeset(crtc_state, conn_state))
- return 0;
- comp_info = kzalloc(sizeof(*comp_info), GFP_KERNEL);
- if (!comp_info)
- return -ENOMEM;
- SDE_DEBUG("reserving hw for conn %d enc %d crtc %d test_only %d\n",
- conn_state->connector->base.id, enc->base.id,
- crtc_state->crtc->base.id, test_only);
- SDE_EVT32(enc->base.id, conn_state->connector->base.id, test_only);
- mutex_lock(&rm->rm_lock);
- _sde_rm_print_rsvps(rm, SDE_RM_STAGE_BEGIN);
- rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
- rsvp_nxt = _sde_rm_get_rsvp_nxt(rm, enc);
- /*
- * RM currently relies on rsvp_nxt assigned to the hw blocks to
- * commit rsvps. This rsvp_nxt can be cleared by a back to back
- * check_only commit with modeset when its predecessor atomic
- * commit is delayed / not committed the reservation yet.
- * Poll for rsvp_nxt clear, allow the check_only commit if rsvp_nxt
- * gets cleared and bailout if it does not get cleared before timeout.
- */
- if (test_only && rsvp_nxt) {
- rsvp_nxt = _sde_rm_poll_get_rsvp_nxt_locked(rm, enc);
- rsvp_cur = _sde_rm_get_rsvp_cur(rm, enc);
- if (rsvp_nxt) {
- pr_err("poll timeout cur %d nxt %d enc %d\n",
- (rsvp_cur) ? rsvp_cur->seq : -1,
- rsvp_nxt->seq, enc->base.id);
- SDE_EVT32(enc->base.id, (rsvp_cur) ? rsvp_cur->seq : -1,
- rsvp_nxt->seq, SDE_EVTLOG_ERROR);
- ret = -EAGAIN;
- goto end;
- }
- }
- if (!test_only && rsvp_nxt)
- goto commit_rsvp;
- reqs.hw_res.comp_info = comp_info;
- ret = _sde_rm_populate_requirements(rm, enc, crtc_state,
- conn_state, sde_kms->catalog, &reqs);
- if (ret) {
- SDE_ERROR("failed to populate hw requirements\n");
- goto end;
- }
- /*
- * We only support one active reservation per-hw-block. But to implement
- * transactional semantics for test-only, and for allowing failure while
- * modifying your existing reservation, over the course of this
- * function we can have two reservations:
- * Current: Existing reservation
- * Next: Proposed reservation. The proposed reservation may fail, or may
- * be discarded if in test-only mode.
- * If reservation is successful, and we're not in test-only, then we
- * replace the current with the next.
- */
- rsvp_nxt = kzalloc(sizeof(*rsvp_nxt), GFP_KERNEL);
- if (!rsvp_nxt) {
- ret = -ENOMEM;
- goto end;
- }
- /*
- * User can request that we clear out any reservation during the
- * atomic_check phase by using this CLEAR bit
- */
- if (rsvp_cur && test_only && RM_RQ_CLEAR(&reqs)) {
- SDE_DEBUG("test_only & CLEAR: clear rsvp[s%de%d]\n",
- rsvp_cur->seq, rsvp_cur->enc_id);
- _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
- rsvp_cur = NULL;
- _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_CLEAR);
- }
- /* Check the proposed reservation, store it in hw's "next" field */
- ret = _sde_rm_make_next_rsvp(rm, enc, crtc_state, conn_state,
- rsvp_nxt, &reqs);
- _sde_rm_print_rsvps(rm, SDE_RM_STAGE_AFTER_RSVPNEXT);
- if (ret) {
- SDE_ERROR("failed to reserve hw resources: %d, test_only %d\n",
- ret, test_only);
- _sde_rm_release_rsvp(rm, rsvp_nxt, conn_state->connector);
- goto end;
- } else if (test_only && !RM_RQ_LOCK(&reqs)) {
- /*
- * Normally, if test_only, test the reservation and then undo
- * However, if the user requests LOCK, then keep the reservation
- * made during the atomic_check phase.
- */
- SDE_DEBUG("test_only: rsvp[s%de%d]\n",
- rsvp_nxt->seq, rsvp_nxt->enc_id);
- goto end;
- } else {
- if (test_only && RM_RQ_LOCK(&reqs))
- SDE_DEBUG("test_only & LOCK: lock rsvp[s%de%d]\n",
- rsvp_nxt->seq, rsvp_nxt->enc_id);
- }
- commit_rsvp:
- _sde_rm_release_rsvp(rm, rsvp_cur, conn_state->connector);
- _sde_rm_commit_rsvp(rm, rsvp_nxt, conn_state);
- _sde_rm_populate_dp_lm_mask(rm, conn_state->connector);
- end:
- kfree(comp_info);
- _sde_rm_print_rsvps(rm, SDE_RM_STAGE_FINAL);
- mutex_unlock(&rm->rm_lock);
- return ret;
- }
|