hal.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. #ifndef XTENSA_HAL_H
  2. #define XTENSA_HAL_H
  3. /*
  4. * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
  5. *
  6. * include/asm-xtensa/xtensa/hal.h -- contains a definition of the
  7. * Core HAL interface.
  8. *
  9. * All definitions in this header file are independent of any specific
  10. * Xtensa processor configuration. Thus an OS or other software can
  11. * include this header file and be compiled into configuration-
  12. * independent objects that can be distributed and eventually linked
  13. * to the HAL library (libhal.a) to create a configuration-specific
  14. * final executable.
  15. *
  16. * Certain definitions, however, are release-specific -- such as the
  17. * XTHAL_RELEASE_xxx macros (or additions made in later releases).
  18. *
  19. * This file is subject to the terms and conditions of the GNU General Public
  20. * License. See the file "COPYING" in the main directory of this archive
  21. * for more details.
  22. *
  23. * Copyright (C) 2002 Tensilica Inc.
  24. */
  25. /*----------------------------------------------------------------------
  26. Constant Definitions
  27. (shared with assembly)
  28. ----------------------------------------------------------------------*/
  29. /* Software release information (not configuration-specific!): */
  30. #define XTHAL_RELEASE_MAJOR 1050
  31. #define XTHAL_RELEASE_MINOR 0
  32. #define XTHAL_RELEASE_NAME "T1050.0-2002-08-06-eng0"
  33. #define XTHAL_RELEASE_INTERNAL "2002-08-06-eng0"
  34. #define XTHAL_REL_T1050 1
  35. #define XTHAL_REL_T1050_0 1
  36. #define XTHAL_REL_T1050_0_2002 1
  37. #define XTHAL_REL_T1050_0_2002_08 1
  38. #define XTHAL_REL_T1050_0_2002_08_06 1
  39. #define XTHAL_REL_T1050_0_2002_08_06_ENG0 1
  40. /* HAL version numbers (these names are for backward compatibility): */
  41. #define XTHAL_MAJOR_REV XTHAL_RELEASE_MAJOR
  42. #define XTHAL_MINOR_REV XTHAL_RELEASE_MINOR
  43. /*
  44. * A bit of software release history on values of XTHAL_{MAJOR,MINOR}_REV:
  45. *
  46. * Release MAJOR MINOR Comment
  47. * ======= ===== ===== =======
  48. * T1015.n n/a n/a (HAL not yet available)
  49. * T1020.{0,1,2} 0 1 (HAL beta)
  50. * T1020.{3,4} 0 2 First release.
  51. * T1020.n (n>4) 0 2 or >3 (TBD)
  52. * T1030.0 0 1 (HAL beta)
  53. * T1030.{1,2} 0 3 Equivalent to first release.
  54. * T1030.n (n>=3) 0 >= 3 (TBD)
  55. * T1040.n 1040 n Full CHAL available from T1040.2
  56. * T1050.n 1050 n Current release.
  57. *
  58. *
  59. * Note: there is a distinction between the software release with
  60. * which something is compiled (accessible using XTHAL_RELEASE_* macros)
  61. * and the software release with which the HAL library was compiled
  62. * (accessible using Xthal_release_* global variables). This
  63. * distinction is particularly relevant for vendors that distribute
  64. * configuration-independent binaries (eg. an OS), where their customer
  65. * might link it with a HAL of a different Xtensa software release.
  66. * In this case, it may be appropriate for the OS to verify at run-time
  67. * whether XTHAL_RELEASE_* and Xthal_release_* are compatible.
  68. * [Guidelines as to which release is compatible with which are not
  69. * currently provided explicitly, but might be inferred from reading
  70. * OSKit documentation for all releases -- compatibility is also highly
  71. * dependent on which HAL features are used. Each release is usually
  72. * backward compatible, with very few exceptions if any.]
  73. *
  74. * Notes:
  75. * Tornado 2.0 supported in T1020.3+, T1030.1+, and T1040.{0,1} only.
  76. * Tornado 2.0.2 supported in T1040.2+, and T1050.
  77. * Compile-time HAL port of NucleusPlus supported by T1040.2+ and T1050.
  78. */
  79. /*
  80. * Architectural limits, independent of configuration.
  81. * Note that these are ISA-defined limits, not micro-architecture implementation
  82. * limits enforced by the Xtensa Processor Generator (which may be stricter than
  83. * these below).
  84. */
  85. #define XTHAL_MAX_CPS 8 /* max number of coprocessors (0..7) */
  86. #define XTHAL_MAX_INTERRUPTS 32 /* max number of interrupts (0..31) */
  87. #define XTHAL_MAX_INTLEVELS 16 /* max number of interrupt levels (0..15) */
  88. /* (as of T1040, implementation limit is 7: 0..6) */
  89. #define XTHAL_MAX_TIMERS 4 /* max number of timers (CCOMPARE0..CCOMPARE3) */
  90. /* (as of T1040, implementation limit is 3: 0..2) */
  91. /* Misc: */
  92. #define XTHAL_LITTLEENDIAN 0
  93. #define XTHAL_BIGENDIAN 1
  94. /* Interrupt types: */
  95. #define XTHAL_INTTYPE_UNCONFIGURED 0
  96. #define XTHAL_INTTYPE_SOFTWARE 1
  97. #define XTHAL_INTTYPE_EXTERN_EDGE 2
  98. #define XTHAL_INTTYPE_EXTERN_LEVEL 3
  99. #define XTHAL_INTTYPE_TIMER 4
  100. #define XTHAL_INTTYPE_NMI 5
  101. #define XTHAL_MAX_INTTYPES 6 /* number of interrupt types */
  102. /* Timer related: */
  103. #define XTHAL_TIMER_UNCONFIGURED -1 /* Xthal_timer_interrupt[] value for non-existent timers */
  104. #define XTHAL_TIMER_UNASSIGNED XTHAL_TIMER_UNCONFIGURED /* (for backwards compatibility only) */
  105. /* Access Mode bits (tentative): */ /* bit abbr unit short_name PPC equ - Description */
  106. #define XTHAL_AMB_EXCEPTION 0 /* 001 E EX fls: EXception none - generate exception on any access (aka "illegal") */
  107. #define XTHAL_AMB_HITCACHE 1 /* 002 C CH fls: use Cache on Hit ~(I CI) - use cache on hit -- way from tag match [or H HC, or U UC] (ISA: same, except for Isolate case) */
  108. #define XTHAL_AMB_ALLOCATE 2 /* 004 A AL fl?: ALlocate none - refill cache on miss -- way from LRU [or F FI fill] (ISA: Read/Write Miss Refill) */
  109. #define XTHAL_AMB_WRITETHRU 3 /* 008 W WT --s: WriteThrough W WT - store immediately to memory (ISA: same) */
  110. #define XTHAL_AMB_ISOLATE 4 /* 010 I IS fls: ISolate none - use cache regardless of hit-vs-miss -- way from vaddr (ISA: use-cache-on-miss+hit) */
  111. #define XTHAL_AMB_GUARD 5 /* 020 G GU ?l?: GUard G * - non-speculative; spec/replay refs not permitted */
  112. #if 0
  113. #define XTHAL_AMB_ORDERED x /* 000 O OR fls: ORdered G * - mem accesses cannot be out of order */
  114. #define XTHAL_AMB_FUSEWRITES x /* 000 F FW --s: FuseWrites none - allow combining/merging multiple writes (to same datapath data unit) into one (implied by writeback) */
  115. #define XTHAL_AMB_COHERENT x /* 000 M MC fl?: Mem/MP Coherent M - on reads, other CPUs/bus-masters may need to supply data */
  116. #define XTHAL_AMB_TRUSTED x /* 000 T TR ?l?: TRusted none - memory will not bus error (if it does, handle as fatal imprecise interrupt) */
  117. #define XTHAL_AMB_PREFETCH x /* 000 P PR fl?: PRefetch none - on refill, read line+1 into prefetch buffers */
  118. #define XTHAL_AMB_STREAM x /* 000 S ST ???: STreaming none - access one of N stream buffers */
  119. #endif /*0*/
  120. #define XTHAL_AM_EXCEPTION (1<<XTHAL_AMB_EXCEPTION)
  121. #define XTHAL_AM_HITCACHE (1<<XTHAL_AMB_HITCACHE)
  122. #define XTHAL_AM_ALLOCATE (1<<XTHAL_AMB_ALLOCATE)
  123. #define XTHAL_AM_WRITETHRU (1<<XTHAL_AMB_WRITETHRU)
  124. #define XTHAL_AM_ISOLATE (1<<XTHAL_AMB_ISOLATE)
  125. #define XTHAL_AM_GUARD (1<<XTHAL_AMB_GUARD)
  126. #if 0
  127. #define XTHAL_AM_ORDERED (1<<XTHAL_AMB_ORDERED)
  128. #define XTHAL_AM_FUSEWRITES (1<<XTHAL_AMB_FUSEWRITES)
  129. #define XTHAL_AM_COHERENT (1<<XTHAL_AMB_COHERENT)
  130. #define XTHAL_AM_TRUSTED (1<<XTHAL_AMB_TRUSTED)
  131. #define XTHAL_AM_PREFETCH (1<<XTHAL_AMB_PREFETCH)
  132. #define XTHAL_AM_STREAM (1<<XTHAL_AMB_STREAM)
  133. #endif /*0*/
  134. /*
  135. * Allowed Access Modes (bit combinations).
  136. *
  137. * Columns are:
  138. * "FOGIWACE"
  139. * Access mode bits (see XTHAL_AMB_xxx above).
  140. * <letter> = bit is set
  141. * '-' = bit is clear
  142. * '.' = bit is irrelevant / don't care, as follows:
  143. * E=1 makes all others irrelevant
  144. * W,F relevant only for stores
  145. * "2345"
  146. * Indicates which Xtensa releases support the corresponding
  147. * access mode. Releases for each character column are:
  148. * 2 = prior to T1020.2: T1015 (V1.5), T1020.0, T1020.1
  149. * 3 = T1020.2 and later: T1020.2+, T1030
  150. * 4 = T1040
  151. * 5 = T1050 (maybe)
  152. * And the character column contents are:
  153. * <number> = support by release(s)
  154. * "." = unsupported by release(s)
  155. * "?" = support unknown
  156. */
  157. /* FOGIWACE 2345 */
  158. /* For instruction fetch: */
  159. #define XTHAL_FAM_EXCEPTION 0x001 /* .......E 2345 exception */
  160. #define XTHAL_FAM_ISOLATE 0x012 /* .--I.-C- .... isolate */
  161. #define XTHAL_FAM_BYPASS 0x000 /* .---.--- 2345 bypass */
  162. #define XTHAL_FAM_NACACHED 0x002 /* .---.-C- .... cached no-allocate (frozen) */
  163. #define XTHAL_FAM_CACHED 0x006 /* .---.AC- 2345 cached */
  164. /* For data load: */
  165. #define XTHAL_LAM_EXCEPTION 0x001 /* .......E 2345 exception */
  166. #define XTHAL_LAM_ISOLATE 0x012 /* .--I.-C- 2345 isolate */
  167. #define XTHAL_LAM_BYPASS 0x000 /* .O--.--- 2... bypass speculative */
  168. #define XTHAL_LAM_BYPASSG 0x020 /* .OG-.--- .345 bypass guarded */
  169. #define XTHAL_LAM_NACACHED 0x002 /* .O--.-C- 2... cached no-allocate speculative */
  170. #define XTHAL_LAM_NACACHEDG 0x022 /* .OG-.-C- .345 cached no-allocate guarded */
  171. #define XTHAL_LAM_CACHED 0x006 /* .---.AC- 2345 cached speculative */
  172. #define XTHAL_LAM_CACHEDG 0x026 /* .?G-.AC- .... cached guarded */
  173. /* For data store: */
  174. #define XTHAL_SAM_EXCEPTION 0x001 /* .......E 2345 exception */
  175. #define XTHAL_SAM_ISOLATE 0x032 /* .-GI--C- 2345 isolate */
  176. #define XTHAL_SAM_BYPASS 0x028 /* -OG-W--- 2345 bypass */
  177. /*efine XTHAL_SAM_BYPASSF 0x028*/ /* F-G-W--- ...? bypass write-combined */
  178. #define XTHAL_SAM_WRITETHRU 0x02A /* -OG-W-C- 234? writethrough */
  179. /*efine XTHAL_SAM_WRITETHRUF 0x02A*/ /* F-G-W-C- ...5 writethrough write-combined */
  180. #define XTHAL_SAM_WRITEALLOC 0x02E /* -OG-WAC- ...? writethrough-allocate */
  181. /*efine XTHAL_SAM_WRITEALLOCF 0x02E*/ /* F-G-WAC- ...? writethrough-allocate write-combined */
  182. #define XTHAL_SAM_WRITEBACK 0x026 /* F-G--AC- ...5 writeback */
  183. #if 0
  184. /*
  185. Cache attribute encoding for CACHEATTR (per ISA):
  186. (Note: if this differs from ISA Ref Manual, ISA has precedence)
  187. Inst-fetches Loads Stores
  188. ------------- ------------ -------------
  189. 0x0 FCA_EXCEPTION ?LCA_NACACHED_G* SCA_WRITETHRU "uncached"
  190. 0x1 FCA_CACHED LCA_CACHED SCA_WRITETHRU cached
  191. 0x2 FCA_BYPASS LCA_BYPASS_G* SCA_BYPASS bypass
  192. 0x3 FCA_CACHED LCA_CACHED SCA_WRITEALLOCF write-allocate
  193. or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
  194. 0x4 FCA_CACHED LCA_CACHED SCA_WRITEBACK write-back
  195. or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
  196. 0x5..D FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION (reserved)
  197. 0xE FCA_EXCEPTION LCA_ISOLATE SCA_ISOLATE isolate
  198. 0xF FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION illegal
  199. * Prior to T1020.2?, guard feature not supported, this defaulted to speculative (no _G)
  200. */
  201. #endif /*0*/
  202. #if !defined(__ASSEMBLY__) && !defined(_NOCLANGUAGE)
  203. #ifdef __cplusplus
  204. extern "C" {
  205. #endif
  206. /*----------------------------------------------------------------------
  207. HAL
  208. ----------------------------------------------------------------------*/
  209. /* Constant to be checked in build = (XTHAL_MAJOR_REV<<16)|XTHAL_MINOR_REV */
  210. extern const unsigned int Xthal_rev_no;
  211. /*----------------------------------------------------------------------
  212. Processor State
  213. ----------------------------------------------------------------------*/
  214. /* save & restore the extra processor state */
  215. extern void xthal_save_extra(void *base);
  216. extern void xthal_restore_extra(void *base);
  217. extern void xthal_save_cpregs(void *base, int);
  218. extern void xthal_restore_cpregs(void *base, int);
  219. /*extern void xthal_save_all_extra(void *base);*/
  220. /*extern void xthal_restore_all_extra(void *base);*/
  221. /* space for processor state */
  222. extern const unsigned int Xthal_extra_size;
  223. extern const unsigned int Xthal_extra_align;
  224. /* space for TIE register files */
  225. extern const unsigned int Xthal_cpregs_size[XTHAL_MAX_CPS];
  226. extern const unsigned int Xthal_cpregs_align[XTHAL_MAX_CPS];
  227. /* total of space for the processor state (for Tor2) */
  228. extern const unsigned int Xthal_all_extra_size;
  229. extern const unsigned int Xthal_all_extra_align;
  230. /* initialize the extra processor */
  231. /*extern void xthal_init_extra(void);*/
  232. /* initialize the TIE coprocessor */
  233. /*extern void xthal_init_cp(int);*/
  234. /* initialize the extra processor */
  235. extern void xthal_init_mem_extra(void *);
  236. /* initialize the TIE coprocessor */
  237. extern void xthal_init_mem_cp(void *, int);
  238. /* validate & invalidate the TIE register file */
  239. extern void xthal_validate_cp(int);
  240. extern void xthal_invalidate_cp(int);
  241. /* the number of TIE coprocessors contiguous from zero (for Tor2) */
  242. extern const unsigned int Xthal_num_coprocessors;
  243. /* actual number of coprocessors */
  244. extern const unsigned char Xthal_cp_num;
  245. /* index of highest numbered coprocessor, plus one */
  246. extern const unsigned char Xthal_cp_max;
  247. /* index of highest allowed coprocessor number, per cfg, plus one */
  248. /*extern const unsigned char Xthal_cp_maxcfg;*/
  249. /* bitmask of which coprocessors are present */
  250. extern const unsigned int Xthal_cp_mask;
  251. /* read and write cpenable register */
  252. extern void xthal_set_cpenable(unsigned);
  253. extern unsigned xthal_get_cpenable(void);
  254. /* read & write extra state register */
  255. /*extern int xthal_read_extra(void *base, unsigned reg, unsigned *value);*/
  256. /*extern int xthal_write_extra(void *base, unsigned reg, unsigned value);*/
  257. /* read & write a TIE coprocessor register */
  258. /*extern int xthal_read_cpreg(void *base, int cp, unsigned reg, unsigned *value);*/
  259. /*extern int xthal_write_cpreg(void *base, int cp, unsigned reg, unsigned value);*/
  260. /* return coprocessor number based on register */
  261. /*extern int xthal_which_cp(unsigned reg);*/
  262. /*----------------------------------------------------------------------
  263. Interrupts
  264. ----------------------------------------------------------------------*/
  265. /* the number of interrupt levels */
  266. extern const unsigned char Xthal_num_intlevels;
  267. /* the number of interrupts */
  268. extern const unsigned char Xthal_num_interrupts;
  269. /* mask for level of interrupts */
  270. extern const unsigned int Xthal_intlevel_mask[XTHAL_MAX_INTLEVELS];
  271. /* mask for level 0 to N interrupts */
  272. extern const unsigned int Xthal_intlevel_andbelow_mask[XTHAL_MAX_INTLEVELS];
  273. /* level of each interrupt */
  274. extern const unsigned char Xthal_intlevel[XTHAL_MAX_INTERRUPTS];
  275. /* type per interrupt */
  276. extern const unsigned char Xthal_inttype[XTHAL_MAX_INTERRUPTS];
  277. /* masks of each type of interrupt */
  278. extern const unsigned int Xthal_inttype_mask[XTHAL_MAX_INTTYPES];
  279. /* interrupt numbers assigned to each timer interrupt */
  280. extern const int Xthal_timer_interrupt[XTHAL_MAX_TIMERS];
  281. /*** Virtual interrupt prioritization: ***/
  282. /* Convert between interrupt levels (as per PS.INTLEVEL) and virtual interrupt priorities: */
  283. extern unsigned xthal_vpri_to_intlevel(unsigned vpri);
  284. extern unsigned xthal_intlevel_to_vpri(unsigned intlevel);
  285. /* Enables/disables given set (mask) of interrupts; returns previous enabled-mask of all ints: */
  286. extern unsigned xthal_int_enable(unsigned);
  287. extern unsigned xthal_int_disable(unsigned);
  288. /* Set/get virtual priority of an interrupt: */
  289. extern int xthal_set_int_vpri(int intnum, int vpri);
  290. extern int xthal_get_int_vpri(int intnum);
  291. /* Set/get interrupt lockout level for exclusive access to virtual priority data structures: */
  292. extern void xthal_set_vpri_locklevel(unsigned intlevel);
  293. extern unsigned xthal_get_vpri_locklevel(void);
  294. /* Set/get current virtual interrupt priority: */
  295. extern unsigned xthal_set_vpri(unsigned vpri);
  296. extern unsigned xthal_get_vpri(unsigned vpri);
  297. extern unsigned xthal_set_vpri_intlevel(unsigned intlevel);
  298. extern unsigned xthal_set_vpri_lock(void);
  299. /*----------------------------------------------------------------------
  300. Generic Interrupt Trampolining Support
  301. ----------------------------------------------------------------------*/
  302. typedef void (XtHalVoidFunc)(void);
  303. /*
  304. * Bitmask of interrupts currently trampolining down:
  305. */
  306. extern unsigned Xthal_tram_pending;
  307. /*
  308. * Bitmask of which interrupts currently trampolining down
  309. * synchronously are actually enabled; this bitmask is necessary
  310. * because INTENABLE cannot hold that state (sync-trampolining
  311. * interrupts must be kept disabled while trampolining);
  312. * in the current implementation, any bit set here is not set
  313. * in INTENABLE, and vice-versa; once a sync-trampoline is
  314. * handled (at level one), its enable bit must be moved from
  315. * here to INTENABLE:
  316. */
  317. extern unsigned Xthal_tram_enabled;
  318. /*
  319. * Bitmask of interrupts configured for sync trampolining:
  320. */
  321. extern unsigned Xthal_tram_sync;
  322. /* Trampoline support functions: */
  323. extern unsigned xthal_tram_pending_to_service( void );
  324. extern void xthal_tram_done( unsigned serviced_mask );
  325. extern int xthal_tram_set_sync( int intnum, int sync );
  326. extern XtHalVoidFunc* xthal_set_tram_trigger_func( XtHalVoidFunc *trigger_fn );
  327. /* INTENABLE,INTREAD,INTSET,INTCLEAR register access functions: */
  328. extern unsigned xthal_get_intenable( void );
  329. extern void xthal_set_intenable( unsigned );
  330. extern unsigned xthal_get_intread( void );
  331. extern void xthal_set_intset( unsigned );
  332. extern void xthal_set_intclear( unsigned );
  333. /*----------------------------------------------------------------------
  334. Register Windows
  335. ----------------------------------------------------------------------*/
  336. /* number of registers in register window */
  337. extern const unsigned int Xthal_num_aregs;
  338. extern const unsigned char Xthal_num_aregs_log2;
  339. /* This spill any live register windows (other than the caller's): */
  340. extern void xthal_window_spill( void );
  341. /*----------------------------------------------------------------------
  342. Cache
  343. ----------------------------------------------------------------------*/
  344. /* size of the cache lines in log2(bytes) */
  345. extern const unsigned char Xthal_icache_linewidth;
  346. extern const unsigned char Xthal_dcache_linewidth;
  347. /* size of the cache lines in bytes */
  348. extern const unsigned short Xthal_icache_linesize;
  349. extern const unsigned short Xthal_dcache_linesize;
  350. /* number of cache sets in log2(lines per way) */
  351. extern const unsigned char Xthal_icache_setwidth;
  352. extern const unsigned char Xthal_dcache_setwidth;
  353. /* cache set associativity (number of ways) */
  354. extern const unsigned int Xthal_icache_ways;
  355. extern const unsigned int Xthal_dcache_ways;
  356. /* size of the caches in bytes (ways * 2^(linewidth + setwidth)) */
  357. extern const unsigned int Xthal_icache_size;
  358. extern const unsigned int Xthal_dcache_size;
  359. /* cache features */
  360. extern const unsigned char Xthal_dcache_is_writeback;
  361. extern const unsigned char Xthal_icache_line_lockable;
  362. extern const unsigned char Xthal_dcache_line_lockable;
  363. /* cache attribute register control (used by other HAL routines) */
  364. extern unsigned xthal_get_cacheattr( void );
  365. extern unsigned xthal_get_icacheattr( void );
  366. extern unsigned xthal_get_dcacheattr( void );
  367. extern void xthal_set_cacheattr( unsigned );
  368. extern void xthal_set_icacheattr( unsigned );
  369. extern void xthal_set_dcacheattr( unsigned );
  370. /* initialize cache support (must be called once at startup, before all other cache calls) */
  371. /*extern void xthal_cache_startinit( void );*/
  372. /* reset caches */
  373. /*extern void xthal_icache_reset( void );*/
  374. /*extern void xthal_dcache_reset( void );*/
  375. /* enable caches */
  376. extern void xthal_icache_enable( void ); /* DEPRECATED */
  377. extern void xthal_dcache_enable( void ); /* DEPRECATED */
  378. /* disable caches */
  379. extern void xthal_icache_disable( void ); /* DEPRECATED */
  380. extern void xthal_dcache_disable( void ); /* DEPRECATED */
  381. /* invalidate the caches */
  382. extern void xthal_icache_all_invalidate( void );
  383. extern void xthal_dcache_all_invalidate( void );
  384. extern void xthal_icache_region_invalidate( void *addr, unsigned size );
  385. extern void xthal_dcache_region_invalidate( void *addr, unsigned size );
  386. extern void xthal_icache_line_invalidate(void *addr);
  387. extern void xthal_dcache_line_invalidate(void *addr);
  388. /* write dirty data back */
  389. extern void xthal_dcache_all_writeback( void );
  390. extern void xthal_dcache_region_writeback( void *addr, unsigned size );
  391. extern void xthal_dcache_line_writeback(void *addr);
  392. /* write dirty data back and invalidate */
  393. extern void xthal_dcache_all_writeback_inv( void );
  394. extern void xthal_dcache_region_writeback_inv( void *addr, unsigned size );
  395. extern void xthal_dcache_line_writeback_inv(void *addr);
  396. /* prefetch and lock specified memory range into cache */
  397. extern void xthal_icache_region_lock( void *addr, unsigned size );
  398. extern void xthal_dcache_region_lock( void *addr, unsigned size );
  399. extern void xthal_icache_line_lock(void *addr);
  400. extern void xthal_dcache_line_lock(void *addr);
  401. /* unlock from cache */
  402. extern void xthal_icache_all_unlock( void );
  403. extern void xthal_dcache_all_unlock( void );
  404. extern void xthal_icache_region_unlock( void *addr, unsigned size );
  405. extern void xthal_dcache_region_unlock( void *addr, unsigned size );
  406. extern void xthal_icache_line_unlock(void *addr);
  407. extern void xthal_dcache_line_unlock(void *addr);
  408. /* sync icache and memory */
  409. extern void xthal_icache_sync( void );
  410. /* sync dcache and memory */
  411. extern void xthal_dcache_sync( void );
  412. /*----------------------------------------------------------------------
  413. Debug
  414. ----------------------------------------------------------------------*/
  415. /* 1 if debug option configured, 0 if not: */
  416. extern const int Xthal_debug_configured;
  417. /* Number of instruction and data break registers: */
  418. extern const int Xthal_num_ibreak;
  419. extern const int Xthal_num_dbreak;
  420. /* Set (plant) and remove software breakpoint, both synchronizing cache: */
  421. extern unsigned int xthal_set_soft_break(void *addr);
  422. extern void xthal_remove_soft_break(void *addr, unsigned int);
  423. /*----------------------------------------------------------------------
  424. Disassembler
  425. ----------------------------------------------------------------------*/
  426. /* Max expected size of the return buffer for a disassembled instruction (hint only): */
  427. #define XTHAL_DISASM_BUFSIZE 80
  428. /* Disassembly option bits for selecting what to return: */
  429. #define XTHAL_DISASM_OPT_ADDR 0x0001 /* display address */
  430. #define XTHAL_DISASM_OPT_OPHEX 0x0002 /* display opcode bytes in hex */
  431. #define XTHAL_DISASM_OPT_OPCODE 0x0004 /* display opcode name (mnemonic) */
  432. #define XTHAL_DISASM_OPT_PARMS 0x0008 /* display parameters */
  433. #define XTHAL_DISASM_OPT_ALL 0x0FFF /* display everything */
  434. /* routine to get a string for the disassembled instruction */
  435. extern int xthal_disassemble( unsigned char *instr_buf, void *tgt_addr,
  436. char *buffer, unsigned buflen, unsigned options );
  437. /* routine to get the size of the next instruction. Returns 0 for
  438. illegal instruction */
  439. extern int xthal_disassemble_size( unsigned char *instr_buf );
  440. /*----------------------------------------------------------------------
  441. Core Counter
  442. ----------------------------------------------------------------------*/
  443. /* counter info */
  444. extern const unsigned char Xthal_have_ccount; /* set if CCOUNT register present */
  445. extern const unsigned char Xthal_num_ccompare; /* number of CCOMPAREn registers */
  446. /* get CCOUNT register (if not present return 0) */
  447. extern unsigned xthal_get_ccount(void);
  448. /* set and get CCOMPAREn registers (if not present, get returns 0) */
  449. extern void xthal_set_ccompare(int, unsigned);
  450. extern unsigned xthal_get_ccompare(int);
  451. /*----------------------------------------------------------------------
  452. Instruction/Data RAM/ROM Access
  453. ----------------------------------------------------------------------*/
  454. extern void* xthal_memcpy(void *dst, const void *src, unsigned len);
  455. extern void* xthal_bcopy(const void *src, void *dst, unsigned len);
  456. /*----------------------------------------------------------------------
  457. MP Synchronization
  458. ----------------------------------------------------------------------*/
  459. extern int xthal_compare_and_set( int *addr, int test_val, int compare_val );
  460. extern unsigned xthal_get_prid( void );
  461. /*extern const char Xthal_have_s32c1i;*/
  462. extern const unsigned char Xthal_have_prid;
  463. /*----------------------------------------------------------------------
  464. Miscellaneous
  465. ----------------------------------------------------------------------*/
  466. extern const unsigned int Xthal_release_major;
  467. extern const unsigned int Xthal_release_minor;
  468. extern const char * const Xthal_release_name;
  469. extern const char * const Xthal_release_internal;
  470. extern const unsigned char Xthal_memory_order;
  471. extern const unsigned char Xthal_have_windowed;
  472. extern const unsigned char Xthal_have_density;
  473. extern const unsigned char Xthal_have_booleans;
  474. extern const unsigned char Xthal_have_loops;
  475. extern const unsigned char Xthal_have_nsa;
  476. extern const unsigned char Xthal_have_minmax;
  477. extern const unsigned char Xthal_have_sext;
  478. extern const unsigned char Xthal_have_clamps;
  479. extern const unsigned char Xthal_have_mac16;
  480. extern const unsigned char Xthal_have_mul16;
  481. extern const unsigned char Xthal_have_fp;
  482. extern const unsigned char Xthal_have_speculation;
  483. extern const unsigned char Xthal_have_exceptions;
  484. extern const unsigned char Xthal_xea_version;
  485. extern const unsigned char Xthal_have_interrupts;
  486. extern const unsigned char Xthal_have_highlevel_interrupts;
  487. extern const unsigned char Xthal_have_nmi;
  488. extern const unsigned short Xthal_num_writebuffer_entries;
  489. extern const unsigned int Xthal_build_unique_id;
  490. /* Release info for hardware targeted by software upgrades: */
  491. extern const unsigned int Xthal_hw_configid0;
  492. extern const unsigned int Xthal_hw_configid1;
  493. extern const unsigned int Xthal_hw_release_major;
  494. extern const unsigned int Xthal_hw_release_minor;
  495. extern const char * const Xthal_hw_release_name;
  496. extern const char * const Xthal_hw_release_internal;
  497. /* Internal memories... */
  498. extern const unsigned char Xthal_num_instrom;
  499. extern const unsigned char Xthal_num_instram;
  500. extern const unsigned char Xthal_num_datarom;
  501. extern const unsigned char Xthal_num_dataram;
  502. extern const unsigned char Xthal_num_xlmi;
  503. extern const unsigned int Xthal_instrom_vaddr[1];
  504. extern const unsigned int Xthal_instrom_paddr[1];
  505. extern const unsigned int Xthal_instrom_size [1];
  506. extern const unsigned int Xthal_instram_vaddr[1];
  507. extern const unsigned int Xthal_instram_paddr[1];
  508. extern const unsigned int Xthal_instram_size [1];
  509. extern const unsigned int Xthal_datarom_vaddr[1];
  510. extern const unsigned int Xthal_datarom_paddr[1];
  511. extern const unsigned int Xthal_datarom_size [1];
  512. extern const unsigned int Xthal_dataram_vaddr[1];
  513. extern const unsigned int Xthal_dataram_paddr[1];
  514. extern const unsigned int Xthal_dataram_size [1];
  515. extern const unsigned int Xthal_xlmi_vaddr[1];
  516. extern const unsigned int Xthal_xlmi_paddr[1];
  517. extern const unsigned int Xthal_xlmi_size [1];
  518. /*----------------------------------------------------------------------
  519. Memory Management Unit
  520. ----------------------------------------------------------------------*/
  521. extern const unsigned char Xthal_have_spanning_way;
  522. extern const unsigned char Xthal_have_identity_map;
  523. extern const unsigned char Xthal_have_mimic_cacheattr;
  524. extern const unsigned char Xthal_have_xlt_cacheattr;
  525. extern const unsigned char Xthal_have_cacheattr;
  526. extern const unsigned char Xthal_have_tlbs;
  527. extern const unsigned char Xthal_mmu_asid_bits; /* 0 .. 8 */
  528. extern const unsigned char Xthal_mmu_asid_kernel;
  529. extern const unsigned char Xthal_mmu_rings; /* 1 .. 4 (perhaps 0 if no MMU and/or no protection?) */
  530. extern const unsigned char Xthal_mmu_ring_bits;
  531. extern const unsigned char Xthal_mmu_sr_bits;
  532. extern const unsigned char Xthal_mmu_ca_bits;
  533. extern const unsigned int Xthal_mmu_max_pte_page_size;
  534. extern const unsigned int Xthal_mmu_min_pte_page_size;
  535. extern const unsigned char Xthal_itlb_way_bits;
  536. extern const unsigned char Xthal_itlb_ways;
  537. extern const unsigned char Xthal_itlb_arf_ways;
  538. extern const unsigned char Xthal_dtlb_way_bits;
  539. extern const unsigned char Xthal_dtlb_ways;
  540. extern const unsigned char Xthal_dtlb_arf_ways;
  541. /* Convert between virtual and physical addresses (through static maps only): */
  542. /*** WARNING: these two functions may go away in a future release; don't depend on them! ***/
  543. extern int xthal_static_v2p( unsigned vaddr, unsigned *paddrp );
  544. extern int xthal_static_p2v( unsigned paddr, unsigned *vaddrp, unsigned cached );
  545. #if 0
  546. /******************* EXPERIMENTAL AND TENTATIVE ONLY ********************/
  547. #define XTHAL_MMU_PAGESZ_COUNT_MAX 8 /* maximum number of different page sizes */
  548. extern const char Xthal_mmu_pagesz_count; /* 0 .. 8 number of different page sizes configured */
  549. /* Note: the following table doesn't necessarily have page sizes in increasing order: */
  550. extern const char Xthal_mmu_pagesz_log2[XTHAL_MMU_PAGESZ_COUNT_MAX]; /* 10 .. 28 (0 past count) */
  551. /* Sorted (increasing) table of page sizes, that indexes into the above table: */
  552. extern const char Xthal_mmu_pagesz_sorted[XTHAL_MMU_PAGESZ_COUNT_MAX]; /* 0 .. 7 (0 past count) */
  553. /*u32 Xthal_virtual_exceptions;*/ /* bitmask of which exceptions execute in virtual mode... */
  554. extern const char Xthal_mmu_pte_pagesz_log2_min; /* ?? minimum page size in PTEs */
  555. extern const char Xthal_mmu_pte_pagesz_log2_max; /* ?? maximum page size in PTEs */
  556. /* Cache Attribute Bits Implemented by the Cache (part of the cache abstraction) */
  557. extern const char Xthal_icache_fca_bits_implemented; /* ITLB/UTLB only! */
  558. extern const char Xthal_dcache_lca_bits_implemented; /* DTLB/UTLB only! */
  559. extern const char Xthal_dcache_sca_bits_implemented; /* DTLB/UTLB only! */
  560. /* Per TLB Parameters (Instruction, Data, Unified) */
  561. struct XtHalMmuTlb Xthal_itlb; /* description of MMU I-TLB generic features */
  562. struct XtHalMmuTlb Xthal_dtlb; /* description of MMU D-TLB generic features */
  563. struct XtHalMmuTlb Xthal_utlb; /* description of MMU U-TLB generic features */
  564. #define XTHAL_MMU_WAYS_MAX 8 /* maximum number of ways (associativities) for each TLB */
  565. /* Structure for common information described for each possible TLB (instruction, data and unified): */
  566. typedef struct XtHalMmuTlb {
  567. u8 va_bits; /* 32 (number of virtual address bits) */
  568. u8 pa_bits; /* 32 (number of physical address bits) */
  569. bool tlb_va_indexed; /* 1 (set if TLB is indexed by virtual address) */
  570. bool tlb_va_tagged; /* 0 (set if TLB is tagged by virtual address) */
  571. bool cache_va_indexed; /* 1 (set if cache is indexed by virtual address) */
  572. bool cache_va_tagged; /* 0 (set if cache is tagged by virtual address) */
  573. /*bool (whether page tables are traversed in vaddr sorted order, paddr sorted order, ...) */
  574. /*u8 (set of available page attribute bits, other than cache attribute bits defined above) */
  575. /*u32 (various masks for pages, MMU table/TLB entries, etc.) */
  576. u8 way_count; /* 0 .. 8 (number of ways, a.k.a. associativities, for this TLB) */
  577. XtHalMmuTlbWay * ways[XTHAL_MMU_WAYS_MAX]; /* pointers to per-way parms for each way */
  578. } XtHalMmuTlb;
  579. /* Per TLB Way (Per Associativity) Parameters */
  580. typedef struct XtHalMmuTlbWay {
  581. u32 index_count_log2; /* 0 .. 4 */
  582. u32 pagesz_mask; /* 0 .. 2^pagesz_count - 1 (each bit corresponds to a size */
  583. /* defined in the Xthal_mmu_pagesz_log2[] table) */
  584. u32 vpn_const_mask;
  585. u32 vpn_const_value;
  586. u64 ppn_const_mask; /* future may support pa_bits > 32 */
  587. u64 ppn_const_value;
  588. u32 ppn_id_mask; /* paddr bits taken directly from vaddr */
  589. bool backgnd_match; /* 0 or 1 */
  590. /* These are defined in terms of the XTHAL_CACHE_xxx bits: */
  591. u8 fca_const_mask; /* ITLB/UTLB only! */
  592. u8 fca_const_value; /* ITLB/UTLB only! */
  593. u8 lca_const_mask; /* DTLB/UTLB only! */
  594. u8 lca_const_value; /* DTLB/UTLB only! */
  595. u8 sca_const_mask; /* DTLB/UTLB only! */
  596. u8 sca_const_value; /* DTLB/UTLB only! */
  597. /* These define an encoding that map 5 bits in TLB and PTE entries to */
  598. /* 8 bits (FCA, ITLB), 16 bits (LCA+SCA, DTLB) or 24 bits (FCA+LCA+SCA, UTLB): */
  599. /* (they may be moved to struct XtHalMmuTlb) */
  600. u8 ca_bits; /* number of bits in TLB/PTE entries for cache attributes */
  601. u32 * ca_map; /* pointer to array of 2^ca_bits entries of FCA+LCA+SCA bits */
  602. } XtHalMmuTlbWay;
  603. /*
  604. * The way to determine whether protection support is present in core
  605. * is to [look at Xthal_mmu_rings ???].
  606. * Give info on memory requirements for MMU tables and other in-memory
  607. * data structures (globally, per task, base and per page, etc.) - whatever bounds can be calculated.
  608. */
  609. /* Default vectors: */
  610. xthal_immu_fetch_miss_vector
  611. xthal_dmmu_load_miss_vector
  612. xthal_dmmu_store_miss_vector
  613. /* Functions called when a fault is detected: */
  614. typedef void (XtHalMmuFaultFunc)( unsigned vaddr, ...context... );
  615. /* Or, */
  616. /* a? = vaddr */
  617. /* a? = context... */
  618. /* PS.xxx = xxx */
  619. XtHalMMuFaultFunc *Xthal_immu_fetch_fault_func;
  620. XtHalMMuFaultFunc *Xthal_dmmu_load_fault_func;
  621. XtHalMMuFaultFunc *Xthal_dmmu_store_fault_func;
  622. /* Default Handlers: */
  623. /* The user and/or kernel exception handlers may jump to these handlers to handle the relevant exceptions,
  624. * according to the value of EXCCAUSE. The exact register state on entry to these handlers is TBD. */
  625. /* When multiple TLB entries match (hit) on the same access: */
  626. xthal_immu_fetch_multihit_handler
  627. xthal_dmmu_load_multihit_handler
  628. xthal_dmmu_store_multihit_handler
  629. /* Protection violations according to cache attributes, and other cache attribute mismatches: */
  630. xthal_immu_fetch_attr_handler
  631. xthal_dmmu_load_attr_handler
  632. xthal_dmmu_store_attr_handler
  633. /* Protection violations due to insufficient ring level: */
  634. xthal_immu_fetch_priv_handler
  635. xthal_dmmu_load_priv_handler
  636. xthal_dmmu_store_priv_handler
  637. /* Alignment exception handlers (if supported by the particular Xtensa MMU configuration): */
  638. xthal_dmmu_load_align_handler
  639. xthal_dmmu_store_align_handler
  640. /* Or, alternatively, the OS user and/or kernel exception handlers may simply jump to the
  641. * following entry points which will handle any values of EXCCAUSE not handled by the OS: */
  642. xthal_user_exc_default_handler
  643. xthal_kernel_exc_default_handler
  644. #endif /*0*/
  645. #ifdef INCLUDE_DEPRECATED_HAL_CODE
  646. extern const unsigned char Xthal_have_old_exc_arch;
  647. extern const unsigned char Xthal_have_mmu;
  648. extern const unsigned int Xthal_num_regs;
  649. extern const unsigned char Xthal_num_iroms;
  650. extern const unsigned char Xthal_num_irams;
  651. extern const unsigned char Xthal_num_droms;
  652. extern const unsigned char Xthal_num_drams;
  653. extern const unsigned int Xthal_configid0;
  654. extern const unsigned int Xthal_configid1;
  655. #endif
  656. #ifdef INCLUDE_DEPRECATED_HAL_DEBUG_CODE
  657. #define XTHAL_24_BIT_BREAK 0x80000000
  658. #define XTHAL_16_BIT_BREAK 0x40000000
  659. extern const unsigned short Xthal_ill_inst_16[16];
  660. #define XTHAL_DEST_REG 0xf0000000 /* Mask for destination register */
  661. #define XTHAL_DEST_REG_INST 0x08000000 /* Branch address is in register */
  662. #define XTHAL_DEST_REL_INST 0x04000000 /* Branch address is relative */
  663. #define XTHAL_RFW_INST 0x00000800
  664. #define XTHAL_RFUE_INST 0x00000400
  665. #define XTHAL_RFI_INST 0x00000200
  666. #define XTHAL_RFE_INST 0x00000100
  667. #define XTHAL_RET_INST 0x00000080
  668. #define XTHAL_BREAK_INST 0x00000040
  669. #define XTHAL_SYSCALL_INST 0x00000020
  670. #define XTHAL_LOOP_END 0x00000010 /* Not set by xthal_inst_type */
  671. #define XTHAL_JUMP_INST 0x00000008 /* Call or jump instruction */
  672. #define XTHAL_BRANCH_INST 0x00000004 /* Branch instruction */
  673. #define XTHAL_24_BIT_INST 0x00000002
  674. #define XTHAL_16_BIT_INST 0x00000001
  675. typedef struct xthal_state {
  676. unsigned pc;
  677. unsigned ar[16];
  678. unsigned lbeg;
  679. unsigned lend;
  680. unsigned lcount;
  681. unsigned extra_ptr;
  682. unsigned cpregs_ptr[XTHAL_MAX_CPS];
  683. } XTHAL_STATE;
  684. extern unsigned int xthal_inst_type(void *addr);
  685. extern unsigned int xthal_branch_addr(void *addr);
  686. extern unsigned int xthal_get_npc(XTHAL_STATE *user_state);
  687. #endif /* INCLUDE_DEPRECATED_HAL_DEBUG_CODE */
  688. #ifdef __cplusplus
  689. }
  690. #endif
  691. #endif /*!__ASSEMBLY__ */
  692. #endif /*XTENSA_HAL_H*/