xref: /openbmc/linux/drivers/soc/qcom/apr.c (revision 27e45f2e)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2018, Linaro Limited
4 
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/device.h>
8 #include <linux/spinlock.h>
9 #include <linux/idr.h>
10 #include <linux/slab.h>
11 #include <linux/workqueue.h>
12 #include <linux/of_device.h>
13 #include <linux/soc/qcom/apr.h>
14 #include <linux/soc/qcom/pdr.h>
15 #include <linux/rpmsg.h>
16 #include <linux/of.h>
17 
18 enum {
19 	PR_TYPE_APR = 0,
20 	PR_TYPE_GPR,
21 };
22 
23 /* Some random values tbh which does not collide with static modules */
24 #define GPR_DYNAMIC_PORT_START	0x10000000
25 #define GPR_DYNAMIC_PORT_END	0x20000000
26 
27 struct packet_router {
28 	struct rpmsg_endpoint *ch;
29 	struct device *dev;
30 	spinlock_t svcs_lock;
31 	spinlock_t rx_lock;
32 	struct idr svcs_idr;
33 	int dest_domain_id;
34 	int type;
35 	struct pdr_handle *pdr;
36 	struct workqueue_struct *rxwq;
37 	struct work_struct rx_work;
38 	struct list_head rx_list;
39 };
40 
41 struct apr_rx_buf {
42 	struct list_head node;
43 	int len;
44 	uint8_t buf[];
45 };
46 
47 /**
48  * apr_send_pkt() - Send a apr message from apr device
49  *
50  * @adev: Pointer to previously registered apr device.
51  * @pkt: Pointer to apr packet to send
52  *
53  * Return: Will be an negative on packet size on success.
54  */
55 int apr_send_pkt(struct apr_device *adev, struct apr_pkt *pkt)
56 {
57 	struct packet_router *apr = dev_get_drvdata(adev->dev.parent);
58 	struct apr_hdr *hdr;
59 	unsigned long flags;
60 	int ret;
61 
62 	spin_lock_irqsave(&adev->svc.lock, flags);
63 
64 	hdr = &pkt->hdr;
65 	hdr->src_domain = APR_DOMAIN_APPS;
66 	hdr->src_svc = adev->svc.id;
67 	hdr->dest_domain = adev->domain_id;
68 	hdr->dest_svc = adev->svc.id;
69 
70 	ret = rpmsg_trysend(apr->ch, pkt, hdr->pkt_size);
71 	spin_unlock_irqrestore(&adev->svc.lock, flags);
72 
73 	return ret ? ret : hdr->pkt_size;
74 }
75 EXPORT_SYMBOL_GPL(apr_send_pkt);
76 
77 void gpr_free_port(gpr_port_t *port)
78 {
79 	struct packet_router *gpr = port->pr;
80 	unsigned long flags;
81 
82 	spin_lock_irqsave(&gpr->svcs_lock, flags);
83 	idr_remove(&gpr->svcs_idr, port->id);
84 	spin_unlock_irqrestore(&gpr->svcs_lock, flags);
85 
86 	kfree(port);
87 }
88 EXPORT_SYMBOL_GPL(gpr_free_port);
89 
90 gpr_port_t *gpr_alloc_port(struct apr_device *gdev, struct device *dev,
91 				gpr_port_cb cb,	void *priv)
92 {
93 	struct packet_router *pr = dev_get_drvdata(gdev->dev.parent);
94 	gpr_port_t *port;
95 	struct pkt_router_svc *svc;
96 	int id;
97 
98 	port = kzalloc(sizeof(*port), GFP_KERNEL);
99 	if (!port)
100 		return ERR_PTR(-ENOMEM);
101 
102 	svc = port;
103 	svc->callback = cb;
104 	svc->pr = pr;
105 	svc->priv = priv;
106 	svc->dev = dev;
107 	spin_lock_init(&svc->lock);
108 
109 	spin_lock(&pr->svcs_lock);
110 	id = idr_alloc_cyclic(&pr->svcs_idr, svc, GPR_DYNAMIC_PORT_START,
111 			      GPR_DYNAMIC_PORT_END, GFP_ATOMIC);
112 	if (id < 0) {
113 		dev_err(dev, "Unable to allocate dynamic GPR src port\n");
114 		kfree(port);
115 		spin_unlock(&pr->svcs_lock);
116 		return ERR_PTR(id);
117 	}
118 
119 	svc->id = id;
120 	spin_unlock(&pr->svcs_lock);
121 
122 	return port;
123 }
124 EXPORT_SYMBOL_GPL(gpr_alloc_port);
125 
126 static int pkt_router_send_svc_pkt(struct pkt_router_svc *svc, struct gpr_pkt *pkt)
127 {
128 	struct packet_router *pr = svc->pr;
129 	struct gpr_hdr *hdr;
130 	unsigned long flags;
131 	int ret;
132 
133 	hdr = &pkt->hdr;
134 
135 	spin_lock_irqsave(&svc->lock, flags);
136 	ret = rpmsg_trysend(pr->ch, pkt, hdr->pkt_size);
137 	spin_unlock_irqrestore(&svc->lock, flags);
138 
139 	return ret ? ret : hdr->pkt_size;
140 }
141 
142 int gpr_send_pkt(struct apr_device *gdev, struct gpr_pkt *pkt)
143 {
144 	return pkt_router_send_svc_pkt(&gdev->svc, pkt);
145 }
146 EXPORT_SYMBOL_GPL(gpr_send_pkt);
147 
148 int gpr_send_port_pkt(gpr_port_t *port, struct gpr_pkt *pkt)
149 {
150 	return pkt_router_send_svc_pkt(port, pkt);
151 }
152 EXPORT_SYMBOL_GPL(gpr_send_port_pkt);
153 
154 static void apr_dev_release(struct device *dev)
155 {
156 	struct apr_device *adev = to_apr_device(dev);
157 
158 	kfree(adev);
159 }
160 
161 static int apr_callback(struct rpmsg_device *rpdev, void *buf,
162 				  int len, void *priv, u32 addr)
163 {
164 	struct packet_router *apr = dev_get_drvdata(&rpdev->dev);
165 	struct apr_rx_buf *abuf;
166 	unsigned long flags;
167 
168 	if (len <= APR_HDR_SIZE) {
169 		dev_err(apr->dev, "APR: Improper apr pkt received:%p %d\n",
170 			buf, len);
171 		return -EINVAL;
172 	}
173 
174 	abuf = kzalloc(sizeof(*abuf) + len, GFP_ATOMIC);
175 	if (!abuf)
176 		return -ENOMEM;
177 
178 	abuf->len = len;
179 	memcpy(abuf->buf, buf, len);
180 
181 	spin_lock_irqsave(&apr->rx_lock, flags);
182 	list_add_tail(&abuf->node, &apr->rx_list);
183 	spin_unlock_irqrestore(&apr->rx_lock, flags);
184 
185 	queue_work(apr->rxwq, &apr->rx_work);
186 
187 	return 0;
188 }
189 
190 static int apr_do_rx_callback(struct packet_router *apr, struct apr_rx_buf *abuf)
191 {
192 	uint16_t hdr_size, msg_type, ver, svc_id;
193 	struct pkt_router_svc *svc;
194 	struct apr_device *adev;
195 	struct apr_driver *adrv = NULL;
196 	struct apr_resp_pkt resp;
197 	struct apr_hdr *hdr;
198 	unsigned long flags;
199 	void *buf = abuf->buf;
200 	int len = abuf->len;
201 
202 	hdr = buf;
203 	ver = APR_HDR_FIELD_VER(hdr->hdr_field);
204 	if (ver > APR_PKT_VER + 1)
205 		return -EINVAL;
206 
207 	hdr_size = APR_HDR_FIELD_SIZE_BYTES(hdr->hdr_field);
208 	if (hdr_size < APR_HDR_SIZE) {
209 		dev_err(apr->dev, "APR: Wrong hdr size:%d\n", hdr_size);
210 		return -EINVAL;
211 	}
212 
213 	if (hdr->pkt_size < APR_HDR_SIZE || hdr->pkt_size != len) {
214 		dev_err(apr->dev, "APR: Wrong packet size\n");
215 		return -EINVAL;
216 	}
217 
218 	msg_type = APR_HDR_FIELD_MT(hdr->hdr_field);
219 	if (msg_type >= APR_MSG_TYPE_MAX) {
220 		dev_err(apr->dev, "APR: Wrong message type: %d\n", msg_type);
221 		return -EINVAL;
222 	}
223 
224 	if (hdr->src_domain >= APR_DOMAIN_MAX ||
225 			hdr->dest_domain >= APR_DOMAIN_MAX ||
226 			hdr->src_svc >= APR_SVC_MAX ||
227 			hdr->dest_svc >= APR_SVC_MAX) {
228 		dev_err(apr->dev, "APR: Wrong APR header\n");
229 		return -EINVAL;
230 	}
231 
232 	svc_id = hdr->dest_svc;
233 	spin_lock_irqsave(&apr->svcs_lock, flags);
234 	svc = idr_find(&apr->svcs_idr, svc_id);
235 	if (svc && svc->dev->driver) {
236 		adev = svc_to_apr_device(svc);
237 		adrv = to_apr_driver(adev->dev.driver);
238 	}
239 	spin_unlock_irqrestore(&apr->svcs_lock, flags);
240 
241 	if (!adrv || !adev) {
242 		dev_err(apr->dev, "APR: service is not registered (%d)\n",
243 			svc_id);
244 		return -EINVAL;
245 	}
246 
247 	resp.hdr = *hdr;
248 	resp.payload_size = hdr->pkt_size - hdr_size;
249 
250 	/*
251 	 * NOTE: hdr_size is not same as APR_HDR_SIZE as remote can include
252 	 * optional headers in to apr_hdr which should be ignored
253 	 */
254 	if (resp.payload_size > 0)
255 		resp.payload = buf + hdr_size;
256 
257 	adrv->callback(adev, &resp);
258 
259 	return 0;
260 }
261 
262 static int gpr_do_rx_callback(struct packet_router *gpr, struct apr_rx_buf *abuf)
263 {
264 	uint16_t hdr_size, ver;
265 	struct pkt_router_svc *svc = NULL;
266 	struct gpr_resp_pkt resp;
267 	struct gpr_hdr *hdr;
268 	unsigned long flags;
269 	void *buf = abuf->buf;
270 	int len = abuf->len;
271 
272 	hdr = buf;
273 	ver = hdr->version;
274 	if (ver > GPR_PKT_VER + 1)
275 		return -EINVAL;
276 
277 	hdr_size = hdr->hdr_size;
278 	if (hdr_size < GPR_PKT_HEADER_WORD_SIZE) {
279 		dev_err(gpr->dev, "GPR: Wrong hdr size:%d\n", hdr_size);
280 		return -EINVAL;
281 	}
282 
283 	if (hdr->pkt_size < GPR_PKT_HEADER_BYTE_SIZE || hdr->pkt_size != len) {
284 		dev_err(gpr->dev, "GPR: Wrong packet size\n");
285 		return -EINVAL;
286 	}
287 
288 	resp.hdr = *hdr;
289 	resp.payload_size = hdr->pkt_size - (hdr_size * 4);
290 
291 	/*
292 	 * NOTE: hdr_size is not same as GPR_HDR_SIZE as remote can include
293 	 * optional headers in to gpr_hdr which should be ignored
294 	 */
295 	if (resp.payload_size > 0)
296 		resp.payload = buf + (hdr_size *  4);
297 
298 
299 	spin_lock_irqsave(&gpr->svcs_lock, flags);
300 	svc = idr_find(&gpr->svcs_idr, hdr->dest_port);
301 	spin_unlock_irqrestore(&gpr->svcs_lock, flags);
302 
303 	if (!svc) {
304 		dev_err(gpr->dev, "GPR: Port(%x) is not registered\n",
305 			hdr->dest_port);
306 		return -EINVAL;
307 	}
308 
309 	if (svc->callback)
310 		svc->callback(&resp, svc->priv, 0);
311 
312 	return 0;
313 }
314 
315 static void apr_rxwq(struct work_struct *work)
316 {
317 	struct packet_router *apr = container_of(work, struct packet_router, rx_work);
318 	struct apr_rx_buf *abuf, *b;
319 	unsigned long flags;
320 
321 	if (!list_empty(&apr->rx_list)) {
322 		list_for_each_entry_safe(abuf, b, &apr->rx_list, node) {
323 			switch (apr->type) {
324 			case PR_TYPE_APR:
325 				apr_do_rx_callback(apr, abuf);
326 				break;
327 			case PR_TYPE_GPR:
328 				gpr_do_rx_callback(apr, abuf);
329 				break;
330 			default:
331 				break;
332 			}
333 			spin_lock_irqsave(&apr->rx_lock, flags);
334 			list_del(&abuf->node);
335 			spin_unlock_irqrestore(&apr->rx_lock, flags);
336 			kfree(abuf);
337 		}
338 	}
339 }
340 
341 static int apr_device_match(struct device *dev, struct device_driver *drv)
342 {
343 	struct apr_device *adev = to_apr_device(dev);
344 	struct apr_driver *adrv = to_apr_driver(drv);
345 	const struct apr_device_id *id = adrv->id_table;
346 
347 	/* Attempt an OF style match first */
348 	if (of_driver_match_device(dev, drv))
349 		return 1;
350 
351 	if (!id)
352 		return 0;
353 
354 	while (id->domain_id != 0 || id->svc_id != 0) {
355 		if (id->domain_id == adev->domain_id &&
356 		    id->svc_id == adev->svc.id)
357 			return 1;
358 		id++;
359 	}
360 
361 	return 0;
362 }
363 
364 static int apr_device_probe(struct device *dev)
365 {
366 	struct apr_device *adev = to_apr_device(dev);
367 	struct apr_driver *adrv = to_apr_driver(dev->driver);
368 	int ret;
369 
370 	ret = adrv->probe(adev);
371 	if (!ret)
372 		adev->svc.callback = adrv->gpr_callback;
373 
374 	return ret;
375 }
376 
377 static void apr_device_remove(struct device *dev)
378 {
379 	struct apr_device *adev = to_apr_device(dev);
380 	struct apr_driver *adrv = to_apr_driver(dev->driver);
381 	struct packet_router *apr = dev_get_drvdata(adev->dev.parent);
382 
383 	if (adrv->remove)
384 		adrv->remove(adev);
385 	spin_lock(&apr->svcs_lock);
386 	idr_remove(&apr->svcs_idr, adev->svc.id);
387 	spin_unlock(&apr->svcs_lock);
388 }
389 
390 static int apr_uevent(struct device *dev, struct kobj_uevent_env *env)
391 {
392 	struct apr_device *adev = to_apr_device(dev);
393 	int ret;
394 
395 	ret = of_device_uevent_modalias(dev, env);
396 	if (ret != -ENODEV)
397 		return ret;
398 
399 	return add_uevent_var(env, "MODALIAS=apr:%s", adev->name);
400 }
401 
402 struct bus_type aprbus = {
403 	.name		= "aprbus",
404 	.match		= apr_device_match,
405 	.probe		= apr_device_probe,
406 	.uevent		= apr_uevent,
407 	.remove		= apr_device_remove,
408 };
409 EXPORT_SYMBOL_GPL(aprbus);
410 
411 static int apr_add_device(struct device *dev, struct device_node *np,
412 			  u32 svc_id, u32 domain_id)
413 {
414 	struct packet_router *apr = dev_get_drvdata(dev);
415 	struct apr_device *adev = NULL;
416 	struct pkt_router_svc *svc;
417 	int ret;
418 
419 	adev = kzalloc(sizeof(*adev), GFP_KERNEL);
420 	if (!adev)
421 		return -ENOMEM;
422 
423 	adev->svc_id = svc_id;
424 	svc = &adev->svc;
425 
426 	svc->id = svc_id;
427 	svc->pr = apr;
428 	svc->priv = adev;
429 	svc->dev = dev;
430 	spin_lock_init(&svc->lock);
431 
432 	adev->domain_id = domain_id;
433 
434 	if (np)
435 		snprintf(adev->name, APR_NAME_SIZE, "%pOFn", np);
436 
437 	switch (apr->type) {
438 	case PR_TYPE_APR:
439 		dev_set_name(&adev->dev, "aprsvc:%s:%x:%x", adev->name,
440 			     domain_id, svc_id);
441 		break;
442 	case PR_TYPE_GPR:
443 		dev_set_name(&adev->dev, "gprsvc:%s:%x:%x", adev->name,
444 			     domain_id, svc_id);
445 		break;
446 	default:
447 		break;
448 	}
449 
450 	adev->dev.bus = &aprbus;
451 	adev->dev.parent = dev;
452 	adev->dev.of_node = np;
453 	adev->dev.release = apr_dev_release;
454 	adev->dev.driver = NULL;
455 
456 	spin_lock(&apr->svcs_lock);
457 	ret = idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC);
458 	spin_unlock(&apr->svcs_lock);
459 	if (ret < 0) {
460 		dev_err(dev, "idr_alloc failed: %d\n", ret);
461 		goto out;
462 	}
463 
464 	ret = of_property_read_string_index(np, "qcom,protection-domain",
465 					    1, &adev->service_path);
466 	if (ret < 0) {
467 		dev_err(dev, "Failed to read second value of qcom,protection-domain\n");
468 		goto out;
469 	}
470 
471 	dev_info(dev, "Adding APR/GPR dev: %s\n", dev_name(&adev->dev));
472 
473 	ret = device_register(&adev->dev);
474 	if (ret) {
475 		dev_err(dev, "device_register failed: %d\n", ret);
476 		put_device(&adev->dev);
477 	}
478 
479 out:
480 	return ret;
481 }
482 
483 static int of_apr_add_pd_lookups(struct device *dev)
484 {
485 	const char *service_name, *service_path;
486 	struct packet_router *apr = dev_get_drvdata(dev);
487 	struct device_node *node;
488 	struct pdr_service *pds;
489 	int ret;
490 
491 	for_each_child_of_node(dev->of_node, node) {
492 		ret = of_property_read_string_index(node, "qcom,protection-domain",
493 						    0, &service_name);
494 		if (ret < 0)
495 			continue;
496 
497 		ret = of_property_read_string_index(node, "qcom,protection-domain",
498 						    1, &service_path);
499 		if (ret < 0) {
500 			dev_err(dev, "pdr service path missing: %d\n", ret);
501 			of_node_put(node);
502 			return ret;
503 		}
504 
505 		pds = pdr_add_lookup(apr->pdr, service_name, service_path);
506 		if (IS_ERR(pds) && PTR_ERR(pds) != -EALREADY) {
507 			dev_err(dev, "pdr add lookup failed: %ld\n", PTR_ERR(pds));
508 			of_node_put(node);
509 			return PTR_ERR(pds);
510 		}
511 	}
512 
513 	return 0;
514 }
515 
516 static void of_register_apr_devices(struct device *dev, const char *svc_path)
517 {
518 	struct packet_router *apr = dev_get_drvdata(dev);
519 	struct device_node *node;
520 	const char *service_path;
521 	int ret;
522 
523 	for_each_child_of_node(dev->of_node, node) {
524 		u32 svc_id;
525 		u32 domain_id;
526 
527 		/*
528 		 * This function is called with svc_path NULL during
529 		 * apr_probe(), in which case we register any apr devices
530 		 * without a qcom,protection-domain specified.
531 		 *
532 		 * Then as the protection domains becomes available
533 		 * (if applicable) this function is again called, but with
534 		 * svc_path representing the service becoming available. In
535 		 * this case we register any apr devices with a matching
536 		 * qcom,protection-domain.
537 		 */
538 
539 		ret = of_property_read_string_index(node, "qcom,protection-domain",
540 						    1, &service_path);
541 		if (svc_path) {
542 			/* skip APR services that are PD independent */
543 			if (ret)
544 				continue;
545 
546 			/* skip APR services whose PD paths don't match */
547 			if (strcmp(service_path, svc_path))
548 				continue;
549 		} else {
550 			/* skip APR services whose PD lookups are registered */
551 			if (ret == 0)
552 				continue;
553 		}
554 
555 		if (of_property_read_u32(node, "reg", &svc_id))
556 			continue;
557 
558 		domain_id = apr->dest_domain_id;
559 
560 		if (apr_add_device(dev, node, svc_id, domain_id))
561 			dev_err(dev, "Failed to add apr %d svc\n", svc_id);
562 	}
563 }
564 
565 static int apr_remove_device(struct device *dev, void *svc_path)
566 {
567 	struct apr_device *adev = to_apr_device(dev);
568 
569 	if (svc_path && adev->service_path) {
570 		if (!strcmp(adev->service_path, (char *)svc_path))
571 			device_unregister(&adev->dev);
572 	} else {
573 		device_unregister(&adev->dev);
574 	}
575 
576 	return 0;
577 }
578 
579 static void apr_pd_status(int state, char *svc_path, void *priv)
580 {
581 	struct packet_router *apr = (struct packet_router *)priv;
582 
583 	switch (state) {
584 	case SERVREG_SERVICE_STATE_UP:
585 		of_register_apr_devices(apr->dev, svc_path);
586 		break;
587 	case SERVREG_SERVICE_STATE_DOWN:
588 		device_for_each_child(apr->dev, svc_path, apr_remove_device);
589 		break;
590 	}
591 }
592 
593 static int apr_probe(struct rpmsg_device *rpdev)
594 {
595 	struct device *dev = &rpdev->dev;
596 	struct packet_router *apr;
597 	int ret;
598 
599 	apr = devm_kzalloc(dev, sizeof(*apr), GFP_KERNEL);
600 	if (!apr)
601 		return -ENOMEM;
602 
603 	ret = of_property_read_u32(dev->of_node, "qcom,domain", &apr->dest_domain_id);
604 
605 	if (of_device_is_compatible(dev->of_node, "qcom,gpr")) {
606 		apr->type = PR_TYPE_GPR;
607 	} else {
608 		if (ret) /* try deprecated apr-domain property */
609 			ret = of_property_read_u32(dev->of_node, "qcom,apr-domain",
610 						   &apr->dest_domain_id);
611 		apr->type = PR_TYPE_APR;
612 	}
613 
614 	if (ret) {
615 		dev_err(dev, "Domain ID not specified in DT\n");
616 		return ret;
617 	}
618 
619 	dev_set_drvdata(dev, apr);
620 	apr->ch = rpdev->ept;
621 	apr->dev = dev;
622 	apr->rxwq = create_singlethread_workqueue("qcom_apr_rx");
623 	if (!apr->rxwq) {
624 		dev_err(apr->dev, "Failed to start Rx WQ\n");
625 		return -ENOMEM;
626 	}
627 	INIT_WORK(&apr->rx_work, apr_rxwq);
628 
629 	apr->pdr = pdr_handle_alloc(apr_pd_status, apr);
630 	if (IS_ERR(apr->pdr)) {
631 		dev_err(dev, "Failed to init PDR handle\n");
632 		ret = PTR_ERR(apr->pdr);
633 		goto destroy_wq;
634 	}
635 
636 	INIT_LIST_HEAD(&apr->rx_list);
637 	spin_lock_init(&apr->rx_lock);
638 	spin_lock_init(&apr->svcs_lock);
639 	idr_init(&apr->svcs_idr);
640 
641 	ret = of_apr_add_pd_lookups(dev);
642 	if (ret)
643 		goto handle_release;
644 
645 	of_register_apr_devices(dev, NULL);
646 
647 	return 0;
648 
649 handle_release:
650 	pdr_handle_release(apr->pdr);
651 destroy_wq:
652 	destroy_workqueue(apr->rxwq);
653 	return ret;
654 }
655 
656 static void apr_remove(struct rpmsg_device *rpdev)
657 {
658 	struct packet_router *apr = dev_get_drvdata(&rpdev->dev);
659 
660 	pdr_handle_release(apr->pdr);
661 	device_for_each_child(&rpdev->dev, NULL, apr_remove_device);
662 	destroy_workqueue(apr->rxwq);
663 }
664 
665 /*
666  * __apr_driver_register() - Client driver registration with aprbus
667  *
668  * @drv:Client driver to be associated with client-device.
669  * @owner: owning module/driver
670  *
671  * This API will register the client driver with the aprbus
672  * It is called from the driver's module-init function.
673  */
674 int __apr_driver_register(struct apr_driver *drv, struct module *owner)
675 {
676 	drv->driver.bus = &aprbus;
677 	drv->driver.owner = owner;
678 
679 	return driver_register(&drv->driver);
680 }
681 EXPORT_SYMBOL_GPL(__apr_driver_register);
682 
683 /*
684  * apr_driver_unregister() - Undo effect of apr_driver_register
685  *
686  * @drv: Client driver to be unregistered
687  */
688 void apr_driver_unregister(struct apr_driver *drv)
689 {
690 	driver_unregister(&drv->driver);
691 }
692 EXPORT_SYMBOL_GPL(apr_driver_unregister);
693 
694 static const struct of_device_id pkt_router_of_match[] = {
695 	{ .compatible = "qcom,apr"},
696 	{ .compatible = "qcom,apr-v2"},
697 	{ .compatible = "qcom,gpr"},
698 	{}
699 };
700 MODULE_DEVICE_TABLE(of, pkt_router_of_match);
701 
702 static struct rpmsg_driver packet_router_driver = {
703 	.probe = apr_probe,
704 	.remove = apr_remove,
705 	.callback = apr_callback,
706 	.drv = {
707 		.name = "qcom,apr",
708 		.of_match_table = pkt_router_of_match,
709 	},
710 };
711 
712 static int __init apr_init(void)
713 {
714 	int ret;
715 
716 	ret = bus_register(&aprbus);
717 	if (!ret)
718 		ret = register_rpmsg_driver(&packet_router_driver);
719 	else
720 		bus_unregister(&aprbus);
721 
722 	return ret;
723 }
724 
725 static void __exit apr_exit(void)
726 {
727 	bus_unregister(&aprbus);
728 	unregister_rpmsg_driver(&packet_router_driver);
729 }
730 
731 subsys_initcall(apr_init);
732 module_exit(apr_exit);
733 
734 MODULE_LICENSE("GPL v2");
735 MODULE_DESCRIPTION("Qualcomm APR Bus");
736