12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
- */
- #include <linux/iommu.h>
- #include <linux/workqueue.h>
- #include <media/v4l2_vidc_extensions.h>
- #include "msm_media_info.h"
- #include "msm_vidc_driver.h"
- #include "msm_vidc_platform.h"
- #include "msm_vidc_internal.h"
- #include "msm_vidc_control.h"
- #include "msm_vidc_memory.h"
- #include "msm_vidc_debug.h"
- #include "msm_vidc_power.h"
- #include "msm_vidc.h"
- #include "msm_vdec.h"
- #include "msm_venc.h"
- #include "venus_hfi.h"
- #include "venus_hfi_response.h"
- #include "hfi_packet.h"
- extern struct msm_vidc_core *g_core;
- #define COUNT_BITS(a, out) { \
- while ((a) >= 1) { \
- (out) += (a) & (1); \
- (a) >>= (1); \
- } \
- }
- #define SSR_TYPE 0x0000000F
- #define SSR_TYPE_SHIFT 0
- #define SSR_SUB_CLIENT_ID 0x000000F0
- #define SSR_SUB_CLIENT_ID_SHIFT 4
- #define SSR_ADDR_ID 0xFFFFFFFF00000000
- #define SSR_ADDR_SHIFT 32
- struct msm_vidc_cap_name {
- enum msm_vidc_inst_capability_type cap;
- char *name;
- };
- static const struct msm_vidc_cap_name cap_name_arr[] = {
- {INST_CAP_NONE, "INST_CAP_NONE" },
- {FRAME_WIDTH, "FRAME_WIDTH" },
- {LOSSLESS_FRAME_WIDTH, "LOSSLESS_FRAME_WIDTH" },
- {SECURE_FRAME_WIDTH, "SECURE_FRAME_WIDTH" },
- {FRAME_HEIGHT, "FRAME_HEIGHT" },
- {LOSSLESS_FRAME_HEIGHT, "LOSSLESS_FRAME_HEIGHT" },
- {SECURE_FRAME_HEIGHT, "SECURE_FRAME_HEIGHT" },
- {PIX_FMTS, "PIX_FMTS" },
- {MIN_BUFFERS_INPUT, "MIN_BUFFERS_INPUT" },
- {MIN_BUFFERS_OUTPUT, "MIN_BUFFERS_OUTPUT" },
- {MBPF, "MBPF" },
- {LOSSLESS_MBPF, "LOSSLESS_MBPF" },
- {BATCH_MBPF, "BATCH_MBPF" },
- {BATCH_FPS, "BATCH_FPS" },
- {SECURE_MBPF, "SECURE_MBPF" },
- {MBPS, "MBPS" },
- {POWER_SAVE_MBPS, "POWER_SAVE_MBPS" },
- {FRAME_RATE, "FRAME_RATE" },
- {OPERATING_RATE, "OPERATING_RATE" },
- {SCALE_X, "SCALE_X" },
- {SCALE_Y, "SCALE_Y" },
- {MB_CYCLES_VSP, "MB_CYCLES_VSP" },
- {MB_CYCLES_VPP, "MB_CYCLES_VPP" },
- {MB_CYCLES_LP, "MB_CYCLES_LP" },
- {MB_CYCLES_FW, "MB_CYCLES_FW" },
- {MB_CYCLES_FW_VPP, "MB_CYCLES_FW_VPP" },
- {SECURE_MODE, "SECURE_MODE" },
- {HFLIP, "HFLIP" },
- {VFLIP, "VFLIP" },
- {ROTATION, "ROTATION" },
- {SUPER_FRAME, "SUPER_FRAME" },
- {SLICE_INTERFACE, "SLICE_INTERFACE" },
- {HEADER_MODE, "HEADER_MODE" },
- {PREPEND_SPSPPS_TO_IDR, "PREPEND_SPSPPS_TO_IDR" },
- {META_SEQ_HDR_NAL, "META_SEQ_HDR_NAL" },
- {WITHOUT_STARTCODE, "WITHOUT_STARTCODE" },
- {NAL_LENGTH_FIELD, "NAL_LENGTH_FIELD" },
- {REQUEST_I_FRAME, "REQUEST_I_FRAME" },
- {BIT_RATE, "BIT_RATE" },
- {BITRATE_MODE, "BITRATE_MODE" },
- {LOSSLESS, "LOSSLESS" },
- {FRAME_SKIP_MODE, "FRAME_SKIP_MODE" },
- {FRAME_RC_ENABLE, "FRAME_RC_ENABLE" },
- {CONSTANT_QUALITY, "CONSTANT_QUALITY" },
- {GOP_SIZE, "GOP_SIZE" },
- {GOP_CLOSURE, "GOP_CLOSURE" },
- {B_FRAME, "B_FRAME" },
- {BLUR_TYPES, "BLUR_TYPES" },
- {BLUR_RESOLUTION, "BLUR_RESOLUTION" },
- {CSC, "CSC" },
- {CSC_CUSTOM_MATRIX, "CSC_CUSTOM_MATRIX" },
- {GRID, "GRID" },
- {LOWLATENCY_MODE, "LOWLATENCY_MODE" },
- {LTR_COUNT, "LTR_COUNT" },
- {USE_LTR, "USE_LTR" },
- {MARK_LTR, "MARK_LTR" },
- {BASELAYER_PRIORITY, "BASELAYER_PRIORITY" },
- {IR_RANDOM, "IR_RANDOM" },
- {AU_DELIMITER, "AU_DELIMITER" },
- {TIME_DELTA_BASED_RC, "TIME_DELTA_BASED_RC" },
- {CONTENT_ADAPTIVE_CODING, "CONTENT_ADAPTIVE_CODING" },
- {BITRATE_BOOST, "BITRATE_BOOST" },
- {MIN_QUALITY, "MIN_QUALITY" },
- {VBV_DELAY, "VBV_DELAY" },
- {PEAK_BITRATE, "PEAK_BITRATE" },
- {MIN_FRAME_QP, "MIN_FRAME_QP" },
- {I_FRAME_MIN_QP, "I_FRAME_MIN_QP" },
- {P_FRAME_MIN_QP, "P_FRAME_MIN_QP" },
- {B_FRAME_MIN_QP, "B_FRAME_MIN_QP" },
- {MAX_FRAME_QP, "MAX_FRAME_QP" },
- {I_FRAME_MAX_QP, "I_FRAME_MAX_QP" },
- {P_FRAME_MAX_QP, "P_FRAME_MAX_QP" },
- {B_FRAME_MAX_QP, "B_FRAME_MAX_QP" },
- {I_FRAME_QP, "I_FRAME_QP" },
- {P_FRAME_QP, "P_FRAME_QP" },
- {B_FRAME_QP, "B_FRAME_QP" },
- {LAYER_TYPE, "LAYER_TYPE" },
- {LAYER_ENABLE, "LAYER_ENABLE" },
- {ENH_LAYER_COUNT, "ENH_LAYER_COUNT" },
- {L0_BR, "L0_BR" },
- {L1_BR, "L1_BR" },
- {L2_BR, "L2_BR" },
- {L3_BR, "L3_BR" },
- {L4_BR, "L4_BR" },
- {L5_BR, "L5_BR" },
- {ENTROPY_MODE, "ENTROPY_MODE" },
- {PROFILE, "PROFILE" },
- {LEVEL, "LEVEL" },
- {HEVC_TIER, "HEVC_TIER" },
- {LF_MODE, "LF_MODE" },
- {LF_ALPHA, "LF_ALPHA" },
- {LF_BETA, "LF_BETA" },
- {SLICE_MODE, "SLICE_MODE" },
- {SLICE_MAX_BYTES, "SLICE_MAX_BYTES" },
- {SLICE_MAX_MB, "SLICE_MAX_MB" },
- {MB_RC, "MB_RC" },
- {TRANSFORM_8X8, "TRANSFORM_8X8" },
- {CHROMA_QP_INDEX_OFFSET, "CHROMA_QP_INDEX_OFFSET" },
- {DISPLAY_DELAY_ENABLE, "DISPLAY_DELAY_ENABLE" },
- {DISPLAY_DELAY, "DISPLAY_DELAY" },
- {CONCEAL_COLOR_8BIT, "CONCEAL_COLOR_8BIT" },
- {CONCEAL_COLOR_10BIT, "CONCEAL_COLOR_10BIT" },
- {STAGE, "STAGE" },
- {PIPE, "PIPE" },
- {POC, "POC" },
- {QUALITY_MODE, "QUALITY_MODE" },
- {CODED_FRAMES, "CODED_FRAMES" },
- {BIT_DEPTH, "BIT_DEPTH" },
- {CODEC_CONFIG, "CODEC_CONFIG" },
- {BITSTREAM_SIZE_OVERWRITE, "BITSTREAM_SIZE_OVERWRITE" },
- {THUMBNAIL_MODE, "THUMBNAIL_MODE" },
- {DEFAULT_HEADER, "DEFAULT_HEADER" },
- {RAP_FRAME, "RAP_FRAME" },
- {SEQ_CHANGE_AT_SYNC_FRAME, "SEQ_CHANGE_AT_SYNC_FRAME" },
- {PRIORITY, "PRIORITY" },
- {ENC_IP_CR, "ENC_IP_CR" },
- {DPB_LIST, "DPB_LIST" },
- {META_LTR_MARK_USE, "META_LTR_MARK_USE" },
- {META_DPB_MISR, "META_DPB_MISR" },
- {META_OPB_MISR, "META_OPB_MISR" },
- {META_INTERLACE, "META_INTERLACE" },
- {META_TIMESTAMP, "META_TIMESTAMP" },
- {META_CONCEALED_MB_CNT, "META_CONCEALED_MB_CNT" },
- {META_HIST_INFO, "META_HIST_INFO" },
- {META_SEI_MASTERING_DISP, "META_SEI_MASTERING_DISP" },
- {META_SEI_CLL, "META_SEI_CLL" },
- {META_HDR10PLUS, "META_HDR10PLUS" },
- {META_EVA_STATS, "META_EVA_STATS" },
- {META_BUF_TAG, "META_BUF_TAG" },
- {META_DPB_TAG_LIST, "META_DPB_TAG_LIST" },
- {META_OUTPUT_BUF_TAG, "META_OUTPUT_BUF_TAG" },
- {META_SUBFRAME_OUTPUT, "META_SUBFRAME_OUTPUT" },
- {META_ENC_QP_METADATA, "META_ENC_QP_METADATA" },
- {META_ROI_INFO, "META_ROI_INFO" },
- {INST_CAP_MAX, "INST_CAP_MAX" },
- };
- const char *cap_name(enum msm_vidc_inst_capability_type cap)
- {
- const char *name = "UNKNOWN CAP";
- if (cap > ARRAY_SIZE(cap_name_arr))
- goto exit;
- if (cap_name_arr[cap].cap != cap)
- goto exit;
- name = cap_name_arr[cap].name;
- exit:
- return name;
- }
- struct msm_vidc_buf_type_name {
- enum msm_vidc_buffer_type type;
- char *name;
- };
- static const struct msm_vidc_buf_type_name buf_type_name_arr[] = {
- {MSM_VIDC_BUF_INPUT, "INPUT" },
- {MSM_VIDC_BUF_OUTPUT, "OUTPUT" },
- {MSM_VIDC_BUF_INPUT_META, "INPUT_META" },
- {MSM_VIDC_BUF_OUTPUT_META, "OUTPUT_META" },
- {MSM_VIDC_BUF_READ_ONLY, "READ_ONLY" },
- {MSM_VIDC_BUF_QUEUE, "QUEUE" },
- {MSM_VIDC_BUF_BIN, "BIN" },
- {MSM_VIDC_BUF_ARP, "ARP" },
- {MSM_VIDC_BUF_COMV, "COMV" },
- {MSM_VIDC_BUF_NON_COMV, "NON_COMV" },
- {MSM_VIDC_BUF_LINE, "LINE" },
- {MSM_VIDC_BUF_DPB, "DPB" },
- {MSM_VIDC_BUF_PERSIST, "PERSIST" },
- {MSM_VIDC_BUF_VPSS, "VPSS" },
- };
- const char *buf_name(enum msm_vidc_buffer_type type)
- {
- const char *name = "UNKNOWN BUF";
- if (!type || type > ARRAY_SIZE(buf_type_name_arr))
- goto exit;
- if (buf_type_name_arr[type - 1].type != type)
- goto exit;
- name = buf_type_name_arr[type - 1].name;
- exit:
- return name;
- }
- struct msm_vidc_inst_state_name {
- enum msm_vidc_inst_state state;
- char *name;
- };
- static const struct msm_vidc_inst_state_name inst_state_name_arr[] = {
- {MSM_VIDC_OPEN, "OPEN" },
- {MSM_VIDC_START_INPUT, "START_INPUT" },
- {MSM_VIDC_START_OUTPUT, "START_OUTPUT" },
- {MSM_VIDC_START, "START" },
- {MSM_VIDC_DRC, "DRC" },
- {MSM_VIDC_DRC_LAST_FLAG, "DRC_LAST_FLAG" },
- {MSM_VIDC_DRAIN, "DRAIN" },
- {MSM_VIDC_DRAIN_LAST_FLAG, "DRAIN_LAST_FLAG" },
- {MSM_VIDC_DRC_DRAIN, "DRC_DRAIN" },
- {MSM_VIDC_DRC_DRAIN_LAST_FLAG, "DRC_DRAIN_LAST_FLAG" },
- {MSM_VIDC_DRAIN_START_INPUT, "DRAIN_START_INPUT" },
- {MSM_VIDC_ERROR, "ERROR" },
- };
- const char *state_name(enum msm_vidc_inst_state state)
- {
- const char *name = "UNKNOWN STATE";
- if (!state || state > ARRAY_SIZE(inst_state_name_arr))
- goto exit;
- if (inst_state_name_arr[state - 1].state != state)
- goto exit;
- name = inst_state_name_arr[state - 1].name;
- exit:
- return name;
- }
- struct msm_vidc_core_state_name {
- enum msm_vidc_core_state state;
- char *name;
- };
- static const struct msm_vidc_core_state_name core_state_name_arr[] = {
- {MSM_VIDC_CORE_DEINIT, "CORE_DEINIT" },
- {MSM_VIDC_CORE_INIT, "CORE_INIT" },
- };
- const char *core_state_name(enum msm_vidc_core_state state)
- {
- const char *name = "UNKNOWN STATE";
- if (state >= ARRAY_SIZE(core_state_name_arr))
- goto exit;
- if (core_state_name_arr[state].state != state)
- goto exit;
- name = core_state_name_arr[state].name;
- exit:
- return name;
- }
- void print_vidc_buffer(u32 tag, const char *tag_str, const char *str, struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *vbuf)
- {
- if (!(tag & msm_vidc_debug) || !inst || !vbuf || !tag_str || !str)
- return;
- dprintk_inst(tag, tag_str, inst,
- "%s: %s: idx %2d fd %3d off %d daddr %#llx size %d filled %d flags %#x ts %lld attr %#x\n",
- str, buf_name(vbuf->type),
- vbuf->index, vbuf->fd, vbuf->data_offset,
- vbuf->device_addr, vbuf->buffer_size, vbuf->data_size,
- vbuf->flags, vbuf->timestamp, vbuf->attr);
- }
- void print_vb2_buffer(const char *str, struct msm_vidc_inst *inst,
- struct vb2_buffer *vb2)
- {
- if (!inst || !vb2)
- return;
- if (vb2->type == INPUT_MPLANE || vb2->type == OUTPUT_MPLANE) {
- i_vpr_e(inst,
- "%s: %s: idx %2d fd %d off %d size %d filled %d\n",
- str, vb2->type == INPUT_MPLANE ? "INPUT" : "OUTPUT",
- vb2->index, vb2->planes[0].m.fd,
- vb2->planes[0].data_offset, vb2->planes[0].length,
- vb2->planes[0].bytesused);
- } else if (vb2->type == INPUT_META_PLANE || vb2->type == OUTPUT_META_PLANE) {
- i_vpr_e(inst,
- "%s: %s: idx %2d fd %d off %d size %d filled %d\n",
- str, vb2->type == INPUT_MPLANE ? "INPUT_META" : "OUTPUT_META",
- vb2->index, vb2->planes[0].m.fd,
- vb2->planes[0].data_offset, vb2->planes[0].length,
- vb2->planes[0].bytesused);
- }
- }
- enum msm_vidc_buffer_type v4l2_type_to_driver(u32 type, const char *func)
- {
- enum msm_vidc_buffer_type buffer_type = 0;
- switch (type) {
- case INPUT_MPLANE:
- buffer_type = MSM_VIDC_BUF_INPUT;
- break;
- case OUTPUT_MPLANE:
- buffer_type = MSM_VIDC_BUF_OUTPUT;
- break;
- case INPUT_META_PLANE:
- buffer_type = MSM_VIDC_BUF_INPUT_META;
- break;
- case OUTPUT_META_PLANE:
- buffer_type = MSM_VIDC_BUF_OUTPUT_META;
- break;
- default:
- d_vpr_e("%s: invalid v4l2 buffer type %#x\n", func, type);
- break;
- }
- return buffer_type;
- }
- u32 v4l2_type_from_driver(enum msm_vidc_buffer_type buffer_type,
- const char *func)
- {
- u32 type = 0;
- switch (buffer_type) {
- case MSM_VIDC_BUF_INPUT:
- type = INPUT_MPLANE;
- break;
- case MSM_VIDC_BUF_OUTPUT:
- type = OUTPUT_MPLANE;
- break;
- case MSM_VIDC_BUF_INPUT_META:
- type = INPUT_META_PLANE;
- break;
- case MSM_VIDC_BUF_OUTPUT_META:
- type = OUTPUT_META_PLANE;
- break;
- default:
- d_vpr_e("%s: invalid driver buffer type %d\n",
- func, buffer_type);
- break;
- }
- return type;
- }
- enum msm_vidc_codec_type v4l2_codec_to_driver(u32 v4l2_codec, const char *func)
- {
- enum msm_vidc_codec_type codec = 0;
- switch (v4l2_codec) {
- case V4L2_PIX_FMT_H264:
- codec = MSM_VIDC_H264;
- break;
- case V4L2_PIX_FMT_HEVC:
- codec = MSM_VIDC_HEVC;
- break;
- case V4L2_PIX_FMT_VP9:
- codec = MSM_VIDC_VP9;
- break;
- case V4L2_PIX_FMT_HEIC:
- codec = MSM_VIDC_HEIC;
- break;
- default:
- d_vpr_e("%s: invalid v4l2 codec %#x\n", func, v4l2_codec);
- break;
- }
- return codec;
- }
- u32 v4l2_codec_from_driver(enum msm_vidc_codec_type codec, const char *func)
- {
- u32 v4l2_codec = 0;
- switch (codec) {
- case MSM_VIDC_H264:
- v4l2_codec = V4L2_PIX_FMT_H264;
- break;
- case MSM_VIDC_HEVC:
- v4l2_codec = V4L2_PIX_FMT_HEVC;
- break;
- case MSM_VIDC_VP9:
- v4l2_codec = V4L2_PIX_FMT_VP9;
- break;
- case MSM_VIDC_HEIC:
- v4l2_codec = V4L2_PIX_FMT_HEIC;
- break;
- default:
- d_vpr_e("%s: invalid driver codec %#x\n", func, codec);
- break;
- }
- return v4l2_codec;
- }
- enum msm_vidc_colorformat_type v4l2_colorformat_to_driver(u32 v4l2_colorformat,
- const char *func)
- {
- enum msm_vidc_colorformat_type colorformat = 0;
- switch (v4l2_colorformat) {
- case V4L2_PIX_FMT_NV12:
- colorformat = MSM_VIDC_FMT_NV12;
- break;
- case V4L2_PIX_FMT_NV21:
- colorformat = MSM_VIDC_FMT_NV21;
- break;
- case V4L2_PIX_FMT_VIDC_NV12C:
- colorformat = MSM_VIDC_FMT_NV12C;
- break;
- case V4L2_PIX_FMT_VIDC_TP10C:
- colorformat = MSM_VIDC_FMT_TP10C;
- break;
- case V4L2_PIX_FMT_RGBA32:
- colorformat = MSM_VIDC_FMT_RGBA8888;
- break;
- case V4L2_PIX_FMT_VIDC_ARGB32C:
- colorformat = MSM_VIDC_FMT_RGBA8888C;
- break;
- case V4L2_PIX_FMT_VIDC_P010:
- colorformat = MSM_VIDC_FMT_P010;
- break;
- default:
- d_vpr_e("%s: invalid v4l2 color format %#x\n",
- func, v4l2_colorformat);
- break;
- }
- return colorformat;
- }
- u32 v4l2_colorformat_from_driver(enum msm_vidc_colorformat_type colorformat,
- const char *func)
- {
- u32 v4l2_colorformat = 0;
- switch (colorformat) {
- case MSM_VIDC_FMT_NV12:
- v4l2_colorformat = V4L2_PIX_FMT_NV12;
- break;
- case MSM_VIDC_FMT_NV21:
- v4l2_colorformat = V4L2_PIX_FMT_NV21;
- break;
- case MSM_VIDC_FMT_NV12C:
- v4l2_colorformat = V4L2_PIX_FMT_VIDC_NV12C;
- break;
- case MSM_VIDC_FMT_TP10C:
- v4l2_colorformat = V4L2_PIX_FMT_VIDC_TP10C;
- break;
- case MSM_VIDC_FMT_RGBA8888:
- v4l2_colorformat = V4L2_PIX_FMT_RGBA32;
- break;
- case MSM_VIDC_FMT_RGBA8888C:
- v4l2_colorformat = V4L2_PIX_FMT_VIDC_ARGB32C;
- break;
- case MSM_VIDC_FMT_P010:
- v4l2_colorformat = V4L2_PIX_FMT_VIDC_P010;
- break;
- default:
- d_vpr_e("%s: invalid driver color format %#x\n",
- func, colorformat);
- break;
- }
- return v4l2_colorformat;
- }
- u32 v4l2_color_primaries_to_driver(struct msm_vidc_inst *inst,
- u32 v4l2_primaries, const char *func)
- {
- u32 vidc_color_primaries = MSM_VIDC_PRIMARIES_RESERVED;
- switch(v4l2_primaries) {
- case V4L2_COLORSPACE_DEFAULT:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_RESERVED;
- break;
- case V4L2_COLORSPACE_REC709:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_BT709;
- break;
- case V4L2_COLORSPACE_470_SYSTEM_M:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_BT470_SYSTEM_M;
- break;
- case V4L2_COLORSPACE_470_SYSTEM_BG:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_BT470_SYSTEM_BG;
- break;
- case V4L2_COLORSPACE_SMPTE170M:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_BT601_525;
- break;
- case V4L2_COLORSPACE_SMPTE240M:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_SMPTE_ST240M;
- break;
- case V4L2_COLORSPACE_VIDC_GENERIC_FILM:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_GENERIC_FILM;
- break;
- case V4L2_COLORSPACE_BT2020:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_BT2020;
- break;
- case V4L2_COLORSPACE_DCI_P3:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_SMPTE_RP431_2;
- break;
- case V4L2_COLORSPACE_VIDC_EG431:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_SMPTE_EG431_1;
- break;
- case V4L2_COLORSPACE_VIDC_EBU_TECH:
- vidc_color_primaries = MSM_VIDC_PRIMARIES_SMPTE_EBU_TECH;
- break;
- default:
- i_vpr_e(inst, "%s: invalid v4l2 color primaries %d\n",
- func, v4l2_primaries);
- break;
- }
- return vidc_color_primaries;
- }
- u32 v4l2_color_primaries_from_driver(struct msm_vidc_inst *inst,
- u32 vidc_color_primaries, const char *func)
- {
- u32 v4l2_primaries = V4L2_COLORSPACE_DEFAULT;
- switch(vidc_color_primaries) {
- case MSM_VIDC_PRIMARIES_UNSPECIFIED:
- v4l2_primaries = V4L2_COLORSPACE_DEFAULT;
- break;
- case MSM_VIDC_PRIMARIES_BT709:
- v4l2_primaries = V4L2_COLORSPACE_REC709;
- break;
- case MSM_VIDC_PRIMARIES_BT470_SYSTEM_M:
- v4l2_primaries = V4L2_COLORSPACE_470_SYSTEM_M;
- break;
- case MSM_VIDC_PRIMARIES_BT470_SYSTEM_BG:
- v4l2_primaries = V4L2_COLORSPACE_470_SYSTEM_BG;
- break;
- case MSM_VIDC_PRIMARIES_BT601_525:
- v4l2_primaries = V4L2_COLORSPACE_SMPTE170M;
- break;
- case MSM_VIDC_PRIMARIES_SMPTE_ST240M:
- v4l2_primaries = V4L2_COLORSPACE_SMPTE240M;
- break;
- case MSM_VIDC_PRIMARIES_GENERIC_FILM:
- v4l2_primaries = V4L2_COLORSPACE_VIDC_GENERIC_FILM;
- break;
- case MSM_VIDC_PRIMARIES_BT2020:
- v4l2_primaries = V4L2_COLORSPACE_BT2020;
- break;
- case MSM_VIDC_PRIMARIES_SMPTE_RP431_2:
- v4l2_primaries = V4L2_COLORSPACE_DCI_P3;
- break;
- case MSM_VIDC_PRIMARIES_SMPTE_EG431_1:
- v4l2_primaries = V4L2_COLORSPACE_VIDC_EG431;
- break;
- case MSM_VIDC_PRIMARIES_SMPTE_EBU_TECH:
- v4l2_primaries = V4L2_COLORSPACE_VIDC_EBU_TECH;
- break;
- default:
- i_vpr_e(inst, "%s: invalid hfi color primaries %d\n",
- func, vidc_color_primaries);
- break;
- }
- return v4l2_primaries;
- }
- u32 v4l2_transfer_char_to_driver(struct msm_vidc_inst *inst,
- u32 v4l2_transfer_char, const char *func)
- {
- u32 vidc_transfer_char = MSM_VIDC_TRANSFER_RESERVED;
- switch(v4l2_transfer_char) {
- case V4L2_XFER_FUNC_DEFAULT:
- vidc_transfer_char = MSM_VIDC_TRANSFER_RESERVED;
- break;
- case V4L2_XFER_FUNC_709:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT709;
- break;
- case V4L2_XFER_FUNC_VIDC_BT470_SYSTEM_M:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT470_SYSTEM_M;
- break;
- case V4L2_XFER_FUNC_VIDC_BT470_SYSTEM_BG:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT470_SYSTEM_BG;
- break;
- case V4L2_XFER_FUNC_VIDC_BT601_525_OR_625:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT601_525_OR_625;
- break;
- case V4L2_XFER_FUNC_SMPTE240M:
- vidc_transfer_char = MSM_VIDC_TRANSFER_SMPTE_ST240M;
- break;
- case V4L2_XFER_FUNC_VIDC_LINEAR:
- vidc_transfer_char = MSM_VIDC_TRANSFER_LINEAR;
- break;
- case V4L2_XFER_FUNC_VIDC_XVYCC:
- vidc_transfer_char = MSM_VIDC_TRANSFER_XVYCC;
- break;
- case V4L2_XFER_FUNC_VIDC_BT1361:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT1361_0;
- break;
- case V4L2_XFER_FUNC_SRGB:
- vidc_transfer_char = MSM_VIDC_TRANSFER_SRGB_SYCC;
- break;
- case V4L2_XFER_FUNC_VIDC_BT2020:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT2020_14;
- break;
- case V4L2_XFER_FUNC_SMPTE2084:
- vidc_transfer_char = MSM_VIDC_TRANSFER_SMPTE_ST2084_PQ;
- break;
- case V4L2_XFER_FUNC_VIDC_ST428:
- vidc_transfer_char = MSM_VIDC_TRANSFER_SMPTE_ST428_1;
- break;
- case V4L2_XFER_FUNC_VIDC_HLG:
- vidc_transfer_char = MSM_VIDC_TRANSFER_BT2100_2_HLG;
- break;
- default:
- i_vpr_e(inst, "%s: invalid v4l2 transfer char %d\n",
- func, v4l2_transfer_char);
- break;
- }
- return vidc_transfer_char;
- }
- u32 v4l2_transfer_char_from_driver(struct msm_vidc_inst *inst,
- u32 vidc_transfer_char, const char *func)
- {
- u32 v4l2_transfer_char = V4L2_XFER_FUNC_DEFAULT;
- switch(vidc_transfer_char) {
- case MSM_VIDC_TRANSFER_UNSPECIFIED:
- v4l2_transfer_char = V4L2_XFER_FUNC_DEFAULT;
- break;
- case MSM_VIDC_TRANSFER_BT709:
- v4l2_transfer_char = V4L2_XFER_FUNC_709;
- break;
- case MSM_VIDC_TRANSFER_BT470_SYSTEM_M:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_BT470_SYSTEM_M;
- break;
- case MSM_VIDC_TRANSFER_BT470_SYSTEM_BG:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_BT470_SYSTEM_BG;
- break;
- case MSM_VIDC_TRANSFER_BT601_525_OR_625:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_BT601_525_OR_625;
- break;
- case MSM_VIDC_TRANSFER_SMPTE_ST240M:
- v4l2_transfer_char = V4L2_XFER_FUNC_SMPTE240M;
- break;
- case MSM_VIDC_TRANSFER_LINEAR:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_LINEAR;
- break;
- case MSM_VIDC_TRANSFER_XVYCC:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_XVYCC;
- break;
- case MSM_VIDC_TRANSFER_BT1361_0:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_BT1361;
- break;
- case MSM_VIDC_TRANSFER_SRGB_SYCC:
- v4l2_transfer_char = V4L2_XFER_FUNC_SRGB;
- break;
- case MSM_VIDC_TRANSFER_BT2020_14:
- case MSM_VIDC_TRANSFER_BT2020_15:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_BT2020;
- break;
- case MSM_VIDC_TRANSFER_SMPTE_ST2084_PQ:
- v4l2_transfer_char = V4L2_XFER_FUNC_SMPTE2084;
- break;
- case MSM_VIDC_TRANSFER_SMPTE_ST428_1:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_ST428;
- break;
- case MSM_VIDC_TRANSFER_BT2100_2_HLG:
- v4l2_transfer_char = V4L2_XFER_FUNC_VIDC_HLG;
- break;
- default:
- i_vpr_e(inst, "%s: invalid hfi transfer char %d\n",
- func, vidc_transfer_char);
- break;
- }
- return v4l2_transfer_char;
- }
- u32 v4l2_matrix_coeff_to_driver(struct msm_vidc_inst *inst,
- u32 v4l2_matrix_coeff, const char *func)
- {
- u32 vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_RESERVED;
- switch(v4l2_matrix_coeff) {
- case V4L2_YCBCR_ENC_DEFAULT:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_RESERVED;
- break;
- case V4L2_YCBCR_VIDC_SRGB_OR_SMPTE_ST428:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_SRGB_SMPTE_ST428_1;
- break;
- case V4L2_YCBCR_ENC_709:
- case V4L2_YCBCR_ENC_XV709:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_BT709;
- break;
- case V4L2_YCBCR_VIDC_FCC47_73_682:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_FCC_TITLE_47;
- break;
- case V4L2_YCBCR_ENC_XV601:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_BT470_SYS_BG_OR_BT601_625;
- break;
- case V4L2_YCBCR_ENC_601:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_BT601_525_BT1358_525_OR_625;
- break;
- case V4L2_YCBCR_ENC_SMPTE240M:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_SMPTE_ST240;
- break;
- case V4L2_YCBCR_ENC_BT2020:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_BT2020_NON_CONSTANT;
- break;
- case V4L2_YCBCR_ENC_BT2020_CONST_LUM:
- vidc_matrix_coeff = MSM_VIDC_MATRIX_COEFF_BT2020_CONSTANT;
- break;
- default:
- i_vpr_e(inst, "%s: invalid v4l2 matrix coeff %d\n",
- func, v4l2_matrix_coeff);
- break;
- }
- return vidc_matrix_coeff;
- }
- u32 v4l2_matrix_coeff_from_driver(struct msm_vidc_inst *inst,
- u32 vidc_matrix_coeff, const char *func)
- {
- u32 v4l2_matrix_coeff = V4L2_YCBCR_ENC_DEFAULT;
- switch(vidc_matrix_coeff) {
- case MSM_VIDC_MATRIX_COEFF_SRGB_SMPTE_ST428_1:
- v4l2_matrix_coeff = V4L2_YCBCR_VIDC_SRGB_OR_SMPTE_ST428;
- break;
- case MSM_VIDC_MATRIX_COEFF_BT709:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_709;
- break;
- case MSM_VIDC_MATRIX_COEFF_UNSPECIFIED:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_DEFAULT;
- break;
- case MSM_VIDC_MATRIX_COEFF_FCC_TITLE_47:
- v4l2_matrix_coeff = V4L2_YCBCR_VIDC_FCC47_73_682;
- break;
- case MSM_VIDC_MATRIX_COEFF_BT470_SYS_BG_OR_BT601_625:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_XV601;
- break;
- case MSM_VIDC_MATRIX_COEFF_BT601_525_BT1358_525_OR_625:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_601;
- break;
- case MSM_VIDC_MATRIX_COEFF_SMPTE_ST240:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_SMPTE240M;
- break;
- case MSM_VIDC_MATRIX_COEFF_BT2020_NON_CONSTANT:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_BT2020;
- break;
- case MSM_VIDC_MATRIX_COEFF_BT2020_CONSTANT:
- v4l2_matrix_coeff = V4L2_YCBCR_ENC_BT2020_CONST_LUM;
- break;
- default:
- i_vpr_e(inst, "%s: invalid hfi matrix coeff %d\n",
- func, vidc_matrix_coeff);
- break;
- }
- return v4l2_matrix_coeff;
- }
- int v4l2_type_to_driver_port(struct msm_vidc_inst *inst, u32 type,
- const char *func)
- {
- int port;
- if (type == INPUT_MPLANE) {
- port = INPUT_PORT;
- } else if (type == INPUT_META_PLANE) {
- port = INPUT_META_PORT;
- } else if (type == OUTPUT_MPLANE) {
- port = OUTPUT_PORT;
- } else if (type == OUTPUT_META_PLANE) {
- port = OUTPUT_META_PORT;
- } else {
- i_vpr_e(inst, "%s: port not found for v4l2 type %d\n",
- func, type);
- port = -EINVAL;
- }
- return port;
- }
- u32 msm_vidc_get_buffer_region(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type, const char *func)
- {
- u32 region = MSM_VIDC_NON_SECURE;
- if (!is_secure_session(inst)) {
- switch (buffer_type) {
- case MSM_VIDC_BUF_ARP:
- region = MSM_VIDC_SECURE_NONPIXEL;
- break;
- case MSM_VIDC_BUF_INPUT:
- if (is_encode_session(inst))
- region = MSM_VIDC_NON_SECURE_PIXEL;
- else
- region = MSM_VIDC_NON_SECURE;
- break;
- case MSM_VIDC_BUF_OUTPUT:
- if (is_encode_session(inst))
- region = MSM_VIDC_NON_SECURE;
- else
- region = MSM_VIDC_NON_SECURE_PIXEL;
- break;
- case MSM_VIDC_BUF_DPB:
- region = MSM_VIDC_NON_SECURE_PIXEL;
- break;
- case MSM_VIDC_BUF_INPUT_META:
- case MSM_VIDC_BUF_OUTPUT_META:
- case MSM_VIDC_BUF_BIN:
- case MSM_VIDC_BUF_COMV:
- case MSM_VIDC_BUF_NON_COMV:
- case MSM_VIDC_BUF_LINE:
- case MSM_VIDC_BUF_PERSIST:
- case MSM_VIDC_BUF_VPSS:
- region = MSM_VIDC_NON_SECURE;
- break;
- default:
- i_vpr_e(inst, "%s: invalid driver buffer type %d\n",
- func, buffer_type);
- }
- } else {
- switch (buffer_type) {
- case MSM_VIDC_BUF_INPUT:
- if (is_encode_session(inst))
- region = MSM_VIDC_SECURE_PIXEL;
- else
- region = MSM_VIDC_SECURE_BITSTREAM;
- break;
- case MSM_VIDC_BUF_OUTPUT:
- if (is_encode_session(inst))
- region = MSM_VIDC_SECURE_BITSTREAM;
- else
- region = MSM_VIDC_SECURE_PIXEL;
- break;
- case MSM_VIDC_BUF_INPUT_META:
- case MSM_VIDC_BUF_OUTPUT_META:
- region = MSM_VIDC_NON_SECURE;
- break;
- case MSM_VIDC_BUF_DPB:
- case MSM_VIDC_BUF_VPSS:
- region = MSM_VIDC_SECURE_PIXEL;
- break;
- case MSM_VIDC_BUF_BIN:
- region = MSM_VIDC_SECURE_BITSTREAM;
- break;
- case MSM_VIDC_BUF_ARP:
- case MSM_VIDC_BUF_COMV:
- case MSM_VIDC_BUF_NON_COMV:
- case MSM_VIDC_BUF_LINE:
- case MSM_VIDC_BUF_PERSIST:
- region = MSM_VIDC_SECURE_NONPIXEL;
- break;
- default:
- i_vpr_e(inst, "%s: invalid driver buffer type %d\n",
- func, buffer_type);
- }
- }
- return region;
- }
- struct msm_vidc_buffers *msm_vidc_get_buffers(
- struct msm_vidc_inst *inst, enum msm_vidc_buffer_type buffer_type,
- const char *func)
- {
- switch (buffer_type) {
- case MSM_VIDC_BUF_INPUT:
- return &inst->buffers.input;
- case MSM_VIDC_BUF_INPUT_META:
- return &inst->buffers.input_meta;
- case MSM_VIDC_BUF_OUTPUT:
- return &inst->buffers.output;
- case MSM_VIDC_BUF_OUTPUT_META:
- return &inst->buffers.output_meta;
- case MSM_VIDC_BUF_READ_ONLY:
- return &inst->buffers.read_only;
- case MSM_VIDC_BUF_BIN:
- return &inst->buffers.bin;
- case MSM_VIDC_BUF_ARP:
- return &inst->buffers.arp;
- case MSM_VIDC_BUF_COMV:
- return &inst->buffers.comv;
- case MSM_VIDC_BUF_NON_COMV:
- return &inst->buffers.non_comv;
- case MSM_VIDC_BUF_LINE:
- return &inst->buffers.line;
- case MSM_VIDC_BUF_DPB:
- return &inst->buffers.dpb;
- case MSM_VIDC_BUF_PERSIST:
- return &inst->buffers.persist;
- case MSM_VIDC_BUF_VPSS:
- return &inst->buffers.vpss;
- case MSM_VIDC_BUF_QUEUE:
- return NULL;
- default:
- i_vpr_e(inst, "%s: invalid driver buffer type %d\n",
- func, buffer_type);
- return NULL;
- }
- }
- struct msm_vidc_mappings *msm_vidc_get_mappings(
- struct msm_vidc_inst *inst, enum msm_vidc_buffer_type buffer_type,
- const char *func)
- {
- switch (buffer_type) {
- case MSM_VIDC_BUF_INPUT:
- return &inst->mappings.input;
- case MSM_VIDC_BUF_INPUT_META:
- return &inst->mappings.input_meta;
- case MSM_VIDC_BUF_OUTPUT:
- return &inst->mappings.output;
- case MSM_VIDC_BUF_OUTPUT_META:
- return &inst->mappings.output_meta;
- case MSM_VIDC_BUF_BIN:
- return &inst->mappings.bin;
- case MSM_VIDC_BUF_ARP:
- return &inst->mappings.arp;
- case MSM_VIDC_BUF_COMV:
- return &inst->mappings.comv;
- case MSM_VIDC_BUF_NON_COMV:
- return &inst->mappings.non_comv;
- case MSM_VIDC_BUF_LINE:
- return &inst->mappings.line;
- case MSM_VIDC_BUF_DPB:
- return &inst->mappings.dpb;
- case MSM_VIDC_BUF_PERSIST:
- return &inst->mappings.persist;
- case MSM_VIDC_BUF_VPSS:
- return &inst->mappings.vpss;
- default:
- i_vpr_e(inst, "%s: invalid driver buffer type %d\n",
- func, buffer_type);
- return NULL;
- }
- }
- struct msm_vidc_allocations *msm_vidc_get_allocations(
- struct msm_vidc_inst *inst, enum msm_vidc_buffer_type buffer_type,
- const char *func)
- {
- switch (buffer_type) {
- case MSM_VIDC_BUF_BIN:
- return &inst->allocations.bin;
- case MSM_VIDC_BUF_ARP:
- return &inst->allocations.arp;
- case MSM_VIDC_BUF_COMV:
- return &inst->allocations.comv;
- case MSM_VIDC_BUF_NON_COMV:
- return &inst->allocations.non_comv;
- case MSM_VIDC_BUF_LINE:
- return &inst->allocations.line;
- case MSM_VIDC_BUF_DPB:
- return &inst->allocations.dpb;
- case MSM_VIDC_BUF_PERSIST:
- return &inst->allocations.persist;
- case MSM_VIDC_BUF_VPSS:
- return &inst->allocations.vpss;
- default:
- i_vpr_e(inst, "%s: invalid driver buffer type %d\n",
- func, buffer_type);
- return NULL;
- }
- }
- int msm_vidc_change_core_state(struct msm_vidc_core *core,
- enum msm_vidc_core_state request_state, const char *func)
- {
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- d_vpr_h("%s: core state changed to %s from %s\n",
- func, core_state_name(request_state),
- core_state_name(core->state));
- core->state = request_state;
- return 0;
- }
- int msm_vidc_change_inst_state(struct msm_vidc_inst *inst,
- enum msm_vidc_inst_state request_state, const char *func)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!request_state) {
- i_vpr_e(inst, "%s: invalid request state\n", func);
- return -EINVAL;
- }
- if (inst->state == MSM_VIDC_ERROR) {
- i_vpr_h(inst,
- "%s: inst is in bad state, can not change state to %s\n",
- func, state_name(request_state));
- return 0;
- }
- if (request_state == MSM_VIDC_ERROR)
- i_vpr_e(inst, "%s: state changed to %s from %s\n",
- func, state_name(request_state), state_name(inst->state));
- else
- i_vpr_h(inst, "%s: state changed to %s from %s\n",
- func, state_name(request_state), state_name(inst->state));
- inst->state = request_state;
- return 0;
- }
- bool msm_vidc_allow_s_fmt(struct msm_vidc_inst *inst, u32 type)
- {
- bool allow = false;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (inst->state == MSM_VIDC_OPEN) {
- allow = true;
- goto exit;
- }
- if (type == OUTPUT_MPLANE || type == OUTPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_INPUT ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- allow = true;
- goto exit;
- }
- }
- if (type == INPUT_MPLANE || type == INPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_OUTPUT) {
- allow = true;
- goto exit;
- }
- }
- exit:
- if (!allow)
- i_vpr_e(inst, "%s: type %d not allowed in state %s\n",
- __func__, type, state_name(inst->state));
- return allow;
- }
- bool msm_vidc_allow_s_ctrl(struct msm_vidc_inst *inst, u32 id)
- {
- bool allow = false;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (inst->state == MSM_VIDC_OPEN) {
- allow = true;
- goto exit;
- }
- if (is_decode_session(inst)) {
- if (!inst->vb2q[INPUT_PORT].streaming) {
- allow = true;
- goto exit;
- }
- if (inst->vb2q[INPUT_PORT].streaming) {
- switch (id) {
- case V4L2_CID_MPEG_VIDC_CODEC_CONFIG:
- case V4L2_CID_MPEG_VIDC_PRIORITY:
- allow = true;
- break;
- default:
- allow = false;
- break;
- }
- }
- } else if (is_encode_session(inst)) {
- if (inst->state == MSM_VIDC_START || inst->state == MSM_VIDC_START_OUTPUT) {
- switch (id) {
- case V4L2_CID_MPEG_VIDEO_BITRATE:
- case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
- case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME:
- case V4L2_CID_HFLIP:
- case V4L2_CID_VFLIP:
- case V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER:
- case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR:
- case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR:
- case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR:
- case V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES:
- case V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX:
- case V4L2_CID_MPEG_VIDC_VIDEO_BLUR_TYPES:
- case V4L2_CID_MPEG_VIDC_VIDEO_BLUR_RESOLUTION:
- case V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY:
- case V4L2_CID_MPEG_VIDC_ENC_INPUT_COMPRESSION_RATIO:
- case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
- case V4L2_CID_MPEG_VIDC_PRIORITY:
- allow = true;
- break;
- default:
- allow = false;
- break;
- }
- }
- }
- exit:
- if (!allow)
- i_vpr_e(inst, "%s: id %d not allowed in state %s\n",
- __func__, id, state_name(inst->state));
- return allow;
- }
- bool msm_vidc_allow_metadata(struct msm_vidc_inst *inst, u32 cap_id)
- {
- bool is_allowed = true;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- switch (cap_id) {
- case META_OUTPUT_BUF_TAG:
- case META_DPB_TAG_LIST:
- if (!is_ubwc_colorformat(inst->capabilities->cap[PIX_FMTS].value)) {
- i_vpr_h(inst,
- "%s: cap: %24s not allowed for split mode\n",
- __func__, cap_name(cap_id));
- is_allowed = false;
- }
- break;
- default:
- is_allowed = true;
- break;
- }
- return is_allowed;
- }
- bool msm_vidc_allow_property(struct msm_vidc_inst *inst, u32 hfi_id)
- {
- bool is_allowed = true;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- switch (hfi_id) {
- case HFI_PROP_WORST_COMPRESSION_RATIO:
- case HFI_PROP_WORST_COMPLEXITY_FACTOR:
- case HFI_PROP_PICTURE_TYPE:
- is_allowed = true;
- break;
- case HFI_PROP_DPB_LIST:
- if (!is_ubwc_colorformat(inst->capabilities->cap[PIX_FMTS].value)) {
- i_vpr_h(inst,
- "%s: cap: %24s not allowed for split mode\n",
- __func__, cap_name(DPB_LIST));
- is_allowed = false;
- }
- break;
- default:
- is_allowed = true;
- break;
- }
- return is_allowed;
- }
- int msm_vidc_update_property_cap(struct msm_vidc_inst *inst, u32 hfi_id,
- bool allow)
- {
- int rc = 0;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- switch (hfi_id) {
- case HFI_PROP_WORST_COMPRESSION_RATIO:
- case HFI_PROP_WORST_COMPLEXITY_FACTOR:
- case HFI_PROP_PICTURE_TYPE:
- break;
- case HFI_PROP_DPB_LIST:
- if (!allow)
- memset(inst->dpb_list_payload, 0, MAX_DPB_LIST_ARRAY_SIZE);
- msm_vidc_update_cap_value(inst, DPB_LIST, allow, __func__);
- break;
- default:
- break;
- }
- return rc;
- }
- bool msm_vidc_allow_reqbufs(struct msm_vidc_inst *inst, u32 type)
- {
- bool allow = false;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (inst->state == MSM_VIDC_OPEN) {
- allow = true;
- goto exit;
- }
- if (type == OUTPUT_MPLANE || type == OUTPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_INPUT ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- allow = true;
- goto exit;
- }
- }
- if (type == INPUT_MPLANE || type == INPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_OUTPUT) {
- allow = true;
- goto exit;
- }
- }
- exit:
- if (!allow)
- i_vpr_e(inst, "%s: type %d not allowed in state %s\n",
- __func__, type, state_name(inst->state));
- return allow;
- }
- enum msm_vidc_allow msm_vidc_allow_stop(struct msm_vidc_inst *inst)
- {
- enum msm_vidc_allow allow = MSM_VIDC_DISALLOW;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return allow;
- }
- if (inst->state == MSM_VIDC_START ||
- inst->state == MSM_VIDC_DRC ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_DRAIN) {
- allow = MSM_VIDC_ALLOW;
- } else if (inst->state == MSM_VIDC_START_INPUT) {
- allow = MSM_VIDC_IGNORE;
- i_vpr_e(inst, "%s: stop ignored in state %s\n",
- __func__, state_name(inst->state));
- } else {
- i_vpr_e(inst, "%s: stop not allowed in state %s\n",
- __func__, state_name(inst->state));
- }
- return allow;
- }
- bool msm_vidc_allow_start(struct msm_vidc_inst *inst)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (inst->state == MSM_VIDC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG)
- return true;
- i_vpr_e(inst, "%s: not allowed in state %s\n",
- __func__, state_name(inst->state));
- return false;
- }
- bool msm_vidc_allow_streamon(struct msm_vidc_inst *inst, u32 type)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (type == INPUT_MPLANE || type == INPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_OUTPUT)
- return true;
- } else if (type == OUTPUT_MPLANE || type == OUTPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_INPUT ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT)
- return true;
- }
- i_vpr_e(inst, "%s: type %d not allowed in state %s\n",
- __func__, type, state_name(inst->state));
- return false;
- }
- bool msm_vidc_allow_streamoff(struct msm_vidc_inst *inst, u32 type)
- {
- bool allow = true;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (type == INPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_OUTPUT)
- allow = false;
- } else if (type == INPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_INPUT)
- allow = false;
- } else if (type == OUTPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_INPUT)
- allow = false;
- } else if (type == OUTPUT_META_PLANE) {
- if (inst->state == MSM_VIDC_START_OUTPUT)
- allow = false;
- }
- if (!allow)
- i_vpr_e(inst, "%s: type %d not allowed in state %s\n",
- __func__, type, state_name(inst->state));
- return allow;
- }
- enum msm_vidc_allow msm_vidc_allow_qbuf(struct msm_vidc_inst *inst, u32 type)
- {
- int port = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return MSM_VIDC_DISALLOW;
- }
- if (inst->state == MSM_VIDC_ERROR) {
- i_vpr_e(inst, "%s: inst in error state\n", __func__);
- return MSM_VIDC_DISALLOW;
- }
- port = v4l2_type_to_driver_port(inst, type, __func__);
- if (port < 0)
- return MSM_VIDC_DISALLOW;
- /* defer queuing if streamon not completed */
- if (!inst->vb2q[port].streaming)
- return MSM_VIDC_DEFER;
- if (type == INPUT_META_PLANE || type == OUTPUT_META_PLANE)
- return MSM_VIDC_DEFER;
- if (type == INPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_OUTPUT)
- return MSM_VIDC_DEFER;
- else
- return MSM_VIDC_ALLOW;
- } else if (type == OUTPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN ||
- inst->state == MSM_VIDC_START_INPUT ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT)
- return MSM_VIDC_DEFER;
- else
- return MSM_VIDC_ALLOW;
- } else {
- i_vpr_e(inst, "%s: unknown buffer type %d\n", __func__, type);
- return MSM_VIDC_DISALLOW;
- }
- return MSM_VIDC_DISALLOW;
- }
- enum msm_vidc_allow msm_vidc_allow_input_psc(struct msm_vidc_inst *inst)
- {
- enum msm_vidc_allow allow = MSM_VIDC_DISALLOW;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return MSM_VIDC_DISALLOW;
- }
- if (inst->state == MSM_VIDC_START ||
- inst->state == MSM_VIDC_START_INPUT ||
- inst->state == MSM_VIDC_DRAIN) {
- allow = MSM_VIDC_ALLOW;
- } else if (inst->state == MSM_VIDC_DRC ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_DRAIN ||
- inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- i_vpr_h(inst, "%s: defer input psc, inst state %s\n",
- __func__, state_name(inst->state));
- allow = MSM_VIDC_DEFER;
- } else {
- i_vpr_e(inst, "%s: input psc in wrong state %s\n",
- __func__, state_name(inst->state));
- allow = MSM_VIDC_DISALLOW;
- }
- return allow;
- }
- bool msm_vidc_allow_last_flag(struct msm_vidc_inst *inst)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- if (inst->state == MSM_VIDC_DRC ||
- inst->state == MSM_VIDC_DRAIN ||
- inst->state == MSM_VIDC_DRC_DRAIN)
- return true;
- i_vpr_e(inst, "%s: not allowed in state %s\n",
- __func__, state_name(inst->state));
- return false;
- }
- static int msm_vidc_process_pending_ipsc(struct msm_vidc_inst *inst,
- enum msm_vidc_inst_state *new_state)
- {
- struct response_work *resp_work, *dummy = NULL;
- int rc = 0;
- if (!inst || !new_state) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (list_empty(&inst->response_works))
- return 0;
- i_vpr_h(inst, "%s: state %s, ipsc pending\n", __func__, state_name(inst->state));
- list_for_each_entry_safe(resp_work, dummy, &inst->response_works, list) {
- if (resp_work->type == RESP_WORK_INPUT_PSC) {
- rc = handle_session_response_work(inst, resp_work);
- if (rc) {
- i_vpr_e(inst, "%s: handle ipsc failed\n", __func__);
- *new_state = MSM_VIDC_ERROR;
- } else {
- if (inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- *new_state = MSM_VIDC_DRC_DRAIN;
- } else if (inst->state == MSM_VIDC_DRC_LAST_FLAG) {
- *new_state = MSM_VIDC_DRC;
- }
- }
- list_del(&resp_work->list);
- kfree(resp_work->data);
- kfree(resp_work);
- /* list contains max only one ipsc at anytime */
- break;
- }
- }
- return rc;
- }
- int msm_vidc_state_change_streamon(struct msm_vidc_inst *inst, u32 type)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (type == INPUT_META_PLANE || type == OUTPUT_META_PLANE)
- return 0;
- if (type == INPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN)
- new_state = MSM_VIDC_START_INPUT;
- else if (inst->state == MSM_VIDC_START_OUTPUT)
- new_state = MSM_VIDC_START;
- } else if (type == OUTPUT_MPLANE) {
- if (inst->state == MSM_VIDC_OPEN) {
- new_state = MSM_VIDC_START_OUTPUT;
- } else if (inst->state == MSM_VIDC_START_INPUT) {
- new_state = MSM_VIDC_START;
- } else if (inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- i_vpr_h(inst, "%s: streamon(output) in %s state\n",
- __func__, state_name(inst->state));
- new_state = MSM_VIDC_DRAIN;
- rc = msm_vidc_process_pending_ipsc(inst, &new_state);
- if (rc) {
- i_vpr_e(inst, "%s: process pending ipsc failed\n", __func__);
- goto state_change;
- }
- }
- }
- state_change:
- msm_vidc_change_inst_state(inst, new_state, __func__);
- return rc;
- }
- int msm_vidc_state_change_streamoff(struct msm_vidc_inst *inst, u32 type)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- struct response_work *resp_work, *dummy;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (type == INPUT_META_PLANE || type == OUTPUT_META_PLANE)
- return 0;
- if (type == INPUT_MPLANE) {
- if (inst->state == MSM_VIDC_START_INPUT) {
- new_state = MSM_VIDC_OPEN;
- } else if (inst->state == MSM_VIDC_START) {
- new_state = MSM_VIDC_START_OUTPUT;
- } else if (inst->state == MSM_VIDC_DRC ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG ||
- inst->state == MSM_VIDC_DRAIN ||
- inst->state == MSM_VIDC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_DRAIN ||
- inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRAIN_START_INPUT) {
- new_state = MSM_VIDC_START_OUTPUT;
- /* discard pending port settings change if any */
- list_for_each_entry_safe(resp_work, dummy,
- &inst->response_works, list) {
- if (resp_work->type == RESP_WORK_INPUT_PSC) {
- i_vpr_h(inst,
- "%s: discard pending input psc\n", __func__);
- list_del(&resp_work->list);
- kfree(resp_work->data);
- kfree(resp_work);
- }
- }
- }
- } else if (type == OUTPUT_MPLANE) {
- if (inst->state == MSM_VIDC_START_OUTPUT) {
- new_state = MSM_VIDC_OPEN;
- } else if (inst->state == MSM_VIDC_START ||
- inst->state == MSM_VIDC_DRAIN ||
- inst->state == MSM_VIDC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_DRAIN) {
- new_state = MSM_VIDC_START_INPUT;
- } else if (inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG) {
- new_state = MSM_VIDC_DRAIN_START_INPUT;
- }
- }
- rc = msm_vidc_change_inst_state(inst, new_state, __func__);
- if (rc)
- goto exit;
- exit:
- return rc;
- }
- int msm_vidc_state_change_stop(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (inst->state == MSM_VIDC_START) {
- new_state = MSM_VIDC_DRAIN;
- } else if (inst->state == MSM_VIDC_DRC) {
- new_state = MSM_VIDC_DRC_DRAIN;
- } else if (inst->state == MSM_VIDC_DRC_DRAIN ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG) {
- new_state = MSM_VIDC_DRC_DRAIN_LAST_FLAG;
- } else {
- i_vpr_e(inst, "%s: wrong state %s\n",
- __func__, state_name(inst->state));
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- return -EINVAL;
- }
- rc = msm_vidc_change_inst_state(inst, new_state, __func__);
- if (rc)
- return rc;
- return rc;
- }
- int msm_vidc_state_change_start(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (inst->state == MSM_VIDC_DRAIN_LAST_FLAG ||
- inst->state == MSM_VIDC_DRC_LAST_FLAG) {
- new_state = MSM_VIDC_START;
- rc = msm_vidc_process_pending_ipsc(inst, &new_state);
- if (rc) {
- i_vpr_e(inst, "%s: process pending ipsc failed\n", __func__);
- goto state_change;
- }
- } else if (inst->state == MSM_VIDC_DRC_DRAIN_LAST_FLAG) {
- new_state = MSM_VIDC_DRAIN;
- rc = msm_vidc_process_pending_ipsc(inst, &new_state);
- if (rc) {
- i_vpr_e(inst, "%s: process pending ipsc failed\n", __func__);
- goto state_change;
- }
- } else {
- i_vpr_e(inst, "%s: wrong state %s\n", __func__, state_name(inst->state));
- new_state = MSM_VIDC_ERROR;
- rc = -EINVAL;
- goto state_change;
- }
- state_change:
- msm_vidc_change_inst_state(inst, new_state, __func__);
- return rc;
- }
- int msm_vidc_state_change_input_psc(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- /* don't change state as output port is not started yet */
- if (inst->state == MSM_VIDC_START_INPUT)
- return 0;
- if (inst->state == MSM_VIDC_START) {
- new_state = MSM_VIDC_DRC;
- } else if (inst->state == MSM_VIDC_DRAIN) {
- new_state = MSM_VIDC_DRC_DRAIN;
- } else {
- i_vpr_e(inst, "%s: wrong state %s\n",
- __func__, state_name(inst->state));
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- return -EINVAL;
- }
- rc = msm_vidc_change_inst_state(inst, new_state, __func__);
- if (rc)
- return rc;
- return rc;
- }
- int msm_vidc_state_change_last_flag(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- enum msm_vidc_inst_state new_state = MSM_VIDC_ERROR;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (inst->state == MSM_VIDC_DRC) {
- new_state = MSM_VIDC_DRC_LAST_FLAG;
- } else if (inst->state == MSM_VIDC_DRAIN) {
- new_state = MSM_VIDC_DRAIN_LAST_FLAG;
- } else if (inst->state == MSM_VIDC_DRC_DRAIN) {
- new_state = MSM_VIDC_DRC_DRAIN_LAST_FLAG;
- } else {
- i_vpr_e(inst, "%s: wrong state %s\n",
- __func__, state_name(inst->state));
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- return -EINVAL;
- }
- rc = msm_vidc_change_inst_state(inst, new_state, __func__);
- if (rc)
- return rc;
- return rc;
- }
- int msm_vidc_get_control(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
- {
- int rc = 0;
- if (!inst || !ctrl) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- switch (ctrl->id) {
- case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
- ctrl->val = inst->buffers.output.min_count +
- inst->buffers.output.extra_count;
- i_vpr_h(inst, "g_min: output buffers %d\n", ctrl->val);
- break;
- case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
- ctrl->val = inst->buffers.input.min_count +
- inst->buffers.input.extra_count;
- i_vpr_h(inst, "g_min: input buffers %d\n", ctrl->val);
- break;
- default:
- break;
- }
- return rc;
- }
- int msm_vidc_get_mbs_per_frame(struct msm_vidc_inst *inst)
- {
- int height, width;
- struct v4l2_format *out_f;
- struct v4l2_format *inp_f;
- out_f = &inst->fmts[OUTPUT_PORT];
- inp_f = &inst->fmts[INPUT_PORT];
- height = max(out_f->fmt.pix_mp.height,
- inp_f->fmt.pix_mp.height);
- width = max(out_f->fmt.pix_mp.width,
- inp_f->fmt.pix_mp.width);
- return NUM_MBS_PER_FRAME(height, width);
- }
- int msm_vidc_get_fps(struct msm_vidc_inst *inst)
- {
- int fps;
- u32 frame_rate, operating_rate;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- frame_rate = inst->capabilities->cap[FRAME_RATE].value;
- operating_rate = inst->capabilities->cap[OPERATING_RATE].value;
- if (operating_rate > frame_rate)
- fps = (operating_rate >> 16) ?
- (operating_rate >> 16) : 1;
- else
- fps = frame_rate >> 16;
- return fps;
- }
- int msm_vidc_num_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type type, enum msm_vidc_buffer_attributes attr)
- {
- int count = 0;
- struct msm_vidc_buffer *vbuf;
- struct msm_vidc_buffers *buffers;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return count;
- }
- if (type == MSM_VIDC_BUF_OUTPUT) {
- buffers = &inst->buffers.output;
- } else if (type == MSM_VIDC_BUF_INPUT) {
- buffers = &inst->buffers.input;
- } else {
- i_vpr_e(inst, "%s: invalid buffer type %#x\n",
- __func__, type);
- return count;
- }
- list_for_each_entry(vbuf, &buffers->list, list) {
- if (vbuf->type != type)
- continue;
- if (!(vbuf->attr & attr))
- continue;
- count++;
- }
- return count;
- }
- static int vb2_buffer_to_driver(struct vb2_buffer *vb2,
- struct msm_vidc_buffer *buf)
- {
- int rc = 0;
- if (!vb2 || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- buf->type = v4l2_type_to_driver(vb2->type, __func__);
- if (!buf->type)
- return -EINVAL;
- buf->index = vb2->index;
- buf->fd = vb2->planes[0].m.fd;
- buf->data_offset = vb2->planes[0].data_offset;
- buf->data_size = vb2->planes[0].bytesused;
- buf->buffer_size = vb2->planes[0].length;
- buf->timestamp = vb2->timestamp;
- return rc;
- }
- int msm_vidc_process_readonly_buffers(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- int rc = 0;
- struct msm_vidc_buffer *ro_buf, *dummy;
- struct msm_vidc_buffers *ro_buffers;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_decode_session(inst) || !is_output_buffer(buf->type))
- return 0;
- ro_buffers = msm_vidc_get_buffers(inst, MSM_VIDC_BUF_READ_ONLY, __func__);
- if (!ro_buffers)
- return -EINVAL;
- /*
- * check if buffer present in ro_buffers list
- * if present: add ro flag to buf and remove from ro_buffers list
- * if not present: do nothing
- */
- list_for_each_entry_safe(ro_buf, dummy, &ro_buffers->list, list) {
- if (ro_buf->device_addr == buf->device_addr) {
- buf->attr |= MSM_VIDC_ATTR_READ_ONLY;
- print_vidc_buffer(VIDC_LOW, "low ", "ro buf removed", inst, ro_buf);
- list_del(&ro_buf->list);
- msm_vidc_put_vidc_buffer(inst, ro_buf);
- break;
- }
- }
- return rc;
- }
- int msm_vidc_memory_unmap_completely(struct msm_vidc_inst *inst,
- struct msm_vidc_map *map)
- {
- int rc = 0;
- if (!inst || !map) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!map->refcount)
- return 0;
- while (map->refcount) {
- rc = msm_vidc_memory_unmap(inst->core, map);
- if (rc)
- break;
- if (!map->refcount) {
- msm_vidc_memory_put_dmabuf(map->dmabuf);
- list_del(&map->list);
- msm_vidc_put_map_buffer(inst, map);
- break;
- }
- }
- return rc;
- }
- struct msm_vidc_buffer *msm_vidc_get_vidc_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffer *buf = NULL;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return NULL;
- }
- if (!list_empty(&inst->pool.buffers.list)) {
- buf = list_first_entry(&inst->pool.buffers.list, struct msm_vidc_buffer, list);
- inst->pool.buffers.count--;
- list_del(&buf->list);
- memset(buf, 0, sizeof(struct msm_vidc_buffer));
- return buf;
- }
- buf = kzalloc(sizeof(struct msm_vidc_buffer), GFP_KERNEL);
- if (!buf) {
- i_vpr_e(inst, "%s: buf failed\n", __func__);
- return NULL;
- }
- return buf;
- }
- int msm_vidc_put_vidc_buffer(struct msm_vidc_inst *inst, struct msm_vidc_buffer *buf)
- {
- if (!inst || !buf) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- inst->pool.buffers.count++;
- list_add_tail(&buf->list, &inst->pool.buffers.list);
- return 0;
- }
- int msm_vidc_destroy_vidc_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffer *buf, *dummy;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- i_vpr_h(inst, "%s: pool: buffer count %u\n", __func__, inst->pool.buffers.count);
- /* free all buffers from pool */
- list_for_each_entry_safe(buf, dummy, &inst->pool.buffers.list, list) {
- list_del(&buf->list);
- kfree(buf);
- }
- return 0;
- }
- struct msm_vidc_alloc *msm_vidc_get_alloc_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_alloc *alloc = NULL;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return NULL;
- }
- if (!list_empty(&inst->pool.allocations.list)) {
- alloc = list_first_entry(&inst->pool.allocations.list, struct msm_vidc_alloc, list);
- inst->pool.allocations.count--;
- list_del(&alloc->list);
- memset(alloc, 0, sizeof(struct msm_vidc_alloc));
- return alloc;
- }
- alloc = kzalloc(sizeof(struct msm_vidc_alloc), GFP_KERNEL);
- if (!alloc) {
- i_vpr_e(inst, "%s: alloc failed\n", __func__);
- return NULL;
- }
- return alloc;
- }
- int msm_vidc_put_alloc_buffer(struct msm_vidc_inst *inst, struct msm_vidc_alloc *alloc)
- {
- if (!inst || !alloc) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- list_add_tail(&alloc->list, &inst->pool.allocations.list);
- inst->pool.allocations.count++;
- return 0;
- }
- int msm_vidc_destroy_alloc_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_alloc *alloc, *dummy;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- i_vpr_h(inst, "%s: pool: allocations count %u\n", __func__, inst->pool.allocations.count);
- /* free all allocations from pool */
- list_for_each_entry_safe(alloc, dummy, &inst->pool.allocations.list, list) {
- list_del(&alloc->list);
- kfree(alloc);
- }
- return 0;
- }
- struct msm_vidc_map *msm_vidc_get_map_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_map *map = NULL;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return NULL;
- }
- if (!list_empty(&inst->pool.mappings.list)) {
- map = list_first_entry(&inst->pool.mappings.list, struct msm_vidc_map, list);
- inst->pool.mappings.count--;
- list_del(&map->list);
- memset(map, 0, sizeof(struct msm_vidc_map));
- return map;
- }
- map = kzalloc(sizeof(struct msm_vidc_map), GFP_KERNEL);
- if (!map) {
- i_vpr_e(inst, "%s: map failed\n", __func__);
- return NULL;
- }
- return map;
- }
- int msm_vidc_put_map_buffer(struct msm_vidc_inst *inst, struct msm_vidc_map *map)
- {
- if (!inst || !map) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- list_add_tail(&map->list, &inst->pool.mappings.list);
- inst->pool.mappings.count++;
- return 0;
- }
- int msm_vidc_get_delayed_unmap(struct msm_vidc_inst *inst, struct msm_vidc_map *map)
- {
- int rc = 0;
- if (!inst || !map) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- map->skip_delayed_unmap = 1;
- rc = msm_vidc_memory_map(inst->core, map);
- if (rc)
- return rc;
- return 0;
- }
- int msm_vidc_put_delayed_unmap(struct msm_vidc_inst *inst, struct msm_vidc_map *map)
- {
- int rc = 0;
- if (!inst || !map) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!map->skip_delayed_unmap) {
- i_vpr_e(inst, "%s: no delayed unmap, addr %#x\n",
- __func__, map->device_addr);
- return -EINVAL;
- }
- map->skip_delayed_unmap = 0;
- rc = msm_vidc_memory_unmap(inst->core, map);
- if (rc)
- i_vpr_e(inst, "%s: unmap failed\n", __func__);
- if (!map->refcount) {
- msm_vidc_memory_put_dmabuf(map->dmabuf);
- list_del(&map->list);
- msm_vidc_put_map_buffer(inst, map);
- }
- return rc;
- }
- int msm_vidc_destroy_map_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_map *map, *dummy;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- i_vpr_h(inst, "%s: pool: mappings count %u\n", __func__, inst->pool.mappings.count);
- /* free all mappings from pool */
- list_for_each_entry_safe(map, dummy, &inst->pool.mappings.list, list) {
- list_del(&map->list);
- kfree(map);
- }
- return 0;
- }
- int msm_vidc_unmap_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type type)
- {
- int rc = 0;
- struct msm_vidc_mappings *mappings;
- struct msm_vidc_map *map, *dummy;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- mappings = msm_vidc_get_mappings(inst, type, __func__);
- if (!mappings)
- return -EINVAL;
- list_for_each_entry_safe(map, dummy, &mappings->list, list) {
- msm_vidc_memory_unmap_completely(inst, map);
- }
- return rc;
- }
- int msm_vidc_unmap_driver_buf(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- int rc = 0;
- struct msm_vidc_mappings *mappings;
- struct msm_vidc_map *map = NULL;
- bool found = false;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- mappings = msm_vidc_get_mappings(inst, buf->type, __func__);
- if (!mappings)
- return -EINVAL;
- /* sanity check to see if it was not removed */
- list_for_each_entry(map, &mappings->list, list) {
- if (map->dmabuf == buf->dmabuf) {
- found = true;
- break;
- }
- }
- if (!found) {
- print_vidc_buffer(VIDC_ERR, "err ", "no buf in mappings", inst, buf);
- return -EINVAL;
- }
- rc = msm_vidc_memory_unmap(inst->core, map);
- if (rc) {
- print_vidc_buffer(VIDC_ERR, "err ", "unmap failed", inst, buf);
- return -EINVAL;
- }
- /* finally delete if refcount is zero */
- if (!map->refcount) {
- msm_vidc_memory_put_dmabuf(map->dmabuf);
- list_del(&map->list);
- msm_vidc_put_map_buffer(inst, map);
- }
- return rc;
- }
- int msm_vidc_map_driver_buf(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- int rc = 0;
- struct msm_vidc_mappings *mappings;
- struct msm_vidc_map *map;
- bool found = false;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- mappings = msm_vidc_get_mappings(inst, buf->type, __func__);
- if (!mappings)
- return -EINVAL;
- /*
- * new buffer: map twice for delayed unmap feature sake
- * existing buffer: map once
- */
- list_for_each_entry(map, &mappings->list, list) {
- if (map->dmabuf == buf->dmabuf) {
- found = true;
- break;
- }
- }
- if (!found) {
- /* new buffer case */
- map = msm_vidc_get_map_buffer(inst);
- if (!map) {
- i_vpr_e(inst, "%s: alloc failed\n", __func__);
- return -ENOMEM;
- }
- INIT_LIST_HEAD(&map->list);
- map->type = buf->type;
- map->dmabuf = msm_vidc_memory_get_dmabuf(buf->fd);
- if (!map->dmabuf)
- return -EINVAL;
- map->region = msm_vidc_get_buffer_region(inst, buf->type, __func__);
- /* delayed unmap feature needed for decoder output buffers */
- if (is_decode_session(inst) && is_output_buffer(buf->type)) {
- rc = msm_vidc_get_delayed_unmap(inst, map);
- if (rc) {
- msm_vidc_memory_put_dmabuf(map->dmabuf);
- msm_vidc_put_map_buffer(inst, map);
- return rc;
- }
- }
- list_add_tail(&map->list, &mappings->list);
- }
- rc = msm_vidc_memory_map(inst->core, map);
- if (rc)
- return rc;
- buf->device_addr = map->device_addr;
- return 0;
- }
- int msm_vidc_put_driver_buf(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- int rc = 0;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- msm_vidc_unmap_driver_buf(inst, buf);
- msm_vidc_memory_put_dmabuf(buf->dmabuf);
- /* delete the buffer from buffers->list */
- list_del(&buf->list);
- msm_vidc_put_vidc_buffer(inst, buf);
- return rc;
- }
- struct msm_vidc_buffer *msm_vidc_get_driver_buf(struct msm_vidc_inst *inst,
- struct vb2_buffer *vb2)
- {
- int rc = 0;
- struct msm_vidc_buffer *buf = NULL;
- struct msm_vidc_buffers *buffers;
- enum msm_vidc_buffer_type buf_type;
- if (!inst || !vb2) {
- d_vpr_e("%s: invalid params\n", __func__);
- return NULL;
- }
- buf_type = v4l2_type_to_driver(vb2->type, __func__);
- if (!buf_type)
- return NULL;
- buffers = msm_vidc_get_buffers(inst, buf_type, __func__);
- if (!buffers)
- return NULL;
- buf = msm_vidc_get_vidc_buffer(inst);
- if (!buf) {
- i_vpr_e(inst, "%s: alloc failed\n", __func__);
- return NULL;
- }
- INIT_LIST_HEAD(&buf->list);
- list_add_tail(&buf->list, &buffers->list);
- rc = vb2_buffer_to_driver(vb2, buf);
- if (rc)
- goto error;
- buf->dmabuf = msm_vidc_memory_get_dmabuf(buf->fd);
- if (!buf->dmabuf)
- goto error;
- /* treat every buffer as deferred buffer initially */
- buf->attr |= MSM_VIDC_ATTR_DEFERRED;
- rc = msm_vidc_map_driver_buf(inst, buf);
- if (rc)
- goto error;
- return buf;
- error:
- msm_vidc_memory_put_dmabuf(buf->dmabuf);
- list_del(&buf->list);
- msm_vidc_put_vidc_buffer(inst, buf);
- return NULL;
- }
- struct msm_vidc_buffer *get_meta_buffer(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- struct msm_vidc_buffer *mbuf;
- struct msm_vidc_buffers *buffers;
- bool found = false;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return NULL;
- }
- if (buf->type == MSM_VIDC_BUF_INPUT) {
- buffers = &inst->buffers.input_meta;
- } else if (buf->type == MSM_VIDC_BUF_OUTPUT) {
- buffers = &inst->buffers.output_meta;
- } else {
- i_vpr_e(inst, "%s: invalid buffer type %d\n",
- __func__, buf->type);
- return NULL;
- }
- list_for_each_entry(mbuf, &buffers->list, list) {
- if (mbuf->index == buf->index) {
- found = true;
- break;
- }
- }
- if (!found)
- return NULL;
- return mbuf;
- }
- bool msm_vidc_is_super_buffer(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_inst_capability *capability = NULL;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return false;
- }
- capability = inst->capabilities;
- return !!capability->cap[SUPER_FRAME].value;
- }
- static bool is_single_session(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_core *core;
- u32 count = 0;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return false;
- }
- core = inst->core;
- core_lock(core, __func__);
- list_for_each_entry(inst, &core->instances, list)
- count++;
- core_unlock(core, __func__);
- return count == 1;
- }
- void msm_vidc_allow_dcvs(struct msm_vidc_inst *inst)
- {
- bool allow = false;
- struct msm_vidc_core *core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: Invalid args: %pK\n", __func__, inst);
- return;
- }
- core = inst->core;
- allow = !msm_vidc_clock_voting;
- if (!allow) {
- i_vpr_h(inst, "%s: core_clock_voting is set\n", __func__);
- goto exit;
- }
- allow = core->capabilities[DCVS].value;
- if (!allow) {
- i_vpr_h(inst, "%s: core doesn't support dcvs\n", __func__);
- goto exit;
- }
- allow = !inst->decode_batch.enable;
- if (!allow) {
- i_vpr_h(inst, "%s: decode_batching enabled\n", __func__);
- goto exit;
- }
- allow = !msm_vidc_is_super_buffer(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: encode_batching(super_buffer) enabled\n", __func__);
- goto exit;
- }
- allow = !is_thumbnail_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: thumbnail session\n", __func__);
- goto exit;
- }
- allow = is_realtime_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: non-realtime session\n", __func__);
- goto exit;
- }
- allow = !is_image_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: image session\n", __func__);
- goto exit;
- }
- exit:
- i_vpr_h(inst, "%s: dcvs: %s\n", __func__, allow ? "enabled" : "disabled");
- inst->power.dcvs_flags = 0;
- inst->power.dcvs_mode = allow;
- }
- bool msm_vidc_allow_decode_batch(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_core *core;
- bool allow = false;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return false;
- }
- core = inst->core;
- allow = inst->decode_batch.enable;
- if (!allow) {
- i_vpr_h(inst, "%s: batching already disabled\n", __func__);
- goto exit;
- }
- allow = core->capabilities[DECODE_BATCH].value;
- if (!allow) {
- i_vpr_h(inst, "%s: core doesn't support batching\n", __func__);
- goto exit;
- }
- allow = is_single_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: multiple sessions running\n", __func__);
- goto exit;
- }
- allow = is_decode_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: not a decoder session\n", __func__);
- goto exit;
- }
- allow = !is_thumbnail_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: thumbnail session\n", __func__);
- goto exit;
- }
- allow = !is_image_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: image session\n", __func__);
- goto exit;
- }
- allow = is_realtime_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: non-realtime session\n", __func__);
- goto exit;
- }
- allow = !is_lowlatency_session(inst);
- if (!allow) {
- i_vpr_h(inst, "%s: lowlatency session\n", __func__);
- goto exit;
- }
- exit:
- i_vpr_h(inst, "%s: batching: %s\n", __func__, allow ? "enabled" : "disabled");
- return allow;
- }
- static void msm_vidc_update_input_cr(struct msm_vidc_inst *inst, u32 idx, u32 cr)
- {
- struct msm_vidc_input_cr_data *temp, *next;
- bool found = false;
- list_for_each_entry_safe(temp, next, &inst->enc_input_crs, list) {
- if (temp->index == idx) {
- temp->input_cr = cr;
- found = true;
- break;
- }
- }
- if (!found) {
- temp = kzalloc(sizeof(*temp), GFP_KERNEL);
- if (!temp) {
- i_vpr_e(inst, "%s: malloc failure.\n", __func__);
- return;
- }
- temp->index = idx;
- temp->input_cr = cr;
- list_add_tail(&temp->list, &inst->enc_input_crs);
- }
- }
- static void msm_vidc_free_input_cr_list(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_input_cr_data *temp, *next;
- list_for_each_entry_safe(temp, next, &inst->enc_input_crs, list) {
- list_del(&temp->list);
- kfree(temp);
- }
- INIT_LIST_HEAD(&inst->enc_input_crs);
- }
- static int msm_vidc_queue_buffer(struct msm_vidc_inst *inst, struct msm_vidc_buffer *buf)
- {
- struct msm_vidc_buffer *meta;
- int rc = 0;
- u32 cr = 0;
- if (!inst || !buf || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (is_encode_session(inst) && is_input_buffer(buf->type)) {
- cr = inst->capabilities->cap[ENC_IP_CR].value;
- msm_vidc_update_input_cr(inst, buf->index, cr);
- msm_vidc_update_cap_value(inst, ENC_IP_CR, 0, __func__);
- }
- if (is_decode_session(inst) && is_input_buffer(buf->type) &&
- inst->capabilities->cap[CODEC_CONFIG].value) {
- buf->flags |= MSM_VIDC_BUF_FLAG_CODECCONFIG;
- msm_vidc_update_cap_value(inst, CODEC_CONFIG, 0, __func__);
- }
- if (is_decode_session(inst) && is_output_buffer(buf->type)) {
- rc = msm_vidc_process_readonly_buffers(inst, buf);
- if (rc)
- return rc;
- }
- print_vidc_buffer(VIDC_HIGH, "high", "qbuf", inst, buf);
- meta = get_meta_buffer(inst, buf);
- if (meta)
- print_vidc_buffer(VIDC_HIGH, "high", "qbuf", inst, meta);
- if (!meta && is_meta_enabled(inst, buf->type)) {
- print_vidc_buffer(VIDC_ERR, "err ", "missing meta for", inst, buf);
- return -EINVAL;
- }
- if (msm_vidc_is_super_buffer(inst) && is_input_buffer(buf->type))
- rc = venus_hfi_queue_super_buffer(inst, buf, meta);
- else
- rc = venus_hfi_queue_buffer(inst, buf, meta);
- if (rc)
- return rc;
- buf->attr &= ~MSM_VIDC_ATTR_DEFERRED;
- buf->attr |= MSM_VIDC_ATTR_QUEUED;
- if (meta) {
- meta->attr &= ~MSM_VIDC_ATTR_DEFERRED;
- meta->attr |= MSM_VIDC_ATTR_QUEUED;
- }
- if (is_input_buffer(buf->type))
- inst->power.buffer_counter++;
- if (buf->type == MSM_VIDC_BUF_INPUT)
- msm_vidc_debugfs_update(inst, MSM_VIDC_DEBUGFS_EVENT_ETB);
- else if (buf->type == MSM_VIDC_BUF_OUTPUT)
- msm_vidc_debugfs_update(inst, MSM_VIDC_DEBUGFS_EVENT_FTB);
- return 0;
- }
- int msm_vidc_queue_buffer_batch(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buf;
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- buffers = msm_vidc_get_buffers(inst, MSM_VIDC_BUF_OUTPUT, __func__);
- if (!buffers)
- return -EINVAL;
- msm_vidc_scale_power(inst, true);
- list_for_each_entry(buf, &buffers->list, list) {
- if (!(buf->attr & MSM_VIDC_ATTR_DEFERRED))
- continue;
- rc = msm_vidc_queue_buffer(inst, buf);
- if (rc)
- return rc;
- }
- return 0;
- }
- int msm_vidc_queue_buffer_single(struct msm_vidc_inst *inst, struct vb2_buffer *vb2)
- {
- int rc = 0;
- struct msm_vidc_buffer *buf;
- enum msm_vidc_allow allow;
- if (!inst || !vb2) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- buf = msm_vidc_get_driver_buf(inst, vb2);
- if (!buf)
- return -EINVAL;
- allow = msm_vidc_allow_qbuf(inst, vb2->type);
- if (allow == MSM_VIDC_DISALLOW) {
- i_vpr_e(inst, "%s: qbuf not allowed\n", __func__);
- return -EINVAL;
- } else if (allow == MSM_VIDC_DEFER) {
- print_vidc_buffer(VIDC_LOW, "low ", "qbuf deferred", inst, buf);
- return 0;
- }
- msm_vidc_scale_power(inst, is_input_buffer(buf->type));
- rc = msm_vidc_queue_buffer(inst, buf);
- if (rc)
- return rc;
- return rc;
- }
- int msm_vidc_destroy_internal_buffer(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buffer)
- {
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_allocations *allocations;
- struct msm_vidc_mappings *mappings;
- struct msm_vidc_alloc *alloc, *alloc_dummy;
- struct msm_vidc_map *map, *map_dummy;
- struct msm_vidc_buffer *buf, *dummy;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_internal_buffer(buffer->type)) {
- i_vpr_e(inst, "%s: type: %s is not internal\n",
- __func__, buf_name(buffer->type));
- return 0;
- }
- i_vpr_h(inst, "%s: destroy: type: %8s, size: %9u, device_addr %#x\n", __func__,
- buf_name(buffer->type), buffer->buffer_size, buffer->device_addr);
- buffers = msm_vidc_get_buffers(inst, buffer->type, __func__);
- if (!buffers)
- return -EINVAL;
- allocations = msm_vidc_get_allocations(inst, buffer->type, __func__);
- if (!allocations)
- return -EINVAL;
- mappings = msm_vidc_get_mappings(inst, buffer->type, __func__);
- if (!mappings)
- return -EINVAL;
- list_for_each_entry_safe(map, map_dummy, &mappings->list, list) {
- if (map->dmabuf == buffer->dmabuf) {
- msm_vidc_memory_unmap(inst->core, map);
- list_del(&map->list);
- msm_vidc_put_map_buffer(inst, map);
- break;
- }
- }
- list_for_each_entry_safe(alloc, alloc_dummy, &allocations->list, list) {
- if (alloc->dmabuf == buffer->dmabuf) {
- msm_vidc_memory_free(inst->core, alloc);
- list_del(&alloc->list);
- msm_vidc_put_alloc_buffer(inst, alloc);
- break;
- }
- }
- list_for_each_entry_safe(buf, dummy, &buffers->list, list) {
- if (buf->dmabuf == buffer->dmabuf) {
- list_del(&buf->list);
- msm_vidc_put_vidc_buffer(inst, buf);
- break;
- }
- }
- buffers->size = 0;
- buffers->min_count = buffers->extra_count = buffers->actual_count = 0;
- return 0;
- }
- int msm_vidc_get_internal_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type)
- {
- u32 buf_size;
- u32 buf_count;
- struct msm_vidc_core *core;
- struct msm_vidc_buffers *buffers;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- buf_size = call_session_op(core, buffer_size,
- inst, buffer_type);
- buf_count = call_session_op(core, min_count,
- inst, buffer_type);
- buffers = msm_vidc_get_buffers(inst, buffer_type, __func__);
- if (!buffers)
- return -EINVAL;
- if (buf_size <= buffers->size &&
- buf_count <= buffers->min_count) {
- buffers->reuse = true;
- } else {
- buffers->reuse = false;
- buffers->size = buf_size;
- buffers->min_count = buf_count;
- }
- return 0;
- }
- int msm_vidc_create_internal_buffer(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type, u32 index)
- {
- int rc = 0;
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_allocations *allocations;
- struct msm_vidc_mappings *mappings;
- struct msm_vidc_buffer *buffer;
- struct msm_vidc_alloc *alloc;
- struct msm_vidc_map *map;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_internal_buffer(buffer_type)) {
- i_vpr_e(inst, "%s: type %s is not internal\n",
- __func__, buf_name(buffer_type));
- return 0;
- }
- buffers = msm_vidc_get_buffers(inst, buffer_type, __func__);
- if (!buffers)
- return -EINVAL;
- allocations = msm_vidc_get_allocations(inst, buffer_type, __func__);
- if (!allocations)
- return -EINVAL;
- mappings = msm_vidc_get_mappings(inst, buffer_type, __func__);
- if (!mappings)
- return -EINVAL;
- if (!buffers->size)
- return 0;
- buffer = msm_vidc_get_vidc_buffer(inst);
- if (!buffer) {
- i_vpr_e(inst, "%s: buf alloc failed\n", __func__);
- return -ENOMEM;
- }
- INIT_LIST_HEAD(&buffer->list);
- buffer->type = buffer_type;
- buffer->index = index;
- buffer->buffer_size = buffers->size;
- list_add_tail(&buffer->list, &buffers->list);
- alloc = msm_vidc_get_alloc_buffer(inst);
- if (!alloc) {
- i_vpr_e(inst, "%s: alloc failed\n", __func__);
- return -ENOMEM;
- }
- INIT_LIST_HEAD(&alloc->list);
- alloc->type = buffer_type;
- alloc->region = msm_vidc_get_buffer_region(inst,
- buffer_type, __func__);
- alloc->size = buffer->buffer_size;
- alloc->secure = is_secure_region(alloc->region);
- rc = msm_vidc_memory_alloc(inst->core, alloc);
- if (rc)
- return -ENOMEM;
- list_add_tail(&alloc->list, &allocations->list);
- map = msm_vidc_get_map_buffer(inst);
- if (!map) {
- i_vpr_e(inst, "%s: map alloc failed\n", __func__);
- return -ENOMEM;
- }
- INIT_LIST_HEAD(&map->list);
- map->type = alloc->type;
- map->region = alloc->region;
- map->dmabuf = alloc->dmabuf;
- rc = msm_vidc_memory_map(inst->core, map);
- if (rc)
- return -ENOMEM;
- list_add_tail(&map->list, &mappings->list);
- buffer->dmabuf = alloc->dmabuf;
- buffer->device_addr = map->device_addr;
- i_vpr_h(inst, "%s: create: type: %8s, size: %9u, device_addr %#x\n", __func__,
- buf_name(buffer_type), buffers->size, buffer->device_addr);
- return 0;
- }
- int msm_vidc_create_internal_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type)
- {
- int rc = 0;
- struct msm_vidc_buffers *buffers;
- int i;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- buffers = msm_vidc_get_buffers(inst, buffer_type, __func__);
- if (!buffers)
- return -EINVAL;
- if (buffers->reuse) {
- i_vpr_l(inst, "%s: reuse enabled for %s\n", __func__, buf_name(buffer_type));
- return 0;
- }
- for (i = 0; i < buffers->min_count; i++) {
- rc = msm_vidc_create_internal_buffer(inst, buffer_type, i);
- if (rc)
- return rc;
- }
- return rc;
- }
- int msm_vidc_queue_internal_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type)
- {
- int rc = 0;
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buffer, *dummy;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_internal_buffer(buffer_type)) {
- i_vpr_e(inst, "%s: %s is not internal\n", __func__, buf_name(buffer_type));
- return 0;
- }
- buffers = msm_vidc_get_buffers(inst, buffer_type, __func__);
- if (!buffers)
- return -EINVAL;
- if (buffers->reuse) {
- i_vpr_l(inst, "%s: reuse enabled for %s buf\n",
- __func__, buf_name(buffer_type));
- return 0;
- }
- list_for_each_entry_safe(buffer, dummy, &buffers->list, list) {
- /* do not queue pending release buffers */
- if (buffer->flags & MSM_VIDC_ATTR_PENDING_RELEASE)
- continue;
- /* do not queue already queued buffers */
- if (buffer->attr & MSM_VIDC_ATTR_QUEUED)
- continue;
- rc = venus_hfi_queue_buffer(inst, buffer, NULL);
- if (rc)
- return rc;
- /* mark queued */
- buffer->attr |= MSM_VIDC_ATTR_QUEUED;
- i_vpr_h(inst, "%s: queue: type: %8s, size: %9u, device_addr %#x\n", __func__,
- buf_name(buffer->type), buffer->buffer_size, buffer->device_addr);
- }
- return 0;
- }
- int msm_vidc_alloc_and_queue_session_internal_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (buffer_type != MSM_VIDC_BUF_ARP &&
- buffer_type != MSM_VIDC_BUF_PERSIST) {
- i_vpr_e(inst, "%s: invalid buffer type: %s\n",
- __func__, buf_name(buffer_type));
- rc = -EINVAL;
- goto exit;
- }
- rc = msm_vidc_get_internal_buffers(inst, buffer_type);
- if (rc)
- goto exit;
- rc = msm_vidc_create_internal_buffers(inst, buffer_type);
- if (rc)
- goto exit;
- rc = msm_vidc_queue_internal_buffers(inst, buffer_type);
- if (rc)
- goto exit;
- exit:
- return rc;
- }
- int msm_vidc_release_internal_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type buffer_type)
- {
- int rc = 0;
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buffer, *dummy;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_internal_buffer(buffer_type)) {
- i_vpr_e(inst, "%s: %s is not internal\n",
- __func__, buf_name(buffer_type));
- return 0;
- }
- buffers = msm_vidc_get_buffers(inst, buffer_type, __func__);
- if (!buffers)
- return -EINVAL;
- if (buffers->reuse) {
- i_vpr_l(inst, "%s: reuse enabled for %s buf\n",
- __func__, buf_name(buffer_type));
- return 0;
- }
- list_for_each_entry_safe(buffer, dummy, &buffers->list, list) {
- /* do not release already pending release buffers */
- if (buffer->attr & MSM_VIDC_ATTR_PENDING_RELEASE)
- continue;
- /* release only queued buffers */
- if (!(buffer->attr & MSM_VIDC_ATTR_QUEUED))
- continue;
- rc = venus_hfi_release_buffer(inst, buffer);
- if (rc)
- return rc;
- /* mark pending release */
- buffer->attr |= MSM_VIDC_ATTR_PENDING_RELEASE;
- i_vpr_h(inst, "%s: release: type: %8s, size: %9u, device_addr %#x\n", __func__,
- buf_name(buffer->type), buffer->buffer_size, buffer->device_addr);
- }
- return 0;
- }
- int msm_vidc_vb2_buffer_done(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buf)
- {
- int type, port;
- struct vb2_queue *q;
- struct vb2_buffer *vb2;
- struct vb2_v4l2_buffer *vbuf;
- bool found;
- if (!inst || !buf) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- type = v4l2_type_from_driver(buf->type, __func__);
- if (!type)
- return -EINVAL;
- port = v4l2_type_to_driver_port(inst, type, __func__);
- if (port < 0)
- return -EINVAL;
- q = &inst->vb2q[port];
- if (!q->streaming) {
- i_vpr_e(inst, "%s: port %d is not streaming\n",
- __func__, port);
- return -EINVAL;
- }
- found = false;
- list_for_each_entry(vb2, &q->queued_list, queued_entry) {
- if (vb2->state != VB2_BUF_STATE_ACTIVE)
- continue;
- if (vb2->index == buf->index) {
- found = true;
- break;
- }
- }
- if (!found) {
- print_vidc_buffer(VIDC_ERR, "err ", "vb2 not found for", inst, buf);
- return -EINVAL;
- }
- vbuf = to_vb2_v4l2_buffer(vb2);
- vbuf->flags = buf->flags;
- vb2->timestamp = buf->timestamp;
- vb2->planes[0].bytesused = buf->data_size;
- vb2_buffer_done(vb2, VB2_BUF_STATE_DONE);
- return 0;
- }
- int msm_vidc_event_queue_init(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- int index;
- struct msm_vidc_core *core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- if (is_decode_session(inst))
- index = 0;
- else if (is_encode_session(inst))
- index = 1;
- else
- return -EINVAL;
- v4l2_fh_init(&inst->event_handler, &core->vdev[index].vdev);
- v4l2_fh_add(&inst->event_handler);
- return rc;
- }
- int msm_vidc_event_queue_deinit(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- v4l2_fh_del(&inst->event_handler);
- v4l2_fh_exit(&inst->event_handler);
- return rc;
- }
- static int vb2q_init(struct msm_vidc_inst *inst,
- struct vb2_queue *q, enum v4l2_buf_type type)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !q || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- q->type = type;
- q->io_modes = VB2_DMABUF;
- q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
- q->ops = core->vb2_ops;
- q->mem_ops = core->vb2_mem_ops;
- q->drv_priv = inst;
- q->allow_zero_bytesused = 1;
- q->copy_timestamp = 1;
- rc = vb2_queue_init(q);
- if (rc)
- i_vpr_e(inst, "%s: vb2_queue_init failed for type %d\n",
- __func__, type);
- return rc;
- }
- int msm_vidc_vb2_queue_init(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- i_vpr_e(inst, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (inst->vb2q_init) {
- i_vpr_h(inst, "%s: vb2q already inited\n", __func__);
- return 0;
- }
- rc = vb2q_init(inst, &inst->vb2q[INPUT_PORT], INPUT_MPLANE);
- if (rc)
- goto exit;
- rc = vb2q_init(inst, &inst->vb2q[OUTPUT_PORT], OUTPUT_MPLANE);
- if (rc)
- goto fail_out_vb2q_init;
- rc = vb2q_init(inst, &inst->vb2q[INPUT_META_PORT], INPUT_META_PLANE);
- if (rc)
- goto fail_in_meta_vb2q_init;
- rc = vb2q_init(inst, &inst->vb2q[OUTPUT_META_PORT], OUTPUT_META_PLANE);
- if (rc)
- goto fail_out_meta_vb2q_init;
- inst->vb2q_init = true;
- return 0;
- fail_out_meta_vb2q_init:
- vb2_queue_release(&inst->vb2q[INPUT_META_PORT]);
- fail_in_meta_vb2q_init:
- vb2_queue_release(&inst->vb2q[OUTPUT_PORT]);
- fail_out_vb2q_init:
- vb2_queue_release(&inst->vb2q[INPUT_PORT]);
- exit:
- return rc;
- }
- int msm_vidc_vb2_queue_deinit(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!inst->vb2q_init) {
- i_vpr_h(inst, "%s: vb2q already deinited\n", __func__);
- return 0;
- }
- vb2_queue_release(&inst->vb2q[OUTPUT_META_PORT]);
- vb2_queue_release(&inst->vb2q[INPUT_META_PORT]);
- vb2_queue_release(&inst->vb2q[OUTPUT_PORT]);
- vb2_queue_release(&inst->vb2q[INPUT_PORT]);
- inst->vb2q_init = false;
- return rc;
- }
- int msm_vidc_add_session(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_inst *i;
- struct msm_vidc_core *core;
- u32 count = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- if (!core->capabilities) {
- i_vpr_e(inst, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core_lock(core, __func__);
- list_for_each_entry(i, &core->instances, list)
- count++;
- if (count < core->capabilities[MAX_SESSION_COUNT].value) {
- list_add_tail(&inst->list, &core->instances);
- } else {
- i_vpr_e(inst, "%s: total sessions %d exceeded max limit %d\n",
- __func__, count, core->capabilities[MAX_SESSION_COUNT].value);
- rc = -EINVAL;
- }
- core_unlock(core, __func__);
- return rc;
- }
- int msm_vidc_remove_session(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_inst *i, *temp;
- struct msm_vidc_core *core;
- u32 count = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- list_for_each_entry_safe(i, temp, &core->instances, list) {
- if (i->session_id == inst->session_id) {
- list_del_init(&i->list);
- i_vpr_h(inst, "%s: removed session %#x\n",
- __func__, i->session_id);
- }
- }
- list_for_each_entry(i, &core->instances, list)
- count++;
- i_vpr_h(inst, "%s: remaining sessions %d\n", __func__, count);
- core_unlock(core, __func__);
- return 0;
- }
- int msm_vidc_session_open(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- inst->packet_size = 4096;
- inst->packet = kzalloc(inst->packet_size, GFP_KERNEL);
- if (!inst->packet) {
- i_vpr_e(inst, "%s(): inst packet allocation failed\n", __func__);
- return -ENOMEM;
- }
- rc = venus_hfi_session_open(inst);
- if (rc)
- goto error;
- return 0;
- error:
- i_vpr_e(inst, "%s(): session open failed\n", __func__);
- kfree(inst->packet);
- inst->packet = NULL;
- return rc;
- }
- int msm_vidc_session_set_codec(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = venus_hfi_session_set_codec(inst);
- if (rc)
- return rc;
- return 0;
- }
- int msm_vidc_session_set_default_header(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- u32 default_header = false;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- default_header = inst->capabilities->cap[DEFAULT_HEADER].value;
- i_vpr_h(inst, "%s: default header: %d", __func__, default_header);
- rc = venus_hfi_session_property(inst,
- HFI_PROP_DEC_DEFAULT_HEADER,
- HFI_HOST_FLAGS_NONE,
- get_hfi_port(inst, INPUT_PORT),
- HFI_PAYLOAD_U32,
- &default_header,
- sizeof(u32));
- if (rc)
- i_vpr_e(inst, "%s: set property failed\n", __func__);
- return rc;
- }
- int msm_vidc_session_streamon(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- msm_vidc_scale_power(inst, true);
- rc = venus_hfi_start(inst, port);
- if (rc)
- return rc;
- return rc;
- }
- int msm_vidc_session_streamoff(struct msm_vidc_inst *inst,
- enum msm_vidc_port_type port)
- {
- int rc = 0;
- int count = 0;
- struct msm_vidc_core *core;
- enum signal_session_response signal_type;
- enum msm_vidc_buffer_type buffer_type;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (port == INPUT_PORT) {
- signal_type = SIGNAL_CMD_STOP_INPUT;
- buffer_type = MSM_VIDC_BUF_INPUT;
- } else if (port == OUTPUT_PORT) {
- signal_type = SIGNAL_CMD_STOP_OUTPUT;
- buffer_type = MSM_VIDC_BUF_OUTPUT;
- } else {
- i_vpr_e(inst, "%s: invalid port: %d\n", __func__, port);
- return -EINVAL;
- }
- rc = venus_hfi_stop(inst, port);
- if (rc)
- goto error;
- core = inst->core;
- i_vpr_h(inst, "%s: wait on port: %d for time: %d ms\n",
- __func__, port, core->capabilities[HW_RESPONSE_TIMEOUT].value);
- mutex_unlock(&inst->lock);
- rc = wait_for_completion_timeout(
- &inst->completions[signal_type],
- msecs_to_jiffies(
- core->capabilities[HW_RESPONSE_TIMEOUT].value));
- if (!rc) {
- i_vpr_e(inst, "%s: session stop timed out for port: %d\n",
- __func__, port);
- rc = -ETIMEDOUT;
- msm_vidc_core_timeout(inst->core);
- } else {
- rc = 0;
- }
- mutex_lock(&inst->lock);
- if(rc)
- goto error;
- /* no more queued buffers after streamoff */
- count = msm_vidc_num_buffers(inst, buffer_type, MSM_VIDC_ATTR_QUEUED);
- if (!count) {
- i_vpr_h(inst, "%s: stop successful on port: %d\n",
- __func__, port);
- } else {
- i_vpr_e(inst,
- "%s: %d buffers pending with firmware on port: %d\n",
- __func__, count, port);
- rc = -EINVAL;
- goto error;
- }
- /* flush deferred buffers */
- msm_vidc_flush_buffers(inst, buffer_type);
- msm_vidc_flush_delayed_unmap_buffers(inst, buffer_type);
- return 0;
- error:
- msm_vidc_kill_session(inst);
- msm_vidc_flush_buffers(inst, buffer_type);
- return rc;
- }
- int msm_vidc_session_close(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = venus_hfi_session_close(inst);
- if (rc)
- return rc;
- /* we are not supposed to send any more commands after close */
- i_vpr_h(inst, "%s: free session packet data\n", __func__);
- kfree(inst->packet);
- inst->packet = NULL;
- core = inst->core;
- i_vpr_h(inst, "%s: wait on close for time: %d ms\n",
- __func__, core->capabilities[HW_RESPONSE_TIMEOUT].value);
- mutex_unlock(&inst->lock);
- rc = wait_for_completion_timeout(
- &inst->completions[SIGNAL_CMD_CLOSE],
- msecs_to_jiffies(
- core->capabilities[HW_RESPONSE_TIMEOUT].value));
- if (!rc) {
- i_vpr_e(inst, "%s: session close timed out\n", __func__);
- rc = -ETIMEDOUT;
- msm_vidc_core_timeout(inst->core);
- } else {
- rc = 0;
- i_vpr_h(inst, "%s: close successful\n", __func__);
- }
- mutex_lock(&inst->lock);
- msm_vidc_remove_session(inst);
- return rc;
- }
- int msm_vidc_kill_session(struct msm_vidc_inst *inst)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!inst->session_id) {
- i_vpr_e(inst, "%s: already killed\n", __func__);
- return 0;
- }
- i_vpr_e(inst, "%s: killing session\n", __func__);
- msm_vidc_session_close(inst);
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- return 0;
- }
- int msm_vidc_get_inst_capability(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- int i;
- struct msm_vidc_core *core;
- if (!inst || !inst->core || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- for (i = 0; i < core->codecs_count; i++) {
- if (core->inst_caps[i].domain == inst->domain &&
- core->inst_caps[i].codec == inst->codec) {
- i_vpr_h(inst,
- "%s: copied capabilities with %#x codec, %#x domain\n",
- __func__, inst->codec, inst->domain);
- memcpy(inst->capabilities, &core->inst_caps[i],
- sizeof(struct msm_vidc_inst_capability));
- }
- }
- return rc;
- }
- int msm_vidc_deinit_core_caps(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- kfree(core->capabilities);
- core->capabilities = NULL;
- d_vpr_h("%s: Core capabilities freed\n", __func__);
- return rc;
- }
- int msm_vidc_init_core_caps(struct msm_vidc_core *core)
- {
- int rc = 0;
- int i, num_platform_caps;
- struct msm_platform_core_capability *platform_data;
- if (!core || !core->platform) {
- d_vpr_e("%s: invalid params\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- platform_data = core->platform->data.core_data;
- if (!platform_data) {
- d_vpr_e("%s: platform core data is NULL\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- core->capabilities = kcalloc(1,
- (sizeof(struct msm_vidc_core_capability) *
- (CORE_CAP_MAX + 1)), GFP_KERNEL);
- if (!core->capabilities) {
- d_vpr_e("%s: failed to allocate core capabilities\n",
- __func__);
- rc = -ENOMEM;
- goto exit;
- }
- num_platform_caps = core->platform->data.core_data_size;
- /* loop over platform caps */
- for (i = 0; i < num_platform_caps && i < CORE_CAP_MAX; i++) {
- core->capabilities[platform_data[i].type].type = platform_data[i].type;
- core->capabilities[platform_data[i].type].value = platform_data[i].value;
- }
- exit:
- return rc;
- }
- static void update_inst_capability(struct msm_platform_inst_capability *in,
- struct msm_vidc_inst_capability *capability)
- {
- if (!in || !capability) {
- d_vpr_e("%s: invalid params %pK %pK\n",
- __func__, in, capability);
- return;
- }
- if (in->cap < INST_CAP_MAX) {
- capability->cap[in->cap].cap = in->cap;
- capability->cap[in->cap].min = in->min;
- capability->cap[in->cap].max = in->max;
- capability->cap[in->cap].step_or_mask = in->step_or_mask;
- capability->cap[in->cap].value = in->value;
- capability->cap[in->cap].flags = in->flags;
- capability->cap[in->cap].v4l2_id = in->v4l2_id;
- capability->cap[in->cap].hfi_id = in->hfi_id;
- memcpy(capability->cap[in->cap].parents, in->parents,
- sizeof(capability->cap[in->cap].parents));
- memcpy(capability->cap[in->cap].children, in->children,
- sizeof(capability->cap[in->cap].children));
- capability->cap[in->cap].adjust = in->adjust;
- capability->cap[in->cap].set = in->set;
- } else {
- d_vpr_e("%s: invalid cap %d\n",
- __func__, in->cap);
- }
- }
- int msm_vidc_deinit_instance_caps(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- kfree(core->inst_caps);
- core->inst_caps = NULL;
- d_vpr_h("%s: core->inst_caps freed\n", __func__);
- return rc;
- }
- int msm_vidc_init_instance_caps(struct msm_vidc_core *core)
- {
- int rc = 0;
- u8 enc_valid_codecs, dec_valid_codecs;
- u8 count_bits, enc_codec_count;
- u8 codecs_count = 0;
- int i, j, check_bit, num_platform_caps;
- struct msm_platform_inst_capability *platform_data = NULL;
- if (!core || !core->platform || !core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- rc = -EINVAL;
- goto error;
- }
- platform_data = core->platform->data.instance_data;
- if (!platform_data) {
- d_vpr_e("%s: platform instance data is NULL\n",
- __func__);
- rc = -EINVAL;
- goto error;
- }
- enc_valid_codecs = core->capabilities[ENC_CODECS].value;
- count_bits = enc_valid_codecs;
- COUNT_BITS(count_bits, codecs_count);
- enc_codec_count = codecs_count;
- dec_valid_codecs = core->capabilities[DEC_CODECS].value;
- count_bits = dec_valid_codecs;
- COUNT_BITS(count_bits, codecs_count);
- core->codecs_count = codecs_count;
- core->inst_caps = kcalloc(codecs_count,
- sizeof(struct msm_vidc_inst_capability),
- GFP_KERNEL);
- if (!core->inst_caps) {
- d_vpr_e("%s: failed to allocate core capabilities\n",
- __func__);
- rc = -ENOMEM;
- goto error;
- }
- check_bit = 0;
- /* determine codecs for enc domain */
- for (i = 0; i < enc_codec_count; i++) {
- while (check_bit < (sizeof(enc_valid_codecs) * 8)) {
- if (enc_valid_codecs & BIT(check_bit)) {
- core->inst_caps[i].domain = MSM_VIDC_ENCODER;
- core->inst_caps[i].codec = enc_valid_codecs &
- BIT(check_bit);
- check_bit++;
- break;
- }
- check_bit++;
- }
- }
- /* reset checkbit to check from 0th bit of decoder codecs set bits*/
- check_bit = 0;
- /* determine codecs for dec domain */
- for (; i < codecs_count; i++) {
- while (check_bit < (sizeof(dec_valid_codecs) * 8)) {
- if (dec_valid_codecs & BIT(check_bit)) {
- core->inst_caps[i].domain = MSM_VIDC_DECODER;
- core->inst_caps[i].codec = dec_valid_codecs &
- BIT(check_bit);
- check_bit++;
- break;
- }
- check_bit++;
- }
- }
- num_platform_caps = core->platform->data.instance_data_size;
- d_vpr_h("%s: num caps %d\n", __func__, num_platform_caps);
- /* loop over each platform capability */
- for (i = 0; i < num_platform_caps; i++) {
- /* select matching core codec and update it */
- for (j = 0; j < codecs_count; j++) {
- if ((platform_data[i].domain &
- core->inst_caps[j].domain) &&
- (platform_data[i].codec &
- core->inst_caps[j].codec)) {
- /* update core capability */
- update_inst_capability(&platform_data[i],
- &core->inst_caps[j]);
- }
- }
- }
- error:
- return rc;
- }
- int msm_vidc_core_deinit(struct msm_vidc_core *core, bool force)
- {
- int rc = 0;
- struct msm_vidc_inst *inst, *dummy;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core_lock(core, __func__);
- d_vpr_h("%s(): force %u\n", __func__, force);
- if (core->state == MSM_VIDC_CORE_DEINIT)
- goto unlock;
- if (!force)
- if (!list_empty(&core->instances))
- goto unlock;
- venus_hfi_core_deinit(core);
- /* unlink all sessions from core, if any */
- list_for_each_entry_safe(inst, dummy, &core->instances, list) {
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- list_del(&inst->list);
- }
- msm_vidc_change_core_state(core, MSM_VIDC_CORE_DEINIT, __func__);
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int msm_vidc_core_init(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core || !core->platform) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core_lock(core, __func__);
- if (core->state == MSM_VIDC_CORE_INIT) {
- rc = 0;
- goto unlock;
- }
- msm_vidc_change_core_state(core, MSM_VIDC_CORE_INIT, __func__);
- init_completion(&core->init_done);
- core->smmu_fault_handled = false;
- core->ssr.trigger = false;
- rc = venus_hfi_core_init(core);
- if (rc) {
- d_vpr_e("%s: core init failed\n", __func__);
- goto unlock;
- }
- d_vpr_h("%s(): waiting for sys_init_done, %d ms\n", __func__,
- core->capabilities[HW_RESPONSE_TIMEOUT].value);
- core_unlock(core, __func__);
- rc = wait_for_completion_timeout(&core->init_done, msecs_to_jiffies(
- core->capabilities[HW_RESPONSE_TIMEOUT].value));
- core_lock(core, __func__);
- if (!rc) {
- d_vpr_e("%s: core init timed out\n", __func__);
- rc = -ETIMEDOUT;
- } else {
- d_vpr_h("%s: system init wait completed\n", __func__);
- rc = 0;
- }
- unlock:
- core_unlock(core, __func__);
- if (rc)
- msm_vidc_core_deinit(core, true);
- return rc;
- }
- int msm_vidc_core_timeout(struct msm_vidc_core *core)
- {
- return msm_vidc_core_deinit(core, true);
- }
- int msm_vidc_print_buffer_info(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffers *buffers;
- int i;
- if (!inst) {
- i_vpr_e(inst, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- /* Print buffer details */
- for (i = 0; i < ARRAY_SIZE(buf_type_name_arr); i++) {
- buffers = msm_vidc_get_buffers(inst, buf_type_name_arr[i].type, __func__);
- if (!buffers)
- continue;
- i_vpr_h(inst, "buf: type: %11s, count %2d, extra %2d, actual %2d, size %9u\n",
- buf_type_name_arr[i].name, buffers->min_count,
- buffers->extra_count, buffers->actual_count,
- buffers->size);
- }
- return 0;
- }
- int msm_vidc_print_inst_info(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buf;
- enum msm_vidc_port_type port;
- bool is_secure, is_decode;
- u32 bit_depth, bit_rate, frame_rate, width, height;
- struct dma_buf *dbuf;
- int i = 0;
- if (!inst || !inst->capabilities) {
- i_vpr_e(inst, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- is_secure = is_secure_session(inst);
- is_decode = inst->domain == MSM_VIDC_DECODER;
- port = is_decode ? INPUT_PORT : OUTPUT_PORT;
- width = inst->fmts[port].fmt.pix_mp.width;
- height = inst->fmts[port].fmt.pix_mp.height;
- bit_depth = inst->capabilities->cap[BIT_DEPTH].value & 0xFFFF;
- bit_rate = inst->capabilities->cap[BIT_RATE].value;
- frame_rate = inst->capabilities->cap[FRAME_RATE].value >> 16;
- i_vpr_e(inst, "%s %s session, HxW: %d x %d, fps: %d, bitrate: %d, bit-depth: %d\n",
- is_secure ? "Secure" : "Non-Secure",
- is_decode ? "Decode" : "Encode",
- height, width,
- frame_rate, bit_rate, bit_depth);
- /* Print buffer details */
- for (i = 0; i < ARRAY_SIZE(buf_type_name_arr); i++) {
- buffers = msm_vidc_get_buffers(inst, buf_type_name_arr[i].type, __func__);
- if (!buffers)
- continue;
- i_vpr_e(inst, "count: type: %11s, min: %2d, extra: %2d, actual: %2d\n",
- buf_type_name_arr[i].name, buffers->min_count,
- buffers->extra_count, buffers->actual_count);
- list_for_each_entry(buf, &buffers->list, list) {
- if (!buf->dmabuf)
- continue;
- dbuf = (struct dma_buf *)buf->dmabuf;
- i_vpr_e(inst,
- "buf: type: %11s, index: %2d, fd: %4d, size: %9u, off: %8u, filled: %9u, iova: %8x, inode: %9ld, flags: %8x, ts: %16lld, attr: %8x\n",
- buf_type_name_arr[i].name, buf->index, buf->fd, buf->buffer_size,
- buf->data_offset, buf->data_size, buf->device_addr,
- file_inode(dbuf->file)->i_ino,
- buf->flags, buf->timestamp, buf->attr);
- }
- }
- return 0;
- }
- void msm_vidc_print_core_info(struct msm_vidc_core *core)
- {
- struct msm_vidc_inst *inst = NULL;
- struct msm_vidc_inst *instances[MAX_SUPPORTED_INSTANCES];
- s32 num_instances = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- core_lock(core, __func__);
- list_for_each_entry(inst, &core->instances, list)
- instances[num_instances++] = inst;
- core_unlock(core, __func__);
- while (num_instances--) {
- inst = instances[num_instances];
- inst = get_inst_ref(core, inst);
- if (!inst)
- continue;
- inst_lock(inst, __func__);
- msm_vidc_print_inst_info(inst);
- inst_unlock(inst, __func__);
- put_inst(inst);
- }
- }
- int msm_vidc_smmu_fault_handler(struct iommu_domain *domain,
- struct device *dev, unsigned long iova, int flags, void *data)
- {
- struct msm_vidc_core *core = data;
- if (!domain || !core || !core->capabilities) {
- d_vpr_e("%s: invalid params %pK %pK\n",
- __func__, domain, core);
- return -EINVAL;
- }
- if (core->smmu_fault_handled) {
- if (core->capabilities[NON_FATAL_FAULTS].value) {
- dprintk_ratelimit(VIDC_ERR, "err ",
- "%s: non-fatal pagefault address: %lx\n",
- __func__, iova);
- return 0;
- }
- }
- d_vpr_e("%s: faulting address: %lx\n", __func__, iova);
- core->smmu_fault_handled = true;
- /* print noc error log registers */
- venus_hfi_noc_error_info(core);
- msm_vidc_print_core_info(core);
- /*
- * Return -ENOSYS to elicit the default behaviour of smmu driver.
- * If we return -ENOSYS, then smmu driver assumes page fault handler
- * is not installed and prints a list of useful debug information like
- * FAR, SID etc. This information is not printed if we return 0.
- */
- return -ENOSYS;
- }
- int msm_vidc_trigger_ssr(struct msm_vidc_core *core,
- u64 trigger_ssr_val)
- {
- struct msm_vidc_ssr *ssr;
- if (!core) {
- d_vpr_e("%s: Invalid parameters\n", __func__);
- return -EINVAL;
- }
- ssr = &core->ssr;
- /*
- * <test_addr><sub_client_id><ssr_type>
- * ssr_type: 0-3 bits
- * sub_client_id: 4-7 bits
- * reserved: 8-31 bits
- * test_addr: 32-63 bits
- */
- ssr->ssr_type = (trigger_ssr_val &
- (unsigned long)SSR_TYPE) >> SSR_TYPE_SHIFT;
- ssr->sub_client_id = (trigger_ssr_val &
- (unsigned long)SSR_SUB_CLIENT_ID) >> SSR_SUB_CLIENT_ID_SHIFT;
- ssr->test_addr = (trigger_ssr_val &
- (unsigned long)SSR_ADDR_ID) >> SSR_ADDR_SHIFT;
- schedule_work(&core->ssr_work);
- return 0;
- }
- void msm_vidc_ssr_handler(struct work_struct *work)
- {
- int rc;
- struct msm_vidc_core *core;
- struct msm_vidc_ssr *ssr;
- core = container_of(work, struct msm_vidc_core, ssr_work);
- if (!core) {
- d_vpr_e("%s: invalid params %pK\n", __func__, core);
- return;
- }
- ssr = &core->ssr;
- core_lock(core, __func__);
- if (core->state == MSM_VIDC_CORE_INIT) {
- /*
- * In current implementation, user-initiated SSR triggers
- * a fatal error from hardware. However, there is no way
- * to know if fatal error is due to SSR or not. Handle
- * user SSR as non-fatal.
- */
- core->ssr.trigger = true;
- rc = venus_hfi_trigger_ssr(core, ssr->ssr_type,
- ssr->sub_client_id, ssr->test_addr);
- if (rc) {
- d_vpr_e("%s: trigger_ssr failed\n", __func__);
- core->ssr.trigger = false;
- }
- } else {
- d_vpr_e("%s: video core not initialized\n", __func__);
- }
- core_unlock(core, __func__);
- }
- void msm_vidc_pm_work_handler(struct work_struct *work)
- {
- }
- void msm_vidc_fw_unload_handler(struct work_struct *work)
- {
- struct msm_vidc_core *core = NULL;
- int rc = 0;
- core = container_of(work, struct msm_vidc_core, fw_unload_work.work);
- if (!core) {
- d_vpr_e("%s: invalid work or core handle\n", __func__);
- return;
- }
- d_vpr_h("%s: deinitializing video core\n",__func__);
- rc = msm_vidc_core_deinit(core, false);
- if (rc)
- d_vpr_e("%s: Failed to deinit core\n", __func__);
- }
- void msm_vidc_batch_handler(struct work_struct *work)
- {
- struct msm_vidc_inst *inst;
- enum msm_vidc_allow allow;
- int rc = 0;
- inst = container_of(work, struct msm_vidc_inst, decode_batch.work.work);
- inst = get_inst_ref(g_core, inst);
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- inst_lock(inst, __func__);
- if (is_session_error(inst)) {
- i_vpr_e(inst, "%s: failled. Session error\n", __func__);
- goto exit;
- }
- allow = msm_vidc_allow_qbuf(inst, OUTPUT_MPLANE);
- if (allow != MSM_VIDC_ALLOW) {
- i_vpr_e(inst, "%s: not allowed in state: %s\n", __func__,
- state_name(inst->state));
- goto exit;
- }
- i_vpr_h(inst, "%s: queue pending batch buffers\n", __func__);
- rc = msm_vidc_queue_buffer_batch(inst);
- if (rc) {
- i_vpr_e(inst, "%s: batch qbufs failed\n", __func__);
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- }
- exit:
- inst_unlock(inst, __func__);
- put_inst(inst);
- }
- int msm_vidc_flush_buffers(struct msm_vidc_inst* inst,
- enum msm_vidc_buffer_type type)
- {
- int rc = 0;
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buf, *dummy;
- enum msm_vidc_buffer_type buffer_type[2];
- int i;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (type == MSM_VIDC_BUF_INPUT) {
- buffer_type[0] = MSM_VIDC_BUF_INPUT_META;
- buffer_type[1] = MSM_VIDC_BUF_INPUT;
- } else if (type == MSM_VIDC_BUF_OUTPUT) {
- buffer_type[0] = MSM_VIDC_BUF_OUTPUT_META;
- buffer_type[1] = MSM_VIDC_BUF_OUTPUT;
- } else {
- i_vpr_h(inst, "%s: invalid buffer type %d\n",
- __func__, type);
- return -EINVAL;
- }
- for (i = 0; i < ARRAY_SIZE(buffer_type); i++) {
- buffers = msm_vidc_get_buffers(inst, buffer_type[i], __func__);
- if (!buffers)
- return -EINVAL;
- list_for_each_entry_safe(buf, dummy, &buffers->list, list) {
- if (buf->attr & MSM_VIDC_ATTR_QUEUED ||
- buf->attr & MSM_VIDC_ATTR_DEFERRED) {
- print_vidc_buffer(VIDC_HIGH, "high", "flushing buffer", inst, buf);
- if (!(buf->attr & MSM_VIDC_ATTR_BUFFER_DONE))
- msm_vidc_vb2_buffer_done(inst, buf);
- msm_vidc_put_driver_buf(inst, buf);
- }
- }
- }
- return rc;
- }
- int msm_vidc_flush_delayed_unmap_buffers(struct msm_vidc_inst *inst,
- enum msm_vidc_buffer_type type)
- {
- int rc = 0;
- struct msm_vidc_mappings *maps;
- struct msm_vidc_map *map, *dummy;
- struct msm_vidc_buffer *ro_buf, *ro_dummy;
- enum msm_vidc_buffer_type buffer_type[2];
- int i;
- bool found = false;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (type == MSM_VIDC_BUF_INPUT) {
- buffer_type[0] = MSM_VIDC_BUF_INPUT_META;
- buffer_type[1] = MSM_VIDC_BUF_INPUT;
- } else if (type == MSM_VIDC_BUF_OUTPUT) {
- buffer_type[0] = MSM_VIDC_BUF_OUTPUT_META;
- buffer_type[1] = MSM_VIDC_BUF_OUTPUT;
- } else {
- i_vpr_h(inst, "%s: invalid buffer type %d\n",
- __func__, type);
- return -EINVAL;
- }
- for (i = 0; i < ARRAY_SIZE(buffer_type); i++) {
- maps = msm_vidc_get_mappings(inst, buffer_type[i], __func__);
- if (!maps)
- return -EINVAL;
- list_for_each_entry_safe(map, dummy, &maps->list, list) {
- /*
- * decoder output bufs will have skip_delayed_unmap = true
- * unmap all decoder output buffers except those present in
- * read_only buffers list
- */
- if (!map->skip_delayed_unmap)
- continue;
- found = false;
- list_for_each_entry_safe(ro_buf, ro_dummy,
- &inst->buffers.read_only.list, list) {
- if (map->dmabuf == ro_buf->dmabuf) {
- found = true;
- break;
- }
- }
- /* completely unmap */
- if (!found) {
- if (map->refcount > 1) {
- i_vpr_e(inst,
- "%s: unexpected map refcount: %u device addr %#x\n",
- __func__, map->refcount, map->device_addr);
- msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
- }
- msm_vidc_memory_unmap_completely(inst, map);
- }
- }
- }
- return rc;
- }
- void msm_vidc_destroy_buffers(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_buffers *buffers;
- struct msm_vidc_buffer *buf, *dummy;
- static const enum msm_vidc_buffer_type ext_buf_types[] = {
- MSM_VIDC_BUF_INPUT,
- MSM_VIDC_BUF_OUTPUT,
- MSM_VIDC_BUF_INPUT_META,
- MSM_VIDC_BUF_OUTPUT_META,
- };
- static const enum msm_vidc_buffer_type internal_buf_types[] = {
- MSM_VIDC_BUF_BIN,
- MSM_VIDC_BUF_ARP,
- MSM_VIDC_BUF_COMV,
- MSM_VIDC_BUF_NON_COMV,
- MSM_VIDC_BUF_LINE,
- MSM_VIDC_BUF_DPB,
- MSM_VIDC_BUF_PERSIST,
- MSM_VIDC_BUF_VPSS,
- };
- int i;
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- for (i = 0; i < ARRAY_SIZE(internal_buf_types); i++) {
- buffers = msm_vidc_get_buffers(inst, internal_buf_types[i], __func__);
- if (!buffers)
- continue;
- list_for_each_entry_safe(buf, dummy, &buffers->list, list) {
- i_vpr_h(inst,
- "destroying internal buffer: type %d idx %d fd %d addr %#x size %d\n",
- buf->type, buf->index, buf->fd, buf->device_addr, buf->buffer_size);
- msm_vidc_destroy_internal_buffer(inst, buf);
- }
- }
- for (i = 0; i < ARRAY_SIZE(ext_buf_types); i++) {
- buffers = msm_vidc_get_buffers(inst, ext_buf_types[i], __func__);
- if (!buffers)
- continue;
- list_for_each_entry_safe(buf, dummy, &buffers->list, list) {
- print_vidc_buffer(VIDC_ERR, "err ", "destroying ", inst, buf);
- if (!(buf->attr & MSM_VIDC_ATTR_BUFFER_DONE))
- msm_vidc_vb2_buffer_done(inst, buf);
- msm_vidc_put_driver_buf(inst, buf);
- }
- msm_vidc_unmap_buffers(inst, ext_buf_types[i]);
- }
- list_for_each_entry_safe(buf, dummy, &inst->buffers.read_only.list, list) {
- print_vidc_buffer(VIDC_ERR, "err ", "destroying ro buffer", inst, buf);
- list_del(&buf->list);
- msm_vidc_put_vidc_buffer(inst, buf);
- }
- list_for_each_entry_safe(buf, dummy, &inst->buffers.release.list, list) {
- print_vidc_buffer(VIDC_ERR, "err ", "destroying release buffer", inst, buf);
- list_del(&buf->list);
- msm_vidc_put_vidc_buffer(inst, buf);
- }
- /* destroy buffers from pool */
- msm_vidc_destroy_vidc_buffer(inst);
- msm_vidc_destroy_alloc_buffer(inst);
- msm_vidc_destroy_map_buffer(inst);
- }
- static void msm_vidc_close_helper(struct kref *kref)
- {
- struct msm_vidc_inst *inst = container_of(kref,
- struct msm_vidc_inst, kref);
- i_vpr_h(inst, "%s()\n", __func__);
- msm_vidc_event_queue_deinit(inst);
- msm_vidc_vb2_queue_deinit(inst);
- msm_vidc_debugfs_deinit_inst(inst);
- if (is_decode_session(inst))
- msm_vdec_inst_deinit(inst);
- else if (is_encode_session(inst))
- msm_venc_inst_deinit(inst);
- msm_vidc_free_input_cr_list(inst);
- kfree(inst->capabilities);
- if (inst->response_workq)
- destroy_workqueue(inst->response_workq);
- kfree(inst);
- }
- struct msm_vidc_inst *get_inst_ref(struct msm_vidc_core *core,
- struct msm_vidc_inst *instance)
- {
- struct msm_vidc_inst *inst = NULL;
- bool matches = false;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return NULL;
- }
- mutex_lock(&core->lock);
- list_for_each_entry(inst, &core->instances, list) {
- if (inst == instance) {
- matches = true;
- break;
- }
- }
- inst = (matches && kref_get_unless_zero(&inst->kref)) ? inst : NULL;
- mutex_unlock(&core->lock);
- return inst;
- }
- struct msm_vidc_inst *get_inst(struct msm_vidc_core *core,
- u32 session_id)
- {
- struct msm_vidc_inst *inst = NULL;
- bool matches = false;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return NULL;
- }
- mutex_lock(&core->lock);
- list_for_each_entry(inst, &core->instances, list) {
- if (inst->session_id == session_id) {
- matches = true;
- break;
- }
- }
- inst = (matches && kref_get_unless_zero(&inst->kref)) ? inst : NULL;
- mutex_unlock(&core->lock);
- return inst;
- }
- void put_inst(struct msm_vidc_inst *inst)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- kref_put(&inst->kref, msm_vidc_close_helper);
- }
- bool core_lock_check(struct msm_vidc_core *core, const char* func)
- {
- return mutex_is_locked(&core->lock);
- }
- void core_lock(struct msm_vidc_core *core, const char *function)
- {
- mutex_lock(&core->lock);
- }
- void core_unlock(struct msm_vidc_core *core, const char *function)
- {
- mutex_unlock(&core->lock);
- }
- bool inst_lock_check(struct msm_vidc_inst *inst, const char* func)
- {
- return mutex_is_locked(&inst->lock);
- }
- void inst_lock(struct msm_vidc_inst *inst, const char *function)
- {
- mutex_lock(&inst->lock);
- }
- void inst_unlock(struct msm_vidc_inst *inst, const char *function)
- {
- mutex_unlock(&inst->lock);
- }
- int msm_vidc_update_bitstream_buffer_size(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_core *core;
- struct v4l2_format *fmt;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- if (is_decode_session(inst)) {
- fmt = &inst->fmts[INPUT_PORT];
- fmt->fmt.pix_mp.plane_fmt[0].sizeimage = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_INPUT);
- }
- return 0;
- }
- int msm_vidc_update_meta_port_settings(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_core *core;
- struct v4l2_format *fmt;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- fmt = &inst->fmts[INPUT_META_PORT];
- if (is_input_meta_enabled(inst)) {
- fmt->fmt.meta.buffersize = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_INPUT_META);
- inst->buffers.input_meta.min_count =
- inst->buffers.input.min_count;
- inst->buffers.input_meta.extra_count =
- inst->buffers.input.extra_count;
- inst->buffers.input_meta.actual_count =
- inst->buffers.input.actual_count;
- inst->buffers.input_meta.size = fmt->fmt.meta.buffersize;
- } else {
- fmt->fmt.meta.buffersize = 0;
- inst->buffers.input_meta.min_count = 0;
- inst->buffers.input_meta.extra_count = 0;
- inst->buffers.input_meta.actual_count = 0;
- inst->buffers.input_meta.size = 0;
- }
- fmt = &inst->fmts[OUTPUT_META_PORT];
- if (is_output_meta_enabled(inst)) {
- fmt->fmt.meta.buffersize = call_session_op(core,
- buffer_size, inst, MSM_VIDC_BUF_OUTPUT_META);
- inst->buffers.output_meta.min_count =
- inst->buffers.output.min_count;
- inst->buffers.output_meta.extra_count =
- inst->buffers.output.extra_count;
- inst->buffers.output_meta.actual_count =
- inst->buffers.output.actual_count;
- inst->buffers.output_meta.size = fmt->fmt.meta.buffersize;
- } else {
- fmt->fmt.meta.buffersize = 0;
- inst->buffers.output_meta.min_count = 0;
- inst->buffers.output_meta.extra_count = 0;
- inst->buffers.output_meta.actual_count = 0;
- inst->buffers.output_meta.size = 0;
- }
- return 0;
- }
- int msm_vidc_update_buffer_count(struct msm_vidc_inst *inst, u32 port)
- {
- struct msm_vidc_core *core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- switch (port) {
- case INPUT_PORT:
- inst->buffers.input.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_INPUT);
- inst->buffers.input.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_INPUT);
- if (inst->buffers.input.actual_count <
- inst->buffers.input.min_count +
- inst->buffers.input.extra_count) {
- inst->buffers.input.actual_count =
- inst->buffers.input.min_count +
- inst->buffers.input.extra_count;
- }
- if (is_input_meta_enabled(inst)) {
- inst->buffers.input_meta.min_count =
- inst->buffers.input.min_count;
- inst->buffers.input_meta.extra_count =
- inst->buffers.input.extra_count;
- inst->buffers.input_meta.actual_count =
- inst->buffers.input.actual_count;
- } else {
- inst->buffers.input_meta.min_count = 0;
- inst->buffers.input_meta.extra_count = 0;
- inst->buffers.input_meta.actual_count = 0;
- }
- i_vpr_h(inst, "%s: type: INPUT, count: min %u, extra %u, actual %u\n", __func__,
- inst->buffers.input.min_count,
- inst->buffers.input.extra_count,
- inst->buffers.input.actual_count);
- break;
- case OUTPUT_PORT:
- if (!inst->vb2q[INPUT_PORT].streaming)
- inst->buffers.output.min_count = call_session_op(core,
- min_count, inst, MSM_VIDC_BUF_OUTPUT);
- inst->buffers.output.extra_count = call_session_op(core,
- extra_count, inst, MSM_VIDC_BUF_OUTPUT);
- if (inst->buffers.output.actual_count <
- inst->buffers.output.min_count +
- inst->buffers.output.extra_count) {
- inst->buffers.output.actual_count =
- inst->buffers.output.min_count +
- inst->buffers.output.extra_count;
- }
- if (is_output_meta_enabled(inst)) {
- inst->buffers.output_meta.min_count =
- inst->buffers.output.min_count;
- inst->buffers.output_meta.extra_count =
- inst->buffers.output.extra_count;
- inst->buffers.output_meta.actual_count =
- inst->buffers.output.actual_count;
- } else {
- inst->buffers.output_meta.min_count = 0;
- inst->buffers.output_meta.extra_count = 0;
- inst->buffers.output_meta.actual_count = 0;
- }
- i_vpr_h(inst, "%s: type: OUTPUT, count: min %u, extra %u, actual %u\n", __func__,
- inst->buffers.output.min_count,
- inst->buffers.output.extra_count,
- inst->buffers.output.actual_count);
- break;
- default:
- d_vpr_e("%s unknown port %d\n", __func__, port);
- return -EINVAL;
- }
- return 0;
- }
- void msm_vidc_schedule_core_deinit(struct msm_vidc_core *core)
- {
- if (!core)
- return;
- if (!core->capabilities[FW_UNLOAD].value)
- return;
- cancel_delayed_work(&core->fw_unload_work);
- schedule_delayed_work(&core->fw_unload_work,
- msecs_to_jiffies(core->capabilities[FW_UNLOAD_DELAY].value));
- d_vpr_h("firmware unload delayed by %u ms\n",
- core->capabilities[FW_UNLOAD_DELAY].value);
- return;
- }
- static const char *get_codec_str(enum msm_vidc_codec_type type)
- {
- switch (type) {
- case MSM_VIDC_H264: return "h264";
- case MSM_VIDC_HEVC: return "h265";
- case MSM_VIDC_VP9: return " vp9";
- case MSM_VIDC_HEIC: return "heic";
- }
- return "....";
- }
- static const char *get_domain_str(enum msm_vidc_domain_type type)
- {
- switch (type) {
- case MSM_VIDC_ENCODER: return "e";
- case MSM_VIDC_DECODER: return "d";
- }
- return ".";
- }
- int msm_vidc_update_debug_str(struct msm_vidc_inst *inst)
- {
- u32 sid;
- const char *codec;
- const char *domain;
- if (!inst) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- sid = inst->session_id;
- codec = get_codec_str(inst->codec);
- domain = get_domain_str(inst->domain);
- snprintf(inst->debug_str, sizeof(inst->debug_str), "%08x: %s%s", sid, codec, domain);
- d_vpr_h("%s: sid: %08x, codec: %s, domain: %s, final: %s\n",
- __func__, sid, codec, domain, inst->debug_str);
- return 0;
- }
- int msm_vidc_check_mbps_supported(struct msm_vidc_inst *inst)
- {
- u32 mbps = 0;
- struct msm_vidc_core *core;
- struct msm_vidc_inst *instance;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- list_for_each_entry(instance, &core->instances, list) {
- /* ignore invalid/error session */
- if (instance->state == MSM_VIDC_ERROR)
- continue;
- /* ignore thumbnail, image, and non realtime sessions */
- if (is_thumbnail_session(instance) ||
- is_image_session(instance) ||
- !is_realtime_session(instance))
- continue;
- mbps += msm_vidc_get_inst_load(instance);
- }
- core_unlock(core, __func__);
- if (mbps > core->capabilities[MAX_MBPS].value) {
- /* todo: print running instances */
- //msm_vidc_print_running_insts(inst->core);
- return -ENOMEM;
- }
- return 0;
- }
- static int msm_vidc_check_mbpf_supported(struct msm_vidc_inst *inst)
- {
- u32 mbpf = 0;
- struct msm_vidc_core *core;
- struct msm_vidc_inst *instance;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- list_for_each_entry(instance, &core->instances, list) {
- /* ignore invalid/error session */
- if (instance->state == MSM_VIDC_ERROR)
- continue;
- /* ignore thumbnail, image, and non realtime sessions */
- if (is_thumbnail_session(instance) ||
- is_image_session(instance) ||
- !is_realtime_session(instance))
- continue;
- mbpf += msm_vidc_get_mbs_per_frame(instance);
- }
- core_unlock(core, __func__);
- if (mbpf > core->capabilities[MAX_MBPF].value) {
- /* todo: print running instances */
- //msm_vidc_print_running_insts(inst->core);
- return -ENOMEM;
- }
- return 0;
- }
- int msm_vidc_check_session_supported(struct msm_vidc_inst *inst)
- {
- struct msm_vidc_inst_capability *capability;
- struct v4l2_format *fmt;
- u32 pix_fmt, profile;
- bool allow = false;
- int rc = 0;
- if (!inst || !inst->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- capability = inst->capabilities;
- /* todo: enable checks for all session type */
- if (!is_image_session(inst))
- return 0;
- pix_fmt = capability->cap[PIX_FMTS].value;
- profile = capability->cap[PROFILE].value;
- if (is_image_encode_session(inst)) {
- /* is linear color fmt */
- allow = is_linear_colorformat(pix_fmt);
- if (!allow) {
- i_vpr_e(inst, "%s: compressed fmt: %#x\n", __func__, pix_fmt);
- goto exit;
- }
- /* is input grid aligned */
- fmt = &inst->fmts[INPUT_PORT];
- allow = IS_ALIGNED(fmt->fmt.pix_mp.width, HEIC_GRID_DIMENSION);
- allow &= IS_ALIGNED(fmt->fmt.pix_mp.height, HEIC_GRID_DIMENSION);
- if (!allow) {
- i_vpr_e(inst, "%s: input is not grid aligned: %u x %u\n", __func__,
- fmt->fmt.pix_mp.width, fmt->fmt.pix_mp.height);
- goto exit;
- }
- /* is output grid dimension */
- fmt = &inst->fmts[OUTPUT_PORT];
- allow = fmt->fmt.pix_mp.width == HEIC_GRID_DIMENSION;
- allow &= fmt->fmt.pix_mp.height == HEIC_GRID_DIMENSION;
- if (!allow) {
- i_vpr_e(inst, "%s: output is not a grid dimension: %u x %u\n", __func__,
- fmt->fmt.pix_mp.width, fmt->fmt.pix_mp.height);
- goto exit;
- }
- /* is bitrate mode CQ */
- allow = capability->cap[BITRATE_MODE].value == HFI_RC_CQ;
- if (!allow) {
- i_vpr_e(inst, "%s: bitrate mode is not CQ: %#x\n", __func__,
- capability->cap[BITRATE_MODE].value);
- goto exit;
- }
- /* is all intra */
- allow = !capability->cap[GOP_SIZE].value;
- allow &= !capability->cap[B_FRAME].value;
- if (!allow) {
- i_vpr_e(inst, "%s: not all intra: gop: %u, bframe: %u\n", __func__,
- capability->cap[GOP_SIZE].value, capability->cap[B_FRAME].value);
- goto exit;
- }
- /* is time delta based rc disabled */
- allow = !capability->cap[TIME_DELTA_BASED_RC].value;
- if (!allow) {
- i_vpr_e(inst, "%s: time delta based rc not disabled: %#x\n", __func__,
- capability->cap[TIME_DELTA_BASED_RC].value);
- goto exit;
- }
- /* is profile type Still Pic */
- if (is_10bit_colorformat(pix_fmt))
- allow = profile == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10;
- else
- allow = profile == V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE;
- if (!allow) {
- i_vpr_e(inst, "%s: profile not valid: %#x\n", __func__,
- capability->cap[PROFILE].value);
- goto exit;
- }
- }
- rc = msm_vidc_check_mbps_supported(inst);
- if (rc)
- goto exit;
- rc = msm_vidc_check_mbpf_supported(inst);
- if (rc)
- goto exit;
- /* todo: add additional checks related to capabilities */
- return 0;
- exit:
- i_vpr_e(inst, "%s: current session not supported\n", __func__);
- return -EINVAL;
- }
- int msm_vidc_check_scaling_supported(struct msm_vidc_inst *inst)
- {
- if (!inst) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (is_image_session(inst) || is_decode_session(inst)) {
- i_vpr_h(inst, "%s: Scaling is supported for encode session only\n", __func__);
- return 0;
- }
- /* todo: add scaling check for encode session */
- return 0;
- }
|