blob: bd3039ab8f98e67e86de56ef8429dfd164c89d86 [file] [log] [blame]
Tomas Winkler2703d4b2013-02-06 14:06:39 +02001/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
5 *
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.
9 *
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
13 * more details.
14 *
15 */
Tomas Winkler2703d4b2013-02-06 14:06:39 +020016#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/kernel.h>
19#include <linux/device.h>
20#include <linux/fs.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>
Tomas Winkler2703d4b2013-02-06 14:06:39 +020027#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>
Tomas Winkler2703d4b2013-02-06 14:06:39 +020034
Tomas Winkler180ea052014-03-18 22:52:02 +020035#include <linux/pm_runtime.h>
36
Tomas Winkler2703d4b2013-02-06 14:06:39 +020037#include <linux/mei.h>
38
39#include "mei_dev.h"
Tomas Winkler2703d4b2013-02-06 14:06:39 +020040#include "client.h"
Tomas Winkler6e4cd272014-03-11 14:49:23 +020041#include "hw-me-regs.h"
42#include "hw-me.h"
Tomas Winkler2703d4b2013-02-06 14:06:39 +020043
Tomas Winkler2703d4b2013-02-06 14:06:39 +020044/* mei_pci_tbl - PCI Device ID Table */
Tomas Winklera05f8f82014-03-16 14:35:58 +020045static const struct pci_device_id mei_me_pci_tbl[] = {
Alexander Usyskin8d929d42014-05-13 01:30:53 +030046 {MEI_PCI_DEVICE(MEI_DEV_ID_82946GZ, mei_me_legacy_cfg)},
47 {MEI_PCI_DEVICE(MEI_DEV_ID_82G35, mei_me_legacy_cfg)},
48 {MEI_PCI_DEVICE(MEI_DEV_ID_82Q965, mei_me_legacy_cfg)},
49 {MEI_PCI_DEVICE(MEI_DEV_ID_82G965, mei_me_legacy_cfg)},
50 {MEI_PCI_DEVICE(MEI_DEV_ID_82GM965, mei_me_legacy_cfg)},
51 {MEI_PCI_DEVICE(MEI_DEV_ID_82GME965, mei_me_legacy_cfg)},
52 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82Q35, mei_me_legacy_cfg)},
53 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82G33, mei_me_legacy_cfg)},
54 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82Q33, mei_me_legacy_cfg)},
55 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82X38, mei_me_legacy_cfg)},
56 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_3200, mei_me_legacy_cfg)},
57
58 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_6, mei_me_legacy_cfg)},
59 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_7, mei_me_legacy_cfg)},
60 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_8, mei_me_legacy_cfg)},
61 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_9, mei_me_legacy_cfg)},
62 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_10, mei_me_legacy_cfg)},
63 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_1, mei_me_legacy_cfg)},
64 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_2, mei_me_legacy_cfg)},
65 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_3, mei_me_legacy_cfg)},
66 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_4, mei_me_legacy_cfg)},
67 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_1, mei_me_ich_cfg)},
68 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_2, mei_me_ich_cfg)},
69 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_3, mei_me_ich_cfg)},
70 {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_4, mei_me_ich_cfg)},
71
72 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_1, mei_me_pch_cfg)},
73 {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_2, mei_me_pch_cfg)},
Tomas Winklerc9199512014-05-13 01:30:54 +030074 {MEI_PCI_DEVICE(MEI_DEV_ID_CPT_1, mei_me_pch_cpt_pbg_cfg)},
75 {MEI_PCI_DEVICE(MEI_DEV_ID_PBG_1, mei_me_pch_cpt_pbg_cfg)},
Alexander Usyskin8d929d42014-05-13 01:30:53 +030076 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_1, mei_me_pch_cfg)},
77 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_2, mei_me_pch_cfg)},
78 {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_3, mei_me_pch_cfg)},
Alexander Usyskinedca5ea2014-11-19 17:01:38 +020079 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, mei_me_pch8_sps_cfg)},
80 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, mei_me_pch8_sps_cfg)},
81 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, mei_me_pch8_cfg)},
82 {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_HR, mei_me_pch8_sps_cfg)},
83 {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP, mei_me_pch8_cfg)},
84 {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP_2, mei_me_pch8_cfg)},
Tomas Winkler2703d4b2013-02-06 14:06:39 +020085
86 /* required last entry */
87 {0, }
88};
89
Tomas Winklerb68301e2013-03-27 16:58:29 +020090MODULE_DEVICE_TABLE(pci, mei_me_pci_tbl);
Tomas Winkler2703d4b2013-02-06 14:06:39 +020091
Rafael J. Wysockibbd6d052014-12-04 22:43:07 +010092#ifdef CONFIG_PM
Tomas Winklere13fa902014-03-18 22:52:05 +020093static inline void mei_me_set_pm_domain(struct mei_device *dev);
94static inline void mei_me_unset_pm_domain(struct mei_device *dev);
95#else
96static inline void mei_me_set_pm_domain(struct mei_device *dev) {}
97static inline void mei_me_unset_pm_domain(struct mei_device *dev) {}
Rafael J. Wysockibbd6d052014-12-04 22:43:07 +010098#endif /* CONFIG_PM */
Tomas Winklere13fa902014-03-18 22:52:05 +020099
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200100/**
Alexander Usyskince231392014-09-29 16:31:50 +0300101 * mei_me_quirk_probe - probe for devices that doesn't valid ME interface
Masanari Iida393b1482013-04-05 01:05:05 +0900102 *
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200103 * @pdev: PCI device structure
Tomas Winklerc9199512014-05-13 01:30:54 +0300104 * @cfg: per generation config
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200105 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300106 * Return: true if ME Interface is valid, false otherwise
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200107 */
Tomas Winklerb68301e2013-03-27 16:58:29 +0200108static bool mei_me_quirk_probe(struct pci_dev *pdev,
Tomas Winklerc9199512014-05-13 01:30:54 +0300109 const struct mei_cfg *cfg)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200110{
Tomas Winklerc9199512014-05-13 01:30:54 +0300111 if (cfg->quirk_probe && cfg->quirk_probe(pdev)) {
112 dev_info(&pdev->dev, "Device doesn't have valid ME Interface\n");
113 return false;
Tomas Winkler5e6533a2014-03-25 21:25:18 +0200114 }
115
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200116 return true;
117}
Tomas Winklerc9199512014-05-13 01:30:54 +0300118
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200119/**
Alexander Usyskince231392014-09-29 16:31:50 +0300120 * mei_me_probe - Device Initialization Routine
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200121 *
122 * @pdev: PCI device structure
123 * @ent: entry in kcs_pci_tbl
124 *
Alexander Usyskina8605ea2014-09-29 16:31:49 +0300125 * Return: 0 on success, <0 on failure.
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200126 */
Tomas Winklerb68301e2013-03-27 16:58:29 +0200127static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200128{
Alexander Usyskin8d929d42014-05-13 01:30:53 +0300129 const struct mei_cfg *cfg = (struct mei_cfg *)(ent->driver_data);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200130 struct mei_device *dev;
Tomas Winkler52c34562013-02-06 14:06:40 +0200131 struct mei_me_hw *hw;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200132 int err;
133
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200134
Tomas Winklerc9199512014-05-13 01:30:54 +0300135 if (!mei_me_quirk_probe(pdev, cfg))
136 return -ENODEV;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200137
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200138 /* enable pci dev */
139 err = pci_enable_device(pdev);
140 if (err) {
141 dev_err(&pdev->dev, "failed to enable pci device.\n");
142 goto end;
143 }
144 /* set PCI host mastering */
145 pci_set_master(pdev);
146 /* pci request regions for mei driver */
147 err = pci_request_regions(pdev, KBUILD_MODNAME);
148 if (err) {
149 dev_err(&pdev->dev, "failed to get pci regions.\n");
150 goto disable_device;
151 }
Tomas Winkler3ecfb162013-12-17 15:56:57 +0200152
153 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) ||
154 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
155
156 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
157 if (err)
158 err = dma_set_coherent_mask(&pdev->dev,
159 DMA_BIT_MASK(32));
160 }
161 if (err) {
162 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n");
163 goto release_regions;
164 }
165
166
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200167 /* allocates and initializes the mei dev structure */
Alexander Usyskin8d929d42014-05-13 01:30:53 +0300168 dev = mei_me_dev_init(pdev, cfg);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200169 if (!dev) {
170 err = -ENOMEM;
171 goto release_regions;
172 }
Tomas Winkler52c34562013-02-06 14:06:40 +0200173 hw = to_me_hw(dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200174 /* mapping IO device memory */
Tomas Winkler52c34562013-02-06 14:06:40 +0200175 hw->mem_addr = pci_iomap(pdev, 0, 0);
176 if (!hw->mem_addr) {
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200177 dev_err(&pdev->dev, "mapping I/O device memory failure.\n");
178 err = -ENOMEM;
179 goto free_device;
180 }
181 pci_enable_msi(pdev);
182
183 /* request and enable interrupt */
184 if (pci_dev_msi_enabled(pdev))
185 err = request_threaded_irq(pdev->irq,
186 NULL,
Tomas Winkler06ecd642013-02-06 14:06:42 +0200187 mei_me_irq_thread_handler,
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200188 IRQF_ONESHOT, KBUILD_MODNAME, dev);
189 else
190 err = request_threaded_irq(pdev->irq,
Tomas Winkler06ecd642013-02-06 14:06:42 +0200191 mei_me_irq_quick_handler,
192 mei_me_irq_thread_handler,
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200193 IRQF_SHARED, KBUILD_MODNAME, dev);
194
195 if (err) {
196 dev_err(&pdev->dev, "request_threaded_irq failure. irq = %d\n",
197 pdev->irq);
198 goto disable_msi;
199 }
200
Tomas Winklerc4d589b2013-03-27 16:58:28 +0200201 if (mei_start(dev)) {
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200202 dev_err(&pdev->dev, "init hw failure.\n");
203 err = -ENODEV;
204 goto release_irq;
205 }
206
Tomas Winkler180ea052014-03-18 22:52:02 +0200207 pm_runtime_set_autosuspend_delay(&pdev->dev, MEI_ME_RPM_TIMEOUT);
208 pm_runtime_use_autosuspend(&pdev->dev);
209
Alexander Usyskinf3d8e872014-06-23 15:10:35 +0300210 err = mei_register(dev, &pdev->dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200211 if (err)
212 goto release_irq;
213
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200214 pci_set_drvdata(pdev, dev);
215
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200216 schedule_delayed_work(&dev->timer_work, HZ);
217
Tomas Winklere13fa902014-03-18 22:52:05 +0200218 /*
219 * For not wake-able HW runtime pm framework
220 * can't be used on pci device level.
221 * Use domain runtime pm callbacks instead.
222 */
223 if (!pci_dev_run_wake(pdev))
224 mei_me_set_pm_domain(dev);
225
Tomas Winkler180ea052014-03-18 22:52:02 +0200226 if (mei_pg_is_enabled(dev))
227 pm_runtime_put_noidle(&pdev->dev);
228
Alexander Usyskinc4e87b52013-10-21 22:05:42 +0300229 dev_dbg(&pdev->dev, "initialization successful.\n");
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200230
231 return 0;
232
233release_irq:
Tomas Winklerdc844b02013-11-11 13:26:06 +0200234 mei_cancel_work(dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200235 mei_disable_interrupts(dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200236 free_irq(pdev->irq, dev);
237disable_msi:
238 pci_disable_msi(pdev);
Tomas Winkler52c34562013-02-06 14:06:40 +0200239 pci_iounmap(pdev, hw->mem_addr);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200240free_device:
241 kfree(dev);
242release_regions:
243 pci_release_regions(pdev);
244disable_device:
245 pci_disable_device(pdev);
246end:
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200247 dev_err(&pdev->dev, "initialization failed.\n");
248 return err;
249}
250
251/**
Alexander Usyskince231392014-09-29 16:31:50 +0300252 * mei_me_remove - Device Removal Routine
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200253 *
254 * @pdev: PCI device structure
255 *
256 * mei_remove is called by the PCI subsystem to alert the driver
257 * that it should release a PCI device.
258 */
Tomas Winklerb68301e2013-03-27 16:58:29 +0200259static void mei_me_remove(struct pci_dev *pdev)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200260{
261 struct mei_device *dev;
Tomas Winkler52c34562013-02-06 14:06:40 +0200262 struct mei_me_hw *hw;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200263
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200264 dev = pci_get_drvdata(pdev);
265 if (!dev)
266 return;
267
Tomas Winkler180ea052014-03-18 22:52:02 +0200268 if (mei_pg_is_enabled(dev))
269 pm_runtime_get_noresume(&pdev->dev);
270
Tomas Winkler52c34562013-02-06 14:06:40 +0200271 hw = to_me_hw(dev);
272
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200273
Paul Bolleed6f7ac2013-10-17 13:52:10 +0300274 dev_dbg(&pdev->dev, "stop\n");
Tomas Winkler7cb035d2013-03-10 13:56:08 +0200275 mei_stop(dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200276
Tomas Winklere13fa902014-03-18 22:52:05 +0200277 if (!pci_dev_run_wake(pdev))
278 mei_me_unset_pm_domain(dev);
279
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200280 /* disable interrupts */
281 mei_disable_interrupts(dev);
282
283 free_irq(pdev->irq, dev);
284 pci_disable_msi(pdev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200285
Tomas Winkler52c34562013-02-06 14:06:40 +0200286 if (hw->mem_addr)
287 pci_iounmap(pdev, hw->mem_addr);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200288
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300289 mei_deregister(dev);
290
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200291 kfree(dev);
292
293 pci_release_regions(pdev);
294 pci_disable_device(pdev);
295
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200296
297}
Alexander Usyskin16833252014-02-18 14:31:08 +0200298#ifdef CONFIG_PM_SLEEP
Tomas Winklerb68301e2013-03-27 16:58:29 +0200299static int mei_me_pci_suspend(struct device *device)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200300{
301 struct pci_dev *pdev = to_pci_dev(device);
302 struct mei_device *dev = pci_get_drvdata(pdev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200303
304 if (!dev)
305 return -ENODEV;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200306
Paul Bolleed6f7ac2013-10-17 13:52:10 +0300307 dev_dbg(&pdev->dev, "suspend\n");
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200308
Tomas Winkler7cb035d2013-03-10 13:56:08 +0200309 mei_stop(dev);
310
311 mei_disable_interrupts(dev);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200312
313 free_irq(pdev->irq, dev);
314 pci_disable_msi(pdev);
315
Tomas Winkler7cb035d2013-03-10 13:56:08 +0200316 return 0;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200317}
318
Tomas Winklerb68301e2013-03-27 16:58:29 +0200319static int mei_me_pci_resume(struct device *device)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200320{
321 struct pci_dev *pdev = to_pci_dev(device);
322 struct mei_device *dev;
323 int err;
324
325 dev = pci_get_drvdata(pdev);
326 if (!dev)
327 return -ENODEV;
328
329 pci_enable_msi(pdev);
330
331 /* request and enable interrupt */
332 if (pci_dev_msi_enabled(pdev))
333 err = request_threaded_irq(pdev->irq,
334 NULL,
Tomas Winkler06ecd642013-02-06 14:06:42 +0200335 mei_me_irq_thread_handler,
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200336 IRQF_ONESHOT, KBUILD_MODNAME, dev);
337 else
338 err = request_threaded_irq(pdev->irq,
Tomas Winkler06ecd642013-02-06 14:06:42 +0200339 mei_me_irq_quick_handler,
340 mei_me_irq_thread_handler,
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200341 IRQF_SHARED, KBUILD_MODNAME, dev);
342
343 if (err) {
344 dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n",
345 pdev->irq);
346 return err;
347 }
348
Tomas Winkler33ec0822014-01-12 00:36:09 +0200349 err = mei_restart(dev);
350 if (err)
351 return err;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200352
353 /* Start timer if stopped in suspend */
354 schedule_delayed_work(&dev->timer_work, HZ);
355
Tomas Winkler33ec0822014-01-12 00:36:09 +0200356 return 0;
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200357}
Tomas Winkler180ea052014-03-18 22:52:02 +0200358#endif /* CONFIG_PM_SLEEP */
Alexander Usyskin16833252014-02-18 14:31:08 +0200359
Rafael J. Wysockibbd6d052014-12-04 22:43:07 +0100360#ifdef CONFIG_PM
Tomas Winkler180ea052014-03-18 22:52:02 +0200361static int mei_me_pm_runtime_idle(struct device *device)
362{
363 struct pci_dev *pdev = to_pci_dev(device);
364 struct mei_device *dev;
365
366 dev_dbg(&pdev->dev, "rpm: me: runtime_idle\n");
367
368 dev = pci_get_drvdata(pdev);
369 if (!dev)
370 return -ENODEV;
371 if (mei_write_is_idle(dev))
Alexander Usyskind5d83f82014-07-17 10:53:36 +0300372 pm_runtime_autosuspend(device);
Tomas Winkler180ea052014-03-18 22:52:02 +0200373
374 return -EBUSY;
375}
376
377static int mei_me_pm_runtime_suspend(struct device *device)
378{
379 struct pci_dev *pdev = to_pci_dev(device);
380 struct mei_device *dev;
381 int ret;
382
383 dev_dbg(&pdev->dev, "rpm: me: runtime suspend\n");
384
385 dev = pci_get_drvdata(pdev);
386 if (!dev)
387 return -ENODEV;
388
389 mutex_lock(&dev->device_lock);
390
391 if (mei_write_is_idle(dev))
392 ret = mei_me_pg_set_sync(dev);
393 else
394 ret = -EAGAIN;
395
396 mutex_unlock(&dev->device_lock);
397
398 dev_dbg(&pdev->dev, "rpm: me: runtime suspend ret=%d\n", ret);
399
400 return ret;
401}
402
403static int mei_me_pm_runtime_resume(struct device *device)
404{
405 struct pci_dev *pdev = to_pci_dev(device);
406 struct mei_device *dev;
407 int ret;
408
409 dev_dbg(&pdev->dev, "rpm: me: runtime resume\n");
410
411 dev = pci_get_drvdata(pdev);
412 if (!dev)
413 return -ENODEV;
414
415 mutex_lock(&dev->device_lock);
416
417 ret = mei_me_pg_unset_sync(dev);
418
419 mutex_unlock(&dev->device_lock);
420
421 dev_dbg(&pdev->dev, "rpm: me: runtime resume ret = %d\n", ret);
422
423 return ret;
424}
Tomas Winklere13fa902014-03-18 22:52:05 +0200425
426/**
Geert Uytterhoeven7efceb52014-09-16 22:00:47 +0200427 * mei_me_set_pm_domain - fill and set pm domain structure for device
Tomas Winklere13fa902014-03-18 22:52:05 +0200428 *
429 * @dev: mei_device
430 */
431static inline void mei_me_set_pm_domain(struct mei_device *dev)
432{
Tomas Winklerd08b8fc2014-09-29 16:31:44 +0300433 struct pci_dev *pdev = to_pci_dev(dev->dev);
Tomas Winklere13fa902014-03-18 22:52:05 +0200434
435 if (pdev->dev.bus && pdev->dev.bus->pm) {
436 dev->pg_domain.ops = *pdev->dev.bus->pm;
437
438 dev->pg_domain.ops.runtime_suspend = mei_me_pm_runtime_suspend;
439 dev->pg_domain.ops.runtime_resume = mei_me_pm_runtime_resume;
440 dev->pg_domain.ops.runtime_idle = mei_me_pm_runtime_idle;
441
442 pdev->dev.pm_domain = &dev->pg_domain;
443 }
444}
445
446/**
Geert Uytterhoeven7efceb52014-09-16 22:00:47 +0200447 * mei_me_unset_pm_domain - clean pm domain structure for device
Tomas Winklere13fa902014-03-18 22:52:05 +0200448 *
449 * @dev: mei_device
450 */
451static inline void mei_me_unset_pm_domain(struct mei_device *dev)
452{
453 /* stop using pm callbacks if any */
Tomas Winkler2bf94cab2014-09-29 16:31:42 +0300454 dev->dev->pm_domain = NULL;
Tomas Winklere13fa902014-03-18 22:52:05 +0200455}
Tomas Winkler180ea052014-03-18 22:52:02 +0200456
Tomas Winkler180ea052014-03-18 22:52:02 +0200457static const struct dev_pm_ops mei_me_pm_ops = {
458 SET_SYSTEM_SLEEP_PM_OPS(mei_me_pci_suspend,
459 mei_me_pci_resume)
460 SET_RUNTIME_PM_OPS(
461 mei_me_pm_runtime_suspend,
462 mei_me_pm_runtime_resume,
463 mei_me_pm_runtime_idle)
464};
465
Tomas Winklerb68301e2013-03-27 16:58:29 +0200466#define MEI_ME_PM_OPS (&mei_me_pm_ops)
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200467#else
Tomas Winklerb68301e2013-03-27 16:58:29 +0200468#define MEI_ME_PM_OPS NULL
Tomas Winkler180ea052014-03-18 22:52:02 +0200469#endif /* CONFIG_PM */
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200470/*
471 * PCI driver structure
472 */
Tomas Winklerb68301e2013-03-27 16:58:29 +0200473static struct pci_driver mei_me_driver = {
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200474 .name = KBUILD_MODNAME,
Tomas Winklerb68301e2013-03-27 16:58:29 +0200475 .id_table = mei_me_pci_tbl,
476 .probe = mei_me_probe,
477 .remove = mei_me_remove,
478 .shutdown = mei_me_remove,
479 .driver.pm = MEI_ME_PM_OPS,
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200480};
481
Tomas Winklerb68301e2013-03-27 16:58:29 +0200482module_pci_driver(mei_me_driver);
Tomas Winkler2703d4b2013-02-06 14:06:39 +0200483
484MODULE_AUTHOR("Intel Corporation");
485MODULE_DESCRIPTION("Intel(R) Management Engine Interface");
486MODULE_LICENSE("GPL v2");