pda.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. unsigned int __softirq_pending;
  17. unsigned int __nmi_count; /* number of NMI on this CPUs */
  18. struct mm_struct *active_mm;
  19. int mmu_state;
  20. unsigned apic_timer_irqs;
  21. } ____cacheline_aligned_in_smp;
  22. #define IRQSTACK_ORDER 2
  23. #define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)
  24. extern struct x8664_pda cpu_pda[];
  25. /*
  26. * There is no fast way to get the base address of the PDA, all the accesses
  27. * have to mention %fs/%gs. So it needs to be done this Torvaldian way.
  28. */
  29. #define sizeof_field(type,field) (sizeof(((type *)0)->field))
  30. #define typeof_field(type,field) typeof(((type *)0)->field)
  31. extern void __bad_pda_field(void);
  32. #define pda_offset(field) offsetof(struct x8664_pda, field)
  33. #define pda_to_op(op,field,val) do { \
  34. typedef typeof_field(struct x8664_pda, field) T__; \
  35. switch (sizeof_field(struct x8664_pda, field)) { \
  36. case 2: \
  37. asm volatile(op "w %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  38. case 4: \
  39. asm volatile(op "l %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  40. case 8: \
  41. asm volatile(op "q %0,%%gs:%P1"::"ri" ((T__)val),"i"(pda_offset(field)):"memory"); break; \
  42. default: __bad_pda_field(); \
  43. } \
  44. } while (0)
  45. /*
  46. * AK: PDA read accesses should be neither volatile nor have an memory clobber.
  47. * Unfortunately removing them causes all hell to break lose currently.
  48. */
  49. #define pda_from_op(op,field) ({ \
  50. typeof_field(struct x8664_pda, field) ret__; \
  51. switch (sizeof_field(struct x8664_pda, field)) { \
  52. case 2: \
  53. asm volatile(op "w %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  54. case 4: \
  55. asm volatile(op "l %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  56. case 8: \
  57. asm volatile(op "q %%gs:%P1,%0":"=r" (ret__):"i"(pda_offset(field)):"memory"); break;\
  58. default: __bad_pda_field(); \
  59. } \
  60. ret__; })
  61. #define read_pda(field) pda_from_op("mov",field)
  62. #define write_pda(field,val) pda_to_op("mov",field,val)
  63. #define add_pda(field,val) pda_to_op("add",field,val)
  64. #define sub_pda(field,val) pda_to_op("sub",field,val)
  65. #define or_pda(field,val) pda_to_op("or",field,val)
  66. #endif
  67. #define PDA_STACKOFFSET (5*8)
  68. #endif