1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright © 2020 - 2021 Intel Corporation
7 * DOC: MEI_PXP Client Driver
9 * The mei_pxp driver acts as a translation layer between PXP
10 * protocol implementer (I915) and ME FW by translating PXP
11 * negotiation messages to ME FW command payloads and vice versa.
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/uuid.h>
17 #include <linux/mei_cl_bus.h>
18 #include <linux/component.h>
19 #include <drm/drm_connector.h>
20 #include <drm/i915_component.h>
21 #include <drm/i915_pxp_tee_interface.h>
26 * mei_pxp_send_message() - Sends a PXP message to ME FW.
27 * @dev: device corresponding to the mei_cl_device
28 * @message: a message buffer to send
29 * @size: size of the message
30 * Return: 0 on Success, <0 on Failure
33 mei_pxp_send_message(struct device *dev, const void *message, size_t size)
35 struct mei_cl_device *cldev;
41 cldev = to_mei_cl_device(dev);
43 /* temporary drop const qualifier till the API is fixed */
44 byte = mei_cldev_send(cldev, (u8 *)message, size);
46 dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
54 * mei_pxp_receive_message() - Receives a PXP message from ME FW.
55 * @dev: device corresponding to the mei_cl_device
56 * @buffer: a message buffer to contain the received message
57 * @size: size of the buffer
58 * Return: bytes sent on Success, <0 on Failure
61 mei_pxp_receive_message(struct device *dev, void *buffer, size_t size)
63 struct mei_cl_device *cldev;
69 cldev = to_mei_cl_device(dev);
71 byte = mei_cldev_recv(cldev, buffer, size);
73 dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
80 static const struct i915_pxp_component_ops mei_pxp_ops = {
82 .send = mei_pxp_send_message,
83 .recv = mei_pxp_receive_message,
86 static int mei_component_master_bind(struct device *dev)
88 struct mei_cl_device *cldev = to_mei_cl_device(dev);
89 struct i915_pxp_component *comp_master = mei_cldev_get_drvdata(cldev);
92 comp_master->ops = &mei_pxp_ops;
93 comp_master->tee_dev = dev;
94 ret = component_bind_all(dev, comp_master);
101 static void mei_component_master_unbind(struct device *dev)
103 struct mei_cl_device *cldev = to_mei_cl_device(dev);
104 struct i915_pxp_component *comp_master = mei_cldev_get_drvdata(cldev);
106 component_unbind_all(dev, comp_master);
109 static const struct component_master_ops mei_component_master_ops = {
110 .bind = mei_component_master_bind,
111 .unbind = mei_component_master_unbind,
115 * mei_pxp_component_match - compare function for matching mei pxp.
117 * The function checks if the driver is i915, the subcomponent is PXP
118 * and the grand parent of pxp and the parent of i915 are the same
121 * @dev: master device
122 * @subcomponent: subcomponent to match (I915_COMPONENT_PXP)
123 * @data: compare data (mei pxp device)
126 * * 1 - if components match
129 static int mei_pxp_component_match(struct device *dev, int subcomponent,
132 struct device *base = data;
134 if (!dev->driver || strcmp(dev->driver->name, "i915") ||
135 subcomponent != I915_COMPONENT_PXP)
145 return (base && dev && dev == base);
148 static int mei_pxp_probe(struct mei_cl_device *cldev,
149 const struct mei_cl_device_id *id)
151 struct i915_pxp_component *comp_master;
152 struct component_match *master_match;
155 ret = mei_cldev_enable(cldev);
157 dev_err(&cldev->dev, "mei_cldev_enable Failed. %d\n", ret);
158 goto enable_err_exit;
161 comp_master = kzalloc(sizeof(*comp_master), GFP_KERNEL);
168 component_match_add_typed(&cldev->dev, &master_match,
169 mei_pxp_component_match, &cldev->dev);
170 if (IS_ERR_OR_NULL(master_match)) {
175 mei_cldev_set_drvdata(cldev, comp_master);
176 ret = component_master_add_with_match(&cldev->dev,
177 &mei_component_master_ops,
180 dev_err(&cldev->dev, "Master comp add failed %d\n", ret);
187 mei_cldev_set_drvdata(cldev, NULL);
189 mei_cldev_disable(cldev);
194 static void mei_pxp_remove(struct mei_cl_device *cldev)
196 struct i915_pxp_component *comp_master = mei_cldev_get_drvdata(cldev);
199 component_master_del(&cldev->dev, &mei_component_master_ops);
201 mei_cldev_set_drvdata(cldev, NULL);
203 ret = mei_cldev_disable(cldev);
205 dev_warn(&cldev->dev, "mei_cldev_disable() failed\n");
208 /* fbf6fcf1-96cf-4e2e-a6a6-1bab8cbe36b1 : PAVP GUID*/
209 #define MEI_GUID_PXP GUID_INIT(0xfbf6fcf1, 0x96cf, 0x4e2e, 0xA6, \
210 0xa6, 0x1b, 0xab, 0x8c, 0xbe, 0x36, 0xb1)
212 static struct mei_cl_device_id mei_pxp_tbl[] = {
213 { .uuid = MEI_GUID_PXP, .version = MEI_CL_VERSION_ANY },
216 MODULE_DEVICE_TABLE(mei, mei_pxp_tbl);
218 static struct mei_cl_driver mei_pxp_driver = {
219 .id_table = mei_pxp_tbl,
220 .name = KBUILD_MODNAME,
221 .probe = mei_pxp_probe,
222 .remove = mei_pxp_remove,
225 module_mei_cl_driver(mei_pxp_driver);
227 MODULE_AUTHOR("Intel Corporation");
228 MODULE_LICENSE("GPL");
229 MODULE_DESCRIPTION("MEI PXP");