From patchwork Mon Aug 8 05:52:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9266685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 33A7C60839 for ; Mon, 8 Aug 2016 05:55:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 240B126E69 for ; Mon, 8 Aug 2016 05:55:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 188D527813; Mon, 8 Aug 2016 05:55:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BFD8C26E69 for ; Mon, 8 Aug 2016 05:55:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bWdW8-0000xA-BA; Mon, 08 Aug 2016 05:54:28 +0000 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bWdVT-0000eX-2U for linux-arm-kernel@lists.infradead.org; Mon, 08 Aug 2016 05:53:48 +0000 Received: by mail-pa0-x234.google.com with SMTP id pp5so110439759pac.3 for ; Sun, 07 Aug 2016 22:53:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LIGxKUJt6kg/YwvzWzDhCUujuiuGrt3lw1punpajGDg=; b=PzzPHPmJ0PMPC0ZEQP+B5NeTMm8dr9WewzVeAtf+MxQzeSUqFAdra7otXpjXFXhOo8 EDP7rZmLQeI8KYTkaTupC+Iol6h6Bj+mSqSMeUGQ5cP2v2iN/JoNtu0SHZ1yeWljkSrB zFmwj45dpshTOOVsoxYRct2sAO7tJSUiiP8BM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LIGxKUJt6kg/YwvzWzDhCUujuiuGrt3lw1punpajGDg=; b=NCahtM0poXGIZeLfEfQ0D+DVKL9pWA4nOphMWGGYlbpDSWPSYTWn/Wof9OVlXDBMc2 Y7xXwJUclBG2f/iC1b3XIMvS6o5pvLLAJTBEFOtluD8fxs1GNzej2x2zG9aHsm8sX3XN QMSleH1L6WmqmhqJeIBcWc2LHO2S8czK84G1hv3HFAf6GB4xxap/LsnV7VZPIzPi+0uh J/THrHD1gsoAgTBUq6UrPdG5x9HMES3EaK5iBEnqp8nvXV+h9MsdcfRkMORqMEwzlc5Z wjPWBNUc83LHIPlPQknxxEral8l+gllAGWP16bATC3jmuMolOZwGM31EpadKOE05OWLm Ov3w== X-Gm-Message-State: AEkoous+9o5Mk9w3jwr98EQF8Ielkpe9KHQp+dMne5mbKZcNHBuzkNjDGLvVMk1F7C4aCbCX X-Received: by 10.66.132.38 with SMTP id or6mr38996010pab.84.1470635606223; Sun, 07 Aug 2016 22:53:26 -0700 (PDT) Received: from anup-HP-Compaq-8100-Elite-CMT-PC.ban.broadcom.com ([202.140.56.34]) by smtp.gmail.com with ESMTPSA id u72sm44404402pfa.31.2016.08.07.22.53.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Aug 2016 22:53:25 -0700 (PDT) From: Anup Patel To: Greg Kroah-Hartman , Jonathan Corbet Subject: [PATCH RESEND v2 3/8] uio: Add new UIO_MEM_PHYS_CACHE type for mem regions Date: Mon, 8 Aug 2016 11:22:32 +0530 Message-Id: <1470635557-13416-4-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470635557-13416-1-git-send-email-anup.patel@broadcom.com> References: <1470635557-13416-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160807_225347_220049_31DF50BF X-CRM114-Status: GOOD ( 15.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Anup Patel , Scott Branden , linux-doc@vger.kernel.org, Ray Jui , Russell King - ARM Linux , linux-kernel@vger.kernel.org, Rob Herring , bcm-kernel-feedback-list@broadcom.com, Ankit Jindal , linux-arm-kernel@lists.infradead.org, Jan Viktorin MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ankit Jindal Currently, three types of mem regions are supported: UIO_MEM_PHYS, UIO_MEM_LOGICAL and UIO_MEM_VIRTUAL. Among these UIO_MEM_PHYS helps UIO driver export physcial memory to user space as non-cacheable user memory. Typcially memory-mapped registers of a device are exported to user space as UIO_MEM_PHYS type mem region. The UIO_MEM_PHYS type is not efficient if dma-capable devices are capable of maintaining coherency with CPU caches. This patch adds new type UIO_MEM_PHYS_CACHE for mem regions to enable cacheable access to physical memory from user space. Signed-off-by: Ankit Jindal Signed-off-by: Anup Patel --- drivers/uio/uio.c | 16 +++++++++++++--- include/linux/uio_driver.h | 9 +++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index f2729b7..0e53076 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -641,7 +641,7 @@ static const struct vm_operations_struct uio_physical_vm_ops = { #endif }; -static int uio_mmap_physical(struct vm_area_struct *vma) +static int uio_mmap_physical(struct vm_area_struct *vma, int memtype) { struct uio_device *idev = vma->vm_private_data; int mi = uio_find_mem_index(vma); @@ -656,7 +656,16 @@ static int uio_mmap_physical(struct vm_area_struct *vma) return -EINVAL; vma->vm_ops = &uio_physical_vm_ops; - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + switch (memtype) { + case UIO_MEM_PHYS: + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + break; + case UIO_MEM_PHYS_CACHE: + /* Do nothing. */ + break; + default: + return -EINVAL; + } /* * We cannot use the vm_iomap_memory() helper here, @@ -704,7 +713,8 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma) switch (idev->info->mem[mi].memtype) { case UIO_MEM_PHYS: - return uio_mmap_physical(vma); + case UIO_MEM_PHYS_CACHE: + return uio_mmap_physical(vma, idev->info->mem[mi].memtype); case UIO_MEM_LOGICAL: case UIO_MEM_VIRTUAL: return uio_mmap_logical(vma); diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h index 32c0e83..31359aee 100644 --- a/include/linux/uio_driver.h +++ b/include/linux/uio_driver.h @@ -124,10 +124,11 @@ extern void uio_event_notify(struct uio_info *info); #define UIO_IRQ_NONE 0 /* defines for uio_mem->memtype */ -#define UIO_MEM_NONE 0 -#define UIO_MEM_PHYS 1 -#define UIO_MEM_LOGICAL 2 -#define UIO_MEM_VIRTUAL 3 +#define UIO_MEM_NONE 0 +#define UIO_MEM_PHYS 1 +#define UIO_MEM_LOGICAL 2 +#define UIO_MEM_VIRTUAL 3 +#define UIO_MEM_PHYS_CACHE 4 /* defines for uio_port->porttype */ #define UIO_PORT_NONE 0