From patchwork Thu Feb 14 12:45:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 14798 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3242523F72 for ; Thu, 14 Feb 2013 12:46:03 +0000 (UTC) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by fiordland.canonical.com (Postfix) with ESMTP id C67F2A1840D for ; Thu, 14 Feb 2013 12:46:02 +0000 (UTC) Received: by mail-vc0-f181.google.com with SMTP id d16so1420436vcd.26 for ; Thu, 14 Feb 2013 04:46:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:date:message-id:x-mailer:in-reply-to :references:x-brightmail-tracker:cc:subject:x-beenthere :x-mailman-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=DYsB1+ndIbNFU2z6PsZhE05RdYJzGJ4olrHl7N8rWFE=; b=LVzsZ4Bq8cpV2bW+VZP6EPUHAx//S/C6QGGqBJck2kLWi7lYNsq9tIeDbfM8eDakow 81fafwt0nQ4GtRRJNOtiwsTleuws80H6R/Por00IWxIWVXfiaM3zt43SXtnz9LFmVfy9 1QARCncY7eGPGsyjx3SGfWBnin6PI/pyEpuBeyx+Q2PBZVryhwRNfDG/1oQVrn+7kjz2 RXNg2O9Yi5MYls8TBQ5+HqUGMXEKD02z5eMdwZebHg26hisbsYKE1xSlyIkum2Z13ziS Cq8yf+PBRMGuv7+q3iWzMghZUkL2TI4wsrr/16hEbzqYSbW1mlnKoca7yT83WoRx3jVp VDDA== X-Received: by 10.52.33.167 with SMTP id s7mr24834174vdi.52.1360845962220; Thu, 14 Feb 2013 04:46:02 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp258290vcb; Thu, 14 Feb 2013 04:46:01 -0800 (PST) X-Received: by 10.14.214.66 with SMTP id b42mr17218546eep.34.1360845960499; Thu, 14 Feb 2013 04:46:00 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id w41si10639955eel.205.2013.02.14.04.45.59; Thu, 14 Feb 2013 04:46:00 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1U5yCN-0004ij-2I; Thu, 14 Feb 2013 12:45:59 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1U5yCL-0004iJ-0s for linaro-mm-sig@lists.linaro.org; Thu, 14 Feb 2013 12:45:57 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MI70031FNF1US70@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Feb 2013 21:45:55 +0900 (KST) X-AuditID: cbfee61b-b7fb06d000000f28-10-511cdc8341ef Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 8D.48.03880.38CDC115; Thu, 14 Feb 2013 21:45:55 +0900 (KST) Received: from localhost.localdomain ([106.116.147.30]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MI7002HQNG3EJ20@mmp2.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Feb 2013 21:45:55 +0900 (KST) From: Marek Szyprowski To: linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree-discuss@lists.ozlabs.org Date: Thu, 14 Feb 2013 13:45:28 +0100 Message-id: <1360845928-8107-3-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1360845928-8107-1-git-send-email-m.szyprowski@samsung.com> References: <1360845928-8107-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jQd3mOzKBBjPXm1t8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGTcuL2EuOGdTcXTHdvYGxluGXYycHBICJhK7N05gg7DFJC7c Ww9kc3EICUxnlHjc0sgM4axikji7ZRITSBWbgKFE19suoCoODhGBfInVs3hBapgFPjFKrJ+x ih2kRlggWGL7xg1gU1kEVCWWrL8KFucVcJe4/HA7WK+EgILEnEk2IGFOAQ+JlU1nWUBsIaCS mxM2ME9g5F3AyLCKUTS1ILmgOCk910ivODG3uDQvXS85P3cTI9jnz6R3MK5qsDjEKMDBqMTD q/BLOlCINbGsuDL3EKMEB7OSCO/LQJlAId6UxMqq1KL8+KLSnNTiQ4zSHCxK4ryMp54ECAmk J5akZqemFqQWwWSZODilGhglaneEm+57cpf31qOG5c/YPkh+2uUjGbym6PqCP9c6LOu1HF+d bJ2d3GF371dLRYhOcOQvn8M7tRzbfz35qb/92apfJi+TJ37P/MLAfqeid+th62z7upMRjc5J vhm/TadWfr4hbM6xe+n6Ced+n5tXJLXF+jXTx48V3kkzH0XZ2E3Z9bViHU+2EktxRqKhFnNR cSIAQgTZTPUBAAA= Cc: Arnd Bergmann , Tomasz Figa , Michal Nazarewicz , Grant Likely , Kyungmin Park Subject: [Linaro-mm-sig] [PATCH 2/2] drivers: dma-contiguous: add initialization from device tree X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQnrHnctWXXNo9A8IeDjNpcVgvHroLElpEva5ZPqVGNPNgVXFG/DOQJHbW+d/Lj/o/l0uz39 Add device tree support for contiguous memory regions defined in device tree. Initialization is done in 2 steps. First, the contiguous memory is reserved, what happens very early, when only flattened device tree is available. Then on device initialization the corresponding cma regions are assigned to device structures. Signed-off-by: Marek Szyprowski Acked-by: Kyungmin Park --- Documentation/devicetree/bindings/memory.txt | 101 ++++++++++++++++++++++++++ arch/arm/boot/dts/skeleton.dtsi | 7 +- drivers/base/dma-contiguous.c | 72 ++++++++++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/memory.txt diff --git a/Documentation/devicetree/bindings/memory.txt b/Documentation/devicetree/bindings/memory.txt new file mode 100644 index 0000000..74e0476 --- /dev/null +++ b/Documentation/devicetree/bindings/memory.txt @@ -0,0 +1,101 @@ +* Memory binding + +The /memory node provides basic information about the address and size +of the physical memory. This node is usually filled or updated by the +bootloader, depending on the actual memory configuration of the given +hardware. + +The memory layout is described by the folllowing node: + +memory { + reg = <(baseaddr1) (size1) + (baseaddr2) (size2) + ... + (baseaddrN) (sizeN)>; +}; + +baseaddrX: the base address of the defined memory bank +sizeX: the size of the defined memory bank + +More than one memory bank can be defined. + + +* Memory regions + +In /memory node one can create additional nodes describing particular +memory regions, usually for the special usage by various device drivers. +A good example are contiguous memory allocations or memory sharing with +other operating system on the same hardware board. Those special memory +regions might depend on the board configuration and devices used on the +target system. + +Parameters for each memory region can be encoded into the device tree +wit the following convention: + +(name): region@(base-address) { + reg = <(baseaddr) (size)>; + (linux,contiguous-region); + (linux,default-contiguous-region); +}; + +name: an name given to the defined region. +base-address: the base address of the defined region. +size: the size of the memory region. +linux,contiguous-region: property indicating that the defined memory + region is used for contiguous memory allocations, + Linux specific (optional) +linux,default-contiguous-region: property indicating that the region + is the default region for all contiguous memory + allocations, Linux specific (optional) + + +* Device nodes + +Once the regions in the /memory node are defined, they can be assigned +to device some device nodes for their special use. The following +properties are defined: + +linux,contiguous-region = <&phandle>; + This property indicates that the device driver should use the + memory region pointed by the given phandle. + + +* Example: + +This example defines a memory consisting of 4 memory banks. 2 contiguous +regions are defined for Linux kernel, one default of all device drivers +(named contig_mem, placed at 0x72000000, 64MiB) and one dedicated to the +framebuffer device (named display_mem, placed at 0x78000000, 16MiB). The +display_mem region is then assigned to fb@12300000 device for contiguous +memory allocation with Linux kernel drivers. + +The reason for creating a separate region for framebuffer device is to +match the framebuffer address of from configuration done by bootloader, +so once Linux kernel drivers starts, no glitches on the displayed boot +logo appears. + +/ { + /* ... */ + memory { + reg = <0x40000000 0x10000000 + 0x50000000 0x10000000 + 0x60000000 0x10000000 + 0x70000000 0x10000000>; + + contig_mem: region@72000000 { + linux,contiguous-region; + linux,default-contiguous-region; + reg = <0x72000000 0x4000000>; + }; + + display_mem: region@78000000 { + linux,contiguous-region; + reg = <0x78000000 0x1000000>; + }; + }; + + fb@12300000 { + linux,contiguous-region = <&display_mem>; + status = "okay"; + }; +}; diff --git a/arch/arm/boot/dts/skeleton.dtsi b/arch/arm/boot/dts/skeleton.dtsi index b41d241..f9988cd 100644 --- a/arch/arm/boot/dts/skeleton.dtsi +++ b/arch/arm/boot/dts/skeleton.dtsi @@ -9,5 +9,10 @@ #size-cells = <1>; chosen { }; aliases { }; - memory { device_type = "memory"; reg = <0 0>; }; + memory { + #address-cells = <1>; + #size-cells = <1>; + device_type = "memory"; + reg = <0 0>; + }; }; diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 085389c..5761f73 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -24,6 +24,9 @@ #include #include +#include +#include +#include #include #include #include @@ -177,6 +180,35 @@ no_mem: return ERR_PTR(ret); } +/*****************************************************************************/ + +#ifdef CONFIG_OF +int __init cma_fdt_scan(unsigned long node, const char *uname, + int depth, void *data) +{ + phys_addr_t base, size; + unsigned long len; + __be32 *prop; + + if (strncmp(uname, "region@", 7) != 0 || depth != 2 || + !of_get_flat_dt_prop(node, "contiguous-region", NULL)) + return 0; + + prop = of_get_flat_dt_prop(node, "reg", &len); + if (!prop || (len != 2 * sizeof(unsigned long))) + return 0; + + base = be32_to_cpu(prop[0]); + size = be32_to_cpu(prop[1]); + + pr_info("Found %s, memory base %lx, size %ld MiB\n", uname, + (unsigned long)base, (unsigned long)size / SZ_1M); + dma_contiguous_reserve_area(size, &base, 0); + + return 0; +} +#endif + /** * dma_contiguous_reserve() - reserve area for contiguous memory handling * @limit: End address of the reserved memory (optional, 0 for any). @@ -215,6 +247,9 @@ void __init dma_contiguous_reserve(phys_addr_t limit) if (dma_contiguous_reserve_area(sel_size, &base, limit) == 0) dma_contiguous_def_base = base; } +#ifdef CONFIG_OF + of_scan_flat_dt(cma_fdt_scan, NULL); +#endif }; /** @@ -319,6 +354,40 @@ int __init dma_contiguous_add_device(struct device *dev, phys_addr_t base) return 0; } +#ifdef CONFIG_OF +static void cma_assign_device_from_dt(struct device *dev) +{ + struct device_node *node; + struct cma *cma; + u32 value; + + node = of_parse_phandle(dev->of_node, "linux,contiguous-region", 0); + if (!node) + return; + if (of_property_read_u32(node, "reg", &value) && !value) + return; + cma = cma_get_area(value); + if (!cma) + return; + + dev_set_cma_area(dev, cma); + pr_info("Assigned CMA region at %lx to %s device\n", (unsigned long)value, dev_name(dev)); +} + +static int cma_device_init_notifier_call(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct device *dev = data; + if (event == BUS_NOTIFY_ADD_DEVICE && dev->of_node) + cma_assign_device_from_dt(dev); + return NOTIFY_DONE; +} + +static struct notifier_block cma_dev_init_nb = { + .notifier_call = cma_device_init_notifier_call, +}; +#endif + static int __init cma_init_reserved_areas(void) { struct cma *cma; @@ -340,6 +409,9 @@ static int __init cma_init_reserved_areas(void) dev_set_cma_area(cma_maps[i].dev, cma); } +#ifdef CONFIG_OF + bus_register_notifier(&platform_bus_type, &cma_dev_init_nb); +#endif return 0; } core_initcall(cma_init_reserved_areas);