pda.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /* Per processor datastructure. %gs points to it while the kernel runs */
  8. struct x8664_pda {
  9. struct task_struct *pcurrent; /* Current process */
  10. unsigned long data_offset; /* Per cpu data offset from linker address */
  11. unsigned long kernelstack; /* top of kernel stack for current */
  12. unsigned long oldrsp; /* user rsp for system call */
  13. int irqcount; /* Irq nesting counter. Starts with -1 */
  14. int cpunumber; /* Logical CPU number */
  15. char *irqstackptr; /* top of irqstack */
  16. int nodenumber; /* number of current node */
  17. unsigned int __softirq_pending;
  18. unsigned int __nmi_count; /* number of NMI on this CPUs */
  19. struct mm_struct *active_mm;
  20. int mmu_state;
  21. unsigned apic_timer_irqs;
  22. } ____cacheline_aligned_in_smp;
  23. #define IRQSTACK_ORDER 2
  24. #define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)
  25. extern struct x8664_pda cpu_pda[];
  26. /*
  27. * There is no fast way to get the base address of the PDA, all the accesses
  28. * have to mention %fs/%gs. So it needs to be done this Torvaldian way.
  29. */
  30. #define sizeof_field(type,field) (sizeof(((type *)0)->field))
  31. #define typeof_field(type,field) typeof(((type *)0)->field)
  32. extern void __bad_pda_field(void);
  33. #define pda_offset(field) offsetof(struct x8664_pda, field)
  34. #define pda_to_op(op,field,val) do { \
  35. typedef typeof_field(struct x8664_pda, field) T__; \
  36. switch (sizeof_field(struct x8664_pda, field)) { \
  37. case 2: \
  38. asm volatile(op "w %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  39. case 4: \
  40. asm volatile(op "l %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  41. case 8: \
  42. asm volatile(op "q %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  43. default: __bad_pda_field(); \
  44. } \
  45. } while (0)
  46. /*
  47. * AK: PDA read accesses should be neither volatile nor have an memory clobber.
  48. * Unfortunately removing them causes all hell to break lose currently.
  49. */
  50. #define pda_from_op(op,field) ({ \
  51. typeof_field(struct x8664_pda, field) ret__; \
  52. switch (sizeof_field(struct x8664_pda, field)) { \
  53. case 2: \
  54. asm volatile(op "w %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  55. case 4: \
  56. asm volatile(op "l %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  57. case 8: \
  58. asm volatile(op "q %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  59. default: __bad_pda_field(); \
  60. } \
  61. ret__; })
  62. #define read_pda(field) pda_from_op("mov",field)
  63. #define write_pda(field,val) pda_to_op("mov",field,val)
  64. #define add_pda(field,val) pda_to_op("add",field,val)
  65. #define sub_pda(field,val) pda_to_op("sub",field,val)
  66. #define or_pda(field,val) pda_to_op("or",field,val)
  67. #endif
  68. #define PDA_STACKOFFSET (5*8)
  69. #endif