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: 2141611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id D4FC13FCF6 for ; Thu, 14 Feb 2013 12:49:18 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U5yCv-0007Pb-MP; Thu, 14 Feb 2013 12:46:33 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U5yCP-0007KR-Ah for linux-arm-kernel@lists.infradead.org; Thu, 14 Feb 2013 12:46:08 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MI7005YQNGK9LC0@mailout1.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 14 Feb 2013 21:45:56 +0900 (KST) X-AuditID: cbfee61a-b7f7d6d000000f4e-f4-511cdc83ca62 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 76.4E.03918.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 linux-arm-kernel@lists.infradead.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 Subject: [PATCH 2/2] drivers: dma-contiguous: add initialization from device tree 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+NgFnrIJMWRmVeSWpSXmKPExsVy+t9jQd3mOzKBBo/Om1psenyN1YHRY/OS +gDGKC6blNSczLLUIn27BK6MG5eXMBecs6k4umM7ewPjLcMuRk4OCQETidsHZrBB2GISF+6t B7K5OIQEpjNKTJz2ihHC2cAksXh1OwtIFZuAoUTX2y6gKg4OEYF8idWzeEFqmAU+MUqsn7GK HaRGWCBYYvvGDWBTWQRUJZasvwoW5xVwl7j8cDtYr4SAgsScSTYgYU4BD4mVTWfBxgsBldyc sIF5AiPvAkaGVYyiqQXJBcVJ6bmGesWJucWleel6yfm5mxjBHn8mtYNxZYPFIUYBDkYlHl7F X9KBQqyJZcWVuYcYJTiYlUR4XwbKBArxpiRWVqUW5ccXleakFh9ilOZgURLnZTz1JEBIID2x JDU7NbUgtQgmy8TBKdXAqLv6s03b+pXxp3JYzSeammrsvXR40gnt5VtuMRdX3GdyaL4kVhTI lRuS8PvU66b8k9tWz1Fj6lXjmL/xbdlK09LlL7lZTi7yyK+8b9in7pI27dLb2PNb9nkekzwi JqEt/GTCQU32H2X6ZdO2zz7/X4WdXTbscJX2rAm3l0vrXVPJNPeqyWUVVmIpzkg01GIuKk4E ANqCUd30AQAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130214_074602_015118_ABA61F7B X-CRM114-Status: GOOD ( 22.45 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.24 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 T_FRT_FOLLOW1 BODY: ReplaceTags: Follow 0.0 T_FRT_FOLLOW2 BODY: ReplaceTags: Follow (2) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Arnd Bergmann , Tomasz Figa , Michal Nazarewicz , Grant Likely , Kyungmin Park , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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);