Merge branch 'v2.6.35-omap-mailbox-for-next' of git://gitorious.org/~doyu/lk/mainline into omap-for-linus

Conflicts:
	arch/arm/mach-omap1/devices.c
This commit is contained in:
Tony Lindgren 2010-08-04 16:10:38 +03:00
commit d21872b368
6 changed files with 240 additions and 278 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Mailbox reservation modules for DSP * Mailbox reservation modules for OMAP1
* *
* Copyright (C) 2006-2009 Nokia Corporation * Copyright (C) 2006-2009 Nokia Corporation
* Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com> * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
@ -9,13 +9,10 @@
* for more details. * for more details.
*/ */
#include <linux/kernel.h>
#include <linux/resource.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/io.h> #include <linux/io.h>
#include <plat/mailbox.h> #include <plat/mailbox.h>
#include <mach/irqs.h>
#define MAILBOX_ARM2DSP1 0x00 #define MAILBOX_ARM2DSP1 0x00
#define MAILBOX_ARM2DSP1b 0x04 #define MAILBOX_ARM2DSP1b 0x04
@ -83,7 +80,7 @@ static int omap1_mbox_fifo_full(struct omap_mbox *mbox)
struct omap_mbox1_fifo *fifo = struct omap_mbox1_fifo *fifo =
&((struct omap_mbox1_priv *)mbox->priv)->rx_fifo; &((struct omap_mbox1_priv *)mbox->priv)->rx_fifo;
return (mbox_read_reg(fifo->flag)); return mbox_read_reg(fifo->flag);
} }
/* irq */ /* irq */
@ -141,47 +138,37 @@ struct omap_mbox mbox_dsp_info = {
.ops = &omap1_mbox_ops, .ops = &omap1_mbox_ops,
.priv = &omap1_mbox_dsp_priv, .priv = &omap1_mbox_dsp_priv,
}; };
EXPORT_SYMBOL(mbox_dsp_info);
struct omap_mbox *omap1_mboxes[] = { &mbox_dsp_info, NULL };
static int __devinit omap1_mbox_probe(struct platform_device *pdev) static int __devinit omap1_mbox_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *mem;
int ret;
int i;
struct omap_mbox **list;
if (pdev->num_resources != 2) { list = omap1_mboxes;
dev_err(&pdev->dev, "invalid number of resources: %d\n", list[0]->irq = platform_get_irq_byname(pdev, "dsp");
pdev->num_resources);
return -ENODEV;
}
/* MBOX base */ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mbox_base = ioremap(mem->start, resource_size(mem));
if (unlikely(!res)) { if (!mbox_base)
dev_err(&pdev->dev, "invalid mem resource\n"); return -ENOMEM;
return -ENODEV;
}
mbox_base = ioremap(res->start, resource_size(res)); ret = omap_mbox_register(&pdev->dev, list);
if (!mbox_base) { if (ret) {
dev_err(&pdev->dev, "ioremap failed\n");
return -ENODEV;
}
/* DSP IRQ */
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (unlikely(!res)) {
dev_err(&pdev->dev, "invalid irq resource\n");
iounmap(mbox_base); iounmap(mbox_base);
return -ENODEV; return ret;
} }
mbox_dsp_info.irq = res->start;
return omap_mbox_register(&pdev->dev, &mbox_dsp_info); return 0;
} }
static int __devexit omap1_mbox_remove(struct platform_device *pdev) static int __devexit omap1_mbox_remove(struct platform_device *pdev)
{ {
omap_mbox_unregister(&mbox_dsp_info); omap_mbox_unregister();
iounmap(mbox_base);
return 0; return 0;
} }
@ -189,7 +176,7 @@ static struct platform_driver omap1_mbox_driver = {
.probe = omap1_mbox_probe, .probe = omap1_mbox_probe,
.remove = __devexit_p(omap1_mbox_remove), .remove = __devexit_p(omap1_mbox_remove),
.driver = { .driver = {
.name = "omap1-mailbox", .name = "omap-mailbox",
}, },
}; };

View File

