From patchwork Thu Oct 5 13:07:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 9987109 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 E5BD56029B for ; Thu, 5 Oct 2017 13:08:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D700328C66 for ; Thu, 5 Oct 2017 13:08:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBCDF28C90; Thu, 5 Oct 2017 13:08:08 +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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8459428C66 for ; Thu, 5 Oct 2017 13:08:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6488C6E7DE; Thu, 5 Oct 2017 13:08:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 441966E7DD; Thu, 5 Oct 2017 13:08:06 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id l68so2079126wmd.5; Thu, 05 Oct 2017 06:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=iPCKRYotBG6ggqjz38fzyHbFky6sn8335IIh4xU4Lxk=; b=clFqZRuEUv1/RfKTFcWZibD1FNznsisjbilM6NW45n9SqYNFEukm/KIldBnV2H2Ii/ wfTlStjqUgun8xkkRq/cyrA8ADYJcnzY7QbLsXZYR5O0bwJL9IQM8F4lomiImCCBTGCt UGlUSU58d6XnbaLot6PJjVoSaf5L4bMotrukb4XQQ0LSjqto+yYFeTxk5vTJA81RFmGS F2vndKgfX7+WsQluUlA6AaUY0vj4kJLFLs+lwlHkufnXQhEKqd7wO4NHWAyk+zKanHq6 2f66715M0mytBYnd21CSN2tULr3qADWidxLu10rNLThgLHlZq8XGbJPKVgDYEZadYpv3 YVoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iPCKRYotBG6ggqjz38fzyHbFky6sn8335IIh4xU4Lxk=; b=gH8q7rpEM1/yvyWUie1PGZ7EcVOJK5MEeJpB2Dhma4yCZEJI7aspBvfcDxbstCNzZO 9TGJ6/pzdYyfoug85n0ScJ+u0zu9fT9hTW52Y1vN9dzHEAeIVv6jIzUXg6MmqWEU2L3R BIEGFJki1lo5B4h6GJoWyHb3Aqw4Ju+tpUc4XqT98AKtRQnxFExk4k5Zk/DzbLsExfJC JJfHVr+PhBdQWdkyHAFyunTU56jo8BNFC35lJ1J1MOluSYdXE3oerwoOpcPQp/sbp/66 C0UhuimivYGFFFwbgo9LAowFKdLzUHeQ3E+Q8VOUlBcyjPhQut1jHY9keNEARumI1P+y HmBg== X-Gm-Message-State: AMCzsaWJcDy/omThUN5S3tm1obkjNuq/tWtmWzXfE0lQePMpt/iZDBg3 4pretvqFAzfn4GCppoLW9seCErfY X-Google-Smtp-Source: AOwi7QDxvbNNmGOTWBr8vtmxFQ+1oEebrsIF/g/Kq/u6+fWXUNbtoMSCWCMVXkUzrMelnAv2Z91OvQ== X-Received: by 10.28.46.210 with SMTP id u201mr18782564wmu.64.1507208884613; Thu, 05 Oct 2017 06:08:04 -0700 (PDT) Received: from localhost.localdomain ([2a02:908:1251:7981:c12c:1293:87f3:cbfe]) by smtp.gmail.com with ESMTPSA id 133sm15002742wmu.4.2017.10.05.06.08.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Oct 2017 06:08:03 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/6] drm/ttm: DMA map/unmap consecutive pages as a whole v2 Date: Thu, 5 Oct 2017 15:07:50 +0200 Message-Id: <1507208874-3448-2-git-send-email-deathsimple@vodafone.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507208874-3448-1-git-send-email-deathsimple@vodafone.de> References: <1507208874-3448-1-git-send-email-deathsimple@vodafone.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Christian König Instead of mapping them bit by bit map/unmap all consecutive pages as in one call. v2: test for consecutive pages instead of using compound page order. Signed-off-by: Christian König Acked-by: Felix Kuehling --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 48 +++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 482dd9a..6c852e8 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -922,16 +922,26 @@ EXPORT_SYMBOL(ttm_pool_unpopulate); #if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU) int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt) { - unsigned i; + unsigned i, j; int r; r = ttm_pool_populate(&tt->ttm); if (r) return r; - for (i = 0; i < tt->ttm.num_pages; i++) { + for (i = 0; i < tt->ttm.num_pages; ++i) { + struct page *p = tt->ttm.pages[i]; + size_t num_pages = 1; + + for (j = i + 1; j < tt->ttm.num_pages; ++j) { + if (++p != tt->ttm.pages[j]) + break; + + ++num_pages; + } + tt->dma_address[i] = dma_map_page(dev, tt->ttm.pages[i], - 0, PAGE_SIZE, + 0, num_pages * PAGE_SIZE, DMA_BIDIRECTIONAL); if (dma_mapping_error(dev, tt->dma_address[i])) { while (i--) { @@ -942,6 +952,11 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt) ttm_pool_unpopulate(&tt->ttm); return -EFAULT; } + + for (j = 1; j < num_pages; ++j) { + tt->dma_address[i + 1] = tt->dma_address[i] + PAGE_SIZE; + ++i; + } } return 0; } @@ -949,13 +964,28 @@ EXPORT_SYMBOL(ttm_populate_and_map_pages); void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt) { - unsigned i; - - for (i = 0; i < tt->ttm.num_pages; i++) { - if (tt->dma_address[i]) { - dma_unmap_page(dev, tt->dma_address[i], - PAGE_SIZE, DMA_BIDIRECTIONAL); + unsigned i, j; + + for (i = 0; i < tt->ttm.num_pages;) { + struct page *p = tt->ttm.pages[i]; + size_t num_pages = 1; + + if (!tt->dma_address[i] || !tt->ttm.pages[i]) { + ++i; + continue; } + + for (j = i + 1; j < tt->ttm.num_pages; ++j) { + if (++p != tt->ttm.pages[j]) + break; + + ++num_pages; + } + + dma_unmap_page(dev, tt->dma_address[i], num_pages * PAGE_SIZE, + DMA_BIDIRECTIONAL); + + i += num_pages; } ttm_pool_unpopulate(&tt->ttm); }