From patchwork Fri Feb 21 12:25:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 25109 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D568820143 for ; Fri, 21 Feb 2014 12:27:01 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id x3sf6050266qcv.5 for ; Fri, 21 Feb 2014 04:27:01 -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:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=Vw1SQGS/o3nPNoyWeqqm6BNI2kk9WH+ru0K2EXpY1yo=; b=Wj7iak8+69/fNdEpZSE9kFaP2runkT78qrGjufT4DJcgxYBx9O1pjOY+mocXI4IK4C QetVa6+QXzZE3iG5oLFEmeFgEfCyMuQd6Jf3VEXuDzgA1gjg1xVCqL0XbFbl5RvrZ70p dgAqKKF5XSaETZvwM6SpjW/0ZeygkjMRo45sR2E4+pGlnbBSBMVwfCV2pJ1Iv1GyU5e6 7rjUlU6TMlsojLxg41a4xhjAAh9R7tdMI50ejTRpM9TPd+wyOIwvpH2RrhZWDL3VurvJ S1yVKj+kEZnyHMybBcflzR7Mo8tpa3UctTAjl2D4RzpJzDlFNQsqUDUcujWpvdOv34I3 4yfw== X-Gm-Message-State: ALoCoQkYEtT/ooBgsakjGEsJcJy0H7cz4X66UUHFgp3na2wv89VP2FwG4KNHqvGZFbmfU91Dqvgc X-Received: by 10.236.118.38 with SMTP id k26mr3317328yhh.35.1392985621686; Fri, 21 Feb 2014 04:27:01 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.139 with SMTP id f11ls942397qgf.71.gmail; Fri, 21 Feb 2014 04:27:01 -0800 (PST) X-Received: by 10.220.2.199 with SMTP id 7mr4633491vck.4.1392985621540; Fri, 21 Feb 2014 04:27:01 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id y6si2906156veb.139.2014.02.21.04.27.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Feb 2014 04:27:01 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id lf12so3207709vcb.17 for ; Fri, 21 Feb 2014 04:27:01 -0800 (PST) X-Received: by 10.220.191.134 with SMTP id dm6mr4684423vcb.16.1392985621444; Fri, 21 Feb 2014 04:27:01 -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.220.174.196 with SMTP id u4csp30064vcz; Fri, 21 Feb 2014 04:27:00 -0800 (PST) X-Received: by 10.14.9.134 with SMTP id 6mr8095256eet.70.1392985620510; Fri, 21 Feb 2014 04:27:00 -0800 (PST) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id t41si15785727eeg.231.2014.02.21.04.26.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 21 Feb 2014 04:27:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WGpAh-0004Hl-UB; Fri, 21 Feb 2014 12:25:39 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1WGpA5-0004D9-Ai for linaro-mm-sig@lists.linaro.org; Fri, 21 Feb 2014 12:25:01 +0000 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N1C00EF1IJJYF90@mailout2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 21 Feb 2014 12:26:07 +0000 (GMT) X-AuditID: cbfec7f4-b7f796d000005a13-92-530745e39c67 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 2E.21.23059.3E547035; Fri, 21 Feb 2014 12:26:11 +0000 (GMT) Received: from amdc1339.mshome.net ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N1C001ZAIJD5M60@eusync3.samsung.com>; Fri, 21 Feb 2014 12:26:11 +0000 (GMT) From: Marek Szyprowski To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org Date: Fri, 21 Feb 2014 13:25:20 +0100 Message-id: <1392985527-6260-5-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1392985527-6260-1-git-send-email-m.szyprowski@samsung.com> References: <1392985527-6260-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAyXRe0hTYRgGcL+zc5mjwWmZHKSWDQRJvFXQR0gNwvpACGFBFkEuXWo4XVuT LKHhjbmmznnFu03NhrpYpU6s3BoqlpZ4mVBqc6E4l2ZKUE7J6X8/nveB54+XzeLp8CB2WsYD iTxDnC4gOfjH3eHpcFcsJYryzEO4ox+i4K/cAhZcb9cC2GQfJ2Cpp4WAg94+AD3FahxautcA HMv1ULC3qIaCW1NODJpdMwRsKWzF4WR/PQm77HMUfLlixWCbYwKDzcP5BPRW8+GoY5OEnXYD BXXVXTgseGun4E6vGYduayEOTTWrODT2ewFc2RjBhcdQZ2MnQNv/9ACtlusAmiwpxpCldo5C Wk8+gczGIhJ9mxkg0avWJ+jrrouFpkZyCdTtdWOodCcKNfSXAFTy2gjQppkff/gmJyZZkp6W JZFHXkjkpH5w1uIye8hDq+UNpgImvgb4sxn6LLPbU0UeOJD5Mm/aN49uA8z0iuzATzHGVCPw maSjGc1PzX4ngG4BzGYjrgEcNoteIBn1hBbzHY7Q15k+QzXwGadDmC3PCOEzl77CFC993zN7 byyYqdfH+GJ/GjGfBpcpX8zbq3Sr7+kAtxn4GcFRiTJJpriTIo2OUIilCmVGSkRSptQMDr64 1QcMQ+dtgGYDwSGujCFFPEKcpciW2gDDZgkCuNZISsTjJouzH0nkmbflynSJwgYwtn+QCmiD hapnsXnyi++XF3vWLTa/z3GG+7aOUFZRXcPvtccF4dcaxtpPuOPr6tRhCVdfVD2fSBLOnibc o6IzfFw/61RJXWHnqhor+PGLdkdCYhN2d/sdGWhOy7u1s1FZXrZMLnXEJt/4c/zkXwcR6kwZ HxAqf5QtVIKKnMv2nEthcQJckSqOPsWSK8T/AR5uRaKjAgAA Cc: Mark Rutland , Benjamin Herrenschmidt , Tomasz Figa , Will Deacon , Tomasz Figa , Paul Mackerras , Arnd Bergmann , Josh Cartwright , Catalin Marinas , Grant Likely , Ian Campbell , Pawel Moll , Stephen Warren , Sascha Hauer , Michal Nazarewicz , Rob Herring , Kumar Gala , Olof Johansson Subject: [Linaro-mm-sig] [PATCH v5 04/11] drivers: of: add support for custom reserved memory drivers X-BeenThere: linaro-mm-sig@lists.linaro.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 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 Add support for custom reserved memory drivers. Call their init() function for each reserved region and prepare for using operations provided by them with by the reserved_mem->ops array. Based on previous code provided by Josh Cartwright Signed-off-by: Marek Szyprowski --- drivers/of/of_reserved_mem.c | 29 +++++++++++++++++++++++++++++ include/asm-generic/vmlinux.lds.h | 11 +++++++++++ include/linux/of_reserved_mem.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index c7ca6a4a42d1..97de6f882f85 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -170,6 +170,33 @@ static int __init __reserved_mem_alloc_size(unsigned long node, return 0; } +static const struct of_device_id __rmem_of_table_sentinel + __used __section(__reservedmem_of_table_end); + +/** + * res_mem_init_node() - call region specific reserved memory init code + */ +static int __init __reserved_mem_init_node(struct reserved_mem *rmem) +{ + extern const struct of_device_id __reservedmem_of_table[]; + const struct of_device_id *i; + + for (i = __reservedmem_of_table; i < &__rmem_of_table_sentinel; i++) { + reservedmem_of_init_fn initfn = i->data; + const char *compat = i->compatible; + + if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) + continue; + + if (initfn(rmem, rmem->fdt_node, rmem->name) == 0) { + pr_info("Reserved memory: initialized node %s, compatible id %s\n", + rmem->name, compat); + return 0; + } + } + return -ENOENT; +} + /** * fdt_init_reserved_mem - allocate and init all saved reserved memory regions */ @@ -184,5 +211,7 @@ void __init fdt_init_reserved_mem(void) if (rmem->size == 0) err = __reserved_mem_alloc_size(node, rmem->name, &rmem->base, &rmem->size); + if (err == 0) + __reserved_mem_init_node(rmem); } } diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index bc2121fa9132..f10f64fcc815 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -167,6 +167,16 @@ #define CLK_OF_TABLES() #endif +#ifdef CONFIG_OF_RESERVED_MEM +#define RESERVEDMEM_OF_TABLES() \ + . = ALIGN(8); \ + VMLINUX_SYMBOL(__reservedmem_of_table) = .; \ + *(__reservedmem_of_table) \ + *(__reservedmem_of_table_end) +#else +#define RESERVEDMEM_OF_TABLES() +#endif + #define KERNEL_DTB() \ STRUCT_ALIGN(); \ VMLINUX_SYMBOL(__dtb_start) = .; \ @@ -490,6 +500,7 @@ TRACE_SYSCALLS() \ MEM_DISCARD(init.rodata) \ CLK_OF_TABLES() \ + RESERVEDMEM_OF_TABLES() \ CLKSRC_OF_TABLES() \ KERNEL_DTB() \ IRQCHIP_OF_MATCH_TABLE() diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 89226ed7d954..f707176619a3 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -1,21 +1,54 @@ #ifndef __OF_RESERVED_MEM_H #define __OF_RESERVED_MEM_H +struct device; +struct of_phandle_args; +struct reserved_mem_ops; + struct reserved_mem { const char *name; unsigned long fdt_node; + const struct reserved_mem_ops *ops; phys_addr_t base; phys_addr_t size; + void *priv; +}; + +struct reserved_mem_ops { + void (*device_init)(struct reserved_mem *rmem, + struct device *dev, + struct of_phandle_args *args); + void (*device_release)(struct reserved_mem *rmem, + struct device *dev); }; +typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem, + unsigned long node, const char *uname); + #ifdef CONFIG_OF_RESERVED_MEM void fdt_init_reserved_mem(void); void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size); + +#define RESERVEDMEM_OF_DECLARE(name, compat, init) \ + static const struct of_device_id __reservedmem_of_table_##name \ + __used __section(__reservedmem_of_table) \ + = { .compatible = compat, \ + .data = (init == (reservedmem_of_init_fn)NULL) ? \ + init : init } + #else static inline void fdt_init_reserved_mem(void) { } static inline void fdt_reserved_mem_save_node(unsigned long node, const char *uname, phys_addr_t base, phys_addr_t size) { } + +#define RESERVEDMEM_OF_DECLARE(name, compat, init) \ + static const struct of_device_id __reservedmem_of_table_##name \ + __attribute__((unused)) \ + = { .compatible = compat, \ + .data = (init == (reservedmem_of_init_fn)NULL) ? \ + init : init } + #endif #endif /* __OF_RESERVED_MEM_H */