12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
- */
- #include <linux/debugfs.h>
- #include <linux/videodev2.h>
- #include <linux/slab.h>
- #include <linux/uaccess.h>
- #include <linux/ratelimit.h>
- #include "cam_mem_mgr.h"
- #include "cam_sync_api.h"
- #include "cam_req_mgr_dev.h"
- #include "cam_trace.h"
- #include "cam_debug_util.h"
- #include "cam_packet_util.h"
- #include "cam_context_utils.h"
- #include "cam_cdm_util.h"
- #include "cam_isp_context.h"
- #include "cam_common_util.h"
- static const char isp_dev_name[] = "cam-isp";
- static struct cam_isp_ctx_debug isp_ctx_debug;
- #define INC_STATE_MONITOR_HEAD(head, ret) \
- div_u64_rem(atomic64_add_return(1, head),\
- CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES, (ret))
- static int cam_isp_context_dump_active_request(void *data, unsigned long iova,
- uint32_t buf_info);
- static int __cam_isp_ctx_start_dev_in_ready(struct cam_context *ctx,
- struct cam_start_stop_dev_cmd *cmd);
- static void __cam_isp_ctx_update_state_monitor_array(
- struct cam_isp_context *ctx_isp,
- enum cam_isp_state_change_trigger trigger_type,
- uint64_t req_id)
- {
- int iterator;
- INC_STATE_MONITOR_HEAD(&ctx_isp->state_monitor_head, &iterator);
- ctx_isp->cam_isp_ctx_state_monitor[iterator].curr_state =
- ctx_isp->substate_activated;
- ctx_isp->cam_isp_ctx_state_monitor[iterator].frame_id =
- ctx_isp->frame_id;
- ctx_isp->cam_isp_ctx_state_monitor[iterator].trigger =
- trigger_type;
- ctx_isp->cam_isp_ctx_state_monitor[iterator].req_id =
- req_id;
- ctx_isp->cam_isp_ctx_state_monitor[iterator].evt_time_stamp =
- jiffies_to_msecs(jiffies) - ctx_isp->init_timestamp;
- }
- static const char *__cam_isp_ctx_substate_val_to_type(
- enum cam_isp_ctx_activated_substate type)
- {
- switch (type) {
- case CAM_ISP_CTX_ACTIVATED_SOF:
- return "SOF";
- case CAM_ISP_CTX_ACTIVATED_APPLIED:
- return "APPLIED";
- case CAM_ISP_CTX_ACTIVATED_EPOCH:
- return "EPOCH";
- case CAM_ISP_CTX_ACTIVATED_BUBBLE:
- return "BUBBLE";
- case CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED:
- return "BUBBLE_APPLIED";
- case CAM_ISP_CTX_ACTIVATED_HW_ERROR:
- return "HW_ERROR";
- case CAM_ISP_CTX_ACTIVATED_HALT:
- return "HALT";
- default:
- return "INVALID";
- }
- }
- static const char *__cam_isp_hw_evt_val_to_type(
- uint32_t evt_id)
- {
- switch (evt_id) {
- case CAM_ISP_STATE_CHANGE_TRIGGER_ERROR:
- return "ERROR";
- case CAM_ISP_STATE_CHANGE_TRIGGER_APPLIED:
- return "APPLIED";
- case CAM_ISP_STATE_CHANGE_TRIGGER_SOF:
- return "SOF";
- case CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE:
- return "REG_UPDATE";
- case CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH:
- return "EPOCH";
- case CAM_ISP_STATE_CHANGE_TRIGGER_EOF:
- return "EOF";
- case CAM_ISP_STATE_CHANGE_TRIGGER_DONE:
- return "DONE";
- case CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH:
- return "FLUSH";
- default:
- return "CAM_ISP_EVENT_INVALID";
- }
- }
- static void __cam_isp_ctx_dump_state_monitor_array(
- struct cam_isp_context *ctx_isp)
- {
- int i = 0;
- int64_t state_head = 0;
- uint32_t index, num_entries, oldest_entry;
- state_head = atomic64_read(&ctx_isp->state_monitor_head);
- if (state_head == -1) {
- return;
- } else if (state_head < CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES) {
- num_entries = state_head;
- oldest_entry = 0;
- } else {
- num_entries = CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES;
- div_u64_rem(state_head + 1,
- CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES, &oldest_entry);
- }
- CAM_ERR(CAM_ISP,
- "Dumping state information for preceding requests");
- index = oldest_entry;
- for (i = 0; i < num_entries; i++) {
- CAM_ERR(CAM_ISP,
- "Index[%d] time[%d] : Substate[%s] Frame[%lld] ReqId[%llu] evt_type[%s]",
- index,
- ctx_isp->cam_isp_ctx_state_monitor[index].evt_time_stamp,
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->cam_isp_ctx_state_monitor[index].curr_state),
- ctx_isp->cam_isp_ctx_state_monitor[index].frame_id,
- ctx_isp->cam_isp_ctx_state_monitor[index].req_id,
- __cam_isp_hw_evt_val_to_type(
- ctx_isp->cam_isp_ctx_state_monitor[index].trigger));
- index = (index + 1) % CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES;
- }
- }
- static int cam_isp_context_info_dump(void *context,
- enum cam_context_dump_id id)
- {
- struct cam_context *ctx = (struct cam_context *)context;
- switch (id) {
- case CAM_CTX_DUMP_ACQ_INFO: {
- cam_context_dump_hw_acq_info(ctx);
- break;
- }
- default:
- CAM_DBG(CAM_ISP, "DUMP id not valid %u", id);
- break;
- }
- return 0;
- }
- static void cam_isp_ctx_dump_req(struct cam_isp_ctx_req *req_isp)
- {
- int i = 0, rc = 0;
- size_t len = 0;
- uint32_t *buf_addr;
- uint32_t *buf_start, *buf_end;
- size_t remain_len = 0;
- for (i = 0; i < req_isp->num_cfg; i++) {
- rc = cam_packet_util_get_cmd_mem_addr(
- req_isp->cfg[i].handle, &buf_addr, &len);
- if (rc) {
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "Failed to get_cmd_mem_addr, rc=%d",
- rc);
- } else {
- if (req_isp->cfg[i].offset >= ((uint32_t)len)) {
- CAM_ERR(CAM_ISP,
- "Invalid offset exp %u actual %u",
- req_isp->cfg[i].offset, (uint32_t)len);
- return;
- }
- remain_len = len - req_isp->cfg[i].offset;
- if (req_isp->cfg[i].len >
- ((uint32_t)remain_len)) {
- CAM_ERR(CAM_ISP,
- "Invalid len exp %u remain_len %u",
- req_isp->cfg[i].len,
- (uint32_t)remain_len);
- return;
- }
- buf_start = (uint32_t *)((uint8_t *) buf_addr +
- req_isp->cfg[i].offset);
- buf_end = (uint32_t *)((uint8_t *) buf_start +
- req_isp->cfg[i].len - 1);
- cam_cdm_util_dump_cmd_buf(buf_start, buf_end);
- }
- }
- }
- static int __cam_isp_ctx_enqueue_request_in_order(
- struct cam_context *ctx, struct cam_ctx_request *req)
- {
- struct cam_ctx_request *req_current;
- struct cam_ctx_request *req_prev;
- struct list_head temp_list;
- INIT_LIST_HEAD(&temp_list);
- spin_lock_bh(&ctx->lock);
- if (list_empty(&ctx->pending_req_list)) {
- list_add_tail(&req->list, &ctx->pending_req_list);
- } else {
- list_for_each_entry_safe_reverse(
- req_current, req_prev, &ctx->pending_req_list, list) {
- if (req->request_id < req_current->request_id) {
- list_del_init(&req_current->list);
- list_add(&req_current->list, &temp_list);
- continue;
- } else if (req->request_id == req_current->request_id) {
- CAM_WARN(CAM_ISP,
- "Received duplicated request %lld",
- req->request_id);
- }
- break;
- }
- list_add_tail(&req->list, &ctx->pending_req_list);
- if (!list_empty(&temp_list)) {
- list_for_each_entry_safe(
- req_current, req_prev, &temp_list, list) {
- list_del_init(&req_current->list);
- list_add_tail(&req_current->list,
- &ctx->pending_req_list);
- }
- }
- }
- spin_unlock_bh(&ctx->lock);
- return 0;
- }
- static int __cam_isp_ctx_enqueue_init_request(
- struct cam_context *ctx, struct cam_ctx_request *req)
- {
- int rc = 0;
- struct cam_ctx_request *req_old;
- struct cam_isp_ctx_req *req_isp_old;
- struct cam_isp_ctx_req *req_isp_new;
- struct cam_isp_prepare_hw_update_data *req_update_old;
- struct cam_isp_prepare_hw_update_data *req_update_new;
- spin_lock_bh(&ctx->lock);
- if (list_empty(&ctx->pending_req_list)) {
- list_add_tail(&req->list, &ctx->pending_req_list);
- CAM_DBG(CAM_ISP, "INIT packet added req id= %d",
- req->request_id);
- goto end;
- }
- req_old = list_first_entry(&ctx->pending_req_list,
- struct cam_ctx_request, list);
- req_isp_old = (struct cam_isp_ctx_req *) req_old->req_priv;
- req_isp_new = (struct cam_isp_ctx_req *) req->req_priv;
- if (req_isp_old->hw_update_data.packet_opcode_type ==
- CAM_ISP_PACKET_INIT_DEV) {
- if ((req_isp_old->num_cfg + req_isp_new->num_cfg) >=
- CAM_ISP_CTX_CFG_MAX) {
- CAM_WARN(CAM_ISP, "Can not merge INIT pkt");
- rc = -ENOMEM;
- }
- if (req_isp_old->num_fence_map_out != 0 ||
- req_isp_old->num_fence_map_in != 0) {
- CAM_WARN(CAM_ISP, "Invalid INIT pkt sequence");
- rc = -EINVAL;
- }
- if (!rc) {
- memcpy(req_isp_old->fence_map_out,
- req_isp_new->fence_map_out,
- sizeof(req_isp_new->fence_map_out[0])*
- req_isp_new->num_fence_map_out);
- req_isp_old->num_fence_map_out =
- req_isp_new->num_fence_map_out;
- memcpy(req_isp_old->fence_map_in,
- req_isp_new->fence_map_in,
- sizeof(req_isp_new->fence_map_in[0])*
- req_isp_new->num_fence_map_in);
- req_isp_old->num_fence_map_in =
- req_isp_new->num_fence_map_in;
- memcpy(&req_isp_old->cfg[req_isp_old->num_cfg],
- req_isp_new->cfg,
- sizeof(req_isp_new->cfg[0])*
- req_isp_new->num_cfg);
- req_isp_old->num_cfg += req_isp_new->num_cfg;
- memcpy(&req_old->pf_data, &req->pf_data,
- sizeof(struct cam_hw_mgr_dump_pf_data));
- if (req_isp_new->hw_update_data.num_reg_dump_buf) {
- req_update_new = &req_isp_new->hw_update_data;
- req_update_old = &req_isp_old->hw_update_data;
- memcpy(&req_update_old->reg_dump_buf_desc,
- &req_update_new->reg_dump_buf_desc,
- sizeof(struct cam_cmd_buf_desc) *
- req_update_new->num_reg_dump_buf);
- req_update_old->num_reg_dump_buf =
- req_update_new->num_reg_dump_buf;
- }
- req_old->request_id = req->request_id;
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- } else {
- CAM_WARN(CAM_ISP,
- "Received Update pkt before INIT pkt. req_id= %lld",
- req->request_id);
- rc = -EINVAL;
- }
- end:
- spin_unlock_bh(&ctx->lock);
- return rc;
- }
- static const char *__cam_isp_resource_handle_id_to_type(
- uint32_t resource_handle)
- {
- switch (resource_handle) {
- case CAM_ISP_IFE_OUT_RES_FULL:
- return "FULL";
- case CAM_ISP_IFE_OUT_RES_DS4:
- return "DS4";
- case CAM_ISP_IFE_OUT_RES_DS16:
- return "DS16";
- case CAM_ISP_IFE_OUT_RES_RAW_DUMP:
- return "RAW_DUMP";
- case CAM_ISP_IFE_OUT_RES_FD:
- return "FD";
- case CAM_ISP_IFE_OUT_RES_PDAF:
- return "PDAF";
- case CAM_ISP_IFE_OUT_RES_RDI_0:
- return "RDI_0";
- case CAM_ISP_IFE_OUT_RES_RDI_1:
- return "RDI_1";
- case CAM_ISP_IFE_OUT_RES_RDI_2:
- return "RDI_2";
- case CAM_ISP_IFE_OUT_RES_RDI_3:
- return "RDI_3";
- case CAM_ISP_IFE_OUT_RES_STATS_HDR_BE:
- return "STATS_HDR_BE";
- case CAM_ISP_IFE_OUT_RES_STATS_HDR_BHIST:
- return "STATS_HDR_BHIST";
- case CAM_ISP_IFE_OUT_RES_STATS_TL_BG:
- return "STATS_TL_BG";
- case CAM_ISP_IFE_OUT_RES_STATS_BF:
- return "STATS_BF";
- case CAM_ISP_IFE_OUT_RES_STATS_AWB_BG:
- return "STATS_AWB_BG";
- case CAM_ISP_IFE_OUT_RES_STATS_BHIST:
- return "STATS_BHIST";
- case CAM_ISP_IFE_OUT_RES_STATS_RS:
- return "STATS_RS";
- case CAM_ISP_IFE_OUT_RES_STATS_CS:
- return "STATS_CS";
- case CAM_ISP_IFE_OUT_RES_STATS_IHIST:
- return "STATS_IHIST";
- case CAM_ISP_IFE_OUT_RES_FULL_DISP:
- return "FULL_DISP";
- case CAM_ISP_IFE_OUT_RES_DS4_DISP:
- return "DS4_DISP";
- case CAM_ISP_IFE_OUT_RES_DS16_DISP:
- return "DS16_DISP";
- case CAM_ISP_IFE_OUT_RES_2PD:
- return "2PD";
- case CAM_ISP_IFE_OUT_RES_RDI_RD:
- return "RDI_RD";
- case CAM_ISP_IFE_OUT_RES_LCR:
- return "LCR";
- default:
- return "CAM_ISP_Invalid_Resource_Type";
- }
- }
- static const char *__cam_isp_tfe_resource_handle_id_to_type(
- uint32_t resource_handle)
- {
- switch (resource_handle) {
- case CAM_ISP_TFE_OUT_RES_FULL:
- return "FULL";
- case CAM_ISP_TFE_OUT_RES_RAW_DUMP:
- return "RAW_DUMP";
- case CAM_ISP_TFE_OUT_RES_PDAF:
- return "PDAF";
- case CAM_ISP_TFE_OUT_RES_RDI_0:
- return "RDI_0";
- case CAM_ISP_TFE_OUT_RES_RDI_1:
- return "RDI_1";
- case CAM_ISP_TFE_OUT_RES_RDI_2:
- return "RDI_2";
- case CAM_ISP_TFE_OUT_RES_STATS_HDR_BE:
- return "STATS_HDR_BE";
- case CAM_ISP_TFE_OUT_RES_STATS_HDR_BHIST:
- return "STATS_HDR_BHIST";
- case CAM_ISP_TFE_OUT_RES_STATS_TL_BG:
- return "STATS_TL_BG";
- case CAM_ISP_TFE_OUT_RES_STATS_BF:
- return "STATS_BF";
- case CAM_ISP_TFE_OUT_RES_STATS_AWB_BG:
- return "STATS_AWB_BG";
- default:
- return "CAM_ISP_Invalid_Resource_Type";
- }
- }
- static uint64_t __cam_isp_ctx_get_event_ts(uint32_t evt_id, void *evt_data)
- {
- uint64_t ts = 0;
- if (!evt_data)
- return 0;
- switch (evt_id) {
- case CAM_ISP_HW_EVENT_ERROR:
- ts = ((struct cam_isp_hw_error_event_data *)evt_data)->
- timestamp;
- break;
- case CAM_ISP_HW_EVENT_SOF:
- ts = ((struct cam_isp_hw_sof_event_data *)evt_data)->
- timestamp;
- break;
- case CAM_ISP_HW_EVENT_REG_UPDATE:
- ts = ((struct cam_isp_hw_reg_update_event_data *)evt_data)->
- timestamp;
- break;
- case CAM_ISP_HW_EVENT_EPOCH:
- ts = ((struct cam_isp_hw_epoch_event_data *)evt_data)->
- timestamp;
- break;
- case CAM_ISP_HW_EVENT_EOF:
- ts = ((struct cam_isp_hw_eof_event_data *)evt_data)->
- timestamp;
- break;
- case CAM_ISP_HW_EVENT_DONE:
- break;
- default:
- CAM_DBG(CAM_ISP, "Invalid Event Type %d", evt_id);
- }
- return ts;
- }
- static void __cam_isp_ctx_send_sof_boot_timestamp(
- struct cam_isp_context *ctx_isp, uint64_t request_id,
- uint32_t sof_event_status)
- {
- struct cam_req_mgr_message req_msg;
- req_msg.session_hdl = ctx_isp->base->session_hdl;
- req_msg.u.frame_msg.frame_id = ctx_isp->frame_id;
- req_msg.u.frame_msg.request_id = request_id;
- req_msg.u.frame_msg.timestamp = ctx_isp->boot_timestamp;
- req_msg.u.frame_msg.link_hdl = ctx_isp->base->link_hdl;
- req_msg.u.frame_msg.sof_status = sof_event_status;
- CAM_DBG(CAM_ISP,
- "request id:%lld frame number:%lld boot time stamp:0x%llx",
- request_id, ctx_isp->frame_id,
- ctx_isp->boot_timestamp);
- if (cam_req_mgr_notify_message(&req_msg,
- V4L_EVENT_CAM_REQ_MGR_SOF_BOOT_TS,
- V4L_EVENT_CAM_REQ_MGR_EVENT))
- CAM_ERR(CAM_ISP,
- "Error in notifying the boot time for req id:%lld",
- request_id);
- }
- static void __cam_isp_ctx_send_sof_timestamp(
- struct cam_isp_context *ctx_isp, uint64_t request_id,
- uint32_t sof_event_status)
- {
- struct cam_req_mgr_message req_msg;
- req_msg.session_hdl = ctx_isp->base->session_hdl;
- req_msg.u.frame_msg.frame_id = ctx_isp->frame_id;
- req_msg.u.frame_msg.request_id = request_id;
- req_msg.u.frame_msg.timestamp = ctx_isp->sof_timestamp_val;
- req_msg.u.frame_msg.link_hdl = ctx_isp->base->link_hdl;
- req_msg.u.frame_msg.sof_status = sof_event_status;
- CAM_DBG(CAM_ISP,
- "request id:%lld frame number:%lld SOF time stamp:0x%llx",
- request_id, ctx_isp->frame_id,
- ctx_isp->sof_timestamp_val);
- CAM_DBG(CAM_ISP, "sof status:%d", sof_event_status);
- if (cam_req_mgr_notify_message(&req_msg,
- V4L_EVENT_CAM_REQ_MGR_SOF, V4L_EVENT_CAM_REQ_MGR_EVENT))
- CAM_ERR(CAM_ISP,
- "Error in notifying the sof time for req id:%lld",
- request_id);
- __cam_isp_ctx_send_sof_boot_timestamp(ctx_isp,
- request_id, sof_event_status);
- }
- static void __cam_isp_ctx_handle_buf_done_fail_log(
- uint64_t request_id, struct cam_isp_ctx_req *req_isp,
- uint32_t isp_device_type)
- {
- int i;
- const char *handle_type;
- if (req_isp->num_fence_map_out >= CAM_ISP_CTX_RES_MAX) {
- CAM_ERR(CAM_ISP,
- "Num Resources exceed mMAX %d >= %d ",
- req_isp->num_fence_map_out, CAM_ISP_CTX_RES_MAX);
- return;
- }
- CAM_WARN(CAM_ISP,
- "Prev Req[%lld] : num_out=%d, num_acked=%d, bubble : report=%d, detected=%d",
- request_id, req_isp->num_fence_map_out, req_isp->num_acked,
- req_isp->bubble_report, req_isp->bubble_detected);
- CAM_WARN(CAM_ISP,
- "Resource Handles that fail to generate buf_done in prev frame");
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- if (req_isp->fence_map_out[i].sync_id != -1) {
- if (isp_device_type == CAM_IFE_DEVICE_TYPE)
- handle_type =
- __cam_isp_resource_handle_id_to_type(
- req_isp->fence_map_out[i].resource_handle);
- else
- handle_type =
- __cam_isp_tfe_resource_handle_id_to_type(
- req_isp->fence_map_out[i].resource_handle);
- CAM_WARN(CAM_ISP,
- "Resource_Handle: [%s][0x%x] Sync_ID: [0x%x]",
- handle_type,
- req_isp->fence_map_out[i].resource_handle,
- req_isp->fence_map_out[i].sync_id);
- }
- }
- }
- static int __cam_isp_ctx_handle_buf_done_for_request(
- struct cam_isp_context *ctx_isp,
- struct cam_ctx_request *req,
- struct cam_isp_hw_done_event_data *done,
- uint32_t bubble_state,
- struct cam_isp_hw_done_event_data *done_next_req)
- {
- int rc = 0;
- int i, j;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- uint64_t buf_done_req_id;
- const char *handle_type;
- trace_cam_buf_done("ISP", ctx, req);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- CAM_DBG(CAM_ISP, "Enter with bubble_state %d, req_bubble_detected %d",
- bubble_state, req_isp->bubble_detected);
- if (done_next_req) {
- done_next_req->num_handles = 0;
- done_next_req->timestamp = done->timestamp;
- }
- for (i = 0; i < done->num_handles; i++) {
- for (j = 0; j < req_isp->num_fence_map_out; j++) {
- if (done->resource_handle[i] ==
- req_isp->fence_map_out[j].resource_handle)
- break;
- }
- if (j == req_isp->num_fence_map_out) {
- CAM_ERR(CAM_ISP,
- "Can not find matching lane handle 0x%x!",
- done->resource_handle[i]);
- rc = -EINVAL;
- continue;
- }
- if (req_isp->fence_map_out[j].sync_id == -1) {
- if (ctx_isp->isp_device_type == CAM_IFE_DEVICE_TYPE)
- handle_type =
- __cam_isp_resource_handle_id_to_type(
- req_isp->fence_map_out[i].resource_handle);
- else
- handle_type =
- __cam_isp_tfe_resource_handle_id_to_type(
- req_isp->fence_map_out[i].resource_handle);
- CAM_WARN(CAM_ISP,
- "Duplicate BUF_DONE for req %lld : i=%d, j=%d, res=%s",
- req->request_id, i, j, handle_type);
- if (done_next_req) {
- done_next_req->resource_handle
- [done_next_req->num_handles++] =
- done->resource_handle[i];
- }
- continue;
- }
- if (!req_isp->bubble_detected) {
- CAM_DBG(CAM_ISP,
- "Sync with success: req %lld res 0x%x fd 0x%x, ctx %u",
- req->request_id,
- req_isp->fence_map_out[j].resource_handle,
- req_isp->fence_map_out[j].sync_id,
- ctx->ctx_id);
- rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id,
- CAM_SYNC_STATE_SIGNALED_SUCCESS);
- if (rc)
- CAM_DBG(CAM_ISP, "Sync failed with rc = %d",
- rc);
- } else if (!req_isp->bubble_report) {
- CAM_ERR(CAM_ISP,
- "Sync with failure: req %lld res 0x%x fd 0x%x, ctx %u",
- req->request_id,
- req_isp->fence_map_out[j].resource_handle,
- req_isp->fence_map_out[j].sync_id,
- ctx->ctx_id);
- rc = cam_sync_signal(req_isp->fence_map_out[j].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- if (rc)
- CAM_ERR(CAM_ISP, "Sync failed with rc = %d",
- rc);
- } else {
- /*
- * Ignore the buffer done if bubble detect is on
- * Increment the ack number here, and queue the
- * request back to pending list whenever all the
- * buffers are done.
- */
- req_isp->num_acked++;
- CAM_DBG(CAM_ISP,
- "buf done with bubble state %d recovery %d",
- bubble_state, req_isp->bubble_report);
- continue;
- }
- CAM_DBG(CAM_ISP, "req %lld, reset sync id 0x%x ctx %u",
- req->request_id,
- req_isp->fence_map_out[j].sync_id, ctx->ctx_id);
- if (!rc) {
- req_isp->num_acked++;
- req_isp->fence_map_out[j].sync_id = -1;
- }
- }
- if (req_isp->num_acked > req_isp->num_fence_map_out) {
- /* Should not happen */
- CAM_ERR(CAM_ISP,
- "WARNING: req_id %lld num_acked %d > map_out %d, ctx %u",
- req->request_id, req_isp->num_acked,
- req_isp->num_fence_map_out, ctx->ctx_id);
- WARN_ON(req_isp->num_acked > req_isp->num_fence_map_out);
- }
- if (req_isp->num_acked != req_isp->num_fence_map_out)
- return rc;
- ctx_isp->active_req_cnt--;
- buf_done_req_id = req->request_id;
- if (req_isp->bubble_detected && req_isp->bubble_report) {
- req_isp->num_acked = 0;
- req_isp->bubble_detected = false;
- list_del_init(&req->list);
- atomic_set(&ctx_isp->process_bubble, 0);
- if (buf_done_req_id <= ctx->last_flush_req) {
- for (i = 0; i < req_isp->num_fence_map_out; i++)
- cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- list_add_tail(&req->list, &ctx->free_req_list);
- CAM_DBG(CAM_REQ,
- "Move active request %lld to free list(cnt = %d) [flushed], ctx %u",
- buf_done_req_id, ctx_isp->active_req_cnt,
- ctx->ctx_id);
- } else {
- list_add(&req->list, &ctx->pending_req_list);
- ctx_isp->bubble_frame_cnt = 0;
- CAM_DBG(CAM_REQ,
- "Move active request %lld to pending list(cnt = %d) [bubble recovery], ctx %u",
- req->request_id, ctx_isp->active_req_cnt,
- ctx->ctx_id);
- }
- } else {
- if (ctx_isp->reported_req_id < buf_done_req_id) {
- ctx_isp->reported_req_id = buf_done_req_id;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp,
- buf_done_req_id, CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- }
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->free_req_list);
- req_isp->reapply = false;
- CAM_DBG(CAM_REQ,
- "Move active request %lld to free list(cnt = %d) [all fences done], ctx %u",
- buf_done_req_id, ctx_isp->active_req_cnt, ctx->ctx_id);
- ctx_isp->req_info.last_bufdone_req_id = req->request_id;
- }
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_DONE, buf_done_req_id);
- return rc;
- }
- static int __cam_isp_ctx_handle_buf_done_in_activated_state(
- struct cam_isp_context *ctx_isp,
- struct cam_isp_hw_done_event_data *done,
- uint32_t bubble_state)
- {
- int rc = 0;
- struct cam_ctx_request *req;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_hw_done_event_data done_next_req;
- if (list_empty(&ctx->active_req_list)) {
- CAM_DBG(CAM_ISP, "Buf done with no active request");
- return 0;
- }
- req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- rc = __cam_isp_ctx_handle_buf_done_for_request(ctx_isp, req, done,
- bubble_state, &done_next_req);
- if (done_next_req.num_handles) {
- struct cam_isp_hw_done_event_data unhandled_res;
- struct cam_ctx_request *next_req = list_last_entry(
- &ctx->active_req_list, struct cam_ctx_request, list);
- if (next_req->request_id != req->request_id) {
- /*
- * Few resource handles are already signalled in the
- * current request, lets check if there is another
- * request waiting for these resources. This can
- * happen if handling some of next request's buf done
- * events are happening first before handling current
- * request's remaining buf dones due to IRQ scheduling.
- * Lets check only one more request as we will have
- * maximum of 2 requests in active_list at any time.
- */
- CAM_WARN(CAM_ISP,
- "Unhandled buf done resources for req %lld, trying next request %lld in active_list",
- req->request_id, next_req->request_id);
- __cam_isp_ctx_handle_buf_done_for_request(ctx_isp,
- next_req, &done_next_req,
- bubble_state, &unhandled_res);
- if (unhandled_res.num_handles == 0)
- CAM_INFO(CAM_ISP,
- "BUF Done event handed for next request %lld",
- next_req->request_id);
- else
- CAM_ERR(CAM_ISP,
- "BUF Done not handled for next request %lld",
- next_req->request_id);
- } else {
- CAM_WARN(CAM_ISP,
- "Req %lld only active request, spurious buf_done rxd",
- req->request_id);
- }
- }
- return rc;
- }
- static int __cam_isp_ctx_reg_upd_in_epoch_bubble_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- if (ctx_isp->frame_id == 1)
- CAM_DBG(CAM_ISP, "Reg update in Substate[%s] for early PCR",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- else
- CAM_WARN(CAM_ISP,
- "Unexpected reg update in activated Substate[%s] for frame_id:%lld",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated),
- ctx_isp->frame_id);
- return 0;
- }
- static int __cam_isp_ctx_reg_upd_in_applied_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_ctx_request *req;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_ctx_req *req_isp;
- uint64_t request_id = 0;
- if (list_empty(&ctx->wait_req_list)) {
- CAM_ERR(CAM_ISP, "Reg upd ack with no waiting request");
- goto end;
- }
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (req_isp->num_fence_map_out != 0) {
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- request_id = req->request_id;
- CAM_DBG(CAM_REQ,
- "move request %lld to active list(cnt = %d), ctx %u",
- req->request_id, ctx_isp->active_req_cnt, ctx->ctx_id);
- } else {
- /* no io config, so the request is completed. */
- list_add_tail(&req->list, &ctx->free_req_list);
- CAM_DBG(CAM_ISP,
- "move active request %lld to free list(cnt = %d), ctx %u",
- req->request_id, ctx_isp->active_req_cnt, ctx->ctx_id);
- }
- /*
- * This function only called directly from applied and bubble applied
- * state so change substate here.
- */
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE, request_id);
- end:
- return rc;
- }
- static int __cam_isp_ctx_notify_sof_in_activated_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_req_mgr_trigger_notify notify;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- uint64_t request_id = 0;
- /*
- * notify reqmgr with sof signal. Note, due to scheduling delay
- * we can run into situation that two active requests has already
- * be in the active queue while we try to do the notification.
- * In this case, we need to skip the current notification. This
- * helps the state machine to catch up the delay.
- */
- if (atomic_read(&ctx_isp->process_bubble)) {
- if (list_empty(&ctx->active_req_list)) {
- CAM_ERR(CAM_ISP,
- "No available active req in bubble");
- atomic_set(&ctx_isp->process_bubble, 0);
- rc = -EINVAL;
- return rc;
- }
- req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (ctx_isp->bubble_frame_cnt >= 1 &&
- req_isp->bubble_detected) {
- req_isp->num_acked = 0;
- ctx_isp->bubble_frame_cnt = 0;
- req_isp->bubble_detected = false;
- list_del_init(&req->list);
- list_add(&req->list, &ctx->pending_req_list);
- atomic_set(&ctx_isp->process_bubble, 0);
- ctx_isp->active_req_cnt--;
- CAM_DBG(CAM_REQ,
- "Move active req: %lld to pending list(cnt = %d) [bubble re-apply], ctx %u",
- req->request_id,
- ctx_isp->active_req_cnt, ctx->ctx_id);
- } else if (req_isp->bubble_detected) {
- ctx_isp->bubble_frame_cnt++;
- CAM_DBG(CAM_ISP,
- "Waiting on bufdone for bubble req: %lld, since frame_cnt = %lld",
- req->request_id, ctx_isp->bubble_frame_cnt);
- } else
- CAM_DBG(CAM_ISP, "Delayed bufdone for req: %lld",
- req->request_id);
- }
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger &&
- ctx_isp->active_req_cnt <= 2) {
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld ctx %u",
- ctx_isp->frame_id, ctx->ctx_id);
- }
- list_for_each_entry(req, &ctx->active_req_list, list) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- break;
- }
- }
- if (ctx_isp->substate_activated == CAM_ISP_CTX_ACTIVATED_BUBBLE)
- request_id = 0;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH,
- request_id);
- } else {
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "Can not notify SOF to CRM for ctx %u",
- ctx->ctx_id);
- rc = -EFAULT;
- }
- return 0;
- }
- static int __cam_isp_ctx_notify_eof_in_activated_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_req_mgr_trigger_notify notify;
- struct cam_context *ctx = ctx_isp->base;
- if (!(ctx_isp->subscribe_event & CAM_TRIGGER_POINT_EOF))
- return rc;
- /* notify reqmgr with eof signal */
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_EOF;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM EOF frame %lld ctx %u",
- ctx_isp->frame_id, ctx->ctx_id);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_EOF, 0);
- } else {
- CAM_ERR(CAM_ISP, "Can not notify EOF to CRM for ctx %u",
- ctx->ctx_id);
- rc = -EFAULT;
- }
- return rc;
- }
- static int __cam_isp_ctx_reg_upd_in_hw_error(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- return 0;
- }
- static int __cam_isp_ctx_sof_in_activated_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- struct cam_ctx_request *req = NULL;
- struct cam_context *ctx = ctx_isp->base;
- uint64_t request_id = 0;
- /* First check if there is a valid request in active list */
- list_for_each_entry(req, &ctx->active_req_list, list) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- break;
- }
- }
- /*
- * If nothing in active list, current request might have not moved
- * from wait to active list. This could happen if REG_UPDATE to sw
- * is coming immediately after SOF
- */
- if (request_id == 0) {
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- if (req)
- request_id = req->request_id;
- }
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_SOF, request_id);
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx, ctx %u",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val, ctx->ctx_id);
- return rc;
- }
- static int __cam_isp_ctx_reg_upd_in_sof(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_ctx_request *req = NULL;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- if (ctx->state != CAM_CTX_ACTIVATED && ctx_isp->frame_id > 1) {
- CAM_DBG(CAM_ISP, "invalid RUP");
- goto end;
- }
- /*
- * This is for the first update. The initial setting will
- * cause the reg_upd in the first frame.
- */
- if (!list_empty(&ctx->wait_req_list)) {
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (req_isp->num_fence_map_out == req_isp->num_acked)
- list_add_tail(&req->list, &ctx->free_req_list);
- else
- CAM_ERR(CAM_ISP,
- "receive rup in unexpected state");
- }
- if (req != NULL) {
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
- req->request_id);
- }
- end:
- return rc;
- }
- static int __cam_isp_ctx_epoch_in_applied(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- uint64_t request_id = 0;
- if (list_empty(&ctx->wait_req_list)) {
- /*
- * If no wait req in epoch, this is an error case.
- * The recovery is to go back to sof state
- */
- CAM_ERR(CAM_ISP, "Ctx:%d No wait request", ctx->ctx_id);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- /* Send SOF event as empty frame*/
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- goto end;
- }
- req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request,
- list);
- req_isp = (struct cam_isp_ctx_req *)req->req_priv;
- req_isp->bubble_detected = true;
- req_isp->reapply = true;
- CAM_INFO(CAM_ISP, "ctx:%d Report Bubble flag %d req id:%lld",
- ctx->ctx_id, req_isp->bubble_report, req->request_id);
- if (req_isp->bubble_report && ctx->ctx_crm_intf &&
- ctx->ctx_crm_intf->notify_err) {
- struct cam_req_mgr_error_notify notify;
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.req_id = req->request_id;
- notify.error = CRM_KMD_ERR_BUBBLE;
- notify.trigger = 0;
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF)
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.frame_id = ctx_isp->frame_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- CAM_WARN(CAM_ISP,
- "Notify CRM about Bubble req %lld frame %lld, ctx %u",
- req->request_id, ctx_isp->frame_id, ctx->ctx_id);
- ctx->ctx_crm_intf->notify_err(¬ify);
- atomic_set(&ctx_isp->process_bubble, 1);
- } else {
- req_isp->bubble_report = 0;
- }
- /*
- * Always move the request to active list. Let buf done
- * function handles the rest.
- */
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- CAM_DBG(CAM_REQ, "move request %lld to active list(cnt = %d), ctx %u",
- req->request_id, ctx_isp->active_req_cnt, ctx->ctx_id);
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- }
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_ERROR);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- end:
- if (request_id == 0) {
- req = list_last_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, req->request_id);
- } else {
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, request_id);
- }
- return 0;
- }
- static int __cam_isp_ctx_buf_done_in_applied(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_done_event_data *done =
- (struct cam_isp_hw_done_event_data *) evt_data;
- rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0);
- return rc;
- }
- static int __cam_isp_ctx_sof_in_epoch(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- struct cam_ctx_request *req;
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- if (list_empty(&ctx->active_req_list))
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- else
- CAM_DBG(CAM_ISP, "Still need to wait for the buf done");
- req = list_last_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- if (req)
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_SOF,
- req->request_id);
- if (ctx_isp->frame_id == 1)
- CAM_INFO(CAM_ISP,
- "First SOF in EPCR ctx:%d frame_id:%lld next substate %s",
- ctx->ctx_id, ctx_isp->frame_id,
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- CAM_DBG(CAM_ISP, "SOF in epoch ctx:%d frame_id:%lld next substate:%s",
- ctx->ctx_id, ctx_isp->frame_id,
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- return rc;
- }
- static int __cam_isp_ctx_buf_done_in_epoch(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_done_event_data *done =
- (struct cam_isp_hw_done_event_data *) evt_data;
- rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0);
- return rc;
- }
- static int __cam_isp_ctx_buf_done_in_bubble(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_done_event_data *done =
- (struct cam_isp_hw_done_event_data *) evt_data;
- rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1);
- return rc;
- }
- static int __cam_isp_ctx_epoch_in_bubble_applied(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- uint64_t request_id = 0;
- /*
- * This means we missed the reg upd ack. So we need to
- * transition to BUBBLE state again.
- */
- if (list_empty(&ctx->wait_req_list)) {
- /*
- * If no pending req in epoch, this is an error case.
- * Just go back to the bubble state.
- */
- CAM_ERR(CAM_ISP, "ctx:%d No pending request.", ctx->ctx_id);
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE;
- goto end;
- }
- req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request,
- list);
- req_isp = (struct cam_isp_ctx_req *)req->req_priv;
- req_isp->bubble_detected = true;
- CAM_INFO(CAM_ISP, "Ctx:%d Report Bubble flag %d req id:%lld",
- ctx->ctx_id, req_isp->bubble_report, req->request_id);
- req_isp->reapply = true;
- if (req_isp->bubble_report && ctx->ctx_crm_intf &&
- ctx->ctx_crm_intf->notify_err) {
- struct cam_req_mgr_error_notify notify;
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.req_id = req->request_id;
- notify.error = CRM_KMD_ERR_BUBBLE;
- notify.trigger = 0;
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF)
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.frame_id = ctx_isp->frame_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- CAM_WARN(CAM_REQ,
- "Notify CRM about Bubble req_id %llu frame %lld, ctx %u",
- req->request_id, ctx_isp->frame_id, ctx->ctx_id);
- ctx->ctx_crm_intf->notify_err(¬ify);
- atomic_set(&ctx_isp->process_bubble, 1);
- } else {
- req_isp->bubble_report = 0;
- }
- /*
- * Always move the request to active list. Let buf done
- * function handles the rest.
- */
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d) ctx %u",
- req->request_id, ctx_isp->active_req_cnt);
- if (!req_isp->bubble_report) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_ERROR);
- } else
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- } else
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- end:
- req = list_last_entry(&ctx->active_req_list, struct cam_ctx_request,
- list);
- if (req)
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH, req->request_id);
- return 0;
- }
- static int __cam_isp_ctx_buf_done_in_bubble_applied(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_done_event_data *done =
- (struct cam_isp_hw_done_event_data *) evt_data;
- rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 1);
- return rc;
- }
- static int __cam_isp_ctx_handle_error(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- uint32_t i = 0;
- bool found = 0;
- struct cam_ctx_request *req = NULL;
- struct cam_ctx_request *req_to_report = NULL;
- struct cam_ctx_request *req_to_dump = NULL;
- struct cam_ctx_request *req_temp;
- struct cam_isp_ctx_req *req_isp = NULL;
- struct cam_isp_ctx_req *req_isp_to_report = NULL;
- struct cam_req_mgr_error_notify notify = {};
- uint64_t error_request_id;
- struct cam_hw_fence_map_entry *fence_map_out = NULL;
- struct cam_req_mgr_message req_msg;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_hw_error_event_data *error_event_data =
- (struct cam_isp_hw_error_event_data *)evt_data;
- uint32_t error_type = error_event_data->error_type;
- CAM_DBG(CAM_ISP, "Enter error_type = %d", error_type);
- if ((error_type == CAM_ISP_HW_ERROR_OVERFLOW) ||
- (error_type == CAM_ISP_HW_ERROR_BUSIF_OVERFLOW) ||
- (error_type == CAM_ISP_HW_ERROR_VIOLATION)) {
- struct cam_hw_cmd_args hw_cmd_args;
- memset(&hw_cmd_args, 0, sizeof(hw_cmd_args));
- hw_cmd_args.ctxt_to_hw_map = ctx->ctxt_to_hw_map;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_REG_DUMP_ON_ERROR;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "Reg dump on error failed rc: %d", rc);
- rc = 0;
- }
- }
- /*
- * The error is likely caused by first request on the active list.
- * If active list is empty check wait list (maybe error hit as soon
- * as RUP and we handle error before RUP.
- */
- if (list_empty(&ctx->active_req_list)) {
- CAM_DBG(CAM_ISP,
- "handling error with no active request");
- if (list_empty(&ctx->wait_req_list)) {
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "Error with no active/wait request");
- goto end;
- } else {
- req_to_dump = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- }
- } else {
- req_to_dump = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- }
- req_isp = (struct cam_isp_ctx_req *) req_to_dump->req_priv;
- if (error_event_data->enable_req_dump)
- cam_isp_ctx_dump_req(req_isp);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_ERROR, req_to_dump->request_id);
- list_for_each_entry_safe(req, req_temp,
- &ctx->active_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (!req_isp->bubble_report) {
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- fence_map_out =
- &req_isp->fence_map_out[i];
- CAM_ERR(CAM_ISP,
- "req %llu, Sync fd 0x%x ctx %u",
- req->request_id,
- req_isp->fence_map_out[i].sync_id,
- ctx->ctx_id);
- if (req_isp->fence_map_out[i].sync_id != -1) {
- rc = cam_sync_signal(
- fence_map_out->sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- fence_map_out->sync_id = -1;
- }
- }
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->free_req_list);
- ctx_isp->active_req_cnt--;
- } else {
- found = 1;
- break;
- }
- }
- if (found)
- goto move_to_pending;
- list_for_each_entry_safe(req, req_temp,
- &ctx->wait_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (!req_isp->bubble_report) {
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- fence_map_out =
- &req_isp->fence_map_out[i];
- CAM_ERR(CAM_ISP,
- "req %llu, Sync fd 0x%x ctx %u",
- req->request_id,
- req_isp->fence_map_out[i].sync_id,
- ctx->ctx_id);
- if (req_isp->fence_map_out[i].sync_id != -1) {
- rc = cam_sync_signal(
- fence_map_out->sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- fence_map_out->sync_id = -1;
- }
- }
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->free_req_list);
- ctx_isp->active_req_cnt--;
- } else {
- found = 1;
- break;
- }
- }
- move_to_pending:
- /*
- * If bubble recovery is enabled on any request we need to move that
- * request and all the subsequent requests to the pending list.
- * Note:
- * We need to traverse the active list in reverse order and add
- * to head of pending list.
- * e.g. pending current state: 10, 11 | active current state: 8, 9
- * intermittent for loop iteration- pending: 9, 10, 11 | active: 8
- * final state - pending: 8, 9, 10, 11 | active: NULL
- */
- if (found) {
- list_for_each_entry_safe_reverse(req, req_temp,
- &ctx->active_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- list_del_init(&req->list);
- list_add(&req->list, &ctx->pending_req_list);
- ctx_isp->active_req_cnt--;
- }
- list_for_each_entry_safe_reverse(req, req_temp,
- &ctx->wait_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- list_del_init(&req->list);
- list_add(&req->list, &ctx->pending_req_list);
- ctx_isp->active_req_cnt--;
- }
- }
- end:
- do {
- if (list_empty(&ctx->pending_req_list)) {
- error_request_id = ctx_isp->last_applied_req_id;
- req_isp = NULL;
- break;
- }
- req = list_first_entry(&ctx->pending_req_list,
- struct cam_ctx_request, list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- error_request_id = ctx_isp->last_applied_req_id;
- if (req_isp->bubble_report) {
- req_to_report = req;
- req_isp_to_report = req_to_report->req_priv;
- break;
- }
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- if (req_isp->fence_map_out[i].sync_id != -1)
- rc = cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- req_isp->fence_map_out[i].sync_id = -1;
- }
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->free_req_list);
- } while (req->request_id < ctx_isp->last_applied_req_id);
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_err) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.req_id = error_request_id;
- notify.error = CRM_KMD_ERR_FATAL;
- if (req_isp_to_report && req_isp_to_report->bubble_report)
- if (error_event_data->recovery_enabled)
- notify.error = CRM_KMD_ERR_BUBBLE;
- CAM_WARN(CAM_ISP,
- "Notify CRM: req %lld, frame %lld ctx %u, error %d",
- error_request_id, ctx_isp->frame_id, ctx->ctx_id,
- notify.error);
- ctx->ctx_crm_intf->notify_err(¬ify);
- /*
- * Need to send error occurred in KMD
- * This will help UMD to take necessary action
- * and to dump relevant info
- */
- if (notify.error == CRM_KMD_ERR_FATAL) {
- req_msg.session_hdl = ctx_isp->base->session_hdl;
- req_msg.u.err_msg.device_hdl = ctx_isp->base->dev_hdl;
- req_msg.u.err_msg.error_type =
- CAM_REQ_MGR_ERROR_TYPE_RECOVERY;
- req_msg.u.err_msg.link_hdl = ctx_isp->base->link_hdl;
- req_msg.u.err_msg.request_id = error_request_id;
- req_msg.u.err_msg.resource_size = 0x0;
- if (cam_req_mgr_notify_message(&req_msg,
- V4L_EVENT_CAM_REQ_MGR_ERROR,
- V4L_EVENT_CAM_REQ_MGR_EVENT))
- CAM_ERR(CAM_ISP,
- "Error in notifying the error time for req id:%lld ctx %u",
- ctx_isp->last_applied_req_id,
- ctx->ctx_id);
- }
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HW_ERROR;
- } else {
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "Can not notify ERRROR to CRM for ctx %u",
- ctx->ctx_id);
- rc = -EFAULT;
- }
- CAM_DBG(CAM_ISP, "Exit");
- return rc;
- }
- static int __cam_isp_ctx_fs2_sof_in_sof_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- struct cam_ctx_request *req;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_req_mgr_trigger_notify notify;
- uint64_t request_id = 0;
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- if (!(list_empty(&ctx->wait_req_list)))
- goto end;
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger &&
- ctx_isp->active_req_cnt <= 2) {
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld",
- ctx_isp->frame_id);
- }
- list_for_each_entry(req, &ctx->active_req_list, list) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- break;
- }
- }
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_SOF, request_id);
- } else {
- CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM");
- rc = -EFAULT;
- }
- end:
- return rc;
- }
- static int __cam_isp_ctx_fs2_buf_done(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_isp_hw_done_event_data *done =
- (struct cam_isp_hw_done_event_data *) evt_data;
- struct cam_context *ctx = ctx_isp->base;
- int prev_active_req_cnt = 0;
- int curr_req_id = 0;
- struct cam_ctx_request *req;
- prev_active_req_cnt = ctx_isp->active_req_cnt;
- req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- if (req)
- curr_req_id = req->request_id;
- rc = __cam_isp_ctx_handle_buf_done_in_activated_state(ctx_isp, done, 0);
- if (prev_active_req_cnt == ctx_isp->active_req_cnt + 1) {
- if (list_empty(&ctx->wait_req_list) &&
- list_empty(&ctx->active_req_list)) {
- CAM_DBG(CAM_ISP, "No request, move to SOF");
- ctx_isp->substate_activated =
- CAM_ISP_CTX_ACTIVATED_SOF;
- if (ctx_isp->reported_req_id < curr_req_id) {
- ctx_isp->reported_req_id = curr_req_id;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp,
- curr_req_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- }
- }
- }
- return rc;
- }
- static int __cam_isp_ctx_fs2_buf_done_in_epoch(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- rc = __cam_isp_ctx_fs2_buf_done(ctx_isp, evt_data);
- return rc;
- }
- static int __cam_isp_ctx_fs2_buf_done_in_applied(
- struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- rc = __cam_isp_ctx_fs2_buf_done(ctx_isp, evt_data);
- return rc;
- }
- static int __cam_isp_ctx_fs2_reg_upd_in_sof(struct cam_isp_context *ctx_isp,
- void *evt_data)
- {
- int rc = 0;
- struct cam_ctx_request *req = NULL;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- if (ctx->state != CAM_CTX_ACTIVATED && ctx_isp->frame_id > 1) {
- CAM_DBG(CAM_ISP, "invalid RUP");
- goto end;
- }
- /*
- * This is for the first update. The initial setting will
- * cause the reg_upd in the first frame.
- */
- if (!list_empty(&ctx->wait_req_list)) {
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (req_isp->num_fence_map_out == req_isp->num_acked)
- list_add_tail(&req->list, &ctx->free_req_list);
- else
- CAM_ERR(CAM_ISP,
- "receive rup in unexpected state");
- }
- if (req != NULL) {
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
- req->request_id);
- }
- end:
- return rc;
- }
- static int __cam_isp_ctx_fs2_reg_upd_in_applied_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_ctx_request *req = NULL;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_ctx_req *req_isp;
- struct cam_req_mgr_trigger_notify notify;
- uint64_t request_id = 0;
- if (list_empty(&ctx->wait_req_list)) {
- CAM_ERR(CAM_ISP, "Reg upd ack with no waiting request");
- goto end;
- }
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (req_isp->num_fence_map_out != 0) {
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- CAM_DBG(CAM_REQ, "move request %lld to active list(cnt = %d)",
- req->request_id, ctx_isp->active_req_cnt);
- } else {
- /* no io config, so the request is completed. */
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- /*
- * This function only called directly from applied and bubble applied
- * state so change substate here.
- */
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH;
- if (req_isp->num_fence_map_out != 1)
- goto end;
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger &&
- ctx_isp->active_req_cnt <= 2) {
- list_for_each_entry(req, &ctx->active_req_list, list) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- break;
- }
- }
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld",
- ctx_isp->frame_id);
- }
- } else {
- CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM");
- rc = -EFAULT;
- }
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- end:
- if (req != NULL && !rc) {
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
- req->request_id);
- }
- return rc;
- }
- static struct cam_isp_ctx_irq_ops
- cam_isp_ctx_activated_state_machine_irq[CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_sof,
- __cam_isp_ctx_notify_sof_in_activated_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- NULL,
- },
- },
- /* APPLIED */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_applied_state,
- __cam_isp_ctx_epoch_in_applied,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_buf_done_in_applied,
- },
- },
- /* EPOCH */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_epoch,
- __cam_isp_ctx_reg_upd_in_epoch_bubble_state,
- __cam_isp_ctx_notify_sof_in_activated_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_buf_done_in_epoch,
- },
- },
- /* BUBBLE */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_epoch_bubble_state,
- __cam_isp_ctx_notify_sof_in_activated_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_buf_done_in_bubble,
- },
- },
- /* Bubble Applied */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_applied_state,
- __cam_isp_ctx_epoch_in_bubble_applied,
- NULL,
- __cam_isp_ctx_buf_done_in_bubble_applied,
- },
- },
- /* HW ERROR */
- {
- .irq_ops = {
- NULL,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_hw_error,
- NULL,
- NULL,
- NULL,
- },
- },
- /* HALT */
- {
- },
- };
- static struct cam_isp_ctx_irq_ops
- cam_isp_ctx_fs2_state_machine_irq[CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_fs2_sof_in_sof_state,
- __cam_isp_ctx_fs2_reg_upd_in_sof,
- __cam_isp_ctx_fs2_sof_in_sof_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- NULL,
- },
- },
- /* APPLIED */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_fs2_reg_upd_in_applied_state,
- __cam_isp_ctx_epoch_in_applied,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_fs2_buf_done_in_applied,
- },
- },
- /* EPOCH */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_epoch,
- __cam_isp_ctx_reg_upd_in_epoch_bubble_state,
- __cam_isp_ctx_notify_sof_in_activated_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_fs2_buf_done_in_epoch,
- },
- },
- /* BUBBLE */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_epoch_bubble_state,
- __cam_isp_ctx_notify_sof_in_activated_state,
- __cam_isp_ctx_notify_eof_in_activated_state,
- __cam_isp_ctx_buf_done_in_bubble,
- },
- },
- /* Bubble Applied */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_applied_state,
- __cam_isp_ctx_epoch_in_bubble_applied,
- NULL,
- __cam_isp_ctx_buf_done_in_bubble_applied,
- },
- },
- /* HW ERROR */
- {
- .irq_ops = {
- NULL,
- __cam_isp_ctx_sof_in_activated_state,
- __cam_isp_ctx_reg_upd_in_hw_error,
- NULL,
- NULL,
- NULL,
- },
- },
- /* HALT */
- {
- },
- };
- static int __cam_isp_ctx_apply_req_in_activated_state(
- struct cam_context *ctx, struct cam_req_mgr_apply_request *apply,
- enum cam_isp_ctx_activated_substate next_state)
- {
- int rc = 0;
- struct cam_ctx_request *req;
- struct cam_ctx_request *active_req = NULL;
- struct cam_isp_ctx_req *req_isp;
- struct cam_isp_ctx_req *active_req_isp;
- struct cam_isp_context *ctx_isp = NULL;
- struct cam_hw_config_args cfg;
- if (list_empty(&ctx->pending_req_list)) {
- CAM_ERR(CAM_ISP, "No available request for Apply id %lld",
- apply->request_id);
- rc = -EFAULT;
- goto end;
- }
- /*
- * When the pipeline has issue, the requests can be queued up in the
- * pipeline. In this case, we should reject the additional request.
- * The maximum number of request allowed to be outstanding is 2.
- *
- */
- ctx_isp = (struct cam_isp_context *) ctx->ctx_priv;
- if (atomic_read(&ctx_isp->process_bubble)) {
- CAM_INFO(CAM_ISP,
- "Processing bubble cannot apply Request Id %llu",
- apply->request_id);
- rc = -EAGAIN;
- goto end;
- }
- spin_lock_bh(&ctx->lock);
- req = list_first_entry(&ctx->pending_req_list, struct cam_ctx_request,
- list);
- spin_unlock_bh(&ctx->lock);
- /*
- * Check whether the request id is matching the tip, if not, this means
- * we are in the middle of the error handling. Need to reject this apply
- */
- if (req->request_id != apply->request_id) {
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "Invalid Request Id asking %llu existing %llu",
- apply->request_id, req->request_id);
- rc = -EFAULT;
- goto end;
- }
- CAM_DBG(CAM_REQ, "Apply request %lld in Substate[%s] ctx %u",
- req->request_id,
- __cam_isp_ctx_substate_val_to_type(ctx_isp->substate_activated),
- ctx->ctx_id);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (ctx_isp->active_req_cnt >= 2) {
- CAM_WARN(CAM_ISP,
- "Reject apply request (id %lld) due to congestion(cnt = %d) ctx %u",
- req->request_id,
- ctx_isp->active_req_cnt,
- ctx->ctx_id);
- spin_lock_bh(&ctx->lock);
- if (!list_empty(&ctx->active_req_list))
- active_req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- else
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "WARNING: should not happen (cnt = %d) but active_list empty",
- ctx_isp->active_req_cnt);
- spin_unlock_bh(&ctx->lock);
- if (active_req) {
- active_req_isp =
- (struct cam_isp_ctx_req *) active_req->req_priv;
- __cam_isp_ctx_handle_buf_done_fail_log(
- active_req->request_id, active_req_isp,
- ctx_isp->isp_device_type);
- }
- rc = -EFAULT;
- goto end;
- }
- req_isp->bubble_report = apply->report_if_bubble;
- cfg.ctxt_to_hw_map = ctx_isp->hw_ctx;
- cfg.request_id = req->request_id;
- cfg.hw_update_entries = req_isp->cfg;
- cfg.num_hw_update_entries = req_isp->num_cfg;
- cfg.priv = &req_isp->hw_update_data;
- cfg.init_packet = 0;
- cfg.reapply = req_isp->reapply;
- rc = ctx->hw_mgr_intf->hw_config(ctx->hw_mgr_intf->hw_mgr_priv, &cfg);
- if (rc) {
- CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not apply the configuration");
- } else {
- spin_lock_bh(&ctx->lock);
- ctx_isp->substate_activated = next_state;
- ctx_isp->last_applied_req_id = apply->request_id;
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->wait_req_list);
- CAM_DBG(CAM_ISP, "new substate Substate[%s], applied req %lld",
- __cam_isp_ctx_substate_val_to_type(next_state),
- ctx_isp->last_applied_req_id);
- spin_unlock_bh(&ctx->lock);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_APPLIED,
- req->request_id);
- }
- end:
- return rc;
- }
- static int __cam_isp_ctx_apply_req_in_sof(
- struct cam_context *ctx, struct cam_req_mgr_apply_request *apply)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "current Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply,
- CAM_ISP_CTX_ACTIVATED_APPLIED);
- CAM_DBG(CAM_ISP, "new Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (rc)
- CAM_DBG(CAM_ISP, "Apply failed in Substate[%s], rc %d",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), rc);
- return rc;
- }
- static int __cam_isp_ctx_apply_req_in_epoch(
- struct cam_context *ctx, struct cam_req_mgr_apply_request *apply)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "current Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply,
- CAM_ISP_CTX_ACTIVATED_APPLIED);
- CAM_DBG(CAM_ISP, "new Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (rc)
- CAM_DBG(CAM_ISP, "Apply failed in Substate[%s], rc %d",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), rc);
- return rc;
- }
- static int __cam_isp_ctx_apply_req_in_bubble(
- struct cam_context *ctx, struct cam_req_mgr_apply_request *apply)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "current Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply,
- CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED);
- CAM_DBG(CAM_ISP, "new Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (rc)
- CAM_DBG(CAM_ISP, "Apply failed in Substate[%s], rc %d",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), rc);
- return rc;
- }
- static int __cam_isp_ctx_flush_req(struct cam_context *ctx,
- struct list_head *req_list, struct cam_req_mgr_flush_request *flush_req)
- {
- int i, rc, tmp = 0;
- uint32_t cancel_req_id_found = 0;
- struct cam_ctx_request *req;
- struct cam_ctx_request *req_temp;
- struct cam_isp_ctx_req *req_isp;
- struct list_head flush_list;
- struct cam_isp_context *ctx_isp = NULL;
- ctx_isp = (struct cam_isp_context *) ctx->ctx_priv;
- INIT_LIST_HEAD(&flush_list);
- if (list_empty(req_list)) {
- CAM_DBG(CAM_ISP, "request list is empty");
- if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) {
- CAM_ERR(CAM_ISP, "no request to cancel");
- return -EINVAL;
- } else
- return 0;
- }
- CAM_DBG(CAM_REQ, "Flush [%u] in progress for req_id %llu",
- flush_req->type, flush_req->req_id);
- list_for_each_entry_safe(req, req_temp, req_list, list) {
- if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) {
- if (req->request_id != flush_req->req_id) {
- continue;
- } else {
- list_del_init(&req->list);
- list_add_tail(&req->list, &flush_list);
- cancel_req_id_found = 1;
- __cam_isp_ctx_update_state_monitor_array(
- ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH,
- req->request_id);
- break;
- }
- }
- list_del_init(&req->list);
- list_add_tail(&req->list, &flush_list);
- __cam_isp_ctx_update_state_monitor_array(ctx_isp,
- CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH, req->request_id);
- }
- list_for_each_entry_safe(req, req_temp, &flush_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- if (req_isp->fence_map_out[i].sync_id != -1) {
- CAM_DBG(CAM_ISP, "Flush req 0x%llx, fence %d",
- req->request_id,
- req_isp->fence_map_out[i].sync_id);
- rc = cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- if (rc) {
- tmp = req_isp->fence_map_out[i].sync_id;
- CAM_ERR_RATE_LIMIT(CAM_ISP,
- "signal fence %d failed", tmp);
- }
- req_isp->fence_map_out[i].sync_id = -1;
- }
- }
- req_isp->reapply = false;
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ &&
- !cancel_req_id_found)
- CAM_DBG(CAM_ISP,
- "Flush request id:%lld is not found in the list",
- flush_req->req_id);
- return 0;
- }
- static int __cam_isp_ctx_flush_req_in_top_state(
- struct cam_context *ctx,
- struct cam_req_mgr_flush_request *flush_req)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp;
- struct cam_isp_stop_args stop_isp;
- struct cam_hw_stop_args stop_args;
- struct cam_hw_reset_args reset_args;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_req_mgr_timer_notify timer;
- ctx_isp = (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "Flush pending list");
- spin_lock_bh(&ctx->lock);
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, flush_req);
- spin_unlock_bh(&ctx->lock);
- if (flush_req->type == CAM_REQ_MGR_FLUSH_TYPE_ALL) {
- if (ctx->state <= CAM_CTX_READY) {
- ctx->state = CAM_CTX_ACQUIRED;
- goto end;
- }
- spin_lock_bh(&ctx->lock);
- ctx->state = CAM_CTX_FLUSHED;
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HALT;
- spin_unlock_bh(&ctx->lock);
- CAM_INFO(CAM_ISP, "Last request id to flush is %lld",
- flush_req->req_id);
- ctx->last_flush_req = flush_req->req_id;
- memset(&hw_cmd_args, 0, sizeof(hw_cmd_args));
- hw_cmd_args.ctxt_to_hw_map = ctx->ctxt_to_hw_map;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_REG_DUMP_ON_FLUSH;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "Reg dump on flush failed rc: %d", rc);
- rc = 0;
- }
- stop_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- stop_isp.hw_stop_cmd = CAM_ISP_HW_STOP_IMMEDIATELY;
- stop_isp.stop_only = true;
- stop_args.args = (void *)&stop_isp;
- rc = ctx->hw_mgr_intf->hw_stop(ctx->hw_mgr_intf->hw_mgr_priv,
- &stop_args);
- if (rc)
- CAM_ERR(CAM_ISP, "Failed to stop HW in Flush rc: %d",
- rc);
- CAM_INFO(CAM_ISP, "Stop HW complete. Reset HW next.");
- CAM_DBG(CAM_ISP, "Flush wait and active lists");
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_timer) {
- timer.link_hdl = ctx->link_hdl;
- timer.dev_hdl = ctx->dev_hdl;
- timer.state = false;
- ctx->ctx_crm_intf->notify_timer(&timer);
- }
- spin_lock_bh(&ctx->lock);
- if (!list_empty(&ctx->wait_req_list))
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->wait_req_list,
- flush_req);
- if (!list_empty(&ctx->active_req_list))
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->active_req_list,
- flush_req);
- ctx_isp->active_req_cnt = 0;
- spin_unlock_bh(&ctx->lock);
- reset_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- rc = ctx->hw_mgr_intf->hw_reset(ctx->hw_mgr_intf->hw_mgr_priv,
- &reset_args);
- if (rc)
- CAM_ERR(CAM_ISP, "Failed to reset HW rc: %d", rc);
- ctx_isp->init_received = false;
- }
- end:
- ctx_isp->bubble_frame_cnt = 0;
- atomic_set(&ctx_isp->process_bubble, 0);
- return rc;
- }
- static int __cam_isp_ctx_flush_req_in_ready(
- struct cam_context *ctx,
- struct cam_req_mgr_flush_request *flush_req)
- {
- int rc = 0;
- CAM_DBG(CAM_ISP, "try to flush pending list");
- spin_lock_bh(&ctx->lock);
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, flush_req);
- /* if nothing is in pending req list, change state to acquire */
- if (list_empty(&ctx->pending_req_list))
- ctx->state = CAM_CTX_ACQUIRED;
- spin_unlock_bh(&ctx->lock);
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP, "Flush request in ready state. next state %d",
- ctx->state);
- return rc;
- }
- static struct cam_ctx_ops
- cam_isp_ctx_activated_state_machine[CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_sof,
- },
- .irq_ops = NULL,
- },
- /* APPLIED */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* EPOCH */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_epoch,
- },
- .irq_ops = NULL,
- },
- /* BUBBLE */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_bubble,
- },
- .irq_ops = NULL,
- },
- /* Bubble Applied */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HW ERROR */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HALT */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- };
- static struct cam_ctx_ops
- cam_isp_ctx_fs2_state_machine[CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_sof,
- },
- .irq_ops = NULL,
- },
- /* APPLIED */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* EPOCH */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_epoch,
- },
- .irq_ops = NULL,
- },
- /* BUBBLE */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_apply_req_in_bubble,
- },
- .irq_ops = NULL,
- },
- /* Bubble Applied */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HW ERROR */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HALT */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- };
- static int __cam_isp_ctx_rdi_only_sof_in_top_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- int rc = 0;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_req_mgr_trigger_notify notify;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- uint64_t request_id = 0;
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- /*
- * notify reqmgr with sof signal. Note, due to scheduling delay
- * we can run into situation that two active requests has already
- * be in the active queue while we try to do the notification.
- * In this case, we need to skip the current notification. This
- * helps the state machine to catch up the delay.
- */
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger &&
- ctx_isp->active_req_cnt <= 2) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld",
- ctx_isp->frame_id);
- /*
- * It is idle frame with out any applied request id, send
- * request id as zero
- */
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- } else {
- CAM_ERR_RATE_LIMIT(CAM_ISP, "Can not notify SOF to CRM");
- }
- if (list_empty(&ctx->active_req_list))
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- else
- CAM_DBG(CAM_ISP, "Still need to wait for the buf done");
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- return rc;
- }
- static int __cam_isp_ctx_rdi_only_sof_in_applied_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- return 0;
- }
- static int __cam_isp_ctx_rdi_only_sof_in_bubble_applied(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- uint64_t request_id = 0;
- /*
- * Sof in bubble applied state means, reg update not received.
- * before increment frame id and override time stamp value, send
- * the previous sof time stamp that got captured in the
- * sof in applied state.
- */
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- if (list_empty(&ctx->wait_req_list)) {
- /*
- * If no pending req in epoch, this is an error case.
- * The recovery is to go back to sof state
- */
- CAM_ERR(CAM_ISP, "No wait request");
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- /* Send SOF event as empty frame*/
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- goto end;
- }
- req = list_first_entry(&ctx->wait_req_list, struct cam_ctx_request,
- list);
- req_isp = (struct cam_isp_ctx_req *)req->req_priv;
- req_isp->bubble_detected = true;
- CAM_INFO(CAM_ISP, "Ctx:%d Report Bubble flag %d req id:%lld",
- ctx->ctx_id, req_isp->bubble_report, req->request_id);
- req_isp->reapply = true;
- if (req_isp->bubble_report && ctx->ctx_crm_intf &&
- ctx->ctx_crm_intf->notify_err) {
- struct cam_req_mgr_error_notify notify;
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.req_id = req->request_id;
- notify.error = CRM_KMD_ERR_BUBBLE;
- notify.trigger = 0;
- if (ctx_isp->subscribe_event & CAM_TRIGGER_POINT_SOF)
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.frame_id = ctx_isp->frame_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- CAM_WARN(CAM_ISP,
- "Notify CRM about Bubble req %lld frame %lld ctx %u",
- req->request_id,
- ctx_isp->frame_id,
- ctx->ctx_id);
- ctx->ctx_crm_intf->notify_err(¬ify);
- } else {
- req_isp->bubble_report = 0;
- }
- /*
- * Always move the request to active list. Let buf done
- * function handles the rest.
- */
- list_del_init(&req->list);
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- CAM_DBG(CAM_ISP, "move request %lld to active list(cnt = %d)",
- req->request_id, ctx_isp->active_req_cnt);
- if (!req_isp->bubble_report) {
- if (req->request_id > ctx_isp->reported_req_id) {
- request_id = req->request_id;
- ctx_isp->reported_req_id = request_id;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_ERROR);
- } else
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- } else
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- /* change the state to bubble, as reg update has not come */
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_BUBBLE;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- end:
- return 0;
- }
- static int __cam_isp_ctx_rdi_only_sof_in_bubble_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- uint32_t i;
- struct cam_ctx_request *req;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_req_mgr_trigger_notify notify;
- struct cam_isp_hw_sof_event_data *sof_event_data = evt_data;
- struct cam_isp_ctx_req *req_isp;
- uint64_t request_id = 0;
- if (!evt_data) {
- CAM_ERR(CAM_ISP, "in valid sof event data");
- return -EINVAL;
- }
- ctx_isp->frame_id++;
- ctx_isp->sof_timestamp_val = sof_event_data->timestamp;
- ctx_isp->boot_timestamp = sof_event_data->boot_time;
- CAM_DBG(CAM_ISP, "frame id: %lld time stamp:0x%llx",
- ctx_isp->frame_id, ctx_isp->sof_timestamp_val);
- /*
- * Signal all active requests with error and move the all the active
- * requests to free list
- */
- while (!list_empty(&ctx->active_req_list)) {
- req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d",
- req_isp->num_fence_map_out);
- for (i = 0; i < req_isp->num_fence_map_out; i++)
- if (req_isp->fence_map_out[i].sync_id != -1) {
- cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- }
- list_add_tail(&req->list, &ctx->free_req_list);
- ctx_isp->active_req_cnt--;
- }
- /* notify reqmgr with sof signal */
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) {
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld",
- ctx_isp->frame_id);
- } else {
- CAM_ERR(CAM_ISP, "Can not notify SOF to CRM");
- }
- /*
- * It is idle frame with out any applied request id, send
- * request id as zero
- */
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- return 0;
- }
- static int __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state(
- struct cam_isp_context *ctx_isp, void *evt_data)
- {
- struct cam_ctx_request *req;
- struct cam_context *ctx = ctx_isp->base;
- struct cam_isp_ctx_req *req_isp;
- struct cam_req_mgr_trigger_notify notify;
- uint64_t request_id = 0;
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_EPOCH;
- /* notify reqmgr with sof signal*/
- if (ctx->ctx_crm_intf && ctx->ctx_crm_intf->notify_trigger) {
- if (list_empty(&ctx->wait_req_list)) {
- CAM_ERR(CAM_ISP, "Reg upd ack with no waiting request");
- goto error;
- }
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- request_id =
- (req_isp->hw_update_data.packet_opcode_type ==
- CAM_ISP_PACKET_INIT_DEV) ?
- 0 : req->request_id;
- if (req_isp->num_fence_map_out != 0) {
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- CAM_DBG(CAM_ISP,
- "move request %lld to active list(cnt = %d)",
- req->request_id, ctx_isp->active_req_cnt);
- /* if packet has buffers, set correct request id */
- request_id = req->request_id;
- } else {
- /* no io config, so the request is completed. */
- list_add_tail(&req->list, &ctx->free_req_list);
- CAM_DBG(CAM_ISP,
- "move active req %lld to free list(cnt=%d)",
- req->request_id, ctx_isp->active_req_cnt);
- }
- notify.link_hdl = ctx->link_hdl;
- notify.dev_hdl = ctx->dev_hdl;
- notify.frame_id = ctx_isp->frame_id;
- notify.trigger = CAM_TRIGGER_POINT_SOF;
- notify.req_id = ctx_isp->req_info.last_bufdone_req_id;
- notify.sof_timestamp_val = ctx_isp->sof_timestamp_val;
- ctx->ctx_crm_intf->notify_trigger(¬ify);
- CAM_DBG(CAM_ISP, "Notify CRM SOF frame %lld",
- ctx_isp->frame_id);
- } else {
- CAM_ERR(CAM_ISP, "Can not notify SOF to CRM");
- }
- if (request_id)
- ctx_isp->reported_req_id = request_id;
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- return 0;
- error:
- /* Send SOF event as idle frame*/
- __cam_isp_ctx_send_sof_timestamp(ctx_isp, request_id,
- CAM_REQ_MGR_SOF_EVENT_SUCCESS);
- /*
- * There is no request in the pending list, move the sub state machine
- * to SOF sub state
- */
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- return 0;
- }
- static struct cam_isp_ctx_irq_ops
- cam_isp_ctx_rdi_only_activated_state_machine_irq
- [CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .irq_ops = {
- NULL,
- __cam_isp_ctx_rdi_only_sof_in_top_state,
- __cam_isp_ctx_reg_upd_in_sof,
- NULL,
- NULL,
- NULL,
- },
- },
- /* APPLIED */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_rdi_only_sof_in_applied_state,
- NULL,
- NULL,
- NULL,
- __cam_isp_ctx_buf_done_in_applied,
- },
- },
- /* EPOCH */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_rdi_only_sof_in_top_state,
- NULL,
- NULL,
- NULL,
- __cam_isp_ctx_buf_done_in_epoch,
- },
- },
- /* BUBBLE*/
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_rdi_only_sof_in_bubble_state,
- NULL,
- NULL,
- NULL,
- __cam_isp_ctx_buf_done_in_bubble,
- },
- },
- /* BUBBLE APPLIED ie PRE_BUBBLE */
- {
- .irq_ops = {
- __cam_isp_ctx_handle_error,
- __cam_isp_ctx_rdi_only_sof_in_bubble_applied,
- __cam_isp_ctx_rdi_only_reg_upd_in_bubble_applied_state,
- NULL,
- NULL,
- __cam_isp_ctx_buf_done_in_bubble_applied,
- },
- },
- /* HW ERROR */
- {
- },
- /* HALT */
- {
- },
- };
- static int __cam_isp_ctx_rdi_only_apply_req_top_state(
- struct cam_context *ctx, struct cam_req_mgr_apply_request *apply)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "current Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- rc = __cam_isp_ctx_apply_req_in_activated_state(ctx, apply,
- CAM_ISP_CTX_ACTIVATED_APPLIED);
- CAM_DBG(CAM_ISP, "new Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (rc)
- CAM_ERR(CAM_ISP, "Apply failed in Substate[%s], rc %d",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), rc);
- return rc;
- }
- static struct cam_ctx_ops
- cam_isp_ctx_rdi_only_activated_state_machine
- [CAM_ISP_CTX_ACTIVATED_MAX] = {
- /* SOF */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state,
- },
- .irq_ops = NULL,
- },
- /* APPLIED */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* EPOCH */
- {
- .ioctl_ops = {},
- .crm_ops = {
- .apply_req = __cam_isp_ctx_rdi_only_apply_req_top_state,
- },
- .irq_ops = NULL,
- },
- /* PRE BUBBLE */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* BUBBLE */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HW ERROR */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* HALT */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- };
- static int __cam_isp_ctx_release_hw_in_top_state(struct cam_context *ctx,
- void *cmd)
- {
- int rc = 0;
- struct cam_hw_release_args rel_arg;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_req_mgr_flush_request flush_req;
- if (ctx_isp->hw_ctx) {
- rel_arg.ctxt_to_hw_map = ctx_isp->hw_ctx;
- ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv,
- &rel_arg);
- ctx_isp->hw_ctx = NULL;
- } else {
- CAM_ERR(CAM_ISP, "No hw resources acquired for this ctx");
- }
- ctx->last_flush_req = 0;
- ctx_isp->frame_id = 0;
- ctx_isp->active_req_cnt = 0;
- ctx_isp->reported_req_id = 0;
- ctx_isp->hw_acquired = false;
- ctx_isp->init_received = false;
- ctx_isp->req_info.last_bufdone_req_id = 0;
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- /*
- * Ideally, we should never have any active request here.
- * But we still add some sanity check code here to help the debug
- */
- if (!list_empty(&ctx->active_req_list))
- CAM_WARN(CAM_ISP, "Active list is not empty");
- /* Flush all the pending request list */
- flush_req.type = CAM_REQ_MGR_FLUSH_TYPE_ALL;
- flush_req.link_hdl = ctx->link_hdl;
- flush_req.dev_hdl = ctx->dev_hdl;
- CAM_DBG(CAM_ISP, "try to flush pending list");
- spin_lock_bh(&ctx->lock);
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, &flush_req);
- spin_unlock_bh(&ctx->lock);
- ctx->state = CAM_CTX_ACQUIRED;
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP, "Release device success[%u] next state %d",
- ctx->ctx_id, ctx->state);
- return rc;
- }
- /* top level state machine */
- static int __cam_isp_ctx_release_dev_in_top_state(struct cam_context *ctx,
- struct cam_release_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_hw_release_args rel_arg;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_req_mgr_flush_request flush_req;
- if (cmd && ctx_isp->hw_ctx) {
- CAM_ERR(CAM_ISP, "releasing hw");
- __cam_isp_ctx_release_hw_in_top_state(ctx, NULL);
- }
- if (ctx_isp->hw_ctx) {
- rel_arg.ctxt_to_hw_map = ctx_isp->hw_ctx;
- ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv,
- &rel_arg);
- ctx_isp->hw_ctx = NULL;
- }
- ctx->session_hdl = -1;
- ctx->dev_hdl = -1;
- ctx->link_hdl = -1;
- ctx->ctx_crm_intf = NULL;
- ctx->last_flush_req = 0;
- ctx_isp->frame_id = 0;
- ctx_isp->active_req_cnt = 0;
- ctx_isp->reported_req_id = 0;
- ctx_isp->hw_acquired = false;
- ctx_isp->init_received = false;
- ctx_isp->rdi_only_context = false;
- ctx_isp->req_info.last_bufdone_req_id = 0;
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- /*
- * Ideally, we should never have any active request here.
- * But we still add some sanity check code here to help the debug
- */
- if (!list_empty(&ctx->active_req_list))
- CAM_ERR(CAM_ISP, "Active list is not empty");
- /* Flush all the pending request list */
- flush_req.type = CAM_REQ_MGR_FLUSH_TYPE_ALL;
- flush_req.link_hdl = ctx->link_hdl;
- flush_req.dev_hdl = ctx->dev_hdl;
- CAM_DBG(CAM_ISP, "try to flush pending list");
- spin_lock_bh(&ctx->lock);
- rc = __cam_isp_ctx_flush_req(ctx, &ctx->pending_req_list, &flush_req);
- spin_unlock_bh(&ctx->lock);
- ctx->state = CAM_CTX_AVAILABLE;
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP, "Release device success[%u] next state %d",
- ctx->ctx_id, ctx->state);
- return rc;
- }
- static int __cam_isp_ctx_config_dev_in_top_state(
- struct cam_context *ctx, struct cam_config_dev_cmd *cmd)
- {
- int rc = 0, i;
- struct cam_ctx_request *req = NULL;
- struct cam_isp_ctx_req *req_isp;
- uintptr_t packet_addr;
- struct cam_packet *packet;
- size_t len = 0;
- size_t remain_len = 0;
- struct cam_hw_prepare_update_args cfg;
- struct cam_req_mgr_add_request add_req;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- uint32_t packet_opcode = 0;
- CAM_DBG(CAM_ISP, "get free request object......");
- /* get free request */
- spin_lock_bh(&ctx->lock);
- if (!list_empty(&ctx->free_req_list)) {
- req = list_first_entry(&ctx->free_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- }
- spin_unlock_bh(&ctx->lock);
- if (!req) {
- CAM_ERR(CAM_ISP, "No more request obj free");
- return -ENOMEM;
- }
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- /* for config dev, only memory handle is supported */
- /* map packet from the memhandle */
- rc = cam_mem_get_cpu_buf((int32_t) cmd->packet_handle,
- &packet_addr, &len);
- if (rc != 0) {
- CAM_ERR(CAM_ISP, "Can not get packet address");
- rc = -EINVAL;
- goto free_req;
- }
- remain_len = len;
- if ((len < sizeof(struct cam_packet)) ||
- ((size_t)cmd->offset >= len - sizeof(struct cam_packet))) {
- CAM_ERR(CAM_ISP, "invalid buff length: %zu or offset", len);
- rc = -EINVAL;
- goto free_req;
- }
- remain_len -= (size_t)cmd->offset;
- packet = (struct cam_packet *)(packet_addr + (uint32_t)cmd->offset);
- CAM_DBG(CAM_ISP, "pack_handle %llx", cmd->packet_handle);
- CAM_DBG(CAM_ISP, "packet address is 0x%zx", packet_addr);
- CAM_DBG(CAM_ISP, "packet with length %zu, offset 0x%llx",
- len, cmd->offset);
- CAM_DBG(CAM_ISP, "Packet request id %lld",
- packet->header.request_id);
- CAM_DBG(CAM_ISP, "Packet size 0x%x", packet->header.size);
- CAM_DBG(CAM_ISP, "packet op %d", packet->header.op_code);
- /* Query the packet opcode */
- hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_GET_PACKET_OPCODE;
- isp_hw_cmd_args.cmd_data = (void *)packet;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "HW command failed");
- goto free_req;
- }
- packet_opcode = isp_hw_cmd_args.u.packet_op_code;
- CAM_DBG(CAM_ISP, "packet op %d", packet_opcode);
- if ((packet_opcode == CAM_ISP_PACKET_UPDATE_DEV)
- && (packet->header.request_id <= ctx->last_flush_req)) {
- CAM_INFO(CAM_ISP,
- "request %lld has been flushed, reject packet",
- packet->header.request_id);
- rc = -EBADR;
- goto free_req;
- }
- /* preprocess the configuration */
- memset(&cfg, 0, sizeof(cfg));
- cfg.packet = packet;
- cfg.remain_len = remain_len;
- cfg.ctxt_to_hw_map = ctx_isp->hw_ctx;
- cfg.max_hw_update_entries = CAM_ISP_CTX_CFG_MAX;
- cfg.hw_update_entries = req_isp->cfg;
- cfg.max_out_map_entries = CAM_ISP_CTX_RES_MAX;
- cfg.max_in_map_entries = CAM_ISP_CTX_RES_MAX;
- cfg.out_map_entries = req_isp->fence_map_out;
- cfg.in_map_entries = req_isp->fence_map_in;
- cfg.priv = &req_isp->hw_update_data;
- cfg.pf_data = &(req->pf_data);
- CAM_DBG(CAM_ISP, "try to prepare config packet......");
- rc = ctx->hw_mgr_intf->hw_prepare_update(
- ctx->hw_mgr_intf->hw_mgr_priv, &cfg);
- if (rc != 0) {
- CAM_ERR(CAM_ISP, "Prepare config packet failed in HW layer");
- rc = -EFAULT;
- goto free_req;
- }
- req_isp->num_cfg = cfg.num_hw_update_entries;
- req_isp->num_fence_map_out = cfg.num_out_map_entries;
- req_isp->num_fence_map_in = cfg.num_in_map_entries;
- req_isp->num_acked = 0;
- req_isp->bubble_detected = false;
- for (i = 0; i < req_isp->num_fence_map_out; i++) {
- rc = cam_sync_get_obj_ref(req_isp->fence_map_out[i].sync_id);
- if (rc) {
- CAM_ERR(CAM_ISP, "Can't get ref for fence %d",
- req_isp->fence_map_out[i].sync_id);
- goto put_ref;
- }
- }
- CAM_DBG(CAM_ISP, "num_entry: %d, num fence out: %d, num fence in: %d",
- req_isp->num_cfg, req_isp->num_fence_map_out,
- req_isp->num_fence_map_in);
- req->request_id = packet->header.request_id;
- req->status = 1;
- CAM_DBG(CAM_ISP, "Packet request id %lld packet opcode:%d",
- packet->header.request_id,
- req_isp->hw_update_data.packet_opcode_type);
- if (req_isp->hw_update_data.packet_opcode_type ==
- CAM_ISP_PACKET_INIT_DEV) {
- if (ctx->state < CAM_CTX_ACTIVATED) {
- rc = __cam_isp_ctx_enqueue_init_request(ctx, req);
- if (rc)
- CAM_ERR(CAM_ISP, "Enqueue INIT pkt failed");
- ctx_isp->init_received = true;
- } else {
- rc = -EINVAL;
- CAM_ERR(CAM_ISP, "Recevied INIT pkt in wrong state:%d",
- ctx->state);
- }
- } else {
- if (ctx->state != CAM_CTX_FLUSHED && ctx->state >= CAM_CTX_READY
- && ctx->ctx_crm_intf->add_req) {
- add_req.link_hdl = ctx->link_hdl;
- add_req.dev_hdl = ctx->dev_hdl;
- add_req.req_id = req->request_id;
- add_req.skip_before_applying = 0;
- rc = ctx->ctx_crm_intf->add_req(&add_req);
- if (rc) {
- CAM_ERR(CAM_ISP, "Add req failed: req id=%llu",
- req->request_id);
- } else {
- __cam_isp_ctx_enqueue_request_in_order(
- ctx, req);
- }
- } else {
- rc = -EINVAL;
- CAM_ERR(CAM_ISP,
- "Recevied update req %lld in wrong state:%d",
- req->request_id, ctx->state);
- }
- }
- if (rc)
- goto put_ref;
- CAM_DBG(CAM_REQ,
- "Preprocessing Config req_id %lld successful on ctx %u",
- req->request_id, ctx->ctx_id);
- return rc;
- put_ref:
- for (--i; i >= 0; i--) {
- if (cam_sync_put_obj_ref(req_isp->fence_map_out[i].sync_id))
- CAM_ERR(CAM_CTXT, "Failed to put ref of fence %d",
- req_isp->fence_map_out[i].sync_id);
- }
- free_req:
- spin_lock_bh(&ctx->lock);
- list_add_tail(&req->list, &ctx->free_req_list);
- spin_unlock_bh(&ctx->lock);
- return rc;
- }
- static int __cam_isp_ctx_acquire_dev_in_available(struct cam_context *ctx,
- struct cam_acquire_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_hw_acquire_args param;
- struct cam_isp_resource *isp_res = NULL;
- struct cam_create_dev_hdl req_hdl_param;
- struct cam_hw_release_args release;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- if (!ctx->hw_mgr_intf) {
- CAM_ERR(CAM_ISP, "HW interface is not ready");
- rc = -EFAULT;
- goto end;
- }
- CAM_DBG(CAM_ISP,
- "session_hdl 0x%x, num_resources %d, hdl type %d, res %lld",
- cmd->session_handle, cmd->num_resources,
- cmd->handle_type, cmd->resource_hdl);
- if (cmd->num_resources == CAM_API_COMPAT_CONSTANT) {
- ctx_isp->split_acquire = true;
- CAM_DBG(CAM_ISP, "Acquire dev handle");
- goto get_dev_handle;
- }
- if (cmd->num_resources > CAM_ISP_CTX_RES_MAX) {
- CAM_ERR(CAM_ISP, "Too much resources in the acquire");
- rc = -ENOMEM;
- goto end;
- }
- /* for now we only support user pointer */
- if (cmd->handle_type != 1) {
- CAM_ERR(CAM_ISP, "Only user pointer is supported");
- rc = -EINVAL;
- goto end;
- }
- isp_res = kzalloc(
- sizeof(*isp_res)*cmd->num_resources, GFP_KERNEL);
- if (!isp_res) {
- rc = -ENOMEM;
- goto end;
- }
- CAM_DBG(CAM_ISP, "start copy %d resources from user",
- cmd->num_resources);
- if (copy_from_user(isp_res, u64_to_user_ptr(cmd->resource_hdl),
- sizeof(*isp_res)*cmd->num_resources)) {
- rc = -EFAULT;
- goto free_res;
- }
- param.context_data = ctx;
- param.event_cb = ctx->irq_cb_intf;
- param.num_acq = cmd->num_resources;
- param.acquire_info = (uintptr_t) isp_res;
- /* call HW manager to reserve the resource */
- rc = ctx->hw_mgr_intf->hw_acquire(ctx->hw_mgr_intf->hw_mgr_priv,
- ¶m);
- if (rc != 0) {
- CAM_ERR(CAM_ISP, "Acquire device failed");
- goto free_res;
- }
- /* Query the context has rdi only resource */
- hw_cmd_args.ctxt_to_hw_map = param.ctxt_to_hw_map;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_CTX_TYPE;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "HW command failed");
- goto free_hw;
- }
- if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_RDI) {
- /*
- * this context has rdi only resource assign rdi only
- * state machine
- */
- CAM_DBG(CAM_ISP, "RDI only session Context");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_rdi_only_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_rdi_only_activated_state_machine;
- ctx_isp->rdi_only_context = true;
- } else if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_FS2) {
- CAM_DBG(CAM_ISP, "FS2 Session has PIX ,RD and RDI");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_fs2_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_fs2_state_machine;
- } else {
- CAM_DBG(CAM_ISP, "Session has PIX or PIX and RDI resources");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_activated_state_machine;
- }
- ctx_isp->hw_ctx = param.ctxt_to_hw_map;
- ctx_isp->hw_acquired = true;
- ctx_isp->split_acquire = false;
- ctx->ctxt_to_hw_map = param.ctxt_to_hw_map;
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- kfree(isp_res);
- isp_res = NULL;
- get_dev_handle:
- req_hdl_param.session_hdl = cmd->session_handle;
- /* bridge is not ready for these flags. so false for now */
- req_hdl_param.v4l2_sub_dev_flag = 0;
- req_hdl_param.media_entity_flag = 0;
- req_hdl_param.ops = ctx->crm_ctx_intf;
- req_hdl_param.priv = ctx;
- CAM_DBG(CAM_ISP, "get device handle form bridge");
- ctx->dev_hdl = cam_create_device_hdl(&req_hdl_param);
- if (ctx->dev_hdl <= 0) {
- rc = -EFAULT;
- CAM_ERR(CAM_ISP, "Can not create device handle");
- goto free_hw;
- }
- cmd->dev_handle = ctx->dev_hdl;
- /* store session information */
- ctx->session_hdl = cmd->session_handle;
- ctx->state = CAM_CTX_ACQUIRED;
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP,
- "Acquire success on session_hdl 0x%x num_rsrces %d ctx %u",
- cmd->session_handle, cmd->num_resources, ctx->ctx_id);
- return rc;
- free_hw:
- release.ctxt_to_hw_map = ctx_isp->hw_ctx;
- if (ctx_isp->hw_acquired)
- ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv,
- &release);
- ctx_isp->hw_ctx = NULL;
- ctx_isp->hw_acquired = false;
- free_res:
- kfree(isp_res);
- end:
- return rc;
- }
- static int __cam_isp_ctx_acquire_hw_v1(struct cam_context *ctx,
- void *args)
- {
- int rc = 0;
- struct cam_acquire_hw_cmd_v1 *cmd =
- (struct cam_acquire_hw_cmd_v1 *)args;
- struct cam_hw_acquire_args param;
- struct cam_hw_release_args release;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_acquire_hw_info *acquire_hw_info = NULL;
- if (!ctx->hw_mgr_intf) {
- CAM_ERR(CAM_ISP, "HW interface is not ready");
- rc = -EFAULT;
- goto end;
- }
- CAM_DBG(CAM_ISP,
- "session_hdl 0x%x, hdl type %d, res %lld",
- cmd->session_handle, cmd->handle_type, cmd->resource_hdl);
- /* for now we only support user pointer */
- if (cmd->handle_type != 1) {
- CAM_ERR(CAM_ISP, "Only user pointer is supported");
- rc = -EINVAL;
- goto end;
- }
- if (cmd->data_size < sizeof(*acquire_hw_info)) {
- CAM_ERR(CAM_ISP, "data_size is not a valid value");
- goto end;
- }
- acquire_hw_info = kzalloc(cmd->data_size, GFP_KERNEL);
- if (!acquire_hw_info) {
- rc = -ENOMEM;
- goto end;
- }
- CAM_DBG(CAM_ISP, "start copy resources from user");
- if (copy_from_user(acquire_hw_info, (void __user *)cmd->resource_hdl,
- cmd->data_size)) {
- rc = -EFAULT;
- goto free_res;
- }
- memset(¶m, 0, sizeof(param));
- param.context_data = ctx;
- param.event_cb = ctx->irq_cb_intf;
- param.num_acq = CAM_API_COMPAT_CONSTANT;
- param.acquire_info_size = cmd->data_size;
- param.acquire_info = (uint64_t) acquire_hw_info;
- /* call HW manager to reserve the resource */
- rc = ctx->hw_mgr_intf->hw_acquire(ctx->hw_mgr_intf->hw_mgr_priv,
- ¶m);
- if (rc != 0) {
- CAM_ERR(CAM_ISP, "Acquire device failed");
- goto free_res;
- }
- /* Query the context has rdi only resource */
- hw_cmd_args.ctxt_to_hw_map = param.ctxt_to_hw_map;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_CTX_TYPE;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "HW command failed");
- goto free_hw;
- }
- if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_RDI) {
- /*
- * this context has rdi only resource assign rdi only
- * state machine
- */
- CAM_DBG(CAM_ISP, "RDI only session Context");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_rdi_only_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_rdi_only_activated_state_machine;
- ctx_isp->rdi_only_context = true;
- } else if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_FS2) {
- CAM_DBG(CAM_ISP, "FS2 Session has PIX ,RD and RDI");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_fs2_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_fs2_state_machine;
- } else {
- CAM_DBG(CAM_ISP, "Session has PIX or PIX and RDI resources");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_activated_state_machine;
- }
- ctx_isp->hw_ctx = param.ctxt_to_hw_map;
- ctx_isp->hw_acquired = true;
- ctx->ctxt_to_hw_map = param.ctxt_to_hw_map;
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP,
- "Acquire success on session_hdl 0x%xs ctx_type %d ctx_id %u",
- ctx->session_hdl, isp_hw_cmd_args.u.ctx_type, ctx->ctx_id);
- kfree(acquire_hw_info);
- return rc;
- free_hw:
- release.ctxt_to_hw_map = ctx_isp->hw_ctx;
- ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, &release);
- ctx_isp->hw_ctx = NULL;
- ctx_isp->hw_acquired = false;
- free_res:
- kfree(acquire_hw_info);
- end:
- return rc;
- }
- static int __cam_isp_ctx_acquire_hw_v2(struct cam_context *ctx,
- void *args)
- {
- int rc = 0, i, j;
- struct cam_acquire_hw_cmd_v2 *cmd =
- (struct cam_acquire_hw_cmd_v2 *)args;
- struct cam_hw_acquire_args param;
- struct cam_hw_release_args release;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_acquire_hw_info *acquire_hw_info = NULL;
- if (!ctx->hw_mgr_intf) {
- CAM_ERR(CAM_ISP, "HW interface is not ready");
- rc = -EFAULT;
- goto end;
- }
- CAM_DBG(CAM_ISP,
- "session_hdl 0x%x, hdl type %d, res %lld",
- cmd->session_handle, cmd->handle_type, cmd->resource_hdl);
- /* for now we only support user pointer */
- if (cmd->handle_type != 1) {
- CAM_ERR(CAM_ISP, "Only user pointer is supported");
- rc = -EINVAL;
- goto end;
- }
- if (cmd->data_size < sizeof(*acquire_hw_info)) {
- CAM_ERR(CAM_ISP, "data_size is not a valid value");
- goto end;
- }
- acquire_hw_info = kzalloc(cmd->data_size, GFP_KERNEL);
- if (!acquire_hw_info) {
- rc = -ENOMEM;
- goto end;
- }
- CAM_DBG(CAM_ISP, "start copy resources from user");
- if (copy_from_user(acquire_hw_info, (void __user *)cmd->resource_hdl,
- cmd->data_size)) {
- rc = -EFAULT;
- goto free_res;
- }
- memset(¶m, 0, sizeof(param));
- param.context_data = ctx;
- param.event_cb = ctx->irq_cb_intf;
- param.num_acq = CAM_API_COMPAT_CONSTANT;
- param.acquire_info_size = cmd->data_size;
- param.acquire_info = (uint64_t) acquire_hw_info;
- /* call HW manager to reserve the resource */
- rc = ctx->hw_mgr_intf->hw_acquire(ctx->hw_mgr_intf->hw_mgr_priv,
- ¶m);
- if (rc != 0) {
- CAM_ERR(CAM_ISP, "Acquire device failed");
- goto free_res;
- }
- /* Query the context has rdi only resource */
- hw_cmd_args.ctxt_to_hw_map = param.ctxt_to_hw_map;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_CTX_TYPE;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "HW command failed");
- goto free_hw;
- }
- if (param.valid_acquired_hw) {
- for (i = 0; i < CAM_MAX_ACQ_RES; i++)
- cmd->hw_info.acquired_hw_id[i] =
- param.acquired_hw_id[i];
- for (i = 0; i < CAM_MAX_ACQ_RES; i++)
- for (j = 0; j < CAM_MAX_HW_SPLIT; j++)
- cmd->hw_info.acquired_hw_path[i][j] =
- param.acquired_hw_path[i][j];
- }
- cmd->hw_info.valid_acquired_hw =
- param.valid_acquired_hw;
- cmd->hw_info.valid_acquired_hw = param.valid_acquired_hw;
- if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_RDI) {
- /*
- * this context has rdi only resource assign rdi only
- * state machine
- */
- CAM_DBG(CAM_ISP, "RDI only session Context");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_rdi_only_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_rdi_only_activated_state_machine;
- ctx_isp->rdi_only_context = true;
- } else if (isp_hw_cmd_args.u.ctx_type == CAM_ISP_CTX_FS2) {
- CAM_DBG(CAM_ISP, "FS2 Session has PIX ,RD and RDI");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_fs2_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_fs2_state_machine;
- } else {
- CAM_DBG(CAM_ISP, "Session has PIX or PIX and RDI resources");
- ctx_isp->substate_machine_irq =
- cam_isp_ctx_activated_state_machine_irq;
- ctx_isp->substate_machine =
- cam_isp_ctx_activated_state_machine;
- }
- ctx_isp->hw_ctx = param.ctxt_to_hw_map;
- ctx_isp->hw_acquired = true;
- ctx->ctxt_to_hw_map = param.ctxt_to_hw_map;
- trace_cam_context_state("ISP", ctx);
- CAM_DBG(CAM_ISP,
- "Acquire success on session_hdl 0x%xs ctx_type %d ctx_id %u",
- ctx->session_hdl, isp_hw_cmd_args.u.ctx_type, ctx->ctx_id);
- kfree(acquire_hw_info);
- return rc;
- free_hw:
- release.ctxt_to_hw_map = ctx_isp->hw_ctx;
- ctx->hw_mgr_intf->hw_release(ctx->hw_mgr_intf->hw_mgr_priv, &release);
- ctx_isp->hw_ctx = NULL;
- ctx_isp->hw_acquired = false;
- free_res:
- kfree(acquire_hw_info);
- end:
- return rc;
- }
- static int __cam_isp_ctx_acquire_hw_in_acquired(struct cam_context *ctx,
- void *args)
- {
- int rc = -EINVAL;
- uint32_t api_version;
- if (!ctx || !args) {
- CAM_ERR(CAM_ISP, "Invalid input pointer");
- return rc;
- }
- api_version = *((uint32_t *)args);
- if (api_version == 1)
- rc = __cam_isp_ctx_acquire_hw_v1(ctx, args);
- else if (api_version == 2)
- rc = __cam_isp_ctx_acquire_hw_v2(ctx, args);
- else
- CAM_ERR(CAM_ISP, "Unsupported api version %d", api_version);
- return rc;
- }
- static int __cam_isp_ctx_config_dev_in_acquired(struct cam_context *ctx,
- struct cam_config_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- if (!ctx_isp->hw_acquired) {
- CAM_ERR(CAM_ISP, "HW is not acquired, reject packet");
- return -EINVAL;
- }
- rc = __cam_isp_ctx_config_dev_in_top_state(ctx, cmd);
- if (!rc && (ctx->link_hdl >= 0)) {
- ctx->state = CAM_CTX_READY;
- trace_cam_context_state("ISP", ctx);
- }
- CAM_DBG(CAM_ISP, "next state %d", ctx->state);
- return rc;
- }
- static int __cam_isp_ctx_config_dev_in_flushed(struct cam_context *ctx,
- struct cam_config_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_start_stop_dev_cmd start_cmd;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- if (!ctx_isp->hw_acquired) {
- CAM_ERR(CAM_ISP, "HW is not acquired, reject packet");
- rc = -EINVAL;
- goto end;
- }
- rc = __cam_isp_ctx_config_dev_in_top_state(ctx, cmd);
- if (rc)
- goto end;
- if (!ctx_isp->init_received) {
- CAM_WARN(CAM_ISP,
- "Received update packet in flushed state, skip start");
- goto end;
- }
- hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_RESUME_HW;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- if (rc) {
- CAM_ERR(CAM_ISP, "Failed to resume HW rc: %d", rc);
- goto end;
- }
- start_cmd.dev_handle = cmd->dev_handle;
- start_cmd.session_handle = cmd->session_handle;
- rc = __cam_isp_ctx_start_dev_in_ready(ctx, &start_cmd);
- if (rc)
- CAM_ERR(CAM_ISP,
- "Failed to re-start HW after flush rc: %d", rc);
- else
- CAM_INFO(CAM_ISP,
- "Received init after flush. Re-start HW complete.");
- end:
- CAM_DBG(CAM_ISP, "next state %d sub_state:%d", ctx->state,
- ctx_isp->substate_activated);
- return rc;
- }
- static int __cam_isp_ctx_link_in_acquired(struct cam_context *ctx,
- struct cam_req_mgr_core_dev_link_setup *link)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- CAM_DBG(CAM_ISP, "Enter.........");
- ctx->link_hdl = link->link_hdl;
- ctx->ctx_crm_intf = link->crm_cb;
- ctx_isp->subscribe_event = link->subscribe_event;
- /* change state only if we had the init config */
- if (ctx_isp->init_received) {
- ctx->state = CAM_CTX_READY;
- trace_cam_context_state("ISP", ctx);
- }
- CAM_DBG(CAM_ISP, "next state %d", ctx->state);
- return rc;
- }
- static int __cam_isp_ctx_unlink_in_acquired(struct cam_context *ctx,
- struct cam_req_mgr_core_dev_link_setup *unlink)
- {
- int rc = 0;
- ctx->link_hdl = -1;
- ctx->ctx_crm_intf = NULL;
- return rc;
- }
- static int __cam_isp_ctx_get_dev_info_in_acquired(struct cam_context *ctx,
- struct cam_req_mgr_device_info *dev_info)
- {
- int rc = 0;
- dev_info->dev_hdl = ctx->dev_hdl;
- strlcpy(dev_info->name, CAM_ISP_DEV_NAME, sizeof(dev_info->name));
- dev_info->dev_id = CAM_REQ_MGR_DEVICE_IFE;
- dev_info->p_delay = 1;
- dev_info->trigger = CAM_TRIGGER_POINT_SOF;
- return rc;
- }
- static int __cam_isp_ctx_start_dev_in_ready(struct cam_context *ctx,
- struct cam_start_stop_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_isp_start_args start_isp;
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- if (cmd->session_handle != ctx->session_hdl ||
- cmd->dev_handle != ctx->dev_hdl) {
- rc = -EPERM;
- goto end;
- }
- if (list_empty(&ctx->pending_req_list)) {
- /* should never happen */
- CAM_ERR(CAM_ISP, "Start device with empty configuration");
- rc = -EFAULT;
- goto end;
- } else {
- req = list_first_entry(&ctx->pending_req_list,
- struct cam_ctx_request, list);
- }
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- if (!ctx_isp->hw_ctx) {
- CAM_ERR(CAM_ISP, "Wrong hw context pointer.");
- rc = -EFAULT;
- goto end;
- }
- start_isp.hw_config.ctxt_to_hw_map = ctx_isp->hw_ctx;
- start_isp.hw_config.request_id = req->request_id;
- start_isp.hw_config.hw_update_entries = req_isp->cfg;
- start_isp.hw_config.num_hw_update_entries = req_isp->num_cfg;
- start_isp.hw_config.priv = &req_isp->hw_update_data;
- start_isp.hw_config.init_packet = 1;
- start_isp.hw_config.reapply = 0;
- ctx_isp->last_applied_req_id = req->request_id;
- if (ctx->state == CAM_CTX_FLUSHED)
- start_isp.start_only = true;
- else
- start_isp.start_only = false;
- atomic_set(&ctx_isp->process_bubble, 0);
- ctx_isp->frame_id = 0;
- ctx_isp->active_req_cnt = 0;
- ctx_isp->reported_req_id = 0;
- ctx_isp->bubble_frame_cnt = 0;
- ctx_isp->substate_activated = ctx_isp->rdi_only_context ?
- CAM_ISP_CTX_ACTIVATED_APPLIED :
- (req_isp->num_fence_map_out) ? CAM_ISP_CTX_ACTIVATED_EPOCH :
- CAM_ISP_CTX_ACTIVATED_SOF;
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- /*
- * In case of CSID TPG we might receive SOF and RUP IRQs
- * before hw_mgr_intf->hw_start has returned. So move
- * req out of pending list before hw_start and add it
- * back to pending list if hw_start fails.
- */
- list_del_init(&req->list);
- if (ctx_isp->rdi_only_context || !req_isp->num_fence_map_out) {
- list_add_tail(&req->list, &ctx->wait_req_list);
- } else {
- list_add_tail(&req->list, &ctx->active_req_list);
- ctx_isp->active_req_cnt++;
- }
- /*
- * Only place to change state before calling the hw due to
- * hardware tasklet has higher priority that can cause the
- * irq handling comes early
- */
- ctx->state = CAM_CTX_ACTIVATED;
- trace_cam_context_state("ISP", ctx);
- rc = ctx->hw_mgr_intf->hw_start(ctx->hw_mgr_intf->hw_mgr_priv,
- &start_isp);
- if (rc) {
- /* HW failure. user need to clean up the resource */
- CAM_ERR(CAM_ISP, "Start HW failed");
- ctx->state = CAM_CTX_READY;
- trace_cam_context_state("ISP", ctx);
- if (rc == -ETIMEDOUT)
- cam_isp_ctx_dump_req(req_isp);
- list_del_init(&req->list);
- list_add(&req->list, &ctx->pending_req_list);
- goto end;
- }
- CAM_DBG(CAM_ISP, "start device success ctx %u", ctx->ctx_id);
- end:
- return rc;
- }
- static int __cam_isp_ctx_unlink_in_ready(struct cam_context *ctx,
- struct cam_req_mgr_core_dev_link_setup *unlink)
- {
- int rc = 0;
- ctx->link_hdl = -1;
- ctx->ctx_crm_intf = NULL;
- ctx->state = CAM_CTX_ACQUIRED;
- trace_cam_context_state("ISP", ctx);
- return rc;
- }
- static int __cam_isp_ctx_stop_dev_in_activated_unlock(
- struct cam_context *ctx, struct cam_start_stop_dev_cmd *stop_cmd)
- {
- int rc = 0;
- uint32_t i;
- struct cam_hw_stop_args stop;
- struct cam_ctx_request *req;
- struct cam_isp_ctx_req *req_isp;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- struct cam_isp_stop_args stop_isp;
- /* stop hw first */
- if (ctx_isp->hw_ctx) {
- stop.ctxt_to_hw_map = ctx_isp->hw_ctx;
- if (stop_cmd)
- stop_isp.hw_stop_cmd =
- CAM_ISP_HW_STOP_AT_FRAME_BOUNDARY;
- else
- stop_isp.hw_stop_cmd = CAM_ISP_HW_STOP_IMMEDIATELY;
- stop_isp.stop_only = false;
- stop.args = (void *) &stop_isp;
- ctx->hw_mgr_intf->hw_stop(ctx->hw_mgr_intf->hw_mgr_priv,
- &stop);
- }
- /* Mask off all the incoming hardware events */
- spin_lock_bh(&ctx->lock);
- ctx_isp->substate_activated = CAM_ISP_CTX_ACTIVATED_HALT;
- spin_unlock_bh(&ctx->lock);
- CAM_DBG(CAM_ISP, "next Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (ctx->ctx_crm_intf &&
- ctx->ctx_crm_intf->notify_stop) {
- struct cam_req_mgr_notify_stop notify;
- notify.link_hdl = ctx->link_hdl;
- CAM_DBG(CAM_ISP,
- "Notify CRM about device stop ctx %u link 0x%x",
- ctx->ctx_id, ctx->link_hdl);
- ctx->ctx_crm_intf->notify_stop(¬ify);
- } else
- CAM_ERR(CAM_ISP, "cb not present");
- while (!list_empty(&ctx->pending_req_list)) {
- req = list_first_entry(&ctx->pending_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- CAM_DBG(CAM_ISP, "signal fence in pending list. fence num %d",
- req_isp->num_fence_map_out);
- for (i = 0; i < req_isp->num_fence_map_out; i++)
- if (req_isp->fence_map_out[i].sync_id != -1) {
- cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- }
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- while (!list_empty(&ctx->wait_req_list)) {
- req = list_first_entry(&ctx->wait_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- CAM_DBG(CAM_ISP, "signal fence in wait list. fence num %d",
- req_isp->num_fence_map_out);
- for (i = 0; i < req_isp->num_fence_map_out; i++)
- if (req_isp->fence_map_out[i].sync_id != -1) {
- cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- }
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- while (!list_empty(&ctx->active_req_list)) {
- req = list_first_entry(&ctx->active_req_list,
- struct cam_ctx_request, list);
- list_del_init(&req->list);
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- CAM_DBG(CAM_ISP, "signal fence in active list. fence num %d",
- req_isp->num_fence_map_out);
- for (i = 0; i < req_isp->num_fence_map_out; i++)
- if (req_isp->fence_map_out[i].sync_id != -1) {
- cam_sync_signal(
- req_isp->fence_map_out[i].sync_id,
- CAM_SYNC_STATE_SIGNALED_ERROR);
- }
- list_add_tail(&req->list, &ctx->free_req_list);
- }
- ctx_isp->frame_id = 0;
- ctx_isp->active_req_cnt = 0;
- ctx_isp->reported_req_id = 0;
- ctx_isp->bubble_frame_cnt = 0;
- ctx_isp->last_applied_req_id = 0;
- ctx_isp->req_info.last_bufdone_req_id = 0;
- atomic_set(&ctx_isp->process_bubble, 0);
- atomic64_set(&ctx_isp->state_monitor_head, -1);
- CAM_DBG(CAM_ISP, "Stop device success next state %d on ctx %u",
- ctx->state, ctx->ctx_id);
- if (!stop_cmd) {
- rc = __cam_isp_ctx_unlink_in_ready(ctx, NULL);
- if (rc)
- CAM_ERR(CAM_ISP, "Unlink failed rc=%d", rc);
- }
- return rc;
- }
- static int __cam_isp_ctx_stop_dev_in_activated(struct cam_context *ctx,
- struct cam_start_stop_dev_cmd *cmd)
- {
- int rc = 0;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *)ctx->ctx_priv;
- __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, cmd);
- ctx_isp->init_received = false;
- ctx->state = CAM_CTX_ACQUIRED;
- trace_cam_context_state("ISP", ctx);
- return rc;
- }
- static int __cam_isp_ctx_release_dev_in_activated(struct cam_context *ctx,
- struct cam_release_dev_cmd *cmd)
- {
- int rc = 0;
- rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, NULL);
- if (rc)
- CAM_ERR(CAM_ISP, "Stop device failed rc=%d", rc);
- rc = __cam_isp_ctx_release_dev_in_top_state(ctx, cmd);
- if (rc)
- CAM_ERR(CAM_ISP, "Release device failed rc=%d", rc);
- return rc;
- }
- static int __cam_isp_ctx_release_hw_in_activated(struct cam_context *ctx,
- void *cmd)
- {
- int rc = 0;
- rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, NULL);
- if (rc)
- CAM_ERR(CAM_ISP, "Stop device failed rc=%d", rc);
- rc = __cam_isp_ctx_release_hw_in_top_state(ctx, cmd);
- if (rc)
- CAM_ERR(CAM_ISP, "Release hw failed rc=%d", rc);
- return rc;
- }
- static int __cam_isp_ctx_link_pause(struct cam_context *ctx)
- {
- int rc = 0;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_PAUSE_HW;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- return rc;
- }
- static int __cam_isp_ctx_link_resume(struct cam_context *ctx)
- {
- int rc = 0;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_RESUME_HW;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- return rc;
- }
- static int __cam_isp_ctx_handle_sof_freeze_evt(
- struct cam_context *ctx)
- {
- int rc = 0;
- struct cam_hw_cmd_args hw_cmd_args;
- struct cam_isp_hw_cmd_args isp_hw_cmd_args;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- hw_cmd_args.ctxt_to_hw_map = ctx_isp->hw_ctx;
- hw_cmd_args.cmd_type = CAM_HW_MGR_CMD_INTERNAL;
- isp_hw_cmd_args.cmd_type = CAM_ISP_HW_MGR_CMD_SOF_DEBUG;
- isp_hw_cmd_args.u.sof_irq_enable = 1;
- hw_cmd_args.u.internal_args = (void *)&isp_hw_cmd_args;
- rc = ctx->hw_mgr_intf->hw_cmd(ctx->hw_mgr_intf->hw_mgr_priv,
- &hw_cmd_args);
- return rc;
- }
- static int __cam_isp_ctx_process_evt(struct cam_context *ctx,
- struct cam_req_mgr_link_evt_data *link_evt_data)
- {
- int rc = 0;
- switch (link_evt_data->evt_type) {
- case CAM_REQ_MGR_LINK_EVT_ERR:
- /* No need to handle this message now */
- break;
- case CAM_REQ_MGR_LINK_EVT_PAUSE:
- __cam_isp_ctx_link_pause(ctx);
- break;
- case CAM_REQ_MGR_LINK_EVT_RESUME:
- __cam_isp_ctx_link_resume(ctx);
- break;
- case CAM_REQ_MGR_LINK_EVT_SOF_FREEZE:
- __cam_isp_ctx_handle_sof_freeze_evt(ctx);
- break;
- default:
- CAM_WARN(CAM_ISP, "Unknown event from CRM");
- break;
- }
- return rc;
- }
- static int __cam_isp_ctx_unlink_in_activated(struct cam_context *ctx,
- struct cam_req_mgr_core_dev_link_setup *unlink)
- {
- int rc = 0;
- CAM_WARN(CAM_ISP,
- "Received unlink in activated state. It's unexpected");
- rc = __cam_isp_ctx_stop_dev_in_activated_unlock(ctx, NULL);
- if (rc)
- CAM_WARN(CAM_ISP, "Stop device failed rc=%d", rc);
- rc = __cam_isp_ctx_unlink_in_ready(ctx, unlink);
- if (rc)
- CAM_ERR(CAM_ISP, "Unlink failed rc=%d", rc);
- return rc;
- }
- static int __cam_isp_ctx_apply_req(struct cam_context *ctx,
- struct cam_req_mgr_apply_request *apply)
- {
- int rc = 0;
- struct cam_ctx_ops *ctx_ops = NULL;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *) ctx->ctx_priv;
- trace_cam_apply_req("ISP", apply->request_id);
- CAM_DBG(CAM_ISP, "Enter: apply req in Substate[%s] request_id:%lld",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), apply->request_id);
- ctx_ops = &ctx_isp->substate_machine[ctx_isp->substate_activated];
- if (ctx_ops->crm_ops.apply_req) {
- rc = ctx_ops->crm_ops.apply_req(ctx, apply);
- } else {
- CAM_WARN_RATE_LIMIT(CAM_ISP,
- "No handle function in activated Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- rc = -EFAULT;
- }
- if (rc)
- CAM_WARN_RATE_LIMIT(CAM_ISP,
- "Apply failed in active Substate[%s] rc %d",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), rc);
- return rc;
- }
- static int __cam_isp_ctx_handle_irq_in_activated(void *context,
- uint32_t evt_id, void *evt_data)
- {
- int rc = 0;
- struct cam_isp_ctx_irq_ops *irq_ops = NULL;
- struct cam_context *ctx = (struct cam_context *)context;
- struct cam_isp_context *ctx_isp =
- (struct cam_isp_context *)ctx->ctx_priv;
- spin_lock(&ctx->lock);
- trace_cam_isp_activated_irq(ctx, ctx_isp->substate_activated, evt_id,
- __cam_isp_ctx_get_event_ts(evt_id, evt_data));
- CAM_DBG(CAM_ISP, "Enter: State %d, Substate[%s], evt id %d",
- ctx->state, __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated), evt_id);
- irq_ops = &ctx_isp->substate_machine_irq[ctx_isp->substate_activated];
- if (irq_ops->irq_ops[evt_id]) {
- rc = irq_ops->irq_ops[evt_id](ctx_isp, evt_data);
- } else {
- CAM_DBG(CAM_ISP, "No handle function for Substate[%s]",
- __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- if (isp_ctx_debug.enable_state_monitor_dump)
- __cam_isp_ctx_dump_state_monitor_array(ctx_isp);
- }
- CAM_DBG(CAM_ISP, "Exit: State %d Substate[%s]",
- ctx->state, __cam_isp_ctx_substate_val_to_type(
- ctx_isp->substate_activated));
- spin_unlock(&ctx->lock);
- return rc;
- }
- /* top state machine */
- static struct cam_ctx_ops
- cam_isp_ctx_top_state_machine[CAM_CTX_STATE_MAX] = {
- /* Uninit */
- {
- .ioctl_ops = {},
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* Available */
- {
- .ioctl_ops = {
- .acquire_dev = __cam_isp_ctx_acquire_dev_in_available,
- },
- .crm_ops = {},
- .irq_ops = NULL,
- },
- /* Acquired */
- {
- .ioctl_ops = {
- .acquire_hw = __cam_isp_ctx_acquire_hw_in_acquired,
- .release_dev = __cam_isp_ctx_release_dev_in_top_state,
- .config_dev = __cam_isp_ctx_config_dev_in_acquired,
- .release_hw = __cam_isp_ctx_release_hw_in_top_state,
- },
- .crm_ops = {
- .link = __cam_isp_ctx_link_in_acquired,
- .unlink = __cam_isp_ctx_unlink_in_acquired,
- .get_dev_info = __cam_isp_ctx_get_dev_info_in_acquired,
- .flush_req = __cam_isp_ctx_flush_req_in_top_state,
- },
- .irq_ops = NULL,
- .pagefault_ops = cam_isp_context_dump_active_request,
- .dumpinfo_ops = cam_isp_context_info_dump,
- },
- /* Ready */
- {
- .ioctl_ops = {
- .start_dev = __cam_isp_ctx_start_dev_in_ready,
- .release_dev = __cam_isp_ctx_release_dev_in_top_state,
- .config_dev = __cam_isp_ctx_config_dev_in_top_state,
- .release_hw = __cam_isp_ctx_release_hw_in_top_state,
- },
- .crm_ops = {
- .unlink = __cam_isp_ctx_unlink_in_ready,
- .flush_req = __cam_isp_ctx_flush_req_in_ready,
- },
- .irq_ops = NULL,
- .pagefault_ops = cam_isp_context_dump_active_request,
- .dumpinfo_ops = cam_isp_context_info_dump,
- },
- /* Flushed */
- {
- .ioctl_ops = {
- .stop_dev = __cam_isp_ctx_stop_dev_in_activated,
- .release_dev = __cam_isp_ctx_release_dev_in_activated,
- .config_dev = __cam_isp_ctx_config_dev_in_flushed,
- .release_hw = __cam_isp_ctx_release_hw_in_activated,
- },
- .crm_ops = {
- .unlink = __cam_isp_ctx_unlink_in_ready,
- .process_evt = __cam_isp_ctx_process_evt,
- },
- .irq_ops = NULL,
- .pagefault_ops = cam_isp_context_dump_active_request,
- .dumpinfo_ops = cam_isp_context_info_dump,
- },
- /* Activated */
- {
- .ioctl_ops = {
- .stop_dev = __cam_isp_ctx_stop_dev_in_activated,
- .release_dev = __cam_isp_ctx_release_dev_in_activated,
- .config_dev = __cam_isp_ctx_config_dev_in_top_state,
- .release_hw = __cam_isp_ctx_release_hw_in_activated,
- },
- .crm_ops = {
- .unlink = __cam_isp_ctx_unlink_in_activated,
- .apply_req = __cam_isp_ctx_apply_req,
- .flush_req = __cam_isp_ctx_flush_req_in_top_state,
- .process_evt = __cam_isp_ctx_process_evt,
- },
- .irq_ops = __cam_isp_ctx_handle_irq_in_activated,
- .pagefault_ops = cam_isp_context_dump_active_request,
- .dumpinfo_ops = cam_isp_context_info_dump,
- },
- };
- static int cam_isp_context_dump_active_request(void *data, unsigned long iova,
- uint32_t buf_info)
- {
- struct cam_context *ctx = (struct cam_context *)data;
- struct cam_ctx_request *req = NULL;
- struct cam_ctx_request *req_temp = NULL;
- struct cam_isp_ctx_req *req_isp = NULL;
- struct cam_isp_prepare_hw_update_data *hw_update_data = NULL;
- struct cam_hw_mgr_dump_pf_data *pf_dbg_entry = NULL;
- bool mem_found = false;
- int rc = 0;
- struct cam_isp_context *isp_ctx =
- (struct cam_isp_context *)ctx->ctx_priv;
- if (!isp_ctx) {
- CAM_ERR(CAM_ISP, "Invalid isp ctx");
- return -EINVAL;
- }
- CAM_INFO(CAM_ISP, "iommu fault handler for isp ctx %d state %d",
- ctx->ctx_id, ctx->state);
- list_for_each_entry_safe(req, req_temp,
- &ctx->active_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- hw_update_data = &req_isp->hw_update_data;
- pf_dbg_entry = &(req->pf_data);
- CAM_INFO(CAM_ISP, "req_id : %lld ", req->request_id);
- rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry->packet,
- iova, buf_info, &mem_found);
- if (rc)
- CAM_ERR(CAM_ISP, "Failed to dump pf info");
- if (mem_found)
- CAM_ERR(CAM_ISP, "Found page fault in req %lld %d",
- req->request_id, rc);
- }
- CAM_INFO(CAM_ISP, "Iterating over wait_list of isp ctx %d state %d",
- ctx->ctx_id, ctx->state);
- list_for_each_entry_safe(req, req_temp,
- &ctx->wait_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- hw_update_data = &req_isp->hw_update_data;
- pf_dbg_entry = &(req->pf_data);
- CAM_INFO(CAM_ISP, "req_id : %lld ", req->request_id);
- rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry->packet,
- iova, buf_info, &mem_found);
- if (rc)
- CAM_ERR(CAM_ISP, "Failed to dump pf info");
- if (mem_found)
- CAM_ERR(CAM_ISP, "Found page fault in req %lld %d",
- req->request_id, rc);
- }
- /*
- * In certain scenarios we observe both overflow and SMMU pagefault
- * for a particular request. If overflow is handled before page fault
- * we need to traverse through pending request list because if
- * bubble recovery is enabled on any request we move that request
- * and all the subsequent requests to the pending list while handling
- * overflow error.
- */
- CAM_INFO(CAM_ISP,
- "Iterating over pending req list of isp ctx %d state %d",
- ctx->ctx_id, ctx->state);
- list_for_each_entry_safe(req, req_temp,
- &ctx->pending_req_list, list) {
- req_isp = (struct cam_isp_ctx_req *) req->req_priv;
- hw_update_data = &req_isp->hw_update_data;
- pf_dbg_entry = &(req->pf_data);
- CAM_INFO(CAM_ISP, "req_id : %lld ", req->request_id);
- rc = cam_context_dump_pf_info_to_hw(ctx, pf_dbg_entry->packet,
- iova, buf_info, &mem_found);
- if (rc)
- CAM_ERR(CAM_ISP, "Failed to dump pf info");
- if (mem_found)
- CAM_ERR(CAM_ISP, "Found page fault in req %lld %d",
- req->request_id, rc);
- }
- return rc;
- }
- static int cam_isp_context_debug_register(void)
- {
- isp_ctx_debug.dentry = debugfs_create_dir("camera_isp_ctx",
- NULL);
- if (!isp_ctx_debug.dentry) {
- CAM_ERR(CAM_ISP, "failed to create dentry");
- return -ENOMEM;
- }
- if (!debugfs_create_u32("enable_state_monitor_dump",
- 0644,
- isp_ctx_debug.dentry,
- &isp_ctx_debug.enable_state_monitor_dump)) {
- CAM_ERR(CAM_ISP, "failed to create enable_state_monitor_dump");
- goto err;
- }
- return 0;
- err:
- debugfs_remove_recursive(isp_ctx_debug.dentry);
- return -ENOMEM;
- }
- int cam_isp_context_init(struct cam_isp_context *ctx,
- struct cam_context *ctx_base,
- struct cam_req_mgr_kmd_ops *crm_node_intf,
- struct cam_hw_mgr_intf *hw_intf,
- uint32_t ctx_id,
- uint32_t isp_device_type)
- {
- int rc = -1;
- int i;
- if (!ctx || !ctx_base) {
- CAM_ERR(CAM_ISP, "Invalid Context");
- goto err;
- }
- /* ISP context setup */
- memset(ctx, 0, sizeof(*ctx));
- ctx->base = ctx_base;
- ctx->frame_id = 0;
- ctx->active_req_cnt = 0;
- ctx->reported_req_id = 0;
- ctx->req_info.last_bufdone_req_id = 0;
- ctx->bubble_frame_cnt = 0;
- ctx->hw_ctx = NULL;
- ctx->substate_activated = CAM_ISP_CTX_ACTIVATED_SOF;
- ctx->substate_machine = cam_isp_ctx_activated_state_machine;
- ctx->substate_machine_irq = cam_isp_ctx_activated_state_machine_irq;
- ctx->init_timestamp = jiffies_to_msecs(jiffies);
- ctx->isp_device_type = isp_device_type;
- for (i = 0; i < CAM_CTX_REQ_MAX; i++) {
- ctx->req_base[i].req_priv = &ctx->req_isp[i];
- ctx->req_isp[i].base = &ctx->req_base[i];
- }
- /* camera context setup */
- rc = cam_context_init(ctx_base, isp_dev_name, CAM_ISP, ctx_id,
- crm_node_intf, hw_intf, ctx->req_base, CAM_CTX_REQ_MAX);
- if (rc) {
- CAM_ERR(CAM_ISP, "Camera Context Base init failed");
- goto err;
- }
- /* link camera context with isp context */
- ctx_base->state_machine = cam_isp_ctx_top_state_machine;
- ctx_base->ctx_priv = ctx;
- /* initializing current state for error logging */
- for (i = 0; i < CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES; i++) {
- ctx->cam_isp_ctx_state_monitor[i].curr_state =
- CAM_ISP_CTX_ACTIVATED_MAX;
- }
- atomic64_set(&ctx->state_monitor_head, -1);
- cam_isp_context_debug_register();
- err:
- return rc;
- }
- int cam_isp_context_deinit(struct cam_isp_context *ctx)
- {
- int rc = 0;
- if (ctx->base)
- cam_context_deinit(ctx->base);
- if (ctx->substate_activated != CAM_ISP_CTX_ACTIVATED_SOF)
- CAM_ERR(CAM_ISP, "ISP context Substate[%s] is invalid",
- __cam_isp_ctx_substate_val_to_type(
- ctx->substate_activated));
- memset(ctx, 0, sizeof(*ctx));
- return rc;
- }
|