From patchwork Fri Aug 24 10:50:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaohui xie X-Patchwork-Id: 179828 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 13B942C03FB for ; Fri, 24 Aug 2012 21:21:03 +1000 (EST) Received: from tx2outboundpool.messaging.microsoft.com (tx2ehsobe005.messaging.microsoft.com [65.55.88.15]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client CN "mail.global.frontbridge.com", Issuer "Microsoft Secure Server Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 4E5922C00BF for ; Fri, 24 Aug 2012 21:20:38 +1000 (EST) Received: from mail23-tx2-R.bigfish.com (10.9.14.250) by TX2EHSOBE008.bigfish.com (10.9.40.28) with Microsoft SMTP Server id 14.1.225.23; Fri, 24 Aug 2012 11:20:33 +0000 Received: from mail23-tx2 (localhost [127.0.0.1]) by mail23-tx2-R.bigfish.com (Postfix) with ESMTP id 6F4DF600FB for ; Fri, 24 Aug 2012 11:20:33 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839he5bhf0ah107ah) Received: from mail23-tx2 (localhost.localdomain [127.0.0.1]) by mail23-tx2 (MessageSwitch) id 1345807232205654_8936; Fri, 24 Aug 2012 11:20:32 +0000 (UTC) Received: from TX2EHSMHS009.bigfish.com (unknown [10.9.14.247]) by mail23-tx2.bigfish.com (Postfix) with ESMTP id 24B77180090 for ; Fri, 24 Aug 2012 11:20:32 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS009.bigfish.com (10.9.99.109) with Microsoft SMTP Server (TLS) id 14.1.225.23; Fri, 24 Aug 2012 11:20:32 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server (TLS) id 14.2.309.3; Fri, 24 Aug 2012 06:20:31 -0500 Received: from localhost.localdomain (rock.ap.freescale.net [10.193.20.106]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id q7OBKSoC031144; Fri, 24 Aug 2012 04:20:29 -0700 From: Shaohui Xie To: Subject: [PATCH][v2] powerpc/mm: using two zones for freescale 64 bit kernel Date: Fri, 24 Aug 2012 18:50:25 +0800 Message-ID: <1345805425-3829-1-git-send-email-Shaohui.Xie@freescale.com> X-Mailer: git-send-email 1.6.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Cc: Mingkai Hu , Shaohui Xie , Chen Yuanquan X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" PowerPC platform only supports ZONE_DMA zone for 64bit kernel, so all the memory will be put into this zone. If the memory size is greater than the device's DMA capability and device uses dma_alloc_coherent to allocate memory, it will get an address which is over the device's DMA addressing, the device will fail. So we split the memory to two zones: zone ZONE_DMA32 & ZONE_NORMAL, since we already allocate PCICSRBAR/PEXCSRBAR right below the 4G boundary (if the lowest PCI address is above 4G), so we constrain the DMA zone ZONE_DMA32 to 2GB, also, we clear flag __GFP_DMA & __GFP_DMA32 and set __GFP_DMA32 only if the device's dma_mask < total memory size. By doing this, devices which cannot DMA all the memory will be limited to ZONE_DMA32, but devices which can DMA all the memory will not be affected by this limitation. Signed-off-by: Shaohui Xie Signed-off-by: Mingkai Hu Signed-off-by: Chen Yuanquan --- changes for v2: 1. use a config option for using two zones (ZONE_DMA32 & ZONE_NORMAL) in freescale 64 bit kernel. arch/powerpc/Kconfig | 3 +++ arch/powerpc/kernel/dma.c | 15 +++++++++++++++ arch/powerpc/mm/mem.c | 4 ++++ 3 files changed, 22 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 352f416..a96fbbb 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -629,6 +629,9 @@ config ZONE_DMA bool default y +config ZONE_DMA32 + def_bool (PPC64 && PPC_FSL_BOOK3E) + config NEED_DMA_MAP_STATE def_bool (PPC64 || NOT_COHERENT_CACHE) diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c index 355b9d8..cbf5ac1 100644 --- a/arch/powerpc/kernel/dma.c +++ b/arch/powerpc/kernel/dma.c @@ -41,9 +41,24 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t size, #else struct page *page; int node = dev_to_node(dev); +#ifdef CONFIG_ZONE_DMA32 + phys_addr_t top_ram_pfn = memblock_end_of_DRAM(); + /* + * check for crappy device which has dma_mask < ZONE_DMA, and + * we are not going to support it, just warn and fail. + */ + if (*dev->dma_mask < DMA_BIT_MASK(31)) { + dev_err(dev, "Unsupported dma_mask 0x%llx\n", *dev->dma_mask); + return NULL; + } /* ignore region specifiers */ + flag &= ~(__GFP_HIGHMEM | __GFP_DMA | __GFP_DMA32); + if (*dev->dma_mask < top_ram_pfn - 1) + flag |= __GFP_DMA32; +#else flag &= ~(__GFP_HIGHMEM); +#endif page = alloc_pages_node(node, flag, get_order(size)); if (page == NULL) diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c index baaafde..2a11e49 100644 --- a/arch/powerpc/mm/mem.c +++ b/arch/powerpc/mm/mem.c @@ -280,6 +280,10 @@ void __init paging_init(void) #ifdef CONFIG_HIGHMEM max_zone_pfns[ZONE_DMA] = lowmem_end_addr >> PAGE_SHIFT; max_zone_pfns[ZONE_HIGHMEM] = top_of_ram >> PAGE_SHIFT; +#elif defined CONFIG_ZONE_DMA32 + max_zone_pfns[ZONE_DMA32] = min_t(phys_addr_t, top_of_ram, + 1ull << 31) >> PAGE_SHIFT; + max_zone_pfns[ZONE_NORMAL] = top_of_ram >> PAGE_SHIFT; #else max_zone_pfns[ZONE_DMA] = top_of_ram >> PAGE_SHIFT; #endif