xref: /linux/drivers/hid/intel-ish-hid/ishtp/bus.c (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /*
2  * ISHTP bus driver
3  *
4  * Copyright (c) 2012-2016, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  */
15 
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/device.h>
20 #include <linux/sched.h>
21 #include <linux/slab.h>
22 #include "bus.h"
23 #include "ishtp-dev.h"
24 #include "client.h"
25 #include "hbm.h"
26 
27 static int ishtp_use_dma;
28 module_param_named(ishtp_use_dma, ishtp_use_dma, int, 0600);
29 MODULE_PARM_DESC(ishtp_use_dma, "Use DMA to send messages");
30 
31 #define to_ishtp_cl_driver(d) container_of(d, struct ishtp_cl_driver, driver)
32 #define to_ishtp_cl_device(d) container_of(d, struct ishtp_cl_device, dev)
33 static bool ishtp_device_ready;
34 
35 /**
36  * ishtp_recv() - process ishtp message
37  * @dev: ishtp device
38  *
39  * If a message with valid header and size is received, then
40  * this function calls appropriate handler. The host or firmware
41  * address is zero, then they are host bus management message,
42  * otherwise they are message fo clients.
43  */
44 void ishtp_recv(struct ishtp_device *dev)
45 {
46 	uint32_t	msg_hdr;
47 	struct ishtp_msg_hdr	*ishtp_hdr;
48 
49 	/* Read ISHTP header dword */
50 	msg_hdr = dev->ops->ishtp_read_hdr(dev);
51 	if (!msg_hdr)
52 		return;
53 
54 	dev->ops->sync_fw_clock(dev);
55 
56 	ishtp_hdr = (struct ishtp_msg_hdr *)&msg_hdr;
57 	dev->ishtp_msg_hdr = msg_hdr;
58 
59 	/* Sanity check: ISHTP frag. length in header */
60 	if (ishtp_hdr->length > dev->mtu) {
61 		dev_err(dev->devc,
62 			"ISHTP hdr - bad length: %u; dropped [%08X]\n",
63 			(unsigned int)ishtp_hdr->length, msg_hdr);
64 		return;
65 	}
66 
67 	/* ISHTP bus message */
68 	if (!ishtp_hdr->host_addr && !ishtp_hdr->fw_addr)
69 		recv_hbm(dev, ishtp_hdr);
70 	/* ISHTP fixed-client message */
71 	else if (!ishtp_hdr->host_addr)
72 		recv_fixed_cl_msg(dev, ishtp_hdr);
73 	else
74 		/* ISHTP client message */
75 		recv_ishtp_cl_msg(dev, ishtp_hdr);
76 }
77 EXPORT_SYMBOL(ishtp_recv);
78 
79 /**
80  * ishtp_send_msg() - Send ishtp message
81  * @dev: ishtp device
82  * @hdr: Message header
83  * @msg: Message contents
84  * @ipc_send_compl: completion callback
85  * @ipc_send_compl_prm: completion callback parameter
86  *
87  * Send a multi fragment message via IPC. After sending the first fragment
88  * the completion callback is called to schedule transmit of next fragment.
89  *
90  * Return: This returns IPC send message status.
91  */
92 int ishtp_send_msg(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
93 		       void *msg, void(*ipc_send_compl)(void *),
94 		       void *ipc_send_compl_prm)
95 {
96 	unsigned char	ipc_msg[IPC_FULL_MSG_SIZE];
97 	uint32_t	drbl_val;
98 
99 	drbl_val = dev->ops->ipc_get_header(dev, hdr->length +
100 					    sizeof(struct ishtp_msg_hdr),
101 					    1);
102 
103 	memcpy(ipc_msg, &drbl_val, sizeof(uint32_t));
104 	memcpy(ipc_msg + sizeof(uint32_t), hdr, sizeof(uint32_t));
105 	memcpy(ipc_msg + 2 * sizeof(uint32_t), msg, hdr->length);
106 	return	dev->ops->write(dev, ipc_send_compl, ipc_send_compl_prm,
107 				ipc_msg, 2 * sizeof(uint32_t) + hdr->length);
108 }
109 
110 /**
111  * ishtp_write_message() - Send ishtp single fragment message
112  * @dev: ishtp device
113  * @hdr: Message header
114  * @buf: message data
115  *
116  * Send a single fragment message via IPC.  This returns IPC send message
117  * status.
118  *
119  * Return: This returns IPC send message status.
120  */
121 int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr,
122 			unsigned char *buf)
123 {
124 	return ishtp_send_msg(dev, hdr, buf, NULL, NULL);
125 }
126 
127 /**
128  * ishtp_fw_cl_by_uuid() - locate index of fw client
129  * @dev: ishtp device
130  * @uuid: uuid of the client to search
131  *
132  * Search firmware client using UUID.
133  *
134  * Return: fw client index or -ENOENT if not found
135  */
136 int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid)
137 {
138 	int i, res = -ENOENT;
139 
140 	for (i = 0; i < dev->fw_clients_num; ++i) {
141 		if (uuid_le_cmp(*uuid, dev->fw_clients[i].props.protocol_name)
142 				== 0) {
143 			res = i;
144 			break;
145 		}
146 	}
147 	return res;
148 }
149 EXPORT_SYMBOL(ishtp_fw_cl_by_uuid);
150 
151 /**
152  * ishtp_fw_cl_by_id() - return index to fw_clients for client_id
153  * @dev: the ishtp device structure
154  * @client_id: fw client id to search
155  *
156  * Search firmware client using client id.
157  *
158  * Return: index on success, -ENOENT on failure.
159  */
160 int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id)
161 {
162 	int i, res = -ENOENT;
163 	unsigned long	flags;
164 
165 	spin_lock_irqsave(&dev->fw_clients_lock, flags);
166 	for (i = 0; i < dev->fw_clients_num; i++) {
167 		if (dev->fw_clients[i].client_id == client_id) {
168 			res = i;
169 			break;
170 		}
171 	}
172 	spin_unlock_irqrestore(&dev->fw_clients_lock, flags);
173 
174 	return res;
175 }
176 
177 /**
178  * ishtp_cl_device_probe() - Bus probe() callback
179  * @dev: the device structure
180  *
181  * This is a bus probe callback and calls the drive probe function.
182  *
183  * Return: Return value from driver probe() call.
184  */
185 static int ishtp_cl_device_probe(struct device *dev)
186 {
187 	struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
188 	struct ishtp_cl_driver *driver;
189 
190 	if (!device)
191 		return 0;
192 
193 	driver = to_ishtp_cl_driver(dev->driver);
194 	if (!driver || !driver->probe)
195 		return -ENODEV;
196 
197 	return driver->probe(device);
198 }
199 
200 /**
201  * ishtp_cl_device_remove() - Bus remove() callback
202  * @dev: the device structure
203  *
204  * This is a bus remove callback and calls the drive remove function.
205  * Since the ISH driver model supports only built in, this is
206  * primarily can be called during pci driver init failure.
207  *
208  * Return: Return value from driver remove() call.
209  */
210 static int ishtp_cl_device_remove(struct device *dev)
211 {
212 	struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
213 	struct ishtp_cl_driver *driver;
214 
215 	if (!device || !dev->driver)
216 		return 0;
217 
218 	if (device->event_cb) {
219 		device->event_cb = NULL;
220 		cancel_work_sync(&device->event_work);
221 	}
222 
223 	driver = to_ishtp_cl_driver(dev->driver);
224 	if (!driver->remove) {
225 		dev->driver = NULL;
226 
227 		return 0;
228 	}
229 
230 	return driver->remove(device);
231 }
232 
233 /**
234  * ishtp_cl_device_suspend() - Bus suspend callback
235  * @dev:	device
236  *
237  * Called during device suspend process.
238  *
239  * Return: Return value from driver suspend() call.
240  */
241 static int ishtp_cl_device_suspend(struct device *dev)
242 {
243 	struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
244 	struct ishtp_cl_driver *driver;
245 	int ret = 0;
246 
247 	if (!device)
248 		return 0;
249 
250 	driver = to_ishtp_cl_driver(dev->driver);
251 	if (driver && driver->driver.pm) {
252 		if (driver->driver.pm->suspend)
253 			ret = driver->driver.pm->suspend(dev);
254 	}
255 
256 	return ret;
257 }
258 
259 /**
260  * ishtp_cl_device_resume() - Bus resume callback
261  * @dev:	device
262  *
263  * Called during device resume process.
264  *
265  * Return: Return value from driver resume() call.
266  */
267 static int ishtp_cl_device_resume(struct device *dev)
268 {
269 	struct ishtp_cl_device *device = to_ishtp_cl_device(dev);
270 	struct ishtp_cl_driver *driver;
271 	int ret = 0;
272 
273 	if (!device)
274 		return 0;
275 
276 	/*
277 	 * When ISH needs hard reset, it is done asynchrnously, hence bus
278 	 * resume will  be called before full ISH resume
279 	 */
280 	if (device->ishtp_dev->resume_flag)
281 		return 0;
282 
283 	driver = to_ishtp_cl_driver(dev->driver);
284 	if (driver && driver->driver.pm) {
285 		if (driver->driver.pm->resume)
286 			ret = driver->driver.pm->resume(dev);
287 	}
288 
289 	return ret;
290 }
291 
292 /**
293  * ishtp_cl_device_reset() - Reset callback
294  * @device:	ishtp client device instance
295  *
296  * This is a callback when HW reset is done and the device need
297  * reinit.
298  *
299  * Return: Return value from driver reset() call.
300  */
301 static int ishtp_cl_device_reset(struct ishtp_cl_device *device)
302 {
303 	struct ishtp_cl_driver *driver;
304 	int ret = 0;
305 
306 	device->event_cb = NULL;
307 	cancel_work_sync(&device->event_work);
308 
309 	driver = to_ishtp_cl_driver(device->dev.driver);
310 	if (driver && driver->reset)
311 		ret = driver->reset(device);
312 
313 	return ret;
314 }
315 
316 static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
317 	char *buf)
318 {
319 	int len;
320 
321 	len = snprintf(buf, PAGE_SIZE, "ishtp:%s\n", dev_name(dev));
322 	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
323 }
324 
325 static struct device_attribute ishtp_cl_dev_attrs[] = {
326 	__ATTR_RO(modalias),
327 	__ATTR_NULL,
328 };
329 
330 static int ishtp_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
331 {
332 	if (add_uevent_var(env, "MODALIAS=ishtp:%s", dev_name(dev)))
333 		return -ENOMEM;
334 	return 0;
335 }
336 
337 static const struct dev_pm_ops ishtp_cl_bus_dev_pm_ops = {
338 	/* Suspend callbacks */
339 	.suspend = ishtp_cl_device_suspend,
340 	.resume = ishtp_cl_device_resume,
341 	/* Hibernate callbacks */
342 	.freeze = ishtp_cl_device_suspend,
343 	.thaw = ishtp_cl_device_resume,
344 	.restore = ishtp_cl_device_resume,
345 };
346 
347 static struct bus_type ishtp_cl_bus_type = {
348 	.name		= "ishtp",
349 	.dev_attrs	= ishtp_cl_dev_attrs,
350 	.probe		= ishtp_cl_device_probe,
351 	.remove		= ishtp_cl_device_remove,
352 	.pm		= &ishtp_cl_bus_dev_pm_ops,
353 	.uevent		= ishtp_cl_uevent,
354 };
355 
356 static void ishtp_cl_dev_release(struct device *dev)
357 {
358 	kfree(to_ishtp_cl_device(dev));
359 }
360 
361 static const struct device_type ishtp_cl_device_type = {
362 	.release	= ishtp_cl_dev_release,
363 };
364 
365 /**
366  * ishtp_bus_add_device() - Function to create device on bus
367  * @dev:	ishtp device
368  * @uuid:	uuid of the client
369  * @name:	Name of the client
370  *
371  * Allocate ISHTP bus client device, attach it to uuid
372  * and register with ISHTP bus.
373  *
374  * Return: ishtp_cl_device pointer or NULL on failure
375  */
376 static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev,
377 						    uuid_le uuid, char *name)
378 {
379 	struct ishtp_cl_device *device;
380 	int status;
381 	unsigned long flags;
382 
383 	spin_lock_irqsave(&dev->device_list_lock, flags);
384 	list_for_each_entry(device, &dev->device_list, device_link) {
385 		if (!strcmp(name, dev_name(&device->dev))) {
386 			device->fw_client = &dev->fw_clients[
387 				dev->fw_client_presentation_num - 1];
388 			spin_unlock_irqrestore(&dev->device_list_lock, flags);
389 			ishtp_cl_device_reset(device);
390 			return device;
391 		}
392 	}
393 	spin_unlock_irqrestore(&dev->device_list_lock, flags);
394 
395 	device = kzalloc(sizeof(struct ishtp_cl_device), GFP_KERNEL);
396 	if (!device)
397 		return NULL;
398 
399 	device->dev.parent = dev->devc;
400 	device->dev.bus = &ishtp_cl_bus_type;
401 	device->dev.type = &ishtp_cl_device_type;
402 	device->ishtp_dev = dev;
403 
404 	device->fw_client =
405 		&dev->fw_clients[dev->fw_client_presentation_num - 1];
406 
407 	dev_set_name(&device->dev, "%s", name);
408 
409 	spin_lock_irqsave(&dev->device_list_lock, flags);
410 	list_add_tail(&device->device_link, &dev->device_list);
411 	spin_unlock_irqrestore(&dev->device_list_lock, flags);
412 
413 	status = device_register(&device->dev);
414 	if (status) {
415 		spin_lock_irqsave(&dev->device_list_lock, flags);
416 		list_del(&device->device_link);
417 		spin_unlock_irqrestore(&dev->device_list_lock, flags);
418 		dev_err(dev->devc, "Failed to register ISHTP client device\n");
419 		kfree(device);
420 		return NULL;
421 	}
422 
423 	ishtp_device_ready = true;
424 
425 	return device;
426 }
427 
428 /**
429  * ishtp_bus_remove_device() - Function to relase device on bus
430  * @device:	client device instance
431  *
432  * This is a counterpart of ishtp_bus_add_device.
433  * Device is unregistered.
434  * the device structure is freed in 'ishtp_cl_dev_release' function
435  * Called only during error in pci driver init path.
436  */
437 static void ishtp_bus_remove_device(struct ishtp_cl_device *device)
438 {
439 	device_unregister(&device->dev);
440 }
441 
442 /**
443  * __ishtp_cl_driver_register() - Client driver register
444  * @driver:	the client driver instance
445  * @owner:	Owner of this driver module
446  *
447  * Once a client driver is probed, it created a client
448  * instance and registers with the bus.
449  *
450  * Return: Return value of driver_register or -ENODEV if not ready
451  */
452 int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver,
453 			       struct module *owner)
454 {
455 	int err;
456 
457 	if (!ishtp_device_ready)
458 		return -ENODEV;
459 
460 	driver->driver.name = driver->name;
461 	driver->driver.owner = owner;
462 	driver->driver.bus = &ishtp_cl_bus_type;
463 
464 	err = driver_register(&driver->driver);
465 	if (err)
466 		return err;
467 
468 	return 0;
469 }
470 EXPORT_SYMBOL(__ishtp_cl_driver_register);
471 
472 /**
473  * ishtp_cl_driver_unregister() - Client driver unregister
474  * @driver:	the client driver instance
475  *
476  * Unregister client during device removal process.
477  */
478 void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver)
479 {
480 	driver_unregister(&driver->driver);
481 }
482 EXPORT_SYMBOL(ishtp_cl_driver_unregister);
483 
484 /**
485  * ishtp_bus_event_work() - event work function
486  * @work:	work struct pointer
487  *
488  * Once an event is received for a client this work
489  * function is called. If the device has registered a
490  * callback then the callback is called.
491  */
492 static void ishtp_bus_event_work(struct work_struct *work)
493 {
494 	struct ishtp_cl_device *device;
495 
496 	device = container_of(work, struct ishtp_cl_device, event_work);
497 
498 	if (device->event_cb)
499 		device->event_cb(device);
500 }
501 
502 /**
503  * ishtp_cl_bus_rx_event() - schedule event work
504  * @device:	client device instance
505  *
506  * Once an event is received for a client this schedules
507  * a work function to process.
508  */
509 void ishtp_cl_bus_rx_event(struct ishtp_cl_device *device)
510 {
511 	if (!device || !device->event_cb)
512 		return;
513 
514 	if (device->event_cb)
515 		schedule_work(&device->event_work);
516 }
517 
518 /**
519  * ishtp_register_event_cb() - Register callback
520  * @device:	client device instance
521  * @event_cb:	Event processor for an client
522  *
523  * Register a callback for events, called from client driver
524  *
525  * Return: Return 0 or -EALREADY if already registered
526  */
527 int ishtp_register_event_cb(struct ishtp_cl_device *device,
528 	void (*event_cb)(struct ishtp_cl_device *))
529 {
530 	if (device->event_cb)
531 		return -EALREADY;
532 
533 	device->event_cb = event_cb;
534 	INIT_WORK(&device->event_work, ishtp_bus_event_work);
535 
536 	return 0;
537 }
538 EXPORT_SYMBOL(ishtp_register_event_cb);
539 
540 /**
541  * ishtp_get_device() - update usage count for the device
542  * @cl_device:	client device instance
543  *
544  * Increment the usage count. The device can't be deleted
545  */
546 void ishtp_get_device(struct ishtp_cl_device *cl_device)
547 {
548 	cl_device->reference_count++;
549 }
550 EXPORT_SYMBOL(ishtp_get_device);
551 
552 /**
553  * ishtp_put_device() - decrement usage count for the device
554  * @cl_device:	client device instance
555  *
556  * Decrement the usage count. The device can be deleted is count = 0
557  */
558 void ishtp_put_device(struct ishtp_cl_device *cl_device)
559 {
560 	cl_device->reference_count--;
561 }
562 EXPORT_SYMBOL(ishtp_put_device);
563 
564 /**
565  * ishtp_bus_new_client() - Create a new client
566  * @dev:	ISHTP device instance
567  *
568  * Once bus protocol enumerates a client, this is called
569  * to add a device for the client.
570  *
571  * Return: 0 on success or error code on failure
572  */
573 int ishtp_bus_new_client(struct ishtp_device *dev)
574 {
575 	int	i;
576 	char	*dev_name;
577 	struct ishtp_cl_device	*cl_device;
578 	uuid_le	device_uuid;
579 
580 	/*
581 	 * For all reported clients, create an unconnected client and add its
582 	 * device to ISHTP bus.
583 	 * If appropriate driver has loaded, this will trigger its probe().
584 	 * Otherwise, probe() will be called when driver is loaded
585 	 */
586 	i = dev->fw_client_presentation_num - 1;
587 	device_uuid = dev->fw_clients[i].props.protocol_name;
588 	dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b);
589 	if (!dev_name)
590 		return	-ENOMEM;
591 
592 	cl_device = ishtp_bus_add_device(dev, device_uuid, dev_name);
593 	if (!cl_device) {
594 		kfree(dev_name);
595 		return	-ENOENT;
596 	}
597 
598 	kfree(dev_name);
599 
600 	return	0;
601 }
602 
603 /**
604  * ishtp_cl_device_bind() - bind a device
605  * @cl:		ishtp client device
606  *
607  * Binds connected ishtp_cl to ISHTP bus device
608  *
609  * Return: 0 on success or fault code
610  */
611 int ishtp_cl_device_bind(struct ishtp_cl *cl)
612 {
613 	struct ishtp_cl_device	*cl_device;
614 	unsigned long flags;
615 	int	rv;
616 
617 	if (!cl->fw_client_id || cl->state != ISHTP_CL_CONNECTED)
618 		return	-EFAULT;
619 
620 	rv = -ENOENT;
621 	spin_lock_irqsave(&cl->dev->device_list_lock, flags);
622 	list_for_each_entry(cl_device, &cl->dev->device_list,
623 			device_link) {
624 		if (cl_device->fw_client->client_id == cl->fw_client_id) {
625 			cl->device = cl_device;
626 			rv = 0;
627 			break;
628 		}
629 	}
630 	spin_unlock_irqrestore(&cl->dev->device_list_lock, flags);
631 	return	rv;
632 }
633 
634 /**
635  * ishtp_bus_remove_all_clients() - Remove all clients
636  * @ishtp_dev:		ishtp device
637  * @warm_reset:		Reset due to FW reset dure to errors or S3 suspend
638  *
639  * This is part of reset/remove flow. This function the main processing
640  * only targets error processing, if the FW has forced reset or
641  * error to remove connected clients. When warm reset the client devices are
642  * not removed.
643  */
644 void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev,
645 				  bool warm_reset)
646 {
647 	struct ishtp_cl_device	*cl_device, *n;
648 	struct ishtp_cl	*cl;
649 	unsigned long	flags;
650 
651 	spin_lock_irqsave(&ishtp_dev->cl_list_lock, flags);
652 	list_for_each_entry(cl, &ishtp_dev->cl_list, link) {
653 		cl->state = ISHTP_CL_DISCONNECTED;
654 
655 		/*
656 		 * Wake any pending process. The waiter would check dev->state
657 		 * and determine that it's not enabled already,
658 		 * and will return error to its caller
659 		 */
660 		wake_up_interruptible(&cl->wait_ctrl_res);
661 
662 		/* Disband any pending read/write requests and free rb */
663 		ishtp_cl_flush_queues(cl);
664 
665 		/* Remove all free and in_process rings, both Rx and Tx */
666 		ishtp_cl_free_rx_ring(cl);
667 		ishtp_cl_free_tx_ring(cl);
668 
669 		/*
670 		 * Free client and ISHTP bus client device structures
671 		 * don't free host client because it is part of the OS fd
672 		 * structure
673 		 */
674 	}
675 	spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags);
676 
677 	/* Release DMA buffers for client messages */
678 	ishtp_cl_free_dma_buf(ishtp_dev);
679 
680 	/* remove bus clients */
681 	spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
682 	list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list,
683 				 device_link) {
684 		if (warm_reset && cl_device->reference_count)
685 			continue;
686 
687 		list_del(&cl_device->device_link);
688 		spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
689 		ishtp_bus_remove_device(cl_device);
690 		spin_lock_irqsave(&ishtp_dev->device_list_lock, flags);
691 	}
692 	spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags);
693 
694 	/* Free all client structures */
695 	spin_lock_irqsave(&ishtp_dev->fw_clients_lock, flags);
696 	kfree(ishtp_dev->fw_clients);
697 	ishtp_dev->fw_clients = NULL;
698 	ishtp_dev->fw_clients_num = 0;
699 	ishtp_dev->fw_client_presentation_num = 0;
700 	ishtp_dev->fw_client_index = 0;
701 	bitmap_zero(ishtp_dev->fw_clients_map, ISHTP_CLIENTS_MAX);
702 	spin_unlock_irqrestore(&ishtp_dev->fw_clients_lock, flags);
703 }
704 EXPORT_SYMBOL(ishtp_bus_remove_all_clients);
705 
706 /**
707  * ishtp_reset_handler() - IPC reset handler
708  * @dev:	ishtp device
709  *
710  * ISHTP Handler for IPC_RESET notification
711  */
712 void ishtp_reset_handler(struct ishtp_device *dev)
713 {
714 	unsigned long	flags;
715 
716 	/* Handle FW-initiated reset */
717 	dev->dev_state = ISHTP_DEV_RESETTING;
718 
719 	/* Clear BH processing queue - no further HBMs */
720 	spin_lock_irqsave(&dev->rd_msg_spinlock, flags);
721 	dev->rd_msg_fifo_head = dev->rd_msg_fifo_tail = 0;
722 	spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags);
723 
724 	/* Handle ISH FW reset against upper layers */
725 	ishtp_bus_remove_all_clients(dev, true);
726 }
727 EXPORT_SYMBOL(ishtp_reset_handler);
728 
729 /**
730  * ishtp_reset_compl_handler() - Reset completion handler
731  * @dev:	ishtp device
732  *
733  * ISHTP handler for IPC_RESET sequence completion to start
734  * host message bus start protocol sequence.
735  */
736 void ishtp_reset_compl_handler(struct ishtp_device *dev)
737 {
738 	dev->dev_state = ISHTP_DEV_INIT_CLIENTS;
739 	dev->hbm_state = ISHTP_HBM_START;
740 	ishtp_hbm_start_req(dev);
741 }
742 EXPORT_SYMBOL(ishtp_reset_compl_handler);
743 
744 /**
745  * ishtp_use_dma_transfer() - Function to use DMA
746  *
747  * This interface is used to enable usage of DMA
748  *
749  * Return non zero if DMA can be enabled
750  */
751 int ishtp_use_dma_transfer(void)
752 {
753 	return ishtp_use_dma;
754 }
755 
756 /**
757  * ishtp_bus_register() - Function to register bus
758  *
759  * This register ishtp bus
760  *
761  * Return: Return output of bus_register
762  */
763 static int  __init ishtp_bus_register(void)
764 {
765 	return bus_register(&ishtp_cl_bus_type);
766 }
767 
768 /**
769  * ishtp_bus_unregister() - Function to unregister bus
770  *
771  * This unregister ishtp bus
772  */
773 static void __exit ishtp_bus_unregister(void)
774 {
775 	bus_unregister(&ishtp_cl_bus_type);
776 }
777 
778 module_init(ishtp_bus_register);
779 module_exit(ishtp_bus_unregister);
780 
781 MODULE_LICENSE("GPL");
782