From patchwork Thu Oct 23 17:27:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 39391 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1C0E620341 for ; Thu, 23 Oct 2014 17:35:58 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id p9sf994145lbv.0 for ; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) 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:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=IIGFp+I04/ZeD57R3TW0zohpfiFABazseFtYWqryErk=; b=cNudTp9qA38tI37RWzksvHoLDcyQjY2pssd68Hwnm9EMxjM+QjxKlKXN9LIZLNT41w zt9kA2+gR269kUQD/Z89sFaFfBGE41OPgOwgqUffAVHxsR95wPjuEFWRdhYW6DqA6wqZ +Awf7Cyk7OY6QpgqN4J+CeNZM7cSIyX1W1B5eLpNqD112kcX61V1kFs4Ydn7JWTNHeud ncavEKcrQ4MAWXxns/gP2OMGP2ZRlBqufn/MxdxwYajRlDc2LbuJI51Y5iCUm+dIA8i7 necZnJk8GYhU7+ifLE+3kAxFa1pJ/4w41SQkmNH+1+O3M97tqp1kKNOqoql41CY3K37N B78A== X-Gm-Message-State: ALoCoQk2o/GK+IAOKn4Eo+75lZ9UaenAlUnHuGdBoMsLlETYvuOY6CKL/jBOsshvLlrLkpCq/hYn X-Received: by 10.112.147.131 with SMTP id tk3mr1336895lbb.2.1414085757916; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.167 with SMTP id uf7ls352063lac.100.gmail; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) X-Received: by 10.152.30.33 with SMTP id p1mr6618337lah.78.1414085757475; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id q9si3627530lag.92.2014.10.23.10.35.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Oct 2014 10:35:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id gi9so1270239lab.5 for ; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) X-Received: by 10.152.5.38 with SMTP id p6mr6709759lap.44.1414085757359; Thu, 23 Oct 2014 10:35:57 -0700 (PDT) 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.84.229 with SMTP id c5csp296075lbz; Thu, 23 Oct 2014 10:35:56 -0700 (PDT) X-Received: by 10.52.142.207 with SMTP id ry15mr1722868vdb.80.1414085755897; Thu, 23 Oct 2014 10:35:55 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id cv7si1371998vcb.2.2014.10.23.10.35.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Oct 2014 10:35:55 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XhMHz-0002MT-01; Thu, 23 Oct 2014 17:35:07 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XhMHx-0002Kl-DP for xen-devel@lists.xensource.com; Thu, 23 Oct 2014 17:35:05 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id A3/C2-02699-84C39445; Thu, 23 Oct 2014 17:35:04 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1414085700!12216351!4 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n X-StarScan-Received: X-StarScan-Version: 6.12.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3051 invoked from network); 23 Oct 2014 17:35:04 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-15.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 23 Oct 2014 17:35:04 -0000 X-IronPort-AV: E=Sophos;i="5.04,776,1406592000"; d="scan'208";a="184362056" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Thu, 23 Oct 2014 13:30:06 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XhMD2-00085f-LY; Thu, 23 Oct 2014 18:30:00 +0100 From: Stefano Stabellini To: Date: Thu, 23 Oct 2014 18:27:24 +0100 Message-ID: <1414085246-16160-4-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 Cc: Ian.Campbell@citrix.com, Stefano Stabellini , will.deacon@arm.com, linux-kernel@vger.kernel.org, david.vrabel@citrix.com, linux-arm-kernel@lists.infradead.org Subject: [Xen-devel] [PATCH v5 4/6] xen/arm/arm64: merge xen/mm32.c into xen/mm.c X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.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.46 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-Archive: Merge xen/mm32.c into xen/mm.c. As a consequence the code gets compiled on arm64 too: introduce a few compat functions to actually be able to compile it. Introduce xen_is_dma_coherent on arm64 and call into the dma_ops functions from the xen_dma wrappers in page-coherent.h to handle non-coherent devices. Signed-off-by: Stefano Stabellini Acked-by: Ian Campbell --- Changes in v5: - introduce xen_is_dma_coherent to arch/arm64/include/asm/xen/page-coherent.h; - do not remove arch/arm64/include/asm/xen/page-coherent.h, add the missing dma_ops calls from it. --- arch/arm/xen/Makefile | 2 +- arch/arm/xen/mm.c | 124 ++++++++++++++++++++++++++++ arch/arm/xen/mm32.c | 110 ------------------------ arch/arm64/include/asm/xen/page-coherent.h | 25 +++--- 4 files changed, 138 insertions(+), 123 deletions(-) delete mode 100644 arch/arm/xen/mm32.c diff --git a/arch/arm/xen/Makefile b/arch/arm/xen/Makefile index 1f85bfe..1296952 100644 --- a/arch/arm/xen/Makefile +++ b/arch/arm/xen/Makefile @@ -1 +1 @@ -obj-y := enlighten.o hypercall.o grant-table.o p2m.o mm.o mm32.o +obj-y := enlighten.o hypercall.o grant-table.o p2m.o mm.o diff --git a/arch/arm/xen/mm.c b/arch/arm/xen/mm.c index b0e77de..659e1c3 100644 --- a/arch/arm/xen/mm.c +++ b/arch/arm/xen/mm.c @@ -1,5 +1,8 @@ +#include +#include #include #include +#include #include #include #include @@ -13,9 +16,130 @@ #include #include +#include #include #include + +#ifdef CONFIG_ARM64 +static inline void dmac_map_area(const void *start, size_t size, int dir) +{ + return __dma_map_area(start, size, dir); +} + +static inline void dmac_unmap_area(const void *start, size_t size, int dir) +{ + return __dma_unmap_area(start, size, dir); +} + +static inline bool cache_is_vipt_nonaliasing(void) +{ + return true; +} + +static inline void *kmap_high_get(struct page *page) +{ + return NULL; +} + +static inline void kunmap_high(struct page *page) {} +#endif + + +/* 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)) +{ + unsigned long pfn; + size_t left = size; + + pfn = (handle >> PAGE_SHIFT) + offset / PAGE_SIZE; + offset %= PAGE_SIZE; + + 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); + } + } + + offset = 0; + pfn++; + left -= len; + } while (left); +} + +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); +} + +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); +} + +void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, + size_t size, enum dma_data_direction dir, + struct dma_attrs *attrs) + +{ + if (xen_is_dma_coherent(hwdev)) + return; + if (dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) + return; + + __xen_dma_page_dev_to_cpu(hwdev, handle, size, dir); +} + +void xen_dma_sync_single_for_cpu(struct device *hwdev, + dma_addr_t handle, size_t size, enum dma_data_direction dir) +{ + if (xen_is_dma_coherent(hwdev)) + return; + __xen_dma_page_dev_to_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) +{ + if (xen_is_dma_coherent(hwdev)) + return; + __xen_dma_page_cpu_to_dev(hwdev, handle, size, dir); +} + int xen_create_contiguous_region(phys_addr_t pstart, unsigned int order, unsigned int address_bits, dma_addr_t *dma_handle) diff --git a/arch/arm/xen/mm32.c b/arch/arm/xen/mm32.c deleted file mode 100644 index 6c0224e..0000000 --- a/arch/arm/xen/mm32.c +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include -#include -#include - -#include - - -/* 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)) -{ - unsigned long pfn; - size_t left = size; - - pfn = (handle >> PAGE_SHIFT) + offset / PAGE_SIZE; - offset %= PAGE_SIZE; - - 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); - } - } - - offset = 0; - pfn++; - left -= len; - } while (left); -} - -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); -} - -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); -} - -void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, - size_t size, enum dma_data_direction dir, - struct dma_attrs *attrs) - -{ - if (xen_is_dma_coherent(hwdev)) - return; - if (dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs)) - return; - - __xen_dma_page_dev_to_cpu(hwdev, handle, size, dir); -} - -void xen_dma_sync_single_for_cpu(struct device *hwdev, - dma_addr_t handle, size_t size, enum dma_data_direction dir) -{ - if (xen_is_dma_coherent(hwdev)) - return; - __xen_dma_page_dev_to_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) -{ - if (xen_is_dma_coherent(hwdev)) - return; - __xen_dma_page_cpu_to_dev(hwdev, handle, size, dir); -} - -int __init xen_mm32_init(void) -{ - if (!xen_initial_domain()) - return 0; - - return 0; -} -arch_initcall(xen_mm32_init); diff --git a/arch/arm64/include/asm/xen/page-coherent.h b/arch/arm64/include/asm/xen/page-coherent.h index dde3fc9..c34132b 100644 --- a/arch/arm64/include/asm/xen/page-coherent.h +++ b/arch/arm64/include/asm/xen/page-coherent.h @@ -5,6 +5,11 @@ #include #include +static inline bool xen_is_dma_coherent(struct device *dev) +{ + return (__generic_dma_ops(dev) == &coherent_swiotlb_dma_ops); +} + 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) @@ -23,21 +28,17 @@ static inline void xen_dma_map_page(struct device *hwdev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { + __generic_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs); } -static inline 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) -{ -} + struct dma_attrs *attrs); -static inline 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_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_dma_sync_single_for_device(struct device *hwdev, - dma_addr_t handle, size_t size, enum dma_data_direction dir) -{ -} #endif /* _ASM_ARM64_XEN_PAGE_COHERENT_H */