From patchwork Wed Nov 12 11:40:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 40656 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 77040206A5 for ; Wed, 12 Nov 2014 11:42:56 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id d17sf7976171eek.11 for ; Wed, 12 Nov 2014 03:42:55 -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=ehNQgvB7ZKtBA7/AbRtFfRTWZqsfu/W/0UjBAaXfBqo=; b=NbGyumgWDX8mKVIO+PJCva14W9cScANLU/SVIalhpVQdvteYMUuiuzbgqopPSSwQGM 5dN4XiTcgvDnDNXr1U3bzmX9EhXrxo7fLOP4rwiCxdkFCmFc9yDX1t/mDe6UaAXteFM0 JJz267b63oIdRpHJTlSKCMWdUwwUEqlbmBscGYfiIhQaiJuRATnQOX5I9I3VKHBaygYG PECHLJQDnv4y8T9h9oNSaFUAzzoApanQU3id+iH3WzZokWyvJM0Dh2E9nL7o0rhxs0tK xlxOFj6n4I1yxtn9fO3wkklj9KmOWXq+4OMehBBsIJEQDgZCaT7wJzChRuLUmKO82ztz vgqg== X-Gm-Message-State: ALoCoQmZRsQ54A8xR0glljBWkjHYqbCBRvPaSyb8Kzt1AJCmUwwVbg1tyv9MAWEgV6YCYAc/E9KQ X-Received: by 10.194.239.200 with SMTP id vu8mr2021563wjc.3.1415792575686; Wed, 12 Nov 2014 03:42:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.165 with SMTP id an5ls719442lac.92.gmail; Wed, 12 Nov 2014 03:42:55 -0800 (PST) X-Received: by 10.112.57.227 with SMTP id l3mr20914739lbq.68.1415792575006; Wed, 12 Nov 2014 03:42:55 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id lf2si34644922lac.52.2014.11.12.03.42.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Nov 2014 03:42:54 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id ge10so10891022lab.8 for ; Wed, 12 Nov 2014 03:42:54 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr41795413lah.56.1415792574857; Wed, 12 Nov 2014 03:42:54 -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 ew9csp408225lbc; Wed, 12 Nov 2014 03:42:54 -0800 (PST) X-Received: by 10.70.93.10 with SMTP id cq10mr46354567pdb.109.1415792573298; Wed, 12 Nov 2014 03:42:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ah9si14119401pad.124.2014.11.12.03.42.52 for ; Wed, 12 Nov 2014 03:42:53 -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 S1753054AbaKLLmv (ORCPT + 25 others); Wed, 12 Nov 2014 06:42:51 -0500 Received: from smtp02.citrix.com ([66.165.176.63]:20177 "EHLO SMTP02.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751782AbaKLLlS (ORCPT ); Wed, 12 Nov 2014 06:41:18 -0500 X-IronPort-AV: E=Sophos;i="5.07,368,1413244800"; d="scan'208";a="191920930" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Wed, 12 Nov 2014 06:41:14 -0500 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XoWIO-0003Gl-TP; Wed, 12 Nov 2014 11:41:08 +0000 From: Stefano Stabellini To: CC: , , , , , , , Stefano Stabellini Subject: [PATCH v9 03/13] xen/arm: if(pfn_valid(pfn)) call native dma_ops Date: Wed, 12 Nov 2014 11:40:44 +0000 Message-ID: <1415792454-23161-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.49 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 Reviewed-by: Catalin Marinas --- Changes in v9: - remove BUG_ON from the loop; - add static inline for xen_dma_unmap_page, xen_dma_sync_single_for_cpu, xen_dma_sync_single_for_device. --- arch/arm/include/asm/xen/page-coherent.h | 49 +++++++++++++++++++++++++---- arch/arm/xen/mm32.c | 50 +++++++----------------------- 2 files changed, 54 insertions(+), 45 deletions(-) diff --git a/arch/arm/include/asm/xen/page-coherent.h b/arch/arm/include/asm/xen/page-coherent.h index e8275ea..9cfd895 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) @@ -26,14 +35,42 @@ static inline void xen_dma_map_page(struct device *hwdev, struct page *page, __generic_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs); } -void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, +static inline 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); +static inline void xen_dma_sync_single_for_cpu(struct device *hwdev, + 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); +static inline void xen_dma_sync_single_for_device(struct device *hwdev, + 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..5bb8391 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,8 @@ 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); - } - } + /* TODO: cache flush */ offset = 0; pfn++; @@ -58,20 +34,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 +56,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 +64,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)