1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (C) 2015 Freescale Semiconductor, Inc.
*
* derived from the omap-rpmsg implementation.
* Remote processor messaging transport - pingpong driver
*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/virtio.h>
#include <linux/rpmsg.h>
#define MSG "hello world!"
#define MSG_LIMIT 100000
static unsigned int rpmsg_pingpong;
static int rx_count;
static int rpmsg_pingpong_cb(struct rpmsg_device *rpdev, void *data, int len,
void *priv, u32 src)
{
int err;
/* reply */
rpmsg_pingpong = *(unsigned int *)data;
pr_info("get %d (src: 0x%x)\n",
rpmsg_pingpong, src);
rx_count++;
/* pingpongs should not live forever */
if (rx_count >= MSG_LIMIT) {
dev_info(&rpdev->dev, "goodbye!\n");
return 0;
}
rpmsg_pingpong++;
err = rpmsg_sendto(rpdev->ept, (void *)(&rpmsg_pingpong), 4, src);
if (err)
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err);
return err;
}
static int rpmsg_pingpong_probe(struct rpmsg_device *rpdev)
{
int err;
dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
rpdev->src, rpdev->dst);
/*
* send a message to our remote processor, and tell remote
* processor about this channel
*/
err = rpmsg_send(rpdev->ept, MSG, strlen(MSG));
if (err) {
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err);
return err;
}
rpmsg_pingpong = 0;
rx_count = 0;
err = rpmsg_sendto(rpdev->ept, (void *)(&rpmsg_pingpong), 4, rpdev->dst);
if (err) {
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err);
return err;
}
return 0;
}
static void rpmsg_pingpong_remove(struct rpmsg_device *rpdev)
{
dev_info(&rpdev->dev, "rpmsg pingpong driver is removed\n");
}
static struct rpmsg_device_id rpmsg_driver_pingpong_id_table[] = {
{ .name = "rpmsg-openamp-demo-channel" },
{ },
};
MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_pingpong_id_table);
static struct rpmsg_driver rpmsg_pingpong_driver = {
.drv.name = KBUILD_MODNAME,
.drv.owner = THIS_MODULE,
.id_table = rpmsg_driver_pingpong_id_table,
.probe = rpmsg_pingpong_probe,
.callback = rpmsg_pingpong_cb,
.remove = rpmsg_pingpong_remove,
};
static int __init init(void)
{
return register_rpmsg_driver(&rpmsg_pingpong_driver);
}
static void __exit fini(void)
{
unregister_rpmsg_driver(&rpmsg_pingpong_driver);
}
module_init(init);
module_exit(fini);
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("iMX virtio remote processor messaging pingpong driver");
MODULE_LICENSE("GPL v2");
|