mipsregs.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2000 Silicon Graphics, Inc.
  8. * Modified for further R[236]000 support by Paul M. Antoine, 1996.
  9. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000, 07 MIPS Technologies, Inc.
  11. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  12. */
  13. #ifndef _ASM_MIPSREGS_H
  14. #define _ASM_MIPSREGS_H
  15. #include <linux/linkage.h>
  16. #include <asm/hazards.h>
  17. #include <asm/war.h>
  18. /*
  19. * The following macros are especially useful for __asm__
  20. * inline assembler.
  21. */
  22. #ifndef __STR
  23. #define __STR(x) #x
  24. #endif
  25. #ifndef STR
  26. #define STR(x) __STR(x)
  27. #endif
  28. /*
  29. * Configure language
  30. */
  31. #ifdef __ASSEMBLY__
  32. #define _ULCAST_
  33. #else
  34. #define _ULCAST_ (unsigned long)
  35. #endif
  36. /*
  37. * Coprocessor 0 register names
  38. */
  39. #define CP0_INDEX $0
  40. #define CP0_RANDOM $1
  41. #define CP0_ENTRYLO0 $2
  42. #define CP0_ENTRYLO1 $3
  43. #define CP0_CONF $3
  44. #define CP0_CONTEXT $4
  45. #define CP0_PAGEMASK $5
  46. #define CP0_WIRED $6
  47. #define CP0_INFO $7
  48. #define CP0_BADVADDR $8
  49. #define CP0_COUNT $9
  50. #define CP0_ENTRYHI $10
  51. #define CP0_COMPARE $11
  52. #define CP0_STATUS $12
  53. #define CP0_CAUSE $13
  54. #define CP0_EPC $14
  55. #define CP0_PRID $15
  56. #define CP0_CONFIG $16
  57. #define CP0_LLADDR $17
  58. #define CP0_WATCHLO $18
  59. #define CP0_WATCHHI $19
  60. #define CP0_XCONTEXT $20
  61. #define CP0_FRAMEMASK $21
  62. #define CP0_DIAGNOSTIC $22
  63. #define CP0_DEBUG $23
  64. #define CP0_DEPC $24
  65. #define CP0_PERFORMANCE $25
  66. #define CP0_ECC $26
  67. #define CP0_CACHEERR $27
  68. #define CP0_TAGLO $28
  69. #define CP0_TAGHI $29
  70. #define CP0_ERROREPC $30
  71. #define CP0_DESAVE $31
  72. /*
  73. * R4640/R4650 cp0 register names. These registers are listed
  74. * here only for completeness; without MMU these CPUs are not useable
  75. * by Linux. A future ELKS port might take make Linux run on them
  76. * though ...
  77. */
  78. #define CP0_IBASE $0
  79. #define CP0_IBOUND $1
  80. #define CP0_DBASE $2
  81. #define CP0_DBOUND $3
  82. #define CP0_CALG $17
  83. #define CP0_IWATCH $18
  84. #define CP0_DWATCH $19
  85. /*
  86. * Coprocessor 0 Set 1 register names
  87. */
  88. #define CP0_S1_DERRADDR0 $26
  89. #define CP0_S1_DERRADDR1 $27
  90. #define CP0_S1_INTCONTROL $20
  91. /*
  92. * Coprocessor 0 Set 2 register names
  93. */
  94. #define CP0_S2_SRSCTL $12 /* MIPSR2 */
  95. /*
  96. * Coprocessor 0 Set 3 register names
  97. */
  98. #define CP0_S3_SRSMAP $12 /* MIPSR2 */
  99. /*
  100. * TX39 Series
  101. */
  102. #define CP0_TX39_CACHE $7
  103. /*
  104. * Coprocessor 1 (FPU) register names
  105. */
  106. #define CP1_REVISION $0
  107. #define CP1_STATUS $31
  108. /*
  109. * FPU Status Register Values
  110. */
  111. /*
  112. * Status Register Values
  113. */
  114. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  115. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  116. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  117. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  118. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  119. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  120. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  121. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  122. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  123. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  124. /*
  125. * Bits 18 - 20 of the FPU Status Register will be read as 0,
  126. * and should be written as zero.
  127. */
  128. #define FPU_CSR_RSVD 0x001c0000
  129. /*
  130. * X the exception cause indicator
  131. * E the exception enable
  132. * S the sticky/flag bit
  133. */
  134. #define FPU_CSR_ALL_X 0x0003f000
  135. #define FPU_CSR_UNI_X 0x00020000
  136. #define FPU_CSR_INV_X 0x00010000
  137. #define FPU_CSR_DIV_X 0x00008000
  138. #define FPU_CSR_OVF_X 0x00004000
  139. #define FPU_CSR_UDF_X 0x00002000
  140. #define FPU_CSR_INE_X 0x00001000
  141. #define FPU_CSR_ALL_E 0x00000f80
  142. #define FPU_CSR_INV_E 0x00000800
  143. #define FPU_CSR_DIV_E 0x00000400
  144. #define FPU_CSR_OVF_E 0x00000200
  145. #define FPU_CSR_UDF_E 0x00000100
  146. #define FPU_CSR_INE_E 0x00000080
  147. #define FPU_CSR_ALL_S 0x0000007c
  148. #define FPU_CSR_INV_S 0x00000040
  149. #define FPU_CSR_DIV_S 0x00000020
  150. #define FPU_CSR_OVF_S 0x00000010
  151. #define FPU_CSR_UDF_S 0x00000008
  152. #define FPU_CSR_INE_S 0x00000004
  153. /* Bits 0 and 1 of FPU Status Register specify the rounding mode */
  154. #define FPU_CSR_RM 0x00000003
  155. #define FPU_CSR_RN 0x0 /* nearest */
  156. #define FPU_CSR_RZ 0x1 /* towards zero */
  157. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  158. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  159. /*
  160. * Values for PageMask register
  161. */
  162. #ifdef CONFIG_CPU_VR41XX
  163. /* Why doesn't stupidity hurt ... */
  164. #define PM_1K 0x00000000
  165. #define PM_4K 0x00001800
  166. #define PM_16K 0x00007800
  167. #define PM_64K 0x0001f800
  168. #define PM_256K 0x0007f800
  169. #else
  170. #define PM_4K 0x00000000
  171. #define PM_8K 0x00002000
  172. #define PM_16K 0x00006000
  173. #define PM_32K 0x0000e000
  174. #define PM_64K 0x0001e000
  175. #define PM_128K 0x0003e000
  176. #define PM_256K 0x0007e000
  177. #define PM_512K 0x000fe000
  178. #define PM_1M 0x001fe000
  179. #define PM_2M 0x003fe000
  180. #define PM_4M 0x007fe000
  181. #define PM_8M 0x00ffe000
  182. #define PM_16M 0x01ffe000
  183. #define PM_32M 0x03ffe000
  184. #define PM_64M 0x07ffe000
  185. #define PM_256M 0x1fffe000
  186. #define PM_1G 0x7fffe000
  187. #endif
  188. /*
  189. * Default page size for a given kernel configuration
  190. */
  191. #ifdef CONFIG_PAGE_SIZE_4KB
  192. #define PM_DEFAULT_MASK PM_4K
  193. #elif defined(CONFIG_PAGE_SIZE_8KB)
  194. #define PM_DEFAULT_MASK PM_8K
  195. #elif defined(CONFIG_PAGE_SIZE_16KB)
  196. #define PM_DEFAULT_MASK PM_16K
  197. #elif defined(CONFIG_PAGE_SIZE_32KB)
  198. #define PM_DEFAULT_MASK PM_32K
  199. #elif defined(CONFIG_PAGE_SIZE_64KB)
  200. #define PM_DEFAULT_MASK PM_64K
  201. #else
  202. #error Bad page size configuration!
  203. #endif
  204. /*
  205. * Default huge tlb size for a given kernel configuration
  206. */
  207. #ifdef CONFIG_PAGE_SIZE_4KB
  208. #define PM_HUGE_MASK PM_1M
  209. #elif defined(CONFIG_PAGE_SIZE_8KB)
  210. #define PM_HUGE_MASK PM_4M
  211. #elif defined(CONFIG_PAGE_SIZE_16KB)
  212. #define PM_HUGE_MASK PM_16M
  213. #elif defined(CONFIG_PAGE_SIZE_32KB)
  214. #define PM_HUGE_MASK PM_64M
  215. #elif defined(CONFIG_PAGE_SIZE_64KB)
  216. #define PM_HUGE_MASK PM_256M
  217. #elif defined(CONFIG_HUGETLB_PAGE)
  218. #error Bad page size configuration for hugetlbfs!
  219. #endif
  220. /*
  221. * Values used for computation of new tlb entries
  222. */
  223. #define PL_4K 12
  224. #define PL_16K 14
  225. #define PL_64K 16
  226. #define PL_256K 18
  227. #define PL_1M 20
  228. #define PL_4M 22
  229. #define PL_16M 24
  230. #define PL_64M 26
  231. #define PL_256M 28
  232. /*
  233. * PageGrain bits
  234. */
  235. #define PG_RIE (_ULCAST_(1) << 31)
  236. #define PG_XIE (_ULCAST_(1) << 30)
  237. #define PG_ELPA (_ULCAST_(1) << 29)
  238. #define PG_ESP (_ULCAST_(1) << 28)
  239. /*
  240. * R4x00 interrupt enable / cause bits
  241. */
  242. #define IE_SW0 (_ULCAST_(1) << 8)
  243. #define IE_SW1 (_ULCAST_(1) << 9)
  244. #define IE_IRQ0 (_ULCAST_(1) << 10)
  245. #define IE_IRQ1 (_ULCAST_(1) << 11)
  246. #define IE_IRQ2 (_ULCAST_(1) << 12)
  247. #define IE_IRQ3 (_ULCAST_(1) << 13)
  248. #define IE_IRQ4 (_ULCAST_(1) << 14)
  249. #define IE_IRQ5 (_ULCAST_(1) << 15)
  250. /*
  251. * R4x00 interrupt cause bits
  252. */
  253. #define C_SW0 (_ULCAST_(1) << 8)
  254. #define C_SW1 (_ULCAST_(1) << 9)
  255. #define C_IRQ0 (_ULCAST_(1) << 10)
  256. #define C_IRQ1 (_ULCAST_(1) << 11)
  257. #define C_IRQ2 (_ULCAST_(1) << 12)
  258. #define C_IRQ3 (_ULCAST_(1) << 13)
  259. #define C_IRQ4 (_ULCAST_(1) << 14)
  260. #define C_IRQ5 (_ULCAST_(1) << 15)
  261. /*
  262. * Bitfields in the R4xx0 cp0 status register
  263. */
  264. #define ST0_IE 0x00000001
  265. #define ST0_EXL 0x00000002
  266. #define ST0_ERL 0x00000004
  267. #define ST0_KSU 0x00000018
  268. # define KSU_USER 0x00000010
  269. # define KSU_SUPERVISOR 0x00000008
  270. # define KSU_KERNEL 0x00000000
  271. #define ST0_UX 0x00000020
  272. #define ST0_SX 0x00000040
  273. #define ST0_KX 0x00000080
  274. #define ST0_DE 0x00010000
  275. #define ST0_CE 0x00020000
  276. /*
  277. * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
  278. * cacheops in userspace. This bit exists only on RM7000 and RM9000
  279. * processors.
  280. */
  281. #define ST0_CO 0x08000000
  282. /*
  283. * Bitfields in the R[23]000 cp0 status register.
  284. */
  285. #define ST0_IEC 0x00000001
  286. #define ST0_KUC 0x00000002
  287. #define ST0_IEP 0x00000004
  288. #define ST0_KUP 0x00000008
  289. #define ST0_IEO 0x00000010
  290. #define ST0_KUO 0x00000020
  291. /* bits 6 & 7 are reserved on R[23]000 */
  292. #define ST0_ISC 0x00010000
  293. #define ST0_SWC 0x00020000
  294. #define ST0_CM 0x00080000
  295. /*
  296. * Bits specific to the R4640/R4650
  297. */
  298. #define ST0_UM (_ULCAST_(1) << 4)
  299. #define ST0_IL (_ULCAST_(1) << 23)
  300. #define ST0_DL (_ULCAST_(1) << 24)
  301. /*
  302. * Enable the MIPS MDMX and DSP ASEs
  303. */
  304. #define ST0_MX 0x01000000
  305. /*
  306. * Bitfields in the TX39 family CP0 Configuration Register 3
  307. */
  308. #define TX39_CONF_ICS_SHIFT 19
  309. #define TX39_CONF_ICS_MASK 0x00380000
  310. #define TX39_CONF_ICS_1KB 0x00000000
  311. #define TX39_CONF_ICS_2KB 0x00080000
  312. #define TX39_CONF_ICS_4KB 0x00100000
  313. #define TX39_CONF_ICS_8KB 0x00180000
  314. #define TX39_CONF_ICS_16KB 0x00200000
  315. #define TX39_CONF_DCS_SHIFT 16
  316. #define TX39_CONF_DCS_MASK 0x00070000
  317. #define TX39_CONF_DCS_1KB 0x00000000
  318. #define TX39_CONF_DCS_2KB 0x00010000
  319. #define TX39_CONF_DCS_4KB 0x00020000
  320. #define TX39_CONF_DCS_8KB 0x00030000
  321. #define TX39_CONF_DCS_16KB 0x00040000
  322. #define TX39_CONF_CWFON 0x00004000
  323. #define TX39_CONF_WBON 0x00002000
  324. #define TX39_CONF_RF_SHIFT 10
  325. #define TX39_CONF_RF_MASK 0x00000c00
  326. #define TX39_CONF_DOZE 0x00000200
  327. #define TX39_CONF_HALT 0x00000100
  328. #define TX39_CONF_LOCK 0x00000080
  329. #define TX39_CONF_ICE 0x00000020
  330. #define TX39_CONF_DCE 0x00000010
  331. #define TX39_CONF_IRSIZE_SHIFT 2
  332. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  333. #define TX39_CONF_DRSIZE_SHIFT 0
  334. #define TX39_CONF_DRSIZE_MASK 0x00000003
  335. /*
  336. * Status register bits available in all MIPS CPUs.
  337. */
  338. #define ST0_IM 0x0000ff00
  339. #define STATUSB_IP0 8
  340. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  341. #define STATUSB_IP1 9
  342. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  343. #define STATUSB_IP2 10
  344. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  345. #define STATUSB_IP3 11
  346. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  347. #define STATUSB_IP4 12
  348. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  349. #define STATUSB_IP5 13
  350. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  351. #define STATUSB_IP6 14
  352. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  353. #define STATUSB_IP7 15
  354. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  355. #define STATUSB_IP8 0
  356. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  357. #define STATUSB_IP9 1
  358. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  359. #define STATUSB_IP10 2
  360. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  361. #define STATUSB_IP11 3
  362. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  363. #define STATUSB_IP12 4
  364. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  365. #define STATUSB_IP13 5
  366. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  367. #define STATUSB_IP14 6
  368. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  369. #define STATUSB_IP15 7
  370. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  371. #define ST0_CH 0x00040000
  372. #define ST0_NMI 0x00080000
  373. #define ST0_SR 0x00100000
  374. #define ST0_TS 0x00200000
  375. #define ST0_BEV 0x00400000
  376. #define ST0_RE 0x02000000
  377. #define ST0_FR 0x04000000
  378. #define ST0_CU 0xf0000000
  379. #define ST0_CU0 0x10000000
  380. #define ST0_CU1 0x20000000
  381. #define ST0_CU2 0x40000000
  382. #define ST0_CU3 0x80000000
  383. #define ST0_XX 0x80000000 /* MIPS IV naming */
  384. /*
  385. * Bitfields and bit numbers in the coprocessor 0 IntCtl register. (MIPSR2)
  386. *
  387. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  388. */
  389. #define INTCTLB_IPPCI 26
  390. #define INTCTLF_IPPCI (_ULCAST_(7) << INTCTLB_IPPCI)
  391. #define INTCTLB_IPTI 29
  392. #define INTCTLF_IPTI (_ULCAST_(7) << INTCTLB_IPTI)
  393. /*
  394. * Bitfields and bit numbers in the coprocessor 0 cause register.
  395. *
  396. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  397. */
  398. #define CAUSEB_EXCCODE 2
  399. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  400. #define CAUSEB_IP 8
  401. #define CAUSEF_IP (_ULCAST_(255) << 8)
  402. #define CAUSEB_IP0 8
  403. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  404. #define CAUSEB_IP1 9
  405. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  406. #define CAUSEB_IP2 10
  407. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  408. #define CAUSEB_IP3 11
  409. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  410. #define CAUSEB_IP4 12
  411. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  412. #define CAUSEB_IP5 13
  413. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  414. #define CAUSEB_IP6 14
  415. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  416. #define CAUSEB_IP7 15
  417. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  418. #define CAUSEB_IV 23
  419. #define CAUSEF_IV (_ULCAST_(1) << 23)
  420. #define CAUSEB_PCI 26
  421. #define CAUSEF_PCI (_ULCAST_(1) << 26)
  422. #define CAUSEB_CE 28
  423. #define CAUSEF_CE (_ULCAST_(3) << 28)
  424. #define CAUSEB_TI 30
  425. #define CAUSEF_TI (_ULCAST_(1) << 30)
  426. #define CAUSEB_BD 31
  427. #define CAUSEF_BD (_ULCAST_(1) << 31)
  428. /*
  429. * Bits in the coprocessor 0 config register.
  430. */
  431. /* Generic bits. */
  432. #define CONF_CM_CACHABLE_NO_WA 0
  433. #define CONF_CM_CACHABLE_WA 1
  434. #define CONF_CM_UNCACHED 2
  435. #define CONF_CM_CACHABLE_NONCOHERENT 3
  436. #define CONF_CM_CACHABLE_CE 4
  437. #define CONF_CM_CACHABLE_COW 5
  438. #define CONF_CM_CACHABLE_CUW 6
  439. #define CONF_CM_CACHABLE_ACCELERATED 7
  440. #define CONF_CM_CMASK 7
  441. #define CONF_BE (_ULCAST_(1) << 15)
  442. /* Bits common to various processors. */
  443. #define CONF_CU (_ULCAST_(1) << 3)
  444. #define CONF_DB (_ULCAST_(1) << 4)
  445. #define CONF_IB (_ULCAST_(1) << 5)
  446. #define CONF_DC (_ULCAST_(7) << 6)
  447. #define CONF_IC (_ULCAST_(7) << 9)
  448. #define CONF_EB (_ULCAST_(1) << 13)
  449. #define CONF_EM (_ULCAST_(1) << 14)
  450. #define CONF_SM (_ULCAST_(1) << 16)
  451. #define CONF_SC (_ULCAST_(1) << 17)
  452. #define CONF_EW (_ULCAST_(3) << 18)
  453. #define CONF_EP (_ULCAST_(15)<< 24)
  454. #define CONF_EC (_ULCAST_(7) << 28)
  455. #define CONF_CM (_ULCAST_(1) << 31)
  456. /* Bits specific to the R4xx0. */
  457. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  458. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  459. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  460. /* Bits specific to the R5000. */
  461. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  462. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  463. /* Bits specific to the RM7000. */
  464. #define RM7K_CONF_SE (_ULCAST_(1) << 3)
  465. #define RM7K_CONF_TE (_ULCAST_(1) << 12)
  466. #define RM7K_CONF_CLK (_ULCAST_(1) << 16)
  467. #define RM7K_CONF_TC (_ULCAST_(1) << 17)
  468. #define RM7K_CONF_SI (_ULCAST_(3) << 20)
  469. #define RM7K_CONF_SC (_ULCAST_(1) << 31)
  470. /* Bits specific to the R10000. */
  471. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  472. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  473. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  474. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  475. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  476. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  477. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  478. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  479. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  480. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  481. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  482. /* Bits specific to the VR41xx. */
  483. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  484. #define VR41_CONF_P4K (_ULCAST_(1) << 13)
  485. #define VR41_CONF_BP (_ULCAST_(1) << 16)
  486. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  487. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  488. /* Bits specific to the R30xx. */
  489. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  490. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  491. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  492. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  493. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  494. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  495. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  496. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  497. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  498. /* Bits specific to the TX49. */
  499. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  500. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  501. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  502. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  503. /* Bits specific to the MIPS32/64 PRA. */
  504. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  505. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  506. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  507. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  508. /*
  509. * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
  510. */
  511. #define MIPS_CONF1_FP (_ULCAST_(1) << 0)
  512. #define MIPS_CONF1_EP (_ULCAST_(1) << 1)
  513. #define MIPS_CONF1_CA (_ULCAST_(1) << 2)
  514. #define MIPS_CONF1_WR (_ULCAST_(1) << 3)
  515. #define MIPS_CONF1_PC (_ULCAST_(1) << 4)
  516. #define MIPS_CONF1_MD (_ULCAST_(1) << 5)
  517. #define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
  518. #define MIPS_CONF1_DA (_ULCAST_(7) << 7)
  519. #define MIPS_CONF1_DL (_ULCAST_(7) << 10)
  520. #define MIPS_CONF1_DS (_ULCAST_(7) << 13)
  521. #define MIPS_CONF1_IA (_ULCAST_(7) << 16)
  522. #define MIPS_CONF1_IL (_ULCAST_(7) << 19)
  523. #define MIPS_CONF1_IS (_ULCAST_(7) << 22)
  524. #define MIPS_CONF1_TLBS (_ULCAST_(63)<< 25)
  525. #define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
  526. #define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
  527. #define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
  528. #define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
  529. #define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
  530. #define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
  531. #define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
  532. #define MIPS_CONF2_TU (_ULCAST_(7) << 28)
  533. #define MIPS_CONF3_TL (_ULCAST_(1) << 0)
  534. #define MIPS_CONF3_SM (_ULCAST_(1) << 1)
  535. #define MIPS_CONF3_MT (_ULCAST_(1) << 2)
  536. #define MIPS_CONF3_SP (_ULCAST_(1) << 4)
  537. #define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
  538. #define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
  539. #define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
  540. #define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
  541. #define MIPS_CONF3_DSP2P (_ULCAST_(1) << 11)
  542. #define MIPS_CONF3_RXI (_ULCAST_(1) << 12)
  543. #define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
  544. #define MIPS_CONF4_MMUSIZEEXT (_ULCAST_(255) << 0)
  545. #define MIPS_CONF4_MMUEXTDEF (_ULCAST_(3) << 14)
  546. #define MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT (_ULCAST_(1) << 14)
  547. #define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
  548. #define MIPS_CONF7_WII (_ULCAST_(1) << 31)
  549. #define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
  550. /*
  551. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  552. */
  553. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  554. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  555. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  556. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  557. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  558. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  559. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  560. #ifndef __ASSEMBLY__
  561. /*
  562. * Functions to access the R10000 performance counters. These are basically
  563. * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
  564. * performance counter number encoded into bits 1 ... 5 of the instruction.
  565. * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
  566. * disassembler these will look like an access to sel 0 or 1.
  567. */
  568. #define read_r10k_perf_cntr(counter) \
  569. ({ \
  570. unsigned int __res; \
  571. __asm__ __volatile__( \
  572. "mfpc\t%0, %1" \
  573. : "=r" (__res) \
  574. : "i" (counter)); \
  575. \
  576. __res; \
  577. })
  578. #define write_r10k_perf_cntr(counter,val) \
  579. do { \
  580. __asm__ __volatile__( \
  581. "mtpc\t%0, %1" \
  582. : \
  583. : "r" (val), "i" (counter)); \
  584. } while (0)
  585. #define read_r10k_perf_event(counter) \
  586. ({ \
  587. unsigned int __res; \
  588. __asm__ __volatile__( \
  589. "mfps\t%0, %1" \
  590. : "=r" (__res) \
  591. : "i" (counter)); \
  592. \
  593. __res; \
  594. })
  595. #define write_r10k_perf_cntl(counter,val) \
  596. do { \
  597. __asm__ __volatile__( \
  598. "mtps\t%0, %1" \
  599. : \
  600. : "r" (val), "i" (counter)); \
  601. } while (0)
  602. /*
  603. * Macros to access the system control coprocessor
  604. */
  605. #define __read_32bit_c0_register(source, sel) \
  606. ({ int __res; \
  607. if (sel == 0) \
  608. __asm__ __volatile__( \
  609. "mfc0\t%0, " #source "\n\t" \
  610. : "=r" (__res)); \
  611. else \
  612. __asm__ __volatile__( \
  613. ".set\tmips32\n\t" \
  614. "mfc0\t%0, " #source ", " #sel "\n\t" \
  615. ".set\tmips0\n\t" \
  616. : "=r" (__res)); \
  617. __res; \
  618. })
  619. #define __read_64bit_c0_register(source, sel) \
  620. ({ unsigned long long __res; \
  621. if (sizeof(unsigned long) == 4) \
  622. __res = __read_64bit_c0_split(source, sel); \
  623. else if (sel == 0) \
  624. __asm__ __volatile__( \
  625. ".set\tmips3\n\t" \
  626. "dmfc0\t%0, " #source "\n\t" \
  627. ".set\tmips0" \
  628. : "=r" (__res)); \
  629. else \
  630. __asm__ __volatile__( \
  631. ".set\tmips64\n\t" \
  632. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  633. ".set\tmips0" \
  634. : "=r" (__res)); \
  635. __res; \
  636. })
  637. #define __write_32bit_c0_register(register, sel, value) \
  638. do { \
  639. if (sel == 0) \
  640. __asm__ __volatile__( \
  641. "mtc0\t%z0, " #register "\n\t" \
  642. : : "Jr" ((unsigned int)(value))); \
  643. else \
  644. __asm__ __volatile__( \
  645. ".set\tmips32\n\t" \
  646. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  647. ".set\tmips0" \
  648. : : "Jr" ((unsigned int)(value))); \
  649. } while (0)
  650. #define __write_64bit_c0_register(register, sel, value) \
  651. do { \
  652. if (sizeof(unsigned long) == 4) \
  653. __write_64bit_c0_split(register, sel, value); \
  654. else if (sel == 0) \
  655. __asm__ __volatile__( \
  656. ".set\tmips3\n\t" \
  657. "dmtc0\t%z0, " #register "\n\t" \
  658. ".set\tmips0" \
  659. : : "Jr" (value)); \
  660. else \
  661. __asm__ __volatile__( \
  662. ".set\tmips64\n\t" \
  663. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  664. ".set\tmips0" \
  665. : : "Jr" (value)); \
  666. } while (0)
  667. #define __read_ulong_c0_register(reg, sel) \
  668. ((sizeof(unsigned long) == 4) ? \
  669. (unsigned long) __read_32bit_c0_register(reg, sel) : \
  670. (unsigned long) __read_64bit_c0_register(reg, sel))
  671. #define __write_ulong_c0_register(reg, sel, val) \
  672. do { \
  673. if (sizeof(unsigned long) == 4) \
  674. __write_32bit_c0_register(reg, sel, val); \
  675. else \
  676. __write_64bit_c0_register(reg, sel, val); \
  677. } while (0)
  678. /*
  679. * On RM7000/RM9000 these are uses to access cop0 set 1 registers
  680. */
  681. #define __read_32bit_c0_ctrl_register(source) \
  682. ({ int __res; \
  683. __asm__ __volatile__( \
  684. "cfc0\t%0, " #source "\n\t" \
  685. : "=r" (__res)); \
  686. __res; \
  687. })
  688. #define __write_32bit_c0_ctrl_register(register, value) \
  689. do { \
  690. __asm__ __volatile__( \
  691. "ctc0\t%z0, " #register "\n\t" \
  692. : : "Jr" ((unsigned int)(value))); \
  693. } while (0)
  694. /*
  695. * These versions are only needed for systems with more than 38 bits of
  696. * physical address space running the 32-bit kernel. That's none atm :-)
  697. */
  698. #define __read_64bit_c0_split(source, sel) \
  699. ({ \
  700. unsigned long long __val; \
  701. unsigned long __flags; \
  702. \
  703. local_irq_save(__flags); \
  704. if (sel == 0) \
  705. __asm__ __volatile__( \
  706. ".set\tmips64\n\t" \
  707. "dmfc0\t%M0, " #source "\n\t" \
  708. "dsll\t%L0, %M0, 32\n\t" \
  709. "dsra\t%M0, %M0, 32\n\t" \
  710. "dsra\t%L0, %L0, 32\n\t" \
  711. ".set\tmips0" \
  712. : "=r" (__val)); \
  713. else \
  714. __asm__ __volatile__( \
  715. ".set\tmips64\n\t" \
  716. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  717. "dsll\t%L0, %M0, 32\n\t" \
  718. "dsra\t%M0, %M0, 32\n\t" \
  719. "dsra\t%L0, %L0, 32\n\t" \
  720. ".set\tmips0" \
  721. : "=r" (__val)); \
  722. local_irq_restore(__flags); \
  723. \
  724. __val; \
  725. })
  726. #define __write_64bit_c0_split(source, sel, val) \
  727. do { \
  728. unsigned long __flags; \
  729. \
  730. local_irq_save(__flags); \
  731. if (sel == 0) \
  732. __asm__ __volatile__( \
  733. ".set\tmips64\n\t" \
  734. "dsll\t%L0, %L0, 32\n\t" \
  735. "dsrl\t%L0, %L0, 32\n\t" \
  736. "dsll\t%M0, %M0, 32\n\t" \
  737. "or\t%L0, %L0, %M0\n\t" \
  738. "dmtc0\t%L0, " #source "\n\t" \
  739. ".set\tmips0" \
  740. : : "r" (val)); \
  741. else \
  742. __asm__ __volatile__( \
  743. ".set\tmips64\n\t" \
  744. "dsll\t%L0, %L0, 32\n\t" \
  745. "dsrl\t%L0, %L0, 32\n\t" \
  746. "dsll\t%M0, %M0, 32\n\t" \
  747. "or\t%L0, %L0, %M0\n\t" \
  748. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  749. ".set\tmips0" \
  750. : : "r" (val)); \
  751. local_irq_restore(__flags); \
  752. } while (0)
  753. #define read_c0_index() __read_32bit_c0_register($0, 0)
  754. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  755. #define read_c0_random() __read_32bit_c0_register($1, 0)
  756. #define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
  757. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  758. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  759. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  760. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  761. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  762. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  763. #define read_c0_context() __read_ulong_c0_register($4, 0)
  764. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  765. #define read_c0_userlocal() __read_ulong_c0_register($4, 2)
  766. #define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
  767. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  768. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  769. #define read_c0_pagegrain() __read_32bit_c0_register($5, 1)
  770. #define write_c0_pagegrain(val) __write_32bit_c0_register($5, 1, val)
  771. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  772. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  773. #define read_c0_info() __read_32bit_c0_register($7, 0)
  774. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  775. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  776. #define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
  777. #define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
  778. #define read_c0_count() __read_32bit_c0_register($9, 0)
  779. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  780. #define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
  781. #define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
  782. #define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
  783. #define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
  784. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  785. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  786. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  787. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  788. #define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
  789. #define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
  790. #define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
  791. #define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
  792. #define read_c0_status() __read_32bit_c0_register($12, 0)
  793. #ifdef CONFIG_MIPS_MT_SMTC
  794. #define write_c0_status(val) \
  795. do { \
  796. __write_32bit_c0_register($12, 0, val); \
  797. __ehb(); \
  798. } while (0)
  799. #else
  800. /*
  801. * Legacy non-SMTC code, which may be hazardous
  802. * but which might not support EHB
  803. */
  804. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  805. #endif /* CONFIG_MIPS_MT_SMTC */
  806. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  807. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  808. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  809. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  810. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  811. #define read_c0_config() __read_32bit_c0_register($16, 0)
  812. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  813. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  814. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  815. #define read_c0_config4() __read_32bit_c0_register($16, 4)
  816. #define read_c0_config5() __read_32bit_c0_register($16, 5)
  817. #define read_c0_config6() __read_32bit_c0_register($16, 6)
  818. #define read_c0_config7() __read_32bit_c0_register($16, 7)
  819. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  820. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  821. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  822. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  823. #define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
  824. #define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
  825. #define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
  826. #define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
  827. /*
  828. * The WatchLo register. There may be up to 8 of them.
  829. */
  830. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  831. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  832. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  833. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  834. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  835. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  836. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  837. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  838. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  839. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  840. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  841. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  842. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  843. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  844. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  845. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  846. /*
  847. * The WatchHi register. There may be up to 8 of them.
  848. */
  849. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  850. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  851. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  852. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  853. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  854. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  855. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  856. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  857. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  858. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  859. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  860. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  861. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  862. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  863. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  864. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  865. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  866. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  867. #define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
  868. #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
  869. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  870. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  871. /* RM9000 PerfControl performance counter control register */
  872. #define read_c0_perfcontrol() __read_32bit_c0_register($22, 0)
  873. #define write_c0_perfcontrol(val) __write_32bit_c0_register($22, 0, val)
  874. #define read_c0_diag() __read_32bit_c0_register($22, 0)
  875. #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
  876. #define read_c0_diag1() __read_32bit_c0_register($22, 1)
  877. #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
  878. #define read_c0_diag2() __read_32bit_c0_register($22, 2)
  879. #define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
  880. #define read_c0_diag3() __read_32bit_c0_register($22, 3)
  881. #define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
  882. #define read_c0_diag4() __read_32bit_c0_register($22, 4)
  883. #define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
  884. #define read_c0_diag5() __read_32bit_c0_register($22, 5)
  885. #define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
  886. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  887. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  888. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  889. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  890. /*
  891. * MIPS32 / MIPS64 performance counters
  892. */
  893. #define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
  894. #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
  895. #define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
  896. #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
  897. #define read_c0_perfcntr0_64() __read_64bit_c0_register($25, 1)
  898. #define write_c0_perfcntr0_64(val) __write_64bit_c0_register($25, 1, val)
  899. #define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
  900. #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
  901. #define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
  902. #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
  903. #define read_c0_perfcntr1_64() __read_64bit_c0_register($25, 3)
  904. #define write_c0_perfcntr1_64(val) __write_64bit_c0_register($25, 3, val)
  905. #define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
  906. #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
  907. #define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
  908. #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
  909. #define read_c0_perfcntr2_64() __read_64bit_c0_register($25, 5)
  910. #define write_c0_perfcntr2_64(val) __write_64bit_c0_register($25, 5, val)
  911. #define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
  912. #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
  913. #define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
  914. #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
  915. #define read_c0_perfcntr3_64() __read_64bit_c0_register($25, 7)
  916. #define write_c0_perfcntr3_64(val) __write_64bit_c0_register($25, 7, val)
  917. /* RM9000 PerfCount performance counter register */
  918. #define read_c0_perfcount() __read_64bit_c0_register($25, 0)
  919. #define write_c0_perfcount(val) __write_64bit_c0_register($25, 0, val)
  920. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  921. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  922. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  923. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  924. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  925. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  926. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  927. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  928. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  929. #define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
  930. #define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
  931. #define read_c0_ddatalo() __read_32bit_c0_register($28, 3)
  932. #define write_c0_ddatalo(val) __write_32bit_c0_register($28, 3, val)
  933. #define read_c0_staglo() __read_32bit_c0_register($28, 4)
  934. #define write_c0_staglo(val) __write_32bit_c0_register($28, 4, val)
  935. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  936. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  937. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  938. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  939. /* MIPSR2 */
  940. #define read_c0_hwrena() __read_32bit_c0_register($7, 0)
  941. #define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
  942. #define read_c0_intctl() __read_32bit_c0_register($12, 1)
  943. #define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
  944. #define read_c0_srsctl() __read_32bit_c0_register($12, 2)
  945. #define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
  946. #define read_c0_srsmap() __read_32bit_c0_register($12, 3)
  947. #define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
  948. #define read_c0_ebase() __read_32bit_c0_register($15, 1)
  949. #define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
  950. /* Cavium OCTEON (cnMIPS) */
  951. #define read_c0_cvmcount() __read_ulong_c0_register($9, 6)
  952. #define write_c0_cvmcount(val) __write_ulong_c0_register($9, 6, val)
  953. #define read_c0_cvmctl() __read_64bit_c0_register($9, 7)
  954. #define write_c0_cvmctl(val) __write_64bit_c0_register($9, 7, val)
  955. #define read_c0_cvmmemctl() __read_64bit_c0_register($11, 7)
  956. #define write_c0_cvmmemctl(val) __write_64bit_c0_register($11, 7, val)
  957. /*
  958. * The cacheerr registers are not standardized. On OCTEON, they are
  959. * 64 bits wide.
  960. */
  961. #define read_octeon_c0_icacheerr() __read_64bit_c0_register($27, 0)
  962. #define write_octeon_c0_icacheerr(val) __write_64bit_c0_register($27, 0, val)
  963. #define read_octeon_c0_dcacheerr() __read_64bit_c0_register($27, 1)
  964. #define write_octeon_c0_dcacheerr(val) __write_64bit_c0_register($27, 1, val)
  965. /* BMIPS3300 */
  966. #define read_c0_brcm_config_0() __read_32bit_c0_register($22, 0)
  967. #define write_c0_brcm_config_0(val) __write_32bit_c0_register($22, 0, val)
  968. #define read_c0_brcm_bus_pll() __read_32bit_c0_register($22, 4)
  969. #define write_c0_brcm_bus_pll(val) __write_32bit_c0_register($22, 4, val)
  970. #define read_c0_brcm_reset() __read_32bit_c0_register($22, 5)
  971. #define write_c0_brcm_reset(val) __write_32bit_c0_register($22, 5, val)
  972. /* BMIPS43xx */
  973. #define read_c0_brcm_cmt_intr() __read_32bit_c0_register($22, 1)
  974. #define write_c0_brcm_cmt_intr(val) __write_32bit_c0_register($22, 1, val)
  975. #define read_c0_brcm_cmt_ctrl() __read_32bit_c0_register($22, 2)
  976. #define write_c0_brcm_cmt_ctrl(val) __write_32bit_c0_register($22, 2, val)
  977. #define read_c0_brcm_cmt_local() __read_32bit_c0_register($22, 3)
  978. #define write_c0_brcm_cmt_local(val) __write_32bit_c0_register($22, 3, val)
  979. #define read_c0_brcm_config_1() __read_32bit_c0_register($22, 5)
  980. #define write_c0_brcm_config_1(val) __write_32bit_c0_register($22, 5, val)
  981. #define read_c0_brcm_cbr() __read_32bit_c0_register($22, 6)
  982. #define write_c0_brcm_cbr(val) __write_32bit_c0_register($22, 6, val)
  983. /* BMIPS5000 */
  984. #define read_c0_brcm_config() __read_32bit_c0_register($22, 0)
  985. #define write_c0_brcm_config(val) __write_32bit_c0_register($22, 0, val)
  986. #define read_c0_brcm_mode() __read_32bit_c0_register($22, 1)
  987. #define write_c0_brcm_mode(val) __write_32bit_c0_register($22, 1, val)
  988. #define read_c0_brcm_action() __read_32bit_c0_register($22, 2)
  989. #define write_c0_brcm_action(val) __write_32bit_c0_register($22, 2, val)
  990. #define read_c0_brcm_edsp() __read_32bit_c0_register($22, 3)
  991. #define write_c0_brcm_edsp(val) __write_32bit_c0_register($22, 3, val)
  992. #define read_c0_brcm_bootvec() __read_32bit_c0_register($22, 4)
  993. #define write_c0_brcm_bootvec(val) __write_32bit_c0_register($22, 4, val)
  994. #define read_c0_brcm_sleepcount() __read_32bit_c0_register($22, 7)
  995. #define write_c0_brcm_sleepcount(val) __write_32bit_c0_register($22, 7, val)
  996. /*
  997. * Macros to access the floating point coprocessor control registers
  998. */
  999. #define read_32bit_cp1_register(source) \
  1000. ({ int __res; \
  1001. __asm__ __volatile__( \
  1002. ".set\tpush\n\t" \
  1003. ".set\treorder\n\t" \
  1004. /* gas fails to assemble cfc1 for some archs (octeon).*/ \
  1005. ".set\tmips1\n\t" \
  1006. "cfc1\t%0,"STR(source)"\n\t" \
  1007. ".set\tpop" \
  1008. : "=r" (__res)); \
  1009. __res;})
  1010. #define rddsp(mask) \
  1011. ({ \
  1012. unsigned int __res; \
  1013. \
  1014. __asm__ __volatile__( \
  1015. " .set push \n" \
  1016. " .set noat \n" \
  1017. " # rddsp $1, %x1 \n" \
  1018. " .word 0x7c000cb8 | (%x1 << 16) \n" \
  1019. " move %0, $1 \n" \
  1020. " .set pop \n" \
  1021. : "=r" (__res) \
  1022. : "i" (mask)); \
  1023. __res; \
  1024. })
  1025. #define wrdsp(val, mask) \
  1026. do { \
  1027. __asm__ __volatile__( \
  1028. " .set push \n" \
  1029. " .set noat \n" \
  1030. " move $1, %0 \n" \
  1031. " # wrdsp $1, %x1 \n" \
  1032. " .word 0x7c2004f8 | (%x1 << 11) \n" \
  1033. " .set pop \n" \
  1034. : \
  1035. : "r" (val), "i" (mask)); \
  1036. } while (0)
  1037. #if 0 /* Need DSP ASE capable assembler ... */
  1038. #define mflo0() ({ long mflo0; __asm__("mflo %0, $ac0" : "=r" (mflo0)); mflo0;})
  1039. #define mflo1() ({ long mflo1; __asm__("mflo %0, $ac1" : "=r" (mflo1)); mflo1;})
  1040. #define mflo2() ({ long mflo2; __asm__("mflo %0, $ac2" : "=r" (mflo2)); mflo2;})
  1041. #define mflo3() ({ long mflo3; __asm__("mflo %0, $ac3" : "=r" (mflo3)); mflo3;})
  1042. #define mfhi0() ({ long mfhi0; __asm__("mfhi %0, $ac0" : "=r" (mfhi0)); mfhi0;})
  1043. #define mfhi1() ({ long mfhi1; __asm__("mfhi %0, $ac1" : "=r" (mfhi1)); mfhi1;})
  1044. #define mfhi2() ({ long mfhi2; __asm__("mfhi %0, $ac2" : "=r" (mfhi2)); mfhi2;})
  1045. #define mfhi3() ({ long mfhi3; __asm__("mfhi %0, $ac3" : "=r" (mfhi3)); mfhi3;})
  1046. #define mtlo0(x) __asm__("mtlo %0, $ac0" ::"r" (x))
  1047. #define mtlo1(x) __asm__("mtlo %0, $ac1" ::"r" (x))
  1048. #define mtlo2(x) __asm__("mtlo %0, $ac2" ::"r" (x))
  1049. #define mtlo3(x) __asm__("mtlo %0, $ac3" ::"r" (x))
  1050. #define mthi0(x) __asm__("mthi %0, $ac0" ::"r" (x))
  1051. #define mthi1(x) __asm__("mthi %0, $ac1" ::"r" (x))
  1052. #define mthi2(x) __asm__("mthi %0, $ac2" ::"r" (x))
  1053. #define mthi3(x) __asm__("mthi %0, $ac3" ::"r" (x))
  1054. #else
  1055. #define mfhi0() \
  1056. ({ \
  1057. unsigned long __treg; \
  1058. \
  1059. __asm__ __volatile__( \
  1060. " .set push \n" \
  1061. " .set noat \n" \
  1062. " # mfhi %0, $ac0 \n" \
  1063. " .word 0x00000810 \n" \
  1064. " move %0, $1 \n" \
  1065. " .set pop \n" \
  1066. : "=r" (__treg)); \
  1067. __treg; \
  1068. })
  1069. #define mfhi1() \
  1070. ({ \
  1071. unsigned long __treg; \
  1072. \
  1073. __asm__ __volatile__( \
  1074. " .set push \n" \
  1075. " .set noat \n" \
  1076. " # mfhi %0, $ac1 \n" \
  1077. " .word 0x00200810 \n" \
  1078. " move %0, $1 \n" \
  1079. " .set pop \n" \
  1080. : "=r" (__treg)); \
  1081. __treg; \
  1082. })
  1083. #define mfhi2() \
  1084. ({ \
  1085. unsigned long __treg; \
  1086. \
  1087. __asm__ __volatile__( \
  1088. " .set push \n" \
  1089. " .set noat \n" \
  1090. " # mfhi %0, $ac2 \n" \
  1091. " .word 0x00400810 \n" \
  1092. " move %0, $1 \n" \
  1093. " .set pop \n" \
  1094. : "=r" (__treg)); \
  1095. __treg; \
  1096. })
  1097. #define mfhi3() \
  1098. ({ \
  1099. unsigned long __treg; \
  1100. \
  1101. __asm__ __volatile__( \
  1102. " .set push \n" \
  1103. " .set noat \n" \
  1104. " # mfhi %0, $ac3 \n" \
  1105. " .word 0x00600810 \n" \
  1106. " move %0, $1 \n" \
  1107. " .set pop \n" \
  1108. : "=r" (__treg)); \
  1109. __treg; \
  1110. })
  1111. #define mflo0() \
  1112. ({ \
  1113. unsigned long __treg; \
  1114. \
  1115. __asm__ __volatile__( \
  1116. " .set push \n" \
  1117. " .set noat \n" \
  1118. " # mflo %0, $ac0 \n" \
  1119. " .word 0x00000812 \n" \
  1120. " move %0, $1 \n" \
  1121. " .set pop \n" \
  1122. : "=r" (__treg)); \
  1123. __treg; \
  1124. })
  1125. #define mflo1() \
  1126. ({ \
  1127. unsigned long __treg; \
  1128. \
  1129. __asm__ __volatile__( \
  1130. " .set push \n" \
  1131. " .set noat \n" \
  1132. " # mflo %0, $ac1 \n" \
  1133. " .word 0x00200812 \n" \
  1134. " move %0, $1 \n" \
  1135. " .set pop \n" \
  1136. : "=r" (__treg)); \
  1137. __treg; \
  1138. })
  1139. #define mflo2() \
  1140. ({ \
  1141. unsigned long __treg; \
  1142. \
  1143. __asm__ __volatile__( \
  1144. " .set push \n" \
  1145. " .set noat \n" \
  1146. " # mflo %0, $ac2 \n" \
  1147. " .word 0x00400812 \n" \
  1148. " move %0, $1 \n" \
  1149. " .set pop \n" \
  1150. : "=r" (__treg)); \
  1151. __treg; \
  1152. })
  1153. #define mflo3() \
  1154. ({ \
  1155. unsigned long __treg; \
  1156. \
  1157. __asm__ __volatile__( \
  1158. " .set push \n" \
  1159. " .set noat \n" \
  1160. " # mflo %0, $ac3 \n" \
  1161. " .word 0x00600812 \n" \
  1162. " move %0, $1 \n" \
  1163. " .set pop \n" \
  1164. : "=r" (__treg)); \
  1165. __treg; \
  1166. })
  1167. #define mthi0(x) \
  1168. do { \
  1169. __asm__ __volatile__( \
  1170. " .set push \n" \
  1171. " .set noat \n" \
  1172. " move $1, %0 \n" \
  1173. " # mthi $1, $ac0 \n" \
  1174. " .word 0x00200011 \n" \
  1175. " .set pop \n" \
  1176. : \
  1177. : "r" (x)); \
  1178. } while (0)
  1179. #define mthi1(x) \
  1180. do { \
  1181. __asm__ __volatile__( \
  1182. " .set push \n" \
  1183. " .set noat \n" \
  1184. " move $1, %0 \n" \
  1185. " # mthi $1, $ac1 \n" \
  1186. " .word 0x00200811 \n" \
  1187. " .set pop \n" \
  1188. : \
  1189. : "r" (x)); \
  1190. } while (0)
  1191. #define mthi2(x) \
  1192. do { \
  1193. __asm__ __volatile__( \
  1194. " .set push \n" \
  1195. " .set noat \n" \
  1196. " move $1, %0 \n" \
  1197. " # mthi $1, $ac2 \n" \
  1198. " .word 0x00201011 \n" \
  1199. " .set pop \n" \
  1200. : \
  1201. : "r" (x)); \
  1202. } while (0)
  1203. #define mthi3(x) \
  1204. do { \
  1205. __asm__ __volatile__( \
  1206. " .set push \n" \
  1207. " .set noat \n" \
  1208. " move $1, %0 \n" \
  1209. " # mthi $1, $ac3 \n" \
  1210. " .word 0x00201811 \n" \
  1211. " .set pop \n" \
  1212. : \
  1213. : "r" (x)); \
  1214. } while (0)
  1215. #define mtlo0(x) \
  1216. do { \
  1217. __asm__ __volatile__( \
  1218. " .set push \n" \
  1219. " .set noat \n" \
  1220. " move $1, %0 \n" \
  1221. " # mtlo $1, $ac0 \n" \
  1222. " .word 0x00200013 \n" \
  1223. " .set pop \n" \
  1224. : \
  1225. : "r" (x)); \
  1226. } while (0)
  1227. #define mtlo1(x) \
  1228. do { \
  1229. __asm__ __volatile__( \
  1230. " .set push \n" \
  1231. " .set noat \n" \
  1232. " move $1, %0 \n" \
  1233. " # mtlo $1, $ac1 \n" \
  1234. " .word 0x00200813 \n" \
  1235. " .set pop \n" \
  1236. : \
  1237. : "r" (x)); \
  1238. } while (0)
  1239. #define mtlo2(x) \
  1240. do { \
  1241. __asm__ __volatile__( \
  1242. " .set push \n" \
  1243. " .set noat \n" \
  1244. " move $1, %0 \n" \
  1245. " # mtlo $1, $ac2 \n" \
  1246. " .word 0x00201013 \n" \
  1247. " .set pop \n" \
  1248. : \
  1249. : "r" (x)); \
  1250. } while (0)
  1251. #define mtlo3(x) \
  1252. do { \
  1253. __asm__ __volatile__( \
  1254. " .set push \n" \
  1255. " .set noat \n" \
  1256. " move $1, %0 \n" \
  1257. " # mtlo $1, $ac3 \n" \
  1258. " .word 0x00201813 \n" \
  1259. " .set pop \n" \
  1260. : \
  1261. : "r" (x)); \
  1262. } while (0)
  1263. #endif
  1264. /*
  1265. * TLB operations.
  1266. *
  1267. * It is responsibility of the caller to take care of any TLB hazards.
  1268. */
  1269. static inline void tlb_probe(void)
  1270. {
  1271. __asm__ __volatile__(
  1272. ".set noreorder\n\t"
  1273. "tlbp\n\t"
  1274. ".set reorder");
  1275. }
  1276. static inline void tlb_read(void)
  1277. {
  1278. #if MIPS34K_MISSED_ITLB_WAR
  1279. int res = 0;
  1280. __asm__ __volatile__(
  1281. " .set push \n"
  1282. " .set noreorder \n"
  1283. " .set noat \n"
  1284. " .set mips32r2 \n"
  1285. " .word 0x41610001 # dvpe $1 \n"
  1286. " move %0, $1 \n"
  1287. " ehb \n"
  1288. " .set pop \n"
  1289. : "=r" (res));
  1290. instruction_hazard();
  1291. #endif
  1292. __asm__ __volatile__(
  1293. ".set noreorder\n\t"
  1294. "tlbr\n\t"
  1295. ".set reorder");
  1296. #if MIPS34K_MISSED_ITLB_WAR
  1297. if ((res & _ULCAST_(1)))
  1298. __asm__ __volatile__(
  1299. " .set push \n"
  1300. " .set noreorder \n"
  1301. " .set noat \n"
  1302. " .set mips32r2 \n"
  1303. " .word 0x41600021 # evpe \n"
  1304. " ehb \n"
  1305. " .set pop \n");
  1306. #endif
  1307. }
  1308. static inline void tlb_write_indexed(void)
  1309. {
  1310. __asm__ __volatile__(
  1311. ".set noreorder\n\t"
  1312. "tlbwi\n\t"
  1313. ".set reorder");
  1314. }
  1315. static inline void tlb_write_random(void)
  1316. {
  1317. __asm__ __volatile__(
  1318. ".set noreorder\n\t"
  1319. "tlbwr\n\t"
  1320. ".set reorder");
  1321. }
  1322. /*
  1323. * Manipulate bits in a c0 register.
  1324. */
  1325. #ifndef CONFIG_MIPS_MT_SMTC
  1326. /*
  1327. * SMTC Linux requires shutting-down microthread scheduling
  1328. * during CP0 register read-modify-write sequences.
  1329. */
  1330. #define __BUILD_SET_C0(name) \
  1331. static inline unsigned int \
  1332. set_c0_##name(unsigned int set) \
  1333. { \
  1334. unsigned int res, new; \
  1335. \
  1336. res = read_c0_##name(); \
  1337. new = res | set; \
  1338. write_c0_##name(new); \
  1339. \
  1340. return res; \
  1341. } \
  1342. \
  1343. static inline unsigned int \
  1344. clear_c0_##name(unsigned int clear) \
  1345. { \
  1346. unsigned int res, new; \
  1347. \
  1348. res = read_c0_##name(); \
  1349. new = res & ~clear; \
  1350. write_c0_##name(new); \
  1351. \
  1352. return res; \
  1353. } \
  1354. \
  1355. static inline unsigned int \
  1356. change_c0_##name(unsigned int change, unsigned int val) \
  1357. { \
  1358. unsigned int res, new; \
  1359. \
  1360. res = read_c0_##name(); \
  1361. new = res & ~change; \
  1362. new |= (val & change); \
  1363. write_c0_##name(new); \
  1364. \
  1365. return res; \
  1366. }
  1367. #else /* SMTC versions that manage MT scheduling */
  1368. #include <linux/irqflags.h>
  1369. /*
  1370. * This is a duplicate of dmt() in mipsmtregs.h to avoid problems with
  1371. * header file recursion.
  1372. */
  1373. static inline unsigned int __dmt(void)
  1374. {
  1375. int res;
  1376. __asm__ __volatile__(
  1377. " .set push \n"
  1378. " .set mips32r2 \n"
  1379. " .set noat \n"
  1380. " .word 0x41610BC1 # dmt $1 \n"
  1381. " ehb \n"
  1382. " move %0, $1 \n"
  1383. " .set pop \n"
  1384. : "=r" (res));
  1385. instruction_hazard();
  1386. return res;
  1387. }
  1388. #define __VPECONTROL_TE_SHIFT 15
  1389. #define __VPECONTROL_TE (1UL << __VPECONTROL_TE_SHIFT)
  1390. #define __EMT_ENABLE __VPECONTROL_TE
  1391. static inline void __emt(unsigned int previous)
  1392. {
  1393. if ((previous & __EMT_ENABLE))
  1394. __asm__ __volatile__(
  1395. " .set mips32r2 \n"
  1396. " .word 0x41600be1 # emt \n"
  1397. " ehb \n"
  1398. " .set mips0 \n");
  1399. }
  1400. static inline void __ehb(void)
  1401. {
  1402. __asm__ __volatile__(
  1403. " .set mips32r2 \n"
  1404. " ehb \n" " .set mips0 \n");
  1405. }
  1406. /*
  1407. * Note that local_irq_save/restore affect TC-specific IXMT state,
  1408. * not Status.IE as in non-SMTC kernel.
  1409. */
  1410. #define __BUILD_SET_C0(name) \
  1411. static inline unsigned int \
  1412. set_c0_##name(unsigned int set) \
  1413. { \
  1414. unsigned int res; \
  1415. unsigned int new; \
  1416. unsigned int omt; \
  1417. unsigned long flags; \
  1418. \
  1419. local_irq_save(flags); \
  1420. omt = __dmt(); \
  1421. res = read_c0_##name(); \
  1422. new = res | set; \
  1423. write_c0_##name(new); \
  1424. __emt(omt); \
  1425. local_irq_restore(flags); \
  1426. \
  1427. return res; \
  1428. } \
  1429. \
  1430. static inline unsigned int \
  1431. clear_c0_##name(unsigned int clear) \
  1432. { \
  1433. unsigned int res; \
  1434. unsigned int new; \
  1435. unsigned int omt; \
  1436. unsigned long flags; \
  1437. \
  1438. local_irq_save(flags); \
  1439. omt = __dmt(); \
  1440. res = read_c0_##name(); \
  1441. new = res & ~clear; \
  1442. write_c0_##name(new); \
  1443. __emt(omt); \
  1444. local_irq_restore(flags); \
  1445. \
  1446. return res; \
  1447. } \
  1448. \
  1449. static inline unsigned int \
  1450. change_c0_##name(unsigned int change, unsigned int newbits) \
  1451. { \
  1452. unsigned int res; \
  1453. unsigned int new; \
  1454. unsigned int omt; \
  1455. unsigned long flags; \
  1456. \
  1457. local_irq_save(flags); \
  1458. \
  1459. omt = __dmt(); \
  1460. res = read_c0_##name(); \
  1461. new = res & ~change; \
  1462. new |= (newbits & change); \
  1463. write_c0_##name(new); \
  1464. __emt(omt); \
  1465. local_irq_restore(flags); \
  1466. \
  1467. return res; \
  1468. }
  1469. #endif
  1470. __BUILD_SET_C0(status)
  1471. __BUILD_SET_C0(cause)
  1472. __BUILD_SET_C0(config)
  1473. __BUILD_SET_C0(intcontrol)
  1474. __BUILD_SET_C0(intctl)
  1475. __BUILD_SET_C0(srsmap)
  1476. __BUILD_SET_C0(brcm_config_0)
  1477. __BUILD_SET_C0(brcm_bus_pll)
  1478. __BUILD_SET_C0(brcm_reset)
  1479. __BUILD_SET_C0(brcm_cmt_intr)
  1480. __BUILD_SET_C0(brcm_cmt_ctrl)
  1481. __BUILD_SET_C0(brcm_config)
  1482. __BUILD_SET_C0(brcm_mode)
  1483. #endif /* !__ASSEMBLY__ */
  1484. #endif /* _ASM_MIPSREGS_H */