diff options
Diffstat (limited to 'arch/tile/include/hv/hypervisor.h')
-rw-r--r-- | arch/tile/include/hv/hypervisor.h | 2366 |
1 files changed, 2366 insertions, 0 deletions
diff --git a/arch/tile/include/hv/hypervisor.h b/arch/tile/include/hv/hypervisor.h new file mode 100644 index 00000000000..84b31551080 --- /dev/null +++ b/arch/tile/include/hv/hypervisor.h | |||
@@ -0,0 +1,2366 @@ | |||
1 | /* | ||
2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation, version 2. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, but | ||
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | ||
11 | * NON INFRINGEMENT. See the GNU General Public License for | ||
12 | * more details. | ||
13 | */ | ||
14 | |||
15 | /** | ||
16 | * @file hypervisor.h | ||
17 | * The hypervisor's public API. | ||
18 | */ | ||
19 | |||
20 | #ifndef _TILE_HV_H | ||
21 | #define _TILE_HV_H | ||
22 | |||
23 | #ifdef __tile__ | ||
24 | #include <arch/chip.h> | ||
25 | #else | ||
26 | /* HACK: Allow use by "tools/cpack/". */ | ||
27 | #include "install/include/arch/chip.h" | ||
28 | #endif | ||
29 | |||
30 | /* Linux builds want unsigned long constants, but assembler wants numbers */ | ||
31 | #ifdef __ASSEMBLER__ | ||
32 | /** One, for assembler */ | ||
33 | #define __HV_SIZE_ONE 1 | ||
34 | #elif !defined(__tile__) && CHIP_VA_WIDTH() > 32 | ||
35 | /** One, for 64-bit on host */ | ||
36 | #define __HV_SIZE_ONE 1ULL | ||
37 | #else | ||
38 | /** One, for Linux */ | ||
39 | #define __HV_SIZE_ONE 1UL | ||
40 | #endif | ||
41 | |||
42 | |||
43 | /** The log2 of the span of a level-1 page table, in bytes. | ||
44 | */ | ||
45 | #define HV_LOG2_L1_SPAN 32 | ||
46 | |||
47 | /** The span of a level-1 page table, in bytes. | ||
48 | */ | ||
49 | #define HV_L1_SPAN (__HV_SIZE_ONE << HV_LOG2_L1_SPAN) | ||
50 | |||
51 | /** The log2 of the size of small pages, in bytes. This value should | ||
52 | * be verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL). | ||
53 | */ | ||
54 | #define HV_LOG2_PAGE_SIZE_SMALL 16 | ||
55 | |||
56 | /** The size of small pages, in bytes. This value should be verified | ||
57 | * at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL). | ||
58 | */ | ||
59 | #define HV_PAGE_SIZE_SMALL (__HV_SIZE_ONE << HV_LOG2_PAGE_SIZE_SMALL) | ||
60 | |||
61 | /** The log2 of the size of large pages, in bytes. This value should be | ||
62 | * verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE). | ||
63 | */ | ||
64 | #define HV_LOG2_PAGE_SIZE_LARGE 24 | ||
65 | |||
66 | /** The size of large pages, in bytes. This value should be verified | ||
67 | * at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE). | ||
68 | */ | ||
69 | #define HV_PAGE_SIZE_LARGE (__HV_SIZE_ONE << HV_LOG2_PAGE_SIZE_LARGE) | ||
70 | |||
71 | /** The log2 of the granularity at which page tables must be aligned; | ||
72 | * in other words, the CPA for a page table must have this many zero | ||
73 | * bits at the bottom of the address. | ||
74 | */ | ||
75 | #define HV_LOG2_PAGE_TABLE_ALIGN 11 | ||
76 | |||
77 | /** The granularity at which page tables must be aligned. | ||
78 | */ | ||
79 | #define HV_PAGE_TABLE_ALIGN (__HV_SIZE_ONE << HV_LOG2_PAGE_TABLE_ALIGN) | ||
80 | |||
81 | /** Normal start of hypervisor glue in client physical memory. */ | ||
82 | #define HV_GLUE_START_CPA 0x10000 | ||
83 | |||
84 | /** This much space is reserved at HV_GLUE_START_CPA | ||
85 | * for the hypervisor glue. The client program must start at | ||
86 | * some address higher than this, and in particular the address of | ||
87 | * its text section should be equal to zero modulo HV_PAGE_SIZE_LARGE | ||
88 | * so that relative offsets to the HV glue are correct. | ||
89 | */ | ||
90 | #define HV_GLUE_RESERVED_SIZE 0x10000 | ||
91 | |||
92 | /** Each entry in the hv dispatch array takes this many bytes. */ | ||
93 | #define HV_DISPATCH_ENTRY_SIZE 32 | ||
94 | |||
95 | /** Version of the hypervisor interface defined by this file */ | ||
96 | #define _HV_VERSION 10 | ||
97 | |||
98 | /* Index into hypervisor interface dispatch code blocks. | ||
99 | * | ||
100 | * Hypervisor calls are invoked from user space by calling code | ||
101 | * at an address HV_BASE_ADDRESS + (index) * HV_DISPATCH_ENTRY_SIZE, | ||
102 | * where index is one of these enum values. | ||
103 | * | ||
104 | * Normally a supervisor is expected to produce a set of symbols | ||
105 | * starting at HV_BASE_ADDRESS that obey this convention, but a user | ||
106 | * program could call directly through function pointers if desired. | ||
107 | * | ||
108 | * These numbers are part of the binary API and will not be changed | ||
109 | * without updating HV_VERSION, which should be a rare event. | ||
110 | */ | ||
111 | |||
112 | /** reserved. */ | ||
113 | #define _HV_DISPATCH_RESERVED 0 | ||
114 | |||
115 | /** hv_init */ | ||
116 | #define HV_DISPATCH_INIT 1 | ||
117 | |||
118 | /** hv_install_context */ | ||
119 | #define HV_DISPATCH_INSTALL_CONTEXT 2 | ||
120 | |||
121 | /** hv_sysconf */ | ||
122 | #define HV_DISPATCH_SYSCONF 3 | ||
123 | |||
124 | /** hv_get_rtc */ | ||
125 | #define HV_DISPATCH_GET_RTC 4 | ||
126 | |||
127 | /** hv_set_rtc */ | ||
128 | #define HV_DISPATCH_SET_RTC 5 | ||
129 | |||
130 | /** hv_flush_asid */ | ||
131 | #define HV_DISPATCH_FLUSH_ASID 6 | ||
132 | |||
133 | /** hv_flush_page */ | ||
134 | #define HV_DISPATCH_FLUSH_PAGE 7 | ||
135 | |||
136 | /** hv_flush_pages */ | ||
137 | #define HV_DISPATCH_FLUSH_PAGES 8 | ||
138 | |||
139 | /** hv_restart */ | ||
140 | #define HV_DISPATCH_RESTART 9 | ||
141 | |||
142 | /** hv_halt */ | ||
143 | #define HV_DISPATCH_HALT 10 | ||
144 | |||
145 | /** hv_power_off */ | ||
146 | #define HV_DISPATCH_POWER_OFF 11 | ||
147 | |||
148 | /** hv_inquire_physical */ | ||
149 | #define HV_DISPATCH_INQUIRE_PHYSICAL 12 | ||
150 | |||
151 | /** hv_inquire_memory_controller */ | ||
152 | #define HV_DISPATCH_INQUIRE_MEMORY_CONTROLLER 13 | ||
153 | |||
154 | /** hv_inquire_virtual */ | ||
155 | #define HV_DISPATCH_INQUIRE_VIRTUAL 14 | ||
156 | |||
157 | /** hv_inquire_asid */ | ||
158 | #define HV_DISPATCH_INQUIRE_ASID 15 | ||
159 | |||
160 | /** hv_nanosleep */ | ||
161 | #define HV_DISPATCH_NANOSLEEP 16 | ||
162 | |||
163 | /** hv_console_read_if_ready */ | ||
164 | #define HV_DISPATCH_CONSOLE_READ_IF_READY 17 | ||
165 | |||
166 | /** hv_console_write */ | ||
167 | #define HV_DISPATCH_CONSOLE_WRITE 18 | ||
168 | |||
169 | /** hv_downcall_dispatch */ | ||
170 | #define HV_DISPATCH_DOWNCALL_DISPATCH 19 | ||
171 | |||
172 | /** hv_inquire_topology */ | ||
173 | #define HV_DISPATCH_INQUIRE_TOPOLOGY 20 | ||
174 | |||
175 | /** hv_fs_findfile */ | ||
176 | #define HV_DISPATCH_FS_FINDFILE 21 | ||
177 | |||
178 | /** hv_fs_fstat */ | ||
179 | #define HV_DISPATCH_FS_FSTAT 22 | ||
180 | |||
181 | /** hv_fs_pread */ | ||
182 | #define HV_DISPATCH_FS_PREAD 23 | ||
183 | |||
184 | /** hv_physaddr_read64 */ | ||
185 | #define HV_DISPATCH_PHYSADDR_READ64 24 | ||
186 | |||
187 | /** hv_physaddr_write64 */ | ||
188 | #define HV_DISPATCH_PHYSADDR_WRITE64 25 | ||
189 | |||
190 | /** hv_get_command_line */ | ||
191 | #define HV_DISPATCH_GET_COMMAND_LINE 26 | ||
192 | |||
193 | /** hv_set_caching */ | ||
194 | #define HV_DISPATCH_SET_CACHING 27 | ||
195 | |||
196 | /** hv_bzero_page */ | ||
197 | #define HV_DISPATCH_BZERO_PAGE 28 | ||
198 | |||
199 | /** hv_register_message_state */ | ||
200 | #define HV_DISPATCH_REGISTER_MESSAGE_STATE 29 | ||
201 | |||
202 | /** hv_send_message */ | ||
203 | #define HV_DISPATCH_SEND_MESSAGE 30 | ||
204 | |||
205 | /** hv_receive_message */ | ||
206 | #define HV_DISPATCH_RECEIVE_MESSAGE 31 | ||
207 | |||
208 | /** hv_inquire_context */ | ||
209 | #define HV_DISPATCH_INQUIRE_CONTEXT 32 | ||
210 | |||
211 | /** hv_start_all_tiles */ | ||
212 | #define HV_DISPATCH_START_ALL_TILES 33 | ||
213 | |||
214 | /** hv_dev_open */ | ||
215 | #define HV_DISPATCH_DEV_OPEN 34 | ||
216 | |||
217 | /** hv_dev_close */ | ||
218 | #define HV_DISPATCH_DEV_CLOSE 35 | ||
219 | |||
220 | /** hv_dev_pread */ | ||
221 | #define HV_DISPATCH_DEV_PREAD 36 | ||
222 | |||
223 | /** hv_dev_pwrite */ | ||
224 | #define HV_DISPATCH_DEV_PWRITE 37 | ||
225 | |||
226 | /** hv_dev_poll */ | ||
227 | #define HV_DISPATCH_DEV_POLL 38 | ||
228 | |||
229 | /** hv_dev_poll_cancel */ | ||
230 | #define HV_DISPATCH_DEV_POLL_CANCEL 39 | ||
231 | |||
232 | /** hv_dev_preada */ | ||
233 | #define HV_DISPATCH_DEV_PREADA 40 | ||
234 | |||
235 | /** hv_dev_pwritea */ | ||
236 | #define HV_DISPATCH_DEV_PWRITEA 41 | ||
237 | |||
238 | /** hv_flush_remote */ | ||
239 | #define HV_DISPATCH_FLUSH_REMOTE 42 | ||
240 | |||
241 | /** hv_console_putc */ | ||
242 | #define HV_DISPATCH_CONSOLE_PUTC 43 | ||
243 | |||
244 | /** hv_inquire_tiles */ | ||
245 | #define HV_DISPATCH_INQUIRE_TILES 44 | ||
246 | |||
247 | /** hv_confstr */ | ||
248 | #define HV_DISPATCH_CONFSTR 45 | ||
249 | |||
250 | /** hv_reexec */ | ||
251 | #define HV_DISPATCH_REEXEC 46 | ||
252 | |||
253 | /** hv_set_command_line */ | ||
254 | #define HV_DISPATCH_SET_COMMAND_LINE 47 | ||
255 | |||
256 | /** hv_dev_register_intr_state */ | ||
257 | #define HV_DISPATCH_DEV_REGISTER_INTR_STATE 48 | ||
258 | |||
259 | /** hv_enable_intr */ | ||
260 | #define HV_DISPATCH_ENABLE_INTR 49 | ||
261 | |||
262 | /** hv_disable_intr */ | ||
263 | #define HV_DISPATCH_DISABLE_INTR 50 | ||
264 | |||
265 | /** hv_trigger_ipi */ | ||
266 | #define HV_DISPATCH_TRIGGER_IPI 51 | ||
267 | |||
268 | /** hv_store_mapping */ | ||
269 | #define HV_DISPATCH_STORE_MAPPING 52 | ||
270 | |||
271 | /** hv_inquire_realpa */ | ||
272 | #define HV_DISPATCH_INQUIRE_REALPA 53 | ||
273 | |||
274 | /** hv_flush_all */ | ||
275 | #define HV_DISPATCH_FLUSH_ALL 54 | ||
276 | |||
277 | /** One more than the largest dispatch value */ | ||
278 | #define _HV_DISPATCH_END 55 | ||
279 | |||
280 | |||
281 | #ifndef __ASSEMBLER__ | ||
282 | |||
283 | #ifdef __KERNEL__ | ||
284 | #include <asm/types.h> | ||
285 | typedef u32 __hv32; /**< 32-bit value */ | ||
286 | typedef u64 __hv64; /**< 64-bit value */ | ||
287 | #else | ||
288 | #include <stdint.h> | ||
289 | typedef uint32_t __hv32; /**< 32-bit value */ | ||
290 | typedef uint64_t __hv64; /**< 64-bit value */ | ||
291 | #endif | ||
292 | |||
293 | |||
294 | /** Hypervisor physical address. */ | ||
295 | typedef __hv64 HV_PhysAddr; | ||
296 | |||
297 | #if CHIP_VA_WIDTH() > 32 | ||
298 | /** Hypervisor virtual address. */ | ||
299 | typedef __hv64 HV_VirtAddr; | ||
300 | #else | ||
301 | /** Hypervisor virtual address. */ | ||
302 | typedef __hv32 HV_VirtAddr; | ||
303 | #endif /* CHIP_VA_WIDTH() > 32 */ | ||
304 | |||
305 | /** Hypervisor ASID. */ | ||
306 | typedef unsigned int HV_ASID; | ||
307 | |||
308 | /** Hypervisor tile location for a memory access | ||
309 | * ("location overridden target"). | ||
310 | */ | ||
311 | typedef unsigned int HV_LOTAR; | ||
312 | |||
313 | /** Hypervisor size of a page. */ | ||
314 | typedef unsigned long HV_PageSize; | ||
315 | |||
316 | /** A page table entry. | ||
317 | */ | ||
318 | typedef struct | ||
319 | { | ||
320 | __hv64 val; /**< Value of PTE */ | ||
321 | } HV_PTE; | ||
322 | |||
323 | /** Hypervisor error code. */ | ||
324 | typedef int HV_Errno; | ||
325 | |||
326 | #endif /* !__ASSEMBLER__ */ | ||
327 | |||
328 | #define HV_OK 0 /**< No error */ | ||
329 | #define HV_EINVAL -801 /**< Invalid argument */ | ||
330 | #define HV_ENODEV -802 /**< No such device */ | ||
331 | #define HV_ENOENT -803 /**< No such file or directory */ | ||
332 | #define HV_EBADF -804 /**< Bad file number */ | ||
333 | #define HV_EFAULT -805 /**< Bad address */ | ||
334 | #define HV_ERECIP -806 /**< Bad recipients */ | ||
335 | #define HV_E2BIG -807 /**< Message too big */ | ||
336 | #define HV_ENOTSUP -808 /**< Service not supported */ | ||
337 | #define HV_EBUSY -809 /**< Device busy */ | ||
338 | #define HV_ENOSYS -810 /**< Invalid syscall */ | ||
339 | #define HV_EPERM -811 /**< No permission */ | ||
340 | #define HV_ENOTREADY -812 /**< Device not ready */ | ||
341 | #define HV_EIO -813 /**< I/O error */ | ||
342 | #define HV_ENOMEM -814 /**< Out of memory */ | ||
343 | |||
344 | #define HV_ERR_MAX -801 /**< Largest HV error code */ | ||
345 | #define HV_ERR_MIN -814 /**< Smallest HV error code */ | ||
346 | |||
347 | #ifndef __ASSEMBLER__ | ||
348 | |||
349 | /** Pass HV_VERSION to hv_init to request this version of the interface. */ | ||
350 | typedef enum { HV_VERSION = _HV_VERSION } HV_VersionNumber; | ||
351 | |||
352 | /** Initializes the hypervisor. | ||
353 | * | ||
354 | * @param interface_version_number The version of the hypervisor interface | ||
355 | * that this program expects, typically HV_VERSION. | ||
356 | * @param chip_num Architecture number of the chip the client was built for. | ||
357 | * @param chip_rev_num Revision number of the chip the client was built for. | ||
358 | */ | ||
359 | void hv_init(HV_VersionNumber interface_version_number, | ||
360 | int chip_num, int chip_rev_num); | ||
361 | |||
362 | |||
363 | /** Queries we can make for hv_sysconf(). | ||
364 | * | ||
365 | * These numbers are part of the binary API and guaranteed not to change. | ||
366 | */ | ||
367 | typedef enum { | ||
368 | /** An invalid value; do not use. */ | ||
369 | _HV_SYSCONF_RESERVED = 0, | ||
370 | |||
371 | /** The length of the glue section containing the hv_ procs, in bytes. */ | ||
372 | HV_SYSCONF_GLUE_SIZE = 1, | ||
373 | |||
374 | /** The size of small pages, in bytes. */ | ||
375 | HV_SYSCONF_PAGE_SIZE_SMALL = 2, | ||
376 | |||
377 | /** The size of large pages, in bytes. */ | ||
378 | HV_SYSCONF_PAGE_SIZE_LARGE = 3, | ||
379 | |||
380 | /** Processor clock speed, in hertz. */ | ||
381 | HV_SYSCONF_CPU_SPEED = 4, | ||
382 | |||
383 | /** Processor temperature, in degrees Kelvin. The value | ||
384 | * HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees | ||
385 | * Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates | ||
386 | * that the temperature has hit an upper limit and is no longer being | ||
387 | * accurately tracked. | ||
388 | */ | ||
389 | HV_SYSCONF_CPU_TEMP = 5, | ||
390 | |||
391 | /** Board temperature, in degrees Kelvin. The value | ||
392 | * HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees | ||
393 | * Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates | ||
394 | * that the temperature has hit an upper limit and is no longer being | ||
395 | * accurately tracked. | ||
396 | */ | ||
397 | HV_SYSCONF_BOARD_TEMP = 6 | ||
398 | |||
399 | } HV_SysconfQuery; | ||
400 | |||
401 | /** Offset to subtract from returned Kelvin temperature to get degrees | ||
402 | Celsius. */ | ||
403 | #define HV_SYSCONF_TEMP_KTOC 273 | ||
404 | |||
405 | /** Pseudo-temperature value indicating that the temperature has | ||
406 | * pegged at its upper limit and is no longer accurate; note that this is | ||
407 | * the value after subtracting HV_SYSCONF_TEMP_KTOC. */ | ||
408 | #define HV_SYSCONF_OVERTEMP 999 | ||
409 | |||
410 | /** Query a configuration value from the hypervisor. | ||
411 | * @param query Which value is requested (HV_SYSCONF_xxx). | ||
412 | * @return The requested value, or -1 the requested value is illegal or | ||
413 | * unavailable. | ||
414 | */ | ||
415 | long hv_sysconf(HV_SysconfQuery query); | ||
416 | |||
417 | |||
418 | /** Queries we can make for hv_confstr(). | ||
419 | * | ||
420 | * These numbers are part of the binary API and guaranteed not to change. | ||
421 | */ | ||
422 | typedef enum { | ||
423 | /** An invalid value; do not use. */ | ||
424 | _HV_CONFSTR_RESERVED = 0, | ||
425 | |||
426 | /** Board part number. */ | ||
427 | HV_CONFSTR_BOARD_PART_NUM = 1, | ||
428 | |||
429 | /** Board serial number. */ | ||
430 | HV_CONFSTR_BOARD_SERIAL_NUM = 2, | ||
431 | |||
432 | /** Chip serial number. */ | ||
433 | HV_CONFSTR_CHIP_SERIAL_NUM = 3, | ||
434 | |||
435 | /** Board revision level. */ | ||
436 | HV_CONFSTR_BOARD_REV = 4, | ||
437 | |||
438 | /** Hypervisor software version. */ | ||
439 | HV_CONFSTR_HV_SW_VER = 5, | ||
440 | |||
441 | /** The name for this chip model. */ | ||
442 | HV_CONFSTR_CHIP_MODEL = 6, | ||
443 | |||
444 | /** Human-readable board description. */ | ||
445 | HV_CONFSTR_BOARD_DESC = 7, | ||
446 | |||
447 | /** Human-readable description of the hypervisor configuration. */ | ||
448 | HV_CONFSTR_HV_CONFIG = 8, | ||
449 | |||
450 | /** Human-readable version string for the boot image (for instance, | ||
451 | * who built it and when, what configuration file was used). */ | ||
452 | HV_CONFSTR_HV_CONFIG_VER = 9, | ||
453 | |||
454 | /** Mezzanine part number. */ | ||
455 | HV_CONFSTR_MEZZ_PART_NUM = 10, | ||
456 | |||
457 | /** Mezzanine serial number. */ | ||
458 | HV_CONFSTR_MEZZ_SERIAL_NUM = 11, | ||
459 | |||
460 | /** Mezzanine revision level. */ | ||
461 | HV_CONFSTR_MEZZ_REV = 12, | ||
462 | |||
463 | /** Human-readable mezzanine description. */ | ||
464 | HV_CONFSTR_MEZZ_DESC = 13, | ||
465 | |||
466 | /** Control path for the onboard network switch. */ | ||
467 | HV_CONFSTR_SWITCH_CONTROL = 14, | ||
468 | |||
469 | /** Chip revision level. */ | ||
470 | HV_CONFSTR_CHIP_REV = 15 | ||
471 | |||
472 | } HV_ConfstrQuery; | ||
473 | |||
474 | /** Query a configuration string from the hypervisor. | ||
475 | * | ||
476 | * @param query Identifier for the specific string to be retrieved | ||
477 | * (HV_CONFSTR_xxx). | ||
478 | * @param buf Buffer in which to place the string. | ||
479 | * @param len Length of the buffer. | ||
480 | * @return If query is valid, then the length of the corresponding string, | ||
481 | * including the trailing null; if this is greater than len, the string | ||
482 | * was truncated. If query is invalid, HV_EINVAL. If the specified | ||
483 | * buffer is not writable by the client, HV_EFAULT. | ||
484 | */ | ||
485 | int hv_confstr(HV_ConfstrQuery query, HV_VirtAddr buf, int len); | ||
486 | |||
487 | /** State object used to enable and disable one-shot and level-sensitive | ||
488 | * interrupts. */ | ||
489 | typedef struct | ||
490 | { | ||
491 | #if CHIP_VA_WIDTH() > 32 | ||
492 | __hv64 opaque[2]; /**< No user-serviceable parts inside */ | ||
493 | #else | ||
494 | __hv32 opaque[2]; /**< No user-serviceable parts inside */ | ||
495 | #endif | ||
496 | } | ||
497 | HV_IntrState; | ||
498 | |||
499 | /** A set of interrupts. */ | ||
500 | typedef __hv32 HV_IntrMask; | ||
501 | |||
502 | /** Tile coordinate */ | ||
503 | typedef struct | ||
504 | { | ||
505 | /** X coordinate, relative to supervisor's top-left coordinate */ | ||
506 | int x; | ||
507 | |||
508 | /** Y coordinate, relative to supervisor's top-left coordinate */ | ||
509 | int y; | ||
510 | } HV_Coord; | ||
511 | |||
512 | /** The low interrupt numbers are reserved for use by the client in | ||
513 | * delivering IPIs. Any interrupt numbers higher than this value are | ||
514 | * reserved for use by HV device drivers. */ | ||
515 | #define HV_MAX_IPI_INTERRUPT 7 | ||
516 | |||
517 | /** Register an interrupt state object. This object is used to enable and | ||
518 | * disable one-shot and level-sensitive interrupts. Once the state is | ||
519 | * registered, the client must not read or write the state object; doing | ||
520 | * so will cause undefined results. | ||
521 | * | ||
522 | * @param intr_state Pointer to interrupt state object. | ||
523 | * @return HV_OK on success, or a hypervisor error code. | ||
524 | */ | ||
525 | HV_Errno hv_dev_register_intr_state(HV_IntrState* intr_state); | ||
526 | |||
527 | /** Enable a set of one-shot and level-sensitive interrupts. | ||
528 | * | ||
529 | * @param intr_state Pointer to interrupt state object. | ||
530 | * @param enab_mask Bitmap of interrupts to enable. | ||
531 | */ | ||
532 | void hv_enable_intr(HV_IntrState* intr_state, HV_IntrMask enab_mask); | ||
533 | |||
534 | /** Disable a set of one-shot and level-sensitive interrupts. | ||
535 | * | ||
536 | * @param intr_state Pointer to interrupt state object. | ||
537 | * @param disab_mask Bitmap of interrupts to disable. | ||
538 | */ | ||
539 | void hv_disable_intr(HV_IntrState* intr_state, HV_IntrMask disab_mask); | ||
540 | |||
541 | /** Trigger a one-shot interrupt on some tile | ||
542 | * | ||
543 | * @param tile Which tile to interrupt. | ||
544 | * @param interrupt Interrupt number to trigger; must be between 0 and | ||
545 | * HV_MAX_IPI_INTERRUPT. | ||
546 | * @return HV_OK on success, or a hypervisor error code. | ||
547 | */ | ||
548 | HV_Errno hv_trigger_ipi(HV_Coord tile, int interrupt); | ||
549 | |||
550 | /** Store memory mapping in debug memory so that external debugger can read it. | ||
551 | * A maximum of 16 entries can be stored. | ||
552 | * | ||
553 | * @param va VA of memory that is mapped. | ||
554 | * @param len Length of mapped memory. | ||
555 | * @param pa PA of memory that is mapped. | ||
556 | * @return 0 on success, -1 if the maximum number of mappings is exceeded. | ||
557 | */ | ||
558 | int hv_store_mapping(HV_VirtAddr va, unsigned int len, HV_PhysAddr pa); | ||
559 | |||
560 | /** Given a client PA and a length, return its real (HV) PA. | ||
561 | * | ||
562 | * @param cpa Client physical address. | ||
563 | * @param len Length of mapped memory. | ||
564 | * @return physical address, or -1 if cpa or len is not valid. | ||
565 | */ | ||
566 | HV_PhysAddr hv_inquire_realpa(HV_PhysAddr cpa, unsigned int len); | ||
567 | |||
568 | /** RTC return flag for no RTC chip present. | ||
569 | */ | ||
570 | #define HV_RTC_NO_CHIP 0x1 | ||
571 | |||
572 | /** RTC return flag for low-voltage condition, indicating that battery had | ||
573 | * died and time read is unreliable. | ||
574 | */ | ||
575 | #define HV_RTC_LOW_VOLTAGE 0x2 | ||
576 | |||
577 | /** Date/Time of day */ | ||
578 | typedef struct { | ||
579 | #if CHIP_WORD_SIZE() > 32 | ||
580 | __hv64 tm_sec; /**< Seconds, 0-59 */ | ||
581 | __hv64 tm_min; /**< Minutes, 0-59 */ | ||
582 | __hv64 tm_hour; /**< Hours, 0-23 */ | ||
583 | __hv64 tm_mday; /**< Day of month, 0-30 */ | ||
584 | __hv64 tm_mon; /**< Month, 0-11 */ | ||
585 | __hv64 tm_year; /**< Years since 1900, 0-199 */ | ||
586 | __hv64 flags; /**< Return flags, 0 if no error */ | ||
587 | #else | ||
588 | __hv32 tm_sec; /**< Seconds, 0-59 */ | ||
589 | __hv32 tm_min; /**< Minutes, 0-59 */ | ||
590 | __hv32 tm_hour; /**< Hours, 0-23 */ | ||
591 | __hv32 tm_mday; /**< Day of month, 0-30 */ | ||
592 | __hv32 tm_mon; /**< Month, 0-11 */ | ||
593 | __hv32 tm_year; /**< Years since 1900, 0-199 */ | ||
594 | __hv32 flags; /**< Return flags, 0 if no error */ | ||
595 | #endif | ||
596 | } HV_RTCTime; | ||
597 | |||
598 | /** Read the current time-of-day clock. | ||
599 | * @return HV_RTCTime of current time (GMT). | ||
600 | */ | ||
601 | HV_RTCTime hv_get_rtc(void); | ||
602 | |||
603 | |||
604 | /** Set the current time-of-day clock. | ||
605 | * @param time time to reset time-of-day to (GMT). | ||
606 | */ | ||
607 | void hv_set_rtc(HV_RTCTime time); | ||
608 | |||
609 | /** Installs a context, comprising a page table and other attributes. | ||
610 | * | ||
611 | * Once this service completes, page_table will be used to translate | ||
612 | * subsequent virtual address references to physical memory. | ||
613 | * | ||
614 | * Installing a context does not cause an implicit TLB flush. Before | ||
615 | * reusing an ASID value for a different address space, the client is | ||
616 | * expected to flush old references from the TLB with hv_flush_asid(). | ||
617 | * (Alternately, hv_flush_all() may be used to flush many ASIDs at once.) | ||
618 | * After invalidating a page table entry, changing its attributes, or | ||
619 | * changing its target CPA, the client is expected to flush old references | ||
620 | * from the TLB with hv_flush_page() or hv_flush_pages(). Making a | ||
621 | * previously invalid page valid does not require a flush. | ||
622 | * | ||
623 | * Specifying an invalid ASID, or an invalid CPA (client physical address) | ||
624 | * (either as page_table_pointer, or within the referenced table), | ||
625 | * or another page table data item documented as above as illegal may | ||
626 | * lead to client termination; since the validation of the table is | ||
627 | * done as needed, this may happen before the service returns, or at | ||
628 | * some later time, or never, depending upon the client's pattern of | ||
629 | * memory references. Page table entries which supply translations for | ||
630 | * invalid virtual addresses may result in client termination, or may | ||
631 | * be silently ignored. "Invalid" in this context means a value which | ||
632 | * was not provided to the client via the appropriate hv_inquire_* routine. | ||
633 | * | ||
634 | * To support changing the instruction VAs at the same time as | ||
635 | * installing the new page table, this call explicitly supports | ||
636 | * setting the "lr" register to a different address and then jumping | ||
637 | * directly to the hv_install_context() routine. In this case, the | ||
638 | * new page table does not need to contain any mapping for the | ||
639 | * hv_install_context address itself. | ||
640 | * | ||
641 | * @param page_table Root of the page table. | ||
642 | * @param access PTE providing info on how to read the page table. This | ||
643 | * value must be consistent between multiple tiles sharing a page table, | ||
644 | * and must also be consistent with any virtual mappings the client | ||
645 | * may be using to access the page table. | ||
646 | * @param asid HV_ASID the page table is to be used for. | ||
647 | * @param flags Context flags, denoting attributes or privileges of the | ||
648 | * current context (HV_CTX_xxx). | ||
649 | * @return Zero on success, or a hypervisor error code on failure. | ||
650 | */ | ||
651 | int hv_install_context(HV_PhysAddr page_table, HV_PTE access, HV_ASID asid, | ||
652 | __hv32 flags); | ||
653 | |||
654 | #endif /* !__ASSEMBLER__ */ | ||
655 | |||
656 | #define HV_CTX_DIRECTIO 0x1 /**< Direct I/O requests are accepted from | ||
657 | PL0. */ | ||
658 | |||
659 | #ifndef __ASSEMBLER__ | ||
660 | |||
661 | /** Value returned from hv_inquire_context(). */ | ||
662 | typedef struct | ||
663 | { | ||
664 | /** Physical address of page table */ | ||
665 | HV_PhysAddr page_table; | ||
666 | |||
667 | /** PTE which defines access method for top of page table */ | ||
668 | HV_PTE access; | ||
669 | |||
670 | /** ASID associated with this page table */ | ||
671 | HV_ASID asid; | ||
672 | |||
673 | /** Context flags */ | ||
674 | __hv32 flags; | ||
675 | } HV_Context; | ||
676 | |||
677 | /** Retrieve information about the currently installed context. | ||
678 | * @return The data passed to the last successful hv_install_context call. | ||
679 | */ | ||
680 | HV_Context hv_inquire_context(void); | ||
681 | |||
682 | |||
683 | /** Flushes all translations associated with the named address space | ||
684 | * identifier from the TLB and any other hypervisor data structures. | ||
685 | * Translations installed with the "global" bit are not flushed. | ||
686 | * | ||
687 | * Specifying an invalid ASID may lead to client termination. "Invalid" | ||
688 | * in this context means a value which was not provided to the client | ||
689 | * via <tt>hv_inquire_asid()</tt>. | ||
690 | * | ||
691 | * @param asid HV_ASID whose entries are to be flushed. | ||
692 | * @return Zero on success, or a hypervisor error code on failure. | ||
693 | */ | ||
694 | int hv_flush_asid(HV_ASID asid); | ||
695 | |||
696 | |||
697 | /** Flushes all translations associated with the named virtual address | ||
698 | * and page size from the TLB and other hypervisor data structures. Only | ||
699 | * pages visible to the current ASID are affected; note that this includes | ||
700 | * global pages in addition to pages specific to the current ASID. | ||
701 | * | ||
702 | * The supplied VA need not be aligned; it may be anywhere in the | ||
703 | * subject page. | ||
704 | * | ||
705 | * Specifying an invalid virtual address may lead to client termination, | ||
706 | * or may silently succeed. "Invalid" in this context means a value | ||
707 | * which was not provided to the client via hv_inquire_virtual. | ||
708 | * | ||
709 | * @param address Address of the page to flush. | ||
710 | * @param page_size Size of pages to assume. | ||
711 | * @return Zero on success, or a hypervisor error code on failure. | ||
712 | */ | ||
713 | int hv_flush_page(HV_VirtAddr address, HV_PageSize page_size); | ||
714 | |||
715 | |||
716 | /** Flushes all translations associated with the named virtual address range | ||
717 | * and page size from the TLB and other hypervisor data structures. Only | ||
718 | * pages visible to the current ASID are affected; note that this includes | ||
719 | * global pages in addition to pages specific to the current ASID. | ||
720 | * | ||
721 | * The supplied VA need not be aligned; it may be anywhere in the | ||
722 | * subject page. | ||
723 | * | ||
724 | * Specifying an invalid virtual address may lead to client termination, | ||
725 | * or may silently succeed. "Invalid" in this context means a value | ||
726 | * which was not provided to the client via hv_inquire_virtual. | ||
727 | * | ||
728 | * @param start Address to flush. | ||
729 | * @param page_size Size of pages to assume. | ||
730 | * @param size The number of bytes to flush. Any page in the range | ||
731 | * [start, start + size) will be flushed from the TLB. | ||
732 | * @return Zero on success, or a hypervisor error code on failure. | ||
733 | */ | ||
734 | int hv_flush_pages(HV_VirtAddr start, HV_PageSize page_size, | ||
735 | unsigned long size); | ||
736 | |||
737 | |||
738 | /** Flushes all non-global translations (if preserve_global is true), | ||
739 | * or absolutely all translations (if preserve_global is false). | ||
740 | * | ||
741 | * @param preserve_global Non-zero if we want to preserve "global" mappings. | ||
742 | * @return Zero on success, or a hypervisor error code on failure. | ||
743 | */ | ||
744 | int hv_flush_all(int preserve_global); | ||
745 | |||
746 | |||
747 | /** Restart machine with optional restart command and optional args. | ||
748 | * @param cmd Const pointer to command to restart with, or NULL | ||
749 | * @param args Const pointer to argument string to restart with, or NULL | ||
750 | */ | ||
751 | void hv_restart(HV_VirtAddr cmd, HV_VirtAddr args); | ||
752 | |||
753 | |||
754 | /** Halt machine. */ | ||
755 | void hv_halt(void); | ||
756 | |||
757 | |||
758 | /** Power off machine. */ | ||
759 | void hv_power_off(void); | ||
760 | |||
761 | |||
762 | /** Re-enter virtual-is-physical memory translation mode and restart | ||
763 | * execution at a given address. | ||
764 | * @param entry Client physical address at which to begin execution. | ||
765 | * @return A hypervisor error code on failure; if the operation is | ||
766 | * successful the call does not return. | ||
767 | */ | ||
768 | int hv_reexec(HV_PhysAddr entry); | ||
769 | |||
770 | |||
771 | /** Chip topology */ | ||
772 | typedef struct | ||
773 | { | ||
774 | /** Relative coordinates of the querying tile */ | ||
775 | HV_Coord coord; | ||
776 | |||
777 | /** Width of the querying supervisor's tile rectangle. */ | ||
778 | int width; | ||
779 | |||
780 | /** Height of the querying supervisor's tile rectangle. */ | ||
781 | int height; | ||
782 | |||
783 | } HV_Topology; | ||
784 | |||
785 | /** Returns information about the tile coordinate system. | ||
786 | * | ||
787 | * Each supervisor is given a rectangle of tiles it potentially controls. | ||
788 | * These tiles are labeled using a relative coordinate system with (0,0) as | ||
789 | * the upper left tile regardless of their physical location on the chip. | ||
790 | * | ||
791 | * This call returns both the size of that rectangle and the position | ||
792 | * within that rectangle of the querying tile. | ||
793 | * | ||
794 | * Not all tiles within that rectangle may be available to the supervisor; | ||
795 | * to get the precise set of available tiles, you must also call | ||
796 | * hv_inquire_tiles(HV_INQ_TILES_AVAIL, ...). | ||
797 | **/ | ||
798 | HV_Topology hv_inquire_topology(void); | ||
799 | |||
800 | /** Sets of tiles we can retrieve with hv_inquire_tiles(). | ||
801 | * | ||
802 | * These numbers are part of the binary API and guaranteed not to change. | ||
803 | */ | ||
804 | typedef enum { | ||
805 | /** An invalid value; do not use. */ | ||
806 | _HV_INQ_TILES_RESERVED = 0, | ||
807 | |||
808 | /** All available tiles within the supervisor's tile rectangle. */ | ||
809 | HV_INQ_TILES_AVAIL = 1, | ||
810 | |||
811 | /** The set of tiles used for hash-for-home caching. */ | ||
812 | HV_INQ_TILES_HFH_CACHE = 2, | ||
813 | |||
814 | /** The set of tiles that can be legally used as a LOTAR for a PTE. */ | ||
815 | HV_INQ_TILES_LOTAR = 3 | ||
816 | } HV_InqTileSet; | ||
817 | |||
818 | /** Returns specific information about various sets of tiles within the | ||
819 | * supervisor's tile rectangle. | ||
820 | * | ||
821 | * @param set Which set of tiles to retrieve. | ||
822 | * @param cpumask Pointer to a returned bitmask (in row-major order, | ||
823 | * supervisor-relative) of tiles. The low bit of the first word | ||
824 | * corresponds to the tile at the upper left-hand corner of the | ||
825 | * supervisor's rectangle. In order for the supervisor to know the | ||
826 | * buffer length to supply, it should first call hv_inquire_topology. | ||
827 | * @param length Number of bytes available for the returned bitmask. | ||
828 | **/ | ||
829 | HV_Errno hv_inquire_tiles(HV_InqTileSet set, HV_VirtAddr cpumask, int length); | ||
830 | |||
831 | |||
832 | /** An identifier for a memory controller. Multiple memory controllers | ||
833 | * may be connected to one chip, and this uniquely identifies each one. | ||
834 | */ | ||
835 | typedef int HV_MemoryController; | ||
836 | |||
837 | /** A range of physical memory. */ | ||
838 | typedef struct | ||
839 | { | ||
840 | HV_PhysAddr start; /**< Starting address. */ | ||
841 | __hv64 size; /**< Size in bytes. */ | ||
842 | HV_MemoryController controller; /**< Which memory controller owns this. */ | ||
843 | } HV_PhysAddrRange; | ||
844 | |||
845 | /** Returns information about a range of physical memory. | ||
846 | * | ||
847 | * hv_inquire_physical() returns one of the ranges of client | ||
848 | * physical addresses which are available to this client. | ||
849 | * | ||
850 | * The first range is retrieved by specifying an idx of 0, and | ||
851 | * successive ranges are returned with subsequent idx values. Ranges | ||
852 | * are ordered by increasing start address (i.e., as idx increases, | ||
853 | * so does start), do not overlap, and do not touch (i.e., the | ||
854 | * available memory is described with the fewest possible ranges). | ||
855 | * | ||
856 | * If an out-of-range idx value is specified, the returned size will be zero. | ||
857 | * A client can count the number of ranges by increasing idx until the | ||
858 | * returned size is zero. There will always be at least one valid range. | ||
859 | * | ||
860 | * Some clients might not be prepared to deal with more than one | ||
861 | * physical address range; they still ought to call this routine and | ||
862 | * issue a warning message if they're given more than one range, on the | ||
863 | * theory that whoever configured the hypervisor to provide that memory | ||
864 | * should know that it's being wasted. | ||
865 | */ | ||
866 | HV_PhysAddrRange hv_inquire_physical(int idx); | ||
867 | |||
868 | |||
869 | /** Memory controller information. */ | ||
870 | typedef struct | ||
871 | { | ||
872 | HV_Coord coord; /**< Relative tile coordinates of the port used by a | ||
873 | specified tile to communicate with this controller. */ | ||
874 | __hv64 speed; /**< Speed of this controller in bytes per second. */ | ||
875 | } HV_MemoryControllerInfo; | ||
876 | |||
877 | /** Returns information about a particular memory controller. | ||
878 | * | ||
879 | * hv_inquire_memory_controller(coord,idx) returns information about a | ||
880 | * particular controller. Two pieces of information are returned: | ||
881 | * - The relative coordinates of the port on the controller that the specified | ||
882 | * tile would use to contact it. The relative coordinates may lie | ||
883 | * outside the supervisor's rectangle, i.e. the controller may not | ||
884 | * be attached to a node managed by the querying node's supervisor. | ||
885 | * In particular note that x or y may be negative. | ||
886 | * - The speed of the memory controller. (This is a not-to-exceed value | ||
887 | * based on the raw hardware data rate, and may not be achievable in | ||
888 | * practice; it is provided to give clients information on the relative | ||
889 | * performance of the available controllers.) | ||
890 | * | ||
891 | * Clients should avoid calling this interface with invalid values. | ||
892 | * A client who does may be terminated. | ||
893 | * @param coord Tile for which to calculate the relative port position. | ||
894 | * @param controller Index of the controller; identical to value returned | ||
895 | * from other routines like hv_inquire_physical. | ||
896 | * @return Information about the controller. | ||
897 | */ | ||
898 | HV_MemoryControllerInfo hv_inquire_memory_controller(HV_Coord coord, | ||
899 | int controller); | ||
900 | |||
901 | |||
902 | /** A range of virtual memory. */ | ||
903 | typedef struct | ||
904 | { | ||
905 | HV_VirtAddr start; /**< Starting address. */ | ||
906 | __hv64 size; /**< Size in bytes. */ | ||
907 | } HV_VirtAddrRange; | ||
908 | |||
909 | /** Returns information about a range of virtual memory. | ||
910 | * | ||
911 | * hv_inquire_virtual() returns one of the ranges of client | ||
912 | * virtual addresses which are available to this client. | ||
913 | * | ||
914 | * The first range is retrieved by specifying an idx of 0, and | ||
915 | * successive ranges are returned with subsequent idx values. Ranges | ||
916 | * are ordered by increasing start address (i.e., as idx increases, | ||
917 | * so does start), do not overlap, and do not touch (i.e., the | ||
918 | * available memory is described with the fewest possible ranges). | ||
919 | * | ||
920 | * If an out-of-range idx value is specified, the returned size will be zero. | ||
921 | * A client can count the number of ranges by increasing idx until the | ||
922 | * returned size is zero. There will always be at least one valid range. | ||
923 | * | ||
924 | * Some clients may well have various virtual addresses hardwired | ||
925 | * into themselves; for instance, their instruction stream may | ||
926 | * have been compiled expecting to live at a particular address. | ||
927 | * Such clients should use this interface to verify they've been | ||
928 | * given the virtual address space they expect, and issue a (potentially | ||
929 | * fatal) warning message otherwise. | ||
930 | * | ||
931 | * Note that the returned size is a __hv64, not a __hv32, so it is | ||
932 | * possible to express a single range spanning the entire 32-bit | ||
933 | * address space. | ||
934 | */ | ||
935 | HV_VirtAddrRange hv_inquire_virtual(int idx); | ||
936 | |||
937 | |||
938 | /** A range of ASID values. */ | ||
939 | typedef struct | ||
940 | { | ||
941 | HV_ASID start; /**< First ASID in the range. */ | ||
942 | unsigned int size; /**< Number of ASIDs. Zero for an invalid range. */ | ||
943 | } HV_ASIDRange; | ||
944 | |||
945 | /** Returns information about a range of ASIDs. | ||
946 | * | ||
947 | * hv_inquire_asid() returns one of the ranges of address | ||
948 | * space identifiers which are available to this client. | ||
949 | * | ||
950 | * The first range is retrieved by specifying an idx of 0, and | ||
951 | * successive ranges are returned with subsequent idx values. Ranges | ||
952 | * are ordered by increasing start value (i.e., as idx increases, | ||
953 | * so does start), do not overlap, and do not touch (i.e., the | ||
954 | * available ASIDs are described with the fewest possible ranges). | ||
955 | * | ||
956 | * If an out-of-range idx value is specified, the returned size will be zero. | ||
957 | * A client can count the number of ranges by increasing idx until the | ||
958 | * returned size is zero. There will always be at least one valid range. | ||
959 | */ | ||
960 | HV_ASIDRange hv_inquire_asid(int idx); | ||
961 | |||
962 | |||
963 | /** Waits for at least the specified number of nanoseconds then returns. | ||
964 | * | ||
965 | * @param nanosecs The number of nanoseconds to sleep. | ||
966 | */ | ||
967 | void hv_nanosleep(int nanosecs); | ||
968 | |||
969 | |||
970 | /** Reads a character from the console without blocking. | ||
971 | * | ||
972 | * @return A value from 0-255 indicates the value successfully read. | ||
973 | * A negative value means no value was ready. | ||
974 | */ | ||
975 | int hv_console_read_if_ready(void); | ||
976 | |||
977 | |||
978 | /** Writes a character to the console, blocking if the console is busy. | ||
979 | * | ||
980 | * This call cannot fail. If the console is broken for some reason, | ||
981 | * output will simply vanish. | ||
982 | * @param byte Character to write. | ||
983 | */ | ||
984 | void hv_console_putc(int byte); | ||
985 | |||
986 | |||
987 | /** Writes a string to the console, blocking if the console is busy. | ||
988 | * @param bytes Pointer to characters to write. | ||
989 | * @param len Number of characters to write. | ||
990 | * @return Number of characters written, or HV_EFAULT if the buffer is invalid. | ||
991 | */ | ||
992 | int hv_console_write(HV_VirtAddr bytes, int len); | ||
993 | |||
994 | |||
995 | /** Dispatch the next interrupt from the client downcall mechanism. | ||
996 | * | ||
997 | * The hypervisor uses downcalls to notify the client of asynchronous | ||
998 | * events. Some of these events are hypervisor-created (like incoming | ||
999 | * messages). Some are regular interrupts which initially occur in | ||
1000 | * the hypervisor, and are normally handled directly by the client; | ||
1001 | * when these occur in a client's interrupt critical section, they must | ||
1002 | * be delivered through the downcall mechanism. | ||
1003 | * | ||
1004 | * A downcall is initially delivered to the client as an INTCTRL_1 | ||
1005 | * interrupt. Upon entry to the INTCTRL_1 vector, the client must | ||
1006 | * immediately invoke the hv_downcall_dispatch service. This service | ||
1007 | * will not return; instead it will cause one of the client's actual | ||
1008 | * downcall-handling interrupt vectors to be entered. The EX_CONTEXT | ||
1009 | * registers in the client will be set so that when the client irets, | ||
1010 | * it will return to the code which was interrupted by the INTCTRL_1 | ||
1011 | * interrupt. | ||
1012 | * | ||
1013 | * Any saving of registers should be done by the actual handling | ||
1014 | * vectors; no registers should be changed by the INTCTRL_1 handler. | ||
1015 | * In particular, the client should not use a jal instruction to invoke | ||
1016 | * the hv_downcall_dispatch service, as that would overwrite the client's | ||
1017 | * lr register. Note that the hv_downcall_dispatch service may overwrite | ||
1018 | * one or more of the client's system save registers. | ||
1019 | * | ||
1020 | * The client must not modify the INTCTRL_1_STATUS SPR. The hypervisor | ||
1021 | * will set this register to cause a downcall to happen, and will clear | ||
1022 | * it when no further downcalls are pending. | ||
1023 | * | ||
1024 | * When a downcall vector is entered, the INTCTRL_1 interrupt will be | ||
1025 | * masked. When the client is done processing a downcall, and is ready | ||
1026 | * to accept another, it must unmask this interrupt; if more downcalls | ||
1027 | * are pending, this will cause the INTCTRL_1 vector to be reentered. | ||
1028 | * Currently the following interrupt vectors can be entered through a | ||
1029 | * downcall: | ||
1030 | * | ||
1031 | * INT_MESSAGE_RCV_DWNCL (hypervisor message available) | ||
1032 | * INT_DMATLB_MISS_DWNCL (DMA TLB miss) | ||
1033 | * INT_SNITLB_MISS_DWNCL (SNI TLB miss) | ||
1034 | * INT_DMATLB_ACCESS_DWNCL (DMA TLB access violation) | ||
1035 | */ | ||
1036 | void hv_downcall_dispatch(void); | ||
1037 | |||
1038 | #endif /* !__ASSEMBLER__ */ | ||
1039 | |||
1040 | /** We use actual interrupt vectors which never occur (they're only there | ||
1041 | * to allow setting MPLs for related SPRs) for our downcall vectors. | ||
1042 | */ | ||
1043 | /** Message receive downcall interrupt vector */ | ||
1044 | #define INT_MESSAGE_RCV_DWNCL INT_BOOT_ACCESS | ||
1045 | /** DMA TLB miss downcall interrupt vector */ | ||
1046 | #define INT_DMATLB_MISS_DWNCL INT_DMA_ASID | ||
1047 | /** Static nework processor instruction TLB miss interrupt vector */ | ||
1048 | #define INT_SNITLB_MISS_DWNCL INT_SNI_ASID | ||
1049 | /** DMA TLB access violation downcall interrupt vector */ | ||
1050 | #define INT_DMATLB_ACCESS_DWNCL INT_DMA_CPL | ||
1051 | /** Device interrupt downcall interrupt vector */ | ||
1052 | #define INT_DEV_INTR_DWNCL INT_WORLD_ACCESS | ||
1053 | |||
1054 | #ifndef __ASSEMBLER__ | ||
1055 | |||
1056 | /** Requests the inode for a specific full pathname. | ||
1057 | * | ||
1058 | * Performs a lookup in the hypervisor filesystem for a given filename. | ||
1059 | * Multiple calls with the same filename will always return the same inode. | ||
1060 | * If there is no such filename, HV_ENOENT is returned. | ||
1061 | * A bad filename pointer may result in HV_EFAULT instead. | ||
1062 | * | ||
1063 | * @param filename Constant pointer to name of requested file | ||
1064 | * @return Inode of requested file | ||
1065 | */ | ||
1066 | int hv_fs_findfile(HV_VirtAddr filename); | ||
1067 | |||
1068 | |||
1069 | /** Data returned from an fstat request. | ||
1070 | * Note that this structure should be no more than 40 bytes in size so | ||
1071 | * that it can always be returned completely in registers. | ||
1072 | */ | ||
1073 | typedef struct | ||
1074 | { | ||
1075 | int size; /**< Size of file (or HV_Errno on error) */ | ||
1076 | unsigned int flags; /**< Flags (see HV_FS_FSTAT_FLAGS) */ | ||
1077 | } HV_FS_StatInfo; | ||
1078 | |||
1079 | /** Bitmask flags for fstat request */ | ||
1080 | typedef enum | ||
1081 | { | ||
1082 | HV_FS_ISDIR = 0x0001 /**< Is the entry a directory? */ | ||
1083 | } HV_FS_FSTAT_FLAGS; | ||
1084 | |||
1085 | /** Get stat information on a given file inode. | ||
1086 | * | ||
1087 | * Return information on the file with the given inode. | ||
1088 | * | ||
1089 | * IF the HV_FS_ISDIR bit is set, the "file" is a directory. Reading | ||
1090 | * it will return NUL-separated filenames (no directory part) relative | ||
1091 | * to the path to the inode of the directory "file". These can be | ||
1092 | * appended to the path to the directory "file" after a forward slash | ||
1093 | * to create additional filenames. Note that it is not required | ||
1094 | * that all valid paths be decomposable into valid parent directories; | ||
1095 | * a filesystem may validly have just a few files, none of which have | ||
1096 | * HV_FS_ISDIR set. However, if clients may wish to enumerate the | ||
1097 | * files in the filesystem, it is recommended to include all the | ||
1098 | * appropriate parent directory "files" to give a consistent view. | ||
1099 | * | ||
1100 | * An invalid file inode will cause an HV_EBADF error to be returned. | ||
1101 | * | ||
1102 | * @param inode The inode number of the query | ||
1103 | * @return An HV_FS_StatInfo structure | ||
1104 | */ | ||
1105 | HV_FS_StatInfo hv_fs_fstat(int inode); | ||
1106 | |||
1107 | |||
1108 | /** Read data from a specific hypervisor file. | ||
1109 | * On error, may return HV_EBADF for a bad inode or HV_EFAULT for a bad buf. | ||
1110 | * Reads near the end of the file will return fewer bytes than requested. | ||
1111 | * Reads at or beyond the end of a file will return zero. | ||
1112 | * | ||
1113 | * @param inode the hypervisor file to read | ||
1114 | * @param buf the buffer to read data into | ||
1115 | * @param length the number of bytes of data to read | ||
1116 | * @param offset the offset into the file to read the data from | ||
1117 | * @return number of bytes successfully read, or an HV_Errno code | ||
1118 | */ | ||
1119 | int hv_fs_pread(int inode, HV_VirtAddr buf, int length, int offset); | ||
1120 | |||
1121 | |||
1122 | /** Read a 64-bit word from the specified physical address. | ||
1123 | * The address must be 8-byte aligned. | ||
1124 | * Specifying an invalid physical address will lead to client termination. | ||
1125 | * @param addr The physical address to read | ||
1126 | * @param access The PTE describing how to read the memory | ||
1127 | * @return The 64-bit value read from the given address | ||
1128 | */ | ||
1129 | unsigned long long hv_physaddr_read64(HV_PhysAddr addr, HV_PTE access); | ||
1130 | |||
1131 | |||
1132 | /** Write a 64-bit word to the specified physical address. | ||
1133 | * The address must be 8-byte aligned. | ||
1134 | * Specifying an invalid physical address will lead to client termination. | ||
1135 | * @param addr The physical address to write | ||
1136 | * @param access The PTE that says how to write the memory | ||
1137 | * @param val The 64-bit value to write to the given address | ||
1138 | */ | ||
1139 | void hv_physaddr_write64(HV_PhysAddr addr, HV_PTE access, | ||
1140 | unsigned long long val); | ||
1141 | |||
1142 | |||
1143 | /** Get the value of the command-line for the supervisor, if any. | ||
1144 | * This will not include the filename of the booted supervisor, but may | ||
1145 | * include configured-in boot arguments or the hv_restart() arguments. | ||
1146 | * If the buffer is not long enough the hypervisor will NUL the first | ||
1147 | * character of the buffer but not write any other data. | ||
1148 | * @param buf The virtual address to write the command-line string to. | ||
1149 | * @param length The length of buf, in characters. | ||
1150 | * @return The actual length of the command line, including the trailing NUL | ||
1151 | * (may be larger than "length"). | ||
1152 | */ | ||
1153 | int hv_get_command_line(HV_VirtAddr buf, int length); | ||
1154 | |||
1155 | |||
1156 | /** Set a new value for the command-line for the supervisor, which will | ||
1157 | * be returned from subsequent invocations of hv_get_command_line() on | ||
1158 | * this tile. | ||
1159 | * @param buf The virtual address to read the command-line string from. | ||
1160 | * @param length The length of buf, in characters; must be no more than | ||
1161 | * HV_COMMAND_LINE_LEN. | ||
1162 | * @return Zero if successful, or a hypervisor error code. | ||
1163 | */ | ||
1164 | HV_Errno hv_set_command_line(HV_VirtAddr buf, int length); | ||
1165 | |||
1166 | /** Maximum size of a command line passed to hv_set_command_line(); note | ||
1167 | * that a line returned from hv_get_command_line() could be larger than | ||
1168 | * this.*/ | ||
1169 | #define HV_COMMAND_LINE_LEN 256 | ||
1170 | |||
1171 | /** Tell the hypervisor how to cache non-priority pages | ||
1172 | * (its own as well as pages explicitly represented in page tables). | ||
1173 | * Normally these will be represented as red/black pages, but | ||
1174 | * when the supervisor starts to allocate "priority" pages in the PTE | ||
1175 | * the hypervisor will need to start marking those pages as (e.g.) "red" | ||
1176 | * and non-priority pages as either "black" (if they cache-alias | ||
1177 | * with the existing priority pages) or "red/black" (if they don't). | ||
1178 | * The bitmask provides information on which parts of the cache | ||
1179 | * have been used for pinned pages so far on this tile; if (1 << N) | ||
1180 | * appears in the bitmask, that indicates that a page has been marked | ||
1181 | * "priority" whose PFN equals N, mod 8. | ||
1182 | * @param bitmask A bitmap of priority page set values | ||
1183 | */ | ||
1184 | void hv_set_caching(unsigned int bitmask); | ||
1185 | |||
1186 | |||
1187 | /** Zero out a specified number of pages. | ||
1188 | * The va and size must both be multiples of 4096. | ||
1189 | * Caches are bypassed and memory is directly set to zero. | ||
1190 | * This API is implemented only in the magic hypervisor and is intended | ||
1191 | * to provide a performance boost to the minimal supervisor by | ||
1192 | * giving it a fast way to zero memory pages when allocating them. | ||
1193 | * @param va Virtual address where the page has been mapped | ||
1194 | * @param size Number of bytes (must be a page size multiple) | ||
1195 | */ | ||
1196 | void hv_bzero_page(HV_VirtAddr va, unsigned int size); | ||
1197 | |||
1198 | |||
1199 | /** State object for the hypervisor messaging subsystem. */ | ||
1200 | typedef struct | ||
1201 | { | ||
1202 | #if CHIP_VA_WIDTH() > 32 | ||
1203 | __hv64 opaque[2]; /**< No user-serviceable parts inside */ | ||
1204 | #else | ||
1205 | __hv32 opaque[2]; /**< No user-serviceable parts inside */ | ||
1206 | #endif | ||
1207 | } | ||
1208 | HV_MsgState; | ||
1209 | |||
1210 | /** Register to receive incoming messages. | ||
1211 | * | ||
1212 | * This routine configures the current tile so that it can receive | ||
1213 | * incoming messages. It must be called before the client can receive | ||
1214 | * messages with the hv_receive_message routine, and must be called on | ||
1215 | * each tile which will receive messages. | ||
1216 | * | ||
1217 | * msgstate is the virtual address of a state object of type HV_MsgState. | ||
1218 | * Once the state is registered, the client must not read or write the | ||
1219 | * state object; doing so will cause undefined results. | ||
1220 | * | ||
1221 | * If this routine is called with msgstate set to 0, the client's message | ||
1222 | * state will be freed and it will no longer be able to receive messages. | ||
1223 | * Note that this may cause the loss of any as-yet-undelivered messages | ||
1224 | * for the client. | ||
1225 | * | ||
1226 | * If another client attempts to send a message to a client which has | ||
1227 | * not yet called hv_register_message_state, or which has freed its | ||
1228 | * message state, the message will not be delivered, as if the client | ||
1229 | * had insufficient buffering. | ||
1230 | * | ||
1231 | * This routine returns HV_OK if the registration was successful, and | ||
1232 | * HV_EINVAL if the supplied state object is unsuitable. Note that some | ||
1233 | * errors may not be detected during this routine, but might be detected | ||
1234 | * during a subsequent message delivery. | ||
1235 | * @param msgstate State object. | ||
1236 | **/ | ||
1237 | HV_Errno hv_register_message_state(HV_MsgState* msgstate); | ||
1238 | |||
1239 | /** Possible message recipient states. */ | ||
1240 | typedef enum | ||
1241 | { | ||
1242 | HV_TO_BE_SENT, /**< Not sent (not attempted, or recipient not ready) */ | ||
1243 | HV_SENT, /**< Successfully sent */ | ||
1244 | HV_BAD_RECIP /**< Bad recipient coordinates (permanent error) */ | ||
1245 | } HV_Recip_State; | ||
1246 | |||
1247 | /** Message recipient. */ | ||
1248 | typedef struct | ||
1249 | { | ||
1250 | /** X coordinate, relative to supervisor's top-left coordinate */ | ||
1251 | unsigned int x:11; | ||
1252 | |||
1253 | /** Y coordinate, relative to supervisor's top-left coordinate */ | ||
1254 | unsigned int y:11; | ||
1255 | |||
1256 | /** Status of this recipient */ | ||
1257 | HV_Recip_State state:10; | ||
1258 | } HV_Recipient; | ||
1259 | |||
1260 | /** Send a message to a set of recipients. | ||
1261 | * | ||
1262 | * This routine sends a message to a set of recipients. | ||
1263 | * | ||
1264 | * recips is an array of HV_Recipient structures. Each specifies a tile, | ||
1265 | * and a message state; initially, it is expected that the state will | ||
1266 | * be set to HV_TO_BE_SENT. nrecip specifies the number of recipients | ||
1267 | * in the recips array. | ||
1268 | * | ||
1269 | * For each recipient whose state is HV_TO_BE_SENT, the hypervisor attempts | ||
1270 | * to send that tile the specified message. In order to successfully | ||
1271 | * receive the message, the receiver must be a valid tile to which the | ||
1272 | * sender has access, must not be the sending tile itself, and must have | ||
1273 | * sufficient free buffer space. (The hypervisor guarantees that each | ||
1274 | * tile which has called hv_register_message_state() will be able to | ||
1275 | * buffer one message from every other tile which can legally send to it; | ||
1276 | * more space may be provided but is not guaranteed.) If an invalid tile | ||
1277 | * is specified, the recipient's state is set to HV_BAD_RECIP; this is a | ||
1278 | * permanent delivery error. If the message is successfully delivered | ||
1279 | * to the recipient's buffer, the recipient's state is set to HV_SENT. | ||
1280 | * Otherwise, the recipient's state is unchanged. Message delivery is | ||
1281 | * synchronous; all attempts to send messages are completed before this | ||
1282 | * routine returns. | ||
1283 | * | ||
1284 | * If no permanent delivery errors were encountered, the routine returns | ||
1285 | * the number of messages successfully sent: that is, the number of | ||
1286 | * recipients whose states changed from HV_TO_BE_SENT to HV_SENT during | ||
1287 | * this operation. If any permanent delivery errors were encountered, | ||
1288 | * the routine returns HV_ERECIP. In the event of permanent delivery | ||
1289 | * errors, it may be the case that delivery was not attempted to all | ||
1290 | * recipients; if any messages were succesfully delivered, however, | ||
1291 | * recipients' state values will be updated appropriately. | ||
1292 | * | ||
1293 | * It is explicitly legal to specify a recipient structure whose state | ||
1294 | * is not HV_TO_BE_SENT; such a recipient is ignored. One suggested way | ||
1295 | * of using hv_send_message to send a message to multiple tiles is to set | ||
1296 | * up a list of recipients, and then call the routine repeatedly with the | ||
1297 | * same list, each time accumulating the number of messages successfully | ||
1298 | * sent, until all messages are sent, a permanent error is encountered, | ||
1299 | * or the desired number of attempts have been made. When used in this | ||
1300 | * way, the routine will deliver each message no more than once to each | ||
1301 | * recipient. | ||
1302 | * | ||
1303 | * Note that a message being successfully delivered to the recipient's | ||
1304 | * buffer space does not guarantee that it is received by the recipient, | ||
1305 | * either immediately or at any time in the future; the recipient might | ||
1306 | * never call hv_receive_message, or could register a different state | ||
1307 | * buffer, losing the message. | ||
1308 | * | ||
1309 | * Specifiying the same recipient more than once in the recipient list | ||
1310 | * is an error, which will not result in an error return but which may | ||
1311 | * or may not result in more than one message being delivered to the | ||
1312 | * recipient tile. | ||
1313 | * | ||
1314 | * buf and buflen specify the message to be sent. buf is a virtual address | ||
1315 | * which must be currently mapped in the client's page table; if not, the | ||
1316 | * routine returns HV_EFAULT. buflen must be greater than zero and less | ||
1317 | * than or equal to HV_MAX_MESSAGE_SIZE, and nrecip must be less than the | ||
1318 | * number of tiles to which the sender has access; if not, the routine | ||
1319 | * returns HV_EINVAL. | ||
1320 | * @param recips List of recipients. | ||
1321 | * @param nrecip Number of recipients. | ||
1322 | * @param buf Address of message data. | ||
1323 | * @param buflen Length of message data. | ||
1324 | **/ | ||
1325 | int hv_send_message(HV_Recipient *recips, int nrecip, | ||
1326 | HV_VirtAddr buf, int buflen); | ||
1327 | |||
1328 | /** Maximum hypervisor message size, in bytes */ | ||
1329 | #define HV_MAX_MESSAGE_SIZE 28 | ||
1330 | |||
1331 | |||
1332 | /** Return value from hv_receive_message() */ | ||
1333 | typedef struct | ||
1334 | { | ||
1335 | int msglen; /**< Message length in bytes, or an error code */ | ||
1336 | __hv32 source; /**< Code identifying message sender (HV_MSG_xxx) */ | ||
1337 | } HV_RcvMsgInfo; | ||
1338 | |||
1339 | #define HV_MSG_TILE 0x0 /**< Message source is another tile */ | ||
1340 | #define HV_MSG_INTR 0x1 /**< Message source is a driver interrupt */ | ||
1341 | |||
1342 | /** Receive a message. | ||
1343 | * | ||
1344 | * This routine retrieves a message from the client's incoming message | ||
1345 | * buffer. | ||
1346 | * | ||
1347 | * Multiple messages sent from a particular sending tile to a particular | ||
1348 | * receiving tile are received in the order that they were sent; however, | ||
1349 | * no ordering is guaranteed between messages sent by different tiles. | ||
1350 | * | ||
1351 | * Whenever the a client's message buffer is empty, the first message | ||
1352 | * subsequently received will cause the client's MESSAGE_RCV_DWNCL | ||
1353 | * interrupt vector to be invoked through the interrupt downcall mechanism | ||
1354 | * (see the description of the hv_downcall_dispatch() routine for details | ||
1355 | * on downcalls). | ||
1356 | * | ||
1357 | * Another message-available downcall will not occur until a call to | ||
1358 | * this routine is made when the message buffer is empty, and a message | ||
1359 | * subsequently arrives. Note that such a downcall could occur while | ||
1360 | * this routine is executing. If the calling code does not wish this | ||
1361 | * to happen, it is recommended that this routine be called with the | ||
1362 | * INTCTRL_1 interrupt masked, or inside an interrupt critical section. | ||
1363 | * | ||
1364 | * msgstate is the value previously passed to hv_register_message_state(). | ||
1365 | * buf is the virtual address of the buffer into which the message will | ||
1366 | * be written; buflen is the length of the buffer. | ||
1367 | * | ||
1368 | * This routine returns an HV_RcvMsgInfo structure. The msglen member | ||
1369 | * of that structure is the length of the message received, zero if no | ||
1370 | * message is available, or HV_E2BIG if the message is too large for the | ||
1371 | * specified buffer. If the message is too large, it is not consumed, | ||
1372 | * and may be retrieved by a subsequent call to this routine specifying | ||
1373 | * a sufficiently large buffer. A buffer which is HV_MAX_MESSAGE_SIZE | ||
1374 | * bytes long is guaranteed to be able to receive any possible message. | ||
1375 | * | ||
1376 | * The source member of the HV_RcvMsgInfo structure describes the sender | ||
1377 | * of the message. For messages sent by another client tile via an | ||
1378 | * hv_send_message() call, this value is HV_MSG_TILE; for messages sent | ||
1379 | * as a result of a device interrupt, this value is HV_MSG_INTR. | ||
1380 | */ | ||
1381 | |||
1382 | HV_RcvMsgInfo hv_receive_message(HV_MsgState msgstate, HV_VirtAddr buf, | ||
1383 | int buflen); | ||
1384 | |||
1385 | |||
1386 | /** Start remaining tiles owned by this supervisor. Initially, only one tile | ||
1387 | * executes the client program; after it calls this service, the other tiles | ||
1388 | * are started. This allows the initial tile to do one-time configuration | ||
1389 | * of shared data structures without having to lock them against simultaneous | ||
1390 | * access. | ||
1391 | */ | ||
1392 | void hv_start_all_tiles(void); | ||
1393 | |||
1394 | |||
1395 | /** Open a hypervisor device. | ||
1396 | * | ||
1397 | * This service initializes an I/O device and its hypervisor driver software, | ||
1398 | * and makes it available for use. The open operation is per-device per-chip; | ||
1399 | * once it has been performed, the device handle returned may be used in other | ||
1400 | * device services calls made by any tile. | ||
1401 | * | ||
1402 | * @param name Name of the device. A base device name is just a text string | ||
1403 | * (say, "pcie"). If there is more than one instance of a device, the | ||
1404 | * base name is followed by a slash and a device number (say, "pcie/0"). | ||
1405 | * Some devices may support further structure beneath those components; | ||
1406 | * most notably, devices which require control operations do so by | ||
1407 | * supporting reads and/or writes to a control device whose name | ||
1408 | * includes a trailing "/ctl" (say, "pcie/0/ctl"). | ||
1409 | * @param flags Flags (HV_DEV_xxx). | ||
1410 | * @return A positive integer device handle, or a negative error code. | ||
1411 | */ | ||
1412 | int hv_dev_open(HV_VirtAddr name, __hv32 flags); | ||
1413 | |||
1414 | |||
1415 | /** Close a hypervisor device. | ||
1416 | * | ||
1417 | * This service uninitializes an I/O device and its hypervisor driver | ||
1418 | * software, and makes it unavailable for use. The close operation is | ||
1419 | * per-device per-chip; once it has been performed, the device is no longer | ||
1420 | * available. Normally there is no need to ever call the close service. | ||
1421 | * | ||
1422 | * @param devhdl Device handle of the device to be closed. | ||
1423 | * @return Zero if the close is successful, otherwise, a negative error code. | ||
1424 | */ | ||
1425 | int hv_dev_close(int devhdl); | ||
1426 | |||
1427 | |||
1428 | /** Read data from a hypervisor device synchronously. | ||
1429 | * | ||
1430 | * This service transfers data from a hypervisor device to a memory buffer. | ||
1431 | * When the service returns, the data has been written from the memory buffer, | ||
1432 | * and the buffer will not be further modified by the driver. | ||
1433 | * | ||
1434 | * No ordering is guaranteed between requests issued from different tiles. | ||
1435 | * | ||
1436 | * Devices may choose to support both the synchronous and asynchronous read | ||
1437 | * operations, only one of them, or neither of them. | ||
1438 | * | ||
1439 | * @param devhdl Device handle of the device to be read from. | ||
1440 | * @param flags Flags (HV_DEV_xxx). | ||
1441 | * @param va Virtual address of the target data buffer. This buffer must | ||
1442 | * be mapped in the currently installed page table; if not, HV_EFAULT | ||
1443 | * may be returned. | ||
1444 | * @param len Number of bytes to be transferred. | ||
1445 | * @param offset Driver-dependent offset. For a random-access device, this is | ||
1446 | * often a byte offset from the beginning of the device; in other cases, | ||
1447 | * like on a control device, it may have a different meaning. | ||
1448 | * @return A non-negative value if the read was at least partially successful; | ||
1449 | * otherwise, a negative error code. The precise interpretation of | ||
1450 | * the return value is driver-dependent, but many drivers will return | ||
1451 | * the number of bytes successfully transferred. | ||
1452 | */ | ||
1453 | int hv_dev_pread(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len, | ||
1454 | __hv64 offset); | ||
1455 | |||
1456 | #define HV_DEV_NB_EMPTY 0x1 /**< Don't block when no bytes of data can | ||
1457 | be transferred. */ | ||
1458 | #define HV_DEV_NB_PARTIAL 0x2 /**< Don't block when some bytes, but not all | ||
1459 | of the requested bytes, can be | ||
1460 | transferred. */ | ||
1461 | #define HV_DEV_NOCACHE 0x4 /**< The caller warrants that none of the | ||
1462 | cache lines which might contain data | ||
1463 | from the requested buffer are valid. | ||
1464 | Useful with asynchronous operations | ||
1465 | only. */ | ||
1466 | |||
1467 | #define HV_DEV_ALLFLAGS (HV_DEV_NB_EMPTY | HV_DEV_NB_PARTIAL | \ | ||
1468 | HV_DEV_NOCACHE) /**< All HV_DEV_xxx flags */ | ||
1469 | |||
1470 | /** Write data to a hypervisor device synchronously. | ||
1471 | * | ||
1472 | * This service transfers data from a memory buffer to a hypervisor device. | ||
1473 | * When the service returns, the data has been read from the memory buffer, | ||
1474 | * and the buffer may be overwritten by the client; the data may not | ||
1475 | * necessarily have been conveyed to the actual hardware I/O interface. | ||
1476 | * | ||
1477 | * No ordering is guaranteed between requests issued from different tiles. | ||
1478 | * | ||
1479 | * Devices may choose to support both the synchronous and asynchronous write | ||
1480 | * operations, only one of them, or neither of them. | ||
1481 | * | ||
1482 | * @param devhdl Device handle of the device to be written to. | ||
1483 | * @param flags Flags (HV_DEV_xxx). | ||
1484 | * @param va Virtual address of the source data buffer. This buffer must | ||
1485 | * be mapped in the currently installed page table; if not, HV_EFAULT | ||
1486 | * may be returned. | ||
1487 | * @param len Number of bytes to be transferred. | ||
1488 | * @param offset Driver-dependent offset. For a random-access device, this is | ||
1489 | * often a byte offset from the beginning of the device; in other cases, | ||
1490 | * like on a control device, it may have a different meaning. | ||
1491 | * @return A non-negative value if the write was at least partially successful; | ||
1492 | * otherwise, a negative error code. The precise interpretation of | ||
1493 | * the return value is driver-dependent, but many drivers will return | ||
1494 | * the number of bytes successfully transferred. | ||
1495 | */ | ||
1496 | int hv_dev_pwrite(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len, | ||
1497 | __hv64 offset); | ||
1498 | |||
1499 | |||
1500 | /** Interrupt arguments, used in the asynchronous I/O interfaces. */ | ||
1501 | #if CHIP_VA_WIDTH() > 32 | ||
1502 | typedef __hv64 HV_IntArg; | ||
1503 | #else | ||
1504 | typedef __hv32 HV_IntArg; | ||
1505 | #endif | ||
1506 | |||
1507 | /** Interrupt messages are delivered via the mechanism as normal messages, | ||
1508 | * but have a message source of HV_DEV_INTR. The message is formatted | ||
1509 | * as an HV_IntrMsg structure. | ||
1510 | */ | ||
1511 | |||
1512 | typedef struct | ||
1513 | { | ||
1514 | HV_IntArg intarg; /**< Interrupt argument, passed to the poll/preada/pwritea | ||
1515 | services */ | ||
1516 | HV_IntArg intdata; /**< Interrupt-specific interrupt data */ | ||
1517 | } HV_IntrMsg; | ||
1518 | |||
1519 | /** Request an interrupt message when a device condition is satisfied. | ||
1520 | * | ||
1521 | * This service requests that an interrupt message be delivered to the | ||
1522 | * requesting tile when a device becomes readable or writable, or when any | ||
1523 | * data queued to the device via previous write operations from this tile | ||
1524 | * has been actually sent out on the hardware I/O interface. Devices may | ||
1525 | * choose to support any, all, or none of the available conditions. | ||
1526 | * | ||
1527 | * If multiple conditions are specified, only one message will be | ||
1528 | * delivered. If the event mask delivered to that interrupt handler | ||
1529 | * indicates that some of the conditions have not yet occurred, the | ||
1530 | * client must issue another poll() call if it wishes to wait for those | ||
1531 | * conditions. | ||
1532 | * | ||
1533 | * Only one poll may be outstanding per device handle per tile. If more than | ||
1534 | * one tile is polling on the same device and condition, they will all be | ||
1535 | * notified when it happens. Because of this, clients may not assume that | ||
1536 | * the condition signaled is necessarily still true when they request a | ||
1537 | * subsequent service; for instance, the readable data which caused the | ||
1538 | * poll call to interrupt may have been read by another tile in the interim. | ||
1539 | * | ||
1540 | * The notification interrupt message could come directly, or via the | ||
1541 | * downcall (intctrl1) method, depending on what the tile is doing | ||
1542 | * when the condition is satisfied. Note that it is possible for the | ||
1543 | * requested interrupt to be delivered after this service is called but | ||
1544 | * before it returns. | ||
1545 | * | ||
1546 | * @param devhdl Device handle of the device to be polled. | ||
1547 | * @param events Flags denoting the events which will cause the interrupt to | ||
1548 | * be delivered (HV_DEVPOLL_xxx). | ||
1549 | * @param intarg Value which will be delivered as the intarg member of the | ||
1550 | * eventual interrupt message; the intdata member will be set to a | ||
1551 | * mask of HV_DEVPOLL_xxx values indicating which conditions have been | ||
1552 | * satisifed. | ||
1553 | * @return Zero if the interrupt was successfully scheduled; otherwise, a | ||
1554 | * negative error code. | ||
1555 | */ | ||
1556 | int hv_dev_poll(int devhdl, __hv32 events, HV_IntArg intarg); | ||
1557 | |||
1558 | #define HV_DEVPOLL_READ 0x1 /**< Test device for readability */ | ||
1559 | #define HV_DEVPOLL_WRITE 0x2 /**< Test device for writability */ | ||
1560 | #define HV_DEVPOLL_FLUSH 0x4 /**< Test device for output drained */ | ||
1561 | |||
1562 | |||
1563 | /** Cancel a request for an interrupt when a device event occurs. | ||
1564 | * | ||
1565 | * This service requests that no interrupt be delivered when the events | ||
1566 | * noted in the last-issued poll() call happen. Once this service returns, | ||
1567 | * the interrupt has been canceled; however, it is possible for the interrupt | ||
1568 | * to be delivered after this service is called but before it returns. | ||
1569 | * | ||
1570 | * @param devhdl Device handle of the device on which to cancel polling. | ||
1571 | * @return Zero if the poll was successfully canceled; otherwise, a negative | ||
1572 | * error code. | ||
1573 | */ | ||
1574 | int hv_dev_poll_cancel(int devhdl); | ||
1575 | |||
1576 | |||
1577 | /** Scatter-gather list for preada/pwritea calls. */ | ||
1578 | typedef struct | ||
1579 | #if CHIP_VA_WIDTH() <= 32 | ||
1580 | __attribute__ ((packed, aligned(4))) | ||
1581 | #endif | ||
1582 | { | ||
1583 | HV_PhysAddr pa; /**< Client physical address of the buffer segment. */ | ||
1584 | HV_PTE pte; /**< Page table entry describing the caching and location | ||
1585 | override characteristics of the buffer segment. Some | ||
1586 | drivers ignore this element and will require that | ||
1587 | the NOCACHE flag be set on their requests. */ | ||
1588 | __hv32 len; /**< Length of the buffer segment. */ | ||
1589 | } HV_SGL; | ||
1590 | |||
1591 | #define HV_SGL_MAXLEN 16 /**< Maximum number of entries in a scatter-gather | ||
1592 | list */ | ||
1593 | |||
1594 | /** Read data from a hypervisor device asynchronously. | ||
1595 | * | ||
1596 | * This service transfers data from a hypervisor device to a memory buffer. | ||
1597 | * When the service returns, the read has been scheduled. When the read | ||
1598 | * completes, an interrupt message will be delivered, and the buffer will | ||
1599 | * not be further modified by the driver. | ||
1600 | * | ||
1601 | * The number of possible outstanding asynchronous requests is defined by | ||
1602 | * each driver, but it is recommended that it be at least two requests | ||
1603 | * per tile per device. | ||
1604 | * | ||
1605 | * No ordering is guaranteed between synchronous and asynchronous requests, | ||
1606 | * even those issued on the same tile. | ||
1607 | * | ||
1608 | * The completion interrupt message could come directly, or via the downcall | ||
1609 | * (intctrl1) method, depending on what the tile is doing when the read | ||
1610 | * completes. Interrupts do not coalesce; one is delivered for each | ||
1611 | * asynchronous I/O request. Note that it is possible for the requested | ||
1612 | * interrupt to be delivered after this service is called but before it | ||
1613 | * returns. | ||
1614 | * | ||
1615 | * Devices may choose to support both the synchronous and asynchronous read | ||
1616 | * operations, only one of them, or neither of them. | ||
1617 | * | ||
1618 | * @param devhdl Device handle of the device to be read from. | ||
1619 | * @param flags Flags (HV_DEV_xxx). | ||
1620 | * @param sgl_len Number of elements in the scatter-gather list. | ||
1621 | * @param sgl Scatter-gather list describing the memory to which data will be | ||
1622 | * written. | ||
1623 | * @param offset Driver-dependent offset. For a random-access device, this is | ||
1624 | * often a byte offset from the beginning of the device; in other cases, | ||
1625 | * like on a control device, it may have a different meaning. | ||
1626 | * @param intarg Value which will be delivered as the intarg member of the | ||
1627 | * eventual interrupt message; the intdata member will be set to the | ||
1628 | * normal return value from the read request. | ||
1629 | * @return Zero if the read was successfully scheduled; otherwise, a negative | ||
1630 | * error code. Note that some drivers may choose to pre-validate | ||
1631 | * their arguments, and may thus detect certain device error | ||
1632 | * conditions at this time rather than when the completion notification | ||
1633 | * occurs, but this is not required. | ||
1634 | */ | ||
1635 | int hv_dev_preada(int devhdl, __hv32 flags, __hv32 sgl_len, | ||
1636 | HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg); | ||
1637 | |||
1638 | |||
1639 | /** Write data to a hypervisor device asynchronously. | ||
1640 | * | ||
1641 | * This service transfers data from a memory buffer to a hypervisor | ||
1642 | * device. When the service returns, the write has been scheduled. | ||
1643 | * When the write completes, an interrupt message will be delivered, | ||
1644 | * and the buffer may be overwritten by the client; the data may not | ||
1645 | * necessarily have been conveyed to the actual hardware I/O interface. | ||
1646 | * | ||
1647 | * The number of possible outstanding asynchronous requests is defined by | ||
1648 | * each driver, but it is recommended that it be at least two requests | ||
1649 | * per tile per device. | ||
1650 | * | ||
1651 | * No ordering is guaranteed between synchronous and asynchronous requests, | ||
1652 | * even those issued on the same tile. | ||
1653 | * | ||
1654 | * The completion interrupt message could come directly, or via the downcall | ||
1655 | * (intctrl1) method, depending on what the tile is doing when the read | ||
1656 | * completes. Interrupts do not coalesce; one is delivered for each | ||
1657 | * asynchronous I/O request. Note that it is possible for the requested | ||
1658 | * interrupt to be delivered after this service is called but before it | ||
1659 | * returns. | ||
1660 | * | ||
1661 | * Devices may choose to support both the synchronous and asynchronous write | ||
1662 | * operations, only one of them, or neither of them. | ||
1663 | * | ||
1664 | * @param devhdl Device handle of the device to be read from. | ||
1665 | * @param flags Flags (HV_DEV_xxx). | ||
1666 | * @param sgl_len Number of elements in the scatter-gather list. | ||
1667 | * @param sgl Scatter-gather list describing the memory from which data will be | ||
1668 | * read. | ||
1669 | * @param offset Driver-dependent offset. For a random-access device, this is | ||
1670 | * often a byte offset from the beginning of the device; in other cases, | ||
1671 | * like on a control device, it may have a different meaning. | ||
1672 | * @param intarg Value which will be delivered as the intarg member of the | ||
1673 | * eventual interrupt message; the intdata member will be set to the | ||
1674 | * normal return value from the write request. | ||
1675 | * @return Zero if the write was successfully scheduled; otherwise, a negative | ||
1676 | * error code. Note that some drivers may choose to pre-validate | ||
1677 | * their arguments, and may thus detect certain device error | ||
1678 | * conditions at this time rather than when the completion notification | ||
1679 | * occurs, but this is not required. | ||
1680 | */ | ||
1681 | int hv_dev_pwritea(int devhdl, __hv32 flags, __hv32 sgl_len, | ||
1682 | HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg); | ||
1683 | |||
1684 | |||
1685 | /** Define a pair of tile and ASID to identify a user process context. */ | ||
1686 | typedef struct | ||
1687 | { | ||
1688 | /** X coordinate, relative to supervisor's top-left coordinate */ | ||
1689 | unsigned int x:11; | ||
1690 | |||
1691 | /** Y coordinate, relative to supervisor's top-left coordinate */ | ||
1692 | unsigned int y:11; | ||
1693 | |||
1694 | /** ASID of the process on this x,y tile */ | ||
1695 | HV_ASID asid:10; | ||
1696 | } HV_Remote_ASID; | ||
1697 | |||
1698 | /** Flush cache and/or TLB state on remote tiles. | ||
1699 | * | ||
1700 | * @param cache_pa Client physical address to flush from cache (ignored if | ||
1701 | * the length encoded in cache_control is zero, or if | ||
1702 | * HV_FLUSH_EVICT_L2 is set, or if cache_cpumask is NULL). | ||
1703 | * @param cache_control This argument allows you to specify a length of | ||
1704 | * physical address space to flush (maximum HV_FLUSH_MAX_CACHE_LEN). | ||
1705 | * You can "or" in HV_FLUSH_EVICT_L2 to flush the whole L2 cache. | ||
1706 | * You can "or" in HV_FLUSH_EVICT_LI1 to flush the whole LII cache. | ||
1707 | * HV_FLUSH_ALL flushes all caches. | ||
1708 | * @param cache_cpumask Bitmask (in row-major order, supervisor-relative) of | ||
1709 | * tile indices to perform cache flush on. The low bit of the first | ||
1710 | * word corresponds to the tile at the upper left-hand corner of the | ||
1711 | * supervisor's rectangle. If passed as a NULL pointer, equivalent | ||
1712 | * to an empty bitmask. On chips which support hash-for-home caching, | ||
1713 | * if passed as -1, equivalent to a mask containing tiles which could | ||
1714 | * be doing hash-for-home caching. | ||
1715 | * @param tlb_va Virtual address to flush from TLB (ignored if | ||
1716 | * tlb_length is zero or tlb_cpumask is NULL). | ||
1717 | * @param tlb_length Number of bytes of data to flush from the TLB. | ||
1718 | * @param tlb_pgsize Page size to use for TLB flushes. | ||
1719 | * tlb_va and tlb_length need not be aligned to this size. | ||
1720 | * @param tlb_cpumask Bitmask for tlb flush, like cache_cpumask. | ||
1721 | * If passed as a NULL pointer, equivalent to an empty bitmask. | ||
1722 | * @param asids Pointer to an HV_Remote_ASID array of tile/ASID pairs to flush. | ||
1723 | * @param asidcount Number of HV_Remote_ASID entries in asids[]. | ||
1724 | * @return Zero for success, or else HV_EINVAL or HV_EFAULT for errors that | ||
1725 | * are detected while parsing the arguments. | ||
1726 | */ | ||
1727 | int hv_flush_remote(HV_PhysAddr cache_pa, unsigned long cache_control, | ||
1728 | unsigned long* cache_cpumask, | ||
1729 | HV_VirtAddr tlb_va, unsigned long tlb_length, | ||
1730 | unsigned long tlb_pgsize, unsigned long* tlb_cpumask, | ||
1731 | HV_Remote_ASID* asids, int asidcount); | ||
1732 | |||
1733 | /** Include in cache_control to ensure a flush of the entire L2. */ | ||
1734 | #define HV_FLUSH_EVICT_L2 (1UL << 31) | ||
1735 | |||
1736 | /** Include in cache_control to ensure a flush of the entire L1I. */ | ||
1737 | #define HV_FLUSH_EVICT_L1I (1UL << 30) | ||
1738 | |||
1739 | /** Maximum legal size to use for the "length" component of cache_control. */ | ||
1740 | #define HV_FLUSH_MAX_CACHE_LEN ((1UL << 30) - 1) | ||
1741 | |||
1742 | /** Use for cache_control to ensure a flush of all caches. */ | ||
1743 | #define HV_FLUSH_ALL -1UL | ||
1744 | |||
1745 | #else /* __ASSEMBLER__ */ | ||
1746 | |||
1747 | /** Include in cache_control to ensure a flush of the entire L2. */ | ||
1748 | #define HV_FLUSH_EVICT_L2 (1 << 31) | ||
1749 | |||
1750 | /** Include in cache_control to ensure a flush of the entire L1I. */ | ||
1751 | #define HV_FLUSH_EVICT_L1I (1 << 30) | ||
1752 | |||
1753 | /** Maximum legal size to use for the "length" component of cache_control. */ | ||
1754 | #define HV_FLUSH_MAX_CACHE_LEN ((1 << 30) - 1) | ||
1755 | |||
1756 | /** Use for cache_control to ensure a flush of all caches. */ | ||
1757 | #define HV_FLUSH_ALL -1 | ||
1758 | |||
1759 | #endif /* __ASSEMBLER__ */ | ||
1760 | |||
1761 | #ifndef __ASSEMBLER__ | ||
1762 | |||
1763 | /** Return a 64-bit value corresponding to the PTE if needed */ | ||
1764 | #define hv_pte_val(pte) ((pte).val) | ||
1765 | |||
1766 | /** Cast a 64-bit value to an HV_PTE */ | ||
1767 | #define hv_pte(val) ((HV_PTE) { val }) | ||
1768 | |||
1769 | #endif /* !__ASSEMBLER__ */ | ||
1770 | |||
1771 | |||
1772 | /** Bits in the size of an HV_PTE */ | ||
1773 | #define HV_LOG2_PTE_SIZE 3 | ||
1774 | |||
1775 | /** Size of an HV_PTE */ | ||
1776 | #define HV_PTE_SIZE (1 << HV_LOG2_PTE_SIZE) | ||
1777 | |||
1778 | |||
1779 | /* Bits in HV_PTE's low word. */ | ||
1780 | #define HV_PTE_INDEX_PRESENT 0 /**< PTE is valid */ | ||
1781 | #define HV_PTE_INDEX_MIGRATING 1 /**< Page is migrating */ | ||
1782 | #define HV_PTE_INDEX_CLIENT0 2 /**< Page client state 0 */ | ||
1783 | #define HV_PTE_INDEX_CLIENT1 3 /**< Page client state 1 */ | ||
1784 | #define HV_PTE_INDEX_NC 4 /**< L1$/L2$ incoherent with L3$ */ | ||
1785 | #define HV_PTE_INDEX_NO_ALLOC_L1 5 /**< Page is uncached in local L1$ */ | ||
1786 | #define HV_PTE_INDEX_NO_ALLOC_L2 6 /**< Page is uncached in local L2$ */ | ||
1787 | #define HV_PTE_INDEX_CACHED_PRIORITY 7 /**< Page is priority cached */ | ||
1788 | #define HV_PTE_INDEX_PAGE 8 /**< PTE describes a page */ | ||
1789 | #define HV_PTE_INDEX_GLOBAL 9 /**< Page is global */ | ||
1790 | #define HV_PTE_INDEX_USER 10 /**< Page is user-accessible */ | ||
1791 | #define HV_PTE_INDEX_ACCESSED 11 /**< Page has been accessed */ | ||
1792 | #define HV_PTE_INDEX_DIRTY 12 /**< Page has been written */ | ||
1793 | /* Bits 13-15 are reserved for | ||
1794 | future use. */ | ||
1795 | #define HV_PTE_INDEX_MODE 16 /**< Page mode; see HV_PTE_MODE_xxx */ | ||
1796 | #define HV_PTE_MODE_BITS 3 /**< Number of bits in mode */ | ||
1797 | /* Bit 19 is reserved for | ||
1798 | future use. */ | ||
1799 | #define HV_PTE_INDEX_LOTAR 20 /**< Page's LOTAR; must be high bits | ||
1800 | of word */ | ||
1801 | #define HV_PTE_LOTAR_BITS 12 /**< Number of bits in a LOTAR */ | ||
1802 | |||
1803 | /* Bits in HV_PTE's high word. */ | ||
1804 | #define HV_PTE_INDEX_READABLE 32 /**< Page is readable */ | ||
1805 | #define HV_PTE_INDEX_WRITABLE 33 /**< Page is writable */ | ||
1806 | #define HV_PTE_INDEX_EXECUTABLE 34 /**< Page is executable */ | ||
1807 | #define HV_PTE_INDEX_PTFN 35 /**< Page's PTFN; must be high bits | ||
1808 | of word */ | ||
1809 | #define HV_PTE_PTFN_BITS 29 /**< Number of bits in a PTFN */ | ||
1810 | |||
1811 | /** Position of the PFN field within the PTE (subset of the PTFN). */ | ||
1812 | #define HV_PTE_INDEX_PFN (HV_PTE_INDEX_PTFN + (HV_LOG2_PAGE_SIZE_SMALL - \ | ||
1813 | HV_LOG2_PAGE_TABLE_ALIGN)) | ||
1814 | |||
1815 | /** Length of the PFN field within the PTE (subset of the PTFN). */ | ||
1816 | #define HV_PTE_INDEX_PFN_BITS (HV_PTE_INDEX_PTFN_BITS - \ | ||
1817 | (HV_LOG2_PAGE_SIZE_SMALL - \ | ||
1818 | HV_LOG2_PAGE_TABLE_ALIGN)) | ||
1819 | |||
1820 | /* | ||
1821 | * Legal values for the PTE's mode field | ||
1822 | */ | ||
1823 | /** Data is not resident in any caches; loads and stores access memory | ||
1824 | * directly. | ||
1825 | */ | ||
1826 | #define HV_PTE_MODE_UNCACHED 1 | ||
1827 | |||
1828 | /** Data is resident in the tile's local L1 and/or L2 caches; if a load | ||
1829 | * or store misses there, it goes to memory. | ||
1830 | * | ||
1831 | * The copy in the local L1$/L2$ is not invalidated when the copy in | ||
1832 | * memory is changed. | ||
1833 | */ | ||
1834 | #define HV_PTE_MODE_CACHE_NO_L3 2 | ||
1835 | |||
1836 | /** Data is resident in the tile's local L1 and/or L2 caches. If a load | ||
1837 | * or store misses there, it goes to an L3 cache in a designated tile; | ||
1838 | * if it misses there, it goes to memory. | ||
1839 | * | ||
1840 | * If the NC bit is not set, the copy in the local L1$/L2$ is invalidated | ||
1841 | * when the copy in the remote L3$ is changed. Otherwise, such | ||
1842 | * invalidation will not occur. | ||
1843 | * | ||
1844 | * Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support | ||
1845 | * invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is | ||
1846 | * clear on such a chip, no copy is kept in the local L1$/L2$ in this mode. | ||
1847 | */ | ||
1848 | #define HV_PTE_MODE_CACHE_TILE_L3 3 | ||
1849 | |||
1850 | /** Data is resident in the tile's local L1 and/or L2 caches. If a load | ||
1851 | * or store misses there, it goes to an L3 cache in one of a set of | ||
1852 | * designated tiles; if it misses there, it goes to memory. Which tile | ||
1853 | * is chosen from the set depends upon a hash function applied to the | ||
1854 | * physical address. This mode is not supported on chips for which | ||
1855 | * CHIP_HAS_CBOX_HOME_MAP() is 0. | ||
1856 | * | ||
1857 | * If the NC bit is not set, the copy in the local L1$/L2$ is invalidated | ||
1858 | * when the copy in the remote L3$ is changed. Otherwise, such | ||
1859 | * invalidation will not occur. | ||
1860 | * | ||
1861 | * Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support | ||
1862 | * invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is | ||
1863 | * clear on such a chip, no copy is kept in the local L1$/L2$ in this mode. | ||
1864 | */ | ||
1865 | #define HV_PTE_MODE_CACHE_HASH_L3 4 | ||
1866 | |||
1867 | /** Data is not resident in memory; accesses are instead made to an I/O | ||
1868 | * device, whose tile coordinates are given by the PTE's LOTAR field. | ||
1869 | * This mode is only supported on chips for which CHIP_HAS_MMIO() is 1. | ||
1870 | * The EXECUTABLE bit may not be set in an MMIO PTE. | ||
1871 | */ | ||
1872 | #define HV_PTE_MODE_MMIO 5 | ||
1873 | |||
1874 | |||
1875 | /* C wants 1ULL so it is typed as __hv64, but the assembler needs just numbers. | ||
1876 | * The assembler can't handle shifts greater than 31, but treats them | ||
1877 | * as shifts mod 32, so assembler code must be aware of which word | ||
1878 | * the bit belongs in when using these macros. | ||
1879 | */ | ||
1880 | #ifdef __ASSEMBLER__ | ||
1881 | #define __HV_PTE_ONE 1 /**< One, for assembler */ | ||
1882 | #else | ||
1883 | #define __HV_PTE_ONE 1ULL /**< One, for C */ | ||
1884 | #endif | ||
1885 | |||
1886 | /** Is this PTE present? | ||
1887 | * | ||
1888 | * If this bit is set, this PTE represents a valid translation or level-2 | ||
1889 | * page table pointer. Otherwise, the page table does not contain a | ||
1890 | * translation for the subject virtual pages. | ||
1891 | * | ||
1892 | * If this bit is not set, the other bits in the PTE are not | ||
1893 | * interpreted by the hypervisor, and may contain any value. | ||
1894 | */ | ||
1895 | #define HV_PTE_PRESENT (__HV_PTE_ONE << HV_PTE_INDEX_PRESENT) | ||
1896 | |||
1897 | /** Does this PTE map a page? | ||
1898 | * | ||
1899 | * If this bit is set in the level-1 page table, the entry should be | ||
1900 | * interpreted as a level-2 page table entry mapping a large page. | ||
1901 | * | ||
1902 | * This bit should not be modified by the client while PRESENT is set, as | ||
1903 | * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits. | ||
1904 | * | ||
1905 | * In a level-2 page table, this bit is ignored and must be zero. | ||
1906 | */ | ||
1907 | #define HV_PTE_PAGE (__HV_PTE_ONE << HV_PTE_INDEX_PAGE) | ||
1908 | |||
1909 | /** Is this a global (non-ASID) mapping? | ||
1910 | * | ||
1911 | * If this bit is set, the translations established by this PTE will | ||
1912 | * not be flushed from the TLB by the hv_flush_asid() service; they | ||
1913 | * will be flushed by the hv_flush_page() or hv_flush_pages() services. | ||
1914 | * | ||
1915 | * Setting this bit for translations which are identical in all page | ||
1916 | * tables (for instance, code and data belonging to a client OS) can | ||
1917 | * be very beneficial, as it will reduce the number of TLB misses. | ||
1918 | * Note that, while it is not an error which will be detected by the | ||
1919 | * hypervisor, it is an extremely bad idea to set this bit for | ||
1920 | * translations which are _not_ identical in all page tables. | ||
1921 | * | ||
1922 | * This bit should not be modified by the client while PRESENT is set, as | ||
1923 | * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits. | ||
1924 | * | ||
1925 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
1926 | */ | ||
1927 | #define HV_PTE_GLOBAL (__HV_PTE_ONE << HV_PTE_INDEX_GLOBAL) | ||
1928 | |||
1929 | /** Is this mapping accessible to users? | ||
1930 | * | ||
1931 | * If this bit is set, code running at any PL will be permitted to | ||
1932 | * access the virtual addresses mapped by this PTE. Otherwise, only | ||
1933 | * code running at PL 1 or above will be allowed to do so. | ||
1934 | * | ||
1935 | * This bit should not be modified by the client while PRESENT is set, as | ||
1936 | * doing so may race with the hypervisor's update of ACCESSED and DIRTY bits. | ||
1937 | * | ||
1938 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
1939 | */ | ||
1940 | #define HV_PTE_USER (__HV_PTE_ONE << HV_PTE_INDEX_USER) | ||
1941 | |||
1942 | /** Has this mapping been accessed? | ||
1943 | * | ||
1944 | * This bit is set by the hypervisor when the memory described by the | ||
1945 | * translation is accessed for the first time. It is never cleared by | ||
1946 | * the hypervisor, but may be cleared by the client. After the bit | ||
1947 | * has been cleared, subsequent references are not guaranteed to set | ||
1948 | * it again until the translation has been flushed from the TLB. | ||
1949 | * | ||
1950 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
1951 | */ | ||
1952 | #define HV_PTE_ACCESSED (__HV_PTE_ONE << HV_PTE_INDEX_ACCESSED) | ||
1953 | |||
1954 | /** Is this mapping dirty? | ||
1955 | * | ||
1956 | * This bit is set by the hypervisor when the memory described by the | ||
1957 | * translation is written for the first time. It is never cleared by | ||
1958 | * the hypervisor, but may be cleared by the client. After the bit | ||
1959 | * has been cleared, subsequent references are not guaranteed to set | ||
1960 | * it again until the translation has been flushed from the TLB. | ||
1961 | * | ||
1962 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
1963 | */ | ||
1964 | #define HV_PTE_DIRTY (__HV_PTE_ONE << HV_PTE_INDEX_DIRTY) | ||
1965 | |||
1966 | /** Migrating bit in PTE. | ||
1967 | * | ||
1968 | * This bit is guaranteed not to be inspected or modified by the | ||
1969 | * hypervisor. The name is indicative of the suggested use by the client | ||
1970 | * to tag pages whose L3 cache is being migrated from one cpu to another. | ||
1971 | */ | ||
1972 | #define HV_PTE_MIGRATING (__HV_PTE_ONE << HV_PTE_INDEX_MIGRATING) | ||
1973 | |||
1974 | /** Client-private bit in PTE. | ||
1975 | * | ||
1976 | * This bit is guaranteed not to be inspected or modified by the | ||
1977 | * hypervisor. | ||
1978 | */ | ||
1979 | #define HV_PTE_CLIENT0 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT0) | ||
1980 | |||
1981 | /** Client-private bit in PTE. | ||
1982 | * | ||
1983 | * This bit is guaranteed not to be inspected or modified by the | ||
1984 | * hypervisor. | ||
1985 | */ | ||
1986 | #define HV_PTE_CLIENT1 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT1) | ||
1987 | |||
1988 | /** Non-coherent (NC) bit in PTE. | ||
1989 | * | ||
1990 | * If this bit is set, the mapping that is set up will be non-coherent | ||
1991 | * (also known as non-inclusive). This means that changes to the L3 | ||
1992 | * cache will not cause a local copy to be invalidated. It is generally | ||
1993 | * recommended only for read-only mappings. | ||
1994 | * | ||
1995 | * In level-1 PTEs, if the Page bit is clear, this bit determines how the | ||
1996 | * level-2 page table is accessed. | ||
1997 | */ | ||
1998 | #define HV_PTE_NC (__HV_PTE_ONE << HV_PTE_INDEX_NC) | ||
1999 | |||
2000 | /** Is this page prevented from filling the L1$? | ||
2001 | * | ||
2002 | * If this bit is set, the page described by the PTE will not be cached | ||
2003 | * the local cpu's L1 cache. | ||
2004 | * | ||
2005 | * If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip, | ||
2006 | * it is illegal to use this attribute, and may cause client termination. | ||
2007 | * | ||
2008 | * In level-1 PTEs, if the Page bit is clear, this bit | ||
2009 | * determines how the level-2 page table is accessed. | ||
2010 | */ | ||
2011 | #define HV_PTE_NO_ALLOC_L1 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L1) | ||
2012 | |||
2013 | /** Is this page prevented from filling the L2$? | ||
2014 | * | ||
2015 | * If this bit is set, the page described by the PTE will not be cached | ||
2016 | * the local cpu's L2 cache. | ||
2017 | * | ||
2018 | * If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip, | ||
2019 | * it is illegal to use this attribute, and may cause client termination. | ||
2020 | * | ||
2021 | * In level-1 PTEs, if the Page bit is clear, this bit determines how the | ||
2022 | * level-2 page table is accessed. | ||
2023 | */ | ||
2024 | #define HV_PTE_NO_ALLOC_L2 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L2) | ||
2025 | |||
2026 | /** Is this a priority page? | ||
2027 | * | ||
2028 | * If this bit is set, the page described by the PTE will be given | ||
2029 | * priority in the cache. Normally this translates into allowing the | ||
2030 | * page to use only the "red" half of the cache. The client may wish to | ||
2031 | * then use the hv_set_caching service to specify that other pages which | ||
2032 | * alias this page will use only the "black" half of the cache. | ||
2033 | * | ||
2034 | * If the Cached Priority bit is clear, the hypervisor uses the | ||
2035 | * current hv_set_caching() value to choose how to cache the page. | ||
2036 | * | ||
2037 | * It is illegal to set the Cached Priority bit if the Non-Cached bit | ||
2038 | * is set and the Cached Remotely bit is clear, i.e. if requests to | ||
2039 | * the page map directly to memory. | ||
2040 | * | ||
2041 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
2042 | */ | ||
2043 | #define HV_PTE_CACHED_PRIORITY (__HV_PTE_ONE << \ | ||
2044 | HV_PTE_INDEX_CACHED_PRIORITY) | ||
2045 | |||
2046 | /** Is this a readable mapping? | ||
2047 | * | ||
2048 | * If this bit is set, code will be permitted to read from (e.g., | ||
2049 | * issue load instructions against) the virtual addresses mapped by | ||
2050 | * this PTE. | ||
2051 | * | ||
2052 | * It is illegal for this bit to be clear if the Writable bit is set. | ||
2053 | * | ||
2054 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
2055 | */ | ||
2056 | #define HV_PTE_READABLE (__HV_PTE_ONE << HV_PTE_INDEX_READABLE) | ||
2057 | |||
2058 | /** Is this a writable mapping? | ||
2059 | * | ||
2060 | * If this bit is set, code will be permitted to write to (e.g., issue | ||
2061 | * store instructions against) the virtual addresses mapped by this | ||
2062 | * PTE. | ||
2063 | * | ||
2064 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
2065 | */ | ||
2066 | #define HV_PTE_WRITABLE (__HV_PTE_ONE << HV_PTE_INDEX_WRITABLE) | ||
2067 | |||
2068 | /** Is this an executable mapping? | ||
2069 | * | ||
2070 | * If this bit is set, code will be permitted to execute from | ||
2071 | * (e.g., jump to) the virtual addresses mapped by this PTE. | ||
2072 | * | ||
2073 | * This bit applies to any processor on the tile, if there are more | ||
2074 | * than one. | ||
2075 | * | ||
2076 | * This bit is ignored in level-1 PTEs unless the Page bit is set. | ||
2077 | */ | ||
2078 | #define HV_PTE_EXECUTABLE (__HV_PTE_ONE << HV_PTE_INDEX_EXECUTABLE) | ||
2079 | |||
2080 | /** The width of a LOTAR's x or y bitfield. */ | ||
2081 | #define HV_LOTAR_WIDTH 11 | ||
2082 | |||
2083 | /** Converts an x,y pair to a LOTAR value. */ | ||
2084 | #define HV_XY_TO_LOTAR(x, y) ((HV_LOTAR)(((x) << HV_LOTAR_WIDTH) | (y))) | ||
2085 | |||
2086 | /** Extracts the X component of a lotar. */ | ||
2087 | #define HV_LOTAR_X(lotar) ((lotar) >> HV_LOTAR_WIDTH) | ||
2088 | |||
2089 | /** Extracts the Y component of a lotar. */ | ||
2090 | #define HV_LOTAR_Y(lotar) ((lotar) & ((1 << HV_LOTAR_WIDTH) - 1)) | ||
2091 | |||
2092 | #ifndef __ASSEMBLER__ | ||
2093 | |||
2094 | /** Define accessor functions for a PTE bit. */ | ||
2095 | #define _HV_BIT(name, bit) \ | ||
2096 | static __inline int \ | ||
2097 | hv_pte_get_##name(HV_PTE pte) \ | ||
2098 | { \ | ||
2099 | return (pte.val >> HV_PTE_INDEX_##bit) & 1; \ | ||
2100 | } \ | ||
2101 | \ | ||
2102 | static __inline HV_PTE \ | ||
2103 | hv_pte_set_##name(HV_PTE pte) \ | ||
2104 | { \ | ||
2105 | pte.val |= 1ULL << HV_PTE_INDEX_##bit; \ | ||
2106 | return pte; \ | ||
2107 | } \ | ||
2108 | \ | ||
2109 | static __inline HV_PTE \ | ||
2110 | hv_pte_clear_##name(HV_PTE pte) \ | ||
2111 | { \ | ||
2112 | pte.val &= ~(1ULL << HV_PTE_INDEX_##bit); \ | ||
2113 | return pte; \ | ||
2114 | } | ||
2115 | |||
2116 | /* Generate accessors to get, set, and clear various PTE flags. | ||
2117 | */ | ||
2118 | _HV_BIT(present, PRESENT) | ||
2119 | _HV_BIT(page, PAGE) | ||
2120 | _HV_BIT(client0, CLIENT0) | ||
2121 | _HV_BIT(client1, CLIENT1) | ||
2122 | _HV_BIT(migrating, MIGRATING) | ||
2123 | _HV_BIT(nc, NC) | ||
2124 | _HV_BIT(readable, READABLE) | ||
2125 | _HV_BIT(writable, WRITABLE) | ||
2126 | _HV_BIT(executable, EXECUTABLE) | ||
2127 | _HV_BIT(accessed, ACCESSED) | ||
2128 | _HV_BIT(dirty, DIRTY) | ||
2129 | _HV_BIT(no_alloc_l1, NO_ALLOC_L1) | ||
2130 | _HV_BIT(no_alloc_l2, NO_ALLOC_L2) | ||
2131 | _HV_BIT(cached_priority, CACHED_PRIORITY) | ||
2132 | _HV_BIT(global, GLOBAL) | ||
2133 | _HV_BIT(user, USER) | ||
2134 | |||
2135 | #undef _HV_BIT | ||
2136 | |||
2137 | /** Get the page mode from the PTE. | ||
2138 | * | ||
2139 | * This field generally determines whether and how accesses to the page | ||
2140 | * are cached; the HV_PTE_MODE_xxx symbols define the legal values for the | ||
2141 | * page mode. The NC, NO_ALLOC_L1, and NO_ALLOC_L2 bits modify this | ||
2142 | * general policy. | ||
2143 | */ | ||
2144 | static __inline unsigned int | ||
2145 | hv_pte_get_mode(const HV_PTE pte) | ||
2146 | { | ||
2147 | return (((__hv32) pte.val) >> HV_PTE_INDEX_MODE) & | ||
2148 | ((1 << HV_PTE_MODE_BITS) - 1); | ||
2149 | } | ||
2150 | |||
2151 | /** Set the page mode into a PTE. See hv_pte_get_mode. */ | ||
2152 | static __inline HV_PTE | ||
2153 | hv_pte_set_mode(HV_PTE pte, unsigned int val) | ||
2154 | { | ||
2155 | pte.val &= ~(((1ULL << HV_PTE_MODE_BITS) - 1) << HV_PTE_INDEX_MODE); | ||
2156 | pte.val |= val << HV_PTE_INDEX_MODE; | ||
2157 | return pte; | ||
2158 | } | ||
2159 | |||
2160 | /** Get the page frame number from the PTE. | ||
2161 | * | ||
2162 | * This field contains the upper bits of the CPA (client physical | ||
2163 | * address) of the target page; the complete CPA is this field with | ||
2164 | * HV_LOG2_PAGE_SIZE_SMALL zero bits appended to it. | ||
2165 | * | ||
2166 | * For PTEs in a level-1 page table where the Page bit is set, the | ||
2167 | * CPA must be aligned modulo the large page size. | ||
2168 | */ | ||
2169 | static __inline unsigned int | ||
2170 | hv_pte_get_pfn(const HV_PTE pte) | ||
2171 | { | ||
2172 | return pte.val >> HV_PTE_INDEX_PFN; | ||
2173 | } | ||
2174 | |||
2175 | |||
2176 | /** Set the page frame number into a PTE. See hv_pte_get_pfn. */ | ||
2177 | static __inline HV_PTE | ||
2178 | hv_pte_set_pfn(HV_PTE pte, unsigned int val) | ||
2179 | { | ||
2180 | /* | ||
2181 | * Note that the use of "PTFN" in the next line is intentional; we | ||
2182 | * don't want any garbage lower bits left in that field. | ||
2183 | */ | ||
2184 | pte.val &= ~(((1ULL << HV_PTE_PTFN_BITS) - 1) << HV_PTE_INDEX_PTFN); | ||
2185 | pte.val |= (__hv64) val << HV_PTE_INDEX_PFN; | ||
2186 | return pte; | ||
2187 | } | ||
2188 | |||
2189 | /** Get the page table frame number from the PTE. | ||
2190 | * | ||
2191 | * This field contains the upper bits of the CPA (client physical | ||
2192 | * address) of the target page table; the complete CPA is this field with | ||
2193 | * with HV_PAGE_TABLE_ALIGN zero bits appended to it. | ||
2194 | * | ||
2195 | * For PTEs in a level-1 page table when the Page bit is not set, the | ||
2196 | * CPA must be aligned modulo the sticter of HV_PAGE_TABLE_ALIGN and | ||
2197 | * the level-2 page table size. | ||
2198 | */ | ||
2199 | static __inline unsigned long | ||
2200 | hv_pte_get_ptfn(const HV_PTE pte) | ||
2201 | { | ||
2202 | return pte.val >> HV_PTE_INDEX_PTFN; | ||
2203 | } | ||
2204 | |||
2205 | |||
2206 | /** Set the page table frame number into a PTE. See hv_pte_get_ptfn. */ | ||
2207 | static __inline HV_PTE | ||
2208 | hv_pte_set_ptfn(HV_PTE pte, unsigned long val) | ||
2209 | { | ||
2210 | pte.val &= ~(((1ULL << HV_PTE_PTFN_BITS)-1) << HV_PTE_INDEX_PTFN); | ||
2211 | pte.val |= (__hv64) val << HV_PTE_INDEX_PTFN; | ||
2212 | return pte; | ||
2213 | } | ||
2214 | |||
2215 | |||
2216 | /** Get the remote tile caching this page. | ||
2217 | * | ||
2218 | * Specifies the remote tile which is providing the L3 cache for this page. | ||
2219 | * | ||
2220 | * This field is ignored unless the page mode is HV_PTE_MODE_CACHE_TILE_L3. | ||
2221 | * | ||
2222 | * In level-1 PTEs, if the Page bit is clear, this field determines how the | ||
2223 | * level-2 page table is accessed. | ||
2224 | */ | ||
2225 | static __inline unsigned int | ||
2226 | hv_pte_get_lotar(const HV_PTE pte) | ||
2227 | { | ||
2228 | unsigned int lotar = ((__hv32) pte.val) >> HV_PTE_INDEX_LOTAR; | ||
2229 | |||
2230 | return HV_XY_TO_LOTAR( (lotar >> (HV_PTE_LOTAR_BITS / 2)), | ||
2231 | (lotar & ((1 << (HV_PTE_LOTAR_BITS / 2)) - 1)) ); | ||
2232 | } | ||
2233 | |||
2234 | |||
2235 | /** Set the remote tile caching a page into a PTE. See hv_pte_get_lotar. */ | ||
2236 | static __inline HV_PTE | ||
2237 | hv_pte_set_lotar(HV_PTE pte, unsigned int val) | ||
2238 | { | ||
2239 | unsigned int x = HV_LOTAR_X(val); | ||
2240 | unsigned int y = HV_LOTAR_Y(val); | ||
2241 | |||
2242 | pte.val &= ~(((1ULL << HV_PTE_LOTAR_BITS)-1) << HV_PTE_INDEX_LOTAR); | ||
2243 | pte.val |= (x << (HV_PTE_INDEX_LOTAR + HV_PTE_LOTAR_BITS / 2)) | | ||
2244 | (y << HV_PTE_INDEX_LOTAR); | ||
2245 | return pte; | ||
2246 | } | ||
2247 | |||
2248 | #endif /* !__ASSEMBLER__ */ | ||
2249 | |||
2250 | /** Converts a client physical address to a pfn. */ | ||
2251 | #define HV_CPA_TO_PFN(p) ((p) >> HV_LOG2_PAGE_SIZE_SMALL) | ||
2252 | |||
2253 | /** Converts a pfn to a client physical address. */ | ||
2254 | #define HV_PFN_TO_CPA(p) (((HV_PhysAddr)(p)) << HV_LOG2_PAGE_SIZE_SMALL) | ||
2255 | |||
2256 | /** Converts a client physical address to a ptfn. */ | ||
2257 | #define HV_CPA_TO_PTFN(p) ((p) >> HV_LOG2_PAGE_TABLE_ALIGN) | ||
2258 | |||
2259 | /** Converts a ptfn to a client physical address. */ | ||
2260 | #define HV_PTFN_TO_CPA(p) (((HV_PhysAddr)(p)) << HV_LOG2_PAGE_TABLE_ALIGN) | ||
2261 | |||
2262 | /** Converts a ptfn to a pfn. */ | ||
2263 | #define HV_PTFN_TO_PFN(p) \ | ||
2264 | ((p) >> (HV_LOG2_PAGE_SIZE_SMALL - HV_LOG2_PAGE_TABLE_ALIGN)) | ||
2265 | |||
2266 | /** Converts a pfn to a ptfn. */ | ||
2267 | #define HV_PFN_TO_PTFN(p) \ | ||
2268 | ((p) << (HV_LOG2_PAGE_SIZE_SMALL - HV_LOG2_PAGE_TABLE_ALIGN)) | ||
2269 | |||
2270 | #if CHIP_VA_WIDTH() > 32 | ||
2271 | |||
2272 | /** Log number of HV_PTE entries in L0 page table */ | ||
2273 | #define HV_LOG2_L0_ENTRIES (CHIP_VA_WIDTH() - HV_LOG2_L1_SPAN) | ||
2274 | |||
2275 | /** Number of HV_PTE entries in L0 page table */ | ||
2276 | #define HV_L0_ENTRIES (1 << HV_LOG2_L0_ENTRIES) | ||
2277 | |||
2278 | /** Log size of L0 page table in bytes */ | ||
2279 | #define HV_LOG2_L0_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L0_ENTRIES) | ||
2280 | |||
2281 | /** Size of L0 page table in bytes */ | ||
2282 | #define HV_L0_SIZE (1 << HV_LOG2_L0_SIZE) | ||
2283 | |||
2284 | #ifdef __ASSEMBLER__ | ||
2285 | |||
2286 | /** Index in L0 for a specific VA */ | ||
2287 | #define HV_L0_INDEX(va) \ | ||
2288 | (((va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1)) | ||
2289 | |||
2290 | #else | ||
2291 | |||
2292 | /** Index in L1 for a specific VA */ | ||
2293 | #define HV_L0_INDEX(va) \ | ||
2294 | (((HV_VirtAddr)(va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1)) | ||
2295 | |||
2296 | #endif | ||
2297 | |||
2298 | #endif /* CHIP_VA_WIDTH() > 32 */ | ||
2299 | |||
2300 | /** Log number of HV_PTE entries in L1 page table */ | ||
2301 | #define HV_LOG2_L1_ENTRIES (HV_LOG2_L1_SPAN - HV_LOG2_PAGE_SIZE_LARGE) | ||
2302 | |||
2303 | /** Number of HV_PTE entries in L1 page table */ | ||
2304 | #define HV_L1_ENTRIES (1 << HV_LOG2_L1_ENTRIES) | ||
2305 | |||
2306 | /** Log size of L1 page table in bytes */ | ||
2307 | #define HV_LOG2_L1_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L1_ENTRIES) | ||
2308 | |||
2309 | /** Size of L1 page table in bytes */ | ||
2310 | #define HV_L1_SIZE (1 << HV_LOG2_L1_SIZE) | ||
2311 | |||
2312 | /** Log number of HV_PTE entries in level-2 page table */ | ||
2313 | #define HV_LOG2_L2_ENTRIES (HV_LOG2_PAGE_SIZE_LARGE - HV_LOG2_PAGE_SIZE_SMALL) | ||
2314 | |||
2315 | /** Number of HV_PTE entries in level-2 page table */ | ||
2316 | #define HV_L2_ENTRIES (1 << HV_LOG2_L2_ENTRIES) | ||
2317 | |||
2318 | /** Log size of level-2 page table in bytes */ | ||
2319 | #define HV_LOG2_L2_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L2_ENTRIES) | ||
2320 | |||
2321 | /** Size of level-2 page table in bytes */ | ||
2322 | #define HV_L2_SIZE (1 << HV_LOG2_L2_SIZE) | ||
2323 | |||
2324 | #ifdef __ASSEMBLER__ | ||
2325 | |||
2326 | #if CHIP_VA_WIDTH() > 32 | ||
2327 | |||
2328 | /** Index in L1 for a specific VA */ | ||
2329 | #define HV_L1_INDEX(va) \ | ||
2330 | (((va) >> HV_LOG2_PAGE_SIZE_LARGE) & (HV_L1_ENTRIES - 1)) | ||
2331 | |||
2332 | #else /* CHIP_VA_WIDTH() > 32 */ | ||
2333 | |||
2334 | /** Index in L1 for a specific VA */ | ||
2335 | #define HV_L1_INDEX(va) \ | ||
2336 | (((va) >> HV_LOG2_PAGE_SIZE_LARGE)) | ||
2337 | |||
2338 | #endif /* CHIP_VA_WIDTH() > 32 */ | ||
2339 | |||
2340 | /** Index in level-2 page table for a specific VA */ | ||
2341 | #define HV_L2_INDEX(va) \ | ||
2342 | (((va) >> HV_LOG2_PAGE_SIZE_SMALL) & (HV_L2_ENTRIES - 1)) | ||
2343 | |||
2344 | #else /* __ASSEMBLER __ */ | ||
2345 | |||
2346 | #if CHIP_VA_WIDTH() > 32 | ||
2347 | |||
2348 | /** Index in L1 for a specific VA */ | ||
2349 | #define HV_L1_INDEX(va) \ | ||
2350 | (((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_LARGE) & (HV_L1_ENTRIES - 1)) | ||
2351 | |||
2352 | #else /* CHIP_VA_WIDTH() > 32 */ | ||
2353 | |||
2354 | /** Index in L1 for a specific VA */ | ||
2355 | #define HV_L1_INDEX(va) \ | ||
2356 | (((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_LARGE)) | ||
2357 | |||
2358 | #endif /* CHIP_VA_WIDTH() > 32 */ | ||
2359 | |||
2360 | /** Index in level-2 page table for a specific VA */ | ||
2361 | #define HV_L2_INDEX(va) \ | ||
2362 | (((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_SMALL) & (HV_L2_ENTRIES - 1)) | ||
2363 | |||
2364 | #endif /* __ASSEMBLER __ */ | ||
2365 | |||
2366 | #endif /* _TILE_HV_H */ | ||