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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
*/
#include <linux/of.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/platform_device.h>
#include <soc/qcom/subsystem_notif.h>
#include <linux/rpmsg/qcom_glink.h>
#include <linux/rpmsg.h>
#include <linux/ipc_logging.h>
#define GLINK_PROBE_LOG_PAGE_CNT 4
static void *glink_ilc;
#define GLINK_INFO(x, ...) ipc_log_string(glink_ilc, x, ##__VA_ARGS__)
#define GLINK_ERR(dev, x, ...) \
do { \
dev_err(dev, "[%s]: "x, __func__, ##__VA_ARGS__); \
ipc_log_string(glink_ilc, "[%s]: "x, __func__, ##__VA_ARGS__); \
} while (0)
struct edge_info {
struct list_head list;
struct device *dev;
struct device_node *node;
const char *glink_label;
const char *ssr_label;
void *glink;
int (*register_fn)(struct edge_info *einfo);
void (*unregister_fn)(struct edge_info *einfo);
struct notifier_block nb;
void *notifier_handle;
};
static LIST_HEAD(edge_infos);
static int glink_probe_ssr_cb(struct notifier_block *this,
unsigned long code, void *data)
{
struct edge_info *einfo = container_of(this, struct edge_info, nb);
GLINK_INFO("received %ld for %s\n", code, einfo->ssr_label);
switch (code) {
case SUBSYS_AFTER_POWERUP:
einfo->register_fn(einfo);
break;
case SUBSYS_AFTER_SHUTDOWN:
einfo->unregister_fn(einfo);
break;
default:
break;
}
return NOTIFY_DONE;
}
static int glink_probe_smem_reg(struct edge_info *einfo)
{
struct device *dev = einfo->dev;
einfo->glink = qcom_glink_smem_register(dev, einfo->node);
if (IS_ERR_OR_NULL(einfo->glink)) {
GLINK_ERR(dev, "register failed for %s\n", einfo->ssr_label);
einfo->glink = NULL;
}
GLINK_INFO("register successful for %s\n", einfo->ssr_label);
return 0;
}
static void glink_probe_smem_unreg(struct edge_info *einfo)
{
if (einfo->glink)
qcom_glink_smem_unregister(einfo->glink);
einfo->glink = NULL;
GLINK_INFO("unregister for %s\n", einfo->ssr_label);
}
static int glink_probe_spss_reg(struct edge_info *einfo)
{
struct device *dev = einfo->dev;
einfo->glink = qcom_glink_spss_register(dev, einfo->node);
if (IS_ERR_OR_NULL(einfo->glink)) {
GLINK_ERR(dev, "register failed for %s\n", einfo->ssr_label);
einfo->glink = NULL;
}
return 0;
}
static void glink_probe_spss_unreg(struct edge_info *einfo)
{
if (einfo->glink)
qcom_glink_spss_unregister(einfo->glink);
einfo->glink = NULL;
}
static void probe_subsystem(struct device *dev, struct device_node *np)
{
struct edge_info *einfo;
const char *transport;
int ret;
void *handle;
einfo = devm_kzalloc(dev, sizeof(*einfo), GFP_KERNEL);
if (!einfo)
return;
ret = of_property_read_string(np, "label", &einfo->ssr_label);
if (ret < 0)
einfo->ssr_label = np->name;
ret = of_property_read_string(np, "qcom,glink-label",
&einfo->glink_label);
if (ret < 0) {
GLINK_ERR(dev, "no qcom,glink-label for %s\n",
einfo->ssr_label);
goto free_einfo;
}
einfo->dev = dev;
einfo->node = np;
ret = of_property_read_string(np, "transport", &transport);
if (ret < 0) {
GLINK_ERR(dev, "%s missing transport\n", einfo->ssr_label);
goto free_einfo;
}
if (!strcmp(transport, "smem")) {
einfo->register_fn = glink_probe_smem_reg;
einfo->unregister_fn = glink_probe_smem_unreg;
} else if (!strcmp(transport, "spss")) {
einfo->register_fn = glink_probe_spss_reg;
einfo->unregister_fn = glink_probe_spss_unreg;
}
einfo->nb.notifier_call = glink_probe_ssr_cb;
handle = subsys_notif_register_notifier(einfo->ssr_label, &einfo->nb);
if (IS_ERR_OR_NULL(handle)) {
GLINK_ERR(dev, "could not register for SSR notifier for %s\n",
einfo->ssr_label);
goto free_einfo;
}
einfo->notifier_handle = handle;
list_add_tail(&einfo->list, &edge_infos);
GLINK_INFO("probe successful for %s\n", einfo->ssr_label);
return;
free_einfo:
devm_kfree(dev, einfo);
}
static int glink_probe(struct platform_device *pdev)
{
struct device_node *pn = pdev->dev.of_node;
struct device_node *cn;
for_each_available_child_of_node(pn, cn) {
probe_subsystem(&pdev->dev, cn);
}
return 0;
}
static int glink_remove(struct platform_device *pdev)
{
struct device_node *pn = pdev->dev.of_node;
struct device_node *cn;
struct edge_info *einfo, *tmp;
for_each_available_child_of_node(pn, cn) {
list_for_each_entry_safe(einfo, tmp, &edge_infos, list) {
subsys_notif_unregister_notifier(einfo->notifier_handle,
&einfo->nb);
list_del(&einfo->list);
}
}
return 0;
}
static const struct of_device_id glink_match_table[] = {
{ .compatible = "qcom,glink" },
{},
};
static struct platform_driver glink_probe_driver = {
.probe = glink_probe,
.remove = glink_remove,
.driver = {
.name = "msm_glink",
.of_match_table = glink_match_table,
},
};
static int __init glink_probe_init(void)
{
int ret;
glink_ilc = ipc_log_context_create(GLINK_PROBE_LOG_PAGE_CNT,
"glink_probe", 0);
ret = platform_driver_register(&glink_probe_driver);
if (ret) {
pr_err("%s: glink_probe register failed %d\n",
__func__, ret);
return ret;
}
return 0;
}
arch_initcall(glink_probe_init);
static void __exit glink_probe_exit(void)
{
if (glink_ilc)
ipc_log_context_destroy(glink_ilc);
platform_driver_unregister(&glink_probe_driver);
}
module_exit(glink_probe_exit);
MODULE_DESCRIPTION("Qualcomm Technologies, Inc. GLINK probe helper driver");
MODULE_LICENSE("GPL v2");
|