diff mbox series

powernv: powercap: Add hard minimum powercap

Message ID 1551260002-26792-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com (mailing list archive)
State Changes Requested
Headers show
Series powernv: powercap: Add hard minimum powercap | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success next/apply_patch Successfully applied
snowpatch_ozlabs/build-ppc64le success build succeeded & removed 0 sparse warning(s)
snowpatch_ozlabs/build-ppc64be success build succeeded & removed 0 sparse warning(s)
snowpatch_ozlabs/build-ppc64e success build succeeded & removed 0 sparse warning(s)
snowpatch_ozlabs/build-pmac32 warning build succeeded but added 17 new sparse warning(s)
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 110 lines checked

Commit Message

Shilpasri G Bhat Feb. 27, 2019, 9:33 a.m. UTC
In POWER9, OCC(On-Chip-Controller) provides for hard and soft system
powercapping range. The hard powercap range is guaranteed while soft
powercap may or may not be asserted due to various power-thermal
reasons based on system configuration and workloads. This patch adds
a sysfs file to export the hard minimum powercap limit to allow the
user to set the appropriate powercap value that can be managed by the
system.

Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
---
 .../ABI/testing/sysfs-firmware-opal-powercap       | 10 ++++
 arch/powerpc/platforms/powernv/opal-powercap.c     | 66 +++++++++-------------
 2 files changed, 37 insertions(+), 39 deletions(-)

Comments

Daniel Axtens Feb. 28, 2019, 4:44 a.m. UTC | #1
Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> writes:

> In POWER9, OCC(On-Chip-Controller) provides for hard and soft system
> powercapping range. The hard powercap range is guaranteed while soft
> powercap may or may not be asserted due to various power-thermal
> reasons based on system configuration and workloads. This patch adds
> a sysfs file to export the hard minimum powercap limit to allow the
> user to set the appropriate powercap value that can be managed by the
> system.

Maybe it's common terminology and I'm just not aware of it, but what do
you mean by "asserted"? It doesn't appear elsewhere in the documentation
you're patching, and it's not a use of assert that I'm familiar with...

Regards,
Daniel

