.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ISHTP bus driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | 6 | */ |
---|
15 | 7 | |
---|
16 | 8 | #include <linux/module.h> |
---|
.. | .. |
---|
119 | 111 | * Return: This returns IPC send message status. |
---|
120 | 112 | */ |
---|
121 | 113 | int ishtp_write_message(struct ishtp_device *dev, struct ishtp_msg_hdr *hdr, |
---|
122 | | - unsigned char *buf) |
---|
| 114 | + void *buf) |
---|
123 | 115 | { |
---|
124 | 116 | return ishtp_send_msg(dev, hdr, buf, NULL, NULL); |
---|
125 | 117 | } |
---|
.. | .. |
---|
133 | 125 | * |
---|
134 | 126 | * Return: fw client index or -ENOENT if not found |
---|
135 | 127 | */ |
---|
136 | | -int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const uuid_le *uuid) |
---|
| 128 | +int ishtp_fw_cl_by_uuid(struct ishtp_device *dev, const guid_t *uuid) |
---|
137 | 129 | { |
---|
138 | | - int i, res = -ENOENT; |
---|
| 130 | + unsigned int i; |
---|
139 | 131 | |
---|
140 | 132 | 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 | | - } |
---|
| 133 | + if (guid_equal(uuid, &dev->fw_clients[i].props.protocol_name)) |
---|
| 134 | + return i; |
---|
146 | 135 | } |
---|
147 | | - return res; |
---|
| 136 | + return -ENOENT; |
---|
148 | 137 | } |
---|
149 | 138 | EXPORT_SYMBOL(ishtp_fw_cl_by_uuid); |
---|
| 139 | + |
---|
| 140 | +/** |
---|
| 141 | + * ishtp_fw_cl_get_client() - return client information to client |
---|
| 142 | + * @dev: the ishtp device structure |
---|
| 143 | + * @uuid: uuid of the client to search |
---|
| 144 | + * |
---|
| 145 | + * Search firmware client using UUID and reture related client information. |
---|
| 146 | + * |
---|
| 147 | + * Return: pointer of client information on success, NULL on failure. |
---|
| 148 | + */ |
---|
| 149 | +struct ishtp_fw_client *ishtp_fw_cl_get_client(struct ishtp_device *dev, |
---|
| 150 | + const guid_t *uuid) |
---|
| 151 | +{ |
---|
| 152 | + int i; |
---|
| 153 | + unsigned long flags; |
---|
| 154 | + |
---|
| 155 | + spin_lock_irqsave(&dev->fw_clients_lock, flags); |
---|
| 156 | + i = ishtp_fw_cl_by_uuid(dev, uuid); |
---|
| 157 | + spin_unlock_irqrestore(&dev->fw_clients_lock, flags); |
---|
| 158 | + if (i < 0 || dev->fw_clients[i].props.fixed_address) |
---|
| 159 | + return NULL; |
---|
| 160 | + |
---|
| 161 | + return &dev->fw_clients[i]; |
---|
| 162 | +} |
---|
| 163 | +EXPORT_SYMBOL(ishtp_fw_cl_get_client); |
---|
| 164 | + |
---|
| 165 | +/** |
---|
| 166 | + * ishtp_get_fw_client_id() - Get fw client id |
---|
| 167 | + * |
---|
| 168 | + * This interface is used to reset HW get FW client id. |
---|
| 169 | + * |
---|
| 170 | + * Return: firmware client id. |
---|
| 171 | + */ |
---|
| 172 | +int ishtp_get_fw_client_id(struct ishtp_fw_client *fw_client) |
---|
| 173 | +{ |
---|
| 174 | + return fw_client->client_id; |
---|
| 175 | +} |
---|
| 176 | +EXPORT_SYMBOL(ishtp_get_fw_client_id); |
---|
150 | 177 | |
---|
151 | 178 | /** |
---|
152 | 179 | * ishtp_fw_cl_by_id() - return index to fw_clients for client_id |
---|
.. | .. |
---|
195 | 222 | return -ENODEV; |
---|
196 | 223 | |
---|
197 | 224 | return driver->probe(device); |
---|
| 225 | +} |
---|
| 226 | + |
---|
| 227 | +/** |
---|
| 228 | + * ishtp_cl_bus_match() - Bus match() callback |
---|
| 229 | + * @dev: the device structure |
---|
| 230 | + * @drv: the driver structure |
---|
| 231 | + * |
---|
| 232 | + * This is a bus match callback, called when a new ishtp_cl_device is |
---|
| 233 | + * registered during ishtp bus client enumeration. Use the guid_t in |
---|
| 234 | + * drv and dev to decide whether they match or not. |
---|
| 235 | + * |
---|
| 236 | + * Return: 1 if dev & drv matches, 0 otherwise. |
---|
| 237 | + */ |
---|
| 238 | +static int ishtp_cl_bus_match(struct device *dev, struct device_driver *drv) |
---|
| 239 | +{ |
---|
| 240 | + struct ishtp_cl_device *device = to_ishtp_cl_device(dev); |
---|
| 241 | + struct ishtp_cl_driver *driver = to_ishtp_cl_driver(drv); |
---|
| 242 | + |
---|
| 243 | + return guid_equal(driver->guid, |
---|
| 244 | + &device->fw_client->props.protocol_name); |
---|
198 | 245 | } |
---|
199 | 246 | |
---|
200 | 247 | /** |
---|
.. | .. |
---|
350 | 397 | .name = "ishtp", |
---|
351 | 398 | .dev_groups = ishtp_cl_dev_groups, |
---|
352 | 399 | .probe = ishtp_cl_device_probe, |
---|
| 400 | + .match = ishtp_cl_bus_match, |
---|
353 | 401 | .remove = ishtp_cl_device_remove, |
---|
354 | 402 | .pm = &ishtp_cl_bus_dev_pm_ops, |
---|
355 | 403 | .uevent = ishtp_cl_uevent, |
---|
.. | .. |
---|
376 | 424 | * Return: ishtp_cl_device pointer or NULL on failure |
---|
377 | 425 | */ |
---|
378 | 426 | static struct ishtp_cl_device *ishtp_bus_add_device(struct ishtp_device *dev, |
---|
379 | | - uuid_le uuid, char *name) |
---|
| 427 | + guid_t uuid, char *name) |
---|
380 | 428 | { |
---|
381 | 429 | struct ishtp_cl_device *device; |
---|
382 | 430 | int status; |
---|
.. | .. |
---|
442 | 490 | } |
---|
443 | 491 | |
---|
444 | 492 | /** |
---|
445 | | - * __ishtp_cl_driver_register() - Client driver register |
---|
| 493 | + * ishtp_cl_driver_register() - Client driver register |
---|
446 | 494 | * @driver: the client driver instance |
---|
447 | 495 | * @owner: Owner of this driver module |
---|
448 | 496 | * |
---|
.. | .. |
---|
451 | 499 | * |
---|
452 | 500 | * Return: Return value of driver_register or -ENODEV if not ready |
---|
453 | 501 | */ |
---|
454 | | -int __ishtp_cl_driver_register(struct ishtp_cl_driver *driver, |
---|
455 | | - struct module *owner) |
---|
| 502 | +int ishtp_cl_driver_register(struct ishtp_cl_driver *driver, |
---|
| 503 | + struct module *owner) |
---|
456 | 504 | { |
---|
457 | | - int err; |
---|
458 | | - |
---|
459 | 505 | if (!ishtp_device_ready) |
---|
460 | 506 | return -ENODEV; |
---|
461 | 507 | |
---|
.. | .. |
---|
463 | 509 | driver->driver.owner = owner; |
---|
464 | 510 | driver->driver.bus = &ishtp_cl_bus_type; |
---|
465 | 511 | |
---|
466 | | - err = driver_register(&driver->driver); |
---|
467 | | - if (err) |
---|
468 | | - return err; |
---|
469 | | - |
---|
470 | | - return 0; |
---|
| 512 | + return driver_register(&driver->driver); |
---|
471 | 513 | } |
---|
472 | | -EXPORT_SYMBOL(__ishtp_cl_driver_register); |
---|
| 514 | +EXPORT_SYMBOL(ishtp_cl_driver_register); |
---|
473 | 515 | |
---|
474 | 516 | /** |
---|
475 | 517 | * ishtp_cl_driver_unregister() - Client driver unregister |
---|
.. | .. |
---|
564 | 606 | EXPORT_SYMBOL(ishtp_put_device); |
---|
565 | 607 | |
---|
566 | 608 | /** |
---|
| 609 | + * ishtp_set_drvdata() - set client driver data |
---|
| 610 | + * @cl_device: client device instance |
---|
| 611 | + * @data: driver data need to be set |
---|
| 612 | + * |
---|
| 613 | + * Set client driver data to cl_device->driver_data. |
---|
| 614 | + */ |
---|
| 615 | +void ishtp_set_drvdata(struct ishtp_cl_device *cl_device, void *data) |
---|
| 616 | +{ |
---|
| 617 | + cl_device->driver_data = data; |
---|
| 618 | +} |
---|
| 619 | +EXPORT_SYMBOL(ishtp_set_drvdata); |
---|
| 620 | + |
---|
| 621 | +/** |
---|
| 622 | + * ishtp_get_drvdata() - get client driver data |
---|
| 623 | + * @cl_device: client device instance |
---|
| 624 | + * |
---|
| 625 | + * Get client driver data from cl_device->driver_data. |
---|
| 626 | + * |
---|
| 627 | + * Return: pointer of driver data |
---|
| 628 | + */ |
---|
| 629 | +void *ishtp_get_drvdata(struct ishtp_cl_device *cl_device) |
---|
| 630 | +{ |
---|
| 631 | + return cl_device->driver_data; |
---|
| 632 | +} |
---|
| 633 | +EXPORT_SYMBOL(ishtp_get_drvdata); |
---|
| 634 | + |
---|
| 635 | +/** |
---|
| 636 | + * ishtp_dev_to_cl_device() - get ishtp_cl_device instance from device instance |
---|
| 637 | + * @device: device instance |
---|
| 638 | + * |
---|
| 639 | + * Get ish_cl_device instance which embeds device instance in it. |
---|
| 640 | + * |
---|
| 641 | + * Return: pointer to ishtp_cl_device instance |
---|
| 642 | + */ |
---|
| 643 | +struct ishtp_cl_device *ishtp_dev_to_cl_device(struct device *device) |
---|
| 644 | +{ |
---|
| 645 | + return to_ishtp_cl_device(device); |
---|
| 646 | +} |
---|
| 647 | +EXPORT_SYMBOL(ishtp_dev_to_cl_device); |
---|
| 648 | + |
---|
| 649 | +/** |
---|
567 | 650 | * ishtp_bus_new_client() - Create a new client |
---|
568 | 651 | * @dev: ISHTP device instance |
---|
569 | 652 | * |
---|
.. | .. |
---|
577 | 660 | int i; |
---|
578 | 661 | char *dev_name; |
---|
579 | 662 | struct ishtp_cl_device *cl_device; |
---|
580 | | - uuid_le device_uuid; |
---|
| 663 | + guid_t device_uuid; |
---|
581 | 664 | |
---|
582 | 665 | /* |
---|
583 | 666 | * For all reported clients, create an unconnected client and add its |
---|
.. | .. |
---|
587 | 670 | */ |
---|
588 | 671 | i = dev->fw_client_presentation_num - 1; |
---|
589 | 672 | device_uuid = dev->fw_clients[i].props.protocol_name; |
---|
590 | | - dev_name = kasprintf(GFP_KERNEL, "{%pUL}", device_uuid.b); |
---|
| 673 | + dev_name = kasprintf(GFP_KERNEL, "{%pUL}", &device_uuid); |
---|
591 | 674 | if (!dev_name) |
---|
592 | 675 | return -ENOMEM; |
---|
593 | 676 | |
---|
.. | .. |
---|
758 | 841 | } |
---|
759 | 842 | |
---|
760 | 843 | /** |
---|
| 844 | + * ishtp_device() - Return device pointer |
---|
| 845 | + * |
---|
| 846 | + * This interface is used to return device pointer from ishtp_cl_device |
---|
| 847 | + * instance. |
---|
| 848 | + * |
---|
| 849 | + * Return: device *. |
---|
| 850 | + */ |
---|
| 851 | +struct device *ishtp_device(struct ishtp_cl_device *device) |
---|
| 852 | +{ |
---|
| 853 | + return &device->dev; |
---|
| 854 | +} |
---|
| 855 | +EXPORT_SYMBOL(ishtp_device); |
---|
| 856 | + |
---|
| 857 | +/** |
---|
| 858 | + * ishtp_get_pci_device() - Return PCI device dev pointer |
---|
| 859 | + * This interface is used to return PCI device pointer |
---|
| 860 | + * from ishtp_cl_device instance. |
---|
| 861 | + * |
---|
| 862 | + * Return: device *. |
---|
| 863 | + */ |
---|
| 864 | +struct device *ishtp_get_pci_device(struct ishtp_cl_device *device) |
---|
| 865 | +{ |
---|
| 866 | + return device->ishtp_dev->devc; |
---|
| 867 | +} |
---|
| 868 | +EXPORT_SYMBOL(ishtp_get_pci_device); |
---|
| 869 | + |
---|
| 870 | +/** |
---|
| 871 | + * ishtp_trace_callback() - Return trace callback |
---|
| 872 | + * |
---|
| 873 | + * This interface is used to return trace callback function pointer. |
---|
| 874 | + * |
---|
| 875 | + * Return: void *. |
---|
| 876 | + */ |
---|
| 877 | +void *ishtp_trace_callback(struct ishtp_cl_device *cl_device) |
---|
| 878 | +{ |
---|
| 879 | + return cl_device->ishtp_dev->print_log; |
---|
| 880 | +} |
---|
| 881 | +EXPORT_SYMBOL(ishtp_trace_callback); |
---|
| 882 | + |
---|
| 883 | +/** |
---|
| 884 | + * ish_hw_reset() - Call HW reset IPC callback |
---|
| 885 | + * |
---|
| 886 | + * This interface is used to reset HW in case of error. |
---|
| 887 | + * |
---|
| 888 | + * Return: value from IPC hw_reset callback |
---|
| 889 | + */ |
---|
| 890 | +int ish_hw_reset(struct ishtp_device *dev) |
---|
| 891 | +{ |
---|
| 892 | + return dev->ops->hw_reset(dev); |
---|
| 893 | +} |
---|
| 894 | +EXPORT_SYMBOL(ish_hw_reset); |
---|
| 895 | + |
---|
| 896 | +/** |
---|
761 | 897 | * ishtp_bus_register() - Function to register bus |
---|
762 | 898 | * |
---|
763 | 899 | * This register ishtp bus |
---|