GNU Linux-libre 4.14.290-gnu1
[releases.git] / arch / tile / include / uapi / arch / sim_def.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Copyright 2010 Tilera Corporation. All Rights Reserved.
4  *
5  *   This program is free software; you can redistribute it and/or
6  *   modify it under the terms of the GNU General Public License
7  *   as published by the Free Software Foundation, version 2.
8  *
9  *   This program is distributed in the hope that it will be useful, but
10  *   WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12  *   NON INFRINGEMENT.  See the GNU General Public License for
13  *   more details.
14  */
15
16 /**
17  * @file
18  *
19  * Some low-level simulator definitions.
20  */
21
22 #ifndef __ARCH_SIM_DEF_H__
23 #define __ARCH_SIM_DEF_H__
24
25
26 /**
27  * Internal: the low bits of the SIM_CONTROL_* SPR values specify
28  * the operation to perform, and the remaining bits are
29  * an operation-specific parameter (often unused).
30  */
31 #define _SIM_CONTROL_OPERATOR_BITS 8
32
33
34 /*
35  * Values which can be written to SPR_SIM_CONTROL.
36  */
37
38 /** If written to SPR_SIM_CONTROL, stops profiling. */
39 #define SIM_CONTROL_PROFILER_DISABLE 0
40
41 /** If written to SPR_SIM_CONTROL, starts profiling. */
42 #define SIM_CONTROL_PROFILER_ENABLE 1
43
44 /** If written to SPR_SIM_CONTROL, clears profiling counters. */
45 #define SIM_CONTROL_PROFILER_CLEAR 2
46
47 /** If written to SPR_SIM_CONTROL, checkpoints the simulator. */
48 #define SIM_CONTROL_CHECKPOINT 3
49
50 /**
51  * If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
52  * sets the tracing mask to the given mask. See "sim_set_tracing()".
53  */
54 #define SIM_CONTROL_SET_TRACING 4
55
56 /**
57  * If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
58  * dumps the requested items of machine state to the log.
59  */
60 #define SIM_CONTROL_DUMP 5
61
62 /** If written to SPR_SIM_CONTROL, clears chip-level profiling counters. */
63 #define SIM_CONTROL_PROFILER_CHIP_CLEAR 6
64
65 /** If written to SPR_SIM_CONTROL, disables chip-level profiling. */
66 #define SIM_CONTROL_PROFILER_CHIP_DISABLE 7
67
68 /** If written to SPR_SIM_CONTROL, enables chip-level profiling. */
69 #define SIM_CONTROL_PROFILER_CHIP_ENABLE 8
70
71 /** If written to SPR_SIM_CONTROL, enables chip-level functional mode */
72 #define SIM_CONTROL_ENABLE_FUNCTIONAL 9
73
74 /** If written to SPR_SIM_CONTROL, disables chip-level functional mode. */
75 #define SIM_CONTROL_DISABLE_FUNCTIONAL 10
76
77 /**
78  * If written to SPR_SIM_CONTROL, enables chip-level functional mode.
79  * All tiles must perform this write for functional mode to be enabled.
80  * Ignored in naked boot mode unless --functional is specified.
81  * WARNING: Only the hypervisor startup code should use this!
82  */
83 #define SIM_CONTROL_ENABLE_FUNCTIONAL_BARRIER 11
84
85 /**
86  * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
87  * writes a string directly to the simulator output.  Written to once for
88  * each character in the string, plus a final NUL.  Instead of NUL,
89  * you can also use "SIM_PUTC_FLUSH_STRING" or "SIM_PUTC_FLUSH_BINARY".
90  */
91 /* ISSUE: Document the meaning of "newline", and the handling of NUL. */
92 #define SIM_CONTROL_PUTC 12
93
94 /**
95  * If written to SPR_SIM_CONTROL, clears the --grind-coherence state for
96  * this core.  This is intended to be used before a loop that will
97  * invalidate the cache by loading new data and evicting all current data.
98  * Generally speaking, this API should only be used by system code.
99  */
100 #define SIM_CONTROL_GRINDER_CLEAR 13
101
102 /** If written to SPR_SIM_CONTROL, shuts down the simulator. */
103 #define SIM_CONTROL_SHUTDOWN 14
104
105 /**
106  * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
107  * indicates that a fork syscall just created the given process.
108  */
109 #define SIM_CONTROL_OS_FORK 15
110
111 /**
112  * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
113  * indicates that an exit syscall was just executed by the given process.
114  */
115 #define SIM_CONTROL_OS_EXIT 16
116
117 /**
118  * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
119  * indicates that the OS just switched to the given process.
120  */
121 #define SIM_CONTROL_OS_SWITCH 17
122
123 /**
124  * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
125  * indicates that an exec syscall was just executed. Written to once for
126  * each character in the executable name, plus a final NUL.
127  */
128 #define SIM_CONTROL_OS_EXEC 18
129
130 /**
131  * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
132  * indicates that an interpreter (PT_INTERP) was loaded.  Written to once
133  * for each character in "ADDR:PATH", plus a final NUL, where "ADDR" is a
134  * hex load address starting with "0x", and "PATH" is the executable name.
135  */
136 #define SIM_CONTROL_OS_INTERP 19
137
138 /**
139  * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
140  * indicates that a dll was loaded.  Written to once for each character
141  * in "ADDR:PATH", plus a final NUL, where "ADDR" is a hexadecimal load
142  * address starting with "0x", and "PATH" is the executable name.
143  */
144 #define SIM_CONTROL_DLOPEN 20
145
146 /**
147  * If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
148  * indicates that a dll was unloaded.  Written to once for each character
149  * in "ADDR", plus a final NUL, where "ADDR" is a hexadecimal load
150  * address starting with "0x".
151  */
152 #define SIM_CONTROL_DLCLOSE 21
153
154 /**
155  * If written to SPR_SIM_CONTROL, combined with a flag (shifted by 8),
156  * indicates whether to allow data reads to remotely-cached
157  * dirty cache lines to be cached locally without grinder warnings or
158  * assertions (used by Linux kernel fast memcpy).
159  */
160 #define SIM_CONTROL_ALLOW_MULTIPLE_CACHING 22
161
162 /** If written to SPR_SIM_CONTROL, enables memory tracing. */
163 #define SIM_CONTROL_ENABLE_MEM_LOGGING 23
164
165 /** If written to SPR_SIM_CONTROL, disables memory tracing. */
166 #define SIM_CONTROL_DISABLE_MEM_LOGGING 24
167
168 /**
169  * If written to SPR_SIM_CONTROL, changes the shaping parameters of one of
170  * the gbe or xgbe shims. Must specify the shim id, the type, the units, and
171  * the rate, as defined in SIM_SHAPING_SPR_ARG.
172  */
173 #define SIM_CONTROL_SHAPING 25
174
175 /**
176  * If written to SPR_SIM_CONTROL, combined with character (shifted by 8),
177  * requests that a simulator command be executed.  Written to once for each
178  * character in the command, plus a final NUL.
179  */
180 #define SIM_CONTROL_COMMAND 26
181
182 /**
183  * If written to SPR_SIM_CONTROL, indicates that the simulated system
184  * is panicking, to allow debugging via --debug-on-panic.
185  */
186 #define SIM_CONTROL_PANIC 27
187
188 /**
189  * If written to SPR_SIM_CONTROL, triggers a simulator syscall.
190  * See "sim_syscall()" for more info.
191  */
192 #define SIM_CONTROL_SYSCALL 32
193
194 /**
195  * If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
196  * provides the pid that subsequent SIM_CONTROL_OS_FORK writes should
197  * use as the pid, rather than the default previous SIM_CONTROL_OS_SWITCH.
198  */
199 #define SIM_CONTROL_OS_FORK_PARENT 33
200
201 /**
202  * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
203  * (shifted by 8), clears the pending magic data section.  The cleared
204  * pending magic data section and any subsequently appended magic bytes
205  * will only take effect when the classifier blast programmer is run.
206  */
207 #define SIM_CONTROL_CLEAR_MPIPE_MAGIC_BYTES 34
208
209 /**
210  * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
211  * (shifted by 8) and a byte of data (shifted by 16), appends that byte
212  * to the shim's pending magic data section.  The pending magic data
213  * section takes effect when the classifier blast programmer is run.
214  */
215 #define SIM_CONTROL_APPEND_MPIPE_MAGIC_BYTE 35
216
217 /**
218  * If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
219  * (shifted by 8), an enable=1/disable=0 bit (shifted by 16), and a
220  * mask of links (shifted by 32), enable or disable the corresponding
221  * mPIPE links.
222  */
223 #define SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE 36
224
225
226 /*
227  * Syscall numbers for use with "sim_syscall()".
228  */
229
230 /** Syscall number for sim_add_watchpoint(). */
231 #define SIM_SYSCALL_ADD_WATCHPOINT 2
232
233 /** Syscall number for sim_remove_watchpoint(). */
234 #define SIM_SYSCALL_REMOVE_WATCHPOINT 3
235
236 /** Syscall number for sim_query_watchpoint(). */
237 #define SIM_SYSCALL_QUERY_WATCHPOINT 4
238
239 /**
240  * Syscall number that asserts that the cache lines whose 64-bit PA
241  * is passed as the second argument to sim_syscall(), and over a
242  * range passed as the third argument, are no longer in cache.
243  * The simulator raises an error if this is not the case.
244  */
245 #define SIM_SYSCALL_VALIDATE_LINES_EVICTED 5
246
247 /** Syscall number for sim_query_cpu_speed(). */
248 #define SIM_SYSCALL_QUERY_CPU_SPEED 6
249
250
251 /*
252  * Bit masks which can be shifted by 8, combined with
253  * SIM_CONTROL_SET_TRACING, and written to SPR_SIM_CONTROL.
254  */
255
256 /**
257  * @addtogroup arch_sim
258  * @{
259  */
260
261 /** Enable --trace-cycle when passed to simulator_set_tracing(). */
262 #define SIM_TRACE_CYCLES          0x01
263
264 /** Enable --trace-router when passed to simulator_set_tracing(). */
265 #define SIM_TRACE_ROUTER          0x02
266
267 /** Enable --trace-register-writes when passed to simulator_set_tracing(). */
268 #define SIM_TRACE_REGISTER_WRITES 0x04
269
270 /** Enable --trace-disasm when passed to simulator_set_tracing(). */
271 #define SIM_TRACE_DISASM          0x08
272
273 /** Enable --trace-stall-info when passed to simulator_set_tracing(). */
274 #define SIM_TRACE_STALL_INFO      0x10
275
276 /** Enable --trace-memory-controller when passed to simulator_set_tracing(). */
277 #define SIM_TRACE_MEMORY_CONTROLLER 0x20
278
279 /** Enable --trace-l2 when passed to simulator_set_tracing(). */
280 #define SIM_TRACE_L2_CACHE 0x40
281
282 /** Enable --trace-lines when passed to simulator_set_tracing(). */
283 #define SIM_TRACE_LINES 0x80
284
285 /** Turn off all tracing when passed to simulator_set_tracing(). */
286 #define SIM_TRACE_NONE 0
287
288 /** Turn on all tracing when passed to simulator_set_tracing(). */
289 #define SIM_TRACE_ALL (-1)
290
291 /** @} */
292
293 /** Computes the value to write to SPR_SIM_CONTROL to set tracing flags. */
294 #define SIM_TRACE_SPR_ARG(mask) \
295   (SIM_CONTROL_SET_TRACING | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
296
297
298 /*
299  * Bit masks which can be shifted by 8, combined with
300  * SIM_CONTROL_DUMP, and written to SPR_SIM_CONTROL.
301  */
302
303 /**
304  * @addtogroup arch_sim
305  * @{
306  */
307
308 /** Dump the general-purpose registers. */
309 #define SIM_DUMP_REGS          0x001
310
311 /** Dump the SPRs. */
312 #define SIM_DUMP_SPRS          0x002
313
314 /** Dump the ITLB. */
315 #define SIM_DUMP_ITLB          0x004
316
317 /** Dump the DTLB. */
318 #define SIM_DUMP_DTLB          0x008
319
320 /** Dump the L1 I-cache. */
321 #define SIM_DUMP_L1I           0x010
322
323 /** Dump the L1 D-cache. */
324 #define SIM_DUMP_L1D           0x020
325
326 /** Dump the L2 cache. */
327 #define SIM_DUMP_L2            0x040
328
329 /** Dump the switch registers. */
330 #define SIM_DUMP_SNREGS        0x080
331
332 /** Dump the switch ITLB. */
333 #define SIM_DUMP_SNITLB        0x100
334
335 /** Dump the switch L1 I-cache. */
336 #define SIM_DUMP_SNL1I         0x200
337
338 /** Dump the current backtrace. */
339 #define SIM_DUMP_BACKTRACE     0x400
340
341 /** Only dump valid lines in caches. */
342 #define SIM_DUMP_VALID_LINES   0x800
343
344 /** Dump everything that is dumpable. */
345 #define SIM_DUMP_ALL (-1 & ~SIM_DUMP_VALID_LINES)
346
347 /** @} */
348
349 /** Computes the value to write to SPR_SIM_CONTROL to dump machine state. */
350 #define SIM_DUMP_SPR_ARG(mask) \
351   (SIM_CONTROL_DUMP | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
352
353
354 /*
355  * Bit masks which can be shifted by 8, combined with
356  * SIM_CONTROL_PROFILER_CHIP_xxx, and written to SPR_SIM_CONTROL.
357  */
358
359 /**
360  * @addtogroup arch_sim
361  * @{
362  */
363
364 /** Use with SIM_PROFILER_CHIP_xxx to control the memory controllers. */
365 #define SIM_CHIP_MEMCTL        0x001
366
367 /** Use with SIM_PROFILER_CHIP_xxx to control the XAUI interface. */
368 #define SIM_CHIP_XAUI          0x002
369
370 /** Use with SIM_PROFILER_CHIP_xxx to control the PCIe interface. */
371 #define SIM_CHIP_PCIE          0x004
372
373 /** Use with SIM_PROFILER_CHIP_xxx to control the MPIPE interface. */
374 #define SIM_CHIP_MPIPE         0x008
375
376 /** Use with SIM_PROFILER_CHIP_xxx to control the TRIO interface. */
377 #define SIM_CHIP_TRIO          0x010
378
379 /** Reference all chip devices. */
380 #define SIM_CHIP_ALL (-1)
381
382 /** @} */
383
384 /** Computes the value to write to SPR_SIM_CONTROL to clear chip statistics. */
385 #define SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask) \
386   (SIM_CONTROL_PROFILER_CHIP_CLEAR | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
387
388 /** Computes the value to write to SPR_SIM_CONTROL to disable chip statistics.*/
389 #define SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask) \
390   (SIM_CONTROL_PROFILER_CHIP_DISABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
391
392 /** Computes the value to write to SPR_SIM_CONTROL to enable chip statistics. */
393 #define SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask) \
394   (SIM_CONTROL_PROFILER_CHIP_ENABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
395
396
397
398 /* Shim bitrate controls. */
399
400 /** The number of bits used to store the shim id. */
401 #define SIM_CONTROL_SHAPING_SHIM_ID_BITS 3
402
403 /**
404  * @addtogroup arch_sim
405  * @{
406  */
407
408 /** Change the gbe 0 bitrate. */
409 #define SIM_CONTROL_SHAPING_GBE_0 0x0
410
411 /** Change the gbe 1 bitrate. */
412 #define SIM_CONTROL_SHAPING_GBE_1 0x1
413
414 /** Change the gbe 2 bitrate. */
415 #define SIM_CONTROL_SHAPING_GBE_2 0x2
416
417 /** Change the gbe 3 bitrate. */
418 #define SIM_CONTROL_SHAPING_GBE_3 0x3
419
420 /** Change the xgbe 0 bitrate. */
421 #define SIM_CONTROL_SHAPING_XGBE_0 0x4
422
423 /** Change the xgbe 1 bitrate. */
424 #define SIM_CONTROL_SHAPING_XGBE_1 0x5
425
426 /** The type of shaping to do. */
427 #define SIM_CONTROL_SHAPING_TYPE_BITS 2
428
429 /** Control the multiplier. */
430 #define SIM_CONTROL_SHAPING_MULTIPLIER 0
431
432 /** Control the PPS. */
433 #define SIM_CONTROL_SHAPING_PPS 1
434
435 /** Control the BPS. */
436 #define SIM_CONTROL_SHAPING_BPS 2
437
438 /** The number of bits for the units for the shaping parameter. */
439 #define SIM_CONTROL_SHAPING_UNITS_BITS 2
440
441 /** Provide a number in single units. */
442 #define SIM_CONTROL_SHAPING_UNITS_SINGLE 0
443
444 /** Provide a number in kilo units. */
445 #define SIM_CONTROL_SHAPING_UNITS_KILO 1
446
447 /** Provide a number in mega units. */
448 #define SIM_CONTROL_SHAPING_UNITS_MEGA 2
449
450 /** Provide a number in giga units. */
451 #define SIM_CONTROL_SHAPING_UNITS_GIGA 3
452
453 /** @} */
454
455 /** How many bits are available for the rate. */
456 #define SIM_CONTROL_SHAPING_RATE_BITS \
457   (32 - (_SIM_CONTROL_OPERATOR_BITS + \
458          SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
459          SIM_CONTROL_SHAPING_TYPE_BITS + \
460          SIM_CONTROL_SHAPING_UNITS_BITS))
461
462 /** Computes the value to write to SPR_SIM_CONTROL to change a bitrate. */
463 #define SIM_SHAPING_SPR_ARG(shim, type, units, rate) \
464   (SIM_CONTROL_SHAPING | \
465    ((shim) | \
466    ((type) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS)) | \
467    ((units) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
468                 SIM_CONTROL_SHAPING_TYPE_BITS)) | \
469    ((rate) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
470                SIM_CONTROL_SHAPING_TYPE_BITS + \
471                SIM_CONTROL_SHAPING_UNITS_BITS))) << _SIM_CONTROL_OPERATOR_BITS)
472
473
474 /*
475  * Values returned when reading SPR_SIM_CONTROL.
476  * ISSUE: These names should share a longer common prefix.
477  */
478
479 /**
480  * When reading SPR_SIM_CONTROL, the mask of simulator tracing bits
481  * (SIM_TRACE_xxx values).
482  */
483 #define SIM_TRACE_FLAG_MASK 0xFFFF
484
485 /** When reading SPR_SIM_CONTROL, the mask for whether profiling is enabled. */
486 #define SIM_PROFILER_ENABLED_MASK 0x10000
487
488
489 /*
490  * Special arguments for "SIM_CONTROL_PUTC".
491  */
492
493 /**
494  * Flag value for forcing a PUTC string-flush, including
495  * coordinate/cycle prefix and newline.
496  */
497 #define SIM_PUTC_FLUSH_STRING 0x100
498
499 /**
500  * Flag value for forcing a PUTC binary-data-flush, which skips the
501  * prefix and does not append a newline.
502  */
503 #define SIM_PUTC_FLUSH_BINARY 0x101
504
505
506 #endif /* __ARCH_SIM_DEF_H__ */