Skip to content

Commit e83636a

Browse files
mwbringmannmpe
authored andcommitted
pseries/drc-info: Search DRC properties for CPU indexes
pseries/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". Signed-off-by: Michael Bringmann <mwb@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3f38000 commit e83636a

File tree

3 files changed

+173
-28
lines changed

3 files changed

+173
-28
lines changed

arch/powerpc/include/asm/prom.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ extern void of_instantiate_rtc(void);
8080

8181
extern int of_get_ibm_chip_id(struct device_node *np);
8282

83+
struct of_drc_info {
84+
char *drc_type;
85+
char *drc_name_prefix;
86+
u32 drc_index_start;
87+
u32 drc_name_suffix_start;
88+
u32 num_sequential_elems;
89+
u32 sequential_inc;
90+
u32 drc_power_domain;
91+
u32 last_drc_index;
92+
};
93+
94+
extern int of_read_drc_info_cell(struct property **prop,
95+
const __be32 **curval, struct of_drc_info *data);
96+
97+
8398
/*
8499
* There are two methods for telling firmware what our capabilities are.
85100
* Newer machines have an "ibm,client-architecture-support" method on the

arch/powerpc/platforms/pseries/of_helpers.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <linux/err.h>
44
#include <linux/slab.h>
55
#include <linux/of.h>
6+
#include <asm/prom.h>
67

78
#include "of_helpers.h"
89

@@ -37,3 +38,62 @@ struct device_node *pseries_of_derive_parent(const char *path)
3738
kfree(parent_path);
3839
return parent ? parent : ERR_PTR(-EINVAL);
3940
}
41+
42+
43+
/* Helper Routines to convert between drc_index to cpu numbers */
44+
45+
int of_read_drc_info_cell(struct property **prop, const __be32 **curval,
46+
struct of_drc_info *data)
47+
{
48+
const char *p;
49+
const __be32 *p2;
50+
51+
if (!data)
52+
return -EINVAL;
53+
54+
/* Get drc-type:encode-string */
55+
p = data->drc_type = (char*) (*curval);
56+
p = of_prop_next_string(*prop, p);
57+
if (!p)
58+
return -EINVAL;
59+
60+
/* Get drc-name-prefix:encode-string */
61+
data->drc_name_prefix = (char *)p;
62+
p = of_prop_next_string(*prop, p);
63+
if (!p)
64+
return -EINVAL;
65+
66+
/* Get drc-index-start:encode-int */
67+
p2 = (const __be32 *)p;
68+
p2 = of_prop_next_u32(*prop, p2, &data->drc_index_start);
69+
if (!p2)
70+
return -EINVAL;
71+
72+
/* Get drc-name-suffix-start:encode-int */
73+
p2 = of_prop_next_u32(*prop, p2, &data->drc_name_suffix_start);
74+
if (!p2)
75+
return -EINVAL;
76+
77+
/* Get number-sequential-elements:encode-int */
78+
p2 = of_prop_next_u32(*prop, p2, &data->num_sequential_elems);
79+
if (!p2)
80+
return -EINVAL;
81+
82+
/* Get sequential-increment:encode-int */
83+
p2 = of_prop_next_u32(*prop, p2, &data->sequential_inc);
84+
if (!p2)
85+
return -EINVAL;
86+
87+
/* Get drc-power-domain:encode-int */
88+
p2 = of_prop_next_u32(*prop, p2, &data->drc_power_domain);
89+
if (!p2)
90+
return -EINVAL;
91+
92+
/* Should now know end of current entry */
93+
(*curval) = (void *)p2;
94+
data->last_drc_index = data->drc_index_start +
95+
((data->num_sequential_elems - 1) * data->sequential_inc);
96+
97+
return 0;
98+
}
99+
EXPORT_SYMBOL(of_read_drc_info_cell);

arch/powerpc/platforms/pseries/pseries_energy.c

Lines changed: 98 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <asm/page.h>
2323
#include <asm/hvcall.h>
2424
#include <asm/firmware.h>
25+
#include <asm/prom.h>
2526

2627

