2 * Mailbox internal functions
4 * Copyright (C) 2006 Nokia Corporation
5 * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
12 #ifndef __ARCH_ARM_PLAT_MAILBOX_H
13 #define __ARCH_ARM_PLAT_MAILBOX_H
16 * Mailbox queue handling API
22 mbox_msg_t msg[MBQ_DEPTH];
26 static inline int mbq_init(struct omap_mbq **addr)
28 struct omap_mbq *m = kmalloc(sizeof(struct omap_mbq), GFP_KERNEL);
32 rwlock_init(&m->lock);
34 write_lock_irq(&m->lock);
35 m->rp = m->wp = &m->msg[0];
36 write_unlock_irq(&m->lock);
43 static inline int mbq_empty(struct omap_mbq *mbq)
47 read_lock_irq(&mbq->lock);
48 ret = (mbq->rp == mbq->wp);
49 read_unlock_irq(&mbq->lock);
54 static inline int mbq_full(struct omap_mbq *mbq)
59 read_lock_irq(&mbq->lock);
62 if (++p == &mbq->msg[MBQ_DEPTH])
67 read_unlock_irq(&mbq->lock);
72 static inline int mbq_add(struct omap_mbq *mbq, mbox_msg_t msg)
76 write_lock_irq(&mbq->lock);
79 if (++mbq->wp == &mbq->msg[MBQ_DEPTH])
80 mbq->wp = &mbq->msg[0];
82 if (mbq->wp == mbq->rp) /* full */
85 write_unlock_irq(&mbq->lock);
90 static inline mbox_msg_t mbq_get(struct omap_mbq *mbq)
94 write_lock_irq(&mbq->lock);
98 if (++mbq->rp == &mbq->msg[MBQ_DEPTH])
99 mbq->rp = &mbq->msg[0];
101 write_unlock_irq(&mbq->lock);
106 static inline void mbq_exit(struct omap_mbq **addr)
113 * Mailbox sequence bit API
115 #if defined(CONFIG_ARCH_OMAP1)
116 # define MBOX_USE_SEQ_BIT
117 #elif defined(CONFIG_ARCH_OMAP2)
118 # define MBOX_USE_SEQ_BIT
121 #ifdef MBOX_USE_SEQ_BIT
122 /* seq_rcv should be initialized with any value other than
123 * 0 and 1 << 31, to allow either value for the first
125 static inline void mbox_seq_init(struct omap_mbox *mbox)
127 /* any value other than 0 and 1 << 31 */
128 mbox->seq_rcv = 0xffffffff;
131 static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
133 /* add seq_snd to msg */
134 *msg = (*msg & 0x7fffffff) | mbox->seq_snd;
136 mbox->seq_snd ^= 1 << 31;
139 static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
141 mbox_msg_t seq = msg & (1 << 31);
142 if (seq == mbox->seq_rcv)
148 static inline void mbox_seq_init(struct omap_mbox *mbox)
151 static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
154 static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
160 /* Mailbox FIFO handle functions */
161 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
163 return mbox->ops->fifo_read(mbox);
165 static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
167 mbox->ops->fifo_write(mbox, msg);
169 static inline int mbox_fifo_empty(struct omap_mbox *mbox)
171 return mbox->ops->fifo_empty(mbox);
173 static inline int mbox_fifo_full(struct omap_mbox *mbox)
175 return mbox->ops->fifo_full(mbox);
178 /* Mailbox IRQ handle functions */
179 static inline void enable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
181 mbox->ops->enable_irq(mbox, irq);
183 static inline void disable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
185 mbox->ops->disable_irq(mbox, irq);
187 static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
189 if (mbox->ops->ack_irq)
190 mbox->ops->ack_irq(mbox, irq);
192 static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
194 return mbox->ops->is_irq(mbox, irq);
197 #endif /* __ARCH_ARM_PLAT_MAILBOX_H */