3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/kernel.h>
19 #include <linux/device.h>
21 #include <linux/errno.h>
22 #include <linux/types.h>
23 #include <linux/fcntl.h>
24 #include <linux/aio.h>
25 #include <linux/pci.h>
26 #include <linux/poll.h>
27 #include <linux/ioctl.h>
28 #include <linux/cdev.h>
29 #include <linux/sched.h>
30 #include <linux/uuid.h>
31 #include <linux/compat.h>
32 #include <linux/jiffies.h>
33 #include <linux/interrupt.h>
34 #include <linux/miscdevice.h>
36 #include <linux/mei.h>
40 #include "hw-me-regs.h"
43 /* mei_pci_tbl - PCI Device ID Table */
44 static DEFINE_PCI_DEVICE_TABLE(mei_me_pci_tbl) = {
45 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82946GZ)},
46 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G35)},
47 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82Q965)},
48 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82G965)},
49 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GM965)},
50 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_82GME965)},
51 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q35)},
52 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82G33)},
53 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82Q33)},
54 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_82X38)},
55 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_3200)},
56 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_6)},
57 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_7)},
58 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_8)},
59 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_9)},
60 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9_10)},
61 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_1)},
62 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_2)},
63 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_3)},
64 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH9M_4)},
65 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_1)},
66 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_2)},
67 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_3)},
68 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_ICH10_4)},
69 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_1)},
70 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_IBXPK_2)},
71 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_CPT_1)},
72 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PBG_1)},
73 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_1)},
74 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_2)},
75 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_PPT_3)},
76 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT_H)},
77 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT_W)},
78 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT_LP)},
79 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_LPT_HR)},
80 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MEI_DEV_ID_WPT_LP)},
82 /* required last entry */
86 MODULE_DEVICE_TABLE(pci, mei_me_pci_tbl);
89 * mei_quirk_probe - probe for devices that doesn't valid ME interface
91 * @pdev: PCI device structure
92 * @ent: entry into pci_device_table
94 * returns true if ME Interface is valid, false otherwise
96 static bool mei_me_quirk_probe(struct pci_dev *pdev,
97 const struct pci_device_id *ent)
100 if (ent->device == MEI_DEV_ID_PBG_1) {
101 pci_read_config_dword(pdev, 0x48, ®);
102 /* make sure that bit 9 is up and bit 10 is down */
103 if ((reg & 0x600) == 0x200) {
104 dev_info(&pdev->dev, "Device doesn't have valid ME Interface\n");
111 * mei_probe - Device Initialization Routine
113 * @pdev: PCI device structure
114 * @ent: entry in kcs_pci_tbl
116 * returns 0 on success, <0 on failure.
118 static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
120 struct mei_device *dev;
121 struct mei_me_hw *hw;
125 if (!mei_me_quirk_probe(pdev, ent)) {
131 err = pci_enable_device(pdev);
133 dev_err(&pdev->dev, "failed to enable pci device.\n");
136 /* set PCI host mastering */
137 pci_set_master(pdev);
138 /* pci request regions for mei driver */
139 err = pci_request_regions(pdev, KBUILD_MODNAME);
141 dev_err(&pdev->dev, "failed to get pci regions.\n");
145 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) ||
146 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
148 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
150 err = dma_set_coherent_mask(&pdev->dev,
154 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
155 goto release_regions;
159 /* allocates and initializes the mei dev structure */
160 dev = mei_me_dev_init(pdev);
163 goto release_regions;
166 /* mapping IO device memory */
167 hw->mem_addr = pci_iomap(pdev, 0, 0);
169 dev_err(&pdev->dev, "mapping I/O device memory failure.\n");
173 pci_enable_msi(pdev);
175 /* request and enable interrupt */
176 if (pci_dev_msi_enabled(pdev))
177 err = request_threaded_irq(pdev->irq,
179 mei_me_irq_thread_handler,
180 IRQF_ONESHOT, KBUILD_MODNAME, dev);
182 err = request_threaded_irq(pdev->irq,
183 mei_me_irq_quick_handler,
184 mei_me_irq_thread_handler,
185 IRQF_SHARED, KBUILD_MODNAME, dev);
188 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
193 if (mei_start(dev)) {
194 dev_err(&pdev->dev, "init hw failure.\n");
199 err = mei_register(dev);
203 pci_set_drvdata(pdev, dev);
205 schedule_delayed_work(&dev->timer_work, HZ);
207 dev_dbg(&pdev->dev, "initialization successful.\n");
212 mei_cancel_work(dev);
213 mei_disable_interrupts(dev);
214 free_irq(pdev->irq, dev);
216 pci_disable_msi(pdev);
217 pci_iounmap(pdev, hw->mem_addr);
221 pci_release_regions(pdev);
223 pci_disable_device(pdev);
225 dev_err(&pdev->dev, "initialization failed.\n");
230 * mei_remove - Device Removal Routine
232 * @pdev: PCI device structure
234 * mei_remove is called by the PCI subsystem to alert the driver
235 * that it should release a PCI device.
237 static void mei_me_remove(struct pci_dev *pdev)
239 struct mei_device *dev;
240 struct mei_me_hw *hw;
242 dev = pci_get_drvdata(pdev);
249 dev_dbg(&pdev->dev, "stop\n");
252 /* disable interrupts */
253 mei_disable_interrupts(dev);
255 free_irq(pdev->irq, dev);
256 pci_disable_msi(pdev);
259 pci_iounmap(pdev, hw->mem_addr);
265 pci_release_regions(pdev);
266 pci_disable_device(pdev);
270 #ifdef CONFIG_PM_SLEEP
271 static int mei_me_pci_suspend(struct device *device)
273 struct pci_dev *pdev = to_pci_dev(device);
274 struct mei_device *dev = pci_get_drvdata(pdev);
279 dev_dbg(&pdev->dev, "suspend\n");
283 mei_disable_interrupts(dev);
285 free_irq(pdev->irq, dev);
286 pci_disable_msi(pdev);
291 static int mei_me_pci_resume(struct device *device)
293 struct pci_dev *pdev = to_pci_dev(device);
294 struct mei_device *dev;
297 dev = pci_get_drvdata(pdev);
301 pci_enable_msi(pdev);
303 /* request and enable interrupt */
304 if (pci_dev_msi_enabled(pdev))
305 err = request_threaded_irq(pdev->irq,
307 mei_me_irq_thread_handler,
308 IRQF_ONESHOT, KBUILD_MODNAME, dev);
310 err = request_threaded_irq(pdev->irq,
311 mei_me_irq_quick_handler,
312 mei_me_irq_thread_handler,
313 IRQF_SHARED, KBUILD_MODNAME, dev);
316 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
321 err = mei_restart(dev);
325 /* Start timer if stopped in suspend */
326 schedule_delayed_work(&dev->timer_work, HZ);
331 static SIMPLE_DEV_PM_OPS(mei_me_pm_ops, mei_me_pci_suspend, mei_me_pci_resume);
332 #define MEI_ME_PM_OPS (&mei_me_pm_ops)
334 #define MEI_ME_PM_OPS NULL
335 #endif /* CONFIG_PM_SLEEP */
337 * PCI driver structure
339 static struct pci_driver mei_me_driver = {
340 .name = KBUILD_MODNAME,
341 .id_table = mei_me_pci_tbl,
342 .probe = mei_me_probe,
343 .remove = mei_me_remove,
344 .shutdown = mei_me_remove,
345 .driver.pm = MEI_ME_PM_OPS,
348 module_pci_driver(mei_me_driver);
350 MODULE_AUTHOR("Intel Corporation");
351 MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
352 MODULE_LICENSE("GPL v2");