pda.h 2.8 KB

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