msm: adsprpc: Use upstream API qcom_scm_assign_mem
Currently hyp_assign_phys is being used to assign mmeory to remote subsystems. hyp_assign_phys is not upstream friendly. Use qcom_scm_assign_mem in place of hyp_assign_phys to deprecate downstream API. Signed-off-by: Himateja Reddy <quic_hmreddy@quicinc.com> Change-Id: Ic4aed6570598a96e6401777836bd390ede877ff2
This commit is contained in:

committed by
Gerrit - the friendly Code Review server

parent
7d90dc2702
commit
ee50316af5
157
dsp/adsprpc.c
157
dsp/adsprpc.c
@@ -24,7 +24,7 @@
|
|||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/hash.h>
|
#include <linux/hash.h>
|
||||||
#include <linux/msm_ion.h>
|
#include <linux/msm_ion.h>
|
||||||
#include <soc/qcom/secure_buffer.h>
|
#include <linux/qcom_scm.h>
|
||||||
#include <linux/ipc_logging.h>
|
#include <linux/ipc_logging.h>
|
||||||
#include <linux/remoteproc/qcom_rproc.h>
|
#include <linux/remoteproc/qcom_rproc.h>
|
||||||
#include <linux/scatterlist.h>
|
#include <linux/scatterlist.h>
|
||||||
@@ -384,8 +384,6 @@ static struct fastrpc_channel_ctx gcinfo[NUM_CHANNELS] = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int hlosvm[1] = {VMID_HLOS};
|
|
||||||
static int hlosvmperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
|
|
||||||
static uint32_t kernel_capabilities[FASTRPC_MAX_ATTRIBUTES -
|
static uint32_t kernel_capabilities[FASTRPC_MAX_ATTRIBUTES -
|
||||||
FASTRPC_MAX_DSP_ATTRIBUTES] = {
|
FASTRPC_MAX_DSP_ATTRIBUTES] = {
|
||||||
@@ -728,9 +726,6 @@ skip_buf_cache:
|
|||||||
buf->raddr = 0;
|
buf->raddr = 0;
|
||||||
}
|
}
|
||||||
if (!IS_ERR_OR_NULL(buf->virt)) {
|
if (!IS_ERR_OR_NULL(buf->virt)) {
|
||||||
int destVM[1] = {VMID_HLOS};
|
|
||||||
int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
|
|
||||||
VERIFY(err, fl->sctx != NULL);
|
VERIFY(err, fl->sctx != NULL);
|
||||||
if (err)
|
if (err)
|
||||||
goto bail;
|
goto bail;
|
||||||
@@ -747,12 +742,16 @@ skip_buf_cache:
|
|||||||
}
|
}
|
||||||
vmid = fl->apps->channel[cid].vmid;
|
vmid = fl->apps->channel[cid].vmid;
|
||||||
if ((vmid) && (fl->apps->channel[cid].in_hib == 0)) {
|
if ((vmid) && (fl->apps->channel[cid].in_hib == 0)) {
|
||||||
int srcVM[2] = {VMID_HLOS, vmid};
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS)| BIT(vmid);
|
||||||
|
struct qcom_scm_vmperm dest_perms = {0};
|
||||||
int hyp_err = 0;
|
int hyp_err = 0;
|
||||||
|
|
||||||
hyp_err = hyp_assign_phys(buf->phys,
|
dest_perms.vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dest_perms.perm = QCOM_SCM_PERM_RWX;
|
||||||
|
|
||||||
|
hyp_err = qcom_scm_assign_mem(buf->phys,
|
||||||
buf_page_size(buf->size),
|
buf_page_size(buf->size),
|
||||||
srcVM, 2, destVM, destVMperm, 1);
|
&src_perms, &dest_perms, 1);
|
||||||
if (hyp_err) {
|
if (hyp_err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -1039,8 +1038,6 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags)
|
|||||||
if (!IS_ERR_OR_NULL(map->buf))
|
if (!IS_ERR_OR_NULL(map->buf))
|
||||||
dma_buf_put(map->buf);
|
dma_buf_put(map->buf);
|
||||||
} else {
|
} else {
|
||||||
int destVM[1] = {VMID_HLOS};
|
|
||||||
int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
if (!fl)
|
if (!fl)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
@@ -1052,11 +1049,14 @@ static void fastrpc_mmap_free(struct fastrpc_mmap *map, uint32_t flags)
|
|||||||
vmid = fl->apps->channel[cid].vmid;
|
vmid = fl->apps->channel[cid].vmid;
|
||||||
if (vmid && map->phys && (me->channel[cid].in_hib == 0)) {
|
if (vmid && map->phys && (me->channel[cid].in_hib == 0)) {
|
||||||
int hyp_err = 0;
|
int hyp_err = 0;
|
||||||
int srcVM[2] = {VMID_HLOS, vmid};
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS) | BIT(vmid);
|
||||||
|
struct qcom_scm_vmperm dst_perms = {0};
|
||||||
|
|
||||||
hyp_err = hyp_assign_phys(map->phys,
|
dst_perms.vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dst_perms.perm = QCOM_SCM_PERM_RWX;
|
||||||
|
hyp_err = qcom_scm_assign_mem(map->phys,
|
||||||
buf_page_size(map->size),
|
buf_page_size(map->size),
|
||||||
srcVM, 2, destVM, destVMperm, 1);
|
&src_perms, &dst_perms, 1);
|
||||||
if (hyp_err) {
|
if (hyp_err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -1351,14 +1351,17 @@ static int fastrpc_mmap_create(struct fastrpc_file *fl, int fd, struct dma_buf *
|
|||||||
|
|
||||||
vmid = fl->apps->channel[cid].vmid;
|
vmid = fl->apps->channel[cid].vmid;
|
||||||
if (vmid) {
|
if (vmid) {
|
||||||
int srcVM[1] = {VMID_HLOS};
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS);
|
||||||
int destVM[2] = {VMID_HLOS, vmid};
|
struct qcom_scm_vmperm dst_perms[2] = {0};
|
||||||
int destVMperm[2] = {PERM_READ | PERM_WRITE,
|
|
||||||
PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
|
|
||||||
err = hyp_assign_phys(map->phys,
|
dst_perms[0].vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dst_perms[0].perm = QCOM_SCM_PERM_RW;
|
||||||
|
dst_perms[1].vmid = vmid;
|
||||||
|
dst_perms[1].perm = QCOM_SCM_PERM_RWX;
|
||||||
|
|
||||||
|
err = qcom_scm_assign_mem(map->phys,
|
||||||
buf_page_size(map->size),
|
buf_page_size(map->size),
|
||||||
srcVM, 1, destVM, destVMperm, 2);
|
&src_perms, dst_perms, 2);
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -1526,13 +1529,16 @@ static int fastrpc_buf_alloc(struct fastrpc_file *fl, size_t size,
|
|||||||
|
|
||||||
vmid = fl->apps->channel[cid].vmid;
|
vmid = fl->apps->channel[cid].vmid;
|
||||||
if (vmid) {
|
if (vmid) {
|
||||||
int srcVM[1] = {VMID_HLOS};
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS);
|
||||||
int destVM[2] = {VMID_HLOS, vmid};
|
struct qcom_scm_vmperm dst_perms[2] = {0};
|
||||||
int destVMperm[2] = {PERM_READ | PERM_WRITE,
|
|
||||||
PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
|
|
||||||
err = hyp_assign_phys(buf->phys, buf_page_size(size),
|
dst_perms[0].vmid = QCOM_SCM_VMID_HLOS;
|
||||||
srcVM, 1, destVM, destVMperm, 2);
|
dst_perms[0].perm = QCOM_SCM_PERM_RW;
|
||||||
|
dst_perms[1].vmid = vmid;
|
||||||
|
dst_perms[1].perm = QCOM_SCM_PERM_RWX;
|
||||||
|
|
||||||
|
err = qcom_scm_assign_mem(buf->phys, buf_page_size(size),
|
||||||
|
&src_perms, dst_perms, 2);
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_DEBUG(
|
ADSPRPC_DEBUG(
|
||||||
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -4013,9 +4019,20 @@ static int fastrpc_init_create_static_process(struct fastrpc_file *fl,
|
|||||||
* hyp_assign from HLOS to those VMs (LPASS, ADSP).
|
* hyp_assign from HLOS to those VMs (LPASS, ADSP).
|
||||||
*/
|
*/
|
||||||
if (rhvm->vmid && mem && mem->refs == 1 && size) {
|
if (rhvm->vmid && mem && mem->refs == 1 && size) {
|
||||||
err = hyp_assign_phys(phys, (uint64_t)size,
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS);
|
||||||
hlosvm, 1,
|
struct qcom_scm_vmperm *dst_perms;
|
||||||
rhvm->vmid, rhvm->vmperm, rhvm->vmcount);
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
VERIFY(err, NULL != (dst_perms = kcalloc(rhvm->vmcount,
|
||||||
|
sizeof(struct qcom_scm_vmperm), GFP_KERNEL)));
|
||||||
|
for (i = 0; i < rhvm->vmcount; i++) {
|
||||||
|
dst_perms[i].vmid = rhvm->vmid[i];
|
||||||
|
dst_perms[i].perm = rhvm->vmperm[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
err = qcom_scm_assign_mem(phys, (uint64_t)size,
|
||||||
|
&src_perms, dst_perms, rhvm->vmcount);
|
||||||
|
kfree(dst_perms);
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -4066,11 +4083,19 @@ bail:
|
|||||||
me->staticpd_flags = 0;
|
me->staticpd_flags = 0;
|
||||||
if (rh_hyp_done) {
|
if (rh_hyp_done) {
|
||||||
int hyp_err = 0;
|
int hyp_err = 0;
|
||||||
|
u64 src_perms = 0;
|
||||||
|
struct qcom_scm_vmperm dst_perms;
|
||||||
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < rhvm->vmcount; i++) {
|
||||||
|
src_perms |= BIT(rhvm->vmid[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
dst_perms.vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dst_perms.perm = QCOM_SCM_PERM_RWX;
|
||||||
/* Assign memory back to HLOS in case of errors */
|
/* Assign memory back to HLOS in case of errors */
|
||||||
hyp_err = hyp_assign_phys(phys, (uint64_t)size,
|
hyp_err = qcom_scm_assign_mem(phys, (uint64_t)size,
|
||||||
rhvm->vmid, rhvm->vmcount,
|
&src_perms, &dst_perms, 1);
|
||||||
hlosvm, hlosvmperm, 1);
|
|
||||||
if (hyp_err)
|
if (hyp_err)
|
||||||
ADSPRPC_WARN(
|
ADSPRPC_WARN(
|
||||||
"rh hyp unassign failed with %d for phys 0x%llx of size %zu\n",
|
"rh hyp unassign failed with %d for phys 0x%llx of size %zu\n",
|
||||||
@@ -4627,10 +4652,21 @@ static int fastrpc_mmap_on_dsp(struct fastrpc_file *fl, uint32_t flags,
|
|||||||
}
|
}
|
||||||
if (flags == ADSP_MMAP_REMOTE_HEAP_ADDR
|
if (flags == ADSP_MMAP_REMOTE_HEAP_ADDR
|
||||||
&& me->channel[cid].rhvm.vmid && refs == 1) {
|
&& me->channel[cid].rhvm.vmid && refs == 1) {
|
||||||
err = hyp_assign_phys(phys, (uint64_t)size,
|
struct secure_vm *rhvm = &me->channel[cid].rhvm;
|
||||||
hlosvm, 1, me->channel[cid].rhvm.vmid,
|
u64 src_perms = BIT(QCOM_SCM_VMID_HLOS);
|
||||||
me->channel[cid].rhvm.vmperm,
|
struct qcom_scm_vmperm *dst_perms;
|
||||||
me->channel[cid].rhvm.vmcount);
|
uint32_t i = 0;
|
||||||
|
|
||||||
|
VERIFY(err, NULL != (dst_perms = kcalloc(rhvm->vmcount,
|
||||||
|
sizeof(struct qcom_scm_vmperm), GFP_KERNEL)));
|
||||||
|
|
||||||
|
for (i = 0; i < rhvm->vmcount; i++) {
|
||||||
|
dst_perms[i].vmid = rhvm->vmid[i];
|
||||||
|
dst_perms[i].perm = rhvm->vmperm[i];
|
||||||
|
}
|
||||||
|
err = qcom_scm_assign_mem(phys, (uint64_t)size,
|
||||||
|
&src_perms, dst_perms, rhvm->vmcount);
|
||||||
|
kfree(dst_perms);
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp assign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -4713,16 +4749,22 @@ static int fastrpc_munmap_rh(uint64_t phys, size_t size,
|
|||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
struct fastrpc_apps *me = &gfa;
|
struct fastrpc_apps *me = &gfa;
|
||||||
int destVM[1] = {VMID_HLOS};
|
struct secure_vm *rhvm = &me->channel[RH_CID].rhvm;
|
||||||
int destVMperm[1] = {PERM_READ | PERM_WRITE | PERM_EXEC};
|
|
||||||
|
|
||||||
if ((me->channel[RH_CID].rhvm.vmid)
|
if ((rhvm->vmid)
|
||||||
&& (me->channel[RH_CID].in_hib == 0)) {
|
&& (me->channel[RH_CID].in_hib == 0)) {
|
||||||
err = hyp_assign_phys(phys,
|
u64 src_perms = 0;
|
||||||
(uint64_t)size,
|
struct qcom_scm_vmperm dst_perms = {0};
|
||||||
me->channel[RH_CID].rhvm.vmid,
|
uint32_t i = 0;
|
||||||
me->channel[RH_CID].rhvm.vmcount,
|
|
||||||
destVM, destVMperm, 1);
|
for (i = 0; i < rhvm->vmcount; i++) {
|
||||||
|
src_perms |= BIT(rhvm->vmid[i]);
|
||||||
|
}
|
||||||
|
dst_perms.vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dst_perms.perm = QCOM_SCM_PERM_RWX;
|
||||||
|
|
||||||
|
err = qcom_scm_assign_mem(phys,
|
||||||
|
(uint64_t)size, &src_perms, &dst_perms, 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
"rh hyp unassign failed with %d for phys 0x%llx, size %zu\n",
|
||||||
@@ -4785,20 +4827,25 @@ static int fastrpc_mmap_remove_ssr(struct fastrpc_file *fl, int locked)
|
|||||||
&& !strcmp(map->servloc_name, fl->servloc_name))) {
|
&& !strcmp(map->servloc_name, fl->servloc_name))) {
|
||||||
match = map;
|
match = map;
|
||||||
if (map->is_persistent && map->in_use) {
|
if (map->is_persistent && map->in_use) {
|
||||||
int destVM[1] = {VMID_HLOS};
|
struct secure_vm *rhvm = &me->channel[RH_CID].rhvm;
|
||||||
int destVMperm[1] = {PERM_READ | PERM_WRITE
|
|
||||||
| PERM_EXEC};
|
|
||||||
uint64_t phys = map->phys;
|
uint64_t phys = map->phys;
|
||||||
size_t size = map->size;
|
size_t size = map->size;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&me->hlock, irq_flags);
|
spin_unlock_irqrestore(&me->hlock, irq_flags);
|
||||||
//hyp assign it back to HLOS
|
//scm assign it back to HLOS
|
||||||
if (me->channel[RH_CID].rhvm.vmid) {
|
if (rhvm->vmid) {
|
||||||
err = hyp_assign_phys(phys,
|
u64 src_perms = 0;
|
||||||
(uint64_t)size,
|
struct qcom_scm_vmperm dst_perms = {0};
|
||||||
me->channel[RH_CID].rhvm.vmid,
|
uint32_t i = 0;
|
||||||
me->channel[RH_CID].rhvm.vmcount,
|
|
||||||
destVM, destVMperm, 1);
|
for (i = 0; i < rhvm->vmcount; i++) {
|
||||||
|
src_perms |= BIT(rhvm->vmid[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
dst_perms.vmid = QCOM_SCM_VMID_HLOS;
|
||||||
|
dst_perms.perm = QCOM_SCM_PERM_RWX;
|
||||||
|
err = qcom_scm_assign_mem(phys, (uint64_t)size,
|
||||||
|
&src_perms, &dst_perms, 1);
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
ADSPRPC_ERR(
|
ADSPRPC_ERR(
|
||||||
@@ -7640,7 +7687,7 @@ static void init_secure_vmid_list(struct device *dev, char *prop_name,
|
|||||||
}
|
}
|
||||||
ADSPRPC_INFO("secure VMID = %d\n",
|
ADSPRPC_INFO("secure VMID = %d\n",
|
||||||
rhvmlist[i]);
|
rhvmlist[i]);
|
||||||
rhvmpermlist[i] = PERM_READ | PERM_WRITE | PERM_EXEC;
|
rhvmpermlist[i] = QCOM_SCM_PERM_RWX;
|
||||||
}
|
}
|
||||||
destvm->vmid = rhvmlist;
|
destvm->vmid = rhvmlist;
|
||||||
destvm->vmperm = rhvmpermlist;
|
destvm->vmperm = rhvmpermlist;
|
||||||
|
Reference in New Issue
Block a user