cam_cpas_hw.c 147 KB

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