This series enables the use of the additional cores on Rockchip
Cortex-A9 SoCs.
To achieve this, add the scu, the needed sram and power-management-unit.
Tested on both a BQ Curie2 (rk3066a / dual core) and
on a Radxa Rock (rk3188 / quad core).
changes since v5:
- Grant Likely liked it better to "specify reserved regions of the
memory instead of the valid ranges", so go back to the mmio-sram-reserved
property originally suggested by Rob Herring
changes since v4:
- rebase on top of the recent rk3188 board support
- implement suggestion from Matt Sealey in moving the sram-limit from
marking reserved regions to marking available regions - hopefully
I got the usage right
- remove __CPUINIT as suggested by Fabio Estevam
changes since v3:
- address comments from Rob Herring:
- split the gathering of the reserve-data into a separate loop
- spelling and style fixes
- first patch only included for reference, already part of the
char-misc git tree
changes since v2:
- rework the sram allocation following the suggestion from Philipp Zabel
changes since v1:
- add reserved block feature for mmio-sram, to not use two logical
sram nodes
- the sram content is kept intact while the device is running, so
copying the trampoline is only needed once
Heiko Stuebner (6):
dt-bindings: sram: describe option to reserve parts of the memory
misc: sram: implement mmio-sram-reserved option
ARM: rockchip: add snoop-control-unit
ARM: rockchip: add sram dt nodes and documentation
ARM: rockchip: add power-management-unit
ARM: rockchip: add smp bringup code
.../devicetree/bindings/arm/rockchip/pmu.txt | 16 ++
.../devicetree/bindings/arm/rockchip/smp-sram.txt | 23 +++
Documentation/devicetree/bindings/misc/sram.txt | 8 +
arch/arm/boot/dts/rk3066a.dtsi | 6 +
arch/arm/boot/dts/rk3188.dtsi | 6 +
arch/arm/boot/dts/rk3xxx.dtsi | 10 +
arch/arm/mach-rockchip/Kconfig | 1 +
arch/arm/mach-rockchip/Makefile | 1 +
arch/arm/mach-rockchip/core.h | 22 +++
arch/arm/mach-rockchip/headsmp.S | 30 +++
arch/arm/mach-rockchip/platsmp.c | 208 ++++++++++++++++++++
arch/arm/mach-rockchip/rockchip.c | 2 +
drivers/misc/sram.c | 118 ++++++++++-
13 files changed, 443 insertions(+), 8 deletions(-)
create mode 100644 Documentation/devicetree/bindings/arm/rockchip/pmu.txt
create mode 100644 Documentation/devicetree/bindings/arm/rockchip/smp-sram.txt
create mode 100644 arch/arm/mach-rockchip/core.h
create mode 100644 arch/arm/mach-rockchip/headsmp.S
create mode 100644 arch/arm/mach-rockchip/platsmp.c
--
1.7.10.4
Some SoCs need parts of their sram for special purposes. So while being part
of the peripheral, it should not be part of the genpool controlling the sram.
Therefore add an option mmio-sram-reserved to keep arbitrary portions of the
sram from general usage.
Suggested-by: Rob Herring <redacted>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
---
Documentation/devicetree/bindings/misc/sram.txt | 8 ++++++++
1 file changed, 8 insertions(+)
@@ -8,9 +8,17 @@ Required properties: - reg : SRAM iomem address range+Optional properties:++- mmio-sram-reserved: ordered list of reserved chunks inside the sram that+ should not be used by the operating system.+ Format is <base size>, <base size>, ...; with base being relative to the+ reg property base.+ Example: sram: sram at 5c000000 { compatible = "mmio-sram"; reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */+ mmio-sram-reserved = <0x0 0x100>; /* reserve 0x5c000000-0x5c000100 */ };
This implements support for the mmio-sram-reserved option to keep the
genpool from using these areas.
Suggested-by: Rob Herring <redacted>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
---
drivers/misc/sram.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 110 insertions(+), 8 deletions(-)
@@ -65,19 +75,111 @@ static int sram_probe(struct platform_device *pdev)if(!sram->pool)return-ENOMEM;-ret=gen_pool_add_virt(sram->pool,(unsignedlong)virt_base,-res->start,size,-1);-if(ret<0){-if(sram->clk)-clk_disable_unprepare(sram->clk);-returnret;+if(pdev->dev.of_node){+reserved_list=of_get_property(pdev->dev.of_node,+"mmio-sram-reserved",+&reserved_size);+if(reserved_list){+reserved_size/=sizeof(*reserved_list);+if(!reserved_size||reserved_size%2){+dev_warn(&pdev->dev,"wrong number of arguments in mmio-sram-reserved\n");+reserved_list=NULL;+reserved_size=0;+}+}+}++/*+*Weneedanadditionalblocktomarktheendofthememoryregion+*afterthereservedblocksfromthedtareprocessed.+*/+nblocks=reserved_size/2+1;+rblocks=kmalloc((nblocks)*sizeof(*rblocks),GFP_KERNEL);+if(!rblocks){+ret=-ENOMEM;+gotoerr_alloc;+}++cur_start=0;+for(i=0;i<nblocks-1;i++){+rblocks[i].start=be32_to_cpu(*reserved_list++);+rblocks[i].size=be32_to_cpu(*reserved_list++);++if(rblocks[i].start<cur_start){+dev_err(&pdev->dev,+"unsorted reserved list (0x%lx before current 0x%lx)\n",+rblocks[i].start,cur_start);+ret=-EINVAL;+gotoerr_chunks;+}++if(rblocks[i].start>=size){+dev_err(&pdev->dev,+"reserved block at 0x%lx outside the sram size 0x%lx\n",+rblocks[i].start,size);+ret=-EINVAL;+gotoerr_chunks;+}++if(rblocks[i].start+rblocks[i].size>size){+dev_warn(&pdev->dev,+"reserved block at 0x%lx to large, trimming\n",+rblocks[i].start);+rblocks[i].size=size-rblocks[i].start;+}++cur_start=rblocks[i].start+rblocks[i].size;++dev_dbg(&pdev->dev,"found reserved block 0x%lx-0x%lx\n",+rblocks[i].start,+rblocks[i].start+rblocks[i].size);+}++/* the last chunk marks the end of the region */+rblocks[nblocks-1].start=size;+rblocks[nblocks-1].size=0;++cur_start=0;+for(i=0;i<nblocks;i++){+/* current start is in a reserved block, so continue after it */+if(rblocks[i].start==cur_start){+cur_start=rblocks[i].start+rblocks[i].size;+continue;+}++/*+*allocatethespacebetweenthecurrentstarting+*addressandthefollowingreservedblock,orthe+*endoftheregion.+*/+cur_size=rblocks[i].start-cur_start;++dev_dbg(&pdev->dev,"adding chunk 0x%lx-0x%lx\n",+cur_start,cur_start+cur_size);+ret=gen_pool_add_virt(sram->pool,+(unsignedlong)virt_base+cur_start,+res->start+cur_start,cur_size,-1);+if(ret<0)+gotoerr_chunks;++/* next allocation after this reserved block */+cur_start=rblocks[i].start+rblocks[i].size;}+kfree(rblocks);+platform_set_drvdata(pdev,sram);dev_dbg(&pdev->dev,"SRAM pool: %ld KiB @ 0x%p\n",size/1024,virt_base);return0;++err_chunks:+kfree(rblocks);+err_alloc:+if(sram->clk)+clk_disable_unprepare(sram->clk);+returnret;}staticintsram_remove(structplatform_device*pdev)
@@ -0,0 +1,23 @@+Rockchip SRAM for smp bringup:+------------------------------++Rockchip's smp-capable SoCs use the first part of the sram for the bringup+of the cores. Once the core gets powered up it executes the code that is+residing at the very beginning of the sram.++Therefore a reserved section has to be added to the mmio-sram declaration.++Required node properties:+- compatible : should contain both "rockchip,rk3066-sram", "mmio-sram"+ so that the smp code can select the correct sram node.++The rest of the properties should follow the generic mmio-sram discription+found in ../../misc/sram.txt++Example:++ sram: sram at 10080000 {+ compatible = "rockchip,rk3066-sram", "mmio-sram";+ reg = <0x10080000 0x10000>;+ mmio-sram-reserved = <0x0 0x50>;+ };
The pmu is needed to bring up the cores during smp operations and later
also other system parts. Therefore add a node and documentation for it.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
---
Documentation/devicetree/bindings/arm/rockchip/pmu.txt | 16 ++++++++++++++++
arch/arm/boot/dts/rk3xxx.dtsi | 5 +++++
2 files changed, 21 insertions(+)
create mode 100644 Documentation/devicetree/bindings/arm/rockchip/pmu.txt
@@ -0,0 +1,16 @@+Rockchip power-management-unit:+-------------------------------++The pmu is used to turn off and on different power domains of the SoCs+This includes the power to the CPU cores.++Required node properties:+- compatible value : = "rockchip,rk3066-pmu";+- reg : physical base address and the size of the registers window++Example:++ pmu at 20004000 {+ compatible = "rockchip,rk3066-pmu";+ reg = <0x20004000 0x100>;+ };
This adds the necessary smp-operations and startup code to use
additional cores on Rockchip SoCs.
We currently hog the power management unit in the smp code, as it is
necessary to control the power to the cpu core and nothing else is
currently using it, so a generic implementation can be done later.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
---
arch/arm/mach-rockchip/Makefile | 1 +
arch/arm/mach-rockchip/core.h | 22 ++++
arch/arm/mach-rockchip/headsmp.S | 30 ++++++
arch/arm/mach-rockchip/platsmp.c | 208 +++++++++++++++++++++++++++++++++++++
arch/arm/mach-rockchip/rockchip.c | 2 +
5 files changed, 263 insertions(+)
create mode 100644 arch/arm/mach-rockchip/core.h
create mode 100644 arch/arm/mach-rockchip/headsmp.S
create mode 100644 arch/arm/mach-rockchip/platsmp.c
@@ -0,0 +1,208 @@+/*+*Copyright(c)2013MundoReaderS.L.+*Author:HeikoStuebner<heiko@sntech.de>+*+*Thisprogramisfreesoftware;youcanredistributeitand/ormodify+*itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby+*theFreeSoftwareFoundation;eitherversion2oftheLicense,or+*(atyouroption)anylaterversion.+*+*Thisprogramisdistributedinthehopethatitwillbeuseful,+*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof+*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe+*GNUGeneralPublicLicenseformoredetails.+*/++#include<linux/delay.h>+#include<linux/init.h>+#include<linux/smp.h>+#include<linux/io.h>+#include<linux/of.h>+#include<linux/of_address.h>++#include<asm/cacheflush.h>+#include<asm/smp_scu.h>+#include<asm/smp_plat.h>+#include<asm/mach/map.h>++#include"core.h"++staticvoid__iomem*scu_base_addr;+staticvoid__iomem*sram_base_addr;+staticintncores;++#define PMU_PWRDN_CON 0x08+#define PMU_PWRDN_ST 0x0c++#define PMU_PWRDN_SCU 4++staticvoid__iomem*pmu_base_addr;++staticinlineboolpmu_power_domain_is_on(intpd)+{+return!(readl_relaxed(pmu_base_addr+PMU_PWRDN_ST)&BIT(pd));+}++staticvoidpmu_set_power_domain(intpd,boolon)+{+u32val=readl_relaxed(pmu_base_addr+PMU_PWRDN_CON);+if(on)+val&=~BIT(pd);+else+val|=BIT(pd);+writel(val,pmu_base_addr+PMU_PWRDN_CON);++while(pmu_power_domain_is_on(pd)!=on){}+}++/*+*HandlingofCPUcores+*/++staticint__cpuinitrockchip_boot_secondary(unsignedintcpu,+structtask_struct*idle)+{+if(!sram_base_addr||!pmu_base_addr){+pr_err("%s: sram or pmu missing for cpu boot\n",__func__);+return-ENXIO;+}++if(cpu>=ncores){+pr_err("%s: cpu %d outside maximum number of cpus %d\n",+__func__,cpu,ncores);+return-ENXIO;+}++/* start the core */+pmu_set_power_domain(0+cpu,true);++return0;+}++/**+*rockchip_smp_prepare_sram-populatenecessarysramblock+*Startingcoresexecutethecoderesidingatthestartoftheon-chipsram+*afterpower-on.Thereforemakesure,thissramregionisreservedand+*bigenough.Afterthischeck,copythetrampolinecodethatdirectsthe+*coretotherealstartupcodeinramintothesram-region.+*@node:mmio-sramdevicenode+*/+staticint__initrockchip_smp_prepare_sram(structdevice_node*node)+{+unsignedinttrampoline_sz=&rockchip_secondary_trampoline_end-+&rockchip_secondary_trampoline;+const__be32*reserved_list=NULL;+intreserved_size;+intrstart=-1;+unsignedintrsize;+unsignedinti;++reserved_list=of_get_property(node,"mmio-sram-reserved",+&reserved_size);+if(!reserved_list){+pr_err("%s: wrong number of arguments in mmio-sram-reserved\n",+__func__);+return-ENOENT;+}++reserved_size/=sizeof(*reserved_list);+if(!reserved_size||reserved_size%2){+pr_err("%s: wrong number of arguments in mmio-sram-reserved\n",+__func__);+return-EINVAL;+}++for(i=0;i<reserved_size;i+=2){+/* get the next reserved block */+rstart=be32_to_cpu(*reserved_list++);+rsize=be32_to_cpu(*reserved_list++);++if(!rstart)+break;+}++if(rstart){+pr_err("%s: start of sram is not reserved from mmio-sram\n",+__func__);+return-EINVAL;+}++if(rsize<trampoline_sz){+pr_err("%s: reserved block with size 0x%x is to small for trampoline size 0x%x\n",+__func__,rsize,trampoline_sz);+return-EINVAL;+}++sram_base_addr=of_iomap(node,0);++/* set the boot function for the sram code */+rockchip_boot_fn=virt_to_phys(rockchip_secondary_startup);++/* copy the trampoline to sram, that runs during startup of the core */+memcpy(sram_base_addr,&rockchip_secondary_trampoline,trampoline_sz);+flush_cache_all();+outer_clean_range(0,trampoline_sz);++dsb_sev();++return0;+}++staticvoid__initrockchip_smp_prepare_cpus(unsignedintmax_cpus)+{+structdevice_node*node;+unsignedinti;++node=of_find_compatible_node(NULL,NULL,"arm,cortex-a9-scu");+if(!node){+pr_err("%s: missing scu\n",__func__);+return;+}++scu_base_addr=of_iomap(node,0);+if(!scu_base_addr){+pr_err("%s: could not map scu registers\n",__func__);+return;+}++node=of_find_compatible_node(NULL,NULL,"rockchip,rk3066-sram");+if(!node){+pr_err("%s: could not find sram dt node\n",__func__);+return;+}++if(rockchip_smp_prepare_sram(node))+return;++node=of_find_compatible_node(NULL,NULL,"rockchip,rk3066-pmu");+if(!node){+pr_err("%s: could not find sram dt node\n",__func__);+return;+}++pmu_base_addr=of_iomap(node,0);+if(!pmu_base_addr){+pr_err("%s: could not map pmu registers\n",__func__);+return;+}++/* enable the SCU power domain */+pmu_set_power_domain(PMU_PWRDN_SCU,true);++/*+*Whilethenumberofcpusisgatheredfromdt,alsogetthenumber+*ofcoresfromthescutoverifythisvaluewhenbootingthecores.+*/+ncores=scu_get_core_count(scu_base_addr);++scu_enable(scu_base_addr);++/* Make sure that all cores except the first are really off */+for(i=1;i<ncores;i++)+pmu_set_power_domain(0+i,false);+}++structsmp_operationsrockchip_smp_ops__initdata={+.smp_prepare_cpus=rockchip_smp_prepare_cpus,+.smp_boot_secondary=rockchip_boot_secondary,+};
From: Mark Rutland <mark.rutland@arm.com> Date: 2014-01-16 12:46:20
On Wed, Jan 15, 2014 at 09:41:28PM +0000, Heiko St?bner wrote:
quoted hunk
This implements support for the mmio-sram-reserved option to keep the
genpool from using these areas.
Suggested-by: Rob Herring <redacted>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
---
drivers/misc/sram.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 110 insertions(+), 8 deletions(-)
@@ -65,19 +75,111 @@ static int sram_probe(struct platform_device *pdev)if(!sram->pool)return-ENOMEM;-ret=gen_pool_add_virt(sram->pool,(unsignedlong)virt_base,-res->start,size,-1);-if(ret<0){-if(sram->clk)-clk_disable_unprepare(sram->clk);-returnret;+if(pdev->dev.of_node){+reserved_list=of_get_property(pdev->dev.of_node,+"mmio-sram-reserved",+&reserved_size);+if(reserved_list){+reserved_size/=sizeof(*reserved_list);
As a general observation, It looks like a lot of people need to know how
many array elements a property might hold (for datastructure
allocation), and are open-coding element counting.
I think it would be nice if we had a helper function to count how many
elements a property can hold (of_property_count_u32_elems?) that would
centralise strict sanity checking (e.g. prop->len % elem_size == 0) and
DTB format details (so you don't have to care about endianness, and it
becomes possible to add DTB metadata later and get runtime type
checking).
That can all come later and shouldn't block this patch.
+ if (!reserved_size || reserved_size % 2) {
+ dev_warn(&pdev->dev, "wrong number of arguments in mmio-sram-reserved\n");
+ reserved_list = NULL;
+ reserved_size = 0;
+ }
+ }
+ }
+
+ /*
+ * We need an additional block to mark the end of the memory region
+ * after the reserved blocks from the dt are processed.
+ */
+ nblocks = reserved_size / 2 + 1;
+ rblocks = kmalloc((nblocks) * sizeof(*rblocks), GFP_KERNEL);
+ if (!rblocks) {
+ ret = -ENOMEM;
+ goto err_alloc;
+ }
+
+ cur_start = 0;
+ for (i = 0; i < nblocks - 1; i++) {
+ rblocks[i].start = be32_to_cpu(*reserved_list++);
+ rblocks[i].size = be32_to_cpu(*reserved_list++);
It feels a little odd to have to have to care about the format of the
dtb and do endianness conversion here. It would be nice to limit the
scope of DTB format details to the of_ helper functions.
Could you use of_property_read_u32_index here instead please?
Otherwise this looks fine to me.
Cheers,
Mark.
From: Rob Herring <hidden> Date: 2014-01-16 14:36:46
On Wed, Jan 15, 2014 at 3:40 PM, Heiko St?bner [off-list ref] wrote:
Some SoCs need parts of their sram for special purposes. So while being part
of the peripheral, it should not be part of the genpool controlling the sram.
Therefore add an option mmio-sram-reserved to keep arbitrary portions of the
sram from general usage.
Suggested-by: Rob Herring <redacted>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Tested-by: Ulrich Prinz <redacted>
@@ -8,9 +8,17 @@ Required properties: - reg : SRAM iomem address range+Optional properties:++- mmio-sram-reserved: ordered list of reserved chunks inside the sram that+ should not be used by the operating system.+ Format is <base size>, <base size>, ...; with base being relative to the+ reg property base.+ Example: sram: sram at 5c000000 { compatible = "mmio-sram"; reg = <0x5c000000 0x40000>; /* 256 KiB SRAM at address 0x5c000000 */+ mmio-sram-reserved = <0x0 0x100>; /* reserve 0x5c000000-0x5c000100 */ };--
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper function that also centralises strict sanity checking
and DTB format details.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Hi Mark,
did you mean it like this? I've tested it with the sram-reserve change and
it made the part of the determining the number elements a lot nicer :-)
drivers/of/base.c | 32 ++++++++++++++++++++++++++++++++
include/linux/of.h | 8 ++++++++
2 files changed, 40 insertions(+)
@@ -920,6 +920,38 @@ int of_property_read_u32_index(const struct device_node *np,EXPORT_SYMBOL_GPL(of_property_read_u32_index);/**+*of_property_count_u32_elems-Countthenumberofu32valuesinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu32elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu32and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u32_elems(conststructdevice_node*np,+constchar*propname)+{+intelem_size=sizeof(u32);+intlen;+structproperty*prop=of_find_property(np,propname,&len);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s is not a multiple of u32\n",propname);+return-EINVAL;+}++returnlen/elem_size;+}+EXPORT_SYMBOL_GPL(of_property_count_u32_elems);++/***of_property_read_u8_array-Findandreadanarrayofu8fromaproperty.**@np:devicenodefromwhichthepropertyvalueistoberead.
From: Rob Herring <hidden> Date: 2014-01-17 14:29:10
On Thu, Jan 16, 2014 at 12:04 PM, Heiko St?bner [off-list ref] wrote:
quoted hunk
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper function that also centralises strict sanity checking
and DTB format details.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Hi Mark,
did you mean it like this? I've tested it with the sram-reserve change and
it made the part of the determining the number elements a lot nicer :-)
drivers/of/base.c | 32 ++++++++++++++++++++++++++++++++
include/linux/of.h | 8 ++++++++
2 files changed, 40 insertions(+)
@@ -920,6 +920,38 @@ int of_property_read_u32_index(const struct device_node *np,EXPORT_SYMBOL_GPL(of_property_read_u32_index);/**+*of_property_count_u32_elems-Countthenumberofu32valuesinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu32elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu32and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u32_elems(conststructdevice_node*np,+constchar*propname)+{+intelem_size=sizeof(u32);
This should be a parameter, so functions for different sized
properties can be a simple wrapper function.
+ int len;
+ struct property *prop = of_find_property(np, propname, &len);
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ if (prop->length % elem_size != 0) {
+ pr_err("size of %s is not a multiple of u32\n", propname);
The node name would be useful here too.
quoted hunk
+ return -EINVAL;
+ }
+
+ return len / elem_size;
+}
+EXPORT_SYMBOL_GPL(of_property_count_u32_elems);
+
+/**
* of_property_read_u8_array - Find and read an array of u8 from a property.
*
* @np: device node from which the property value is to be read.
From: Mark Rutland <mark.rutland@arm.com> Date: 2014-01-17 14:45:37
On Thu, Jan 16, 2014 at 06:04:42PM +0000, Heiko St?bner wrote:
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper function that also centralises strict sanity checking
and DTB format details.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Hi Mark,
did you mean it like this? I've tested it with the sram-reserve change and
it made the part of the determining the number elements a lot nicer :-)
@@ -920,6 +920,38 @@ int of_property_read_u32_index(const struct device_node *np,EXPORT_SYMBOL_GPL(of_property_read_u32_index);/**+*of_property_count_u32_elems-Countthenumberofu32valuesinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu32elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu32and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u32_elems(conststructdevice_node*np,+constchar*propname)+{+intelem_size=sizeof(u32);+intlen;+structproperty*prop=of_find_property(np,propname,&len);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s is not a multiple of u32\n",propname);+return-EINVAL;+}++returnlen/elem_size;+}+EXPORT_SYMBOL_GPL(of_property_count_u32_elems);
As Rob said in his reply, it would be nice to split this into a static
helper that took elem size as a parameter, so we can have the full suite
of of_property_count_{u8,u16,u32,u64}_elems.
Also, I think you can get rid of len and always use prop->length, as
other helpers seem to do.
Cheers for putting this together!
Mark.
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
drivers/of/base.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 32 +++++++++++++++++
2 files changed, 130 insertions(+)
@@ -862,6 +862,104 @@ struct device_node *of_find_node_by_phandle(phandle handle)EXPORT_SYMBOL(of_find_node_by_phandle);/**+*of_count_property_elems_of_size-Countthenumberofelementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*@elem_size:sizeoftheindividualelement+*/+staticintof_count_property_elems_of_size(conststructdevice_node*np,+constchar*propname,intelem_size)+{+structproperty*prop=of_find_property(np,propname,NULL);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s in node %s is not a multiple of %d\n",+propname,np->name,elem_size);+return-EINVAL;+}++returnprop->length/elem_size;+}++/**+*of_property_count_u8_elems-Countthenumberofu8elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu8elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu8and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u8_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_count_property_elems_of_size(np,propname,sizeof(u8));+}+EXPORT_SYMBOL_GPL(of_property_count_u8_elems);++/**+*of_property_count_u16_elems-Countthenumberofu16elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu16elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu16and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u16_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_count_property_elems_of_size(np,propname,sizeof(u16));+}+EXPORT_SYMBOL_GPL(of_property_count_u16_elems);++/**+*of_property_count_u32_elems-Countthenumberofu32elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu32elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu32and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u32_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_count_property_elems_of_size(np,propname,sizeof(u32));+}+EXPORT_SYMBOL_GPL(of_property_count_u32_elems);++/**+*of_property_count_u64_elems-Countthenumberofu64elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu64elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu64and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u64_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_count_property_elems_of_size(np,propname,sizeof(u64));+}+EXPORT_SYMBOL_GPL(of_property_count_u64_elems);++/***of_find_property_value_of_size**@np:devicenodefromwhichthepropertyvalueistoberead.
From: Mark Rutland <mark.rutland@arm.com> Date: 2014-01-17 16:54:11
On Fri, Jan 17, 2014 at 03:44:14PM +0000, Heiko St?bner wrote:
quoted hunk
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
drivers/of/base.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 32 +++++++++++++++++
2 files changed, 130 insertions(+)
As a minor nit, it would be nicer to have 'count' and 'property' switch
places in the name (i.e. call this of_property_count_elems_of_size).
That way it's concistent with the naming of the wrappers.
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ if (prop->length % elem_size != 0) {
+ pr_err("size of %s in node %s is not a multiple of %d\n",
+ propname, np->name, elem_size);
It would be nice to use np->full_name so you get the absolute path of
the node -- it makes finding them easier later.
Otherwise, the patch looks good to me, thanks for implementing it!
With those changes:
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Cheers,
Mark.
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
---
changes since v2:
address more comments from Mark Rutland
- switch to of_property_count_elems_of_size
- use full_name instead of name in error message
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
Posted for completenes sake. If nobody complains,
I'll simply make it part of my Rockchip-SMP series.
drivers/of/base.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 32 +++++++++++++++++
2 files changed, 131 insertions(+)
@@ -862,6 +862,105 @@ struct device_node *of_find_node_by_phandle(phandle handle)EXPORT_SYMBOL(of_find_node_by_phandle);/**+*of_property_count_elems_of_size-Countthenumberofelementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*@elem_size:sizeoftheindividualelement+*/+staticintof_property_count_elems_of_size(conststructdevice_node*np,+constchar*propname,intelem_size)+{+structproperty*prop=of_find_property(np,propname,NULL);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++pr_err("size of %s in node %s is not a multiple of %d\n",propname,np->full_name,elem_size);+if(prop->length%elem_size!=0){+pr_err("size of %s in node %s is not a multiple of %d\n",+propname,np->full_name,elem_size);+return-EINVAL;+}++returnprop->length/elem_size;+}++/**+*of_property_count_u8_elems-Countthenumberofu8elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu8elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu8and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u8_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_property_count_elems_of_size(np,propname,sizeof(u8));+}+EXPORT_SYMBOL_GPL(of_property_count_u8_elems);++/**+*of_property_count_u16_elems-Countthenumberofu16elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu16elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu16and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u16_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_property_count_elems_of_size(np,propname,sizeof(u16));+}+EXPORT_SYMBOL_GPL(of_property_count_u16_elems);++/**+*of_property_count_u32_elems-Countthenumberofu32elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu32elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu32and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u32_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_property_count_elems_of_size(np,propname,sizeof(u32));+}+EXPORT_SYMBOL_GPL(of_property_count_u32_elems);++/**+*of_property_count_u64_elems-Countthenumberofu64elementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*+*Searchforapropertyinadevicenodeandcountthenumberofu64elements+*init.Returnsnumberofelementsonsucess,-EINVALifthepropertydoes+*notexistoritslengthdoesnotmatchamultipleofu64and-ENODATAifthe+*propertydoesnothaveavalue.+*/+intof_property_count_u64_elems(conststructdevice_node*np,+constchar*propname)+{+returnof_property_count_elems_of_size(np,propname,sizeof(u64));+}+EXPORT_SYMBOL_GPL(of_property_count_u64_elems);++/***of_find_property_value_of_size**@np:devicenodefromwhichthepropertyvalueistoberead.
From: Rob Herring <hidden> Date: 2014-01-17 17:42:17
On Fri, Jan 17, 2014 at 9:44 AM, Heiko St?bner [off-list ref] wrote:
quoted hunk
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
drivers/of/base.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/of.h | 32 +++++++++++++++++
2 files changed, 130 insertions(+)
@@ -862,6 +862,104 @@ struct device_node *of_find_node_by_phandle(phandle handle)EXPORT_SYMBOL(of_find_node_by_phandle);/**+*of_count_property_elems_of_size-Countthenumberofelementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*@elem_size:sizeoftheindividualelement+*/+staticintof_count_property_elems_of_size(conststructdevice_node*np,+constchar*propname,intelem_size)+{+structproperty*prop=of_find_property(np,propname,NULL);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s in node %s is not a multiple of %d\n",+propname,np->name,elem_size);+return-EINVAL;+}++returnprop->length/elem_size;+}
Export this one.
+
+/**
+ * of_property_count_u8_elems - Count the number of u8 elements in a property
+ *
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node and count the number of u8 elements
+ * in it. Returns number of elements on sucess, -EINVAL if the property does
+ * not exist or its length does not match a multiple of u8 and -ENODATA if the
+ * property does not have a value.
+ */
+int of_property_count_u8_elems(const struct device_node *np,
+ const char *propname)
+{
+ return of_count_property_elems_of_size(np, propname, sizeof(u8));
+}
+EXPORT_SYMBOL_GPL(of_property_count_u8_elems);
And make all these static inline.
Then you only need a single empty function for !OF.
Rob
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
changes since v3:
address more comments from Rob Herring
- export the base function and inline the type-specific wrappers
changes since v2:
address more comments from Mark Rutland
- switch to of_property_count_elems_of_size
- use full_name instead of name in error message
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
Mark, does your Reviewed-by holds for this variant too?
drivers/of/base.c | 32 ++++++++++++++++++++++
include/linux/of.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+)
@@ -862,6 +862,38 @@ struct device_node *of_find_node_by_phandle(phandle handle)EXPORT_SYMBOL(of_find_node_by_phandle);/**+*of_property_count_elems_of_size-Countthenumberofelementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*@elem_size:sizeoftheindividualelement+*+*Searchforapropertyinadevicenodeandcountthenumberofelementsof+*sizeelem_sizeinit.Returnsnumberofelementsonsucess,-EINVALifthe+*propertydoesnotexistoritslengthdoesnotmatchamultipleofu16and+*-ENODATAifthepropertydoesnothaveavalue.+*/+intof_property_count_elems_of_size(conststructdevice_node*np,+constchar*propname,intelem_size)+{+structproperty*prop=of_find_property(np,propname,NULL);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s in node %s is not a multiple of %d\n",+propname,np->full_name,elem_size);+return-EINVAL;+}++returnprop->length/elem_size;+}+EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);++/***of_find_property_value_of_size**@np:devicenodefromwhichthepropertyvalueistoberead.
From: Rob Herring <hidden> Date: 2014-01-18 15:07:34
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St?bner [off-list ref] wrote:
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
Rob
quoted hunk
changes since v3:
address more comments from Rob Herring
- export the base function and inline the type-specific wrappers
changes since v2:
address more comments from Mark Rutland
- switch to of_property_count_elems_of_size
- use full_name instead of name in error message
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
Mark, does your Reviewed-by holds for this variant too?
drivers/of/base.c | 32 ++++++++++++++++++++++
include/linux/of.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+)
@@ -862,6 +862,38 @@ struct device_node *of_find_node_by_phandle(phandle handle)EXPORT_SYMBOL(of_find_node_by_phandle);/**+*of_property_count_elems_of_size-Countthenumberofelementsinaproperty+*+*@np:devicenodefromwhichthepropertyvalueistoberead.+*@propname:nameofthepropertytobesearched.+*@elem_size:sizeoftheindividualelement+*+*Searchforapropertyinadevicenodeandcountthenumberofelementsof+*sizeelem_sizeinit.Returnsnumberofelementsonsucess,-EINVALifthe+*propertydoesnotexistoritslengthdoesnotmatchamultipleofu16and+*-ENODATAifthepropertydoesnothaveavalue.+*/+intof_property_count_elems_of_size(conststructdevice_node*np,+constchar*propname,intelem_size)+{+structproperty*prop=of_find_property(np,propname,NULL);++if(!prop)+return-EINVAL;+if(!prop->value)+return-ENODATA;++if(prop->length%elem_size!=0){+pr_err("size of %s in node %s is not a multiple of %d\n",+propname,np->full_name,elem_size);+return-EINVAL;+}++returnprop->length/elem_size;+}+EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);++/***of_find_property_value_of_size**@np:devicenodefromwhichthepropertyvalueistoberead.
Am Samstag, 18. Januar 2014, 09:07:30 schrieb Rob Herring:
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St?bner [off-list ref] wrote:
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
My plan at the moment was to "just" use it for my mmio-sram-reserve stuff -
just wanted to make sure that this change is sane, before having to sent the
whole thing for each iteration.
I haven't yet looked where the other users, that Mark mentioned, are at :-)
Heiko
quoted
changes since v3:
address more comments from Rob Herring
- export the base function and inline the type-specific wrappers
changes since v2:
address more comments from Mark Rutland
- switch to of_property_count_elems_of_size
- use full_name instead of name in error message
changes since v1:
address comments from Rob Herring and Mark Rutland:
- provide a helper and a set of wrappers for u8-u64
- get rid of extra len variable, prop->length is enough
- include node name in error message
Mark, does your Reviewed-by holds for this variant too?
drivers/of/base.c | 32 ++++++++++++++++++++++
include/linux/of.h | 76
++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed,
108 insertions(+)
handle)>
EXPORT_SYMBOL(of_find_node_by_phandle);
/**
+ * of_property_count_elems_of_size - Count the number of elements in a
property + *
+ * @np: device node from which the property value is to be
read. + * @propname: name of the property to be searched.
+ * @elem_size: size of the individual element
+ *
+ * Search for a property in a device node and count the number of
elements of + * size elem_size in it. Returns number of elements on
sucess, -EINVAL if the + * property does not exist or its length does not
match a multiple of u16 and + * -ENODATA if the property does not have a
value.
+ */
+int of_property_count_elems_of_size(const struct device_node *np,
+ const char *propname, int elem_size)
+{
+ struct property *prop = of_find_property(np, propname, NULL);
+
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+
+ if (prop->length % elem_size != 0) {
+ pr_err("size of %s in node %s is not a multiple of %d\n",
+ propname, np->full_name, elem_size);
+ return -EINVAL;
+ }
+
+ return prop->length / elem_size;
+}
+EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
+
+/**
* of_find_property_value_of_size
*
* @np: device node from which the property value is to be
read.>
@@ -565,6 +573,74 @@ static inline int of_node_to_nid(struct device_node
*device) { return 0; }>
#endif
/**
+ * of_property_count_u8_elems - Count the number of u8 elements in a
property + *
+ * @np: device node from which the property value is to be
read. + * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node and count the number of u8
elements + * in it. Returns number of elements on sucess, -EINVAL if the
property does + * not exist or its length does not match a multiple of u8
and -ENODATA if the + * property does not have a value.
+ */
+static inline int of_property_count_u8_elems(const struct device_node
*np,
+ const char *propname)
+{
+ return of_property_count_elems_of_size(np, propname, sizeof(u8));
+}
+
+/**
+ * of_property_count_u16_elems - Count the number of u16 elements in a
property + *
+ * @np: device node from which the property value is to be
read. + * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node and count the number of u16
elements + * in it. Returns number of elements on sucess, -EINVAL if the
property does + * not exist or its length does not match a multiple of
u16 and -ENODATA if the + * property does not have a value.
+ */
+static inline int of_property_count_u16_elems(const struct device_node
*np, + const char *propname)
+{
+ return of_property_count_elems_of_size(np, propname, sizeof(u16));
+}
+
+/**
+ * of_property_count_u32_elems - Count the number of u32 elements in a
property + *
+ * @np: device node from which the property value is to be
read. + * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node and count the number of u32
elements + * in it. Returns number of elements on sucess, -EINVAL if the
property does + * not exist or its length does not match a multiple of
u32 and -ENODATA if the + * property does not have a value.
+ */
+static inline int of_property_count_u32_elems(const struct device_node
*np, + const char *propname)
+{
+ return of_property_count_elems_of_size(np, propname, sizeof(u32));
+}
+
+/**
+ * of_property_count_u64_elems - Count the number of u64 elements in a
property + *
+ * @np: device node from which the property value is to be
read. + * @propname: name of the property to be searched.
+ *
+ * Search for a property in a device node and count the number of u64
elements + * in it. Returns number of elements on sucess, -EINVAL if the
property does + * not exist or its length does not match a multiple of
u64 and -ENODATA if the + * property does not have a value.
+ */
+static inline int of_property_count_u64_elems(const struct device_node
*np, + const char *propname)
+{
+ return of_property_count_elems_of_size(np, propname, sizeof(u64));
+}
+
+/**
* of_property_read_bool - Findfrom a property
* @np: device node from which the property value is to be
read. * @propname: name of the property to be searched.
--
1.7.10.4
From: Grant Likely <hidden> Date: 2014-02-04 17:30:34
On Sat, 18 Jan 2014 09:07:30 -0600, Rob Herring [off-list ref] wrote:
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St??bner [off-list ref] wrote:
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
Hi Grant,
On Tuesday, 4. February 2014 17:30:34 Grant Likely wrote:
On Sat, 18 Jan 2014 09:07:30 -0600, Rob Herring [off-list ref]
wrote:
quoted
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St??bner [off-list ref] wrote:
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
I'll take that as an acked-by. Merged, thanks.
before you taking this patch, I was planning on simply sending this as part of
my rockchip-smp series - as I'm currently the only user of it :-) .
This going through your tree is most likely the better way, but now I need it
to somehow make its way into arm-soc too ... I guess some sort of stable
branch arm-soc could pull?
Thanks
Heiko
From: Grant Likely <hidden> Date: 2014-02-05 12:06:52
On Tue, 04 Feb 2014 19:48:17 +0100, Heiko St??bner [off-list ref] wrote:
Hi Grant,
On Tuesday, 4. February 2014 17:30:34 Grant Likely wrote:
quoted
On Sat, 18 Jan 2014 09:07:30 -0600, Rob Herring [off-list ref]
wrote:
quoted
quoted
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St????bner [off-list ref] wrote:
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
I'll take that as an acked-by. Merged, thanks.
before you taking this patch, I was planning on simply sending this as part of
my rockchip-smp series - as I'm currently the only user of it :-) .
This going through your tree is most likely the better way, but now I need it
to somehow make its way into arm-soc too ... I guess some sort of stable
branch arm-soc could pull?
Nah, I'll drop it from my tree. Add my acked-by and merge it via
arm-soc.
g.
Am Mittwoch, 5. Februar 2014, 12:06:52 schrieb Grant Likely:
On Tue, 04 Feb 2014 19:48:17 +0100, Heiko St??bner [off-list ref] wrote:
quoted
Hi Grant,
On Tuesday, 4. February 2014 17:30:34 Grant Likely wrote:
quoted
On Sat, 18 Jan 2014 09:07:30 -0600, Rob Herring [off-list ref]
wrote:
quoted
quoted
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St????bner [off-list ref]
wrote:
quoted
quoted
quoted
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded
implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper
functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
I'll take that as an acked-by. Merged, thanks.
before you taking this patch, I was planning on simply sending this as
part of my rockchip-smp series - as I'm currently the only user of it :-)
.
This going through your tree is most likely the better way, but now I need
it to somehow make its way into arm-soc too ... I guess some sort of
stable branch arm-soc could pull?
Nah, I'll drop it from my tree. Add my acked-by and merge it via
arm-soc.
As I said on IRC, now it seems like you can keep this patch in your tree :-)
If we're really going with reserved-memory like you suggested in the rockchip-
smp series it removes the need to count u32-elements in a property for me, as
the reserved blocks move into individual subnodes.
Heiko
From: Grant Likely <hidden> Date: 2014-02-05 13:47:39
On Wed, 05 Feb 2014 13:45:36 +0100, Heiko St??bner [off-list ref] wrote:
Am Mittwoch, 5. Februar 2014, 12:06:52 schrieb Grant Likely:
quoted
On Tue, 04 Feb 2014 19:48:17 +0100, Heiko St????bner [off-list ref] wrote:
quoted
Hi Grant,
On Tuesday, 4. February 2014 17:30:34 Grant Likely wrote:
quoted
On Sat, 18 Jan 2014 09:07:30 -0600, Rob Herring [off-list ref]
wrote:
quoted
quoted
On Sat, Jan 18, 2014 at 6:02 AM, Heiko St????????bner [off-list ref]
wrote:
quoted
quoted
quoted
quoted
quoted
The need to know the number of array elements in a property is
a common pattern. To prevent duplication of open-coded
implementations
add a helper static function that also centralises strict sanity
checking and DTB format details, as well as a set of wrapper
functions
for u8, u16, u32 and u64.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
Looks good. Do you plan to convert some users to use this?
I'll take that as an acked-by. Merged, thanks.
before you taking this patch, I was planning on simply sending this as
part of my rockchip-smp series - as I'm currently the only user of it :-)
.
This going through your tree is most likely the better way, but now I need
it to somehow make its way into arm-soc too ... I guess some sort of
stable branch arm-soc could pull?
Nah, I'll drop it from my tree. Add my acked-by and merge it via
arm-soc.
As I said on IRC, now it seems like you can keep this patch in your tree :-)
If we're really going with reserved-memory like you suggested in the rockchip-
smp series it removes the need to count u32-elements in a property for me, as
the reserved blocks move into individual subnodes.
Right, but I'm not going to merge a patch with no users. I'll leave it
out and it can be added to a series that converts some users to the new
API.
g.