-
Notifications
You must be signed in to change notification settings - Fork 5
/
rpmsg_init_neo.c
174 lines (127 loc) · 3.98 KB
/
rpmsg_init_neo.c
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rpmsg.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <linux/fs.h>
#include <linux/kfifo.h>
#include <linux/uaccess.h>
#include <linux/kthread.h>
#include <linux/ioctl.h>
#include <linux/errno.h>
#include <linux/poll.h>
#include "rpmsg_neo.h"
#define RPMSG_MAX_SIZE (512 - sizeof(struct rpmsg_hdr))
#define MSG "hello world!"
struct _rpmsg_dev_params
{
struct device *rpmsg_dev;
struct rpmsg_channel *rpmsg_chnl;
char tx_buff[RPMSG_MAX_SIZE];
rpmsg_neo_remove_t remove_proxy;
rpmsg_neo_remove_t remove_tty;
rpmsg_neo_remove_t remove_ethernet;
};
static void rpmsg_proxy_dev_rpmsg_drv_cb(struct rpmsg_channel *rpdev, void *data,
int len, void *priv, u32 src)
{
pr_err("ERROR: %s %d\n", __FUNCTION__, __LINE__);
}
static int rpmsg_proxy_dev_rpmsg_drv_probe(struct rpmsg_channel *rpdev);
static void rpmsg_proxy_dev_rpmsg_drv_remove(struct rpmsg_channel *rpdev);
static struct rpmsg_device_id rpmsg_proxy_dev_drv_id_table[] =
{
{ .name = "rpmsg-openamp-demo-channel" },
{},
};
static struct rpmsg_driver rpmsg_proxy_dev_drv =
{
.drv.name = "rpmsg_proxy_dev_rpmsg",
.drv.owner = THIS_MODULE,
.id_table = rpmsg_proxy_dev_drv_id_table,
.probe = rpmsg_proxy_dev_rpmsg_drv_probe,
.remove = rpmsg_proxy_dev_rpmsg_drv_remove,
.callback = rpmsg_proxy_dev_rpmsg_drv_cb,
};
static int rpmsg_proxy_dev_rpmsg_drv_probe(struct rpmsg_channel *rpdev)
{
struct _rpmsg_dev_params *local;
int err=0;
pr_info("%s %d\n", __FUNCTION__, __LINE__);
local = devm_kzalloc(&rpdev->dev, sizeof(struct _rpmsg_dev_params),
GFP_KERNEL);
if (!local)
{
dev_err(&rpdev->dev, "Failed to allocate memory for rpmsg user dev.\n");
return -ENOMEM;
}
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, MSG, strlen(MSG));
if (err)
{
dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err);
goto error2;
}
memset(local, 0x0, sizeof(struct _rpmsg_dev_params));
local->rpmsg_chnl = rpdev;
dev_set_drvdata(&rpdev->dev, local);
pr_info("INFO: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
if ( rpmsg_neo_proxy(local->rpmsg_chnl, &local->remove_proxy) || local->remove_proxy==NULL)
{
dev_err(&rpdev->dev, "Failed: rpmsg_neo_proxy\n");
goto error2;
}
pr_info(" %s %d\n", __FUNCTION__, __LINE__);
if ( rpmsg_neo_tty(local->rpmsg_chnl, &local->remove_tty) || local->remove_tty==NULL)
{
dev_err(&rpdev->dev, "Failed: rpmsg_neo_tty\n");
if(local->remove_proxy)
local->remove_proxy();
goto error2;
}
if ( rpmsg_neo_ethernet(local->rpmsg_chnl, &local->remove_ethernet) || local->remove_ethernet==NULL)
{
dev_err(&rpdev->dev, "Failed: rpmsg_neo_ethernet\n");
if(local->remove_proxy)
local->remove_proxy();
if(local->remove_tty)
local->remove_tty();
goto error2;
}
goto out;
error2:
return -ENODEV;
out:
return 0;
}
static void rpmsg_proxy_dev_rpmsg_drv_remove(struct rpmsg_channel *rpdev)
{
struct _rpmsg_device *local = dev_get_drvdata(&rpdev->dev);
local;
}
static int __init rpmsg_init(void)
{
int err = 0;
if ( (err = register_rpmsg_driver(&rpmsg_proxy_dev_drv)) != 0)
{
pr_err("ERROR: %s %d rc=%d\n", __FUNCTION__, __LINE__,err);
}
return err;
}
static void __exit rpmsg_exit(void)
{
unregister_rpmsg_driver(&rpmsg_proxy_dev_drv);
}
module_init(rpmsg_init);
module_exit(rpmsg_exit);
MODULE_AUTHOR("Tim Michals <tcmichals@gmail.com>");
MODULE_DESCRIPTION("rpmsg proxy user access driver");
MODULE_LICENSE("GPL v2");