123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
- */
- #include <linux/module.h>
- #include <linux/rpmsg.h>
- #include <linux/of_platform.h>
- #include <linux/of_fdt.h>
- #include <soc/qcom/secure_buffer.h>
- #include "msm_cvp_core.h"
- #include "msm_cvp.h"
- #include "cvp_hfi.h"
- struct cvp_dsp_apps gfa_cv;
- static int hlosVM[HLOS_VM_NUM] = {VMID_HLOS};
- static int dspVM[DSP_VM_NUM] = {VMID_HLOS, VMID_CDSP_Q6};
- static int dspVMperm[DSP_VM_NUM] = { PERM_READ | PERM_WRITE | PERM_EXEC,
- PERM_READ | PERM_WRITE | PERM_EXEC };
- static int hlosVMperm[HLOS_VM_NUM] = { PERM_READ | PERM_WRITE | PERM_EXEC };
- static int cvp_reinit_dsp(void);
- 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 = 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;
- if (!me->hyp_assigned) {
- rc = hyp_assign_phys(addr, size, hlosVM, HLOS_VM_NUM, dspVM,
- dspVMperm, 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;
- if (me->hyp_assigned) {
- rc = hyp_assign_phys(me->addr, me->size, dspVM, DSP_VM_NUM,
- hlosVM, hlosVMperm, 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->lock);
- me->chan = rpdev;
- me->state = DSP_PROBED;
- complete(&me->completions[CPU2DSP_MAX_CMD]);
- mutex_unlock(&me->lock);
- return ret;
- }
- static void cvp_dsp_rpmsg_remove(struct rpmsg_device *rpdev)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- dprintk(CVP_WARN, "%s: CDSP SSR triggered\n", __func__);
- mutex_lock(&me->lock);
- cvp_hyp_assign_from_dsp();
- me->chan = NULL;
- me->state = DSP_UNINIT;
- mutex_unlock(&me->lock);
- /* kernel driver needs clean all dsp sessions */
- }
- 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_msg)) {
- 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_msg));
- goto exit;
- }
- memcpy(&me->pending_dsp2cpu_cmd, rsp,
- sizeof(struct cvp_dsp2cpu_cmd_msg));
- 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;
- }
- int cvp_dsp_suspend(uint32_t session_flag)
- {
- 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;
- cmd.type = CPU2DSP_SUSPEND;
- mutex_lock(&me->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) {
- if (!retried) {
- mutex_unlock(&me->lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->lock);
- if (rc)
- goto fatal_exit;
- else
- goto retry;
- } else {
- goto fatal_exit;
- }
- }
- me->state = DSP_SUSPEND;
- goto exit;
- fatal_exit:
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- rc = -ENOTSUPP;
- exit:
- mutex_unlock(&me->lock);
- return rc;
- }
- int cvp_dsp_resume(uint32_t session_flag)
- {
- 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)
- goto exit;
- me->state = DSP_READY;
- exit:
- return rc;
- }
- int cvp_dsp_shutdown(uint32_t session_flag)
- {
- 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->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->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->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->lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->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->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->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->lock);
- retried = true;
- rc = cvp_reinit_dsp();
- mutex_lock(&me->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->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;
- uint32_t flag = 0;
- 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 = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
- 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(flag);
- if (rc)
- return rc;
- /* Resend HFI queue */
- mutex_lock(&me->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->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->lock);
- me->state = DSP_INVALID;
- cvp_hyp_assign_from_dsp();
- mutex_unlock(&me->lock);
- }
- return rc;
- }
- #ifdef FASTRPC_DRIVER_AVAILABLE
- static struct cvp_dsp_fastrpc_driver_entry *cvp_find_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;
- 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 (handle == frpc_node->handle) {
- dprintk(CVP_DSP, "Find frpc_node with handle 0x%x\n",
- handle);
- break;
- }
- }
- mutex_unlock(&me->fastrpc_driver_list.lock);
- return frpc_node;
- }
- static void eva_fastrpc_driver_unregister(struct msm_cvp_inst *inst,
- 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_find_fastrpc_node_with_handle(rpc_dev->handle);
- if (frpc_node) {
- frpc_node->cvp_fastrpc_device = rpc_dev;
- // static structure with signal and pid
- complete(&frpc_node->fastrpc_probe_completion);
- }
- 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);
- */
- return 0;
- }
- static struct fastrpc_driver cvp_fastrpc_client = {
- .probe = cvp_fastrpc_probe,
- .callback = cvp_fastrpc_callback,
- .driver = {
- .name = "qcom,fastcv",
- },
- };
- 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)
- {
- 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;
- } else {
- dprintk(CVP_DSP, "%s Buffer not mapped to dsp\n", __func__);
- buf->fd = 0;
- }
- return rc;
- }
- static int eva_fastrpc_dev_unmap_dma(struct fastrpc_device *frpc_device,
- struct cvp_internal_buf *buf)
- {
- 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(CVP_ERR, "%s Failed to unmap buffer 0x%x\n",
- __func__, rc);
- return rc;
- }
- } else {
- dprintk(CVP_DSP, "%s buffer not mapped to dsp\n", __func__);
- }
- return rc;
- }
- static int eva_fastrpc_driver_register(uint32_t handle)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- int rc = 0;
- //struct cvp_dsp2cpu_cmd_msg *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- frpc_node = cvp_find_fastrpc_node_with_handle(handle);
- if (frpc_node == NULL) {
- 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));
- /* Init completion */
- init_completion(&frpc_node->fastrpc_probe_completion);
- mutex_lock(&me->fastrpc_driver_list.lock);
- dprintk(CVP_DSP, "Add frpc node 0x%x to list\n", frpc_node);
- list_add_tail(&frpc_node->list, &me->fastrpc_driver_list.list);
- mutex_unlock(&me->fastrpc_driver_list.lock);
- /* register fastrpc device to this session */
- frpc_node->handle = handle;
- frpc_node->cvp_fastrpc_driver = cvp_fastrpc_client;
- frpc_node->cvp_fastrpc_driver.handle = handle;
- rc = fastrpc_driver_register(&frpc_node->cvp_fastrpc_driver);
- if (rc) {
- dprintk(CVP_ERR, "%s fastrpc driver reg fail err %d\n",
- __func__, rc);
- 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\n",
- __func__);
- goto fail_fastrpc_driver_timeout;
- }
- /* initialize dspbuf list */
- INIT_MSM_CVP_LIST(&frpc_node->dspbufs);
- }
- frpc_node->session_cnt++;
- return rc;
- fail_fastrpc_driver_timeout:
- /* remove list if this is the last session */
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_del(&frpc_node->list);
- mutex_unlock(&me->fastrpc_driver_list.lock);
- fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
- fail_fastrpc_driver_register:
- kfree(frpc_node);
- return -EINVAL;
- }
- static void eva_fastrpc_driver_unregister(struct msm_cvp_inst *inst,
- uint32_t handle,
- bool force_exit)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- struct list_head *ptr = NULL, *next = NULL;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct msm_cvp_list *buf_list = NULL;
- struct cvp_internal_buf *buf = NULL;
- struct fastrpc_device *frpc_device = NULL;
- struct cvp_dsp2cpu_cmd_msg *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- int rc = 0;
- dprintk(CVP_DSP, "%s Unregister fastrpc driver handle 0x%x, force %d\n",
- __func__, handle, (uint32_t)force_exit);
- /* Foundd fastrpc node */
- frpc_node = cvp_find_fastrpc_node_with_handle(dsp2cpu_cmd->pid);
- if (frpc_node == NULL)
- return;
- frpc_node->session_cnt--;
- 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);
- //Free any left over buffers
- ptr = NULL;
- next = NULL;
- buf_list = &frpc_node->dspbufs;
- mutex_lock(&buf_list->lock);
- list_for_each_safe(ptr, next, &buf_list->list) {
- buf = list_entry(ptr, struct cvp_internal_buf, list);
- if (!buf->smem) {
- dprintk(CVP_DSP, "%s Empyt smem\n", __func__);
- list_del(&buf->list);
- kfree(buf);
- continue;
- }
- rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
- if (rc) {
- dprintk(CVP_ERR,
- "%s Fail to unmap buffer 0x%x\n",
- __func__, rc);
- continue;
- }
- rc = cvp_release_dsp_buffers(inst, buf);
- if (rc) {
- dprintk(CVP_ERR,
- "%s Fail to free buffer 0x%x\n",
- __func__, rc);
- continue;
- }
- list_del(&buf->list);
- kfree(buf);
- }
- mutex_unlock(&buf_list->lock);
- DEINIT_MSM_CVP_LIST(&frpc_node->dspbufs);
- /* remove list if this is the last session */
- mutex_lock(&me->fastrpc_driver_list.lock);
- list_del(&frpc_node->list);
- mutex_unlock(&me->fastrpc_driver_list.lock);
- fastrpc_driver_unregister(&frpc_node->cvp_fastrpc_driver);
- kfree(frpc_node);
- }
- }
- #endif
- 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 = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
- 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->lock);
- if (!device->dsp_iface_q_table.align_virtual_addr) {
- dprintk(CVP_ERR, "%s: DSP HFI queue released\n", __func__);
- mutex_unlock(&me->lock);
- mutex_unlock(&device->lock);
- return;
- }
- 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\n",
- __func__, rsp.dsp_state);
- 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->lock);
- if (cvp_reinit_dsp()) {
- dprintk(CVP_ERR, "%s reinit dsp fail\n", __func__);
- mutex_unlock(&device->lock);
- return;
- }
- mutex_lock(&me->lock);
- }
- dprintk(CVP_DSP, "%s: dsp initialized\n", __func__);
- me->state = DSP_READY;
- exit:
- mutex_unlock(&me->lock);
- mutex_unlock(&device->lock);
- }
- /* 32 or 64 bit CPU Side Ptr <-> 2 32 bit DSP Pointers. Dirty Fix. */
- static void *ptr_dsp2cpu(uint32_t session_cpu_high, uint32_t session_cpu_low)
- {
- 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;
- }
- 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);
- }
- }
- static int msm_cvp_register_buffer_dsp(struct msm_cvp_inst *inst,
- struct eva_kmd_buffer *buf,
- int32_t pid,
- uint32_t *iova)
- {
- struct cvp_hfi_device *hdev;
- struct cvp_hal_session *session;
- struct msm_cvp_inst *s;
- int rc = 0;
- if (!inst || !inst->core || !buf) {
- dprintk(CVP_ERR, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!buf->index)
- return 0;
- s = cvp_get_inst_validate(inst->core, inst);
- if (!s)
- return -ECONNRESET;
- inst->cur_cmd_type = EVA_KMD_REGISTER_BUFFER;
- session = (struct cvp_hal_session *)inst->session;
- if (!session) {
- dprintk(CVP_ERR, "%s: invalid session\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- hdev = inst->core->device;
- print_client_buffer(CVP_HFI, "register", inst, buf);
- rc = msm_cvp_map_buf_dsp_new(inst, buf, pid, iova);
- dprintk(CVP_DSP, "%s: fd %d, iova 0x%x\n", __func__, buf->fd, *iova);
- exit:
- inst->cur_cmd_type = 0;
- cvp_put_inst(s);
- return rc;
- }
- static int msm_cvp_unregister_buffer_dsp(struct msm_cvp_inst *inst,
- struct eva_kmd_buffer *buf)
- {
- struct msm_cvp_inst *s;
- int rc = 0;
- if (!inst || !inst->core || !buf) {
- dprintk(CVP_ERR, "%s: invalid params\n", __func__);
- return -EINVAL;
- }
- if (!buf->index)
- return 0;
- s = cvp_get_inst_validate(inst->core, inst);
- if (!s)
- return -ECONNRESET;
- inst->cur_cmd_type = EVA_KMD_UNREGISTER_BUFFER;
- print_client_buffer(CVP_HFI, "unregister", inst, buf);
- rc = msm_cvp_unmap_buf_dsp_new(inst, buf);
- inst->cur_cmd_type = 0;
- cvp_put_inst(s);
- return rc;
- }
- static 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;
- struct eva_kmd_arg *kmd;
- struct eva_kmd_sys_properties *sys_prop = NULL;
- struct eva_kmd_session_control *sys_ctrl = NULL;
- int rc = 0;
- struct cvp_dsp2cpu_cmd_msg *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- cmd->ret = 0;
- dprintk(CVP_DSP,
- "%s sess Type %d Mask %d Prio %d Sec %d pid 0x%x\n",
- __func__, dsp2cpu_cmd->session_type,
- dsp2cpu_cmd->kernel_mask,
- dsp2cpu_cmd->session_prio,
- dsp2cpu_cmd->is_secure,
- dsp2cpu_cmd->pid);
- kmd = kzalloc(sizeof(*kmd), GFP_KERNEL);
- if (!kmd) {
- dprintk(CVP_ERR, "%s kzalloc failure\n", __func__);
- goto fail_frpc_driver_reg;
- }
- #ifdef FASTRPC_DRIVER_AVAILABLE
- rc = eva_fastrpc_driver_register(dsp2cpu_cmd->pid);
- #endif
- if (rc) {
- dprintk(CVP_ERR, "%s Register fastrpc driver fail\n", __func__);
- goto fail_frpc_driver_reg;
- }
- inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_USER);
- if (!inst) {
- dprintk(CVP_ERR, "%s Failed create instance\n", __func__);
- goto fail_msm_cvp_open;
- }
- kmd->type = EVA_KMD_SET_SYS_PROPERTY;
- sys_prop = (struct eva_kmd_sys_properties *)&kmd->data.sys_properties;
- sys_prop->prop_num = 5;
- sys_prop->prop_data[0].prop_type = EVA_KMD_PROP_SESSION_KERNELMASK;
- sys_prop->prop_data[0].data = dsp2cpu_cmd->kernel_mask;
- sys_prop->prop_data[1].prop_type = EVA_KMD_PROP_SESSION_TYPE;
- sys_prop->prop_data[1].data = dsp2cpu_cmd->session_type;
- sys_prop->prop_data[2].prop_type = EVA_KMD_PROP_SESSION_PRIORITY;
- sys_prop->prop_data[2].data = dsp2cpu_cmd->session_prio;
- sys_prop->prop_data[3].prop_type = EVA_KMD_PROP_SESSION_SECURITY;
- sys_prop->prop_data[3].data = dsp2cpu_cmd->is_secure;
- sys_prop->prop_data[4].prop_type = EVA_KMD_PROP_SESSION_DSPMASK;
- sys_prop->prop_data[4].data = dsp2cpu_cmd->dsp_access_mask;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to set sys property\n", __func__);
- goto fail_set_sys_property;
- }
- dprintk(CVP_DSP, "%s set sys property done\n", __func__);
- /* EVA_KMD_SESSION_CONTROL from DSP */
- memset(kmd, 0, sizeof(struct eva_kmd_arg));
- kmd->type = EVA_KMD_SESSION_CONTROL;
- sys_ctrl = (struct eva_kmd_session_control *)&kmd->data.session_ctrl;
- sys_ctrl->ctrl_type = SESSION_CREATE;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "Warning: send Session Create failed\n");
- goto fail_session_create;
- }
- dprintk(CVP_DSP, "%s send Session Create done\n", __func__);
- /* Get session id */
- memset(kmd, 0, sizeof(struct eva_kmd_arg));
- kmd->type = EVA_KMD_GET_SESSION_INFO;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "Warning: get session index failed\n");
- goto fail_get_session_info;
- }
- cmd->session_id = kmd->data.session.session_id;
- inst_handle = (uint64_t)inst;
- cmd->session_cpu_high = (uint32_t)((inst_handle & HIGH32) >> 32);
- cmd->session_cpu_low = (uint32_t)(inst_handle & LOW32);
- 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);
- kfree(kmd);
- return;
- fail_get_session_info:
- fail_session_create:
- fail_set_sys_property:
- fail_msm_cvp_open:
- /* unregister fastrpc driver */
- fail_frpc_driver_reg:
- cmd->ret = -1;
- kfree(kmd);
- }
- static void __dsp_cvp_sess_delete(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_session_control *sys_ctrl;
- int rc;
- struct cvp_dsp2cpu_cmd_msg *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 *)ptr_dsp2cpu(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- #ifdef FASTRPC_DRIVER_AVAILABLE
- /* unregister fastrpc driver */
- eva_fastrpc_driver_unregister(inst, dsp2cpu_cmd->pid, false);
- #endif
- kmd->type = EVA_KMD_SESSION_CONTROL;
- sys_ctrl = (struct eva_kmd_session_control *)&kmd->data.session_ctrl;
- /* Session delete does nothing here */
- sys_ctrl->ctrl_type = SESSION_DELETE;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "Warning: send Delete Session failed\n");
- cmd->ret = -1;
- goto dsp_fail_delete;
- }
- rc = msm_cvp_close(inst);
- if (rc) {
- dprintk(CVP_ERR, "Warning: Failed to close cvp instance\n");
- cmd->ret = -1;
- goto dsp_fail_delete;
- }
- dprintk(CVP_DSP, "%s DSP2CPU_DETELE_SESSION Done\n", __func__);
- dsp_fail_delete:
- kfree(kmd);
- }
- static void __dsp_cvp_power_req(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_sys_properties *sys_prop;
- int rc;
- struct cvp_dsp2cpu_cmd_msg *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);
- 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 *)ptr_dsp2cpu(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- print_power(&dsp2cpu_cmd->power_req);
- /* EVA_KMD_SET_SYS_PROPERTY
- * Total 14 properties, 8 max once
- * Need to do 2 rounds
- */
- kmd->type = EVA_KMD_SET_SYS_PROPERTY;
- sys_prop = (struct eva_kmd_sys_properties *)&kmd->data.sys_properties;
- sys_prop->prop_num = 7;
- sys_prop->prop_data[0].prop_type = EVA_KMD_PROP_PWR_FDU;
- sys_prop->prop_data[0].data =
- dsp2cpu_cmd->power_req.clock_fdu;
- sys_prop->prop_data[1].prop_type = EVA_KMD_PROP_PWR_ICA;
- sys_prop->prop_data[1].data =
- dsp2cpu_cmd->power_req.clock_ica;
- sys_prop->prop_data[2].prop_type = EVA_KMD_PROP_PWR_OD;
- sys_prop->prop_data[2].data =
- dsp2cpu_cmd->power_req.clock_od;
- sys_prop->prop_data[3].prop_type = EVA_KMD_PROP_PWR_MPU;
- sys_prop->prop_data[3].data =
- dsp2cpu_cmd->power_req.clock_mpu;
- sys_prop->prop_data[4].prop_type = EVA_KMD_PROP_PWR_FW;
- sys_prop->prop_data[4].data =
- dsp2cpu_cmd->power_req.clock_fw;
- sys_prop->prop_data[5].prop_type = EVA_KMD_PROP_PWR_DDR;
- sys_prop->prop_data[5].data =
- dsp2cpu_cmd->power_req.bw_ddr;
- sys_prop->prop_data[6].prop_type = EVA_KMD_PROP_PWR_SYSCACHE;
- sys_prop->prop_data[6].data =
- dsp2cpu_cmd->power_req.bw_sys_cache;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to set sys property\n", __func__);
- cmd->ret = -1;
- goto dsp_fail_power_req;
- }
- dprintk(CVP_DSP, "%s set sys property done part 1\n", __func__);
- /* EVA_KMD_SET_SYS_PROPERTY Round 2 */
- memset(kmd, 0, sizeof(struct eva_kmd_arg));
- kmd->type = EVA_KMD_SET_SYS_PROPERTY;
- sys_prop = (struct eva_kmd_sys_properties *)&kmd->data.sys_properties;
- sys_prop->prop_num = 7;
- sys_prop->prop_data[0].prop_type = EVA_KMD_PROP_PWR_FDU_OP;
- sys_prop->prop_data[0].data =
- dsp2cpu_cmd->power_req.op_clock_fdu;
- sys_prop->prop_data[1].prop_type = EVA_KMD_PROP_PWR_ICA_OP;
- sys_prop->prop_data[1].data =
- dsp2cpu_cmd->power_req.op_clock_ica;
- sys_prop->prop_data[2].prop_type = EVA_KMD_PROP_PWR_OD_OP;
- sys_prop->prop_data[2].data =
- dsp2cpu_cmd->power_req.op_clock_od;
- sys_prop->prop_data[3].prop_type = EVA_KMD_PROP_PWR_MPU_OP;
- sys_prop->prop_data[3].data =
- dsp2cpu_cmd->power_req.op_clock_mpu;
- sys_prop->prop_data[4].prop_type = EVA_KMD_PROP_PWR_FW_OP;
- sys_prop->prop_data[4].data =
- dsp2cpu_cmd->power_req.op_clock_fw;
- sys_prop->prop_data[5].prop_type = EVA_KMD_PROP_PWR_DDR_OP;
- sys_prop->prop_data[5].data =
- dsp2cpu_cmd->power_req.op_bw_ddr;
- sys_prop->prop_data[6].prop_type = EVA_KMD_PROP_PWR_SYSCACHE_OP;
- sys_prop->prop_data[6].data =
- dsp2cpu_cmd->power_req.op_bw_sys_cache;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to set sys property\n", __func__);
- cmd->ret = -1;
- goto dsp_fail_power_req;
- }
- dprintk(CVP_DSP, "%s set sys property done part 2\n", __func__);
- memset(kmd, 0, sizeof(struct eva_kmd_arg));
- kmd->type = EVA_KMD_UPDATE_POWER;
- rc = msm_cvp_handle_syscall(inst, kmd);
- if (rc) {
- /* May need to define more error types
- * Check UMD implementation here:
- * https://opengrok.qualcomm.com/source/xref/LA.UM.9.14/vendor/qcom/proprietary/cv-noship/cvp/cpurev/src/cvpcpuRev_skel_imp_cvp2.cpp#380
- */
- dprintk(CVP_ERR, "%s Failed to send update power numbers\n", __func__);
- cmd->ret = -1;
- goto dsp_fail_power_req;
- }
- dprintk(CVP_DSP, "%s DSP2CPU_POWER_REQUEST Done\n", __func__);
- dsp_fail_power_req:
- kfree(kmd);
- }
- static 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_msg *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 *)ptr_dsp2cpu(
- 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_dsp(inst, kmd_buf,
- dsp2cpu_cmd->pid, &cmd->sbuf.iova);
- 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.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);
- }
- static 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_msg *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 *)ptr_dsp2cpu(
- 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_dsp(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);
- }
- static 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_msg *dsp2cpu_cmd = &me->pending_dsp2cpu_cmd;
- uint64_t v_dsp_addr = 0;
- #ifdef FASTRPC_DRIVER_AVAILABLE
- struct fastrpc_device *frpc_device = NULL;
- struct cvp_dsp_fastrpc_driver_entry *frpc_node = NULL;
- struct msm_cvp_list *buf_list = NULL;
- #endif
- 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);
- #ifdef FASTRPC_DRIVER_AVAILABLE
- frpc_node = cvp_find_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;
- #endif
- inst = (struct msm_cvp_inst *)ptr_dsp2cpu(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- buf = kzalloc(sizeof(*buf), 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 != 0)
- goto fail_allocate_dsp_buf;
- #ifdef FASTRPC_DRIVER_AVAILABLE
- rc = eva_fastrpc_dev_map_dma(frpc_device, buf,
- dsp2cpu_cmd->sbuf.dsp_remote_map,
- &v_dsp_addr);
- #endif
- if (rc) {
- dprintk(CVP_ERR, "%s Failed to map buffer 0x%x\n", __func__,
- rc);
- goto fail_fastrpc_dev_map_dma;
- }
- #ifdef FASTRPC_DRIVER_AVAILABLE
- buf_list = &frpc_node->dspbufs;
- mutex_lock(&buf_list->lock);
- list_add_tail(&buf->list, &buf_list->list);
- mutex_unlock(&buf_list->lock);
- #endif
- 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);
- return;
- fail_fastrpc_dev_map_dma:
- cvp_release_dsp_buffers(inst, buf);
- fail_allocate_dsp_buf:
- kfree(buf);
- fail_kzalloc_buf:
- #ifdef FASTRPC_DRIVER_AVAILABLE
- fail_fastrpc_node:
- #endif
- cmd->ret = -1;
- return;
- }
- static void __dsp_cvp_mem_free(struct cvp_dsp_cmd_msg *cmd)
- {
- #ifdef FASTRPC_DRIVER_AVAILABLE
- 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_msg *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, 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 *)ptr_dsp2cpu(
- dsp2cpu_cmd->session_cpu_high,
- dsp2cpu_cmd->session_cpu_low);
- frpc_node = cvp_find_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 = &frpc_node->dspbufs;
- mutex_lock(&buf_list->lock);
- list_for_each_safe(ptr, next, &buf_list->list) {
- buf = list_entry(ptr, struct cvp_internal_buf, list);
- dprintk(CVP_DSP, "fd in list 0x%x, fd from dsp 0x%x\n",
- buf->fd, dsp2cpu_cmd->sbuf.fd);
- 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);
- rc = eva_fastrpc_dev_unmap_dma(frpc_device, buf);
- if (rc) {
- dprintk(CVP_ERR,
- "%s Failed to unmap buffer 0x%x\n",
- __func__, 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);
- kfree(buf);
- break;
- }
- }
- fail_release_buf:
- fail_fastrpc_dev_unmap_dma:
- mutex_unlock(&buf_list->lock);
- #endif
- }
- 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 = list_first_entry(&cvp_driver->cores, struct msm_cvp_core, list);
- 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->lock);
- switch (me->pending_dsp2cpu_cmd.type) {
- case DSP2CPU_POWERON:
- {
- if (me->state == DSP_READY) {
- cmd.ret = 0;
- break;
- }
- mutex_unlock(&me->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__);
- mutex_lock(&me->lock);
- me->state = old_state;
- cmd.ret = 1;
- break;
- }
- mutex_lock(&me->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;
- }
- 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->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");
- do_exit(rc);
- }
- int cvp_dsp_device_init(void)
- {
- struct cvp_dsp_apps *me = &gfa_cv;
- char tname[16];
- int rc;
- int i;
- mutex_init(&me->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);
- 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->lock);
- me->state = DSP_INVALID;
- mutex_unlock(&me->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->lock);
- unregister_rpmsg_driver(&cvp_dsp_rpmsg_client);
- }
|