system.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #ifndef _ASM_IA64_SYSTEM_H
  2. #define _ASM_IA64_SYSTEM_H
  3. /*
  4. * System defines. Note that this is included both from .c and .S
  5. * files, so it does only defines, not any C code. This is based
  6. * on information published in the Processor Abstraction Layer
  7. * and the System Abstraction Layer manual.
  8. *
  9. * Copyright (C) 1998-2003 Hewlett-Packard Co
  10. * David Mosberger-Tang <davidm@hpl.hp.com>
  11. * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
  12. * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
  13. */
  14. #include <linux/config.h>
  15. #include <asm/kregs.h>
  16. #include <asm/page.h>
  17. #include <asm/pal.h>
  18. #include <asm/percpu.h>
  19. #define GATE_ADDR RGN_BASE(RGN_GATE)
  20. /*
  21. * 0xa000000000000000+2*PERCPU_PAGE_SIZE
  22. * - 0xa000000000000000+3*PERCPU_PAGE_SIZE remain unmapped (guard page)
  23. */
  24. #define KERNEL_START (GATE_ADDR+0x100000000)
  25. #define PERCPU_ADDR (-PERCPU_PAGE_SIZE)
  26. #ifndef __ASSEMBLY__
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. struct pci_vector_struct {
  30. __u16 segment; /* PCI Segment number */
  31. __u16 bus; /* PCI Bus number */
  32. __u32 pci_id; /* ACPI split 16 bits device, 16 bits function (see section 6.1.1) */
  33. __u8 pin; /* PCI PIN (0 = A, 1 = B, 2 = C, 3 = D) */
  34. __u32 irq; /* IRQ assigned */
  35. };
  36. extern struct ia64_boot_param {
  37. __u64 command_line; /* physical address of command line arguments */
  38. __u64 efi_systab; /* physical address of EFI system table */
  39. __u64 efi_memmap; /* physical address of EFI memory map */
  40. __u64 efi_memmap_size; /* size of EFI memory map */
  41. __u64 efi_memdesc_size; /* size of an EFI memory map descriptor */
  42. __u32 efi_memdesc_version; /* memory descriptor version */
  43. struct {
  44. __u16 num_cols; /* number of columns on console output device */
  45. __u16 num_rows; /* number of rows on console output device */
  46. __u16 orig_x; /* cursor's x position */
  47. __u16 orig_y; /* cursor's y position */
  48. } console_info;
  49. __u64 fpswa; /* physical address of the fpswa interface */
  50. __u64 initrd_start;
  51. __u64 initrd_size;
  52. } *ia64_boot_param;
  53. /*
  54. * Macros to force memory ordering. In these descriptions, "previous"
  55. * and "subsequent" refer to program order; "visible" means that all
  56. * architecturally visible effects of a memory access have occurred
  57. * (at a minimum, this means the memory has been read or written).
  58. *
  59. * wmb(): Guarantees that all preceding stores to memory-
  60. * like regions are visible before any subsequent
  61. * stores and that all following stores will be
  62. * visible only after all previous stores.
  63. * rmb(): Like wmb(), but for reads.
  64. * mb(): wmb()/rmb() combo, i.e., all previous memory
  65. * accesses are visible before all subsequent
  66. * accesses and vice versa. This is also known as
  67. * a "fence."
  68. *
  69. * Note: "mb()" and its variants cannot be used as a fence to order
  70. * accesses to memory mapped I/O registers. For that, mf.a needs to
  71. * be used. However, we don't want to always use mf.a because (a)
  72. * it's (presumably) much slower than mf and (b) mf.a is supported for
  73. * sequential memory pages only.
  74. */
  75. #define mb() ia64_mf()
  76. #define rmb() mb()
  77. #define wmb() mb()
  78. #define read_barrier_depends() do { } while(0)
  79. #ifdef CONFIG_SMP
  80. # define smp_mb() mb()
  81. # define smp_rmb() rmb()
  82. # define smp_wmb() wmb()
  83. # define smp_read_barrier_depends() read_barrier_depends()
  84. #else
  85. # define smp_mb() barrier()
  86. # define smp_rmb() barrier()
  87. # define smp_wmb() barrier()
  88. # define smp_read_barrier_depends() do { } while(0)
  89. #endif
  90. /*
  91. * XXX check on these---I suspect what Linus really wants here is
  92. * acquire vs release semantics but we can't discuss this stuff with
  93. * Linus just yet. Grrr...
  94. */
  95. #define set_mb(var, value) do { (var) = (value); mb(); } while (0)
  96. #define set_wmb(var, value) do { (var) = (value); mb(); } while (0)
  97. #define safe_halt() ia64_pal_halt_light() /* PAL_HALT_LIGHT */
  98. /*
  99. * The group barrier in front of the rsm & ssm are necessary to ensure
  100. * that none of the previous instructions in the same group are
  101. * affected by the rsm/ssm.
  102. */
  103. /* For spinlocks etc */
  104. /*
  105. * - clearing psr.i is implicitly serialized (visible by next insn)
  106. * - setting psr.i requires data serialization
  107. * - we need a stop-bit before reading PSR because we sometimes
  108. * write a floating-point register right before reading the PSR
  109. * and that writes to PSR.mfl
  110. */
  111. #define __local_irq_save(x) \
  112. do { \
  113. ia64_stop(); \
  114. (x) = ia64_getreg(_IA64_REG_PSR); \
  115. ia64_stop(); \
  116. ia64_rsm(IA64_PSR_I); \
  117. } while (0)
  118. #define __local_irq_disable() \
  119. do { \
  120. ia64_stop(); \
  121. ia64_rsm(IA64_PSR_I); \
  122. } while (0)
  123. #define __local_irq_restore(x) ia64_intrin_local_irq_restore((x) & IA64_PSR_I)
  124. #ifdef CONFIG_IA64_DEBUG_IRQ
  125. extern unsigned long last_cli_ip;
  126. # define __save_ip() last_cli_ip = ia64_getreg(_IA64_REG_IP)
  127. # define local_irq_save(x) \
  128. do { \
  129. unsigned long psr; \
  130. \
  131. __local_irq_save(psr); \
  132. if (psr & IA64_PSR_I) \
  133. __save_ip(); \
  134. (x) = psr; \
  135. } while (0)
  136. # define local_irq_disable() do { unsigned long x; local_irq_save(x); } while (0)
  137. # define local_irq_restore(x) \
  138. do { \
  139. unsigned long old_psr, psr = (x); \
  140. \
  141. local_save_flags(old_psr); \
  142. __local_irq_restore(psr); \
  143. if ((old_psr & IA64_PSR_I) && !(psr & IA64_PSR_I)) \
  144. __save_ip(); \
  145. } while (0)
  146. #else /* !CONFIG_IA64_DEBUG_IRQ */
  147. # define local_irq_save(x) __local_irq_save(x)
  148. # define local_irq_disable() __local_irq_disable()
  149. # define local_irq_restore(x) __local_irq_restore(x)
  150. #endif /* !CONFIG_IA64_DEBUG_IRQ */
  151. #define local_irq_enable() ({ ia64_stop(); ia64_ssm(IA64_PSR_I); ia64_srlz_d(); })
  152. #define local_save_flags(flags) ({ ia64_stop(); (flags) = ia64_getreg(_IA64_REG_PSR); })
  153. #define irqs_disabled() \
  154. ({ \
  155. unsigned long __ia64_id_flags; \
  156. local_save_flags(__ia64_id_flags); \
  157. (__ia64_id_flags & IA64_PSR_I) == 0; \
  158. })
  159. #ifdef __KERNEL__
  160. #ifdef CONFIG_IA32_SUPPORT
  161. # define IS_IA32_PROCESS(regs) (ia64_psr(regs)->is != 0)
  162. #else
  163. # define IS_IA32_PROCESS(regs) 0
  164. struct task_struct;
  165. static inline void ia32_save_state(struct task_struct *t __attribute__((unused))){}
  166. static inline void ia32_load_state(struct task_struct *t __attribute__((unused))){}
  167. #endif
  168. /*
  169. * Context switch from one thread to another. If the two threads have
  170. * different address spaces, schedule() has already taken care of
  171. * switching to the new address space by calling switch_mm().
  172. *
  173. * Disabling access to the fph partition and the debug-register
  174. * context switch MUST be done before calling ia64_switch_to() since a
  175. * newly created thread returns directly to
  176. * ia64_ret_from_syscall_clear_r8.
  177. */
  178. extern struct task_struct *ia64_switch_to (void *next_task);
  179. struct task_struct;
  180. extern void ia64_save_extra (struct task_struct *task);
  181. extern void ia64_load_extra (struct task_struct *task);
  182. #ifdef CONFIG_PERFMON
  183. DECLARE_PER_CPU(unsigned long, pfm_syst_info);
  184. # define PERFMON_IS_SYSWIDE() (__get_cpu_var(pfm_syst_info) & 0x1)
  185. #else
  186. # define PERFMON_IS_SYSWIDE() (0)
  187. #endif
  188. #define IA64_HAS_EXTRA_STATE(t) \
  189. ((t)->thread.flags & (IA64_THREAD_DBG_VALID|IA64_THREAD_PM_VALID) \
  190. || IS_IA32_PROCESS(task_pt_regs(t)) || PERFMON_IS_SYSWIDE())
  191. #define __switch_to(prev,next,last) do { \
  192. if (IA64_HAS_EXTRA_STATE(prev)) \
  193. ia64_save_extra(prev); \
  194. if (IA64_HAS_EXTRA_STATE(next)) \
  195. ia64_load_extra(next); \
  196. ia64_psr(task_pt_regs(next))->dfh = !ia64_is_local_fpu_owner(next); \
  197. (last) = ia64_switch_to((next)); \
  198. } while (0)
  199. #ifdef CONFIG_SMP
  200. /*
  201. * In the SMP case, we save the fph state when context-switching away from a thread that
  202. * modified fph. This way, when the thread gets scheduled on another CPU, the CPU can
  203. * pick up the state from task->thread.fph, avoiding the complication of having to fetch
  204. * the latest fph state from another CPU. In other words: eager save, lazy restore.
  205. */
  206. # define switch_to(prev,next,last) do { \
  207. if (ia64_psr(task_pt_regs(prev))->mfh && ia64_is_local_fpu_owner(prev)) { \
  208. ia64_psr(task_pt_regs(prev))->mfh = 0; \
  209. (prev)->thread.flags |= IA64_THREAD_FPH_VALID; \
  210. __ia64_save_fpu((prev)->thread.fph); \
  211. } \
  212. __switch_to(prev, next, last); \
  213. } while (0)
  214. #else
  215. # define switch_to(prev,next,last) __switch_to(prev, next, last)
  216. #endif
  217. /*
  218. * On IA-64, we don't want to hold the runqueue's lock during the low-level context-switch,
  219. * because that could cause a deadlock. Here is an example by Erich Focht:
  220. *
  221. * Example:
  222. * CPU#0:
  223. * schedule()
  224. * -> spin_lock_irq(&rq->lock)
  225. * -> context_switch()
  226. * -> wrap_mmu_context()
  227. * -> read_lock(&tasklist_lock)
  228. *
  229. * CPU#1:
  230. * sys_wait4() or release_task() or forget_original_parent()
  231. * -> write_lock(&tasklist_lock)
  232. * -> do_notify_parent()
  233. * -> wake_up_parent()
  234. * -> try_to_wake_up()
  235. * -> spin_lock_irq(&parent_rq->lock)
  236. *
  237. * If the parent's rq happens to be on CPU#0, we'll wait for the rq->lock
  238. * of that CPU which will not be released, because there we wait for the
  239. * tasklist_lock to become available.
  240. */
  241. #define __ARCH_WANT_UNLOCKED_CTXSW
  242. #define ARCH_HAS_PREFETCH_SWITCH_STACK
  243. #define ia64_platform_is(x) (strcmp(x, platform_name) == 0)
  244. void cpu_idle_wait(void);
  245. void sched_cacheflush(void);
  246. #define arch_align_stack(x) (x)
  247. #endif /* __KERNEL__ */
  248. #endif /* __ASSEMBLY__ */
  249. #endif /* _ASM_IA64_SYSTEM_H */