17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/device.h>
24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/fcntl.h>
28 #include <linux/pci.h>
29 #include <linux/poll.h>
33 #include <linux/sched.h>
34 #include <linux/uuid.h>
45 static struct pci_dev *mei_pdev;
110 struct file *file_temp;
111 bool removed =
false;
117 if (file_temp == file) {
146 static bool mei_clear_lists(
struct mei_device *dev,
struct file *file)
148 bool removed =
false;
152 if (mei_clear_list(dev, file,
156 mei_clear_list(dev, file, &dev->
ctrl_rd_list.mei_cb.cb_list);
158 if (mei_clear_list(dev, file, &dev->
ctrl_wr_list.mei_cb.cb_list))
164 if (mei_clear_list(dev, file, &dev->
write_list.mei_cb.cb_list))
187 static struct mei_cl_cb *find_read_list_entry(
200 if (mei_cl_cmp_id(cl, cl_temp))
214 static int mei_open(
struct inode *
inode,
struct file *file)
225 dev = pci_get_drvdata(mei_pdev);
237 dev_dbg(&dev->
pdev->dev,
"dev_state != MEI_ENABLED dev_state = %s\n",
243 dev_err(&dev->
pdev->dev,
"open_handle_count exceded %d",
287 static int mei_release(
struct inode *inode,
struct file *file)
304 "disconnecting client host client = %d, "
311 dev_dbg(&dev->
pdev->dev,
"remove client host client = %d, ME client = %d\n",
324 cb = find_read_list_entry(dev, cl);
348 dev_dbg(&dev->
pdev->dev,
"amthi canceled iamthif state %d\n",
352 dev_dbg(&dev->
pdev->dev,
"run next amthi iamthif cb\n");
357 if (mei_clear_lists(dev, file))
376 static ssize_t mei_read(
struct file *file,
char __user *ubuf,
414 rets =
amthi_read(dev, file, ubuf, length, offset);
422 cl->
read_cb->information <= *offset) {
435 if (err && err != -
EBUSY) {
437 "mei start read failure with status = %d\n", err);
443 !waitqueue_active(&cl->
rx_wait)) {
482 dev_dbg(&dev->
pdev->dev,
"cb->response_buffer size - %d\n",
484 dev_dbg(&dev->
pdev->dev,
"cb->information - %lu\n",
506 cb_pos = find_read_list_entry(dev, cl);
515 dev_dbg(&dev->
pdev->dev,
"end mei read rets= %d\n", rets);
530 static ssize_t mei_write(
struct file *file,
const char __user *ubuf,
531 size_t length, loff_t *offset)
573 write_cb = find_read_list_entry(dev, cl);
599 dev_dbg(&dev->
pdev->dev,
"length =%d\n", (
int) length);
615 INIT_LIST_HEAD(&write_cb->
cb_list);
632 if (length > dev->
me_clients[i].props.max_msg_length ||
651 dev_dbg(&dev->
pdev->dev,
"add amthi cb to amthi cmd waiting list\n");
660 dev_dbg(&dev->
pdev->dev,
"amthi write failed with status = %d\n",
676 dev_dbg(&dev->
pdev->dev,
"host client = %d, ME client = %d\n",
680 dev_dbg(&dev->
pdev->dev,
"host client = %d, is not connected to ME client = %d",
690 if (length > dev->
me_clients[i].props.max_msg_length || length <= 0) {
703 if (length > mei_hbuf_max_data(dev)) {
704 mei_hdr.length = mei_hbuf_max_data(dev);
705 mei_hdr.msg_complete = 0;
708 mei_hdr.msg_complete = 1;
712 mei_hdr.reserved = 0;
713 dev_dbg(&dev->
pdev->dev,
"call mei_write_message header=%08x.\n",
714 *((
u32 *) &mei_hdr));
723 if (mei_hdr.msg_complete) {
761 static long mei_ioctl(
struct file *file,
unsigned int cmd,
unsigned long data)
784 dev_dbg(&dev->
pdev->dev,
": IOCTL_MEI_CONNECT_CLIENT.\n");
792 dev_dbg(&dev->
pdev->dev,
"copy connect data from user\n");
795 dev_dbg(&dev->
pdev->dev,
"failed to copy data from userland\n");
805 dev_dbg(&dev->
pdev->dev,
"copy connect data to user\n");
808 dev_dbg(&dev->
pdev->dev,
"failed to copy data to userland\n");
829 static long mei_compat_ioctl(
struct file *file,
830 unsigned int cmd,
unsigned long data)
832 return mei_ioctl(file, cmd, (
unsigned long)compat_ptr(data));
849 unsigned int mask = 0;
876 poll_wait(file, &cl->
tx_wait, wait);
892 .unlocked_ioctl = mei_ioctl,
894 .compat_ioctl = mei_compat_ioctl,
897 .release = mei_release,
925 pci_read_config_dword(pdev, 0x48, ®);
927 if ((reg & 0x600) == 0x200) {
928 dev_info(&pdev->
dev,
"Device doesn't have valid ME Interface\n");
950 if (!mei_quirk_probe(pdev, ent)) {
962 dev_err(&pdev->
dev,
"failed to enable pci device.\n");
970 dev_err(&pdev->
dev,
"failed to get pci regions.\n");
977 goto release_regions;
980 dev->
mem_addr = pci_iomap(pdev, 0, 0);
982 dev_err(&pdev->
dev,
"mapping I/O device memory failure.\n");
986 pci_enable_msi(pdev);
989 if (pci_dev_msi_enabled(pdev))
1001 dev_err(&pdev->
dev,
"request_threaded_irq failure. irq = %d\n",
1017 pci_set_drvdata(pdev, dev);
1024 pr_debug(
"initialization successful.\n");
1045 dev_err(&pdev->
dev,
"initialization failed.\n");
1061 if (mei_pdev != pdev)
1064 dev = pci_get_drvdata(pdev);
1089 dev_dbg(&pdev->
dev,
"list del iamthif and wd file list.\n");
1105 pci_set_drvdata(pdev,
NULL);
1121 struct mei_device *dev = pci_get_drvdata(pdev);
1146 static int mei_pci_resume(
struct device *device)
1152 dev = pci_get_drvdata(pdev);
1156 pci_enable_msi(pdev);
1159 if (pci_dev_msi_enabled(pdev))
1171 dev_err(&pdev->
dev,
"request_threaded_irq failed: irq = %d.\n",
1187 #define MEI_PM_OPS (&mei_pm_ops)
1189 #define MEI_PM_OPS NULL
1195 .name = KBUILD_MODNAME,
1196 .id_table = mei_pci_tbl,