123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
- */
- #include <linux/iommu.h>
- #include <linux/qcom_scm.h>
- #include <linux/soc/qcom/smem.h>
- #include <linux/irqreturn.h>
- #include <linux/reset.h>
- #include <linux/interconnect.h>
- #include <linux/of_address.h>
- #include <linux/firmware.h>
- #include <linux/qcom_scm.h>
- #include <linux/soc/qcom/mdt_loader.h>
- #include <linux/iopoll.h>
- #include "venus_hfi.h"
- #include "msm_vidc_core.h"
- #include "msm_vidc_power.h"
- #include "msm_vidc_platform.h"
- #include "msm_vidc_memory.h"
- #include "msm_vidc_driver.h"
- #include "msm_vidc_debug.h"
- #include "hfi_packet.h"
- #include "venus_hfi_response.h"
- #include "msm_vidc_events.h"
- #define MIN_PAYLOAD_SIZE 3
- #define MAX_FIRMWARE_NAME_SIZE 128
- #define update_offset(offset, val) ((offset) += (val))
- #define update_timestamp(ts, val) \
- do { \
- do_div((ts), NSEC_PER_USEC); \
- (ts) += (val); \
- (ts) *= NSEC_PER_USEC; \
- } while (0)
- extern struct msm_vidc_core *g_core;
- static int __resume(struct msm_vidc_core *core);
- static int __suspend(struct msm_vidc_core *core);
- struct tzbsp_memprot {
- u32 cp_start;
- u32 cp_size;
- u32 cp_nonpixel_start;
- u32 cp_nonpixel_size;
- };
- enum tzbsp_video_state {
- TZBSP_VIDEO_STATE_SUSPEND = 0,
- TZBSP_VIDEO_STATE_RESUME = 1,
- TZBSP_VIDEO_STATE_RESTORE_THRESHOLD = 2,
- };
- enum reset_state {
- INIT = 1,
- ASSERT,
- DEASSERT,
- };
- /* Less than 50MBps is treated as trivial BW change */
- #define TRIVIAL_BW_THRESHOLD 50000
- #define TRIVIAL_BW_CHANGE(a, b) \
- ((a) > (b) ? (a) - (b) < TRIVIAL_BW_THRESHOLD : \
- (b) - (a) < TRIVIAL_BW_THRESHOLD)
- /**
- * Utility function to enforce some of our assumptions. Spam calls to this
- * in hotspots in code to double check some of the assumptions that we hold.
- */
- struct lut const *__lut(int width, int height, int fps)
- {
- int frame_size = height * width, c = 0;
- do {
- if (LUT[c].frame_size >= frame_size && LUT[c].frame_rate >= fps)
- return &LUT[c];
- } while (++c < ARRAY_SIZE(LUT));
- return &LUT[ARRAY_SIZE(LUT) - 1];
- }
- fp_t __compression_ratio(struct lut const *entry, int bpp)
- {
- int c = 0;
- for (c = 0; c < COMPRESSION_RATIO_MAX; ++c) {
- if (entry->compression_ratio[c].bpp == bpp)
- return entry->compression_ratio[c].ratio;
- }
- WARN(true, "Shouldn't be here, LUT possibly corrupted?\n");
- return FP_ZERO; /* impossible */
- }
- void __dump(struct dump dump[], int len)
- {
- int c = 0;
- for (c = 0; c < len; ++c) {
- char format_line[128] = "", formatted_line[128] = "";
- if (dump[c].val == DUMP_HEADER_MAGIC) {
- snprintf(formatted_line, sizeof(formatted_line), "%s\n",
- dump[c].key);
- } else {
- bool fp_format = !strcmp(dump[c].format, DUMP_FP_FMT);
- if (!fp_format) {
- snprintf(format_line, sizeof(format_line),
- " %-35s: %s\n", dump[c].key,
- dump[c].format);
- snprintf(formatted_line, sizeof(formatted_line),
- format_line, dump[c].val);
- } else {
- size_t integer_part, fractional_part;
- integer_part = fp_int(dump[c].val);
- fractional_part = fp_frac(dump[c].val);
- snprintf(formatted_line, sizeof(formatted_line),
- " %-35s: %zd + %zd/%zd\n",
- dump[c].key, integer_part,
- fractional_part,
- fp_frac_base());
- }
- }
- d_vpr_b("%s", formatted_line);
- }
- }
- static void __dump_packet(u8 *packet, const char *function, void *qinfo)
- {
- u32 c = 0, session_id, packet_size = *(u32 *)packet;
- const int row_size = 32;
- struct msm_vidc_inst *inst = NULL;
- bool matches = false;
- /*
- * row must contain enough for 0xdeadbaad * 8 to be converted into
- * "de ad ba ab " * 8 + '\0'
- */
- char row[3 * 32];
- session_id = *((u32 *)packet + 1);
- list_for_each_entry(inst, &g_core->instances, list) {
- if (inst->session_id == session_id) {
- matches = true;
- break;
- }
- }
- if (matches)
- i_vpr_t(inst, "%s: %pK\n", function, qinfo);
- else
- d_vpr_t("%s: %pK\n", function, qinfo);
- for (c = 0; c * row_size < packet_size; ++c) {
- int bytes_to_read = ((c + 1) * row_size > packet_size) ?
- packet_size % row_size : row_size;
- hex_dump_to_buffer(packet + c * row_size, bytes_to_read,
- row_size, 4, row, sizeof(row), false);
- if (matches)
- i_vpr_t(inst, "%s\n", row);
- else
- d_vpr_t("%s\n", row);
- }
- }
- static void __fatal_error(bool fatal)
- {
- WARN_ON(fatal);
- }
- static int __strict_check(struct msm_vidc_core *core, const char *function)
- {
- bool fatal = !mutex_is_locked(&core->lock);
- __fatal_error(fatal);
- if (fatal)
- d_vpr_e("%s: strict check failed\n", function);
- return fatal ? -EINVAL : 0;
- }
- bool __core_in_valid_state(struct msm_vidc_core *core)
- {
- return core->state != MSM_VIDC_CORE_DEINIT;
- }
- bool is_sys_cache_present(struct msm_vidc_core *core)
- {
- return core->dt->sys_cache_present;
- }
- static bool __valdiate_session(struct msm_vidc_core *core,
- struct msm_vidc_inst *inst, const char *func)
- {
- bool valid = false;
- struct msm_vidc_inst *temp;
- int rc = 0;
- if (!core || !inst)
- return false;
- rc = __strict_check(core, __func__);
- if (rc)
- return false;
- list_for_each_entry(temp, &core->instances, list) {
- if (temp == inst) {
- valid = true;
- break;
- }
- }
- if (!valid)
- i_vpr_e(inst, "%s: invalid session\n", func);
- return valid;
- }
- int __write_register(struct msm_vidc_core *core,
- u32 reg, u32 value)
- {
- u32 hwiosymaddr = reg;
- u8 *base_addr;
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- if (!core->power_enabled) {
- d_vpr_e("HFI Write register failed : Power is OFF\n");
- return -EINVAL;
- }
- base_addr = core->register_base_addr;
- d_vpr_l("regwrite(%pK + %#x) = %#x\n", base_addr, hwiosymaddr, value);
- base_addr += hwiosymaddr;
- writel_relaxed(value, base_addr);
- /*
- * Memory barrier to make sure value is written into the register.
- */
- wmb();
- return rc;
- }
- /*
- * Argument mask is used to specify which bits to update. In case mask is 0x11,
- * only bits 0 & 4 will be updated with corresponding bits from value. To update
- * entire register with value, set mask = 0xFFFFFFFF.
- */
- int __write_register_masked(struct msm_vidc_core *core,
- u32 reg, u32 value, u32 mask)
- {
- u32 prev_val, new_val;
- u8 *base_addr;
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- if (!core->power_enabled) {
- d_vpr_e("%s: register write failed, power is off\n",
- __func__);
- return -EINVAL;
- }
- base_addr = core->register_base_addr;
- base_addr += reg;
- prev_val = readl_relaxed(base_addr);
- /*
- * Memory barrier to ensure register read is correct
- */
- rmb();
- new_val = (prev_val & ~mask) | (value & mask);
- d_vpr_l(
- "Base addr: %pK, writing to: %#x, previous-value: %#x, value: %#x, mask: %#x, new-value: %#x...\n",
- base_addr, reg, prev_val, value, mask, new_val);
- writel_relaxed(new_val, base_addr);
- /*
- * Memory barrier to make sure value is written into the register.
- */
- wmb();
- return rc;
- }
- int __read_register(struct msm_vidc_core *core, u32 reg, u32 *value)
- {
- int rc = 0;
- u8 *base_addr;
- if (!core || !value) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!core->power_enabled) {
- d_vpr_e("HFI Read register failed : Power is OFF\n");
- return -EINVAL;
- }
- base_addr = core->register_base_addr;
- *value = readl_relaxed(base_addr + reg);
- /*
- * Memory barrier to make sure value is read correctly from the
- * register.
- */
- rmb();
- d_vpr_l("regread(%pK + %#x) = %#x\n", base_addr, reg, *value);
- return rc;
- }
- int __read_register_with_poll_timeout(struct msm_vidc_core *core,
- u32 reg, u32 mask, u32 exp_val, u32 sleep_us, u32 timeout_us)
- {
- int rc = 0;
- u32 val = 0;
- u8 *addr;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!core->power_enabled) {
- d_vpr_e("%s failed: Power is OFF\n", __func__);
- return -EINVAL;
- }
- addr = (u8 *)core->register_base_addr + reg;
- rc = readl_relaxed_poll_timeout(addr, val, ((val & mask) == exp_val), sleep_us, timeout_us);
- /*
- * Memory barrier to make sure value is read correctly from the
- * register.
- */
- rmb();
- d_vpr_l(
- "regread(%pK + %#x) = %#x. rc %d, mask %#x, exp_val %#x, cond %u, sleep %u, timeout %u\n",
- core->register_base_addr, reg, val, rc, mask, exp_val,
- ((val & mask) == exp_val), sleep_us, timeout_us);
- return rc;
- }
- static void __schedule_power_collapse_work(struct msm_vidc_core *core)
- {
- if (!core || !core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- if (!core->capabilities[SW_PC].value) {
- d_vpr_l("software power collapse not enabled\n");
- return;
- }
- if (!mod_delayed_work(core->pm_workq, &core->pm_work,
- msecs_to_jiffies(core->capabilities[SW_PC_DELAY].value))) {
- d_vpr_h("power collapse already scheduled\n");
- } else {
- d_vpr_l("power collapse scheduled for %d ms\n",
- core->capabilities[SW_PC_DELAY].value);
- }
- }
- static void __cancel_power_collapse_work(struct msm_vidc_core *core)
- {
- if (!core || !core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- if (!core->capabilities[SW_PC].value)
- return;
- cancel_delayed_work(&core->pm_work);
- }
- int __acquire_regulator(struct msm_vidc_core *core,
- struct regulator_info *rinfo)
- {
- int rc = 0;
- if (!core || !rinfo) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (rinfo->has_hw_power_collapse) {
- if (!rinfo->regulator) {
- d_vpr_e("%s: invalid regulator\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- if (regulator_get_mode(rinfo->regulator) ==
- REGULATOR_MODE_NORMAL) {
- core->handoff_done = false;
- d_vpr_h("Skip acquire regulator %s\n", rinfo->name);
- goto exit;
- }
- rc = regulator_set_mode(rinfo->regulator,
- REGULATOR_MODE_NORMAL);
- if (rc) {
- /*
- * This is somewhat fatal, but nothing we can do
- * about it. We can't disable the regulator w/o
- * getting it back under s/w control
- */
- d_vpr_e("Failed to acquire regulator control: %s\n",
- rinfo->name);
- goto exit;
- } else {
- core->handoff_done = false;
- d_vpr_h("Acquired regulator control from HW: %s\n",
- rinfo->name);
- }
- if (!regulator_is_enabled(rinfo->regulator)) {
- d_vpr_e("%s: Regulator is not enabled %s\n",
- __func__, rinfo->name);
- __fatal_error(true);
- }
- }
- exit:
- return rc;
- }
- static int __acquire_regulators(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct regulator_info *rinfo;
- venus_hfi_for_each_regulator(core, rinfo)
- __acquire_regulator(core, rinfo);
- return rc;
- }
- static int __hand_off_regulator(struct msm_vidc_core *core,
- struct regulator_info *rinfo)
- {
- int rc = 0;
- if (rinfo->has_hw_power_collapse) {
- if (!rinfo->regulator) {
- d_vpr_e("%s: invalid regulator\n", __func__);
- return -EINVAL;
- }
- rc = regulator_set_mode(rinfo->regulator,
- REGULATOR_MODE_FAST);
- if (rc) {
- d_vpr_e("Failed to hand off regulator control: %s\n",
- rinfo->name);
- return rc;
- } else {
- core->handoff_done = true;
- d_vpr_h("Hand off regulator control to HW: %s\n",
- rinfo->name);
- }
- if (!regulator_is_enabled(rinfo->regulator)) {
- d_vpr_e("%s: Regulator is not enabled %s\n",
- __func__, rinfo->name);
- __fatal_error(true);
- }
- }
- return rc;
- }
- static int __hand_off_regulators(struct msm_vidc_core *core)
- {
- struct regulator_info *rinfo;
- int rc = 0, c = 0;
- venus_hfi_for_each_regulator(core, rinfo) {
- rc = __hand_off_regulator(core, rinfo);
- /*
- * If one regulator hand off failed, driver should take
- * the control for other regulators back.
- */
- if (rc)
- goto err_reg_handoff_failed;
- c++;
- }
- return rc;
- err_reg_handoff_failed:
- venus_hfi_for_each_regulator_reverse_continue(core, rinfo, c)
- __acquire_regulator(core, rinfo);
- return rc;
- }
- int __set_registers(struct msm_vidc_core *core)
- {
- struct reg_set *reg_set;
- int i, rc = 0;
- if (!core || !core->dt) {
- d_vpr_e("core resources null, cannot set registers\n");
- return -EINVAL;
- }
- reg_set = &core->dt->reg_set;
- for (i = 0; i < reg_set->count; i++) {
- rc = __write_register_masked(core, reg_set->reg_tbl[i].reg,
- reg_set->reg_tbl[i].value,
- reg_set->reg_tbl[i].mask);
- if (rc)
- return rc;
- }
- return rc;
- }
- static int __vote_bandwidth(struct bus_info *bus,
- unsigned long bw_kbps)
- {
- int rc = 0;
- if (!bus->path) {
- d_vpr_e("%s: invalid bus\n", __func__);
- return -EINVAL;
- }
- d_vpr_p("Voting bus %s to ab %llu kBps\n", bus->name, bw_kbps);
- rc = icc_set_bw(bus->path, bw_kbps, 0);
- if (rc)
- d_vpr_e("Failed voting bus %s to ab %llu, rc=%d\n",
- bus->name, bw_kbps, rc);
- return rc;
- }
- int __unvote_buses(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct bus_info *bus = NULL;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core->power.bw_ddr = 0;
- core->power.bw_llcc = 0;
- venus_hfi_for_each_bus(core, bus) {
- rc = __vote_bandwidth(bus, 0);
- if (rc)
- goto err_unknown_device;
- }
- err_unknown_device:
- return rc;
- }
- int __vote_buses(struct msm_vidc_core *core,
- unsigned long bw_ddr, unsigned long bw_llcc)
- {
- int rc = 0;
- struct bus_info *bus = NULL;
- unsigned long bw_kbps = 0, bw_prev = 0;
- enum vidc_bus_type type;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- venus_hfi_for_each_bus(core, bus) {
- if (bus && bus->path) {
- type = get_type_frm_name(bus->name);
- if (type == DDR) {
- bw_kbps = bw_ddr;
- bw_prev = core->power.bw_ddr;
- } else if (type == LLCC) {
- bw_kbps = bw_llcc;
- bw_prev = core->power.bw_llcc;
- } else {
- bw_kbps = bus->range[1];
- bw_prev = core->power.bw_ddr ?
- bw_kbps : 0;
- }
- /* ensure freq is within limits */
- bw_kbps = clamp_t(typeof(bw_kbps), bw_kbps,
- bus->range[0], bus->range[1]);
- if (TRIVIAL_BW_CHANGE(bw_kbps, bw_prev) && bw_prev) {
- d_vpr_l("Skip voting bus %s to %llu kBps\n",
- bus->name, bw_kbps);
- continue;
- }
- rc = __vote_bandwidth(bus, bw_kbps);
- if (type == DDR)
- core->power.bw_ddr = bw_kbps;
- else if (type == LLCC)
- core->power.bw_llcc = bw_kbps;
- } else {
- d_vpr_e("No BUS to Vote\n");
- }
- }
- return rc;
- }
- static int __tzbsp_set_video_state(enum tzbsp_video_state state)
- {
- int tzbsp_rsp = qcom_scm_set_remote_state(state, 0);
- d_vpr_l("Set state %d, resp %d\n", state, tzbsp_rsp);
- if (tzbsp_rsp) {
- d_vpr_e("Failed to set video core state to suspend: %d\n",
- tzbsp_rsp);
- return -EINVAL;
- }
- return 0;
- }
- int __set_clk_rate(struct msm_vidc_core *core,
- struct clock_info *cl, u64 rate)
- {
- int rc = 0;
- struct mmrm_client_data client_data;
- struct mmrm_client *client;
- /* not registered */
- if (!core || !cl || !core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (core->capabilities[MMRM].value && !cl->mmrm_client) {
- d_vpr_e("%s: invalid mmrm client\n", __func__);
- return -EINVAL;
- }
- /*
- * This conversion is necessary since we are scaling clock values based on
- * the branch clock. However, mmrm driver expects source clock to be registered
- * and used for scaling.
- * TODO: Remove this scaling if using source clock instead of branch clock.
- */
- rate = rate * MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
- /* bail early if requested clk rate is not changed */
- if (rate == cl->prev)
- return 0;
- d_vpr_p("Scaling clock %s to %llu, prev %llu\n", cl->name, rate, cl->prev);
- if (core->capabilities[MMRM].value) {
- /* set clock rate to mmrm driver */
- client = cl->mmrm_client;
- memset(&client_data, 0, sizeof(client_data));
- client_data.num_hw_blocks = 1;
- rc = mmrm_client_set_value(client, &client_data, rate);
- if (rc) {
- d_vpr_e("%s: Failed to set mmrm clock rate %llu %s: %d\n",
- __func__, rate, cl->name, rc);
- return rc;
- }
- } else {
- /* set clock rate to clock driver */
- rc = clk_set_rate(cl->clk, rate);
- if (rc) {
- d_vpr_e("%s: Failed to set clock rate %llu %s: %d\n",
- __func__, rate, cl->name, rc);
- return rc;
- }
- }
- cl->prev = rate;
- return rc;
- }
- int __set_clocks(struct msm_vidc_core *core, u32 freq)
- {
- int rc = 0;
- struct clock_info *cl;
- venus_hfi_for_each_clock(core, cl) {
- if (cl->has_scaling) {/* has_scaling */
- rc = __set_clk_rate(core, cl, freq);
- if (rc)
- return rc;
- }
- }
- return 0;
- }
- int __scale_clocks(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct allowed_clock_rates_table *allowed_clks_tbl;
- u32 freq = 0;
- if (!core || !core->dt) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- allowed_clks_tbl = core->dt->allowed_clks_tbl;
- freq = core->power.clk_freq ? core->power.clk_freq :
- allowed_clks_tbl[0].clock_rate;
- rc = __set_clocks(core, freq);
- if (rc)
- return rc;
- core->power.clk_freq = freq;
- return 0;
- }
- static int __write_queue(struct msm_vidc_iface_q_info *qinfo, u8 *packet,
- bool *rx_req_is_set)
- {
- struct hfi_queue_header *queue;
- u32 packet_size_in_words, new_write_idx;
- u32 empty_space, read_idx, write_idx;
- u32 *write_ptr;
- if (!qinfo || !packet) {
- d_vpr_e("%s: invalid params %pK %pK\n",
- __func__, qinfo, packet);
- return -EINVAL;
- } else if (!qinfo->q_array.align_virtual_addr) {
- d_vpr_e("Queues have already been freed\n");
- return -EINVAL;
- }
- queue = (struct hfi_queue_header *) qinfo->q_hdr;
- if (!queue) {
- d_vpr_e("queue not present\n");
- return -ENOENT;
- }
- if (msm_vidc_debug & VIDC_PKT)
- __dump_packet(packet, __func__, qinfo);
- // TODO: handle writing packet
- //d_vpr_e("skip writing packet\n");
- //return 0;
- packet_size_in_words = (*(u32 *)packet) >> 2;
- if (!packet_size_in_words || packet_size_in_words >
- qinfo->q_array.mem_size>>2) {
- d_vpr_e("Invalid packet size\n");
- return -ENODATA;
- }
- read_idx = queue->qhdr_read_idx;
- write_idx = queue->qhdr_write_idx;
- empty_space = (write_idx >= read_idx) ?
- ((qinfo->q_array.mem_size>>2) - (write_idx - read_idx)) :
- (read_idx - write_idx);
- if (empty_space <= packet_size_in_words) {
- queue->qhdr_tx_req = 1;
- d_vpr_e("Insufficient size (%d) to write (%d)\n",
- empty_space, packet_size_in_words);
- return -ENOTEMPTY;
- }
- queue->qhdr_tx_req = 0;
- new_write_idx = write_idx + packet_size_in_words;
- write_ptr = (u32 *)((qinfo->q_array.align_virtual_addr) +
- (write_idx << 2));
- if (write_ptr < (u32 *)qinfo->q_array.align_virtual_addr ||
- write_ptr > (u32 *)(qinfo->q_array.align_virtual_addr +
- qinfo->q_array.mem_size)) {
- d_vpr_e("Invalid write index\n");
- return -ENODATA;
- }
- if (new_write_idx < (qinfo->q_array.mem_size >> 2)) {
- memcpy(write_ptr, packet, packet_size_in_words << 2);
- } else {
- new_write_idx -= qinfo->q_array.mem_size >> 2;
- memcpy(write_ptr, packet, (packet_size_in_words -
- new_write_idx) << 2);
- memcpy((void *)qinfo->q_array.align_virtual_addr,
- packet + ((packet_size_in_words - new_write_idx) << 2),
- new_write_idx << 2);
- }
- /*
- * Memory barrier to make sure packet is written before updating the
- * write index
- */
- mb();
- queue->qhdr_write_idx = new_write_idx;
- if (rx_req_is_set)
- *rx_req_is_set = true;
- /*
- * Memory barrier to make sure write index is updated before an
- * interrupt is raised on venus.
- */
- mb();
- return 0;
- }
- static int __read_queue(struct msm_vidc_iface_q_info *qinfo, u8 *packet,
- u32 *pb_tx_req_is_set)
- {
- struct hfi_queue_header *queue;
- u32 packet_size_in_words, new_read_idx;
- u32 *read_ptr;
- u32 receive_request = 0;
- u32 read_idx, write_idx;
- int rc = 0;
- if (!qinfo || !packet || !pb_tx_req_is_set) {
- d_vpr_e("%s: invalid params %pK %pK %pK\n",
- __func__, qinfo, packet, pb_tx_req_is_set);
- return -EINVAL;
- } else if (!qinfo->q_array.align_virtual_addr) {
- d_vpr_e("Queues have already been freed\n");
- return -EINVAL;
- }
- /*
- * Memory barrier to make sure data is valid before
- *reading it
- */
- mb();
- queue = (struct hfi_queue_header *) qinfo->q_hdr;
- if (!queue) {
- d_vpr_e("Queue memory is not allocated\n");
- return -ENOMEM;
- }
- /*
- * Do not set receive request for debug queue, if set,
- * Venus generates interrupt for debug messages even
- * when there is no response message available.
- * In general debug queue will not become full as it
- * is being emptied out for every interrupt from Venus.
- * Venus will anyway generates interrupt if it is full.
- */
- if (queue->qhdr_type & HFI_Q_ID_CTRL_TO_HOST_MSG_Q)
- receive_request = 1;
- read_idx = queue->qhdr_read_idx;
- write_idx = queue->qhdr_write_idx;
- if (read_idx == write_idx) {
- queue->qhdr_rx_req = receive_request;
- /*
- * mb() to ensure qhdr is updated in main memory
- * so that venus reads the updated header values
- */
- mb();
- *pb_tx_req_is_set = 0;
- d_vpr_l(
- "%s queue is empty, rx_req = %u, tx_req = %u, read_idx = %u\n",
- receive_request ? "message" : "debug",
- queue->qhdr_rx_req, queue->qhdr_tx_req,
- queue->qhdr_read_idx);
- return -ENODATA;
- }
- read_ptr = (u32 *)((qinfo->q_array.align_virtual_addr) +
- (read_idx << 2));
- if (read_ptr < (u32 *)qinfo->q_array.align_virtual_addr ||
- read_ptr > (u32 *)(qinfo->q_array.align_virtual_addr +
- qinfo->q_array.mem_size - sizeof(*read_ptr))) {
- d_vpr_e("Invalid read index\n");
- return -ENODATA;
- }
- packet_size_in_words = (*read_ptr) >> 2;
- if (!packet_size_in_words) {
- d_vpr_e("Zero packet size\n");
- return -ENODATA;
- }
- new_read_idx = read_idx + packet_size_in_words;
- if (((packet_size_in_words << 2) <= VIDC_IFACEQ_VAR_HUGE_PKT_SIZE) &&
- read_idx <= (qinfo->q_array.mem_size >> 2)) {
- if (new_read_idx < (qinfo->q_array.mem_size >> 2)) {
- memcpy(packet, read_ptr,
- packet_size_in_words << 2);
- } else {
- new_read_idx -= (qinfo->q_array.mem_size >> 2);
- memcpy(packet, read_ptr,
- (packet_size_in_words - new_read_idx) << 2);
- memcpy(packet + ((packet_size_in_words -
- new_read_idx) << 2),
- (u8 *)qinfo->q_array.align_virtual_addr,
- new_read_idx << 2);
- }
- } else {
- d_vpr_e("BAD packet received, read_idx: %#x, pkt_size: %d\n",
- read_idx, packet_size_in_words << 2);
- d_vpr_e("Dropping this packet\n");
- new_read_idx = write_idx;
- rc = -ENODATA;
- }
- queue->qhdr_rx_req = receive_request;
- queue->qhdr_read_idx = new_read_idx;
- /*
- * mb() to ensure qhdr is updated in main memory
- * so that venus reads the updated header values
- */
- mb();
- *pb_tx_req_is_set = (queue->qhdr_tx_req == 1) ? 1 : 0;
- if ((msm_vidc_debug & VIDC_PKT) &&
- !(queue->qhdr_type & HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q)) {
- __dump_packet(packet, __func__, qinfo);
- }
- return rc;
- }
- /* Writes into cmdq without raising an interrupt */
- static int __iface_cmdq_write_relaxed(struct msm_vidc_core *core,
- void *pkt, bool *requires_interrupt)
- {
- struct msm_vidc_iface_q_info *q_info;
- //struct vidc_hal_cmd_pkt_hdr *cmd_packet;
- int rc = -E2BIG;
- if (!core || !pkt) {
- d_vpr_e("%s: invalid params %pK %pK\n",
- __func__, core, pkt);
- return -EINVAL;
- }
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- if (!__core_in_valid_state(core)) {
- d_vpr_e("%s: fw not in init state\n", __func__);
- rc = -EINVAL;
- goto err_q_null;
- }
- //cmd_packet = (struct vidc_hal_cmd_pkt_hdr *)pkt;
- //core->last_packet_type = cmd_packet->packet_type;
- q_info = &core->iface_queues[VIDC_IFACEQ_CMDQ_IDX];
- if (!q_info) {
- d_vpr_e("cannot write to shared Q's\n");
- goto err_q_null;
- }
- if (!q_info->q_array.align_virtual_addr) {
- d_vpr_e("cannot write to shared CMD Q's\n");
- rc = -ENODATA;
- goto err_q_null;
- }
- rc = __resume(core);
- if (rc) {
- d_vpr_e("%s: Power on failed\n", __func__);
- goto err_q_write;
- }
- if (!__write_queue(q_info, (u8 *)pkt, requires_interrupt)) {
- __schedule_power_collapse_work(core);
- rc = 0;
- } else {
- d_vpr_e("__iface_cmdq_write: queue full\n");
- }
- err_q_write:
- err_q_null:
- return rc;
- }
- int __iface_cmdq_write(struct msm_vidc_core *core,
- void *pkt)
- {
- bool needs_interrupt = false;
- int rc = __iface_cmdq_write_relaxed(core, pkt, &needs_interrupt);
- if (!rc && needs_interrupt)
- call_venus_op(core, raise_interrupt, core);
- return rc;
- }
- static int __iface_cmdq_write_intr(struct msm_vidc_core *core,
- void *pkt, bool allow)
- {
- bool needs_interrupt = false;
- int rc = __iface_cmdq_write_relaxed(core, pkt, &needs_interrupt);
- if (!rc && allow && needs_interrupt)
- call_venus_op(core, raise_interrupt, core);
- return rc;
- }
- int __iface_msgq_read(struct msm_vidc_core *core, void *pkt)
- {
- u32 tx_req_is_set = 0;
- int rc = 0;
- struct msm_vidc_iface_q_info *q_info;
- if (!pkt) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!__core_in_valid_state(core)) {
- d_vpr_e("%s: fw not in init state\n", __func__);
- rc = -EINVAL;
- goto read_error_null;
- }
- q_info = &core->iface_queues[VIDC_IFACEQ_MSGQ_IDX];
- if (!q_info->q_array.align_virtual_addr) {
- d_vpr_e("cannot read from shared MSG Q's\n");
- rc = -ENODATA;
- goto read_error_null;
- }
- if (!__read_queue(q_info, (u8 *)pkt, &tx_req_is_set)) {
- if (tx_req_is_set) {
- //call_venus_op(core, raise_interrupt, core);
- d_vpr_e("%s: queue is full\n", __func__);
- rc = -EINVAL;
- goto read_error_null;
- }
- rc = 0;
- } else {
- rc = -ENODATA;
- }
- read_error_null:
- return rc;
- }
- int __iface_dbgq_read(struct msm_vidc_core *core, void *pkt)
- {
- u32 tx_req_is_set = 0;
- int rc = 0;
- struct msm_vidc_iface_q_info *q_info;
- if (!pkt) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- q_info = &core->iface_queues[VIDC_IFACEQ_DBGQ_IDX];
- if (!q_info->q_array.align_virtual_addr) {
- d_vpr_e("cannot read from shared DBG Q's\n");
- rc = -ENODATA;
- goto dbg_error_null;
- }
- if (!__read_queue(q_info, (u8 *)pkt, &tx_req_is_set)) {
- if (tx_req_is_set) {
- d_vpr_e("%s: queue is full\n", __func__);
- //call_venus_op(core, raise_interrupt, core);
- rc = -EINVAL;
- goto dbg_error_null;
- }
- rc = 0;
- } else {
- rc = -ENODATA;
- }
- dbg_error_null:
- return rc;
- }
- static void __flush_debug_queue(struct msm_vidc_core *core,
- u8 *packet, u32 packet_size)
- {
- u8 *log;
- struct hfi_debug_header *pkt;
- bool local_packet = false;
- enum vidc_msg_prio log_level = msm_vidc_debug;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- if (!packet || !packet_size) {
- packet = kzalloc(VIDC_IFACEQ_VAR_HUGE_PKT_SIZE, GFP_KERNEL);
- if (!packet) {
- d_vpr_e("%s: fail to allocate\n", __func__);
- return;
- }
- packet_size = VIDC_IFACEQ_VAR_HUGE_PKT_SIZE;
- local_packet = true;
- /*
- * Local packet is used when error occurred.
- * It is good to print these logs to printk as well.
- */
- log_level |= FW_PRINTK;
- }
- while (!__iface_dbgq_read(core, packet)) {
- pkt = (struct hfi_debug_header *) packet;
- if (pkt->size < sizeof(struct hfi_debug_header)) {
- d_vpr_e("%s: invalid pkt size %d\n",
- __func__, pkt->size);
- continue;
- }
- if (pkt->size >= packet_size) {
- d_vpr_e("%s: pkt size[%d] >= packet_size[%d]\n",
- __func__, pkt->size, packet_size);
- continue;
- }
- packet[pkt->size] = '\0';
- /*
- * All fw messages starts with new line character. This
- * causes dprintk to print this message in two lines
- * in the kernel log. Ignoring the first character
- * from the message fixes this to print it in a single
- * line.
- */
- log = (u8 *)packet + sizeof(struct hfi_debug_header) + 1;
- dprintk_firmware(log_level, "%s", log);
- }
- if (local_packet)
- kfree(packet);
- }
- static int __sys_set_debug(struct msm_vidc_core *core, u32 debug)
- {
- int rc = 0;
- rc = hfi_packet_sys_debug_config(core, core->packet,
- core->packet_size, debug);
- if (rc)
- goto exit;
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- goto exit;
- exit:
- if (rc)
- d_vpr_e("Debug mode setting to FW failed\n");
- return rc;
- }
- /*
- static int __sys_set_coverage(struct msm_vidc_core *core,
- u32 mode)
- {
- int rc = 0;
- //rc = call_hfi_pkt_op(core, sys_coverage_config, pkt, mode);
- if (rc) {
- d_vpr_e("Coverage mode setting to FW failed\n");
- return -ENOTEMPTY;
- }
- //if (__iface_cmdq_write(core, pkt, sid)) {
- // d_vpr_e("Failed to send coverage pkt to f/w\n");
- // return -ENOTEMPTY;
- //}
- return 0;
- }
- */
- static int __sys_set_power_control(struct msm_vidc_core *core, bool enable)
- {
- int rc = 0;
- if (!core->handoff_done) {
- d_vpr_e("%s: skipping as power control hanfoff was not done\n",
- __func__);
- return rc;
- }
- rc = hfi_packet_sys_intraframe_powercollapse(core,
- core->packet, core->packet_size, enable);
- if (rc)
- return rc;
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- return rc;
- core->hw_power_control = true;
- d_vpr_h("%s: set hardware power control successful\n", __func__);
- return rc;
- }
- int __prepare_pc(struct msm_vidc_core *core)
- {
- int rc = 0;
- rc = hfi_packet_sys_pc_prep(core, core->packet, core->packet_size);
- if (rc) {
- d_vpr_e("Failed to create sys pc prep pkt\n");
- goto err_pc_prep;
- }
- if (__iface_cmdq_write(core, core->packet))
- rc = -ENOTEMPTY;
- if (rc)
- d_vpr_e("Failed to prepare venus for power off");
- err_pc_prep:
- return rc;
- }
- static int __power_collapse(struct msm_vidc_core *core, bool force)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!core->power_enabled) {
- d_vpr_h("%s: Power already disabled\n", __func__);
- goto exit;
- }
- if (!__core_in_valid_state(core)) {
- d_vpr_e("%s: Core not in init state\n", __func__);
- return -EINVAL;
- }
- __flush_debug_queue(core, (!force ? core->packet : NULL), core->packet_size);
- rc = call_venus_op(core, prepare_pc, core);
- if (rc)
- goto skip_power_off;
- rc = __suspend(core);
- if (rc)
- d_vpr_e("Failed __suspend\n");
- exit:
- return rc;
- skip_power_off:
- d_vpr_e("%s: skipped\n", __func__);
- return -EAGAIN;
- }
- static int __protect_cp_mem(struct msm_vidc_core *core)
- {
- struct tzbsp_memprot memprot;
- int rc = 0;
- struct context_bank_info *cb;
- if (!core)
- return -EINVAL;
- memprot.cp_start = 0x0;
- memprot.cp_size = 0x0;
- memprot.cp_nonpixel_start = 0x0;
- memprot.cp_nonpixel_size = 0x0;
- list_for_each_entry(cb, &core->dt->context_banks, list) {
- if (!strcmp(cb->name, "venus_ns")) {
- memprot.cp_size = cb->addr_range.start;
- d_vpr_h("%s: memprot.cp_size: %#x\n",
- __func__, memprot.cp_size);
- }
- if (!strcmp(cb->name, "venus_sec_non_pixel")) {
- memprot.cp_nonpixel_start = cb->addr_range.start;
- memprot.cp_nonpixel_size = cb->addr_range.size;
- d_vpr_h("%s: cp_nonpixel_start: %#x size: %#x\n",
- __func__, memprot.cp_nonpixel_start,
- memprot.cp_nonpixel_size);
- }
- }
- rc = qcom_scm_mem_protect_video_var(memprot.cp_start, memprot.cp_size,
- memprot.cp_nonpixel_start, memprot.cp_nonpixel_size);
- if (rc)
- d_vpr_e("Failed to protect memory(%d)\n", rc);
- trace_venus_hfi_var_done(
- memprot.cp_start, memprot.cp_size,
- memprot.cp_nonpixel_start, memprot.cp_nonpixel_size);
- return rc;
- }
- #if 0 // TODO
- static int __core_set_resource(struct msm_vidc_core *core,
- struct vidc_resource_hdr *resource_hdr, void *resource_value)
- {
- int rc = 0;
- if (!core || !resource_hdr || !resource_value) {
- d_vpr_e("%s: invalid params %pK %pK %pK\n", __func__,
- core, resource_hdr, resource_value);
- return -EINVAL;
- }
- //rc = hfi_packet_sys_set_resource(core, core->packet, core->packet_size,
- // resource_hdr, resource_value);
- if (rc) {
- d_vpr_e("set_res: failed to create packet\n");
- goto err_create_pkt;
- }
- //rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- rc = -ENOTEMPTY;
- err_create_pkt:
- return rc;
- }
- static int __core_release_resource(struct msm_vidc_core *core,
- struct vidc_resource_hdr *resource_hdr)
- {
- int rc = 0;
- if (!core || !resource_hdr) {
- d_vpr_e("%s: invalid params %pK %pK\n",
- __func__, core, resource_hdr);
- return -EINVAL;
- }
- //rc = hfi_packet_sys_release_resource(core, core->packet, core->packet_size, resource_hdr);
- if (rc) {
- d_vpr_e("release_res: failed to create packet\n");
- goto err_create_pkt;
- }
- //rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- rc = -ENOTEMPTY;
- err_create_pkt:
- return rc;
- }
- #endif
- static void __deinit_clocks(struct msm_vidc_core *core)
- {
- struct clock_info *cl;
- core->power.clk_freq = 0;
- venus_hfi_for_each_clock_reverse(core, cl) {
- if (cl->clk) {
- clk_put(cl->clk);
- cl->clk = NULL;
- }
- }
- }
- static int __init_clocks(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct clock_info *cl = NULL;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- venus_hfi_for_each_clock(core, cl) {
- d_vpr_h("%s: scalable? %d, count %d\n",
- cl->name, cl->has_scaling, cl->count);
- }
- venus_hfi_for_each_clock(core, cl) {
- if (!cl->clk) {
- cl->clk = clk_get(&core->pdev->dev, cl->name);
- if (IS_ERR_OR_NULL(cl->clk)) {
- d_vpr_e("Failed to get clock: %s\n", cl->name);
- rc = PTR_ERR(cl->clk) ?
- PTR_ERR(cl->clk) : -EINVAL;
- cl->clk = NULL;
- goto err_clk_get;
- }
- }
- }
- core->power.clk_freq = 0;
- return 0;
- err_clk_get:
- __deinit_clocks(core);
- return rc;
- }
- static void __deregister_mmrm(struct msm_vidc_core *core)
- {
- struct clock_info *cl;
- if (!core || !core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- if (!core->capabilities[MMRM].value) {
- d_vpr_h("%s: MMRM not supported\n", __func__);
- return;
- }
- venus_hfi_for_each_clock(core, cl) {
- if (cl->has_scaling && cl->mmrm_client) {
- mmrm_client_deregister(cl->mmrm_client);
- cl->mmrm_client = NULL;
- }
- }
- }
- static int __register_mmrm(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct clock_info *cl;
- if (!core ||!core->capabilities) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!core->capabilities[MMRM].value) {
- d_vpr_h("%s: MMRM not supported\n", __func__);
- return 0;
- }
- venus_hfi_for_each_clock(core, cl) {
- struct mmrm_client_desc desc;
- char *name = (char *)desc.client_info.desc.name;
- // TODO: set notifier data vals
- struct mmrm_client_notifier_data notifier_data = {
- MMRM_CLIENT_RESOURCE_VALUE_CHANGE,
- {{0, 0}},
- NULL};
- // TODO: add callback fn
- desc.notifier_callback_fn = NULL;
- if (!cl->has_scaling)
- continue;
- if (IS_ERR_OR_NULL(cl->clk)) {
- d_vpr_e("%s: Invalid clock: %s\n", __func__, cl->name);
- rc = PTR_ERR(cl->clk) ? PTR_ERR(cl->clk) : -EINVAL;
- goto err_register_mmrm;
- }
- desc.client_type = MMRM_CLIENT_CLOCK;
- desc.client_info.desc.client_domain = MMRM_CLIENT_DOMAIN_VIDEO;
- desc.client_info.desc.client_id = cl->clk_id;
- strlcpy(name, cl->name, sizeof(desc.client_info.desc.name));
- desc.client_info.desc.clk = cl->clk;
- desc.priority = MMRM_CLIENT_PRIOR_LOW;
- desc.pvt_data = notifier_data.pvt_data;
- d_vpr_h("%s: domain(%d) cid(%d) name(%s) clk(%pK)\n",
- __func__,
- desc.client_info.desc.client_domain,
- desc.client_info.desc.client_id,
- desc.client_info.desc.name,
- desc.client_info.desc.clk);
- d_vpr_h("%s: type(%d) pri(%d) pvt(%pK) notifier(%pK)\n",
- __func__,
- desc.client_type,
- desc.priority,
- desc.pvt_data,
- desc.notifier_callback_fn);
- cl->mmrm_client = mmrm_client_register(&desc);
- if (!cl->mmrm_client) {
- d_vpr_e("%s: Failed to register clk(%s): %d\n",
- __func__, cl->name, rc);
- rc = -EINVAL;
- goto err_register_mmrm;
- }
- }
- return 0;
- err_register_mmrm:
- __deregister_mmrm(core);
- return rc;
- }
- static int __handle_reset_clk(struct msm_vidc_core *core,
- int reset_index, enum reset_state state)
- {
- int rc = 0;
- struct msm_vidc_dt *dt = core->dt;
- struct reset_control *rst;
- struct reset_set *rst_set = &dt->reset_set;
- if (!rst_set->reset_tbl)
- return 0;
- rst = rst_set->reset_tbl[reset_index].rst;
- d_vpr_h("reset_clk: name %s reset_state %d rst %pK\n",
- rst_set->reset_tbl[reset_index].name, state, rst);
- switch (state) {
- case INIT:
- if (rst)
- goto skip_reset_init;
- rst = devm_reset_control_get(&core->pdev->dev,
- rst_set->reset_tbl[reset_index].name);
- if (IS_ERR(rst))
- rc = PTR_ERR(rst);
- rst_set->reset_tbl[reset_index].rst = rst;
- break;
- case ASSERT:
- if (!rst) {
- rc = PTR_ERR(rst);
- goto failed_to_reset;
- }
- rc = reset_control_assert(rst);
- break;
- case DEASSERT:
- if (!rst) {
- rc = PTR_ERR(rst);
- goto failed_to_reset;
- }
- rc = reset_control_deassert(rst);
- break;
- default:
- d_vpr_e("%s: invalid reset request\n", __func__);
- if (rc)
- goto failed_to_reset;
- }
- return 0;
- skip_reset_init:
- failed_to_reset:
- return rc;
- }
- void __disable_unprepare_clks(struct msm_vidc_core *core)
- {
- struct clock_info *cl;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- venus_hfi_for_each_clock_reverse(core, cl) {
- if (!cl->clk)
- continue;
- d_vpr_h("Clock: %s disable and unprepare\n",
- cl->name);
- if (!__clk_is_enabled(cl->clk))
- d_vpr_e("%s: clock %s already disabled\n",
- __func__, cl->name);
- clk_disable_unprepare(cl->clk);
- if (cl->has_scaling)
- __set_clk_rate(core, cl, 0);
- cl->prev = 0;
- }
- }
- int __reset_ahb2axi_bridge(struct msm_vidc_core *core)
- {
- int rc, i;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- for (i = 0; i < core->dt->reset_set.count; i++) {
- rc = __handle_reset_clk(core, i, ASSERT);
- if (rc) {
- d_vpr_e("failed to assert reset clocks\n");
- goto failed_to_reset;
- }
- /* wait for deassert */
- usleep_range(1000, 1100);
- }
- for (i = 0; i < core->dt->reset_set.count; i++) {
- rc = __handle_reset_clk(core, i, DEASSERT);
- if (rc) {
- d_vpr_e("failed to deassert reset clocks\n");
- goto failed_to_reset;
- }
- }
- return 0;
- failed_to_reset:
- return rc;
- }
- int __prepare_enable_clks(struct msm_vidc_core *core)
- {
- struct clock_info *cl = NULL;
- int rc = 0, c = 0;
- u64 rate = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- venus_hfi_for_each_clock(core, cl) {
- if (!cl->clk) {
- d_vpr_e("%s: invalid clock\n", __func__);
- rc = -EINVAL;
- goto fail_clk_enable;
- }
- /*
- * For the clocks we control, set the rate prior to preparing
- * them. Since we don't really have a load at this point, scale
- * it to the lowest frequency possible
- */
- if (cl->has_scaling) {
- rate = clk_round_rate(cl->clk, 0);
- /**
- * source clock is already multipled with scaling ratio and __set_clk_rate
- * attempts to multiply again. So divide scaling ratio before calling
- * __set_clk_rate.
- */
- rate = rate / MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
- __set_clk_rate(core, cl, rate);
- }
- rc = clk_prepare_enable(cl->clk);
- if (rc) {
- d_vpr_e("Failed to enable clocks\n");
- goto fail_clk_enable;
- }
- if (!__clk_is_enabled(cl->clk))
- d_vpr_e("%s: clock %s not enabled\n",
- __func__, cl->name);
- c++;
- d_vpr_h("Clock: %s prepared and enabled\n", cl->name);
- }
- call_venus_op(core, clock_config_on_enable, core);
- return rc;
- fail_clk_enable:
- venus_hfi_for_each_clock_reverse_continue(core, cl, c) {
- if (!cl->clk)
- continue;
- d_vpr_e("Clock: %s disable and unprepare\n",
- cl->name);
- clk_disable_unprepare(cl->clk);
- if (cl->has_scaling)
- __set_clk_rate(core, cl, 0);
- cl->prev = 0;
- }
- return rc;
- }
- static void __deinit_bus(struct msm_vidc_core *core)
- {
- struct bus_info *bus = NULL;
- if (!core)
- return;
- core->power.bw_ddr = 0;
- core->power.bw_llcc = 0;
- venus_hfi_for_each_bus_reverse(core, bus) {
- if (!bus->path)
- continue;
- icc_put(bus->path);
- bus->path = NULL;
- }
- }
- static int __init_bus(struct msm_vidc_core *core)
- {
- struct bus_info *bus = NULL;
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid param\n", __func__);
- return -EINVAL;
- }
- venus_hfi_for_each_bus(core, bus) {
- if (!strcmp(bus->name, "venus-llcc")) {
- if (msm_vidc_syscache_disable) {
- d_vpr_h("Skipping LLC bus init: %s\n",
- bus->name);
- continue;
- }
- }
- bus->path = of_icc_get(bus->dev, bus->name);
- if (IS_ERR_OR_NULL(bus->path)) {
- rc = PTR_ERR(bus->path) ?
- PTR_ERR(bus->path) : -EBADHANDLE;
- d_vpr_e("Failed to register bus %s: %d\n",
- bus->name, rc);
- bus->path = NULL;
- goto err_add_dev;
- }
- }
- return 0;
- err_add_dev:
- __deinit_bus(core);
- return rc;
- }
- static void __deinit_regulators(struct msm_vidc_core *core)
- {
- struct regulator_info *rinfo = NULL;
- venus_hfi_for_each_regulator_reverse(core, rinfo) {
- if (rinfo->regulator) {
- regulator_put(rinfo->regulator);
- rinfo->regulator = NULL;
- }
- }
- }
- static int __init_regulators(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct regulator_info *rinfo = NULL;
- venus_hfi_for_each_regulator(core, rinfo) {
- rinfo->regulator = regulator_get(&core->pdev->dev,
- rinfo->name);
- if (IS_ERR_OR_NULL(rinfo->regulator)) {
- rc = PTR_ERR(rinfo->regulator) ?
- PTR_ERR(rinfo->regulator) : -EBADHANDLE;
- d_vpr_e("Failed to get regulator: %s\n", rinfo->name);
- rinfo->regulator = NULL;
- goto err_reg_get;
- }
- }
- return 0;
- err_reg_get:
- __deinit_regulators(core);
- return rc;
- }
- static void __deinit_subcaches(struct msm_vidc_core *core)
- {
- struct subcache_info *sinfo = NULL;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- goto exit;
- }
- if (!is_sys_cache_present(core))
- goto exit;
- venus_hfi_for_each_subcache_reverse(core, sinfo) {
- if (sinfo->subcache) {
- d_vpr_h("deinit_subcaches: %s\n", sinfo->name);
- llcc_slice_putd(sinfo->subcache);
- sinfo->subcache = NULL;
- }
- }
- exit:
- return;
- }
- static int __init_subcaches(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct subcache_info *sinfo = NULL;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!is_sys_cache_present(core))
- return 0;
- venus_hfi_for_each_subcache(core, sinfo) {
- if (!strcmp("vidsc0", sinfo->name)) {
- sinfo->subcache = llcc_slice_getd(LLCC_VIDSC0);
- } else if (!strcmp("vidsc1", sinfo->name)) {
- sinfo->subcache = llcc_slice_getd(LLCC_VIDSC1);
- } else if (!strcmp("vidscfw", sinfo->name)) {
- sinfo->subcache = llcc_slice_getd(LLCC_VIDFW);
- } else {
- d_vpr_e("Invalid subcache name %s\n",
- sinfo->name);
- }
- if (IS_ERR_OR_NULL(sinfo->subcache)) {
- rc = PTR_ERR(sinfo->subcache) ?
- PTR_ERR(sinfo->subcache) : -EBADHANDLE;
- d_vpr_e("init_subcaches: invalid subcache: %s rc %d\n",
- sinfo->name, rc);
- sinfo->subcache = NULL;
- goto err_subcache_get;
- }
- d_vpr_h("init_subcaches: %s\n", sinfo->name);
- }
- return 0;
- err_subcache_get:
- __deinit_subcaches(core);
- return rc;
- }
- static int __init_resources(struct msm_vidc_core *core)
- {
- int i, rc = 0;
- rc = __init_regulators(core);
- if (rc) {
- d_vpr_e("Failed to get all regulators\n");
- return -ENODEV;
- }
- rc = __init_clocks(core);
- if (rc) {
- d_vpr_e("Failed to init clocks\n");
- rc = -ENODEV;
- goto err_init_clocks;
- }
- rc = __register_mmrm(core);
- if (rc) {
- d_vpr_e("Failed to register mmrm\n");
- rc = -ENODEV;
- goto err_init_mmrm;
- }
- for (i = 0; i < core->dt->reset_set.count; i++) {
- rc = __handle_reset_clk(core, i, INIT);
- if (rc) {
- d_vpr_e("Failed to init reset clocks\n");
- rc = -ENODEV;
- goto err_init_reset_clk;
- }
- }
- rc = __init_bus(core);
- if (rc) {
- d_vpr_e("Failed to init bus: %d\n", rc);
- goto err_init_bus;
- }
- rc = __init_subcaches(core);
- if (rc)
- d_vpr_e("Failed to init subcaches: %d\n", rc);
- return rc;
- err_init_reset_clk:
- err_init_bus:
- __deregister_mmrm(core);
- err_init_mmrm:
- __deinit_clocks(core);
- err_init_clocks:
- __deinit_regulators(core);
- return rc;
- }
- static void __deinit_resources(struct msm_vidc_core *core)
- {
- __deinit_subcaches(core);
- __deinit_bus(core);
- __deregister_mmrm(core);
- __deinit_clocks(core);
- __deinit_regulators(core);
- }
- static int __disable_regulator(struct regulator_info *rinfo,
- struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!rinfo->regulator) {
- d_vpr_e("%s: invalid regulator\n", __func__);
- return -EINVAL;
- }
- d_vpr_h("Disabling regulator %s\n", rinfo->name);
- /*
- * This call is needed. Driver needs to acquire the control back
- * from HW in order to disable the regualtor. Else the behavior
- * is unknown.
- */
- rc = __acquire_regulator(core, rinfo);
- if (rc) {
- /*
- * This is somewhat fatal, but nothing we can do
- * about it. We can't disable the regulator w/o
- * getting it back under s/w control
- */
- d_vpr_e("Failed to acquire control on %s\n",
- rinfo->name);
- goto disable_regulator_failed;
- }
- if (!regulator_is_enabled(rinfo->regulator))
- d_vpr_e("%s: regulator %s already disabled\n",
- __func__, rinfo->name);
- rc = regulator_disable(rinfo->regulator);
- if (rc) {
- d_vpr_e("Failed to disable %s: %d\n",
- rinfo->name, rc);
- goto disable_regulator_failed;
- }
- return 0;
- disable_regulator_failed:
- /* Bring attention to this issue */
- __fatal_error(true);
- return rc;
- }
- int __enable_regulators(struct msm_vidc_core *core)
- {
- int rc = 0, c = 0;
- struct regulator_info *rinfo;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- d_vpr_h("Enabling regulators\n");
- venus_hfi_for_each_regulator(core, rinfo) {
- if (!rinfo->regulator) {
- d_vpr_e("%s: invalid regulator\n", __func__);
- rc = -EINVAL;
- goto err_reg_enable_failed;
- }
- rc = regulator_enable(rinfo->regulator);
- if (rc) {
- d_vpr_e("Failed to enable %s: %d\n",
- rinfo->name, rc);
- goto err_reg_enable_failed;
- }
- if (!regulator_is_enabled(rinfo->regulator))
- d_vpr_e("%s: regulator %s not enabled\n",
- __func__, rinfo->name);
- d_vpr_h("Enabled regulator %s\n",
- rinfo->name);
- c++;
- }
- return 0;
- err_reg_enable_failed:
- venus_hfi_for_each_regulator_reverse_continue(core, rinfo, c) {
- if (!rinfo->regulator)
- continue;
- __disable_regulator(rinfo, core);
- }
- return rc;
- }
- int __disable_regulators(struct msm_vidc_core *core)
- {
- struct regulator_info *rinfo;
- d_vpr_h("Disabling regulators\n");
- venus_hfi_for_each_regulator_reverse(core, rinfo)
- __disable_regulator(rinfo, core);
- return 0;
- }
- static int __release_subcaches(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct subcache_info* sinfo;
- struct hfi_buffer buf;
- if (msm_vidc_syscache_disable || !is_sys_cache_present(core))
- return 0;
- if (!core->dt->sys_cache_res_set) {
- d_vpr_h("Subcaches not set to Venus\n");
- return 0;
- }
- rc = hfi_create_header(core->packet, core->packet_size,
- 0, core->header_id++);
- if (rc)
- return rc;
- memset(&buf, 0, sizeof(struct hfi_buffer));
- buf.type = HFI_BUFFER_SUBCACHE;
- buf.flags = HFI_BUF_HOST_FLAG_RELEASE;
- venus_hfi_for_each_subcache_reverse(core, sinfo) {
- if (sinfo->isactive) {
- buf.index = sinfo->subcache->slice_id;
- buf.buffer_size = sinfo->subcache->slice_size;
- rc = hfi_create_packet(core->packet,
- core->packet_size,
- HFI_CMD_BUFFER,
- HFI_BUF_HOST_FLAG_NONE,
- HFI_PAYLOAD_STRUCTURE,
- HFI_PORT_NONE,
- core->packet_id++,
- &buf,
- sizeof(buf));
- if (rc)
- return rc;
- }
- }
- /* Set resource to Venus for activated subcaches */
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- return rc;
- venus_hfi_for_each_subcache_reverse(core, sinfo) {
- if (sinfo->isactive) {
- sinfo->isset = false;
- d_vpr_h("Release Subcache id %d size %d done\n",
- sinfo->subcache->slice_id,
- sinfo->subcache->slice_size);
- }
- }
- core->dt->sys_cache_res_set = false;
- return 0;
- }
- static int __disable_subcaches(struct msm_vidc_core *core)
- {
- struct subcache_info *sinfo;
- int rc = 0;
- if (msm_vidc_syscache_disable || !is_sys_cache_present(core))
- return 0;
- /* De-activate subcaches */
- venus_hfi_for_each_subcache_reverse(core, sinfo) {
- if (sinfo->isactive) {
- d_vpr_h("De-activate subcache %s\n",
- sinfo->name);
- rc = llcc_slice_deactivate(sinfo->subcache);
- if (rc) {
- d_vpr_e("Failed to de-activate %s: %d\n",
- sinfo->name, rc);
- }
- sinfo->isactive = false;
- }
- }
- return 0;
- }
- static int __enable_subcaches(struct msm_vidc_core *core)
- {
- int rc = 0;
- u32 c = 0;
- struct subcache_info *sinfo;
- if (msm_vidc_syscache_disable || !is_sys_cache_present(core))
- return 0;
- /* Activate subcaches */
- venus_hfi_for_each_subcache(core, sinfo) {
- rc = llcc_slice_activate(sinfo->subcache);
- if (rc) {
- d_vpr_e("Failed to activate %s: %d\n",
- sinfo->name, rc);
- __fatal_error(true);
- goto err_activate_fail;
- }
- sinfo->isactive = true;
- d_vpr_h("Activated subcache %s\n", sinfo->name);
- c++;
- }
- d_vpr_h("Activated %d Subcaches to Venus\n", c);
- return 0;
- err_activate_fail:
- __release_subcaches(core);
- __disable_subcaches(core);
- return rc;
- }
- static int __set_subcaches(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct subcache_info *sinfo;
- struct hfi_buffer buf;
- if (msm_vidc_syscache_disable ||
- !is_sys_cache_present(core)) {
- return 0;
- }
- if (core->dt->sys_cache_res_set) {
- d_vpr_h("Subcaches already set to Venus\n");
- return 0;
- }
- rc = hfi_create_header(core->packet, core->packet_size,
- 0, core->header_id++);
- if (rc)
- goto err_fail_set_subacaches;
- memset(&buf, 0, sizeof(struct hfi_buffer));
- buf.type = HFI_BUFFER_SUBCACHE;
- buf.flags = HFI_BUF_HOST_FLAG_NONE;
- venus_hfi_for_each_subcache(core, sinfo) {
- if (sinfo->isactive) {
- buf.index = sinfo->subcache->slice_id;
- buf.buffer_size = sinfo->subcache->slice_size;
- rc = hfi_create_packet(core->packet,
- core->packet_size,
- HFI_CMD_BUFFER,
- HFI_BUF_HOST_FLAG_NONE,
- HFI_PAYLOAD_STRUCTURE,
- HFI_PORT_NONE,
- core->packet_id++,
- &buf,
- sizeof(buf));
- if (rc)
- goto err_fail_set_subacaches;
- }
- }
- /* Set resource to Venus for activated subcaches */
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- goto err_fail_set_subacaches;
- venus_hfi_for_each_subcache(core, sinfo) {
- if (sinfo->isactive) {
- sinfo->isset = true;
- d_vpr_h("Set Subcache id %d size %d done\n",
- sinfo->subcache->slice_id,
- sinfo->subcache->slice_size);
- }
- }
- core->dt->sys_cache_res_set = true;
- return 0;
- err_fail_set_subacaches:
- __disable_subcaches(core);
- return rc;
- }
- /*
- static int __set_ubwc_config(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core->platform->data.ubwc_config) {
- d_vpr_h("%s: invalid ubwc config\n", __func__);
- return -EINVAL;
- }
- //rc = hfi_packet_sys_ubwc_config(core, core->packet, core->packet_size);
- if (rc)
- return rc;
- //rc = __iface_cmdq_write(core, core->packet));
- if (rc)
- return rc;
- d_vpr_h("Configured UBWC Config\n");
- return rc;
- }
- */
- static int __venus_power_off(struct msm_vidc_core* core)
- {
- int rc = 0;
- if (!core->power_enabled)
- return 0;
- rc = call_venus_op(core, power_off, core);
- if (rc) {
- d_vpr_e("Failed to power off, err: %d\n", rc);
- return rc;
- }
- core->power_enabled = false;
- return rc;
- }
- static int __venus_power_on(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (core->power_enabled)
- return 0;
- rc = call_venus_op(core, power_on, core);
- if (rc) {
- d_vpr_e("Failed to power on, err: %d\n", rc);
- return rc;
- }
- core->power_enabled = true;
- return rc;
- }
- static int __suspend(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- } else if (!core->power_enabled) {
- d_vpr_h("Power already disabled\n");
- return 0;
- }
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- d_vpr_h("Entering suspend\n");
- rc = __tzbsp_set_video_state(TZBSP_VIDEO_STATE_SUSPEND);
- if (rc) {
- d_vpr_e("Failed to suspend video core %d\n", rc);
- goto err_tzbsp_suspend;
- }
- __disable_subcaches(core);
- __venus_power_off(core);
- d_vpr_h("Venus power off\n");
- return rc;
- err_tzbsp_suspend:
- return rc;
- }
- static int __resume(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- } else if (core->power_enabled) {
- goto exit;
- } else if (!__core_in_valid_state(core)) {
- d_vpr_e("%s: core not in valid state\n", __func__);
- return -EINVAL;
- }
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- d_vpr_h("Resuming from power collapse\n");
- core->handoff_done = false;
- core->hw_power_control = false;
- rc = __venus_power_on(core);
- if (rc) {
- d_vpr_e("Failed to power on venus\n");
- goto err_venus_power_on;
- }
- /* Reboot the firmware */
- rc = __tzbsp_set_video_state(TZBSP_VIDEO_STATE_RESUME);
- if (rc) {
- d_vpr_e("Failed to resume video core %d\n", rc);
- goto err_set_video_state;
- }
- /*
- * Hand off control of regulators to h/w _after_ loading fw.
- * Note that the GDSC will turn off when switching from normal
- * (s/w triggered) to fast (HW triggered) unless the h/w vote is
- * present.
- */
- __hand_off_regulators(core);
- call_venus_op(core, setup_ucregion_memmap, core);
- /* Wait for boot completion */
- rc = call_venus_op(core, boot_firmware, core);
- if (rc) {
- d_vpr_e("Failed to reset venus core\n");
- goto err_reset_core;
- }
- __sys_set_debug(core, (msm_vidc_debug & FW_LOGMASK) >> FW_LOGSHIFT);
- rc = __enable_subcaches(core);
- if (rc) {
- d_vpr_e("Failed to activate subcache\n");
- goto err_reset_core;
- }
- __set_subcaches(core);
- rc = __sys_set_power_control(core, true);
- if (rc) {
- d_vpr_e("%s: set power control failed\n", __func__);
- __acquire_regulators(core);
- rc = 0;
- }
- d_vpr_h("Resumed from power collapse\n");
- exit:
- /* Don't reset skip_pc_count for SYS_PC_PREP cmd */
- //if (core->last_packet_type != HFI_CMD_SYS_PC_PREP)
- // core->skip_pc_count = 0;
- return rc;
- err_reset_core:
- __tzbsp_set_video_state(TZBSP_VIDEO_STATE_SUSPEND);
- err_set_video_state:
- __venus_power_off(core);
- err_venus_power_on:
- d_vpr_e("Failed to resume from power collapse\n");
- return rc;
- }
- static void __set_queue_hdr_defaults(struct hfi_queue_header *q_hdr)
- {
- q_hdr->qhdr_status = 0x1;
- q_hdr->qhdr_type = VIDC_IFACEQ_DFLT_QHDR;
- q_hdr->qhdr_q_size = VIDC_IFACEQ_QUEUE_SIZE / 4;
- q_hdr->qhdr_pkt_size = 0;
- q_hdr->qhdr_rx_wm = 0x1;
- q_hdr->qhdr_tx_wm = 0x1;
- q_hdr->qhdr_rx_req = 0x1;
- q_hdr->qhdr_tx_req = 0x0;
- q_hdr->qhdr_rx_irq_status = 0x0;
- q_hdr->qhdr_tx_irq_status = 0x0;
- q_hdr->qhdr_read_idx = 0x0;
- q_hdr->qhdr_write_idx = 0x0;
- }
- static void __interface_queues_deinit(struct msm_vidc_core *core)
- {
- int i;
- d_vpr_h("%s()\n", __func__);
- msm_vidc_memory_unmap(core, &core->iface_q_table.map);
- msm_vidc_memory_free(core, &core->iface_q_table.alloc);
- msm_vidc_memory_unmap(core, &core->sfr.map);
- msm_vidc_memory_free(core, &core->sfr.alloc);
- for (i = 0; i < VIDC_IFACEQ_NUMQ; i++) {
- core->iface_queues[i].q_hdr = NULL;
- core->iface_queues[i].q_array.align_virtual_addr = NULL;
- core->iface_queues[i].q_array.align_device_addr = 0;
- }
- core->iface_q_table.align_virtual_addr = NULL;
- core->iface_q_table.align_device_addr = 0;
- core->sfr.align_virtual_addr = NULL;
- core->sfr.align_device_addr = 0;
- }
- static int __interface_queues_init(struct msm_vidc_core *core)
- {
- int rc = 0;
- struct hfi_queue_table_header *q_tbl_hdr;
- struct hfi_queue_header *q_hdr;
- struct msm_vidc_iface_q_info *iface_q;
- struct msm_vidc_alloc alloc;
- struct msm_vidc_map map;
- int offset = 0;
- u32 i;
- d_vpr_h("%s()\n", __func__);
- memset(&alloc, 0, sizeof(alloc));
- alloc.type = MSM_VIDC_BUF_QUEUE;
- alloc.region = MSM_VIDC_NON_SECURE;
- alloc.size = TOTAL_QSIZE;
- alloc.secure = false;
- alloc.map_kernel = true;
- rc = msm_vidc_memory_alloc(core, &alloc);
- if (rc) {
- d_vpr_e("%s: alloc failed\n", __func__);
- goto fail_alloc_queue;
- }
- memset(&map, 0, sizeof(map));
- map.type = alloc.type;
- map.region = alloc.region;
- map.dmabuf = alloc.dmabuf;
- rc = msm_vidc_memory_map(core, &map);
- if (rc) {
- d_vpr_e("%s: alloc failed\n", __func__);
- goto fail_alloc_queue;
- }
- core->iface_q_table.align_virtual_addr = alloc.kvaddr;
- core->iface_q_table.align_device_addr = map.device_addr;
- core->iface_q_table.mem_size = VIDC_IFACEQ_TABLE_SIZE;
- core->iface_q_table.alloc = alloc;
- core->iface_q_table.map = map;
- offset += core->iface_q_table.mem_size;
- for (i = 0; i < VIDC_IFACEQ_NUMQ; i++) {
- iface_q = &core->iface_queues[i];
- iface_q->q_array.align_device_addr = map.device_addr + offset;
- iface_q->q_array.align_virtual_addr = (void*)((char*)alloc.kvaddr + offset);
- iface_q->q_array.mem_size = VIDC_IFACEQ_QUEUE_SIZE;
- offset += iface_q->q_array.mem_size;
- iface_q->q_hdr = VIDC_IFACEQ_GET_QHDR_START_ADDR(
- core->iface_q_table.align_virtual_addr, i);
- __set_queue_hdr_defaults(iface_q->q_hdr);
- }
- q_tbl_hdr = (struct hfi_queue_table_header *)
- core->iface_q_table.align_virtual_addr;
- q_tbl_hdr->qtbl_version = 0;
- q_tbl_hdr->device_addr = (void *)core;
- strlcpy(q_tbl_hdr->name, "msm_v4l2_vidc", sizeof(q_tbl_hdr->name));
- q_tbl_hdr->qtbl_size = VIDC_IFACEQ_TABLE_SIZE;
- q_tbl_hdr->qtbl_qhdr0_offset = sizeof(struct hfi_queue_table_header);
- q_tbl_hdr->qtbl_qhdr_size = sizeof(struct hfi_queue_header);
- q_tbl_hdr->qtbl_num_q = VIDC_IFACEQ_NUMQ;
- q_tbl_hdr->qtbl_num_active_q = VIDC_IFACEQ_NUMQ;
- iface_q = &core->iface_queues[VIDC_IFACEQ_CMDQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_HOST_TO_CTRL_CMD_Q;
- iface_q = &core->iface_queues[VIDC_IFACEQ_MSGQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_MSG_Q;
- iface_q = &core->iface_queues[VIDC_IFACEQ_DBGQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q;
- /*
- * Set receive request to zero on debug queue as there is no
- * need of interrupt from video hardware for debug messages
- */
- q_hdr->qhdr_rx_req = 0;
- /* sfr buffer */
- memset(&alloc, 0, sizeof(alloc));
- alloc.type = MSM_VIDC_BUF_QUEUE;
- alloc.region = MSM_VIDC_NON_SECURE;
- alloc.size = ALIGNED_SFR_SIZE;
- alloc.secure = false;
- alloc.map_kernel = true;
- rc = msm_vidc_memory_alloc(core, &alloc);
- if (rc) {
- d_vpr_e("%s: sfr alloc failed\n", __func__);
- goto fail_alloc_queue;
- }
- memset(&map, 0, sizeof(map));
- map.type = alloc.type;
- map.region = alloc.region;
- map.dmabuf = alloc.dmabuf;
- rc = msm_vidc_memory_map(core, &map);
- if (rc) {
- d_vpr_e("%s: sfr map failed\n", __func__);
- goto fail_alloc_queue;
- }
- core->sfr.align_device_addr = map.device_addr;
- core->sfr.align_virtual_addr = alloc.kvaddr;
- core->sfr.mem_size = ALIGNED_SFR_SIZE;
- core->sfr.alloc = alloc;
- core->sfr.map = map;
- /* write sfr buffer size in first word */
- *((u32 *)core->sfr.align_virtual_addr) = ALIGNED_SFR_SIZE;
- rc = call_venus_op(core, setup_ucregion_memmap, core);
- if (rc)
- return rc;
- return 0;
- fail_alloc_queue:
- return -ENOMEM;
- }
- static int __load_fw_to_memory(struct platform_device *pdev,
- const char *fw_name)
- {
- int rc = 0;
- const struct firmware *firmware = NULL;
- char firmware_name[MAX_FIRMWARE_NAME_SIZE] = { 0 };
- struct device_node *node = NULL;
- struct resource res = { 0 };
- phys_addr_t phys = 0;
- size_t res_size = 0;
- ssize_t fw_size = 0;
- void *virt = NULL;
- int pas_id = 0;
- if (!fw_name || !(*fw_name) || !pdev) {
- d_vpr_e("%s: Invalid inputs\n", __func__);
- return -EINVAL;
- }
- if (strlen(fw_name) >= MAX_FIRMWARE_NAME_SIZE - 4) {
- d_vpr_e("%s: Invalid fw name\n", __func__);
- return -EINVAL;
- }
- scnprintf(firmware_name, ARRAY_SIZE(firmware_name), "%s.mbn", fw_name);
- rc = of_property_read_u32(pdev->dev.of_node, "pas-id", &pas_id);
- if (rc) {
- d_vpr_e("%s: failed to read \"pas-id\". error %d\n",
- __func__, rc);
- goto exit;
- }
- node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
- if (!node) {
- d_vpr_e("%s: failed to read \"memory-region\"\n",
- __func__);
- return -EINVAL;
- }
- rc = of_address_to_resource(node, 0, &res);
- if (rc) {
- d_vpr_e("%s: failed to read \"memory-region\", error %d\n",
- __func__, rc);
- goto exit;
- }
- phys = res.start;
- res_size = (size_t)resource_size(&res);
- rc = request_firmware(&firmware, firmware_name, &pdev->dev);
- if (rc) {
- d_vpr_e("%s: failed to request fw \"%s\", error %d\n",
- __func__, firmware_name, rc);
- goto exit;
- }
- fw_size = qcom_mdt_get_size(firmware);
- if (fw_size < 0 || res_size < (size_t)fw_size) {
- rc = -EINVAL;
- d_vpr_e("%s: out of bound fw image fw size: %ld, res_size: %lu",
- __func__, fw_size, res_size);
- goto exit;
- }
- virt = memremap(phys, res_size, MEMREMAP_WC);
- if (!virt) {
- d_vpr_e("%s: failed to remap fw memory phys %pa[p]\n",
- __func__, phys);
- return -ENOMEM;
- }
- /* prevent system suspend during fw_load */
- pm_stay_awake(pdev->dev.parent);
- rc = qcom_mdt_load(&pdev->dev, firmware, firmware_name,
- pas_id, virt, phys, res_size, NULL);
- pm_relax(pdev->dev.parent);
- if (rc) {
- d_vpr_e("%s: error %d loading fw \"%s\"\n",
- __func__, rc, firmware_name);
- goto exit;
- }
- rc = qcom_scm_pas_auth_and_reset(pas_id);
- if (rc) {
- d_vpr_e("%s: error %d authenticating fw \"%s\"\n",
- __func__, rc, firmware_name);
- goto exit;
- }
- memunmap(virt);
- release_firmware(firmware);
- d_vpr_h("%s: firmware \"%s\" loaded successfully\n",
- __func__, firmware_name);
- return pas_id;
- exit:
- if (virt)
- memunmap(virt);
- if (firmware)
- release_firmware(firmware);
- return rc;
- }
- int __load_fw(struct msm_vidc_core *core)
- {
- int rc = 0;
- d_vpr_h("%s\n", __func__);
- core->handoff_done = false;
- core->hw_power_control = false;
- trace_msm_v4l2_vidc_fw_load("START");
- rc = __init_resources(core);
- if (rc) {
- d_vpr_e("%s: Failed to init resources: %d\n", __func__, rc);
- goto fail_init_res;
- }
- rc = __venus_power_on(core);
- if (rc) {
- d_vpr_e("%s: power on failed\n", __func__);
- goto fail_venus_power_on;
- }
- if (!core->dt->fw_cookie) {
- core->dt->fw_cookie = __load_fw_to_memory(core->pdev,
- core->dt->fw_name);
- if (core->dt->fw_cookie <= 0) {
- d_vpr_e("%s: firmware download failed %d\n",
- __func__, core->dt->fw_cookie);
- core->dt->fw_cookie = 0;
- rc = -ENOMEM;
- goto fail_load_fw;
- }
- }
- rc = __protect_cp_mem(core);
- if (rc) {
- d_vpr_e("%s: protect memory failed\n", __func__);
- goto fail_protect_mem;
- }
- /*
- * Hand off control of regulators to h/w _after_ loading fw.
- * Note that the GDSC will turn off when switching from normal
- * (s/w triggered) to fast (HW triggered) unless the h/w vote is
- * present.
- */
- __hand_off_regulators(core);
- trace_msm_v4l2_vidc_fw_load("END");
- return rc;
- fail_protect_mem:
- if (core->dt->fw_cookie)
- qcom_scm_pas_shutdown(core->dt->fw_cookie);
- core->dt->fw_cookie = 0;
- fail_load_fw:
- __venus_power_off(core);
- fail_venus_power_on:
- __deinit_resources(core);
- fail_init_res:
- trace_msm_v4l2_vidc_fw_load("END");
- return rc;
- }
- void __unload_fw(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core->dt->fw_cookie)
- return;
- cancel_delayed_work(&core->pm_work);
- rc = qcom_scm_pas_shutdown(core->dt->fw_cookie);
- if (rc)
- d_vpr_e("Firmware unload failed rc=%d\n", rc);
- core->dt->fw_cookie = 0;
- __venus_power_off(core);
- __deinit_resources(core);
- d_vpr_h("%s done\n", __func__);
- }
- static int __response_handler(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (call_venus_op(core, watchdog, core, core->intr_status)) {
- struct hfi_packet pkt = {.type = HFI_SYS_ERROR_WD_TIMEOUT};
- return handle_system_error(core, &pkt);
- }
- memset(core->response_packet, 0, core->packet_size);
- while (!__iface_msgq_read(core, core->response_packet)) {
- rc = handle_response(core, core->response_packet);
- if (rc)
- continue;
- /* check for system error */
- if (core->state != MSM_VIDC_CORE_INIT)
- break;
- memset(core->response_packet, 0, core->packet_size);
- }
- __schedule_power_collapse_work(core);
- __flush_debug_queue(core, core->response_packet, core->packet_size);
- return rc;
- }
- irqreturn_t venus_hfi_isr(int irq, void *data)
- {
- disable_irq_nosync(irq);
- return IRQ_WAKE_THREAD;
- }
- irqreturn_t venus_hfi_isr_handler(int irq, void *data)
- {
- struct msm_vidc_core *core = data;
- int num_responses = 0, rc = 0;
- d_vpr_l("%s()\n", __func__);
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return IRQ_NONE;
- }
- core_lock(core, __func__);
- rc = __resume(core);
- if (rc) {
- d_vpr_e("%s: Power on failed\n", __func__);
- core_unlock(core, __func__);
- goto exit;
- }
- call_venus_op(core, clear_interrupt, core);
- core_unlock(core, __func__);
- num_responses = __response_handler(core);
- exit:
- if (!call_venus_op(core, watchdog, core, core->intr_status))
- enable_irq(irq);
- return IRQ_HANDLED;
- }
- void venus_hfi_pm_work_handler(struct work_struct *work)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- core = container_of(work, struct msm_vidc_core, pm_work.work);
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return;
- }
- d_vpr_h("%s: try power collapse\n", __func__);
- /*
- * It is ok to check this variable outside the lock since
- * it is being updated in this context only
- */
- if (core->skip_pc_count >= VIDC_MAX_PC_SKIP_COUNT) {
- d_vpr_e("Failed to PC for %d times\n",
- core->skip_pc_count);
- core->skip_pc_count = 0;
- msm_vidc_core_deinit(core, true);
- return;
- }
- core_lock(core, __func__);
- /* core already deinited - skip power collapse */
- if (core->state == MSM_VIDC_CORE_DEINIT) {
- d_vpr_e("%s: core is already de-inited\n", __func__);
- goto unlock;
- }
- rc = __power_collapse(core, false);
- switch (rc) {
- case 0:
- core->skip_pc_count = 0;
- /* Cancel pending delayed works if any */
- __cancel_power_collapse_work(core);
- d_vpr_h("%s: power collapse successful!\n", __func__);
- break;
- case -EBUSY:
- core->skip_pc_count = 0;
- d_vpr_h("%s: retry PC as dsp is busy\n", __func__);
- __schedule_power_collapse_work(core);
- break;
- case -EAGAIN:
- core->skip_pc_count++;
- d_vpr_e("%s: retry power collapse (count %d)\n",
- __func__, core->skip_pc_count);
- __schedule_power_collapse_work(core);
- break;
- default:
- d_vpr_e("%s: power collapse failed\n", __func__);
- break;
- }
- unlock:
- core_unlock(core, __func__);
- }
- static int __sys_init(struct msm_vidc_core *core)
- {
- int rc = 0;
- rc = hfi_packet_sys_init(core, core->packet, core->packet_size);
- if (rc)
- return rc;
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- return rc;
- return 0;
- }
- static int __sys_image_version(struct msm_vidc_core *core)
- {
- int rc = 0;
- rc = hfi_packet_image_version(core, core->packet, core->packet_size);
- if (rc)
- return rc;
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- return rc;
- return 0;
- }
- int venus_hfi_core_init(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- d_vpr_h("%s(): core %pK\n", __func__, core);
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- rc = __load_fw(core);
- if (rc)
- goto error;
- rc = __interface_queues_init(core);
- if (rc)
- goto error;
- rc = call_venus_op(core, boot_firmware, core);
- if (rc)
- goto error;
- rc = __enable_subcaches(core);
- if (rc)
- goto error;
- rc = __sys_init(core);
- if (rc)
- goto error;
- rc = __sys_image_version(core);
- if (rc)
- goto error;
- rc = __sys_set_debug(core, (msm_vidc_debug & FW_LOGMASK) >> FW_LOGSHIFT);
- if (rc)
- goto error;
- rc = __set_subcaches(core);
- if (rc)
- goto error;
- rc = __sys_set_power_control(core, true);
- if (rc) {
- d_vpr_e("%s: set power control failed\n", __func__);
- __acquire_regulators(core);
- rc = 0;
- }
- d_vpr_h("%s(): successful\n", __func__);
- return 0;
- error:
- d_vpr_e("%s(): failed\n", __func__);
- return rc;
- }
- int venus_hfi_core_deinit(struct msm_vidc_core *core, bool force)
- {
- int rc = 0;
- if (!core) {
- d_vpr_h("%s(): invalid params\n", __func__);
- return -EINVAL;
- }
- d_vpr_h("%s(): core %pK\n", __func__, core);
- rc = __strict_check(core, __func__);
- if (rc)
- return rc;
- if (core->state == MSM_VIDC_CORE_DEINIT)
- return 0;
- __resume(core);
- __flush_debug_queue(core, (!force ? core->packet : NULL), core->packet_size);
- __disable_subcaches(core);
- __unload_fw(core);
- /**
- * coredump need to be called after firmware unload, coredump also
- * copying queues memory. So need to be called before queues deinit.
- */
- if (msm_vidc_fw_dump)
- fw_coredump(core);
- __interface_queues_deinit(core);
- return 0;
- }
- int venus_hfi_noc_error_info(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core || !core->capabilities) {
- d_vpr_e("%s: Invalid parameters: %pK\n",
- __func__, core);
- return -EINVAL;
- }
- if (!core->capabilities[NON_FATAL_FAULTS].value)
- return 0;
- core_lock(core, __func__);
- if (core->state == MSM_VIDC_CORE_DEINIT)
- goto unlock;
- /* resume venus before accessing noc registers */
- rc = __resume(core);
- if (rc) {
- d_vpr_e("%s: Power on failed\n", __func__);
- goto unlock;
- }
- call_venus_op(core, noc_error_info, core);
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_suspend(struct msm_vidc_core *core)
- {
- int rc = 0;
- if (!core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core_lock(core, __func__);
- d_vpr_h("Suspending Venus\n");
- rc = __power_collapse(core, true);
- if (!rc) {
- /* Cancel pending delayed works if any */
- __cancel_power_collapse_work(core);
- } else {
- d_vpr_e("%s: Venus is busy\n", __func__);
- rc = -EBUSY;
- }
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_trigger_ssr(struct msm_vidc_core *core, u32 type,
- u32 client_id, u32 addr)
- {
- int rc = 0;
- u32 payload[2];
- if (!core || !core->packet) {
- d_vpr_e("%s: Invalid params\n", __func__);
- return -EINVAL;
- }
- payload[0] = client_id << 4 | type;
- payload[1] = addr;
- rc = hfi_create_header(core->packet, core->packet_size,
- 0 /*session_id*/,
- core->header_id++);
- if (rc)
- goto exit;
- /* HFI_CMD_SSR */
- rc = hfi_create_packet(core->packet, core->packet_size,
- HFI_CMD_SSR,
- HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED,
- HFI_PAYLOAD_U64,
- HFI_PORT_NONE,
- core->packet_id++,
- &payload, sizeof(u64));
- if (rc)
- goto exit;
- rc = __iface_cmdq_write(core, core->packet);
- if (rc)
- goto exit;
- exit:
- if (rc)
- d_vpr_e("%s(): failed\n", __func__);
- return rc;
- }
- int venus_hfi_session_open(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- __sys_set_debug(core,
- (msm_vidc_debug & FW_LOGMASK) >> FW_LOGSHIFT);
- rc = hfi_packet_session_command(inst,
- HFI_CMD_OPEN,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED),
- HFI_PORT_NONE,
- 0, /* session_id */
- HFI_PAYLOAD_U32,
- &inst->session_id, /* payload */
- sizeof(u32));
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_session_set_codec(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 codec;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- codec = get_hfi_codec(inst);
- rc = hfi_create_packet(inst->packet, inst->packet_size,
- HFI_PROP_CODEC,
- HFI_HOST_FLAGS_NONE,
- HFI_PAYLOAD_U32_ENUM,
- HFI_PORT_NONE,
- core->packet_id++,
- &codec,
- sizeof(u32));
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_session_set_secure_mode(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- u32 secure_mode;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- secure_mode = inst->capabilities->cap[SECURE_MODE].value;
- rc = hfi_create_packet(inst->packet, inst->packet_size,
- HFI_PROP_SECURE,
- HFI_HOST_FLAGS_NONE,
- HFI_PAYLOAD_U32,
- HFI_PORT_NONE,
- core->packet_id++,
- &secure_mode,
- sizeof(u32));
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_session_property(struct msm_vidc_inst *inst,
- u32 pkt_type, u32 flags, u32 port, u32 payload_type,
- void *payload, u32 payload_size)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- rc = hfi_create_packet(inst->packet, inst->packet_size,
- pkt_type,
- flags,
- payload_type,
- port,
- core->packet_id++,
- payload,
- payload_size);
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_session_close(struct msm_vidc_inst *inst)
- {
- int rc = 0;
- struct msm_vidc_core* core;
- if (!inst || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = hfi_packet_session_command(inst,
- HFI_CMD_CLOSE,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED |
- HFI_HOST_FLAGS_NON_DISCARDABLE),
- HFI_PORT_NONE,
- inst->session_id,
- HFI_PAYLOAD_NONE,
- NULL,
- 0);
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_start(struct msm_vidc_inst *inst, enum msm_vidc_port_type port)
- {
- int rc = 0;
- struct msm_vidc_core* core;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- if (port != INPUT_PORT && port != OUTPUT_PORT) {
- i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
- goto unlock;
- }
- rc = hfi_packet_session_command(inst,
- HFI_CMD_START,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED),
- get_hfi_port(inst, port),
- inst->session_id,
- HFI_PAYLOAD_NONE,
- NULL,
- 0);
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_stop(struct msm_vidc_inst *inst, enum msm_vidc_port_type port)
- {
- int rc = 0;
- struct msm_vidc_core* core;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- if (port != INPUT_PORT && port != OUTPUT_PORT) {
- i_vpr_e(inst, "%s: invalid port %d\n", __func__, port);
- goto unlock;
- }
- rc = hfi_packet_session_command(inst,
- HFI_CMD_STOP,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED |
- HFI_HOST_FLAGS_NON_DISCARDABLE),
- get_hfi_port(inst, port),
- inst->session_id,
- HFI_PAYLOAD_NONE,
- NULL,
- 0);
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_session_command(struct msm_vidc_inst *inst,
- u32 cmd, enum msm_vidc_port_type port, u32 payload_type,
- void *payload, u32 payload_size)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id,
- core->header_id++);
- if (rc)
- goto unlock;
- rc = hfi_create_packet(inst->packet, inst->packet_size,
- cmd,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED),
- payload_type,
- get_hfi_port(inst, port),
- core->packet_id++,
- payload,
- payload_size);
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_queue_super_buffer(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buffer, struct msm_vidc_buffer *metabuf)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- struct hfi_buffer hfi_buffer;
- struct hfi_buffer hfi_meta_buffer;
- struct msm_vidc_inst_capability *capability;
- u32 frame_size, meta_size, batch_size, cnt = 0;
- u64 ts_delta_us;
- if (!inst || !inst->core || !inst->capabilities || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- capability = inst->capabilities;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- /* Get super yuv buffer */
- rc = get_hfi_buffer(inst, buffer, &hfi_buffer);
- if (rc)
- goto unlock;
- /* Get super meta buffer */
- if (metabuf) {
- rc = get_hfi_buffer(inst, metabuf, &hfi_meta_buffer);
- if (rc)
- goto unlock;
- }
- batch_size = capability->cap[SUPER_FRAME].value;
- frame_size = call_session_op(core, buffer_size, inst, MSM_VIDC_BUF_INPUT);
- meta_size = call_session_op(core, buffer_size, inst, MSM_VIDC_BUF_INPUT_META);
- ts_delta_us = 1000000 / (capability->cap[FRAME_RATE].value >> 16);
- /* Sanitize super yuv buffer */
- if (frame_size * batch_size != buffer->buffer_size) {
- i_vpr_e(inst, "%s: invalid super yuv buffer. frame %u, batch %u, buffer size %u\n",
- __func__, frame_size, batch_size, buffer->buffer_size);
- goto unlock;
- }
- /* Sanitize super meta buffer */
- if (metabuf && meta_size * batch_size != metabuf->buffer_size) {
- i_vpr_e(inst, "%s: invalid super meta buffer. meta %u, batch %u, buffer size %u\n",
- __func__, meta_size, batch_size, metabuf->buffer_size);
- goto unlock;
- }
- /* Initialize yuv buffer */
- hfi_buffer.data_size = frame_size;
- hfi_buffer.addr_offset = 0;
- /* Initialize meta buffer */
- if (metabuf) {
- hfi_meta_buffer.data_size = meta_size;
- hfi_meta_buffer.addr_offset = 0;
- }
- while (cnt < batch_size) {
- /* Create header */
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- /* Create yuv packet */
- update_offset(hfi_buffer.addr_offset, (cnt ? frame_size : 0u));
- update_timestamp(hfi_buffer.timestamp, (cnt ? ts_delta_us : 0u));
- rc = hfi_create_packet(inst->packet,
- inst->packet_size,
- HFI_CMD_BUFFER,
- HFI_HOST_FLAGS_INTR_REQUIRED,
- HFI_PAYLOAD_STRUCTURE,
- get_hfi_port_from_buffer_type(inst, buffer->type),
- core->packet_id++,
- &hfi_buffer,
- sizeof(hfi_buffer));
- if (rc)
- goto unlock;
- /* Create meta packet */
- if (metabuf) {
- update_offset(hfi_meta_buffer.addr_offset, (cnt ? meta_size : 0u));
- update_timestamp(hfi_meta_buffer.timestamp, (cnt ? ts_delta_us : 0u));
- rc = hfi_create_packet(inst->packet,
- inst->packet_size,
- HFI_CMD_BUFFER,
- HFI_HOST_FLAGS_INTR_REQUIRED,
- HFI_PAYLOAD_STRUCTURE,
- get_hfi_port_from_buffer_type(inst, metabuf->type),
- core->packet_id++,
- &hfi_meta_buffer,
- sizeof(hfi_meta_buffer));
- if (rc)
- goto unlock;
- }
- /* Raise interrupt only for last pkt in the batch */
- rc = __iface_cmdq_write_intr(inst->core, inst->packet, (cnt == batch_size - 1));
- if (rc)
- goto unlock;
- cnt++;
- }
- unlock:
- core_unlock(core, __func__);
- if (rc)
- i_vpr_e(inst, "%s: queue super buffer failed: %d\n", __func__, rc);
- return rc;
- }
- int venus_hfi_queue_buffer(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buffer, struct msm_vidc_buffer *metabuf)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- struct hfi_buffer hfi_buffer;
- if (!inst || !inst->core || !inst->packet) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = get_hfi_buffer(inst, buffer, &hfi_buffer);
- if (rc)
- goto unlock;
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- rc = hfi_create_packet(inst->packet,
- inst->packet_size,
- HFI_CMD_BUFFER,
- HFI_HOST_FLAGS_INTR_REQUIRED,
- HFI_PAYLOAD_STRUCTURE,
- get_hfi_port_from_buffer_type(inst, buffer->type),
- core->packet_id++,
- &hfi_buffer,
- sizeof(hfi_buffer));
- if (rc)
- goto unlock;
- if (metabuf) {
- rc = get_hfi_buffer(inst, metabuf, &hfi_buffer);
- if (rc)
- goto unlock;
- rc = hfi_create_packet(inst->packet,
- inst->packet_size,
- HFI_CMD_BUFFER,
- HFI_HOST_FLAGS_INTR_REQUIRED,
- HFI_PAYLOAD_STRUCTURE,
- get_hfi_port_from_buffer_type(inst, metabuf->type),
- core->packet_id++,
- &hfi_buffer,
- sizeof(hfi_buffer));
- if (rc)
- goto unlock;
- }
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_release_buffer(struct msm_vidc_inst *inst,
- struct msm_vidc_buffer *buffer)
- {
- int rc = 0;
- struct msm_vidc_core *core;
- struct hfi_buffer hfi_buffer;
- if (!inst || !inst->core || !inst->packet || !buffer) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- if (!__valdiate_session(core, inst, __func__)) {
- rc = -EINVAL;
- goto unlock;
- }
- rc = get_hfi_buffer(inst, buffer, &hfi_buffer);
- if (rc)
- goto unlock;
- /* add release flag */
- hfi_buffer.flags |= HFI_BUF_HOST_FLAG_RELEASE;
- rc = hfi_create_header(inst->packet, inst->packet_size,
- inst->session_id, core->header_id++);
- if (rc)
- goto unlock;
- rc = hfi_create_packet(inst->packet,
- inst->packet_size,
- HFI_CMD_BUFFER,
- (HFI_HOST_FLAGS_RESPONSE_REQUIRED |
- HFI_HOST_FLAGS_INTR_REQUIRED),
- HFI_PAYLOAD_STRUCTURE,
- get_hfi_port_from_buffer_type(inst, buffer->type),
- core->packet_id++,
- &hfi_buffer,
- sizeof(hfi_buffer));
- if (rc)
- goto unlock;
- rc = __iface_cmdq_write(inst->core, inst->packet);
- if (rc)
- goto unlock;
- unlock:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_scale_clocks(struct msm_vidc_inst* inst, u64 freq)
- {
- int rc = 0;
- struct msm_vidc_core* core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- rc = __resume(core);
- if (rc) {
- i_vpr_e(inst, "%s: Resume from power collapse failed\n", __func__);
- goto exit;
- }
- rc = __set_clocks(core, freq);
- if (rc)
- goto exit;
- exit:
- core_unlock(core, __func__);
- return rc;
- }
- int venus_hfi_scale_buses(struct msm_vidc_inst *inst, u64 bw_ddr, u64 bw_llcc)
- {
- int rc = 0;
- struct msm_vidc_core* core;
- if (!inst || !inst->core) {
- d_vpr_e("%s: invalid params\n", __func__);
- return -EINVAL;
- }
- core = inst->core;
- core_lock(core, __func__);
- rc = __resume(core);
- if (rc) {
- i_vpr_e(inst, "%s: Resume from power collapse failed\n", __func__);
- goto exit;
- }
- rc = __vote_buses(core, bw_ddr, bw_llcc);
- if (rc)
- goto exit;
- exit:
- core_unlock(core, __func__);
- return rc;
- }
|