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];
27 static inline int mbq_init(struct omap_mbq **addr)
29 struct omap_mbq *m = kmalloc(sizeof(struct omap_mbq), GFP_KERNEL);
33 rwlock_init(&m->lock);
35 write_lock_irq(&m->lock);
36 m->rp = m->wp = &m->msg[0];
38 write_unlock_irq(&m->lock);
45 static inline int mbq_empty(struct omap_mbq *mbq)
49 read_lock_irq(&mbq->lock);
50 ret = (mbq->cnt == 0);
51 read_unlock_irq(&mbq->lock);
56 static inline int mbq_full(struct omap_mbq *mbq)
60 read_lock_irq(&mbq->lock);
61 ret = (mbq->cnt == MBQ_DEPTH);
62 read_unlock_irq(&mbq->lock);
67 static inline int mbq_add(struct omap_mbq *mbq, mbox_msg_t msg)
71 write_lock_irq(&mbq->lock);
74 if (++mbq->wp == &mbq->msg[MBQ_DEPTH])
75 mbq->wp = &mbq->msg[0];
77 if (++mbq->cnt == MBQ_DEPTH) /* full */
80 write_unlock_irq(&mbq->lock);
85 static inline mbox_msg_t mbq_get(struct omap_mbq *mbq)
89 write_lock_irq(&mbq->lock);
93 if (++mbq->rp == &mbq->msg[MBQ_DEPTH])
94 mbq->rp = &mbq->msg[0];
97 write_unlock_irq(&mbq->lock);
102 static inline void mbq_exit(struct omap_mbq **addr)
109 * Mailbox sequence bit API
111 #if defined(CONFIG_ARCH_OMAP1)
112 # define MBOX_USE_SEQ_BIT
113 #elif defined(CONFIG_ARCH_OMAP2)
114 # define MBOX_USE_SEQ_BIT
117 #ifdef MBOX_USE_SEQ_BIT
118 /* seq_rcv should be initialized with any value other than
119 * 0 and 1 << 31, to allow either value for the first
121 static inline void mbox_seq_init(struct omap_mbox *mbox)
123 /* any value other than 0 and 1 << 31 */
124 mbox->seq_rcv = 0xffffffff;
127 static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
129 /* add seq_snd to msg */
130 *msg = (*msg & 0x7fffffff) | mbox->seq_snd;
132 mbox->seq_snd ^= 1 << 31;
135 static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
137 mbox_msg_t seq = msg & (1 << 31);
138 if (seq == mbox->seq_rcv)
144 static inline void mbox_seq_init(struct omap_mbox *mbox)
147 static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
150 static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
156 /* Mailbox FIFO handle functions */
157 static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
159 return mbox->ops->fifo_read(mbox);
161 static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
163 mbox->ops->fifo_write(mbox, msg);
165 static inline int mbox_fifo_empty(struct omap_mbox *mbox)
167 return mbox->ops->fifo_empty(mbox);
169 static inline int mbox_fifo_full(struct omap_mbox *mbox)
171 return mbox->ops->fifo_full(mbox);
174 /* Mailbox IRQ handle functions */
175 static inline void enable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
177 mbox->ops->enable_irq(mbox, irq);
179 static inline void disable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
181 mbox->ops->disable_irq(mbox, irq);
183 static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
185 if (mbox->ops->ack_irq)
186 mbox->ops->ack_irq(mbox, irq);
188 static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
190 return mbox->ops->is_irq(mbox, irq);
193 #endif /* __ARCH_ARM_PLAT_MAILBOX_H */