cam_cpas_hw.c 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/device.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/of.h>
  9. #include <linux/pm_opp.h>
  10. #include <linux/slab.h>
  11. #include <linux/module.h>
  12. #include "cam_cpas_hw.h"
  13. #include "cam_cpas_hw_intf.h"
  14. #include "cam_cpas_soc.h"
  15. #include "cam_req_mgr_dev.h"
  16. #include "cam_smmu_api.h"
  17. #include "cam_compat.h"
  18. #include "cam_mem_mgr_api.h"
  19. #include "cam_req_mgr_interface.h"
  20. #define CAM_CPAS_LOG_BUF_LEN 512
  21. #define CAM_CPAS_APPLY_TYPE_START 1
  22. #define CAM_CPAS_APPLY_TYPE_STOP 2
  23. #define CAM_CPAS_APPLY_TYPE_UPDATE 3
  24. static uint cam_min_camnoc_ib_bw;
  25. module_param(cam_min_camnoc_ib_bw, uint, 0644);
  26. static void cam_cpas_update_monitor_array(struct cam_hw_info *cpas_hw,
  27. const char *identifier_string, int32_t identifier_value);
  28. static void cam_cpas_dump_monitor_array(
  29. struct cam_hw_info *cpas_hw);
  30. static int cam_cpas_log_vote(struct cam_hw_info *cpas_hw, bool ddr_only);
  31. static struct cam_cpas_subpart_info g_cam_cpas_camera_subpart_info = {
  32. .num_bits = 8,
  33. /*
  34. * Below fuse indexing is based on software fuse definition which is in SMEM and provided
  35. * by XBL team.
  36. */
  37. .hw_bitmap_mask = {
  38. {CAM_CPAS_CAM_FUSE, BIT(0)},
  39. {CAM_CPAS_ISP_FUSE, BIT(0)},
  40. {CAM_CPAS_ISP_FUSE, BIT(1)},
  41. {CAM_CPAS_ISP_FUSE, BIT(2)},
  42. {CAM_CPAS_SFE_FUSE, BIT(0)},
  43. {CAM_CPAS_SFE_FUSE, BIT(1)},
  44. {CAM_CPAS_SFE_FUSE, BIT(2)},
  45. {CAM_CPAS_CUSTOM_FUSE, BIT(0)},
  46. }
  47. };
  48. static void cam_cpas_process_drv_bw_overrides(
  49. struct cam_cpas_bus_client *bus_client, uint64_t *high_ab, uint64_t *high_ib,
  50. uint64_t *low_ab, uint64_t *low_ib, const struct cam_cpas_debug_settings *cpas_settings)
  51. {
  52. uint64_t curr_ab_high = *high_ab;
  53. uint64_t curr_ib_high = *high_ib;
  54. uint64_t curr_ab_low = *low_ab;
  55. uint64_t curr_ib_low = *low_ib;
  56. size_t name_len = strlen(bus_client->common_data.name);
  57. if (!cpas_settings) {
  58. CAM_ERR(CAM_CPAS, "Invalid cpas debug settings");
  59. return;
  60. }
  61. if (strnstr(bus_client->common_data.name, "cam_ife_0_drv",
  62. name_len)) {
  63. if (cpas_settings->cam_ife_0_drv_ab_high_bw)
  64. *high_ab = cpas_settings->cam_ife_0_drv_ab_high_bw;
  65. if (cpas_settings->cam_ife_0_drv_ib_high_bw)
  66. *high_ib = cpas_settings->cam_ife_0_drv_ib_high_bw;
  67. if (cpas_settings->cam_ife_0_drv_ab_low_bw)
  68. *low_ab = cpas_settings->cam_ife_0_drv_ab_low_bw;
  69. if (cpas_settings->cam_ife_0_drv_ib_low_bw)
  70. *low_ib = cpas_settings->cam_ife_0_drv_ib_low_bw;
  71. if (cpas_settings->cam_ife_0_drv_low_set_zero) {
  72. *low_ab = 0;
  73. *low_ib = 0;
  74. }
  75. } else if (strnstr(bus_client->common_data.name, "cam_ife_1_drv",
  76. name_len)) {
  77. if (cpas_settings->cam_ife_1_drv_ab_high_bw)
  78. *high_ab = cpas_settings->cam_ife_1_drv_ab_high_bw;
  79. if (cpas_settings->cam_ife_1_drv_ib_high_bw)
  80. *high_ib = cpas_settings->cam_ife_1_drv_ib_high_bw;
  81. if (cpas_settings->cam_ife_1_drv_ab_low_bw)
  82. *low_ab = cpas_settings->cam_ife_1_drv_ab_low_bw;
  83. if (cpas_settings->cam_ife_1_drv_ib_low_bw)
  84. *low_ib = cpas_settings->cam_ife_1_drv_ib_low_bw;
  85. if (cpas_settings->cam_ife_1_drv_low_set_zero) {
  86. *low_ab = 0;
  87. *low_ib = 0;
  88. }
  89. } else if (strnstr(bus_client->common_data.name, "cam_ife_2_drv",
  90. name_len)) {
  91. if (cpas_settings->cam_ife_2_drv_ab_high_bw)
  92. *high_ab = cpas_settings->cam_ife_2_drv_ab_high_bw;
  93. if (cpas_settings->cam_ife_2_drv_ib_high_bw)
  94. *high_ib = cpas_settings->cam_ife_2_drv_ib_high_bw;
  95. if (cpas_settings->cam_ife_2_drv_ab_low_bw)
  96. *low_ab = cpas_settings->cam_ife_2_drv_ab_low_bw;
  97. if (cpas_settings->cam_ife_2_drv_ib_low_bw)
  98. *low_ib = cpas_settings->cam_ife_2_drv_ib_low_bw;
  99. if (cpas_settings->cam_ife_2_drv_low_set_zero) {
  100. *low_ab = 0;
  101. *low_ib = 0;
  102. }
  103. } else {
  104. CAM_ERR(CAM_CPAS, "unknown mnoc port: %s, bw override failed",
  105. bus_client->common_data.name);
  106. return;
  107. }
  108. CAM_INFO(CAM_CPAS,
  109. "Overriding mnoc bw for: %s with [AB IB] high: [%llu %llu], low: [%llu %llu], curr high: [%llu %llu], curr low: [%llu %llu]",
  110. bus_client->common_data.name, *high_ab, *high_ib, *low_ab, *low_ib,
  111. curr_ab_high, curr_ib_high, curr_ab_low, curr_ib_low);
  112. }
  113. static void cam_cpas_process_bw_overrides(
  114. struct cam_cpas_bus_client *bus_client, uint64_t *ab, uint64_t *ib,
  115. const struct cam_cpas_debug_settings *cpas_settings)
  116. {
  117. uint64_t curr_ab = *ab;
  118. uint64_t curr_ib = *ib;
  119. size_t name_len = strlen(bus_client->common_data.name);
  120. if (!cpas_settings) {
  121. CAM_ERR(CAM_CPAS, "Invalid cpas debug settings");
  122. return;
  123. }
  124. if (strnstr(bus_client->common_data.name, "cam_hf_0", name_len)) {
  125. if (cpas_settings->mnoc_hf_0_ab_bw)
  126. *ab = cpas_settings->mnoc_hf_0_ab_bw;
  127. if (cpas_settings->mnoc_hf_0_ib_bw)
  128. *ib = cpas_settings->mnoc_hf_0_ib_bw;
  129. } else if (strnstr(bus_client->common_data.name, "cam_hf_1",
  130. name_len)) {
  131. if (cpas_settings->mnoc_hf_1_ab_bw)
  132. *ab = cpas_settings->mnoc_hf_1_ab_bw;
  133. if (cpas_settings->mnoc_hf_1_ib_bw)
  134. *ib = cpas_settings->mnoc_hf_1_ib_bw;
  135. } else if (strnstr(bus_client->common_data.name, "cam_sf_0",
  136. name_len)) {
  137. if (cpas_settings->mnoc_sf_0_ab_bw)
  138. *ab = cpas_settings->mnoc_sf_0_ab_bw;
  139. if (cpas_settings->mnoc_sf_0_ib_bw)
  140. *ib = cpas_settings->mnoc_sf_0_ib_bw;
  141. } else if (strnstr(bus_client->common_data.name, "cam_sf_1",
  142. name_len)) {
  143. if (cpas_settings->mnoc_sf_1_ab_bw)
  144. *ab = cpas_settings->mnoc_sf_1_ab_bw;
  145. if (cpas_settings->mnoc_sf_1_ib_bw)
  146. *ib = cpas_settings->mnoc_sf_1_ib_bw;
  147. } else if (strnstr(bus_client->common_data.name, "cam_sf_icp",
  148. name_len)) {
  149. if (cpas_settings->mnoc_sf_icp_ab_bw)
  150. *ab = cpas_settings->mnoc_sf_icp_ab_bw;
  151. if (cpas_settings->mnoc_sf_icp_ib_bw)
  152. *ib = cpas_settings->mnoc_sf_icp_ib_bw;
  153. } else {
  154. CAM_ERR(CAM_CPAS, "unknown mnoc port: %s, bw override failed",
  155. bus_client->common_data.name);
  156. return;
  157. }
  158. CAM_INFO(CAM_CPAS,
  159. "Overriding mnoc bw for: %s with ab: %llu, ib: %llu, curr_ab: %llu, curr_ib: %llu",
  160. bus_client->common_data.name, *ab, *ib, curr_ab, curr_ib);
  161. }
  162. int cam_cpas_util_reg_read(struct cam_hw_info *cpas_hw,
  163. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info)
  164. {
  165. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  166. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  167. uint32_t value;
  168. int reg_base_index;
  169. if (!reg_info->enable)
  170. return 0;
  171. reg_base_index = cpas_core->regbase_index[reg_base];
  172. if (reg_base_index == -1)
  173. return -EINVAL;
  174. value = cam_io_r_mb(
  175. soc_info->reg_map[reg_base_index].mem_base + reg_info->offset);
  176. CAM_INFO(CAM_CPAS, "Base[%d] Offset[0x%08x] Value[0x%08x]",
  177. reg_base, reg_info->offset, value);
  178. return 0;
  179. }
  180. int cam_cpas_util_reg_update(struct cam_hw_info *cpas_hw,
  181. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info)
  182. {
  183. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  184. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  185. uint32_t value;
  186. int reg_base_index;
  187. if (reg_info->enable == false)
  188. return 0;
  189. reg_base_index = cpas_core->regbase_index[reg_base];
  190. if (reg_base_index == -1)
  191. return -EINVAL;
  192. if (reg_info->masked_value) {
  193. value = cam_io_r_mb(
  194. soc_info->reg_map[reg_base_index].mem_base +
  195. reg_info->offset);
  196. value = value & (~reg_info->mask);
  197. value = value | (reg_info->value << reg_info->shift);
  198. } else {
  199. value = reg_info->value;
  200. }
  201. CAM_DBG(CAM_CPAS, "Base[%d]:[0x%08x] Offset[0x%08x] Value[0x%08x]",
  202. reg_base, soc_info->reg_map[reg_base_index].mem_base, reg_info->offset, value);
  203. cam_io_w_mb(value, soc_info->reg_map[reg_base_index].mem_base +
  204. reg_info->offset);
  205. return 0;
  206. }
  207. static int cam_cpas_util_vote_bus_client_level(
  208. struct cam_cpas_bus_client *bus_client, unsigned int level)
  209. {
  210. int rc = 0;
  211. if (!bus_client->valid) {
  212. CAM_ERR(CAM_CPAS, "bus client not valid");
  213. rc = -EINVAL;
  214. goto end;
  215. }
  216. if (level >= CAM_MAX_VOTE) {
  217. CAM_ERR(CAM_CPAS,
  218. "Invalid votelevel=%d,usecases=%d,Bus client=[%s]",
  219. level, bus_client->common_data.num_usecases,
  220. bus_client->common_data.name);
  221. return -EINVAL;
  222. }
  223. if (level == bus_client->curr_vote_level)
  224. goto end;
  225. rc = cam_soc_bus_client_update_request(bus_client->soc_bus_client,
  226. level);
  227. if (rc) {
  228. CAM_ERR(CAM_CPAS, "Client: %s update request failed rc: %d",
  229. bus_client->common_data.name, rc);
  230. goto end;
  231. }
  232. bus_client->curr_vote_level = level;
  233. end:
  234. return rc;
  235. }
  236. static int cam_cpas_util_vote_drv_bus_client_bw(struct cam_cpas_bus_client *bus_client,
  237. struct cam_cpas_axi_bw_info *curr_vote, struct cam_cpas_axi_bw_info *applied_vote)
  238. {
  239. int rc = 0;
  240. const struct camera_debug_settings *cam_debug = NULL;
  241. if (!bus_client->valid) {
  242. CAM_ERR(CAM_CPAS, "bus client: %s not valid",
  243. bus_client->common_data.name);
  244. rc = -EINVAL;
  245. goto end;
  246. }
  247. mutex_lock(&bus_client->lock);
  248. if ((curr_vote->drv_vote.high.ab > 0) &&
  249. (curr_vote->drv_vote.high.ab < CAM_CPAS_AXI_MIN_MNOC_AB_BW))
  250. curr_vote->drv_vote.high.ab = CAM_CPAS_AXI_MIN_MNOC_AB_BW;
  251. if ((curr_vote->drv_vote.high.ib > 0) &&
  252. (curr_vote->drv_vote.high.ib < CAM_CPAS_AXI_MIN_MNOC_IB_BW))
  253. curr_vote->drv_vote.high.ib = CAM_CPAS_AXI_MIN_MNOC_IB_BW;
  254. if ((curr_vote->drv_vote.low.ab > 0) &&
  255. (curr_vote->drv_vote.low.ab < CAM_CPAS_AXI_MIN_MNOC_AB_BW))
  256. curr_vote->drv_vote.low.ab = CAM_CPAS_AXI_MIN_MNOC_AB_BW;
  257. if ((curr_vote->drv_vote.low.ib > 0) &&
  258. (curr_vote->drv_vote.low.ib < CAM_CPAS_AXI_MIN_MNOC_IB_BW))
  259. curr_vote->drv_vote.low.ib = CAM_CPAS_AXI_MIN_MNOC_IB_BW;
  260. cam_debug = cam_debug_get_settings();
  261. if ((curr_vote->drv_vote.high.ab || curr_vote->drv_vote.high.ib ||
  262. curr_vote->drv_vote.low.ab || curr_vote->drv_vote.low.ib) &&
  263. cam_debug && cam_debug->cpas_settings.is_updated)
  264. cam_cpas_process_drv_bw_overrides(bus_client, &curr_vote->drv_vote.high.ab,
  265. &curr_vote->drv_vote.high.ib, &curr_vote->drv_vote.low.ab,
  266. &curr_vote->drv_vote.low.ib, &cam_debug->cpas_settings);
  267. if (debug_drv)
  268. CAM_INFO(CAM_CPAS, "Bus_client: %s, DRV vote high=[%llu %llu] low=[%llu %llu]",
  269. bus_client->common_data.name, curr_vote->drv_vote.high.ab,
  270. curr_vote->drv_vote.high.ib, curr_vote->drv_vote.low.ab,
  271. curr_vote->drv_vote.low.ib);
  272. CAM_DBG(CAM_CPAS, "Bus_client: %s, DRV vote high=[%llu %llu] low=[%llu %llu]",
  273. bus_client->common_data.name, curr_vote->drv_vote.high.ab,
  274. curr_vote->drv_vote.high.ib, curr_vote->drv_vote.low.ab,
  275. curr_vote->drv_vote.low.ib);
  276. rc = cam_soc_bus_client_update_bw(bus_client->soc_bus_client, curr_vote->drv_vote.high.ab,
  277. curr_vote->drv_vote.high.ib, CAM_SOC_BUS_PATH_DATA_DRV_HIGH);
  278. if (rc) {
  279. CAM_ERR(CAM_CPAS, "Update bw failed, Bus path: %s ab[%llu] ib[%llu]",
  280. cam_soc_bus_path_data_to_str(CAM_SOC_BUS_PATH_DATA_DRV_HIGH),
  281. curr_vote->drv_vote.high.ab, curr_vote->drv_vote.high.ib);
  282. goto unlock_client;
  283. }
  284. rc = cam_soc_bus_client_update_bw(bus_client->soc_bus_client, curr_vote->drv_vote.low.ab,
  285. curr_vote->drv_vote.low.ib, CAM_SOC_BUS_PATH_DATA_DRV_LOW);
  286. if (rc) {
  287. CAM_ERR(CAM_CPAS, "Update bw failed, Bus path: %s ab[%llu] ib[%llu]",
  288. cam_soc_bus_path_data_to_str(CAM_SOC_BUS_PATH_DATA_DRV_LOW),
  289. curr_vote->drv_vote.low.ab, curr_vote->drv_vote.low.ib);
  290. goto unlock_client;
  291. }
  292. if (applied_vote)
  293. memcpy(applied_vote, curr_vote, sizeof(struct cam_cpas_axi_bw_info));
  294. unlock_client:
  295. mutex_unlock(&bus_client->lock);
  296. end:
  297. return rc;
  298. }
  299. static int cam_cpas_util_vote_hlos_bus_client_bw(
  300. struct cam_cpas_bus_client *bus_client, uint64_t ab, uint64_t ib,
  301. bool is_camnoc_bw, uint64_t *applied_ab, uint64_t *applied_ib)
  302. {
  303. int rc = 0;
  304. uint64_t min_camnoc_ib_bw = CAM_CPAS_AXI_MIN_CAMNOC_IB_BW;
  305. const struct camera_debug_settings *cam_debug = NULL;
  306. if (!bus_client->valid) {
  307. CAM_ERR(CAM_CPAS, "bus client: %s not valid",
  308. bus_client->common_data.name);
  309. rc = -EINVAL;
  310. goto end;
  311. }
  312. if (cam_min_camnoc_ib_bw > 0)
  313. min_camnoc_ib_bw = (uint64_t)cam_min_camnoc_ib_bw * 1000000L;
  314. CAM_DBG(CAM_CPAS,
  315. "Bus_client: %s, cam_min_camnoc_ib_bw = %d, min_camnoc_ib_bw=%llu",
  316. bus_client->common_data.name, cam_min_camnoc_ib_bw,
  317. min_camnoc_ib_bw);
  318. mutex_lock(&bus_client->lock);
  319. if (is_camnoc_bw) {
  320. if ((ab > 0) && (ab < CAM_CPAS_AXI_MIN_CAMNOC_AB_BW))
  321. ab = CAM_CPAS_AXI_MIN_CAMNOC_AB_BW;
  322. if ((ib > 0) && (ib < min_camnoc_ib_bw))
  323. ib = min_camnoc_ib_bw;
  324. } else {
  325. if ((ab > 0) && (ab < CAM_CPAS_AXI_MIN_MNOC_AB_BW))
  326. ab = CAM_CPAS_AXI_MIN_MNOC_AB_BW;
  327. if ((ib > 0) && (ib < CAM_CPAS_AXI_MIN_MNOC_IB_BW))
  328. ib = CAM_CPAS_AXI_MIN_MNOC_IB_BW;
  329. }
  330. cam_debug = cam_debug_get_settings();
  331. if ((ab || ib) && cam_debug && cam_debug->cpas_settings.is_updated)
  332. cam_cpas_process_bw_overrides(bus_client, &ab, &ib,
  333. &cam_debug->cpas_settings);
  334. rc = cam_soc_bus_client_update_bw(bus_client->soc_bus_client, ab, ib,
  335. CAM_SOC_BUS_PATH_DATA_HLOS);
  336. if (rc) {
  337. CAM_ERR(CAM_CPAS,
  338. "Update bw failed, Bus path %s ab[%llu] ib[%llu]",
  339. cam_soc_bus_path_data_to_str(CAM_SOC_BUS_PATH_DATA_HLOS), ab, ib);
  340. goto unlock_client;
  341. }
  342. if (applied_ab)
  343. *applied_ab = ab;
  344. if (applied_ib)
  345. *applied_ib = ib;
  346. unlock_client:
  347. mutex_unlock(&bus_client->lock);
  348. end:
  349. return rc;
  350. }
  351. static int cam_cpas_util_register_bus_client(
  352. struct cam_hw_soc_info *soc_info, struct device_node *dev_node,
  353. struct cam_cpas_bus_client *bus_client)
  354. {
  355. int rc = 0;
  356. rc = cam_soc_bus_client_register(soc_info->pdev, dev_node,
  357. &bus_client->soc_bus_client, &bus_client->common_data);
  358. if (rc) {
  359. CAM_ERR(CAM_CPAS, "Bus client: %s registertion failed ,rc: %d",
  360. bus_client->common_data.name, rc);
  361. return rc;
  362. }
  363. bus_client->curr_vote_level = 0;
  364. bus_client->valid = true;
  365. mutex_init(&bus_client->lock);
  366. return 0;
  367. }
  368. static int cam_cpas_util_unregister_bus_client(
  369. struct cam_cpas_bus_client *bus_client)
  370. {
  371. if (!bus_client->valid) {
  372. CAM_ERR(CAM_CPAS, "bus client not valid");
  373. return -EINVAL;
  374. }
  375. cam_soc_bus_client_unregister(&bus_client->soc_bus_client);
  376. bus_client->curr_vote_level = 0;
  377. bus_client->valid = false;
  378. mutex_destroy(&bus_client->lock);
  379. return 0;
  380. }
  381. static int cam_cpas_util_axi_cleanup(struct cam_cpas *cpas_core,
  382. struct cam_hw_soc_info *soc_info)
  383. {
  384. int i = 0;
  385. if (cpas_core->num_axi_ports > CAM_CPAS_MAX_AXI_PORTS) {
  386. CAM_ERR(CAM_CPAS, "Invalid num_axi_ports: %d",
  387. cpas_core->num_axi_ports);
  388. return -EINVAL;
  389. }
  390. if (cpas_core->num_camnoc_axi_ports > CAM_CPAS_MAX_AXI_PORTS) {
  391. CAM_ERR(CAM_CPAS, "Invalid num_camnoc_axi_ports: %d",
  392. cpas_core->num_camnoc_axi_ports);
  393. return -EINVAL;
  394. }
  395. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  396. cam_cpas_util_unregister_bus_client(
  397. &cpas_core->axi_port[i].bus_client);
  398. of_node_put(cpas_core->axi_port[i].axi_port_node);
  399. cpas_core->axi_port[i].axi_port_node = NULL;
  400. }
  401. for (i = 0; i < cpas_core->num_camnoc_axi_ports; i++) {
  402. cam_cpas_util_unregister_bus_client(
  403. &cpas_core->camnoc_axi_port[i].bus_client);
  404. of_node_put(cpas_core->camnoc_axi_port[i].axi_port_node);
  405. cpas_core->camnoc_axi_port[i].axi_port_node = NULL;
  406. }
  407. return 0;
  408. }
  409. static int cam_cpas_util_axi_setup(struct cam_cpas *cpas_core,
  410. struct cam_hw_soc_info *soc_info)
  411. {
  412. int i = 0, rc = 0;
  413. struct device_node *axi_port_mnoc_node = NULL;
  414. struct device_node *axi_port_camnoc_node = NULL;
  415. if (cpas_core->num_axi_ports > CAM_CPAS_MAX_AXI_PORTS) {
  416. CAM_ERR(CAM_CPAS, "Invalid num_axi_ports: %d",
  417. cpas_core->num_axi_ports);
  418. return -EINVAL;
  419. }
  420. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  421. axi_port_mnoc_node = cpas_core->axi_port[i].axi_port_node;
  422. rc = cam_cpas_util_register_bus_client(soc_info,
  423. axi_port_mnoc_node, &cpas_core->axi_port[i].bus_client);
  424. if (rc)
  425. goto bus_register_fail;
  426. }
  427. for (i = 0; i < cpas_core->num_camnoc_axi_ports; i++) {
  428. axi_port_camnoc_node =
  429. cpas_core->camnoc_axi_port[i].axi_port_node;
  430. rc = cam_cpas_util_register_bus_client(soc_info,
  431. axi_port_camnoc_node,
  432. &cpas_core->camnoc_axi_port[i].bus_client);
  433. if (rc)
  434. goto bus_register_fail;
  435. }
  436. return 0;
  437. bus_register_fail:
  438. of_node_put(cpas_core->axi_port[i].axi_port_node);
  439. return rc;
  440. }
  441. int cam_cpas_util_vote_default_ahb_axi(struct cam_hw_info *cpas_hw,
  442. int enable)
  443. {
  444. int rc, i = 0;
  445. struct cam_cpas *cpas_core = (struct cam_cpas *)cpas_hw->core_info;
  446. uint64_t ab_bw, ib_bw;
  447. uint64_t applied_ab_bw = 0, applied_ib_bw = 0;
  448. rc = cam_cpas_util_vote_bus_client_level(&cpas_core->ahb_bus_client,
  449. (enable == true) ? CAM_LOWSVS_D1_VOTE : CAM_SUSPEND_VOTE);
  450. if (rc) {
  451. CAM_ERR(CAM_CPAS, "Failed in AHB vote, enable=%d, rc=%d",
  452. enable, rc);
  453. return rc;
  454. }
  455. if (enable) {
  456. ab_bw = CAM_CPAS_DEFAULT_AXI_BW;
  457. ib_bw = CAM_CPAS_DEFAULT_AXI_BW;
  458. } else {
  459. ab_bw = 0;
  460. ib_bw = 0;
  461. }
  462. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  463. if (cpas_core->axi_port[i].bus_client.common_data.is_drv_port)
  464. continue;
  465. rc = cam_cpas_util_vote_hlos_bus_client_bw(
  466. &cpas_core->axi_port[i].bus_client,
  467. ab_bw, ib_bw, false, &applied_ab_bw, &applied_ib_bw);
  468. if (rc) {
  469. CAM_ERR(CAM_CPAS,
  470. "Failed in mnoc vote, enable=%d, rc=%d",
  471. enable, rc);
  472. goto remove_ahb_vote;
  473. }
  474. cpas_core->axi_port[i].applied_bw.hlos_vote.ab = applied_ab_bw;
  475. cpas_core->axi_port[i].applied_bw.hlos_vote.ib = applied_ib_bw;
  476. }
  477. return 0;
  478. remove_ahb_vote:
  479. cam_cpas_util_vote_bus_client_level(&cpas_core->ahb_bus_client,
  480. CAM_SUSPEND_VOTE);
  481. return rc;
  482. }
  483. static int cam_cpas_hw_reg_write(struct cam_hw_info *cpas_hw,
  484. uint32_t client_handle, enum cam_cpas_reg_base reg_base,
  485. uint32_t offset, bool mb, uint32_t value)
  486. {
  487. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  488. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  489. struct cam_cpas_client *cpas_client = NULL;
  490. int reg_base_index = cpas_core->regbase_index[reg_base];
  491. uint32_t client_indx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  492. int rc = 0;
  493. if (reg_base_index < 0 || reg_base_index >= soc_info->num_reg_map) {
  494. CAM_ERR(CAM_CPAS,
  495. "Invalid reg_base=%d, reg_base_index=%d, num_map=%d",
  496. reg_base, reg_base_index, soc_info->num_reg_map);
  497. return -EINVAL;
  498. }
  499. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  500. return -EINVAL;
  501. mutex_lock(&cpas_core->client_mutex[client_indx]);
  502. cpas_client = cpas_core->cpas_client[client_indx];
  503. if (!CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  504. CAM_ERR(CAM_CPAS, "client=[%d][%s][%d] has not started",
  505. client_indx, cpas_client->data.identifier,
  506. cpas_client->data.cell_index);
  507. rc = -EPERM;
  508. goto unlock_client;
  509. }
  510. if (mb)
  511. cam_io_w_mb(value,
  512. soc_info->reg_map[reg_base_index].mem_base + offset);
  513. else
  514. cam_io_w(value,
  515. soc_info->reg_map[reg_base_index].mem_base + offset);
  516. unlock_client:
  517. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  518. return rc;
  519. }
  520. static int cam_cpas_hw_reg_read(struct cam_hw_info *cpas_hw,
  521. uint32_t client_handle, enum cam_cpas_reg_base reg_base,
  522. uint32_t offset, bool mb, uint32_t *value)
  523. {
  524. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  525. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  526. struct cam_cpas_client *cpas_client = NULL;
  527. int reg_base_index = cpas_core->regbase_index[reg_base];
  528. uint32_t reg_value;
  529. uint32_t client_indx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  530. int rc = 0;
  531. if (!value)
  532. return -EINVAL;
  533. if (reg_base_index < 0 || reg_base_index >= soc_info->num_reg_map) {
  534. CAM_ERR(CAM_CPAS,
  535. "Invalid reg_base=%d, reg_base_index=%d, num_map=%d",
  536. reg_base, reg_base_index, soc_info->num_reg_map);
  537. return -EINVAL;
  538. }
  539. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  540. return -EINVAL;
  541. cpas_client = cpas_core->cpas_client[client_indx];
  542. if (!CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  543. CAM_ERR(CAM_CPAS, "client=[%d][%s][%d] has not started",
  544. client_indx, cpas_client->data.identifier,
  545. cpas_client->data.cell_index);
  546. return -EPERM;
  547. }
  548. if (mb)
  549. reg_value = cam_io_r_mb(
  550. soc_info->reg_map[reg_base_index].mem_base + offset);
  551. else
  552. reg_value = cam_io_r(
  553. soc_info->reg_map[reg_base_index].mem_base + offset);
  554. *value = reg_value;
  555. return rc;
  556. }
  557. static int cam_cpas_hw_dump_camnoc_buff_fill_info(
  558. struct cam_hw_info *cpas_hw,
  559. uint32_t client_handle)
  560. {
  561. int rc = 0, i, camnoc_idx;
  562. uint32_t val = 0, client_idx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  563. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  564. struct cam_camnoc_info *camnoc_info;
  565. char log_buf[CAM_CPAS_LOG_BUF_LEN];
  566. size_t len;
  567. if (!CAM_CPAS_CLIENT_VALID(client_idx)) {
  568. CAM_ERR(CAM_CPAS, "Invalid client idx: %u", client_idx);
  569. return -EPERM;
  570. }
  571. /* log buffer fill level of both RT/NRT NIU */
  572. for (camnoc_idx = 0; camnoc_idx < cpas_core->num_valid_camnoc; camnoc_idx++) {
  573. log_buf[0] = '\0';
  574. len = 0;
  575. camnoc_info = cpas_core->camnoc_info[camnoc_idx];
  576. for (i = 0; i < camnoc_info->specific_size; i++) {
  577. if ((!camnoc_info->specific[i].enable) ||
  578. (!camnoc_info->specific[i].maxwr_low.enable))
  579. continue;
  580. rc = cam_cpas_hw_reg_read(cpas_hw, client_handle,
  581. camnoc_info->reg_base,
  582. camnoc_info->specific[i].maxwr_low.offset, true, &val);
  583. if (rc)
  584. break;
  585. len += scnprintf((log_buf + len), (CAM_CPAS_LOG_BUF_LEN - len),
  586. " %s:[%d %d]", camnoc_info->specific[i].port_name,
  587. (val & 0x7FF), (val & 0x7F0000) >> 16);
  588. }
  589. CAM_INFO(CAM_CPAS, "%s Fill level [Queued Pending] %s",
  590. camnoc_info->camnoc_name, log_buf);
  591. }
  592. return rc;
  593. }
  594. static void cam_cpas_print_smart_qos_priority(
  595. struct cam_hw_info *cpas_hw)
  596. {
  597. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  598. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  599. struct cam_cpas_private_soc *soc_private =
  600. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  601. struct cam_camnoc_info *camnoc_info = NULL;
  602. struct cam_cpas_tree_node *niu_node;
  603. uint8_t i;
  604. int32_t reg_indx;
  605. char log_buf[CAM_CPAS_LOG_BUF_LEN] = {0};
  606. size_t len = 0;
  607. uint32_t val_low = 0, val_high = 0;
  608. /* Smart QOS only apply to CPAS RT nius */
  609. camnoc_info = cpas_core->camnoc_info[cpas_core->camnoc_rt_idx];
  610. reg_indx = cpas_core->regbase_index[camnoc_info->reg_base];
  611. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  612. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  613. val_high = cam_io_r_mb(soc_info->reg_map[reg_indx].mem_base +
  614. niu_node->pri_lut_high_offset);
  615. val_low = cam_io_r_mb(soc_info->reg_map[reg_indx].mem_base +
  616. niu_node->pri_lut_low_offset);
  617. len += scnprintf((log_buf + len), (CAM_CPAS_LOG_BUF_LEN - len),
  618. " [%s:high 0x%x low 0x%x]", niu_node->node_name,
  619. val_high, val_low);
  620. }
  621. CAM_INFO(CAM_CPAS, "%s SmartQoS [Node Pri_lut] %s", camnoc_info->camnoc_name, log_buf);
  622. }
  623. static bool cam_cpas_is_new_rt_bw_lower(
  624. const struct cam_hw_info *cpas_hw)
  625. {
  626. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  627. int i;
  628. struct cam_cpas_axi_port *temp_axi_port = NULL;
  629. uint64_t applied_total = 0, new_total = 0;
  630. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  631. temp_axi_port = &cpas_core->axi_port[i];
  632. if (!temp_axi_port->is_rt)
  633. continue;
  634. if (temp_axi_port->bus_client.common_data.is_drv_port) {
  635. CAM_DBG(CAM_PERF, "Port %s DRV ab applied [%llu %llu] new [%llu %llu]",
  636. temp_axi_port->axi_port_name,
  637. temp_axi_port->applied_bw.drv_vote.high.ab,
  638. temp_axi_port->applied_bw.drv_vote.low.ab,
  639. temp_axi_port->curr_bw.drv_vote.high.ab,
  640. temp_axi_port->curr_bw.drv_vote.low.ab);
  641. applied_total += temp_axi_port->applied_bw.drv_vote.high.ab;
  642. new_total += temp_axi_port->curr_bw.drv_vote.high.ab;
  643. } else {
  644. CAM_DBG(CAM_PERF, "Port %s HLOS ab applied %llu new %llu",
  645. temp_axi_port->axi_port_name,
  646. temp_axi_port->applied_bw.hlos_vote.ab,
  647. temp_axi_port->curr_bw.hlos_vote.ab);
  648. applied_total += temp_axi_port->applied_bw.hlos_vote.ab;
  649. new_total += temp_axi_port->curr_bw.hlos_vote.ab;
  650. }
  651. }
  652. return (new_total < applied_total) ? true : false;
  653. }
  654. static void cam_cpas_reset_niu_priorities(
  655. struct cam_hw_info *cpas_hw)
  656. {
  657. struct cam_cpas_private_soc *soc_private =
  658. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  659. uint8_t i;
  660. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  661. soc_private->smart_qos_info->rt_wr_niu_node[i]->applied_priority_low = 0x0;
  662. soc_private->smart_qos_info->rt_wr_niu_node[i]->applied_priority_high = 0x0;
  663. }
  664. }
  665. static bool cam_cpas_calculate_smart_qos(
  666. struct cam_hw_info *cpas_hw)
  667. {
  668. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  669. struct cam_cpas_private_soc *soc_private =
  670. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  671. struct cam_cpas_tree_node *niu_node;
  672. uint8_t i;
  673. bool needs_update = false;
  674. uint64_t bw_per_kb, total_camnoc_bw, max_bw_per_kb = 0, remainder, ramp_val;
  675. uint64_t total_bw_per_kb = 0, total_bw_ramp_val = 0;
  676. int8_t pos;
  677. uint64_t priority;
  678. uint8_t val, clamp_threshold;
  679. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  680. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  681. bw_per_kb = niu_node->bw_info[CAM_CPAS_PORT_HLOS_DRV].hlos_vote.camnoc;
  682. if (soc_private->enable_cam_clk_drv)
  683. bw_per_kb += niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.high.camnoc +
  684. niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.low.camnoc +
  685. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.high.camnoc +
  686. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.low.camnoc +
  687. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.high.camnoc +
  688. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.low.camnoc;
  689. total_camnoc_bw = bw_per_kb;
  690. remainder = do_div(bw_per_kb, niu_node->niu_size);
  691. total_bw_per_kb += bw_per_kb;
  692. if (max_bw_per_kb < bw_per_kb)
  693. max_bw_per_kb = bw_per_kb;
  694. CAM_DBG(CAM_PERF,
  695. "NIU[%d][%s]camnoc_bw %llu, niu_size %u, init_bw_per_kb %lld, remainder %lld, max_bw_per_kb %lld, total_bw_per_kb %lld",
  696. i, niu_node->node_name, total_camnoc_bw, niu_node->niu_size,
  697. bw_per_kb, remainder, max_bw_per_kb, total_bw_per_kb);
  698. }
  699. if (!max_bw_per_kb) {
  700. CAM_DBG(CAM_PERF, "No valid bw on NIU nodes");
  701. return false;
  702. }
  703. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  704. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  705. bw_per_kb = niu_node->bw_info[CAM_CPAS_PORT_HLOS_DRV].hlos_vote.camnoc;
  706. if (soc_private->enable_cam_clk_drv)
  707. bw_per_kb += niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.high.camnoc +
  708. niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.low.camnoc +
  709. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.high.camnoc +
  710. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.low.camnoc +
  711. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.high.camnoc +
  712. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.low.camnoc;
  713. do_div(bw_per_kb, niu_node->niu_size);
  714. if ((bw_per_kb * CAM_CPAS_MAX_STRESS_INDICATOR) >
  715. (total_bw_per_kb *
  716. soc_private->smart_qos_info->highstress_indicator_th)) {
  717. clamp_threshold = soc_private->smart_qos_info->moststressed_clamp_th;
  718. CAM_DBG(CAM_PERF, "Current niu clamp_threshold=%d",
  719. clamp_threshold);
  720. } else {
  721. ramp_val = soc_private->smart_qos_info->bw_ratio_scale_factor *
  722. bw_per_kb;
  723. ramp_val = ramp_val *
  724. (soc_private->smart_qos_info->leaststressed_clamp_th -
  725. soc_private->smart_qos_info->moststressed_clamp_th);
  726. /*
  727. * Stress indicator threshold may have a float type value
  728. * such as 0.5 according max stress indicator value 1,
  729. * we take in percentages to avoid float type calcaulate.
  730. */
  731. total_bw_ramp_val = total_bw_per_kb *
  732. (soc_private->smart_qos_info->highstress_indicator_th -
  733. soc_private->smart_qos_info->lowstress_indicator_th) /
  734. CAM_CPAS_MAX_STRESS_INDICATOR;
  735. CAM_DBG(CAM_PERF, "ramp_val=%lld, total_bw_ramp_val=%lld",
  736. ramp_val, total_bw_ramp_val);
  737. remainder = do_div(ramp_val, total_bw_ramp_val);
  738. /* round the value */
  739. if ((remainder * 2) >= total_bw_ramp_val)
  740. ramp_val += 1;
  741. val = (uint8_t)(ramp_val);
  742. clamp_threshold =
  743. soc_private->smart_qos_info->leaststressed_clamp_th - val;
  744. CAM_DBG(CAM_PERF, "Current niu clamp_threshold=%d, val=%d",
  745. clamp_threshold, val);
  746. }
  747. priority = 0;
  748. for (pos = 15; pos >= clamp_threshold; pos--) {
  749. val = soc_private->smart_qos_info->rt_wr_priority_clamp;
  750. priority = priority << 4;
  751. priority |= val;
  752. CAM_DBG(CAM_PERF, "pos=%d, val=0x%x, priority=0x%llx", pos, val, priority);
  753. }
  754. for (pos = clamp_threshold - 1; pos >= 0; pos--) {
  755. if (pos == 0) {
  756. val = soc_private->smart_qos_info->rt_wr_priority_min;
  757. } else {
  758. ramp_val = pos * bw_per_kb;
  759. /*
  760. * Slope factor may have a float type value such as 0.7
  761. * according max slope factor value 1,
  762. * we take in percentages to avoid float type calcaulate.
  763. */
  764. ramp_val = ramp_val *
  765. soc_private->smart_qos_info->rt_wr_slope_factor /
  766. CAM_CPAS_MAX_SLOPE_FACTOR;
  767. remainder = do_div(ramp_val, max_bw_per_kb);
  768. CAM_DBG(CAM_PERF,
  769. "pos=%d, bw_per_kb=%lld, pos*bw_per_kb=%lld, ramp_val=%lld, remainder=%lld, max_bw_per_kb=%lld",
  770. pos, bw_per_kb, pos * bw_per_kb, ramp_val, remainder,
  771. max_bw_per_kb);
  772. /* round the value */
  773. if ((remainder * 2) >= max_bw_per_kb)
  774. ramp_val += 1;
  775. val = (uint8_t)(ramp_val);
  776. val += soc_private->smart_qos_info->rt_wr_priority_min;
  777. val = min(val, soc_private->smart_qos_info->rt_wr_priority_max);
  778. }
  779. priority = priority << 4;
  780. priority |= val;
  781. CAM_DBG(CAM_PERF, "pos=%d, val=0x%x, priority=0x%llx", pos, val, priority);
  782. }
  783. niu_node->curr_priority_low = (uint32_t)(priority & 0xFFFFFFFF);
  784. niu_node->curr_priority_high = (uint32_t)((priority >> 32) & 0xFFFFFFFF);
  785. if ((niu_node->curr_priority_low != niu_node->applied_priority_low) ||
  786. (niu_node->curr_priority_high != niu_node->applied_priority_high))
  787. needs_update = true;
  788. CAM_DBG(CAM_PERF,
  789. "Node[%d][%s]Priority applied high 0x%x low 0x%x, new high 0x%x low 0x%x, needs_update %d",
  790. i, niu_node->node_name,
  791. niu_node->applied_priority_high, niu_node->applied_priority_low,
  792. niu_node->curr_priority_high, niu_node->curr_priority_low,
  793. needs_update);
  794. }
  795. if (cpas_core->smart_qos_dump && needs_update) {
  796. uint64_t total_camnoc;
  797. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  798. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  799. total_camnoc = niu_node->bw_info[CAM_CPAS_PORT_HLOS_DRV].hlos_vote.camnoc;
  800. if (soc_private->enable_cam_clk_drv)
  801. total_camnoc +=
  802. niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.high.camnoc +
  803. niu_node->bw_info[CAM_CPAS_PORT_DRV_0].drv_vote.low.camnoc +
  804. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.high.camnoc +
  805. niu_node->bw_info[CAM_CPAS_PORT_DRV_1].drv_vote.low.camnoc +
  806. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.high.camnoc +
  807. niu_node->bw_info[CAM_CPAS_PORT_DRV_2].drv_vote.low.camnoc;
  808. CAM_INFO(CAM_PERF,
  809. "Node[%d][%s] camnoc_bw=%lld, niu_size=%d, offset high 0x%x, low 0x%x, Priority new high 0x%x low 0x%x, applied high 0x%x low 0x%x",
  810. i, niu_node->node_name, total_camnoc, niu_node->niu_size,
  811. niu_node->pri_lut_high_offset, niu_node->pri_lut_low_offset,
  812. niu_node->curr_priority_high, niu_node->curr_priority_low,
  813. niu_node->applied_priority_high, niu_node->applied_priority_low);
  814. }
  815. }
  816. return needs_update;
  817. }
  818. static int cam_cpas_apply_smart_qos(
  819. struct cam_hw_info *cpas_hw)
  820. {
  821. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  822. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  823. struct cam_cpas_private_soc *soc_private =
  824. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  825. struct cam_cpas_tree_node *niu_node;
  826. struct cam_camnoc_info *camnoc_info;
  827. uint8_t i;
  828. int32_t reg_indx, cam_qos_cnt = 0, ret = 0;
  829. struct qcom_scm_camera_qos scm_buf[QCOM_SCM_CAMERA_MAX_QOS_CNT] = {0};
  830. if (cpas_core->smart_qos_dump) {
  831. CAM_INFO(CAM_PERF, "Printing SmartQos values before update");
  832. cam_cpas_print_smart_qos_priority(cpas_hw);
  833. }
  834. /* Smart QOS only apply to CPAS RT nius */
  835. camnoc_info = cpas_core->camnoc_info[cpas_core->camnoc_rt_idx];
  836. reg_indx = cpas_core->regbase_index[camnoc_info->reg_base];
  837. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  838. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  839. if (niu_node->curr_priority_high != niu_node->applied_priority_high) {
  840. if (!soc_private->enable_secure_qos_update) {
  841. cam_io_w_mb(niu_node->curr_priority_high,
  842. soc_info->reg_map[reg_indx].mem_base +
  843. niu_node->pri_lut_high_offset);
  844. } else {
  845. scm_buf[cam_qos_cnt].offset = niu_node->pri_lut_high_offset;
  846. scm_buf[cam_qos_cnt].val = niu_node->curr_priority_high;
  847. cam_qos_cnt++;
  848. }
  849. niu_node->applied_priority_high = niu_node->curr_priority_high;
  850. }
  851. if (niu_node->curr_priority_low != niu_node->applied_priority_low) {
  852. if (!soc_private->enable_secure_qos_update) {
  853. cam_io_w_mb(niu_node->curr_priority_low,
  854. soc_info->reg_map[reg_indx].mem_base +
  855. niu_node->pri_lut_low_offset);
  856. } else {
  857. scm_buf[cam_qos_cnt].offset = niu_node->pri_lut_low_offset;
  858. scm_buf[cam_qos_cnt].val = niu_node->curr_priority_low;
  859. cam_qos_cnt++;
  860. }
  861. niu_node->applied_priority_low = niu_node->curr_priority_low;
  862. }
  863. if (soc_private->enable_secure_qos_update && cam_qos_cnt) {
  864. CAM_DBG(CAM_PERF, "Updating secure camera smartOos count: %d", cam_qos_cnt);
  865. ret = cam_update_camnoc_qos_settings(CAM_QOS_UPDATE_TYPE_SMART,
  866. cam_qos_cnt, scm_buf);
  867. if (ret) {
  868. CAM_ERR(CAM_PERF, "Secure camera smartOos update failed:%d", ret);
  869. return ret;
  870. }
  871. CAM_DBG(CAM_PERF, "Updated secure camera smartOos");
  872. cam_qos_cnt = 0;
  873. }
  874. }
  875. if (cpas_core->smart_qos_dump) {
  876. CAM_INFO(CAM_PERF, "Printing SmartQos values after update");
  877. cam_cpas_print_smart_qos_priority(cpas_hw);
  878. }
  879. return 0;
  880. }
  881. static int cam_cpas_util_camnoc_drv_idx_to_cesta_hw_client_idx(int camnoc_drv_idx)
  882. {
  883. int hw_client = -1;
  884. switch (camnoc_drv_idx) {
  885. case CAM_CPAS_PORT_HLOS_DRV:
  886. hw_client = -1;
  887. break;
  888. case CAM_CPAS_PORT_DRV_0:
  889. hw_client = 0;
  890. break;
  891. case CAM_CPAS_PORT_DRV_1:
  892. hw_client = 1;
  893. break;
  894. case CAM_CPAS_PORT_DRV_2:
  895. hw_client = 2;
  896. break;
  897. default:
  898. CAM_WARN(CAM_CPAS, "Invalid drv idx %d", camnoc_drv_idx);
  899. break;
  900. }
  901. return hw_client;
  902. }
  903. static int cam_cpas_util_set_camnoc_axi_drv_clk_rate(struct cam_hw_soc_info *soc_info,
  904. struct cam_cpas_private_soc *soc_private, struct cam_cpas *cpas_core, int cesta_drv_idx)
  905. {
  906. struct cam_cpas_tree_node *tree_node = NULL;
  907. uint64_t req_drv_high_camnoc_bw = 0, intermediate_drv_high_result = 0,
  908. req_drv_low_camnoc_bw = 0, intermediate_drv_low_result = 0;
  909. int64_t drv_high_clk_rate = 0, drv_low_clk_rate = 0;
  910. int i, rc = 0;
  911. if (!soc_private->enable_cam_clk_drv) {
  912. CAM_ERR(CAM_CPAS, "Clk DRV not enabled, can't set clk rates through cesta APIs");
  913. return -EINVAL;
  914. }
  915. for (i = 0; i < CAM_CPAS_MAX_TREE_NODES; i++) {
  916. tree_node = soc_private->tree_node[i];
  917. if (!tree_node ||
  918. !tree_node->camnoc_max_needed)
  919. continue;
  920. if (req_drv_high_camnoc_bw <
  921. (tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc *
  922. tree_node->bus_width_factor))
  923. req_drv_high_camnoc_bw =
  924. (tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc *
  925. tree_node->bus_width_factor);
  926. if (req_drv_low_camnoc_bw <
  927. (tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc *
  928. tree_node->bus_width_factor))
  929. req_drv_low_camnoc_bw =
  930. (tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc *
  931. tree_node->bus_width_factor);
  932. }
  933. intermediate_drv_high_result = req_drv_high_camnoc_bw *
  934. soc_private->camnoc_axi_clk_bw_margin;
  935. intermediate_drv_low_result = req_drv_low_camnoc_bw *
  936. soc_private->camnoc_axi_clk_bw_margin;
  937. do_div(intermediate_drv_high_result, 100);
  938. do_div(intermediate_drv_low_result, 100);
  939. req_drv_high_camnoc_bw += intermediate_drv_high_result;
  940. req_drv_low_camnoc_bw += intermediate_drv_low_result;
  941. /*
  942. * Since all low votes are considered as part of high votes as well, add low camnoc bw
  943. * to final requested high camnoc bw value.
  944. */
  945. req_drv_high_camnoc_bw += req_drv_low_camnoc_bw;
  946. intermediate_drv_high_result = req_drv_high_camnoc_bw;
  947. intermediate_drv_low_result = req_drv_low_camnoc_bw;
  948. do_div(intermediate_drv_high_result, soc_private->camnoc_bus_width);
  949. do_div(intermediate_drv_low_result, soc_private->camnoc_bus_width);
  950. drv_high_clk_rate = intermediate_drv_high_result;
  951. drv_low_clk_rate = intermediate_drv_low_result;
  952. if (cpas_core->streamon_clients) {
  953. int hw_client_idx;
  954. /*
  955. * cesta_drv_idx is based on enum we set in dtsi properties which is +1 of actual
  956. * corresponding hw client index
  957. */
  958. hw_client_idx = cam_cpas_util_camnoc_drv_idx_to_cesta_hw_client_idx(cesta_drv_idx);
  959. if (hw_client_idx == -1) {
  960. CAM_ERR(CAM_CPAS, "Invalid hw client idx %d, cesta_drv_idx %d",
  961. hw_client_idx, cesta_drv_idx);
  962. return rc;
  963. }
  964. if (debug_drv)
  965. CAM_INFO(CAM_PERF,
  966. "Setting camnoc axi cesta clk rate[BW Clk] : High [%llu %lld] Low [%llu %lld] cesta/hw_client_idx:[%d][%d]",
  967. req_drv_high_camnoc_bw, drv_high_clk_rate, req_drv_low_camnoc_bw,
  968. drv_low_clk_rate, cesta_drv_idx, hw_client_idx);
  969. else
  970. CAM_DBG(CAM_PERF,
  971. "Setting camnoc axi cesta clk rate[BW Clk] : High [%llu %lld] Low [%llu %lld] cesta/hw_client_idx:[%d][%d]",
  972. req_drv_high_camnoc_bw, drv_high_clk_rate, req_drv_low_camnoc_bw,
  973. drv_low_clk_rate, cesta_drv_idx, hw_client_idx);
  974. rc = cam_soc_util_set_src_clk_rate(soc_info, hw_client_idx,
  975. drv_high_clk_rate, drv_low_clk_rate);
  976. if (rc) {
  977. CAM_ERR(CAM_CPAS,
  978. "Failed in setting camnoc cesta clk rates[high low]:[%ld %ld] client_idx:%d rc:%d",
  979. drv_high_clk_rate, drv_low_clk_rate, hw_client_idx,
  980. rc);
  981. return rc;
  982. }
  983. cpas_core->applied_camnoc_axi_rate.hw_client[hw_client_idx].high =
  984. drv_high_clk_rate;
  985. cpas_core->applied_camnoc_axi_rate.hw_client[hw_client_idx].low =
  986. drv_low_clk_rate;
  987. if (debug_drv)
  988. CAM_INFO(CAM_PERF, "Triggering channel switch for cesta client %d",
  989. hw_client_idx);
  990. else
  991. CAM_DBG(CAM_PERF, "Triggering channel switch for cesta client %d",
  992. hw_client_idx);
  993. rc = cam_soc_util_cesta_channel_switch(hw_client_idx, "cpas_update");
  994. if (rc) {
  995. CAM_ERR(CAM_CPAS, "Failed to apply power states for cesta client:%d rc:%d",
  996. hw_client_idx, rc);
  997. return rc;
  998. }
  999. }
  1000. return rc;
  1001. }
  1002. static int cam_cpas_util_set_camnoc_axi_hlos_clk_rate(struct cam_hw_soc_info *soc_info,
  1003. struct cam_cpas_private_soc *soc_private, struct cam_cpas *cpas_core)
  1004. {
  1005. struct cam_cpas_tree_node *tree_node = NULL;
  1006. uint64_t req_hlos_camnoc_bw = 0, intermediate_hlos_result = 0;
  1007. int64_t hlos_clk_rate = 0;
  1008. int i, rc = 0;
  1009. const struct camera_debug_settings *cam_debug = NULL;
  1010. for (i = 0; i < CAM_CPAS_MAX_TREE_NODES; i++) {
  1011. tree_node = soc_private->tree_node[i];
  1012. if (!tree_node || !tree_node->camnoc_max_needed)
  1013. continue;
  1014. if (req_hlos_camnoc_bw <
  1015. (tree_node->bw_info[CAM_CPAS_PORT_HLOS_DRV].hlos_vote.camnoc *
  1016. tree_node->bus_width_factor)) {
  1017. req_hlos_camnoc_bw =
  1018. (tree_node->bw_info[CAM_CPAS_PORT_HLOS_DRV].hlos_vote.camnoc *
  1019. tree_node->bus_width_factor);
  1020. }
  1021. }
  1022. intermediate_hlos_result = req_hlos_camnoc_bw * soc_private->camnoc_axi_clk_bw_margin;
  1023. do_div(intermediate_hlos_result, 100);
  1024. req_hlos_camnoc_bw += intermediate_hlos_result;
  1025. if (cpas_core->streamon_clients && (req_hlos_camnoc_bw == 0)) {
  1026. CAM_DBG(CAM_CPAS,
  1027. "Set min vote if streamon_clients is non-zero : streamon_clients=%d",
  1028. cpas_core->streamon_clients);
  1029. req_hlos_camnoc_bw = CAM_CPAS_DEFAULT_AXI_BW;
  1030. }
  1031. if ((req_hlos_camnoc_bw > 0) && (req_hlos_camnoc_bw < soc_private->camnoc_axi_min_ib_bw))
  1032. req_hlos_camnoc_bw = soc_private->camnoc_axi_min_ib_bw;
  1033. cam_debug = cam_debug_get_settings();
  1034. if (cam_debug && cam_debug->cpas_settings.camnoc_bw) {
  1035. if (cam_debug->cpas_settings.camnoc_bw < soc_private->camnoc_bus_width)
  1036. req_hlos_camnoc_bw = soc_private->camnoc_bus_width;
  1037. else
  1038. req_hlos_camnoc_bw = cam_debug->cpas_settings.camnoc_bw;
  1039. CAM_INFO(CAM_CPAS, "Overriding camnoc bw: %llu", req_hlos_camnoc_bw);
  1040. }
  1041. intermediate_hlos_result = req_hlos_camnoc_bw;
  1042. do_div(intermediate_hlos_result, soc_private->camnoc_bus_width);
  1043. hlos_clk_rate = intermediate_hlos_result;
  1044. CAM_DBG(CAM_PERF, "Setting camnoc axi HLOS clk rate[BW Clk] : [%llu %lld]",
  1045. req_hlos_camnoc_bw, hlos_clk_rate);
  1046. /*
  1047. * CPAS hw is not powered on for the first client.
  1048. * Also, clk_rate will be overwritten with default
  1049. * value while power on. So, skipping this for first
  1050. * client.
  1051. */
  1052. if (cpas_core->streamon_clients) {
  1053. rc = cam_soc_util_set_src_clk_rate(soc_info, CAM_CLK_SW_CLIENT_IDX,
  1054. hlos_clk_rate, 0);
  1055. if (rc)
  1056. CAM_ERR(CAM_CPAS,
  1057. "Failed in setting camnoc axi clk [BW Clk]:[%llu %lld] rc:%d",
  1058. req_hlos_camnoc_bw, hlos_clk_rate, rc);
  1059. cpas_core->applied_camnoc_axi_rate.sw_client = hlos_clk_rate;
  1060. }
  1061. return rc;
  1062. }
  1063. static int cam_cpas_util_set_camnoc_axi_clk_rate(struct cam_hw_info *cpas_hw,
  1064. int cesta_drv_idx)
  1065. {
  1066. struct cam_cpas_private_soc *soc_private =
  1067. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  1068. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1069. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  1070. int rc = 0;
  1071. CAM_DBG(CAM_CPAS, "control_camnoc_axi_clk=%d", soc_private->control_camnoc_axi_clk);
  1072. if (cesta_drv_idx == CAM_CPAS_PORT_HLOS_DRV) {
  1073. rc = cam_cpas_util_set_camnoc_axi_hlos_clk_rate(soc_info,
  1074. soc_private, cpas_core);
  1075. if (rc) {
  1076. CAM_ERR(CAM_CPAS, "Failed in setting hlos clk rate rc: %d",
  1077. rc);
  1078. goto end;
  1079. }
  1080. } else {
  1081. rc = cam_cpas_util_set_camnoc_axi_drv_clk_rate(soc_info,
  1082. soc_private, cpas_core, cesta_drv_idx);
  1083. if (rc) {
  1084. CAM_ERR(CAM_CPAS,
  1085. "Failed in setting drv clk rate drv_idx:%d rc: %d",
  1086. cesta_drv_idx, rc);
  1087. goto end;
  1088. }
  1089. }
  1090. end:
  1091. return rc;
  1092. }
  1093. static int cam_cpas_util_translate_client_paths(
  1094. struct cam_axi_vote *axi_vote)
  1095. {
  1096. int i;
  1097. uint32_t *path_data_type = NULL;
  1098. if (!axi_vote)
  1099. return -EINVAL;
  1100. for (i = 0; i < axi_vote->num_paths; i++) {
  1101. path_data_type = &axi_vote->axi_path[i].path_data_type;
  1102. /* Update path_data_type from UAPI value to internal value */
  1103. if (*path_data_type >= CAM_CPAS_PATH_DATA_CONSO_OFFSET)
  1104. *path_data_type = CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT +
  1105. (*path_data_type %
  1106. CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT);
  1107. else
  1108. *path_data_type %= CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT;
  1109. if (*path_data_type >= CAM_CPAS_PATH_DATA_MAX) {
  1110. CAM_ERR(CAM_CPAS, "index Invalid: %d", path_data_type);
  1111. return -EINVAL;
  1112. }
  1113. }
  1114. return 0;
  1115. }
  1116. static int cam_cpas_axi_consolidate_path_votes(
  1117. struct cam_cpas_client *cpas_client,
  1118. struct cam_axi_vote *axi_vote)
  1119. {
  1120. int rc = 0, i, k, l;
  1121. struct cam_axi_vote *con_axi_vote = &cpas_client->axi_vote;
  1122. bool path_found = false, cons_entry_found;
  1123. struct cam_cpas_tree_node *curr_tree_node = NULL;
  1124. struct cam_cpas_tree_node *sum_tree_node = NULL;
  1125. uint32_t transac_type;
  1126. uint32_t path_data_type;
  1127. struct cam_cpas_axi_per_path_bw_vote *axi_path;
  1128. con_axi_vote->num_paths = 0;
  1129. for (i = 0; i < axi_vote->num_paths; i++) {
  1130. path_found = false;
  1131. path_data_type = axi_vote->axi_path[i].path_data_type;
  1132. transac_type = axi_vote->axi_path[i].transac_type;
  1133. if ((path_data_type >= CAM_CPAS_PATH_DATA_MAX) ||
  1134. (transac_type >= CAM_CPAS_TRANSACTION_MAX)) {
  1135. CAM_ERR(CAM_CPAS, "Invalid path or transac type: %d %d",
  1136. path_data_type, transac_type);
  1137. return -EINVAL;
  1138. }
  1139. axi_path = &con_axi_vote->axi_path[con_axi_vote->num_paths];
  1140. curr_tree_node =
  1141. cpas_client->tree_node[path_data_type][transac_type];
  1142. if (curr_tree_node) {
  1143. memcpy(axi_path, &axi_vote->axi_path[i],
  1144. sizeof(struct cam_cpas_axi_per_path_bw_vote));
  1145. con_axi_vote->num_paths++;
  1146. continue;
  1147. }
  1148. for (k = 0; k < CAM_CPAS_PATH_DATA_MAX; k++) {
  1149. sum_tree_node = cpas_client->tree_node[k][transac_type];
  1150. if (!sum_tree_node)
  1151. continue;
  1152. if (sum_tree_node->constituent_paths[path_data_type]) {
  1153. path_found = true;
  1154. /*
  1155. * Check if corresponding consolidated path
  1156. * entry is already added into consolidated list
  1157. */
  1158. cons_entry_found = false;
  1159. for (l = 0; l < con_axi_vote->num_paths; l++) {
  1160. if ((con_axi_vote->axi_path[l].path_data_type == k) &&
  1161. (con_axi_vote->axi_path[l].transac_type == transac_type)) {
  1162. cons_entry_found = true;
  1163. con_axi_vote->axi_path[l].camnoc_bw +=
  1164. axi_vote->axi_path[i].camnoc_bw;
  1165. con_axi_vote->axi_path[l].mnoc_ab_bw +=
  1166. axi_vote->axi_path[i].mnoc_ab_bw;
  1167. con_axi_vote->axi_path[l].mnoc_ib_bw +=
  1168. axi_vote->axi_path[i].mnoc_ib_bw;
  1169. break;
  1170. }
  1171. }
  1172. /* If not found, add a new entry */
  1173. if (!cons_entry_found) {
  1174. axi_path->path_data_type = k;
  1175. axi_path->transac_type = transac_type;
  1176. axi_path->camnoc_bw = axi_vote->axi_path[i].camnoc_bw;
  1177. axi_path->mnoc_ab_bw = axi_vote->axi_path[i].mnoc_ab_bw;
  1178. axi_path->mnoc_ib_bw = axi_vote->axi_path[i].mnoc_ib_bw;
  1179. axi_path->vote_level = axi_vote->axi_path[i].vote_level;
  1180. con_axi_vote->num_paths++;
  1181. }
  1182. break;
  1183. }
  1184. }
  1185. if (!path_found) {
  1186. CAM_ERR(CAM_CPAS,
  1187. "Client [%s][%d] i=%d num_paths=%d Consolidated path not found for path=%d, transac=%d",
  1188. cpas_client->data.identifier, cpas_client->data.cell_index, i,
  1189. axi_vote->num_paths, path_data_type, transac_type);
  1190. return -EINVAL;
  1191. }
  1192. }
  1193. return rc;
  1194. }
  1195. static int cam_cpas_update_axi_vote_bw(
  1196. struct cam_hw_info *cpas_hw,
  1197. struct cam_cpas_tree_node *cpas_tree_node,
  1198. int ddr_drv_idx, int cesta_drv_idx,
  1199. bool *mnoc_axi_port_updated,
  1200. bool *camnoc_axi_port_updated)
  1201. {
  1202. int axi_port_idx = -1;
  1203. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1204. struct cam_cpas_private_soc *soc_private =
  1205. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  1206. axi_port_idx = cpas_tree_node->axi_port_idx_arr[ddr_drv_idx];
  1207. if ((axi_port_idx < 0) || (axi_port_idx >= CAM_CPAS_MAX_AXI_PORTS)) {
  1208. CAM_ERR(CAM_CPAS, "Invalid axi_port_idx: %d drv_idx: %d", axi_port_idx,
  1209. ddr_drv_idx);
  1210. return -EINVAL;
  1211. }
  1212. memcpy(&cpas_core->axi_port[axi_port_idx].curr_bw, &cpas_tree_node->bw_info[ddr_drv_idx],
  1213. sizeof(struct cam_cpas_axi_bw_info));
  1214. /* Add low value to high for drv */
  1215. if (ddr_drv_idx > CAM_CPAS_PORT_HLOS_DRV) {
  1216. cpas_core->axi_port[axi_port_idx].curr_bw.drv_vote.high.ab +=
  1217. cpas_core->axi_port[axi_port_idx].curr_bw.drv_vote.low.ab;
  1218. cpas_core->axi_port[axi_port_idx].curr_bw.drv_vote.high.ib +=
  1219. cpas_core->axi_port[axi_port_idx].curr_bw.drv_vote.low.ib;
  1220. }
  1221. mnoc_axi_port_updated[axi_port_idx] = true;
  1222. if (soc_private->control_camnoc_axi_clk)
  1223. return 0;
  1224. if (cesta_drv_idx > CAM_CPAS_PORT_HLOS_DRV)
  1225. cpas_core->camnoc_axi_port[cpas_tree_node->axi_port_idx_arr[CAM_CPAS_PORT_HLOS_DRV]]
  1226. .curr_bw.hlos_vote.camnoc =
  1227. cpas_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc +
  1228. cpas_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc;
  1229. else
  1230. cpas_core->camnoc_axi_port[cpas_tree_node->axi_port_idx_arr[CAM_CPAS_PORT_HLOS_DRV]]
  1231. .curr_bw.hlos_vote.camnoc =
  1232. cpas_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc;
  1233. camnoc_axi_port_updated[cpas_tree_node->camnoc_axi_port_idx] = true;
  1234. return 0;
  1235. }
  1236. static int cam_cpas_camnoc_set_bw_vote(struct cam_hw_info *cpas_hw,
  1237. bool *camnoc_axi_port_updated)
  1238. {
  1239. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1240. int i;
  1241. int rc = 0;
  1242. struct cam_cpas_axi_port *camnoc_axi_port = NULL;
  1243. uint64_t camnoc_bw;
  1244. uint64_t applied_ab = 0, applied_ib = 0;
  1245. /* Below code is executed if we just vote and do not set the clk rate
  1246. * for camnoc
  1247. */
  1248. if (cpas_core->num_camnoc_axi_ports > CAM_CPAS_MAX_AXI_PORTS) {
  1249. CAM_ERR(CAM_CPAS, "Invalid num_camnoc_axi_ports: %d",
  1250. cpas_core->num_camnoc_axi_ports);
  1251. return -EINVAL;
  1252. }
  1253. for (i = 0; i < cpas_core->num_camnoc_axi_ports; i++) {
  1254. if (camnoc_axi_port_updated[i])
  1255. camnoc_axi_port = &cpas_core->camnoc_axi_port[i];
  1256. else
  1257. continue;
  1258. CAM_DBG(CAM_PERF, "Port[%s] : camnoc_bw=%lld",
  1259. camnoc_axi_port->axi_port_name,
  1260. camnoc_axi_port->curr_bw.hlos_vote.camnoc);
  1261. if (camnoc_axi_port->curr_bw.hlos_vote.camnoc)
  1262. camnoc_bw = camnoc_axi_port->curr_bw.hlos_vote.camnoc;
  1263. else if (camnoc_axi_port->additional_bw)
  1264. camnoc_bw = camnoc_axi_port->additional_bw;
  1265. else if (cpas_core->streamon_clients)
  1266. camnoc_bw = CAM_CPAS_DEFAULT_AXI_BW;
  1267. else
  1268. camnoc_bw = 0;
  1269. rc = cam_cpas_util_vote_hlos_bus_client_bw(
  1270. &camnoc_axi_port->bus_client,
  1271. 0, camnoc_bw, true, &applied_ab, &applied_ib);
  1272. CAM_DBG(CAM_CPAS,
  1273. "camnoc vote camnoc_bw[%llu] rc=%d %s",
  1274. camnoc_bw, rc, camnoc_axi_port->axi_port_name);
  1275. if (rc) {
  1276. CAM_ERR(CAM_CPAS,
  1277. "Failed in camnoc vote camnoc_bw[%llu] rc=%d",
  1278. camnoc_bw, rc);
  1279. break;
  1280. }
  1281. camnoc_axi_port->applied_bw.hlos_vote.ab = applied_ab;
  1282. camnoc_axi_port->applied_bw.hlos_vote.ib = applied_ib;
  1283. }
  1284. return rc;
  1285. }
  1286. static int cam_cpas_util_apply_client_axi_vote(
  1287. struct cam_hw_info *cpas_hw,
  1288. struct cam_cpas_client *cpas_client,
  1289. struct cam_axi_vote *axi_vote, uint32_t apply_type)
  1290. {
  1291. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1292. struct cam_cpas_private_soc *soc_private =
  1293. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  1294. struct cam_axi_vote *con_axi_vote = NULL;
  1295. struct cam_cpas_axi_port *mnoc_axi_port = NULL;
  1296. struct cam_cpas_tree_node *curr_tree_node = NULL;
  1297. struct cam_cpas_tree_node *par_tree_node = NULL;
  1298. uint32_t transac_type;
  1299. uint32_t path_data_type;
  1300. bool mnoc_axi_port_updated[CAM_CPAS_MAX_AXI_PORTS] = {false};
  1301. bool camnoc_axi_port_updated[CAM_CPAS_MAX_AXI_PORTS] = {false};
  1302. struct cam_cpas_axi_bw_info curr_mnoc_old = {0}, par_mnoc_old = {0}, curr_camnoc_old = {0},
  1303. par_camnoc_old = {0}, curr_port_bw = {0}, applied_port_bw = {0};
  1304. int rc = 0, i = 0, ddr_drv_idx, merge_type_factor = 1;
  1305. bool apply_smart_qos = false;
  1306. bool rt_bw_updated = false;
  1307. bool camnoc_unchanged;
  1308. int cesta_drv_idx = CAM_CPAS_PORT_HLOS_DRV;
  1309. int first_ddr_drv_idx = -1, first_cesta_drv_idx = -1;
  1310. mutex_lock(&cpas_core->tree_lock);
  1311. if (!cpas_client->tree_node_valid) {
  1312. /*
  1313. * This is by assuming apply_client_axi_vote is called
  1314. * for these clients from only cpas_start, cpas_stop.
  1315. * not called from hw_update_axi_vote
  1316. */
  1317. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  1318. if (cpas_core->axi_port[i].bus_client.common_data.is_drv_port)
  1319. continue;
  1320. if (axi_vote->axi_path[0].mnoc_ab_bw) {
  1321. /* start case */
  1322. cpas_core->axi_port[i].additional_bw +=
  1323. CAM_CPAS_DEFAULT_AXI_BW;
  1324. } else {
  1325. /* stop case */
  1326. cpas_core->axi_port[i].additional_bw -=
  1327. CAM_CPAS_DEFAULT_AXI_BW;
  1328. }
  1329. mnoc_axi_port_updated[i] = true;
  1330. }
  1331. for (i = 0; i < cpas_core->num_camnoc_axi_ports; i++) {
  1332. if (axi_vote->axi_path[0].camnoc_bw) {
  1333. /* start case */
  1334. cpas_core->camnoc_axi_port[i].additional_bw +=
  1335. CAM_CPAS_DEFAULT_AXI_BW;
  1336. } else {
  1337. /* stop case */
  1338. cpas_core->camnoc_axi_port[i].additional_bw -=
  1339. CAM_CPAS_DEFAULT_AXI_BW;
  1340. }
  1341. camnoc_axi_port_updated[i] = true;
  1342. }
  1343. goto vote_start_clients;
  1344. }
  1345. rc = cam_cpas_axi_consolidate_path_votes(cpas_client, axi_vote);
  1346. if (rc) {
  1347. CAM_ERR(CAM_PERF, "Failed in bw consolidation, Client [%s][%d]",
  1348. cpas_client->data.identifier,
  1349. cpas_client->data.cell_index);
  1350. goto unlock_tree;
  1351. }
  1352. con_axi_vote = &cpas_client->axi_vote;
  1353. cam_cpas_dump_axi_vote_info(cpas_client, "Consolidated Vote", con_axi_vote);
  1354. cam_cpas_dump_full_tree_state(cpas_hw, "BeforeClientVoteUpdate");
  1355. /* Traverse through node tree and update bw vote values */
  1356. for (i = 0; i < con_axi_vote->num_paths; i++) {
  1357. camnoc_unchanged = false;
  1358. path_data_type = con_axi_vote->axi_path[i].path_data_type;
  1359. transac_type = con_axi_vote->axi_path[i].transac_type;
  1360. curr_tree_node = cpas_client->tree_node[path_data_type][transac_type];
  1361. ddr_drv_idx = curr_tree_node->drv_voting_idx;
  1362. cesta_drv_idx = curr_tree_node->drv_voting_idx;
  1363. if (!soc_private->enable_cam_ddr_drv || cpas_core->force_hlos_drv) {
  1364. ddr_drv_idx = CAM_CPAS_PORT_HLOS_DRV;
  1365. cesta_drv_idx = CAM_CPAS_PORT_HLOS_DRV;
  1366. } else if (!soc_private->enable_cam_clk_drv || cpas_core->force_cesta_sw_client) {
  1367. cesta_drv_idx = CAM_CPAS_PORT_HLOS_DRV;
  1368. }
  1369. if ((ddr_drv_idx < 0) || (ddr_drv_idx > CAM_CPAS_PORT_DRV_2) ||
  1370. (cesta_drv_idx < 0) || (cesta_drv_idx > CAM_CPAS_PORT_DRV_2)) {
  1371. CAM_ERR(CAM_CPAS, "Invalid drv idx : ddr_drv_idx=%d, cesta_drv_idx=%d",
  1372. ddr_drv_idx, cesta_drv_idx);
  1373. goto unlock_tree;
  1374. }
  1375. if (i == 0) {
  1376. first_ddr_drv_idx = ddr_drv_idx;
  1377. first_cesta_drv_idx = cesta_drv_idx;
  1378. } else if ((first_ddr_drv_idx != ddr_drv_idx) ||
  1379. (first_cesta_drv_idx != cesta_drv_idx)) {
  1380. /*
  1381. * drv indices won't change for a given client for different paths in a
  1382. * given axi vote update
  1383. */
  1384. CAM_WARN(CAM_CPAS, "DRV indices different : DDR: %d, %d, CESTA %d %d",
  1385. first_ddr_drv_idx, ddr_drv_idx, first_cesta_drv_idx, cesta_drv_idx);
  1386. }
  1387. memcpy(&curr_camnoc_old, &curr_tree_node->bw_info[cesta_drv_idx],
  1388. sizeof(struct cam_cpas_axi_bw_info));
  1389. memcpy(&curr_mnoc_old, &curr_tree_node->bw_info[ddr_drv_idx],
  1390. sizeof(struct cam_cpas_axi_bw_info));
  1391. cam_cpas_dump_tree_vote_info(cpas_hw, curr_tree_node, "Level0 before update",
  1392. ddr_drv_idx, cesta_drv_idx);
  1393. /* Check and update camnoc bw first */
  1394. if (con_axi_vote->axi_path[i].vote_level == CAM_CPAS_VOTE_LEVEL_HIGH) {
  1395. if ((apply_type != CAM_CPAS_APPLY_TYPE_STOP) &&
  1396. (curr_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc ==
  1397. con_axi_vote->axi_path[i].camnoc_bw)) {
  1398. camnoc_unchanged = true;
  1399. goto update_l0_mnoc;
  1400. }
  1401. curr_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc =
  1402. con_axi_vote->axi_path[i].camnoc_bw;
  1403. curr_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc = 0;
  1404. } else {
  1405. if (cesta_drv_idx > CAM_CPAS_PORT_HLOS_DRV) {
  1406. if ((apply_type != CAM_CPAS_APPLY_TYPE_STOP) &&
  1407. (curr_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc
  1408. == con_axi_vote->axi_path[i].camnoc_bw)) {
  1409. camnoc_unchanged = true;
  1410. goto update_l0_mnoc;
  1411. }
  1412. curr_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc =
  1413. con_axi_vote->axi_path[i].camnoc_bw;
  1414. curr_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc = 0;
  1415. } else {
  1416. if (curr_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc ==
  1417. con_axi_vote->axi_path[i].camnoc_bw) {
  1418. camnoc_unchanged = true;
  1419. goto update_l0_mnoc;
  1420. }
  1421. curr_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc =
  1422. con_axi_vote->axi_path[i].camnoc_bw;
  1423. }
  1424. }
  1425. update_l0_mnoc:
  1426. /* Check and update mnoc ab and ib */
  1427. if (con_axi_vote->axi_path[i].vote_level == CAM_CPAS_VOTE_LEVEL_HIGH) {
  1428. if ((apply_type != CAM_CPAS_APPLY_TYPE_STOP) && camnoc_unchanged &&
  1429. (curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab ==
  1430. con_axi_vote->axi_path[i].mnoc_ab_bw) &&
  1431. (curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib ==
  1432. con_axi_vote->axi_path[i].mnoc_ib_bw))
  1433. continue;
  1434. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab =
  1435. con_axi_vote->axi_path[i].mnoc_ab_bw;
  1436. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib =
  1437. con_axi_vote->axi_path[i].mnoc_ib_bw;
  1438. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab = 0;
  1439. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib = 0;
  1440. } else {
  1441. if (ddr_drv_idx > CAM_CPAS_PORT_HLOS_DRV) {
  1442. if ((apply_type != CAM_CPAS_APPLY_TYPE_STOP) && camnoc_unchanged &&
  1443. (curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab ==
  1444. con_axi_vote->axi_path[i].mnoc_ab_bw) &&
  1445. (curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib ==
  1446. con_axi_vote->axi_path[i].mnoc_ib_bw))
  1447. continue;
  1448. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab =
  1449. con_axi_vote->axi_path[i].mnoc_ab_bw;
  1450. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib =
  1451. con_axi_vote->axi_path[i].mnoc_ib_bw;
  1452. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab = 0;
  1453. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib = 0;
  1454. } else {
  1455. if (camnoc_unchanged &&
  1456. (curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ab ==
  1457. con_axi_vote->axi_path[i].mnoc_ab_bw) &&
  1458. (curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ib ==
  1459. con_axi_vote->axi_path[i].mnoc_ib_bw))
  1460. continue;
  1461. curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ab =
  1462. con_axi_vote->axi_path[i].mnoc_ab_bw;
  1463. curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ib =
  1464. con_axi_vote->axi_path[i].mnoc_ib_bw;
  1465. }
  1466. }
  1467. cam_cpas_dump_tree_vote_info(cpas_hw, curr_tree_node, "Level0 after update",
  1468. ddr_drv_idx, cesta_drv_idx);
  1469. while (curr_tree_node->parent_node) {
  1470. par_tree_node = curr_tree_node->parent_node;
  1471. memcpy(&par_camnoc_old, &par_tree_node->bw_info[cesta_drv_idx],
  1472. sizeof(struct cam_cpas_axi_bw_info));
  1473. memcpy(&par_mnoc_old, &par_tree_node->bw_info[ddr_drv_idx],
  1474. sizeof(struct cam_cpas_axi_bw_info));
  1475. cam_cpas_dump_tree_vote_info(cpas_hw, par_tree_node, "Parent before update",
  1476. ddr_drv_idx, cesta_drv_idx);
  1477. if (par_tree_node->merge_type == CAM_CPAS_TRAFFIC_MERGE_SUM) {
  1478. merge_type_factor = 1;
  1479. } else if (par_tree_node->merge_type ==
  1480. CAM_CPAS_TRAFFIC_MERGE_SUM_INTERLEAVE) {
  1481. merge_type_factor = 2;
  1482. } else {
  1483. CAM_ERR(CAM_CPAS, "Invalid Merge type");
  1484. rc = -EINVAL;
  1485. goto unlock_tree;
  1486. }
  1487. /*
  1488. * Remove contribution of current node old camnoc bw from parent,
  1489. * then add new camnoc bw of current level to the parent
  1490. */
  1491. if (cesta_drv_idx > CAM_CPAS_PORT_HLOS_DRV) {
  1492. par_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc -=
  1493. (curr_camnoc_old.drv_vote.high.camnoc/merge_type_factor);
  1494. par_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc -=
  1495. (curr_camnoc_old.drv_vote.low.camnoc/merge_type_factor);
  1496. par_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc +=
  1497. (curr_tree_node->bw_info[cesta_drv_idx].drv_vote.high.camnoc/
  1498. merge_type_factor);
  1499. par_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc +=
  1500. (curr_tree_node->bw_info[cesta_drv_idx].drv_vote.low.camnoc/
  1501. merge_type_factor);
  1502. } else {
  1503. par_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc -=
  1504. (curr_camnoc_old.hlos_vote.camnoc/merge_type_factor);
  1505. par_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc +=
  1506. (curr_tree_node->bw_info[cesta_drv_idx].hlos_vote.camnoc/
  1507. merge_type_factor);
  1508. }
  1509. /*
  1510. * Remove contribution of current node old mnoc bw from parent,
  1511. * then add new mnoc bw of current level to the parent
  1512. */
  1513. if (ddr_drv_idx > CAM_CPAS_PORT_HLOS_DRV) {
  1514. par_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab -=
  1515. curr_mnoc_old.drv_vote.high.ab;
  1516. par_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib -=
  1517. curr_mnoc_old.drv_vote.high.ib;
  1518. par_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab -=
  1519. curr_mnoc_old.drv_vote.low.ab;
  1520. par_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib -=
  1521. curr_mnoc_old.drv_vote.low.ib;
  1522. par_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab +=
  1523. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ab;
  1524. par_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib +=
  1525. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.high.ib;
  1526. par_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab +=
  1527. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ab;
  1528. par_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib +=
  1529. curr_tree_node->bw_info[ddr_drv_idx].drv_vote.low.ib;
  1530. } else {
  1531. par_tree_node->bw_info[ddr_drv_idx].hlos_vote.ab -=
  1532. curr_mnoc_old.hlos_vote.ab;
  1533. par_tree_node->bw_info[ddr_drv_idx].hlos_vote.ib -=
  1534. curr_mnoc_old.hlos_vote.ib;
  1535. par_tree_node->bw_info[ddr_drv_idx].hlos_vote.ab +=
  1536. curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ab;
  1537. par_tree_node->bw_info[ddr_drv_idx].hlos_vote.ib +=
  1538. curr_tree_node->bw_info[ddr_drv_idx].hlos_vote.ib;
  1539. }
  1540. cam_cpas_dump_tree_vote_info(cpas_hw, par_tree_node, "Parent after update",
  1541. ddr_drv_idx, cesta_drv_idx);
  1542. if (!par_tree_node->parent_node) {
  1543. rc = cam_cpas_update_axi_vote_bw(cpas_hw, par_tree_node,
  1544. ddr_drv_idx, cesta_drv_idx, mnoc_axi_port_updated,
  1545. camnoc_axi_port_updated);
  1546. if (rc) {
  1547. CAM_ERR(CAM_CPAS, "Update Vote failed");
  1548. goto unlock_tree;
  1549. }
  1550. }
  1551. curr_tree_node = par_tree_node;
  1552. memcpy(&curr_camnoc_old, &par_camnoc_old,
  1553. sizeof(struct cam_cpas_axi_bw_info));
  1554. memcpy(&curr_mnoc_old, &par_mnoc_old, sizeof(struct cam_cpas_axi_bw_info));
  1555. }
  1556. }
  1557. cam_cpas_dump_full_tree_state(cpas_hw, "AfterClientVoteUpdate");
  1558. if (!par_tree_node) {
  1559. CAM_DBG(CAM_CPAS, "No change in BW for all paths");
  1560. rc = 0;
  1561. goto unlock_tree;
  1562. }
  1563. if (soc_private->enable_smart_qos) {
  1564. CAM_DBG(CAM_PERF, "Start QoS update for client[%s][%d]",
  1565. cpas_client->data.identifier, cpas_client->data.cell_index);
  1566. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  1567. if (mnoc_axi_port_updated[i] && cpas_core->axi_port[i].is_rt) {
  1568. rt_bw_updated = true;
  1569. break;
  1570. }
  1571. }
  1572. if (rt_bw_updated) {
  1573. apply_smart_qos = cam_cpas_calculate_smart_qos(cpas_hw);
  1574. if (apply_smart_qos && cam_cpas_is_new_rt_bw_lower(cpas_hw)) {
  1575. /*
  1576. * If new BW is low, apply QoS first and then vote,
  1577. * otherwise vote first and then apply QoS
  1578. */
  1579. CAM_DBG(CAM_PERF, "Apply Smart QoS first");
  1580. rc = cam_cpas_apply_smart_qos(cpas_hw);
  1581. if (rc) {
  1582. CAM_ERR(CAM_CPAS,
  1583. "Failed in Smart QoS rc=%d", rc);
  1584. goto unlock_tree;
  1585. }
  1586. apply_smart_qos = false;
  1587. }
  1588. }
  1589. }
  1590. vote_start_clients:
  1591. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  1592. if (mnoc_axi_port_updated[i])
  1593. mnoc_axi_port = &cpas_core->axi_port[i];
  1594. else
  1595. continue;
  1596. memcpy(&curr_port_bw, &mnoc_axi_port->curr_bw, sizeof(struct cam_cpas_axi_bw_info));
  1597. if (mnoc_axi_port->bus_client.common_data.is_drv_port) {
  1598. CAM_DBG(CAM_PERF,
  1599. "Port[%s] :DRV high [%lld %lld] low [%lld %lld] streamon_clients=%d",
  1600. mnoc_axi_port->axi_port_name,
  1601. mnoc_axi_port->curr_bw.drv_vote.high.ab,
  1602. mnoc_axi_port->curr_bw.drv_vote.high.ib,
  1603. mnoc_axi_port->curr_bw.drv_vote.low.ab,
  1604. mnoc_axi_port->curr_bw.drv_vote.low.ib,
  1605. cpas_core->streamon_clients);
  1606. if (!mnoc_axi_port->ib_bw_voting_needed) {
  1607. curr_port_bw.drv_vote.high.ib = 0;
  1608. curr_port_bw.drv_vote.low.ib = 0;
  1609. }
  1610. /* Vote bw on appropriate bus id */
  1611. rc = cam_cpas_util_vote_drv_bus_client_bw(&mnoc_axi_port->bus_client,
  1612. &curr_port_bw, &applied_port_bw);
  1613. if (rc) {
  1614. CAM_ERR(CAM_CPAS, "Failed in mnoc vote for %s rc=%d",
  1615. mnoc_axi_port->axi_port_name, rc);
  1616. goto unlock_tree;
  1617. }
  1618. /* Do start/stop/channel switch based on apply type */
  1619. if ((apply_type == CAM_CPAS_APPLY_TYPE_START) &&
  1620. !mnoc_axi_port->is_drv_started) {
  1621. rc = cam_cpas_start_drv_for_dev(mnoc_axi_port->cam_rsc_dev);
  1622. if (rc) {
  1623. CAM_ERR(CAM_CPAS, "Port[%s] failed in DRV start rc:%d",
  1624. mnoc_axi_port->axi_port_name, rc);
  1625. goto unlock_tree;
  1626. }
  1627. if (debug_drv)
  1628. CAM_INFO(CAM_CPAS, "Started rsc dev %s mnoc port:%s",
  1629. dev_name(mnoc_axi_port->cam_rsc_dev),
  1630. mnoc_axi_port->axi_port_name);
  1631. CAM_DBG(CAM_CPAS, "Started rsc dev %s mnoc port:%s",
  1632. dev_name(mnoc_axi_port->cam_rsc_dev),
  1633. mnoc_axi_port->axi_port_name);
  1634. mnoc_axi_port->is_drv_started = true;
  1635. } else if ((apply_type == CAM_CPAS_APPLY_TYPE_STOP) &&
  1636. mnoc_axi_port->is_drv_started &&
  1637. (applied_port_bw.drv_vote.high.ab == 0) &&
  1638. (applied_port_bw.drv_vote.high.ib == 0) &&
  1639. (applied_port_bw.drv_vote.low.ab == 0) &&
  1640. (applied_port_bw.drv_vote.low.ib == 0)) {
  1641. rc = cam_cpas_stop_drv_for_dev(mnoc_axi_port->cam_rsc_dev);
  1642. if (rc) {
  1643. CAM_ERR(CAM_CPAS, "Port[%s] failed in DRV stop rc:%d",
  1644. mnoc_axi_port->axi_port_name, rc);
  1645. goto unlock_tree;
  1646. }
  1647. if (debug_drv)
  1648. CAM_INFO(CAM_CPAS, "Stopped rsc dev %s mnoc port:%s",
  1649. dev_name(mnoc_axi_port->cam_rsc_dev),
  1650. mnoc_axi_port->axi_port_name);
  1651. CAM_DBG(CAM_CPAS, "Stopped rsc dev %s mnoc port:%s",
  1652. dev_name(mnoc_axi_port->cam_rsc_dev),
  1653. mnoc_axi_port->axi_port_name);
  1654. mnoc_axi_port->is_drv_started = false;
  1655. } else {
  1656. if (mnoc_axi_port->is_drv_started) {
  1657. rc = cam_cpas_drv_channel_switch_for_dev(
  1658. mnoc_axi_port->cam_rsc_dev);
  1659. if (rc) {
  1660. CAM_ERR(CAM_CPAS,
  1661. "Port[%s] failed in channel switch rc:%d",
  1662. mnoc_axi_port->axi_port_name, rc);
  1663. goto unlock_tree;
  1664. }
  1665. if (debug_drv)
  1666. CAM_INFO(CAM_CPAS,
  1667. "Channel switch for rsc dev %s mnoc port:%s",
  1668. dev_name(mnoc_axi_port->cam_rsc_dev),
  1669. mnoc_axi_port->axi_port_name);
  1670. CAM_DBG(CAM_CPAS,
  1671. "Channel switch for rsc dev %s mnoc port:%s",
  1672. dev_name(mnoc_axi_port->cam_rsc_dev),
  1673. mnoc_axi_port->axi_port_name);
  1674. }
  1675. }
  1676. } else {
  1677. CAM_DBG(CAM_PERF,
  1678. "Port[%s] :HLOS ab=%lld ib=%lld additional=%lld, streamon_clients=%d",
  1679. mnoc_axi_port->axi_port_name, mnoc_axi_port->curr_bw.hlos_vote.ab,
  1680. mnoc_axi_port->curr_bw.hlos_vote.ib, mnoc_axi_port->additional_bw,
  1681. cpas_core->streamon_clients);
  1682. if (!mnoc_axi_port->curr_bw.hlos_vote.ab) {
  1683. if (mnoc_axi_port->additional_bw)
  1684. curr_port_bw.hlos_vote.ab = mnoc_axi_port->additional_bw;
  1685. else if (cpas_core->streamon_clients)
  1686. curr_port_bw.hlos_vote.ab = CAM_CPAS_DEFAULT_AXI_BW;
  1687. else
  1688. curr_port_bw.hlos_vote.ab = 0;
  1689. }
  1690. if (!mnoc_axi_port->ib_bw_voting_needed)
  1691. curr_port_bw.hlos_vote.ib = 0;
  1692. rc = cam_cpas_util_vote_hlos_bus_client_bw(&mnoc_axi_port->bus_client,
  1693. curr_port_bw.hlos_vote.ab, curr_port_bw.hlos_vote.ib, false,
  1694. &applied_port_bw.hlos_vote.ab, &applied_port_bw.hlos_vote.ib);
  1695. if (rc) {
  1696. CAM_ERR(CAM_CPAS, "Failed in mnoc vote for %s rc=%d",
  1697. mnoc_axi_port->axi_port_name, rc);
  1698. goto unlock_tree;
  1699. }
  1700. }
  1701. memcpy(&mnoc_axi_port->applied_bw, &applied_port_bw,
  1702. sizeof(struct cam_cpas_axi_bw_info));
  1703. }
  1704. if (soc_private->control_camnoc_axi_clk) {
  1705. rc = cam_cpas_util_set_camnoc_axi_clk_rate(cpas_hw, cesta_drv_idx);
  1706. if (rc) {
  1707. CAM_ERR(CAM_CPAS, "Failed in setting axi clk rate rc=%d", rc);
  1708. goto unlock_tree;
  1709. }
  1710. } else {
  1711. rc = cam_cpas_camnoc_set_bw_vote(cpas_hw, camnoc_axi_port_updated);
  1712. if (rc) {
  1713. CAM_ERR(CAM_CPAS, "Failed in setting camnoc bw vote rc=%d", rc);
  1714. goto unlock_tree;
  1715. }
  1716. }
  1717. if (soc_private->enable_smart_qos && apply_smart_qos) {
  1718. CAM_DBG(CAM_PERF, "Apply Smart QoS after bw votes");
  1719. rc = cam_cpas_apply_smart_qos(cpas_hw);
  1720. if (rc) {
  1721. CAM_ERR(CAM_CPAS, "Failed in Smart QoS rc=%d", rc);
  1722. goto unlock_tree;
  1723. }
  1724. }
  1725. unlock_tree:
  1726. mutex_unlock(&cpas_core->tree_lock);
  1727. return rc;
  1728. }
  1729. static int cam_cpas_util_apply_default_axi_vote(
  1730. struct cam_hw_info *cpas_hw, bool enable)
  1731. {
  1732. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1733. struct cam_cpas_axi_port *axi_port = NULL;
  1734. uint64_t mnoc_ab_bw = 0, mnoc_ib_bw = 0;
  1735. int rc = 0, i = 0;
  1736. mutex_lock(&cpas_core->tree_lock);
  1737. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  1738. if ((!cpas_core->axi_port[i].bus_client.common_data.is_drv_port) &&
  1739. (!cpas_core->axi_port[i].curr_bw.hlos_vote.ab ||
  1740. !cpas_core->axi_port[i].curr_bw.hlos_vote.ib))
  1741. axi_port = &cpas_core->axi_port[i];
  1742. else
  1743. continue;
  1744. if (enable)
  1745. mnoc_ib_bw = CAM_CPAS_DEFAULT_AXI_BW;
  1746. else
  1747. mnoc_ib_bw = 0;
  1748. CAM_DBG(CAM_CPAS, "Port=[%s] :ab[%llu] ib[%llu]",
  1749. axi_port->axi_port_name, mnoc_ab_bw, mnoc_ib_bw);
  1750. rc = cam_cpas_util_vote_hlos_bus_client_bw(&axi_port->bus_client,
  1751. mnoc_ab_bw, mnoc_ib_bw, false, &axi_port->applied_bw.hlos_vote.ab,
  1752. &axi_port->applied_bw.hlos_vote.ib);
  1753. if (rc) {
  1754. CAM_ERR(CAM_CPAS,
  1755. "Failed in mnoc vote ab[%llu] ib[%llu] rc=%d",
  1756. mnoc_ab_bw, mnoc_ib_bw, rc);
  1757. goto unlock_tree;
  1758. }
  1759. }
  1760. unlock_tree:
  1761. mutex_unlock(&cpas_core->tree_lock);
  1762. return rc;
  1763. }
  1764. static int cam_cpas_hw_update_axi_vote(struct cam_hw_info *cpas_hw,
  1765. uint32_t client_handle, struct cam_axi_vote *client_axi_vote)
  1766. {
  1767. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1768. struct cam_cpas_client *cpas_client = NULL;
  1769. struct cam_axi_vote *axi_vote = NULL;
  1770. uint32_t client_indx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  1771. int rc = 0;
  1772. if (!client_axi_vote) {
  1773. CAM_ERR(CAM_CPAS, "Invalid arg, client_handle=%d",
  1774. client_handle);
  1775. return -EINVAL;
  1776. }
  1777. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  1778. return -EINVAL;
  1779. mutex_lock(&cpas_hw->hw_mutex);
  1780. mutex_lock(&cpas_core->client_mutex[client_indx]);
  1781. axi_vote = kmemdup(client_axi_vote, sizeof(struct cam_axi_vote),
  1782. GFP_KERNEL);
  1783. if (!axi_vote) {
  1784. CAM_ERR(CAM_CPAS, "Out of memory");
  1785. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  1786. mutex_unlock(&cpas_hw->hw_mutex);
  1787. return -ENOMEM;
  1788. }
  1789. cam_cpas_dump_axi_vote_info(cpas_core->cpas_client[client_indx],
  1790. "Incoming Vote", axi_vote);
  1791. cpas_client = cpas_core->cpas_client[client_indx];
  1792. if (!CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  1793. CAM_ERR(CAM_CPAS, "client=[%d][%s][%d] has not started",
  1794. client_indx, cpas_client->data.identifier,
  1795. cpas_client->data.cell_index);
  1796. rc = -EPERM;
  1797. goto unlock_client;
  1798. }
  1799. rc = cam_cpas_util_translate_client_paths(axi_vote);
  1800. if (rc) {
  1801. CAM_ERR(CAM_CPAS,
  1802. "Unable to translate per path votes rc: %d", rc);
  1803. goto unlock_client;
  1804. }
  1805. cam_cpas_dump_axi_vote_info(cpas_core->cpas_client[client_indx],
  1806. "Translated Vote", axi_vote);
  1807. rc = cam_cpas_util_apply_client_axi_vote(cpas_hw,
  1808. cpas_core->cpas_client[client_indx], axi_vote, CAM_CPAS_APPLY_TYPE_UPDATE);
  1809. /* Log an entry whenever there is an AXI update - after updating */
  1810. cam_cpas_update_monitor_array(cpas_hw, "CPAS AXI post-update",
  1811. client_indx);
  1812. unlock_client:
  1813. cam_free_clear((void *)axi_vote);
  1814. axi_vote = NULL;
  1815. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  1816. mutex_unlock(&cpas_hw->hw_mutex);
  1817. return rc;
  1818. }
  1819. static int cam_cpas_util_get_ahb_level(struct cam_hw_info *cpas_hw,
  1820. struct device *dev, unsigned long freq, enum cam_vote_level *req_level)
  1821. {
  1822. struct cam_cpas_private_soc *soc_private =
  1823. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  1824. struct dev_pm_opp *opp;
  1825. unsigned int corner;
  1826. enum cam_vote_level level = CAM_LOWSVS_D1_VOTE;
  1827. unsigned long corner_freq = freq;
  1828. int i;
  1829. if (!dev || !req_level) {
  1830. CAM_ERR(CAM_CPAS, "Invalid params %pK, %pK", dev, req_level);
  1831. return -EINVAL;
  1832. }
  1833. opp = dev_pm_opp_find_freq_ceil(dev, &corner_freq);
  1834. if (IS_ERR(opp)) {
  1835. CAM_DBG(CAM_CPAS, "OPP Ceil not available for freq :%ld, %pK",
  1836. corner_freq, opp);
  1837. *req_level = CAM_TURBO_VOTE;
  1838. return 0;
  1839. }
  1840. corner = dev_pm_opp_get_voltage(opp);
  1841. for (i = 0; i < soc_private->num_vdd_ahb_mapping; i++)
  1842. if (corner == soc_private->vdd_ahb[i].vdd_corner)
  1843. level = soc_private->vdd_ahb[i].ahb_level;
  1844. CAM_DBG(CAM_CPAS,
  1845. "From OPP table : freq=[%ld][%ld], corner=%d, level=%d",
  1846. freq, corner_freq, corner, level);
  1847. *req_level = level;
  1848. return 0;
  1849. }
  1850. static int cam_cpas_util_apply_client_ahb_vote(struct cam_hw_info *cpas_hw,
  1851. struct cam_cpas_client *cpas_client, struct cam_ahb_vote *ahb_vote,
  1852. enum cam_vote_level *applied_level)
  1853. {
  1854. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1855. struct cam_cpas_bus_client *ahb_bus_client = &cpas_core->ahb_bus_client;
  1856. enum cam_vote_level required_level;
  1857. enum cam_vote_level highest_level;
  1858. int i, rc = 0;
  1859. if (!ahb_bus_client->valid) {
  1860. CAM_ERR(CAM_CPAS, "AHB Bus client not valid");
  1861. return -EINVAL;
  1862. }
  1863. if (ahb_vote->type == CAM_VOTE_DYNAMIC) {
  1864. rc = cam_cpas_util_get_ahb_level(cpas_hw, cpas_client->data.dev,
  1865. ahb_vote->vote.freq, &required_level);
  1866. if (rc)
  1867. return rc;
  1868. } else {
  1869. required_level = ahb_vote->vote.level;
  1870. }
  1871. if (cpas_client->ahb_level == required_level)
  1872. return 0;
  1873. mutex_lock(&ahb_bus_client->lock);
  1874. cpas_client->ahb_level = required_level;
  1875. CAM_DBG(CAM_CPAS, "Client[%s] required level[%d], curr_level[%d]",
  1876. ahb_bus_client->common_data.name, required_level,
  1877. ahb_bus_client->curr_vote_level);
  1878. if (required_level == ahb_bus_client->curr_vote_level)
  1879. goto unlock_bus_client;
  1880. highest_level = required_level;
  1881. for (i = 0; i < cpas_core->num_clients; i++) {
  1882. if (cpas_core->cpas_client[i] && (highest_level <
  1883. cpas_core->cpas_client[i]->ahb_level))
  1884. highest_level = cpas_core->cpas_client[i]->ahb_level;
  1885. }
  1886. CAM_DBG(CAM_CPAS, "Required highest_level[%d]", highest_level);
  1887. if (!cpas_core->ahb_bus_scaling_disable) {
  1888. rc = cam_cpas_util_vote_bus_client_level(ahb_bus_client,
  1889. highest_level);
  1890. if (rc) {
  1891. CAM_ERR(CAM_CPAS, "Failed in ahb vote, level=%d, rc=%d",
  1892. highest_level, rc);
  1893. goto unlock_bus_client;
  1894. }
  1895. }
  1896. if (cpas_core->streamon_clients) {
  1897. rc = cam_soc_util_set_clk_rate_level(&cpas_hw->soc_info, CAM_CLK_SW_CLIENT_IDX,
  1898. highest_level, 0, true);
  1899. if (rc) {
  1900. CAM_ERR(CAM_CPAS,
  1901. "Failed in scaling clock rate level %d for AHB",
  1902. highest_level);
  1903. goto unlock_bus_client;
  1904. }
  1905. }
  1906. if (applied_level)
  1907. *applied_level = highest_level;
  1908. unlock_bus_client:
  1909. mutex_unlock(&ahb_bus_client->lock);
  1910. return rc;
  1911. }
  1912. static int cam_cpas_hw_update_ahb_vote(struct cam_hw_info *cpas_hw,
  1913. uint32_t client_handle, struct cam_ahb_vote *client_ahb_vote)
  1914. {
  1915. struct cam_ahb_vote ahb_vote;
  1916. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  1917. struct cam_cpas_client *cpas_client = NULL;
  1918. uint32_t client_indx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  1919. int rc = 0;
  1920. if (!client_ahb_vote) {
  1921. CAM_ERR(CAM_CPAS, "Invalid input arg");
  1922. return -EINVAL;
  1923. }
  1924. ahb_vote = *client_ahb_vote;
  1925. if (ahb_vote.vote.level == 0) {
  1926. CAM_DBG(CAM_CPAS, "0 ahb vote from client %d",
  1927. client_handle);
  1928. ahb_vote.type = CAM_VOTE_ABSOLUTE;
  1929. ahb_vote.vote.level = CAM_LOWSVS_D1_VOTE;
  1930. }
  1931. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  1932. return -EINVAL;
  1933. mutex_lock(&cpas_hw->hw_mutex);
  1934. mutex_lock(&cpas_core->client_mutex[client_indx]);
  1935. cpas_client = cpas_core->cpas_client[client_indx];
  1936. if (!CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  1937. CAM_ERR(CAM_CPAS, "client=[%d][%s][%d] has not started",
  1938. client_indx, cpas_client->data.identifier,
  1939. cpas_client->data.cell_index);
  1940. rc = -EPERM;
  1941. goto unlock_client;
  1942. }
  1943. CAM_DBG(CAM_PERF,
  1944. "client=[%d][%s][%d] : type[%d], level[%d], freq[%ld], applied[%d]",
  1945. client_indx, cpas_client->data.identifier,
  1946. cpas_client->data.cell_index, ahb_vote.type,
  1947. ahb_vote.vote.level, ahb_vote.vote.freq,
  1948. cpas_core->cpas_client[client_indx]->ahb_level);
  1949. rc = cam_cpas_util_apply_client_ahb_vote(cpas_hw,
  1950. cpas_core->cpas_client[client_indx], &ahb_vote, NULL);
  1951. unlock_client:
  1952. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  1953. mutex_unlock(&cpas_hw->hw_mutex);
  1954. return rc;
  1955. }
  1956. static int cam_cpas_util_create_vote_all_paths(
  1957. struct cam_cpas_client *cpas_client,
  1958. struct cam_axi_vote *axi_vote)
  1959. {
  1960. int i, j;
  1961. uint64_t camnoc_bw, mnoc_ab_bw, mnoc_ib_bw;
  1962. struct cam_cpas_axi_per_path_bw_vote *axi_path;
  1963. if (!cpas_client || !axi_vote)
  1964. return -EINVAL;
  1965. camnoc_bw = axi_vote->axi_path[0].camnoc_bw;
  1966. mnoc_ab_bw = axi_vote->axi_path[0].mnoc_ab_bw;
  1967. mnoc_ib_bw = axi_vote->axi_path[0].mnoc_ib_bw;
  1968. axi_vote->num_paths = 0;
  1969. for (i = 0; i < CAM_CPAS_TRANSACTION_MAX; i++) {
  1970. for (j = 0; j < CAM_CPAS_PATH_DATA_MAX; j++) {
  1971. if (cpas_client->tree_node[j][i]) {
  1972. axi_path = &axi_vote->axi_path[axi_vote->num_paths];
  1973. axi_path->path_data_type = j;
  1974. axi_path->transac_type = i;
  1975. axi_path->camnoc_bw = camnoc_bw;
  1976. axi_path->mnoc_ab_bw = mnoc_ab_bw;
  1977. axi_path->mnoc_ib_bw = mnoc_ib_bw;
  1978. if (cpas_client->tree_node[j][i]->drv_voting_idx >
  1979. CAM_CPAS_PORT_HLOS_DRV)
  1980. axi_path->vote_level = CAM_CPAS_VOTE_LEVEL_LOW;
  1981. axi_vote->num_paths++;
  1982. }
  1983. }
  1984. }
  1985. return 0;
  1986. }
  1987. static int cam_cpas_hw_start(void *hw_priv, void *start_args,
  1988. uint32_t arg_size)
  1989. {
  1990. struct cam_hw_info *cpas_hw;
  1991. struct cam_cpas *cpas_core;
  1992. uint32_t client_indx;
  1993. struct cam_cpas_hw_cmd_start *cmd_hw_start;
  1994. struct cam_cpas_client *cpas_client;
  1995. struct cam_ahb_vote *ahb_vote;
  1996. struct cam_ahb_vote remove_ahb;
  1997. struct cam_axi_vote axi_vote = {0};
  1998. enum cam_vote_level applied_level = CAM_LOWSVS_D1_VOTE;
  1999. int rc, i = 0, err_val = 0;
  2000. struct cam_cpas_private_soc *soc_private = NULL;
  2001. bool invalid_start = true;
  2002. int count;
  2003. if (!hw_priv || !start_args) {
  2004. CAM_ERR(CAM_CPAS, "Invalid arguments %pK %pK",
  2005. hw_priv, start_args);
  2006. return -EINVAL;
  2007. }
  2008. if (sizeof(struct cam_cpas_hw_cmd_start) != arg_size) {
  2009. CAM_ERR(CAM_CPAS, "HW_CAPS size mismatch %zd %d",
  2010. sizeof(struct cam_cpas_hw_cmd_start), arg_size);
  2011. return -EINVAL;
  2012. }
  2013. cpas_hw = (struct cam_hw_info *)hw_priv;
  2014. cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2015. soc_private = (struct cam_cpas_private_soc *)
  2016. cpas_hw->soc_info.soc_private;
  2017. cmd_hw_start = (struct cam_cpas_hw_cmd_start *)start_args;
  2018. client_indx = CAM_CPAS_GET_CLIENT_IDX(cmd_hw_start->client_handle);
  2019. ahb_vote = cmd_hw_start->ahb_vote;
  2020. if (!ahb_vote || !cmd_hw_start->axi_vote)
  2021. return -EINVAL;
  2022. if (!ahb_vote->vote.level) {
  2023. CAM_ERR(CAM_CPAS, "Invalid vote ahb[%d]",
  2024. ahb_vote->vote.level);
  2025. return -EINVAL;
  2026. }
  2027. memcpy(&axi_vote, cmd_hw_start->axi_vote, sizeof(struct cam_axi_vote));
  2028. for (i = 0; i < axi_vote.num_paths; i++) {
  2029. if ((axi_vote.axi_path[i].camnoc_bw != 0) ||
  2030. (axi_vote.axi_path[i].mnoc_ab_bw != 0) ||
  2031. (axi_vote.axi_path[i].mnoc_ib_bw != 0)) {
  2032. invalid_start = false;
  2033. break;
  2034. }
  2035. }
  2036. if (invalid_start) {
  2037. CAM_ERR(CAM_CPAS, "Zero start vote");
  2038. return -EINVAL;
  2039. }
  2040. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  2041. return -EINVAL;
  2042. mutex_lock(&cpas_hw->hw_mutex);
  2043. mutex_lock(&cpas_core->client_mutex[client_indx]);
  2044. cpas_client = cpas_core->cpas_client[client_indx];
  2045. if (!CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx)) {
  2046. CAM_ERR(CAM_CPAS, "client=[%d] is not registered",
  2047. client_indx);
  2048. rc = -EPERM;
  2049. goto error;
  2050. }
  2051. if (CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  2052. CAM_ERR(CAM_CPAS, "client=[%d][%s][%d] is in start state",
  2053. client_indx, cpas_client->data.identifier,
  2054. cpas_client->data.cell_index);
  2055. rc = -EPERM;
  2056. goto error;
  2057. }
  2058. CAM_DBG(CAM_CPAS,
  2059. "AHB :client=[%d][%s][%d] type[%d], level[%d], applied[%d]",
  2060. client_indx, cpas_client->data.identifier,
  2061. cpas_client->data.cell_index,
  2062. ahb_vote->type, ahb_vote->vote.level, cpas_client->ahb_level);
  2063. rc = cam_cpas_util_apply_client_ahb_vote(cpas_hw, cpas_client,
  2064. ahb_vote, &applied_level);
  2065. if (rc)
  2066. goto error;
  2067. cam_cpas_dump_axi_vote_info(cpas_client, "CPAS Start Vote",
  2068. &axi_vote);
  2069. /*
  2070. * If client has indicated start bw to be applied on all paths
  2071. * of client, apply that otherwise apply whatever the client supplies
  2072. * for specific paths
  2073. */
  2074. if (axi_vote.axi_path[0].path_data_type ==
  2075. CAM_CPAS_API_PATH_DATA_STD_START) {
  2076. rc = cam_cpas_util_create_vote_all_paths(cpas_client,
  2077. &axi_vote);
  2078. } else {
  2079. rc = cam_cpas_util_translate_client_paths(&axi_vote);
  2080. }
  2081. if (rc) {
  2082. CAM_ERR(CAM_CPAS, "Unable to create or translate paths rc: %d",
  2083. rc);
  2084. goto remove_ahb_vote;
  2085. }
  2086. cam_cpas_dump_axi_vote_info(cpas_client, "CPAS Start Translated Vote", &axi_vote);
  2087. if (cpas_core->streamon_clients == 0) {
  2088. if (cpas_core->force_hlos_drv) {
  2089. soc_private->enable_cam_ddr_drv = false;
  2090. soc_private->enable_cam_clk_drv = false;
  2091. }
  2092. if (cpas_core->force_cesta_sw_client)
  2093. soc_private->enable_cam_clk_drv = false;
  2094. if (debug_drv)
  2095. CAM_INFO(CAM_CPAS, "DRV enable[DDR CLK]:[%s %s]",
  2096. CAM_BOOL_TO_YESNO(soc_private->enable_cam_ddr_drv),
  2097. CAM_BOOL_TO_YESNO(soc_private->enable_cam_clk_drv));
  2098. rc = cam_cpas_util_apply_default_axi_vote(cpas_hw, true);
  2099. if (rc)
  2100. goto remove_ahb_vote;
  2101. atomic_set(&cpas_core->soc_access_count, 1);
  2102. count = cam_soc_util_regulators_enabled(&cpas_hw->soc_info);
  2103. if (count > 0)
  2104. CAM_DBG(CAM_CPAS, "Regulators already enabled %d", count);
  2105. rc = cam_cpas_soc_enable_resources(&cpas_hw->soc_info,
  2106. applied_level);
  2107. if (rc) {
  2108. atomic_set(&cpas_core->soc_access_count, 0);
  2109. CAM_ERR(CAM_CPAS, "enable_resorce failed, rc=%d", rc);
  2110. goto remove_ahb_vote;
  2111. }
  2112. if (cpas_core->internal_ops.qchannel_handshake) {
  2113. rc = cpas_core->internal_ops.qchannel_handshake(cpas_hw, true, false);
  2114. if (rc) {
  2115. CAM_WARN(CAM_CPAS, "failed in qchannel_handshake rc=%d", rc);
  2116. /* Do not return error, passthrough */
  2117. rc = cpas_core->internal_ops.qchannel_handshake(cpas_hw,
  2118. true, true);
  2119. if (rc) {
  2120. CAM_ERR(CAM_CPAS,
  2121. "failed in qchannel_handshake, hw blocks may not work rc=%d",
  2122. rc);
  2123. /* Do not return error, passthrough */
  2124. }
  2125. }
  2126. }
  2127. if (cpas_core->internal_ops.power_on) {
  2128. rc = cpas_core->internal_ops.power_on(cpas_hw);
  2129. if (rc) {
  2130. atomic_set(&cpas_core->soc_access_count, 0);
  2131. cam_cpas_soc_disable_resources(
  2132. &cpas_hw->soc_info, true, true);
  2133. CAM_ERR(CAM_CPAS,
  2134. "failed in power_on settings rc=%d",
  2135. rc);
  2136. goto remove_ahb_vote;
  2137. }
  2138. }
  2139. CAM_DBG(CAM_CPAS, "soc_access_count=%d\n",
  2140. atomic_read(&cpas_core->soc_access_count));
  2141. if (soc_private->enable_smart_qos)
  2142. cam_cpas_reset_niu_priorities(cpas_hw);
  2143. cam_smmu_reset_cb_page_fault_cnt();
  2144. cpas_hw->hw_state = CAM_HW_STATE_POWER_UP;
  2145. }
  2146. /*
  2147. * Need to apply axi vote after we enable clocks, since we need certain clocks enabled for
  2148. * drv channel switch
  2149. */
  2150. rc = cam_cpas_util_apply_client_axi_vote(cpas_hw, cpas_client, &axi_vote,
  2151. CAM_CPAS_APPLY_TYPE_START);
  2152. if (rc)
  2153. goto remove_ahb_vote;
  2154. cpas_client->started = true;
  2155. cpas_core->streamon_clients++;
  2156. if (debug_drv && (cpas_core->streamon_clients == 1)) {
  2157. cam_cpas_log_vote(cpas_hw, false);
  2158. cam_cpas_dump_full_tree_state(cpas_hw, "StartFirstClient");
  2159. }
  2160. CAM_DBG(CAM_CPAS, "client=[%d][%s][%d] streamon_clients=%d",
  2161. client_indx, cpas_client->data.identifier,
  2162. cpas_client->data.cell_index, cpas_core->streamon_clients);
  2163. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2164. mutex_unlock(&cpas_hw->hw_mutex);
  2165. return rc;
  2166. remove_ahb_vote:
  2167. remove_ahb.type = CAM_VOTE_ABSOLUTE;
  2168. remove_ahb.vote.level = CAM_SUSPEND_VOTE;
  2169. err_val = cam_cpas_util_apply_client_ahb_vote(cpas_hw, cpas_client,
  2170. &remove_ahb, NULL);
  2171. if (err_val)
  2172. CAM_ERR(CAM_CPAS, "Removing AHB vote failed, rc=%d", err_val);
  2173. error:
  2174. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2175. mutex_unlock(&cpas_hw->hw_mutex);
  2176. return rc;
  2177. }
  2178. static int _check_soc_access_count(struct cam_cpas *cpas_core)
  2179. {
  2180. return (atomic_read(&cpas_core->soc_access_count) > 0) ? 0 : 1;
  2181. }
  2182. static int cam_cpas_util_validate_stop_bw(struct cam_cpas_private_soc *soc_private,
  2183. struct cam_cpas *cpas_core)
  2184. {
  2185. int i;
  2186. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  2187. if (soc_private->enable_cam_ddr_drv &&
  2188. (cpas_core->axi_port[i].bus_client.common_data.is_drv_port)) {
  2189. if ((cpas_core->axi_port[i].applied_bw.drv_vote.high.ab) ||
  2190. (cpas_core->axi_port[i].applied_bw.drv_vote.high.ib) ||
  2191. (cpas_core->axi_port[i].applied_bw.drv_vote.low.ab) ||
  2192. (cpas_core->axi_port[i].applied_bw.drv_vote.low.ib)) {
  2193. CAM_ERR(CAM_CPAS,
  2194. "port:%s Non zero DRV applied BW high[%llu %llu] low[%llu %llu]",
  2195. cpas_core->axi_port[i].axi_port_name,
  2196. cpas_core->axi_port[i].applied_bw.drv_vote.high.ab,
  2197. cpas_core->axi_port[i].applied_bw.drv_vote.high.ib,
  2198. cpas_core->axi_port[i].applied_bw.drv_vote.low.ab,
  2199. cpas_core->axi_port[i].applied_bw.drv_vote.low.ib);
  2200. return -EINVAL;
  2201. }
  2202. } else {
  2203. if (cpas_core->axi_port[i].bus_client.common_data.is_drv_port)
  2204. continue;
  2205. if ((cpas_core->axi_port[i].applied_bw.hlos_vote.ab) ||
  2206. (cpas_core->axi_port[i].applied_bw.hlos_vote.ib)) {
  2207. CAM_ERR(CAM_CPAS,
  2208. "port:%s Non zero HLOS applied BW [%llu %llu]",
  2209. cpas_core->axi_port[i].axi_port_name,
  2210. cpas_core->axi_port[i].applied_bw.hlos_vote.ab,
  2211. cpas_core->axi_port[i].applied_bw.hlos_vote.ib);
  2212. return -EINVAL;
  2213. }
  2214. }
  2215. }
  2216. return 0;
  2217. }
  2218. static int cam_cpas_hw_stop(void *hw_priv, void *stop_args,
  2219. uint32_t arg_size)
  2220. {
  2221. struct cam_hw_info *cpas_hw;
  2222. struct cam_cpas *cpas_core;
  2223. uint32_t client_indx;
  2224. struct cam_cpas_hw_cmd_stop *cmd_hw_stop;
  2225. struct cam_cpas_client *cpas_client;
  2226. struct cam_ahb_vote ahb_vote;
  2227. struct cam_axi_vote axi_vote = {0};
  2228. struct cam_cpas_private_soc *soc_private = NULL;
  2229. int rc = 0, count;
  2230. long result;
  2231. int retry_camnoc_idle = 0;
  2232. if (!hw_priv || !stop_args) {
  2233. CAM_ERR(CAM_CPAS, "Invalid arguments %pK %pK",
  2234. hw_priv, stop_args);
  2235. return -EINVAL;
  2236. }
  2237. if (sizeof(struct cam_cpas_hw_cmd_stop) != arg_size) {
  2238. CAM_ERR(CAM_CPAS, "HW_CAPS size mismatch %zd %d",
  2239. sizeof(struct cam_cpas_hw_cmd_stop), arg_size);
  2240. return -EINVAL;
  2241. }
  2242. cpas_hw = (struct cam_hw_info *)hw_priv;
  2243. cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2244. soc_private = (struct cam_cpas_private_soc *)
  2245. cpas_hw->soc_info.soc_private;
  2246. cmd_hw_stop = (struct cam_cpas_hw_cmd_stop *)stop_args;
  2247. client_indx = CAM_CPAS_GET_CLIENT_IDX(cmd_hw_stop->client_handle);
  2248. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  2249. return -EINVAL;
  2250. mutex_lock(&cpas_hw->hw_mutex);
  2251. mutex_lock(&cpas_core->client_mutex[client_indx]);
  2252. cpas_client = cpas_core->cpas_client[client_indx];
  2253. CAM_DBG(CAM_CPAS, "Client=[%d][%s][%d] streamon_clients=%d",
  2254. client_indx, cpas_client->data.identifier,
  2255. cpas_client->data.cell_index, cpas_core->streamon_clients);
  2256. if (!CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  2257. CAM_ERR(CAM_CPAS, "Client=[%d][%s][%d] is not started",
  2258. client_indx, cpas_client->data.identifier,
  2259. cpas_client->data.cell_index);
  2260. rc = -EPERM;
  2261. goto done;
  2262. }
  2263. rc = cam_cpas_util_create_vote_all_paths(cpas_client, &axi_vote);
  2264. if (rc) {
  2265. CAM_ERR(CAM_CPAS, "Unable to create per path votes rc: %d", rc);
  2266. goto done;
  2267. }
  2268. cam_cpas_dump_axi_vote_info(cpas_client, "CPAS Stop Vote", &axi_vote);
  2269. rc = cam_cpas_util_apply_client_axi_vote(cpas_hw, cpas_client, &axi_vote,
  2270. CAM_CPAS_APPLY_TYPE_STOP);
  2271. if (rc)
  2272. goto done;
  2273. cpas_client->started = false;
  2274. if (debug_drv && (cpas_core->streamon_clients == 1)) {
  2275. cam_cpas_log_vote(cpas_hw, false);
  2276. cam_cpas_dump_full_tree_state(cpas_hw, "StopLastClient");
  2277. }
  2278. cpas_core->streamon_clients--;
  2279. if (cpas_core->streamon_clients == 0) {
  2280. if (cpas_core->internal_ops.power_off) {
  2281. rc = cpas_core->internal_ops.power_off(cpas_hw);
  2282. if (rc) {
  2283. CAM_ERR(CAM_CPAS,
  2284. "failed in power_off settings rc=%d",
  2285. rc);
  2286. /* Do not return error, passthrough */
  2287. }
  2288. }
  2289. if (cpas_core->internal_ops.qchannel_handshake) {
  2290. rc = cpas_core->internal_ops.qchannel_handshake(cpas_hw, false, false);
  2291. if (rc) {
  2292. CAM_ERR(CAM_CPAS, "failed in qchannel_handshake rc=%d", rc);
  2293. retry_camnoc_idle = 1;
  2294. /* Do not return error, passthrough */
  2295. }
  2296. }
  2297. rc = cam_cpas_soc_disable_irq(&cpas_hw->soc_info);
  2298. if (rc) {
  2299. CAM_ERR(CAM_CPAS, "disable_irq failed, rc=%d", rc);
  2300. goto done;
  2301. }
  2302. /* Wait for any IRQs still being handled */
  2303. atomic_dec(&cpas_core->soc_access_count);
  2304. result = wait_event_timeout(cpas_core->soc_access_count_wq,
  2305. _check_soc_access_count(cpas_core), HZ);
  2306. if (result == 0) {
  2307. CAM_ERR(CAM_CPAS, "Wait failed: soc_access_count=%d",
  2308. atomic_read(&cpas_core->soc_access_count));
  2309. }
  2310. /* try again incase camnoc is still not idle */
  2311. if (cpas_core->internal_ops.qchannel_handshake &&
  2312. retry_camnoc_idle) {
  2313. rc = cpas_core->internal_ops.qchannel_handshake(cpas_hw, false, false);
  2314. if (rc) {
  2315. CAM_ERR(CAM_CPAS, "failed in qchannel_handshake rc=%d", rc);
  2316. /* Do not return error, passthrough */
  2317. }
  2318. }
  2319. rc = cam_cpas_soc_disable_resources(&cpas_hw->soc_info,
  2320. true, false);
  2321. if (rc) {
  2322. CAM_ERR(CAM_CPAS, "disable_resorce failed, rc=%d", rc);
  2323. goto done;
  2324. }
  2325. CAM_DBG(CAM_CPAS, "Disabled all the resources: soc_access_count=%d",
  2326. atomic_read(&cpas_core->soc_access_count));
  2327. count = cam_soc_util_regulators_enabled(&cpas_hw->soc_info);
  2328. if (count > 0)
  2329. CAM_WARN(CAM_CPAS,
  2330. "Client=[%d][%s][%d] qchannel shut down while top gdsc is still on %d",
  2331. client_indx, cpas_client->data.identifier,
  2332. cpas_client->data.cell_index, count);
  2333. rc = cam_cpas_util_apply_default_axi_vote(cpas_hw, false);
  2334. if (rc)
  2335. CAM_ERR(CAM_CPAS, "Failed in power off default vote rc: %d", rc);
  2336. rc = cam_cpas_util_validate_stop_bw(soc_private, cpas_core);
  2337. if (rc)
  2338. CAM_ERR(CAM_CPAS, "Invalid applied bw at stop rc: %d", rc);
  2339. cpas_hw->hw_state = CAM_HW_STATE_POWER_DOWN;
  2340. }
  2341. ahb_vote.type = CAM_VOTE_ABSOLUTE;
  2342. ahb_vote.vote.level = CAM_SUSPEND_VOTE;
  2343. rc = cam_cpas_util_apply_client_ahb_vote(cpas_hw, cpas_client,
  2344. &ahb_vote, NULL);
  2345. if (rc)
  2346. goto done;
  2347. done:
  2348. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2349. mutex_unlock(&cpas_hw->hw_mutex);
  2350. return rc;
  2351. }
  2352. static int cam_cpas_hw_init(void *hw_priv, void *init_hw_args,
  2353. uint32_t arg_size)
  2354. {
  2355. struct cam_hw_info *cpas_hw;
  2356. struct cam_cpas *cpas_core;
  2357. int rc = 0;
  2358. if (!hw_priv || !init_hw_args) {
  2359. CAM_ERR(CAM_CPAS, "Invalid arguments %pK %pK",
  2360. hw_priv, init_hw_args);
  2361. return -EINVAL;
  2362. }
  2363. if (sizeof(struct cam_cpas_hw_caps) != arg_size) {
  2364. CAM_ERR(CAM_CPAS, "INIT HW size mismatch %zd %d",
  2365. sizeof(struct cam_cpas_hw_caps), arg_size);
  2366. return -EINVAL;
  2367. }
  2368. cpas_hw = (struct cam_hw_info *)hw_priv;
  2369. cpas_core = (struct cam_cpas *)cpas_hw->core_info;
  2370. if (cpas_core->internal_ops.init_hw_version) {
  2371. rc = cpas_core->internal_ops.init_hw_version(cpas_hw,
  2372. (struct cam_cpas_hw_caps *)init_hw_args);
  2373. }
  2374. return rc;
  2375. }
  2376. static int cam_cpas_hw_register_client(struct cam_hw_info *cpas_hw,
  2377. struct cam_cpas_register_params *register_params)
  2378. {
  2379. int rc;
  2380. char client_name[CAM_HW_IDENTIFIER_LENGTH + 3];
  2381. int32_t client_indx = -1;
  2382. struct cam_cpas *cpas_core = (struct cam_cpas *)cpas_hw->core_info;
  2383. struct cam_cpas_private_soc *soc_private =
  2384. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  2385. if ((!register_params) ||
  2386. (strlen(register_params->identifier) < 1)) {
  2387. CAM_ERR(CAM_CPAS, "Invalid cpas client identifier");
  2388. return -EINVAL;
  2389. }
  2390. CAM_DBG(CAM_CPAS, "Register params : identifier=%s, cell_index=%d",
  2391. register_params->identifier, register_params->cell_index);
  2392. if (soc_private->client_id_based)
  2393. snprintf(client_name, sizeof(client_name), "%s%d",
  2394. register_params->identifier,
  2395. register_params->cell_index);
  2396. else
  2397. snprintf(client_name, sizeof(client_name), "%s",
  2398. register_params->identifier);
  2399. mutex_lock(&cpas_hw->hw_mutex);
  2400. rc = cam_common_util_get_string_index(soc_private->client_name,
  2401. soc_private->num_clients, client_name, &client_indx);
  2402. if (rc) {
  2403. CAM_ERR(CAM_CPAS, "Client %s is not found in CPAS client list rc=%d",
  2404. client_name, rc);
  2405. mutex_unlock(&cpas_hw->hw_mutex);
  2406. return -ENODEV;
  2407. }
  2408. mutex_lock(&cpas_core->client_mutex[client_indx]);
  2409. if (rc || !CAM_CPAS_CLIENT_VALID(client_indx) ||
  2410. CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx)) {
  2411. CAM_ERR(CAM_CPAS,
  2412. "Inval client %s %d : %d %d %pK %d",
  2413. register_params->identifier,
  2414. register_params->cell_index,
  2415. CAM_CPAS_CLIENT_VALID(client_indx),
  2416. CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx),
  2417. cpas_core->cpas_client[client_indx], rc);
  2418. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2419. mutex_unlock(&cpas_hw->hw_mutex);
  2420. return -EPERM;
  2421. }
  2422. register_params->client_handle =
  2423. CAM_CPAS_GET_CLIENT_HANDLE(client_indx);
  2424. memcpy(&cpas_core->cpas_client[client_indx]->data, register_params,
  2425. sizeof(struct cam_cpas_register_params));
  2426. cpas_core->registered_clients++;
  2427. cpas_core->cpas_client[client_indx]->registered = true;
  2428. CAM_DBG(CAM_CPAS, "client=[%d][%s][%d], registered_clients=%d",
  2429. client_indx,
  2430. cpas_core->cpas_client[client_indx]->data.identifier,
  2431. cpas_core->cpas_client[client_indx]->data.cell_index,
  2432. cpas_core->registered_clients);
  2433. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2434. mutex_unlock(&cpas_hw->hw_mutex);
  2435. return 0;
  2436. }
  2437. static int cam_cpas_hw_unregister_client(struct cam_hw_info *cpas_hw,
  2438. uint32_t client_handle)
  2439. {
  2440. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2441. uint32_t client_indx = CAM_CPAS_GET_CLIENT_IDX(client_handle);
  2442. int rc = 0;
  2443. if (!CAM_CPAS_CLIENT_VALID(client_indx))
  2444. return -EINVAL;
  2445. mutex_lock(&cpas_hw->hw_mutex);
  2446. mutex_lock(&cpas_core->client_mutex[client_indx]);
  2447. if (!CAM_CPAS_CLIENT_REGISTERED(cpas_core, client_indx)) {
  2448. CAM_ERR(CAM_CPAS, "Client=[%d][%s][%d] not registered",
  2449. client_indx,
  2450. cpas_core->cpas_client[client_indx]->data.identifier,
  2451. cpas_core->cpas_client[client_indx]->data.cell_index);
  2452. rc = -EPERM;
  2453. goto done;
  2454. }
  2455. if (CAM_CPAS_CLIENT_STARTED(cpas_core, client_indx)) {
  2456. CAM_ERR(CAM_CPAS, "Client=[%d][%s][%d] is not stopped",
  2457. client_indx,
  2458. cpas_core->cpas_client[client_indx]->data.identifier,
  2459. cpas_core->cpas_client[client_indx]->data.cell_index);
  2460. rc = -EPERM;
  2461. goto done;
  2462. }
  2463. CAM_DBG(CAM_CPAS, "client=[%d][%s][%d], registered_clients=%d",
  2464. client_indx,
  2465. cpas_core->cpas_client[client_indx]->data.identifier,
  2466. cpas_core->cpas_client[client_indx]->data.cell_index,
  2467. cpas_core->registered_clients);
  2468. cpas_core->cpas_client[client_indx]->registered = false;
  2469. cpas_core->registered_clients--;
  2470. done:
  2471. mutex_unlock(&cpas_core->client_mutex[client_indx]);
  2472. mutex_unlock(&cpas_hw->hw_mutex);
  2473. return rc;
  2474. }
  2475. static int cam_cpas_hw_get_hw_info(void *hw_priv,
  2476. void *get_hw_cap_args, uint32_t arg_size)
  2477. {
  2478. struct cam_hw_info *cpas_hw;
  2479. struct cam_cpas *cpas_core;
  2480. struct cam_cpas_hw_caps *hw_caps;
  2481. struct cam_cpas_private_soc *soc_private;
  2482. if (!hw_priv || !get_hw_cap_args) {
  2483. CAM_ERR(CAM_CPAS, "Invalid arguments %pK %pK",
  2484. hw_priv, get_hw_cap_args);
  2485. return -EINVAL;
  2486. }
  2487. if (sizeof(struct cam_cpas_hw_caps) != arg_size) {
  2488. CAM_ERR(CAM_CPAS, "HW_CAPS size mismatch %zd %d",
  2489. sizeof(struct cam_cpas_hw_caps), arg_size);
  2490. return -EINVAL;
  2491. }
  2492. cpas_hw = (struct cam_hw_info *)hw_priv;
  2493. cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2494. hw_caps = (struct cam_cpas_hw_caps *)get_hw_cap_args;
  2495. *hw_caps = cpas_core->hw_caps;
  2496. /*Extract Fuse Info*/
  2497. soc_private = (struct cam_cpas_private_soc *)
  2498. cpas_hw->soc_info.soc_private;
  2499. hw_caps->fuse_info = soc_private->fuse_info;
  2500. CAM_DBG(CAM_CPAS, "fuse info->num_fuses %d", hw_caps->fuse_info.num_fuses);
  2501. return 0;
  2502. }
  2503. static int cam_cpas_log_vote(struct cam_hw_info *cpas_hw, bool ddr_only)
  2504. {
  2505. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2506. struct cam_cpas_private_soc *soc_private =
  2507. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  2508. uint32_t i, vcd_idx;
  2509. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  2510. struct cam_cpas_cesta_info *cesta_info =
  2511. (struct cam_cpas_cesta_info *)cpas_core->cesta_info;
  2512. if ((cpas_core->streamon_clients > 0) && soc_private->enable_smart_qos && !ddr_only)
  2513. cam_cpas_print_smart_qos_priority(cpas_hw);
  2514. /*
  2515. * First print rpmh registers as early as possible to catch nearest
  2516. * state of rpmh after an issue (overflow) occurs.
  2517. */
  2518. if ((cpas_core->streamon_clients > 0) &&
  2519. (cpas_core->regbase_index[CAM_CPAS_REG_RPMH] != -1)) {
  2520. int reg_base_index =
  2521. cpas_core->regbase_index[CAM_CPAS_REG_RPMH];
  2522. void __iomem *rpmh_base =
  2523. soc_info->reg_map[reg_base_index].mem_base;
  2524. uint32_t offset_fe, offset_be;
  2525. uint32_t fe_val, be_val;
  2526. uint32_t *rpmh_info = &soc_private->rpmh_info[0];
  2527. uint32_t ddr_bcm_index =
  2528. soc_private->rpmh_info[CAM_RPMH_BCM_DDR_INDEX];
  2529. uint32_t mnoc_bcm_index =
  2530. soc_private->rpmh_info[CAM_RPMH_BCM_MNOC_INDEX];
  2531. /*
  2532. * print 12 registers from 0x4, 0x800 offsets -
  2533. * this will give ddr, mmnoc and other BCM info.
  2534. * i=0 for DDR, i=4 for mnoc, but double check for each chipset.
  2535. */
  2536. for (i = 0; i < rpmh_info[CAM_RPMH_NUMBER_OF_BCMS]; i++) {
  2537. if ((!cpas_core->full_state_dump) &&
  2538. (i != ddr_bcm_index) &&
  2539. (i != mnoc_bcm_index))
  2540. continue;
  2541. offset_fe = rpmh_info[CAM_RPMH_BCM_FE_OFFSET] +
  2542. (i * 0x4);
  2543. offset_be = rpmh_info[CAM_RPMH_BCM_BE_OFFSET] +
  2544. (i * 0x4);
  2545. fe_val = cam_io_r_mb(rpmh_base + offset_fe);
  2546. be_val = cam_io_r_mb(rpmh_base + offset_be);
  2547. CAM_INFO(CAM_CPAS,
  2548. "i=%d, FE[offset=0x%x, value=0x%x] BE[offset=0x%x, value=0x%x]",
  2549. i, offset_fe, fe_val, offset_be, be_val);
  2550. }
  2551. }
  2552. if ((cpas_core->streamon_clients > 0) &&
  2553. cpas_core->regbase_index[CAM_CPAS_REG_CESTA] != -1) {
  2554. int reg_base_index =
  2555. cpas_core->regbase_index[CAM_CPAS_REG_CESTA];
  2556. void __iomem *cesta_base =
  2557. soc_info->reg_map[reg_base_index].mem_base;
  2558. uint32_t vcd_base_inc =
  2559. cesta_info->cesta_reg_info->vcd_currol.vcd_base_inc;
  2560. uint32_t num_vcds = cesta_info->num_vcds;
  2561. uint32_t vcd_curr_lvl_base =
  2562. cesta_info->cesta_reg_info->vcd_currol.reg_offset;
  2563. uint32_t cesta_vcd_curr_perfol_offset, cesta_vcd_curr_perfol_val;
  2564. if (!atomic_inc_not_zero(&cpas_core->soc_access_count))
  2565. goto skip_vcd_dump;
  2566. for (i = 0; i < num_vcds; i++) {
  2567. vcd_idx = cesta_info->vcd_info[i].index;
  2568. cesta_vcd_curr_perfol_offset = vcd_curr_lvl_base +
  2569. (vcd_base_inc * vcd_idx);
  2570. cesta_vcd_curr_perfol_val =
  2571. cam_io_r_mb(cesta_base + cesta_vcd_curr_perfol_offset);
  2572. CAM_INFO(CAM_CPAS,
  2573. "i=%d, VCD[index=%d, type=%d, name=%s] [offset=0x%x, value=0x%x]",
  2574. i, cesta_info->vcd_info[i].index,
  2575. cesta_info->vcd_info[i].type,
  2576. cesta_info->vcd_info[i].clk,
  2577. cesta_vcd_curr_perfol_offset,
  2578. cesta_vcd_curr_perfol_val);
  2579. }
  2580. atomic_dec(&cpas_core->soc_access_count);
  2581. wake_up(&cpas_core->soc_access_count_wq);
  2582. }
  2583. skip_vcd_dump:
  2584. if (ddr_only)
  2585. return 0;
  2586. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  2587. if (cpas_core->axi_port[i].bus_client.common_data.is_drv_port) {
  2588. CAM_INFO(CAM_PERF,
  2589. "[%s] DRV applied: high [%llu %llu] low[%llu %llu] new: high [%llu %llu] low [%llu %llu]",
  2590. cpas_core->axi_port[i].axi_port_name,
  2591. cpas_core->axi_port[i].applied_bw.drv_vote.high.ab,
  2592. cpas_core->axi_port[i].applied_bw.drv_vote.high.ib,
  2593. cpas_core->axi_port[i].applied_bw.drv_vote.low.ab,
  2594. cpas_core->axi_port[i].applied_bw.drv_vote.low.ib,
  2595. cpas_core->axi_port[i].curr_bw.drv_vote.high.ab,
  2596. cpas_core->axi_port[i].curr_bw.drv_vote.high.ib,
  2597. cpas_core->axi_port[i].curr_bw.drv_vote.low.ab,
  2598. cpas_core->axi_port[i].curr_bw.drv_vote.low.ib);
  2599. } else {
  2600. CAM_INFO(CAM_PERF, "Port %s HLOS applied [%llu %llu] new [%llu %llu]",
  2601. cpas_core->axi_port[i].axi_port_name,
  2602. cpas_core->axi_port[i].applied_bw.hlos_vote.ab,
  2603. cpas_core->axi_port[i].applied_bw.hlos_vote.ib,
  2604. cpas_core->axi_port[i].curr_bw.hlos_vote.ab,
  2605. cpas_core->axi_port[i].curr_bw.hlos_vote.ib);
  2606. }
  2607. }
  2608. if (soc_private->control_camnoc_axi_clk) {
  2609. CAM_INFO(CAM_CPAS, "applied camnoc axi clk sw_client[%lld]",
  2610. cpas_core->applied_camnoc_axi_rate.sw_client);
  2611. if (soc_private->enable_cam_clk_drv)
  2612. CAM_INFO(CAM_CPAS,
  2613. "applied camnoc axi clk hw_client[high low] cesta_idx0:[%lld %lld] cesta_idx1:[%lld %lld] cesta_idx2:[%lld %lld]",
  2614. cpas_core->applied_camnoc_axi_rate.hw_client[0].high,
  2615. cpas_core->applied_camnoc_axi_rate.hw_client[0].low,
  2616. cpas_core->applied_camnoc_axi_rate.hw_client[1].high,
  2617. cpas_core->applied_camnoc_axi_rate.hw_client[1].low,
  2618. cpas_core->applied_camnoc_axi_rate.hw_client[2].high,
  2619. cpas_core->applied_camnoc_axi_rate.hw_client[2].low);
  2620. } else {
  2621. for (i = 0; i < cpas_core->num_camnoc_axi_ports; i++) {
  2622. CAM_INFO(CAM_CPAS,
  2623. "[%s] ab_bw[%lld] ib_bw[%lld] additional_bw[%lld] applied_ab[%lld] applied_ib[%lld]",
  2624. cpas_core->camnoc_axi_port[i].axi_port_name,
  2625. cpas_core->camnoc_axi_port[i].curr_bw.hlos_vote.ab,
  2626. cpas_core->camnoc_axi_port[i].curr_bw.hlos_vote.ib,
  2627. cpas_core->camnoc_axi_port[i].additional_bw,
  2628. cpas_core->camnoc_axi_port[i].applied_bw.hlos_vote.ab,
  2629. cpas_core->camnoc_axi_port[i].applied_bw.hlos_vote.ib);
  2630. }
  2631. }
  2632. CAM_INFO(CAM_CPAS, "ahb client curr vote level[%d]",
  2633. cpas_core->ahb_bus_client.curr_vote_level);
  2634. if (!cpas_core->full_state_dump) {
  2635. CAM_DBG(CAM_CPAS, "CPAS full state dump not enabled");
  2636. return 0;
  2637. }
  2638. /* This will traverse through all nodes in the tree and print stats */
  2639. cam_cpas_dump_full_tree_state(cpas_hw, "state_dump_on_error");
  2640. cam_cpas_dump_monitor_array(cpas_hw);
  2641. if (cpas_core->internal_ops.print_poweron_settings)
  2642. cpas_core->internal_ops.print_poweron_settings(cpas_hw);
  2643. else
  2644. CAM_DBG(CAM_CPAS, "No ops for print_poweron_settings");
  2645. return 0;
  2646. }
  2647. static void cam_cpas_update_monitor_array(struct cam_hw_info *cpas_hw,
  2648. const char *identifier_string, int32_t identifier_value)
  2649. {
  2650. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2651. struct cam_camnoc_info *camnoc_info = NULL;
  2652. struct cam_cpas_cesta_info *cesta_info = cpas_core->cesta_info;
  2653. struct cam_hw_soc_info *soc_info = &cpas_hw->soc_info;
  2654. struct cam_cpas_private_soc *soc_private =
  2655. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  2656. struct cam_cpas_monitor *entry;
  2657. int iterator, i, j = 0, vcd_idx, camnoc_reg_idx;
  2658. uint32_t val = 0, camnoc_idx;
  2659. CAM_CPAS_INC_MONITOR_HEAD(&cpas_core->monitor_head, &iterator);
  2660. entry = &cpas_core->monitor_entries[iterator];
  2661. entry->cpas_hw = cpas_hw;
  2662. CAM_GET_TIMESTAMP(entry->timestamp);
  2663. strlcpy(entry->identifier_string, identifier_string,
  2664. sizeof(entry->identifier_string));
  2665. entry->identifier_value = identifier_value;
  2666. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  2667. entry->axi_info[i].axi_port_name = cpas_core->axi_port[i].axi_port_name;
  2668. memcpy(&entry->axi_info[i].curr_bw, &cpas_core->axi_port[i].curr_bw,
  2669. sizeof(struct cam_cpas_axi_bw_info));
  2670. /* camnoc bw value not applicable for mnoc ports */
  2671. entry->axi_info[i].camnoc_bw = 0;
  2672. memcpy(&entry->axi_info[i].applied_bw, &cpas_core->axi_port[i].applied_bw,
  2673. sizeof(struct cam_cpas_axi_bw_info));
  2674. entry->axi_info[i].is_drv_started = cpas_core->axi_port[i].is_drv_started;
  2675. }
  2676. memcpy(&entry->applied_camnoc_clk, &cpas_core->applied_camnoc_axi_rate,
  2677. sizeof(struct cam_soc_util_clk_rates));
  2678. entry->applied_ahb_level = cpas_core->ahb_bus_client.curr_vote_level;
  2679. if ((cpas_core->streamon_clients > 0) &&
  2680. (cpas_core->regbase_index[CAM_CPAS_REG_RPMH] != -1) &&
  2681. soc_private->rpmh_info[CAM_RPMH_NUMBER_OF_BCMS]) {
  2682. int reg_base_index =
  2683. cpas_core->regbase_index[CAM_CPAS_REG_RPMH];
  2684. void __iomem *rpmh_base =
  2685. soc_info->reg_map[reg_base_index].mem_base;
  2686. uint32_t fe_ddr_offset =
  2687. soc_private->rpmh_info[CAM_RPMH_BCM_FE_OFFSET] +
  2688. (0x4 * soc_private->rpmh_info[CAM_RPMH_BCM_DDR_INDEX]);
  2689. uint32_t fe_mnoc_offset =
  2690. soc_private->rpmh_info[CAM_RPMH_BCM_FE_OFFSET] +
  2691. (0x4 * soc_private->rpmh_info[CAM_RPMH_BCM_MNOC_INDEX]);
  2692. uint32_t be_ddr_offset =
  2693. soc_private->rpmh_info[CAM_RPMH_BCM_BE_OFFSET] +
  2694. (0x4 * soc_private->rpmh_info[CAM_RPMH_BCM_DDR_INDEX]);
  2695. uint32_t be_mnoc_offset =
  2696. soc_private->rpmh_info[CAM_RPMH_BCM_BE_OFFSET] +
  2697. (0x4 * soc_private->rpmh_info[CAM_RPMH_BCM_MNOC_INDEX]);
  2698. uint32_t be_shub_offset =
  2699. soc_private->rpmh_info[CAM_RPMH_BCM_BE_OFFSET] +
  2700. (0x4 * 1); /* i=1 for SHUB, hardcode for now */
  2701. /*
  2702. * 0x4, 0x800 - DDR
  2703. * 0x800, 0x810 - mmnoc
  2704. */
  2705. entry->fe_ddr = cam_io_r_mb(rpmh_base + fe_ddr_offset);
  2706. entry->fe_mnoc = cam_io_r_mb(rpmh_base + fe_mnoc_offset);
  2707. entry->be_ddr = cam_io_r_mb(rpmh_base + be_ddr_offset);
  2708. entry->be_mnoc = cam_io_r_mb(rpmh_base + be_mnoc_offset);
  2709. entry->be_shub = cam_io_r_mb(rpmh_base + be_shub_offset);
  2710. CAM_DBG(CAM_CPAS,
  2711. "fe_ddr=0x%x, fe_mnoc=0x%x, be_ddr=0x%x, be_mnoc=0x%x",
  2712. entry->fe_ddr, entry->fe_mnoc, entry->be_ddr,
  2713. entry->be_mnoc);
  2714. }
  2715. if ((cpas_core->streamon_clients > 0) &&
  2716. cpas_core->regbase_index[CAM_CPAS_REG_CESTA] != -1) {
  2717. int reg_base_index =
  2718. cpas_core->regbase_index[CAM_CPAS_REG_CESTA];
  2719. void __iomem *cesta_base =
  2720. soc_info->reg_map[reg_base_index].mem_base;
  2721. uint32_t vcd_base_inc = cesta_info->cesta_reg_info->vcd_currol.vcd_base_inc;
  2722. uint32_t num_vcds = cesta_info->num_vcds;
  2723. uint32_t vcd_curr_lvl_base = cesta_info->cesta_reg_info->vcd_currol.reg_offset;
  2724. uint32_t cesta_vcd_curr_perfol_offset, cesta_vcd_curr_perfol_val;
  2725. if (atomic_inc_not_zero(&cpas_core->soc_access_count)) {
  2726. for (i = 0; i < num_vcds; i++) {
  2727. vcd_idx = cesta_info->vcd_info[i].index;
  2728. cesta_vcd_curr_perfol_offset = vcd_curr_lvl_base +
  2729. (vcd_base_inc * vcd_idx);
  2730. cesta_vcd_curr_perfol_val =
  2731. cam_io_r_mb(cesta_base +
  2732. cesta_vcd_curr_perfol_offset);
  2733. entry->vcd_reg_debug_info.vcd_curr_lvl_debug_info[i].index =
  2734. cesta_info->vcd_info[i].index;
  2735. entry->vcd_reg_debug_info.vcd_curr_lvl_debug_info[i]
  2736. .reg_value = cesta_vcd_curr_perfol_val;
  2737. }
  2738. atomic_dec(&cpas_core->soc_access_count);
  2739. wake_up(&cpas_core->soc_access_count_wq);
  2740. }
  2741. }
  2742. for (camnoc_idx = 0; camnoc_idx < cpas_core->num_valid_camnoc; camnoc_idx++) {
  2743. camnoc_info = cpas_core->camnoc_info[camnoc_idx];
  2744. camnoc_reg_idx = cpas_core->regbase_index[camnoc_info->reg_base];
  2745. for (i = 0, j = 0; i < camnoc_info->specific_size; i++) {
  2746. if ((!camnoc_info->specific[i].enable) ||
  2747. (!camnoc_info->specific[i].maxwr_low.enable))
  2748. continue;
  2749. if (j >= CAM_CAMNOC_FILL_LVL_REG_INFO_MAX) {
  2750. CAM_WARN(CAM_CPAS,
  2751. "CPAS monitor reg info buffer full, max : %d",
  2752. j);
  2753. break;
  2754. }
  2755. entry->camnoc_port_name[camnoc_idx][j] =
  2756. camnoc_info->specific[i].port_name;
  2757. val = cam_io_r_mb(soc_info->reg_map[camnoc_reg_idx].mem_base +
  2758. camnoc_info->specific[i].maxwr_low.offset);
  2759. entry->camnoc_fill_level[camnoc_idx][j] = val;
  2760. j++;
  2761. }
  2762. entry->num_camnoc_lvl_regs[camnoc_idx] = j;
  2763. }
  2764. if (soc_private->enable_smart_qos) {
  2765. camnoc_info = cpas_core->camnoc_info[cpas_core->camnoc_rt_idx];
  2766. camnoc_reg_idx = cpas_core->regbase_index[camnoc_info->reg_base];
  2767. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  2768. struct cam_cpas_tree_node *niu_node =
  2769. soc_private->smart_qos_info->rt_wr_niu_node[i];
  2770. entry->rt_wr_niu_pri_lut_high[i] =
  2771. cam_io_r_mb(soc_info->reg_map[camnoc_reg_idx].mem_base +
  2772. niu_node->pri_lut_high_offset);
  2773. entry->rt_wr_niu_pri_lut_low[i] =
  2774. cam_io_r_mb(soc_info->reg_map[camnoc_reg_idx].mem_base +
  2775. niu_node->pri_lut_low_offset);
  2776. }
  2777. }
  2778. }
  2779. static void cam_cpas_dump_monitor_array(
  2780. struct cam_hw_info *cpas_hw)
  2781. {
  2782. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2783. struct cam_cpas_private_soc *soc_private =
  2784. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  2785. int i = 0, k = 0;
  2786. int64_t state_head = 0;
  2787. uint32_t index, num_entries, oldest_entry, camnoc_idx, j;
  2788. uint64_t ms, hrs, min, sec;
  2789. struct cam_cpas_monitor *entry;
  2790. struct timespec64 curr_timestamp;
  2791. char log_buf[CAM_CPAS_LOG_BUF_LEN];
  2792. size_t len;
  2793. uint8_t vcd_index;
  2794. struct cam_cpas_cesta_info *cesta_info = cpas_core->cesta_info;
  2795. struct cam_camnoc_info *camnoc_info;
  2796. if (!cpas_core->full_state_dump)
  2797. return;
  2798. state_head = atomic64_read(&cpas_core->monitor_head);
  2799. if (state_head == -1) {
  2800. CAM_WARN(CAM_CPAS, "No valid entries in cpas monitor array");
  2801. return;
  2802. } else if (state_head < CAM_CPAS_MONITOR_MAX_ENTRIES) {
  2803. num_entries = state_head;
  2804. oldest_entry = 0;
  2805. } else {
  2806. num_entries = CAM_CPAS_MONITOR_MAX_ENTRIES;
  2807. div_u64_rem(state_head + 1,
  2808. CAM_CPAS_MONITOR_MAX_ENTRIES, &oldest_entry);
  2809. }
  2810. CAM_GET_TIMESTAMP(curr_timestamp);
  2811. CAM_CONVERT_TIMESTAMP_FORMAT(curr_timestamp, hrs, min, sec, ms);
  2812. CAM_INFO(CAM_CPAS,
  2813. "**** %llu:%llu:%llu.%llu : ======== Dumping monitor information ===========",
  2814. hrs, min, sec, ms);
  2815. index = oldest_entry;
  2816. for (i = 0; i < num_entries; i++) {
  2817. entry = &cpas_core->monitor_entries[index];
  2818. CAM_CONVERT_TIMESTAMP_FORMAT(entry->timestamp, hrs, min, sec, ms);
  2819. log_buf[0] = '\0';
  2820. CAM_INFO(CAM_CPAS,
  2821. "**** %llu:%llu:%llu.%llu : Index[%d] Identifier[%s][%d] camnoc=sw : %ld, hw clients [%ld %ld][%ld %ld][%ld %ld], ahb=%d",
  2822. hrs, min, sec, ms,
  2823. index,
  2824. entry->identifier_string, entry->identifier_value,
  2825. entry->applied_camnoc_clk.sw_client,
  2826. entry->applied_camnoc_clk.hw_client[0].high,
  2827. entry->applied_camnoc_clk.hw_client[0].low,
  2828. entry->applied_camnoc_clk.hw_client[1].high,
  2829. entry->applied_camnoc_clk.hw_client[1].low,
  2830. entry->applied_camnoc_clk.hw_client[2].high,
  2831. entry->applied_camnoc_clk.hw_client[2].low,
  2832. entry->applied_ahb_level);
  2833. for (j = 0; j < cpas_core->num_axi_ports; j++) {
  2834. if ((entry->axi_info[j].applied_bw.vote_type == CAM_CPAS_VOTE_TYPE_DRV) &&
  2835. !cpas_core->force_hlos_drv)
  2836. CAM_INFO(CAM_CPAS,
  2837. "BW [%s] : DRV started:%s high=[%lld %lld], low=[%lld %lld]",
  2838. entry->axi_info[j].axi_port_name,
  2839. CAM_BOOL_TO_YESNO(entry->axi_info[j].is_drv_started),
  2840. entry->axi_info[j].applied_bw.drv_vote.high.ab,
  2841. entry->axi_info[j].applied_bw.drv_vote.high.ib,
  2842. entry->axi_info[j].applied_bw.drv_vote.low.ab,
  2843. entry->axi_info[j].applied_bw.drv_vote.low.ib);
  2844. else
  2845. CAM_INFO(CAM_CPAS,
  2846. "BW [%s] : HLOS ab=%lld, ib=%lld, DRV high_ab=%lld, high_ib=%lld, low_ab=%lld, low_ib=%lld",
  2847. entry->axi_info[j].axi_port_name,
  2848. entry->axi_info[j].applied_bw.hlos_vote.ab,
  2849. entry->axi_info[j].applied_bw.hlos_vote.ib);
  2850. }
  2851. if (cpas_core->regbase_index[CAM_CPAS_REG_RPMH] != -1) {
  2852. CAM_INFO(CAM_CPAS,
  2853. "fe_ddr=0x%x, fe_mnoc=0x%x, be_ddr=0x%x, be_mnoc=0x%x, be_shub=0x%x",
  2854. entry->fe_ddr, entry->fe_mnoc,
  2855. entry->be_ddr, entry->be_mnoc, entry->be_shub);
  2856. }
  2857. if (cpas_core->regbase_index[CAM_CPAS_REG_CESTA] != -1) {
  2858. uint32_t vcd_base_inc =
  2859. cesta_info->cesta_reg_info->vcd_currol.vcd_base_inc;
  2860. uint32_t vcd_curr_lvl_base =
  2861. cesta_info->cesta_reg_info->vcd_currol.reg_offset;
  2862. uint32_t reg_offset;
  2863. uint32_t num_vcds = cesta_info->num_vcds;
  2864. for (k = 0; k < num_vcds; k++) {
  2865. vcd_index =
  2866. entry->vcd_reg_debug_info.vcd_curr_lvl_debug_info[k].index;
  2867. reg_offset = vcd_curr_lvl_base + (vcd_base_inc * vcd_index);
  2868. CAM_INFO(CAM_CPAS,
  2869. "VCD[index=%d, type=%d, name=%s] [offset=0x%x, value=0x%x]",
  2870. vcd_index,
  2871. cesta_info->vcd_info[k].type,
  2872. cesta_info->vcd_info[k].clk,
  2873. reg_offset,
  2874. entry->vcd_reg_debug_info.vcd_curr_lvl_debug_info[k]
  2875. .reg_value);
  2876. }
  2877. }
  2878. for (camnoc_idx = 0; camnoc_idx < cpas_core->num_valid_camnoc; camnoc_idx++) {
  2879. camnoc_info = cpas_core->camnoc_info[camnoc_idx];
  2880. log_buf[0] = '\0';
  2881. len = 0;
  2882. for (j = 0; j < entry->num_camnoc_lvl_regs[camnoc_idx]; j++) {
  2883. len += scnprintf((log_buf + len),
  2884. (CAM_CPAS_LOG_BUF_LEN - len), " %s:[%d %d]",
  2885. entry->camnoc_port_name[camnoc_idx][j],
  2886. (entry->camnoc_fill_level[camnoc_idx][j] & 0x7FF),
  2887. (entry->camnoc_fill_level[camnoc_idx][j] & 0x7F0000)
  2888. >> 16);
  2889. }
  2890. CAM_INFO(CAM_CPAS, "%s REG[Queued Pending] %s",
  2891. camnoc_info->camnoc_name, log_buf);
  2892. }
  2893. if (soc_private->enable_smart_qos) {
  2894. len = 0;
  2895. for (j = 0; j < soc_private->smart_qos_info->num_rt_wr_nius; j++) {
  2896. struct cam_cpas_tree_node *niu_node =
  2897. soc_private->smart_qos_info->rt_wr_niu_node[j];
  2898. len += scnprintf((log_buf + len),
  2899. (CAM_CPAS_LOG_BUF_LEN - len), " [%s: high 0x%x low 0x%x]",
  2900. niu_node->node_name,
  2901. entry->rt_wr_niu_pri_lut_high[j],
  2902. entry->rt_wr_niu_pri_lut_low[j]);
  2903. }
  2904. CAM_INFO(CAM_CPAS, "SmartQoS [Node: Pri_lut] %s", log_buf);
  2905. }
  2906. index = (index + 1) % CAM_CPAS_MONITOR_MAX_ENTRIES;
  2907. }
  2908. }
  2909. static void *cam_cpas_user_dump_state_monitor_array_info(
  2910. void *dump_struct, uint8_t *addr_ptr)
  2911. {
  2912. uint64_t *addr;
  2913. struct cam_common_hw_dump_header *hdr;
  2914. struct cam_cpas_monitor *monitor = (struct cam_cpas_monitor *)dump_struct;
  2915. struct cam_cpas_axi_port_debug_info *axi_info = NULL;
  2916. struct cam_cpas_cesta_vcd_reg_debug_info *vcd_reg_debug_info = NULL;
  2917. struct cam_hw_info *cpas_hw = (struct cam_hw_info *) monitor->cpas_hw;
  2918. struct cam_cpas_private_soc *soc_private =
  2919. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  2920. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  2921. struct cam_cpas_tree_node *niu_node;
  2922. uint8_t *dst;
  2923. uint32_t num_vcds = CAM_CPAS_MAX_CESTA_VCD_NUM, camnoc_idx, i;
  2924. addr = (uint64_t *)addr_ptr;
  2925. *addr++ = monitor->timestamp.tv_sec;
  2926. *addr++ = monitor->timestamp.tv_nsec / NSEC_PER_USEC;
  2927. *addr++ = monitor->identifier_value;
  2928. *addr++ = monitor->applied_camnoc_clk.sw_client,
  2929. *addr++ = monitor->applied_camnoc_clk.hw_client[0].high,
  2930. *addr++ = monitor->applied_camnoc_clk.hw_client[0].low,
  2931. *addr++ = monitor->applied_camnoc_clk.hw_client[1].high,
  2932. *addr++ = monitor->applied_camnoc_clk.hw_client[1].low,
  2933. *addr++ = monitor->applied_camnoc_clk.hw_client[2].high,
  2934. *addr++ = monitor->applied_camnoc_clk.hw_client[2].low,
  2935. *addr++ = monitor->applied_ahb_level;
  2936. *addr++ = cpas_core->num_valid_camnoc;
  2937. if (soc_private->enable_smart_qos)
  2938. *addr++ = soc_private->smart_qos_info->num_rt_wr_nius;
  2939. *addr++ = num_vcds;
  2940. *addr++ = cpas_core->num_axi_ports;
  2941. *addr++ = monitor->fe_ddr;
  2942. *addr++ = monitor->be_ddr;
  2943. *addr++ = monitor->fe_mnoc;
  2944. *addr++ = monitor->be_mnoc;
  2945. *addr++ = monitor->be_shub;
  2946. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  2947. axi_info = &monitor->axi_info[i];
  2948. dst = (uint8_t *)addr;
  2949. hdr = (struct cam_common_hw_dump_header *)dst;
  2950. if (axi_info->applied_bw.vote_type == CAM_CPAS_VOTE_TYPE_DRV) {
  2951. scnprintf(hdr->tag, CAM_COMMON_HW_DUMP_TAG_MAX_LEN, "%s.%s.%s:",
  2952. axi_info->axi_port_name, "DRV",
  2953. CAM_BOOL_TO_YESNO(axi_info->is_drv_started));
  2954. addr = (uint64_t *)(dst + sizeof(struct cam_common_hw_dump_header));
  2955. *addr++ = axi_info->applied_bw.drv_vote.high.ab;
  2956. *addr++ = axi_info->applied_bw.drv_vote.high.ib;
  2957. *addr++ = axi_info->applied_bw.drv_vote.low.ab;
  2958. *addr++ = axi_info->applied_bw.drv_vote.low.ib;
  2959. } else {
  2960. scnprintf(hdr->tag, CAM_COMMON_HW_DUMP_TAG_MAX_LEN, "%s.%s.%s:",
  2961. axi_info->axi_port_name, "HLOS",
  2962. CAM_BOOL_TO_YESNO(axi_info->is_drv_started));
  2963. addr = (uint64_t *)(dst + sizeof(struct cam_common_hw_dump_header));
  2964. *addr++ = axi_info->applied_bw.hlos_vote.ab;
  2965. *addr++ = axi_info->applied_bw.hlos_vote.ib;
  2966. }
  2967. }
  2968. for (camnoc_idx = 0; camnoc_idx < cpas_core->num_valid_camnoc; camnoc_idx++) {
  2969. *addr++ = monitor->num_camnoc_lvl_regs[camnoc_idx];
  2970. for (i = 0; i < monitor->num_camnoc_lvl_regs[camnoc_idx]; i++) {
  2971. dst = (uint8_t *)addr;
  2972. hdr = (struct cam_common_hw_dump_header *)dst;
  2973. scnprintf(hdr->tag, CAM_COMMON_HW_DUMP_TAG_MAX_LEN, "%s:[%d %d].",
  2974. monitor->camnoc_port_name[camnoc_idx][i],
  2975. monitor->camnoc_fill_level[camnoc_idx][i] & 0x7FF,
  2976. (monitor->camnoc_fill_level[camnoc_idx][i] & 0x7F0000) >> 16);
  2977. addr = (uint64_t *)(dst + sizeof(struct cam_common_hw_dump_header));
  2978. }
  2979. }
  2980. if (soc_private->enable_smart_qos) {
  2981. for (i = 0; i < soc_private->smart_qos_info->num_rt_wr_nius; i++) {
  2982. niu_node = soc_private->smart_qos_info->rt_wr_niu_node[i];
  2983. dst = (uint8_t *)addr;
  2984. hdr = (struct cam_common_hw_dump_header *)dst;
  2985. scnprintf(hdr->tag, CAM_COMMON_HW_DUMP_TAG_MAX_LEN, "%s:", niu_node->node_name);
  2986. addr = (uint64_t *)(dst + sizeof(struct cam_common_hw_dump_header));
  2987. *addr++ = monitor->rt_wr_niu_pri_lut_high[i];
  2988. *addr++ = monitor->rt_wr_niu_pri_lut_low[i];
  2989. }
  2990. }
  2991. vcd_reg_debug_info = &monitor->vcd_reg_debug_info;
  2992. for (i = 0; i < num_vcds; i++) {
  2993. *addr++ = vcd_reg_debug_info->vcd_curr_lvl_debug_info[i].index;
  2994. *addr++ = vcd_reg_debug_info->vcd_curr_lvl_debug_info[i].reg_value;
  2995. }
  2996. return addr;
  2997. }
  2998. /**
  2999. * cam_cpas_dump_state_monitor_array_info()
  3000. *
  3001. * @brief : dump the state monitor array info, dump from monitor_head
  3002. * to save state information in time order.
  3003. * @cpas_hw : hardware information
  3004. * @dump_info : dump payload
  3005. */
  3006. static int cam_cpas_dump_state_monitor_array_info(
  3007. struct cam_hw_info *cpas_hw,
  3008. struct cam_req_mgr_dump_info *dump_info)
  3009. {
  3010. int rc = 0;
  3011. int i, j;
  3012. struct cam_common_hw_dump_args dump_args;
  3013. size_t buf_len;
  3014. size_t remain_len;
  3015. uint32_t min_len = 0, camnoc_idx;
  3016. uintptr_t cpu_addr;
  3017. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3018. int64_t state_head = 0;
  3019. uint32_t index, num_entries, oldest_entry;
  3020. struct cam_cpas_private_soc *soc_private =
  3021. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3022. struct cam_cpas_monitor *entry;
  3023. uint32_t monitor_idx;
  3024. state_head = atomic64_read(&cpas_core->monitor_head);
  3025. if (state_head == -1) {
  3026. CAM_WARN(CAM_CPAS, "No valid entries in cpas monitor array");
  3027. return 0;
  3028. } else if (state_head < CAM_CPAS_MONITOR_MAX_ENTRIES) {
  3029. num_entries = state_head;
  3030. oldest_entry = 0;
  3031. } else {
  3032. num_entries = CAM_CPAS_MONITOR_MAX_ENTRIES;
  3033. div_u64_rem(state_head + 1,
  3034. CAM_CPAS_MONITOR_MAX_ENTRIES, &oldest_entry);
  3035. }
  3036. monitor_idx = index = oldest_entry;
  3037. rc = cam_mem_get_cpu_buf(dump_info->buf_handle, &cpu_addr, &buf_len);
  3038. if (rc) {
  3039. CAM_ERR(CAM_CPAS, "Invalid handle %u rc %d",
  3040. dump_info->buf_handle, rc);
  3041. return rc;
  3042. }
  3043. if (buf_len <= dump_info->offset) {
  3044. CAM_WARN(CAM_CPAS, "Dump buffer overshoot len %zu offset %zu",
  3045. buf_len, dump_info->offset);
  3046. cam_mem_put_cpu_buf(dump_info->buf_handle);
  3047. return -ENOSPC;
  3048. }
  3049. remain_len = buf_len - dump_info->offset;
  3050. for (i = 0; i < num_entries; i++) {
  3051. min_len += sizeof(struct cam_common_hw_dump_header) +
  3052. CAM_CPAS_DUMP_NUM_WORDS_COMM * sizeof(uint64_t);
  3053. entry = &cpas_core->monitor_entries[monitor_idx];
  3054. for (j = 0; j < cpas_core->num_axi_ports; j++) {
  3055. if (entry->axi_info[j].applied_bw.vote_type ==
  3056. CAM_CPAS_VOTE_TYPE_DRV) {
  3057. min_len += sizeof(struct cam_common_hw_dump_header) +
  3058. CAM_CPAS_DUMP_NUM_WORDS_VOTE_TYEP_DRV * sizeof(uint64_t);
  3059. } else {
  3060. min_len += sizeof(struct cam_common_hw_dump_header) +
  3061. CAM_CPAS_DUMP_NUM_WORDS_VOTE_TYEP_HLOS * sizeof(uint64_t);
  3062. }
  3063. }
  3064. for (camnoc_idx = 0; camnoc_idx < cpas_core->num_valid_camnoc; camnoc_idx++) {
  3065. min_len += sizeof(uint64_t);
  3066. for (j = 0; j < entry->num_camnoc_lvl_regs[camnoc_idx]; j++)
  3067. min_len += sizeof(struct cam_common_hw_dump_header);
  3068. }
  3069. if (soc_private->enable_smart_qos) {
  3070. for (j = 0; j < soc_private->smart_qos_info->num_rt_wr_nius; j++)
  3071. min_len += sizeof(struct cam_common_hw_dump_header) +
  3072. CAM_CPAS_DUMP_NUM_WORDS_RT_WR_NIUS * sizeof(uint64_t);
  3073. }
  3074. for (j = 0; j < CAM_CPAS_MAX_CESTA_VCD_NUM; j++)
  3075. min_len += CAM_CPAS_DUMP_NUM_WORDS_VCD_CURR_LVL * sizeof(uint64_t);
  3076. monitor_idx = (monitor_idx + 1) % CAM_CPAS_MONITOR_MAX_ENTRIES;
  3077. }
  3078. if (remain_len < min_len) {
  3079. CAM_WARN(CAM_CPAS, "Dump buffer exhaust remain %zu min %u",
  3080. remain_len, min_len);
  3081. cam_mem_put_cpu_buf(dump_info->buf_handle);
  3082. return -ENOSPC;
  3083. }
  3084. dump_args.req_id = dump_info->req_id;
  3085. dump_args.cpu_addr = cpu_addr;
  3086. dump_args.buf_len = buf_len;
  3087. dump_args.offset = dump_info->offset;
  3088. dump_args.ctxt_to_hw_map = NULL;
  3089. for (i = 0; i < num_entries; i++) {
  3090. rc = cam_common_user_dump_helper(&dump_args,
  3091. cam_cpas_user_dump_state_monitor_array_info,
  3092. &cpas_core->monitor_entries[index],
  3093. sizeof(uint64_t), "CPAS_MONITOR.%d.%s:", index,
  3094. &cpas_core->monitor_entries[index].identifier_string);
  3095. if (rc) {
  3096. CAM_ERR(CAM_CPAS, "Dump state info failed, rc: %d", rc);
  3097. cam_mem_put_cpu_buf(dump_info->buf_handle);
  3098. return rc;
  3099. }
  3100. index = (index + 1) % CAM_CPAS_MONITOR_MAX_ENTRIES;
  3101. }
  3102. dump_info->offset = dump_args.offset;
  3103. cam_mem_put_cpu_buf(dump_info->buf_handle);
  3104. return rc;
  3105. }
  3106. static int cam_cpas_log_event(struct cam_hw_info *cpas_hw,
  3107. const char *identifier_string, int32_t identifier_value)
  3108. {
  3109. cam_cpas_update_monitor_array(cpas_hw, identifier_string,
  3110. identifier_value);
  3111. return 0;
  3112. }
  3113. static int cam_cpas_select_qos(struct cam_hw_info *cpas_hw,
  3114. uint32_t selection_mask)
  3115. {
  3116. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3117. int rc = 0;
  3118. mutex_lock(&cpas_hw->hw_mutex);
  3119. if (cpas_hw->hw_state == CAM_HW_STATE_POWER_UP) {
  3120. CAM_ERR(CAM_CPAS,
  3121. "Hw already in power up state, can't change QoS settings");
  3122. rc = -EINVAL;
  3123. goto done;
  3124. }
  3125. if (cpas_core->internal_ops.setup_qos_settings) {
  3126. rc = cpas_core->internal_ops.setup_qos_settings(cpas_hw,
  3127. selection_mask);
  3128. if (rc)
  3129. CAM_ERR(CAM_CPAS, "Failed in changing QoS %d", rc);
  3130. } else {
  3131. CAM_WARN(CAM_CPAS, "No ops for qos_settings");
  3132. }
  3133. done:
  3134. mutex_unlock(&cpas_hw->hw_mutex);
  3135. return rc;
  3136. }
  3137. static int cam_cpas_hw_enable_tpg_mux_sel(struct cam_hw_info *cpas_hw,
  3138. uint32_t tpg_mux)
  3139. {
  3140. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3141. int rc = 0;
  3142. mutex_lock(&cpas_hw->hw_mutex);
  3143. if (cpas_core->internal_ops.set_tpg_mux_sel) {
  3144. rc = cpas_core->internal_ops.set_tpg_mux_sel(
  3145. cpas_hw, tpg_mux);
  3146. if (rc) {
  3147. CAM_ERR(CAM_CPAS,
  3148. "failed in tpg mux selection rc=%d",
  3149. rc);
  3150. }
  3151. } else {
  3152. CAM_ERR(CAM_CPAS,
  3153. "CPAS tpg mux sel not enabled");
  3154. rc = -EINVAL;
  3155. }
  3156. mutex_unlock(&cpas_hw->hw_mutex);
  3157. return rc;
  3158. }
  3159. static int cam_cpas_activate_cache(
  3160. struct cam_hw_info *cpas_hw,
  3161. struct cam_sys_cache_info *cache_info)
  3162. {
  3163. int rc = 0;
  3164. mutex_lock(&cpas_hw->hw_mutex);
  3165. cache_info->ref_cnt++;
  3166. if (cache_info->ref_cnt > 1) {
  3167. mutex_unlock(&cpas_hw->hw_mutex);
  3168. CAM_DBG(CAM_CPAS, "Cache: %s has already been activated cnt: %d",
  3169. cache_info->name, cache_info->ref_cnt);
  3170. return rc;
  3171. }
  3172. rc = llcc_slice_activate(cache_info->slic_desc);
  3173. if (rc) {
  3174. CAM_ERR(CAM_CPAS, "Failed to activate cache:%s",
  3175. cache_info->name);
  3176. goto end;
  3177. }
  3178. mutex_unlock(&cpas_hw->hw_mutex);
  3179. CAM_DBG(CAM_CPAS, "Activated cache:%s", cache_info->name);
  3180. return rc;
  3181. end:
  3182. cache_info->ref_cnt--;
  3183. mutex_unlock(&cpas_hw->hw_mutex);
  3184. return rc;
  3185. }
  3186. static int cam_cpas_deactivate_cache(
  3187. struct cam_hw_info *cpas_hw,
  3188. struct cam_sys_cache_info *cache_info)
  3189. {
  3190. int rc = 0;
  3191. mutex_lock(&cpas_hw->hw_mutex);
  3192. if (!cache_info->ref_cnt) {
  3193. mutex_unlock(&cpas_hw->hw_mutex);
  3194. CAM_ERR(CAM_CPAS, "Unbalanced deactivate");
  3195. return -EFAULT;
  3196. }
  3197. cache_info->ref_cnt--;
  3198. if (cache_info->ref_cnt) {
  3199. mutex_unlock(&cpas_hw->hw_mutex);
  3200. CAM_DBG(CAM_CPAS, "activate cnt for: %s non-zero: %d",
  3201. cache_info->name, cache_info->ref_cnt);
  3202. return rc;
  3203. }
  3204. rc = llcc_slice_deactivate(cache_info->slic_desc);
  3205. if (rc)
  3206. CAM_ERR(CAM_CPAS, "Failed to deactivate cache:%s",
  3207. cache_info->name);
  3208. mutex_unlock(&cpas_hw->hw_mutex);
  3209. CAM_DBG(CAM_CPAS, "De-activated cache:%s", cache_info->name);
  3210. return rc;
  3211. }
  3212. #if IS_ENABLED(CONFIG_SPECTRA_LLCC_STALING)
  3213. static int cam_cpas_configure_staling_cache(
  3214. struct cam_hw_info *cpas_hw,
  3215. struct cam_sys_cache_info *cache_info,
  3216. struct cam_sys_cache_local_info *sys_cache_info)
  3217. {
  3218. int rc = 0;
  3219. struct llcc_staling_mode_params staling_params;
  3220. mutex_lock(&cpas_hw->hw_mutex);
  3221. switch (sys_cache_info->mode) {
  3222. case CAM_LLCC_STALING_MODE_CAPACITY: {
  3223. staling_params.staling_mode = LLCC_STALING_MODE_CAPACITY;
  3224. break;
  3225. }
  3226. case CAM_LLCC_STALING_MODE_NOTIFY: {
  3227. staling_params.staling_mode = LLCC_STALING_MODE_NOTIFY;
  3228. break;
  3229. }
  3230. default:
  3231. CAM_ERR(CAM_CPAS, "CPAS LLCC sys cache mode is not valid =%d"
  3232. , sys_cache_info->mode);
  3233. break;
  3234. }
  3235. switch (sys_cache_info->op_type) {
  3236. case CAM_LLCC_NOTIFY_STALING_EVICT: {
  3237. staling_params.notify_params.op = LLCC_NOTIFY_STALING_WRITEBACK;
  3238. break;
  3239. }
  3240. default:
  3241. CAM_ERR(CAM_CPAS, "CPAS LLCC sys cache op_type is not valid =%d"
  3242. , sys_cache_info->op_type);
  3243. break;
  3244. }
  3245. staling_params.notify_params.staling_distance
  3246. = cache_info->staling_distance;
  3247. rc = llcc_configure_staling_mode(cache_info->slic_desc,
  3248. &staling_params);
  3249. if (!rc) {
  3250. cache_info->staling_distance = sys_cache_info->staling_distance;
  3251. cache_info->mode = sys_cache_info->mode;
  3252. cache_info->op_type = sys_cache_info->op_type;
  3253. } else if (rc == -EOPNOTSUPP) {
  3254. CAM_ERR(CAM_CPAS, "llcc staling feature is not supported cache:%s",
  3255. cache_info->name);
  3256. } else if (rc) {
  3257. CAM_ERR(CAM_CPAS, "Failed to enable llcc notif cache:%s",
  3258. cache_info->name);
  3259. }
  3260. mutex_unlock(&cpas_hw->hw_mutex);
  3261. CAM_DBG(CAM_CPAS,
  3262. "llcc notif cache name:%s staling_distance %d cache mode :%d cache op_type :%s",
  3263. cache_info->name, cache_info->staling_distance,
  3264. cache_info->mode, cache_info->op_type);
  3265. return rc;
  3266. }
  3267. static int cam_cpas_notif_stalling_inc_cache(
  3268. struct cam_hw_info *cpas_hw,
  3269. struct cam_sys_cache_info *cache_info)
  3270. {
  3271. int rc = 0;
  3272. mutex_lock(&cpas_hw->hw_mutex);
  3273. rc = llcc_notif_staling_inc_counter(cache_info->slic_desc);
  3274. if (rc == -EOPNOTSUPP)
  3275. CAM_ERR(CAM_CPAS, "llcc notif stalling inc not supported: %s",
  3276. cache_info->name);
  3277. else if (rc)
  3278. CAM_ERR(CAM_CPAS, "Failed to llcc staling frame trigger:%s",
  3279. cache_info->name);
  3280. mutex_unlock(&cpas_hw->hw_mutex);
  3281. CAM_DBG(CAM_CPAS, "llcc staling frame triggered cache:%s",
  3282. cache_info->name);
  3283. return rc;
  3284. }
  3285. #endif
  3286. static inline int cam_cpas_validate_cache_type(
  3287. uint32_t num_caches, enum cam_sys_cache_config_types type)
  3288. {
  3289. if ((!num_caches) || (type < 0) || (type >= CAM_LLCC_MAX))
  3290. return -EINVAL;
  3291. else
  3292. return 0;
  3293. }
  3294. static int cam_cpas_get_slice_id(
  3295. struct cam_hw_info *cpas_hw,
  3296. enum cam_sys_cache_config_types type)
  3297. {
  3298. struct cam_cpas_private_soc *soc_private =
  3299. (struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
  3300. uint32_t num_caches = soc_private->num_caches;
  3301. int scid = -1, i;
  3302. if (cam_cpas_validate_cache_type(num_caches, type))
  3303. goto end;
  3304. for (i = 0; i < num_caches; i++) {
  3305. if (type == soc_private->llcc_info[i].type) {
  3306. scid = soc_private->llcc_info[i].scid;
  3307. CAM_DBG(CAM_CPAS, "Cache:%s type:%d scid:%d",
  3308. soc_private->llcc_info[i].name, type, scid);
  3309. break;
  3310. }
  3311. }
  3312. end:
  3313. return scid;
  3314. }
  3315. static int cam_cpas_activate_cache_slice(
  3316. struct cam_hw_info *cpas_hw,
  3317. enum cam_sys_cache_config_types type)
  3318. {
  3319. struct cam_cpas_private_soc *soc_private =
  3320. (struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
  3321. uint32_t num_caches = soc_private->num_caches;
  3322. int rc = 0, i;
  3323. CAM_DBG(CAM_CPAS, "Activate type: %d", type);
  3324. if (cam_cpas_validate_cache_type(num_caches, type))
  3325. goto end;
  3326. for (i = 0; i < num_caches; i++) {
  3327. if (type == soc_private->llcc_info[i].type)
  3328. rc = cam_cpas_activate_cache(cpas_hw,
  3329. &soc_private->llcc_info[i]);
  3330. }
  3331. end:
  3332. return rc;
  3333. }
  3334. static int cam_cpas_deactivate_cache_slice(
  3335. struct cam_hw_info *cpas_hw,
  3336. enum cam_sys_cache_config_types type)
  3337. {
  3338. struct cam_cpas_private_soc *soc_private =
  3339. (struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
  3340. uint32_t num_caches = soc_private->num_caches;
  3341. int rc = 0, i;
  3342. CAM_DBG(CAM_CPAS, "De-activate type: %d", type);
  3343. if (cam_cpas_validate_cache_type(num_caches, type))
  3344. goto end;
  3345. for (i = 0; i < num_caches; i++) {
  3346. if (type == soc_private->llcc_info[i].type)
  3347. rc = cam_cpas_deactivate_cache(cpas_hw,
  3348. &soc_private->llcc_info[i]);
  3349. }
  3350. end:
  3351. return rc;
  3352. }
  3353. #if IS_ENABLED(CONFIG_SPECTRA_LLCC_STALING)
  3354. static int cam_cpas_configure_staling_cache_slice(
  3355. struct cam_hw_info *cpas_hw,
  3356. struct cam_sys_cache_local_info sys_cache_info)
  3357. {
  3358. struct cam_cpas_private_soc *soc_private =
  3359. (struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
  3360. uint32_t num_caches = soc_private->num_caches;
  3361. int rc = 0, i;
  3362. CAM_DBG(CAM_CPAS, "De-activate type: %d", sys_cache_info.type);
  3363. if (cam_cpas_validate_cache_type(num_caches, sys_cache_info.type))
  3364. goto end;
  3365. for (i = 0; i < num_caches; i++) {
  3366. if (sys_cache_info.type == soc_private->llcc_info[i].type) {
  3367. rc = cam_cpas_configure_staling_cache(cpas_hw,
  3368. &soc_private->llcc_info[i], &sys_cache_info);
  3369. if (rc) {
  3370. CAM_ERR(CAM_CPAS, "llc sys cache type %d config failed, rc: %d",
  3371. soc_private->llcc_info[i].type, rc);
  3372. }
  3373. break;
  3374. }
  3375. }
  3376. end:
  3377. return rc;
  3378. }
  3379. static int cam_cpas_notif_stalling_inc_cache_slice(
  3380. struct cam_hw_info *cpas_hw,
  3381. enum cam_sys_cache_config_types type)
  3382. {
  3383. struct cam_cpas_private_soc *soc_private =
  3384. (struct cam_cpas_private_soc *)cpas_hw->soc_info.soc_private;
  3385. uint32_t num_caches = soc_private->num_caches;
  3386. int rc = 0, i;
  3387. CAM_DBG(CAM_CPAS, "De-activate type: %d", type);
  3388. if (cam_cpas_validate_cache_type(num_caches, type))
  3389. goto end;
  3390. for (i = 0; i < num_caches; i++) {
  3391. if (type == soc_private->llcc_info[i].type)
  3392. rc = cam_cpas_notif_stalling_inc_cache(cpas_hw,
  3393. &soc_private->llcc_info[i]);
  3394. }
  3395. end:
  3396. return rc;
  3397. }
  3398. #else
  3399. static int cam_cpas_configure_staling_cache_slice(
  3400. struct cam_hw_info *cpas_hw,
  3401. struct cam_sys_cache_local_info sys_cache_info)
  3402. {
  3403. return -EOPNOTSUPP;
  3404. }
  3405. static int cam_cpas_notif_stalling_inc_cache_slice(
  3406. struct cam_hw_info *cpas_hw,
  3407. enum cam_sys_cache_config_types type)
  3408. {
  3409. return -EOPNOTSUPP;
  3410. }
  3411. #endif
  3412. static int cam_cpas_hw_csid_input_core_info_update(struct cam_hw_info *cpas_hw,
  3413. int csid_idx, int sfe_idx, bool set_port)
  3414. {
  3415. int i, j, rc = 0;
  3416. char client_name[CAM_HW_IDENTIFIER_LENGTH + 3];
  3417. int32_t client_indx = -1;
  3418. struct cam_cpas_private_soc *soc_private =
  3419. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3420. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3421. struct cam_cpas_tree_node *tree_node = NULL;
  3422. if (!soc_private->enable_cam_ddr_drv || cpas_core->force_hlos_drv)
  3423. return 0;
  3424. if ((csid_idx < 0) || (sfe_idx < 0)) {
  3425. CAM_ERR(CAM_CPAS, "Invalid core info csid:%d sfe:%d", csid_idx, sfe_idx);
  3426. return -EINVAL;
  3427. }
  3428. snprintf(client_name, sizeof(client_name), "%s%d", "sfe", sfe_idx);
  3429. rc = cam_common_util_get_string_index(soc_private->client_name,
  3430. soc_private->num_clients, client_name, &client_indx);
  3431. if (!cpas_core->cpas_client[client_indx]->is_drv_dyn)
  3432. return 0;
  3433. for (i = 0; i < CAM_CPAS_PATH_DATA_MAX; i++) {
  3434. for (j = 0; j < CAM_CPAS_TRANSACTION_MAX; j++) {
  3435. tree_node = cpas_core->cpas_client[client_indx]->tree_node[i][j];
  3436. if (!tree_node)
  3437. continue;
  3438. if (set_port)
  3439. tree_node->drv_voting_idx = CAM_CPAS_PORT_DRV_0 + csid_idx;
  3440. else
  3441. tree_node->drv_voting_idx = CAM_CPAS_PORT_DRV_DYN;
  3442. }
  3443. }
  3444. return rc;
  3445. }
  3446. static int cam_cpas_hw_enable_domain_id_clks(struct cam_hw_info *cpas_hw,
  3447. bool enable)
  3448. {
  3449. int rc = 0, i;
  3450. struct cam_cpas_private_soc *soc_private =
  3451. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3452. struct cam_cpas_domain_id_support_clks *domain_id_clks =
  3453. soc_private->domain_id_clks;
  3454. if (!soc_private->domain_id_info.domain_id_supported) {
  3455. CAM_DBG(CAM_CPAS, "Domain-id not supported on target");
  3456. return -EINVAL;
  3457. }
  3458. if (enable) {
  3459. for (i = 0; i < domain_id_clks->number_clks; i++) {
  3460. rc = cam_soc_util_clk_enable(&cpas_hw->soc_info, CAM_CLK_SW_CLIENT_IDX,
  3461. true, domain_id_clks->clk_idx[i], 0);
  3462. if (rc) {
  3463. CAM_ERR(CAM_CPAS, "Domain-id clk %s enable failed, rc: %d",
  3464. domain_id_clks->clk_names[i], i);
  3465. goto clean_up;
  3466. }
  3467. }
  3468. CAM_DBG(CAM_CPAS, "Domain-id clks enable success");
  3469. } else {
  3470. for (i = 0; i < domain_id_clks->number_clks; i++) {
  3471. rc = cam_soc_util_clk_disable(&cpas_hw->soc_info, CAM_CLK_SW_CLIENT_IDX,
  3472. true, domain_id_clks->clk_idx[i]);
  3473. if (rc)
  3474. CAM_WARN(CAM_CPAS, "Domain-id clk %s disable failed, rc: %d",
  3475. domain_id_clks->clk_names[i], rc);
  3476. }
  3477. if (!rc)
  3478. CAM_DBG(CAM_CPAS, "Domain-id clks disable success");
  3479. }
  3480. return rc;
  3481. clean_up:
  3482. for (--i; i >= 0; i--)
  3483. cam_soc_util_clk_disable(&cpas_hw->soc_info, CAM_CLK_SW_CLIENT_IDX, true,
  3484. domain_id_clks->clk_idx[i]);
  3485. return rc;
  3486. }
  3487. static int cam_cpas_hw_csid_process_resume(struct cam_hw_info *cpas_hw, uint32_t csid_idx)
  3488. {
  3489. int i, rc = 0;
  3490. struct cam_cpas_private_soc *soc_private =
  3491. (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3492. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3493. if (!soc_private->enable_cam_ddr_drv)
  3494. return 0;
  3495. for (i = 0; i < cpas_core->num_axi_ports; i++) {
  3496. if (!cpas_core->axi_port[i].bus_client.common_data.is_drv_port ||
  3497. !cpas_core->axi_port[i].is_drv_started ||
  3498. (cpas_core->axi_port[i].drv_idx != (CAM_CPAS_PORT_DRV_0 + csid_idx)))
  3499. continue;
  3500. /* Apply last applied bw again to applicable DRV port */
  3501. rc = cam_cpas_util_vote_drv_bus_client_bw(&cpas_core->axi_port[i].bus_client,
  3502. &cpas_core->axi_port[i].applied_bw, &cpas_core->axi_port[i].applied_bw);
  3503. if (rc) {
  3504. CAM_ERR(CAM_CPAS, "Failed in BW update on resume rc:%d", rc);
  3505. goto end;
  3506. }
  3507. /* Trigger channel switch for RSC dev */
  3508. rc = cam_cpas_drv_channel_switch_for_dev(cpas_core->axi_port[i].cam_rsc_dev);
  3509. if (rc) {
  3510. CAM_ERR(CAM_CPAS,
  3511. "Port[%s] failed in channel switch during resume rc:%d",
  3512. cpas_core->axi_port[i].axi_port_name, rc);
  3513. goto end;
  3514. }
  3515. }
  3516. end:
  3517. return rc;
  3518. }
  3519. static int cam_cpas_hw_process_cmd(void *hw_priv,
  3520. uint32_t cmd_type, void *cmd_args, uint32_t arg_size)
  3521. {
  3522. int rc = -EINVAL;
  3523. if (!hw_priv || !cmd_args ||
  3524. (cmd_type >= CAM_CPAS_HW_CMD_INVALID)) {
  3525. CAM_ERR(CAM_CPAS, "Invalid arguments %pK %pK %d",
  3526. hw_priv, cmd_args, cmd_type);
  3527. return -EINVAL;
  3528. }
  3529. switch (cmd_type) {
  3530. case CAM_CPAS_HW_CMD_REGISTER_CLIENT: {
  3531. struct cam_cpas_register_params *register_params;
  3532. if (sizeof(struct cam_cpas_register_params) != arg_size) {
  3533. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3534. cmd_type, arg_size);
  3535. break;
  3536. }
  3537. register_params = (struct cam_cpas_register_params *)cmd_args;
  3538. rc = cam_cpas_hw_register_client(hw_priv, register_params);
  3539. break;
  3540. }
  3541. case CAM_CPAS_HW_CMD_UNREGISTER_CLIENT: {
  3542. uint32_t *client_handle;
  3543. if (sizeof(uint32_t) != arg_size) {
  3544. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3545. cmd_type, arg_size);
  3546. break;
  3547. }
  3548. client_handle = (uint32_t *)cmd_args;
  3549. rc = cam_cpas_hw_unregister_client(hw_priv, *client_handle);
  3550. break;
  3551. }
  3552. case CAM_CPAS_HW_CMD_REG_WRITE: {
  3553. struct cam_cpas_hw_cmd_reg_read_write *reg_write;
  3554. if (sizeof(struct cam_cpas_hw_cmd_reg_read_write) !=
  3555. arg_size) {
  3556. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3557. cmd_type, arg_size);
  3558. break;
  3559. }
  3560. reg_write =
  3561. (struct cam_cpas_hw_cmd_reg_read_write *)cmd_args;
  3562. rc = cam_cpas_hw_reg_write(hw_priv, reg_write->client_handle,
  3563. reg_write->reg_base, reg_write->offset, reg_write->mb,
  3564. reg_write->value);
  3565. break;
  3566. }
  3567. case CAM_CPAS_HW_CMD_REG_READ: {
  3568. struct cam_cpas_hw_cmd_reg_read_write *reg_read;
  3569. if (sizeof(struct cam_cpas_hw_cmd_reg_read_write) !=
  3570. arg_size) {
  3571. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3572. cmd_type, arg_size);
  3573. break;
  3574. }
  3575. reg_read =
  3576. (struct cam_cpas_hw_cmd_reg_read_write *)cmd_args;
  3577. rc = cam_cpas_hw_reg_read(hw_priv,
  3578. reg_read->client_handle, reg_read->reg_base,
  3579. reg_read->offset, reg_read->mb, &reg_read->value);
  3580. break;
  3581. }
  3582. case CAM_CPAS_HW_CMD_AHB_VOTE: {
  3583. struct cam_cpas_hw_cmd_ahb_vote *cmd_ahb_vote;
  3584. if (sizeof(struct cam_cpas_hw_cmd_ahb_vote) != arg_size) {
  3585. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3586. cmd_type, arg_size);
  3587. break;
  3588. }
  3589. cmd_ahb_vote = (struct cam_cpas_hw_cmd_ahb_vote *)cmd_args;
  3590. rc = cam_cpas_hw_update_ahb_vote(hw_priv,
  3591. cmd_ahb_vote->client_handle, cmd_ahb_vote->ahb_vote);
  3592. break;
  3593. }
  3594. case CAM_CPAS_HW_CMD_AXI_VOTE: {
  3595. struct cam_cpas_hw_cmd_axi_vote *cmd_axi_vote;
  3596. if (sizeof(struct cam_cpas_hw_cmd_axi_vote) != arg_size) {
  3597. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3598. cmd_type, arg_size);
  3599. break;
  3600. }
  3601. cmd_axi_vote = (struct cam_cpas_hw_cmd_axi_vote *)cmd_args;
  3602. rc = cam_cpas_hw_update_axi_vote(hw_priv,
  3603. cmd_axi_vote->client_handle, cmd_axi_vote->axi_vote);
  3604. break;
  3605. }
  3606. case CAM_CPAS_HW_CMD_LOG_VOTE: {
  3607. bool *ddr_only;
  3608. if (sizeof(bool) != arg_size) {
  3609. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3610. cmd_type, arg_size);
  3611. break;
  3612. }
  3613. ddr_only = (bool *) cmd_args;
  3614. rc = cam_cpas_log_vote(hw_priv, *ddr_only);
  3615. break;
  3616. }
  3617. case CAM_CPAS_HW_CMD_LOG_EVENT: {
  3618. struct cam_cpas_hw_cmd_notify_event *event;
  3619. if (sizeof(struct cam_cpas_hw_cmd_notify_event) != arg_size) {
  3620. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3621. cmd_type, arg_size);
  3622. break;
  3623. }
  3624. event = (struct cam_cpas_hw_cmd_notify_event *)cmd_args;
  3625. rc = cam_cpas_log_event(hw_priv, event->identifier_string,
  3626. event->identifier_value);
  3627. break;
  3628. }
  3629. case CAM_CPAS_HW_CMD_SELECT_QOS: {
  3630. uint32_t *selection_mask;
  3631. if (sizeof(uint32_t) != arg_size) {
  3632. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3633. cmd_type, arg_size);
  3634. break;
  3635. }
  3636. selection_mask = (uint32_t *)cmd_args;
  3637. rc = cam_cpas_select_qos(hw_priv, *selection_mask);
  3638. break;
  3639. }
  3640. case CAM_CPAS_HW_CMD_GET_SCID: {
  3641. enum cam_sys_cache_config_types type;
  3642. if (sizeof(enum cam_sys_cache_config_types) != arg_size) {
  3643. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3644. cmd_type, arg_size);
  3645. break;
  3646. }
  3647. type = *((enum cam_sys_cache_config_types *) cmd_args);
  3648. rc = cam_cpas_get_slice_id(hw_priv, type);
  3649. }
  3650. break;
  3651. case CAM_CPAS_HW_CMD_ACTIVATE_LLC: {
  3652. enum cam_sys_cache_config_types type;
  3653. if (sizeof(enum cam_sys_cache_config_types) != arg_size) {
  3654. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3655. cmd_type, arg_size);
  3656. break;
  3657. }
  3658. type = *((enum cam_sys_cache_config_types *) cmd_args);
  3659. rc = cam_cpas_activate_cache_slice(hw_priv, type);
  3660. }
  3661. break;
  3662. case CAM_CPAS_HW_CMD_DEACTIVATE_LLC: {
  3663. enum cam_sys_cache_config_types type;
  3664. if (sizeof(enum cam_sys_cache_config_types) != arg_size) {
  3665. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3666. cmd_type, arg_size);
  3667. break;
  3668. }
  3669. type = *((enum cam_sys_cache_config_types *) cmd_args);
  3670. rc = cam_cpas_deactivate_cache_slice(hw_priv, type);
  3671. }
  3672. break;
  3673. case CAM_CPAS_HW_CMD_CONFIGURE_STALING_LLC: {
  3674. struct cam_sys_cache_local_info sys_cache_info;
  3675. if (sizeof(struct cam_sys_cache_local_info) != arg_size) {
  3676. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3677. cmd_type, arg_size);
  3678. break;
  3679. }
  3680. sys_cache_info =
  3681. *((struct cam_sys_cache_local_info *) cmd_args);
  3682. rc = cam_cpas_configure_staling_cache_slice(hw_priv, sys_cache_info);
  3683. }
  3684. break;
  3685. case CAM_CPAS_HW_CMD_NOTIF_STALL_INC_LLC: {
  3686. enum cam_sys_cache_config_types type;
  3687. if (sizeof(enum cam_sys_cache_config_types) != arg_size) {
  3688. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3689. cmd_type, arg_size);
  3690. break;
  3691. }
  3692. type = *((enum cam_sys_cache_config_types *) cmd_args);
  3693. rc = cam_cpas_notif_stalling_inc_cache_slice(hw_priv, type);
  3694. }
  3695. break;
  3696. case CAM_CPAS_HW_CMD_DUMP_BUFF_FILL_INFO: {
  3697. uint32_t *client_handle;
  3698. if (sizeof(uint32_t) != arg_size) {
  3699. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3700. cmd_type, arg_size);
  3701. break;
  3702. }
  3703. client_handle = (uint32_t *)cmd_args;
  3704. rc = cam_cpas_hw_dump_camnoc_buff_fill_info(hw_priv,
  3705. *client_handle);
  3706. break;
  3707. }
  3708. case CAM_CPAS_HW_CMD_CSID_INPUT_CORE_INFO_UPDATE: {
  3709. struct cam_cpas_hw_cmd_csid_input_core_info_update *core_info_update;
  3710. if (sizeof(struct cam_cpas_hw_cmd_csid_input_core_info_update) != arg_size) {
  3711. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d", cmd_type, arg_size);
  3712. break;
  3713. }
  3714. core_info_update = (struct cam_cpas_hw_cmd_csid_input_core_info_update *)cmd_args;
  3715. rc = cam_cpas_hw_csid_input_core_info_update(hw_priv, core_info_update->csid_idx,
  3716. core_info_update->sfe_idx, core_info_update->set_port);
  3717. break;
  3718. }
  3719. case CAM_CPAS_HW_CMD_CSID_PROCESS_RESUME: {
  3720. uint32_t *csid_idx;
  3721. if (sizeof(uint32_t) != arg_size) {
  3722. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3723. cmd_type, arg_size);
  3724. break;
  3725. }
  3726. csid_idx = (uint32_t *)cmd_args;
  3727. rc = cam_cpas_hw_csid_process_resume(hw_priv, *csid_idx);
  3728. break;
  3729. }
  3730. case CAM_CPAS_HW_CMD_TPG_MUX_SEL: {
  3731. uint32_t *tpg_mux_sel;
  3732. if (sizeof(uint32_t) != arg_size) {
  3733. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3734. cmd_type, arg_size);
  3735. break;
  3736. }
  3737. tpg_mux_sel = (uint32_t *)cmd_args;
  3738. rc = cam_cpas_hw_enable_tpg_mux_sel(hw_priv, *tpg_mux_sel);
  3739. break;
  3740. }
  3741. case CAM_CPAS_HW_CMD_ENABLE_DISABLE_DOMAIN_ID_CLK: {
  3742. bool *enable;
  3743. if (sizeof(bool) != arg_size) {
  3744. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3745. cmd_type, arg_size);
  3746. break;
  3747. }
  3748. enable = (bool *)cmd_args;
  3749. rc = cam_cpas_hw_enable_domain_id_clks(hw_priv, *enable);
  3750. break;
  3751. }
  3752. case CAM_CPAS_HW_CMD_DUMP_STATE_MONITOR_INFO: {
  3753. struct cam_req_mgr_dump_info *info;
  3754. if (sizeof(struct cam_req_mgr_dump_info) != arg_size) {
  3755. CAM_ERR(CAM_CPAS, "cmd_type %d, size mismatch %d",
  3756. cmd_type, arg_size);
  3757. break;
  3758. }
  3759. info = (struct cam_req_mgr_dump_info *)cmd_args;
  3760. rc = cam_cpas_dump_state_monitor_array_info(hw_priv, info);
  3761. break;
  3762. }
  3763. default:
  3764. CAM_ERR(CAM_CPAS, "CPAS HW command not valid =%d", cmd_type);
  3765. break;
  3766. }
  3767. return rc;
  3768. }
  3769. static int cam_cpas_util_client_setup(struct cam_hw_info *cpas_hw)
  3770. {
  3771. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3772. int i;
  3773. for (i = 0; i < CAM_CPAS_MAX_CLIENTS; i++) {
  3774. mutex_init(&cpas_core->client_mutex[i]);
  3775. }
  3776. return 0;
  3777. }
  3778. int cam_cpas_util_client_cleanup(struct cam_hw_info *cpas_hw)
  3779. {
  3780. struct cam_cpas *cpas_core = (struct cam_cpas *) cpas_hw->core_info;
  3781. int i;
  3782. for (i = 0; i < CAM_CPAS_MAX_CLIENTS; i++) {
  3783. if (cpas_core->cpas_client[i] &&
  3784. cpas_core->cpas_client[i]->registered) {
  3785. cam_cpas_hw_unregister_client(cpas_hw, i);
  3786. }
  3787. kfree(cpas_core->cpas_client[i]);
  3788. cpas_core->cpas_client[i] = NULL;
  3789. mutex_destroy(&cpas_core->client_mutex[i]);
  3790. }
  3791. return 0;
  3792. }
  3793. static int cam_cpas_util_get_internal_ops(struct platform_device *pdev,
  3794. struct cam_hw_intf *hw_intf, struct cam_cpas_internal_ops *internal_ops)
  3795. {
  3796. struct device_node *of_node = pdev->dev.of_node;
  3797. int rc;
  3798. const char *compat_str = NULL;
  3799. rc = of_property_read_string_index(of_node, "arch-compat", 0,
  3800. (const char **)&compat_str);
  3801. if (rc) {
  3802. CAM_ERR(CAM_CPAS, "failed to get arch-compat rc=%d", rc);
  3803. return -EINVAL;
  3804. }
  3805. if (strnstr(compat_str, "camss_top", strlen(compat_str))) {
  3806. hw_intf->hw_type = CAM_HW_CAMSSTOP;
  3807. rc = cam_camsstop_get_internal_ops(internal_ops);
  3808. } else if (strnstr(compat_str, "cpas_top", strlen(compat_str))) {
  3809. hw_intf->hw_type = CAM_HW_CPASTOP;
  3810. rc = cam_cpastop_get_internal_ops(internal_ops);
  3811. } else {
  3812. CAM_ERR(CAM_CPAS, "arch-compat %s not supported", compat_str);
  3813. rc = -EINVAL;
  3814. }
  3815. return rc;
  3816. }
  3817. static int cam_cpas_util_create_debugfs(struct cam_cpas *cpas_core)
  3818. {
  3819. int rc = 0;
  3820. struct dentry *dbgfileptr = NULL;
  3821. if (!cam_debugfs_available())
  3822. return 0;
  3823. rc = cam_debugfs_create_subdir("cpas", &dbgfileptr);
  3824. if (rc) {
  3825. CAM_ERR(CAM_CPAS,"DebugFS could not create directory!");
  3826. rc = -ENOENT;
  3827. goto end;
  3828. }
  3829. /* Store parent inode for cleanup in caller */
  3830. cpas_core->dentry = dbgfileptr;
  3831. debugfs_create_bool("ahb_bus_scaling_disable", 0644,
  3832. cpas_core->dentry, &cpas_core->ahb_bus_scaling_disable);
  3833. debugfs_create_bool("full_state_dump", 0644,
  3834. cpas_core->dentry, &cpas_core->full_state_dump);
  3835. debugfs_create_bool("smart_qos_dump", 0644,
  3836. cpas_core->dentry, &cpas_core->smart_qos_dump);
  3837. debugfs_create_bool("force_hlos_drv", 0644,
  3838. cpas_core->dentry, &cpas_core->force_hlos_drv);
  3839. debugfs_create_bool("force_cesta_sw_client", 0644,
  3840. cpas_core->dentry, &cpas_core->force_cesta_sw_client);
  3841. end:
  3842. return rc;
  3843. }
  3844. static struct cam_hw_info *cam_cpas_kobj_to_cpas_hw(struct kobject *kobj)
  3845. {
  3846. return container_of(kobj, struct cam_cpas_kobj_map, base_kobj)->cpas_hw;
  3847. }
  3848. static ssize_t cam_cpas_sysfs_get_subparts_info(struct kobject *kobj, struct kobj_attribute *attr,
  3849. char *buf)
  3850. {
  3851. int len = 0;
  3852. struct cam_hw_info *cpas_hw = cam_cpas_kobj_to_cpas_hw(kobj);
  3853. struct cam_cpas_private_soc *soc_private = NULL;
  3854. struct cam_cpas_sysfs_info *sysfs_info = NULL;
  3855. mutex_lock(&cpas_hw->hw_mutex);
  3856. soc_private = (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3857. sysfs_info = &soc_private->sysfs_info;
  3858. len += scnprintf(buf, PAGE_SIZE, "num_ifes: 0x%x, 0x%x\nnum_ife_lites: 0x%x, 0x%x\n"
  3859. "num_sfes: 0x%x, 0x%x\nnum_custom: 0x%x, 0x%x\n",
  3860. sysfs_info->num_ifes[CAM_CPAS_AVAILABLE_NUM_SUBPARTS],
  3861. sysfs_info->num_ifes[CAM_CPAS_FUNCTIONAL_NUM_SUBPARTS],
  3862. sysfs_info->num_ife_lites[CAM_CPAS_AVAILABLE_NUM_SUBPARTS],
  3863. sysfs_info->num_ife_lites[CAM_CPAS_FUNCTIONAL_NUM_SUBPARTS],
  3864. sysfs_info->num_sfes[CAM_CPAS_AVAILABLE_NUM_SUBPARTS],
  3865. sysfs_info->num_sfes[CAM_CPAS_FUNCTIONAL_NUM_SUBPARTS],
  3866. sysfs_info->num_custom[CAM_CPAS_AVAILABLE_NUM_SUBPARTS],
  3867. sysfs_info->num_custom[CAM_CPAS_FUNCTIONAL_NUM_SUBPARTS]);
  3868. /*
  3869. * subparts_info sysfs string looks like below.
  3870. * num_ifes: 0x3, 0x3 (If all IFEs are available)/0x2 (If 1 IFE is unavailable)
  3871. * num_ife_lites: 0x2, 0x2
  3872. * num_sfes: 0x3, 0x3 (If all SFEs are available)/0x2 (If 1 SFE is unavailable)
  3873. * num_custom: 0x0, 0x0
  3874. */
  3875. if (len >= PAGE_SIZE) {
  3876. CAM_ERR(CAM_CPAS, "camera subparts info sysfs string is truncated, len: %d", len);
  3877. mutex_unlock(&cpas_hw->hw_mutex);
  3878. return -EOVERFLOW;
  3879. }
  3880. mutex_unlock(&cpas_hw->hw_mutex);
  3881. return len;
  3882. }
  3883. static struct kobj_attribute cam_subparts_info_attribute = __ATTR(subparts_info, 0444,
  3884. cam_cpas_sysfs_get_subparts_info, NULL);
  3885. static void cam_cpas_hw_kobj_release(struct kobject *kobj)
  3886. {
  3887. CAM_DBG(CAM_CPAS, "Release kobj");
  3888. kfree(container_of(kobj, struct cam_cpas_kobj_map, base_kobj));
  3889. }
  3890. static struct kobj_type kobj_cam_cpas_hw_type = {
  3891. .release = cam_cpas_hw_kobj_release,
  3892. .sysfs_ops = &kobj_sysfs_ops
  3893. };
  3894. static void cam_cpas_remove_sysfs(struct cam_hw_info *cpas_hw)
  3895. {
  3896. struct cam_cpas_private_soc *soc_private = NULL;
  3897. mutex_lock(&cpas_hw->hw_mutex);
  3898. soc_private = (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3899. sysfs_remove_file(soc_private->sysfs_info.kobj, &cam_subparts_info_attribute.attr);
  3900. kobject_put(soc_private->sysfs_info.kobj);
  3901. mutex_unlock(&cpas_hw->hw_mutex);
  3902. }
  3903. static int cam_cpas_create_sysfs(struct cam_hw_info *cpas_hw)
  3904. {
  3905. int rc = 0;
  3906. struct cam_cpas_kobj_map *kobj_camera = NULL;
  3907. struct cam_cpas_private_soc *soc_private = NULL;
  3908. mutex_lock(&cpas_hw->hw_mutex);
  3909. soc_private = (struct cam_cpas_private_soc *) cpas_hw->soc_info.soc_private;
  3910. kobj_camera = kzalloc(sizeof(*kobj_camera), GFP_KERNEL);
  3911. if (!kobj_camera) {
  3912. CAM_ERR(CAM_CPAS, "failed to allocate memory for kobj_camera");
  3913. mutex_unlock(&cpas_hw->hw_mutex);
  3914. return -ENOMEM;
  3915. }
  3916. kobject_init(&kobj_camera->base_kobj, &kobj_cam_cpas_hw_type);
  3917. kobj_camera->cpas_hw = cpas_hw;
  3918. soc_private->sysfs_info.kobj = &kobj_camera->base_kobj;
  3919. rc = kobject_add(&kobj_camera->base_kobj, kernel_kobj, "%s", "camera");
  3920. if (rc) {
  3921. CAM_ERR(CAM_CPAS, "failed to add camera entry in sysfs");
  3922. goto end;
  3923. }
  3924. /* sysfs file is created in /sys/kernel/camera */
  3925. rc = sysfs_create_file(&kobj_camera->base_kobj, &cam_subparts_info_attribute.attr);
  3926. if (rc) {
  3927. CAM_ERR(CAM_CPAS, "failed to create subparts_info file, rc: %d", rc);
  3928. goto end;
  3929. }
  3930. mutex_unlock(&cpas_hw->hw_mutex);
  3931. return 0;
  3932. end:
  3933. kobject_put(&kobj_camera->base_kobj);
  3934. mutex_unlock(&cpas_hw->hw_mutex);
  3935. return rc;
  3936. }
  3937. int cam_cpas_hw_probe(struct platform_device *pdev,
  3938. struct cam_hw_intf **hw_intf)
  3939. {
  3940. int rc = 0;
  3941. int i;
  3942. struct cam_hw_info *cpas_hw = NULL;
  3943. struct cam_hw_intf *cpas_hw_intf = NULL;
  3944. struct cam_cpas *cpas_core = NULL;
  3945. struct cam_cpas_private_soc *soc_private;
  3946. struct cam_cpas_internal_ops *internal_ops;
  3947. cpas_hw_intf = kzalloc(sizeof(struct cam_hw_intf), GFP_KERNEL);
  3948. if (!cpas_hw_intf)
  3949. return -ENOMEM;
  3950. cpas_hw = kzalloc(sizeof(struct cam_hw_info), GFP_KERNEL);
  3951. if (!cpas_hw) {
  3952. kfree(cpas_hw_intf);
  3953. return -ENOMEM;
  3954. }
  3955. cpas_core = kzalloc(sizeof(struct cam_cpas), GFP_KERNEL);
  3956. if (!cpas_core) {
  3957. kfree(cpas_hw);
  3958. kfree(cpas_hw_intf);
  3959. return -ENOMEM;
  3960. }
  3961. for (i = 0; i < CAM_CPAS_REG_MAX; i++)
  3962. cpas_core->regbase_index[i] = -1;
  3963. cpas_hw_intf->hw_priv = cpas_hw;
  3964. cpas_hw->core_info = cpas_core;
  3965. cpas_hw->hw_state = CAM_HW_STATE_POWER_DOWN;
  3966. cpas_hw->soc_info.pdev = pdev;
  3967. cpas_hw->soc_info.dev = &pdev->dev;
  3968. cpas_hw->soc_info.dev_name = pdev->name;
  3969. cpas_hw->open_count = 0;
  3970. cpas_core->ahb_bus_scaling_disable = false;
  3971. cpas_core->full_state_dump = false;
  3972. cpas_core->smart_qos_dump = false;
  3973. atomic64_set(&cpas_core->monitor_head, -1);
  3974. mutex_init(&cpas_hw->hw_mutex);
  3975. spin_lock_init(&cpas_hw->hw_lock);
  3976. init_completion(&cpas_hw->hw_complete);
  3977. cpas_hw_intf->hw_ops.get_hw_caps = cam_cpas_hw_get_hw_info;
  3978. cpas_hw_intf->hw_ops.init = cam_cpas_hw_init;
  3979. cpas_hw_intf->hw_ops.deinit = NULL;
  3980. cpas_hw_intf->hw_ops.reset = NULL;
  3981. cpas_hw_intf->hw_ops.reserve = NULL;
  3982. cpas_hw_intf->hw_ops.release = NULL;
  3983. cpas_hw_intf->hw_ops.start = cam_cpas_hw_start;
  3984. cpas_hw_intf->hw_ops.stop = cam_cpas_hw_stop;
  3985. cpas_hw_intf->hw_ops.read = NULL;
  3986. cpas_hw_intf->hw_ops.write = NULL;
  3987. cpas_hw_intf->hw_ops.process_cmd = cam_cpas_hw_process_cmd;
  3988. cpas_core->work_queue = alloc_workqueue(CAM_CPAS_WORKQUEUE_NAME,
  3989. WQ_UNBOUND | WQ_MEM_RECLAIM, CAM_CPAS_INFLIGHT_WORKS);
  3990. if (!cpas_core->work_queue) {
  3991. rc = -ENOMEM;
  3992. goto release_mem;
  3993. }
  3994. internal_ops = &cpas_core->internal_ops;
  3995. rc = cam_cpas_util_get_internal_ops(pdev, cpas_hw_intf, internal_ops);
  3996. if (rc)
  3997. goto release_workq;
  3998. rc = cam_cpas_soc_init_resources(&cpas_hw->soc_info,
  3999. internal_ops->handle_irq, cpas_hw);
  4000. if (rc)
  4001. goto release_workq;
  4002. soc_private = (struct cam_cpas_private_soc *)
  4003. cpas_hw->soc_info.soc_private;
  4004. rc = cam_cpas_create_sysfs(cpas_hw);
  4005. if (rc) {
  4006. CAM_ERR(CAM_CPAS, "Failed to create sysfs entries, rc: %d", rc);
  4007. goto sysfs_fail;
  4008. }
  4009. cpas_core->num_clients = soc_private->num_clients;
  4010. atomic_set(&cpas_core->soc_access_count, 0);
  4011. init_waitqueue_head(&cpas_core->soc_access_count_wq);
  4012. if (internal_ops->setup_regbase) {
  4013. rc = internal_ops->setup_regbase(&cpas_hw->soc_info,
  4014. cpas_core->regbase_index, CAM_CPAS_REG_MAX);
  4015. if (rc)
  4016. goto deinit_platform_res;
  4017. }
  4018. rc = cam_cpas_util_client_setup(cpas_hw);
  4019. if (rc) {
  4020. CAM_ERR(CAM_CPAS, "failed in client setup, rc=%d", rc);
  4021. goto deinit_platform_res;
  4022. }
  4023. rc = cam_cpas_util_register_bus_client(&cpas_hw->soc_info,
  4024. cpas_hw->soc_info.pdev->dev.of_node,
  4025. &cpas_core->ahb_bus_client);
  4026. if (rc) {
  4027. CAM_ERR(CAM_CPAS, "failed in ahb setup, rc=%d", rc);
  4028. goto client_cleanup;
  4029. }
  4030. rc = cam_cpas_util_axi_setup(cpas_core, &cpas_hw->soc_info);
  4031. if (rc) {
  4032. CAM_ERR(CAM_CPAS, "failed in axi setup, rc=%d", rc);
  4033. goto ahb_cleanup;
  4034. }
  4035. /* Need to vote first before enabling clocks */
  4036. rc = cam_cpas_util_vote_default_ahb_axi(cpas_hw, true);
  4037. if (rc)
  4038. goto axi_cleanup;
  4039. rc = cam_cpas_soc_enable_resources(&cpas_hw->soc_info,
  4040. cpas_hw->soc_info.lowest_clk_level);
  4041. if (rc) {
  4042. CAM_ERR(CAM_CPAS, "failed in soc_enable_resources, rc=%d", rc);
  4043. goto remove_default_vote;
  4044. }
  4045. if (internal_ops->get_hw_info) {
  4046. rc = internal_ops->get_hw_info(cpas_hw, &cpas_core->hw_caps);
  4047. if (rc) {
  4048. CAM_ERR(CAM_CPAS, "failed in get_hw_info, rc=%d", rc);
  4049. goto disable_soc_res;
  4050. }
  4051. } else {
  4052. CAM_ERR(CAM_CPAS, "Invalid get_hw_info");
  4053. goto disable_soc_res;
  4054. }
  4055. rc = cam_cpas_hw_init(cpas_hw_intf->hw_priv,
  4056. &cpas_core->hw_caps, sizeof(struct cam_cpas_hw_caps));
  4057. if (rc)
  4058. goto disable_soc_res;
  4059. cpas_core->cam_subpart_info = &g_cam_cpas_camera_subpart_info;
  4060. rc = cam_get_subpart_info(&soc_private->part_info, CAM_CPAS_CAMERA_INSTANCES);
  4061. if (rc) {
  4062. CAM_ERR(CAM_CPAS, "Failed to get subpart_info, rc = %d", rc);
  4063. goto disable_soc_res;
  4064. }
  4065. rc = cam_cpas_soc_disable_resources(&cpas_hw->soc_info, true, true);
  4066. if (rc) {
  4067. CAM_ERR(CAM_CPAS, "failed in soc_disable_resources, rc=%d", rc);
  4068. goto remove_default_vote;
  4069. }
  4070. rc = cam_cpas_util_vote_default_ahb_axi(cpas_hw, false);
  4071. if (rc)
  4072. goto axi_cleanup;
  4073. rc = cam_cpas_util_create_debugfs(cpas_core);
  4074. if (unlikely(rc))
  4075. CAM_WARN(CAM_CPAS, "failed to create cpas debugfs rc: %d", rc);
  4076. *hw_intf = cpas_hw_intf;
  4077. return 0;
  4078. disable_soc_res:
  4079. cam_cpas_soc_disable_resources(&cpas_hw->soc_info, true, true);
  4080. remove_default_vote:
  4081. cam_cpas_util_vote_default_ahb_axi(cpas_hw, false);
  4082. axi_cleanup:
  4083. cam_cpas_util_axi_cleanup(cpas_core, &cpas_hw->soc_info);
  4084. ahb_cleanup:
  4085. cam_cpas_util_unregister_bus_client(&cpas_core->ahb_bus_client);
  4086. client_cleanup:
  4087. cam_cpas_util_client_cleanup(cpas_hw);
  4088. cam_cpas_node_tree_cleanup(cpas_core, cpas_hw->soc_info.soc_private);
  4089. deinit_platform_res:
  4090. cam_cpas_remove_sysfs(cpas_hw);
  4091. sysfs_fail:
  4092. cam_cpas_soc_deinit_resources(&cpas_hw->soc_info);
  4093. release_workq:
  4094. flush_workqueue(cpas_core->work_queue);
  4095. destroy_workqueue(cpas_core->work_queue);
  4096. release_mem:
  4097. mutex_destroy(&cpas_hw->hw_mutex);
  4098. kfree(cpas_core);
  4099. kfree(cpas_hw);
  4100. kfree(cpas_hw_intf);
  4101. CAM_ERR(CAM_CPAS, "failed in hw probe");
  4102. return rc;
  4103. }
  4104. int cam_cpas_hw_remove(struct cam_hw_intf *cpas_hw_intf)
  4105. {
  4106. struct cam_hw_info *cpas_hw;
  4107. struct cam_cpas *cpas_core;
  4108. if (!cpas_hw_intf) {
  4109. CAM_ERR(CAM_CPAS, "cpas interface not initialized");
  4110. return -EINVAL;
  4111. }
  4112. cpas_hw = (struct cam_hw_info *)cpas_hw_intf->hw_priv;
  4113. cpas_core = (struct cam_cpas *)cpas_hw->core_info;
  4114. if (cpas_hw->hw_state == CAM_HW_STATE_POWER_UP) {
  4115. CAM_ERR(CAM_CPAS, "cpas hw is in power up state");
  4116. return -EINVAL;
  4117. }
  4118. cam_cpas_remove_sysfs(cpas_hw);
  4119. cam_cpas_util_axi_cleanup(cpas_core, &cpas_hw->soc_info);
  4120. cam_cpas_node_tree_cleanup(cpas_core, cpas_hw->soc_info.soc_private);
  4121. cam_cpas_util_unregister_bus_client(&cpas_core->ahb_bus_client);
  4122. cam_cpas_util_client_cleanup(cpas_hw);
  4123. cam_cpas_soc_deinit_resources(&cpas_hw->soc_info);
  4124. cpas_core->dentry = NULL;
  4125. flush_workqueue(cpas_core->work_queue);
  4126. destroy_workqueue(cpas_core->work_queue);
  4127. mutex_destroy(&cpas_hw->hw_mutex);
  4128. kfree(cpas_core);
  4129. kfree(cpas_hw);
  4130. kfree(cpas_hw_intf);
  4131. return 0;
  4132. }