mipsregs.h 45 KB

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