processor.h 11 KB

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