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