From patchwork Thu May 9 17:38:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10937507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 783D2912 for ; Thu, 9 May 2019 17:39:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63A5C212DA for ; Thu, 9 May 2019 17:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57BAC28AE3; Thu, 9 May 2019 17:39:58 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5560928B3E for ; Thu, 9 May 2019 17:39:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726851AbfEIRjg (ORCPT ); Thu, 9 May 2019 13:39:36 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59074 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbfEIRjf (ORCPT ); Thu, 9 May 2019 13:39:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Zh+SE7SPz23Ox2vKTKGMxIaCp2/ny0ISAkGrrJwXZK4=; b=WeT/W1ulWZ47DBVh93Jw6mADBB ReR4tx89c06k+f+fgfwNLSafBfWwz7gB6PCu78hmGrawmkfcxSNAzx/W7nv5ufZGAAPbhTJglvVrQ rACri3Pejn2PQnUB2lQcZ798IPa7LhjVlC54l0qqx3zabLLYnttY850qFRZpLRt+UVndSfmf805PO SKEkWqnOp/PsrqaUhba/EkaEOK1pUSycmQ+DA3xJSOO1ZturZWKBZsJDkxoSIZ2zdiA+9wBQfvp54 L43RRnodwUlolioQJFOo9btaVPKmqXUJimLcJFNXF3GgVDVGljESr5aWvSpsPeY3yI60VuATKQcIN gUOcWPug==; Received: from 089144210233.atnat0019.highway.a1.net ([89.144.210.233] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOn14-0005KS-0K; Thu, 09 May 2019 17:39:34 +0000 From: Christoph Hellwig To: Bartlomiej Zolnierkiewicz , Manuel Lauss Cc: linux-mips@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] au1100fb: fix DMA API abuse Date: Thu, 9 May 2019 19:38:47 +0200 Message-Id: <20190509173849.11825-2-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190509173849.11825-1-hch@lst.de> References: <20190509173849.11825-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Virtual addresses return from dma(m)_alloc_coherent are opaque in what backs then, and drivers must not poke into them. Switch the driver to use the generic DMA API mmap helper to avoid these problems. Signed-off-by: Christoph Hellwig Acked-by: Bartlomiej Zolnierkiewicz --- drivers/video/fbdev/au1100fb.c | 24 ++++-------------------- drivers/video/fbdev/au1100fb.h | 1 + 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/drivers/video/fbdev/au1100fb.c b/drivers/video/fbdev/au1100fb.c index 0adf0683cf08..99941ae1f3a1 100644 --- a/drivers/video/fbdev/au1100fb.c +++ b/drivers/video/fbdev/au1100fb.c @@ -340,14 +340,12 @@ int au1100fb_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *fbi) */ int au1100fb_fb_mmap(struct fb_info *fbi, struct vm_area_struct *vma) { - struct au1100fb_device *fbdev; - - fbdev = to_au1100fb_device(fbi); + struct au1100fb_device *fbdev = to_au1100fb_device(fbi); - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); pgprot_val(vma->vm_page_prot) |= (6 << 9); //CCA=6 - return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len); + return dma_mmap_coherent(fbdev->dev, vma, fbdev->fb_mem, fbdev->fb_phys, + fbdev->fb_len); } static struct fb_ops au1100fb_ops = @@ -412,7 +410,6 @@ static int au1100fb_drv_probe(struct platform_device *dev) { struct au1100fb_device *fbdev; struct resource *regs_res; - unsigned long page; struct clk *c; /* Allocate new device private */ @@ -424,6 +421,7 @@ static int au1100fb_drv_probe(struct platform_device *dev) goto failed; platform_set_drvdata(dev, (void *)fbdev); + fbdev->dev = &dev->dev; /* Allocate region for our registers and map them */ regs_res = platform_get_resource(dev, IORESOURCE_MEM, 0); @@ -472,20 +470,6 @@ static int au1100fb_drv_probe(struct platform_device *dev) au1100fb_fix.smem_start = fbdev->fb_phys; au1100fb_fix.smem_len = fbdev->fb_len; - /* - * Set page reserved so that mmap will work. This is necessary - * since we'll be remapping normal memory. - */ - for (page = (unsigned long)fbdev->fb_mem; - page < PAGE_ALIGN((unsigned long)fbdev->fb_mem + fbdev->fb_len); - page += PAGE_SIZE) { -#ifdef CONFIG_DMA_NONCOHERENT - SetPageReserved(virt_to_page(CAC_ADDR((void *)page))); -#else - SetPageReserved(virt_to_page(page)); -#endif - } - print_dbg("Framebuffer memory map at %p", fbdev->fb_mem); print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); diff --git a/drivers/video/fbdev/au1100fb.h b/drivers/video/fbdev/au1100fb.h index 9af19939a9c6..e7239bceefd3 100644 --- a/drivers/video/fbdev/au1100fb.h +++ b/drivers/video/fbdev/au1100fb.h @@ -110,6 +110,7 @@ struct au1100fb_device { dma_addr_t fb_phys; int panel_idx; struct clk *lcdclk; + struct device *dev; }; /********************************************************************/ From patchwork Thu May 9 17:38:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10937503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B0EF17E0 for ; Thu, 9 May 2019 17:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 571F928B4C for ; Thu, 9 May 2019 17:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B7B328B56; Thu, 9 May 2019 17:39:56 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB0A528B3E for ; Thu, 9 May 2019 17:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbfEIRjl (ORCPT ); Thu, 9 May 2019 13:39:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59084 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726892AbfEIRji (ORCPT ); Thu, 9 May 2019 13:39:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=X0FjL3aO2ta2FtrLYrKKJDSOB+TS7uOhK8cSSGK92Po=; b=dg0Ik94KC7aLTSmZBv/TQo1F3m ROVzdjdVCdMqmOdYVDtJNKdQj4GMA8rZPkfoXoLuBfYbbCt6q1LYgzYGn+ExJDSUJVhpS7cS9+nme 2oGZuR3O8smbZ3yU967o1U0E4tsQYOp1MqH+z6PiKT0khC1Mrvd7Fdhv6jTUdKbZtVMeo+ZwCNBjE s3lFeIa1IDYBxGgA1+p7OZd4aNvbRJ6+u+tg/yrXXFUUuAF+ie/2FMO9j/0al/OguuQdZ7W7a/d+p RavW6s1PoL5nDGzcozjvYrtwZ44Cn8MCBpOsnlqg7gY3Pg8p8N2xZzC5oAINq9FcnBITuUEpsz8hy rWe12bSw==; Received: from 089144210233.atnat0019.highway.a1.net ([89.144.210.233] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOn16-0005Kc-Nv; Thu, 09 May 2019 17:39:37 +0000 From: Christoph Hellwig To: Bartlomiej Zolnierkiewicz , Manuel Lauss Cc: linux-mips@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] au1200fb: fix DMA API abuse Date: Thu, 9 May 2019 19:38:48 +0200 Message-Id: <20190509173849.11825-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190509173849.11825-1-hch@lst.de> References: <20190509173849.11825-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Virtual addresses return from dma(m)_alloc_attrs are opaque in what backs then, and drivers must not poke into them. Similarly caching modes are not supposed to be directly set by the driver. Switch the driver to use the generic DMA API mmap helper to avoid these problems. Signed-off-by: Christoph Hellwig Tested-by: Manuel Lauss --- drivers/video/fbdev/au1200fb.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/video/fbdev/au1200fb.c b/drivers/video/fbdev/au1200fb.c index 3872ccef4cb2..26caffb02b7e 100644 --- a/drivers/video/fbdev/au1200fb.c +++ b/drivers/video/fbdev/au1200fb.c @@ -147,6 +147,7 @@ struct au1200_lcd_iodata_t { struct au1200fb_device { struct fb_info *fb_info; /* FB driver info record */ struct au1200fb_platdata *pd; + struct device *dev; int plane; unsigned char* fb_mem; /* FrameBuffer memory map */ @@ -1232,10 +1233,8 @@ static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) { struct au1200fb_device *fbdev = info->par; - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */ - - return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len); + return dma_mmap_attrs(fbdev->dev, vma, fbdev->fb_mem, fbdev->fb_phys, + fbdev->fb_len, DMA_ATTR_NON_CONSISTENT); } static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata) @@ -1647,7 +1646,6 @@ static int au1200fb_drv_probe(struct platform_device *dev) struct au1200fb_device *fbdev; struct au1200fb_platdata *pd; struct fb_info *fbi = NULL; - unsigned long page; int bpp, plane, ret, irq; print_info("" DRIVER_DESC ""); @@ -1685,6 +1683,7 @@ static int au1200fb_drv_probe(struct platform_device *dev) fbdev = fbi->par; fbdev->fb_info = fbi; fbdev->pd = pd; + fbdev->dev = &dev->dev; fbdev->plane = plane; @@ -1702,16 +1701,6 @@ static int au1200fb_drv_probe(struct platform_device *dev) goto failed; } - /* - * Set page reserved so that mmap will work. This is necessary - * since we'll be remapping normal memory. - */ - for (page = (unsigned long)fbdev->fb_phys; - page < PAGE_ALIGN((unsigned long)fbdev->fb_phys + - fbdev->fb_len); - page += PAGE_SIZE) { - SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */ - } print_dbg("Framebuffer memory map at %p", fbdev->fb_mem); print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024); From patchwork Thu May 9 17:38:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10937499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C88B912 for ; Thu, 9 May 2019 17:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AC1A287E6 for ; Thu, 9 May 2019 17:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F378228B4C; Thu, 9 May 2019 17:39:55 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A63F1287E6 for ; Thu, 9 May 2019 17:39:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726914AbfEIRjl (ORCPT ); Thu, 9 May 2019 13:39:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59102 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbfEIRjl (ORCPT ); Thu, 9 May 2019 13:39:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ze3bI7R/AWInMMM2JlDlT8P7z6aa7ltggLIal7qS1fs=; b=WKveJiy42tZa3XL3xEuRZRY2+Y /wFrD9wGXNbRmW3FI4knn62zQ0lsa6/yA554tTuDxACiFGD8H04SFguP6SpPJJUTsC9tPHHKZLDUZ dcrqukr1oW1BbrODPMEMDZ0F99786dV4u+ip4Mdgdg84PgQVUN5dJ4JJFag0QCQkBNkHjjgRFZnNI YzHQgyhXf0ADhDO3gkNf3dFevriC+kuga/MwMBKDLxfOO4Iewqh3AVidMqdnS4JTJUoM4rtwpzh8M rqzmN7vQta8y7T0YPLC/1YsWg8+sUCJgTNSr5V6Rn8UQBbQt/z2KZpcPGJehPUrW5SZtJ4cAKqFm7 TwsCOg/A==; Received: from 089144210233.atnat0019.highway.a1.net ([89.144.210.233] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hOn19-0005Lf-Nm; Thu, 09 May 2019 17:39:40 +0000 From: Christoph Hellwig To: Bartlomiej Zolnierkiewicz , Manuel Lauss Cc: linux-mips@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] jz4740_fb: fix DMA API abuse Date: Thu, 9 May 2019 19:38:49 +0200 Message-Id: <20190509173849.11825-4-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190509173849.11825-1-hch@lst.de> References: <20190509173849.11825-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Virtual addresses return from dma(m)_alloc_coherent are opaque in what backs then, and drivers must not poke into them. Switch the driver to use the generic DMA API mmap helper to avoid these problems. Signed-off-by: Christoph Hellwig --- drivers/video/fbdev/jz4740_fb.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/video/fbdev/jz4740_fb.c b/drivers/video/fbdev/jz4740_fb.c index b57df83fdbd3..b95cdfa9e0a1 100644 --- a/drivers/video/fbdev/jz4740_fb.c +++ b/drivers/video/fbdev/jz4740_fb.c @@ -466,7 +466,6 @@ static int jzfb_alloc_devmem(struct jzfb *jzfb) { int max_videosize = 0; struct fb_videomode *mode = jzfb->pdata->modes; - void *page; int i; for (i = 0; i < jzfb->pdata->num_modes; ++mode, ++i) { @@ -491,12 +490,6 @@ static int jzfb_alloc_devmem(struct jzfb *jzfb) if (!jzfb->vidmem) goto err_free_framedesc; - for (page = jzfb->vidmem; - page < jzfb->vidmem + PAGE_ALIGN(jzfb->vidmem_size); - page += PAGE_SIZE) { - SetPageReserved(virt_to_page(page)); - } - jzfb->framedesc->next = jzfb->framedesc_phys; jzfb->framedesc->addr = jzfb->vidmem_phys; jzfb->framedesc->id = 0xdeafbead;