.. | .. |
---|
5 | 5 | * Copyright (C) 2018 ARM Ltd. |
---|
6 | 6 | */ |
---|
7 | 7 | |
---|
| 8 | +#define pr_fmt(fmt) "SCMI Notifications BASE - " fmt |
---|
| 9 | + |
---|
| 10 | +#include <linux/module.h> |
---|
| 11 | +#include <linux/scmi_protocol.h> |
---|
| 12 | + |
---|
8 | 13 | #include "common.h" |
---|
| 14 | +#include "notify.h" |
---|
| 15 | + |
---|
| 16 | +#define SCMI_BASE_NUM_SOURCES 1 |
---|
| 17 | +#define SCMI_BASE_MAX_CMD_ERR_COUNT 1024 |
---|
9 | 18 | |
---|
10 | 19 | enum scmi_base_protocol_cmd { |
---|
11 | 20 | BASE_DISCOVER_VENDOR = 0x3, |
---|
.. | .. |
---|
14 | 23 | BASE_DISCOVER_LIST_PROTOCOLS = 0x6, |
---|
15 | 24 | BASE_DISCOVER_AGENT = 0x7, |
---|
16 | 25 | BASE_NOTIFY_ERRORS = 0x8, |
---|
| 26 | + BASE_SET_DEVICE_PERMISSIONS = 0x9, |
---|
| 27 | + BASE_SET_PROTOCOL_PERMISSIONS = 0xa, |
---|
| 28 | + BASE_RESET_AGENT_CONFIGURATION = 0xb, |
---|
17 | 29 | }; |
---|
18 | 30 | |
---|
19 | 31 | struct scmi_msg_resp_base_attributes { |
---|
.. | .. |
---|
22 | 34 | __le16 reserved; |
---|
23 | 35 | }; |
---|
24 | 36 | |
---|
| 37 | +struct scmi_msg_base_error_notify { |
---|
| 38 | + __le32 event_control; |
---|
| 39 | +#define BASE_TP_NOTIFY_ALL BIT(0) |
---|
| 40 | +}; |
---|
| 41 | + |
---|
| 42 | +struct scmi_base_error_notify_payld { |
---|
| 43 | + __le32 agent_id; |
---|
| 44 | + __le32 error_status; |
---|
| 45 | +#define IS_FATAL_ERROR(x) ((x) & BIT(31)) |
---|
| 46 | +#define ERROR_CMD_COUNT(x) FIELD_GET(GENMASK(9, 0), (x)) |
---|
| 47 | + __le64 msg_reports[SCMI_BASE_MAX_CMD_ERR_COUNT]; |
---|
| 48 | +}; |
---|
| 49 | + |
---|
25 | 50 | /** |
---|
26 | 51 | * scmi_base_attributes_get() - gets the implementation details |
---|
27 | 52 | * that are associated with the base protocol. |
---|
28 | 53 | * |
---|
29 | | - * @handle: SCMI entity handle |
---|
| 54 | + * @ph: SCMI protocol handle |
---|
30 | 55 | * |
---|
31 | 56 | * Return: 0 on success, else appropriate SCMI error. |
---|
32 | 57 | */ |
---|
33 | | -static int scmi_base_attributes_get(const struct scmi_handle *handle) |
---|
| 58 | +static int scmi_base_attributes_get(const struct scmi_protocol_handle *ph) |
---|
34 | 59 | { |
---|
35 | 60 | int ret; |
---|
36 | 61 | struct scmi_xfer *t; |
---|
37 | 62 | struct scmi_msg_resp_base_attributes *attr_info; |
---|
38 | | - struct scmi_revision_info *rev = handle->version; |
---|
| 63 | + struct scmi_revision_info *rev = ph->get_priv(ph); |
---|
39 | 64 | |
---|
40 | | - ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES, |
---|
41 | | - SCMI_PROTOCOL_BASE, 0, sizeof(*attr_info), &t); |
---|
| 65 | + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, |
---|
| 66 | + 0, sizeof(*attr_info), &t); |
---|
42 | 67 | if (ret) |
---|
43 | 68 | return ret; |
---|
44 | 69 | |
---|
45 | | - ret = scmi_do_xfer(handle, t); |
---|
| 70 | + ret = ph->xops->do_xfer(ph, t); |
---|
46 | 71 | if (!ret) { |
---|
47 | 72 | attr_info = t->rx.buf; |
---|
48 | 73 | rev->num_protocols = attr_info->num_protocols; |
---|
49 | 74 | rev->num_agents = attr_info->num_agents; |
---|
50 | 75 | } |
---|
51 | 76 | |
---|
52 | | - scmi_xfer_put(handle, t); |
---|
| 77 | + ph->xops->xfer_put(ph, t); |
---|
53 | 78 | |
---|
54 | 79 | return ret; |
---|
55 | 80 | } |
---|
.. | .. |
---|
57 | 82 | /** |
---|
58 | 83 | * scmi_base_vendor_id_get() - gets vendor/subvendor identifier ASCII string. |
---|
59 | 84 | * |
---|
60 | | - * @handle: SCMI entity handle |
---|
| 85 | + * @ph: SCMI protocol handle |
---|
61 | 86 | * @sub_vendor: specify true if sub-vendor ID is needed |
---|
62 | 87 | * |
---|
63 | 88 | * Return: 0 on success, else appropriate SCMI error. |
---|
64 | 89 | */ |
---|
65 | 90 | static int |
---|
66 | | -scmi_base_vendor_id_get(const struct scmi_handle *handle, bool sub_vendor) |
---|
| 91 | +scmi_base_vendor_id_get(const struct scmi_protocol_handle *ph, bool sub_vendor) |
---|
67 | 92 | { |
---|
68 | 93 | u8 cmd; |
---|
69 | 94 | int ret, size; |
---|
70 | 95 | char *vendor_id; |
---|
71 | 96 | struct scmi_xfer *t; |
---|
72 | | - struct scmi_revision_info *rev = handle->version; |
---|
| 97 | + struct scmi_revision_info *rev = ph->get_priv(ph); |
---|
| 98 | + |
---|
73 | 99 | |
---|
74 | 100 | if (sub_vendor) { |
---|
75 | 101 | cmd = BASE_DISCOVER_SUB_VENDOR; |
---|
.. | .. |
---|
81 | 107 | size = ARRAY_SIZE(rev->vendor_id); |
---|
82 | 108 | } |
---|
83 | 109 | |
---|
84 | | - ret = scmi_xfer_get_init(handle, cmd, SCMI_PROTOCOL_BASE, 0, size, &t); |
---|
| 110 | + ret = ph->xops->xfer_get_init(ph, cmd, 0, size, &t); |
---|
85 | 111 | if (ret) |
---|
86 | 112 | return ret; |
---|
87 | 113 | |
---|
88 | | - ret = scmi_do_xfer(handle, t); |
---|
| 114 | + ret = ph->xops->do_xfer(ph, t); |
---|
89 | 115 | if (!ret) |
---|
90 | 116 | memcpy(vendor_id, t->rx.buf, size); |
---|
91 | 117 | |
---|
92 | | - scmi_xfer_put(handle, t); |
---|
| 118 | + ph->xops->xfer_put(ph, t); |
---|
93 | 119 | |
---|
94 | 120 | return ret; |
---|
95 | 121 | } |
---|
.. | .. |
---|
99 | 125 | * implementation 32-bit version. The format of the version number is |
---|
100 | 126 | * vendor-specific |
---|
101 | 127 | * |
---|
102 | | - * @handle: SCMI entity handle |
---|
| 128 | + * @ph: SCMI protocol handle |
---|
103 | 129 | * |
---|
104 | 130 | * Return: 0 on success, else appropriate SCMI error. |
---|
105 | 131 | */ |
---|
106 | 132 | static int |
---|
107 | | -scmi_base_implementation_version_get(const struct scmi_handle *handle) |
---|
| 133 | +scmi_base_implementation_version_get(const struct scmi_protocol_handle *ph) |
---|
108 | 134 | { |
---|
109 | 135 | int ret; |
---|
110 | 136 | __le32 *impl_ver; |
---|
111 | 137 | struct scmi_xfer *t; |
---|
112 | | - struct scmi_revision_info *rev = handle->version; |
---|
| 138 | + struct scmi_revision_info *rev = ph->get_priv(ph); |
---|
113 | 139 | |
---|
114 | | - ret = scmi_xfer_get_init(handle, BASE_DISCOVER_IMPLEMENT_VERSION, |
---|
115 | | - SCMI_PROTOCOL_BASE, 0, sizeof(*impl_ver), &t); |
---|
| 140 | + ret = ph->xops->xfer_get_init(ph, BASE_DISCOVER_IMPLEMENT_VERSION, |
---|
| 141 | + 0, sizeof(*impl_ver), &t); |
---|
116 | 142 | if (ret) |
---|
117 | 143 | return ret; |
---|
118 | 144 | |
---|
119 | | - ret = scmi_do_xfer(handle, t); |
---|
| 145 | + ret = ph->xops->do_xfer(ph, t); |
---|
120 | 146 | if (!ret) { |
---|
121 | 147 | impl_ver = t->rx.buf; |
---|
122 | 148 | rev->impl_ver = le32_to_cpu(*impl_ver); |
---|
123 | 149 | } |
---|
124 | 150 | |
---|
125 | | - scmi_xfer_put(handle, t); |
---|
| 151 | + ph->xops->xfer_put(ph, t); |
---|
126 | 152 | |
---|
127 | 153 | return ret; |
---|
128 | 154 | } |
---|
.. | .. |
---|
131 | 157 | * scmi_base_implementation_list_get() - gets the list of protocols it is |
---|
132 | 158 | * OSPM is allowed to access |
---|
133 | 159 | * |
---|
134 | | - * @handle: SCMI entity handle |
---|
| 160 | + * @ph: SCMI protocol handle |
---|
135 | 161 | * @protocols_imp: pointer to hold the list of protocol identifiers |
---|
136 | 162 | * |
---|
137 | 163 | * Return: 0 on success, else appropriate SCMI error. |
---|
138 | 164 | */ |
---|
139 | | -static int scmi_base_implementation_list_get(const struct scmi_handle *handle, |
---|
140 | | - u8 *protocols_imp) |
---|
| 165 | +static int |
---|
| 166 | +scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph, |
---|
| 167 | + u8 *protocols_imp) |
---|
141 | 168 | { |
---|
142 | 169 | u8 *list; |
---|
143 | 170 | int ret, loop; |
---|
144 | 171 | struct scmi_xfer *t; |
---|
145 | 172 | __le32 *num_skip, *num_ret; |
---|
146 | 173 | u32 tot_num_ret = 0, loop_num_ret; |
---|
147 | | - struct device *dev = handle->dev; |
---|
| 174 | + struct device *dev = ph->dev; |
---|
148 | 175 | |
---|
149 | | - ret = scmi_xfer_get_init(handle, BASE_DISCOVER_LIST_PROTOCOLS, |
---|
150 | | - SCMI_PROTOCOL_BASE, sizeof(*num_skip), 0, &t); |
---|
| 176 | + ret = ph->xops->xfer_get_init(ph, BASE_DISCOVER_LIST_PROTOCOLS, |
---|
| 177 | + sizeof(*num_skip), 0, &t); |
---|
151 | 178 | if (ret) |
---|
152 | 179 | return ret; |
---|
153 | 180 | |
---|
.. | .. |
---|
159 | 186 | /* Set the number of protocols to be skipped/already read */ |
---|
160 | 187 | *num_skip = cpu_to_le32(tot_num_ret); |
---|
161 | 188 | |
---|
162 | | - ret = scmi_do_xfer(handle, t); |
---|
| 189 | + ret = ph->xops->do_xfer(ph, t); |
---|
163 | 190 | if (ret) |
---|
164 | 191 | break; |
---|
165 | 192 | |
---|
166 | 193 | loop_num_ret = le32_to_cpu(*num_ret); |
---|
167 | | - if (tot_num_ret + loop_num_ret > MAX_PROTOCOLS_IMP) { |
---|
| 194 | + if (loop_num_ret > MAX_PROTOCOLS_IMP - tot_num_ret) { |
---|
168 | 195 | dev_err(dev, "No. of Protocol > MAX_PROTOCOLS_IMP"); |
---|
169 | 196 | break; |
---|
170 | 197 | } |
---|
.. | .. |
---|
173 | 200 | protocols_imp[tot_num_ret + loop] = *(list + loop); |
---|
174 | 201 | |
---|
175 | 202 | tot_num_ret += loop_num_ret; |
---|
| 203 | + |
---|
| 204 | + ph->xops->reset_rx_to_maxsz(ph, t); |
---|
176 | 205 | } while (loop_num_ret); |
---|
177 | 206 | |
---|
178 | | - scmi_xfer_put(handle, t); |
---|
| 207 | + ph->xops->xfer_put(ph, t); |
---|
179 | 208 | |
---|
180 | 209 | return ret; |
---|
181 | 210 | } |
---|
.. | .. |
---|
183 | 212 | /** |
---|
184 | 213 | * scmi_base_discover_agent_get() - discover the name of an agent |
---|
185 | 214 | * |
---|
186 | | - * @handle: SCMI entity handle |
---|
| 215 | + * @ph: SCMI protocol handle |
---|
187 | 216 | * @id: Agent identifier |
---|
188 | 217 | * @name: Agent identifier ASCII string |
---|
189 | 218 | * |
---|
.. | .. |
---|
192 | 221 | * |
---|
193 | 222 | * Return: 0 on success, else appropriate SCMI error. |
---|
194 | 223 | */ |
---|
195 | | -static int scmi_base_discover_agent_get(const struct scmi_handle *handle, |
---|
| 224 | +static int scmi_base_discover_agent_get(const struct scmi_protocol_handle *ph, |
---|
196 | 225 | int id, char *name) |
---|
197 | 226 | { |
---|
198 | 227 | int ret; |
---|
199 | 228 | struct scmi_xfer *t; |
---|
200 | 229 | |
---|
201 | | - ret = scmi_xfer_get_init(handle, BASE_DISCOVER_AGENT, |
---|
202 | | - SCMI_PROTOCOL_BASE, sizeof(__le32), |
---|
203 | | - SCMI_MAX_STR_SIZE, &t); |
---|
| 230 | + ret = ph->xops->xfer_get_init(ph, BASE_DISCOVER_AGENT, |
---|
| 231 | + sizeof(__le32), SCMI_MAX_STR_SIZE, &t); |
---|
204 | 232 | if (ret) |
---|
205 | 233 | return ret; |
---|
206 | 234 | |
---|
207 | 235 | put_unaligned_le32(id, t->tx.buf); |
---|
208 | 236 | |
---|
209 | | - ret = scmi_do_xfer(handle, t); |
---|
| 237 | + ret = ph->xops->do_xfer(ph, t); |
---|
210 | 238 | if (!ret) |
---|
211 | 239 | strlcpy(name, t->rx.buf, SCMI_MAX_STR_SIZE); |
---|
212 | 240 | |
---|
213 | | - scmi_xfer_put(handle, t); |
---|
| 241 | + ph->xops->xfer_put(ph, t); |
---|
214 | 242 | |
---|
215 | 243 | return ret; |
---|
216 | 244 | } |
---|
217 | 245 | |
---|
218 | | -int scmi_base_protocol_init(struct scmi_handle *h) |
---|
| 246 | +static int scmi_base_error_notify(const struct scmi_protocol_handle *ph, |
---|
| 247 | + bool enable) |
---|
| 248 | +{ |
---|
| 249 | + int ret; |
---|
| 250 | + u32 evt_cntl = enable ? BASE_TP_NOTIFY_ALL : 0; |
---|
| 251 | + struct scmi_xfer *t; |
---|
| 252 | + struct scmi_msg_base_error_notify *cfg; |
---|
| 253 | + |
---|
| 254 | + ret = ph->xops->xfer_get_init(ph, BASE_NOTIFY_ERRORS, |
---|
| 255 | + sizeof(*cfg), 0, &t); |
---|
| 256 | + if (ret) |
---|
| 257 | + return ret; |
---|
| 258 | + |
---|
| 259 | + cfg = t->tx.buf; |
---|
| 260 | + cfg->event_control = cpu_to_le32(evt_cntl); |
---|
| 261 | + |
---|
| 262 | + ret = ph->xops->do_xfer(ph, t); |
---|
| 263 | + |
---|
| 264 | + ph->xops->xfer_put(ph, t); |
---|
| 265 | + return ret; |
---|
| 266 | +} |
---|
| 267 | + |
---|
| 268 | +static int scmi_base_set_notify_enabled(const struct scmi_protocol_handle *ph, |
---|
| 269 | + u8 evt_id, u32 src_id, bool enable) |
---|
| 270 | +{ |
---|
| 271 | + int ret; |
---|
| 272 | + |
---|
| 273 | + ret = scmi_base_error_notify(ph, enable); |
---|
| 274 | + if (ret) |
---|
| 275 | + pr_debug("FAIL_ENABLED - evt[%X] ret:%d\n", evt_id, ret); |
---|
| 276 | + |
---|
| 277 | + return ret; |
---|
| 278 | +} |
---|
| 279 | + |
---|
| 280 | +static void *scmi_base_fill_custom_report(const struct scmi_protocol_handle *ph, |
---|
| 281 | + u8 evt_id, ktime_t timestamp, |
---|
| 282 | + const void *payld, size_t payld_sz, |
---|
| 283 | + void *report, u32 *src_id) |
---|
| 284 | +{ |
---|
| 285 | + int i; |
---|
| 286 | + const struct scmi_base_error_notify_payld *p = payld; |
---|
| 287 | + struct scmi_base_error_report *r = report; |
---|
| 288 | + |
---|
| 289 | + /* |
---|
| 290 | + * BaseError notification payload is variable in size but |
---|
| 291 | + * up to a maximum length determined by the struct ponted by p. |
---|
| 292 | + * Instead payld_sz is the effective length of this notification |
---|
| 293 | + * payload so cannot be greater of the maximum allowed size as |
---|
| 294 | + * pointed by p. |
---|
| 295 | + */ |
---|
| 296 | + if (evt_id != SCMI_EVENT_BASE_ERROR_EVENT || sizeof(*p) < payld_sz) |
---|
| 297 | + return NULL; |
---|
| 298 | + |
---|
| 299 | + r->timestamp = timestamp; |
---|
| 300 | + r->agent_id = le32_to_cpu(p->agent_id); |
---|
| 301 | + r->fatal = IS_FATAL_ERROR(le32_to_cpu(p->error_status)); |
---|
| 302 | + r->cmd_count = ERROR_CMD_COUNT(le32_to_cpu(p->error_status)); |
---|
| 303 | + for (i = 0; i < r->cmd_count; i++) |
---|
| 304 | + r->reports[i] = le64_to_cpu(p->msg_reports[i]); |
---|
| 305 | + *src_id = 0; |
---|
| 306 | + |
---|
| 307 | + return r; |
---|
| 308 | +} |
---|
| 309 | + |
---|
| 310 | +static const struct scmi_event base_events[] = { |
---|
| 311 | + { |
---|
| 312 | + .id = SCMI_EVENT_BASE_ERROR_EVENT, |
---|
| 313 | + .max_payld_sz = sizeof(struct scmi_base_error_notify_payld), |
---|
| 314 | + .max_report_sz = sizeof(struct scmi_base_error_report) + |
---|
| 315 | + SCMI_BASE_MAX_CMD_ERR_COUNT * sizeof(u64), |
---|
| 316 | + }, |
---|
| 317 | +}; |
---|
| 318 | + |
---|
| 319 | +static const struct scmi_event_ops base_event_ops = { |
---|
| 320 | + .set_notify_enabled = scmi_base_set_notify_enabled, |
---|
| 321 | + .fill_custom_report = scmi_base_fill_custom_report, |
---|
| 322 | +}; |
---|
| 323 | + |
---|
| 324 | +static const struct scmi_protocol_events base_protocol_events = { |
---|
| 325 | + .queue_sz = 4 * SCMI_PROTO_QUEUE_SZ, |
---|
| 326 | + .ops = &base_event_ops, |
---|
| 327 | + .evts = base_events, |
---|
| 328 | + .num_events = ARRAY_SIZE(base_events), |
---|
| 329 | + .num_sources = SCMI_BASE_NUM_SOURCES, |
---|
| 330 | +}; |
---|
| 331 | + |
---|
| 332 | +static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph) |
---|
219 | 333 | { |
---|
220 | 334 | int id, ret; |
---|
221 | 335 | u8 *prot_imp; |
---|
222 | 336 | u32 version; |
---|
223 | 337 | char name[SCMI_MAX_STR_SIZE]; |
---|
224 | | - const struct scmi_handle *handle = h; |
---|
225 | | - struct device *dev = handle->dev; |
---|
226 | | - struct scmi_revision_info *rev = handle->version; |
---|
| 338 | + struct device *dev = ph->dev; |
---|
| 339 | + struct scmi_revision_info *rev = scmi_get_revision_area(ph); |
---|
227 | 340 | |
---|
228 | | - ret = scmi_version_get(handle, SCMI_PROTOCOL_BASE, &version); |
---|
| 341 | + ret = ph->xops->version_get(ph, &version); |
---|
229 | 342 | if (ret) |
---|
230 | 343 | return ret; |
---|
231 | 344 | |
---|
.. | .. |
---|
235 | 348 | |
---|
236 | 349 | rev->major_ver = PROTOCOL_REV_MAJOR(version), |
---|
237 | 350 | rev->minor_ver = PROTOCOL_REV_MINOR(version); |
---|
| 351 | + ph->set_priv(ph, rev); |
---|
238 | 352 | |
---|
239 | | - scmi_base_attributes_get(handle); |
---|
240 | | - scmi_base_vendor_id_get(handle, false); |
---|
241 | | - scmi_base_vendor_id_get(handle, true); |
---|
242 | | - scmi_base_implementation_version_get(handle); |
---|
243 | | - scmi_base_implementation_list_get(handle, prot_imp); |
---|
244 | | - scmi_setup_protocol_implemented(handle, prot_imp); |
---|
| 353 | + scmi_base_attributes_get(ph); |
---|
| 354 | + scmi_base_vendor_id_get(ph, false); |
---|
| 355 | + scmi_base_vendor_id_get(ph, true); |
---|
| 356 | + scmi_base_implementation_version_get(ph); |
---|
| 357 | + scmi_base_implementation_list_get(ph, prot_imp); |
---|
| 358 | + |
---|
| 359 | + scmi_setup_protocol_implemented(ph, prot_imp); |
---|
245 | 360 | |
---|
246 | 361 | dev_info(dev, "SCMI Protocol v%d.%d '%s:%s' Firmware version 0x%x\n", |
---|
247 | 362 | rev->major_ver, rev->minor_ver, rev->vendor_id, |
---|
.. | .. |
---|
250 | 365 | rev->num_agents); |
---|
251 | 366 | |
---|
252 | 367 | for (id = 0; id < rev->num_agents; id++) { |
---|
253 | | - scmi_base_discover_agent_get(handle, id, name); |
---|
| 368 | + scmi_base_discover_agent_get(ph, id, name); |
---|
254 | 369 | dev_dbg(dev, "Agent %d: %s\n", id, name); |
---|
255 | 370 | } |
---|
256 | 371 | |
---|
257 | 372 | return 0; |
---|
258 | 373 | } |
---|
| 374 | + |
---|
| 375 | +static const struct scmi_protocol scmi_base = { |
---|
| 376 | + .id = SCMI_PROTOCOL_BASE, |
---|
| 377 | + .owner = NULL, |
---|
| 378 | + .init_instance = &scmi_base_protocol_init, |
---|
| 379 | + .ops = NULL, |
---|
| 380 | + .events = &base_protocol_events, |
---|
| 381 | +}; |
---|
| 382 | + |
---|
| 383 | +DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(base, scmi_base) |
---|