Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 1 | /* |
| 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 Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 16 | #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> |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 24 | #include <linux/pci.h> |
| 25 | #include <linux/poll.h> |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 26 | #include <linux/ioctl.h> |
| 27 | #include <linux/cdev.h> |
| 28 | #include <linux/sched.h> |
| 29 | #include <linux/uuid.h> |
| 30 | #include <linux/compat.h> |
| 31 | #include <linux/jiffies.h> |
| 32 | #include <linux/interrupt.h> |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 33 | |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 34 | #include <linux/pm_runtime.h> |
| 35 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 36 | #include <linux/mei.h> |
| 37 | |
| 38 | #include "mei_dev.h" |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 39 | #include "client.h" |
Tomas Winkler | 6e4cd27 | 2014-03-11 14:49:23 +0200 | [diff] [blame] | 40 | #include "hw-me-regs.h" |
| 41 | #include "hw-me.h" |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 42 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 43 | /* mei_pci_tbl - PCI Device ID Table */ |
Tomas Winkler | a05f8f8 | 2014-03-16 14:35:58 +0200 | [diff] [blame] | 44 | static const struct pci_device_id mei_me_pci_tbl[] = { |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 45 | {MEI_PCI_DEVICE(MEI_DEV_ID_82946GZ, mei_me_legacy_cfg)}, |
| 46 | {MEI_PCI_DEVICE(MEI_DEV_ID_82G35, mei_me_legacy_cfg)}, |
| 47 | {MEI_PCI_DEVICE(MEI_DEV_ID_82Q965, mei_me_legacy_cfg)}, |
| 48 | {MEI_PCI_DEVICE(MEI_DEV_ID_82G965, mei_me_legacy_cfg)}, |
| 49 | {MEI_PCI_DEVICE(MEI_DEV_ID_82GM965, mei_me_legacy_cfg)}, |
| 50 | {MEI_PCI_DEVICE(MEI_DEV_ID_82GME965, mei_me_legacy_cfg)}, |
| 51 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82Q35, mei_me_legacy_cfg)}, |
| 52 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82G33, mei_me_legacy_cfg)}, |
| 53 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82Q33, mei_me_legacy_cfg)}, |
| 54 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_82X38, mei_me_legacy_cfg)}, |
| 55 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_3200, mei_me_legacy_cfg)}, |
| 56 | |
| 57 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_6, mei_me_legacy_cfg)}, |
| 58 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_7, mei_me_legacy_cfg)}, |
| 59 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_8, mei_me_legacy_cfg)}, |
| 60 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_9, mei_me_legacy_cfg)}, |
| 61 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9_10, mei_me_legacy_cfg)}, |
| 62 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_1, mei_me_legacy_cfg)}, |
| 63 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_2, mei_me_legacy_cfg)}, |
| 64 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_3, mei_me_legacy_cfg)}, |
| 65 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH9M_4, mei_me_legacy_cfg)}, |
| 66 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_1, mei_me_ich_cfg)}, |
| 67 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_2, mei_me_ich_cfg)}, |
| 68 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_3, mei_me_ich_cfg)}, |
| 69 | {MEI_PCI_DEVICE(MEI_DEV_ID_ICH10_4, mei_me_ich_cfg)}, |
| 70 | |
| 71 | {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_1, mei_me_pch_cfg)}, |
| 72 | {MEI_PCI_DEVICE(MEI_DEV_ID_IBXPK_2, mei_me_pch_cfg)}, |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 73 | {MEI_PCI_DEVICE(MEI_DEV_ID_CPT_1, mei_me_pch_cpt_pbg_cfg)}, |
| 74 | {MEI_PCI_DEVICE(MEI_DEV_ID_PBG_1, mei_me_pch_cpt_pbg_cfg)}, |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 75 | {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_1, mei_me_pch_cfg)}, |
| 76 | {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_2, mei_me_pch_cfg)}, |
| 77 | {MEI_PCI_DEVICE(MEI_DEV_ID_PPT_3, mei_me_pch_cfg)}, |
Alexander Usyskin | edca5ea | 2014-11-19 17:01:38 +0200 | [diff] [blame] | 78 | {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_H, mei_me_pch8_sps_cfg)}, |
| 79 | {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_W, mei_me_pch8_sps_cfg)}, |
| 80 | {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_LP, mei_me_pch8_cfg)}, |
| 81 | {MEI_PCI_DEVICE(MEI_DEV_ID_LPT_HR, mei_me_pch8_sps_cfg)}, |
| 82 | {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP, mei_me_pch8_cfg)}, |
| 83 | {MEI_PCI_DEVICE(MEI_DEV_ID_WPT_LP_2, mei_me_pch8_cfg)}, |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 84 | |
Tomas Winkler | 1625c7e | 2015-08-02 22:20:57 +0300 | [diff] [blame^] | 85 | {MEI_PCI_DEVICE(MEI_DEV_ID_SPT, mei_me_pch8_cfg)}, |
| 86 | {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_2, mei_me_pch8_cfg)}, |
| 87 | {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H, mei_me_pch8_cfg)}, |
| 88 | {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H_2, mei_me_pch8_cfg)}, |
| 89 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 90 | /* required last entry */ |
| 91 | {0, } |
| 92 | }; |
| 93 | |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 94 | MODULE_DEVICE_TABLE(pci, mei_me_pci_tbl); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 95 | |
Rafael J. Wysocki | bbd6d05 | 2014-12-04 22:43:07 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_PM |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 97 | static inline void mei_me_set_pm_domain(struct mei_device *dev); |
| 98 | static inline void mei_me_unset_pm_domain(struct mei_device *dev); |
| 99 | #else |
| 100 | static inline void mei_me_set_pm_domain(struct mei_device *dev) {} |
| 101 | static inline void mei_me_unset_pm_domain(struct mei_device *dev) {} |
Rafael J. Wysocki | bbd6d05 | 2014-12-04 22:43:07 +0100 | [diff] [blame] | 102 | #endif /* CONFIG_PM */ |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 103 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 104 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 105 | * mei_me_quirk_probe - probe for devices that doesn't valid ME interface |
Masanari Iida | 393b148 | 2013-04-05 01:05:05 +0900 | [diff] [blame] | 106 | * |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 107 | * @pdev: PCI device structure |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 108 | * @cfg: per generation config |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 109 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 110 | * Return: true if ME Interface is valid, false otherwise |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 111 | */ |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 112 | static bool mei_me_quirk_probe(struct pci_dev *pdev, |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 113 | const struct mei_cfg *cfg) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 114 | { |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 115 | if (cfg->quirk_probe && cfg->quirk_probe(pdev)) { |
| 116 | dev_info(&pdev->dev, "Device doesn't have valid ME Interface\n"); |
| 117 | return false; |
Tomas Winkler | 5e6533a | 2014-03-25 21:25:18 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 120 | return true; |
| 121 | } |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 122 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 123 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 124 | * mei_me_probe - Device Initialization Routine |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 125 | * |
| 126 | * @pdev: PCI device structure |
| 127 | * @ent: entry in kcs_pci_tbl |
| 128 | * |
Alexander Usyskin | a8605ea | 2014-09-29 16:31:49 +0300 | [diff] [blame] | 129 | * Return: 0 on success, <0 on failure. |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 130 | */ |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 131 | static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 132 | { |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 133 | const struct mei_cfg *cfg = (struct mei_cfg *)(ent->driver_data); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 134 | struct mei_device *dev; |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 135 | struct mei_me_hw *hw; |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 136 | unsigned int irqflags; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 137 | int err; |
| 138 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 139 | |
Tomas Winkler | c919951 | 2014-05-13 01:30:54 +0300 | [diff] [blame] | 140 | if (!mei_me_quirk_probe(pdev, cfg)) |
| 141 | return -ENODEV; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 142 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 143 | /* enable pci dev */ |
| 144 | err = pci_enable_device(pdev); |
| 145 | if (err) { |
| 146 | dev_err(&pdev->dev, "failed to enable pci device.\n"); |
| 147 | goto end; |
| 148 | } |
| 149 | /* set PCI host mastering */ |
| 150 | pci_set_master(pdev); |
| 151 | /* pci request regions for mei driver */ |
| 152 | err = pci_request_regions(pdev, KBUILD_MODNAME); |
| 153 | if (err) { |
| 154 | dev_err(&pdev->dev, "failed to get pci regions.\n"); |
| 155 | goto disable_device; |
| 156 | } |
Tomas Winkler | 3ecfb16 | 2013-12-17 15:56:57 +0200 | [diff] [blame] | 157 | |
| 158 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) || |
| 159 | dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
| 160 | |
| 161 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 162 | if (err) |
| 163 | err = dma_set_coherent_mask(&pdev->dev, |
| 164 | DMA_BIT_MASK(32)); |
| 165 | } |
| 166 | if (err) { |
| 167 | dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
| 168 | goto release_regions; |
| 169 | } |
| 170 | |
| 171 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 172 | /* allocates and initializes the mei dev structure */ |
Alexander Usyskin | 8d929d4 | 2014-05-13 01:30:53 +0300 | [diff] [blame] | 173 | dev = mei_me_dev_init(pdev, cfg); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 174 | if (!dev) { |
| 175 | err = -ENOMEM; |
| 176 | goto release_regions; |
| 177 | } |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 178 | hw = to_me_hw(dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 179 | /* mapping IO device memory */ |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 180 | hw->mem_addr = pci_iomap(pdev, 0, 0); |
| 181 | if (!hw->mem_addr) { |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 182 | dev_err(&pdev->dev, "mapping I/O device memory failure.\n"); |
| 183 | err = -ENOMEM; |
| 184 | goto free_device; |
| 185 | } |
| 186 | pci_enable_msi(pdev); |
| 187 | |
| 188 | /* request and enable interrupt */ |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 189 | irqflags = pci_dev_msi_enabled(pdev) ? IRQF_ONESHOT : IRQF_SHARED; |
| 190 | |
| 191 | err = request_threaded_irq(pdev->irq, |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 192 | mei_me_irq_quick_handler, |
| 193 | mei_me_irq_thread_handler, |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 194 | irqflags, KBUILD_MODNAME, dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 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 Winkler | c4d589b | 2013-03-27 16:58:28 +0200 | [diff] [blame] | 201 | if (mei_start(dev)) { |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 202 | dev_err(&pdev->dev, "init hw failure.\n"); |
| 203 | err = -ENODEV; |
| 204 | goto release_irq; |
| 205 | } |
| 206 | |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 207 | pm_runtime_set_autosuspend_delay(&pdev->dev, MEI_ME_RPM_TIMEOUT); |
| 208 | pm_runtime_use_autosuspend(&pdev->dev); |
| 209 | |
Alexander Usyskin | f3d8e87 | 2014-06-23 15:10:35 +0300 | [diff] [blame] | 210 | err = mei_register(dev, &pdev->dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 211 | if (err) |
| 212 | goto release_irq; |
| 213 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 214 | pci_set_drvdata(pdev, dev); |
| 215 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 216 | schedule_delayed_work(&dev->timer_work, HZ); |
| 217 | |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 218 | /* |
| 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 Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 226 | if (mei_pg_is_enabled(dev)) |
| 227 | pm_runtime_put_noidle(&pdev->dev); |
| 228 | |
Alexander Usyskin | c4e87b5 | 2013-10-21 22:05:42 +0300 | [diff] [blame] | 229 | dev_dbg(&pdev->dev, "initialization successful.\n"); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 230 | |
| 231 | return 0; |
| 232 | |
| 233 | release_irq: |
Tomas Winkler | dc844b0 | 2013-11-11 13:26:06 +0200 | [diff] [blame] | 234 | mei_cancel_work(dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 235 | mei_disable_interrupts(dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 236 | free_irq(pdev->irq, dev); |
| 237 | disable_msi: |
| 238 | pci_disable_msi(pdev); |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 239 | pci_iounmap(pdev, hw->mem_addr); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 240 | free_device: |
| 241 | kfree(dev); |
| 242 | release_regions: |
| 243 | pci_release_regions(pdev); |
| 244 | disable_device: |
| 245 | pci_disable_device(pdev); |
| 246 | end: |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 247 | dev_err(&pdev->dev, "initialization failed.\n"); |
| 248 | return err; |
| 249 | } |
| 250 | |
| 251 | /** |
Alexander Usyskin | ce23139 | 2014-09-29 16:31:50 +0300 | [diff] [blame] | 252 | * mei_me_remove - Device Removal Routine |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 253 | * |
| 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 Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 259 | static void mei_me_remove(struct pci_dev *pdev) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 260 | { |
| 261 | struct mei_device *dev; |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 262 | struct mei_me_hw *hw; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 263 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 264 | dev = pci_get_drvdata(pdev); |
| 265 | if (!dev) |
| 266 | return; |
| 267 | |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 268 | if (mei_pg_is_enabled(dev)) |
| 269 | pm_runtime_get_noresume(&pdev->dev); |
| 270 | |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 271 | hw = to_me_hw(dev); |
| 272 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 273 | |
Paul Bolle | ed6f7ac | 2013-10-17 13:52:10 +0300 | [diff] [blame] | 274 | dev_dbg(&pdev->dev, "stop\n"); |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 275 | mei_stop(dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 276 | |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 277 | if (!pci_dev_run_wake(pdev)) |
| 278 | mei_me_unset_pm_domain(dev); |
| 279 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 280 | /* disable interrupts */ |
| 281 | mei_disable_interrupts(dev); |
| 282 | |
| 283 | free_irq(pdev->irq, dev); |
| 284 | pci_disable_msi(pdev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 285 | |
Tomas Winkler | 52c3456 | 2013-02-06 14:06:40 +0200 | [diff] [blame] | 286 | if (hw->mem_addr) |
| 287 | pci_iounmap(pdev, hw->mem_addr); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 288 | |
Tomas Winkler | 30e53bb | 2013-04-05 22:10:34 +0300 | [diff] [blame] | 289 | mei_deregister(dev); |
| 290 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 291 | kfree(dev); |
| 292 | |
| 293 | pci_release_regions(pdev); |
| 294 | pci_disable_device(pdev); |
| 295 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 296 | |
| 297 | } |
Alexander Usyskin | 1683325 | 2014-02-18 14:31:08 +0200 | [diff] [blame] | 298 | #ifdef CONFIG_PM_SLEEP |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 299 | static int mei_me_pci_suspend(struct device *device) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 300 | { |
| 301 | struct pci_dev *pdev = to_pci_dev(device); |
| 302 | struct mei_device *dev = pci_get_drvdata(pdev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 303 | |
| 304 | if (!dev) |
| 305 | return -ENODEV; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 306 | |
Paul Bolle | ed6f7ac | 2013-10-17 13:52:10 +0300 | [diff] [blame] | 307 | dev_dbg(&pdev->dev, "suspend\n"); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 308 | |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 309 | mei_stop(dev); |
| 310 | |
| 311 | mei_disable_interrupts(dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 312 | |
| 313 | free_irq(pdev->irq, dev); |
| 314 | pci_disable_msi(pdev); |
| 315 | |
Tomas Winkler | 7cb035d | 2013-03-10 13:56:08 +0200 | [diff] [blame] | 316 | return 0; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 319 | static int mei_me_pci_resume(struct device *device) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 320 | { |
| 321 | struct pci_dev *pdev = to_pci_dev(device); |
| 322 | struct mei_device *dev; |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 323 | unsigned int irqflags; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 324 | int err; |
| 325 | |
| 326 | dev = pci_get_drvdata(pdev); |
| 327 | if (!dev) |
| 328 | return -ENODEV; |
| 329 | |
| 330 | pci_enable_msi(pdev); |
| 331 | |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 332 | irqflags = pci_dev_msi_enabled(pdev) ? IRQF_ONESHOT : IRQF_SHARED; |
| 333 | |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 334 | /* request and enable interrupt */ |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 335 | err = request_threaded_irq(pdev->irq, |
Tomas Winkler | 06ecd64 | 2013-02-06 14:06:42 +0200 | [diff] [blame] | 336 | mei_me_irq_quick_handler, |
| 337 | mei_me_irq_thread_handler, |
Alexander Usyskin | 1fa55b4 | 2015-08-02 22:20:52 +0300 | [diff] [blame] | 338 | irqflags, KBUILD_MODNAME, dev); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 339 | |
| 340 | if (err) { |
| 341 | dev_err(&pdev->dev, "request_threaded_irq failed: irq = %d.\n", |
| 342 | pdev->irq); |
| 343 | return err; |
| 344 | } |
| 345 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 346 | err = mei_restart(dev); |
| 347 | if (err) |
| 348 | return err; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 349 | |
| 350 | /* Start timer if stopped in suspend */ |
| 351 | schedule_delayed_work(&dev->timer_work, HZ); |
| 352 | |
Tomas Winkler | 33ec082 | 2014-01-12 00:36:09 +0200 | [diff] [blame] | 353 | return 0; |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 354 | } |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 355 | #endif /* CONFIG_PM_SLEEP */ |
Alexander Usyskin | 1683325 | 2014-02-18 14:31:08 +0200 | [diff] [blame] | 356 | |
Rafael J. Wysocki | bbd6d05 | 2014-12-04 22:43:07 +0100 | [diff] [blame] | 357 | #ifdef CONFIG_PM |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 358 | static int mei_me_pm_runtime_idle(struct device *device) |
| 359 | { |
| 360 | struct pci_dev *pdev = to_pci_dev(device); |
| 361 | struct mei_device *dev; |
| 362 | |
| 363 | dev_dbg(&pdev->dev, "rpm: me: runtime_idle\n"); |
| 364 | |
| 365 | dev = pci_get_drvdata(pdev); |
| 366 | if (!dev) |
| 367 | return -ENODEV; |
| 368 | if (mei_write_is_idle(dev)) |
Alexander Usyskin | d5d83f8 | 2014-07-17 10:53:36 +0300 | [diff] [blame] | 369 | pm_runtime_autosuspend(device); |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 370 | |
| 371 | return -EBUSY; |
| 372 | } |
| 373 | |
| 374 | static int mei_me_pm_runtime_suspend(struct device *device) |
| 375 | { |
| 376 | struct pci_dev *pdev = to_pci_dev(device); |
| 377 | struct mei_device *dev; |
| 378 | int ret; |
| 379 | |
| 380 | dev_dbg(&pdev->dev, "rpm: me: runtime suspend\n"); |
| 381 | |
| 382 | dev = pci_get_drvdata(pdev); |
| 383 | if (!dev) |
| 384 | return -ENODEV; |
| 385 | |
| 386 | mutex_lock(&dev->device_lock); |
| 387 | |
| 388 | if (mei_write_is_idle(dev)) |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 389 | ret = mei_me_pg_enter_sync(dev); |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 390 | else |
| 391 | ret = -EAGAIN; |
| 392 | |
| 393 | mutex_unlock(&dev->device_lock); |
| 394 | |
| 395 | dev_dbg(&pdev->dev, "rpm: me: runtime suspend ret=%d\n", ret); |
| 396 | |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | static int mei_me_pm_runtime_resume(struct device *device) |
| 401 | { |
| 402 | struct pci_dev *pdev = to_pci_dev(device); |
| 403 | struct mei_device *dev; |
| 404 | int ret; |
| 405 | |
| 406 | dev_dbg(&pdev->dev, "rpm: me: runtime resume\n"); |
| 407 | |
| 408 | dev = pci_get_drvdata(pdev); |
| 409 | if (!dev) |
| 410 | return -ENODEV; |
| 411 | |
| 412 | mutex_lock(&dev->device_lock); |
| 413 | |
Alexander Usyskin | 2d1995f | 2015-02-10 10:39:34 +0200 | [diff] [blame] | 414 | ret = mei_me_pg_exit_sync(dev); |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 415 | |
| 416 | mutex_unlock(&dev->device_lock); |
| 417 | |
| 418 | dev_dbg(&pdev->dev, "rpm: me: runtime resume ret = %d\n", ret); |
| 419 | |
| 420 | return ret; |
| 421 | } |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 422 | |
| 423 | /** |
Geert Uytterhoeven | 7efceb5 | 2014-09-16 22:00:47 +0200 | [diff] [blame] | 424 | * mei_me_set_pm_domain - fill and set pm domain structure for device |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 425 | * |
| 426 | * @dev: mei_device |
| 427 | */ |
| 428 | static inline void mei_me_set_pm_domain(struct mei_device *dev) |
| 429 | { |
Tomas Winkler | d08b8fc | 2014-09-29 16:31:44 +0300 | [diff] [blame] | 430 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 431 | |
| 432 | if (pdev->dev.bus && pdev->dev.bus->pm) { |
| 433 | dev->pg_domain.ops = *pdev->dev.bus->pm; |
| 434 | |
| 435 | dev->pg_domain.ops.runtime_suspend = mei_me_pm_runtime_suspend; |
| 436 | dev->pg_domain.ops.runtime_resume = mei_me_pm_runtime_resume; |
| 437 | dev->pg_domain.ops.runtime_idle = mei_me_pm_runtime_idle; |
| 438 | |
| 439 | pdev->dev.pm_domain = &dev->pg_domain; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /** |
Geert Uytterhoeven | 7efceb5 | 2014-09-16 22:00:47 +0200 | [diff] [blame] | 444 | * mei_me_unset_pm_domain - clean pm domain structure for device |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 445 | * |
| 446 | * @dev: mei_device |
| 447 | */ |
| 448 | static inline void mei_me_unset_pm_domain(struct mei_device *dev) |
| 449 | { |
| 450 | /* stop using pm callbacks if any */ |
Tomas Winkler | 2bf94cab | 2014-09-29 16:31:42 +0300 | [diff] [blame] | 451 | dev->dev->pm_domain = NULL; |
Tomas Winkler | e13fa90 | 2014-03-18 22:52:05 +0200 | [diff] [blame] | 452 | } |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 453 | |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 454 | static const struct dev_pm_ops mei_me_pm_ops = { |
| 455 | SET_SYSTEM_SLEEP_PM_OPS(mei_me_pci_suspend, |
| 456 | mei_me_pci_resume) |
| 457 | SET_RUNTIME_PM_OPS( |
| 458 | mei_me_pm_runtime_suspend, |
| 459 | mei_me_pm_runtime_resume, |
| 460 | mei_me_pm_runtime_idle) |
| 461 | }; |
| 462 | |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 463 | #define MEI_ME_PM_OPS (&mei_me_pm_ops) |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 464 | #else |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 465 | #define MEI_ME_PM_OPS NULL |
Tomas Winkler | 180ea05 | 2014-03-18 22:52:02 +0200 | [diff] [blame] | 466 | #endif /* CONFIG_PM */ |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 467 | /* |
| 468 | * PCI driver structure |
| 469 | */ |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 470 | static struct pci_driver mei_me_driver = { |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 471 | .name = KBUILD_MODNAME, |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 472 | .id_table = mei_me_pci_tbl, |
| 473 | .probe = mei_me_probe, |
| 474 | .remove = mei_me_remove, |
| 475 | .shutdown = mei_me_remove, |
| 476 | .driver.pm = MEI_ME_PM_OPS, |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 477 | }; |
| 478 | |
Tomas Winkler | b68301e | 2013-03-27 16:58:29 +0200 | [diff] [blame] | 479 | module_pci_driver(mei_me_driver); |
Tomas Winkler | 2703d4b | 2013-02-06 14:06:39 +0200 | [diff] [blame] | 480 | |
| 481 | MODULE_AUTHOR("Intel Corporation"); |
| 482 | MODULE_DESCRIPTION("Intel(R) Management Engine Interface"); |
| 483 | MODULE_LICENSE("GPL v2"); |