2 * Intel Management Engine Interface (Intel MEI) Linux driver
3 * Copyright (c) 2012-2013, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include <linux/module.h>
17 #include <linux/device.h>
18 #include <linux/kernel.h>
19 #include <linux/sched/signal.h>
20 #include <linux/init.h>
21 #include <linux/errno.h>
22 #include <linux/slab.h>
23 #include <linux/mutex.h>
24 #include <linux/interrupt.h>
25 #include <linux/mei_cl_bus.h>
30 #define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver)
31 #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
34 * __mei_cl_send - internal client send (write)
37 * @buf: buffer to send
38 * @length: buffer length
41 * Return: written size bytes or < 0 on error
43 ssize_t
__mei_cl_send(struct mei_cl
*cl
, u8
*buf
, size_t length
,
46 struct mei_device
*bus
;
50 if (WARN_ON(!cl
|| !cl
->dev
))
55 mutex_lock(&bus
->device_lock
);
56 if (bus
->dev_state
!= MEI_DEV_ENABLED
) {
61 if (!mei_cl_is_connected(cl
)) {
66 /* Check if we have an ME client device */
67 if (!mei_me_cl_is_active(cl
->me_cl
)) {
72 if (length
> mei_cl_mtu(cl
)) {
77 cb
= mei_cl_alloc_cb(cl
, length
, MEI_FOP_WRITE
, NULL
);
83 cb
->internal
= !!(mode
& MEI_CL_IO_TX_INTERNAL
);
84 cb
->blocking
= !!(mode
& MEI_CL_IO_TX_BLOCKING
);
85 memcpy(cb
->buf
.data
, buf
, length
);
87 rets
= mei_cl_write(cl
, cb
);
90 mutex_unlock(&bus
->device_lock
);
96 * __mei_cl_recv - internal client receive (read)
99 * @buf: buffer to receive
100 * @length: buffer length
103 * Return: read size in bytes of < 0 on error
105 ssize_t
__mei_cl_recv(struct mei_cl
*cl
, u8
*buf
, size_t length
,
108 struct mei_device
*bus
;
109 struct mei_cl_cb
*cb
;
112 bool nonblock
= !!(mode
& MEI_CL_IO_RX_NONBLOCK
);
114 if (WARN_ON(!cl
|| !cl
->dev
))
119 mutex_lock(&bus
->device_lock
);
120 if (bus
->dev_state
!= MEI_DEV_ENABLED
) {
125 cb
= mei_cl_read_cb(cl
, NULL
);
129 rets
= mei_cl_read_start(cl
, length
, NULL
);
130 if (rets
&& rets
!= -EBUSY
)
138 /* wait on event only if there is no other waiter */
139 /* synchronized under device mutex */
140 if (!waitqueue_active(&cl
->rx_wait
)) {
142 mutex_unlock(&bus
->device_lock
);
144 if (wait_event_interruptible(cl
->rx_wait
,
145 (!list_empty(&cl
->rd_completed
)) ||
146 (!mei_cl_is_connected(cl
)))) {
148 if (signal_pending(current
))
153 mutex_lock(&bus
->device_lock
);
155 if (!mei_cl_is_connected(cl
)) {
161 cb
= mei_cl_read_cb(cl
, NULL
);
173 r_length
= min_t(size_t, length
, cb
->buf_idx
);
174 memcpy(buf
, cb
->buf
.data
, r_length
);
180 mutex_unlock(&bus
->device_lock
);
186 * mei_cldev_send - me device send (write)
188 * @cldev: me client device
189 * @buf: buffer to send
190 * @length: buffer length
192 * Return: written size in bytes or < 0 on error
194 ssize_t
mei_cldev_send(struct mei_cl_device
*cldev
, u8
*buf
, size_t length
)
196 struct mei_cl
*cl
= cldev
->cl
;
198 return __mei_cl_send(cl
, buf
, length
, MEI_CL_IO_TX_BLOCKING
);
200 EXPORT_SYMBOL_GPL(mei_cldev_send
);
203 * mei_cldev_recv_nonblock - non block client receive (read)
205 * @cldev: me client device
206 * @buf: buffer to receive
207 * @length: buffer length
209 * Return: read size in bytes of < 0 on error
210 * -EAGAIN if function will block.
212 ssize_t
mei_cldev_recv_nonblock(struct mei_cl_device
*cldev
, u8
*buf
,
215 struct mei_cl
*cl
= cldev
->cl
;
217 return __mei_cl_recv(cl
, buf
, length
, MEI_CL_IO_RX_NONBLOCK
);
219 EXPORT_SYMBOL_GPL(mei_cldev_recv_nonblock
);
222 * mei_cldev_recv - client receive (read)
224 * @cldev: me client device
225 * @buf: buffer to receive
226 * @length: buffer length
228 * Return: read size in bytes of < 0 on error
230 ssize_t
mei_cldev_recv(struct mei_cl_device
*cldev
, u8
*buf
, size_t length
)
232 struct mei_cl
*cl
= cldev
->cl
;
234 return __mei_cl_recv(cl
, buf
, length
, 0);
236 EXPORT_SYMBOL_GPL(mei_cldev_recv
);
239 * mei_cl_bus_rx_work - dispatch rx event for a bus device
243 static void mei_cl_bus_rx_work(struct work_struct
*work
)
245 struct mei_cl_device
*cldev
;
246 struct mei_device
*bus
;
248 cldev
= container_of(work
, struct mei_cl_device
, rx_work
);
255 mutex_lock(&bus
->device_lock
);
256 mei_cl_read_start(cldev
->cl
, mei_cl_mtu(cldev
->cl
), NULL
);
257 mutex_unlock(&bus
->device_lock
);
261 * mei_cl_bus_notif_work - dispatch FW notif event for a bus device
265 static void mei_cl_bus_notif_work(struct work_struct
*work
)
267 struct mei_cl_device
*cldev
;
269 cldev
= container_of(work
, struct mei_cl_device
, notif_work
);
272 cldev
->notif_cb(cldev
);
276 * mei_cl_bus_notify_event - schedule notify cb on bus client
280 * Return: true if event was scheduled
281 * false if the client is not waiting for event
283 bool mei_cl_bus_notify_event(struct mei_cl
*cl
)
285 struct mei_cl_device
*cldev
= cl
->cldev
;
287 if (!cldev
|| !cldev
->notif_cb
)
293 schedule_work(&cldev
->notif_work
);
295 cl
->notify_ev
= false;
301 * mei_cl_bus_rx_event - schedule rx event
305 * Return: true if event was scheduled
306 * false if the client is not waiting for event
308 bool mei_cl_bus_rx_event(struct mei_cl
*cl
)
310 struct mei_cl_device
*cldev
= cl
->cldev
;
312 if (!cldev
|| !cldev
->rx_cb
)
315 schedule_work(&cldev
->rx_work
);
321 * mei_cldev_register_rx_cb - register Rx event callback
323 * @cldev: me client devices
324 * @rx_cb: callback function
326 * Return: 0 on success
327 * -EALREADY if an callback is already registered
330 int mei_cldev_register_rx_cb(struct mei_cl_device
*cldev
, mei_cldev_cb_t rx_cb
)
332 struct mei_device
*bus
= cldev
->bus
;
340 cldev
->rx_cb
= rx_cb
;
341 INIT_WORK(&cldev
->rx_work
, mei_cl_bus_rx_work
);
343 mutex_lock(&bus
->device_lock
);
344 ret
= mei_cl_read_start(cldev
->cl
, mei_cl_mtu(cldev
->cl
), NULL
);
345 mutex_unlock(&bus
->device_lock
);
346 if (ret
&& ret
!= -EBUSY
)
351 EXPORT_SYMBOL_GPL(mei_cldev_register_rx_cb
);
354 * mei_cldev_register_notif_cb - register FW notification event callback
356 * @cldev: me client devices
357 * @notif_cb: callback function
359 * Return: 0 on success
360 * -EALREADY if an callback is already registered
363 int mei_cldev_register_notif_cb(struct mei_cl_device
*cldev
,
364 mei_cldev_cb_t notif_cb
)
366 struct mei_device
*bus
= cldev
->bus
;
375 cldev
->notif_cb
= notif_cb
;
376 INIT_WORK(&cldev
->notif_work
, mei_cl_bus_notif_work
);
378 mutex_lock(&bus
->device_lock
);
379 ret
= mei_cl_notify_request(cldev
->cl
, NULL
, 1);
380 mutex_unlock(&bus
->device_lock
);
386 EXPORT_SYMBOL_GPL(mei_cldev_register_notif_cb
);
389 * mei_cldev_get_drvdata - driver data getter
391 * @cldev: mei client device
393 * Return: driver private data
395 void *mei_cldev_get_drvdata(const struct mei_cl_device
*cldev
)
397 return dev_get_drvdata(&cldev
->dev
);
399 EXPORT_SYMBOL_GPL(mei_cldev_get_drvdata
);
402 * mei_cldev_set_drvdata - driver data setter
404 * @cldev: mei client device
405 * @data: data to store
407 void mei_cldev_set_drvdata(struct mei_cl_device
*cldev
, void *data
)
409 dev_set_drvdata(&cldev
->dev
, data
);
411 EXPORT_SYMBOL_GPL(mei_cldev_set_drvdata
);
414 * mei_cldev_uuid - return uuid of the underlying me client
416 * @cldev: mei client device
418 * Return: me client uuid
420 const uuid_le
*mei_cldev_uuid(const struct mei_cl_device
*cldev
)
422 return mei_me_cl_uuid(cldev
->me_cl
);
424 EXPORT_SYMBOL_GPL(mei_cldev_uuid
);
427 * mei_cldev_ver - return protocol version of the underlying me client
429 * @cldev: mei client device
431 * Return: me client protocol version
433 u8
mei_cldev_ver(const struct mei_cl_device
*cldev
)
435 return mei_me_cl_ver(cldev
->me_cl
);
437 EXPORT_SYMBOL_GPL(mei_cldev_ver
);
440 * mei_cldev_enabled - check whether the device is enabled
442 * @cldev: mei client device
444 * Return: true if me client is initialized and connected
446 bool mei_cldev_enabled(struct mei_cl_device
*cldev
)
448 return mei_cl_is_connected(cldev
->cl
);
450 EXPORT_SYMBOL_GPL(mei_cldev_enabled
);
453 * mei_cldev_enable - enable me client device
454 * create connection with me client
456 * @cldev: me client device
458 * Return: 0 on success and < 0 on error
460 int mei_cldev_enable(struct mei_cl_device
*cldev
)
462 struct mei_device
*bus
= cldev
->bus
;
468 if (cl
->state
== MEI_FILE_UNINITIALIZED
) {
469 mutex_lock(&bus
->device_lock
);
470 ret
= mei_cl_link(cl
);
471 mutex_unlock(&bus
->device_lock
);
474 /* update pointers */
478 mutex_lock(&bus
->device_lock
);
479 if (mei_cl_is_connected(cl
)) {
484 if (!mei_me_cl_is_active(cldev
->me_cl
)) {
485 dev_err(&cldev
->dev
, "me client is not active\n");
490 ret
= mei_cl_connect(cl
, cldev
->me_cl
, NULL
);
492 dev_err(&cldev
->dev
, "cannot connect\n");
495 mutex_unlock(&bus
->device_lock
);
499 EXPORT_SYMBOL_GPL(mei_cldev_enable
);
502 * mei_cldev_unregister_callbacks - internal wrapper for unregistering
505 * @cldev: client device
507 static void mei_cldev_unregister_callbacks(struct mei_cl_device
*cldev
)
510 cancel_work_sync(&cldev
->rx_work
);
514 if (cldev
->notif_cb
) {
515 cancel_work_sync(&cldev
->notif_work
);
516 cldev
->notif_cb
= NULL
;
521 * mei_cldev_disable - disable me client device
522 * disconnect form the me client
524 * @cldev: me client device
526 * Return: 0 on success and < 0 on error
528 int mei_cldev_disable(struct mei_cl_device
*cldev
)
530 struct mei_device
*bus
;
541 mei_cldev_unregister_callbacks(cldev
);
543 mutex_lock(&bus
->device_lock
);
545 if (!mei_cl_is_connected(cl
)) {
546 dev_dbg(bus
->dev
, "Already disconnected\n");
551 err
= mei_cl_disconnect(cl
);
553 dev_err(bus
->dev
, "Could not disconnect from the ME client\n");
556 /* Flush queues and remove any pending read */
557 mei_cl_flush_queues(cl
, NULL
);
560 mutex_unlock(&bus
->device_lock
);
563 EXPORT_SYMBOL_GPL(mei_cldev_disable
);
566 * mei_cl_bus_module_get - acquire module of the underlying
571 * Return: true on success; false if the module was removed.
573 bool mei_cl_bus_module_get(struct mei_cl
*cl
)
575 struct mei_cl_device
*cldev
= cl
->cldev
;
580 return try_module_get(cldev
->bus
->dev
->driver
->owner
);
584 * mei_cl_bus_module_put - release the underlying hw module.
588 void mei_cl_bus_module_put(struct mei_cl
*cl
)
590 struct mei_cl_device
*cldev
= cl
->cldev
;
593 module_put(cldev
->bus
->dev
->driver
->owner
);
597 * mei_cl_device_find - find matching entry in the driver id table
599 * @cldev: me client device
600 * @cldrv: me client driver
602 * Return: id on success; NULL if no id is matching
605 struct mei_cl_device_id
*mei_cl_device_find(struct mei_cl_device
*cldev
,
606 struct mei_cl_driver
*cldrv
)
608 const struct mei_cl_device_id
*id
;
613 uuid
= mei_me_cl_uuid(cldev
->me_cl
);
614 version
= mei_me_cl_ver(cldev
->me_cl
);
616 id
= cldrv
->id_table
;
617 while (uuid_le_cmp(NULL_UUID_LE
, id
->uuid
)) {
618 if (!uuid_le_cmp(*uuid
, id
->uuid
)) {
622 if (strncmp(cldev
->name
, id
->name
,
626 if (id
->version
!= MEI_CL_VERSION_ANY
)
627 if (id
->version
!= version
)
640 * mei_cl_device_match - device match function
645 * Return: 1 if matching device was found 0 otherwise
647 static int mei_cl_device_match(struct device
*dev
, struct device_driver
*drv
)
649 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
650 struct mei_cl_driver
*cldrv
= to_mei_cl_driver(drv
);
651 const struct mei_cl_device_id
*found_id
;
656 if (!cldev
->do_match
)
659 if (!cldrv
|| !cldrv
->id_table
)
662 found_id
= mei_cl_device_find(cldev
, cldrv
);
670 * mei_cl_device_probe - bus probe function
674 * Return: 0 on success; < 0 otherwise
676 static int mei_cl_device_probe(struct device
*dev
)
678 struct mei_cl_device
*cldev
;
679 struct mei_cl_driver
*cldrv
;
680 const struct mei_cl_device_id
*id
;
683 cldev
= to_mei_cl_device(dev
);
684 cldrv
= to_mei_cl_driver(dev
->driver
);
689 if (!cldrv
|| !cldrv
->probe
)
692 id
= mei_cl_device_find(cldev
, cldrv
);
696 ret
= cldrv
->probe(cldev
, id
);
700 __module_get(THIS_MODULE
);
705 * mei_cl_device_remove - remove device from the bus
709 * Return: 0 on success; < 0 otherwise
711 static int mei_cl_device_remove(struct device
*dev
)
713 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
714 struct mei_cl_driver
*cldrv
;
717 if (!cldev
|| !dev
->driver
)
720 cldrv
= to_mei_cl_driver(dev
->driver
);
722 ret
= cldrv
->remove(cldev
);
724 mei_cldev_unregister_callbacks(cldev
);
726 module_put(THIS_MODULE
);
732 static ssize_t
name_show(struct device
*dev
, struct device_attribute
*a
,
735 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
737 return scnprintf(buf
, PAGE_SIZE
, "%s", cldev
->name
);
739 static DEVICE_ATTR_RO(name
);
741 static ssize_t
uuid_show(struct device
*dev
, struct device_attribute
*a
,
744 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
745 const uuid_le
*uuid
= mei_me_cl_uuid(cldev
->me_cl
);
747 return scnprintf(buf
, PAGE_SIZE
, "%pUl", uuid
);
749 static DEVICE_ATTR_RO(uuid
);
751 static ssize_t
version_show(struct device
*dev
, struct device_attribute
*a
,
754 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
755 u8 version
= mei_me_cl_ver(cldev
->me_cl
);
757 return scnprintf(buf
, PAGE_SIZE
, "%02X", version
);
759 static DEVICE_ATTR_RO(version
);
761 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*a
,
764 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
765 const uuid_le
*uuid
= mei_me_cl_uuid(cldev
->me_cl
);
766 u8 version
= mei_me_cl_ver(cldev
->me_cl
);
768 return scnprintf(buf
, PAGE_SIZE
, "mei:%s:%pUl:%02X:",
769 cldev
->name
, uuid
, version
);
771 static DEVICE_ATTR_RO(modalias
);
773 static struct attribute
*mei_cldev_attrs
[] = {
776 &dev_attr_version
.attr
,
777 &dev_attr_modalias
.attr
,
780 ATTRIBUTE_GROUPS(mei_cldev
);
783 * mei_cl_device_uevent - me client bus uevent handler
786 * @env: uevent kobject
788 * Return: 0 on success -ENOMEM on when add_uevent_var fails
790 static int mei_cl_device_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
792 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
793 const uuid_le
*uuid
= mei_me_cl_uuid(cldev
->me_cl
);
794 u8 version
= mei_me_cl_ver(cldev
->me_cl
);
796 if (add_uevent_var(env
, "MEI_CL_VERSION=%d", version
))
799 if (add_uevent_var(env
, "MEI_CL_UUID=%pUl", uuid
))
802 if (add_uevent_var(env
, "MEI_CL_NAME=%s", cldev
->name
))
805 if (add_uevent_var(env
, "MODALIAS=mei:%s:%pUl:%02X:",
806 cldev
->name
, uuid
, version
))
812 static struct bus_type mei_cl_bus_type
= {
814 .dev_groups
= mei_cldev_groups
,
815 .match
= mei_cl_device_match
,
816 .probe
= mei_cl_device_probe
,
817 .remove
= mei_cl_device_remove
,
818 .uevent
= mei_cl_device_uevent
,
821 static struct mei_device
*mei_dev_bus_get(struct mei_device
*bus
)
824 get_device(bus
->dev
);
829 static void mei_dev_bus_put(struct mei_device
*bus
)
832 put_device(bus
->dev
);
835 static void mei_cl_bus_dev_release(struct device
*dev
)
837 struct mei_cl_device
*cldev
= to_mei_cl_device(dev
);
842 mei_me_cl_put(cldev
->me_cl
);
843 mei_dev_bus_put(cldev
->bus
);
848 static const struct device_type mei_cl_device_type
= {
849 .release
= mei_cl_bus_dev_release
,
853 * mei_cl_bus_set_name - set device name for me client device
855 * @cldev: me client device
857 static inline void mei_cl_bus_set_name(struct mei_cl_device
*cldev
)
859 dev_set_name(&cldev
->dev
, "mei:%s:%pUl:%02X",
861 mei_me_cl_uuid(cldev
->me_cl
),
862 mei_me_cl_ver(cldev
->me_cl
));
866 * mei_cl_bus_dev_alloc - initialize and allocate mei client device
871 * Return: allocated device structur or NULL on allocation failure
873 static struct mei_cl_device
*mei_cl_bus_dev_alloc(struct mei_device
*bus
,
874 struct mei_me_client
*me_cl
)
876 struct mei_cl_device
*cldev
;
879 cldev
= kzalloc(sizeof(struct mei_cl_device
), GFP_KERNEL
);
883 cl
= mei_cl_allocate(bus
);
889 device_initialize(&cldev
->dev
);
890 cldev
->dev
.parent
= bus
->dev
;
891 cldev
->dev
.bus
= &mei_cl_bus_type
;
892 cldev
->dev
.type
= &mei_cl_device_type
;
893 cldev
->bus
= mei_dev_bus_get(bus
);
894 cldev
->me_cl
= mei_me_cl_get(me_cl
);
896 mei_cl_bus_set_name(cldev
);
898 INIT_LIST_HEAD(&cldev
->bus_list
);
904 * mei_cl_dev_setup - setup me client device
905 * run fix up routines and set the device name
908 * @cldev: me client device
910 * Return: true if the device is eligible for enumeration
912 static bool mei_cl_bus_dev_setup(struct mei_device
*bus
,
913 struct mei_cl_device
*cldev
)
916 mei_cl_bus_dev_fixup(cldev
);
918 /* the device name can change during fix up */
920 mei_cl_bus_set_name(cldev
);
922 return cldev
->do_match
== 1;
926 * mei_cl_bus_dev_add - add me client devices
928 * @cldev: me client device
930 * Return: 0 on success; < 0 on failre
932 static int mei_cl_bus_dev_add(struct mei_cl_device
*cldev
)
936 dev_dbg(cldev
->bus
->dev
, "adding %pUL:%02X\n",
937 mei_me_cl_uuid(cldev
->me_cl
),
938 mei_me_cl_ver(cldev
->me_cl
));
939 ret
= device_add(&cldev
->dev
);
947 * mei_cl_bus_dev_stop - stop the driver
949 * @cldev: me client device
951 static void mei_cl_bus_dev_stop(struct mei_cl_device
*cldev
)
954 device_release_driver(&cldev
->dev
);
958 * mei_cl_bus_dev_destroy - destroy me client devices object
960 * @cldev: me client device
962 * Locking: called under "dev->cl_bus_lock" lock
964 static void mei_cl_bus_dev_destroy(struct mei_cl_device
*cldev
)
967 WARN_ON(!mutex_is_locked(&cldev
->bus
->cl_bus_lock
));
969 if (!cldev
->is_added
)
972 device_del(&cldev
->dev
);
974 list_del_init(&cldev
->bus_list
);
977 put_device(&cldev
->dev
);
981 * mei_cl_bus_remove_device - remove a devices form the bus
983 * @cldev: me client device
985 static void mei_cl_bus_remove_device(struct mei_cl_device
*cldev
)
987 mei_cl_bus_dev_stop(cldev
);
988 mei_cl_bus_dev_destroy(cldev
);
992 * mei_cl_bus_remove_devices - remove all devices form the bus
996 void mei_cl_bus_remove_devices(struct mei_device
*bus
)
998 struct mei_cl_device
*cldev
, *next
;
1000 mutex_lock(&bus
->cl_bus_lock
);
1001 list_for_each_entry_safe(cldev
, next
, &bus
->device_list
, bus_list
)
1002 mei_cl_bus_remove_device(cldev
);
1003 mutex_unlock(&bus
->cl_bus_lock
);
1008 * mei_cl_bus_dev_init - allocate and initializes an mei client devices
1009 * based on me client
1014 * Locking: called under "dev->cl_bus_lock" lock
1016 static void mei_cl_bus_dev_init(struct mei_device
*bus
,
1017 struct mei_me_client
*me_cl
)
1019 struct mei_cl_device
*cldev
;
1021 WARN_ON(!mutex_is_locked(&bus
->cl_bus_lock
));
1023 dev_dbg(bus
->dev
, "initializing %pUl", mei_me_cl_uuid(me_cl
));
1025 if (me_cl
->bus_added
)
1028 cldev
= mei_cl_bus_dev_alloc(bus
, me_cl
);
1032 me_cl
->bus_added
= true;
1033 list_add_tail(&cldev
->bus_list
, &bus
->device_list
);
1038 * mei_cl_bus_rescan - scan me clients list and add create
1039 * devices for eligible clients
1043 static void mei_cl_bus_rescan(struct mei_device
*bus
)
1045 struct mei_cl_device
*cldev
, *n
;
1046 struct mei_me_client
*me_cl
;
1048 mutex_lock(&bus
->cl_bus_lock
);
1050 down_read(&bus
->me_clients_rwsem
);
1051 list_for_each_entry(me_cl
, &bus
->me_clients
, list
)
1052 mei_cl_bus_dev_init(bus
, me_cl
);
1053 up_read(&bus
->me_clients_rwsem
);
1055 list_for_each_entry_safe(cldev
, n
, &bus
->device_list
, bus_list
) {
1057 if (!mei_me_cl_is_active(cldev
->me_cl
)) {
1058 mei_cl_bus_remove_device(cldev
);
1062 if (cldev
->is_added
)
1065 if (mei_cl_bus_dev_setup(bus
, cldev
))
1066 mei_cl_bus_dev_add(cldev
);
1068 list_del_init(&cldev
->bus_list
);
1069 put_device(&cldev
->dev
);
1072 mutex_unlock(&bus
->cl_bus_lock
);
1074 dev_dbg(bus
->dev
, "rescan end");
1077 void mei_cl_bus_rescan_work(struct work_struct
*work
)
1079 struct mei_device
*bus
=
1080 container_of(work
, struct mei_device
, bus_rescan_work
);
1082 mei_cl_bus_rescan(bus
);
1085 int __mei_cldev_driver_register(struct mei_cl_driver
*cldrv
,
1086 struct module
*owner
)
1090 cldrv
->driver
.name
= cldrv
->name
;
1091 cldrv
->driver
.owner
= owner
;
1092 cldrv
->driver
.bus
= &mei_cl_bus_type
;
1094 err
= driver_register(&cldrv
->driver
);
1098 pr_debug("mei: driver [%s] registered\n", cldrv
->driver
.name
);
1102 EXPORT_SYMBOL_GPL(__mei_cldev_driver_register
);
1104 void mei_cldev_driver_unregister(struct mei_cl_driver
*cldrv
)
1106 driver_unregister(&cldrv
->driver
);
1108 pr_debug("mei: driver [%s] unregistered\n", cldrv
->driver
.name
);
1110 EXPORT_SYMBOL_GPL(mei_cldev_driver_unregister
);
1113 int __init
mei_cl_bus_init(void)
1115 return bus_register(&mei_cl_bus_type
);
1118 void __exit
mei_cl_bus_exit(void)
1120 bus_unregister(&mei_cl_bus_type
);