From patchwork Fri Sep 28 06:48:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10619057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 089F6913 for ; Fri, 28 Sep 2018 06:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8902B009 for ; Fri, 28 Sep 2018 06:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1D362B005; Fri, 28 Sep 2018 06:59:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F26842B005 for ; Fri, 28 Sep 2018 06:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uUkxX81w8WW03EH+EfktsB+Hj2BxiiRHlyZ6Y9lS7vg=; b=oWX5H4lEomAvnH J+vCVGY9lPJtk3IYUrGQ4p8pl3CCXGVHL4eYwqcwELmS2VnMqlKbB1wR9V8mn1KOXZwo6mPnqOgeh he+W1G4kW0HQE3Nj5rAbvA8AaE3wArtcQDOMENx92SRi8kzMA5KaKwJS4cyoIGnhSHpFVp2JeJDX9 qtpzu0PBFPrzVdfROtUSWSwwA3pfw+m8HRITtCyBi2zgCLjDWo1vuQ3XqX4DIlgbw7wTxzFHRKC+i +F6jrGF5jG0ZlJg1Vi6qk6MjDeG/iI42uW9LQqJMvVv5ylXJRX+6Et0AuX2HXY/vj49SXv+rqnzej g8wdbUfYlTSU8Zmf7CDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5mk3-0003i2-Hb; Fri, 28 Sep 2018 06:59:11 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5ma0-0004fu-QQ for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 06:48:51 +0000 Received: by mail-pg1-x543.google.com with SMTP id q19-v6so3715339pgn.10 for ; Thu, 27 Sep 2018 23:48:23 -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 :mime-version:content-transfer-encoding; bh=Pt0GdTUj/ouoBc0plwl0qxBtF8IeFfWdoXUu09cJo+Q=; b=a1qa43cUD3aEMCBBW+bPEPzCN0FPKwq7mNCLZT1Q8/I1oH07mIv3ms6vWZ0nRdjueB RWCSvRKjgb6jdgEZYiv0PSwrzd6TycaifX8EGVal+obfRXgDcaEMCtDQq3NzhlXgp3jV +q/uY98I7cnuQEWg2SjjZxoM4ZG3JndQxgZNo= 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:mime-version:content-transfer-encoding; bh=Pt0GdTUj/ouoBc0plwl0qxBtF8IeFfWdoXUu09cJo+Q=; b=kl/qbZvulawXr8th2IDiqbXI6SpUV9esDdi7kCk+IU4mfBTnAB2R5vC5gX/RpJLBrX LdG28Tef/u8kJtEqZdJjww7rWirHi77sQjd2fRGIQFSLfZQBMBYYRLZD1rdFLDLUpQdB 0cqSboghgb9QBqzSVg28aEEDuruakYIhBSt879z3iAh3PPMibkOh5VCrDD/42EIT0e7S L5SUmNFKOGiHGzHwY9tXkmqeW20LGxHB/kcB6wmC3/mqyXtMponQaN+/QEe6i3WQMEjg EK+rP7KAOaJCUlyMDAX2PTfjIdS/0gx9OnX3hBte23Ysf7UJk7hSmw17hoxQHz7DMOM0 ZaqA== X-Gm-Message-State: ABuFfoh5bBaDa18My9NKoXZqqpOi+NGJjEwuru2kKw7AVVTNy9kUrCHA plvZeByorTW7pmi52/8KbqPWi+oi3Lg= X-Google-Smtp-Source: ACcGV6132QMgaHUkEnzpOJ34vEDqPCuVCNDWxwxsgSM4vQASkor4Pf8KuOATk2NREZeo2zXkL7a4ZA== X-Received: by 2002:a17:902:a40e:: with SMTP id p14-v6mr1085759plq.338.1538117302650; Thu, 27 Sep 2018 23:48:22 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 89-v6sm9522313pfk.134.2018.09.27.23.48.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 23:48:21 -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, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com Subject: [PATCH v15 06/16] of/fdt: add helper functions for handling properties Date: Fri, 28 Sep 2018 15:48:31 +0900 Message-Id: <20180928064841.14117-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180928064841.14117-1-takahiro.akashi@linaro.org> References: <20180928064841.14117-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180927_234848_902926_269AD026 X-CRM114-Status: GOOD ( 12.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, prudo@linux.ibm.com, AKASHI Takahiro , Rob Herring , james.morse@arm.com, Frank Rowand , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Cc: devicetree@vger.kernel.org --- drivers/of/fdt.c | 56 ++++++++++++++++++++++++++++++++++++++++++ include/linux/of_fdt.h | 4 +++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 800ad252cf9c..c65c31562ccb 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 @@ -1323,3 +1324,58 @@ late_initcall(of_fdt_raw_init); #endif #endif /* CONFIG_OF_EARLY_FLATTREE */ + +#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) +{ + int addr_cells, size_cells; + char buf[sizeof(__be32) * 2 * 2]; + /* assume dt_root_[addr|size]_cells <= 2 */ + void *prop; + size_t buf_size; + + addr_cells = fdt_address_cells(fdt, 0); + if (addr_cells < 0) + return addr_cells; + size_cells = fdt_size_cells(fdt, 0); + if (size_cells < 0) + return size_cells; + + /* if *_cells >= 2, cells can hold 64-bit values anyway */ + if ((addr_cells == 1) && (addr > U32_MAX)) + return -FDT_ERR_BADVALUE; + + if ((size_cells == 1) && (size > U32_MAX)) + return -FDT_ERR_BADVALUE; + + buf_size = (addr_cells + size_cells) * sizeof(u32); + prop = buf; + + fill_property(prop, addr, addr_cells); + prop += addr_cells * sizeof(u32); + + fill_property(prop, size, 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..842af6ea92ea 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -108,5 +108,9 @@ static inline void unflatten_device_tree(void) {} static inline void unflatten_and_copy_device_tree(void) {} #endif /* CONFIG_OF_EARLY_FLATTREE */ +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 */