hal.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. /*
  2. xtensa/hal.h -- contains a definition of the Core HAL interface
  3. All definitions in this header file are independent of any specific
  4. Xtensa processor configuration. Thus software (eg. OS, application,
  5. etc) can include this header file and be compiled into configuration-
  6. independent objects that can be distributed and eventually linked
  7. to the HAL library (libhal.a) to create a configuration-specific
  8. final executable.
  9. Certain definitions, however, are release/version-specific -- such as
  10. the XTHAL_RELEASE_xxx macros (or additions made in later versions).
  11. $Id: //depot/rel/Foxhill/dot.9/Xtensa/OS/target-os-src/hal.h.tpp#1 $
  12. Copyright (c) 1999-2015 Cadence Design Systems, Inc.
  13. Permission is hereby granted, free of charge, to any person obtaining
  14. a copy of this software and associated documentation files (the
  15. "Software"), to deal in the Software without restriction, including
  16. without limitation the rights to use, copy, modify, merge, publish,
  17. distribute, sublicense, and/or sell copies of the Software, and to
  18. permit persons to whom the Software is furnished to do so, subject to
  19. the following conditions:
  20. The above copyright notice and this permission notice shall be included
  21. in all copies or substantial portions of the Software.
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  25. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  26. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  27. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  28. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. #ifndef XTENSA_HAL_H
  31. #define XTENSA_HAL_H
  32. /****************************************************************************
  33. Definitions Useful for Any Code, USER or PRIVILEGED
  34. ****************************************************************************/
  35. /*----------------------------------------------------------------------
  36. Constant Definitions (shared with assembly)
  37. ----------------------------------------------------------------------*/
  38. /*
  39. * Software (Xtensa Tools) version information. Not configuration-specific!
  40. *
  41. * NOTE: "release" is a misnomer here, these are really product "version"
  42. * numbers. A "release" is a collection of product versions
  43. * made available at once (together) to customers.
  44. * In the past, release and version names all matched in T####.# form,
  45. * making the distinction irrelevant. This is no longer the case.
  46. */
  47. #define XTHAL_RELEASE_MAJOR 12000
  48. #define XTHAL_RELEASE_MINOR 9
  49. #define XTHAL_RELEASE_NAME "12.0.9"
  50. #define XTHAL_REL_12 1
  51. #define XTHAL_REL_12_0 1
  52. #define XTHAL_REL_12_0_9 1
  53. /* HAL version numbers (these names are for backward compatibility): */
  54. #define XTHAL_MAJOR_REV XTHAL_RELEASE_MAJOR
  55. #define XTHAL_MINOR_REV XTHAL_RELEASE_MINOR
  56. /*
  57. * A bit of software release/version history on values of XTHAL_{MAJOR,MINOR}_REV:
  58. *
  59. * SW Version MAJOR MINOR Comment
  60. * ======= ===== ===== =======
  61. * T1015.n n/a n/a (HAL not yet available)
  62. * T1020.{0,1,2} 0 1 (HAL beta)
  63. * T1020.{3,4} 0 2 First release.
  64. * T1020.n (n>4) 0 2 or >3 (TBD)
  65. * T1030.0 0 1 (HAL beta)
  66. * T1030.{1,2} 0 3 Equivalent to first release.
  67. * T1030.n (n>=3) 0 >= 3 (TBD)
  68. * T1040.n 1040 n Full CHAL available from T1040.2
  69. * T1050.n 1050 n .
  70. * 6.0.n 6000 n Xtensa Tools v6 (RA-200x.n)
  71. * 7.0.n 7000 n Xtensa Tools v7 (RB-200x.n)
  72. * 7.1.n 7010 n Xtensa Tools v7.1 (RB-200x.(n+2))
  73. * 8.0.n 8000 n Xtensa Tools v8 (RC-20xx.n)
  74. * 9.0.n 9000 n Xtensa Tools v9 (RD-201x.n)
  75. * 10.0.n 10000 n Xtensa Tools v10 (RE-201x.n)
  76. *
  77. *
  78. * Note: there is a distinction between the software version with
  79. * which something is compiled (accessible using XTHAL_RELEASE_* macros)
  80. * and the software version with which the HAL library was compiled
  81. * (accessible using Xthal_release_* global variables). This
  82. * distinction is particularly relevant for vendors that distribute
  83. * configuration-independent binaries (eg. an OS), where their customer
  84. * might link it with a HAL of a different Xtensa software version.
  85. * In this case, it may be appropriate for the OS to verify at run-time
  86. * whether XTHAL_RELEASE_* and Xthal_release_* are compatible.
  87. * [Guidelines as to which version is compatible with which are not
  88. * currently provided explicitly, but might be inferred from reading
  89. * OSKit documentation for all releases -- compatibility is also highly
  90. * dependent on which HAL features are used. Each version is usually
  91. * backward compatible, with very few exceptions if any.]
  92. */
  93. /* Version comparison operators (among major/minor pairs): */
  94. #define XTHAL_REL_GE(maja,mina, majb,minb) ((maja) > (majb) || \
  95. ((maja) == (majb) && (mina) >= (minb)))
  96. #define XTHAL_REL_GT(maja,mina, majb,minb) ((maja) > (majb) || \
  97. ((maja) == (majb) && (mina) > (minb)))
  98. #define XTHAL_REL_LE(maja,mina, majb,minb) ((maja) < (majb) || \
  99. ((maja) == (majb) && (mina) <= (minb)))
  100. #define XTHAL_REL_LT(maja,mina, majb,minb) ((maja) < (majb) || \
  101. ((maja) == (majb) && (mina) < (minb)))
  102. #define XTHAL_REL_EQ(maja,mina, majb,minb) ((maja) == (majb) && (mina) == (minb))
  103. /* Fuzzy (3-way) logic operators: */
  104. #define XTHAL_MAYBE -1 /* 0=NO, 1=YES, -1=MAYBE */
  105. #define XTHAL_FUZZY_AND(a,b) (((a)==0 || (b)==0) ? 0 : ((a)==1 && (b)==1) ? 1 : XTHAL_MAYBE)
  106. #define XTHAL_FUZZY_OR(a,b) (((a)==1 || (b)==1) ? 1 : ((a)==0 && (b)==0) ? 0 : XTHAL_MAYBE)
  107. #define XTHAL_FUZZY_NOT(a) (((a)==0 || (a)==1) ? (1-(a)) : XTHAL_MAYBE)
  108. /*
  109. * Architectural limit, independent of configuration:
  110. */
  111. #define XTHAL_MAX_CPS 8 /* max number of coprocessors (0..7) */
  112. /* Misc: */
  113. #define XTHAL_LITTLEENDIAN 0
  114. #define XTHAL_BIGENDIAN 1
  115. #if !defined(_ASMLANGUAGE) && !defined(_NOCLANGUAGE) && !defined(__ASSEMBLER__)
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif
  119. #include <stdint.h>
  120. #include <stddef.h>
  121. /*----------------------------------------------------------------------
  122. HAL
  123. ----------------------------------------------------------------------*/
  124. /* Constant to be checked in build = (XTHAL_MAJOR_REV<<16)|XTHAL_MINOR_REV */
  125. extern const unsigned int Xthal_rev_no;
  126. /*----------------------------------------------------------------------
  127. Optional/Custom Processor State
  128. ----------------------------------------------------------------------*/
  129. /* save & restore the extra processor state */
  130. extern void xthal_save_extra(void *base);
  131. extern void xthal_restore_extra(void *base);
  132. extern void xthal_save_cpregs(void *base, int);
  133. extern void xthal_restore_cpregs(void *base, int);
  134. /* versions specific to each coprocessor id */
  135. extern void xthal_save_cp0(void *base);
  136. extern void xthal_save_cp1(void *base);
  137. extern void xthal_save_cp2(void *base);
  138. extern void xthal_save_cp3(void *base);
  139. extern void xthal_save_cp4(void *base);
  140. extern void xthal_save_cp5(void *base);
  141. extern void xthal_save_cp6(void *base);
  142. extern void xthal_save_cp7(void *base);
  143. extern void xthal_restore_cp0(void *base);
  144. extern void xthal_restore_cp1(void *base);
  145. extern void xthal_restore_cp2(void *base);
  146. extern void xthal_restore_cp3(void *base);
  147. extern void xthal_restore_cp4(void *base);
  148. extern void xthal_restore_cp5(void *base);
  149. extern void xthal_restore_cp6(void *base);
  150. extern void xthal_restore_cp7(void *base);
  151. /* pointers to each of the functions above */
  152. extern void* Xthal_cpregs_save_fn[XTHAL_MAX_CPS];
  153. extern void* Xthal_cpregs_restore_fn[XTHAL_MAX_CPS];
  154. /* similarly for non-windowed ABI (may be same or different) */
  155. extern void* Xthal_cpregs_save_nw_fn[XTHAL_MAX_CPS];
  156. extern void* Xthal_cpregs_restore_nw_fn[XTHAL_MAX_CPS];
  157. /*extern void xthal_save_all_extra(void *base);*/
  158. /*extern void xthal_restore_all_extra(void *base);*/
  159. /* space for processor state */
  160. extern const unsigned int Xthal_extra_size;
  161. extern const unsigned int Xthal_extra_align;
  162. extern const unsigned int Xthal_cpregs_size[XTHAL_MAX_CPS];
  163. extern const unsigned int Xthal_cpregs_align[XTHAL_MAX_CPS];
  164. extern const unsigned int Xthal_all_extra_size;
  165. extern const unsigned int Xthal_all_extra_align;
  166. /* coprocessor names */
  167. extern const char * const Xthal_cp_names[XTHAL_MAX_CPS];
  168. /* initialize the extra processor */
  169. /*extern void xthal_init_extra(void);*/
  170. /* initialize the TIE coprocessor */
  171. /*extern void xthal_init_cp(int);*/
  172. /* initialize the extra processor */
  173. extern void xthal_init_mem_extra(void *);
  174. /* initialize the TIE coprocessor */
  175. extern void xthal_init_mem_cp(void *, int);
  176. /* the number of TIE coprocessors contiguous from zero (for Tor2) */
  177. extern const unsigned int Xthal_num_coprocessors;
  178. /* actual number of coprocessors */
  179. extern const unsigned char Xthal_cp_num;
  180. /* index of highest numbered coprocessor, plus one */
  181. extern const unsigned char Xthal_cp_max;
  182. /* index of highest allowed coprocessor number, per cfg, plus one */
  183. /*extern const unsigned char Xthal_cp_maxcfg;*/
  184. /* bitmask of which coprocessors are present */
  185. extern const unsigned int Xthal_cp_mask;
  186. /* read & write extra state register */
  187. /*extern int xthal_read_extra(void *base, unsigned reg, unsigned *value);*/
  188. /*extern int xthal_write_extra(void *base, unsigned reg, unsigned value);*/
  189. /* read & write a TIE coprocessor register */
  190. /*extern int xthal_read_cpreg(void *base, int cp, unsigned reg, unsigned *value);*/
  191. /*extern int xthal_write_cpreg(void *base, int cp, unsigned reg, unsigned value);*/
  192. /* return coprocessor number based on register */
  193. /*extern int xthal_which_cp(unsigned reg);*/
  194. /*----------------------------------------------------------------------
  195. Register Windows
  196. ----------------------------------------------------------------------*/
  197. /* number of registers in register window */
  198. extern const unsigned int Xthal_num_aregs;
  199. extern const unsigned char Xthal_num_aregs_log2;
  200. /*----------------------------------------------------------------------
  201. Cache
  202. ----------------------------------------------------------------------*/
  203. /* size of the cache lines in log2(bytes) */
  204. extern const unsigned char Xthal_icache_linewidth;
  205. extern const unsigned char Xthal_dcache_linewidth;
  206. /* size of the cache lines in bytes (2^linewidth) */
  207. extern const unsigned short Xthal_icache_linesize;
  208. extern const unsigned short Xthal_dcache_linesize;
  209. /* size of the caches in bytes (ways * 2^(linewidth + setwidth)) */
  210. extern const unsigned int Xthal_icache_size;
  211. extern const unsigned int Xthal_dcache_size;
  212. /* cache features */
  213. extern const unsigned char Xthal_dcache_is_writeback;
  214. /* cache region operations*/
  215. extern void xthal_icache_region_invalidate( void *addr, unsigned size );
  216. extern void xthal_dcache_region_invalidate( void *addr, unsigned size );
  217. extern void xthal_dcache_region_writeback( void *addr, unsigned size );
  218. extern void xthal_dcache_region_writeback_inv( void *addr, unsigned size );
  219. #ifndef XTHAL_USE_CACHE_MACROS
  220. /* cache line operations*/
  221. extern void xthal_icache_line_invalidate(void *addr);
  222. extern void xthal_dcache_line_invalidate(void *addr);
  223. extern void xthal_dcache_line_writeback(void *addr);
  224. extern void xthal_dcache_line_writeback_inv(void *addr);
  225. /* sync icache and memory */
  226. extern void xthal_icache_sync( void );
  227. /* sync dcache and memory */
  228. extern void xthal_dcache_sync( void );
  229. #endif
  230. /* get/set number of icache ways enabled */
  231. extern unsigned int xthal_icache_get_ways(void);
  232. extern void xthal_icache_set_ways(unsigned int ways);
  233. /* get/set number of dcache ways enabled */
  234. extern unsigned int xthal_dcache_get_ways(void);
  235. extern void xthal_dcache_set_ways(unsigned int ways);
  236. /* coherency (low-level -- not normally called directly) */
  237. extern void xthal_cache_coherence_on( void );
  238. extern void xthal_cache_coherence_off( void );
  239. /* coherency (high-level) */
  240. extern void xthal_cache_coherence_optin( void );
  241. extern void xthal_cache_coherence_optout( void );
  242. /*
  243. * Cache prefetch control.
  244. * The parameter to xthal_set_cache_prefetch() contains both
  245. * a PREFCTL register value and a mask of which bits to actually modify.
  246. * This allows easily combining field macros (below) by ORing,
  247. * leaving unspecified fields unmodified.
  248. *
  249. * For backward compatibility with the older version of this routine
  250. * (that took 15-bit value and mask in a 32-bit parameter, for pre-RF
  251. * cores with only the lower 15 bits of PREFCTL defined), the 32-bit
  252. * value and mask are staggered as follows in a 64-bit parameter:
  253. * param[63:48] are PREFCTL[31:16] if param[31] is set
  254. * param[47:32] are mask[31:16] if param[31] is set
  255. * param[31] is set if mask is used, 0 if not
  256. * param[31:16] are mask[15:0] if param[31] is set
  257. * param[31:16] are PREFCTL[31:16] if param[31] is clear
  258. * param[15:0] are PREFCTL[15:0]
  259. *
  260. * Limitation: PREFCTL register bit 31 cannot be set without masking,
  261. * and bit 15 must always be set when using masking, so it is hoped that
  262. * these two bits will remain reserved, read-as-zero in PREFCTL.
  263. */
  264. #define XTHAL_PREFETCH_ENABLE -1 /* enable inst+data prefetch */
  265. #define XTHAL_PREFETCH_DISABLE 0xFFFF0000 /* disab inst+data prefetch*/
  266. #define XTHAL_DCACHE_PREFETCH(n) (0x800F0000+((n)&0xF)) /* data-side */
  267. #define XTHAL_DCACHE_PREFETCH_OFF XTHAL_DCACHE_PREFETCH(0) /* disable */
  268. #define XTHAL_DCACHE_PREFETCH_LOW XTHAL_DCACHE_PREFETCH(4) /* less aggr.*/
  269. #define XTHAL_DCACHE_PREFETCH_MEDIUM XTHAL_DCACHE_PREFETCH(5) /* mid aggr. */
  270. #define XTHAL_DCACHE_PREFETCH_HIGH XTHAL_DCACHE_PREFETCH(8) /* more aggr.*/
  271. #define XTHAL_DCACHE_PREFETCH_L1_OFF 0x90000000 /* to prefetch buffers*/
  272. #define XTHAL_DCACHE_PREFETCH_L1 0x90001000 /* direct to L1 dcache*/
  273. #define XTHAL_ICACHE_PREFETCH(n) (0x80F00000+(((n)&0xF)<<4)) /* i-side */
  274. #define XTHAL_ICACHE_PREFETCH_OFF XTHAL_ICACHE_PREFETCH(0) /* disable */
  275. #define XTHAL_ICACHE_PREFETCH_LOW XTHAL_ICACHE_PREFETCH(4) /* less aggr.*/
  276. #define XTHAL_ICACHE_PREFETCH_MEDIUM XTHAL_ICACHE_PREFETCH(5) /* mid aggr. */
  277. #define XTHAL_ICACHE_PREFETCH_HIGH XTHAL_ICACHE_PREFETCH(8) /* more aggr.*/
  278. #define XTHAL_ICACHE_PREFETCH_L1_OFF 0xA0000000 /* (not implemented) */
  279. #define XTHAL_ICACHE_PREFETCH_L1 0xA0002000 /* (not implemented) */
  280. #define _XTHAL_PREFETCH_BLOCKS(n) ((n)<0?0:(n)<5?(n):(n)<15?((n)>>1)+2:9)
  281. #define XTHAL_PREFETCH_BLOCKS(n) (0x0000000F80000000ULL + \
  282. (((unsigned long long)_XTHAL_PREFETCH_BLOCKS(n))<<48))
  283. extern int xthal_get_cache_prefetch( void );
  284. extern int xthal_set_cache_prefetch( int );
  285. extern int xthal_set_cache_prefetch_long( unsigned long long );
  286. /* Only use the new extended function from now on: */
  287. #define xthal_set_cache_prefetch xthal_set_cache_prefetch_long
  288. #define xthal_set_cache_prefetch_nw xthal_set_cache_prefetch_long_nw
  289. /*----------------------------------------------------------------------
  290. Debug
  291. ----------------------------------------------------------------------*/
  292. /* 1 if debug option configured, 0 if not: */
  293. extern const int Xthal_debug_configured;
  294. /* Set (plant) and remove software breakpoint, both synchronizing cache: */
  295. extern unsigned int xthal_set_soft_break(void *addr);
  296. extern void xthal_remove_soft_break(void *addr, unsigned int);
  297. /*----------------------------------------------------------------------
  298. Disassembler
  299. ----------------------------------------------------------------------*/
  300. /* Max expected size of the return buffer for a disassembled instruction (hint only): */
  301. #define XTHAL_DISASM_BUFSIZE 80
  302. /* Disassembly option bits for selecting what to return: */
  303. #define XTHAL_DISASM_OPT_ADDR 0x0001 /* display address */
  304. #define XTHAL_DISASM_OPT_OPHEX 0x0002 /* display opcode bytes in hex */
  305. #define XTHAL_DISASM_OPT_OPCODE 0x0004 /* display opcode name (mnemonic) */
  306. #define XTHAL_DISASM_OPT_PARMS 0x0008 /* display parameters */
  307. #define XTHAL_DISASM_OPT_ALL 0x0FFF /* display everything */
  308. /* routine to get a string for the disassembled instruction */
  309. extern int xthal_disassemble( unsigned char *instr_buf, void *tgt_addr,
  310. char *buffer, unsigned buflen, unsigned options );
  311. /* routine to get the size of the next instruction. Returns 0 for
  312. illegal instruction */
  313. extern int xthal_disassemble_size( unsigned char *instr_buf );
  314. /*----------------------------------------------------------------------
  315. Instruction/Data RAM/ROM Access
  316. ----------------------------------------------------------------------*/
  317. extern void* xthal_memcpy(void *dst, const void *src, unsigned len);
  318. extern void* xthal_bcopy(const void *src, void *dst, unsigned len);
  319. /*----------------------------------------------------------------------
  320. MP Synchronization
  321. ----------------------------------------------------------------------*/
  322. extern int xthal_compare_and_set( int *addr, int test_val, int compare_val );
  323. /*extern const char Xthal_have_s32c1i;*/
  324. /*----------------------------------------------------------------------
  325. Miscellaneous
  326. ----------------------------------------------------------------------*/
  327. extern const unsigned int Xthal_release_major;
  328. extern const unsigned int Xthal_release_minor;
  329. extern const char * const Xthal_release_name;
  330. extern const char * const Xthal_release_internal;
  331. extern const unsigned char Xthal_memory_order;
  332. extern const unsigned char Xthal_have_windowed;
  333. extern const unsigned char Xthal_have_density;
  334. extern const unsigned char Xthal_have_booleans;
  335. extern const unsigned char Xthal_have_loops;
  336. extern const unsigned char Xthal_have_nsa;
  337. extern const unsigned char Xthal_have_minmax;
  338. extern const unsigned char Xthal_have_sext;
  339. extern const unsigned char Xthal_have_clamps;
  340. extern const unsigned char Xthal_have_mac16;
  341. extern const unsigned char Xthal_have_mul16;
  342. extern const unsigned char Xthal_have_fp;
  343. extern const unsigned char Xthal_have_speculation;
  344. extern const unsigned char Xthal_have_threadptr;
  345. extern const unsigned char Xthal_have_pif;
  346. extern const unsigned short Xthal_num_writebuffer_entries;
  347. extern const unsigned int Xthal_build_unique_id;
  348. /* Version info for hardware targeted by software upgrades: */
  349. extern const unsigned int Xthal_hw_configid0;
  350. extern const unsigned int Xthal_hw_configid1;
  351. extern const unsigned int Xthal_hw_release_major;
  352. extern const unsigned int Xthal_hw_release_minor;
  353. extern const char * const Xthal_hw_release_name;
  354. extern const char * const Xthal_hw_release_internal;
  355. /* Clear any remnant code-dependent state (i.e. clear loop count regs). */
  356. extern void xthal_clear_regcached_code( void );
  357. #ifdef __cplusplus
  358. }
  359. #endif
  360. #endif /*!_ASMLANGUAGE && !_NOCLANGUAGE && !__ASSEMBLER__ */
  361. /****************************************************************************
  362. Definitions Useful for PRIVILEGED (Supervisory or Non-Virtualized) Code
  363. ****************************************************************************/
  364. #ifndef XTENSA_HAL_NON_PRIVILEGED_ONLY
  365. /*----------------------------------------------------------------------
  366. Constant Definitions (shared with assembly)
  367. ----------------------------------------------------------------------*/
  368. /*
  369. * Architectural limits, independent of configuration.
  370. * Note that these are ISA-defined limits, not micro-architecture implementation
  371. * limits enforced by the Xtensa Processor Generator (which may be stricter than
  372. * these below).
  373. */
  374. #define XTHAL_MAX_INTERRUPTS 32 /* max number of interrupts (0..31) */
  375. #define XTHAL_MAX_INTLEVELS 16 /* max number of interrupt levels (0..15) */
  376. /* (as of T1040, implementation limit is 7: 0..6) */
  377. #define XTHAL_MAX_TIMERS 4 /* max number of timers (CCOMPARE0..CCOMPARE3) */
  378. /* (as of T1040, implementation limit is 3: 0..2) */
  379. /* Interrupt types: */
  380. #define XTHAL_INTTYPE_UNCONFIGURED 0
  381. #define XTHAL_INTTYPE_SOFTWARE 1
  382. #define XTHAL_INTTYPE_EXTERN_EDGE 2
  383. #define XTHAL_INTTYPE_EXTERN_LEVEL 3
  384. #define XTHAL_INTTYPE_TIMER 4
  385. #define XTHAL_INTTYPE_NMI 5
  386. #define XTHAL_INTTYPE_WRITE_ERROR 6
  387. #define XTHAL_INTTYPE_PROFILING 7
  388. #define XTHAL_INTTYPE_IDMA_DONE 8
  389. #define XTHAL_INTTYPE_IDMA_ERR 9
  390. #define XTHAL_INTTYPE_GS_ERR 10
  391. #define XTHAL_INTTYPE_SG_ERR 10 /* backward compatibility name - deprecated */
  392. #define XTHAL_MAX_INTTYPES 11 /* number of interrupt types */
  393. /* Timer related: */
  394. #define XTHAL_TIMER_UNCONFIGURED -1 /* Xthal_timer_interrupt[] value for non-existent timers */
  395. #define XTHAL_TIMER_UNASSIGNED XTHAL_TIMER_UNCONFIGURED /* (for backwards compatibility only) */
  396. /* Local Memory ECC/Parity: */
  397. #define XTHAL_MEMEP_PARITY 1
  398. #define XTHAL_MEMEP_ECC 2
  399. /* Flags parameter to xthal_memep_inject_error(): */
  400. #define XTHAL_MEMEP_F_LOCAL 0 /* local memory (default) */
  401. #define XTHAL_MEMEP_F_DCACHE_DATA 4 /* data cache data */
  402. #define XTHAL_MEMEP_F_DCACHE_TAG 5 /* data cache tag */
  403. #define XTHAL_MEMEP_F_ICACHE_DATA 6 /* instruction cache data */
  404. #define XTHAL_MEMEP_F_ICACHE_TAG 7 /* instruction cache tag */
  405. #define XTHAL_MEMEP_F_CORRECTABLE 16 /* inject correctable error
  406. (default is non-corr.) */
  407. /* Access Mode bits (tentative): */ /* bit abbr unit short_name PPC equ - Description */
  408. #define XTHAL_AMB_EXCEPTION 0 /* 001 E EX fls: EXception none
  409. exception on any access (aka "illegal") */
  410. #define XTHAL_AMB_HITCACHE 1 /* 002 C CH fls: use Cache on Hit ~(I CI)
  411. [or H HC] way from tag match;
  412. [or U UC] (ISA: same except Isolate case) */
  413. #define XTHAL_AMB_ALLOCATE 2 /* 004 A AL fl?: ALlocate none
  414. [or F FI fill] refill cache on miss, way from LRU
  415. (ISA: Read/Write Miss Refill) */
  416. #define XTHAL_AMB_WRITETHRU 3 /* 008 W WT --s: WriteThrough W WT
  417. store immediately to memory (ISA: same) */
  418. #define XTHAL_AMB_ISOLATE 4 /* 010 I IS fls: ISolate none
  419. use cache regardless of hit-vs-miss,
  420. way from vaddr (ISA: use-cache-on-miss+hit) */
  421. #define XTHAL_AMB_GUARD 5 /* 020 G GU ?l?: GUard G *
  422. non-speculative; spec/replay refs not permitted */
  423. #define XTHAL_AMB_COHERENT 6 /* 040 M MC ?ls: Mem/MP Coherent M
  424. on read, other CPU/bus-master may need to supply data;
  425. on write, maybe redirect to or flush other CPU dirty line; etc */
  426. #if 0
  427. #define XTHAL_AMB_BUFFERABLE x /* 000 B BU --s: BUfferable ?
  428. write response may return earlier than from final destination */
  429. #define XTHAL_AMB_ORDERED x /* 000 O OR fls: ORdered G *
  430. mem accesses cannot be out of order */
  431. #define XTHAL_AMB_FUSEWRITES x /* 000 F FW --s: FuseWrites none
  432. allow combining/merging/coalescing multiple writes
  433. (to same datapath data unit) into one
  434. (implied by writeback) */
  435. #define XTHAL_AMB_TRUSTED x /* 000 T TR ?l?: TRusted none
  436. memory will not bus error (if it does,
  437. handle as fatal imprecise interrupt) */
  438. #define XTHAL_AMB_PREFETCH x /* 000 P PR fl?: PRefetch none
  439. on refill, read line+1 into prefetch buffers */
  440. #define XTHAL_AMB_STREAM x /* 000 S ST ???: STreaming none
  441. access one of N stream buffers */
  442. #endif /*0*/
  443. #define XTHAL_AM_EXCEPTION (1<<XTHAL_AMB_EXCEPTION)
  444. #define XTHAL_AM_HITCACHE (1<<XTHAL_AMB_HITCACHE)
  445. #define XTHAL_AM_ALLOCATE (1<<XTHAL_AMB_ALLOCATE)
  446. #define XTHAL_AM_WRITETHRU (1<<XTHAL_AMB_WRITETHRU)
  447. #define XTHAL_AM_ISOLATE (1<<XTHAL_AMB_ISOLATE)
  448. #define XTHAL_AM_GUARD (1<<XTHAL_AMB_GUARD)
  449. #define XTHAL_AM_COHERENT (1<<XTHAL_AMB_COHERENT)
  450. #if 0
  451. #define XTHAL_AM_BUFFERABLE (1<<XTHAL_AMB_BUFFERABLE)
  452. #define XTHAL_AM_ORDERED (1<<XTHAL_AMB_ORDERED)
  453. #define XTHAL_AM_FUSEWRITES (1<<XTHAL_AMB_FUSEWRITES)
  454. #define XTHAL_AM_TRUSTED (1<<XTHAL_AMB_TRUSTED)
  455. #define XTHAL_AM_PREFETCH (1<<XTHAL_AMB_PREFETCH)
  456. #define XTHAL_AM_STREAM (1<<XTHAL_AMB_STREAM)
  457. #endif /*0*/
  458. /*
  459. * Allowed Access Modes (bit combinations).
  460. *
  461. * Columns are:
  462. * "FOGIWACE"
  463. * Access mode bits (see XTHAL_AMB_xxx above).
  464. * <letter> = bit is set
  465. * '-' = bit is clear
  466. * '.' = bit is irrelevant / don't care, as follows:
  467. * E=1 makes all others irrelevant
  468. * W,F relevant only for stores
  469. * "2345"
  470. * Indicates which Xtensa releases support the corresponding
  471. * access mode. Releases for each character column are:
  472. * 2 = prior to T1020.2: T1015 (V1.5), T1020.0, T1020.1
  473. * 3 = T1020.2 and later: T1020.2+, T1030
  474. * 4 = T1040
  475. * 5 = T1050 (maybe), LX1, LX2, LX2.1
  476. * 7 = LX2.2
  477. * 8 = LX3, LX4
  478. * 9 = LX5
  479. * And the character column contents are:
  480. * <number> = supported by release(s)
  481. * "." = unsupported by release(s)
  482. * "?" = support unknown
  483. */
  484. /* foMGIWACE 2345789 */
  485. /* For instruction fetch: */
  486. #define XTHAL_FAM_EXCEPTION 0x001 /* ........E 2345789 exception */
  487. /*efine XTHAL_FAM_ISOLATE*/ /*0x012*/ /* .---I.-C- ....... isolate */
  488. #define XTHAL_FAM_BYPASS 0x000 /* .----.--- 2345789 bypass */
  489. /*efine XTHAL_FAM_NACACHED*/ /*0x002*/ /* .----.-C- ....... cached no-allocate (frozen) */
  490. #define XTHAL_FAM_CACHED 0x006 /* .----.AC- 2345789 cached */
  491. /* For data load: */
  492. #define XTHAL_LAM_EXCEPTION 0x001 /* ........E 2345789 exception */
  493. #define XTHAL_LAM_ISOLATE 0x012 /* .---I.-C- 2345789 isolate */
  494. #define XTHAL_LAM_BYPASS 0x000 /* .O---.--- 2...... bypass speculative */
  495. #define XTHAL_LAM_BYPASSG 0x020 /* .O-G-.--- .345789 bypass guarded */
  496. #define XTHAL_LAM_CACHED_NOALLOC 0x002 /* .O---.-C- 2345789 cached no-allocate speculative */
  497. #define XTHAL_LAM_NACACHED XTHAL_LAM_CACHED_NOALLOC
  498. #define XTHAL_LAM_NACACHEDG 0x022 /* .O-G-.-C- .?..... cached no-allocate guarded */
  499. #define XTHAL_LAM_CACHED 0x006 /* .----.AC- 2345789 cached speculative */
  500. #define XTHAL_LAM_COHCACHED 0x046 /* .-M--.AC- ....*89 cached speculative MP-coherent */
  501. /* For data store: */
  502. #define XTHAL_SAM_EXCEPTION 0x001 /* ........E 2345789 exception */
  503. #define XTHAL_SAM_ISOLATE 0x032 /* .--GI--C- 2345789 isolate */
  504. #define XTHAL_SAM_BYPASS 0x028 /* -O-G-W--- 2345789 bypass */
  505. #define XTHAL_SAM_WRITETHRU 0x02A /* -O-G-W-C- 2345789 writethrough */
  506. /*efine XTHAL_SAM_WRITETHRU_ALLOC*/ /*0x02E*/ /* -O-G-WAC- ....... writethrough allocate */
  507. #define XTHAL_SAM_WRITEBACK 0x026 /* F--G--AC- ...5789 writeback */
  508. #define XTHAL_SAM_WRITEBACK_NOALLOC 0x022 /* ?--G---C- .....89 writeback no-allocate */
  509. #define XTHAL_SAM_COHWRITEBACK 0x066 /* F-MG--AC- ....*89 writeback MP-coherent */
  510. /* For PIF attributes: */ /* -PIwrWCBUUUU ...9 */
  511. #define XTHAL_PAM_BYPASS 0x000 /* xxx00000xxxx ...9 bypass non-bufferable */
  512. #define XTHAL_PAM_BYPASS_BUF 0x010 /* xxx0000bxxxx ...9 bypass */
  513. #define XTHAL_PAM_CACHED_NOALLOC 0x030 /* xxx0001bxxxx ...9 cached no-allocate */
  514. #define XTHAL_PAM_WRITETHRU 0x0B0 /* xxx0101bxxxx ...9 writethrough (WT) */
  515. #define XTHAL_PAM_WRITEBACK_NOALLOC 0x0F0 /* xxx0111bxxxx ...9 writeback no-alloc (WBNA) */
  516. #define XTHAL_PAM_WRITEBACK 0x1F0 /* xxx1111bxxxx ...9 writeback (WB) */
  517. /*efine XTHAL_PAM_NORMAL*/ /*0x050*/ /* xxx0010bxxxx .... (unimplemented) */
  518. /*efine XTHAL_PAM_WRITETHRU_WA*/ /*0x130*/ /* xxx1001bxxxx .... (unimplemented, less likely) */
  519. /*efine XTHAL_PAM_WRITETHRU_RWA*/ /*0x1B0*/ /* xxx1101bxxxx .... (unimplemented, less likely) */
  520. /*efine XTHAL_PAM_WRITEBACK_WA*/ /*0x170*/ /* xxx1011bxxxx .... (unimplemented, less likely) */
  521. #if 0
  522. /*
  523. Cache attribute encoding for CACHEATTR (per ISA):
  524. (Note: if this differs from ISA Ref Manual, ISA has precedence)
  525. Inst-fetches Loads Stores
  526. ------------- ------------ -------------
  527. 0x0 FCA_EXCEPTION LCA_NACACHED SCA_WRITETHRU cached no-allocate (previously misnamed "uncached")
  528. 0x1 FCA_CACHED LCA_CACHED SCA_WRITETHRU cached
  529. 0x2 FCA_BYPASS LCA_BYPASS_G* SCA_BYPASS bypass cache (what most people call uncached)
  530. 0x3 FCA_CACHED LCA_CACHED SCA_WRITEALLOCF write-allocate
  531. or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
  532. 0x4 FCA_CACHED LCA_CACHED SCA_WRITEBACK[M] write-back [MP-coherent]
  533. or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
  534. 0x5 FCA_CACHED LCA_CACHED SCA_WRITEBACK_NOALLOC write-back no-allocate
  535. or FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
  536. 0x6..D FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION (reserved)
  537. 0xE FCA_EXCEPTION LCA_ISOLATE SCA_ISOLATE isolate
  538. 0xF FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION illegal
  539. * Prior to T1020.2?, guard feature not supported, this defaulted to speculative (no _G)
  540. */
  541. #endif /*0*/
  542. #if !defined(_ASMLANGUAGE) && !defined(_NOCLANGUAGE) && !defined(__ASSEMBLER__)
  543. #ifdef __cplusplus
  544. extern "C" {
  545. #endif
  546. /*----------------------------------------------------------------------
  547. Register Windows
  548. ----------------------------------------------------------------------*/
  549. /* This spill any live register windows (other than the caller's):
  550. * (NOTE: current implementation require privileged code, but
  551. * a user-callable implementation is possible.) */
  552. extern void xthal_window_spill( void );
  553. /*----------------------------------------------------------------------
  554. Optional/Custom Processor State
  555. ----------------------------------------------------------------------*/
  556. /* validate & invalidate the TIE register file */
  557. extern void xthal_validate_cp(int);
  558. extern void xthal_invalidate_cp(int);
  559. /* read and write cpenable register */
  560. extern void xthal_set_cpenable(unsigned);
  561. extern unsigned xthal_get_cpenable(void);
  562. /*----------------------------------------------------------------------
  563. Interrupts
  564. ----------------------------------------------------------------------*/
  565. /* the number of interrupt levels */
  566. extern const unsigned char Xthal_num_intlevels;
  567. /* the number of interrupts */
  568. extern const unsigned char Xthal_num_interrupts;
  569. /* the highest level of interrupts masked by PS.EXCM */
  570. extern const unsigned char Xthal_excm_level;
  571. /* mask for level of interrupts */
  572. extern const unsigned int Xthal_intlevel_mask[XTHAL_MAX_INTLEVELS];
  573. /* mask for level 0 to N interrupts */
  574. extern const unsigned int Xthal_intlevel_andbelow_mask[XTHAL_MAX_INTLEVELS];
  575. /* level of each interrupt */
  576. extern const unsigned char Xthal_intlevel[XTHAL_MAX_INTERRUPTS];
  577. /* type per interrupt */
  578. extern const unsigned char Xthal_inttype[XTHAL_MAX_INTERRUPTS];
  579. /* masks of each type of interrupt */
  580. extern const unsigned int Xthal_inttype_mask[XTHAL_MAX_INTTYPES];
  581. /* interrupt numbers assigned to each timer interrupt */
  582. extern const int Xthal_timer_interrupt[XTHAL_MAX_TIMERS];
  583. /* INTENABLE,INTERRUPT,INTSET,INTCLEAR register access functions: */
  584. extern unsigned xthal_get_intenable( void );
  585. extern void xthal_set_intenable( unsigned );
  586. extern unsigned xthal_get_interrupt( void );
  587. #define xthal_get_intread xthal_get_interrupt /* backward compatibility */
  588. /* These two functions are deprecated. Use the newer functions
  589. xthal_interrupt_trigger and xthal_interrupt_clear instead. */
  590. extern void xthal_set_intset( unsigned );
  591. extern void xthal_set_intclear( unsigned );
  592. /*----------------------------------------------------------------------
  593. Debug
  594. ----------------------------------------------------------------------*/
  595. /* Number of instruction and data break registers: */
  596. extern const int Xthal_num_ibreak;
  597. extern const int Xthal_num_dbreak;
  598. /*----------------------------------------------------------------------
  599. Core Counter
  600. ----------------------------------------------------------------------*/
  601. /* counter info */
  602. extern const unsigned char Xthal_have_ccount; /* set if CCOUNT register present */
  603. extern const unsigned char Xthal_num_ccompare; /* number of CCOMPAREn registers */
  604. /* get CCOUNT register (if not present return 0) */
  605. extern unsigned xthal_get_ccount(void);
  606. /* set and get CCOMPAREn registers (if not present, get returns 0) */
  607. extern void xthal_set_ccompare(int, unsigned);
  608. extern unsigned xthal_get_ccompare(int);
  609. /*----------------------------------------------------------------------
  610. Miscellaneous
  611. ----------------------------------------------------------------------*/
  612. extern const unsigned char Xthal_have_prid;
  613. extern const unsigned char Xthal_have_exceptions;
  614. extern const unsigned char Xthal_xea_version;
  615. extern const unsigned char Xthal_have_interrupts;
  616. extern const unsigned char Xthal_have_highlevel_interrupts;
  617. extern const unsigned char Xthal_have_nmi;
  618. extern unsigned xthal_get_prid( void );
  619. /*----------------------------------------------------------------------
  620. Virtual interrupt prioritization (DEPRECATED)
  621. ----------------------------------------------------------------------*/
  622. /* Convert between interrupt levels (as per PS.INTLEVEL) and virtual interrupt priorities: */
  623. extern unsigned xthal_vpri_to_intlevel(unsigned vpri);
  624. extern unsigned xthal_intlevel_to_vpri(unsigned intlevel);
  625. /* Enables/disables given set (mask) of interrupts; returns previous enabled-mask of all ints: */
  626. /* These functions are deprecated. Use xthal_interrupt_enable and xthal_interrupt_disable instead. */
  627. extern unsigned xthal_int_enable(unsigned);
  628. extern unsigned xthal_int_disable(unsigned);
  629. /* Set/get virtual priority of an interrupt: */
  630. extern int xthal_set_int_vpri(int intnum, int vpri);
  631. extern int xthal_get_int_vpri(int intnum);
  632. /* Set/get interrupt lockout level for exclusive access to virtual priority data structures: */
  633. extern void xthal_set_vpri_locklevel(unsigned intlevel);
  634. extern unsigned xthal_get_vpri_locklevel(void);
  635. /* Set/get current virtual interrupt priority: */
  636. extern unsigned xthal_set_vpri(unsigned vpri);
  637. extern unsigned xthal_get_vpri(void);
  638. extern unsigned xthal_set_vpri_intlevel(unsigned intlevel);
  639. extern unsigned xthal_set_vpri_lock(void);
  640. /*----------------------------------------------------------------------
  641. Generic Interrupt Trampolining Support (DEPRECATED)
  642. ----------------------------------------------------------------------*/
  643. typedef void (XtHalVoidFunc)(void);
  644. /* Bitmask of interrupts currently trampolining down: */
  645. extern unsigned Xthal_tram_pending;
  646. /*
  647. * Bitmask of which interrupts currently trampolining down synchronously are
  648. * actually enabled; this bitmask is necessary because INTENABLE cannot hold
  649. * that state (sync-trampolining interrupts must be kept disabled while
  650. * trampolining); in the current implementation, any bit set here is not set
  651. * in INTENABLE, and vice-versa; once a sync-trampoline is handled (at level
  652. * one), its enable bit must be moved from here to INTENABLE:
  653. */
  654. extern unsigned Xthal_tram_enabled;
  655. /* Bitmask of interrupts configured for sync trampolining: */
  656. extern unsigned Xthal_tram_sync;
  657. /* Trampoline support functions: */
  658. extern unsigned xthal_tram_pending_to_service( void );
  659. extern void xthal_tram_done( unsigned serviced_mask );
  660. extern int xthal_tram_set_sync( int intnum, int sync );
  661. extern XtHalVoidFunc* xthal_set_tram_trigger_func( XtHalVoidFunc *trigger_fn );
  662. /*----------------------------------------------------------------------
  663. Internal Memories
  664. ----------------------------------------------------------------------*/
  665. extern const unsigned char Xthal_num_instrom;
  666. extern const unsigned char Xthal_num_instram;
  667. extern const unsigned char Xthal_num_datarom;
  668. extern const unsigned char Xthal_num_dataram;
  669. extern const unsigned char Xthal_num_xlmi;
  670. /* Each of the following arrays contains at least one entry,
  671. * or as many entries as needed if more than one: */
  672. extern const unsigned int Xthal_instrom_vaddr[];
  673. extern const unsigned int Xthal_instrom_paddr[];
  674. extern const unsigned int Xthal_instrom_size [];
  675. extern const unsigned int Xthal_instram_vaddr[];
  676. extern const unsigned int Xthal_instram_paddr[];
  677. extern const unsigned int Xthal_instram_size [];
  678. extern const unsigned int Xthal_datarom_vaddr[];
  679. extern const unsigned int Xthal_datarom_paddr[];
  680. extern const unsigned int Xthal_datarom_size [];
  681. extern const unsigned int Xthal_dataram_vaddr[];
  682. extern const unsigned int Xthal_dataram_paddr[];
  683. extern const unsigned int Xthal_dataram_size [];
  684. extern const unsigned int Xthal_xlmi_vaddr[];
  685. extern const unsigned int Xthal_xlmi_paddr[];
  686. extern const unsigned int Xthal_xlmi_size [];
  687. /*----------------------------------------------------------------------
  688. Cache
  689. ----------------------------------------------------------------------*/
  690. /* number of cache sets in log2(lines per way) */
  691. extern const unsigned char Xthal_icache_setwidth;
  692. extern const unsigned char Xthal_dcache_setwidth;
  693. /* cache set associativity (number of ways) */
  694. extern const unsigned int Xthal_icache_ways;
  695. extern const unsigned int Xthal_dcache_ways;
  696. /* cache features */
  697. extern const unsigned char Xthal_icache_line_lockable;
  698. extern const unsigned char Xthal_dcache_line_lockable;
  699. /* cache attribute register control (used by other HAL routines) */
  700. extern unsigned xthal_get_cacheattr( void );
  701. extern unsigned xthal_get_icacheattr( void );
  702. extern unsigned xthal_get_dcacheattr( void );
  703. extern void xthal_set_cacheattr( unsigned );
  704. extern void xthal_set_icacheattr( unsigned );
  705. extern void xthal_set_dcacheattr( unsigned );
  706. /* set cache attribute (access modes) for a range of memory */
  707. extern int xthal_set_region_attribute( void *addr, unsigned size,
  708. unsigned cattr, unsigned flags );
  709. /* Bits of flags parameter to xthal_set_region_attribute(): */
  710. #define XTHAL_CAFLAG_EXPAND 0x000100 /* only expand allowed access to range, don't reduce it */
  711. #define XTHAL_CAFLAG_EXACT 0x000200 /* return error if can't apply change to exact range specified */
  712. #define XTHAL_CAFLAG_NO_PARTIAL 0x000400 /* don't apply change to regions partially covered by range */
  713. #define XTHAL_CAFLAG_NO_AUTO_WB 0x000800 /* don't writeback data after leaving writeback attribute */
  714. #define XTHAL_CAFLAG_NO_AUTO_INV 0x001000 /* don't invalidate after disabling cache (entering bypass) */
  715. /* enable caches */
  716. extern void xthal_icache_enable( void ); /* DEPRECATED */
  717. extern void xthal_dcache_enable( void ); /* DEPRECATED */
  718. /* disable caches */
  719. extern void xthal_icache_disable( void ); /* DEPRECATED */
  720. extern void xthal_dcache_disable( void ); /* DEPRECATED */
  721. /* whole cache operations (privileged) */
  722. extern void xthal_icache_all_invalidate( void );
  723. extern void xthal_dcache_all_invalidate( void );
  724. extern void xthal_dcache_all_writeback( void );
  725. extern void xthal_dcache_all_writeback_inv( void );
  726. extern void xthal_icache_all_unlock( void );
  727. extern void xthal_dcache_all_unlock( void );
  728. /* address-range cache operations (privileged) */
  729. /* prefetch and lock specified memory range into cache */
  730. extern void xthal_icache_region_lock( void *addr, unsigned size );
  731. extern void xthal_dcache_region_lock( void *addr, unsigned size );
  732. /* unlock from cache */
  733. extern void xthal_icache_region_unlock( void *addr, unsigned size );
  734. extern void xthal_dcache_region_unlock( void *addr, unsigned size );
  735. /* huge-range cache operations (privileged) (EXPERIMENTAL) */
  736. extern void xthal_icache_hugerange_invalidate( void *addr, unsigned size );
  737. extern void xthal_icache_hugerange_unlock( void *addr, unsigned size );
  738. extern void xthal_dcache_hugerange_invalidate( void *addr, unsigned size );
  739. extern void xthal_dcache_hugerange_unlock( void *addr, unsigned size );
  740. extern void xthal_dcache_hugerange_writeback( void *addr, unsigned size );
  741. extern void xthal_dcache_hugerange_writeback_inv( void *addr, unsigned size );
  742. # ifndef XTHAL_USE_CACHE_MACROS
  743. /* cache line operations (privileged) */
  744. extern void xthal_icache_line_lock(void *addr);
  745. extern void xthal_dcache_line_lock(void *addr);
  746. extern void xthal_icache_line_unlock(void *addr);
  747. extern void xthal_dcache_line_unlock(void *addr);
  748. # endif
  749. /*----------------------------------------------------------------------
  750. Local Memory ECC/Parity
  751. ----------------------------------------------------------------------*/
  752. /* Inject memory errors; flags is bit combination of XTHAL_MEMEP_F_xxx: */
  753. extern void xthal_memep_inject_error(void *addr, int size, int flags);
  754. /*----------------------------------------------------------------------
  755. Memory Management Unit
  756. ----------------------------------------------------------------------*/
  757. extern const unsigned char Xthal_have_spanning_way;
  758. extern const unsigned char Xthal_have_identity_map;
  759. extern const unsigned char Xthal_have_mimic_cacheattr;
  760. extern const unsigned char Xthal_have_xlt_cacheattr;
  761. extern const unsigned char Xthal_have_cacheattr;
  762. extern const unsigned char Xthal_have_tlbs;
  763. extern const unsigned char Xthal_mmu_asid_bits; /* 0 .. 8 */
  764. extern const unsigned char Xthal_mmu_asid_kernel;
  765. extern const unsigned char Xthal_mmu_rings; /* 1 .. 4 (perhaps 0 if no MMU and/or no protection?) */
  766. extern const unsigned char Xthal_mmu_ring_bits;
  767. extern const unsigned char Xthal_mmu_sr_bits;
  768. extern const unsigned char Xthal_mmu_ca_bits;
  769. extern const unsigned int Xthal_mmu_max_pte_page_size;
  770. extern const unsigned int Xthal_mmu_min_pte_page_size;
  771. extern const unsigned char Xthal_itlb_way_bits;
  772. extern const unsigned char Xthal_itlb_ways;
  773. extern const unsigned char Xthal_itlb_arf_ways;
  774. extern const unsigned char Xthal_dtlb_way_bits;
  775. extern const unsigned char Xthal_dtlb_ways;
  776. extern const unsigned char Xthal_dtlb_arf_ways;
  777. /* Return error codes for hal functions */
  778. /* function sucessful, operation completed as expected */
  779. #define XTHAL_SUCCESS 0
  780. /* XTHAL_CAFLAGS_NO_PARTIAL was specified, and no full region is
  781. * covered by the address range. */
  782. #define XTHAL_NO_REGIONS_COVERED -1
  783. /* The XTHAL_CAFLAGS_EXACT flag was given, but no exact mapping is possible. */
  784. #define XTHAL_INEXACT -2
  785. /* The supplied address doesn't correspond to the start of a region. */
  786. #define XTHAL_INVALID_ADDRESS -3
  787. /* This functionality is not available on this architecture. */
  788. #define XTHAL_UNSUPPORTED -4
  789. /* Translation failed because vaddr and paddr were not aligned. */
  790. #define XTHAL_ADDRESS_MISALIGNED -5
  791. /* There is mapping for the supplied address. */
  792. #define XTHAL_NO_MAPPING -6
  793. /* The requested access rights are not supported */
  794. #define XTHAL_BAD_ACCESS_RIGHTS -7
  795. /* The requested memory type is not supported */
  796. #define XTHAL_BAD_MEMORY_TYPE -8
  797. /* The entries supplied are not properly aligned to the MPU's background map. */
  798. #define XTHAL_MAP_NOT_ALIGNED -9
  799. /* There are not enough MPU entries available to do the requeste mapping. */
  800. #define XTHAL_OUT_OF_ENTRIES -10
  801. /* The entries supplied are not properly ordered for the MPU. */
  802. #define XTHAL_OUT_OF_ORDER_MAP -11
  803. /* an invalid argument such as a null pointer was supplied to the function */
  804. #define XTHAL_INVALID -12
  805. /* specified region is of zero size, therefore no mapping is done. */
  806. #define XTHAL_ZERO_SIZED_REGION -13
  807. /* specified range wraps around '0' */
  808. #define XTHAL_INVALID_ADDRESS_RANGE -14
  809. /*
  810. For backward compatibility we retain the following inconsistenly named
  811. constants. Do not use them as they may be removed in a future release.
  812. */
  813. #define XCHAL_SUCCESS XTHAL_SUCCESS
  814. #define XCHAL_ADDRESS_MISALIGNED XTHAL_ADDRESS_MISALIGNED
  815. #define XCHAL_INEXACT XTHAL_INEXACT
  816. #define XCHAL_INVALID_ADDRESS XTHAL_INVALID_ADDRESS
  817. #define XCHAL_UNSUPPORTED_ON_THIS_ARCH XTHAL_UNSUPPORTED
  818. #define XCHAL_NO_PAGES_MAPPED XTHAL_NO_REGIONS_COVERED
  819. /* Convert between virtual and physical addresses (through static maps only)
  820. * WARNING: these two functions may go away in a future release;
  821. * don't depend on them!
  822. */
  823. extern int xthal_static_v2p( unsigned vaddr, unsigned *paddrp );
  824. extern int xthal_static_p2v( unsigned paddr, unsigned *vaddrp, unsigned cached );
  825. extern int xthal_set_region_translation(void* vaddr, void* paddr,
  826. unsigned size, unsigned cache_atr, unsigned flags);
  827. extern int xthal_v2p(void*, void**, unsigned*, unsigned*);
  828. extern int xthal_invalidate_region(void* addr);
  829. extern int xthal_set_region_translation_raw(void *vaddr, void *paddr, unsigned cattr);
  830. /*------------------------------------------------------------------------
  831. MPU (Memory Protection Unit)
  832. -------------------------------------------------------------------------*/
  833. /*
  834. * General notes on MPU (Memory Protection Unit):
  835. *
  836. * The MPU supports setting the access rights (read, write, execute) as
  837. * well as the memory type (cacheablity, ...)
  838. * for regions of memory. The granularity can be as small as 32 bytes.
  839. * (XCHAL_MPU_ALIGN specifies the granularity for any specific MPU config)
  840. *
  841. * The MPU doesn't support mapping between virtual and physical addresses.
  842. *
  843. * The MPU contains a fixed number of map changeable forground map entries,
  844. * and a background map which is fixed at configuration time.
  845. *
  846. * Each entry has a start address (up to 27 bits), valid flag,
  847. * access rights (4 bits), and memory type (9 bits);
  848. *
  849. */
  850. /*
  851. MPU access rights constants:
  852. Only the combinations listed below are supported by the MPU.
  853. */
  854. #define XTHAL_AR_NONE 0 /* no access */
  855. #define XTHAL_AR_R 4 /* Kernel read, User no access*/
  856. #define XTHAL_AR_RX 5 /* Kernel read/execute, User no access */
  857. #define XTHAL_AR_RW 6 /* Kernel read/write, User no access */
  858. #define XTHAL_AR_RWX 7 /* Kernel read/write/execute, User no access */
  859. #define XTHAL_AR_Ww 8 /* Kernel write, User write */
  860. #define XTHAL_AR_RWrwx 9 /* Kernel read/write , User read/write/execute */
  861. #define XTHAL_AR_RWr 10 /* Kernel read/write, User read */
  862. #define XTHAL_AR_RWXrx 11 /* Kernel read/write/execute, User read/execute */
  863. #define XTHAL_AR_Rr 12 /* Kernel read, User read */
  864. #define XTHAL_AR_RXrx 13 /* Kernel read/execute, User read/execute */
  865. #define XTHAL_AR_RWrw 14 /* Kernel read/write, User read/write */
  866. #define XTHAL_AR_RWXrwx 15 /* Kernel read/write/execute,
  867. User read/write/execute */
  868. #define XTHAL_AR_WIDTH 4 /* # bits used to encode access rights */
  869. /* If the bit XTHAL_MPU_USE_EXISTING_ACCESS_RIGHTS is set in the accessRights
  870. * argument to xthal_mpu_set_region_attribute(), or to the cattr argument of
  871. * xthal_set_region_attribute() then the existing access rights for the first
  872. * byte of the region will be used as the access rights of the new region.
  873. */
  874. #define XTHAL_MPU_USE_EXISTING_ACCESS_RIGHTS 0x00002000
  875. /* If the bit XTHAL_MPU_USE_EXISTING_MEMORY_TYPE is set in the memoryType
  876. * argument to xthal_mpu_set_region_attribute(), or to the cattr argument of
  877. * xthal_set_region_attribute() then the existing memory type for the first
  878. * byte of the region will be used as the memory type of the new region.
  879. */
  880. #define XTHAL_MPU_USE_EXISTING_MEMORY_TYPE 0x00004000
  881. /* The following groups of constants are bit-wise or'd together to specify
  882. * the memory type as input to the macros and functions that accept an
  883. * unencoded memory type specifier:
  884. * XTHAL_ENCODE_MEMORY_TYPE, xthal_encode_memory_type,
  885. * xthal_mpu_set_region_attribute(), and xthal_set_region_attribute().
  886. *
  887. * example:
  888. * XTHAL_MEM_DEVICE | XTHAL_MEM_INTERRUPTIBLE | XTHAL_MEM_SYSTEM_SHARABLE
  889. *
  890. * or
  891. * XTHAL_MEM_WRITEBACK | XTHAL_MEM_INNER_SHAREABLE
  892. *
  893. * If it is desired to specify different attributes for the system and
  894. * local cache, then macro XTHAL_MEM_PROC_CACHE is used:
  895. *
  896. * XTHAL_MEM_PROC_CACHE(XTHAL_MEM_WRITEBACK, XTHAL_MEM_WRITETHRU)
  897. *
  898. * indicates the shared cache is writeback, but the processor's local cache
  899. * is writethrough.
  900. *
  901. */
  902. /* The following group of constants are used to specify cache attributes of
  903. * an MPU entry. If the processors local cache and the system's shared cache
  904. * have the same attributes (or if there aren't distinct local and shared
  905. * caches) then the constant can be used directly. If different attributes
  906. * for the shared and local caches, then use these constants as the parameters
  907. * to the XTHAL_MEM_PROC_CACHE() macro.
  908. */
  909. #define XTHAL_MEM_DEVICE 0x00008000
  910. #define XTHAL_MEM_NON_CACHEABLE 0x00090000
  911. #define XTHAL_MEM_WRITETHRU_NOALLOC 0x00080000
  912. #define XTHAL_MEM_WRITETHRU 0x00040000
  913. #define XTHAL_MEM_WRITETHRU_WRITEALLOC 0x00060000
  914. #define XTHAL_MEM_WRITEBACK_NOALLOC 0x00050000
  915. #define XTHAL_MEM_WRITEBACK 0x00070000
  916. /* Indicates a read is interruptible. Only applicable to devices */
  917. #define XTHAL_MEM_INTERRUPTIBLE 0x08000000
  918. /* Indicates if writes to this memory are bufferable ... only applicable
  919. * to devices, and non-cacheable memory.
  920. */
  921. #define XTHAL_MEM_BUFFERABLE 0x01000000
  922. /* The following group of constants indicates the scope of the sharing of
  923. * the memory region. XTHAL_MEM_INNER_SHAREABLE and XTHAL_MEM_OUTER_SHARABLE are
  924. * only applicable to cacheable regions. XTHAL_MEM_SYSTEM_SHAREABLE is only
  925. * applicable to devices and non-cacheable regions.
  926. */
  927. #define XTHAL_MEM_NON_SHAREABLE 0x00000000
  928. #define XTHAL_MEM_INNER_SHAREABLE 0x02000000
  929. #define XTHAL_MEM_OUTER_SHAREABLE 0x04000000
  930. #define XTHAL_MEM_SYSTEM_SHAREABLE 0x06000000
  931. /*
  932. * This macro is needed when the cache attributes are different for the shared
  933. * and processor's local caches. For example:
  934. *
  935. * XTHAL_MEM_PROC_CACHE(XTHAL_MEM_WRITEBACK, XTHAL_MEM_NON_CACHEABLE)
  936. * creates a memory type that is writeback cacheable in the system cache, and not
  937. * cacheable in the processor's local cache.
  938. */
  939. #define XTHAL_MEM_PROC_CACHE(system, processor) \
  940. (((system) & 0x000f0000) | (((processor) & 0x000f0000 ) << 4) | \
  941. (((system) & XTHAL_MEM_DEVICE) | ((processor) & XTHAL_MEM_DEVICE)))
  942. /*
  943. * This macro converts a bit-wise combination of the XTHAL_MEM_... constants
  944. * to the corresponding MPU memory type (9-bits).
  945. *
  946. * Unsupported combinations are mapped to the best available substitute.
  947. *
  948. * The same functionality plus error checking is available from
  949. * xthal_encode_memory_type().
  950. */
  951. #define XTHAL_ENCODE_MEMORY_TYPE(x) \
  952. (((x) & 0xffffe000) ? \
  953. (_XTHAL_MEM_IS_DEVICE((x)) ? _XTHAL_ENCODE_DEVICE((x)) : \
  954. (_XTHAL_IS_SYSTEM_NONCACHEABLE((x)) ? \
  955. _XTHAL_ENCODE_SYSTEM_NONCACHEABLE((x)) : \
  956. _XTHAL_ENCODE_SYSTEM_CACHEABLE((x)))) : (x))
  957. /*
  958. * This structure is used to represent each MPU entry (both foreground and
  959. * background). The internal representation of the structure is subject to
  960. * change, so it should only be accessed by the XTHAL_MPU_ENTRY_... macros
  961. * below.
  962. */
  963. typedef struct xthal_MPU_entry
  964. {
  965. uint32_t as; /* virtual start address, and valid bit */
  966. uint32_t at; /* access rights, and memory type (and space for entry index) */
  967. } xthal_MPU_entry;
  968. extern const xthal_MPU_entry Xthal_mpu_bgmap[];
  969. /*
  970. * XTHAL_MPU_ENTRY creates an MPU entry from its component values. It is
  971. * intended for initializing an MPU map. Example:
  972. * const struct xthal_MPU_entry mpumap[] =
  973. { XTHAL_MPU_ENTRY( 0x00000000, 1, XTHAL_AR_RWXrwx, XTHAL_MEM_WRITEBACK),
  974. XTHAL_MPU_ENTRY( 0xE0000000, 1, XTHAL_AR_RWXrwx,
  975. XTHAL_MEM_NON_CACHEABLE | XTHAL_MEM_BUFFERABLE),
  976. XTHAL_MPU_ENTRY( 0xF0000000, 1, XTHAL_AR_RWX,
  977. XTHAL_MEM_NON_CACHEABLE | XTHAL_MEM_BUFFERABLE) };
  978. xthal_write_map(mpumap, sizeof(mpumap) / sizeof(struct xthal_MPU_entry));
  979. *
  980. */
  981. #define XTHAL_MPU_ENTRY(vaddr, valid, access, memtype) \
  982. { (((vaddr) & 0xffffffe0) | ((valid & 0x1))), \
  983. (((XTHAL_ENCODE_MEMORY_TYPE(memtype)) << 12) | (((access) & 0xf) << 8)) }
  984. /*
  985. * These macros get (or set) the specified field of the MPU entry.
  986. */
  987. #define XTHAL_MPU_ENTRY_GET_VSTARTADDR(x) ((x).as & 0xffffffe0)
  988. #define XTHAL_MPU_ENTRY_SET_VSTARTADDR(x, vaddr) (x).as = \
  989. (((x).as) & 0x1) | ((vaddr) & 0xffffffe0)
  990. #define XTHAL_MPU_ENTRY_GET_VALID(x) (((x).as & 0x1))
  991. #define XTHAL_MPU_ENTRY_SET_VALID(x, valid) (x).as = \
  992. (((x).as & 0xfffffffe) | ((valid) & 0x1))
  993. #define XTHAL_MPU_ENTRY_GET_ACCESS(x) ((((x).at) >> 8) & 0xf)
  994. #define XTHAL_MPU_ENTRY_SET_ACCESS(x, accessRights) ((x).at = \
  995. ((x).at & 0xfffff0ff) | (((accessRights) & 0xf) << 8))
  996. #define XTHAL_MPU_ENTRY_GET_MEMORY_TYPE(x) ((((x).at) >> 12) & 0x1ff)
  997. #define XTHAL_MPU_ENTRY_SET_MEMORY_TYPE(x, memtype) ((x).at = \
  998. ((x).at & 0xffe00fff) | (((XTHAL_ENCODE_MEMORY_TYPE(memtype)) & 0x1ff) << 12))
  999. /*
  1000. * These functions accept encoded access rights, and return 1 if the
  1001. * supplied memory type has the property specified by the function name,
  1002. * otherwise they return 0.
  1003. */
  1004. extern int32_t xthal_is_kernel_readable(uint32_t accessRights);
  1005. extern int32_t xthal_is_kernel_writeable(uint32_t accessRights);
  1006. extern int32_t xthal_is_kernel_executable(uint32_t accessRights);
  1007. extern int32_t xthal_is_user_readable(uint32_t accessRights);
  1008. extern int32_t xthal_is_user_writeable (uint32_t accessRights);
  1009. extern int32_t xthal_is_user_executable(uint32_t accessRights);
  1010. /*
  1011. * This function converts a bit-wise combination of the XTHAL_MEM_.. constants
  1012. * to the corresponding MPU memory type (9-bits).
  1013. *
  1014. * If none of the XTHAL_MEM_.. bits are present in the argument, then
  1015. * bits 4-12 (9-bits) are returned ... this supports using an already encoded
  1016. * memoryType (perhaps obtained from an xthal_MPU_entry structure) as input
  1017. * to xthal_set_region_attribute().
  1018. *
  1019. * This function first checks that the supplied constants are a valid and
  1020. * supported combination. If not, it returns XTHAL_BAD_MEMORY_TYPE.
  1021. */
  1022. extern int xthal_encode_memory_type(uint32_t x);
  1023. /*
  1024. * This function accepts a 9-bit memory type value (such as returned by
  1025. * XTHAL_MEM_ENTRY_GET_MEMORY_TYPE() or xthal_encode_memory_type(). They
  1026. * return 1 if the memoryType has the property specified in the function
  1027. * name and 0 otherwise.
  1028. */
  1029. extern int32_t xthal_is_cacheable(uint32_t memoryType);
  1030. extern int32_t xthal_is_writeback(uint32_t memoryType);
  1031. extern int32_t xthal_is_device(uint32_t memoryType);
  1032. /*
  1033. * Copies the current MPU entry list into 'entries' which
  1034. * must point to available memory of at least
  1035. * sizeof(struct xthal_MPU_entry) * XCHAL_MPU_ENTRIES.
  1036. *
  1037. * This function returns XTHAL_SUCCESS.
  1038. * XTHAL_INVALID, or
  1039. * XTHAL_UNSUPPORTED.
  1040. */
  1041. extern int32_t xthal_read_map(struct xthal_MPU_entry* entries);
  1042. /*
  1043. * Writes the map pointed to by 'entries' to the MPU. Before updating
  1044. * the map, it commits any uncommitted
  1045. * cache writes, and invalidates the cache if necessary.
  1046. *
  1047. * This function does not check for the correctness of the map. Generally
  1048. * xthal_check_map() should be called first to check the map.
  1049. *
  1050. * If n == 0 then the existing map is cleared, and no new map is written
  1051. * (useful for returning to reset state)
  1052. *
  1053. * If (n > 0 && n < XCHAL_MPU_ENTRIES) then a new map is written with
  1054. * (XCHAL_MPU_ENTRIES-n) padding entries added to ensure a properly ordered
  1055. * map. The resulting foreground map will be equivalent to the map vector
  1056. * fg, but the position of the padding entries should not be relied upon.
  1057. *
  1058. * If n == XCHAL_MPU_ENTRIES then the complete map as specified by fg is
  1059. * written.
  1060. *
  1061. * The CACHEADRDIS register will be set to enable caching any 512MB region
  1062. * that is overlapped by an MPU region with a cacheable memory type.
  1063. * Caching will be disabled if none of the 512 MB region is cacheable.
  1064. *
  1065. * xthal_write_map() disables the MPU foreground map during the MPU
  1066. * update and relies on the background map.
  1067. *
  1068. * As a result any interrupt that does not meet the following conditions
  1069. * must be disabled before calling xthal_write_map():
  1070. * 1) All code and data needed for the interrupt must be
  1071. * mapped by the background map with sufficient access rights.
  1072. * 2) The interrupt code must not access the MPU.
  1073. *
  1074. */
  1075. extern void xthal_write_map(const struct xthal_MPU_entry* entries, uint32_t n);
  1076. /*
  1077. * Checks if entry vector 'entries' of length 'n' is a valid MPU access map.
  1078. * Returns:
  1079. * XTHAL_SUCCESS if valid,
  1080. * XTHAL_OUT_OF_ENTRIES
  1081. * XTHAL_MAP_NOT_ALIGNED,
  1082. * XTHAL_BAD_ACCESS_RIGHTS,
  1083. * XTHAL_OUT_OF_ORDER_MAP, or
  1084. * XTHAL_UNSUPPORTED if config doesn't have an MPU.
  1085. */
  1086. extern int xthal_check_map(const struct xthal_MPU_entry* entries, uint32_t n);
  1087. /*
  1088. * Returns the MPU entry that maps 'vaddr'. If 'infgmap' is non-NULL then
  1089. * *infgmap is set to 1 if 'vaddr' is mapped by the foreground map, and
  1090. * *infgmap is set to 0 if 'vaddr' is mapped by the background map.
  1091. */
  1092. extern struct xthal_MPU_entry xthal_get_entry_for_address(void* vaddr,
  1093. int32_t* infgmap);
  1094. /*
  1095. * Scans the supplied MPU map and returns a value suitable for writing to
  1096. * the CACHEADRDIS register:
  1097. * Bits 0-7 -> 1 if there are no cacheable areas in the corresponding 512MB
  1098. * region and 0 otherwise.
  1099. * Bits 8-31 -> undefined.
  1100. * This function can accept a partial memory map in the same manner
  1101. * xthal_write_map() does, */
  1102. extern uint32_t
  1103. xthal_calc_cacheadrdis(const struct xthal_MPU_entry* e, uint32_t n);
  1104. /*
  1105. * This function is intended as an MPU specific version of
  1106. * xthal_set_region_attributes(). xthal_set_region_attributes() calls
  1107. * this function for MPU configurations.
  1108. *
  1109. * This function sets the attributes for the region [vaddr, vaddr+size)
  1110. * in the MPU.
  1111. *
  1112. * Depending on the state of the MPU this function will require from
  1113. * 0 to 3 unused MPU entries.
  1114. *
  1115. * This function typically will move, add, and subtract entries from
  1116. * the MPU map during execution, so that the resulting map may
  1117. * be quite different than when the function was called.
  1118. *
  1119. * This function does make the following guarantees:
  1120. * 1) The MPU access map remains in a valid state at all times
  1121. * during its execution.
  1122. * 2) At all points during (and after) completion the memoryType
  1123. * and accessRights remain the same for all addresses
  1124. * that are not in the range [vaddr, vaddr+size).
  1125. * 3) If XTHAL_SUCCESS is returned, then the range
  1126. * [vaddr, vaddr+size) will have the accessRights and memoryType
  1127. * specified.
  1128. * 4) The CACHEADRDIS register will be set to enable caching any 512MB region
  1129. * that is overlapped by an MPU region with a cacheable memory type.
  1130. * Caching will be disabled if none of the 512 MB region is cacheable.
  1131. *
  1132. * The accessRights parameter should be either a 4-bit value corresponding
  1133. * to an MPU access mode (as defined by the XTHAL_AR_.. constants), or
  1134. * XTHAL_MPU_USE_EXISTING_ACCESS_RIGHTS.
  1135. *
  1136. * The memoryType parameter should be either a bit-wise or-ing of XTHAL_MEM_..
  1137. * constants that represent a valid MPU memoryType, a 9-bit MPU memoryType
  1138. * value, or XTHAL_MPU_USE_EXISTING_MEMORY_TYPE.
  1139. *
  1140. * In addition to the error codes that xthal_set_region_attribute()
  1141. * returns, this function can also return: XTHAL_BAD_ACCESS_RIGHTS
  1142. * (if the access rights bits map to an unsupported combination), or
  1143. * XTHAL_OUT_OF_MAP_ENTRIES (if there are not enough unused MPU entries)
  1144. *
  1145. * If this function is called with an invalid MPU map, then this function
  1146. * will return one of the codes that is returned by xthal_check_map().
  1147. *
  1148. * The flag, XTHAL_CAFLAG_EXPAND, is not supported
  1149. *
  1150. */
  1151. extern int xthal_mpu_set_region_attribute(void* vaddr, size_t size,
  1152. int32_t accessRights, int32_t memoryType, uint32_t flags);
  1153. /* The following are internal implementation macros. These should not
  1154. * be directly used except by the hal code and headers.
  1155. */
  1156. /*
  1157. * Layout of the MPU specifier for: XTHAL_ENCODE_MEMORY_TYPE(),
  1158. * xthal_encode_memory_type(), xthal_set_region_attribute(),
  1159. * and xthal_mpu_set_region_attribute(). THIS IS SUBJECT TO CHANGE:
  1160. *
  1161. * Bits 0-3 - reserved for pass through of accessRights
  1162. * Bits 4-12 - reserved for pass through of memoryType bits
  1163. * Bit 13 - indicates to use existing access rights of region
  1164. * Bit 14 - indicates to use existing memory type of region
  1165. * Bit 15 - indicates device
  1166. * Bit 16-19- system cache properties
  1167. * Bit 20-23- local cache properties
  1168. * Bit 24 - indicates bufferable
  1169. * Bit 25-26- encodes shareability (1=inner, 2=outer, 3=system)
  1170. * Bit 27 - indicates interruptible
  1171. * Bits 28-31- reserved for future use
  1172. */
  1173. #define _XTHAL_SYSTEM_CACHE_BITS 0x000f0000
  1174. #define _XTHAL_LOCAL_CACHE_BITS 0x00f00000
  1175. #define _XTHAL_MEM_SYSTEM_RWC_MASK 0x00070000
  1176. #define _XTHAL_MEM_LOCAL_RWC_MASK 0x00700000
  1177. #define _XTHAL_SHIFT_RWC 16
  1178. #define _XTHAL_MEM_ANY_SHAREABLE(x) (((x) & XTHAL_MEM_SYSTEM_SHAREABLE) ? 1 : 0)
  1179. #define _XTHAL_MEM_INNER_SHAREABLE(x) ((((x) & XTHAL_MEM_SYSTEM_SHAREABLE) \
  1180. == XTHAL_MEM_INNER_SHAREABLE) ? 1 : 0)
  1181. #define _XTHAL_MEM_IS_BUFFERABLE(x) (((x) & XTHAL_MEM_BUFFERABLE) ? 1 : 0)
  1182. #define _XTHAL_MEM_IS_DEVICE(x) (((x) & XTHAL_MEM_DEVICE) ? 1 : 0)
  1183. #define _XTHAL_NON_CACHEABLE_DOMAIN(x) \
  1184. (_XTHAL_MEM_IS_DEVICE(x) || _XTHAL_MEM_ANY_SHAREABLE(x)? 0x3 : 0)
  1185. #define _XTHAL_CACHEABLE_DOMAIN(x) (_XTHAL_MEM_ANY_SHAREABLE(x) ? \
  1186. 0x3 : 0x1)
  1187. #define _XTHAL_MEM_CACHE_MASK(x) ((x) & _XTHAL_SYSTEM_CACHE_BITS)
  1188. #define _XTHAL_IS_SYSTEM_NONCACHEABLE(x) \
  1189. (((_XTHAL_MEM_CACHE_MASK(x) & XTHAL_MEM_NON_CACHEABLE) == \
  1190. XTHAL_MEM_NON_CACHEABLE) ? 1 : 0)
  1191. #define _XTHAL_ENCODE_DEVICE(x) \
  1192. (((((x) & XTHAL_MEM_INTERRUPTIBLE) ? 1 : 0) << 3) | \
  1193. (_XTHAL_NON_CACHEABLE_DOMAIN(x) << 1) | _XTHAL_MEM_IS_BUFFERABLE(x))
  1194. #define _XTHAL_ENCODE_SYSTEM_NONCACHEABLE(x) \
  1195. (0x18 | (_XTHAL_NON_CACHEABLE_DOMAIN(x) << 1) \
  1196. | _XTHAL_MEM_IS_BUFFERABLE(x))
  1197. #define _XTHAL_ENCODE_SYSTEM_CACHEABLE(x) \
  1198. (((((((x) & _XTHAL_LOCAL_CACHE_BITS) >> 4) & XTHAL_MEM_NON_CACHEABLE) == \
  1199. XTHAL_MEM_NON_CACHEABLE) ? 1 : 0) ? \
  1200. (_XTHAL_CACHEABLE_DOMAIN(x) << 4) : \
  1201. _XTHAL_ENCODE_SYSTEM_CACHEABLE_LOCAL_CACHEABLE(x)) | \
  1202. ((_XTHAL_MEM_INNER_SHAREABLE(x) << 3) | \
  1203. (_XTHAL_MEM_CACHE_MASK(x) & _XTHAL_MEM_SYSTEM_RWC_MASK) \
  1204. >> _XTHAL_SHIFT_RWC)
  1205. #define _XTHAL_ENCODE_SYSTEM_CACHEABLE_LOCAL_CACHEABLE(x) \
  1206. ((_XTHAL_CACHEABLE_DOMAIN(x) << 7) | (((((x) & _XTHAL_LOCAL_CACHE_BITS) ? \
  1207. ((x) & _XTHAL_LOCAL_CACHE_BITS) : \
  1208. (_XTHAL_MEM_CACHE_MASK(x) << 4)) \
  1209. & (_XTHAL_MEM_LOCAL_RWC_MASK)) >> _XTHAL_SHIFT_RWC ))
  1210. /* End of internal macros */
  1211. /* The functions and constants below here have been deprecated.*/
  1212. #define XTHAL_MEM_NON_CACHED XTHAL_MEM_NON_CACHEABLE
  1213. #define XTHAL_MEM_NON_SHARED XTHAL_MEM_NON_SHAREABLE
  1214. #define XTHAL_MEM_INNER_SHARED XTHAL_MEM_INNER_SHAREABLE
  1215. #define XTHAL_MEM_OUTER_SHARED XTHAL_MEM_OUTER_SHAREABLE
  1216. #define XTHAL_MEM_SYSTEM_SHARED XTHAL_MEM_SYSTEM_SHAREABLE
  1217. #define XTHAL_MEM_SW_SHAREABLE 0
  1218. #define xthal_is_cached(memoryType) (xthal_is_cacheable((memoryType)))
  1219. extern int32_t xthal_read_background_map(struct xthal_MPU_entry* entries);
  1220. /* end deprecated functions and constants */
  1221. #ifdef __cplusplus
  1222. }
  1223. #endif
  1224. #endif /*!_ASMLANGUAGE && !_NOCLANGUAGE && !__ASSEMBLER__ */
  1225. #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
  1226. /****************************************************************************
  1227. EXPERIMENTAL and DEPRECATED Definitions
  1228. ****************************************************************************/
  1229. #if !defined(_ASMLANGUAGE) && !defined(_NOCLANGUAGE) && !defined(__ASSEMBLER__)
  1230. #ifdef __cplusplus
  1231. extern "C" {
  1232. #endif
  1233. #ifdef INCLUDE_DEPRECATED_HAL_DEBUG_CODE
  1234. #define XTHAL_24_BIT_BREAK 0x80000000
  1235. #define XTHAL_16_BIT_BREAK 0x40000000
  1236. extern const unsigned short Xthal_ill_inst_16[16];
  1237. #define XTHAL_DEST_REG 0xf0000000 /* Mask for destination register */
  1238. #define XTHAL_DEST_REG_INST 0x08000000 /* Branch address is in register */
  1239. #define XTHAL_DEST_REL_INST 0x04000000 /* Branch address is relative */
  1240. #define XTHAL_RFW_INST 0x00000800
  1241. #define XTHAL_RFUE_INST 0x00000400
  1242. #define XTHAL_RFI_INST 0x00000200
  1243. #define XTHAL_RFE_INST 0x00000100
  1244. #define XTHAL_RET_INST 0x00000080
  1245. #define XTHAL_BREAK_INST 0x00000040
  1246. #define XTHAL_SYSCALL_INST 0x00000020
  1247. #define XTHAL_LOOP_END 0x00000010 /* Not set by xthal_inst_type */
  1248. #define XTHAL_JUMP_INST 0x00000008 /* Call or jump instruction */
  1249. #define XTHAL_BRANCH_INST 0x00000004 /* Branch instruction */
  1250. #define XTHAL_24_BIT_INST 0x00000002
  1251. #define XTHAL_16_BIT_INST 0x00000001
  1252. typedef struct xthal_state {
  1253. unsigned pc;
  1254. unsigned ar[16];
  1255. unsigned lbeg;
  1256. unsigned lend;
  1257. unsigned lcount;
  1258. unsigned extra_ptr;
  1259. unsigned cpregs_ptr[XTHAL_MAX_CPS];
  1260. } XTHAL_STATE;
  1261. extern unsigned int xthal_inst_type(void *addr);
  1262. extern unsigned int xthal_branch_addr(void *addr);
  1263. extern unsigned int xthal_get_npc(XTHAL_STATE *user_state);
  1264. #endif /* INCLUDE_DEPRECATED_HAL_DEBUG_CODE */
  1265. #ifdef __cplusplus
  1266. }
  1267. #endif
  1268. #endif /*!_ASMLANGUAGE && !_NOCLANGUAGE && !__ASSEMBLER__ */
  1269. #endif /*XTENSA_HAL_H*/