Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3496174ybi; Mon, 29 Jul 2019 07:33:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGBndbV1FcdsqYHDfrGllZb/d9dsYjhXXGDufUwSl9j3+hbHTRFfIakuYRyi9ZV9QFYuuL X-Received: by 2002:aa7:85d8:: with SMTP id z24mr28489671pfn.218.1564410783320; Mon, 29 Jul 2019 07:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564410783; cv=none; d=google.com; s=arc-20160816; b=sr2OsIV3bF+g6vvFLmMfnqANDLKNztR32cptgYx/7X7hRNp0hKa2+7yr81mGH7aKKC 9Hm6dXawrntaltFhrpH0AxlQY8KIEbrkIF4guDZY+nNnnBd1PFmluWqGZXZxoAjvlBVK 8LlfdotwOwlYw7/h7RQa0iU3yVso/UAyeIAxj81ujAfjosZ2jt8pX8pplMkzBEn6qmBo LqW2ZVc/iOl8DkPYE1qTg3Ta7N2Z/1ouJY3CJUYZ6IPlWZjUDxjvIVP912GdAnIRrsL2 ZzFq+bFCSgrtA9yiAbGDlO9ajRUI2+m4DSgeE70jNnxeY7kDAQdUZ4trGpuE95U1MwQy jIjA== 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=WNbeZsrKTCXULf+D139i7mF6RNWaCytF37Kc/BZsHxE=; b=WOC6sznQWhNficr2VkTwObYpklVqN2fqLV9pTyTc3G4zTr2aAApAb3NaGjJAi6soKD YXXhWu+AbBAsfZoFsYH3P7/4ay2Ry5IBjcz/YdbfkATXdg0oBJ0tR4L85WU9Aymx5A14 DJNmJIzUz7PxD/GPjKS4lZlxXVuyBzZHGfc+qpfi8AIlQH0mMRz+9Y5xhkvkOICz9Dvz BHyHrnimomyrXwbUItCfL5NA18DMkGX4Rtl1FI4VE8/kuydzhBwfWYouz2qVKBmlObJA /7MpdzBNGKItR6l9WjOYLwP373LsedYZ9lthKlr2hAKqQT+IeLlxLpJKmO8A0ajfICr5 JW+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PNwlQ8P7; 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 g6si26700784pll.82.2019.07.29.07.32.47; Mon, 29 Jul 2019 07:33:03 -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=PNwlQ8P7; 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 S1728581AbfG2O3j (ORCPT + 99 others); Mon, 29 Jul 2019 10:29:39 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46876 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727326AbfG2O3H (ORCPT ); Mon, 29 Jul 2019 10:29:07 -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=WNbeZsrKTCXULf+D139i7mF6RNWaCytF37Kc/BZsHxE=; b=PNwlQ8P7J1JXZHPMS7QK4NjaHG 1+8pEBbPQHaghI0tSWAiWKebJ404qQV4Xce2AcNcWX9NFpjoevp8RCfsf18lI1+fCw1lJJKNjf3FF MsSlQ+bLSfnbxCpCa9NB74M7o25AVZ4thH8mGldmmc45goQWJVzg0laJPaqtvQ7SJhD+Gj4bkTuNJ O0TjODMfJ7YNGm4PkjN1dEUUlWeXMej2J2htzQFjaDwRnUJ6dQUyH+8s67xOKPhi2+BnUaDzhIhqa iC4R6p6ARtEIqs4TqPjrH7YXMsZtpQjnTi/vL+ithy4Tsi3xX+SGuxR6G12prx/Lk8g+dBL5NvP2t PuE+xgUQ==; Received: from [195.167.85.94] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hs6e6-0006JY-RO; Mon, 29 Jul 2019 14:29:03 +0000 From: Christoph Hellwig To: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Jason Gunthorpe , Ben Skeggs Cc: Ralph Campbell , Bharata B Rao , Andrew Morton , linux-mm@kvack.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/9] nouveau: factor out device memory address calculation Date: Mon, 29 Jul 2019 17:28:37 +0300 Message-Id: <20190729142843.22320-4-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190729142843.22320-1-hch@lst.de> References: <20190729142843.22320-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 Factor out the repeated device memory address calculation into a helper. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/nouveau/nouveau_dmem.c | 42 +++++++++++--------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_dmem.c b/drivers/gpu/drm/nouveau/nouveau_dmem.c index e696157f771e..d469bc334438 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dmem.c +++ b/drivers/gpu/drm/nouveau/nouveau_dmem.c @@ -102,6 +102,14 @@ struct nouveau_migrate { unsigned long dma_nr; }; +static unsigned long nouveau_dmem_page_addr(struct page *page) +{ + struct nouveau_dmem_chunk *chunk = page->zone_device_data; + unsigned long idx = page_to_pfn(page) - chunk->pfn_first; + + return (idx << PAGE_SHIFT) + chunk->bo->bo.offset; +} + static void nouveau_dmem_page_free(struct page *page) { struct nouveau_dmem_chunk *chunk = page->zone_device_data; @@ -169,9 +177,7 @@ nouveau_dmem_fault_alloc_and_copy(struct vm_area_struct *vma, /* Copy things over */ copy = drm->dmem->migrate.copy_func; for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) { - struct nouveau_dmem_chunk *chunk; struct page *spage, *dpage; - u64 src_addr, dst_addr; dpage = migrate_pfn_to_page(dst_pfns[i]); if (!dpage || dst_pfns[i] == MIGRATE_PFN_ERROR) @@ -194,14 +200,10 @@ nouveau_dmem_fault_alloc_and_copy(struct vm_area_struct *vma, continue; } - dst_addr = fault->dma[fault->npages++]; - - chunk = spage->zone_device_data; - src_addr = page_to_pfn(spage) - chunk->pfn_first; - src_addr = (src_addr << PAGE_SHIFT) + chunk->bo->bo.offset; - - ret = copy(drm, 1, NOUVEAU_APER_HOST, dst_addr, - NOUVEAU_APER_VRAM, src_addr); + ret = copy(drm, 1, NOUVEAU_APER_HOST, + fault->dma[fault->npages++], + NOUVEAU_APER_VRAM, + nouveau_dmem_page_addr(spage)); if (ret) { dst_pfns[i] = MIGRATE_PFN_ERROR; __free_page(dpage); @@ -687,18 +689,12 @@ nouveau_dmem_migrate_alloc_and_copy(struct vm_area_struct *vma, /* Copy things over */ copy = drm->dmem->migrate.copy_func; for (addr = start, i = 0; addr < end; addr += PAGE_SIZE, i++) { - struct nouveau_dmem_chunk *chunk; struct page *spage, *dpage; - u64 src_addr, dst_addr; dpage = migrate_pfn_to_page(dst_pfns[i]); if (!dpage || dst_pfns[i] == MIGRATE_PFN_ERROR) continue; - chunk = dpage->zone_device_data; - dst_addr = page_to_pfn(dpage) - chunk->pfn_first; - dst_addr = (dst_addr << PAGE_SHIFT) + chunk->bo->bo.offset; - spage = migrate_pfn_to_page(src_pfns[i]); if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE)) { nouveau_dmem_page_free_locked(drm, dpage); @@ -716,10 +712,10 @@ nouveau_dmem_migrate_alloc_and_copy(struct vm_area_struct *vma, continue; } - src_addr = migrate->dma[migrate->dma_nr++]; - - ret = copy(drm, 1, NOUVEAU_APER_VRAM, dst_addr, - NOUVEAU_APER_HOST, src_addr); + ret = copy(drm, 1, NOUVEAU_APER_VRAM, + nouveau_dmem_page_addr(dpage), + NOUVEAU_APER_HOST, + migrate->dma[migrate->dma_nr++]); if (ret) { nouveau_dmem_page_free_locked(drm, dpage); dst_pfns[i] = 0; @@ -846,7 +842,6 @@ nouveau_dmem_convert_pfn(struct nouveau_drm *drm, npages = (range->end - range->start) >> PAGE_SHIFT; for (i = 0; i < npages; ++i) { - struct nouveau_dmem_chunk *chunk; struct page *page; uint64_t addr; @@ -864,10 +859,7 @@ nouveau_dmem_convert_pfn(struct nouveau_drm *drm, continue; } - chunk = page->zone_device_data; - addr = page_to_pfn(page) - chunk->pfn_first; - addr = (addr + chunk->bo->bo.mem.start) << PAGE_SHIFT; - + addr = nouveau_dmem_page_addr(page); range->pfns[i] &= ((1UL << range->pfn_shift) - 1); range->pfns[i] |= (addr >> PAGE_SHIFT) << range->pfn_shift; } -- 2.20.1