mailbox: add support for APM X-Gene platform mailbox driver
PATCH 2/3 Documentation: mailbox: Add APM X-Gene SLIMpro mailbox dts documentation
In reply to Feng KanThis adds the APM X-Gene SLIMpro mailbox device tree node documentation.
--- .../bindings/mailbox/xgene-slimpro-mailbox.txt | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/xgene-slimpro-mailbox.txt
Documentation/devicetree/bindings/mailbox/xgene-slimpro-mailbox.txt new file +34 -0
@@ -0,0 +1,34 @@ +The APM X-Gene SLIMpro mailbox is used to communicate messages between +the ARM64 processors and the Cortex M3 (dubbed SLIMpro). It uses a simple +interrupt based door bell mechanism and can exchange simple messages using the +internal registers. + +There are total of 7 interrupts in this mailbox. Each used for an individual +door bell (or mailbox channel). + +Required properties: +- compatible: Should be as "apm, xgene-slimpro-mbox". + +- reg: Contain the mailbox register address range. + +- interrupts: 7 interrupts must start from 0 to 6, interrupt 0 define the + the interrupt for mailbox channel 0 and interrupt 1 for + mailbox channel 1 and so likewise for the reminder. + +- #mbox-cells: only one to specify the mailbox channel number. + +Example: + +Mailbox Node: + slimpro-mbox: slimpro-mbox@10540000 { + compatible = "apm,xgene-slimpro-mbox"; + reg = <0x0 0x10540000 0x0 0xa000>; + #mbox-cells = <1>; + interrupts = <0x0 0x0 0x4>, + <0x0 0x1 0x4>, + <0x0 0x2 0x4>, + <0x0 0x3 0x4>, + <0x0 0x4 0x4>, + <0x0 0x5 0x4>, + <0x0 0x6 0x4>, + };
Signature · 1 line
1.9.1
PATCH 1/3 mailbox: add support for APM X-Gene platform mailbox driver
Add support for APM X-Gene platform mailbox driver.
--- drivers/mailbox/Kconfig | 10 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/mailbox-xgene-slimpro.c | 289 ++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 drivers/mailbox/mailbox-xgene-slimpro.c
drivers/mailbox/Kconfig +10 -0
@@ -51,4 +51,14 @@ config ALTERA_MBOX An implementation of the Altera Mailbox soft core. It is used to send message between processors. Say Y here if you want to use the Altera mailbox support. + +config XGENE_SLIMPRO_MBOX + tristate "APM SoC X-Gene SLIMpro Mailbox Controller" + depends on ARCH_XGENE + help + An implementation of the APM X-Gene Interprocessor Communication + Mailbox (IPCM) between the ARM 64-bit cores and SLIMpro controller. + It is used to send short messages between ARM64-bit cores and + the SLIMpro Management Engine, primarily for PM. Say Y here if you + want to use the APM X-Gene SLIMpro IPCM support. endif
drivers/mailbox/Makefile +2 -0
@@ -9,3 +9,5 @@ obj-$(CONFIG_OMAP2PLUS_MBOX) += omap-mailbox.o obj-$(CONFIG_PCC) += pcc.o obj-$(CONFIG_ALTERA_MBOX) += mailbox-altera.o + +obj-$(CONFIG_XGENE_SLIMPRO_MBOX) += mailbox-xgene-slimpro.o
drivers/mailbox/mailbox-xgene-slimpro.c new file +289 -0
289 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 3/3 arm64: dts: mailbox device tree node for APM X-Gene platform.
Mailbox device tree node for APM X-Gene platform.
--- arch/arm64/boot/dts/apm/apm-storm.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/apm/apm-storm.dtsi +14 -0
@@ -469,6 +469,20 @@ clocks = <&pcie4clk 0>; }; + mailbox: slimpro-mbox at 10540000 { + compatible = "apm,xgene-slimpro-mbox"; + reg = <0x0 0x10540000 0x0 0xa000>; + #mbox-cells = <1>; + interrupts = <0x0 0x0 0x4>, + <0x0 0x1 0x4>, + <0x0 0x2 0x4>, + <0x0 0x3 0x4>, + <0x0 0x4 0x4>, + <0x0 0x5 0x4>, + <0x0 0x6 0x4>, + <0x0 0x7 0x4>; + }; + serial0: serial at 1c020000 { status = "disabled"; device_type = "serial";
Signature · 1 line
1.9.1
Jassi Brar
maintainerdrivers/mailbox/mailbox-xgene-slimpro.c line 35
Quoted 6 lines · Feng Kan
drivers/mailbox/mailbox-xgene-slimpro.c new file +5
-0+#define MBOX_CON_NAME "slimpro-mbox" +#define MBOX_REG_SET_OFFSET 0x1000 +#define MBOX_CNT 8 +#define MBOX_STATUS_AVAIL_MASK 0x00010000 +#define MBOX_STATUS_ACK_MASK 0x00000001
Nit: BIT(16) and BIT(0) is more readable
Quoted 4 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +4
-0+/* Configuration and Status Registers */ +struct slimpro_mbox_reg { +u32 in; +u32 din0;
drivers/mailbox/mailbox-xgene-slimpro.c line 50
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+u32 din1; +u32 rsvd1; +u32 out; +u32 dout0; +u32 dout1; +u32 rsvd2; +u32 status; +u32 statusmask; +}; +
Why not the normal way of defining offset macros, like most drivers do?
Quoted 9 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +9
-0+struct slimpro_mbox_chan { +struct device *dev; +struct mbox_chan *chan; +struct slimpro_mbox_reg __iomem *reg; +int id; +int irq; +u32 rx_msg[3 ]; +}; +
drivers/mailbox/mailbox-xgene-slimpro.c line 69
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+struct slimpro_mbox { +struct mbox_controller mb_ctrl; +struct slimpro_mbox_chan mc[MBOX_CNT ]; +struct mbox_chan chans[MBOX_CNT ]; +}; + +static struct slimpro_mbox_chan *to_slimpro_mbox_chan (struct mbox_chan *chan) +{ +if (!chan || !chan->con_priv) +return NULL ;
This seems un-necessary. Anyway you don't care for NULL returned :) Probably just kill this function?
Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +8
-0+ +return (struct slimpro_mbox_chan *)chan->con_priv; +} + +static void mb_chan_send_msg (struct slimpro_mbox_chan *mb_chan,u32 *msg) +{ +writel (msg[1 ], &mb_chan->reg->dout0); +writel (msg[2 ], &mb_chan->reg->dout1);
drivers/mailbox/mailbox-xgene-slimpro.c line 87
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+writel (msg[0 ], &mb_chan->reg->out); +} + +static void mb_chan_recv_msg (struct slimpro_mbox_chan *mb_chan) +{ + mb_chan->rx_msg[1 ] =readl (&mb_chan->reg->din0); + mb_chan->rx_msg[2 ] =readl (&mb_chan->reg->din1); + mb_chan->rx_msg[0 ] =readl (&mb_chan->reg->in); +} +
maybe move the send/recv function inline the caller?
Quoted 41 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +40
-0+static void mb_chan_enable_int (struct slimpro_mbox_chan *mb_chan,u32 mask) +{ +u32 val =readl (&mb_chan->reg->statusmask); + + val &= ~mask; + +writel (val, &mb_chan->reg->statusmask); +} + +static void mb_chan_disable_int (struct slimpro_mbox_chan *mb_chan,u32 mask) +{ +u32 val =readl (&mb_chan->reg->statusmask); + + val |= mask; + +writel (val, &mb_chan->reg->statusmask); +} + +static int mb_chan_status_ack (struct slimpro_mbox_chan *mb_chan) +{ +u32 val =readl (&mb_chan->reg->status); + +if (val &MBOX_STATUS_ACK_MASK ) { +writel (MBOX_STATUS_ACK_MASK , &mb_chan->reg->status); +return 1 ; + } +return 0 ; +} + +static int mb_chan_status_avail (struct slimpro_mbox_chan *mb_chan) +{ +u32 val =readl (&mb_chan->reg->status); + +if (val &MBOX_STATUS_AVAIL_MASK ) { +mb_chan_recv_msg (mb_chan); +writel (MBOX_STATUS_AVAIL_MASK , &mb_chan->reg->status); +return 1 ; + } +return 0 ; +}
drivers/mailbox/mailbox-xgene-slimpro.c line 137
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+ +static irqreturn_t slimpro_mbox_irq (int irq,void *id) +{ +struct slimpro_mbox_chan *mb_chan = id; + +if (mb_chan_status_ack (mb_chan)) +mbox_chan_txdone (mb_chan->chan,0 ); + +if (mb_chan_status_avail (mb_chan)) { +mb_chan_recv_msg (mb_chan);
you already did this in mb_chan_status_avail() is it needed?
Quoted 12 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +11
-0+mbox_chan_received_data (mb_chan->chan, mb_chan->rx_msg); + } + +return IRQ_HANDLED ; +} + +static int slimpro_mbox_send_data (struct mbox_chan *chan,void *msg) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); + +mb_chan_send_msg (mb_chan, msg);
drivers/mailbox/mailbox-xgene-slimpro.c line 158
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+return 0 ; +} + +static int slimpro_mbox_startup (struct mbox_chan *chan) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); +int rc; + + rc =devm_request_irq (mb_chan->dev, mb_chan->irq, slimpro_mbox_irq,0 , +MBOX_CON_NAME , mb_chan);
You may want to use IRQF_SHARED flag here and make slimpro_mbox_irq() aware of that -- some platforms tie together irq lines of all instances of a resource, like dma, mbox, so they may share the same irq line.
Quoted 24 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +23
-0+static int __init slimpro_mbox_probe (struct platform_device *pdev) +{ +struct slimpro_mbox *ctx; +struct resource *regs; +void __iomem *mb_base; +int rc; +int i; + + ctx =devm_kzalloc (&pdev->dev,sizeof (struct slimpro_mbox ),GFP_KERNEL ); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + +platform_set_drvdata (pdev, ctx); + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mb_base =devm_ioremap_resource (&pdev->dev, regs); +if (IS_ERR (mb_base)) +return PTR_ERR (mb_base); + +/* Setup mailbox links */ +for (i =0 ; i <MBOX_CNT ; i++) { + ctx->mc[i].irq =platform_get_irq (pdev, i); +if (ctx->mc[i].irq <0 ) {
drivers/mailbox/mailbox-xgene-slimpro.c line 220
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+dev_err (&pdev->dev,"no IRQ at index %d\n" , + ctx->mc[i].irq); +return -ENODEV ; + } + + ctx->mc[i].dev = &pdev->dev; + ctx->mc[i].reg = mb_base + i *MBOX_REG_SET_OFFSET ; + ctx->mc[i].id = i; + ctx->mc[i].chan = &ctx->chans[i]; + ctx->chans[i].con_priv = &ctx->mc[i];
Note to self: Maybe we should make it possible to populate a channel during request/of_xlate.
drivers/mailbox/mailbox-xgene-slimpro.c line 286
Quoted 12 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +12
-0+ +static int __init slimpro_mbox_init (void ) +{ +return platform_driver_register (&slimpro_mbox_driver); +} + +static void __exit slimpro_mbox_exit(void) +{ +} + +subsys_initcall (slimpro_mbox_init); +module_exit (slimpro_mbox_exit);
Why empty module_exit?
regards.
Quoted 9 lines · Jassi Brar
drivers/mailbox/mailbox-xgene-slimpro.c line 35
Quoted 6 lines · Feng Kan
drivers/mailbox/mailbox-xgene-slimpro.c new file +5
-0+#define MBOX_CON_NAME "slimpro-mbox" +#define MBOX_REG_SET_OFFSET 0x1000 +#define MBOX_CNT 8 +#define MBOX_STATUS_AVAIL_MASK 0x00010000 +#define MBOX_STATUS_ACK_MASK 0x00000001Nit: BIT(16) and BIT(0) is more readable
will fix
Quoted 16 lines
Quoted 5 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +4
-0+/* Configuration and Status Registers */ +struct slimpro_mbox_reg { +u32 in; +u32 din0;drivers/mailbox/mailbox-xgene-slimpro.c line 50
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+u32 din1; +u32 rsvd1; +u32 out; +u32 dout0; +u32 dout1; +u32 rsvd2; +u32 status; +u32 statusmask; +}; +Why not the normal way of defining offset macros, like most drivers do?
I personally don't prefer one way over another, let me know if you want me to change to use defines.
Quoted 14 lines
Quoted 14 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +13
-0+struct slimpro_mbox_chan { +struct device *dev; +struct mbox_chan *chan; +struct slimpro_mbox_reg __iomem *reg; +int id; +int irq; +u32 rx_msg[3 ]; +}; + +struct slimpro_mbox { +struct mbox_controller mb_ctrl; +struct slimpro_mbox_chan mc[MBOX_CNT ]; +struct mbox_chan chans[MBOX_CNT ];
Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c line 69
Quoted 6 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +6
-0+}; + +static struct slimpro_mbox_chan *to_slimpro_mbox_chan (struct mbox_chan *chan) +{ +if (!chan || !chan->con_priv) +return NULL ;This seems un-necessary. Anyway you don't care for NULL returned :) Probably just kill this function?
done
Quoted 12 lines
Quoted 12 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +11
-0+ +return (struct slimpro_mbox_chan *)chan->con_priv; +} + +static void mb_chan_send_msg (struct slimpro_mbox_chan *mb_chan,u32 *msg) +{ +writel (msg[1 ], &mb_chan->reg->dout0); +writel (msg[2 ], &mb_chan->reg->dout1); +writel (msg[0 ], &mb_chan->reg->out); +} +
Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c line 87
Quoted 7 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +7
-0+static void mb_chan_recv_msg (struct slimpro_mbox_chan *mb_chan) +{ + mb_chan->rx_msg[1 ] =readl (&mb_chan->reg->din0); + mb_chan->rx_msg[2 ] =readl (&mb_chan->reg->din1); + mb_chan->rx_msg[0 ] =readl (&mb_chan->reg->in); +} +maybe move the send/recv function inline the caller?
done
Quoted 45 lines
Quoted 45 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +44
-0+static void mb_chan_enable_int (struct slimpro_mbox_chan *mb_chan,u32 mask) +{ +u32 val =readl (&mb_chan->reg->statusmask); + + val &= ~mask; + +writel (val, &mb_chan->reg->statusmask); +} + +static void mb_chan_disable_int (struct slimpro_mbox_chan *mb_chan,u32 mask) +{ +u32 val =readl (&mb_chan->reg->statusmask); + + val |= mask; + +writel (val, &mb_chan->reg->statusmask); +} + +static int mb_chan_status_ack (struct slimpro_mbox_chan *mb_chan) +{ +u32 val =readl (&mb_chan->reg->status); + +if (val &MBOX_STATUS_ACK_MASK ) { +writel (MBOX_STATUS_ACK_MASK , &mb_chan->reg->status); +return 1 ; + } +return 0 ; +} + +static int mb_chan_status_avail (struct slimpro_mbox_chan *mb_chan) +{ +u32 val =readl (&mb_chan->reg->status); + +if (val &MBOX_STATUS_AVAIL_MASK ) { +mb_chan_recv_msg (mb_chan); +writel (MBOX_STATUS_AVAIL_MASK , &mb_chan->reg->status); +return 1 ; + } +return 0 ; +} + +static irqreturn_t slimpro_mbox_irq (int irq,void *id) +{ +struct slimpro_mbox_chan *mb_chan = id;
Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c
Quoted 7 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +6
-0+ +if (mb_chan_status_ack (mb_chan)) +mbox_chan_txdone (mb_chan->chan,0 ); + +if (mb_chan_status_avail (mb_chan)) { +mb_chan_recv_msg (mb_chan)you already did this in
mb_chan_status_avail()is it needed?
removed
Quoted 19 lines
Quoted 19 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +18
-0+mbox_chan_received_data (mb_chan->chan, mb_chan->rx_msg); + } + +return IRQ_HANDLED ; +} + +static int slimpro_mbox_send_data (struct mbox_chan *chan,void *msg) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); + +mb_chan_send_msg (mb_chan, msg); +return 0 ; +} + +static int slimpro_mbox_startup (struct mbox_chan *chan) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); +int rc;
Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c line 158
Quoted 4 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +3
-0+ + rc =devm_request_irq (mb_chan->dev, mb_chan->irq, slimpro_mbox_irq,0 , +MBOX_CON_NAME , mb_chan);You may want to use
IRQF_SHAREDflag here and makeslimpro_mbox_irq()aware of that -- some platforms tie together irq lines of all instances of a resource, like dma, mbox, so they may share the same irq line.
this is an internal dedicated irq line.
Quoted 39 lines
Quoted 26 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +23
-0+static int __init slimpro_mbox_probe (struct platform_device *pdev) +{ +struct slimpro_mbox *ctx; +struct resource *regs; +void __iomem *mb_base; +int rc; +int i; + + ctx =devm_kzalloc (&pdev->dev,sizeof (struct slimpro_mbox ),GFP_KERNEL ); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + +platform_set_drvdata (pdev, ctx); + + regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + mb_base =devm_ioremap_resource (&pdev->dev, regs); +if (IS_ERR (mb_base)) +return PTR_ERR (mb_base); + +/* Setup mailbox links */ +for (i =0 ; i <MBOX_CNT ; i++) { + ctx->mc[i].irq =platform_get_irq (pdev, i); +if (ctx->mc[i].irq <0 ) {drivers/mailbox/mailbox-xgene-slimpro.c line 220
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+dev_err (&pdev->dev,"no IRQ at index %d\n" , + ctx->mc[i].irq); +return -ENODEV ; + } + + ctx->mc[i].dev = &pdev->dev; + ctx->mc[i].reg = mb_base + i *MBOX_REG_SET_OFFSET ; + ctx->mc[i].id = i; + ctx->mc[i].chan = &ctx->chans[i]; + ctx->chans[i].con_priv = &ctx->mc[i];Note to self: Maybe we should make it possible to populate a channel during request/of_xlate.
Quoted 12 lines
drivers/mailbox/mailbox-xgene-slimpro.c line 286
Quoted 12 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +12
-0+ +static int __init slimpro_mbox_init (void ) +{ +return platform_driver_register (&slimpro_mbox_driver); +} + +static void __exit slimpro_mbox_exit(void) +{ +} + +subsys_initcall (slimpro_mbox_init); +module_exit (slimpro_mbox_exit);
will remove
Quoted 3 lines
Why empty
module_exit?regards.
Quoted 17 lines · Feng Kan
Quoted 16 lines · Jassi Brar
Quoted 5 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +4
-0+/* Configuration and Status Registers */ +struct slimpro_mbox_reg { +u32 in; +u32 din0;drivers/mailbox/mailbox-xgene-slimpro.c line 50
Quoted 10 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +10
-0+u32 din1; +u32 rsvd1; +u32 out; +u32 dout0; +u32 dout1; +u32 rsvd2; +u32 status; +u32 statusmask; +}; +Why not the normal way of defining offset macros, like most drivers do?
Quoted 3 lines
I personally don't prefer one way over another, let me know if you want me to change to use defines.
Yes please.
Quoted 27 lines
Quoted 19 lines
Quoted 19 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +18
-0+mbox_chan_received_data (mb_chan->chan, mb_chan->rx_msg); + } + +return IRQ_HANDLED ; +} + +static int slimpro_mbox_send_data (struct mbox_chan *chan,void *msg) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); + +mb_chan_send_msg (mb_chan, msg); +return 0 ; +} + +static int slimpro_mbox_startup (struct mbox_chan *chan) +{ +struct slimpro_mbox_chan *mb_chan =to_slimpro_mbox_chan (chan); +int rc;Quoted 8 lines
drivers/mailbox/mailbox-xgene-slimpro.c line 158
Quoted 4 lines
drivers/mailbox/mailbox-xgene-slimpro.c new file +3
-0+ + rc =devm_request_irq (mb_chan->dev, mb_chan->irq, slimpro_mbox_irq,0 , +MBOX_CON_NAME , mb_chan);You may want to use
IRQF_SHAREDflag here and makeslimpro_mbox_irq()aware of that -- some platforms tie together irq lines of all instances of a resource, like dma, mbox, so they may share the same irq line.
Quoted 2 lines
this is an internal dedicated irq line.
Yes on this platform/soc it is. But some future platform that uses the same mbox controller might choose to tie all irqs together at the cost of slightly increased latency. However I am OK if you are. So as you wish for now.