Skip to content

Commit c793c36

Browse files
committed
feat(ipc_interrupt): enable ipc delivery via interrupt in Linux
- 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 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 <clay.chang@gmail.com>
1 parent e6f1f6f commit c793c36

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

demos/linux+freertos/devicetrees/qemu-aarch64-virt/linux.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
reg = <0x0 0xf0000000 0x0 0x00010000>;
121121
read-channel = <0x0 0x2000>;
122122
write-channel = <0x2000 0x2000>;
123-
interrupts = <0 52 1>;
123+
interrupts = <0 20 1>;
124124
id = <0>;
125125
};
126126

demos/linux+freertos/devicetrees/qemu-riscv64-virt/linux.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
read-channel = <0x0 0x2000>;
136136
write-channel = <0x2000 0x2000>;
137137
interrupt-parent = <&plic>;
138-
interrupts = <52>;
138+
interrupts = <20>;
139139
id = <0>;
140140
};
141141

demos/linux+freertos/devicetrees/rpi4/linux.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
reg = <0x0 0xf0000000 0x0 0x00010000>;
109109
read-channel = <0x0 0x2000>;
110110
write-channel = <0x2000 0x2000>;
111-
interrupts = <0 52 1>;
111+
interrupts = <0 20 1>;
112112
id = <0>;
113113
};
114114

demos/linux+zephyr/devicetrees/qemu-aarch64-virt/linux.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
reg = <0x0 0xf0000000 0x0 0x00010000>;
115115
read-channel = <0x0 0x2000>;
116116
write-channel = <0x2000 0x2000>;
117-
interrupts = <0 52 1>;
117+
interrupts = <0 20 1>;
118118
id = <0>;
119119
};
120120

demos/linux+zephyr/devicetrees/rpi4/linux.dts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
reg = <0x0 0xf0000000 0x0 0x00010000>;
109109
read-channel = <0x0 0x2000>;
110110
write-channel = <0x2000 0x2000>;
111-
interrupts = <0 52 1>;
111+
interrupts = <0 20 1>;
112112
id = <0>;
113113
};
114114

demos/linux+zephyr/zephyr/app/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void uart_rx_handler() {
4141
snprintf(msg, MSG_SIZE,
4242
"zephyr has received %ld uart interrupts!\n", irq_count);
4343
bao_ipcshmem_write(shmem, msg, strnlen(msg, MSG_SIZE)+1);
44+
bao_ipcshmem_notify(shmem);
4445
}
4546

4647
void shmem_irq_handler(const struct device *dev) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From be0d07b654e3e1011e87df84709155683120acd3 Mon Sep 17 00:00:00 2001
2+
From: Clay Chang <clay.chang@gmail.com>
3+
Date: Mon, 17 Jul 2023 18:49:55 +0800
4+
Subject: [PATCH 3/3] bao-ipcshmem: receive ipc message from ipc interrupt
5+
6+
---
7+
drivers/bao/bao-ipcshmem.c | 18 ++++++++++++++++++
8+
1 file changed, 18 insertions(+)
9+
10+
diff --git a/drivers/bao/bao-ipcshmem.c b/drivers/bao/bao-ipcshmem.c
11+
index e9cc304ea..9af4f6e37 100644
12+
--- a/drivers/bao/bao-ipcshmem.c
13+
+++ b/drivers/bao/bao-ipcshmem.c
14+
@@ -181,6 +181,15 @@ static struct file_operations bao_ipcshmem_fops = {
15+
.release = bao_ipcshmem_release_fops
16+
};
17+
18+
+static irqreturn_t ipc_message_handler(int irq, void *data)
19+
+{
20+
+ struct bao_ipcshmem *bao = (struct bao_ipcshmem *)data;
21+
+
22+
+ pr_info("ipc message: %s", (char *)bao->read_base);
23+
+
24+
+ return IRQ_HANDLED;
25+
+}
26+
+
27+
int bao_ipcshmem_register(struct platform_device *pdev)
28+
{
29+
int ret = 0;
30+
@@ -194,6 +203,7 @@ int bao_ipcshmem_register(struct platform_device *pdev)
31+
bool rd_in_range, wr_in_range, disjoint;
32+
void* shmem_base_addr = NULL;
33+
int id = -1;
34+
+ unsigned int irq;
35+
struct bao_ipcshmem *bao;
36+
37+
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
38+
@@ -241,6 +251,13 @@ int bao_ipcshmem_register(struct platform_device *pdev)
39+
bao->write_base = shmem_base_addr + write_offset;
40+
bao->physical_base = (void *)r->start;
41+
42+
+ irq = platform_get_irq(pdev, 0);
43+
+ ret = devm_request_irq(&pdev->dev, irq, ipc_message_handler, IRQF_TRIGGER_RISING, bao->label, (void *)bao);
44+
+ if (ret != 0) {
45+
+ pr_err("failed to request irq: ret=%d\n", ret);
46+
+ goto err_unmap;
47+
+ }
48+
+
49+
cdev_init(&bao->cdev, &bao_ipcshmem_fops);
50+
bao->cdev.owner = owner;
51+
52+
@@ -322,4 +339,5 @@ module_exit(bao_ipcshmem_exit);
53+
MODULE_LICENSE("GPL");
54+
MODULE_AUTHOR("David Cerdeira");
55+
MODULE_AUTHOR("José Martins");
56+
+MODULE_AUTHOR("Clay Chang");
57+
MODULE_DESCRIPTION("bao ipc through shared-memory sample driver");
58+
--
59+
2.34.1
60+

0 commit comments

Comments
 (0)