From: Tomas Winkler <tomas.winkler@intel.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
Tomas Winkler <tomas.winkler@intel.com>
Subject: [char-misc-next 13/17] mei: bus: enable running fixup routines before device registration
Date: Sat, 13 Jun 2015 22:11:45 +0300 [thread overview]
Message-ID: <1434222709-10966-14-git-send-email-tomas.winkler@intel.com> (raw)
In-Reply-To: <1434222709-10966-1-git-send-email-tomas.winkler@intel.com>
We split the device registration to allocation and device struct
initialization , setup, and final registration.
This way we can run fixups and quirks during the setup stage on
an initialized device. If a fixup sets do_match flag to false
the device won't be registered on the bus.
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
---
drivers/misc/mei/bus-fixup.c | 30 +++++++++++++++
drivers/misc/mei/bus.c | 91 ++++++++++++++++++++++++++++++++++++--------
drivers/misc/mei/mei_dev.h | 2 +-
include/linux/mei_cl_bus.h | 4 ++
4 files changed, 111 insertions(+), 16 deletions(-)
diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index 9bd76cda1608..2c02a338f63b 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -20,12 +20,15 @@
#include <linux/moduleparam.h>
#include <linux/device.h>
#include <linux/slab.h>
+#include <linux/uuid.h>
#include <linux/mei_cl_bus.h>
#include "mei_dev.h"
#include "client.h"
+#define MEI_UUID_ANY NULL_UUID_LE
+
struct mei_nfc_cmd {
u8 command;
u8 status;
@@ -411,4 +414,31 @@ void mei_nfc_host_exit(struct mei_device *bus)
mutex_unlock(&bus->device_lock);
}
+#define MEI_FIXUP(_uuid, _hook) { _uuid, _hook }
+
+static struct mei_fixup {
+
+ const uuid_le uuid;
+ void (*hook)(struct mei_cl_device *cldev);
+} mei_fixups[] = {};
+
+/**
+ * mei_cl_dev_fixup - run fixup handlers
+ *
+ * @cldev: me client device
+ */
+void mei_cl_dev_fixup(struct mei_cl_device *cldev)
+{
+ struct mei_fixup *f;
+ const uuid_le *uuid = mei_me_cl_uuid(cldev->me_cl);
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(mei_fixups); i++) {
+
+ f = &mei_fixups[i];
+ if (uuid_le_cmp(f->uuid, MEI_UUID_ANY) == 0 ||
+ uuid_le_cmp(f->uuid, *uuid) == 0)
+ f->hook(cldev);
+ }
+}
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
index 592f2a1651bf..8ff824950597 100644
--- a/drivers/misc/mei/bus.c
+++ b/drivers/misc/mei/bus.c
@@ -435,6 +435,9 @@ static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
if (!cldev)
return 0;
+ if (!cldev->do_match)
+ return 0;
+
if (!cldrv || !cldrv->id_table)
return 0;
@@ -660,6 +663,76 @@ struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *bus,
return NULL;
}
+/**
+ * mei_cl_dev_alloc - initialize and allocate mei client device
+ *
+ * @bus: mei device
+ * @me_cl: me client
+ *
+ * Return: allocated device structur or NULL on allocation failure
+ */
+static struct mei_cl_device *mei_cl_dev_alloc(struct mei_device *bus,
+ struct mei_me_client *me_cl)
+{
+ struct mei_cl_device *cldev;
+
+ cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
+ if (!cldev)
+ return NULL;
+
+ device_initialize(&cldev->dev);
+ cldev->dev.parent = bus->dev;
+ cldev->dev.bus = &mei_cl_bus_type;
+ cldev->dev.type = &mei_cl_device_type;
+ cldev->bus = mei_dev_bus_get(bus);
+ cldev->me_cl = mei_me_cl_get(me_cl);
+ cldev->is_added = 0;
+ INIT_LIST_HEAD(&cldev->bus_list);
+
+ return cldev;
+}
+
+/**
+ * mei_cl_dev_setup - setup me client device
+ * run fix up routines and set the device name
+ *
+ * @bus: mei device
+ * @cldev: me client device
+ *
+ * Return: true if the device is eligible for enumeration
+ */
+static bool mei_cl_dev_setup(struct mei_device *bus,
+ struct mei_cl_device *cldev)
+{
+ cldev->do_match = 1;
+ mei_cl_dev_fixup(cldev);
+
+ if (cldev->do_match)
+ dev_set_name(&cldev->dev, "mei:%s:%pUl",
+ cldev->name, mei_me_cl_uuid(cldev->me_cl));
+
+ return cldev->do_match == 1;
+}
+
+/**
+ * mei_cl_bus_dev_add - add me client devices
+ *
+ * @cldev: me client device
+ *
+ * Return: 0 on success; < 0 on failre
+ */
+static int mei_cl_bus_dev_add(struct mei_cl_device *cldev)
+{
+ int ret;
+
+ dev_dbg(cldev->bus->dev, "adding %pUL\n", mei_me_cl_uuid(cldev->me_cl));
+ ret = device_add(&cldev->dev);
+ if (!ret)
+ cldev->is_added = 1;
+
+ return ret;
+}
+
struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
struct mei_me_client *me_cl,
struct mei_cl *cl,
@@ -668,28 +741,16 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
struct mei_cl_device *cldev;
int status;
- cldev = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
+ cldev = mei_cl_dev_alloc(bus, me_cl);
if (!cldev)
return NULL;
- cldev->me_cl = mei_me_cl_get(me_cl);
- if (!cldev->me_cl) {
- kfree(cldev);
- return NULL;
- }
-
cldev->cl = cl;
- cldev->dev.parent = bus->dev;
- cldev->dev.bus = &mei_cl_bus_type;
- cldev->dev.type = &mei_cl_device_type;
- cldev->bus = mei_dev_bus_get(bus);
- INIT_LIST_HEAD(&cldev->bus_list);
-
strlcpy(cldev->name, name, sizeof(cldev->name));
- dev_set_name(&cldev->dev, "mei:%s:%pUl", name, mei_me_cl_uuid(me_cl));
+ mei_cl_dev_setup(bus, cldev);
- status = device_register(&cldev->dev);
+ status = mei_cl_bus_dev_add(cldev);
if (status) {
dev_err(bus->dev, "Failed to register MEI device\n");
mei_me_cl_put(cldev->me_cl);
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index 4ce11c98b61a..24c70fada758 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -335,7 +335,7 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *bus,
struct mei_cl *cl,
char *name);
void mei_cl_remove_device(struct mei_cl_device *cldev);
-
+void mei_cl_dev_fixup(struct mei_cl_device *dev);
ssize_t __mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
bool blocking);
ssize_t __mei_cl_recv(struct mei_cl *cl, u8 *buf, size_t length);
diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h
index 85239138251c..81ab56dd0ae0 100644
--- a/include/linux/mei_cl_bus.h
+++ b/include/linux/mei_cl_bus.h
@@ -29,6 +29,8 @@ typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device,
* events (e.g. Rx buffer pending) notifications.
* @event_context: event callback run context
* @events: Events bitmask sent to the driver.
+ *
+ * @do_match: wheather device can be matched with a driver
* @is_added: device is already scanned
* @priv_data: client private data
*/
@@ -45,6 +47,8 @@ struct mei_cl_device {
mei_cl_event_cb_t event_cb;
void *event_context;
unsigned long events;
+
+ unsigned int do_match:1;
unsigned int is_added:1;
void *priv_data;
--
2.4.2
next prev parent reply other threads:[~2015-06-13 19:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-13 19:11 [char-misc-next 00/17] revamp mei bus Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 01/17] MAINTAINERS: mei: add mei_cl_bus.h to maintained file list Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 02/17] mei: bus: fix drivers and devices names confusion Tomas Winkler
2015-06-13 21:21 ` Greg KH
2015-06-14 6:30 ` Winkler, Tomas
2015-06-13 19:11 ` [char-misc-next 03/17] mei: bus: rename device_list to simple devices Tomas Winkler
2015-06-13 21:21 ` Greg KH
2015-06-13 19:11 ` [char-misc-next 04/17] mei: bus: rename nfc.c to bus-fixup.c Tomas Winkler
2015-06-13 21:22 ` Greg KH
2015-06-13 19:11 ` [char-misc-next 05/17] mei: bus: move driver api functions at the start of the file Tomas Winkler
2015-06-13 21:22 ` Greg KH
2015-06-13 19:11 ` [char-misc-next 06/17] mei: bus: add kdoc for device attribute functions Tomas Winkler
2015-06-13 21:23 ` Greg KH
2015-06-13 19:11 ` [char-misc-next 07/17] mei: bus: don't enable events implicitly in device enable Tomas Winkler
2015-06-13 21:24 ` Greg KH
2015-06-13 19:11 ` [char-misc-next 08/17] mei: bus: report if event registration failed Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 09/17] mei: bus: simplify device matching Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 10/17] mei: bus: revamp probe and remove functions Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 11/17] mei: bus: add reference to bus device in struct mei_cl_client Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 12/17] mei: bus: add me client device list infrastructure Tomas Winkler
2015-06-13 19:11 ` Tomas Winkler [this message]
2015-06-13 19:11 ` [char-misc-next 14/17] mei: bus: blacklist clients by number of connections and nfc info client Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 15/17] mei: bus: simplify how we build nfc bus name Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 16/17] mei: bus: also unregister the driver when removing the device Tomas Winkler
2015-06-13 19:11 ` [char-misc-next 17/17] mei: bus: link client devices instead of host clients Tomas Winkler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434222709-10966-14-git-send-email-tomas.winkler@intel.com \
--to=tomas.winkler@intel.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox