Branch data Line data Source code
1 : : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2 : : /* Copyright 2013-2019 IBM Corp. */
3 : :
4 : : #ifndef __CHIP_H
5 : : #define __CHIP_H
6 : :
7 : : #include <stdint.h>
8 : : #include <lock.h>
9 : :
10 : : #include <ccan/list/list.h>
11 : :
12 : : /*
13 : : * Note on chip IDs:
14 : : *
15 : : * We carry a "chip_id" around, in the cpu_thread, but also as
16 : : * ibm,chip-id properties.
17 : : *
18 : : * This ID is the HW fabric ID of a chip based on the XSCOM numbering,
19 : : * also known as "GCID" (Global Chip ID).
20 : : *
21 : : * The format of this number is different between chip generations and care must
22 : : * be taken when trying to convert between this chip ID and some other
23 : : * representation such as PIR values, interrupt-server numbers etc... :
24 : : *
25 : : */
26 : :
27 : : /*
28 : : * P8 GCID
29 : : * -------
30 : : *
31 : : * Global chip ID is a 6 bit number:
32 : : *
33 : : * NodeID ChipID
34 : : * | | |
35 : : * |___|___|___|___|___|___|
36 : : *
37 : : * The the ChipID is 3 bits long, the GCID is the same as the high bits of PIR
38 : : */
39 : : #define P8_PIR2GCID(pir) (((pir) >> 7) & 0x3f)
40 : :
41 : : #define P8_PIR2COREID(pir) (((pir) >> 3) & 0xf)
42 : :
43 : : #define P8_PIR2THREADID(pir) ((pir) & 0x7)
44 : :
45 : : /*
46 : : * P9 GCID
47 : : * -------
48 : : *
49 : : * Global chip ID is a 7 bit number:
50 : : *
51 : : * NodeID ChipID
52 : : * | | |
53 : : * |___|___|___|___|___|___|___|
54 : : *
55 : : * Bit 56 is unused according to the manual by we add it to the coreid here,
56 : : * thus we have a 6-bit core number.
57 : : *
58 : : * Note: XIVE Only supports 4-bit chip numbers ...
59 : : *
60 : : * Upper PIR Bits
61 : : * --------------
62 : : *
63 : : * Normal-Core Mode:
64 : : * 57:61 CoreID
65 : : * 62:63 ThreadID
66 : : *
67 : : * Fused-Core Mode:
68 : : * 57:59 FusedQuadID
69 : : * 60 FusedCoreID
70 : : * 61:63 FusedThreadID
71 : : *
72 : : * FusedCoreID 0 contains normal-core chiplet 0 and 1
73 : : * FusedCoreID 1 contains normal-core chiplet 2 and 3
74 : : *
75 : : * Fused cores have interleaved threads:
76 : : * core chiplet 0/2 = t0, t2, t4, t6
77 : : * core chiplet 1/3 = t1, t3, t5, t7
78 : : *
79 : : */
80 : : #define P9_PIR2GCID(pir) (((pir) >> 8) & 0x7f)
81 : :
82 : : #define P9_PIR2COREID(pir) (((pir) >> 2) & 0x3f)
83 : :
84 : : #define P9_PIR2THREADID(pir) ((pir) & 0x3)
85 : :
86 : : #define P9_GCID2NODEID(gcid) (((gcid) >> 3) & 0xf)
87 : :
88 : : #define P9_GCID2CHIPID(gcid) ((gcid) & 0x7)
89 : :
90 : : #define P9_PIR2FUSEDQUADID(pir) (((pir) >> 4) & 0x7)
91 : :
92 : : #define P9_PIR2FUSEDCOREID(pir) (((pir) >> 3) & 0x1)
93 : :
94 : : #define P9_PIR2FUSEDTHREADID(pir) ((pir) & 0x7)
95 : :
96 : : #define P9_PIRFUSED2NORMALCOREID(pir) \
97 : : (P9_PIR2FUSEDQUADID(pir) << 2) | \
98 : : (P9_PIR2FUSEDCOREID(pir) << 1) | \
99 : : (P9_PIR2FUSEDTHREADID(pir) & 1)
100 : :
101 : : #define P9_PIRFUSED2NORMALTHREADID(pir) (((pir) >> 1) & 0x3)
102 : :
103 : : #define P10_PIR2FUSEDCOREID(pir) P9_PIR2FUSEDCOREID(pir)
104 : : #define P10_PIRFUSED2NORMALCOREID(pir) P9_PIRFUSED2NORMALCOREID(pir)
105 : : #define P10_PIRFUSED2NORMALTHREADID(pir) P9_PIRFUSED2NORMALTHREADID(pir)
106 : :
107 : : /* P9 specific ones mostly used by XIVE */
108 : : #define P9_PIR2LOCALCPU(pir) ((pir) & 0xff)
109 : : #define P9_PIRFROMLOCALCPU(chip, cpu) (((chip) << 8) | (cpu))
110 : :
111 : : /*
112 : : * P10 PIR
113 : : * -------
114 : : *
115 : : * PIR layout:
116 : : *
117 : : * | 49| 50| 51| 52| 53| 54| 55| 56| 57| 58| 59| 60| 61| 62| 63|
118 : : * |Spare ID |Topology ID |Sp. |Quad ID |Core ID |Thread ID|
119 : : *
120 : : * Bit 56 is a spare quad ID. In big-core mode, thread ID extends to bit 61.
121 : : *
122 : : * P10 GCID
123 : : * --------
124 : : *
125 : : * - Global chip ID is also called Topology ID.
126 : : * - Node ID is called Group ID (? XXX P10).
127 : : *
128 : : * Global chip ID is a 4 bit number.
129 : : *
130 : : * There is a topology mode bit that can be 0 or 1, which changes GCID mapping.
131 : : *
132 : : * Topology mode 0:
133 : : * NodeID ChipID
134 : : * | | |
135 : : * |____|____|____|____|
136 : : *
137 : : * Topology mode 1:
138 : : * NodeID ChipID
139 : : * | | |
140 : : * |____|____|____|____|
141 : : */
142 : : #define P10_PIR2GCID(pir) (((pir) >> 8) & 0xf)
143 : :
144 : : #define P10_PIR2COREID(pir) (((pir) >> 2) & 0x3f)
145 : :
146 : : #define P10_PIR2THREADID(pir) ((pir) & 0x3)
147 : :
148 : : // XXX P10 These depend on the topology mode, how to get that (system type?)
149 : : #define P10_GCID2NODEID(gcid, mode) ((mode) == 0 ? ((gcid) >> 1) & 0x7 : ((gcid) >> 2) & 0x3)
150 : : #define P10_GCID2CHIPID(gcid, mode) ((mode) == 0 ? (gcid) & 0x1 : (gcid) & 0x3)
151 : :
152 : : /* P10 specific ones mostly used by XIVE */
153 : : #define P10_PIR2LOCALCPU(pir) ((pir) & 0xff)
154 : : #define P10_PIRFROMLOCALCPU(chip, cpu) (((chip) << 8) | (cpu))
155 : :
156 : : struct dt_node;
157 : : struct centaur_chip;
158 : : struct mfsi;
159 : : struct xive;
160 : : struct lpcm;
161 : : struct vas;
162 : : struct p9_sbe;
163 : : struct p9_dio;
164 : :
165 : : /* Chip type */
166 : : enum proc_chip_type {
167 : : PROC_CHIP_UNKNOWN,
168 : : PROC_CHIP_P8_MURANO,
169 : : PROC_CHIP_P8_VENICE,
170 : : PROC_CHIP_P8_NAPLES,
171 : : PROC_CHIP_P9_NIMBUS,
172 : : PROC_CHIP_P9_CUMULUS,
173 : : PROC_CHIP_P9P,
174 : : PROC_CHIP_P10,
175 : : };
176 : :
177 : : /* Simulator quirks */
178 : : enum proc_chip_quirks {
179 : : QUIRK_NO_CHIPTOD = 0x00000001,
180 : : QUIRK_MAMBO_CALLOUTS = 0x00000002,
181 : : QUIRK_NO_F000F = 0x00000004,
182 : : QUIRK_NO_PBA = 0x00000008,
183 : : QUIRK_NO_OCC_IRQ = 0x00000010,
184 : : QUIRK_SIMICS = 0x00000020,
185 : : QUIRK_SLOW_SIM = 0x00000040,
186 : : QUIRK_NO_DIRECT_CTL = 0x00000080,
187 : : QUIRK_NO_RNG = 0x00000100,
188 : : QUIRK_QEMU = 0x00000200,
189 : : QUIRK_AWAN = 0x00000400,
190 : : QUIRK_BML = 0x00000800,
191 : : QUIRK_NO_SBE = 0x00001000,
192 : : };
193 : :
194 : : extern enum proc_chip_quirks proc_chip_quirks;
195 : :
196 : 36 : static inline bool chip_quirk(unsigned int q)
197 : : {
198 : 36 : return !!(proc_chip_quirks & q);
199 : : }
200 : :
201 : : #define MAX_CHIPS (1 << 6) /* 6-bit chip ID */
202 : :
203 : : /*
204 : : * For each chip in the system, we maintain this structure
205 : : *
206 : : * This contains fields used by different modules including
207 : : * modules in hw/ but is handy to keep per-chip data
208 : : */
209 : : struct proc_chip {
210 : : uint32_t id; /* HW Chip ID (GCID) */
211 : : struct dt_node *devnode; /* "xscom" chip node */
212 : :
213 : : /* These are only initialized after xcom_init */
214 : : enum proc_chip_type type;
215 : : uint32_t ec_level; /* 0xMm (DD1.0 = 0x10) */
216 : : uint8_t ec_rev; /* sub-revision */
217 : :
218 : : /* Those two values are only populated on machines with an FSP
219 : : * dbob_id = Drawer/Block/Octant/Blade (DBOBID)
220 : : * pcid = HDAT processor_chip_id
221 : : */
222 : : uint32_t dbob_id;
223 : : uint32_t pcid;
224 : :
225 : : /* If we expect to have an OCC (i.e. P8) and it is functional,
226 : : * set TRUE. If something has told us it is not, set FALSE and
227 : : * we can not wait for OCCs to init. This is only going to be
228 : : * FALSE in a simulator that doesn't simulate OCCs. */
229 : : bool occ_functional;
230 : :
231 : : /* Used by hw/xscom.c */
232 : : uint64_t xscom_base;
233 : :
234 : : /* Used by hw/lpc.c */
235 : : struct lpcm *lpc;
236 : :
237 : : /* Used by hw/slw.c */
238 : : uint64_t slw_base;
239 : : uint64_t slw_bar_size;
240 : : uint64_t slw_image_size;
241 : :
242 : : /* Used by hw/homer.c */
243 : : uint64_t homer_base;
244 : : uint64_t homer_size;
245 : : uint64_t occ_common_base;
246 : : uint64_t occ_common_size;
247 : : uint8_t throttle;
248 : :
249 : : /* Must hold capi_lock to change */
250 : : uint8_t capp_phb3_attached_mask;
251 : : uint8_t capp_ucode_loaded;
252 : :
253 : : /* Used by hw/centaur.c */
254 : : struct centaur_chip *centaurs;
255 : :
256 : : /* Used by hw/p8-i2c.c */
257 : : struct list_head i2cms;
258 : :
259 : : /* Used by hw/psi.c */
260 : : struct psi *psi;
261 : :
262 : : /* Used by hw/fsi-master.c */
263 : : struct mfsi *fsi_masters;
264 : :
265 : : /* Used by hw/xive.c */
266 : : struct xive *xive;
267 : :
268 : : struct vas *vas;
269 : :
270 : : /* Used by hw/nx-compress.c */
271 : : uint64_t nx_base;
272 : : /* location code of this chip */
273 : : const uint8_t *loc_code;
274 : :
275 : : /* Used by hw/sbe-p9.c */
276 : : struct p9_sbe *sbe;
277 : :
278 : : /* Used by hw/dio-p9.c */
279 : : struct p9_dio *dio;
280 : :
281 : : /* Used during OCC init */
282 : : bool ex_present;
283 : :
284 : : /* Used by hw/vas.c on p10 */
285 : : uint32_t primary_topology;
286 : : };
287 : :
288 : : extern uint32_t pir_to_chip_id(uint32_t pir);
289 : :
290 : : /*
291 : : * Note: In P9 fused-core mode, these will return the "normal"
292 : : * core ID and thread ID (ie, thread ID 0..3)
293 : : */
294 : : extern uint32_t pir_to_core_id(uint32_t pir);
295 : : extern uint32_t pir_to_thread_id(uint32_t pir);
296 : :
297 : : /* In P9 fused core mode, this is the "fused" core ID, in
298 : : * normal core mode or P8, this is the same as pir_to_core_id
299 : : */
300 : : extern uint32_t pir_to_fused_core_id(uint32_t pir);
301 : :
302 : : extern struct proc_chip *next_chip(struct proc_chip *chip);
303 : :
304 : : #define for_each_chip(__c) for (__c=next_chip(NULL); __c; __c=next_chip(__c))
305 : :
306 : : extern struct proc_chip *get_chip(uint32_t chip_id);
307 : :
308 : : extern void init_chips(void);
309 : :
310 : : /* helper to get number of chips in the system */
311 : : static inline int nr_chips(void)
312 : : {
313 : : struct proc_chip *chip;
314 : : int nr_chips = 0;
315 : :
316 : : for_each_chip(chip)
317 : : nr_chips++;
318 : :
319 : : return nr_chips;
320 : : }
321 : :
322 : : /* helper to get location code of a chip */
323 : : static inline const char *chip_loc_code(uint32_t chip_id)
324 : : {
325 : : struct proc_chip *chip;
326 : :
327 : : chip = get_chip(chip_id);
328 : : if (!chip)
329 : : return NULL;
330 : :
331 : : return chip->loc_code;
332 : : }
333 : :
334 : : #endif /* __CHIP_H */
335 : :
|