processor.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:25k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef _ASM_IA64_PROCESSOR_H
  2. #define _ASM_IA64_PROCESSOR_H
  3. /*
  4.  * Copyright (C) 1998-2002 Hewlett-Packard Co
  5.  * David Mosberger-Tang <davidm@hpl.hp.com>
  6.  * Stephane Eranian <eranian@hpl.hp.com>
  7.  * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
  8.  * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
  9.  *
  10.  * 11/24/98 S.Eranian added ia64_set_iva()
  11.  * 12/03/99 D. Mosberger implement thread_saved_pc() via kernel unwind API
  12.  * 06/16/00 A. Mallick added csd/ssd/tssd for ia32 support
  13.  */
  14. #include <linux/config.h>
  15. #include <linux/cache.h>
  16. #include <asm/ptrace.h>
  17. #include <asm/kregs.h>
  18. #include <asm/types.h>
  19. #define IA64_NUM_DBG_REGS 8
  20. /*
  21.  * Limits for PMC and PMD are set to less than maximum architected values
  22.  * but should be sufficient for a while
  23.  */
  24. #define IA64_NUM_PMC_REGS 32
  25. #define IA64_NUM_PMD_REGS 32
  26. #define DEFAULT_MAP_BASE 0x2000000000000000
  27. #define DEFAULT_TASK_SIZE 0xa000000000000000
  28. /*
  29.  * TASK_SIZE really is a mis-named.  It really is the maximum user
  30.  * space address (plus one).  On IA-64, there are five regions of 2TB
  31.  * each (assuming 8KB page size), for a total of 8TB of user virtual
  32.  * address space.
  33.  */
  34. #define TASK_SIZE (current->thread.task_size)
  35. /*
  36.  * This decides where the kernel will search for a free chunk of vm
  37.  * space during mmap's.
  38.  */
  39. #define TASK_UNMAPPED_BASE (current->thread.map_base)
  40. /*
  41.  * Bus types
  42.  */
  43. #define EISA_bus 0
  44. #define EISA_bus__is_a_macro /* for versions in ksyms.c */
  45. #define MCA_bus 0
  46. #define MCA_bus__is_a_macro /* for versions in ksyms.c */
  47. #define IA64_THREAD_FPH_VALID (__IA64_UL(1) << 0) /* floating-point high state valid? */
  48. #define IA64_THREAD_DBG_VALID (__IA64_UL(1) << 1) /* debug registers valid? */
  49. #define IA64_THREAD_PM_VALID (__IA64_UL(1) << 2) /* performance registers valid? */
  50. #define IA64_THREAD_UAC_NOPRINT (__IA64_UL(1) << 3) /* don't log unaligned accesses */
  51. #define IA64_THREAD_UAC_SIGBUS (__IA64_UL(1) << 4) /* generate SIGBUS on unaligned acc. */
  52. #define IA64_THREAD_KRBS_SYNCED (__IA64_UL(1) << 5) /* krbs synced with process vm? */
  53. #define IA64_THREAD_FPEMU_NOPRINT (__IA64_UL(1) << 6) /* don't log any fpswa faults */
  54. #define IA64_THREAD_FPEMU_SIGFPE  (__IA64_UL(1) << 7) /* send a SIGFPE for fpswa faults */
  55. #define IA64_THREAD_XSTACK (__IA64_UL(1) << 8) /* stack executable by default? */
  56. #define IA64_THREAD_UAC_SHIFT 3
  57. #define IA64_THREAD_UAC_MASK (IA64_THREAD_UAC_NOPRINT | IA64_THREAD_UAC_SIGBUS)
  58. #define IA64_THREAD_FPEMU_SHIFT 6
  59. #define IA64_THREAD_FPEMU_MASK (IA64_THREAD_FPEMU_NOPRINT | IA64_THREAD_FPEMU_SIGFPE)
  60. /*
  61.  * This shift should be large enough to be able to represent
  62.  * 1000000/itc_freq with good accuracy while being small enough to fit
  63.  * 1000000<<IA64_USEC_PER_CYC_SHIFT in 64 bits.
  64.  */
  65. #define IA64_USEC_PER_CYC_SHIFT 41
  66. #ifndef __ASSEMBLY__
  67. #include <linux/threads.h>
  68. #include <linux/cache.h>
  69. #include <asm/fpu.h>
  70. #include <asm/offsets.h>
  71. #include <asm/page.h>
  72. #include <asm/rse.h>
  73. #include <asm/unwind.h>
  74. #include <asm/atomic.h>
  75. /* like above but expressed as bitfields for more efficient access: */
  76. struct ia64_psr {
  77. __u64 reserved0 : 1;
  78. __u64 be : 1;
  79. __u64 up : 1;
  80. __u64 ac : 1;
  81. __u64 mfl : 1;
  82. __u64 mfh : 1;
  83. __u64 reserved1 : 7;
  84. __u64 ic : 1;
  85. __u64 i : 1;
  86. __u64 pk : 1;
  87. __u64 reserved2 : 1;
  88. __u64 dt : 1;
  89. __u64 dfl : 1;
  90. __u64 dfh : 1;
  91. __u64 sp : 1;
  92. __u64 pp : 1;
  93. __u64 di : 1;
  94. __u64 si : 1;
  95. __u64 db : 1;
  96. __u64 lp : 1;
  97. __u64 tb : 1;
  98. __u64 rt : 1;
  99. __u64 reserved3 : 4;
  100. __u64 cpl : 2;
  101. __u64 is : 1;
  102. __u64 mc : 1;
  103. __u64 it : 1;
  104. __u64 id : 1;
  105. __u64 da : 1;
  106. __u64 dd : 1;
  107. __u64 ss : 1;
  108. __u64 ri : 2;
  109. __u64 ed : 1;
  110. __u64 bn : 1;
  111. __u64 reserved4 : 19;
  112. };
  113. /*
  114.  * CPU type, hardware bug flags, and per-CPU state.  Frequently used
  115.  * state comes earlier:
  116.  */
  117. struct cpuinfo_ia64 {
  118. /* irq_stat must be 64-bit aligned */
  119. union {
  120. struct {
  121. __u32 irq_count;
  122. __u32 bh_count;
  123. } f;
  124. __u64 irq_and_bh_counts;
  125. } irq_stat;
  126. __u32 softirq_pending;
  127. __u32 phys_stacked_size_p8; /* size of physical stacked registers + 8 */
  128. __u64 itm_delta; /* # of clock cycles between clock ticks */
  129. __u64 itm_next; /* interval timer mask value to use for next clock tick */
  130. __u64 *pgd_quick;
  131. __u64 *pmd_quick;
  132. __u64 *pte_quick;
  133. __u64 pgtable_cache_sz;
  134. /* CPUID-derived information: */
  135. __u64 ppn;
  136. __u64 features;
  137. __u8 number;
  138. __u8 revision;
  139. __u8 model;
  140. __u8 family;
  141. __u8 archrev;
  142. char vendor[16];
  143. __u64 itc_freq; /* frequency of ITC counter */
  144. __u64 proc_freq; /* frequency of processor */
  145. __u64 cyc_per_usec; /* itc_freq/1000000 */
  146. __u64 usec_per_cyc; /* 2^IA64_USEC_PER_CYC_SHIFT*1000000/itc_freq */
  147. __u64 unimpl_va_mask; /* mask of unimplemented virtual address bits (from PAL) */
  148. __u64 unimpl_pa_mask; /* mask of unimplemented physical address bits (from PAL) */
  149. __u64 ptce_base;
  150. __u32 ptce_count[2];
  151. __u32 ptce_stride[2];
  152. struct task_struct *ksoftirqd; /* kernel softirq daemon for this CPU */
  153. #ifdef CONFIG_SMP
  154. int processor;
  155. __u64 loops_per_jiffy;
  156. __u64 ipi_count;
  157. __u64 prof_counter;
  158. __u64 prof_multiplier;
  159. # ifdef CONFIG_PERFMON
  160. __u32 pfm_syst_wide;
  161. __u32 pfm_dcr_pp;
  162. # endif
  163. union {
  164. /*
  165.  *  This is written to by *other* CPUs,
  166.  *  so isolate it in its own cacheline.
  167.  */
  168. __u64 operation;
  169. char pad[SMP_CACHE_BYTES] ____cacheline_aligned;
  170. } ipi;
  171. #endif
  172. #ifdef CONFIG_NUMA
  173. void *node_directory;
  174. int numa_node_id;
  175. struct cpuinfo_ia64 *cpu_data[NR_CPUS];
  176. #endif
  177. /* Platform specific word.  MUST BE LAST IN STRUCT */
  178. __u64 platform_specific;
  179. } __attribute__ ((aligned (PAGE_SIZE)));
  180. /*
  181.  * The "local" data pointer.  It points to the per-CPU data of the currently executing
  182.  * CPU, much like "current" points to the per-task data of the currently executing task.
  183.  */
  184. #define local_cpu_data ((struct cpuinfo_ia64 *) PERCPU_ADDR)
  185. /*
  186.  * On NUMA systems, cpu_data for each cpu is allocated during cpu_init() & is allocated on
  187.  * the node that contains the cpu. This minimizes off-node memory references.  cpu_data
  188.  * for each cpu contains an array of pointers to the cpu_data structures of each of the
  189.  * other cpus.
  190.  *
  191.  * On non-NUMA systems, cpu_data is a static array allocated at compile time.  References
  192.  * to the cpu_data of another cpu is done by direct references to the appropriate entry of
  193.  * the array.
  194.  */
  195. #ifdef CONFIG_NUMA
  196. # define cpu_data(cpu) local_cpu_data->cpu_data[cpu]
  197. # define numa_node_id() (local_cpu_data->numa_node_id)
  198. #else
  199.   extern struct cpuinfo_ia64 _cpu_data[NR_CPUS];
  200. # define cpu_data(cpu) (&_cpu_data[cpu])
  201. #endif
  202. extern void identify_cpu (struct cpuinfo_ia64 *);
  203. extern void print_cpu_info (struct cpuinfo_ia64 *);
  204. typedef struct {
  205. unsigned long seg;
  206. } mm_segment_t;
  207. #define SET_UNALIGN_CTL(task,value)
  208. ({
  209. (task)->thread.flags = (((task)->thread.flags & ~IA64_THREAD_UAC_MASK)
  210. | (((value) << IA64_THREAD_UAC_SHIFT) & IA64_THREAD_UAC_MASK));
  211. 0;
  212. })
  213. #define GET_UNALIGN_CTL(task,addr)
  214. ({
  215. put_user(((task)->thread.flags & IA64_THREAD_UAC_MASK) >> IA64_THREAD_UAC_SHIFT,
  216.  (int *) (addr));
  217. })
  218. #define SET_FPEMU_CTL(task,value)
  219. ({
  220. (task)->thread.flags = (((task)->thread.flags & ~IA64_THREAD_FPEMU_MASK)
  221.   | (((value) << IA64_THREAD_FPEMU_SHIFT) & IA64_THREAD_FPEMU_MASK));
  222. 0;
  223. })
  224. #define GET_FPEMU_CTL(task,addr)
  225. ({
  226. put_user(((task)->thread.flags & IA64_THREAD_FPEMU_MASK) >> IA64_THREAD_FPEMU_SHIFT,
  227.  (int *) (addr));
  228. })
  229. struct siginfo;
  230. struct thread_struct {
  231. __u64 ksp; /* kernel stack pointer */
  232. unsigned long flags; /* various flags */
  233. __u64 map_base; /* base address for get_unmapped_area() */
  234. __u64 task_size; /* limit for task size */
  235. struct siginfo *siginfo; /* current siginfo struct for ptrace() */
  236. #ifdef CONFIG_IA32_SUPPORT
  237. __u64 eflag; /* IA32 EFLAGS reg */
  238. __u64 fsr; /* IA32 floating pt status reg */
  239. __u64 fcr; /* IA32 floating pt control reg */
  240. __u64 fir; /* IA32 fp except. instr. reg */
  241. __u64 fdr; /* IA32 fp except. data reg */
  242. __u64 csd; /* IA32 code selector descriptor */
  243. __u64 ssd; /* IA32 stack selector descriptor */
  244. __u64 old_k1; /* old value of ar.k1 */
  245. __u64 old_iob; /* old IOBase value */
  246. # define INIT_THREAD_IA32 0, 0, 0x17800000037fULL, 0, 0, 0, 0, 0, 0,
  247. #else
  248. # define INIT_THREAD_IA32
  249. #endif /* CONFIG_IA32_SUPPORT */
  250. #ifdef CONFIG_PERFMON
  251. __u64 pmc[IA64_NUM_PMC_REGS];
  252. __u64 pmd[IA64_NUM_PMD_REGS];
  253. unsigned long pfm_ovfl_block_reset;/* non-zero if we need to block or reset regs on ovfl */
  254. void *pfm_context; /* pointer to detailed PMU context */
  255. atomic_t pfm_notifiers_check; /* when >0, will cleanup ctx_notify_task in tasklist */
  256. atomic_t pfm_owners_check; /* when >0, will cleanup ctx_owner in tasklist */
  257. void *pfm_smpl_buf_list; /* list of sampling buffers to vfree */
  258. # define INIT_THREAD_PM {0, }, {0, }, 0, NULL, {0}, {0}, NULL,
  259. #else
  260. # define INIT_THREAD_PM
  261. #endif
  262. __u64 dbr[IA64_NUM_DBG_REGS];
  263. __u64 ibr[IA64_NUM_DBG_REGS];
  264. struct ia64_fpreg fph[96]; /* saved/loaded on demand */
  265. int last_fph_cpu;
  266. };
  267. #define INIT_THREAD {
  268. 0, /* ksp */
  269. 0, /* flags */
  270. DEFAULT_MAP_BASE, /* map_base */
  271. DEFAULT_TASK_SIZE, /* task_size */
  272. 0, /* siginfo */
  273. INIT_THREAD_IA32
  274. INIT_THREAD_PM
  275. {0, }, /* dbr */
  276. {0, }, /* ibr */
  277. {{{{0}}}, } /* fph */
  278. }
  279. #define start_thread(regs,new_ip,new_sp) do {
  280. set_fs(USER_DS);
  281. regs->cr_ipsr = ((regs->cr_ipsr | (IA64_PSR_BITS_TO_SET | IA64_PSR_CPL | IA64_PSR_SP))
  282.  & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_RI | IA64_PSR_IS));
  283. regs->cr_iip = new_ip;
  284. regs->ar_rsc = 0xf; /* eager mode, privilege level 3 */
  285. regs->ar_rnat = 0;
  286. regs->ar_bspstore = IA64_RBS_BOT;
  287. regs->ar_fpsr = FPSR_DEFAULT;
  288. regs->loadrs = 0;
  289. regs->r8 = current->mm->dumpable; /* set "don't zap registers" flag */
  290. regs->r12 = new_sp - 16; /* allocate 16 byte scratch area */
  291. if (!__builtin_expect (current->mm->dumpable, 1)) {
  292. /*
  293.  * Zap scratch regs to avoid leaking bits between processes with different
  294.  * uid/privileges.
  295.  */
  296. regs->ar_pfs = 0;
  297. regs->pr = 0;
  298. /*
  299.  * XXX fix me: everything below can go away once we stop preserving scratch
  300.  * regs on a system call.
  301.  */
  302. regs->b6 = 0;
  303. regs->r1 = 0; regs->r2 = 0; regs->r3 = 0;
  304. regs->r13 = 0; regs->r14 = 0; regs->r15 = 0;
  305. regs->r9  = 0; regs->r11 = 0;
  306. regs->r16 = 0; regs->r17 = 0; regs->r18 = 0; regs->r19 = 0;
  307. regs->r20 = 0; regs->r21 = 0; regs->r22 = 0; regs->r23 = 0;
  308. regs->r24 = 0; regs->r25 = 0; regs->r26 = 0; regs->r27 = 0;
  309. regs->r28 = 0; regs->r29 = 0; regs->r30 = 0; regs->r31 = 0;
  310. regs->ar_ccv = 0;
  311. regs->b0 = 0; regs->b7 = 0;
  312. regs->f6.u.bits[0] = 0; regs->f6.u.bits[1] = 0;
  313. regs->f7.u.bits[0] = 0; regs->f7.u.bits[1] = 0;
  314. regs->f8.u.bits[0] = 0; regs->f8.u.bits[1] = 0;
  315. regs->f9.u.bits[0] = 0; regs->f9.u.bits[1] = 0;
  316. }
  317. } while (0)
  318. /* Forward declarations, a strange C thing... */
  319. struct mm_struct;
  320. struct task_struct;
  321. /*
  322.  * Free all resources held by a thread. This is called after the
  323.  * parent of DEAD_TASK has collected the exist status of the task via
  324.  * wait().
  325.  */
  326. #ifdef CONFIG_PERFMON
  327.   extern void release_thread (struct task_struct *task);
  328. #else
  329. # define release_thread(dead_task)
  330. #endif
  331. /*
  332.  * This is the mechanism for creating a new kernel thread.
  333.  *
  334.  * NOTE 1: Only a kernel-only process (ie the swapper or direct
  335.  * descendants who haven't done an "execve()") should use this: it
  336.  * will work within a system call from a "real" process, but the
  337.  * process memory space will not be free'd until both the parent and
  338.  * the child have exited.
  339.  *
  340.  * NOTE 2: This MUST NOT be an inlined function.  Otherwise, we get
  341.  * into trouble in init/main.c when the child thread returns to
  342.  * do_basic_setup() and the timing is such that free_initmem() has
  343.  * been called already.
  344.  */
  345. extern int kernel_thread (int (*fn)(void *), void *arg, unsigned long flags);
  346. /* Copy and release all segment info associated with a VM */
  347. #define copy_segments(tsk, mm) do { } while (0)
  348. #define release_segments(mm) do { } while (0)
  349. /* Get wait channel for task P.  */
  350. extern unsigned long get_wchan (struct task_struct *p);
  351. /* Return instruction pointer of blocked task TSK.  */
  352. #define KSTK_EIP(tsk)
  353.   ({
  354. struct pt_regs *_regs = ia64_task_regs(tsk);
  355. _regs->cr_iip + ia64_psr(_regs)->ri;
  356.   })
  357. /* Return stack pointer of blocked task TSK.  */
  358. #define KSTK_ESP(tsk)  ((tsk)->thread.ksp)
  359. static inline unsigned long
  360. ia64_get_kr (unsigned long regnum)
  361. {
  362. unsigned long r;
  363. switch (regnum) {
  364.       case 0: asm volatile ("mov %0=ar.k0" : "=r"(r)); break;
  365.       case 1: asm volatile ("mov %0=ar.k1" : "=r"(r)); break;
  366.       case 2: asm volatile ("mov %0=ar.k2" : "=r"(r)); break;
  367.       case 3: asm volatile ("mov %0=ar.k3" : "=r"(r)); break;
  368.       case 4: asm volatile ("mov %0=ar.k4" : "=r"(r)); break;
  369.       case 5: asm volatile ("mov %0=ar.k5" : "=r"(r)); break;
  370.       case 6: asm volatile ("mov %0=ar.k6" : "=r"(r)); break;
  371.       case 7: asm volatile ("mov %0=ar.k7" : "=r"(r)); break;
  372. }
  373. return r;
  374. }
  375. static inline void
  376. ia64_set_kr (unsigned long regnum, unsigned long r)
  377. {
  378. switch (regnum) {
  379.       case 0: asm volatile ("mov ar.k0=%0" :: "r"(r)); break;
  380.       case 1: asm volatile ("mov ar.k1=%0" :: "r"(r)); break;
  381.       case 2: asm volatile ("mov ar.k2=%0" :: "r"(r)); break;
  382.       case 3: asm volatile ("mov ar.k3=%0" :: "r"(r)); break;
  383.       case 4: asm volatile ("mov ar.k4=%0" :: "r"(r)); break;
  384.       case 5: asm volatile ("mov ar.k5=%0" :: "r"(r)); break;
  385.       case 6: asm volatile ("mov ar.k6=%0" :: "r"(r)); break;
  386.       case 7: asm volatile ("mov ar.k7=%0" :: "r"(r)); break;
  387. }
  388. }
  389. static inline struct task_struct *
  390. ia64_get_fpu_owner (void)
  391. {
  392. return (struct task_struct *) ia64_get_kr(IA64_KR_FPU_OWNER);
  393. }
  394. static inline void
  395. ia64_set_fpu_owner (struct task_struct *t)
  396. {
  397. ia64_set_kr(IA64_KR_FPU_OWNER, (unsigned long) t);
  398. }
  399. extern void __ia64_init_fpu (void);
  400. extern void __ia64_save_fpu (struct ia64_fpreg *fph);
  401. extern void __ia64_load_fpu (struct ia64_fpreg *fph);
  402. extern void ia64_save_debug_regs (unsigned long *save_area);
  403. extern void ia64_load_debug_regs (unsigned long *save_area);
  404. #ifdef CONFIG_IA32_SUPPORT
  405. extern void ia32_save_state (struct task_struct *task);
  406. extern void ia32_load_state (struct task_struct *task);
  407. #endif
  408. #define ia64_fph_enable() asm volatile (";; rsm psr.dfh;; srlz.d;;" ::: "memory");
  409. #define ia64_fph_disable() asm volatile (";; ssm psr.dfh;; srlz.d;;" ::: "memory");
  410. /* load fp 0.0 into fph */
  411. static inline void
  412. ia64_init_fpu (void) {
  413. ia64_fph_enable();
  414. __ia64_init_fpu();
  415. ia64_fph_disable();
  416. }
  417. /* save f32-f127 at FPH */
  418. static inline void
  419. ia64_save_fpu (struct ia64_fpreg *fph) {
  420. ia64_fph_enable();
  421. __ia64_save_fpu(fph);
  422. ia64_fph_disable();
  423. }
  424. /* load f32-f127 from FPH */
  425. static inline void
  426. ia64_load_fpu (struct ia64_fpreg *fph) {
  427. ia64_fph_enable();
  428. __ia64_load_fpu(fph);
  429. ia64_fph_disable();
  430. }
  431. static inline void
  432. ia64_fc (void *addr)
  433. {
  434. asm volatile ("fc %0" :: "r"(addr) : "memory");
  435. }
  436. static inline void
  437. ia64_sync_i (void)
  438. {
  439. asm volatile (";; sync.i" ::: "memory");
  440. }
  441. static inline void
  442. ia64_srlz_i (void)
  443. {
  444. asm volatile (";; srlz.i ;;" ::: "memory");
  445. }
  446. static inline void
  447. ia64_srlz_d (void)
  448. {
  449. asm volatile (";; srlz.d" ::: "memory");
  450. }
  451. static inline __u64
  452. ia64_get_rr (__u64 reg_bits)
  453. {
  454. __u64 r;
  455. asm volatile ("mov %0=rr[%1]" : "=r"(r) : "r"(reg_bits) : "memory");
  456. return r;
  457. }
  458. static inline void
  459. ia64_set_rr (__u64 reg_bits, __u64 rr_val)
  460. {
  461. asm volatile ("mov rr[%0]=%1" :: "r"(reg_bits), "r"(rr_val) : "memory");
  462. }
  463. static inline __u64
  464. ia64_get_dcr (void)
  465. {
  466. __u64 r;
  467. asm volatile ("mov %0=cr.dcr" : "=r"(r));
  468. return r;
  469. }
  470. static inline void
  471. ia64_set_dcr (__u64 val)
  472. {
  473. asm volatile ("mov cr.dcr=%0;;" :: "r"(val) : "memory");
  474. ia64_srlz_d();
  475. }
  476. static inline __u64
  477. ia64_get_lid (void)
  478. {
  479. __u64 r;
  480. asm volatile ("mov %0=cr.lid" : "=r"(r));
  481. return r;
  482. }
  483. static inline void
  484. ia64_invala (void)
  485. {
  486. asm volatile ("invala" ::: "memory");
  487. }
  488. /*
  489.  * Save the processor status flags in FLAGS and then clear the interrupt collection and
  490.  * interrupt enable bits.  Don't trigger any mandatory RSE references while this bit is
  491.  * off!
  492.  */
  493. static inline __u64
  494. ia64_clear_ic (void)
  495. {
  496. __u64 psr;
  497. asm volatile ("mov %0=psr;; rsm psr.i | psr.ic;; srlz.i;;" : "=r"(psr) :: "memory");
  498. return psr;
  499. }
  500. /*
  501.  * Restore the psr.
  502.  */
  503. static inline void
  504. ia64_set_psr (__u64 psr)
  505. {
  506. asm volatile (";; mov psr.l=%0;; srlz.d" :: "r" (psr) : "memory");
  507. }
  508. /*
  509.  * Insert a translation into an instruction and/or data translation
  510.  * register.
  511.  */
  512. static inline void
  513. ia64_itr (__u64 target_mask, __u64 tr_num,
  514.   __u64 vmaddr, __u64 pte,
  515.   __u64 log_page_size)
  516. {
  517. asm volatile ("mov cr.itir=%0" :: "r"(log_page_size << 2) : "memory");
  518. asm volatile ("mov cr.ifa=%0;;" :: "r"(vmaddr) : "memory");
  519. if (target_mask & 0x1)
  520. asm volatile ("itr.i itr[%0]=%1"
  521.       :: "r"(tr_num), "r"(pte) : "memory");
  522. if (target_mask & 0x2)
  523. asm volatile (";;itr.d dtr[%0]=%1"
  524.       :: "r"(tr_num), "r"(pte) : "memory");
  525. }
  526. /*
  527.  * Insert a translation into the instruction and/or data translation
  528.  * cache.
  529.  */
  530. static inline void
  531. ia64_itc (__u64 target_mask, __u64 vmaddr, __u64 pte,
  532.   __u64 log_page_size)
  533. {
  534. asm volatile ("mov cr.itir=%0" :: "r"(log_page_size << 2) : "memory");
  535. asm volatile ("mov cr.ifa=%0;;" :: "r"(vmaddr) : "memory");
  536. /* as per EAS2.6, itc must be the last instruction in an instruction group */
  537. if (target_mask & 0x1)
  538. asm volatile ("itc.i %0;;" :: "r"(pte) : "memory");
  539. if (target_mask & 0x2)
  540. asm volatile (";;itc.d %0;;" :: "r"(pte) : "memory");
  541. }
  542. /*
  543.  * Purge a range of addresses from instruction and/or data translation
  544.  * register(s).
  545.  */
  546. static inline void
  547. ia64_ptr (__u64 target_mask, __u64 vmaddr, __u64 log_size)
  548. {
  549. if (target_mask & 0x1)
  550. asm volatile ("ptr.i %0,%1" :: "r"(vmaddr), "r"(log_size << 2));
  551. if (target_mask & 0x2)
  552. asm volatile ("ptr.d %0,%1" :: "r"(vmaddr), "r"(log_size << 2));
  553. }
  554. /* Set the interrupt vector address.  The address must be suitably aligned (32KB).  */
  555. static inline void
  556. ia64_set_iva (void *ivt_addr)
  557. {
  558. asm volatile ("mov cr.iva=%0;; srlz.i;;" :: "r"(ivt_addr) : "memory");
  559. }
  560. /* Set the page table address and control bits.  */
  561. static inline void
  562. ia64_set_pta (__u64 pta)
  563. {
  564. /* Note: srlz.i implies srlz.d */
  565. asm volatile ("mov cr.pta=%0;; srlz.i;;" :: "r"(pta) : "memory");
  566. }
  567. static inline __u64
  568. ia64_get_cpuid (__u64 regnum)
  569. {
  570. __u64 r;
  571. asm ("mov %0=cpuid[%r1]" : "=r"(r) : "rO"(regnum));
  572. return r;
  573. }
  574. static inline void
  575. ia64_eoi (void)
  576. {
  577. asm ("mov cr.eoi=r0;; srlz.d;;" ::: "memory");
  578. }
  579. static inline void
  580. ia64_set_lrr0 (unsigned long val)
  581. {
  582. asm volatile ("mov cr.lrr0=%0;; srlz.d" :: "r"(val) : "memory");
  583. }
  584. #define cpu_relax() do { } while (0)
  585. static inline void
  586. ia64_set_lrr1 (unsigned long val)
  587. {
  588. asm volatile ("mov cr.lrr1=%0;; srlz.d" :: "r"(val) : "memory");
  589. }
  590. static inline void
  591. ia64_set_pmv (__u64 val)
  592. {
  593. asm volatile ("mov cr.pmv=%0" :: "r"(val) : "memory");
  594. }
  595. static inline __u64
  596. ia64_get_pmc (__u64 regnum)
  597. {
  598. __u64 retval;
  599. asm volatile ("mov %0=pmc[%1]" : "=r"(retval) : "r"(regnum));
  600. return retval;
  601. }
  602. static inline void
  603. ia64_set_pmc (__u64 regnum, __u64 value)
  604. {
  605. asm volatile ("mov pmc[%0]=%1" :: "r"(regnum), "r"(value));
  606. }
  607. static inline __u64
  608. ia64_get_pmd (__u64 regnum)
  609. {
  610. __u64 retval;
  611. asm volatile ("mov %0=pmd[%1]" : "=r"(retval) : "r"(regnum));
  612. return retval;
  613. }
  614. static inline void
  615. ia64_set_pmd (__u64 regnum, __u64 value)
  616. {
  617. asm volatile ("mov pmd[%0]=%1" :: "r"(regnum), "r"(value));
  618. }
  619. /*
  620.  * Given the address to which a spill occurred, return the unat bit
  621.  * number that corresponds to this address.
  622.  */
  623. static inline __u64
  624. ia64_unat_pos (void *spill_addr)
  625. {
  626. return ((__u64) spill_addr >> 3) & 0x3f;
  627. }
  628. /*
  629.  * Set the NaT bit of an integer register which was spilled at address
  630.  * SPILL_ADDR.  UNAT is the mask to be updated.
  631.  */
  632. static inline void
  633. ia64_set_unat (__u64 *unat, void *spill_addr, unsigned long nat)
  634. {
  635. __u64 bit = ia64_unat_pos(spill_addr);
  636. __u64 mask = 1UL << bit;
  637. *unat = (*unat & ~mask) | (nat << bit);
  638. }
  639. /*
  640.  * Return saved PC of a blocked thread.
  641.  * Note that the only way T can block is through a call to schedule() -> switch_to().
  642.  */
  643. static inline unsigned long
  644. thread_saved_pc (struct thread_struct *t)
  645. {
  646. struct unw_frame_info info;
  647. unsigned long ip;
  648. /* XXX ouch: Linus, please pass the task pointer to thread_saved_pc() instead! */
  649. struct task_struct *p = (void *) ((unsigned long) t - IA64_TASK_THREAD_OFFSET);
  650. unw_init_from_blocked_task(&info, p);
  651. if (unw_unwind(&info) < 0)
  652. return 0;
  653. unw_get_ip(&info, &ip);
  654. return ip;
  655. }
  656. /*
  657.  * Get the current instruction/program counter value.
  658.  */
  659. #define current_text_addr() 
  660. ({ void *_pc; asm volatile ("mov %0=ip" : "=r" (_pc)); _pc; })
  661. #define THREAD_SIZE IA64_STK_OFFSET
  662. /* NOTE: The task struct and the stacks are allocated together.  */
  663. #define alloc_task_struct() 
  664.         ((struct task_struct *) __get_free_pages(GFP_KERNEL, IA64_TASK_STRUCT_LOG_NUM_PAGES))
  665. #define free_task_struct(p) free_pages((unsigned long)(p), IA64_TASK_STRUCT_LOG_NUM_PAGES)
  666. #define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
  667. #define init_task (init_task_union.task)
  668. #define init_stack (init_task_union.stack)
  669. /*
  670.  * Set the correctable machine check vector register
  671.  */
  672. static inline void
  673. ia64_set_cmcv (__u64 val)
  674. {
  675. asm volatile ("mov cr.cmcv=%0" :: "r"(val) : "memory");
  676. }
  677. /*
  678.  * Read the correctable machine check vector register
  679.  */
  680. static inline __u64
  681. ia64_get_cmcv (void)
  682. {
  683. __u64 val;
  684. asm volatile ("mov %0=cr.cmcv" : "=r"(val) :: "memory");
  685. return val;
  686. }
  687. static inline __u64
  688. ia64_get_ivr (void)
  689. {
  690. __u64 r;
  691. asm volatile ("srlz.d;; mov %0=cr.ivr;; srlz.d;;" : "=r"(r));
  692. return r;
  693. }
  694. static inline void
  695. ia64_set_tpr (__u64 val)
  696. {
  697. asm volatile ("mov cr.tpr=%0" :: "r"(val));
  698. }
  699. static inline __u64
  700. ia64_get_tpr (void)
  701. {
  702. __u64 r;
  703. asm volatile ("mov %0=cr.tpr" : "=r"(r));
  704. return r;
  705. }
  706. static inline void
  707. ia64_set_irr0 (__u64 val)
  708. {
  709. asm volatile("mov cr.irr0=%0;;" :: "r"(val) : "memory");
  710. ia64_srlz_d();
  711. }
  712. static inline __u64
  713. ia64_get_irr0 (void)
  714. {
  715. __u64 val;
  716. /* this is volatile because irr may change unbeknownst to gcc... */
  717. asm volatile("mov %0=cr.irr0" : "=r"(val));
  718. return val;
  719. }
  720. static inline void
  721. ia64_set_irr1 (__u64 val)
  722. {
  723. asm volatile("mov cr.irr1=%0;;" :: "r"(val) : "memory");
  724. ia64_srlz_d();
  725. }
  726. static inline __u64
  727. ia64_get_irr1 (void)
  728. {
  729. __u64 val;
  730. /* this is volatile because irr may change unbeknownst to gcc... */
  731. asm volatile("mov %0=cr.irr1" : "=r"(val));
  732. return val;
  733. }
  734. static inline void
  735. ia64_set_irr2 (__u64 val)
  736. {
  737. asm volatile("mov cr.irr2=%0;;" :: "r"(val) : "memory");
  738. ia64_srlz_d();
  739. }
  740. static inline __u64
  741. ia64_get_irr2 (void)
  742. {
  743. __u64 val;
  744. /* this is volatile because irr may change unbeknownst to gcc... */
  745. asm volatile("mov %0=cr.irr2" : "=r"(val));
  746. return val;
  747. }
  748. static inline void
  749. ia64_set_irr3 (__u64 val)
  750. {
  751. asm volatile("mov cr.irr3=%0;;" :: "r"(val) : "memory");
  752. ia64_srlz_d();
  753. }
  754. static inline __u64
  755. ia64_get_irr3 (void)
  756. {
  757. __u64 val;
  758. /* this is volatile because irr may change unbeknownst to gcc... */
  759. asm volatile ("mov %0=cr.irr3" : "=r"(val));
  760. return val;
  761. }
  762. static inline __u64
  763. ia64_get_gp(void)
  764. {
  765. __u64 val;
  766. asm ("mov %0=gp" : "=r"(val));
  767. return val;
  768. }
  769. static inline void
  770. ia64_set_ibr (__u64 regnum, __u64 value)
  771. {
  772. asm volatile ("mov ibr[%0]=%1" :: "r"(regnum), "r"(value));
  773. }
  774. static inline void
  775. ia64_set_dbr (__u64 regnum, __u64 value)
  776. {
  777. asm volatile ("mov dbr[%0]=%1" :: "r"(regnum), "r"(value));
  778. #ifdef CONFIG_ITANIUM
  779. asm volatile (";; srlz.d");
  780. #endif
  781. }
  782. static inline __u64
  783. ia64_get_ibr (__u64 regnum)
  784. {
  785. __u64 retval;
  786. asm volatile ("mov %0=ibr[%1]" : "=r"(retval) : "r"(regnum));
  787. return retval;
  788. }
  789. static inline __u64
  790. ia64_get_dbr (__u64 regnum)
  791. {
  792. __u64 retval;
  793. asm volatile ("mov %0=dbr[%1]" : "=r"(retval) : "r"(regnum));
  794. #ifdef CONFIG_ITANIUM
  795. asm volatile (";; srlz.d");
  796. #endif
  797. return retval;
  798. }
  799. /* XXX remove the handcoded version once we have a sufficiently clever compiler... */
  800. #ifdef SMART_COMPILER
  801. # define ia64_rotr(w,n)
  802.   ({
  803. __u64 _w = (w), _n = (n);
  804. (_w >> _n) | (_w << (64 - _n));
  805.   })
  806. #else
  807. # define ia64_rotr(w,n)
  808.   ({
  809. __u64 result;
  810. asm ("shrp %0=%1,%1,%2" : "=r"(result) : "r"(w), "i"(n));
  811. result;
  812.   })
  813. #endif
  814. #define ia64_rotl(w,n) ia64_rotr((w),(64)-(n))
  815. static inline __u64
  816. ia64_thash (__u64 addr)
  817. {
  818. __u64 result;
  819. asm ("thash %0=%1" : "=r"(result) : "r" (addr));
  820. return result;
  821. }
  822. static inline __u64
  823. ia64_tpa (__u64 addr)
  824. {
  825. __u64 result;
  826. asm ("tpa %0=%1" : "=r"(result) : "r"(addr));
  827. return result;
  828. }
  829. #define ARCH_HAS_PREFETCH
  830. #define ARCH_HAS_PREFETCHW
  831. #define ARCH_HAS_SPINLOCK_PREFETCH
  832. #define PREFETCH_STRIDE 256
  833. extern inline void
  834. prefetch (const void *x)
  835. {
  836.          __asm__ __volatile__ ("lfetch [%0]" : : "r"(x));
  837. }
  838. extern inline void
  839. prefetchw (const void *x)
  840. {
  841. __asm__ __volatile__ ("lfetch.excl [%0]" : : "r"(x));
  842. }
  843. #define spin_lock_prefetch(x) prefetchw(x)
  844. #endif /* !__ASSEMBLY__ */
  845. #endif /* _ASM_IA64_PROCESSOR_H */