Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp533003ybb; Wed, 8 Apr 2020 05:02:50 -0700 (PDT) X-Google-Smtp-Source: APiQypJ4zVmbRSOXdpk9C95OyVE4sAAe0FtxYD0dpol5072eIdMywfCr7YCYRMO0YXZ4x+1dGvCp X-Received: by 2002:a05:6830:1610:: with SMTP id g16mr5177002otr.358.1586347370475; Wed, 08 Apr 2020 05:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586347370; cv=none; d=google.com; s=arc-20160816; b=eXT204mz6jTDThT0HabHSxPF4UPVPZnnPlpGDJ48oPSLwveApSJi2Zta9ElgEdiAlT lSOoVeH+CAeziG9469v6ZYRJuNzJVLUIDn2rq+kI8/H0v0Te7gRFn7p/0bdunwErkXmd SxVN5tnIlXAU1mU9eDQWPPlrxf4mmy4wkZje9k9oRBPcx/wiSCC3I/2Fgu9EGYUJwptg yBZFyap0UzE3D6KDi/IqOgPMYUBU/Wy8QgGe4G3XEs6EJHEv+qU/EesiwkYxHUlm2fjV h4ESCcr7F4V94tB2HgB2D0J9w7ssoqbIkucOTbqFobCMpkK6VVOfguOBGqsTeBGV9of5 3mLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hvIl8nFdM9AKvvDd2B5Ptj/sPZlvFIjnu0sAKeiFvVM=; b=k5xkuLtGW9O30l/0y4WxyYIjg0MUPPAuo1nQ0HfKI/wfOz8Oj6Fjogo7RtyA0dnZWE 4Vb2uWcCLCyYZhi0DSgMHc5kjXTt/Qg5KQhoDjI4RXqLCeGoHNybYy9zAvCSa0JL8tIX Wvp81MShPzLFVioyqvF2pswcSqbvjku0tvm+YofFPspXOedCzBA+GhA/2k4c6dae4JG5 xSVcKmVMCyIyA4rws6yaqto1lqIgYDxIpMB48+c8ckQkt5Rd+1VB7bcwKw3DAbcS/Fnn HoLTZsOCA4zfHhuHUo1oiWv6DsMN5MWm6sLuCx4J9aqGFGZF5XgfDqNW8dca6xGXTxHd 04aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Aw93+jFA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 94si2433313otc.25.2020.04.08.05.02.30; Wed, 08 Apr 2020 05:02:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Aw93+jFA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728774AbgDHL77 (ORCPT + 99 others); Wed, 8 Apr 2020 07:59:59 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46414 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728646AbgDHL76 (ORCPT ); Wed, 8 Apr 2020 07:59:58 -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; bh=hvIl8nFdM9AKvvDd2B5Ptj/sPZlvFIjnu0sAKeiFvVM=; b=Aw93+jFA2GdNKeSsa38wNjnfeJ /Hxs35R5BvUIjAi75y9i06TKeMeJbZEpxu+5xdycGhgCnuMKfysp5Xo29U87h+hjXj05dBgfGKrWf i91U3+oTCKj4kvk5IzZbHTAvVhzAiQp/zMp5dFUe+PvkjRZkXTi92j4SSBAM/VBRNxIotnDHo5aQ/ 2mXhOdSdmKmXpCO8V3CsqLFu1Bjml4USrfdhJMKZ631fM0E0nBcJirRT2+fCqkHq+fRYLuqt949GV Si/voJR5Bp21VepCL6NCwOddv+lAijSqgdykatW2/GLZ2L/I+/7pJ67IF1ZHnLDSPWi+KEDDMxI8x NESmQdmQ==; Received: from [2001:4bb8:180:5765:65b6:f11e:f109:b151] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jM9Mo-0001cr-R8; Wed, 08 Apr 2020 11:59:39 +0000 From: Christoph Hellwig To: Andrew Morton , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , x86@kernel.org, David Airlie , Daniel Vetter , Laura Abbott , Sumit Semwal , Sakari Ailus , Minchan Kim , Nitin Gupta Cc: Robin Murphy , Christophe Leroy , Peter Zijlstra , linuxppc-dev@lists.ozlabs.org, linux-hyperv@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/28] staging: media: ipu3: use vmap insted of reimplementing it Date: Wed, 8 Apr 2020 13:59:01 +0200 Message-Id: <20200408115926.1467567-4-hch@lst.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200408115926.1467567-1-hch@lst.de> References: <20200408115926.1467567-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just use vmap instead of messing with vmalloc internals. Signed-off-by: Christoph Hellwig --- drivers/staging/media/ipu3/ipu3-css-pool.h | 4 +-- drivers/staging/media/ipu3/ipu3-dmamap.c | 30 ++++++---------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css-pool.h b/drivers/staging/media/ipu3/ipu3-css-pool.h index f4a60b41401b..a8ccd4f70320 100644 --- a/drivers/staging/media/ipu3/ipu3-css-pool.h +++ b/drivers/staging/media/ipu3/ipu3-css-pool.h @@ -15,14 +15,12 @@ struct imgu_device; * @size: size of the buffer in bytes. * @vaddr: kernel virtual address. * @daddr: iova dma address to access IPU3. - * @vma: private, a pointer to &struct vm_struct, - * used for imgu_dmamap_free. */ struct imgu_css_map { size_t size; void *vaddr; dma_addr_t daddr; - struct vm_struct *vma; + struct page **pages; }; /** diff --git a/drivers/staging/media/ipu3/ipu3-dmamap.c b/drivers/staging/media/ipu3/ipu3-dmamap.c index 7431322379f6..8a19b0024152 100644 --- a/drivers/staging/media/ipu3/ipu3-dmamap.c +++ b/drivers/staging/media/ipu3/ipu3-dmamap.c @@ -96,6 +96,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, unsigned long shift = iova_shift(&imgu->iova_domain); struct device *dev = &imgu->pci_dev->dev; size_t size = PAGE_ALIGN(len); + int count = size >> PAGE_SHIFT; struct page **pages; dma_addr_t iovaddr; struct iova *iova; @@ -114,7 +115,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, /* Call IOMMU driver to setup pgt */ iovaddr = iova_dma_addr(&imgu->iova_domain, iova); - for (i = 0; i < size / PAGE_SIZE; ++i) { + for (i = 0; i < count; ++i) { rval = imgu_mmu_map(imgu->mmu, iovaddr, page_to_phys(pages[i]), PAGE_SIZE); if (rval) @@ -123,33 +124,23 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, iovaddr += PAGE_SIZE; } - /* Now grab a virtual region */ - map->vma = __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END); - if (!map->vma) + map->vaddr = vmap(pages, count, VM_USERMAP, PAGE_KERNEL); + if (!map->vaddr) goto out_unmap; - map->vma->pages = pages; - /* And map it in KVA */ - if (map_vm_area(map->vma, PAGE_KERNEL, pages)) - goto out_vunmap; - + map->pages = pages; map->size = size; map->daddr = iova_dma_addr(&imgu->iova_domain, iova); - map->vaddr = map->vma->addr; dev_dbg(dev, "%s: allocated %zu @ IOVA %pad @ VA %p\n", __func__, - size, &map->daddr, map->vma->addr); - - return map->vma->addr; + size, &map->daddr, map->vaddr); -out_vunmap: - vunmap(map->vma->addr); + return map->vaddr; out_unmap: imgu_dmamap_free_buffer(pages, size); imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova), i * PAGE_SIZE); - map->vma = NULL; out_free_iova: __free_iova(&imgu->iova_domain, iova); @@ -177,8 +168,6 @@ void imgu_dmamap_unmap(struct imgu_device *imgu, struct imgu_css_map *map) */ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map) { - struct vm_struct *area = map->vma; - dev_dbg(&imgu->pci_dev->dev, "%s: freeing %zu @ IOVA %pad @ VA %p\n", __func__, map->size, &map->daddr, map->vaddr); @@ -187,11 +176,8 @@ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map) imgu_dmamap_unmap(imgu, map); - if (WARN_ON(!area) || WARN_ON(!area->pages)) - return; - - imgu_dmamap_free_buffer(area->pages, map->size); vunmap(map->vaddr); + imgu_dmamap_free_buffer(map->pages, map->size); map->vaddr = NULL; } -- 2.25.1