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