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. struct x8664_pda *me; /* Pointer to itself */
  12. unsigned long kernelstack; /* top of kernel stack for current */
  13. unsigned long oldrsp; /* user rsp for system call */
  14. unsigned long irqrsp; /* Old rsp for interrupts. */
  15. int irqcount; /* Irq nesting counter. Starts with -1 */
  16. int cpunumber; /* Logical CPU number */
  17. char *irqstackptr; /* top of irqstack */
  18. unsigned int __softirq_pending;
  19. unsigned int __nmi_count; /* number of NMI on this CPUs */
  20. struct mm_struct *active_mm;
  21. int mmu_state;
  22. unsigned apic_timer_irqs;
  23. } ____cacheline_aligned;
  24. #define IRQSTACK_ORDER 2
  25. #define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER)
  26. extern struct x8664_pda cpu_pda[];
  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. #define sizeof_field(type,field) (sizeof(((type *)0)->field))
  32. #define typeof_field(type,field) typeof(((type *)0)->field)
  33. extern void __bad_pda_field(void);
  34. #define pda_offset(field) offsetof(struct x8664_pda, field)
  35. #define pda_to_op(op,field,val) do { \
  36. switch (sizeof_field(struct x8664_pda, field)) { \
  37. case 2: \
  38. asm volatile(op "w %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); break; \
  39. case 4: \
  40. asm volatile(op "l %0,%%gs:%P1"::"r" (val),"i"(pda_offset(field)):"memory"); break; \
  41. case 8: \
  42. asm volatile(op "q %0,%%gs:%P1"::"r" (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. typedef typeof_field(struct x8664_pda, field) T__; T__ 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. #endif
  67. #define PDA_STACKOFFSET (5*8)
  68. #endif