@ -152,10 +152,12 @@ static struct resource omap2_mbox_resources[] = {
{ {
.start = INT_24XX_MAIL_U0_MPU, .start = INT_24XX_MAIL_U0_MPU,
.flags = IORESOURCE_IRQ, .flags = IORESOURCE_IRQ,
.name = "dsp",
}, },
{ {
.start = INT_24XX_MAIL_U3_MPU, .start = INT_24XX_MAIL_U3_MPU,
.flags = IORESOURCE_IRQ, .flags = IORESOURCE_IRQ,
.name = "iva",
}, },
}; };
static int omap2_mbox_resources_sz = ARRAY_SIZE(omap2_mbox_resources); static int omap2_mbox_resources_sz = ARRAY_SIZE(omap2_mbox_resources);
@ -174,6 +176,7 @@ static struct resource omap3_mbox_resources[] = {
{ {
.start = INT_24XX_MAIL_U0_MPU, .start = INT_24XX_MAIL_U0_MPU,
.flags = IORESOURCE_IRQ, .flags = IORESOURCE_IRQ,
.name = "dsp",
}, },
}; };
static int omap3_mbox_resources_sz = ARRAY_SIZE(omap3_mbox_resources); static int omap3_mbox_resources_sz = ARRAY_SIZE(omap3_mbox_resources);
@ -195,6 +198,7 @@ static struct resource omap4_mbox_resources[] = {
{ {
.start = OMAP44XX_IRQ_MAIL_U0, .start = OMAP44XX_IRQ_MAIL_U0,
.flags = IORESOURCE_IRQ, .flags = IORESOURCE_IRQ,
.name = "mbox",
}, },
}; };
static int omap4_mbox_resources_sz = ARRAY_SIZE(omap4_mbox_resources); static int omap4_mbox_resources_sz = ARRAY_SIZE(omap4_mbox_resources);
@ -204,7 +208,7 @@ static int omap4_mbox_resources_sz = ARRAY_SIZE(omap4_mbox_resources);
#endif #endif
static struct platform_device mbox_device = { static struct platform_device mbox_device = {
.name = "omap2-mailbox", .name = "omap-mailbox",
.id = -1, .id = -1,
}; };

View File

