hypervisor.h 91 KB

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