>
> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
> ---
>  .../ABI/testing/sysfs-firmware-opal-powercap       | 10 ++++
>  arch/powerpc/platforms/powernv/opal-powercap.c     | 66 +++++++++-------------
>  2 files changed, 37 insertions(+), 39 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-powercap b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> index c9b66ec..65db4c1 100644
> --- a/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> +++ b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> @@ -29,3 +29,13 @@ Description:	System powercap directory and attributes applicable for
>  		  creates a request for setting a new-powercap. The
>  		  powercap requested must be between powercap-min
>  		  and powercap-max.
> +
> +What:		/sys/firmware/opal/powercap/system-powercap/powercap-hard-min
> +Date:		Feb 2019
> +Contact:	Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
> +Description:	Hard minimum powercap
> +
> +		This file provides the hard minimum powercap limit in
> +		Watts. The powercap value above hard minimum is always
> +		guaranteed to be asserted and the powercap value below
> +		the hard minimum limit may or may not be guaranteed.
> diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
> index d90ee4f..38408e7 100644
> --- a/arch/powerpc/platforms/powernv/opal-powercap.c
> +++ b/arch/powerpc/platforms/powernv/opal-powercap.c
> @@ -139,10 +139,24 @@ static void powercap_add_attr(int handle, const char *name,
>  	attr->handle = handle;
>  	sysfs_attr_init(&attr->attr.attr);
>  	attr->attr.attr.name = name;
> -	attr->attr.attr.mode = 0444;
> +
> +	if (!strncmp(name, "powercap-current", strlen(name))) {
> +		attr->attr.attr.mode = 0664;
> +		attr->attr.store = powercap_store;
> +	} else {
> +		attr->attr.attr.mode = 0444;
> +	}
> +
>  	attr->attr.show = powercap_show;
>  }
>  
> +static const char * const powercap_strs[] = {
> +	"powercap-max",
> +	"powercap-min",
> +	"powercap-current",
> +	"powercap-hard-min",
> +};
> +
>  void __init opal_powercap_init(void)
>  {
>  	struct device_node *powercap, *node;
> @@ -167,60 +181,34 @@ void __init opal_powercap_init(void)
>  
>  	i = 0;
>  	for_each_child_of_node(powercap, node) {
> -		u32 cur, min, max;
> -		int j = 0;
> -		bool has_cur = false, has_min = false, has_max = false;
> +		u32 id;
> +		int j, count = 0;
>  
> -		if (!of_property_read_u32(node, "powercap-min", &min)) {
> -			j++;
> -			has_min = true;
> -		}
> -
> -		if (!of_property_read_u32(node, "powercap-max", &max)) {
> -			j++;
> -			has_max = true;
> -		}
> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++)
> +			if (!of_property_read_u32(node, powercap_strs[j], &id))
> +				count++;
>  
> -		if (!of_property_read_u32(node, "powercap-current", &cur)) {
> -			j++;
> -			has_cur = true;
> -		}
> -
> -		pcaps[i].pattrs = kcalloc(j, sizeof(struct powercap_attr),
> +		pcaps[i].pattrs = kcalloc(count, sizeof(struct powercap_attr),
>  					  GFP_KERNEL);
>  		if (!pcaps[i].pattrs)
>  			goto out_pcaps_pattrs;
>  
> -		pcaps[i].pg.attrs = kcalloc(j + 1, sizeof(struct attribute *),
> +		pcaps[i].pg.attrs = kcalloc(count + 1,
> +					    sizeof(struct attribute *),
>  					    GFP_KERNEL);
>  		if (!pcaps[i].pg.attrs) {
>  			kfree(pcaps[i].pattrs);
>  			goto out_pcaps_pattrs;
>  		}
>  
> -		j = 0;
>  		pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
> -		if (has_min) {
> -			powercap_add_attr(min, "powercap-min",
> -					  &pcaps[i].pattrs[j]);
> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> -			j++;
> -		}
> -
> -		if (has_max) {
> -			powercap_add_attr(max, "powercap-max",
> -					  &pcaps[i].pattrs[j]);
> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> -			j++;
> -		}
> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++) {
> +			if (of_property_read_u32(node, powercap_strs[j], &id))
> +				continue;
>  
> -		if (has_cur) {
> -			powercap_add_attr(cur, "powercap-current",
> +			powercap_add_attr(id, powercap_strs[j],
>  					  &pcaps[i].pattrs[j]);
> -			pcaps[i].pattrs[j].attr.attr.mode |= 0220;
> -			pcaps[i].pattrs[j].attr.store = powercap_store;
>  			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> -			j++;
>  		}
>  
>  		if (sysfs_create_group(powercap_kobj, &pcaps[i].pg)) {
> -- 
> 1.8.3.1
Shilpasri G Bhat Feb. 28, 2019, 5:55 a.m. UTC | #2
Hi,

On 02/28/2019 10:14 AM, Daniel Axtens wrote:
> Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> writes:
> 
>> In POWER9, OCC(On-Chip-Controller) provides for hard and soft system
>> powercapping range. The hard powercap range is guaranteed while soft
>> powercap may or may not be asserted due to various power-thermal
>> reasons based on system configuration and workloads. This patch adds
>> a sysfs file to export the hard minimum powercap limit to allow the
>> user to set the appropriate powercap value that can be managed by the
>> system.
> 
> Maybe it's common terminology and I'm just not aware of it, but what do
> you mean by "asserted"? It doesn't appear elsewhere in the documentation
> you're patching, and it's not a use of assert that I'm familiar with...
> 
> Regards,
> Daniel
> 

I meant to say powercap will not be assured in the soft powercap range, i.e,
system may or may not be throttled of CPU frequency to remain within the powercap.

I can reword the document and commit message.

Thanks and Regards,
Shilpa

>>
>> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
>> ---
>>  .../ABI/testing/sysfs-firmware-opal-powercap       | 10 ++++
>>  arch/powerpc/platforms/powernv/opal-powercap.c     | 66 +++++++++-------------
>>  2 files changed, 37 insertions(+), 39 deletions(-)
>>
>> diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-powercap b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
>> index c9b66ec..65db4c1 100644
>> --- a/Documentation/ABI/testing/sysfs-firmware-opal-powercap
>> +++ b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
>> @@ -29,3 +29,13 @@ Description:	System powercap directory and attributes applicable for
>>  		  creates a request for setting a new-powercap. The
>>  		  powercap requested must be between powercap-min
>>  		  and powercap-max.
>> +
>> +What:		/sys/firmware/opal/powercap/system-powercap/powercap-hard-min
>> +Date:		Feb 2019
>> +Contact:	Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
>> +Description:	Hard minimum powercap
>> +
>> +		This file provides the hard minimum powercap limit in
>> +		Watts. The powercap value above hard minimum is always
>> +		guaranteed to be asserted and the powercap value below
>> +		the hard minimum limit may or may not be guaranteed.
>> diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
>> index d90ee4f..38408e7 100644
>> --- a/arch/powerpc/platforms/powernv/opal-powercap.c
>> +++ b/arch/powerpc/platforms/powernv/opal-powercap.c
>> @@ -139,10 +139,24 @@ static void powercap_add_attr(int handle, const char *name,
>>  	attr->handle = handle;
>>  	sysfs_attr_init(&attr->attr.attr);
>>  	attr->attr.attr.name = name;
>> -	attr->attr.attr.mode = 0444;
>> +
>> +	if (!strncmp(name, "powercap-current", strlen(name))) {
>> +		attr->attr.attr.mode = 0664;
>> +		attr->attr.store = powercap_store;
>> +	} else {
>> +		attr->attr.attr.mode = 0444;
>> +	}
>> +
>>  	attr->attr.show = powercap_show;
>>  }
>>  
>> +static const char * const powercap_strs[] = {
>> +	"powercap-max",
>> +	"powercap-min",
>> +	"powercap-current",
>> +	"powercap-hard-min",
>> +};
>> +
>>  void __init opal_powercap_init(void)
>>  {
>>  	struct device_node *powercap, *node;
>> @@ -167,60 +181,34 @@ void __init opal_powercap_init(void)
>>  
>>  	i = 0;
>>  	for_each_child_of_node(powercap, node) {
>> -		u32 cur, min, max;
>> -		int j = 0;
>> -		bool has_cur = false, has_min = false, has_max = false;
>> +		u32 id;
>> +		int j, count = 0;
>>  
>> -		if (!of_property_read_u32(node, "powercap-min", &min)) {
>> -			j++;
>> -			has_min = true;
>> -		}
>> -
>> -		if (!of_property_read_u32(node, "powercap-max", &max)) {
>> -			j++;
>> -			has_max = true;
>> -		}
>> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++)
>> +			if (!of_property_read_u32(node, powercap_strs[j], &id))
>> +				count++;
>>  
>> -		if (!of_property_read_u32(node, "powercap-current", &cur)) {
>> -			j++;
>> -			has_cur = true;
>> -		}
>> -
>> -		pcaps[i].pattrs = kcalloc(j, sizeof(struct powercap_attr),
>> +		pcaps[i].pattrs = kcalloc(count, sizeof(struct powercap_attr),
>>  					  GFP_KERNEL);
>>  		if (!pcaps[i].pattrs)
>>  			goto out_pcaps_pattrs;
>>  
>> -		pcaps[i].pg.attrs = kcalloc(j + 1, sizeof(struct attribute *),
>> +		pcaps[i].pg.attrs = kcalloc(count + 1,
>> +					    sizeof(struct attribute *),
>>  					    GFP_KERNEL);
>>  		if (!pcaps[i].pg.attrs) {
>>  			kfree(pcaps[i].pattrs);
>>  			goto out_pcaps_pattrs;
>>  		}
>>  
>> -		j = 0;
>>  		pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
>> -		if (has_min) {
>> -			powercap_add_attr(min, "powercap-min",
>> -					  &pcaps[i].pattrs[j]);
>> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
>> -			j++;
>> -		}
>> -
>> -		if (has_max) {
>> -			powercap_add_attr(max, "powercap-max",
>> -					  &pcaps[i].pattrs[j]);
>> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
>> -			j++;
>> -		}
>> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++) {
>> +			if (of_property_read_u32(node, powercap_strs[j], &id))
>> +				continue;
>>  
>> -		if (has_cur) {
>> -			powercap_add_attr(cur, "powercap-current",
>> +			powercap_add_attr(id, powercap_strs[j],
>>  					  &pcaps[i].pattrs[j]);
>> -			pcaps[i].pattrs[j].attr.attr.mode |= 0220;
>> -			pcaps[i].pattrs[j].attr.store = powercap_store;
>>  			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
>> -			j++;
>>  		}
>>  
>>  		if (sysfs_create_group(powercap_kobj, &pcaps[i].pg)) {
>> -- 
>> 1.8.3.1
>
Gautham R Shenoy Feb. 28, 2019, 9:52 a.m. UTC | #3
Hi Shilpa,

On Thu, Feb 28, 2019 at 11:25:25AM +0530, Shilpasri G Bhat wrote:
> Hi,
> 
> On 02/28/2019 10:14 AM, Daniel Axtens wrote:
> > Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> writes:
> > 
> >> In POWER9, OCC(On-Chip-Controller) provides for hard and soft system
> >> powercapping range. The hard powercap range is guaranteed while soft
> >> powercap may or may not be asserted due to various power-thermal
> >> reasons based on system configuration and workloads. This patch adds
> >> a sysfs file to export the hard minimum powercap limit to allow the
> >> user to set the appropriate powercap value that can be managed by the
> >> system.
> > 
> > Maybe it's common terminology and I'm just not aware of it, but what do
> > you mean by "asserted"? It doesn't appear elsewhere in the documentation
> > you're patching, and it's not a use of assert that I'm familiar with...
> > 
> > Regards,
> > Daniel
> > 
> 
> I meant to say powercap will not be assured in the soft powercap range, i.e,
> system may or may not be throttled of CPU frequency to remain within the powercap.
> 
> I can reword the document and commit message.

I agree with Daniel. How about replacing "asserted" with "enforced by
the OCC"?


> 
> Thanks and Regards,
> Shilpa

--
Thanks and Regards
gautham.

> 
> >>
> >> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
> >> ---
> >>  .../ABI/testing/sysfs-firmware-opal-powercap       | 10 ++++
> >>  arch/powerpc/platforms/powernv/opal-powercap.c     | 66 +++++++++-------------
> >>  2 files changed, 37 insertions(+), 39 deletions(-)
> >>
> >> diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-powercap b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> >> index c9b66ec..65db4c1 100644
> >> --- a/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> >> +++ b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
> >> @@ -29,3 +29,13 @@ Description:	System powercap directory and attributes applicable for
> >>  		  creates a request for setting a new-powercap. The
> >>  		  powercap requested must be between powercap-min
> >>  		  and powercap-max.
> >> +
> >> +What:		/sys/firmware/opal/powercap/system-powercap/powercap-hard-min
> >> +Date:		Feb 2019
> >> +Contact:	Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
> >> +Description:	Hard minimum powercap
> >> +
> >> +		This file provides the hard minimum powercap limit in
> >> +		Watts. The powercap value above hard minimum is always
> >> +		guaranteed to be asserted and the powercap value below
> >> +		the hard minimum limit may or may not be guaranteed.
> >> diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
> >> index d90ee4f..38408e7 100644
> >> --- a/arch/powerpc/platforms/powernv/opal-powercap.c
> >> +++ b/arch/powerpc/platforms/powernv/opal-powercap.c
> >> @@ -139,10 +139,24 @@ static void powercap_add_attr(int handle, const char *name,
> >>  	attr->handle = handle;
> >>  	sysfs_attr_init(&attr->attr.attr);
> >>  	attr->attr.attr.name = name;
> >> -	attr->attr.attr.mode = 0444;
> >> +
> >> +	if (!strncmp(name, "powercap-current", strlen(name))) {
> >> +		attr->attr.attr.mode = 0664;
> >> +		attr->attr.store = powercap_store;
> >> +	} else {
> >> +		attr->attr.attr.mode = 0444;
> >> +	}
> >> +
> >>  	attr->attr.show = powercap_show;
> >>  }
> >>  
> >> +static const char * const powercap_strs[] = {
> >> +	"powercap-max",
> >> +	"powercap-min",
> >> +	"powercap-current",
> >> +	"powercap-hard-min",
> >> +};
> >> +
> >>  void __init opal_powercap_init(void)
> >>  {
> >>  	struct device_node *powercap, *node;
> >> @@ -167,60 +181,34 @@ void __init opal_powercap_init(void)
> >>  
> >>  	i = 0;
> >>  	for_each_child_of_node(powercap, node) {
> >> -		u32 cur, min, max;
> >> -		int j = 0;
> >> -		bool has_cur = false, has_min = false, has_max = false;
> >> +		u32 id;
> >> +		int j, count = 0;
> >>  
> >> -		if (!of_property_read_u32(node, "powercap-min", &min)) {
> >> -			j++;
> >> -			has_min = true;
> >> -		}
> >> -
> >> -		if (!of_property_read_u32(node, "powercap-max", &max)) {
> >> -			j++;
> >> -			has_max = true;
> >> -		}
> >> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++)
> >> +			if (!of_property_read_u32(node, powercap_strs[j], &id))
> >> +				count++;
> >>  
> >> -		if (!of_property_read_u32(node, "powercap-current", &cur)) {
> >> -			j++;
> >> -			has_cur = true;
> >> -		}
> >> -
> >> -		pcaps[i].pattrs = kcalloc(j, sizeof(struct powercap_attr),
> >> +		pcaps[i].pattrs = kcalloc(count, sizeof(struct powercap_attr),
> >>  					  GFP_KERNEL);
> >>  		if (!pcaps[i].pattrs)
> >>  			goto out_pcaps_pattrs;
> >>  
> >> -		pcaps[i].pg.attrs = kcalloc(j + 1, sizeof(struct attribute *),
> >> +		pcaps[i].pg.attrs = kcalloc(count + 1,
> >> +					    sizeof(struct attribute *),
> >>  					    GFP_KERNEL);
> >>  		if (!pcaps[i].pg.attrs) {
> >>  			kfree(pcaps[i].pattrs);
> >>  			goto out_pcaps_pattrs;
> >>  		}
> >>  
> >> -		j = 0;
> >>  		pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
> >> -		if (has_min) {
> >> -			powercap_add_attr(min, "powercap-min",
> >> -					  &pcaps[i].pattrs[j]);
> >> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> >> -			j++;
> >> -		}
> >> -
> >> -		if (has_max) {
> >> -			powercap_add_attr(max, "powercap-max",
> >> -					  &pcaps[i].pattrs[j]);
> >> -			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> >> -			j++;
> >> -		}
> >> +		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++) {
> >> +			if (of_property_read_u32(node, powercap_strs[j], &id))
> >> +				continue;
> >>  
> >> -		if (has_cur) {
> >> -			powercap_add_attr(cur, "powercap-current",
> >> +			powercap_add_attr(id, powercap_strs[j],
> >>  					  &pcaps[i].pattrs[j]);
> >> -			pcaps[i].pattrs[j].attr.attr.mode |= 0220;
> >> -			pcaps[i].pattrs[j].attr.store = powercap_store;
> >>  			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
> >> -			j++;
> >>  		}
> >>  
> >>  		if (sysfs_create_group(powercap_kobj, &pcaps[i].pg)) {
> >> -- 
> >> 1.8.3.1
> >
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-firmware-opal-powercap b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
index c9b66ec..65db4c1 100644
--- a/Documentation/ABI/testing/sysfs-firmware-opal-powercap
+++ b/Documentation/ABI/testing/sysfs-firmware-opal-powercap
@@ -29,3 +29,13 @@  Description:	System powercap directory and attributes applicable for
 		  creates a request for setting a new-powercap. The
 		  powercap requested must be between powercap-min
 		  and powercap-max.
+
+What:		/sys/firmware/opal/powercap/system-powercap/powercap-hard-min
+Date:		Feb 2019
+Contact:	Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
+Description:	Hard minimum powercap
+
+		This file provides the hard minimum powercap limit in
+		Watts. The powercap value above hard minimum is always
+		guaranteed to be asserted and the powercap value below
+		the hard minimum limit may or may not be guaranteed.
diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
index d90ee4f..38408e7 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -139,10 +139,24 @@  static void powercap_add_attr(int handle, const char *name,
 	attr->handle = handle;
 	sysfs_attr_init(&attr->attr.attr);
 	attr->attr.attr.name = name;
-	attr->attr.attr.mode = 0444;
+
+	if (!strncmp(name, "powercap-current", strlen(name))) {
+		attr->attr.attr.mode = 0664;
+		attr->attr.store = powercap_store;
+	} else {
+		attr->attr.attr.mode = 0444;
+	}
+
 	attr->attr.show = powercap_show;
 }
 
+static const char * const powercap_strs[] = {
+	"powercap-max",
+	"powercap-min",
+	"powercap-current",
+	"powercap-hard-min",
+};
+
 void __init opal_powercap_init(void)
 {
 	struct device_node *powercap, *node;
@@ -167,60 +181,34 @@  void __init opal_powercap_init(void)
 
 	i = 0;
 	for_each_child_of_node(powercap, node) {
-		u32 cur, min, max;
-		int j = 0;
-		bool has_cur = false, has_min = false, has_max = false;
+		u32 id;
+		int j, count = 0;
 
-		if (!of_property_read_u32(node, "powercap-min", &min)) {
-			j++;
-			has_min = true;
-		}
-
-		if (!of_property_read_u32(node, "powercap-max", &max)) {
-			j++;
-			has_max = true;
-		}
+		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++)
+			if (!of_property_read_u32(node, powercap_strs[j], &id))
+				count++;
 
-		if (!of_property_read_u32(node, "powercap-current", &cur)) {
-			j++;
-			has_cur = true;
-		}
-
-		pcaps[i].pattrs = kcalloc(j, sizeof(struct powercap_attr),
+		pcaps[i].pattrs = kcalloc(count, sizeof(struct powercap_attr),
 					  GFP_KERNEL);
 		if (!pcaps[i].pattrs)
 			goto out_pcaps_pattrs;
 
-		pcaps[i].pg.attrs = kcalloc(j + 1, sizeof(struct attribute *),
+		pcaps[i].pg.attrs = kcalloc(count + 1,
+					    sizeof(struct attribute *),
 					    GFP_KERNEL);
 		if (!pcaps[i].pg.attrs) {
 			kfree(pcaps[i].pattrs);
 			goto out_pcaps_pattrs;
 		}
 
-		j = 0;
 		pcaps[i].pg.name = kasprintf(GFP_KERNEL, "%pOFn", node);
-		if (has_min) {
-			powercap_add_attr(min, "powercap-min",
-					  &pcaps[i].pattrs[j]);
-			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
-			j++;
-		}
-
-		if (has_max) {
-			powercap_add_attr(max, "powercap-max",
-					  &pcaps[i].pattrs[j]);
-			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
-			j++;
-		}
+		for (j = 0; j < ARRAY_SIZE(powercap_strs); j++) {
+			if (of_property_read_u32(node, powercap_strs[j], &id))
+				continue;
 
-		if (has_cur) {
-			powercap_add_attr(cur, "powercap-current",
+			powercap_add_attr(id, powercap_strs[j],
 					  &pcaps[i].pattrs[j]);
-			pcaps[i].pattrs[j].attr.attr.mode |= 0220;
-			pcaps[i].pattrs[j].attr.store = powercap_store;
 			pcaps[i].pg.attrs[j] = &pcaps[i].pattrs[j].attr.attr;
-			j++;
 		}
 
 		if (sysfs_create_group(powercap_kobj, &pcaps[i].pg)) {