Path: blob/master/arch/tile/include/hv/hypervisor.h
10819 views
/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314/**15* @file hypervisor.h16* The hypervisor's public API.17*/1819#ifndef _TILE_HV_H20#define _TILE_HV_H2122#include <arch/chip.h>2324/* Linux builds want unsigned long constants, but assembler wants numbers */25#ifdef __ASSEMBLER__26/** One, for assembler */27#define __HV_SIZE_ONE 128#elif !defined(__tile__) && CHIP_VA_WIDTH() > 3229/** One, for 64-bit on host */30#define __HV_SIZE_ONE 1ULL31#else32/** One, for Linux */33#define __HV_SIZE_ONE 1UL34#endif3536/** The log2 of the span of a level-1 page table, in bytes.37*/38#define HV_LOG2_L1_SPAN 323940/** The span of a level-1 page table, in bytes.41*/42#define HV_L1_SPAN (__HV_SIZE_ONE << HV_LOG2_L1_SPAN)4344/** The log2 of the size of small pages, in bytes. This value should45* be verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).46*/47#define HV_LOG2_PAGE_SIZE_SMALL 164849/** The size of small pages, in bytes. This value should be verified50* at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).51*/52#define HV_PAGE_SIZE_SMALL (__HV_SIZE_ONE << HV_LOG2_PAGE_SIZE_SMALL)5354/** The log2 of the size of large pages, in bytes. This value should be55* verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).56*/57#define HV_LOG2_PAGE_SIZE_LARGE 245859/** The size of large pages, in bytes. This value should be verified60* at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).61*/62#define HV_PAGE_SIZE_LARGE (__HV_SIZE_ONE << HV_LOG2_PAGE_SIZE_LARGE)6364/** The log2 of the granularity at which page tables must be aligned;65* in other words, the CPA for a page table must have this many zero66* bits at the bottom of the address.67*/68#define HV_LOG2_PAGE_TABLE_ALIGN 116970/** The granularity at which page tables must be aligned.71*/72#define HV_PAGE_TABLE_ALIGN (__HV_SIZE_ONE << HV_LOG2_PAGE_TABLE_ALIGN)7374/** Normal start of hypervisor glue in client physical memory. */75#define HV_GLUE_START_CPA 0x100007677/** This much space is reserved at HV_GLUE_START_CPA78* for the hypervisor glue. The client program must start at79* some address higher than this, and in particular the address of80* its text section should be equal to zero modulo HV_PAGE_SIZE_LARGE81* so that relative offsets to the HV glue are correct.82*/83#define HV_GLUE_RESERVED_SIZE 0x100008485/** Each entry in the hv dispatch array takes this many bytes. */86#define HV_DISPATCH_ENTRY_SIZE 328788/** Version of the hypervisor interface defined by this file */89#define _HV_VERSION 119091/* Index into hypervisor interface dispatch code blocks.92*93* Hypervisor calls are invoked from user space by calling code94* at an address HV_BASE_ADDRESS + (index) * HV_DISPATCH_ENTRY_SIZE,95* where index is one of these enum values.96*97* Normally a supervisor is expected to produce a set of symbols98* starting at HV_BASE_ADDRESS that obey this convention, but a user99* program could call directly through function pointers if desired.100*101* These numbers are part of the binary API and will not be changed102* without updating HV_VERSION, which should be a rare event.103*/104105/** reserved. */106#define _HV_DISPATCH_RESERVED 0107108/** hv_init */109#define HV_DISPATCH_INIT 1110111/** hv_install_context */112#define HV_DISPATCH_INSTALL_CONTEXT 2113114/** hv_sysconf */115#define HV_DISPATCH_SYSCONF 3116117/** hv_get_rtc */118#define HV_DISPATCH_GET_RTC 4119120/** hv_set_rtc */121#define HV_DISPATCH_SET_RTC 5122123/** hv_flush_asid */124#define HV_DISPATCH_FLUSH_ASID 6125126/** hv_flush_page */127#define HV_DISPATCH_FLUSH_PAGE 7128129/** hv_flush_pages */130#define HV_DISPATCH_FLUSH_PAGES 8131132/** hv_restart */133#define HV_DISPATCH_RESTART 9134135/** hv_halt */136#define HV_DISPATCH_HALT 10137138/** hv_power_off */139#define HV_DISPATCH_POWER_OFF 11140141/** hv_inquire_physical */142#define HV_DISPATCH_INQUIRE_PHYSICAL 12143144/** hv_inquire_memory_controller */145#define HV_DISPATCH_INQUIRE_MEMORY_CONTROLLER 13146147/** hv_inquire_virtual */148#define HV_DISPATCH_INQUIRE_VIRTUAL 14149150/** hv_inquire_asid */151#define HV_DISPATCH_INQUIRE_ASID 15152153/** hv_nanosleep */154#define HV_DISPATCH_NANOSLEEP 16155156/** hv_console_read_if_ready */157#define HV_DISPATCH_CONSOLE_READ_IF_READY 17158159/** hv_console_write */160#define HV_DISPATCH_CONSOLE_WRITE 18161162/** hv_downcall_dispatch */163#define HV_DISPATCH_DOWNCALL_DISPATCH 19164165/** hv_inquire_topology */166#define HV_DISPATCH_INQUIRE_TOPOLOGY 20167168/** hv_fs_findfile */169#define HV_DISPATCH_FS_FINDFILE 21170171/** hv_fs_fstat */172#define HV_DISPATCH_FS_FSTAT 22173174/** hv_fs_pread */175#define HV_DISPATCH_FS_PREAD 23176177/** hv_physaddr_read64 */178#define HV_DISPATCH_PHYSADDR_READ64 24179180/** hv_physaddr_write64 */181#define HV_DISPATCH_PHYSADDR_WRITE64 25182183/** hv_get_command_line */184#define HV_DISPATCH_GET_COMMAND_LINE 26185186/** hv_set_caching */187#define HV_DISPATCH_SET_CACHING 27188189/** hv_bzero_page */190#define HV_DISPATCH_BZERO_PAGE 28191192/** hv_register_message_state */193#define HV_DISPATCH_REGISTER_MESSAGE_STATE 29194195/** hv_send_message */196#define HV_DISPATCH_SEND_MESSAGE 30197198/** hv_receive_message */199#define HV_DISPATCH_RECEIVE_MESSAGE 31200201/** hv_inquire_context */202#define HV_DISPATCH_INQUIRE_CONTEXT 32203204/** hv_start_all_tiles */205#define HV_DISPATCH_START_ALL_TILES 33206207/** hv_dev_open */208#define HV_DISPATCH_DEV_OPEN 34209210/** hv_dev_close */211#define HV_DISPATCH_DEV_CLOSE 35212213/** hv_dev_pread */214#define HV_DISPATCH_DEV_PREAD 36215216/** hv_dev_pwrite */217#define HV_DISPATCH_DEV_PWRITE 37218219/** hv_dev_poll */220#define HV_DISPATCH_DEV_POLL 38221222/** hv_dev_poll_cancel */223#define HV_DISPATCH_DEV_POLL_CANCEL 39224225/** hv_dev_preada */226#define HV_DISPATCH_DEV_PREADA 40227228/** hv_dev_pwritea */229#define HV_DISPATCH_DEV_PWRITEA 41230231/** hv_flush_remote */232#define HV_DISPATCH_FLUSH_REMOTE 42233234/** hv_console_putc */235#define HV_DISPATCH_CONSOLE_PUTC 43236237/** hv_inquire_tiles */238#define HV_DISPATCH_INQUIRE_TILES 44239240/** hv_confstr */241#define HV_DISPATCH_CONFSTR 45242243/** hv_reexec */244#define HV_DISPATCH_REEXEC 46245246/** hv_set_command_line */247#define HV_DISPATCH_SET_COMMAND_LINE 47248249#if !CHIP_HAS_IPI()250251/** hv_clear_intr */252#define HV_DISPATCH_CLEAR_INTR 48253254/** hv_enable_intr */255#define HV_DISPATCH_ENABLE_INTR 49256257/** hv_disable_intr */258#define HV_DISPATCH_DISABLE_INTR 50259260/** hv_raise_intr */261#define HV_DISPATCH_RAISE_INTR 51262263/** hv_trigger_ipi */264#define HV_DISPATCH_TRIGGER_IPI 52265266#endif /* !CHIP_HAS_IPI() */267268/** hv_store_mapping */269#define HV_DISPATCH_STORE_MAPPING 53270271/** hv_inquire_realpa */272#define HV_DISPATCH_INQUIRE_REALPA 54273274/** hv_flush_all */275#define HV_DISPATCH_FLUSH_ALL 55276277#if CHIP_HAS_IPI()278/** hv_get_ipi_pte */279#define HV_DISPATCH_GET_IPI_PTE 56280#endif281282/** One more than the largest dispatch value */283#define _HV_DISPATCH_END 57284285286#ifndef __ASSEMBLER__287288#ifdef __KERNEL__289#include <asm/types.h>290typedef u32 __hv32; /**< 32-bit value */291typedef u64 __hv64; /**< 64-bit value */292#else293#include <stdint.h>294typedef uint32_t __hv32; /**< 32-bit value */295typedef uint64_t __hv64; /**< 64-bit value */296#endif297298299/** Hypervisor physical address. */300typedef __hv64 HV_PhysAddr;301302#if CHIP_VA_WIDTH() > 32303/** Hypervisor virtual address. */304typedef __hv64 HV_VirtAddr;305#else306/** Hypervisor virtual address. */307typedef __hv32 HV_VirtAddr;308#endif /* CHIP_VA_WIDTH() > 32 */309310/** Hypervisor ASID. */311typedef unsigned int HV_ASID;312313/** Hypervisor tile location for a memory access314* ("location overridden target").315*/316typedef unsigned int HV_LOTAR;317318/** Hypervisor size of a page. */319typedef unsigned long HV_PageSize;320321/** A page table entry.322*/323typedef struct324{325__hv64 val; /**< Value of PTE */326} HV_PTE;327328/** Hypervisor error code. */329typedef int HV_Errno;330331#endif /* !__ASSEMBLER__ */332333#define HV_OK 0 /**< No error */334#define HV_EINVAL -801 /**< Invalid argument */335#define HV_ENODEV -802 /**< No such device */336#define HV_ENOENT -803 /**< No such file or directory */337#define HV_EBADF -804 /**< Bad file number */338#define HV_EFAULT -805 /**< Bad address */339#define HV_ERECIP -806 /**< Bad recipients */340#define HV_E2BIG -807 /**< Message too big */341#define HV_ENOTSUP -808 /**< Service not supported */342#define HV_EBUSY -809 /**< Device busy */343#define HV_ENOSYS -810 /**< Invalid syscall */344#define HV_EPERM -811 /**< No permission */345#define HV_ENOTREADY -812 /**< Device not ready */346#define HV_EIO -813 /**< I/O error */347#define HV_ENOMEM -814 /**< Out of memory */348#define HV_EAGAIN -815 /**< Try again */349350#define HV_ERR_MAX -801 /**< Largest HV error code */351#define HV_ERR_MIN -815 /**< Smallest HV error code */352353#ifndef __ASSEMBLER__354355/** Pass HV_VERSION to hv_init to request this version of the interface. */356typedef enum { HV_VERSION = _HV_VERSION } HV_VersionNumber;357358/** Initializes the hypervisor.359*360* @param interface_version_number The version of the hypervisor interface361* that this program expects, typically HV_VERSION.362* @param chip_num Architecture number of the chip the client was built for.363* @param chip_rev_num Revision number of the chip the client was built for.364*/365void hv_init(HV_VersionNumber interface_version_number,366int chip_num, int chip_rev_num);367368369/** Queries we can make for hv_sysconf().370*371* These numbers are part of the binary API and guaranteed not to change.372*/373typedef enum {374/** An invalid value; do not use. */375_HV_SYSCONF_RESERVED = 0,376377/** The length of the glue section containing the hv_ procs, in bytes. */378HV_SYSCONF_GLUE_SIZE = 1,379380/** The size of small pages, in bytes. */381HV_SYSCONF_PAGE_SIZE_SMALL = 2,382383/** The size of large pages, in bytes. */384HV_SYSCONF_PAGE_SIZE_LARGE = 3,385386/** Processor clock speed, in hertz. */387HV_SYSCONF_CPU_SPEED = 4,388389/** Processor temperature, in degrees Kelvin. The value390* HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees391* Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates392* that the temperature has hit an upper limit and is no longer being393* accurately tracked.394*/395HV_SYSCONF_CPU_TEMP = 5,396397/** Board temperature, in degrees Kelvin. The value398* HV_SYSCONF_TEMP_KTOC may be subtracted from this to get degrees399* Celsius. If that Celsius value is HV_SYSCONF_OVERTEMP, this indicates400* that the temperature has hit an upper limit and is no longer being401* accurately tracked.402*/403HV_SYSCONF_BOARD_TEMP = 6404405} HV_SysconfQuery;406407/** Offset to subtract from returned Kelvin temperature to get degrees408Celsius. */409#define HV_SYSCONF_TEMP_KTOC 273410411/** Pseudo-temperature value indicating that the temperature has412* pegged at its upper limit and is no longer accurate; note that this is413* the value after subtracting HV_SYSCONF_TEMP_KTOC. */414#define HV_SYSCONF_OVERTEMP 999415416/** Query a configuration value from the hypervisor.417* @param query Which value is requested (HV_SYSCONF_xxx).418* @return The requested value, or -1 the requested value is illegal or419* unavailable.420*/421long hv_sysconf(HV_SysconfQuery query);422423424/** Queries we can make for hv_confstr().425*426* These numbers are part of the binary API and guaranteed not to change.427*/428typedef enum {429/** An invalid value; do not use. */430_HV_CONFSTR_RESERVED = 0,431432/** Board part number. */433HV_CONFSTR_BOARD_PART_NUM = 1,434435/** Board serial number. */436HV_CONFSTR_BOARD_SERIAL_NUM = 2,437438/** Chip serial number. */439HV_CONFSTR_CHIP_SERIAL_NUM = 3,440441/** Board revision level. */442HV_CONFSTR_BOARD_REV = 4,443444/** Hypervisor software version. */445HV_CONFSTR_HV_SW_VER = 5,446447/** The name for this chip model. */448HV_CONFSTR_CHIP_MODEL = 6,449450/** Human-readable board description. */451HV_CONFSTR_BOARD_DESC = 7,452453/** Human-readable description of the hypervisor configuration. */454HV_CONFSTR_HV_CONFIG = 8,455456/** Human-readable version string for the boot image (for instance,457* who built it and when, what configuration file was used). */458HV_CONFSTR_HV_CONFIG_VER = 9,459460/** Mezzanine part number. */461HV_CONFSTR_MEZZ_PART_NUM = 10,462463/** Mezzanine serial number. */464HV_CONFSTR_MEZZ_SERIAL_NUM = 11,465466/** Mezzanine revision level. */467HV_CONFSTR_MEZZ_REV = 12,468469/** Human-readable mezzanine description. */470HV_CONFSTR_MEZZ_DESC = 13,471472/** Control path for the onboard network switch. */473HV_CONFSTR_SWITCH_CONTROL = 14,474475/** Chip revision level. */476HV_CONFSTR_CHIP_REV = 15477478} HV_ConfstrQuery;479480/** Query a configuration string from the hypervisor.481*482* @param query Identifier for the specific string to be retrieved483* (HV_CONFSTR_xxx).484* @param buf Buffer in which to place the string.485* @param len Length of the buffer.486* @return If query is valid, then the length of the corresponding string,487* including the trailing null; if this is greater than len, the string488* was truncated. If query is invalid, HV_EINVAL. If the specified489* buffer is not writable by the client, HV_EFAULT.490*/491int hv_confstr(HV_ConfstrQuery query, HV_VirtAddr buf, int len);492493/** Tile coordinate */494typedef struct495{496/** X coordinate, relative to supervisor's top-left coordinate */497int x;498499/** Y coordinate, relative to supervisor's top-left coordinate */500int y;501} HV_Coord;502503504#if CHIP_HAS_IPI()505506/** Get the PTE for sending an IPI to a particular tile.507*508* @param tile Tile which will receive the IPI.509* @param pl Indicates which IPI registers: 0 = IPI_0, 1 = IPI_1.510* @param pte Filled with resulting PTE.511* @result Zero if no error, non-zero for invalid parameters.512*/513int hv_get_ipi_pte(HV_Coord tile, int pl, HV_PTE* pte);514515#else /* !CHIP_HAS_IPI() */516517/** A set of interrupts. */518typedef __hv32 HV_IntrMask;519520/** The low interrupt numbers are reserved for use by the client in521* delivering IPIs. Any interrupt numbers higher than this value are522* reserved for use by HV device drivers. */523#define HV_MAX_IPI_INTERRUPT 7524525/** Enable a set of device interrupts.526*527* @param enab_mask Bitmap of interrupts to enable.528*/529void hv_enable_intr(HV_IntrMask enab_mask);530531/** Disable a set of device interrupts.532*533* @param disab_mask Bitmap of interrupts to disable.534*/535void hv_disable_intr(HV_IntrMask disab_mask);536537/** Clear a set of device interrupts.538*539* @param clear_mask Bitmap of interrupts to clear.540*/541void hv_clear_intr(HV_IntrMask clear_mask);542543/** Raise a set of device interrupts.544*545* @param raise_mask Bitmap of interrupts to raise.546*/547void hv_raise_intr(HV_IntrMask raise_mask);548549/** Trigger a one-shot interrupt on some tile550*551* @param tile Which tile to interrupt.552* @param interrupt Interrupt number to trigger; must be between 0 and553* HV_MAX_IPI_INTERRUPT.554* @return HV_OK on success, or a hypervisor error code.555*/556HV_Errno hv_trigger_ipi(HV_Coord tile, int interrupt);557558#endif /* !CHIP_HAS_IPI() */559560/** Store memory mapping in debug memory so that external debugger can read it.561* A maximum of 16 entries can be stored.562*563* @param va VA of memory that is mapped.564* @param len Length of mapped memory.565* @param pa PA of memory that is mapped.566* @return 0 on success, -1 if the maximum number of mappings is exceeded.567*/568int hv_store_mapping(HV_VirtAddr va, unsigned int len, HV_PhysAddr pa);569570/** Given a client PA and a length, return its real (HV) PA.571*572* @param cpa Client physical address.573* @param len Length of mapped memory.574* @return physical address, or -1 if cpa or len is not valid.575*/576HV_PhysAddr hv_inquire_realpa(HV_PhysAddr cpa, unsigned int len);577578/** RTC return flag for no RTC chip present.579*/580#define HV_RTC_NO_CHIP 0x1581582/** RTC return flag for low-voltage condition, indicating that battery had583* died and time read is unreliable.584*/585#define HV_RTC_LOW_VOLTAGE 0x2586587/** Date/Time of day */588typedef struct {589#if CHIP_WORD_SIZE() > 32590__hv64 tm_sec; /**< Seconds, 0-59 */591__hv64 tm_min; /**< Minutes, 0-59 */592__hv64 tm_hour; /**< Hours, 0-23 */593__hv64 tm_mday; /**< Day of month, 0-30 */594__hv64 tm_mon; /**< Month, 0-11 */595__hv64 tm_year; /**< Years since 1900, 0-199 */596__hv64 flags; /**< Return flags, 0 if no error */597#else598__hv32 tm_sec; /**< Seconds, 0-59 */599__hv32 tm_min; /**< Minutes, 0-59 */600__hv32 tm_hour; /**< Hours, 0-23 */601__hv32 tm_mday; /**< Day of month, 0-30 */602__hv32 tm_mon; /**< Month, 0-11 */603__hv32 tm_year; /**< Years since 1900, 0-199 */604__hv32 flags; /**< Return flags, 0 if no error */605#endif606} HV_RTCTime;607608/** Read the current time-of-day clock.609* @return HV_RTCTime of current time (GMT).610*/611HV_RTCTime hv_get_rtc(void);612613614/** Set the current time-of-day clock.615* @param time time to reset time-of-day to (GMT).616*/617void hv_set_rtc(HV_RTCTime time);618619/** Installs a context, comprising a page table and other attributes.620*621* Once this service completes, page_table will be used to translate622* subsequent virtual address references to physical memory.623*624* Installing a context does not cause an implicit TLB flush. Before625* reusing an ASID value for a different address space, the client is626* expected to flush old references from the TLB with hv_flush_asid().627* (Alternately, hv_flush_all() may be used to flush many ASIDs at once.)628* After invalidating a page table entry, changing its attributes, or629* changing its target CPA, the client is expected to flush old references630* from the TLB with hv_flush_page() or hv_flush_pages(). Making a631* previously invalid page valid does not require a flush.632*633* Specifying an invalid ASID, or an invalid CPA (client physical address)634* (either as page_table_pointer, or within the referenced table),635* or another page table data item documented as above as illegal may636* lead to client termination; since the validation of the table is637* done as needed, this may happen before the service returns, or at638* some later time, or never, depending upon the client's pattern of639* memory references. Page table entries which supply translations for640* invalid virtual addresses may result in client termination, or may641* be silently ignored. "Invalid" in this context means a value which642* was not provided to the client via the appropriate hv_inquire_* routine.643*644* To support changing the instruction VAs at the same time as645* installing the new page table, this call explicitly supports646* setting the "lr" register to a different address and then jumping647* directly to the hv_install_context() routine. In this case, the648* new page table does not need to contain any mapping for the649* hv_install_context address itself.650*651* @param page_table Root of the page table.652* @param access PTE providing info on how to read the page table. This653* value must be consistent between multiple tiles sharing a page table,654* and must also be consistent with any virtual mappings the client655* may be using to access the page table.656* @param asid HV_ASID the page table is to be used for.657* @param flags Context flags, denoting attributes or privileges of the658* current context (HV_CTX_xxx).659* @return Zero on success, or a hypervisor error code on failure.660*/661int hv_install_context(HV_PhysAddr page_table, HV_PTE access, HV_ASID asid,662__hv32 flags);663664#endif /* !__ASSEMBLER__ */665666#define HV_CTX_DIRECTIO 0x1 /**< Direct I/O requests are accepted from667PL0. */668669#ifndef __ASSEMBLER__670671/** Value returned from hv_inquire_context(). */672typedef struct673{674/** Physical address of page table */675HV_PhysAddr page_table;676677/** PTE which defines access method for top of page table */678HV_PTE access;679680/** ASID associated with this page table */681HV_ASID asid;682683/** Context flags */684__hv32 flags;685} HV_Context;686687/** Retrieve information about the currently installed context.688* @return The data passed to the last successful hv_install_context call.689*/690HV_Context hv_inquire_context(void);691692693/** Flushes all translations associated with the named address space694* identifier from the TLB and any other hypervisor data structures.695* Translations installed with the "global" bit are not flushed.696*697* Specifying an invalid ASID may lead to client termination. "Invalid"698* in this context means a value which was not provided to the client699* via <tt>hv_inquire_asid()</tt>.700*701* @param asid HV_ASID whose entries are to be flushed.702* @return Zero on success, or a hypervisor error code on failure.703*/704int hv_flush_asid(HV_ASID asid);705706707/** Flushes all translations associated with the named virtual address708* and page size from the TLB and other hypervisor data structures. Only709* pages visible to the current ASID are affected; note that this includes710* global pages in addition to pages specific to the current ASID.711*712* The supplied VA need not be aligned; it may be anywhere in the713* subject page.714*715* Specifying an invalid virtual address may lead to client termination,716* or may silently succeed. "Invalid" in this context means a value717* which was not provided to the client via hv_inquire_virtual.718*719* @param address Address of the page to flush.720* @param page_size Size of pages to assume.721* @return Zero on success, or a hypervisor error code on failure.722*/723int hv_flush_page(HV_VirtAddr address, HV_PageSize page_size);724725726/** Flushes all translations associated with the named virtual address range727* and page size from the TLB and other hypervisor data structures. Only728* pages visible to the current ASID are affected; note that this includes729* global pages in addition to pages specific to the current ASID.730*731* The supplied VA need not be aligned; it may be anywhere in the732* subject page.733*734* Specifying an invalid virtual address may lead to client termination,735* or may silently succeed. "Invalid" in this context means a value736* which was not provided to the client via hv_inquire_virtual.737*738* @param start Address to flush.739* @param page_size Size of pages to assume.740* @param size The number of bytes to flush. Any page in the range741* [start, start + size) will be flushed from the TLB.742* @return Zero on success, or a hypervisor error code on failure.743*/744int hv_flush_pages(HV_VirtAddr start, HV_PageSize page_size,745unsigned long size);746747748/** Flushes all non-global translations (if preserve_global is true),749* or absolutely all translations (if preserve_global is false).750*751* @param preserve_global Non-zero if we want to preserve "global" mappings.752* @return Zero on success, or a hypervisor error code on failure.753*/754int hv_flush_all(int preserve_global);755756757/** Restart machine with optional restart command and optional args.758* @param cmd Const pointer to command to restart with, or NULL759* @param args Const pointer to argument string to restart with, or NULL760*/761void hv_restart(HV_VirtAddr cmd, HV_VirtAddr args);762763764/** Halt machine. */765void hv_halt(void);766767768/** Power off machine. */769void hv_power_off(void);770771772/** Re-enter virtual-is-physical memory translation mode and restart773* execution at a given address.774* @param entry Client physical address at which to begin execution.775* @return A hypervisor error code on failure; if the operation is776* successful the call does not return.777*/778int hv_reexec(HV_PhysAddr entry);779780781/** Chip topology */782typedef struct783{784/** Relative coordinates of the querying tile */785HV_Coord coord;786787/** Width of the querying supervisor's tile rectangle. */788int width;789790/** Height of the querying supervisor's tile rectangle. */791int height;792793} HV_Topology;794795/** Returns information about the tile coordinate system.796*797* Each supervisor is given a rectangle of tiles it potentially controls.798* These tiles are labeled using a relative coordinate system with (0,0) as799* the upper left tile regardless of their physical location on the chip.800*801* This call returns both the size of that rectangle and the position802* within that rectangle of the querying tile.803*804* Not all tiles within that rectangle may be available to the supervisor;805* to get the precise set of available tiles, you must also call806* hv_inquire_tiles(HV_INQ_TILES_AVAIL, ...).807**/808HV_Topology hv_inquire_topology(void);809810/** Sets of tiles we can retrieve with hv_inquire_tiles().811*812* These numbers are part of the binary API and guaranteed not to change.813*/814typedef enum {815/** An invalid value; do not use. */816_HV_INQ_TILES_RESERVED = 0,817818/** All available tiles within the supervisor's tile rectangle. */819HV_INQ_TILES_AVAIL = 1,820821/** The set of tiles used for hash-for-home caching. */822HV_INQ_TILES_HFH_CACHE = 2,823824/** The set of tiles that can be legally used as a LOTAR for a PTE. */825HV_INQ_TILES_LOTAR = 3826} HV_InqTileSet;827828/** Returns specific information about various sets of tiles within the829* supervisor's tile rectangle.830*831* @param set Which set of tiles to retrieve.832* @param cpumask Pointer to a returned bitmask (in row-major order,833* supervisor-relative) of tiles. The low bit of the first word834* corresponds to the tile at the upper left-hand corner of the835* supervisor's rectangle. In order for the supervisor to know the836* buffer length to supply, it should first call hv_inquire_topology.837* @param length Number of bytes available for the returned bitmask.838**/839HV_Errno hv_inquire_tiles(HV_InqTileSet set, HV_VirtAddr cpumask, int length);840841842/** An identifier for a memory controller. Multiple memory controllers843* may be connected to one chip, and this uniquely identifies each one.844*/845typedef int HV_MemoryController;846847/** A range of physical memory. */848typedef struct849{850HV_PhysAddr start; /**< Starting address. */851__hv64 size; /**< Size in bytes. */852HV_MemoryController controller; /**< Which memory controller owns this. */853} HV_PhysAddrRange;854855/** Returns information about a range of physical memory.856*857* hv_inquire_physical() returns one of the ranges of client858* physical addresses which are available to this client.859*860* The first range is retrieved by specifying an idx of 0, and861* successive ranges are returned with subsequent idx values. Ranges862* are ordered by increasing start address (i.e., as idx increases,863* so does start), do not overlap, and do not touch (i.e., the864* available memory is described with the fewest possible ranges).865*866* If an out-of-range idx value is specified, the returned size will be zero.867* A client can count the number of ranges by increasing idx until the868* returned size is zero. There will always be at least one valid range.869*870* Some clients might not be prepared to deal with more than one871* physical address range; they still ought to call this routine and872* issue a warning message if they're given more than one range, on the873* theory that whoever configured the hypervisor to provide that memory874* should know that it's being wasted.875*/876HV_PhysAddrRange hv_inquire_physical(int idx);877878/** Possible DIMM types. */879typedef enum880{881NO_DIMM = 0, /**< No DIMM */882DDR2 = 1, /**< DDR2 */883DDR3 = 2 /**< DDR3 */884} HV_DIMM_Type;885886#ifdef __tilegx__887888/** Log2 of minimum DIMM bytes supported by the memory controller. */889#define HV_MSH_MIN_DIMM_SIZE_SHIFT 29890891/** Max number of DIMMs contained by one memory controller. */892#define HV_MSH_MAX_DIMMS 8893894#else895896/** Log2 of minimum DIMM bytes supported by the memory controller. */897#define HV_MSH_MIN_DIMM_SIZE_SHIFT 26898899/** Max number of DIMMs contained by one memory controller. */900#define HV_MSH_MAX_DIMMS 2901902#endif903904/** Number of bits to right-shift to get the DIMM type. */905#define HV_DIMM_TYPE_SHIFT 0906907/** Bits to mask to get the DIMM type. */908#define HV_DIMM_TYPE_MASK 0xf909910/** Number of bits to right-shift to get the DIMM size. */911#define HV_DIMM_SIZE_SHIFT 4912913/** Bits to mask to get the DIMM size. */914#define HV_DIMM_SIZE_MASK 0xf915916/** Memory controller information. */917typedef struct918{919HV_Coord coord; /**< Relative tile coordinates of the port used by a920specified tile to communicate with this controller. */921__hv64 speed; /**< Speed of this controller in bytes per second. */922} HV_MemoryControllerInfo;923924/** Returns information about a particular memory controller.925*926* hv_inquire_memory_controller(coord,idx) returns information about a927* particular controller. Two pieces of information are returned:928* - The relative coordinates of the port on the controller that the specified929* tile would use to contact it. The relative coordinates may lie930* outside the supervisor's rectangle, i.e. the controller may not931* be attached to a node managed by the querying node's supervisor.932* In particular note that x or y may be negative.933* - The speed of the memory controller. (This is a not-to-exceed value934* based on the raw hardware data rate, and may not be achievable in935* practice; it is provided to give clients information on the relative936* performance of the available controllers.)937*938* Clients should avoid calling this interface with invalid values.939* A client who does may be terminated.940* @param coord Tile for which to calculate the relative port position.941* @param controller Index of the controller; identical to value returned942* from other routines like hv_inquire_physical.943* @return Information about the controller.944*/945HV_MemoryControllerInfo hv_inquire_memory_controller(HV_Coord coord,946int controller);947948949/** A range of virtual memory. */950typedef struct951{952HV_VirtAddr start; /**< Starting address. */953__hv64 size; /**< Size in bytes. */954} HV_VirtAddrRange;955956/** Returns information about a range of virtual memory.957*958* hv_inquire_virtual() returns one of the ranges of client959* virtual addresses which are available to this client.960*961* The first range is retrieved by specifying an idx of 0, and962* successive ranges are returned with subsequent idx values. Ranges963* are ordered by increasing start address (i.e., as idx increases,964* so does start), do not overlap, and do not touch (i.e., the965* available memory is described with the fewest possible ranges).966*967* If an out-of-range idx value is specified, the returned size will be zero.968* A client can count the number of ranges by increasing idx until the969* returned size is zero. There will always be at least one valid range.970*971* Some clients may well have various virtual addresses hardwired972* into themselves; for instance, their instruction stream may973* have been compiled expecting to live at a particular address.974* Such clients should use this interface to verify they've been975* given the virtual address space they expect, and issue a (potentially976* fatal) warning message otherwise.977*978* Note that the returned size is a __hv64, not a __hv32, so it is979* possible to express a single range spanning the entire 32-bit980* address space.981*/982HV_VirtAddrRange hv_inquire_virtual(int idx);983984985/** A range of ASID values. */986typedef struct987{988HV_ASID start; /**< First ASID in the range. */989unsigned int size; /**< Number of ASIDs. Zero for an invalid range. */990} HV_ASIDRange;991992/** Returns information about a range of ASIDs.993*994* hv_inquire_asid() returns one of the ranges of address995* space identifiers which are available to this client.996*997* The first range is retrieved by specifying an idx of 0, and998* successive ranges are returned with subsequent idx values. Ranges999* are ordered by increasing start value (i.e., as idx increases,1000* so does start), do not overlap, and do not touch (i.e., the1001* available ASIDs are described with the fewest possible ranges).1002*1003* If an out-of-range idx value is specified, the returned size will be zero.1004* A client can count the number of ranges by increasing idx until the1005* returned size is zero. There will always be at least one valid range.1006*/1007HV_ASIDRange hv_inquire_asid(int idx);100810091010/** Waits for at least the specified number of nanoseconds then returns.1011*1012* NOTE: this deprecated function currently assumes a 750 MHz clock,1013* and is thus not generally suitable for use. New code should call1014* hv_sysconf(HV_SYSCONF_CPU_SPEED), compute a cycle count to wait for,1015* and delay by looping while checking the cycle counter SPR.1016*1017* @param nanosecs The number of nanoseconds to sleep.1018*/1019void hv_nanosleep(int nanosecs);102010211022/** Reads a character from the console without blocking.1023*1024* @return A value from 0-255 indicates the value successfully read.1025* A negative value means no value was ready.1026*/1027int hv_console_read_if_ready(void);102810291030/** Writes a character to the console, blocking if the console is busy.1031*1032* This call cannot fail. If the console is broken for some reason,1033* output will simply vanish.1034* @param byte Character to write.1035*/1036void hv_console_putc(int byte);103710381039/** Writes a string to the console, blocking if the console is busy.1040* @param bytes Pointer to characters to write.1041* @param len Number of characters to write.1042* @return Number of characters written, or HV_EFAULT if the buffer is invalid.1043*/1044int hv_console_write(HV_VirtAddr bytes, int len);104510461047/** Dispatch the next interrupt from the client downcall mechanism.1048*1049* The hypervisor uses downcalls to notify the client of asynchronous1050* events. Some of these events are hypervisor-created (like incoming1051* messages). Some are regular interrupts which initially occur in1052* the hypervisor, and are normally handled directly by the client;1053* when these occur in a client's interrupt critical section, they must1054* be delivered through the downcall mechanism.1055*1056* A downcall is initially delivered to the client as an INTCTRL_CL1057* interrupt, where CL is the client's PL. Upon entry to the INTCTRL_CL1058* vector, the client must immediately invoke the hv_downcall_dispatch1059* service. This service will not return; instead it will cause one of1060* the client's actual downcall-handling interrupt vectors to be entered.1061* The EX_CONTEXT registers in the client will be set so that when the1062* client irets, it will return to the code which was interrupted by the1063* INTCTRL_CL interrupt.1064*1065* Under some circumstances, the firing of INTCTRL_CL can race with1066* the lowering of a device interrupt. In such a case, the1067* hv_downcall_dispatch service may issue an iret instruction instead1068* of entering one of the client's actual downcall-handling interrupt1069* vectors. This will return execution to the location that was1070* interrupted by INTCTRL_CL.1071*1072* Any saving of registers should be done by the actual handling1073* vectors; no registers should be changed by the INTCTRL_CL handler.1074* In particular, the client should not use a jal instruction to invoke1075* the hv_downcall_dispatch service, as that would overwrite the client's1076* lr register. Note that the hv_downcall_dispatch service may overwrite1077* one or more of the client's system save registers.1078*1079* The client must not modify the INTCTRL_CL_STATUS SPR. The hypervisor1080* will set this register to cause a downcall to happen, and will clear1081* it when no further downcalls are pending.1082*1083* When a downcall vector is entered, the INTCTRL_CL interrupt will be1084* masked. When the client is done processing a downcall, and is ready1085* to accept another, it must unmask this interrupt; if more downcalls1086* are pending, this will cause the INTCTRL_CL vector to be reentered.1087* Currently the following interrupt vectors can be entered through a1088* downcall:1089*1090* INT_MESSAGE_RCV_DWNCL (hypervisor message available)1091* INT_DEV_INTR_DWNCL (device interrupt)1092* INT_DMATLB_MISS_DWNCL (DMA TLB miss)1093* INT_SNITLB_MISS_DWNCL (SNI TLB miss)1094* INT_DMATLB_ACCESS_DWNCL (DMA TLB access violation)1095*/1096void hv_downcall_dispatch(void);10971098#endif /* !__ASSEMBLER__ */10991100/** We use actual interrupt vectors which never occur (they're only there1101* to allow setting MPLs for related SPRs) for our downcall vectors.1102*/1103/** Message receive downcall interrupt vector */1104#define INT_MESSAGE_RCV_DWNCL INT_BOOT_ACCESS1105/** DMA TLB miss downcall interrupt vector */1106#define INT_DMATLB_MISS_DWNCL INT_DMA_ASID1107/** Static nework processor instruction TLB miss interrupt vector */1108#define INT_SNITLB_MISS_DWNCL INT_SNI_ASID1109/** DMA TLB access violation downcall interrupt vector */1110#define INT_DMATLB_ACCESS_DWNCL INT_DMA_CPL1111/** Device interrupt downcall interrupt vector */1112#define INT_DEV_INTR_DWNCL INT_WORLD_ACCESS11131114#ifndef __ASSEMBLER__11151116/** Requests the inode for a specific full pathname.1117*1118* Performs a lookup in the hypervisor filesystem for a given filename.1119* Multiple calls with the same filename will always return the same inode.1120* If there is no such filename, HV_ENOENT is returned.1121* A bad filename pointer may result in HV_EFAULT instead.1122*1123* @param filename Constant pointer to name of requested file1124* @return Inode of requested file1125*/1126int hv_fs_findfile(HV_VirtAddr filename);112711281129/** Data returned from an fstat request.1130* Note that this structure should be no more than 40 bytes in size so1131* that it can always be returned completely in registers.1132*/1133typedef struct1134{1135int size; /**< Size of file (or HV_Errno on error) */1136unsigned int flags; /**< Flags (see HV_FS_FSTAT_FLAGS) */1137} HV_FS_StatInfo;11381139/** Bitmask flags for fstat request */1140typedef enum1141{1142HV_FS_ISDIR = 0x0001 /**< Is the entry a directory? */1143} HV_FS_FSTAT_FLAGS;11441145/** Get stat information on a given file inode.1146*1147* Return information on the file with the given inode.1148*1149* IF the HV_FS_ISDIR bit is set, the "file" is a directory. Reading1150* it will return NUL-separated filenames (no directory part) relative1151* to the path to the inode of the directory "file". These can be1152* appended to the path to the directory "file" after a forward slash1153* to create additional filenames. Note that it is not required1154* that all valid paths be decomposable into valid parent directories;1155* a filesystem may validly have just a few files, none of which have1156* HV_FS_ISDIR set. However, if clients may wish to enumerate the1157* files in the filesystem, it is recommended to include all the1158* appropriate parent directory "files" to give a consistent view.1159*1160* An invalid file inode will cause an HV_EBADF error to be returned.1161*1162* @param inode The inode number of the query1163* @return An HV_FS_StatInfo structure1164*/1165HV_FS_StatInfo hv_fs_fstat(int inode);116611671168/** Read data from a specific hypervisor file.1169* On error, may return HV_EBADF for a bad inode or HV_EFAULT for a bad buf.1170* Reads near the end of the file will return fewer bytes than requested.1171* Reads at or beyond the end of a file will return zero.1172*1173* @param inode the hypervisor file to read1174* @param buf the buffer to read data into1175* @param length the number of bytes of data to read1176* @param offset the offset into the file to read the data from1177* @return number of bytes successfully read, or an HV_Errno code1178*/1179int hv_fs_pread(int inode, HV_VirtAddr buf, int length, int offset);118011811182/** Read a 64-bit word from the specified physical address.1183* The address must be 8-byte aligned.1184* Specifying an invalid physical address will lead to client termination.1185* @param addr The physical address to read1186* @param access The PTE describing how to read the memory1187* @return The 64-bit value read from the given address1188*/1189unsigned long long hv_physaddr_read64(HV_PhysAddr addr, HV_PTE access);119011911192/** Write a 64-bit word to the specified physical address.1193* The address must be 8-byte aligned.1194* Specifying an invalid physical address will lead to client termination.1195* @param addr The physical address to write1196* @param access The PTE that says how to write the memory1197* @param val The 64-bit value to write to the given address1198*/1199void hv_physaddr_write64(HV_PhysAddr addr, HV_PTE access,1200unsigned long long val);120112021203/** Get the value of the command-line for the supervisor, if any.1204* This will not include the filename of the booted supervisor, but may1205* include configured-in boot arguments or the hv_restart() arguments.1206* If the buffer is not long enough the hypervisor will NUL the first1207* character of the buffer but not write any other data.1208* @param buf The virtual address to write the command-line string to.1209* @param length The length of buf, in characters.1210* @return The actual length of the command line, including the trailing NUL1211* (may be larger than "length").1212*/1213int hv_get_command_line(HV_VirtAddr buf, int length);121412151216/** Set a new value for the command-line for the supervisor, which will1217* be returned from subsequent invocations of hv_get_command_line() on1218* this tile.1219* @param buf The virtual address to read the command-line string from.1220* @param length The length of buf, in characters; must be no more than1221* HV_COMMAND_LINE_LEN.1222* @return Zero if successful, or a hypervisor error code.1223*/1224HV_Errno hv_set_command_line(HV_VirtAddr buf, int length);12251226/** Maximum size of a command line passed to hv_set_command_line(); note1227* that a line returned from hv_get_command_line() could be larger than1228* this.*/1229#define HV_COMMAND_LINE_LEN 25612301231/** Tell the hypervisor how to cache non-priority pages1232* (its own as well as pages explicitly represented in page tables).1233* Normally these will be represented as red/black pages, but1234* when the supervisor starts to allocate "priority" pages in the PTE1235* the hypervisor will need to start marking those pages as (e.g.) "red"1236* and non-priority pages as either "black" (if they cache-alias1237* with the existing priority pages) or "red/black" (if they don't).1238* The bitmask provides information on which parts of the cache1239* have been used for pinned pages so far on this tile; if (1 << N)1240* appears in the bitmask, that indicates that a page has been marked1241* "priority" whose PFN equals N, mod 8.1242* @param bitmask A bitmap of priority page set values1243*/1244void hv_set_caching(unsigned int bitmask);124512461247/** Zero out a specified number of pages.1248* The va and size must both be multiples of 4096.1249* Caches are bypassed and memory is directly set to zero.1250* This API is implemented only in the magic hypervisor and is intended1251* to provide a performance boost to the minimal supervisor by1252* giving it a fast way to zero memory pages when allocating them.1253* @param va Virtual address where the page has been mapped1254* @param size Number of bytes (must be a page size multiple)1255*/1256void hv_bzero_page(HV_VirtAddr va, unsigned int size);125712581259/** State object for the hypervisor messaging subsystem. */1260typedef struct1261{1262#if CHIP_VA_WIDTH() > 321263__hv64 opaque[2]; /**< No user-serviceable parts inside */1264#else1265__hv32 opaque[2]; /**< No user-serviceable parts inside */1266#endif1267}1268HV_MsgState;12691270/** Register to receive incoming messages.1271*1272* This routine configures the current tile so that it can receive1273* incoming messages. It must be called before the client can receive1274* messages with the hv_receive_message routine, and must be called on1275* each tile which will receive messages.1276*1277* msgstate is the virtual address of a state object of type HV_MsgState.1278* Once the state is registered, the client must not read or write the1279* state object; doing so will cause undefined results.1280*1281* If this routine is called with msgstate set to 0, the client's message1282* state will be freed and it will no longer be able to receive messages.1283* Note that this may cause the loss of any as-yet-undelivered messages1284* for the client.1285*1286* If another client attempts to send a message to a client which has1287* not yet called hv_register_message_state, or which has freed its1288* message state, the message will not be delivered, as if the client1289* had insufficient buffering.1290*1291* This routine returns HV_OK if the registration was successful, and1292* HV_EINVAL if the supplied state object is unsuitable. Note that some1293* errors may not be detected during this routine, but might be detected1294* during a subsequent message delivery.1295* @param msgstate State object.1296**/1297HV_Errno hv_register_message_state(HV_MsgState* msgstate);12981299/** Possible message recipient states. */1300typedef enum1301{1302HV_TO_BE_SENT, /**< Not sent (not attempted, or recipient not ready) */1303HV_SENT, /**< Successfully sent */1304HV_BAD_RECIP /**< Bad recipient coordinates (permanent error) */1305} HV_Recip_State;13061307/** Message recipient. */1308typedef struct1309{1310/** X coordinate, relative to supervisor's top-left coordinate */1311unsigned int x:11;13121313/** Y coordinate, relative to supervisor's top-left coordinate */1314unsigned int y:11;13151316/** Status of this recipient */1317HV_Recip_State state:10;1318} HV_Recipient;13191320/** Send a message to a set of recipients.1321*1322* This routine sends a message to a set of recipients.1323*1324* recips is an array of HV_Recipient structures. Each specifies a tile,1325* and a message state; initially, it is expected that the state will1326* be set to HV_TO_BE_SENT. nrecip specifies the number of recipients1327* in the recips array.1328*1329* For each recipient whose state is HV_TO_BE_SENT, the hypervisor attempts1330* to send that tile the specified message. In order to successfully1331* receive the message, the receiver must be a valid tile to which the1332* sender has access, must not be the sending tile itself, and must have1333* sufficient free buffer space. (The hypervisor guarantees that each1334* tile which has called hv_register_message_state() will be able to1335* buffer one message from every other tile which can legally send to it;1336* more space may be provided but is not guaranteed.) If an invalid tile1337* is specified, the recipient's state is set to HV_BAD_RECIP; this is a1338* permanent delivery error. If the message is successfully delivered1339* to the recipient's buffer, the recipient's state is set to HV_SENT.1340* Otherwise, the recipient's state is unchanged. Message delivery is1341* synchronous; all attempts to send messages are completed before this1342* routine returns.1343*1344* If no permanent delivery errors were encountered, the routine returns1345* the number of messages successfully sent: that is, the number of1346* recipients whose states changed from HV_TO_BE_SENT to HV_SENT during1347* this operation. If any permanent delivery errors were encountered,1348* the routine returns HV_ERECIP. In the event of permanent delivery1349* errors, it may be the case that delivery was not attempted to all1350* recipients; if any messages were successfully delivered, however,1351* recipients' state values will be updated appropriately.1352*1353* It is explicitly legal to specify a recipient structure whose state1354* is not HV_TO_BE_SENT; such a recipient is ignored. One suggested way1355* of using hv_send_message to send a message to multiple tiles is to set1356* up a list of recipients, and then call the routine repeatedly with the1357* same list, each time accumulating the number of messages successfully1358* sent, until all messages are sent, a permanent error is encountered,1359* or the desired number of attempts have been made. When used in this1360* way, the routine will deliver each message no more than once to each1361* recipient.1362*1363* Note that a message being successfully delivered to the recipient's1364* buffer space does not guarantee that it is received by the recipient,1365* either immediately or at any time in the future; the recipient might1366* never call hv_receive_message, or could register a different state1367* buffer, losing the message.1368*1369* Specifying the same recipient more than once in the recipient list1370* is an error, which will not result in an error return but which may1371* or may not result in more than one message being delivered to the1372* recipient tile.1373*1374* buf and buflen specify the message to be sent. buf is a virtual address1375* which must be currently mapped in the client's page table; if not, the1376* routine returns HV_EFAULT. buflen must be greater than zero and less1377* than or equal to HV_MAX_MESSAGE_SIZE, and nrecip must be less than the1378* number of tiles to which the sender has access; if not, the routine1379* returns HV_EINVAL.1380* @param recips List of recipients.1381* @param nrecip Number of recipients.1382* @param buf Address of message data.1383* @param buflen Length of message data.1384**/1385int hv_send_message(HV_Recipient *recips, int nrecip,1386HV_VirtAddr buf, int buflen);13871388/** Maximum hypervisor message size, in bytes */1389#define HV_MAX_MESSAGE_SIZE 28139013911392/** Return value from hv_receive_message() */1393typedef struct1394{1395int msglen; /**< Message length in bytes, or an error code */1396__hv32 source; /**< Code identifying message sender (HV_MSG_xxx) */1397} HV_RcvMsgInfo;13981399#define HV_MSG_TILE 0x0 /**< Message source is another tile */1400#define HV_MSG_INTR 0x1 /**< Message source is a driver interrupt */14011402/** Receive a message.1403*1404* This routine retrieves a message from the client's incoming message1405* buffer.1406*1407* Multiple messages sent from a particular sending tile to a particular1408* receiving tile are received in the order that they were sent; however,1409* no ordering is guaranteed between messages sent by different tiles.1410*1411* Whenever the a client's message buffer is empty, the first message1412* subsequently received will cause the client's MESSAGE_RCV_DWNCL1413* interrupt vector to be invoked through the interrupt downcall mechanism1414* (see the description of the hv_downcall_dispatch() routine for details1415* on downcalls).1416*1417* Another message-available downcall will not occur until a call to1418* this routine is made when the message buffer is empty, and a message1419* subsequently arrives. Note that such a downcall could occur while1420* this routine is executing. If the calling code does not wish this1421* to happen, it is recommended that this routine be called with the1422* INTCTRL_1 interrupt masked, or inside an interrupt critical section.1423*1424* msgstate is the value previously passed to hv_register_message_state().1425* buf is the virtual address of the buffer into which the message will1426* be written; buflen is the length of the buffer.1427*1428* This routine returns an HV_RcvMsgInfo structure. The msglen member1429* of that structure is the length of the message received, zero if no1430* message is available, or HV_E2BIG if the message is too large for the1431* specified buffer. If the message is too large, it is not consumed,1432* and may be retrieved by a subsequent call to this routine specifying1433* a sufficiently large buffer. A buffer which is HV_MAX_MESSAGE_SIZE1434* bytes long is guaranteed to be able to receive any possible message.1435*1436* The source member of the HV_RcvMsgInfo structure describes the sender1437* of the message. For messages sent by another client tile via an1438* hv_send_message() call, this value is HV_MSG_TILE; for messages sent1439* as a result of a device interrupt, this value is HV_MSG_INTR.1440*/14411442HV_RcvMsgInfo hv_receive_message(HV_MsgState msgstate, HV_VirtAddr buf,1443int buflen);144414451446/** Start remaining tiles owned by this supervisor. Initially, only one tile1447* executes the client program; after it calls this service, the other tiles1448* are started. This allows the initial tile to do one-time configuration1449* of shared data structures without having to lock them against simultaneous1450* access.1451*/1452void hv_start_all_tiles(void);145314541455/** Open a hypervisor device.1456*1457* This service initializes an I/O device and its hypervisor driver software,1458* and makes it available for use. The open operation is per-device per-chip;1459* once it has been performed, the device handle returned may be used in other1460* device services calls made by any tile.1461*1462* @param name Name of the device. A base device name is just a text string1463* (say, "pcie"). If there is more than one instance of a device, the1464* base name is followed by a slash and a device number (say, "pcie/0").1465* Some devices may support further structure beneath those components;1466* most notably, devices which require control operations do so by1467* supporting reads and/or writes to a control device whose name1468* includes a trailing "/ctl" (say, "pcie/0/ctl").1469* @param flags Flags (HV_DEV_xxx).1470* @return A positive integer device handle, or a negative error code.1471*/1472int hv_dev_open(HV_VirtAddr name, __hv32 flags);147314741475/** Close a hypervisor device.1476*1477* This service uninitializes an I/O device and its hypervisor driver1478* software, and makes it unavailable for use. The close operation is1479* per-device per-chip; once it has been performed, the device is no longer1480* available. Normally there is no need to ever call the close service.1481*1482* @param devhdl Device handle of the device to be closed.1483* @return Zero if the close is successful, otherwise, a negative error code.1484*/1485int hv_dev_close(int devhdl);148614871488/** Read data from a hypervisor device synchronously.1489*1490* This service transfers data from a hypervisor device to a memory buffer.1491* When the service returns, the data has been written from the memory buffer,1492* and the buffer will not be further modified by the driver.1493*1494* No ordering is guaranteed between requests issued from different tiles.1495*1496* Devices may choose to support both the synchronous and asynchronous read1497* operations, only one of them, or neither of them.1498*1499* @param devhdl Device handle of the device to be read from.1500* @param flags Flags (HV_DEV_xxx).1501* @param va Virtual address of the target data buffer. This buffer must1502* be mapped in the currently installed page table; if not, HV_EFAULT1503* may be returned.1504* @param len Number of bytes to be transferred.1505* @param offset Driver-dependent offset. For a random-access device, this is1506* often a byte offset from the beginning of the device; in other cases,1507* like on a control device, it may have a different meaning.1508* @return A non-negative value if the read was at least partially successful;1509* otherwise, a negative error code. The precise interpretation of1510* the return value is driver-dependent, but many drivers will return1511* the number of bytes successfully transferred.1512*/1513int hv_dev_pread(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len,1514__hv64 offset);15151516#define HV_DEV_NB_EMPTY 0x1 /**< Don't block when no bytes of data can1517be transferred. */1518#define HV_DEV_NB_PARTIAL 0x2 /**< Don't block when some bytes, but not all1519of the requested bytes, can be1520transferred. */1521#define HV_DEV_NOCACHE 0x4 /**< The caller warrants that none of the1522cache lines which might contain data1523from the requested buffer are valid.1524Useful with asynchronous operations1525only. */15261527#define HV_DEV_ALLFLAGS (HV_DEV_NB_EMPTY | HV_DEV_NB_PARTIAL | \1528HV_DEV_NOCACHE) /**< All HV_DEV_xxx flags */15291530/** Write data to a hypervisor device synchronously.1531*1532* This service transfers data from a memory buffer to a hypervisor device.1533* When the service returns, the data has been read from the memory buffer,1534* and the buffer may be overwritten by the client; the data may not1535* necessarily have been conveyed to the actual hardware I/O interface.1536*1537* No ordering is guaranteed between requests issued from different tiles.1538*1539* Devices may choose to support both the synchronous and asynchronous write1540* operations, only one of them, or neither of them.1541*1542* @param devhdl Device handle of the device to be written to.1543* @param flags Flags (HV_DEV_xxx).1544* @param va Virtual address of the source data buffer. This buffer must1545* be mapped in the currently installed page table; if not, HV_EFAULT1546* may be returned.1547* @param len Number of bytes to be transferred.1548* @param offset Driver-dependent offset. For a random-access device, this is1549* often a byte offset from the beginning of the device; in other cases,1550* like on a control device, it may have a different meaning.1551* @return A non-negative value if the write was at least partially successful;1552* otherwise, a negative error code. The precise interpretation of1553* the return value is driver-dependent, but many drivers will return1554* the number of bytes successfully transferred.1555*/1556int hv_dev_pwrite(int devhdl, __hv32 flags, HV_VirtAddr va, __hv32 len,1557__hv64 offset);155815591560/** Interrupt arguments, used in the asynchronous I/O interfaces. */1561#if CHIP_VA_WIDTH() > 321562typedef __hv64 HV_IntArg;1563#else1564typedef __hv32 HV_IntArg;1565#endif15661567/** Interrupt messages are delivered via the mechanism as normal messages,1568* but have a message source of HV_DEV_INTR. The message is formatted1569* as an HV_IntrMsg structure.1570*/15711572typedef struct1573{1574HV_IntArg intarg; /**< Interrupt argument, passed to the poll/preada/pwritea1575services */1576HV_IntArg intdata; /**< Interrupt-specific interrupt data */1577} HV_IntrMsg;15781579/** Request an interrupt message when a device condition is satisfied.1580*1581* This service requests that an interrupt message be delivered to the1582* requesting tile when a device becomes readable or writable, or when any1583* data queued to the device via previous write operations from this tile1584* has been actually sent out on the hardware I/O interface. Devices may1585* choose to support any, all, or none of the available conditions.1586*1587* If multiple conditions are specified, only one message will be1588* delivered. If the event mask delivered to that interrupt handler1589* indicates that some of the conditions have not yet occurred, the1590* client must issue another poll() call if it wishes to wait for those1591* conditions.1592*1593* Only one poll may be outstanding per device handle per tile. If more than1594* one tile is polling on the same device and condition, they will all be1595* notified when it happens. Because of this, clients may not assume that1596* the condition signaled is necessarily still true when they request a1597* subsequent service; for instance, the readable data which caused the1598* poll call to interrupt may have been read by another tile in the interim.1599*1600* The notification interrupt message could come directly, or via the1601* downcall (intctrl1) method, depending on what the tile is doing1602* when the condition is satisfied. Note that it is possible for the1603* requested interrupt to be delivered after this service is called but1604* before it returns.1605*1606* @param devhdl Device handle of the device to be polled.1607* @param events Flags denoting the events which will cause the interrupt to1608* be delivered (HV_DEVPOLL_xxx).1609* @param intarg Value which will be delivered as the intarg member of the1610* eventual interrupt message; the intdata member will be set to a1611* mask of HV_DEVPOLL_xxx values indicating which conditions have been1612* satisifed.1613* @return Zero if the interrupt was successfully scheduled; otherwise, a1614* negative error code.1615*/1616int hv_dev_poll(int devhdl, __hv32 events, HV_IntArg intarg);16171618#define HV_DEVPOLL_READ 0x1 /**< Test device for readability */1619#define HV_DEVPOLL_WRITE 0x2 /**< Test device for writability */1620#define HV_DEVPOLL_FLUSH 0x4 /**< Test device for output drained */162116221623/** Cancel a request for an interrupt when a device event occurs.1624*1625* This service requests that no interrupt be delivered when the events1626* noted in the last-issued poll() call happen. Once this service returns,1627* the interrupt has been canceled; however, it is possible for the interrupt1628* to be delivered after this service is called but before it returns.1629*1630* @param devhdl Device handle of the device on which to cancel polling.1631* @return Zero if the poll was successfully canceled; otherwise, a negative1632* error code.1633*/1634int hv_dev_poll_cancel(int devhdl);163516361637/** Scatter-gather list for preada/pwritea calls. */1638typedef struct1639#if CHIP_VA_WIDTH() <= 321640__attribute__ ((packed, aligned(4)))1641#endif1642{1643HV_PhysAddr pa; /**< Client physical address of the buffer segment. */1644HV_PTE pte; /**< Page table entry describing the caching and location1645override characteristics of the buffer segment. Some1646drivers ignore this element and will require that1647the NOCACHE flag be set on their requests. */1648__hv32 len; /**< Length of the buffer segment. */1649} HV_SGL;16501651#define HV_SGL_MAXLEN 16 /**< Maximum number of entries in a scatter-gather1652list */16531654/** Read data from a hypervisor device asynchronously.1655*1656* This service transfers data from a hypervisor device to a memory buffer.1657* When the service returns, the read has been scheduled. When the read1658* completes, an interrupt message will be delivered, and the buffer will1659* not be further modified by the driver.1660*1661* The number of possible outstanding asynchronous requests is defined by1662* each driver, but it is recommended that it be at least two requests1663* per tile per device.1664*1665* No ordering is guaranteed between synchronous and asynchronous requests,1666* even those issued on the same tile.1667*1668* The completion interrupt message could come directly, or via the downcall1669* (intctrl1) method, depending on what the tile is doing when the read1670* completes. Interrupts do not coalesce; one is delivered for each1671* asynchronous I/O request. Note that it is possible for the requested1672* interrupt to be delivered after this service is called but before it1673* returns.1674*1675* Devices may choose to support both the synchronous and asynchronous read1676* operations, only one of them, or neither of them.1677*1678* @param devhdl Device handle of the device to be read from.1679* @param flags Flags (HV_DEV_xxx).1680* @param sgl_len Number of elements in the scatter-gather list.1681* @param sgl Scatter-gather list describing the memory to which data will be1682* written.1683* @param offset Driver-dependent offset. For a random-access device, this is1684* often a byte offset from the beginning of the device; in other cases,1685* like on a control device, it may have a different meaning.1686* @param intarg Value which will be delivered as the intarg member of the1687* eventual interrupt message; the intdata member will be set to the1688* normal return value from the read request.1689* @return Zero if the read was successfully scheduled; otherwise, a negative1690* error code. Note that some drivers may choose to pre-validate1691* their arguments, and may thus detect certain device error1692* conditions at this time rather than when the completion notification1693* occurs, but this is not required.1694*/1695int hv_dev_preada(int devhdl, __hv32 flags, __hv32 sgl_len,1696HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg);169716981699/** Write data to a hypervisor device asynchronously.1700*1701* This service transfers data from a memory buffer to a hypervisor1702* device. When the service returns, the write has been scheduled.1703* When the write completes, an interrupt message will be delivered,1704* and the buffer may be overwritten by the client; the data may not1705* necessarily have been conveyed to the actual hardware I/O interface.1706*1707* The number of possible outstanding asynchronous requests is defined by1708* each driver, but it is recommended that it be at least two requests1709* per tile per device.1710*1711* No ordering is guaranteed between synchronous and asynchronous requests,1712* even those issued on the same tile.1713*1714* The completion interrupt message could come directly, or via the downcall1715* (intctrl1) method, depending on what the tile is doing when the read1716* completes. Interrupts do not coalesce; one is delivered for each1717* asynchronous I/O request. Note that it is possible for the requested1718* interrupt to be delivered after this service is called but before it1719* returns.1720*1721* Devices may choose to support both the synchronous and asynchronous write1722* operations, only one of them, or neither of them.1723*1724* @param devhdl Device handle of the device to be read from.1725* @param flags Flags (HV_DEV_xxx).1726* @param sgl_len Number of elements in the scatter-gather list.1727* @param sgl Scatter-gather list describing the memory from which data will be1728* read.1729* @param offset Driver-dependent offset. For a random-access device, this is1730* often a byte offset from the beginning of the device; in other cases,1731* like on a control device, it may have a different meaning.1732* @param intarg Value which will be delivered as the intarg member of the1733* eventual interrupt message; the intdata member will be set to the1734* normal return value from the write request.1735* @return Zero if the write was successfully scheduled; otherwise, a negative1736* error code. Note that some drivers may choose to pre-validate1737* their arguments, and may thus detect certain device error1738* conditions at this time rather than when the completion notification1739* occurs, but this is not required.1740*/1741int hv_dev_pwritea(int devhdl, __hv32 flags, __hv32 sgl_len,1742HV_SGL sgl[/* sgl_len */], __hv64 offset, HV_IntArg intarg);174317441745/** Define a pair of tile and ASID to identify a user process context. */1746typedef struct1747{1748/** X coordinate, relative to supervisor's top-left coordinate */1749unsigned int x:11;17501751/** Y coordinate, relative to supervisor's top-left coordinate */1752unsigned int y:11;17531754/** ASID of the process on this x,y tile */1755HV_ASID asid:10;1756} HV_Remote_ASID;17571758/** Flush cache and/or TLB state on remote tiles.1759*1760* @param cache_pa Client physical address to flush from cache (ignored if1761* the length encoded in cache_control is zero, or if1762* HV_FLUSH_EVICT_L2 is set, or if cache_cpumask is NULL).1763* @param cache_control This argument allows you to specify a length of1764* physical address space to flush (maximum HV_FLUSH_MAX_CACHE_LEN).1765* You can "or" in HV_FLUSH_EVICT_L2 to flush the whole L2 cache.1766* You can "or" in HV_FLUSH_EVICT_L1I to flush the whole L1I cache.1767* HV_FLUSH_ALL flushes all caches.1768* @param cache_cpumask Bitmask (in row-major order, supervisor-relative) of1769* tile indices to perform cache flush on. The low bit of the first1770* word corresponds to the tile at the upper left-hand corner of the1771* supervisor's rectangle. If passed as a NULL pointer, equivalent1772* to an empty bitmask. On chips which support hash-for-home caching,1773* if passed as -1, equivalent to a mask containing tiles which could1774* be doing hash-for-home caching.1775* @param tlb_va Virtual address to flush from TLB (ignored if1776* tlb_length is zero or tlb_cpumask is NULL).1777* @param tlb_length Number of bytes of data to flush from the TLB.1778* @param tlb_pgsize Page size to use for TLB flushes.1779* tlb_va and tlb_length need not be aligned to this size.1780* @param tlb_cpumask Bitmask for tlb flush, like cache_cpumask.1781* If passed as a NULL pointer, equivalent to an empty bitmask.1782* @param asids Pointer to an HV_Remote_ASID array of tile/ASID pairs to flush.1783* @param asidcount Number of HV_Remote_ASID entries in asids[].1784* @return Zero for success, or else HV_EINVAL or HV_EFAULT for errors that1785* are detected while parsing the arguments.1786*/1787int hv_flush_remote(HV_PhysAddr cache_pa, unsigned long cache_control,1788unsigned long* cache_cpumask,1789HV_VirtAddr tlb_va, unsigned long tlb_length,1790unsigned long tlb_pgsize, unsigned long* tlb_cpumask,1791HV_Remote_ASID* asids, int asidcount);17921793/** Include in cache_control to ensure a flush of the entire L2. */1794#define HV_FLUSH_EVICT_L2 (1UL << 31)17951796/** Include in cache_control to ensure a flush of the entire L1I. */1797#define HV_FLUSH_EVICT_L1I (1UL << 30)17981799/** Maximum legal size to use for the "length" component of cache_control. */1800#define HV_FLUSH_MAX_CACHE_LEN ((1UL << 30) - 1)18011802/** Use for cache_control to ensure a flush of all caches. */1803#define HV_FLUSH_ALL -1UL18041805#else /* __ASSEMBLER__ */18061807/** Include in cache_control to ensure a flush of the entire L2. */1808#define HV_FLUSH_EVICT_L2 (1 << 31)18091810/** Include in cache_control to ensure a flush of the entire L1I. */1811#define HV_FLUSH_EVICT_L1I (1 << 30)18121813/** Maximum legal size to use for the "length" component of cache_control. */1814#define HV_FLUSH_MAX_CACHE_LEN ((1 << 30) - 1)18151816/** Use for cache_control to ensure a flush of all caches. */1817#define HV_FLUSH_ALL -118181819#endif /* __ASSEMBLER__ */18201821#ifndef __ASSEMBLER__18221823/** Return a 64-bit value corresponding to the PTE if needed */1824#define hv_pte_val(pte) ((pte).val)18251826/** Cast a 64-bit value to an HV_PTE */1827#define hv_pte(val) ((HV_PTE) { val })18281829#endif /* !__ASSEMBLER__ */183018311832/** Bits in the size of an HV_PTE */1833#define HV_LOG2_PTE_SIZE 318341835/** Size of an HV_PTE */1836#define HV_PTE_SIZE (1 << HV_LOG2_PTE_SIZE)183718381839/* Bits in HV_PTE's low word. */1840#define HV_PTE_INDEX_PRESENT 0 /**< PTE is valid */1841#define HV_PTE_INDEX_MIGRATING 1 /**< Page is migrating */1842#define HV_PTE_INDEX_CLIENT0 2 /**< Page client state 0 */1843#define HV_PTE_INDEX_CLIENT1 3 /**< Page client state 1 */1844#define HV_PTE_INDEX_NC 4 /**< L1$/L2$ incoherent with L3$ */1845#define HV_PTE_INDEX_NO_ALLOC_L1 5 /**< Page is uncached in local L1$ */1846#define HV_PTE_INDEX_NO_ALLOC_L2 6 /**< Page is uncached in local L2$ */1847#define HV_PTE_INDEX_CACHED_PRIORITY 7 /**< Page is priority cached */1848#define HV_PTE_INDEX_PAGE 8 /**< PTE describes a page */1849#define HV_PTE_INDEX_GLOBAL 9 /**< Page is global */1850#define HV_PTE_INDEX_USER 10 /**< Page is user-accessible */1851#define HV_PTE_INDEX_ACCESSED 11 /**< Page has been accessed */1852#define HV_PTE_INDEX_DIRTY 12 /**< Page has been written */1853/* Bits 13-15 are reserved for1854future use. */1855#define HV_PTE_INDEX_MODE 16 /**< Page mode; see HV_PTE_MODE_xxx */1856#define HV_PTE_MODE_BITS 3 /**< Number of bits in mode */1857/* Bit 19 is reserved for1858future use. */1859#define HV_PTE_INDEX_LOTAR 20 /**< Page's LOTAR; must be high bits1860of word */1861#define HV_PTE_LOTAR_BITS 12 /**< Number of bits in a LOTAR */18621863/* Bits in HV_PTE's high word. */1864#define HV_PTE_INDEX_READABLE 32 /**< Page is readable */1865#define HV_PTE_INDEX_WRITABLE 33 /**< Page is writable */1866#define HV_PTE_INDEX_EXECUTABLE 34 /**< Page is executable */1867#define HV_PTE_INDEX_PTFN 35 /**< Page's PTFN; must be high bits1868of word */1869#define HV_PTE_PTFN_BITS 29 /**< Number of bits in a PTFN */18701871/** Position of the PFN field within the PTE (subset of the PTFN). */1872#define HV_PTE_INDEX_PFN (HV_PTE_INDEX_PTFN + (HV_LOG2_PAGE_SIZE_SMALL - \1873HV_LOG2_PAGE_TABLE_ALIGN))18741875/** Length of the PFN field within the PTE (subset of the PTFN). */1876#define HV_PTE_INDEX_PFN_BITS (HV_PTE_INDEX_PTFN_BITS - \1877(HV_LOG2_PAGE_SIZE_SMALL - \1878HV_LOG2_PAGE_TABLE_ALIGN))18791880/*1881* Legal values for the PTE's mode field1882*/1883/** Data is not resident in any caches; loads and stores access memory1884* directly.1885*/1886#define HV_PTE_MODE_UNCACHED 118871888/** Data is resident in the tile's local L1 and/or L2 caches; if a load1889* or store misses there, it goes to memory.1890*1891* The copy in the local L1$/L2$ is not invalidated when the copy in1892* memory is changed.1893*/1894#define HV_PTE_MODE_CACHE_NO_L3 218951896/** Data is resident in the tile's local L1 and/or L2 caches. If a load1897* or store misses there, it goes to an L3 cache in a designated tile;1898* if it misses there, it goes to memory.1899*1900* If the NC bit is not set, the copy in the local L1$/L2$ is invalidated1901* when the copy in the remote L3$ is changed. Otherwise, such1902* invalidation will not occur.1903*1904* Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support1905* invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is1906* clear on such a chip, no copy is kept in the local L1$/L2$ in this mode.1907*/1908#define HV_PTE_MODE_CACHE_TILE_L3 319091910/** Data is resident in the tile's local L1 and/or L2 caches. If a load1911* or store misses there, it goes to an L3 cache in one of a set of1912* designated tiles; if it misses there, it goes to memory. Which tile1913* is chosen from the set depends upon a hash function applied to the1914* physical address. This mode is not supported on chips for which1915* CHIP_HAS_CBOX_HOME_MAP() is 0.1916*1917* If the NC bit is not set, the copy in the local L1$/L2$ is invalidated1918* when the copy in the remote L3$ is changed. Otherwise, such1919* invalidation will not occur.1920*1921* Chips for which CHIP_HAS_COHERENT_LOCAL_CACHE() is 0 do not support1922* invalidation from an L3$ to another tile's L1$/L2$. If the NC bit is1923* clear on such a chip, no copy is kept in the local L1$/L2$ in this mode.1924*/1925#define HV_PTE_MODE_CACHE_HASH_L3 419261927/** Data is not resident in memory; accesses are instead made to an I/O1928* device, whose tile coordinates are given by the PTE's LOTAR field.1929* This mode is only supported on chips for which CHIP_HAS_MMIO() is 1.1930* The EXECUTABLE bit may not be set in an MMIO PTE.1931*/1932#define HV_PTE_MODE_MMIO 5193319341935/* C wants 1ULL so it is typed as __hv64, but the assembler needs just numbers.1936* The assembler can't handle shifts greater than 31, but treats them1937* as shifts mod 32, so assembler code must be aware of which word1938* the bit belongs in when using these macros.1939*/1940#ifdef __ASSEMBLER__1941#define __HV_PTE_ONE 1 /**< One, for assembler */1942#else1943#define __HV_PTE_ONE 1ULL /**< One, for C */1944#endif19451946/** Is this PTE present?1947*1948* If this bit is set, this PTE represents a valid translation or level-21949* page table pointer. Otherwise, the page table does not contain a1950* translation for the subject virtual pages.1951*1952* If this bit is not set, the other bits in the PTE are not1953* interpreted by the hypervisor, and may contain any value.1954*/1955#define HV_PTE_PRESENT (__HV_PTE_ONE << HV_PTE_INDEX_PRESENT)19561957/** Does this PTE map a page?1958*1959* If this bit is set in the level-1 page table, the entry should be1960* interpreted as a level-2 page table entry mapping a large page.1961*1962* This bit should not be modified by the client while PRESENT is set, as1963* doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.1964*1965* In a level-2 page table, this bit is ignored and must be zero.1966*/1967#define HV_PTE_PAGE (__HV_PTE_ONE << HV_PTE_INDEX_PAGE)19681969/** Is this a global (non-ASID) mapping?1970*1971* If this bit is set, the translations established by this PTE will1972* not be flushed from the TLB by the hv_flush_asid() service; they1973* will be flushed by the hv_flush_page() or hv_flush_pages() services.1974*1975* Setting this bit for translations which are identical in all page1976* tables (for instance, code and data belonging to a client OS) can1977* be very beneficial, as it will reduce the number of TLB misses.1978* Note that, while it is not an error which will be detected by the1979* hypervisor, it is an extremely bad idea to set this bit for1980* translations which are _not_ identical in all page tables.1981*1982* This bit should not be modified by the client while PRESENT is set, as1983* doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.1984*1985* This bit is ignored in level-1 PTEs unless the Page bit is set.1986*/1987#define HV_PTE_GLOBAL (__HV_PTE_ONE << HV_PTE_INDEX_GLOBAL)19881989/** Is this mapping accessible to users?1990*1991* If this bit is set, code running at any PL will be permitted to1992* access the virtual addresses mapped by this PTE. Otherwise, only1993* code running at PL 1 or above will be allowed to do so.1994*1995* This bit should not be modified by the client while PRESENT is set, as1996* doing so may race with the hypervisor's update of ACCESSED and DIRTY bits.1997*1998* This bit is ignored in level-1 PTEs unless the Page bit is set.1999*/2000#define HV_PTE_USER (__HV_PTE_ONE << HV_PTE_INDEX_USER)20012002/** Has this mapping been accessed?2003*2004* This bit is set by the hypervisor when the memory described by the2005* translation is accessed for the first time. It is never cleared by2006* the hypervisor, but may be cleared by the client. After the bit2007* has been cleared, subsequent references are not guaranteed to set2008* it again until the translation has been flushed from the TLB.2009*2010* This bit is ignored in level-1 PTEs unless the Page bit is set.2011*/2012#define HV_PTE_ACCESSED (__HV_PTE_ONE << HV_PTE_INDEX_ACCESSED)20132014/** Is this mapping dirty?2015*2016* This bit is set by the hypervisor when the memory described by the2017* translation is written for the first time. It is never cleared by2018* the hypervisor, but may be cleared by the client. After the bit2019* has been cleared, subsequent references are not guaranteed to set2020* it again until the translation has been flushed from the TLB.2021*2022* This bit is ignored in level-1 PTEs unless the Page bit is set.2023*/2024#define HV_PTE_DIRTY (__HV_PTE_ONE << HV_PTE_INDEX_DIRTY)20252026/** Migrating bit in PTE.2027*2028* This bit is guaranteed not to be inspected or modified by the2029* hypervisor. The name is indicative of the suggested use by the client2030* to tag pages whose L3 cache is being migrated from one cpu to another.2031*/2032#define HV_PTE_MIGRATING (__HV_PTE_ONE << HV_PTE_INDEX_MIGRATING)20332034/** Client-private bit in PTE.2035*2036* This bit is guaranteed not to be inspected or modified by the2037* hypervisor.2038*/2039#define HV_PTE_CLIENT0 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT0)20402041/** Client-private bit in PTE.2042*2043* This bit is guaranteed not to be inspected or modified by the2044* hypervisor.2045*/2046#define HV_PTE_CLIENT1 (__HV_PTE_ONE << HV_PTE_INDEX_CLIENT1)20472048/** Non-coherent (NC) bit in PTE.2049*2050* If this bit is set, the mapping that is set up will be non-coherent2051* (also known as non-inclusive). This means that changes to the L32052* cache will not cause a local copy to be invalidated. It is generally2053* recommended only for read-only mappings.2054*2055* In level-1 PTEs, if the Page bit is clear, this bit determines how the2056* level-2 page table is accessed.2057*/2058#define HV_PTE_NC (__HV_PTE_ONE << HV_PTE_INDEX_NC)20592060/** Is this page prevented from filling the L1$?2061*2062* If this bit is set, the page described by the PTE will not be cached2063* the local cpu's L1 cache.2064*2065* If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip,2066* it is illegal to use this attribute, and may cause client termination.2067*2068* In level-1 PTEs, if the Page bit is clear, this bit2069* determines how the level-2 page table is accessed.2070*/2071#define HV_PTE_NO_ALLOC_L1 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L1)20722073/** Is this page prevented from filling the L2$?2074*2075* If this bit is set, the page described by the PTE will not be cached2076* the local cpu's L2 cache.2077*2078* If CHIP_HAS_NC_AND_NOALLOC_BITS() is not true in <chip.h> for this chip,2079* it is illegal to use this attribute, and may cause client termination.2080*2081* In level-1 PTEs, if the Page bit is clear, this bit determines how the2082* level-2 page table is accessed.2083*/2084#define HV_PTE_NO_ALLOC_L2 (__HV_PTE_ONE << HV_PTE_INDEX_NO_ALLOC_L2)20852086/** Is this a priority page?2087*2088* If this bit is set, the page described by the PTE will be given2089* priority in the cache. Normally this translates into allowing the2090* page to use only the "red" half of the cache. The client may wish to2091* then use the hv_set_caching service to specify that other pages which2092* alias this page will use only the "black" half of the cache.2093*2094* If the Cached Priority bit is clear, the hypervisor uses the2095* current hv_set_caching() value to choose how to cache the page.2096*2097* It is illegal to set the Cached Priority bit if the Non-Cached bit2098* is set and the Cached Remotely bit is clear, i.e. if requests to2099* the page map directly to memory.2100*2101* This bit is ignored in level-1 PTEs unless the Page bit is set.2102*/2103#define HV_PTE_CACHED_PRIORITY (__HV_PTE_ONE << \2104HV_PTE_INDEX_CACHED_PRIORITY)21052106/** Is this a readable mapping?2107*2108* If this bit is set, code will be permitted to read from (e.g.,2109* issue load instructions against) the virtual addresses mapped by2110* this PTE.2111*2112* It is illegal for this bit to be clear if the Writable bit is set.2113*2114* This bit is ignored in level-1 PTEs unless the Page bit is set.2115*/2116#define HV_PTE_READABLE (__HV_PTE_ONE << HV_PTE_INDEX_READABLE)21172118/** Is this a writable mapping?2119*2120* If this bit is set, code will be permitted to write to (e.g., issue2121* store instructions against) the virtual addresses mapped by this2122* PTE.2123*2124* This bit is ignored in level-1 PTEs unless the Page bit is set.2125*/2126#define HV_PTE_WRITABLE (__HV_PTE_ONE << HV_PTE_INDEX_WRITABLE)21272128/** Is this an executable mapping?2129*2130* If this bit is set, code will be permitted to execute from2131* (e.g., jump to) the virtual addresses mapped by this PTE.2132*2133* This bit applies to any processor on the tile, if there are more2134* than one.2135*2136* This bit is ignored in level-1 PTEs unless the Page bit is set.2137*/2138#define HV_PTE_EXECUTABLE (__HV_PTE_ONE << HV_PTE_INDEX_EXECUTABLE)21392140/** The width of a LOTAR's x or y bitfield. */2141#define HV_LOTAR_WIDTH 1121422143/** Converts an x,y pair to a LOTAR value. */2144#define HV_XY_TO_LOTAR(x, y) ((HV_LOTAR)(((x) << HV_LOTAR_WIDTH) | (y)))21452146/** Extracts the X component of a lotar. */2147#define HV_LOTAR_X(lotar) ((lotar) >> HV_LOTAR_WIDTH)21482149/** Extracts the Y component of a lotar. */2150#define HV_LOTAR_Y(lotar) ((lotar) & ((1 << HV_LOTAR_WIDTH) - 1))21512152#ifndef __ASSEMBLER__21532154/** Define accessor functions for a PTE bit. */2155#define _HV_BIT(name, bit) \2156static __inline int \2157hv_pte_get_##name(HV_PTE pte) \2158{ \2159return (pte.val >> HV_PTE_INDEX_##bit) & 1; \2160} \2161\2162static __inline HV_PTE \2163hv_pte_set_##name(HV_PTE pte) \2164{ \2165pte.val |= 1ULL << HV_PTE_INDEX_##bit; \2166return pte; \2167} \2168\2169static __inline HV_PTE \2170hv_pte_clear_##name(HV_PTE pte) \2171{ \2172pte.val &= ~(1ULL << HV_PTE_INDEX_##bit); \2173return pte; \2174}21752176/* Generate accessors to get, set, and clear various PTE flags.2177*/2178_HV_BIT(present, PRESENT)2179_HV_BIT(page, PAGE)2180_HV_BIT(client0, CLIENT0)2181_HV_BIT(client1, CLIENT1)2182_HV_BIT(migrating, MIGRATING)2183_HV_BIT(nc, NC)2184_HV_BIT(readable, READABLE)2185_HV_BIT(writable, WRITABLE)2186_HV_BIT(executable, EXECUTABLE)2187_HV_BIT(accessed, ACCESSED)2188_HV_BIT(dirty, DIRTY)2189_HV_BIT(no_alloc_l1, NO_ALLOC_L1)2190_HV_BIT(no_alloc_l2, NO_ALLOC_L2)2191_HV_BIT(cached_priority, CACHED_PRIORITY)2192_HV_BIT(global, GLOBAL)2193_HV_BIT(user, USER)21942195#undef _HV_BIT21962197/** Get the page mode from the PTE.2198*2199* This field generally determines whether and how accesses to the page2200* are cached; the HV_PTE_MODE_xxx symbols define the legal values for the2201* page mode. The NC, NO_ALLOC_L1, and NO_ALLOC_L2 bits modify this2202* general policy.2203*/2204static __inline unsigned int2205hv_pte_get_mode(const HV_PTE pte)2206{2207return (((__hv32) pte.val) >> HV_PTE_INDEX_MODE) &2208((1 << HV_PTE_MODE_BITS) - 1);2209}22102211/** Set the page mode into a PTE. See hv_pte_get_mode. */2212static __inline HV_PTE2213hv_pte_set_mode(HV_PTE pte, unsigned int val)2214{2215pte.val &= ~(((1ULL << HV_PTE_MODE_BITS) - 1) << HV_PTE_INDEX_MODE);2216pte.val |= val << HV_PTE_INDEX_MODE;2217return pte;2218}22192220/** Get the page frame number from the PTE.2221*2222* This field contains the upper bits of the CPA (client physical2223* address) of the target page; the complete CPA is this field with2224* HV_LOG2_PAGE_SIZE_SMALL zero bits appended to it.2225*2226* For PTEs in a level-1 page table where the Page bit is set, the2227* CPA must be aligned modulo the large page size.2228*/2229static __inline unsigned int2230hv_pte_get_pfn(const HV_PTE pte)2231{2232return pte.val >> HV_PTE_INDEX_PFN;2233}223422352236/** Set the page frame number into a PTE. See hv_pte_get_pfn. */2237static __inline HV_PTE2238hv_pte_set_pfn(HV_PTE pte, unsigned int val)2239{2240/*2241* Note that the use of "PTFN" in the next line is intentional; we2242* don't want any garbage lower bits left in that field.2243*/2244pte.val &= ~(((1ULL << HV_PTE_PTFN_BITS) - 1) << HV_PTE_INDEX_PTFN);2245pte.val |= (__hv64) val << HV_PTE_INDEX_PFN;2246return pte;2247}22482249/** Get the page table frame number from the PTE.2250*2251* This field contains the upper bits of the CPA (client physical2252* address) of the target page table; the complete CPA is this field with2253* with HV_PAGE_TABLE_ALIGN zero bits appended to it.2254*2255* For PTEs in a level-1 page table when the Page bit is not set, the2256* CPA must be aligned modulo the sticter of HV_PAGE_TABLE_ALIGN and2257* the level-2 page table size.2258*/2259static __inline unsigned long2260hv_pte_get_ptfn(const HV_PTE pte)2261{2262return pte.val >> HV_PTE_INDEX_PTFN;2263}226422652266/** Set the page table frame number into a PTE. See hv_pte_get_ptfn. */2267static __inline HV_PTE2268hv_pte_set_ptfn(HV_PTE pte, unsigned long val)2269{2270pte.val &= ~(((1ULL << HV_PTE_PTFN_BITS)-1) << HV_PTE_INDEX_PTFN);2271pte.val |= (__hv64) val << HV_PTE_INDEX_PTFN;2272return pte;2273}227422752276/** Get the remote tile caching this page.2277*2278* Specifies the remote tile which is providing the L3 cache for this page.2279*2280* This field is ignored unless the page mode is HV_PTE_MODE_CACHE_TILE_L3.2281*2282* In level-1 PTEs, if the Page bit is clear, this field determines how the2283* level-2 page table is accessed.2284*/2285static __inline unsigned int2286hv_pte_get_lotar(const HV_PTE pte)2287{2288unsigned int lotar = ((__hv32) pte.val) >> HV_PTE_INDEX_LOTAR;22892290return HV_XY_TO_LOTAR( (lotar >> (HV_PTE_LOTAR_BITS / 2)),2291(lotar & ((1 << (HV_PTE_LOTAR_BITS / 2)) - 1)) );2292}229322942295/** Set the remote tile caching a page into a PTE. See hv_pte_get_lotar. */2296static __inline HV_PTE2297hv_pte_set_lotar(HV_PTE pte, unsigned int val)2298{2299unsigned int x = HV_LOTAR_X(val);2300unsigned int y = HV_LOTAR_Y(val);23012302pte.val &= ~(((1ULL << HV_PTE_LOTAR_BITS)-1) << HV_PTE_INDEX_LOTAR);2303pte.val |= (x << (HV_PTE_INDEX_LOTAR + HV_PTE_LOTAR_BITS / 2)) |2304(y << HV_PTE_INDEX_LOTAR);2305return pte;2306}23072308#endif /* !__ASSEMBLER__ */23092310/** Converts a client physical address to a pfn. */2311#define HV_CPA_TO_PFN(p) ((p) >> HV_LOG2_PAGE_SIZE_SMALL)23122313/** Converts a pfn to a client physical address. */2314#define HV_PFN_TO_CPA(p) (((HV_PhysAddr)(p)) << HV_LOG2_PAGE_SIZE_SMALL)23152316/** Converts a client physical address to a ptfn. */2317#define HV_CPA_TO_PTFN(p) ((p) >> HV_LOG2_PAGE_TABLE_ALIGN)23182319/** Converts a ptfn to a client physical address. */2320#define HV_PTFN_TO_CPA(p) (((HV_PhysAddr)(p)) << HV_LOG2_PAGE_TABLE_ALIGN)23212322/** Converts a ptfn to a pfn. */2323#define HV_PTFN_TO_PFN(p) \2324((p) >> (HV_LOG2_PAGE_SIZE_SMALL - HV_LOG2_PAGE_TABLE_ALIGN))23252326/** Converts a pfn to a ptfn. */2327#define HV_PFN_TO_PTFN(p) \2328((p) << (HV_LOG2_PAGE_SIZE_SMALL - HV_LOG2_PAGE_TABLE_ALIGN))23292330#if CHIP_VA_WIDTH() > 3223312332/** Log number of HV_PTE entries in L0 page table */2333#define HV_LOG2_L0_ENTRIES (CHIP_VA_WIDTH() - HV_LOG2_L1_SPAN)23342335/** Number of HV_PTE entries in L0 page table */2336#define HV_L0_ENTRIES (1 << HV_LOG2_L0_ENTRIES)23372338/** Log size of L0 page table in bytes */2339#define HV_LOG2_L0_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L0_ENTRIES)23402341/** Size of L0 page table in bytes */2342#define HV_L0_SIZE (1 << HV_LOG2_L0_SIZE)23432344#ifdef __ASSEMBLER__23452346/** Index in L0 for a specific VA */2347#define HV_L0_INDEX(va) \2348(((va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1))23492350#else23512352/** Index in L1 for a specific VA */2353#define HV_L0_INDEX(va) \2354(((HV_VirtAddr)(va) >> HV_LOG2_L1_SPAN) & (HV_L0_ENTRIES - 1))23552356#endif23572358#endif /* CHIP_VA_WIDTH() > 32 */23592360/** Log number of HV_PTE entries in L1 page table */2361#define HV_LOG2_L1_ENTRIES (HV_LOG2_L1_SPAN - HV_LOG2_PAGE_SIZE_LARGE)23622363/** Number of HV_PTE entries in L1 page table */2364#define HV_L1_ENTRIES (1 << HV_LOG2_L1_ENTRIES)23652366/** Log size of L1 page table in bytes */2367#define HV_LOG2_L1_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L1_ENTRIES)23682369/** Size of L1 page table in bytes */2370#define HV_L1_SIZE (1 << HV_LOG2_L1_SIZE)23712372/** Log number of HV_PTE entries in level-2 page table */2373#define HV_LOG2_L2_ENTRIES (HV_LOG2_PAGE_SIZE_LARGE - HV_LOG2_PAGE_SIZE_SMALL)23742375/** Number of HV_PTE entries in level-2 page table */2376#define HV_L2_ENTRIES (1 << HV_LOG2_L2_ENTRIES)23772378/** Log size of level-2 page table in bytes */2379#define HV_LOG2_L2_SIZE (HV_LOG2_PTE_SIZE + HV_LOG2_L2_ENTRIES)23802381/** Size of level-2 page table in bytes */2382#define HV_L2_SIZE (1 << HV_LOG2_L2_SIZE)23832384#ifdef __ASSEMBLER__23852386#if CHIP_VA_WIDTH() > 3223872388/** Index in L1 for a specific VA */2389#define HV_L1_INDEX(va) \2390(((va) >> HV_LOG2_PAGE_SIZE_LARGE) & (HV_L1_ENTRIES - 1))23912392#else /* CHIP_VA_WIDTH() > 32 */23932394/** Index in L1 for a specific VA */2395#define HV_L1_INDEX(va) \2396(((va) >> HV_LOG2_PAGE_SIZE_LARGE))23972398#endif /* CHIP_VA_WIDTH() > 32 */23992400/** Index in level-2 page table for a specific VA */2401#define HV_L2_INDEX(va) \2402(((va) >> HV_LOG2_PAGE_SIZE_SMALL) & (HV_L2_ENTRIES - 1))24032404#else /* __ASSEMBLER __ */24052406#if CHIP_VA_WIDTH() > 3224072408/** Index in L1 for a specific VA */2409#define HV_L1_INDEX(va) \2410(((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_LARGE) & (HV_L1_ENTRIES - 1))24112412#else /* CHIP_VA_WIDTH() > 32 */24132414/** Index in L1 for a specific VA */2415#define HV_L1_INDEX(va) \2416(((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_LARGE))24172418#endif /* CHIP_VA_WIDTH() > 32 */24192420/** Index in level-2 page table for a specific VA */2421#define HV_L2_INDEX(va) \2422(((HV_VirtAddr)(va) >> HV_LOG2_PAGE_SIZE_SMALL) & (HV_L2_ENTRIES - 1))24232424#endif /* __ASSEMBLER __ */24252426#endif /* _TILE_HV_H */242724282429