2728
#define MODULE_VERS "1.0"
@@ -38,26 +39,58 @@ static int sysfs_entries;
3839
static u32 cpu_to_drc_index(int cpu)
3940
{
4041
struct device_node *dn = NULL;
41-
const int *indexes;
42-
int i;
42+
int thread_index;
4343
int rc = 1;
4444
u32 ret = 0;
4545

4646
dn = of_find_node_by_path("/cpus");
4747
if (dn == NULL)
4848
goto err;
49-
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
50-
if (indexes == NULL)
51-
goto err_of_node_put;
49+
5250
/* Convert logical cpu number to core number */
53-
i = cpu_core_index_of_thread(cpu);
54-
/*
55-
* The first element indexes[0] is the number of drc_indexes
56-
* returned in the list. Hence i+1 will get the drc_index
57-
* corresponding to core number i.
58-
*/
59-
WARN_ON(i > indexes[0]);
60-
ret = indexes[i + 1];
51+
thread_index = cpu_core_index_of_thread(cpu);
52+
53+
if (firmware_has_feature(FW_FEATURE_DRC_INFO)) {
54+
struct property *info = NULL;
55+
struct of_drc_info drc;
56+
int j;
57+
u32 num_set_entries;
58+
const __be32 *value;
59+
60+
info = of_find_property(dn, "ibm,drc-info", NULL);
61+
if (info == NULL)
62+
goto err_of_node_put;
63+
64+
value = of_prop_next_u32(info, NULL, &num_set_entries);
65+
if (!value)
66+
goto err_of_node_put;
67+
68+
for (j = 0; j < num_set_entries; j++) {
69+
70+
of_read_drc_info_cell(&info, &value, &drc);
71+
if (strncmp(drc.drc_type, "CPU", 3))
72+
goto err;
73+
74+
if (thread_index < drc.last_drc_index)
75+
break;
76+
}
77+
78+
ret = drc.drc_index_start + (thread_index * drc.sequential_inc);
79+
} else {
80+
const __be32 *indexes;
81+
82+
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
83+
if (indexes == NULL)
84+
goto err_of_node_put;
85+
86+
/*
87+
* The first element indexes[0] is the number of drc_indexes
88+
* returned in the list. Hence thread_index+1 will get the
89+
* drc_index corresponding to core number thread_index.
90+
*/
91+
ret = indexes[thread_index + 1];
92+
}
93+
6194
rc = 0;
6295

6396
err_of_node_put:
@@ -72,34 +105,71 @@ static int drc_index_to_cpu(u32 drc_index)
72105
{
73106
struct device_node *dn = NULL;
74107
const int *indexes;
75-
int i, cpu = 0;
108+
int thread_index = 0, cpu = 0;
76109
int rc = 1;
77110

78111
dn = of_find_node_by_path("/cpus");
79112
if (dn == NULL)
80113
goto err;
81-
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
82-
if (indexes == NULL)
83-
goto err_of_node_put;
84-
/*
85-
* First element in the array is the number of drc_indexes
86-
* returned. Search through the list to find the matching
87-
* drc_index and get the core number
88-
*/
89-
for (i = 0; i < indexes[0]; i++) {
90-
if (indexes[i + 1] == drc_index)
114+
115+
if (firmware_has_feature(FW_FEATURE_DRC_INFO)) {
116+
struct property *info = NULL;
117+
struct of_drc_info drc;
118+
int j;
119+
u32 num_set_entries;
120+
const __be32 *value;
121+
122+
info = of_find_property(dn, "ibm,drc-info", NULL);
123+
if (info == NULL)
124+
goto err_of_node_put;
125+
126+
value = of_prop_next_u32(info, NULL, &num_set_entries);
127+
if (!value)
128+
goto err_of_node_put;
129+
130+
for (j = 0; j < num_set_entries; j++) {
131+
132+
of_read_drc_info_cell(&info, &value, &drc);
133+
if (strncmp(drc.drc_type, "CPU", 3))
134+
goto err;
135+
136+
if (drc_index > drc.last_drc_index) {
137+
cpu += drc.num_sequential_elems;
138+
continue;
139+
}
140+
cpu += ((drc_index - drc.drc_index_start) /
141+
drc.sequential_inc);
142+
143+
thread_index = cpu_first_thread_of_core(cpu);
144+
rc = 0;
91145
break;
146+
}
147+
} else {
148+
unsigned long int i;
149+
150+
indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
151+
if (indexes == NULL)
152+
goto err_of_node_put;
153+
/*
154+
* First element in the array is the number of drc_indexes
155+
* returned. Search through the list to find the matching
156+
* drc_index and get the core number
157+
*/
158+
for (i = 0; i < indexes[0]; i++) {
159+
if (indexes[i + 1] == drc_index)
160+
break;
161+
}
162+
/* Convert core number to logical cpu number */
163+
thread_index = cpu_first_thread_of_core(i);
164+
rc = 0;
92165
}
93-
/* Convert core number to logical cpu number */
94-
cpu = cpu_first_thread_of_core(i);
95-
rc = 0;
96166

97167
err_of_node_put:
98168
of_node_put(dn);
99169
err:
100170
if (rc)
101171
printk(KERN_WARNING "drc_index_to_cpu(%d) failed", drc_index);
102-
return cpu;
172+
return thread_index;
103173
}
104174

105175
/*

0 commit comments

Comments
 (0)