1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/* Copyright 2013-2014 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <skiboot.h>
#include "spira.h"
#include <cpu.h>
#include <fsp.h>
#include <opal.h>
#include <ccan/str/str.h>
#include <device.h>
#include "hdata.h"
#define PCIA_MAX_THREADS 8
static unsigned int pcia_index(const void *pcia)
{
return (pcia - (void *)get_hdif(&spira.ntuples.pcia, "SPPCIA"))
/ be32_to_cpu(spira.ntuples.pcia.alloc_len);
}
static const struct sppcia_cpu_thread *find_tada(const void *pcia,
unsigned int thread)
{
int count = HDIF_get_iarray_size(pcia, SPPCIA_IDATA_THREAD_ARRAY);
int i;
if (count < 0)
return NULL;
for (i = 0; i < count; i++) {
const struct sppcia_cpu_thread *t;
unsigned int size;
t = HDIF_get_iarray_item(pcia, SPPCIA_IDATA_THREAD_ARRAY,
i, &size);
if (!t || size < sizeof(*t))
continue;
if (be32_to_cpu(t->phys_thread_id) == thread)
return t;
}
return NULL;
}
static void add_xics_icp(const void *pcia, u32 tcount, const char *compat)
{
const struct sppcia_cpu_thread *t;
struct dt_node *icp;
__be64 *reg;
u32 i, irange[2], rsize;
rsize = tcount * 2 * sizeof(__be64);
reg = malloc(rsize);
assert(reg);
/* Suppresses uninitialized warning from gcc */
irange[0] = 0;
for (i = 0; i < tcount; i++) {
t = find_tada(pcia, i);
assert(t);
if (i == 0)
irange[0] = be32_to_cpu(t->pir);
reg[i * 2] = cpu_to_be64(cleanup_addr(be64_to_cpu(t->ibase)));
reg[i * 2 + 1] = cpu_to_be64(0x1000);
}
irange[1] = tcount;
icp = dt_new_addr(dt_root, "interrupt-controller", be64_to_cpu(reg[0]));
if (!icp) {
free(reg);
return;
}
if (compat)
dt_add_property_strings(icp, "compatible", "ibm,ppc-xicp", compat);
else
dt_add_property_strings(icp, "compatible", "ibm,ppc-xicp");
dt_add_property_cells(icp, "ibm,interrupt-server-ranges",
irange[0], irange[1]);
dt_add_property(icp, "interrupt-controller", NULL, 0);
dt_add_property(icp, "reg", reg, rsize);
dt_add_property_cells(icp, "#address-cells", 0);
dt_add_property_string(icp, "device_type",
"PowerPC-External-Interrupt-Presentation");
free(reg);
}
static struct dt_node *add_core_node(struct dt_node *cpus,
const void *pcia,
const struct sppcia_core_unique *id,
bool okay)
{
const struct sppcia_cpu_thread *t;
const struct sppcia_cpu_timebase *timebase;
const struct sppcia_cpu_cache *cache;
const struct sppcia_cpu_attr *attr;
struct dt_node *cpu;
const char *icp_compat;
u32 i, size, threads, ve_flags, l2_phandle, chip_id;
__be32 iserv[PCIA_MAX_THREADS];
/* Look for thread 0 */
t = find_tada(pcia, 0);
if (!t) {
prerror("CORE[%i]: Failed to find thread 0 !\n",
pcia_index(pcia));
return NULL;
}
ve_flags = be32_to_cpu(id->verif_exist_flags);
threads = ((ve_flags & CPU_ID_NUM_SECONDARY_THREAD_MASK)
>> CPU_ID_NUM_SECONDARY_THREAD_SHIFT) + 1;
assert(threads <= PCIA_MAX_THREADS);
prlog(PR_INFO, "CORE[%i]: PIR=%.8x %s %s(%u threads)\n",
pcia_index(pcia), be32_to_cpu(t->pir),
ve_flags & CPU_ID_PACA_RESERVED
? "**RESERVED**" : cpu_state(ve_flags),
be32_to_cpu(t->pir) == boot_cpu->pir ? "[boot] " : "", threads);
timebase = HDIF_get_idata(pcia, SPPCIA_IDATA_TIMEBASE, &size);
if (!timebase || size < sizeof(*timebase)) {
prerror("CORE[%i]: bad timebase size %u @ %p\n",
pcia_index(pcia), size, timebase);
return NULL;
}
cache = HDIF_get_idata(pcia, SPPCIA_IDATA_CPU_CACHE, &size);
if (!cache || size < sizeof(*cache)) {
prerror("CORE[%i]: bad cache size %u @ %p\n",
pcia_index(pcia), size, cache);
return NULL;
}
cpu = add_core_common(cpus, cache, timebase,
be32_to_cpu(t->pir), okay);
/* Core attributes */
attr = HDIF_get_idata(pcia, SPPCIA_IDATA_CPU_ATTR, &size);
if (attr)
add_core_attr(cpu, be32_to_cpu(attr->attr));
/* Add cache info */
l2_phandle = add_core_cache_info(cpus, cache,
be32_to_cpu(t->pir), okay);
dt_add_property_cells(cpu, "l2-cache", l2_phandle);
if (proc_gen == proc_gen_p7)
icp_compat = "IBM,power7-icp";
else
icp_compat = "IBM,power8-icp";
/* Get HW Chip ID */
chip_id = pcid_to_chip_id(be32_to_cpu(id->proc_chip_id));
dt_add_property_cells(cpu, "ibm,pir", be32_to_cpu(t->pir));
dt_add_property_cells(cpu, "ibm,chip-id", chip_id);
/* Build ibm,ppc-interrupt-server#s with all threads */
for (i = 0; i < threads; i++) {
t = find_tada(pcia, i);
if (!t) {
threads = i;
break;
}
iserv[i] = t->pir;
}
dt_add_property(cpu, "ibm,ppc-interrupt-server#s", iserv, 4 * threads);
/* Add the ICP node for this CPU for P7 / P8 */
if (proc_gen <= proc_gen_p8)
add_xics_icp(pcia, threads, icp_compat);
return cpu;
}
bool pcia_parse(void)
{
const void *pcia;
struct dt_node *cpus;
/* Check PCIA exists... if not, maybe we are getting a PACA ? */
pcia = get_hdif(&spira.ntuples.pcia, "SPPCIA");
if (!pcia)
return false;
prlog(PR_INFO, "Got PCIA !\n");
cpus = dt_new(dt_root, "cpus");
dt_add_property_cells(cpus, "#address-cells", 1);
dt_add_property_cells(cpus, "#size-cells", 0);
for_each_pcia(pcia) {
const struct sppcia_core_unique *id;
u32 size, ve_flags;
bool okay;
id = HDIF_get_idata(pcia, SPPCIA_IDATA_CORE_UNIQUE, &size);
if (!id || size < sizeof(*id)) {
prerror("CORE[%i]: bad id size %u @ %p\n",
pcia_index(pcia), size, id);
return false;
}
ve_flags = be32_to_cpu(id->verif_exist_flags);
switch ((ve_flags & CPU_ID_VERIFY_MASK)
>> CPU_ID_VERIFY_SHIFT) {
case CPU_ID_VERIFY_USABLE_NO_FAILURES:
case CPU_ID_VERIFY_USABLE_FAILURES:
okay = true;
break;
default:
okay = false;
}
prlog(okay ? PR_INFO : PR_WARNING,
"CORE[%i]: HW_PROC_ID=%i PROC_CHIP_ID=%i EC=0x%x %s\n",
pcia_index(pcia), be32_to_cpu(id->hw_proc_id),
be32_to_cpu(id->proc_chip_id),
be32_to_cpu(id->chip_ec_level),
okay ? "OK" : "UNAVAILABLE");
if (!add_core_node(cpus, pcia, id, okay))
break;
}
return true;
}
|