Skip to content

Commit

Permalink
feat(ipc_interrupt): enable ipc delivery via interrupt in Linux
Browse files Browse the repository at this point in the history
- modify the irq number in Linux dts files to reflect the 32 offset
- implement and register ipc_message_handler to receive ipc notification
  in bao-ipcshmem driver
- call bao_ipcshmem_notify in uart_rx_handler in Zephyr
- modify irq number in all linux guest for ARM

On success, a message like below will appear in dmesg:

[   12.881296] ipc message: freertos has received 1 uart interrupts!

Tested:
- qemu-aarch64-virt
  - linux+freertos
  - linux+zephyr
- qemu-riscv-virt (by @josecm)
  - linux+freertos
- rpi4
  - linux+freertos

Signed-off-by: Clay Chang <[email protected]>
  • Loading branch information
clachan committed Jul 24, 2023
1 parent e6f1f6f commit 1e50dd6
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 19 deletions.
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/fvp-a-aarch32/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/fvp-a/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/fvp-r/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
reg = <0x0 0x70000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/imx8qm/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
interrupt-parent = <&gic>;
id = <0>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupt-parent = <&plic>;
interrupts = <52>;
interrupts = <20>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/rpi4/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
4 changes: 2 additions & 2 deletions demos/linux+freertos/devicetrees/tx2/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand All @@ -195,4 +195,4 @@
bootargs = "clk_ignore_unused ip=192.168.42.15 carrier_timeout=0";
};

};
};
2 changes: 1 addition & 1 deletion demos/linux+freertos/devicetrees/zcu104/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/fvp-a-aarch32/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/fvp-a/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/fvp-r/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
reg = <0x0 0x70000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/imx8qm/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
interrupt-parent = <&gic>;
id = <0>;
};
Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/qemu-aarch64-virt/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/rpi4/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
4 changes: 2 additions & 2 deletions demos/linux+zephyr/devicetrees/tx2/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand All @@ -195,4 +195,4 @@
bootargs = "clk_ignore_unused ip=192.168.42.15 carrier_timeout=0";
};

};
};
2 changes: 1 addition & 1 deletion demos/linux+zephyr/devicetrees/zcu104/linux.dts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
reg = <0x0 0xf0000000 0x0 0x00010000>;
read-channel = <0x0 0x2000>;
write-channel = <0x2000 0x2000>;
interrupts = <0 52 1>;
interrupts = <0 20 1>;
id = <0>;
};

Expand Down
1 change: 1 addition & 0 deletions demos/linux+zephyr/zephyr/app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void uart_rx_handler() {
snprintf(msg, MSG_SIZE,
"zephyr has received %ld uart interrupts!\n", irq_count);
bao_ipcshmem_write(shmem, msg, strnlen(msg, MSG_SIZE)+1);
bao_ipcshmem_notify(shmem);
}

void shmem_irq_handler(const struct device *dev) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From be0d07b654e3e1011e87df84709155683120acd3 Mon Sep 17 00:00:00 2001
From: Clay Chang <[email protected]>
Date: Mon, 17 Jul 2023 18:49:55 +0800
Subject: [PATCH 3/3] bao-ipcshmem: receive ipc message from ipc interrupt

---
drivers/bao/bao-ipcshmem.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/drivers/bao/bao-ipcshmem.c b/drivers/bao/bao-ipcshmem.c
index e9cc304ea..9af4f6e37 100644
--- a/drivers/bao/bao-ipcshmem.c
+++ b/drivers/bao/bao-ipcshmem.c
@@ -181,6 +181,15 @@ static struct file_operations bao_ipcshmem_fops = {
.release = bao_ipcshmem_release_fops
};

+static irqreturn_t ipc_message_handler(int irq, void *data)
+{
+ struct bao_ipcshmem *bao = (struct bao_ipcshmem *)data;
+
+ pr_info("ipc message: %s", (char *)bao->read_base);
+
+ return IRQ_HANDLED;
+}
+
int bao_ipcshmem_register(struct platform_device *pdev)
{
int ret = 0;
@@ -194,6 +203,7 @@ int bao_ipcshmem_register(struct platform_device *pdev)
bool rd_in_range, wr_in_range, disjoint;
void* shmem_base_addr = NULL;
int id = -1;
+ unsigned int irq;
struct bao_ipcshmem *bao;

r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -241,6 +251,13 @@ int bao_ipcshmem_register(struct platform_device *pdev)
bao->write_base = shmem_base_addr + write_offset;
bao->physical_base = (void *)r->start;

+ irq = platform_get_irq(pdev, 0);
+ ret = devm_request_irq(&pdev->dev, irq, ipc_message_handler, IRQF_TRIGGER_RISING, bao->label, (void *)bao);
+ if (ret != 0) {
+ pr_err("failed to request irq: ret=%d\n", ret);
+ goto err_unmap;
+ }
+
cdev_init(&bao->cdev, &bao_ipcshmem_fops);
bao->cdev.owner = owner;

@@ -322,4 +339,5 @@ module_exit(bao_ipcshmem_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Cerdeira");
MODULE_AUTHOR("José Martins");
+MODULE_AUTHOR("Clay Chang");
MODULE_DESCRIPTION("bao ipc through shared-memory sample driver");
--
2.34.1

0 comments on commit 1e50dd6

Please sign in to comment.