This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-mips / smtc_ipi.h
1 /*
2  * Definitions used in MIPS MT SMTC "Interprocessor Interrupt" code.
3  */
4 #ifndef __ASM_SMTC_IPI_H
5 #define __ASM_SMTC_IPI_H
6
7 //#define SMTC_IPI_DEBUG
8
9 #ifdef SMTC_IPI_DEBUG
10 #include <asm/mipsregs.h>
11 #include <asm/mipsmtregs.h>
12 #endif /* SMTC_IPI_DEBUG */
13
14 /*
15  * An IPI "message"
16  */
17
18 struct smtc_ipi {
19         struct smtc_ipi *flink;
20         int type;
21         void *arg;
22         int dest;
23 #ifdef  SMTC_IPI_DEBUG
24         int sender;
25         long stamp;
26 #endif /* SMTC_IPI_DEBUG */
27 };
28
29 /*
30  * Defined IPI Types
31  */
32
33 #define LINUX_SMP_IPI 1
34 #define SMTC_CLOCK_TICK 2
35
36 /*
37  * A queue of IPI messages
38  */
39
40 struct smtc_ipi_q {
41         struct smtc_ipi *head;
42         spinlock_t lock;
43         struct smtc_ipi *tail;
44         int depth;
45 };
46
47 extern struct smtc_ipi_q IPIQ[NR_CPUS];
48 extern struct smtc_ipi_q freeIPIq;
49
50 static inline void smtc_ipi_nq(struct smtc_ipi_q *q, struct smtc_ipi *p)
51 {
52         long flags;
53
54         spin_lock_irqsave(&q->lock, flags);
55         if (q->head == NULL)
56                 q->head = q->tail = p;
57         else
58                 q->tail->flink = p;
59         p->flink = NULL;
60         q->tail = p;
61         q->depth++;
62 #ifdef  SMTC_IPI_DEBUG
63         p->sender = read_c0_tcbind();
64         p->stamp = read_c0_count();
65 #endif /* SMTC_IPI_DEBUG */
66         spin_unlock_irqrestore(&q->lock, flags);
67 }
68
69 static inline struct smtc_ipi *smtc_ipi_dq(struct smtc_ipi_q *q)
70 {
71         struct smtc_ipi *p;
72         long flags;
73
74         spin_lock_irqsave(&q->lock, flags);
75         if (q->head == NULL)
76                 p = NULL;
77         else {
78                 p = q->head;
79                 q->head = q->head->flink;
80                 q->depth--;
81                 /* Arguably unnecessary, but leaves queue cleaner */
82                 if (q->head == NULL)
83                         q->tail = NULL;
84         }
85         spin_unlock_irqrestore(&q->lock, flags);
86         return p;
87 }
88
89 static inline void smtc_ipi_req(struct smtc_ipi_q *q, struct smtc_ipi *p)
90 {
91         long flags;
92
93         spin_lock_irqsave(&q->lock, flags);
94         if (q->head == NULL) {
95                 q->head = q->tail = p;
96                 p->flink = NULL;
97         } else {
98                 p->flink = q->head;
99                 q->head = p;
100         }
101         q->depth++;
102         spin_unlock_irqrestore(&q->lock, flags);
103 }
104
105 static inline int smtc_ipi_qdepth(struct smtc_ipi_q *q)
106 {
107         long flags;
108         int retval;
109
110         spin_lock_irqsave(&q->lock, flags);
111         retval = q->depth;
112         spin_unlock_irqrestore(&q->lock, flags);
113         return retval;
114 }
115
116 extern void smtc_send_ipi(int cpu, int type, unsigned int action);
117
118 #endif /* __ASM_SMTC_IPI_H */