Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4506302pxk; Wed, 30 Sep 2020 04:58:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA1ZQzizI9uhSXwxHXyoJiPhxd7o1UMNpIk6IrL0Nn2i/7VwrFKKNehZACDET68MZdQQaV X-Received: by 2002:aa7:de91:: with SMTP id j17mr2311445edv.85.1601467088684; Wed, 30 Sep 2020 04:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601467088; cv=none; d=google.com; s=arc-20160816; b=uwM1deAmr6hOWbuqZWh5w0YbhWlfb+f1cZ45ukxpwoDxD778XX2u4TG1WHUmSKhQpH ypaiqvOweHUevpwv33SFUhcYrnpJwO6O7xtyr8soV8UwsXlUCjdsFW3FtANX/L96O2a5 rs/5iBCm52y7ugpQ4xPqFf+x8j3MMsHUNXdYdq79E3mnZIu0+UkMUxh/tGpQAqlCY5ff 6/6gX/dZQX6As6PkcugQYbs1FNYV0C3c+jw2jUsthwNPql+ZLBWX9rK2j6qq5WU6E/8L l7VPJQMRpMKn8wyEtYdTrjVI00nNuWIGGqIsinBpItEONgDejyw1PXe3FOVAJz94nzE0 MA5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qfj+TClPlVYbpelD2YZsoi79IQBZqKkdlSt5zFsjIAs=; b=zsdZxmULhAW/ZPaEe/KB8Ugp8rqPc5ond/SzuJjjYlySmeq7DRauVtLbk1MjIGMoz9 IEWKjv/mhB8sV5g8HDuEYv7D2RZWhHpLsAN3x7XnojSCWPjBr7wNQGPiYEHnjo58DBcz Zlb3GklW0Z6pwuk/+coobRkLuHhzjqgmP8+MYG+F4Q9fMwabLGEzw7+QZYC+htqyLpdT gncEen+ekcqZ8sUMLN1UJ61HYVBd0ERf5naZb44xxvIvF7Wkt7Y46O6IJGkIYe+GeePQ vrD9FiPAoeuh/wH48J470NWcuVw0hjansEI8hDvu21ONQ9kzeyPwUaM4F2hJI0IK5aZ8 3Fhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=XsLsT1M+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si1018101ejd.140.2020.09.30.04.57.46; Wed, 30 Sep 2020 04:58:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=XsLsT1M+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729674AbgI3Lxo (ORCPT + 99 others); Wed, 30 Sep 2020 07:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbgI3Lxn (ORCPT ); Wed, 30 Sep 2020 07:53:43 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2169C0613D7 for ; Wed, 30 Sep 2020 04:53:38 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id j2so1459605wrx.7 for ; Wed, 30 Sep 2020 04:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qfj+TClPlVYbpelD2YZsoi79IQBZqKkdlSt5zFsjIAs=; b=XsLsT1M+AlmtzTtVzfmpzEdnlyNhgSN9Vm8/VlqSDOFx3bzC+XKoQ6tfO8635GE2tB K4vNvrMU0OcJbL5ljhMpoGtOKhgbOkp5FrOVTy+N0F82YWhBZHVCuDVdyGRE1fg1PgGn jzTp9PjGVE07lHazWB3jPXMvDMVbJU+/5UQOaU5HwqXr3dI68pK7GE043+co0vkKxtw+ bpmODmoZ0zaZTG5p5ikahzCupx34VdUhGSItgXN754D+DE0eO5hlStfSH5xPGlO9LqwD kKr6RQDtIOXnWwTkySeNkk2hKiAqaWuGQT2si3rGDyPrmvi2QX8DxX5HrBD4MxCEz4hG BrDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qfj+TClPlVYbpelD2YZsoi79IQBZqKkdlSt5zFsjIAs=; b=a3XJ6Zvqg+suwY3Zsn26BGgUjJYqImLNAv47U9jFGzcm9lMIfxOJ2QJgj68HLIGM/D SVbw0ZrVujSCCTFFqOXR9Kya0eU0hL9jkNrOjk8qeNXID3ARpdDwLIp3o+6VcfuL8T6E qRu0eIKK/+iA9YHaqJRYzo6jY7y4tbenVp62+uYae80qLMvZEZp+pUNx8hmdOuO9LLN/ QEOv8xW0kTs5bN9Ggome/Ui2zmoobBsY3IWOK/4SHPj39bWbaPJ1rTVuvLysg586+MBa eGgFxcJcjS0mw8wuzm29kU5KXpD396PGI1wQsqCP6iJJt9M0YkN/2bWqU98eSsGkpw6Q OdAg== X-Gm-Message-State: AOAM530jaZC3j7wrfmtOh8BQ6c/cn5vJ8/uiJHqTur16ANX2C0JmYKvH TRxw8mLxAHCQ38GWS30r4qgqEw== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr2696721wrr.283.1601466817417; Wed, 30 Sep 2020 04:53:37 -0700 (PDT) Received: from alex-xps13.baylibre.local (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id s12sm2222353wmd.20.2020.09.30.04.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2020 04:53:36 -0700 (PDT) From: Alexandre Bailon To: linux-remoteproc@vger.kernel.org Cc: ohad@wizery.com, bjorn.andersson@linaro.org, sumit.semwal@linaro.org, christian.koenig@amd.com, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, jstephan@baylibre.com, stephane.leprovost@mediatek.com, gpain@baylibre.com, mturquette@baylibre.com, Alexandre Bailon Subject: [RFC PATCH 4/4] rpmsg: apu_rpmsg: Add an IOCTL to request IOMMU mapping Date: Wed, 30 Sep 2020 13:53:50 +0200 Message-Id: <20200930115350.5272-5-abailon@baylibre.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200930115350.5272-1-abailon@baylibre.com> References: <20200930115350.5272-1-abailon@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the kernel is automatically doing an IOMMU memory mapping. But we want to do it automatically for two reasons: - to reduce the overhead of each APU operation - to get the device address and use it as input for an operation This adds 2 IOCTL to manually IOMMU map and unmap memory. Signed-off-by: Alexandre Bailon --- drivers/rpmsg/apu_rpmsg.c | 52 ++++++++++++++++++++++++++++++---- include/uapi/linux/apu_rpmsg.h | 7 +++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/drivers/rpmsg/apu_rpmsg.c b/drivers/rpmsg/apu_rpmsg.c index 343bd08a859a..4c064feddf5a 100644 --- a/drivers/rpmsg/apu_rpmsg.c +++ b/drivers/rpmsg/apu_rpmsg.c @@ -114,7 +114,7 @@ static int apu_rpmsg_callback(struct rpmsg_device *rpdev, void *data, int count, } static struct apu_buffer *apu_device_memory_map(struct rpmsg_apu *apu, - uint32_t fd, struct rpmsg_request *rpmsg_req) + uint32_t fd) { struct rpmsg_device *rpdev = apu->rpdev; struct apu_buffer *buffer; @@ -129,10 +129,6 @@ static struct apu_buffer *apu_device_memory_map(struct rpmsg_apu *apu, list_for_each_entry(buffer, &apu->buffers, node) { if (buffer->fd == fd) { kref_get(&buffer->refcount); - if (rpmsg_req) - list_add(&buffer->req_node, - &rpmsg_req->buffers); - return buffer; } } @@ -230,6 +226,44 @@ static void apu_device_memory_unmap(struct kref *ref) kfree(buffer); } +static int apu_iommu_mmap_ioctl(struct rpmsg_apu *apu, void __user *argp) +{ + struct apu_iommu_mmap apu_iommu_mmap; + struct apu_buffer *buffer; + int ret; + + if (copy_from_user(&apu_iommu_mmap, argp, sizeof(apu_iommu_mmap))) + return -EFAULT; + + buffer = apu_device_memory_map(apu, apu_iommu_mmap.fd); + if (!buffer) + return -ENOMEM; + + apu_iommu_mmap.da = buffer->iova; + if (copy_to_user(argp, &apu_iommu_mmap, sizeof(apu_iommu_mmap))) + ret = -EFAULT; + + return 0; +} + +static int apu_iommu_munmap_ioctl(struct rpmsg_apu *apu, void __user *argp) +{ + u32 fd; + struct apu_buffer *buffer, *tmp; + + if (copy_from_user(&fd, argp, sizeof(fd))) + return -EFAULT; + + list_for_each_entry_safe(buffer, tmp, &apu->buffers, node) { + if (buffer->fd == fd) { + kref_put(&buffer->refcount, apu_device_memory_unmap); + return 0; + } + } + + return -EINVAL; +} + static int apu_send_request(struct rpmsg_apu *apu, struct apu_request *req) { @@ -266,7 +300,7 @@ static int apu_send_request(struct rpmsg_apu *apu, INIT_LIST_HEAD(&rpmsg_req->buffers); for (i = 0; i < req->count; i++) { - buffer = apu_device_memory_map(apu, fd[i], rpmsg_req); + buffer = apu_device_memory_map(apu, fd[i]); if (IS_ERR(buffer)) { ret = PTR_ERR(buffer); goto err_free_memory; @@ -417,6 +451,12 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd, } spin_unlock_irqrestore(&apu->ctx_lock, flags); + break; + case APU_IOMMU_MMAP: + ret = apu_iommu_mmap_ioctl(apu, argp); + break; + case APU_IOMMU_MUNMAP: + ret = apu_iommu_munmap_ioctl(apu, argp); break; default: ret = -EINVAL; diff --git a/include/uapi/linux/apu_rpmsg.h b/include/uapi/linux/apu_rpmsg.h index f61207520254..e9b841dcbcb4 100644 --- a/include/uapi/linux/apu_rpmsg.h +++ b/include/uapi/linux/apu_rpmsg.h @@ -31,10 +31,17 @@ struct apu_request { __u8 data[0]; }; +struct apu_iommu_mmap { + __u32 fd; + __u32 da; +}; + /* Send synchronous request to an APU */ #define APU_SEND_REQ_IOCTL _IOW(0xb7, 0x2, struct apu_request) #define APU_GET_NEXT_AVAILABLE_IOCTL _IOR(0xb7, 0x3, __u16) #define APU_GET_RESP _IOWR(0xb7, 0x4, struct apu_request) +#define APU_IOMMU_MMAP _IOWR(0xb7, 0x5, struct apu_iommu_mmap) +#define APU_IOMMU_MUNMAP _IOWR(0xb7, 0x6, __u32) #endif -- 2.26.2