123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
- */
- #include <linux/module.h>
- #include <linux/rpmsg.h>
- #include <linux/of_platform.h>
- #include <linux/of_fdt.h>
- #include <linux/qcom_scm.h>
- #include <soc/qcom/secure_buffer.h>
- #include "msm_cvp_core.h"
- #include "msm_cvp.h"
- #include "cvp_hfi.h"
- #include "cvp_dump.h"
- static atomic_t nr_maps;
- struct cvp_dsp_apps gfa_cv;
- static int cvp_reinit_dsp(void);
- static void cvp_remove_dsp_sessions(void);
- static int __fastrpc_driver_register(struct fastrpc_driver *driver)
- {
- #ifdef CVP_FASTRPC_ENABLED
- return fastrpc_driver_register(driver);
- #else
- return -ENODEV;
- #endif
- }
- static void __fastrpc_driver_unregister(struct fastrpc_driver *driver)
- {
- #ifdef CVP_FASTRPC_ENABLED
- return fastrpc_driver_unregister(driver);
- #endif
- }
- #ifdef CVP_FASTRPC_ENABLED
- static int __fastrpc_driver_invoke(struct fastrpc_device *dev,
- enum fastrpc_driver_invoke_nums invoke_num,
- unsigned long invoke_param)
- {
- return fastrpc_driver_invoke(dev, invoke_num, invoke_param);
- }
- #endif /* End of CVP_FASTRPC_ENABLED */
- static int cvp_dsp_send_cmd(struct cvp_dsp_cmd_msg *cmd, uint32_t len)
- {
- int rc = 0;
- struct cvp_dsp_apps *me = &gfa_cv;
- dprintk(CVP_DSP, "%s: cmd = %d\n", __func__, cmd->type);
- if (IS_ERR_OR_NULL(me->chan)) {
- dprintk(CVP_ERR, "%s: DSP GLink is not ready\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- rc = rpmsg_send(me->chan->ept, cmd, len);
- if (rc) {
- dprintk(CVP_ERR, "%s: DSP rpmsg_send failed rc=%d\n",
- __func__, rc);
- goto exit;
- }
- exit:
- return rc;
- }
- static int cvp_dsp_send_cmd_sync(struct cvp_dsp_cmd_msg *cmd,
- uint32_t len, struct cvp_dsp_rsp_msg *rsp)
- {
- int rc = 0;
- struct cvp_dsp_apps *me = &gfa_cv;
- dprintk(CVP_DSP, "%s: cmd = %d\n", __func__, cmd->type);
- me->pending_dsp2cpu_rsp.type = cmd->type;
- rc = cvp_dsp_send_cmd(cmd, len);
- if (rc) {
- dprintk(CVP_ERR, "%s: cvp_dsp_send_cmd failed rc=%d\n",
- __func__, rc);
- goto exit;
- }
- if (!wait_for_completion_timeout(&me->completions[cmd->type],
- msecs_to_jiffies(CVP_DSP_RESPONSE_TIMEOUT))) {
- dprintk(CVP_ERR, "%s cmd %d timeout\n", __func__, cmd->type);
- rc = -ETIMEDOUT;
- goto exit;
- }
- exit:
- rsp->ret = me->pending_dsp2cpu_rsp.ret;
- rsp->dsp_state = me->pending_dsp2cpu_rsp.dsp_state;
- me->pending_dsp2cpu_rsp.type = CVP_INVALID_RPMSG_TYPE;
- return rc;
- }
- static int cvp_dsp_send_cmd_hfi_queue(phys_addr_t *phys_addr,
- uint32_t size_in_bytes,
- struct cvp_dsp_rsp_msg *rsp)
- {
- int rc = 0;
- struct cvp_dsp_cmd_msg cmd;
- cmd.type = CPU2DSP_SEND_HFI_QUEUE;
- cmd.msg_ptr = (uint64_t)phys_addr;
- cmd.msg_ptr_len = size_in_bytes;
- cmd.ddr_type = cvp_of_fdt_get_ddrtype();
- if (cmd.ddr_type < 0) {
- dprintk(CVP_WARN,
- "%s: Incorrect DDR type value %d, use default %d\n",
- __func__, cmd.ddr_type, DDR_TYPE_LPDDR5);
- /*return -EINVAL;*/
- cmd.ddr_type = DDR_TYPE_LPDDR5;
- }
- dprintk(CVP_DSP,
- "%s: address of buffer, PA=0x%pK size_buff=%d ddr_type=%d\n",
- __func__, phys_addr, size_in_bytes, cmd.ddr_type);
- rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), rsp);
- if (rc) {
- dprintk(CVP_ERR,
- "%s: cvp_dsp_send_cmd failed rc = %d\n",
- __func__, rc);
- goto exit;
- }
- exit:
- return rc;
- }
- static int cvp_hyp_assign_to_dsp(uint64_t addr, uint32_t size)
- {
- int rc = 0;
- struct cvp_dsp_apps *me = &gfa_cv;
- uint64_t hlosVMid = BIT(VMID_HLOS);
- struct qcom_scm_vmperm dspVM[DSP_VM_NUM] = {
- {VMID_HLOS, PERM_READ | PERM_WRITE | PERM_EXEC},
- {VMID_CDSP_Q6, PERM_READ | PERM_WRITE | PERM_EXEC}
- };
- if (!me->hyp_assigned) {
- rc = qcom_scm_assign_mem(addr, size, &hlosVMid, dspVM, DSP_VM_NUM);
- if (rc) {
- dprintk(CVP_ERR, "%s failed. rc=%d\n", __func__, rc);
- return rc;
- }
- me->addr = addr;
- me->size = size;
- me->hyp_assigned = true;
- }
- return rc;
- }
- static int cvp_hyp_assign_from_dsp(void)
- {
- int rc = 0;
- struct cvp_dsp_apps *me = &gfa_cv;
- uint64_t dspVMids = BIT(VMID_HLOS) | BIT(VMID_CDSP_Q6);
- struct qcom_scm_vmperm hlosVM[HLOS_VM_NUM] = {
- {VMID_HLOS, PERM_READ | PERM_WRITE | PERM_EXEC},
- };
- if (me->hyp_assigned) {
- rc = qcom_scm_assign_mem(me->addr, me->size, &dspVMids, hlosVM, HLOS_VM_NUM);
- if (rc) {
- dprintk(CVP_ERR, "%s failed. rc=%d\n", __func__, rc);
- return rc;
- }
- me->addr = 0;
- me->size = 0;
- me->hyp_assigned = false;
- }
- return rc;
- }
- static int cvp_dsp_rpmsg_probe(struct rpmsg_device *rpdev)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- const char *edge_name = NULL;
- int ret = 0;
- ret = of_property_read_string(rpdev->dev.parent->of_node,
- "label", &edge_name);
- if (ret) {
- dprintk(CVP_ERR, "glink edge 'label' not found in node\n");
- return ret;
- }
- if (strcmp(edge_name, "cdsp")) {
- dprintk(CVP_ERR,
- "%s: Failed to probe rpmsg device.Node name:%s\n",
- __func__, edge_name);
- return -EINVAL;
- }
- mutex_lock(&me->tx_lock);
- me->chan = rpdev;
- me->state = DSP_PROBED;
- mutex_unlock(&me->tx_lock);
- complete(&me->completions[CPU2DSP_MAX_CMD]);
- return ret;
- }
- static int eva_fastrpc_dev_unmap_dma(
- struct fastrpc_device *frpc_device,
- struct cvp_internal_buf *buf);
- static int delete_dsp_session(struct msm_cvp_inst *inst,
- struct cvp_dsp_fastrpc_driver_entry *frpc_node)
- {
- struct msm_cvp_list *buf_list = NULL;
- struct list_head *ptr_dsp_buf = NULL, *next_dsp_buf = NULL;
- struct cvp_internal_buf *buf = NULL;
- struct task_struct *task = NULL;
- struct cvp_hfi_device *hdev;
- int rc;
- if (!inst)
- return -EINVAL;
- buf_list = &inst->cvpdspbufs;
- mutex_lock(&buf_list->lock);
- ptr_dsp_buf = &buf_list->list;
- list_for_each_safe(ptr_dsp_buf, next_dsp_buf, &buf_list->list) {
- if (!ptr_dsp_buf)
- break;
- buf = list_entry(ptr_dsp_buf, struct cvp_internal_buf, list);
- if (buf) {
- dprintk(CVP_DSP, "fd in list 0x%x\n", buf->fd);
- if (!buf->smem) {
- dprintk(CVP_DSP, "Empyt smem\n");
- continue;
- }
- dprintk(CVP_DSP, "%s find device addr 0x%x\n",
- __func__, buf->smem->device_addr);
- rc = eva_fastrpc_dev_unmap_dma(
- frpc_node->cvp_fastrpc_device,
- buf);
- if (rc)
- dprintk_rl(CVP_WARN,
- "%s Failed to unmap buffer 0x%x\n",
- __func__, rc);
- rc = cvp_release_dsp_buffers(inst, buf);
- if (rc)
- dprintk(CVP_ERR,
- "%s Failed to free buffer 0x%x\n",
- __func__, rc);
- list_del(&buf->list);
- cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
- }
- }
- mutex_unlock(&buf_list->lock);
- task = inst->task;
- spin_lock(&inst->core->resources.pm_qos.lock);
- if (inst->core->resources.pm_qos.off_vote_cnt > 0)
- inst->core->resources.pm_qos.off_vote_cnt--;
- else
- dprintk(CVP_WARN, "%s Unexpected pm_qos off vote %d\n",
- __func__,
- inst->core->resources.pm_qos.off_vote_cnt);
- spin_unlock(&inst->core->resources.pm_qos.lock);
- hdev = inst->core->device;
- call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
- rc = msm_cvp_close(inst);
- if (rc)
- dprintk(CVP_ERR, "Warning: Failed to close cvp instance\n");
- if (task)
- put_task_struct(task);
- dprintk(CVP_DSP, "%s DSP2CPU_DETELE_SESSION Done\n", __func__);
- return rc;
- }
- static int eva_fastrpc_driver_get_name(
- struct cvp_dsp_fastrpc_driver_entry *frpc_node)
- {
- int i = 0;
- struct cvp_dsp_apps *me = &gfa_cv;
- for (i = 0; i < MAX_FASTRPC_DRIVER_NUM; i++) {
- if (me->cvp_fastrpc_name[i].status == DRIVER_NAME_AVAILABLE) {
- frpc_node->driver_name_idx = i;
- frpc_node->cvp_fastrpc_driver.driver.name =
- me->cvp_fastrpc_name[i].name;
- me->cvp_fastrpc_name[i].status = DRIVER_NAME_USED;
- dprintk(CVP_DSP, "%s -> handle 0x%x get name %s\n",
- __func__, frpc_node->cvp_fastrpc_driver.handle,
- frpc_node->cvp_fastrpc_driver.driver.name);
- return 0;
- }
- }
- return -1;
- }
- static void eva_fastrpc_driver_release_name(
- struct cvp_dsp_fastrpc_driver_entry *frpc_node)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- me->cvp_fastrpc_name[frpc_node->driver_name_idx].status =
- DRIVER_NAME_AVAILABLE;
- }
- /* The function may not return for up to 50ms */
- static bool dequeue_frpc_node(struct cvp_dsp_fastrpc_driver_entry *node)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct list_head *ptr = NULL, *next = NULL;
- u32 refcount, max_count = 10;
- bool rc = false;
- if (!node)
- return rc;
- search_again:
- ptr = &me->fastrpc_driver_list.list;
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
- frpc_node = list_entry(ptr,
- struct cvp_dsp_fastrpc_driver_entry, list);
- if (frpc_node == node) {
- refcount = atomic_read(&frpc_node->refcount);
- if (refcount > 0) {
- mutex_unlock(&me->fastrpc_driver_list.lock);
- usleep_range(5000, 10000);
- if (max_count-- == 0) {
- dprintk(CVP_ERR, "%s timeout %d\n",
- __func__, refcount);
- WARN_ON(true);
- goto exit;
- }
- goto search_again;
- }
- list_del(&frpc_node->list);
- rc = true;
- break;
- }
- }
- mutex_unlock(&me->fastrpc_driver_list.lock);
- exit:
- return rc;
- }
- /* The function may not return for up to 50ms */
- static struct cvp_dsp_fastrpc_driver_entry *pop_frpc_node(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct list_head *ptr = NULL, *next = NULL;
- u32 refcount, max_count = 10;
- search_again:
- ptr = &me->fastrpc_driver_list.list;
- if (!ptr) {
- frpc_node = NULL;
- goto exit;
- }
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
- if (!ptr)
- break;
- frpc_node = list_entry(ptr,
- struct cvp_dsp_fastrpc_driver_entry, list);
- if (frpc_node) {
- refcount = atomic_read(&frpc_node->refcount);
- if (refcount > 0) {
- mutex_unlock(&me->fastrpc_driver_list.lock);
- usleep_range(5000, 10000);
- if (max_count-- == 0) {
- dprintk(CVP_ERR, "%s timeout\n",
- __func__);
- frpc_node = NULL;
- goto exit;
- }
- goto search_again;
- }
- list_del(&frpc_node->list);
- break;
- }
- }
- mutex_unlock(&me->fastrpc_driver_list.lock);
- exit:
- return frpc_node;
- }
- static void cvp_dsp_rpmsg_remove(struct rpmsg_device *rpdev)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- u32 max_num_retries = 100;
- dprintk(CVP_WARN, "%s: CDSP SSR triggered\n", __func__);
- mutex_lock(&me->rx_lock);
- while (max_num_retries > 0) {
- if (me->pending_dsp2cpu_cmd.type !=
- CVP_INVALID_RPMSG_TYPE) {
- mutex_unlock(&me->rx_lock);
- usleep_range(1000, 5000);
- mutex_lock(&me->rx_lock);
- } else {
- break;
- }
- max_num_retries--;
- }
- if (!max_num_retries)
- dprintk(CVP_ERR, "stuck processing pending DSP cmds\n");
- mutex_lock(&me->tx_lock);
- cvp_hyp_assign_from_dsp();
- me->chan = NULL;
- me->state = DSP_UNINIT;
- mutex_unlock(&me->tx_lock);
- mutex_unlock(&me->rx_lock);
- /* Wait HW finish current frame processing */
- usleep_range(20000, 50000);
- cvp_remove_dsp_sessions();
- dprintk(CVP_WARN, "%s: CDSP SSR handled nr_maps %d\n", __func__,
- atomic_read(&nr_maps));
- }
- static int cvp_dsp_rpmsg_callback(struct rpmsg_device *rpdev,
- void *data, int len, void *priv, u32 addr)
- {
- struct cvp_dsp_rsp_msg *rsp = (struct cvp_dsp_rsp_msg *)data;
- struct cvp_dsp_apps *me = &gfa_cv;
- dprintk(CVP_DSP, "%s: type = 0x%x ret = 0x%x len = 0x%x\n",
- __func__, rsp->type, rsp->ret, len);
- if (rsp->type < CPU2DSP_MAX_CMD && len == sizeof(*rsp)) {
- if (me->pending_dsp2cpu_rsp.type == rsp->type) {
- memcpy(&me->pending_dsp2cpu_rsp, rsp,
- sizeof(struct cvp_dsp_rsp_msg));
- complete(&me->completions[rsp->type]);
- } else {
- dprintk(CVP_ERR, "%s: CPU2DSP resp %d, pending %d\n",
- __func__, rsp->type,
- me->pending_dsp2cpu_rsp.type);
- goto exit;
- }
- } else if (rsp->type < CVP_DSP_MAX_CMD &&
- len == sizeof(struct cvp_dsp2cpu_cmd)) {
- if (me->pending_dsp2cpu_cmd.type != CVP_INVALID_RPMSG_TYPE) {
- dprintk(CVP_ERR,
- "%s: DSP2CPU cmd:%d pending %d %d expect %d\n",
- __func__, rsp->type,
- me->pending_dsp2cpu_cmd.type, len,
- sizeof(struct cvp_dsp2cpu_cmd));
- goto exit;
- }
- memcpy(&me->pending_dsp2cpu_cmd, rsp,
- sizeof(struct cvp_dsp2cpu_cmd));
- complete(&me->completions[CPU2DSP_MAX_CMD]);
- } else {
- dprintk(CVP_ERR, "%s: Invalid type: %d\n", __func__, rsp->type);
- return 0;
- }
- return 0;
- exit:
- dprintk(CVP_ERR, "concurrent dsp cmd type = %d, rsp type = %d\n",
- me->pending_dsp2cpu_cmd.type,
- me->pending_dsp2cpu_rsp.type);
- return 0;
- }
- static bool dsp_session_exist(void)
- {
- struct msm_cvp_core *core;
- struct msm_cvp_inst *inst = NULL;
- core = cvp_driver->cvp_core;
- if (core) {
- mutex_lock(&core->lock);
- list_for_each_entry(inst, &core->instances, list) {
- if (inst->session_type == MSM_CVP_DSP) {
- mutex_unlock(&core->lock);
- return true;
- }
- }
- mutex_unlock(&core->lock);
- }
- return false;
- }
- int cvp_dsp_suspend(bool force)
- {
- int rc = 0;
- struct cvp_dsp_cmd_msg cmd;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp;
- bool retried = false;
- /* If not forced to suspend, check if DSP requested PC earlier */
- if (force == false)
- if (dsp_session_exist())
- if (me->state != DSP_SUSPEND)
- return -EBUSY;
- cmd.type = CPU2DSP_SUSPEND;
- mutex_lock(&me->tx_lock);
- if (me->state != DSP_READY)
- goto exit;
- retry:
- /* Use cvp_dsp_send_cmd_sync after dsp driver is ready */
- rc = cvp_dsp_send_cmd_sync(&cmd,
- sizeof(struct cvp_dsp_cmd_msg),
- &rsp);
- if (rc) {
- dprintk(CVP_ERR,
- "%s: cvp_dsp_send_cmd failed rc = %d\n",
- __func__, rc);
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EUNAVAILABLE)
- goto fatal_exit;
- if (rsp.ret == CPU2DSP_EFATAL) {
- dprintk(CVP_ERR, "%s: suspend dsp got EFATAL error\n",
- __func__);
- if (!retried) {
- mutex_unlock(&me->tx_lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->tx_lock);
- if (rc)
- goto fatal_exit;
- else
- goto retry;
- } else {
- goto fatal_exit;
- }
- }
- me->state = DSP_SUSPEND;
- dprintk(CVP_DSP, "DSP suspended, nr_map: %d\n", atomic_read(&nr_maps));
- goto exit;
- fatal_exit:
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- rc = -ENOTSUPP;
- exit:
- mutex_unlock(&me->tx_lock);
- return rc;
- }
- int cvp_dsp_resume(void)
- {
- int rc = 0;
- struct cvp_dsp_cmd_msg cmd;
- struct cvp_dsp_apps *me = &gfa_cv;
- cmd.type = CPU2DSP_RESUME;
- /*
- * Deadlock against DSP2CPU_CREATE_SESSION in dsp_thread
- * Probably get rid of this entirely as discussed before
- */
- if (me->state != DSP_SUSPEND)
- dprintk(CVP_WARN, "%s DSP not in SUSPEND state\n", __func__);
- return rc;
- }
- static void cvp_remove_dsp_sessions(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct msm_cvp_inst *inst = NULL;
- struct list_head *s = NULL, *next_s = NULL;
- while ((frpc_node = pop_frpc_node())) {
- s = &frpc_node->dsp_sessions.list;
- if (!s || !(s->next))
- return;
- list_for_each_safe(s, next_s,
- &frpc_node->dsp_sessions.list) {
- if (!s || !next_s)
- return;
- inst = list_entry(s, struct msm_cvp_inst,
- dsp_list);
- if (inst) {
- mutex_lock(&frpc_node->dsp_sessions.lock);
- list_del(&inst->dsp_list);
- frpc_node->session_cnt--;
- mutex_unlock(&frpc_node->dsp_sessions.lock);
- delete_dsp_session(inst, frpc_node);
- }
- }
- dprintk(CVP_DSP, "%s DEINIT_MSM_CVP_LIST 0x%x\n",
- __func__, frpc_node->dsp_sessions);
- DEINIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
- dprintk(CVP_DSP, "%s list_del fastrpc node 0x%x\n",
- __func__, frpc_node);
- __fastrpc_driver_unregister(
- &frpc_node->cvp_fastrpc_driver);
- dprintk(CVP_DSP,
- "%s Unregistered fastrpc handle 0x%x\n",
- __func__, frpc_node->handle);
- mutex_lock(&me->driver_name_lock);
- eva_fastrpc_driver_release_name(frpc_node);
- mutex_unlock(&me->driver_name_lock);
- kfree(frpc_node);
- frpc_node = NULL;
- }
- dprintk(CVP_WARN, "%s: EVA SSR handled for CDSP\n", __func__);
- }
- int cvp_dsp_shutdown(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- int rc = 0;
- struct cvp_dsp_cmd_msg cmd;
- struct cvp_dsp_rsp_msg rsp;
- cmd.type = CPU2DSP_SHUTDOWN;
- mutex_lock(&me->tx_lock);
- if (me->state == DSP_INVALID)
- goto exit;
- me->state = DSP_INACTIVE;
- rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
- if (rc) {
- dprintk(CVP_ERR,
- "%s: cvp_dsp_send_cmd failed with rc = %d\n",
- __func__, rc);
- cvp_hyp_assign_from_dsp();
- goto exit;
- }
- rc = cvp_hyp_assign_from_dsp();
- exit:
- mutex_unlock(&me->tx_lock);
- return rc;
- }
- int cvp_dsp_register_buffer(uint32_t session_id, uint32_t buff_fd,
- uint32_t buff_fd_size, uint32_t buff_size,
- uint32_t buff_offset, uint32_t buff_index,
- uint32_t buff_fd_iova)
- {
- struct cvp_dsp_cmd_msg cmd;
- int rc;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp;
- bool retried = false;
- cmd.type = CPU2DSP_REGISTER_BUFFER;
- cmd.session_id = session_id;
- cmd.buff_fd = buff_fd;
- cmd.buff_fd_size = buff_fd_size;
- cmd.buff_size = buff_size;
- cmd.buff_offset = buff_offset;
- cmd.buff_index = buff_index;
- cmd.buff_fd_iova = buff_fd_iova;
- dprintk(CVP_DSP,
- "%s: type=0x%x, buff_fd_iova=0x%x buff_index=0x%x\n",
- __func__, cmd.type, buff_fd_iova,
- cmd.buff_index);
- dprintk(CVP_DSP, "%s: buff_size=0x%x session_id=0x%x\n",
- __func__, cmd.buff_size, cmd.session_id);
- mutex_lock(&me->tx_lock);
- retry:
- rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
- if (rc) {
- dprintk(CVP_ERR, "%s send failed rc = %d\n", __func__, rc);
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EFAIL || rsp.ret == CPU2DSP_EUNSUPPORTED) {
- dprintk(CVP_WARN, "%s, DSP return err %d\n", __func__, rsp.ret);
- rc = -EINVAL;
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EUNAVAILABLE)
- goto fatal_exit;
- if (rsp.ret == CPU2DSP_EFATAL) {
- if (!retried) {
- mutex_unlock(&me->tx_lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->tx_lock);
- if (rc)
- goto fatal_exit;
- else
- goto retry;
- } else {
- goto fatal_exit;
- }
- }
- goto exit;
- fatal_exit:
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- rc = -ENOTSUPP;
- exit:
- mutex_unlock(&me->tx_lock);
- return rc;
- }
- int cvp_dsp_deregister_buffer(uint32_t session_id, uint32_t buff_fd,
- uint32_t buff_fd_size, uint32_t buff_size,
- uint32_t buff_offset, uint32_t buff_index,
- uint32_t buff_fd_iova)
- {
- struct cvp_dsp_cmd_msg cmd;
- int rc;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp;
- bool retried = false;
- cmd.type = CPU2DSP_DEREGISTER_BUFFER;
- cmd.session_id = session_id;
- cmd.buff_fd = buff_fd;
- cmd.buff_fd_size = buff_fd_size;
- cmd.buff_size = buff_size;
- cmd.buff_offset = buff_offset;
- cmd.buff_index = buff_index;
- cmd.buff_fd_iova = buff_fd_iova;
- dprintk(CVP_DSP,
- "%s: type=0x%x, buff_fd_iova=0x%x buff_index=0x%x\n",
- __func__, cmd.type, buff_fd_iova,
- cmd.buff_index);
- dprintk(CVP_DSP, "%s: buff_size=0x%x session_id=0x%x\n",
- __func__, cmd.buff_size, cmd.session_id);
- mutex_lock(&me->tx_lock);
- retry:
- rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
- if (rc) {
- dprintk(CVP_ERR, "%s send failed rc = %d\n", __func__, rc);
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EFAIL || rsp.ret == CPU2DSP_EUNSUPPORTED) {
- dprintk(CVP_WARN, "%s, DSP return err %d\n", __func__, rsp.ret);
- rc = -EINVAL;
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EUNAVAILABLE)
- goto fatal_exit;
- if (rsp.ret == CPU2DSP_EFATAL) {
- if (!retried) {
- mutex_unlock(&me->tx_lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->tx_lock);
- if (rc)
- goto fatal_exit;
- else
- goto retry;
- } else {
- goto fatal_exit;
- }
- }
- goto exit;
- fatal_exit:
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- rc = -ENOTSUPP;
- exit:
- mutex_unlock(&me->tx_lock);
- return rc;
- }
- static const struct rpmsg_device_id cvp_dsp_rpmsg_match[] = {
- { CVP_APPS_DSP_GLINK_GUID },
- { },
- };
- static struct rpmsg_driver cvp_dsp_rpmsg_client = {
- .id_table = cvp_dsp_rpmsg_match,
- .probe = cvp_dsp_rpmsg_probe,
- .remove = cvp_dsp_rpmsg_remove,
- .callback = cvp_dsp_rpmsg_callback,
- .drv = {
- .name = "qcom,msm_cvp_dsp_rpmsg",
- },
- };
- static void cvp_dsp_set_queue_hdr_defaults(struct cvp_hfi_queue_header *q_hdr)
- {
- q_hdr->qhdr_status = 0x1;
- q_hdr->qhdr_type = CVP_IFACEQ_DFLT_QHDR;
- q_hdr->qhdr_q_size = CVP_IFACEQ_QUEUE_SIZE / 4;
- q_hdr->qhdr_pkt_size = 0;
- q_hdr->qhdr_rx_wm = 0x1;
- q_hdr->qhdr_tx_wm = 0x1;
- q_hdr->qhdr_rx_req = 0x1;
- q_hdr->qhdr_tx_req = 0x0;
- q_hdr->qhdr_rx_irq_status = 0x0;
- q_hdr->qhdr_tx_irq_status = 0x0;
- q_hdr->qhdr_read_idx = 0x0;
- q_hdr->qhdr_write_idx = 0x0;
- }
- void cvp_dsp_init_hfi_queue_hdr(struct iris_hfi_device *device)
- {
- u32 i;
- struct cvp_hfi_queue_table_header *q_tbl_hdr;
- struct cvp_hfi_queue_header *q_hdr;
- struct cvp_iface_q_info *iface_q;
- for (i = 0; i < CVP_IFACEQ_NUMQ; i++) {
- iface_q = &device->dsp_iface_queues[i];
- iface_q->q_hdr = CVP_IFACEQ_GET_QHDR_START_ADDR(
- device->dsp_iface_q_table.align_virtual_addr, i);
- cvp_dsp_set_queue_hdr_defaults(iface_q->q_hdr);
- }
- q_tbl_hdr = (struct cvp_hfi_queue_table_header *)
- device->dsp_iface_q_table.align_virtual_addr;
- q_tbl_hdr->qtbl_version = 0;
- q_tbl_hdr->device_addr = (void *)device;
- strlcpy(q_tbl_hdr->name, "msm_cvp", sizeof(q_tbl_hdr->name));
- q_tbl_hdr->qtbl_size = CVP_IFACEQ_TABLE_SIZE;
- q_tbl_hdr->qtbl_qhdr0_offset =
- sizeof(struct cvp_hfi_queue_table_header);
- q_tbl_hdr->qtbl_qhdr_size = sizeof(struct cvp_hfi_queue_header);
- q_tbl_hdr->qtbl_num_q = CVP_IFACEQ_NUMQ;
- q_tbl_hdr->qtbl_num_active_q = CVP_IFACEQ_NUMQ;
- iface_q = &device->dsp_iface_queues[CVP_IFACEQ_CMDQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_HOST_TO_CTRL_CMD_Q;
- iface_q = &device->dsp_iface_queues[CVP_IFACEQ_MSGQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_MSG_Q;
- iface_q = &device->dsp_iface_queues[CVP_IFACEQ_DBGQ_IDX];
- q_hdr = iface_q->q_hdr;
- q_hdr->qhdr_start_addr = iface_q->q_array.align_device_addr;
- q_hdr->qhdr_type |= HFI_Q_ID_CTRL_TO_HOST_DEBUG_Q;
- /*
- * Set receive request to zero on debug queue as there is no
- * need of interrupt from cvp hardware for debug messages
- */
- q_hdr->qhdr_rx_req = 0;
- }
- static int __reinit_dsp(void)
- {
- int rc;
- uint64_t addr;
- uint32_t size;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp;
- struct msm_cvp_core *core;
- struct iris_hfi_device *device;
- core = cvp_driver->cvp_core;
- if (core && core->device)
- device = core->device->hfi_device_data;
- else
- return -EINVAL;
- if (!device) {
- dprintk(CVP_ERR, "%s: NULL device\n", __func__);
- return -EINVAL;
- }
- /* Force shutdown DSP */
- rc = cvp_dsp_shutdown();
- if (rc)
- return rc;
- /*
- * Workaround to force delete DSP session resources
- * To be removed after DSP optimization ready
- */
- cvp_remove_dsp_sessions();
- dprintk(CVP_WARN, "Reinit EVA DSP interface: nr_map %d\n",
- atomic_read(&nr_maps));
- /* Resend HFI queue */
- mutex_lock(&me->tx_lock);
- if (!device->dsp_iface_q_table.align_virtual_addr) {
- dprintk(CVP_ERR, "%s: DSP HFI queue released\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- addr = (uint64_t)device->dsp_iface_q_table.mem_data.dma_handle;
- size = device->dsp_iface_q_table.mem_data.size;
- if (!addr || !size) {
- dprintk(CVP_DSP, "%s: HFI queue is not ready\n", __func__);
- goto exit;
- }
- rc = cvp_hyp_assign_to_dsp(addr, size);
- if (rc) {
- dprintk(CVP_ERR, "%s: cvp_hyp_assign_to_dsp. rc=%d\n",
- __func__, rc);
- goto exit;
- }
- rc = cvp_dsp_send_cmd_hfi_queue((phys_addr_t *)addr, size, &rsp);
- if (rc) {
- dprintk(CVP_WARN, "%s: Send HFI Queue failed rc = %d\n",
- __func__, rc);
- goto exit;
- }
- if (rsp.ret) {
- dprintk(CVP_ERR, "%s: DSP error %d %d\n", __func__,
- rsp.ret, rsp.dsp_state);
- rc = -ENODEV;
- }
- exit:
- mutex_unlock(&me->tx_lock);
- return rc;
- }
- static int cvp_reinit_dsp(void)
- {
- int rc;
- struct cvp_dsp_apps *me = &gfa_cv;
- rc = __reinit_dsp();
- if (rc) {
- mutex_lock(&me->tx_lock);
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- mutex_unlock(&me->tx_lock);
- }
- return rc;
- }
- static void cvp_put_fastrpc_node(struct cvp_dsp_fastrpc_driver_entry *node)
- {
- if (node && (atomic_read(&node->refcount) > 0))
- atomic_dec(&node->refcount);
- }
- static struct cvp_dsp_fastrpc_driver_entry *cvp_get_fastrpc_node_with_handle(
- uint32_t handle)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct list_head *ptr = NULL, *next = NULL;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL, *tmp_node = NULL;
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_for_each_safe(ptr, next, &me->fastrpc_driver_list.list) {
- if (!ptr)
- break;
- tmp_node = list_entry(ptr,
- struct cvp_dsp_fastrpc_driver_entry, list);
- if (handle == tmp_node->handle) {
- frpc_node = tmp_node;
- atomic_inc(&frpc_node->refcount);
- dprintk(CVP_DSP, "Find tmp_node with handle 0x%x\n",
- handle);
- break;
- }
- }
- mutex_unlock(&me->fastrpc_driver_list.lock);
- dprintk(CVP_DSP, "%s found fastrpc probe handle %pK pid 0x%x\n",
- __func__, frpc_node, handle);
- return frpc_node;
- }
- static void eva_fastrpc_driver_unregister(uint32_t handle, bool force_exit);
- static int cvp_fastrpc_probe(struct fastrpc_device *rpc_dev)
- {
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- dprintk(CVP_DSP, "%s fastrpc probe handle 0x%x\n",
- __func__, rpc_dev->handle);
- frpc_node = cvp_get_fastrpc_node_with_handle(rpc_dev->handle);
- if (frpc_node) {
- frpc_node->cvp_fastrpc_device = rpc_dev;
- complete(&frpc_node->fastrpc_probe_completion);
- cvp_put_fastrpc_node(frpc_node);
- }
- return 0;
- }
- static int cvp_fastrpc_callback(struct fastrpc_device *rpc_dev,
- enum fastrpc_driver_status fastrpc_proc_num)
- {
- dprintk(CVP_DSP, "%s handle 0x%x, proc %d\n", __func__,
- rpc_dev->handle, fastrpc_proc_num);
- /* fastrpc drive down when process gone
- * any handling can happen here, such as
- * eva_fastrpc_driver_unregister(rpc_dev->handle, true);
- */
- eva_fastrpc_driver_unregister(rpc_dev->handle, true);
- return 0;
- }
- static struct fastrpc_driver cvp_fastrpc_client = {
- .probe = cvp_fastrpc_probe,
- .callback = cvp_fastrpc_callback,
- };
- static int eva_fastrpc_dev_map_dma(struct fastrpc_device *frpc_device,
- struct cvp_internal_buf *buf,
- uint32_t dsp_remote_map,
- uint64_t *v_dsp_addr)
- {
- #ifdef CVP_FASTRPC_ENABLED
- struct fastrpc_dev_map_dma frpc_map_buf = {0};
- int rc = 0;
- if (dsp_remote_map == 1) {
- frpc_map_buf.buf = buf->smem->dma_buf;
- frpc_map_buf.size = buf->smem->size;
- frpc_map_buf.attrs = 0;
- dprintk(CVP_DSP,
- "%s frpc_map_buf size %d, dma_buf %pK, map %pK, 0x%x\n",
- __func__, frpc_map_buf.size, frpc_map_buf.buf,
- &frpc_map_buf, (unsigned long)&frpc_map_buf);
- rc = __fastrpc_driver_invoke(frpc_device, FASTRPC_DEV_MAP_DMA,
- (unsigned long)(&frpc_map_buf));
- if (rc) {
- dprintk(CVP_ERR,
- "%s Failed to map buffer 0x%x\n", __func__, rc);
- return rc;
- }
- buf->fd = (s32)frpc_map_buf.v_dsp_addr;
- *v_dsp_addr = frpc_map_buf.v_dsp_addr;
- atomic_inc(&nr_maps);
- } else {
- dprintk(CVP_DSP, "%s Buffer not mapped to dsp\n", __func__);
- buf->fd = 0;
- }
- return rc;
- #else
- return -ENODEV;
- #endif /* End of CVP_FASTRPC_ENABLED */
- }
- static int eva_fastrpc_dev_unmap_dma(struct fastrpc_device *frpc_device,
- struct cvp_internal_buf *buf)
- {
- #ifdef CVP_FASTRPC_ENABLED
- struct fastrpc_dev_unmap_dma frpc_unmap_buf = {0};
- int rc = 0;
- /* Only if buffer is mapped to dsp */
- if (buf->fd != 0) {
- frpc_unmap_buf.buf = buf->smem->dma_buf;
- rc = __fastrpc_driver_invoke(frpc_device, FASTRPC_DEV_UNMAP_DMA,
- (unsigned long)(&frpc_unmap_buf));
- if (rc) {
- dprintk_rl(CVP_ERR, "%s Failed to unmap buffer %d\n",
- __func__, rc);
- return rc;
- }
- if (atomic_read(&nr_maps) > 0)
- atomic_dec(&nr_maps);
- } else {
- dprintk(CVP_DSP, "%s buffer not mapped to dsp\n", __func__);
- }
- return rc;
- #else
- return -ENODEV;
- #endif /* End of CVP_FASTRPC_ENABLED */
- }
- static int eva_fastrpc_dev_get_pid(struct fastrpc_device *frpc_device, int *pid)
- {
- #ifdef CVP_FASTRPC_ENABLED
- struct fastrpc_dev_get_hlos_pid get_pid = {0};
- int rc = 0;
- rc = __fastrpc_driver_invoke(frpc_device, FASTRPC_DEV_GET_HLOS_PID,
- (unsigned long)(&get_pid));
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to get PID %x\n",
- __func__, rc);
- return rc;
- }
- *pid = get_pid.hlos_pid;
- return rc;
- #else
- return -ENODEV;
- #endif /* End of CVP_FASTRPC_ENABLED */
- }
- static void eva_fastrpc_driver_add_sess(
- struct cvp_dsp_fastrpc_driver_entry *frpc,
- struct msm_cvp_inst *inst)
- {
- mutex_lock(&frpc->dsp_sessions.lock);
- if (inst)
- list_add_tail(&inst->dsp_list, &frpc->dsp_sessions.list);
- else
- dprintk(CVP_ERR, "%s incorrect input %pK\n", __func__, inst);
- frpc->session_cnt++;
- mutex_unlock(&frpc->dsp_sessions.lock);
- dprintk(CVP_DSP, "add dsp sess %pK fastrpc_driver %pK\n", inst, frpc);
- }
- int cvp_dsp_fastrpc_unmap(uint32_t handle, struct cvp_internal_buf *buf)
- {
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct fastrpc_device *frpc_device = NULL;
- int rc = 0;
- frpc_node = cvp_get_fastrpc_node_with_handle(handle);
- if (!frpc_node) {
- dprintk(CVP_ERR, "%s no frpc node for dsp handle %d\n",
- __func__, handle);
- return -EINVAL;
- }
- frpc_device = frpc_node->cvp_fastrpc_device;
- rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
- if (rc)
- dprintk(CVP_ERR, "%s Fail to unmap buffer 0x%x\n",
- __func__, rc);
- cvp_put_fastrpc_node(frpc_node);
- return rc;
- }
- int cvp_dsp_del_sess(uint32_t handle, struct msm_cvp_inst *inst)
- {
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct list_head *ptr = NULL, *next = NULL;
- struct msm_cvp_inst *sess;
- bool found = false;
- frpc_node = cvp_get_fastrpc_node_with_handle(handle);
- if (!frpc_node) {
- dprintk(CVP_ERR, "%s no frpc node for dsp handle %d\n",
- __func__, handle);
- return -EINVAL;
- }
- mutex_lock(&frpc_node->dsp_sessions.lock);
- list_for_each_safe(ptr, next, &frpc_node->dsp_sessions.list) {
- if (!ptr)
- break;
- sess = list_entry(ptr, struct msm_cvp_inst, dsp_list);
- if (sess == inst) {
- dprintk(CVP_DSP, "%s Find sess %pK to be deleted\n",
- __func__, inst);
- found = true;
- break;
- }
- }
- if (found) {
- list_del(&inst->dsp_list);
- frpc_node->session_cnt--;
- }
- mutex_unlock(&frpc_node->dsp_sessions.lock);
- cvp_put_fastrpc_node(frpc_node);
- return 0;
- }
- static int eva_fastrpc_driver_register(uint32_t handle)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- int rc = 0;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- bool skip_deregister = true;
- dprintk(CVP_DSP, "%s -> cvp_get_fastrpc_node_with_handle hdl 0x%x\n",
- __func__, handle);
- frpc_node = cvp_get_fastrpc_node_with_handle(handle);
- if (frpc_node == NULL) {
- dprintk(CVP_DSP, "%s new fastrpc node hdl 0x%x\n",
- __func__, handle);
- frpc_node = kzalloc(sizeof(*frpc_node), GFP_KERNEL);
- if (!frpc_node) {
- dprintk(CVP_DSP, "%s allocate frpc node fail\n",
- __func__);
- return -EINVAL;
- }
- memset(frpc_node, 0, sizeof(*frpc_node));
- /* Setup fastrpc_node */
- frpc_node->handle = handle;
- frpc_node->cvp_fastrpc_driver = cvp_fastrpc_client;
- frpc_node->cvp_fastrpc_driver.handle = handle;
- mutex_lock(&me->driver_name_lock);
- rc = eva_fastrpc_driver_get_name(frpc_node);
- mutex_unlock(&me->driver_name_lock);
- if (rc) {
- dprintk(CVP_ERR, "%s fastrpc get name fail err %d\n",
- __func__, rc);
- goto fail_fastrpc_driver_get_name;
- }
- /* Init completion */
- init_completion(&frpc_node->fastrpc_probe_completion);
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_add_tail(&frpc_node->list, &me->fastrpc_driver_list.list);
- INIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
- mutex_unlock(&me->fastrpc_driver_list.lock);
- dprintk(CVP_DSP, "Add frpc node 0x%x to list\n", frpc_node);
- /* register fastrpc device to this session */
- rc = __fastrpc_driver_register(&frpc_node->cvp_fastrpc_driver);
- if (rc) {
- dprintk(CVP_ERR, "%s fastrpc driver reg fail err %d\n",
- __func__, rc);
- skip_deregister = true;
- goto fail_fastrpc_driver_register;
- }
- /* signal wait reuse dsp timeout setup for now */
- if (!wait_for_completion_timeout(
- &frpc_node->fastrpc_probe_completion,
- msecs_to_jiffies(CVP_DSP_RESPONSE_TIMEOUT))) {
- dprintk(CVP_ERR, "%s fastrpc driver_register timeout %#x\n",
- __func__, frpc_node->handle);
- skip_deregister = false;
- goto fail_fastrpc_driver_register;
- }
- } else {
- dprintk(CVP_DSP, "%s fastrpc probe frpc_node %pK hdl 0x%x\n",
- __func__, frpc_node, handle);
- cvp_put_fastrpc_node(frpc_node);
- }
- return rc;
- fail_fastrpc_driver_register:
- dequeue_frpc_node(frpc_node);
- if (!skip_deregister)
- __fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
- mutex_lock(&me->driver_name_lock);
- eva_fastrpc_driver_release_name(frpc_node);
- mutex_unlock(&me->driver_name_lock);
- fail_fastrpc_driver_get_name:
- kfree(frpc_node);
- return -EINVAL;
- }
- static void eva_fastrpc_driver_unregister(uint32_t handle, bool force_exit)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- dprintk(CVP_DSP, "%s Unregister fastrpc driver hdl %#x hdl %#x, f %d\n",
- __func__, handle, dsp2cpu_cmd->pid, (uint32_t)force_exit);
- if (handle != dsp2cpu_cmd->pid)
- dprintk(CVP_ERR, "Unregister pid != hndl %#x %#x\n",
- handle, dsp2cpu_cmd->pid);
- /* Foundd fastrpc node */
- frpc_node = cvp_get_fastrpc_node_with_handle(handle);
- if (frpc_node == NULL) {
- dprintk(CVP_DSP, "%s fastrpc handle 0x%x unregistered\n",
- __func__, handle);
- return;
- }
- if ((frpc_node->session_cnt == 0) || force_exit) {
- dprintk(CVP_DSP, "%s session cnt %d, force %d\n",
- __func__, frpc_node->session_cnt, (uint32_t)force_exit);
- DEINIT_MSM_CVP_LIST(&frpc_node->dsp_sessions);
- cvp_put_fastrpc_node(frpc_node);
- if (!dequeue_frpc_node(frpc_node))
- /* Don't find the node */
- return;
- __fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
- mutex_lock(&me->driver_name_lock);
- eva_fastrpc_driver_release_name(frpc_node);
- mutex_unlock(&me->driver_name_lock);
- kfree(frpc_node);
- } else {
- cvp_put_fastrpc_node(frpc_node);
- }
- }
- void cvp_dsp_send_debug_mask(void)
- {
- struct cvp_dsp_cmd_msg cmd;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp;
- int rc;
- cmd.type = CPU2DSP_SET_DEBUG_LEVEL;
- cmd.eva_dsp_debug_mask = me->debug_mask;
- dprintk(CVP_DSP,
- "%s: debug mask 0x%x\n",
- __func__, cmd.eva_dsp_debug_mask);
- rc = cvp_dsp_send_cmd_sync(&cmd, sizeof(struct cvp_dsp_cmd_msg), &rsp);
- if (rc)
- dprintk(CVP_ERR,
- "%s: cvp_dsp_send_cmd failed rc = %d\n",
- __func__, rc);
- }
- void cvp_dsp_send_hfi_queue(void)
- {
- struct msm_cvp_core *core;
- struct iris_hfi_device *device;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_rsp_msg rsp = {0};
- uint64_t addr;
- uint32_t size;
- int rc;
- core = cvp_driver->cvp_core;
- if (core && core->device)
- device = core->device->hfi_device_data;
- else
- return;
- if (!device) {
- dprintk(CVP_ERR, "%s: NULL device\n", __func__);
- return;
- }
- dprintk(CVP_DSP, "Entering %s\n", __func__);
- mutex_lock(&device->lock);
- mutex_lock(&me->tx_lock);
- if (!device->dsp_iface_q_table.align_virtual_addr) {
- dprintk(CVP_ERR, "%s: DSP HFI queue released\n", __func__);
- goto exit;
- }
- addr = (uint64_t)device->dsp_iface_q_table.mem_data.dma_handle;
- size = device->dsp_iface_q_table.mem_data.size;
- if (!addr || !size) {
- dprintk(CVP_DSP, "%s: HFI queue is not ready\n", __func__);
- goto exit;
- }
- if (me->state != DSP_PROBED && me->state != DSP_INACTIVE)
- goto exit;
- rc = cvp_hyp_assign_to_dsp(addr, size);
- if (rc) {
- dprintk(CVP_ERR, "%s: cvp_hyp_assign_to_dsp. rc=%d\n",
- __func__, rc);
- goto exit;
- }
- if (me->state == DSP_PROBED) {
- cvp_dsp_init_hfi_queue_hdr(device);
- dprintk(CVP_WARN,
- "%s: Done init of HFI queue headers\n", __func__);
- }
- rc = cvp_dsp_send_cmd_hfi_queue((phys_addr_t *)addr, size, &rsp);
- if (rc) {
- dprintk(CVP_WARN, "%s: Send HFI Queue failed rc = %d\n",
- __func__, rc);
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EUNSUPPORTED) {
- dprintk(CVP_WARN, "%s unsupported cmd %d\n",
- __func__, rsp.type);
- goto exit;
- }
- if (rsp.ret == CPU2DSP_EFATAL || rsp.ret == CPU2DSP_EUNAVAILABLE) {
- dprintk(CVP_ERR, "%s fatal error returned %d %d\n",
- __func__, rsp.dsp_state, rsp.ret);
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- goto exit;
- } else if (rsp.ret == CPU2DSP_EINVALSTATE) {
- dprintk(CVP_ERR, "%s dsp invalid state %d\n",
- __func__, rsp.dsp_state);
- mutex_unlock(&me->tx_lock);
- if (cvp_reinit_dsp()) {
- dprintk(CVP_ERR, "%s reinit dsp fail\n", __func__);
- mutex_unlock(&device->lock);
- return;
- }
- mutex_lock(&me->tx_lock);
- }
- dprintk(CVP_DSP, "%s: dsp initialized\n", __func__);
- me->state = DSP_READY;
- exit:
- mutex_unlock(&me->tx_lock);
- mutex_unlock(&device->lock);
- }
- /* 32 or 64 bit CPU Side Ptr <-> 2 32 bit DSP Pointers. Dirty Fix. */
- static void *get_inst_from_dsp(uint32_t session_cpu_high, uint32_t session_cpu_low)
- {
- struct msm_cvp_core *core;
- struct msm_cvp_inst *sess_inst;
- void *inst;
- if ((session_cpu_high == 0) && (sizeof(void *) == BITPTRSIZE32)) {
- inst = (void *)((uintptr_t)session_cpu_low);
- } else if ((session_cpu_high != 0) && (sizeof(void *) == BITPTRSIZE64)) {
- inst = (void *)((uintptr_t)(((uint64_t)session_cpu_high) << 32
- | session_cpu_low));
- } else {
- dprintk(CVP_ERR,
- "%s Invalid _cpu_high = 0x%x _cpu_low = 0x%x\n",
- __func__, session_cpu_high, session_cpu_low);
- inst = NULL;
- return inst;
- }
- core = cvp_driver->cvp_core;
- if (core) {
- mutex_lock(&core->lock);
- list_for_each_entry(sess_inst, &core->instances, list) {
- if (sess_inst->session_type == MSM_CVP_DSP) {
- if (sess_inst == (struct msm_cvp_inst *)inst) {
- mutex_unlock(&core->lock);
- return inst;
- }
- }
- }
- mutex_unlock(&core->lock);
- inst = NULL;
- } else {
- return NULL;
- }
- return inst;
- }
- static void print_power(const struct eva_power_req *pwr_req)
- {
- if (pwr_req) {
- dprintk(CVP_DSP, "Clock: Fdu %d Ica %d Od %d Mpu %d Fw %d",
- pwr_req->clock_fdu, pwr_req->clock_ica,
- pwr_req->clock_od, pwr_req->clock_mpu,
- pwr_req->clock_fw);
- dprintk(CVP_DSP, "OpClock: Fdu %d Ica %d Od %d Mpu %d Fw %d",
- pwr_req->op_clock_fdu, pwr_req->op_clock_ica,
- pwr_req->op_clock_od, pwr_req->op_clock_mpu,
- pwr_req->op_clock_fw);
- dprintk(CVP_DSP, "Actual Bw: Ddr %d, SysCache %d",
- pwr_req->bw_ddr, pwr_req->bw_sys_cache);
- dprintk(CVP_DSP, "OpBw: Ddr %d, SysCache %d",
- pwr_req->op_bw_ddr, pwr_req->op_bw_sys_cache);
- }
- }
- void __dsp_cvp_sess_create(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst = NULL;
- uint64_t inst_handle = 0;
- uint32_t pid;
- int rc = 0;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct pid *pid_s = NULL;
- struct task_struct *task = NULL;
- struct cvp_hfi_device *hdev;
- struct fastrpc_device *frpc_device;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess Type %d Mask %d Prio %d Sec %d hdl 0x%x\n",
- __func__, dsp2cpu_cmd->session_type,
- dsp2cpu_cmd->kernel_mask,
- dsp2cpu_cmd->session_prio,
- dsp2cpu_cmd->is_secure,
- dsp2cpu_cmd->pid);
- rc = eva_fastrpc_driver_register(dsp2cpu_cmd->pid);
- if (rc) {
- dprintk(CVP_ERR, "%s Register fastrpc driver fail\n", __func__);
- cmd->ret = -1;
- return;
- }
- frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
- if (!frpc_node) {
- dprintk(CVP_WARN, "%s cannot get fastrpc node from pid %x\n",
- __func__, dsp2cpu_cmd->pid);
- goto fail_lookup;
- }
- if (!frpc_node->cvp_fastrpc_device) {
- dprintk(CVP_WARN, "%s invalid fastrpc device from pid %x\n",
- __func__, dsp2cpu_cmd->pid);
- goto fail_pid;
- }
- frpc_device = frpc_node->cvp_fastrpc_device;
- rc = eva_fastrpc_dev_get_pid(frpc_device, &pid);
- if (rc) {
- dprintk(CVP_ERR,
- "%s Failed to map buffer 0x%x\n", __func__, rc);
- goto fail_pid;
- }
- pid_s = find_get_pid(pid);
- if (pid_s == NULL) {
- dprintk(CVP_WARN, "%s incorrect pid %x\n", __func__, pid);
- goto fail_pid;
- }
- dprintk(CVP_DSP, "%s get pid_s 0x%x from hdl 0x%x\n", __func__,
- pid_s, dsp2cpu_cmd->pid);
- task = get_pid_task(pid_s, PIDTYPE_TGID);
- if (!task) {
- dprintk(CVP_WARN, "%s task doesn't exist\n", __func__);
- goto fail_pid;
- }
- inst = msm_cvp_open(MSM_CVP_DSP, task);
- if (!inst) {
- dprintk(CVP_ERR, "%s Failed create instance\n", __func__);
- goto fail_msm_cvp_open;
- }
- inst->dsp_handle = dsp2cpu_cmd->pid;
- inst->prop.kernel_mask = dsp2cpu_cmd->kernel_mask;
- inst->prop.type = dsp2cpu_cmd->session_type;
- inst->prop.priority = dsp2cpu_cmd->session_prio;
- inst->prop.is_secure = dsp2cpu_cmd->is_secure;
- inst->prop.dsp_mask = dsp2cpu_cmd->dsp_access_mask;
- eva_fastrpc_driver_add_sess(frpc_node, inst);
- rc = msm_cvp_session_create(inst);
- if (rc) {
- dprintk(CVP_ERR, "Warning: send Session Create failed\n");
- goto fail_get_session_info;
- } else {
- dprintk(CVP_DSP, "%s DSP Session Create done\n", __func__);
- }
- /* Get session id */
- rc = msm_cvp_get_session_info(inst, &cmd->session_id);
- if (rc) {
- dprintk(CVP_ERR, "Warning: get session index failed %d\n", rc);
- goto fail_get_session_info;
- }
- inst_handle = (uint64_t)inst;
- cmd->session_cpu_high = (uint32_t)((inst_handle & HIGH32) >> 32);
- cmd->session_cpu_low = (uint32_t)(inst_handle & LOW32);
- cvp_put_fastrpc_node(frpc_node);
- inst->task = task;
- dprintk(CVP_DSP,
- "%s CREATE_SESS id 0x%x, cpu_low 0x%x, cpu_high 0x%x\n",
- __func__, cmd->session_id, cmd->session_cpu_low,
- cmd->session_cpu_high);
- spin_lock(&inst->core->resources.pm_qos.lock);
- inst->core->resources.pm_qos.off_vote_cnt++;
- spin_unlock(&inst->core->resources.pm_qos.lock);
- hdev = inst->core->device;
- call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
- return;
- fail_get_session_info:
- msm_cvp_close(inst);
- fail_msm_cvp_open:
- put_task_struct(task);
- fail_pid:
- cvp_put_fastrpc_node(frpc_node);
- fail_lookup:
- /* unregister fastrpc driver */
- eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
- cmd->ret = -1;
- }
- void __dsp_cvp_sess_delete(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct task_struct *task = NULL;
- struct cvp_hfi_device *hdev;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x low 0x%x high 0x%x, pid 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
- if (!frpc_node) {
- dprintk(CVP_ERR, "%s pid 0x%x not registered with fastrpc\n",
- __func__, dsp2cpu_cmd->pid);
- cmd->ret = -1;
- return;
- }
- cvp_put_fastrpc_node(frpc_node);
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- if (!inst || !is_cvp_inst_valid(inst)) {
- dprintk(CVP_ERR, "%s incorrect session ID %llx\n", __func__, inst);
- cmd->ret = -1;
- goto dsp_fail_delete;
- }
- task = inst->task;
- spin_lock(&inst->core->resources.pm_qos.lock);
- if (inst->core->resources.pm_qos.off_vote_cnt > 0)
- inst->core->resources.pm_qos.off_vote_cnt--;
- else
- dprintk(CVP_WARN, "%s Unexpected pm_qos off vote %d\n",
- __func__,
- inst->core->resources.pm_qos.off_vote_cnt);
- spin_unlock(&inst->core->resources.pm_qos.lock);
- hdev = inst->core->device;
- call_hfi_op(hdev, pm_qos_update, hdev->hfi_device_data);
- rc = msm_cvp_close(inst);
- if (rc) {
- dprintk(CVP_ERR, "Warning: Failed to close cvp instance\n");
- cmd->ret = -1;
- goto dsp_fail_delete;
- }
- /* unregister fastrpc driver */
- eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
- if (task)
- put_task_struct(task);
- dprintk(CVP_DSP, "%s DSP2CPU_DETELE_SESSION Done, nr_maps %d\n",
- __func__, atomic_read(&nr_maps));
- dsp_fail_delete:
- return;
- }
- void __dsp_cvp_power_req(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high);
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- if (!inst) {
- cmd->ret = -1;
- goto dsp_fail_power_req;
- }
- print_power(&dsp2cpu_cmd->power_req);
- inst->prop.cycles[HFI_HW_FDU] = dsp2cpu_cmd->power_req.clock_fdu;
- inst->prop.cycles[HFI_HW_ICA] = dsp2cpu_cmd->power_req.clock_ica;
- inst->prop.cycles[HFI_HW_OD] = dsp2cpu_cmd->power_req.clock_od;
- inst->prop.cycles[HFI_HW_MPU] = dsp2cpu_cmd->power_req.clock_mpu;
- inst->prop.fw_cycles = dsp2cpu_cmd->power_req.clock_fw;
- inst->prop.ddr_bw = dsp2cpu_cmd->power_req.bw_ddr;
- inst->prop.ddr_cache = dsp2cpu_cmd->power_req.bw_sys_cache;
- inst->prop.op_cycles[HFI_HW_FDU] = dsp2cpu_cmd->power_req.op_clock_fdu;
- inst->prop.op_cycles[HFI_HW_ICA] = dsp2cpu_cmd->power_req.op_clock_ica;
- inst->prop.op_cycles[HFI_HW_OD] = dsp2cpu_cmd->power_req.op_clock_od;
- inst->prop.op_cycles[HFI_HW_MPU] = dsp2cpu_cmd->power_req.op_clock_mpu;
- inst->prop.fw_op_cycles = dsp2cpu_cmd->power_req.op_clock_fw;
- inst->prop.ddr_op_bw = dsp2cpu_cmd->power_req.op_bw_ddr;
- inst->prop.ddr_op_cache = dsp2cpu_cmd->power_req.op_bw_sys_cache;
- rc = msm_cvp_update_power(inst);
- if (rc) {
- /*
- *May need to define more error types
- * Check UMD implementation
- */
- dprintk(CVP_ERR, "%s Failed update power\n", __func__);
- cmd->ret = -1;
- goto dsp_fail_power_req;
- }
- dprintk(CVP_DSP, "%s DSP2CPU_POWER_REQUEST Done\n", __func__);
- dsp_fail_power_req:
- return;
- }
- void __dsp_cvp_buf_register(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- struct eva_kmd_arg *kmd;
- struct eva_kmd_buffer *kmd_buf;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- kmd = kzalloc(sizeof(*kmd), GFP_KERNEL);
- if (!kmd) {
- dprintk(CVP_ERR, "%s kzalloc failure\n", __func__);
- cmd->ret = -1;
- return;
- }
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- kmd->type = EVA_KMD_REGISTER_BUFFER;
- kmd_buf = (struct eva_kmd_buffer *)&(kmd->data.regbuf);
- kmd_buf->type = EVA_KMD_BUFTYPE_INPUT;
- kmd_buf->index = dsp2cpu_cmd->sbuf.index;
- kmd_buf->fd = dsp2cpu_cmd->sbuf.fd;
- kmd_buf->size = dsp2cpu_cmd->sbuf.size;
- kmd_buf->offset = dsp2cpu_cmd->sbuf.offset;
- kmd_buf->pixelformat = 0;
- kmd_buf->flags = EVA_KMD_FLAG_UNSECURE;
- rc = msm_cvp_register_buffer(inst, kmd_buf);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to register buffer\n", __func__);
- cmd->ret = -1;
- goto dsp_fail_buf_reg;
- }
- dprintk(CVP_DSP, "%s register buffer done\n", __func__);
- cmd->sbuf.iova = kmd_buf->reserved[0];
- cmd->sbuf.size = kmd_buf->size;
- cmd->sbuf.fd = kmd_buf->fd;
- cmd->sbuf.index = kmd_buf->index;
- cmd->sbuf.offset = kmd_buf->offset;
- dprintk(CVP_DSP, "%s: fd %d, iova 0x%x\n", __func__,
- cmd->sbuf.fd, cmd->sbuf.iova);
- dsp_fail_buf_reg:
- kfree(kmd);
- }
- void __dsp_cvp_buf_deregister(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- struct eva_kmd_arg *kmd;
- struct eva_kmd_buffer *kmd_buf;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s : sess id 0x%x, low 0x%x, high 0x%x, hdl 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- kmd = kzalloc(sizeof(*kmd), GFP_KERNEL);
- if (!kmd) {
- dprintk(CVP_ERR, "%s kzalloc failure\n", __func__);
- cmd->ret = -1;
- return;
- }
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- kmd->type = EVA_KMD_UNREGISTER_BUFFER;
- kmd_buf = (struct eva_kmd_buffer *)&(kmd->data.regbuf);
- kmd_buf->type = EVA_KMD_UNREGISTER_BUFFER;
- kmd_buf->type = EVA_KMD_BUFTYPE_INPUT;
- kmd_buf->index = dsp2cpu_cmd->sbuf.index;
- kmd_buf->fd = dsp2cpu_cmd->sbuf.fd;
- kmd_buf->size = dsp2cpu_cmd->sbuf.size;
- kmd_buf->offset = dsp2cpu_cmd->sbuf.offset;
- kmd_buf->pixelformat = 0;
- kmd_buf->flags = EVA_KMD_FLAG_UNSECURE;
- rc = msm_cvp_unregister_buffer(inst, kmd_buf);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to deregister buffer\n", __func__);
- cmd->ret = -1;
- goto fail_dsp_buf_dereg;
- }
- dprintk(CVP_DSP, "%s deregister buffer done\n", __func__);
- fail_dsp_buf_dereg:
- kfree(kmd);
- }
- void __dsp_cvp_mem_alloc(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_internal_buf *buf = NULL;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- uint64_t v_dsp_addr = 0;
- struct fastrpc_device *frpc_device = NULL;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x, hdl 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
- if (!frpc_node) {
- dprintk(CVP_ERR, "%s Failed to find fastrpc node 0x%x\n",
- __func__, dsp2cpu_cmd->pid);
- goto fail_fastrpc_node;
- }
- frpc_device = frpc_node->cvp_fastrpc_device;
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- buf = cvp_kmem_cache_zalloc(&cvp_driver->buf_cache, GFP_KERNEL);
- if (!buf)
- goto fail_kzalloc_buf;
- rc = cvp_allocate_dsp_bufs(inst, buf,
- dsp2cpu_cmd->sbuf.size,
- dsp2cpu_cmd->sbuf.type);
- if (rc)
- goto fail_allocate_dsp_buf;
- rc = eva_fastrpc_dev_map_dma(frpc_device, buf,
- dsp2cpu_cmd->sbuf.dsp_remote_map,
- &v_dsp_addr);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to map buffer 0x%x\n", __func__,
- rc);
- goto fail_fastrpc_dev_map_dma;
- }
- mutex_lock(&inst->cvpdspbufs.lock);
- list_add_tail(&buf->list, &inst->cvpdspbufs.list);
- mutex_unlock(&inst->cvpdspbufs.lock);
- dprintk(CVP_DSP, "%s allocate buffer done, addr 0x%llx\n",
- __func__, v_dsp_addr);
- cmd->sbuf.size = buf->smem->size;
- cmd->sbuf.fd = buf->fd;
- cmd->sbuf.offset = 0;
- cmd->sbuf.iova = buf->smem->device_addr;
- cmd->sbuf.v_dsp_addr = v_dsp_addr;
- dprintk(CVP_DSP, "%s: size %d, iova 0x%x, v_dsp_addr 0x%llx\n",
- __func__, cmd->sbuf.size, cmd->sbuf.iova,
- cmd->sbuf.v_dsp_addr);
- cvp_put_fastrpc_node(frpc_node);
- return;
- fail_fastrpc_dev_map_dma:
- cvp_release_dsp_buffers(inst, buf);
- fail_allocate_dsp_buf:
- cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
- fail_kzalloc_buf:
- fail_fastrpc_node:
- cmd->ret = -1;
- cvp_put_fastrpc_node(frpc_node);
- return;
- }
- void __dsp_cvp_mem_free(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_internal_buf *buf = NULL;
- struct list_head *ptr = NULL, *next = NULL;
- struct msm_cvp_list *buf_list = NULL;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- struct fastrpc_device *frpc_device = NULL;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x, hnl 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- if (!inst) {
- dprintk(CVP_ERR, "%s Failed to get inst\n",
- __func__);
- cmd->ret = -1;
- return;
- }
- frpc_node = cvp_get_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
- if (!frpc_node) {
- dprintk(CVP_ERR, "%s Failed to find fastrpc node 0x%x\n",
- __func__, dsp2cpu_cmd->pid);
- cmd->ret = -1;
- return;
- }
- frpc_device = frpc_node->cvp_fastrpc_device;
- buf_list = &inst->cvpdspbufs;
- mutex_lock(&buf_list->lock);
- list_for_each_safe(ptr, next, &buf_list->list) {
- if (!ptr)
- break;
- buf = list_entry(ptr, struct cvp_internal_buf, list);
- if (!buf->smem) {
- dprintk(CVP_DSP, "Empyt smem\n");
- continue;
- }
- /* Verify with device addr */
- if (buf->smem->device_addr == dsp2cpu_cmd->sbuf.iova) {
- dprintk(CVP_DSP, "%s find device addr 0x%x\n",
- __func__, buf->smem->device_addr);
- dprintk(CVP_DSP, "fd in list 0x%x, fd from dsp 0x%x\n",
- buf->fd, dsp2cpu_cmd->sbuf.fd);
- rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
- if (rc) {
- cmd->ret = -1;
- goto fail_fastrpc_dev_unmap_dma;
- }
- rc = cvp_release_dsp_buffers(inst, buf);
- if (rc) {
- dprintk(CVP_ERR,
- "%s Failed to free buffer 0x%x\n",
- __func__, rc);
- cmd->ret = -1;
- goto fail_release_buf;
- }
- list_del(&buf->list);
- cvp_kmem_cache_free(&cvp_driver->buf_cache, buf);
- break;
- }
- }
- fail_release_buf:
- fail_fastrpc_dev_unmap_dma:
- mutex_unlock(&buf_list->lock);
- cvp_put_fastrpc_node(frpc_node);
- }
- void __dsp_cvp_sess_start(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- rc = msm_cvp_session_start(inst, (struct eva_kmd_arg *)NULL);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to start session %llx\n", __func__, inst);
- cmd->ret = -1;
- return;
- }
- dprintk(CVP_DSP, "%s session started\n", __func__);
- }
- void __dsp_cvp_sess_stop(struct cvp_dsp_cmd_msg *cmd)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct msm_cvp_inst *inst;
- int rc;
- struct cvp_dsp2cpu_cmd *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess id 0x%x, low 0x%x, high 0x%x, pid 0x%x\n",
- __func__, dsp2cpu_cmd->session_id,
- dsp2cpu_cmd->session_cpu_low,
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->pid);
- inst = (struct msm_cvp_inst *)get_inst_from_dsp(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- rc = msm_cvp_session_stop(inst, (struct eva_kmd_arg *)NULL);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to stop session\n", __func__);
- cmd->ret = -1;
- return;
- }
- dprintk(CVP_DSP, "%s session stoppd\n", __func__);
- }
- static int cvp_dsp_thread(void *data)
- {
- int rc = 0, old_state;
- struct cvp_dsp_apps *me = &gfa_cv;
- struct cvp_dsp_cmd_msg cmd;
- struct cvp_hfi_device *hdev;
- struct msm_cvp_core *core;
- core = cvp_driver->cvp_core;
- if (!core) {
- dprintk(CVP_ERR, "%s: Failed to find core\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- hdev = (struct cvp_hfi_device *)core->device;
- if (!hdev) {
- dprintk(CVP_ERR, "%s Invalid device handle\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- wait_dsp:
- rc = wait_for_completion_interruptible(
- &me->completions[CPU2DSP_MAX_CMD]);
- if (me->state == DSP_INVALID)
- goto exit;
- if (me->state == DSP_UNINIT)
- goto wait_dsp;
- if (me->state == DSP_PROBED) {
- cvp_dsp_send_hfi_queue();
- goto wait_dsp;
- }
- cmd.type = me->pending_dsp2cpu_cmd.type;
- if (rc == -ERESTARTSYS) {
- dprintk(CVP_WARN, "%s received interrupt signal\n", __func__);
- } else {
- mutex_lock(&me->rx_lock);
- if (me->state == DSP_UNINIT) {
- /* DSP SSR may have happened */
- mutex_unlock(&me->rx_lock);
- goto wait_dsp;
- }
- switch (me->pending_dsp2cpu_cmd.type) {
- case DSP2CPU_POWERON:
- {
- if (me->state == DSP_READY) {
- cmd.ret = 0;
- break;
- }
- mutex_lock(&me->tx_lock);
- old_state = me->state;
- me->state = DSP_READY;
- rc = call_hfi_op(hdev, resume, hdev->hfi_device_data);
- if (rc) {
- dprintk(CVP_WARN, "%s Failed to resume cvp\n",
- __func__);
- me->state = old_state;
- mutex_unlock(&me->tx_lock);
- cmd.ret = 1;
- break;
- }
- mutex_unlock(&me->tx_lock);
- cmd.ret = 0;
- break;
- }
- case DSP2CPU_POWEROFF:
- {
- me->state = DSP_SUSPEND;
- cmd.ret = 0;
- break;
- }
- case DSP2CPU_CREATE_SESSION:
- {
- __dsp_cvp_sess_create(&cmd);
- break;
- }
- case DSP2CPU_DETELE_SESSION:
- {
- __dsp_cvp_sess_delete(&cmd);
- break;
- }
- case DSP2CPU_POWER_REQUEST:
- {
- __dsp_cvp_power_req(&cmd);
- break;
- }
- case DSP2CPU_REGISTER_BUFFER:
- {
- __dsp_cvp_buf_register(&cmd);
- break;
- }
- case DSP2CPU_DEREGISTER_BUFFER:
- {
- __dsp_cvp_buf_deregister(&cmd);
- break;
- }
- case DSP2CPU_MEM_ALLOC:
- {
- __dsp_cvp_mem_alloc(&cmd);
- break;
- }
- case DSP2CPU_MEM_FREE:
- {
- __dsp_cvp_mem_free(&cmd);
- break;
- }
- case DSP2CPU_START_SESSION:
- {
- __dsp_cvp_sess_start(&cmd);
- break;
- }
- case DSP2CPU_STOP_SESSION:
- {
- __dsp_cvp_sess_stop(&cmd);
- break;
- }
- default:
- dprintk(CVP_ERR, "unrecognaized dsp cmds: %d\n",
- me->pending_dsp2cpu_cmd.type);
- break;
- }
- me->pending_dsp2cpu_cmd.type = CVP_INVALID_RPMSG_TYPE;
- mutex_unlock(&me->rx_lock);
- }
- /* Responds to DSP */
- rc = cvp_dsp_send_cmd(&cmd, sizeof(struct cvp_dsp_cmd_msg));
- if (rc)
- dprintk(CVP_ERR,
- "%s: cvp_dsp_send_cmd failed rc = %d cmd type=%d\n",
- __func__, rc, cmd.type);
- goto wait_dsp;
- exit:
- dprintk(CVP_DBG, "dsp thread exit\n");
- return rc;
- }
- int cvp_dsp_device_init(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- char tname[16];
- int rc;
- int i;
- char name[CVP_FASTRPC_DRIVER_NAME_SIZE] = "qcom,fastcv0\0";
- add_va_node_to_list(CVP_DBG_DUMP, &gfa_cv, sizeof(struct cvp_dsp_apps),
- "cvp_dsp_apps-gfa_cv", false);
- mutex_init(&me->tx_lock);
- mutex_init(&me->rx_lock);
- me->state = DSP_INVALID;
- me->hyp_assigned = false;
- for (i = 0; i <= CPU2DSP_MAX_CMD; i++)
- init_completion(&me->completions[i]);
- me->pending_dsp2cpu_cmd.type = CVP_INVALID_RPMSG_TYPE;
- me->pending_dsp2cpu_rsp.type = CVP_INVALID_RPMSG_TYPE;
- INIT_MSM_CVP_LIST(&me->fastrpc_driver_list);
- mutex_init(&me->driver_name_lock);
- for (i = 0; i < MAX_FASTRPC_DRIVER_NUM; i++) {
- me->cvp_fastrpc_name[i].status = DRIVER_NAME_AVAILABLE;
- snprintf(me->cvp_fastrpc_name[i].name, sizeof(name), name);
- name[11]++;
- }
- rc = register_rpmsg_driver(&cvp_dsp_rpmsg_client);
- if (rc) {
- dprintk(CVP_ERR,
- "%s : register_rpmsg_driver failed rc = %d\n",
- __func__, rc);
- goto register_bail;
- }
- snprintf(tname, sizeof(tname), "cvp-dsp-thread");
- me->state = DSP_UNINIT;
- me->dsp_thread = kthread_run(cvp_dsp_thread, me, tname);
- if (!me->dsp_thread) {
- dprintk(CVP_ERR, "%s create %s fail", __func__, tname);
- rc = -ECHILD;
- me->state = DSP_INVALID;
- goto register_bail;
- }
- return 0;
- register_bail:
- return rc;
- }
- void cvp_dsp_device_exit(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- int i;
- mutex_lock(&me->tx_lock);
- me->state = DSP_INVALID;
- mutex_unlock(&me->tx_lock);
- DEINIT_MSM_CVP_LIST(&me->fastrpc_driver_list);
- for (i = 0; i <= CPU2DSP_MAX_CMD; i++)
- complete_all(&me->completions[i]);
- mutex_destroy(&me->tx_lock);
- mutex_destroy(&me->rx_lock);
- mutex_destroy(&me->driver_name_lock);
- unregister_rpmsg_driver(&cvp_dsp_rpmsg_client);
- }
|