processor.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * include/asm-s390/processor.h
  3. *
  4. * S390 version
  5. * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Hartmut Penner (hp@de.ibm.com),
  7. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. *
  9. * Derived from "include/asm-i386/processor.h"
  10. * Copyright (C) 1994, Linus Torvalds
  11. */
  12. #ifndef __ASM_S390_PROCESSOR_H
  13. #define __ASM_S390_PROCESSOR_H
  14. #include <asm/ptrace.h>
  15. #ifdef __KERNEL__
  16. /*
  17. * Default implementation of macro that returns current
  18. * instruction pointer ("program counter").
  19. */
  20. #define current_text_addr() ({ void *pc; asm("basr %0,0" : "=a" (pc)); pc; })
  21. /*
  22. * CPU type and hardware bug flags. Kept separately for each CPU.
  23. * Members of this structure are referenced in head.S, so think twice
  24. * before touching them. [mj]
  25. */
  26. typedef struct
  27. {
  28. unsigned int version : 8;
  29. unsigned int ident : 24;
  30. unsigned int machine : 16;
  31. unsigned int unused : 16;
  32. } __attribute__ ((packed)) cpuid_t;
  33. static inline void get_cpu_id(cpuid_t *ptr)
  34. {
  35. asm volatile("stidp 0(%1)" : "=m" (*ptr) : "a" (ptr));
  36. }
  37. struct cpuinfo_S390
  38. {
  39. cpuid_t cpu_id;
  40. __u16 cpu_addr;
  41. __u16 cpu_nr;
  42. unsigned long loops_per_jiffy;
  43. unsigned long *pgd_quick;
  44. #ifdef __s390x__
  45. unsigned long *pmd_quick;
  46. #endif /* __s390x__ */
  47. unsigned long *pte_quick;
  48. unsigned long pgtable_cache_sz;
  49. };
  50. extern void s390_adjust_jiffies(void);
  51. extern void print_cpu_info(struct cpuinfo_S390 *);
  52. extern int get_cpu_capability(unsigned int *);
  53. /* Lazy FPU handling on uni-processor */
  54. extern struct task_struct *last_task_used_math;
  55. /*
  56. * User space process size: 2GB for 31 bit, 4TB for 64 bit.
  57. */
  58. #ifndef __s390x__
  59. # define TASK_SIZE (0x80000000UL)
  60. # define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
  61. # define DEFAULT_TASK_SIZE (0x80000000UL)
  62. #else /* __s390x__ */
  63. # define TASK_SIZE (test_thread_flag(TIF_31BIT) ? \
  64. (0x80000000UL) : (0x40000000000UL))
  65. # define TASK_UNMAPPED_BASE (TASK_SIZE / 2)
  66. # define DEFAULT_TASK_SIZE (0x40000000000UL)
  67. #endif /* __s390x__ */
  68. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  69. typedef struct {
  70. __u32 ar4;
  71. } mm_segment_t;
  72. /*
  73. * Thread structure
  74. */
  75. struct thread_struct {
  76. s390_fp_regs fp_regs;
  77. unsigned int acrs[NUM_ACRS];
  78. unsigned long ksp; /* kernel stack pointer */
  79. unsigned long user_seg; /* HSTD */
  80. mm_segment_t mm_segment;
  81. unsigned long prot_addr; /* address of protection-excep. */
  82. unsigned int error_code; /* error-code of last prog-excep. */
  83. unsigned int trap_no;
  84. per_struct per_info;
  85. /* Used to give failing instruction back to user for ieee exceptions */
  86. unsigned long ieee_instruction_pointer;
  87. /* pfault_wait is used to block the process on a pfault event */
  88. unsigned long pfault_wait;
  89. };
  90. typedef struct thread_struct thread_struct;
  91. /*
  92. * Stack layout of a C stack frame.
  93. */
  94. #ifndef __PACK_STACK
  95. struct stack_frame {
  96. unsigned long back_chain;
  97. unsigned long empty1[5];
  98. unsigned long gprs[10];
  99. unsigned int empty2[8];
  100. };
  101. #else
  102. struct stack_frame {
  103. unsigned long empty1[5];
  104. unsigned int empty2[8];
  105. unsigned long gprs[10];
  106. unsigned long back_chain;
  107. };
  108. #endif
  109. #define ARCH_MIN_TASKALIGN 8
  110. #ifndef __s390x__
  111. # define __SWAPPER_PG_DIR __pa(&swapper_pg_dir[0]) + _SEGMENT_TABLE
  112. #else /* __s390x__ */
  113. # define __SWAPPER_PG_DIR __pa(&swapper_pg_dir[0]) + _REGION_TABLE
  114. #endif /* __s390x__ */
  115. #define INIT_THREAD {{0,{{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, \
  116. {0},{0},{0},{0},{0},{0}}}, \
  117. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \
  118. sizeof(init_stack) + (unsigned long) &init_stack, \
  119. __SWAPPER_PG_DIR, \
  120. {0}, \
  121. 0,0,0, \
  122. (per_struct) {{{{0,}}},0,0,0,0,{{0,}}}, \
  123. 0, 0 \
  124. }
  125. /*
  126. * Do necessary setup to start up a new thread.
  127. */
  128. #ifndef __s390x__
  129. #define start_thread(regs, new_psw, new_stackp) do { \
  130. set_fs(USER_DS); \
  131. regs->psw.mask = psw_user_bits; \
  132. regs->psw.addr = new_psw | PSW_ADDR_AMODE; \
  133. regs->gprs[15] = new_stackp ; \
  134. } while (0)
  135. #else /* __s390x__ */
  136. #define start_thread(regs, new_psw, new_stackp) do { \
  137. set_fs(USER_DS); \
  138. regs->psw.mask = psw_user_bits; \
  139. regs->psw.addr = new_psw; \
  140. regs->gprs[15] = new_stackp; \
  141. } while (0)
  142. #define start_thread31(regs, new_psw, new_stackp) do { \
  143. set_fs(USER_DS); \
  144. regs->psw.mask = psw_user32_bits; \
  145. regs->psw.addr = new_psw; \
  146. regs->gprs[15] = new_stackp; \
  147. } while (0)
  148. #endif /* __s390x__ */
  149. /* Forward declaration, a strange C thing */
  150. struct task_struct;
  151. struct mm_struct;
  152. /* Free all resources held by a thread. */
  153. extern void release_thread(struct task_struct *);
  154. extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
  155. /* Prepare to copy thread state - unlazy all lazy status */
  156. #define prepare_to_copy(tsk) do { } while (0)
  157. /*
  158. * Return saved PC of a blocked thread.
  159. */
  160. extern unsigned long thread_saved_pc(struct task_struct *t);
  161. /*
  162. * Print register of task into buffer. Used in fs/proc/array.c.
  163. */
  164. extern char *task_show_regs(struct task_struct *task, char *buffer);
  165. extern void show_registers(struct pt_regs *regs);
  166. extern void show_code(struct pt_regs *regs);
  167. extern void show_trace(struct task_struct *task, unsigned long *sp);
  168. unsigned long get_wchan(struct task_struct *p);
  169. #define task_pt_regs(tsk) ((struct pt_regs *) \
  170. (task_stack_page(tsk) + THREAD_SIZE) - 1)
  171. #define KSTK_EIP(tsk) (task_pt_regs(tsk)->psw.addr)
  172. #define KSTK_ESP(tsk) (task_pt_regs(tsk)->gprs[15])
  173. /*
  174. * Give up the time slice of the virtual PU.
  175. */
  176. static inline void cpu_relax(void)
  177. {
  178. if (MACHINE_HAS_DIAG44)
  179. asm volatile("diag 0,0,68");
  180. barrier();
  181. }
  182. static inline void psw_set_key(unsigned int key)
  183. {
  184. asm volatile("spka 0(%0)" : : "d" (key));
  185. }
  186. /*
  187. * Set PSW to specified value.
  188. */
  189. static inline void __load_psw(psw_t psw)
  190. {
  191. #ifndef __s390x__
  192. asm volatile("lpsw 0(%0)" : : "a" (&psw), "m" (psw) : "cc");
  193. #else
  194. asm volatile("lpswe 0(%0)" : : "a" (&psw), "m" (psw) : "cc");
  195. #endif
  196. }
  197. /*
  198. * Set PSW mask to specified value, while leaving the
  199. * PSW addr pointing to the next instruction.
  200. */
  201. static inline void __load_psw_mask (unsigned long mask)
  202. {
  203. unsigned long addr;
  204. psw_t psw;
  205. psw.mask = mask;
  206. #ifndef __s390x__
  207. asm volatile(
  208. " basr %0,0\n"
  209. "0: ahi %0,1f-0b\n"
  210. " st %0,4(%1)\n"
  211. " lpsw 0(%1)\n"
  212. "1:"
  213. : "=&d" (addr) : "a" (&psw), "m" (psw) : "memory", "cc");
  214. #else /* __s390x__ */
  215. asm volatile(
  216. " larl %0,1f\n"
  217. " stg %0,8(%1)\n"
  218. " lpswe 0(%1)\n"
  219. "1:"
  220. : "=&d" (addr) : "a" (&psw), "m" (psw) : "memory", "cc");
  221. #endif /* __s390x__ */
  222. }
  223. /*
  224. * Function to stop a processor until an interruption occurred
  225. */
  226. static inline void enabled_wait(void)
  227. {
  228. __load_psw_mask(PSW_BASE_BITS | PSW_MASK_IO | PSW_MASK_EXT |
  229. PSW_MASK_MCHECK | PSW_MASK_WAIT | PSW_DEFAULT_KEY);
  230. }
  231. /*
  232. * Function to drop a processor into disabled wait state
  233. */
  234. static inline void disabled_wait(unsigned long code)
  235. {
  236. unsigned long ctl_buf;
  237. psw_t dw_psw;
  238. dw_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
  239. dw_psw.addr = code;
  240. /*
  241. * Store status and then load disabled wait psw,
  242. * the processor is dead afterwards
  243. */
  244. #ifndef __s390x__
  245. asm volatile(
  246. " stctl 0,0,0(%2)\n"
  247. " ni 0(%2),0xef\n" /* switch off protection */
  248. " lctl 0,0,0(%2)\n"
  249. " stpt 0xd8\n" /* store timer */
  250. " stckc 0xe0\n" /* store clock comparator */
  251. " stpx 0x108\n" /* store prefix register */
  252. " stam 0,15,0x120\n" /* store access registers */
  253. " std 0,0x160\n" /* store f0 */
  254. " std 2,0x168\n" /* store f2 */
  255. " std 4,0x170\n" /* store f4 */
  256. " std 6,0x178\n" /* store f6 */
  257. " stm 0,15,0x180\n" /* store general registers */
  258. " stctl 0,15,0x1c0\n" /* store control registers */
  259. " oi 0x1c0,0x10\n" /* fake protection bit */
  260. " lpsw 0(%1)"
  261. : "=m" (ctl_buf)
  262. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc");
  263. #else /* __s390x__ */
  264. asm volatile(
  265. " stctg 0,0,0(%2)\n"
  266. " ni 4(%2),0xef\n" /* switch off protection */
  267. " lctlg 0,0,0(%2)\n"
  268. " lghi 1,0x1000\n"
  269. " stpt 0x328(1)\n" /* store timer */
  270. " stckc 0x330(1)\n" /* store clock comparator */
  271. " stpx 0x318(1)\n" /* store prefix register */
  272. " stam 0,15,0x340(1)\n"/* store access registers */
  273. " stfpc 0x31c(1)\n" /* store fpu control */
  274. " std 0,0x200(1)\n" /* store f0 */
  275. " std 1,0x208(1)\n" /* store f1 */
  276. " std 2,0x210(1)\n" /* store f2 */
  277. " std 3,0x218(1)\n" /* store f3 */
  278. " std 4,0x220(1)\n" /* store f4 */
  279. " std 5,0x228(1)\n" /* store f5 */
  280. " std 6,0x230(1)\n" /* store f6 */
  281. " std 7,0x238(1)\n" /* store f7 */
  282. " std 8,0x240(1)\n" /* store f8 */
  283. " std 9,0x248(1)\n" /* store f9 */
  284. " std 10,0x250(1)\n" /* store f10 */
  285. " std 11,0x258(1)\n" /* store f11 */
  286. " std 12,0x260(1)\n" /* store f12 */
  287. " std 13,0x268(1)\n" /* store f13 */
  288. " std 14,0x270(1)\n" /* store f14 */
  289. " std 15,0x278(1)\n" /* store f15 */
  290. " stmg 0,15,0x280(1)\n"/* store general registers */
  291. " stctg 0,15,0x380(1)\n"/* store control registers */
  292. " oi 0x384(1),0x10\n"/* fake protection bit */
  293. " lpswe 0(%1)"
  294. : "=m" (ctl_buf)
  295. : "a" (&dw_psw), "a" (&ctl_buf), "m" (dw_psw) : "cc", "0");
  296. #endif /* __s390x__ */
  297. }
  298. /*
  299. * Basic Machine Check/Program Check Handler.
  300. */
  301. extern void s390_base_mcck_handler(void);
  302. extern void s390_base_pgm_handler(void);
  303. extern void s390_base_ext_handler(void);
  304. extern void (*s390_base_mcck_handler_fn)(void);
  305. extern void (*s390_base_pgm_handler_fn)(void);
  306. extern void (*s390_base_ext_handler_fn)(void);
  307. /*
  308. * CPU idle notifier chain.
  309. */
  310. #define S390_CPU_IDLE 0
  311. #define S390_CPU_NOT_IDLE 1
  312. struct notifier_block;
  313. int register_idle_notifier(struct notifier_block *nb);
  314. int unregister_idle_notifier(struct notifier_block *nb);
  315. #define ARCH_LOW_ADDRESS_LIMIT 0x7fffffffUL
  316. #endif
  317. /*
  318. * Helper macro for exception table entries
  319. */
  320. #ifndef __s390x__
  321. #define EX_TABLE(_fault,_target) \
  322. ".section __ex_table,\"a\"\n" \
  323. " .align 4\n" \
  324. " .long " #_fault "," #_target "\n" \
  325. ".previous\n"
  326. #else
  327. #define EX_TABLE(_fault,_target) \
  328. ".section __ex_table,\"a\"\n" \
  329. " .align 8\n" \
  330. " .quad " #_fault "," #_target "\n" \
  331. ".previous\n"
  332. #endif
  333. #endif /* __ASM_S390_PROCESSOR_H */