aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-03-27 11:29:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-03-29 11:35:47 -0400
commite5354107e14755991da82e0d2a4791db92908d9d (patch)
treeadb8491f5d2a37cbd9304aafb1f762fed4d6c4a5
parent40e0b67be099175d069b0cf46f1102f352d46c61 (diff)
mei: bus: Initial MEI Client bus type implementation
mei client bus will present some of the mei clients as devices for other standard subsystems Implement the probe, remove, match, device addtion routines, along with the sysfs and uevent ones. mei_cl_device_id is also added to mod_devicetable.h A mei-cleint-bus.txt document describing the rationale and the API usage is also added while ABI/testing/sysfs-bus-mei describeis the modalias ABI. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/ABI/testing/sysfs-bus-mei7
-rw-r--r--Documentation/misc-devices/mei/mei-client-bus.txt135
-rw-r--r--drivers/misc/mei/Makefile1
-rw-r--r--drivers/misc/mei/bus.c172
-rw-r--r--drivers/misc/mei/mei_dev.h26
-rw-r--r--include/linux/mei_cl_bus.h20
-rw-r--r--include/linux/mod_devicetable.h9
-rw-r--r--scripts/mod/devicetable-offsets.c3
-rw-r--r--scripts/mod/file2alias.c12
9 files changed, 385 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-mei b/Documentation/ABI/testing/sysfs-bus-mei
new file mode 100644
index 000000000000..2066f0bbd453
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-mei
@@ -0,0 +1,7 @@
1What: /sys/bus/mei/devices/.../modalias
2Date: March 2013
3KernelVersion: 3.10
4Contact: Samuel Ortiz <sameo@linux.intel.com>
5 linux-mei@linux.intel.com
6Description: Stores the same MODALIAS value emitted by uevent
7 Format: mei:<mei device name>
diff --git a/Documentation/misc-devices/mei/mei-client-bus.txt b/Documentation/misc-devices/mei/mei-client-bus.txt
new file mode 100644
index 000000000000..9dc5ebf94eb1
--- /dev/null
+++ b/Documentation/misc-devices/mei/mei-client-bus.txt
@@ -0,0 +1,135 @@
1Intel(R) Management Engine (ME) Client bus API
2===============================================
3
4
5Rationale
6=========
7MEI misc character device is useful for dedicated applications to send and receive
8data to the many FW appliance found in Intel's ME from the user space.
9However for some of the ME functionalities it make sense to leverage existing software
10stack and expose them through existing kernel subsystems.
11
12In order to plug seamlessly into the kernel device driver model we add kernel virtual
13bus abstraction on top of the MEI driver. This allows implementing linux kernel drivers
14for the various MEI features as a stand alone entities found in their respective subsystem.
15Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to
16the existing code.
17
18
19MEI CL bus API
20===========
21A driver implementation for an MEI Client is very similar to existing bus
22based device drivers. The driver registers itself as an MEI CL bus driver through
23the mei_cl_driver structure:
24
25struct mei_cl_driver {
26 struct device_driver driver;
27 const char *name;
28
29 const struct mei_cl_device_id *id_table;
30
31 int (*probe)(struct mei_cl_device *dev, const struct mei_cl_id *id);
32 int (*remove)(struct mei_cl_device *dev);
33};
34
35struct mei_cl_id {
36 char name[MEI_NAME_SIZE];
37 kernel_ulong_t driver_info;
38};
39
40The mei_cl_id structure allows the driver to bind itself against a device name.
41
42To actually register a driver on the ME Client bus one must call the mei_cl_add_driver()
43API. This is typically called at module init time.
44
45Once registered on the ME Client bus, a driver will typically try to do some I/O on
46this bus and this should be done through the mei_cl_send() and mei_cl_recv()
47routines. The latter is synchronous (blocks and sleeps until data shows up).
48In order for drivers to be notified of pending events waiting for them (e.g.
49an Rx event) they can register an event handler through the
50mei_cl_register_event_cb() routine. Currently only the MEI_EVENT_RX event
51will trigger an event handler call and the driver implementation is supposed
52to call mei_recv() from the event handler in order to fetch the pending
53received buffers.
54
55
56Example
57=======
58As a theoretical example let's pretend the ME comes with a "contact" NFC IP.
59The driver init and exit routines for this device would look like:
60
61#define CONTACT_DRIVER_NAME "contact"
62
63static struct mei_cl_device_id contact_mei_cl_tbl[] = {
64 { CONTACT_DRIVER_NAME, },
65
66 /* required last entry */
67 { }
68};
69MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl);
70
71static struct mei_cl_driver contact_driver = {
72 .id_table = contact_mei_tbl,
73 .name = CONTACT_DRIVER_NAME,
74
75 .probe = contact_probe,
76 .remove = contact_remove,
77};
78
79static int contact_init(void)
80{
81 int r;
82
83 r = mei_cl_driver_register(&contact_driver);
84 if (r) {
85 pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n");
86 return r;
87 }
88
89 return 0;
90}
91
92static void __exit contact_exit(void)
93{
94 mei_cl_driver_unregister(&contact_driver);
95}
96
97module_init(contact_init);
98module_exit(contact_exit);
99
100And the driver's simplified probe routine would look like that:
101
102int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id)
103{
104 struct contact_driver *contact;
105
106 [...]
107 mei_cl_register_event_cb(dev, contact_event_cb, contact);
108
109 return 0;
110 }
111
112In the probe routine the driver basically registers an ME bus event handler
113which is as close as it can get to registering a threaded IRQ handler.
114The handler implementation will typically call some I/O routine depending on
115the pending events:
116
117#define MAX_NFC_PAYLOAD 128
118
119static void contact_event_cb(struct mei_cl_device *dev, u32 events,
120 void *context)
121{
122 struct contact_driver *contact = context;
123
124 if (events & BIT(MEI_EVENT_RX)) {
125 u8 payload[MAX_NFC_PAYLOAD];
126 int payload_size;
127
128 payload_size = mei_recv(dev, payload, MAX_NFC_PAYLOAD);
129 if (payload_size <= 0)
130 return;
131
132 /* Hook to the NFC subsystem */
133 nfc_hci_recv_frame(contact->hdev, payload, payload_size);
134 }
135}
diff --git a/drivers/misc/mei/Makefile b/drivers/misc/mei/Makefile
index 2c336d087749..1b29f7ccac49 100644
--- a/drivers/misc/mei/Makefile
+++ b/drivers/misc/mei/Makefile
@@ -10,6 +10,7 @@ mei-objs += client.o
10mei-objs += main.o 10mei-objs += main.o
11mei-objs += amthif.o 11mei-objs += amthif.o
12mei-objs += wd.o 12mei-objs += wd.o
13mei-objs += bus.o
13 14
14obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o 15obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o
15mei-me-objs := pci-me.o 16mei-me-objs := pci-me.o
diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c
new file mode 100644
index 000000000000..78c876af2676
--- /dev/null
+++ b/drivers/misc/mei/bus.c
@@ -0,0 +1,172 @@
1/*
2 * Intel Management Engine Interface (Intel MEI) Linux driver
3 * Copyright (c) 2012-2013, Intel Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
14 */
15
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/errno.h>
21#include <linux/slab.h>
22#include <linux/mutex.h>
23#include <linux/interrupt.h>
24#include <linux/pci.h>
25#include <linux/mei_cl_bus.h>
26
27#include "mei_dev.h"
28
29#define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver)
30#define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev)
31
32static int mei_cl_device_match(struct device *dev, struct device_driver *drv)
33{
34 struct mei_cl_device *device = to_mei_cl_device(dev);
35 struct mei_cl_driver *driver = to_mei_cl_driver(drv);
36 const struct mei_cl_device_id *id;
37
38 if (!device)
39 return 0;
40
41 if (!driver || !driver->id_table)
42 return 0;
43
44 id = driver->id_table;
45
46 while (id->name[0]) {
47 if (!strcmp(dev_name(dev), id->name))
48 return 1;
49
50 id++;
51 }
52
53 return 0;
54}
55
56static int mei_cl_device_probe(struct device *dev)
57{
58 struct mei_cl_device *device = to_mei_cl_device(dev);
59 struct mei_cl_driver *driver;
60 struct mei_cl_device_id id;
61
62 if (!device)
63 return 0;
64
65 driver = to_mei_cl_driver(dev->driver);
66 if (!driver || !driver->probe)
67 return -ENODEV;
68
69 dev_dbg(dev, "Device probe\n");
70
71 strncpy(id.name, dev_name(dev), MEI_CL_NAME_SIZE);
72
73 return driver->probe(device, &id);
74}
75
76static int mei_cl_device_remove(struct device *dev)
77{
78 struct mei_cl_device *device = to_mei_cl_device(dev);
79 struct mei_cl_driver *driver;
80
81 if (!device || !dev->driver)
82 return 0;
83
84 driver = to_mei_cl_driver(dev->driver);
85 if (!driver->remove) {
86 dev->driver = NULL;
87
88 return 0;
89 }
90
91 return driver->remove(device);
92}
93
94static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
95 char *buf)
96{
97 int len;
98
99 len = snprintf(buf, PAGE_SIZE, "mei:%s\n", dev_name(dev));
100
101 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
102}
103
104static struct device_attribute mei_cl_dev_attrs[] = {
105 __ATTR_RO(modalias),
106 __ATTR_NULL,
107};
108
109static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env)
110{
111 if (add_uevent_var(env, "MODALIAS=mei:%s", dev_name(dev)))
112 return -ENOMEM;
113
114 return 0;
115}
116
117static struct bus_type mei_cl_bus_type = {
118 .name = "mei",
119 .dev_attrs = mei_cl_dev_attrs,
120 .match = mei_cl_device_match,
121 .probe = mei_cl_device_probe,
122 .remove = mei_cl_device_remove,
123 .uevent = mei_cl_uevent,
124};
125
126static void mei_cl_dev_release(struct device *dev)
127{
128 kfree(to_mei_cl_device(dev));
129}
130
131static struct device_type mei_cl_device_type = {
132 .release = mei_cl_dev_release,
133};
134
135struct mei_cl_device *mei_cl_add_device(struct mei_device *mei_device,
136 uuid_le uuid, char *name)
137{
138 struct mei_cl_device *device;
139 int status;
140
141 device = kzalloc(sizeof(struct mei_cl_device), GFP_KERNEL);
142 if (!device)
143 return NULL;
144
145 device->dev.parent = &mei_device->pdev->dev;
146 device->dev.bus = &mei_cl_bus_type;
147 device->dev.type = &mei_cl_device_type;
148
149 dev_set_name(&device->dev, "%s", name);
150
151 status = device_register(&device->dev);
152 if (status)
153 goto out_err;
154
155 dev_dbg(&device->dev, "client %s registered\n", name);
156
157 return device;
158
159out_err:
160 dev_err(device->dev.parent, "Failed to register MEI client\n");
161
162 kfree(device);
163
164 return NULL;
165}
166EXPORT_SYMBOL_GPL(mei_cl_add_device);
167
168void mei_cl_remove_device(struct mei_cl_device *device)
169{
170 device_unregister(&device->dev);
171}
172EXPORT_SYMBOL_GPL(mei_cl_remove_device);
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index b5d66076de3d..7abb705ddf3f 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -21,6 +21,7 @@
21#include <linux/watchdog.h> 21#include <linux/watchdog.h>
22#include <linux/poll.h> 22#include <linux/poll.h>
23#include <linux/mei.h> 23#include <linux/mei.h>
24#include <linux/mei_cl_bus.h>
24 25
25#include "hw.h" 26#include "hw.h"
26#include "hw-me-regs.h" 27#include "hw-me-regs.h"
@@ -262,6 +263,31 @@ struct mei_hw_ops {
262 unsigned char *buf, unsigned long len); 263 unsigned char *buf, unsigned long len);
263}; 264};
264 265
266/* MEI bus API*/
267struct mei_cl_device *mei_cl_add_device(struct mei_device *dev,
268 uuid_le uuid, char *name);
269void mei_cl_remove_device(struct mei_cl_device *device);
270
271/**
272 * struct mei_cl_device - MEI device handle
273 * An mei_cl_device pointer is returned from mei_add_device()
274 * and links MEI bus clients to their actual ME host client pointer.
275 * Drivers for MEI devices will get an mei_cl_device pointer
276 * when being probed and shall use it for doing ME bus I/O.
277 *
278 * @dev: linux driver model device pointer
279 * @uuid: me client uuid
280 * @cl: mei client
281 * @priv_data: client private data
282 */
283struct mei_cl_device {
284 struct device dev;
285
286 struct mei_cl *cl;
287
288 void *priv_data;
289};
290
265/** 291/**
266 * struct mei_device - MEI private device struct 292 * struct mei_device - MEI private device struct
267 293
diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h
new file mode 100644
index 000000000000..4e7351de7eca
--- /dev/null
+++ b/include/linux/mei_cl_bus.h
@@ -0,0 +1,20 @@
1#ifndef _LINUX_MEI_CL_BUS_H
2#define _LINUX_MEI_CL_BUS_H
3
4#include <linux/device.h>
5#include <linux/uuid.h>
6
7struct mei_cl_device;
8
9struct mei_cl_driver {
10 struct device_driver driver;
11 const char *name;
12
13 const struct mei_cl_device_id *id_table;
14
15 int (*probe)(struct mei_cl_device *dev,
16 const struct mei_cl_device_id *id);
17 int (*remove)(struct mei_cl_device *dev);
18};
19
20#endif /* _LINUX_MEI_CL_BUS_H */
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 779cf7c4a3d1..b508016fb76d 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -9,6 +9,7 @@
9 9
10#ifdef __KERNEL__ 10#ifdef __KERNEL__
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/uuid.h>
12typedef unsigned long kernel_ulong_t; 13typedef unsigned long kernel_ulong_t;
13#endif 14#endif
14 15
@@ -568,4 +569,12 @@ struct ipack_device_id {
568 __u32 device; /* Device ID or IPACK_ANY_ID */ 569 __u32 device; /* Device ID or IPACK_ANY_ID */
569}; 570};
570 571
572#define MEI_CL_MODULE_PREFIX "mei:"
573#define MEI_CL_NAME_SIZE 32
574
575struct mei_cl_device_id {
576 char name[MEI_CL_NAME_SIZE];
577 kernel_ulong_t driver_info;
578};
579
571#endif /* LINUX_MOD_DEVICETABLE_H */ 580#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index b45260bfeaa0..e66d4d258e1a 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -174,5 +174,8 @@ int main(void)
174 DEVID_FIELD(x86_cpu_id, model); 174 DEVID_FIELD(x86_cpu_id, model);
175 DEVID_FIELD(x86_cpu_id, vendor); 175 DEVID_FIELD(x86_cpu_id, vendor);
176 176
177 DEVID(mei_cl_device_id);
178 DEVID_FIELD(mei_cl_device_id, name);
179
177 return 0; 180 return 0;
178} 181}
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 771ac17f635d..45f9a3377dcd 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1133,6 +1133,18 @@ static int do_x86cpu_entry(const char *filename, void *symval,
1133} 1133}
1134ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry); 1134ADD_TO_DEVTABLE("x86cpu", x86_cpu_id, do_x86cpu_entry);
1135 1135
1136/* Looks like: mei:S */
1137static int do_mei_entry(const char *filename, void *symval,
1138 char *alias)
1139{
1140 DEF_FIELD_ADDR(symval, mei_cl_device_id, name);
1141
1142 sprintf(alias, MEI_CL_MODULE_PREFIX "%s", *name);
1143
1144 return 1;
1145}
1146ADD_TO_DEVTABLE("mei", mei_cl_device_id, do_mei_entry);
1147
1136/* Does namelen bytes of name exactly match the symbol? */ 1148/* Does namelen bytes of name exactly match the symbol? */
1137static bool sym_is(const char *name, unsigned namelen, const char *symbol) 1149static bool sym_is(const char *name, unsigned namelen, const char *symbol)
1138{ 1150{