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_get_client() - return client information to client 153 * @dev: the ishtp device structure 154 * @uuid: uuid of the client to search 155 * 156 * Search firmware client using UUID and reture related client information. 157 * 158 * Return: pointer of client information on success, NULL on failure. 159 */ 160 struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, 161 const uuid_le *uuid) 162 { 163 int i; 164 unsigned long flags; 165 166 spin_lock_irqsave(&dev->fw_clients_lock, flags); 167 i = ishtp_fw_cl_by_uuid(dev, uuid); 168 spin_unlock_irqrestore(&dev->fw_clients_lock, flags); 169 if (i < 0 || dev->fw_clients[i].props.fixed_address) 170 return NULL; 171 172 return &dev->fw_clients[i]; 173 } 174 EXPORT_SYMBOL(ishtp_fw_cl_get_client); 175 176 /** 177 * ishtp_fw_cl_by_id() - return index to fw_clients for client_id 178 * @dev: the ishtp device structure 179 * @client_id: fw client id to search 180 * 181 * Search firmware client using client id. 182 * 183 * Return: index on success, -ENOENT on failure. 184 */ 185 int ishtp_fw_cl_by_id(struct ishtp_device *dev, uint8_t client_id) 186 { 187 int i, res = -ENOENT; 188 unsigned long flags; 189 190 spin_lock_irqsave(&dev->fw_clients_lock, flags); 191 for (i = 0; i < dev->fw_clients_num; i++) { 192 if (dev->fw_clients[i].client_id == client_id) { 193 res = i; 194 break; 195 } 196 } 197 spin_unlock_irqrestore(&dev->fw_clients_lock, flags); 198 199 return res; 200 } 201 202 /** 203 * ishtp_cl_device_probe() - Bus probe() callback 204 * @dev: the device structure 205 * 206 * This is a bus probe callback and calls the drive probe function. 207 * 208 * Return: Return value from driver probe() call. 209 */ 210 static int ishtp_cl_device_probe(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) 216 return 0; 217 218 driver = to_ishtp_cl_driver(dev->driver); 219 if (!driver || !driver->probe) 220 return -ENODEV; 221 222 return driver->probe(device); 223 } 224 225 /** 226 * ishtp_cl_device_remove() - Bus remove() callback 227 * @dev: the device structure 228 * 229 * This is a bus remove callback and calls the drive remove function. 230 * Since the ISH driver model supports only built in, this is 231 * primarily can be called during pci driver init failure. 232 * 233 * Return: Return value from driver remove() call. 234 */ 235 static int ishtp_cl_device_remove(struct device *dev) 236 { 237 struct ishtp_cl_device *device = to_ishtp_cl_device(dev); 238 struct ishtp_cl_driver *driver; 239 240 if (!device || !dev->driver) 241 return 0; 242 243 if (device->event_cb) { 244 device->event_cb = NULL; 245 cancel_work_sync(&device->event_work); 246 } 247 248 driver = to_ishtp_cl_driver(dev->driver); 249 if (!driver->remove) { 250 dev->driver = NULL; 251 252 return 0; 253 } 254 255 return driver->remove(device); 256 } 257 258 /** 259 * ishtp_cl_device_suspend() - Bus suspend callback 260 * @dev: device 261 * 262 * Called during device suspend process. 263 * 264 * Return: Return value from driver suspend() call. 265 */ 266 static int ishtp_cl_device_suspend(struct device *dev) 267 { 268 struct ishtp_cl_device *device = to_ishtp_cl_device(dev); 269 struct ishtp_cl_driver *driver; 270 int ret = 0; 271 272 if (!device) 273 return 0; 274 275 driver = to_ishtp_cl_driver(dev->driver); 276 if (driver && driver->driver.pm) { 277 if (driver->driver.pm->suspend) 278 ret = driver->driver.pm->suspend(dev); 279 } 280 281 return ret; 282 } 283 284 /** 285 * ishtp_cl_device_resume() - Bus resume callback 286 * @dev: device 287 * 288 * Called during device resume process. 289 * 290 * Return: Return value from driver resume() call. 291 */ 292 static int ishtp_cl_device_resume(struct device *dev) 293 { 294 struct ishtp_cl_device *device = to_ishtp_cl_device(dev); 295 struct ishtp_cl_driver *driver; 296 int ret = 0; 297 298 if (!device) 299 return 0; 300 301 /* 302 * When ISH needs hard reset, it is done asynchrnously, hence bus 303 * resume will be called before full ISH resume 304 */ 305 if (device->ishtp_dev->resume_flag) 306 return 0; 307 308 driver = to_ishtp_cl_driver(dev->driver); 309 if (driver && driver->driver.pm) { 310 if (driver->driver.pm->resume) 311 ret = driver->driver.pm->resume(dev); 312 } 313 314 return ret; 315 } 316 317 /** 318 * ishtp_cl_device_reset() - Reset callback 319 * @device: ishtp client device instance 320 * 321 * This is a callback when HW reset is done and the device need 322 * reinit. 323 * 324 * Return: Return value from driver reset() call. 325 */ 326 static int ishtp_cl_device_reset(struct ishtp_cl_device *device) 327 { 328 struct ishtp_cl_driver *driver; 329 int ret = 0; 330 331 device->event_cb = NULL; 332 cancel_work_sync(&device->event_work); 333 334 driver = to_ishtp_cl_driver(device->dev.driver); 335 if (driver && driver->reset) 336 ret = driver->reset(device); 337 338 return ret; 339 } 340 341 static ssize_t modalias_show(struct device *dev, struct device_attribute *a, 342 char *buf) 343 { 344 int len; 345 346 len = snprintf(buf, PAGE_SIZE, "ishtp:%s\n", dev_name(dev)); 347 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; 348 } 349 static DEVICE_ATTR_RO(modalias); 350 351 static struct attribute *ishtp_cl_dev_attrs[] = { 352 &dev_attr_modalias.attr, 353 NULL, 354 }; 355 ATTRIBUTE_GROUPS(ishtp_cl_dev); 356 357 static int ishtp_cl_uevent(struct device *dev, struct kobj_uevent_env *env) 358 { 359 if (add_uevent_var(env, "MODALIAS=ishtp:%s", dev_name(dev))) 360 return -ENOMEM; 361 return 0; 362 } 363 364 static const struct dev_pm_ops ishtp_cl_bus_dev_pm_ops = { 365 /* Suspend callbacks */ 366 .suspend = ishtp_cl_device_suspend, 367 .resume = ishtp_cl_device_resume, 368 /* Hibernate callbacks */ 369 .freeze = ishtp_cl_device_suspend, 370 .thaw = ishtp_cl_device_resume, 371 .restore = ishtp_cl_device_resume, 372 }; 373 374 static struct bus_type ishtp_cl_bus_type = { 375 .name = "ishtp", 376 .dev_groups = ishtp_cl_dev_groups, 377 .probe = ishtp_cl_device_probe, 378 .remove = ishtp_cl_device_remove, 379 .pm = &ishtp_cl_bus_dev_pm_ops, 380 .uevent = ishtp_cl_uevent, 381 }; 382 383 static void ishtp_cl_dev_release(struct device *dev) 384 { 385 kfree(to_ishtp_cl_device(dev)); 386 } 387 388 static const struct device_type ishtp_cl_device_type = { 389 .release = ishtp_cl_dev_release, 390 }; 391 392 /** 393 * ishtp_bus_add_device() - Function to create device on bus 394 * @dev: ishtp device 395 * @uuid: uuid of the client 396 * @name: Name of the client 397 * 398 * Allocate ISHTP bus client device, attach it to uuid 399 * and register with ISHTP bus. 400 * 401 * Return: ishtp_cl_device pointer or NULL on failure 402 */ 403 static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev, 404 uuid_le uuid, char *name) 405 { 406 struct ishtp_cl_device *device; 407 int status; 408 unsigned long flags; 409 410 spin_lock_irqsave(&dev->device_list_lock, flags); 411 list_for_each_entry(device, &dev->device_list, device_link) { 412 if (!strcmp(name, dev_name(&device->dev))) { 413 device->fw_client = &dev->fw_clients[ 414 dev->fw_client_presentation_num - 1]; 415 spin_unlock_irqrestore(&dev->device_list_lock, flags); 416 ishtp_cl_device_reset(device); 417 return device; 418 } 419 } 420 spin_unlock_irqrestore(&dev->device_list_lock, flags); 421 422 device = kzalloc(sizeof(struct ishtp_cl_device), GFP_KERNEL); 423 if (!device) 424 return NULL; 425 426 device->dev.parent = dev->devc; 427 device->dev.bus = &ishtp_cl_bus_type; 428 device->dev.type = &ishtp_cl_device_type; 429 device->ishtp_dev = dev; 430 431 device->fw_client = 432 &dev->fw_clients[dev->fw_client_presentation_num - 1]; 433 434 dev_set_name(&device->dev, "%s", name); 435 436 spin_lock_irqsave(&dev->device_list_lock, flags); 437 list_add_tail(&device->device_link, &dev->device_list); 438 spin_unlock_irqrestore(&dev->device_list_lock, flags); 439 440 status = device_register(&device->dev); 441 if (status) { 442 spin_lock_irqsave(&dev->device_list_lock, flags); 443 list_del(&device->device_link); 444 spin_unlock_irqrestore(&dev->device_list_lock, flags); 445 dev_err(dev->devc, "Failed to register ISHTP client device\n"); 446 put_device(&device->dev); 447 return NULL; 448 } 449 450 ishtp_device_ready = true; 451 452 return device; 453 } 454 455 /** 456 * ishtp_bus_remove_device() - Function to relase device on bus 457 * @device: client device instance 458 * 459 * This is a counterpart of ishtp_bus_add_device. 460 * Device is unregistered. 461 * the device structure is freed in 'ishtp_cl_dev_release' function 462 * Called only during error in pci driver init path. 463 */ 464 static void ishtp_bus_remove_device(struct ishtp_cl_device *device) 465 { 466 device_unregister(&device->dev); 467 } 468 469 /** 470 * __ishtp_cl_driver_register() - Client driver register 471 * @driver: the client driver instance 472 * @owner: Owner of this driver module 473 * 474 * Once a client driver is probed, it created a client 475 * instance and registers with the bus. 476 * 477 * Return: Return value of driver_register or -ENODEV if not ready 478 */ 479 int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, 480 struct module *owner) 481 { 482 int err; 483 484 if (!ishtp_device_ready) 485 return -ENODEV; 486 487 driver->driver.name = driver->name; 488 driver->driver.owner = owner; 489 driver->driver.bus = &ishtp_cl_bus_type; 490 491 err = driver_register(&driver->driver); 492 if (err) 493 return err; 494 495 return 0; 496 } 497 EXPORT_SYMBOL(__ishtp_cl_driver_register); 498 499 /** 500 * ishtp_cl_driver_unregister() - Client driver unregister 501 * @driver: the client driver instance 502 * 503 * Unregister client during device removal process. 504 */ 505 void ishtp_cl_driver_unregister(struct ishtp_cl_driver *driver) 506 { 507 driver_unregister(&driver->driver); 508 } 509 EXPORT_SYMBOL(ishtp_cl_driver_unregister); 510 511 /** 512 * ishtp_bus_event_work() - event work function 513 * @work: work struct pointer 514 * 515 * Once an event is received for a client this work 516 * function is called. If the device has registered a 517 * callback then the callback is called. 518 */ 519 static void ishtp_bus_event_work(struct work_struct *work) 520 { 521 struct ishtp_cl_device *device; 522 523 device = container_of(work, struct ishtp_cl_device, event_work); 524 525 if (device->event_cb) 526 device->event_cb(device); 527 } 528 529 /** 530 * ishtp_cl_bus_rx_event() - schedule event work 531 * @device: client device instance 532 * 533 * Once an event is received for a client this schedules 534 * a work function to process. 535 */ 536 void ishtp_cl_bus_rx_event(struct ishtp_cl_device *device) 537 { 538 if (!device || !device->event_cb) 539 return; 540 541 if (device->event_cb) 542 schedule_work(&device->event_work); 543 } 544 545 /** 546 * ishtp_register_event_cb() - Register callback 547 * @device: client device instance 548 * @event_cb: Event processor for an client 549 * 550 * Register a callback for events, called from client driver 551 * 552 * Return: Return 0 or -EALREADY if already registered 553 */ 554 int ishtp_register_event_cb(struct ishtp_cl_device *device, 555 void (*event_cb)(struct ishtp_cl_device *)) 556 { 557 if (device->event_cb) 558 return -EALREADY; 559 560 device->event_cb = event_cb; 561 INIT_WORK(&device->event_work, ishtp_bus_event_work); 562 563 return 0; 564 } 565 EXPORT_SYMBOL(ishtp_register_event_cb); 566 567 /** 568 * ishtp_get_device() - update usage count for the device 569 * @cl_device: client device instance 570 * 571 * Increment the usage count. The device can't be deleted 572 */ 573 void ishtp_get_device(struct ishtp_cl_device *cl_device) 574 { 575 cl_device->reference_count++; 576 } 577 EXPORT_SYMBOL(ishtp_get_device); 578 579 /** 580 * ishtp_put_device() - decrement usage count for the device 581 * @cl_device: client device instance 582 * 583 * Decrement the usage count. The device can be deleted is count = 0 584 */ 585 void ishtp_put_device(struct ishtp_cl_device *cl_device) 586 { 587 cl_device->reference_count--; 588 } 589 EXPORT_SYMBOL(ishtp_put_device); 590 591 /** 592 * ishtp_set_drvdata() - set client driver data 593 * @cl_device: client device instance 594 * @data: driver data need to be set 595 * 596 * Set client driver data to cl_device->driver_data. 597 */ 598 void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data) 599 { 600 cl_device->driver_data = data; 601 } 602 EXPORT_SYMBOL(ishtp_set_drvdata); 603 604 /** 605 * ishtp_get_drvdata() - get client driver data 606 * @cl_device: client device instance 607 * 608 * Get client driver data from cl_device->driver_data. 609 * 610 * Return: pointer of driver data 611 */ 612 void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device) 613 { 614 return cl_device->driver_data; 615 } 616 EXPORT_SYMBOL(ishtp_get_drvdata); 617 618 /** 619 * ishtp_bus_new_client() - Create a new client 620 * @dev: ISHTP device instance 621 * 622 * Once bus protocol enumerates a client, this is called 623 * to add a device for the client. 624 * 625 * Return: 0 on success or error code on failure 626 */ 627 int ishtp_bus_new_client(struct ishtp_device *dev) 628 { 629 int i; 630 char *dev_name; 631 struct ishtp_cl_device *cl_device; 632 uuid_le device_uuid; 633 634 /* 635 * For all reported clients, create an unconnected client and add its 636 * device to ISHTP bus. 637 * If appropriate driver has loaded, this will trigger its probe(). 638 * Otherwise, probe() will be called when driver is loaded 639 */ 640 i = dev->fw_client_presentation_num - 1; 641 device_uuid = dev->fw_clients[i].props.protocol_name; 642 dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b); 643 if (!dev_name) 644 return -ENOMEM; 645 646 cl_device = ishtp_bus_add_device(dev, device_uuid, dev_name); 647 if (!cl_device) { 648 kfree(dev_name); 649 return -ENOENT; 650 } 651 652 kfree(dev_name); 653 654 return 0; 655 } 656 657 /** 658 * ishtp_cl_device_bind() - bind a device 659 * @cl: ishtp client device 660 * 661 * Binds connected ishtp_cl to ISHTP bus device 662 * 663 * Return: 0 on success or fault code 664 */ 665 int ishtp_cl_device_bind(struct ishtp_cl *cl) 666 { 667 struct ishtp_cl_device *cl_device; 668 unsigned long flags; 669 int rv; 670 671 if (!cl->fw_client_id || cl->state != ISHTP_CL_CONNECTED) 672 return -EFAULT; 673 674 rv = -ENOENT; 675 spin_lock_irqsave(&cl->dev->device_list_lock, flags); 676 list_for_each_entry(cl_device, &cl->dev->device_list, 677 device_link) { 678 if (cl_device->fw_client->client_id == cl->fw_client_id) { 679 cl->device = cl_device; 680 rv = 0; 681 break; 682 } 683 } 684 spin_unlock_irqrestore(&cl->dev->device_list_lock, flags); 685 return rv; 686 } 687 688 /** 689 * ishtp_bus_remove_all_clients() - Remove all clients 690 * @ishtp_dev: ishtp device 691 * @warm_reset: Reset due to FW reset dure to errors or S3 suspend 692 * 693 * This is part of reset/remove flow. This function the main processing 694 * only targets error processing, if the FW has forced reset or 695 * error to remove connected clients. When warm reset the client devices are 696 * not removed. 697 */ 698 void ishtp_bus_remove_all_clients(struct ishtp_device *ishtp_dev, 699 bool warm_reset) 700 { 701 struct ishtp_cl_device *cl_device, *n; 702 struct ishtp_cl *cl; 703 unsigned long flags; 704 705 spin_lock_irqsave(&ishtp_dev->cl_list_lock, flags); 706 list_for_each_entry(cl, &ishtp_dev->cl_list, link) { 707 cl->state = ISHTP_CL_DISCONNECTED; 708 709 /* 710 * Wake any pending process. The waiter would check dev->state 711 * and determine that it's not enabled already, 712 * and will return error to its caller 713 */ 714 wake_up_interruptible(&cl->wait_ctrl_res); 715 716 /* Disband any pending read/write requests and free rb */ 717 ishtp_cl_flush_queues(cl); 718 719 /* Remove all free and in_process rings, both Rx and Tx */ 720 ishtp_cl_free_rx_ring(cl); 721 ishtp_cl_free_tx_ring(cl); 722 723 /* 724 * Free client and ISHTP bus client device structures 725 * don't free host client because it is part of the OS fd 726 * structure 727 */ 728 } 729 spin_unlock_irqrestore(&ishtp_dev->cl_list_lock, flags); 730 731 /* Release DMA buffers for client messages */ 732 ishtp_cl_free_dma_buf(ishtp_dev); 733 734 /* remove bus clients */ 735 spin_lock_irqsave(&ishtp_dev->device_list_lock, flags); 736 list_for_each_entry_safe(cl_device, n, &ishtp_dev->device_list, 737 device_link) { 738 if (warm_reset && cl_device->reference_count) 739 continue; 740 741 list_del(&cl_device->device_link); 742 spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags); 743 ishtp_bus_remove_device(cl_device); 744 spin_lock_irqsave(&ishtp_dev->device_list_lock, flags); 745 } 746 spin_unlock_irqrestore(&ishtp_dev->device_list_lock, flags); 747 748 /* Free all client structures */ 749 spin_lock_irqsave(&ishtp_dev->fw_clients_lock, flags); 750 kfree(ishtp_dev->fw_clients); 751 ishtp_dev->fw_clients = NULL; 752 ishtp_dev->fw_clients_num = 0; 753 ishtp_dev->fw_client_presentation_num = 0; 754 ishtp_dev->fw_client_index = 0; 755 bitmap_zero(ishtp_dev->fw_clients_map, ISHTP_CLIENTS_MAX); 756 spin_unlock_irqrestore(&ishtp_dev->fw_clients_lock, flags); 757 } 758 EXPORT_SYMBOL(ishtp_bus_remove_all_clients); 759 760 /** 761 * ishtp_reset_handler() - IPC reset handler 762 * @dev: ishtp device 763 * 764 * ISHTP Handler for IPC_RESET notification 765 */ 766 void ishtp_reset_handler(struct ishtp_device *dev) 767 { 768 unsigned long flags; 769 770 /* Handle FW-initiated reset */ 771 dev->dev_state = ISHTP_DEV_RESETTING; 772 773 /* Clear BH processing queue - no further HBMs */ 774 spin_lock_irqsave(&dev->rd_msg_spinlock, flags); 775 dev->rd_msg_fifo_head = dev->rd_msg_fifo_tail = 0; 776 spin_unlock_irqrestore(&dev->rd_msg_spinlock, flags); 777 778 /* Handle ISH FW reset against upper layers */ 779 ishtp_bus_remove_all_clients(dev, true); 780 } 781 EXPORT_SYMBOL(ishtp_reset_handler); 782 783 /** 784 * ishtp_reset_compl_handler() - Reset completion handler 785 * @dev: ishtp device 786 * 787 * ISHTP handler for IPC_RESET sequence completion to start 788 * host message bus start protocol sequence. 789 */ 790 void ishtp_reset_compl_handler(struct ishtp_device *dev) 791 { 792 dev->dev_state = ISHTP_DEV_INIT_CLIENTS; 793 dev->hbm_state = ISHTP_HBM_START; 794 ishtp_hbm_start_req(dev); 795 } 796 EXPORT_SYMBOL(ishtp_reset_compl_handler); 797 798 /** 799 * ishtp_use_dma_transfer() - Function to use DMA 800 * 801 * This interface is used to enable usage of DMA 802 * 803 * Return non zero if DMA can be enabled 804 */ 805 int ishtp_use_dma_transfer(void) 806 { 807 return ishtp_use_dma; 808 } 809 810 /** 811 * ishtp_bus_register() - Function to register bus 812 * 813 * This register ishtp bus 814 * 815 * Return: Return output of bus_register 816 */ 817 static int __init ishtp_bus_register(void) 818 { 819 return bus_register(&ishtp_cl_bus_type); 820 } 821 822 /** 823 * ishtp_bus_unregister() - Function to unregister bus 824 * 825 * This unregister ishtp bus 826 */ 827 static void __exit ishtp_bus_unregister(void) 828 { 829 bus_unregister(&ishtp_cl_bus_type); 830 } 831 832 module_init(ishtp_bus_register); 833 module_exit(ishtp_bus_unregister); 834 835 MODULE_LICENSE("GPL"); 836