pda.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef X86_64_PDA_H
  2. #define X86_64_PDA_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/stddef.h>
  5. #include <linux/types.h>
  6. #include <linux/cache.h>
  7. #include <asm/page.h>
  8. /* Per processor datastructure. %gs points to it while the kernel runs */
  9. struct x8664_pda {
  10. struct task_struct *pcurrent; /* 0 Current process */
  11. unsigned long data_offset; /* 8 Per cpu data offset from linker
  12. address */
  13. unsigned long kernelstack; /* 16 top of kernel stack for current */
  14. unsigned long oldrsp; /* 24 user rsp for system call */
  15. int irqcount; /* 32 Irq nesting counter. Starts with -1 */
  16. int cpunumber; /* 36 Logical CPU number */
  17. char *irqstackptr; /* 40 top of irqstack */
  18. int nodenumber; /* number of current node */
  19. unsigned int __softirq_pending;
  20. unsigned int __nmi_count; /* number of NMI on this CPUs */
  21. int mmu_state;
  22. struct mm_struct *active_mm;
  23. unsigned apic_timer_irqs;
  24. } ____cacheline_aligned_in_smp;
  25. extern struct x8664_pda *_cpu_pda[];
  26. extern struct x8664_pda boot_cpu_pda[];
  27. #define cpu_pda(i) (_cpu_pda[i])
  28. /*
  29. * There is no fast way to get the base address of the PDA, all the accesses
  30. * have to mention %fs/%gs. So it needs to be done this Torvaldian way.
  31. */
  32. extern void __bad_pda_field(void);
  33. /* proxy_pda doesn't actually exist, but tell gcc it is accessed
  34. for all PDA accesses so it gets read/write dependencies right. */
  35. extern struct x8664_pda _proxy_pda;
  36. #define pda_offset(field) offsetof(struct x8664_pda, field)
  37. #define pda_to_op(op,field,val) do { \
  38. typedef typeof(_proxy_pda.field) T__; \
  39. switch (sizeof(_proxy_pda.field)) { \
  40. case 2: \
  41. asm(op "w %1,%%gs:%P2" : "+m" (_proxy_pda.field) : \
  42. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  43. case 4: \
  44. asm(op "l %1,%%gs:%P2" : "+m" (_proxy_pda.field) : \
  45. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  46. case 8: \
  47. asm(op "q %1,%%gs:%P2": "+m" (_proxy_pda.field) : \
  48. "ri" ((T__)val),"i"(pda_offset(field))); break; \
  49. default: __bad_pda_field(); \
  50. } \
  51. } while (0)
  52. #define pda_from_op(op,field) ({ \
  53. typeof(_proxy_pda.field) ret__; \
  54. switch (sizeof(_proxy_pda.field)) { \
  55. case 2: \
  56. asm(op "w %%gs:%P1,%0":"=r" (ret__):\
  57. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  58. case 4: \
  59. asm(op "l %%gs:%P1,%0":"=r" (ret__):\
  60. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  61. case 8: \
  62. asm(op "q %%gs:%P1,%0":"=r" (ret__):\
  63. "i" (pda_offset(field)), "m" (_proxy_pda.field)); break;\
  64. default: __bad_pda_field(); \
  65. } \
  66. ret__; })
  67. #define read_pda(field) pda_from_op("mov",field)
  68. #define write_pda(field,val) pda_to_op("mov",field,val)
  69. #define add_pda(field,val) pda_to_op("add",field,val)
  70. #define sub_pda(field,val) pda_to_op("sub",field,val)
  71. #define or_pda(field,val) pda_to_op("or",field,val)
  72. #endif
  73. #define PDA_STACKOFFSET (5*8)
  74. #endif