@ -10,7 +10,6 @@
* for more details. * for more details.
*/ */
#include <linux/kernel.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
@ -18,8 +17,6 @@
#include <plat/mailbox.h> #include <plat/mailbox.h>
#include <mach/irqs.h> #include <mach/irqs.h>
#define DRV_NAME "omap2-mailbox"
#define MAILBOX_REVISION 0x000 #define MAILBOX_REVISION 0x000
#define MAILBOX_SYSCONFIG 0x010 #define MAILBOX_SYSCONFIG 0x010
#define MAILBOX_SYSSTATUS 0x014 #define MAILBOX_SYSSTATUS 0x014
@ -131,7 +128,7 @@ static int omap2_mbox_startup(struct omap_mbox *mbox)
} }
l = mbox_read_reg(MAILBOX_REVISION); l = mbox_read_reg(MAILBOX_REVISION);
pr_info("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f)); pr_debug("omap mailbox rev %d.%d\n", (l & 0xf0) >> 4, (l & 0x0f));
if (cpu_is_omap44xx()) if (cpu_is_omap44xx())
l = OMAP4_SMARTIDLE; l = OMAP4_SMARTIDLE;
@ -283,6 +280,8 @@ static struct omap_mbox_ops omap2_mbox_ops = {
*/ */
/* FIXME: the following structs should be filled automatically by the user id */ /* FIXME: the following structs should be filled automatically by the user id */
#if defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_ARCH_OMAP2420)
/* DSP */ /* DSP */
static struct omap_mbox2_priv omap2_mbox_dsp_priv = { static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
.tx_fifo = { .tx_fifo = {
@ -300,10 +299,46 @@ static struct omap_mbox2_priv omap2_mbox_dsp_priv = {
.irqdisable = MAILBOX_IRQENABLE(0), .irqdisable = MAILBOX_IRQENABLE(0),
}; };
struct omap_mbox mbox_dsp_info = {
.name = "dsp",
.ops = &omap2_mbox_ops,
.priv = &omap2_mbox_dsp_priv,
};
#endif
#if defined(CONFIG_ARCH_OMAP3430)
struct omap_mbox *omap3_mboxes[] = { &mbox_dsp_info, NULL };
#endif
/* OMAP4 specific data structure. Use the cpu_is_omap4xxx() #if defined(CONFIG_ARCH_OMAP2420)
to use this*/ /* IVA */
static struct omap_mbox2_priv omap2_mbox_iva_priv = {
.tx_fifo = {
.msg = MAILBOX_MESSAGE(2),
.fifo_stat = MAILBOX_FIFOSTATUS(2),
},
.rx_fifo = {
.msg = MAILBOX_MESSAGE(3),
.msg_stat = MAILBOX_MSGSTATUS(3),
},
.irqenable = MAILBOX_IRQENABLE(3),
.irqstatus = MAILBOX_IRQSTATUS(3),
.notfull_bit = MAILBOX_IRQ_NOTFULL(2),
.newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
.irqdisable = MAILBOX_IRQENABLE(3),
};
static struct omap_mbox mbox_iva_info = {
.name = "iva",
.ops = &omap2_mbox_ops,
.priv = &omap2_mbox_iva_priv,
};
struct omap_mbox *omap2_mboxes[] = { &mbox_iva_info, &mbox_dsp_info, NULL };
#endif
#if defined(CONFIG_ARCH_OMAP4)
/* OMAP4 */
static struct omap_mbox2_priv omap2_mbox_1_priv = { static struct omap_mbox2_priv omap2_mbox_1_priv = {
.tx_fifo = { .tx_fifo = {
.msg = MAILBOX_MESSAGE(0), .msg = MAILBOX_MESSAGE(0),
@ -325,14 +360,6 @@ struct omap_mbox mbox_1_info = {
.ops = &omap2_mbox_ops, .ops = &omap2_mbox_ops,
.priv = &omap2_mbox_1_priv, .priv = &omap2_mbox_1_priv,
}; };
EXPORT_SYMBOL(mbox_1_info);
struct omap_mbox mbox_dsp_info = {
.name = "dsp",
.ops = &omap2_mbox_ops,
.priv = &omap2_mbox_dsp_priv,
};
EXPORT_SYMBOL(mbox_dsp_info);
static struct omap_mbox2_priv omap2_mbox_2_priv = { static struct omap_mbox2_priv omap2_mbox_2_priv = {
.tx_fifo = { .tx_fifo = {
@ -355,110 +382,64 @@ struct omap_mbox mbox_2_info = {
.ops = &omap2_mbox_ops, .ops = &omap2_mbox_ops,
.priv = &omap2_mbox_2_priv, .priv = &omap2_mbox_2_priv,
}; };
EXPORT_SYMBOL(mbox_2_info);
struct omap_mbox *omap4_mboxes[] = { &mbox_1_info, &mbox_2_info, NULL };
#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
static struct omap_mbox2_priv omap2_mbox_iva_priv = {
.tx_fifo = {
.msg = MAILBOX_MESSAGE(2),
.fifo_stat = MAILBOX_FIFOSTATUS(2),
},
.rx_fifo = {
.msg = MAILBOX_MESSAGE(3),
.msg_stat = MAILBOX_MSGSTATUS(3),
},
.irqenable = MAILBOX_IRQENABLE(3),
.irqstatus = MAILBOX_IRQSTATUS(3),
.notfull_bit = MAILBOX_IRQ_NOTFULL(2),
.newmsg_bit = MAILBOX_IRQ_NEWMSG(3),
.irqdisable = MAILBOX_IRQENABLE(3),
};
static struct omap_mbox mbox_iva_info = {
.name = "iva",
.ops = &omap2_mbox_ops,
.priv = &omap2_mbox_iva_priv,
};
#endif #endif
static int __devinit omap2_mbox_probe(struct platform_device *pdev) static int __devinit omap2_mbox_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *mem;
int ret; int ret;
struct omap_mbox **list;
/* MBOX base */ if (false)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); ;
if (unlikely(!res)) { #if defined(CONFIG_ARCH_OMAP3430)
dev_err(&pdev->dev, "invalid mem resource\n"); else if (cpu_is_omap3430()) {
list = omap3_mboxes;
list[0]->irq = platform_get_irq_byname(pdev, "dsp");
}
#endif
#if defined(CONFIG_ARCH_OMAP2420)
else if (cpu_is_omap2420()) {
list = omap2_mboxes;
list[0]->irq = platform_get_irq_byname(pdev, "dsp");
list[1]->irq = platform_get_irq_byname(pdev, "iva");
}
#endif
#if defined(CONFIG_ARCH_OMAP4)
else if (cpu_is_omap44xx()) {
list = omap4_mboxes;
list[0]->irq = list[1]->irq =
platform_get_irq_byname(pdev, "mbox");
}
#endif
else {
pr_err("%s: platform not supported\n", __func__);
return -ENODEV; return -ENODEV;
} }
mbox_base = ioremap(res->start, resource_size(res));
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mbox_base = ioremap(mem->start, resource_size(mem));
if (!mbox_base) if (!mbox_base)
return -ENOMEM; return -ENOMEM;
/* DSP or IVA2 IRQ */ ret = omap_mbox_register(&pdev->dev, list);
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (ret) {
iounmap(mbox_base);
if (unlikely(!res)) { return ret;
dev_err(&pdev->dev, "invalid irq resource\n");
ret = -ENODEV;
goto err_dsp;
} }
if (cpu_is_omap44xx()) {
mbox_1_info.irq = res->start;
ret = omap_mbox_register(&pdev->dev, &mbox_1_info);
} else {
mbox_dsp_info.irq = res->start;
ret = omap_mbox_register(&pdev->dev, &mbox_dsp_info);
}
if (ret)
goto err_dsp;
if (cpu_is_omap44xx()) {
mbox_2_info.irq = res->start;
ret = omap_mbox_register(&pdev->dev, &mbox_2_info);
if (ret) {
omap_mbox_unregister(&mbox_1_info);
goto err_dsp;
}
}
#if defined(CONFIG_ARCH_OMAP2420) /* IVA */
if (cpu_is_omap2420()) {
/* IVA IRQ */
res = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
if (unlikely(!res)) {
dev_err(&pdev->dev, "invalid irq resource\n");
ret = -ENODEV;
omap_mbox_unregister(&mbox_dsp_info);
goto err_dsp;
}
mbox_iva_info.irq = res->start;
ret = omap_mbox_register(&pdev->dev, &mbox_iva_info);
if (ret) {
omap_mbox_unregister(&mbox_dsp_info);
goto err_dsp;
}
}
#endif
return 0; return 0;
err_dsp:
iounmap(mbox_base);
return ret; return ret;
} }
static int __devexit omap2_mbox_remove(struct platform_device *pdev) static int __devexit omap2_mbox_remove(struct platform_device *pdev)
{ {
#if defined(CONFIG_ARCH_OMAP2420) omap_mbox_unregister();
omap_mbox_unregister(&mbox_iva_info);
#endif
if (cpu_is_omap44xx()) {
omap_mbox_unregister(&mbox_2_info);
omap_mbox_unregister(&mbox_1_info);
} else
omap_mbox_unregister(&mbox_dsp_info);
iounmap(mbox_base); iounmap(mbox_base);
return 0; return 0;
} }
@ -467,7 +448,7 @@ static struct platform_driver omap2_mbox_driver = {
.probe = omap2_mbox_probe, .probe = omap2_mbox_probe,
.remove = __devexit_p(omap2_mbox_remove), .remove = __devexit_p(omap2_mbox_remove),
.driver = { .driver = {
.name = DRV_NAME, .name = "omap-mailbox",
}, },
}; };
@ -486,5 +467,6 @@ module_exit(omap2_mbox_exit);
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions"); MODULE_DESCRIPTION("omap mailbox: omap2/3/4 architecture specific functions");
MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>, Paul Mundt"); MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU@nokia.com>");
MODULE_ALIAS("platform:"DRV_NAME); MODULE_AUTHOR("Paul Mundt");
MODULE_ALIAS("platform:omap2-mailbox");

View File

@ -88,6 +88,15 @@ config OMAP_MBOX_FWK
Say Y here if you want to use OMAP Mailbox framework support for Say Y here if you want to use OMAP Mailbox framework support for
DSP, IVA1.0 and IVA2 in OMAP1/2/3. DSP, IVA1.0 and IVA2 in OMAP1/2/3.
config OMAP_MBOX_KFIFO_SIZE
int "Mailbox kfifo default buffer size (bytes)"
depends on OMAP_MBOX_FWK
default 256
help
Specify the default size of mailbox's kfifo buffers (bytes).
This can also be changed at runtime (via the mbox_kfifo_size
module parameter).
config OMAP_IOMMU config OMAP_IOMMU
tristate tristate

View File

@ -3,10 +3,11 @@
#ifndef MAILBOX_H #ifndef MAILBOX_H
#define MAILBOX_H #define MAILBOX_H
#include <linux/wait.h> #include <linux/spinlock.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/blkdev.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/kfifo.h>
typedef u32 mbox_msg_t; typedef u32 mbox_msg_t;
struct omap_mbox; struct omap_mbox;
@ -42,7 +43,7 @@ struct omap_mbox_ops {
struct omap_mbox_queue { struct omap_mbox_queue {
spinlock_t lock; spinlock_t lock;
struct request_queue *queue; struct kfifo fifo;
struct work_struct work; struct work_struct work;
struct tasklet_struct tasklet; struct tasklet_struct tasklet;
int (*callback)(void *); int (*callback)(void *);
@ -52,19 +53,10 @@ struct omap_mbox_queue {
struct omap_mbox { struct omap_mbox {
char *name; char *name;
unsigned int irq; unsigned int irq;
struct omap_mbox_queue *txq, *rxq; struct omap_mbox_queue *txq, *rxq;
struct omap_mbox_ops *ops; struct omap_mbox_ops *ops;
mbox_msg_t seq_snd, seq_rcv;
struct device *dev; struct device *dev;
struct omap_mbox *next;
void *priv; void *priv;
void (*err_notify)(void);
}; };
int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg); int omap_mbox_msg_send(struct omap_mbox *, mbox_msg_t msg);
@ -73,8 +65,8 @@ void omap_mbox_init_seq(struct omap_mbox *);
struct omap_mbox *omap_mbox_get(const char *); struct omap_mbox *omap_mbox_get(const char *);
void omap_mbox_put(struct omap_mbox *); void omap_mbox_put(struct omap_mbox *);
int omap_mbox_register(struct device *parent, struct omap_mbox *); int omap_mbox_register(struct device *parent, struct omap_mbox **);
int omap_mbox_unregister(struct omap_mbox *); int omap_mbox_unregister(void);
static inline void omap_mbox_save_ctx(struct omap_mbox *mbox) static inline void omap_mbox_save_ctx(struct omap_mbox *mbox)
{ {

View File

@ -21,19 +21,26 @@
* *
*/ */
#include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/device.h> #include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/kfifo.h>
#include <linux/err.h>
#include <plat/mailbox.h> #include <plat/mailbox.h>
static struct workqueue_struct *mboxd; static struct workqueue_struct *mboxd;
static struct omap_mbox *mboxes; static struct omap_mbox **mboxes;
static DEFINE_RWLOCK(mboxes_lock); static bool rq_full;
static int mbox_configured; static int mbox_configured;
static DEFINE_MUTEX(mbox_configured_lock);
static unsigned int mbox_kfifo_size = CONFIG_OMAP_MBOX_KFIFO_SIZE;
module_param(mbox_kfifo_size, uint, S_IRUGO);
MODULE_PARM_DESC(mbox_kfifo_size, "Size of omap's mailbox kfifo (bytes)");
/* Mailbox FIFO handle functions */ /* Mailbox FIFO handle functions */
static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox) static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
@ -67,7 +74,7 @@ static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
/* /*
* message sender * message sender
*/ */
static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) static int __mbox_poll_for_space(struct omap_mbox *mbox)
{ {
int ret = 0, i = 1000; int ret = 0, i = 1000;
@ -78,49 +85,50 @@ static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
return -1; return -1;
udelay(1); udelay(1);
} }
mbox_fifo_write(mbox, msg);
return ret; return ret;
} }
int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg) int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg)
{ {
struct omap_mbox_queue *mq = mbox->txq;
int ret = 0, len;
struct request *rq; spin_lock(&mq->lock);
struct request_queue *q = mbox->txq->queue;
rq = blk_get_request(q, WRITE, GFP_ATOMIC); if (kfifo_avail(&mq->fifo) < sizeof(msg)) {
if (unlikely(!rq)) ret = -ENOMEM;
return -ENOMEM; goto out;
}
len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
WARN_ON(len != sizeof(msg));
blk_insert_request(q, rq, 0, (void *) msg);
tasklet_schedule(&mbox->txq->tasklet); tasklet_schedule(&mbox->txq->tasklet);
return 0; out:
spin_unlock(&mq->lock);
return ret;
} }
EXPORT_SYMBOL(omap_mbox_msg_send); EXPORT_SYMBOL(omap_mbox_msg_send);
static void mbox_tx_tasklet(unsigned long tx_data) static void mbox_tx_tasklet(unsigned long tx_data)
{ {
int ret;
struct request *rq;
struct omap_mbox *mbox = (struct omap_mbox *)tx_data; struct omap_mbox *mbox = (struct omap_mbox *)tx_data;
struct request_queue *q = mbox->txq->queue; struct omap_mbox_queue *mq = mbox->txq;
mbox_msg_t msg;
int ret;
while (1) { while (kfifo_len(&mq->fifo)) {
if (__mbox_poll_for_space(mbox)) {
rq = blk_fetch_request(q);
if (!rq)
break;
ret = __mbox_msg_send(mbox, (mbox_msg_t)rq->special);
if (ret) {
omap_mbox_enable_irq(mbox, IRQ_TX); omap_mbox_enable_irq(mbox, IRQ_TX);
blk_requeue_request(q, rq); break;
return;
} }
blk_end_request_all(rq, 0);
ret = kfifo_out(&mq->fifo, (unsigned char *)&msg,
sizeof(msg));
WARN_ON(ret != sizeof(msg));
mbox_fifo_write(mbox, msg);
} }
} }
@ -131,36 +139,21 @@ static void mbox_rx_work(struct work_struct *work)
{ {
struct omap_mbox_queue *mq = struct omap_mbox_queue *mq =
container_of(work, struct omap_mbox_queue, work); container_of(work, struct omap_mbox_queue, work);
struct omap_mbox *mbox = mq->queue->queuedata;
struct request_queue *q = mbox->rxq->queue;
struct request *rq;
mbox_msg_t msg; mbox_msg_t msg;
unsigned long flags; int len;
while (1) { while (kfifo_len(&mq->fifo) >= sizeof(msg)) {
spin_lock_irqsave(q->queue_lock, flags); len = kfifo_out(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
rq = blk_fetch_request(q); WARN_ON(len != sizeof(msg));
spin_unlock_irqrestore(q->queue_lock, flags);
if (!rq)
break;
msg = (mbox_msg_t)rq->special; if (mq->callback)
blk_end_request_all(rq, 0); mq->callback((void *)msg);
mbox->rxq->callback((void *)msg);
} }
} }
/* /*
* Mailbox interrupt handler * Mailbox interrupt handler
*/ */
static void mbox_txq_fn(struct request_queue *q)
{
}
static void mbox_rxq_fn(struct request_queue *q)
{
}
static void __mbox_tx_interrupt(struct omap_mbox *mbox) static void __mbox_tx_interrupt(struct omap_mbox *mbox)
{ {
omap_mbox_disable_irq(mbox, IRQ_TX); omap_mbox_disable_irq(mbox, IRQ_TX);
@ -170,19 +163,22 @@ static void __mbox_tx_interrupt(struct omap_mbox *mbox)
static void __mbox_rx_interrupt(struct omap_mbox *mbox) static void __mbox_rx_interrupt(struct omap_mbox *mbox)
{ {
struct request *rq; struct omap_mbox_queue *mq = mbox->rxq;
mbox_msg_t msg; mbox_msg_t msg;
struct request_queue *q = mbox->rxq->queue; int len;
while (!mbox_fifo_empty(mbox)) { while (!mbox_fifo_empty(mbox)) {
rq = blk_get_request(q, WRITE, GFP_ATOMIC); if (unlikely(kfifo_avail(&mq->fifo) < sizeof(msg))) {
if (unlikely(!rq)) omap_mbox_disable_irq(mbox, IRQ_RX);
rq_full = true;
goto nomem; goto nomem;
}
msg = mbox_fifo_read(mbox); msg = mbox_fifo_read(mbox);
len = kfifo_in(&mq->fifo, (unsigned char *)&msg, sizeof(msg));
WARN_ON(len != sizeof(msg));
blk_insert_request(q, rq, 0, (void *)msg);
if (mbox->ops->type == OMAP_MBOX_TYPE1) if (mbox->ops->type == OMAP_MBOX_TYPE1)
break; break;
} }
@ -207,11 +203,9 @@ static irqreturn_t mbox_interrupt(int irq, void *p)
} }
static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox, static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
request_fn_proc *proc,
void (*work) (struct work_struct *), void (*work) (struct work_struct *),
void (*tasklet)(unsigned long)) void (*tasklet)(unsigned long))
{ {
struct request_queue *q;
struct omap_mbox_queue *mq; struct omap_mbox_queue *mq;
mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL); mq = kzalloc(sizeof(struct omap_mbox_queue), GFP_KERNEL);
@ -220,11 +214,8 @@ static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
spin_lock_init(&mq->lock); spin_lock_init(&mq->lock);
q = blk_init_queue(proc, &mq->lock); if (kfifo_alloc(&mq->fifo, mbox_kfifo_size, GFP_KERNEL))
if (!q)
goto error; goto error;
q->queuedata = mbox;
mq->queue = q;
if (work) if (work)
INIT_WORK(&mq->work, work); INIT_WORK(&mq->work, work);
@ -239,7 +230,7 @@ static struct omap_mbox_queue *mbox_queue_alloc(struct omap_mbox *mbox,
static void mbox_queue_free(struct omap_mbox_queue *q) static void mbox_queue_free(struct omap_mbox_queue *q)
{ {
blk_cleanup_queue(q->queue); kfifo_free(&q->fifo);
kfree(q); kfree(q);
} }
@ -248,35 +239,35 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
int ret = 0; int ret = 0;
struct omap_mbox_queue *mq; struct omap_mbox_queue *mq;
if (likely(mbox->ops->startup)) { if (mbox->ops->startup) {
write_lock(&mboxes_lock); mutex_lock(&mbox_configured_lock);
if (!mbox_configured) if (!mbox_configured)
ret = mbox->ops->startup(mbox); ret = mbox->ops->startup(mbox);
if (unlikely(ret)) { if (ret) {
write_unlock(&mboxes_lock); mutex_unlock(&mbox_configured_lock);
return ret; return ret;
} }
mbox_configured++; mbox_configured++;
write_unlock(&mboxes_lock); mutex_unlock(&mbox_configured_lock);
} }
ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED, ret = request_irq(mbox->irq, mbox_interrupt, IRQF_SHARED,
mbox->name, mbox); mbox->name, mbox);
if (unlikely(ret)) { if (ret) {
printk(KERN_ERR printk(KERN_ERR
"failed to register mailbox interrupt:%d\n", ret); "failed to register mailbox interrupt:%d\n", ret);
goto fail_request_irq; goto fail_request_irq;
} }
mq = mbox_queue_alloc(mbox, mbox_txq_fn, NULL, mbox_tx_tasklet); mq = mbox_queue_alloc(mbox, NULL, mbox_tx_tasklet);
if (!mq) { if (!mq) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_alloc_txq; goto fail_alloc_txq;
} }
mbox->txq = mq; mbox->txq = mq;
mq = mbox_queue_alloc(mbox, mbox_rxq_fn, mbox_rx_work, NULL); mq = mbox_queue_alloc(mbox, mbox_rx_work, NULL);
if (!mq) { if (!mq) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_alloc_rxq; goto fail_alloc_rxq;
@ -290,7 +281,7 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
fail_alloc_txq: fail_alloc_txq:
free_irq(mbox->irq, mbox); free_irq(mbox->irq, mbox);
fail_request_irq: fail_request_irq:
if (unlikely(mbox->ops->shutdown)) if (mbox->ops->shutdown)
mbox->ops->shutdown(mbox); mbox->ops->shutdown(mbox);
return ret; return ret;
@ -298,46 +289,36 @@ static int omap_mbox_startup(struct omap_mbox *mbox)
static void omap_mbox_fini(struct omap_mbox *mbox) static void omap_mbox_fini(struct omap_mbox *mbox)
{ {
free_irq(mbox->irq, mbox);
tasklet_kill(&mbox->txq->tasklet);
flush_work(&mbox->rxq->work);
mbox_queue_free(mbox->txq); mbox_queue_free(mbox->txq);
mbox_queue_free(mbox->rxq); mbox_queue_free(mbox->rxq);
free_irq(mbox->irq, mbox); if (mbox->ops->shutdown) {
mutex_lock(&mbox_configured_lock);
if (unlikely(mbox->ops->shutdown)) {
write_lock(&mboxes_lock);
if (mbox_configured > 0) if (mbox_configured > 0)
mbox_configured--; mbox_configured--;
if (!mbox_configured) if (!mbox_configured)
mbox->ops->shutdown(mbox); mbox->ops->shutdown(mbox);
write_unlock(&mboxes_lock); mutex_unlock(&mbox_configured_lock);
} }
} }
static struct omap_mbox **find_mboxes(const char *name)
{
struct omap_mbox **p;
for (p = &mboxes; *p; p = &(*p)->next) {
if (strcmp((*p)->name, name) == 0)
break;
}
return p;
}
struct omap_mbox *omap_mbox_get(const char *name) struct omap_mbox *omap_mbox_get(const char *name)
{ {
struct omap_mbox *mbox; struct omap_mbox *mbox;
int ret; int ret;
read_lock(&mboxes_lock); if (!mboxes)
mbox = *(find_mboxes(name)); return ERR_PTR(-EINVAL);
if (mbox == NULL) {
read_unlock(&mboxes_lock);
return ERR_PTR(-ENOENT);
}
read_unlock(&mboxes_lock); for (mbox = *mboxes; mbox; mbox++)
if (!strcmp(mbox->name, name))
break;
if (!mbox)
return ERR_PTR(-ENOENT);
ret = omap_mbox_startup(mbox); ret = omap_mbox_startup(mbox);
if (ret) if (ret)
@ -353,70 +334,77 @@ void omap_mbox_put(struct omap_mbox *mbox)
} }
EXPORT_SYMBOL(omap_mbox_put); EXPORT_SYMBOL(omap_mbox_put);
int omap_mbox_register(struct device *parent, struct omap_mbox *mbox) static struct class omap_mbox_class = { .name = "mbox", };
int omap_mbox_register(struct device *parent, struct omap_mbox **list)
{ {
int ret = 0; int ret;
struct omap_mbox **tmp; int i;
if (!mbox) mboxes = list;
if (!mboxes)
return -EINVAL; return -EINVAL;
if (mbox->next)
return -EBUSY;
write_lock(&mboxes_lock); for (i = 0; mboxes[i]; i++) {
tmp = find_mboxes(mbox->name); struct omap_mbox *mbox = mboxes[i];
if (*tmp) { mbox->dev = device_create(&omap_mbox_class,
ret = -EBUSY; parent, 0, mbox, "%s", mbox->name);
write_unlock(&mboxes_lock); if (IS_ERR(mbox->dev)) {
goto err_find; ret = PTR_ERR(mbox->dev);
goto err_out;
}
} }
*tmp = mbox;
write_unlock(&mboxes_lock);
return 0; return 0;
err_find: err_out:
while (i--)
device_unregister(mboxes[i]->dev);
return ret; return ret;
} }
EXPORT_SYMBOL(omap_mbox_register); EXPORT_SYMBOL(omap_mbox_register);
int omap_mbox_unregister(struct omap_mbox *mbox) int omap_mbox_unregister(void)
{ {
struct omap_mbox **tmp; int i;
write_lock(&mboxes_lock); if (!mboxes)
tmp = &mboxes; return -EINVAL;
while (*tmp) {
if (mbox == *tmp) {
*tmp = mbox->next;
mbox->next = NULL;
write_unlock(&mboxes_lock);
return 0;
}
tmp = &(*tmp)->next;
}
write_unlock(&mboxes_lock);
return -EINVAL; for (i = 0; mboxes[i]; i++)
device_unregister(mboxes[i]->dev);
mboxes = NULL;
return 0;
} }
EXPORT_SYMBOL(omap_mbox_unregister); EXPORT_SYMBOL(omap_mbox_unregister);
static int __init omap_mbox_init(void) static int __init omap_mbox_init(void)
{ {
int err;
err = class_register(&omap_mbox_class);
if (err)
return err;
mboxd = create_workqueue("mboxd"); mboxd = create_workqueue("mboxd");
if (!mboxd) if (!mboxd)
return -ENOMEM; return -ENOMEM;
/* kfifo size sanity check: alignment and minimal size */
mbox_kfifo_size = ALIGN(mbox_kfifo_size, sizeof(mbox_msg_t));
mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size, sizeof(mbox_msg_t));
return 0; return 0;
} }
module_init(omap_mbox_init); subsys_initcall(omap_mbox_init);
static void __exit omap_mbox_exit(void) static void __exit omap_mbox_exit(void)
{ {
destroy_workqueue(mboxd); destroy_workqueue(mboxd);
class_unregister(&omap_mbox_class);
} }
module_exit(omap_mbox_exit); module_exit(omap_mbox_exit);
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging"); MODULE_DESCRIPTION("omap mailbox: interrupt driven messaging");
MODULE_AUTHOR("Toshihiro Kobayashi and Hiroshi DOYU"); MODULE_AUTHOR("Toshihiro Kobayashi");
MODULE_AUTHOR("Hiroshi DOYU");