From patchwork Wed Jul 11 07:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 141671 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4799977ljj; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLqXI9/X8h8TZJ0X35bg4HrDFqN97zFW6q+w5Ga+afGe8eRvsMnpOxaImIzty/Be32Nhsh X-Received: by 2002:a62:c0c4:: with SMTP id g65-v6mr28707597pfk.72.1531294924769; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531294924; cv=none; d=google.com; s=arc-20160816; b=L0RDJnDeVsOBNsAUh/yNPeXcrQGJoif9Z1rMAHbY8eR6ctQlJMU5qbwOmYvWDhNTZ8 /lqRaRwszbDVo68vu/D+QVmrwgZoVWj52w+jA61ax0uYj93mvWx3SSdq7dw9G/vViwuH U2R/NKOyE6/PskNcsZMCQw4v+mzo3tzUrrExoEwlG2sRsPb7PY+1tY7XC+4pPDGhY6Eg T8eiIJYTi49o9X6qztkAH6WFi/kOLjR6akjB3eR/XsDMEDdg+9JH2pHDcS4ZsS4krZOn LLsOfe8IaaboY8PGi26f2TBMZAj5/TG/e77H0y2WoQMAXbydmJVeZefdMa9sqZD5GgF2 XQ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=ccQ0a0WFPQMrD/bs/H0pwNo1cxf7zg+lTvsBlDuQI4baEso/fq0hpLiGGUuiHjBzf3 Y4evm33D9LziyBsmIS7FsZsZOlKyrtNgeND6NBgsybKKNm9vtx2BpR13fC3B4rgYwrG2 2RH/hYTpLQv8wy3TMcYpPqdxZy3aSO+pG3EjfdjIWn/jtRyfA+G82AVcD6B5GlAlq2oI Mqe4jUInEdRhRPPSnKZGNc6AylzpK/y+lOjdemc4obbTPXfp05O/AMO9ODFMU1e1yARd bnVAyFfIBrnbz2Jv+/ZqQ672AEq2eu9MY0oJwxWq5ZiLW2jBatapxEgqw1rPH3iZ1Ngm NhXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXQZ5Wpy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l26-v6si17887254pgu.191.2018.07.11.00.42.04; Wed, 11 Jul 2018 00:42:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXQZ5Wpy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726784AbeGKHo5 (ORCPT + 22 others); Wed, 11 Jul 2018 03:44:57 -0400 Received: from mail-pf0-f171.google.com ([209.85.192.171]:42724 "EHLO mail-pf0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeGKHo5 (ORCPT ); Wed, 11 Jul 2018 03:44:57 -0400 Received: by mail-pf0-f171.google.com with SMTP id l9-v6so6236545pff.9 for ; Wed, 11 Jul 2018 00:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=DXQZ5WpyyE/KxO3vIz5rWYCBHP7Lq8wvgXXdAfcutCKQ1PjOwNUMf9pHWjihE7kCN6 wCRwpC0/G/+BB97oJk3u5bGddZchoyATlbRWnK7k31Ymk75J2/XTNuV8C0Y80zVDHCxL t5Xdfigyj0cD+P2602F/sN+miEljoBN2AMtak= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QlhV7eDSbsU4GPDGTwzyQDGWNJMnX8a7YNDVlGTagBM=; b=MJzDPjJYirlxdKDVTB95utIJOcPXkh7MZxfDkZbEkYe5FCzTeEbqzO24nM6h3ehjU1 upay//NpQGyOeZlhyAvES4RhZSPzGDPTdFScqSIzpnFK5Vr0vw609UoZZ/p09EMtXzRX Ej2OcD3U8GdFQ45giyJIu6QCsS0cAvUz7SNSn3x/khtchpFNM12ADmFKfNEDzFlc9+SN 8gExsJ0tqf4MUhxRM+J+6QI4TDq/h8V2HW+QCUXrQUC+u0wwDUp11bIR/pKQvZ51cYJD qye6YzFkJA9kcvpaDRrK4CfyTEQg2gfuO4TEtBHRoqaK8L38XuO1bxG9Yaee8g0EuUwZ XSOQ== X-Gm-Message-State: APt69E33V6JMsFlvat0S2uJZuYxKyoEnhYlKgfQe6W1qZwHymjZgTRIX XihJgVrOUfOasUbeuguz1EEMkg== X-Received: by 2002:a65:6689:: with SMTP id b9-v6mr25416801pgw.326.1531294920730; Wed, 11 Jul 2018 00:42:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p20-v6sm29051873pff.90.2018.07.11.00.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 00:42:00 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , Rob Herring , Frank Rowand Subject: [PATCH v11 05/15] of/fdt: add helper functions for handling properties Date: Wed, 11 Jul 2018 16:41:53 +0900 Message-Id: <20180711074203.3019-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180711074203.3019-1-takahiro.akashi@linaro.org> References: <20180711074203.3019-1-takahiro.akashi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These functions will be used later to handle kexec-specific properties in arm64's kexec_file implementation. Signed-off-by: AKASHI Takahiro Cc: Rob Herring Cc: Frank Rowand --- drivers/of/fdt.c | 62 ++++++++++++++++++++++++++++++++++++++++-- include/linux/of_fdt.h | 10 +++++-- 2 files changed, 68 insertions(+), 4 deletions(-) -- 2.17.0 diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 6da20b9688f7..f7c9d69ce86c 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -25,6 +25,7 @@ #include #include #include +#include #include /* for COMMAND_LINE_SIZE */ #include @@ -537,8 +538,8 @@ void *of_fdt_unflatten_tree(const unsigned long *blob, EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); /* Everything below here references initial_boot_params directly. */ -int __initdata dt_root_addr_cells; -int __initdata dt_root_size_cells; +int dt_root_addr_cells; +int dt_root_size_cells; void *initial_boot_params; @@ -1330,3 +1331,60 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +bool of_fdt_cells_size_fitted(u64 base, u64 size) +{ + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((dt_root_addr_cells == 1) && (base > U32_MAX)) + return false; + + if ((dt_root_size_cells == 1) && (size > U32_MAX)) + return false; + + return true; +} + +size_t of_fdt_reg_cells_size(void) +{ + return (dt_root_addr_cells + dt_root_size_cells) * sizeof(u32); +} + +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) + +int fdt_prop_len(const char *prop_name, int len) +{ + return (strlen(prop_name) + 1) + + sizeof(struct fdt_property) + + FDT_TAGALIGN(len); +} + +static void fill_property(void *buf, u64 val64, int cells) +{ + __be32 val32; + + while (cells) { + val32 = cpu_to_fdt32((val64 >> (32 * (--cells))) & U32_MAX); + memcpy(buf, &val32, sizeof(val32)); + buf += sizeof(val32); + } +} + +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size) +{ + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + buf_size = of_fdt_reg_cells_size(); + prop = buf; + + fill_property(prop, addr, dt_root_addr_cells); + prop += dt_root_addr_cells * sizeof(u32); + + fill_property(prop, size, dt_root_size_cells); + + return fdt_setprop(fdt, nodeoffset, name, buf, buf_size); +} diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index b9cd9ebdf9b9..9615d6142578 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -37,8 +37,8 @@ extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node **mynodes); /* TBD: Temporary export of fdt globals - remove when code fully merged */ -extern int __initdata dt_root_addr_cells; -extern int __initdata dt_root_size_cells; +extern int dt_root_addr_cells; +extern int dt_root_size_cells; extern void *initial_boot_params; extern char __dtb_start[]; @@ -108,5 +108,11 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +bool of_fdt_cells_size_fitted(u64 base, u64 size); +size_t of_fdt_reg_cells_size(void); +int fdt_prop_len(const char *prop_name, int len); +int fdt_setprop_reg(void *fdt, int nodeoffset, const char *name, + u64 addr, u64 size); + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_OF_FDT_H */