Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1069202imm; Tue, 2 Oct 2018 02:04:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV62DavMiCn63/QYrm3DC0P95DnUupCoa40h+bYdNK2ssTmzQhG/R4P0uDqDuUm9w94P5pKtV X-Received: by 2002:a62:12c9:: with SMTP id 70-v6mr15333533pfs.140.1538471089059; Tue, 02 Oct 2018 02:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538471089; cv=none; d=google.com; s=arc-20160816; b=hpmw4CWvXJB7qZlG8Zj/rqBm2cHM565fMP3L/rAKiiMsrfoSSMFWVyNHRAIEJ7jp55 fzQoRtpTQvqk0khJa2MNG7g1h4VMxv2XgBn2VVFTVGrA0z9OqCi/7i8TVTkOR1/OsFNR veSROfRFQgqbdCLQc2CE4QzIBXfeqHI6Cu7FnbtFgVy4LA+N4IbGQNk21MEPzfNADFGu OeoBBp5jhxXV/vOTbJKwIuwQmXscmTFv7EDBWQG5hxKvSQnSH4c6DHAGVtm0XUwmfT8F 3GHxGqRI0X1A4IjojQD0m6eXhhCYW4xQnGvnwPRzbBSxjN2UED5IA+qyiXcHEdMYqMn2 5kiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=jhRth2zriuuqvJAv2fDFsUEb0CAiwLAS3hhHepahHtc=; b=qP6LlqXOSKFn1AV+0fKZIeUkZWr3SSvl70IxbyO+1OfzRKAEf3fwNLfAs3PKSeO2Uk bER8Q0F6qoiJKRa0VG70EUsxfpYduguINqALV+tWR8uJPOzV6ER5meQuxyQLhG7lHJ4c xwKA8OeRfYEX6ECGz5tGIjdswKUlJfQ8sr18e06Py24DHDzxourMLcCF014MJtDmyroa wA6EtS7PSCmBsbAnyQ3S24fcjDUAyuqgS9w2hO/diSwiEJe+7IHv86SiKhDb8caOLAzY YJNZPDNy0hdRjMtkwKJGBTDn3KAxRcSdqHfIXe2wJo7Fue41jWKfHY7udGrk39KAf0Pc xYaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PYZl6qkf; 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 g4-v6si14455801plb.484.2018.10.02.02.04.34; Tue, 02 Oct 2018 02:04:49 -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=PYZl6qkf; 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 S1727240AbeJBPp2 (ORCPT + 99 others); Tue, 2 Oct 2018 11:45:28 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42242 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726734AbeJBPp2 (ORCPT ); Tue, 2 Oct 2018 11:45:28 -0400 Received: by mail-pl1-f193.google.com with SMTP id c8-v6so669797plo.9 for ; Tue, 02 Oct 2018 02:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jhRth2zriuuqvJAv2fDFsUEb0CAiwLAS3hhHepahHtc=; b=PYZl6qkfvisyyLDNWoGBhRPpWxFDfL/ZSyzkSuc2xWJeyXlg4bVcMtIZ2RTQfYDoZe S7Wvu3IyiJJDef7vr3tnl8mk3wBqtOYeitoVnBgvaxsVl9XZ7IUdqqxz1yoUfC2+p89J 9Bl+T3imF8JQmaCVsMO2Yi3uEvCT5VGR0KAs0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=jhRth2zriuuqvJAv2fDFsUEb0CAiwLAS3hhHepahHtc=; b=cwpAt6zquiVMQO234Fg8NOy3COi8aYAJG4sGaA6KzFkPHkH10qA15jEYoUuuM8s/se 7utssllWRtD4CkSWo4fOv6KgEdEmRNLif4DjqWp+I2mSTDDu1zuaOu/hr0KjnUx4fdFy A2uMp/g7mWyVVImmwz+8ipd/qJ7dE6T1VnMbFygr0jw7JTnakSmXFlm+/lHbYphegV4F cxbX4mlVFMfFloqWpLAN8VExNLfy3sFLs269UTCx9HxChP8AHT9A8zsQN6rJJDKvzUW9 YTquIkGIoS4+sGfEWtS18hN32NOETH4qc7kJbVu+FdKPPg4eTd4yVeBqUxxGJjqCVRhB hfrg== X-Gm-Message-State: ABuFfoh1TYsrwYD3Nu7ct4Ye7UMq43xkzYaisESbpTAtJAG5+soFIu/P QYNrK4fZ+uUNMZpHJkzUeex9oQ== X-Received: by 2002:a17:902:286a:: with SMTP id e97-v6mr15885558plb.340.1538470994414; Tue, 02 Oct 2018 02:03:14 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y1-v6sm23019752pfy.89.2018.10.02.02.03.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 02:03:13 -0700 (PDT) Date: Tue, 2 Oct 2018 18:04:40 +0900 From: "AKASHI, Takahiro" To: David Gibson Cc: Rob Herring , Catalin Marinas , Will Deacon , David Howells , Vivek Goyal , Herbert Xu , David Miller , dyoung@redhat.com, Baoquan He , Arnd Bergmann , Martin Schwidefsky , Heiko Carstens , prudo@linux.ibm.com, Ard Biesheuvel , James Morse , bhsharma@redhat.com, kexec@lists.infradead.org, "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , "linux-kernel@vger.kernel.org" , Frank Rowand , devicetree@vger.kernel.org Subject: Re: [PATCH v15 06/16] of/fdt: add helper functions for handling properties Message-ID: <20181002090438.GH32578@linaro.org> Mail-Followup-To: "AKASHI, Takahiro" , David Gibson , Rob Herring , Catalin Marinas , Will Deacon , David Howells , Vivek Goyal , Herbert Xu , David Miller , dyoung@redhat.com, Baoquan He , Arnd Bergmann , Martin Schwidefsky , Heiko Carstens , prudo@linux.ibm.com, Ard Biesheuvel , James Morse , bhsharma@redhat.com, kexec@lists.infradead.org, "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , "linux-kernel@vger.kernel.org" , Frank Rowand , devicetree@vger.kernel.org References: <20180928064841.14117-1-takahiro.akashi@linaro.org> <20180928064841.14117-7-takahiro.akashi@linaro.org> <20181002044710.GD1886@umbus.fritz.box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181002044710.GD1886@umbus.fritz.box> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 02, 2018 at 02:47:10PM +1000, David Gibson wrote: > On Fri, Sep 28, 2018 at 08:44:42AM -0500, Rob Herring wrote: > > +David Gibson > > > > On Fri, Sep 28, 2018 at 1:48 AM AKASHI Takahiro > > wrote: > > > > > > 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); > > > > Looks like you are using this to calculate how much space you need to > > allocate in addition to the current DTB for a couple of new or > > replaced properties. I'm not sure that this calculation is completely > > accurate. And it is strange there doesn't seem to be any libfdt > > function for this already. It would be simpler to just add some fixed > > additional amount. > > > > Maybe David G has comments on this? > > Hrm. Yeah, the approach I'd suggest would be to just add a fixed > amount, and if your functions return -FDT_ERR_NOSPACE, add some more. > That's pretty much the expected way of working with fdts in write > mode. I will try to follow this approach. Thanks, -Takahiro Akashi > If that's really not suitable, we could look at adding a helper to > estimate this in libfdt. Or, actually, I suspect taking an existing > libfdt internal helper, polishing and exporting it. > > > > > > +} > > > + > > > > The rest of this should go in drivers/of/fdt_address.c. Ultimately, it > > should go into libfdt, but I'm fine with having it in the kernel for > > now. > > > > > +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); > > > > This is kind of hard to read. I would copy u-boot's fdt_pack_reg function. > > > > BTW, for purposes of moving to libfdt, we'll need the authors' > > (Masahiro Yamada and Hans de Goede) permission to dual license. > > > > > + } > > > +} > > > + > > > +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 */ > > > > > > > -- > David Gibson | I'll have my music baroque, and my code > david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ > | _way_ _around_! > http://www.ozlabs.org/~dgibson