From patchwork Mon Nov 10 16:13:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 40509 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B9DF0218DE for ; Mon, 10 Nov 2014 16:16:52 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf4308233wiv.10 for ; Mon, 10 Nov 2014 08:16:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=AKcKUE1W+Ma7lligYxp+Nk9zNqx3RHOiD1d289qya7U=; b=MPY15KMF2cxt1IpA3dAlemTd3r6Ar4HiF6OiJNhuzXDUFywUtrUVjz7ZpsvidUwddp cvlyjfg6WffKZPlP829vO31SMyR+cYnmKSAVxHA6shcrRMCcDbvc8w9FY6oNEPflFVW4 QAf3fHmGH2Qfj8V6YhFUWLjXkhcM7BT/NLYQy79S0Zg4VIcpQaapX+lDrQMBj+dZqk/w /ZW6tzI88360j9mVUFXFAPh11RMl7SmvxHJ3aYiHM2hWB1QimXXkVqi/Ifzv52CkaSfT UULYZ0nkj7CZ2ysQV5khCf9DiykrzmIuKAARWj3j+OlpSjGKnqHnzo3hex5i0YDf9twB woIg== X-Gm-Message-State: ALoCoQlyGvbBcNstenmnesfZQPJ5y22Kv+O2jZNP/Krox5XPQqySrCocGmjcEA6dFDdpHe7gbamG X-Received: by 10.194.61.243 with SMTP id t19mr691801wjr.5.1415636210020; Mon, 10 Nov 2014 08:16:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.227 with SMTP id e3ls483163laa.69.gmail; Mon, 10 Nov 2014 08:16:49 -0800 (PST) X-Received: by 10.112.63.70 with SMTP id e6mr3195914lbs.93.1415636209695; Mon, 10 Nov 2014 08:16:49 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id y9si10353757lbw.115.2014.11.10.08.16.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 08:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gq15so8082343lab.1 for ; Mon, 10 Nov 2014 08:16:49 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr20891250lbc.66.1415636209586; Mon, 10 Nov 2014 08:16:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp116309lbc; Mon, 10 Nov 2014 08:16:48 -0800 (PST) X-Received: by 10.70.48.38 with SMTP id i6mr33372778pdn.74.1415636207878; Mon, 10 Nov 2014 08:16:47 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si16826622pdf.219.2014.11.10.08.16.47 for ; Mon, 10 Nov 2014 08:16:47 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753506AbaKJQQp (ORCPT + 25 others); Mon, 10 Nov 2014 11:16:45 -0500 Received: from smtp.citrix.com ([66.165.176.89]:48719 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753280AbaKJQPK (ORCPT ); Mon, 10 Nov 2014 11:15:10 -0500 X-IronPort-AV: E=Sophos;i="5.07,353,1413244800"; d="scan'208";a="189798981" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.79) with Microsoft SMTP Server id 14.3.181.6; Mon, 10 Nov 2014 11:14:23 -0500 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Xnrbd-0000Mx-V2; Mon, 10 Nov 2014 16:14:17 +0000 From: Stefano Stabellini To: CC: , , , , , , , Stefano Stabellini Subject: [PATCH v8 03/13] xen/arm: if(pfn_valid(pfn)) call native dma_ops Date: Mon, 10 Nov 2014 16:13:55 +0000 Message-ID: <1415636045-24669-3-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Remove code duplication in mm32.c by calling the native dma_ops if the page is a local page (not a foreign page). Use a simple pfn_valid(pfn) check to figure out if the page is local, exploiting the fact that dom0 is mapped 1:1, therefore pfn_valid always returns false when called on a foreign mfn. Suggested-by: Catalin Marinas Signed-off-by: Stefano Stabellini --- arch/arm/include/asm/xen/page-coherent.h | 43 ++++++++++++++++++++++-- arch/arm/xen/mm32.c | 52 ++++++++---------------------- 2 files changed, 53 insertions(+), 42 deletions(-) diff --git a/arch/arm/include/asm/xen/page-coherent.h b/arch/arm/include/asm/xen/page-coherent.h index e8275ea..d97b0b4 100644 --- a/arch/arm/include/asm/xen/page-coherent.h +++ b/arch/arm/include/asm/xen/page-coherent.h @@ -5,6 +5,15 @@ #include #include +void __xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs); +void __xen_dma_sync_single_for_cpu(struct device *hwdev, + dma_addr_t handle, size_t size, enum dma_data_direction dir); + +void __xen_dma_sync_single_for_device(struct device *hwdev, + dma_addr_t handle, size_t size, enum dma_data_direction dir); + static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags, struct dma_attrs *attrs) @@ -28,12 +37,40 @@ static inline void xen_dma_map_page(struct device *hwdev, struct page *page, void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir, - struct dma_attrs *attrs); + struct dma_attrs *attrs) +{ + unsigned long pfn = PFN_DOWN(handle); + /* Dom0 is mapped 1:1, so calling pfn_valid on a foreign mfn will + * always return false. If the page is local we can safely call the + * native dma_ops function, otherwise we call the xen specific + * function. */ + if (pfn_valid(pfn)) { + if (__generic_dma_ops(hwdev)->unmap_page) + __generic_dma_ops(hwdev)->unmap_page(hwdev, handle, size, dir, attrs); + } else + __xen_dma_unmap_page(hwdev, handle, size, dir, attrs); +} void xen_dma_sync_single_for_cpu(struct device *hwdev, - dma_addr_t handle, size_t size, enum dma_data_direction dir); + dma_addr_t handle, size_t size, enum dma_data_direction dir) +{ + unsigned long pfn = PFN_DOWN(handle); + if (pfn_valid(pfn)) { + if (__generic_dma_ops(hwdev)->sync_single_for_cpu) + __generic_dma_ops(hwdev)->sync_single_for_cpu(hwdev, handle, size, dir); + } else + __xen_dma_sync_single_for_cpu(hwdev, handle, size, dir); +} void xen_dma_sync_single_for_device(struct device *hwdev, - dma_addr_t handle, size_t size, enum dma_data_direction dir); + dma_addr_t handle, size_t size, enum dma_data_direction dir) +{ + unsigned long pfn = PFN_DOWN(handle); + if (pfn_valid(pfn)) { + if (__generic_dma_ops(hwdev)->sync_single_for_device) + __generic_dma_ops(hwdev)->sync_single_for_device(hwdev, handle, size, dir); + } else + __xen_dma_sync_single_for_device(hwdev, handle, size, dir); +} #endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */ diff --git a/arch/arm/xen/mm32.c b/arch/arm/xen/mm32.c index 6153d61..b26bf84 100644 --- a/arch/arm/xen/mm32.c +++ b/arch/arm/xen/mm32.c @@ -4,13 +4,15 @@ #include #include - +enum dma_cache_op { + DMA_UNMAP, + DMA_MAP, +}; /* functions called by SWIOTLB */ static void dma_cache_maint(dma_addr_t handle, unsigned long offset, - size_t size, enum dma_data_direction dir, - void (*op)(const void *, size_t, int)) + size_t size, enum dma_data_direction dir, enum dma_cache_op op) { unsigned long pfn; size_t left = size; @@ -20,34 +22,10 @@ static void dma_cache_maint(dma_addr_t handle, unsigned long offset, do { size_t len = left; - void *vaddr; - if (!pfn_valid(pfn)) - { - /* TODO: cache flush */ - } else { - struct page *page = pfn_to_page(pfn); - - if (PageHighMem(page)) { - if (len + offset > PAGE_SIZE) - len = PAGE_SIZE - offset; - - if (cache_is_vipt_nonaliasing()) { - vaddr = kmap_atomic(page); - op(vaddr + offset, len, dir); - kunmap_atomic(vaddr); - } else { - vaddr = kmap_high_get(page); - if (vaddr) { - op(vaddr + offset, len, dir); - kunmap_high(page); - } - } - } else { - vaddr = page_address(page) + offset; - op(vaddr, len, dir); - } - } + BUG_ON(pfn_valid(pfn)); + + /* TODO: cache flush */ offset = 0; pfn++; @@ -58,20 +36,16 @@ static void dma_cache_maint(dma_addr_t handle, unsigned long offset, static void __xen_dma_page_dev_to_cpu(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { - /* Cannot use __dma_page_dev_to_cpu because we don't have a - * struct page for handle */ - - dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, dmac_unmap_area); + dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_UNMAP); } static void __xen_dma_page_cpu_to_dev(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { - - dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, dmac_map_area); + dma_cache_maint(handle & PAGE_MASK, handle & ~PAGE_MASK, size, dir, DMA_MAP); } -void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, +void __xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) @@ -84,7 +58,7 @@ void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, __xen_dma_page_dev_to_cpu(hwdev, handle, size, dir); } -void xen_dma_sync_single_for_cpu(struct device *hwdev, +void __xen_dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { if (!__generic_dma_ops(hwdev)->sync_single_for_cpu) @@ -92,7 +66,7 @@ void xen_dma_sync_single_for_cpu(struct device *hwdev, __xen_dma_page_dev_to_cpu(hwdev, handle, size, dir); } -void xen_dma_sync_single_for_device(struct device *hwdev, +void __xen_dma_sync_single_for_device(struct device *hwdev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { if (!__generic_dma_ops(hwdev)->sync_single_for_device)