powerpc/devtree: Add support for 'ibm,drc-info' property
Subsystems (4)
v2 cover powerpc/devtree: Add support for 'ibm,drc-info' property
Several properties in the DRC device tree format are replaced by more compact representations to allow, for example, for the encoding of vast amounts of memory, and or reduced duplication of information in related data structures.
"ibm,drc-info": This property, when present, replaces the following four properties: "ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types" and "ibm,drc-power-domains". This property is defined for all dynamically reconfigurable platform nodes. The "ibm,drc-info" elements are intended to provide a more compact representation, and reduce some search overhead.
"ibm,architecture.vec": Bidirectional communication mechanism between the host system and the front end processor indicating what features the host system supports and what features the front end processor will actually provide. In this case, we are indicating that the host system can support the new device tree structure "ibm,drc-info".
Michael Bringmann (4):
powerpc/firmware: Add definitions for new drc-info firmware feature. pseries/drc-info: Search new DRC properties for CPU indexes hotplug/drc-info: Add code to search new devtree property
powerpc: Enable support for new DRC devtree property
---
Changes in V2:
-- Minor changes to integrate to latest 4.13 code
PATCH v2 1/4 powerpc/firmware: Add definitions for new drc-info firmware feature
Firmware Features: Define new bit flag representing the presence of new device tree property "ibm,drc-info". The flag is used to tell the front end processor when the Linux kernel supports the new properties, and by the front end processor to tell the Linux kernel that the new property is present in the device tree.
--- arch/powerpc/include/asm/firmware.h | 3 ++- arch/powerpc/include/asm/prom.h | 1 + arch/powerpc/platforms/pseries/firmware.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/firmware.h +2 -1
@@ -51,6 +51,7 @@#define FW_FEATURE_BEST_ENERGY ASM_CONST(0x0000000080000000)#define FW_FEATURE_TYPE1_AFFINITY ASM_CONST(0x0000000100000000)#define FW_FEATURE_PRRN ASM_CONST(0x0000000200000000) +#define FW_FEATURE_DRC_INFO ASM_CONST(0x0000000400000000)#ifndef __ASSEMBLY__
@@ -67,7 +68,7 @@ enum {FW_FEATURE_CMO |FW_FEATURE_VPHN |FW_FEATURE_XCMO |FW_FEATURE_SET_MODE |FW_FEATURE_BEST_ENERGY |FW_FEATURE_TYPE1_AFFINITY |FW_FEATURE_PRRN | -FW_FEATURE_HPT_RESIZE , +FW_FEATURE_HPT_RESIZE |FW_FEATURE_DRC_INFO ,FW_FEATURE_PSERIES_ALWAYS =0 ,FW_FEATURE_POWERNV_POSSIBLE =FW_FEATURE_OPAL , FW_FEATURE_POWERNV_ALWAYS = 0,
arch/powerpc/include/asm/prom.h +1 -0
@@ -172,6 +172,7 @@ struct of_drconf_cell {#define OV5_HASH_GTSE 0x1940/* Guest Translation Shoot Down Avail */ /* Radix Table Extensions */ #define OV5_RADIX_GTSE 0x1A40/* Guest Translation Shoot Down Avail */ +#define OV5_DRC_INFO 0x1640/* Redef Prop Structures: drc-info */ /* Option Vector 6: IBM PAPR hints */ #define OV6_LINUX 0x02/* Linux is our OS */
arch/powerpc/platforms/pseries/firmware.c +1 -0
@@ -114,6 +114,7 @@ struct vec5_fw_feature { vec5_fw_features_table[] = { {FW_FEATURE_TYPE1_AFFINITY ,OV5_TYPE1_AFFINITY }, {FW_FEATURE_PRRN ,OV5_PRRN }, + {FW_FEATURE_DRC_INFO ,OV5_DRC_INFO }, };static void __init fw_vec5_feature_init (const char *vec5,unsigned long len)
PATCH v2 2/4 pseries/drc-info: Search DRC properties for CPU indexes
In reply to Michael Bringmannpseries/drc-info: Provide parallel routines to convert between drc_index and CPU numbers at runtime, using the older device-tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types" and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
--- arch/powerpc/include/asm/prom.h | 7 + arch/powerpc/platforms/pseries/of_helpers.c | 79 ++++++++++++ arch/powerpc/platforms/pseries/pseries_energy.c | 150 +++++++++++++++++++---- 3 files changed, 210 insertions(+), 26 deletions(-)
---
Changes in V2:
-- Minor changes to integrate to latest 4.13 code
arch/powerpc/include/asm/prom.h +7 -0
@@ -96,6 +96,13 @@ struct of_drconf_cell {#define DRCONF_MEM_AI_INVALID 0x00000040#define DRCONF_MEM_RESERVED 0x00000080 +extern int of_one_drc_info (struct property **prop,void **curval, +char **dtype,char **dname, +u32 *drc_index_start_p, +u32 *num_sequential_elems_p, +u32 *sequential_inc_p, +u32 *last_drc_index_p); +/* * There are two methods for telling firmware what our capabilities are. * Newer machines have an "ibm,client-architecture-support" method on the
arch/powerpc/platforms/pseries/of_helpers.c +79 -0
82 lines not on this page · raw message
arch/powerpc/platforms/pseries/pseries_energy.c +124 -26
189 lines not on this page · raw message
Re: [PATCH 2/4] pseries/drc-info: Search DRC properties for CPU indexes
Quoted 71 lines · Michael Bringmann
pseries/drc-info: Provide parallel routines to convert between
drc_indexand CPU numbers at runtime, using the older device-tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types" and "ibm,drc-power-domains"), or the new property "ibm,drc-info".Signed-off-by Michael Bringmann <[email protected]>--- arch/powerpc/include/asm/prom.h | 7 + arch/powerpc/platforms/pseries/of_helpers.c | 79 ++++++++++++ arch/powerpc/platforms/pseries/pseries_energy.c | 150 +++++++++++++++++++---- 3 files changed, 210 insertions(+), 26 deletions(-)---
Changes in V2:
-- Minor changes to integrate to latest 4.13 codearch/powerpc/include/asm/prom.h +7
-0@@ -96,6 +96,13 @@ struct of_drconf_cell {#define DRCONF_MEM_AI_INVALID 0x00000040#define DRCONF_MEM_RESERVED 0x00000080 +extern int of_one_drc_info (struct property **prop,void **curval, +char **dtype,char **dname, +u32 *drc_index_start_p, +u32 *num_sequential_elems_p, +u32 *sequential_inc_p, +u32 *last_drc_index_p); +/* * There are two methods for telling firmware what our capabilities are. * Newer machines have an "ibm,client-architecture-support" method on the arch/powerpc/platforms/pseries/of_helpers.c +29
-0@@ -36,3 +36,82 @@ struct device_node *pseries_of_derive_parent(const char *path)kfree (parent_path);return parent ? parent :ERR_PTR (-EINVAL ); } + + +/* Helper Routines to convert between drc_index to cpu numbers */ + +int of_one_drc_info (struct property **prop,void **curval, +char **dtype,char **dname, +u32 *drc_index_start_p, +u32 *num_sequential_elems_p, +u32 *sequential_inc_p, +u32 *last_drc_index_p) +{ +char *drc_type, *drc_name_prefix; +u32 drc_index_start, num_sequential_elems, dummy; +u32 sequential_inc, last_drc_index; +const char *p; +const __be32 *p2; + + drc_index_start = num_sequential_elems =0 ; + sequential_inc = last_drc_index =0 ; + +/* Get drc-type:encode-string */ + p = drc_type = (*curval); + p =of_prop_next_string (*prop, p); +if (!p) +return -EINVAL ; + +/* Get drc-name-prefix:encode-string */ + drc_name_prefix = (char *)p; + p =of_prop_next_string (*prop, p);
arch/powerpc/platforms/pseries/of_helpers.c struct device_node *pseries_of_derive_parent(const char *path) · line 77
Quoted 10 lines
arch/powerpc/platforms/pseries/of_helpers.c +10
-0+if (!p) +return -EINVAL ; + +/* Get drc-index-start:encode-int */ + p2 = (const __be32 *)p; + p2 =of_prop_next_u32 (*prop, p2, &drc_index_start); +if (!p2) +return -EINVAL ; + +/* Get/skip drc-name-suffix-start:encode-int */
Why are we skipping the drc name suffix start value? It seems this would make the routine unusable for anyone wanting to get drc-name values.
arch/powerpc/platforms/pseries/of_helpers.c struct device_node *pseries_of_derive_parent(const char *path) · line 79
Quoted 2 lines
arch/powerpc/platforms/pseries/of_helpers.c +2
-0+ p2 =of_prop_next_u32 (*prop, p2, &dummy); +if (!p)
shouldn't this be checking p2?
arch/powerpc/platforms/pseries/of_helpers.c struct device_node *pseries_of_derive_parent(const char *path) · line 92
Quoted 13 lines
arch/powerpc/platforms/pseries/of_helpers.c +13
-0+return -EINVAL ; + +/* Get number-sequential-elements:encode-int */ + p2 =of_prop_next_u32 (*prop, p2, &num_sequential_elems); +if (!p2) +return -EINVAL ; + +/* Get sequential-increment:encode-int */ + p2 =of_prop_next_u32 (*prop, p2, &sequential_inc); +if (!p2) +return -EINVAL ; + +/* Get/skip drc-power-domain:encode-int */
Same for power-domain, why skip it?
I don't think any parts of the kernel are currently looking at this piece of the DRC information, but if we are going to have a routine to return all the data for a drc-info block shouldn't it return all of it?
Would it be easier if the routine were to return a drc_info struct with pointers to the string values and int values read into it?
Quoted 56 lines
arch/powerpc/platforms/pseries/of_helpers.c +25
-0+ p2 =of_prop_next_u32 (*prop, p2, &dummy); +if (!p2) +return -EINVAL ; + +/* Should now know end of current entry */ + (*curval) = (void *)p2; + last_drc_index = drc_index_start + + ((num_sequential_elems-1 )*sequential_inc); + +if (dtype) + *dtype = drc_type; +if (dname) + *dname = drc_name_prefix; +if (drc_index_start_p) + *drc_index_start_p = drc_index_start; +if (num_sequential_elems_p) + *num_sequential_elems_p = num_sequential_elems; +if (sequential_inc_p) + *sequential_inc_p = sequential_inc; +if (last_drc_index_p) + *last_drc_index_p = last_drc_index; + +return 0 ; +} +EXPORT_SYMBOL (of_one_drc_info);arch/powerpc/platforms/pseries/pseries_energy.c +2
-5@@ -22,6 +22,7 @@#include <asm/page.h> #include <asm/hvcall.h> #include <asm/firmware.h> +#include <asm/prom.h> #define MODULE_VERS "1.0"@@ -38,7 +39,6 @@static u32 cpu_to_drc_index (int cpu) {struct device_node *dn =NULL ; -const int *indexes;int i;int rc =1 ;u32 ret =0 ;@@ -46,18 +46,65 @@ static u32 cpu_to_drc_index(int cpu) dn =of_find_node_by_path ("/cpus" );if (dn ==NULL ) goto err; - indexes =of_get_property (dn,"ibm,drc-indexes" ,NULL ); -if (indexes ==NULL ) - goto err_of_node_put; +/* Convert logical cpu number to core number */ i =cpu_core_index_of_thread (cpu); -/*
arch/powerpc/platforms/pseries/pseries_energy.c static u32 cpu_to_drc_index(int cpu) · line 55
Quoted 10 lines
arch/powerpc/platforms/pseries/pseries_energy.c +4
-6-* The first element indexes[0] is the number of drc_indexes -* returned in the list. Hence i+1 will get the drc_index -* corresponding to core number i. -*/ -WARN_ON (i > indexes[0 ]); - ret = indexes[i +1 ]; + +if (firmware_has_feature (FW_FEATURE_DRC_INFO )) { +struct property *info =NULL ; +int j, check_val = i;
Why use check_val here? it seems a bit confusing.
I think perhaps renaming 'i' to thread_index and using that everywhere may help the readability.
Quoted 15 lines
arch/powerpc/platforms/pseries/pseries_energy.c +15
-0+u32 num_set_entries; +u32 drc_index_start =0 ; +u32 last_drc_index =0 ; +u32 num_sequential_elems =0 ; +u32 sequential_inc =0 ; +char *dtype; +char *dname; +void *value; + + info =of_find_property (dn,"ibm,drc-info" ,NULL ); +if (info ==NULL ) + goto err_of_node_put; + + value = info->value; + value = (void *)of_prop_next_u32 (info, value, &num_set_entries);
arch/powerpc/platforms/pseries/pseries_energy.c static u32 cpu_to_drc_index(int cpu) · line 80
Quoted 10 lines
arch/powerpc/platforms/pseries/pseries_energy.c +10
-0+if (!value) + goto err_of_node_put; + +for (j =0 ; j < num_set_entries; j++) { + +of_one_drc_info (&info, &value, &dtype, &dname, + &drc_index_start, + &num_sequential_elems, + &sequential_inc, &last_drc_index); +if (strcmp (dtype,"CPU" ))
Perhaps use strncmp() here.
arch/powerpc/platforms/pseries/pseries_energy.c static u32 cpu_to_drc_index(int cpu) · line 83
Quoted 3 lines
arch/powerpc/platforms/pseries/pseries_energy.c +3
-0+ goto err; + +if (check_val < last_drc_index)
So, check_val here is just the thread_index for the cpu we are looking for. I think this value will likely always be less than last_drc_index. On systems I have always seen the drc-index values for CPUs start at 0x10000000 and increment from there.
If there is ever more than one set of drc-info blocks in the drc-info property this check would not be valid.
arch/powerpc/platforms/pseries/pseries_energy.c static u32 cpu_to_drc_index(int cpu) · line 91
Quoted 8 lines
arch/powerpc/platforms/pseries/pseries_energy.c +8
-0+break ; + +WARN_ON (((check_val-drc_index_start)% + sequential_inc) !=0 ); + } +WARN_ON ((num_sequential_elems ==0 ) || (sequential_inc ==0 )); + + ret = last_drc_index + (check_val*sequential_inc);
Shouldn't this be drc_index_start?
Quoted 67 lines
arch/powerpc/platforms/pseries/pseries_energy.c +44
-11+ }else { +const __be32 *indexes; + + indexes =of_get_property (dn,"ibm,drc-indexes" ,NULL ); +if (indexes ==NULL ) + goto err_of_node_put; + +/* +* The first element indexes[0] is the number of drc_indexes +* returned in the list. Hence i+1 will get the drc_index +* corresponding to core number i. +*/ +WARN_ON (i > indexes[0 ]); + ret = indexes[i +1 ]; + } + rc =0 ; err_of_node_put:@@ -72,34 +119,85 @@ static int drc_index_to_cpu(u32 drc_index) {struct device_node *dn =NULL ;const int *indexes; -int i, cpu =0 ; +int thread =0 , cpu =0 ;int rc =1 ; dn =of_find_node_by_path ("/cpus" );if (dn ==NULL ) goto err; - indexes =of_get_property (dn,"ibm,drc-indexes" ,NULL ); -if (indexes ==NULL ) - goto err_of_node_put; -/* -* First element in the array is the number of drc_indexes -* returned. Search through the list to find the matching -* drc_index and get the core number -*/ -for (i =0 ; i < indexes[0 ]; i++) { -if (indexes[i +1 ] == drc_index) + +if (firmware_has_feature (FW_FEATURE_DRC_INFO )) { +struct property *info =NULL ; +int j; +u32 num_set_entries; +u32 drc_index_start =0 ; +u32 last_drc_index =0 ; +u32 num_sequential_elems =0 ; +u32 sequential_inc =0 ; +char *dtype, *dname; +void *value; + + info =of_find_property (dn,"ibm,drc-info" ,NULL ); +if (info ==NULL ) + goto err_of_node_put; + + value = info->value; + value = (void *)of_prop_next_u32 (info, value, &num_set_entries); +if (!value) + goto err_of_node_put; + +for (j =0 ; j < num_set_entries; j++) { + +of_one_drc_info (&info, &value, &dtype, &dname, + &drc_index_start, + &num_sequential_elems, + &sequential_inc, &last_drc_index);
arch/powerpc/platforms/pseries/pseries_energy.c static int drc_index_to_cpu(u32 drc_index) · line 164
Quoted 10 lines
arch/powerpc/platforms/pseries/pseries_energy.c +10
-0+if (strcmp (dtype,"CPU" )) + goto err; + +WARN_ON (drc_index < drc_index_start); +WARN_ON (((drc_index-drc_index_start)% + sequential_inc) !=0 ); + +if (drc_index > last_drc_index) { + cpu += ((last_drc_index-drc_index_start)/ + sequential_inc);
Could we just use num_sequential_elems here?
cpu += num_sequential_elems;
-Nathan
Quoted 44 lines
arch/powerpc/platforms/pseries/pseries_energy.c +28
-4+continue ; + }else { + cpu += ((drc_index-drc_index_start)/ + sequential_inc); + } + + thread =cpu_first_thread_of_core (cpu); + rc =0 ;break ; + } + }else { +unsigned long int i; + + indexes =of_get_property (dn,"ibm,drc-indexes" ,NULL ); +if (indexes ==NULL ) + goto err_of_node_put; +/* +* First element in the array is the number of drc_indexes +* returned. Search through the list to find the matching +* drc_index and get the core number +*/ +for (i =0 ; i < indexes[0 ]; i++) { +if (indexes[i +1 ] == drc_index) +break ; + } +/* Convert core number to logical cpu number */ + thread =cpu_first_thread_of_core (i); + rc =0 ; } -/* Convert core number to logical cpu number */ - cpu =cpu_first_thread_of_core (i); - rc =0 ; err_of_node_put:of_node_put (dn); err:if (rc)printk (KERN_WARNING "drc_index_to_cpu(%d) failed" , drc_index); -return cpu; +return thread; }/*
PATCH v2 3/4 hotplug/drc-info: Add code to search ibm,drc-info property
In reply to Michael Bringmannrpadlpar_core.c: Provide parallel routines to search the older device- tree properties ("ibm,drc-indexes", "ibm,drc-names", "ibm,drc-types" and "ibm,drc-power-domains"), or the new property "ibm,drc-info".
The interface to examine the DRC information is changed from a "get" function that returns values for local verification elsewhere, to a "check" function that validates the 'name' and/or 'type' of a device node. This update hides the format of the underlying device-tree properties, and concentrates the value checks into a single function without requiring the user to verify whether a search was successful.
--- drivers/pci/hotplug/rpadlpar_core.c | 13 ++-- drivers/pci/hotplug/rpaphp.h | 4 + drivers/pci/hotplug/rpaphp_core.c | 109 +++++++++++++++++++++++++++-------- 3 files changed, 91 insertions(+), 35 deletions(-)
drivers/pci/hotplug/rpadlpar_core.c +5 -8
@@ -27,6 +27,7 @@#include <linux/mutex.h> #include <asm/rtas.h> #include <asm/vio.h> +#include <linux/firmware.h> #include "../pci.h" #include "rpaphp.h"
@@ -44,15 +45,14 @@ static struct device_node *find_vio_slot_node(char *drc_name) {struct device_node *parent =of_find_node_by_name (NULL ,"vdevice" );struct device_node *dn =NULL ; -char *name;int rc;if (!parent)return NULL ;while ((dn =of_get_next_child (parent, dn))) { - rc =rpaphp_get_drc_props (dn,NULL , &name,NULL ,NULL ); -if ((rc ==0 ) && (!strcmp (drc_name, name))) + rc =rpaphp_check_drc_props (dn, drc_name,NULL ); +if (rc ==0 )break ; }
@@ -64,15 +64,12 @@ static struct device_node *find_php_slot_pci_node(char *drc_name, char *drc_type) {struct device_node *np =NULL ; -char *name; -char *type;int rc;while ((np =of_find_node_by_name (np,"pci" ))) { - rc =rpaphp_get_drc_props (np,NULL , &name, &type,NULL ); + rc =rpaphp_check_drc_props (np, drc_name, drc_type);if (rc ==0 ) -if (!strcmp (drc_name, name) && !strcmp (drc_type, type)) -break ; +break ; }return np;
drivers/pci/hotplug/rpaphp.h +2 -2
@@ -91,8 +91,8 @@ struct slot {/* rpaphp_core.c */ int rpaphp_add_slot (struct device_node *dn); -int rpaphp_get_drc_props (struct device_node *dn,int *drc_index, -char **drc_name,char **drc_type,int *drc_power_domain); +int rpaphp_check_drc_props (struct device_node *dn,char *drc_name, +char *drc_type);/* rpaphp_slot.c */ void dealloc_slot_struct (struct slot *slot);
drivers/pci/hotplug/rpaphp_core.c +84 -25
139 lines not on this page · raw message
PATCH v2 4/4 powerpc: Enable support for ibm,drc-info devtree property
In reply to Michael Bringmannprom_init.c: Enable support for new DRC device tree property "ibm,drc-info" in initial handshake between the Linux kernel and the front end processor.
--- arch/powerpc/kernel/prom_init.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kernel/prom_init.c +1 -0
@@ -872,6 +872,7 @@ struct ibm_arch_vec __cacheline_aligned ibm_architecture_vec = { .mmu = 0, .hash_ext = 0, .radix_ext = 0, + .byte22 = OV5_FEAT(OV5_DRC_INFO), },/* option vector 6: IBM PAPR hints */