msi.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * File: msi.c
  3. * Purpose: PCI Message Signaled Interrupt (MSI)
  4. *
  5. * Copyright (C) 2003-2004 Intel
  6. * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/irq.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/init.h>
  12. #include <linux/ioport.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/pci.h>
  15. #include <linux/proc_fs.h>
  16. #include <asm/errno.h>
  17. #include <asm/io.h>
  18. #include <asm/smp.h>
  19. #include "pci.h"
  20. #include "msi.h"
  21. static DEFINE_SPINLOCK(msi_lock);
  22. static struct msi_desc* msi_desc[NR_IRQS] = { [0 ... NR_IRQS-1] = NULL };
  23. static kmem_cache_t* msi_cachep;
  24. static int pci_msi_enable = 1;
  25. static int last_alloc_vector;
  26. static int nr_released_vectors;
  27. static int nr_reserved_vectors = NR_HP_RESERVED_VECTORS;
  28. static int nr_msix_devices;
  29. #ifndef CONFIG_X86_IO_APIC
  30. int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1};
  31. #endif
  32. static struct msi_ops *msi_ops;
  33. int
  34. msi_register(struct msi_ops *ops)
  35. {
  36. msi_ops = ops;
  37. return 0;
  38. }
  39. static int msi_cache_init(void)
  40. {
  41. msi_cachep = kmem_cache_create("msi_cache", sizeof(struct msi_desc),
  42. 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
  43. if (!msi_cachep)
  44. return -ENOMEM;
  45. return 0;
  46. }
  47. static void msi_set_mask_bit(unsigned int vector, int flag)
  48. {
  49. struct msi_desc *entry;
  50. entry = (struct msi_desc *)msi_desc[vector];
  51. if (!entry || !entry->dev || !entry->mask_base)
  52. return;
  53. switch (entry->msi_attrib.type) {
  54. case PCI_CAP_ID_MSI:
  55. {
  56. int pos;
  57. u32 mask_bits;
  58. pos = (long)entry->mask_base;
  59. pci_read_config_dword(entry->dev, pos, &mask_bits);
  60. mask_bits &= ~(1);
  61. mask_bits |= flag;
  62. pci_write_config_dword(entry->dev, pos, mask_bits);
  63. break;
  64. }
  65. case PCI_CAP_ID_MSIX:
  66. {
  67. int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
  68. PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
  69. writel(flag, entry->mask_base + offset);
  70. break;
  71. }
  72. default:
  73. break;
  74. }
  75. }
  76. static void read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
  77. {
  78. switch(entry->msi_attrib.type) {
  79. case PCI_CAP_ID_MSI:
  80. {
  81. struct pci_dev *dev = entry->dev;
  82. int pos = entry->msi_attrib.pos;
  83. u16 data;
  84. pci_read_config_dword(dev, msi_lower_address_reg(pos),
  85. &msg->address_lo);
  86. if (entry->msi_attrib.is_64) {
  87. pci_read_config_dword(dev, msi_upper_address_reg(pos),
  88. &msg->address_hi);
  89. pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
  90. } else {
  91. msg->address_hi = 0;
  92. pci_read_config_word(dev, msi_data_reg(pos, 1), &data);
  93. }
  94. msg->data = data;
  95. break;
  96. }
  97. case PCI_CAP_ID_MSIX:
  98. {
  99. void __iomem *base;
  100. base = entry->mask_base +
  101. entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
  102. msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
  103. msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
  104. msg->data = readl(base + PCI_MSIX_ENTRY_DATA_OFFSET);
  105. break;
  106. }
  107. default:
  108. BUG();
  109. }
  110. }
  111. static void write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
  112. {
  113. switch (entry->msi_attrib.type) {
  114. case PCI_CAP_ID_MSI:
  115. {
  116. struct pci_dev *dev = entry->dev;
  117. int pos = entry->msi_attrib.pos;
  118. pci_write_config_dword(dev, msi_lower_address_reg(pos),
  119. msg->address_lo);
  120. if (entry->msi_attrib.is_64) {
  121. pci_write_config_dword(dev, msi_upper_address_reg(pos),
  122. msg->address_hi);
  123. pci_write_config_word(dev, msi_data_reg(pos, 1),
  124. msg->data);
  125. } else {
  126. pci_write_config_word(dev, msi_data_reg(pos, 0),
  127. msg->data);
  128. }
  129. break;
  130. }
  131. case PCI_CAP_ID_MSIX:
  132. {
  133. void __iomem *base;
  134. base = entry->mask_base +
  135. entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
  136. writel(msg->address_lo,
  137. base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
  138. writel(msg->address_hi,
  139. base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
  140. writel(msg->data, base + PCI_MSIX_ENTRY_DATA_OFFSET);
  141. break;
  142. }
  143. default:
  144. BUG();
  145. }
  146. }
  147. #ifdef CONFIG_SMP
  148. static void set_msi_affinity(unsigned int vector, cpumask_t cpu_mask)
  149. {
  150. struct msi_desc *entry;
  151. struct msi_msg msg;
  152. unsigned int irq = vector;
  153. unsigned int dest_cpu = first_cpu(cpu_mask);
  154. entry = (struct msi_desc *)msi_desc[vector];
  155. if (!entry || !entry->dev)
  156. return;
  157. read_msi_msg(entry, &msg);
  158. msi_ops->target(vector, dest_cpu, &msg.address_hi, &msg.address_lo);
  159. write_msi_msg(entry, &msg);
  160. set_native_irq_info(irq, cpu_mask);
  161. }
  162. #else
  163. #define set_msi_affinity NULL
  164. #endif /* CONFIG_SMP */
  165. static void mask_MSI_irq(unsigned int vector)
  166. {
  167. msi_set_mask_bit(vector, 1);
  168. }
  169. static void unmask_MSI_irq(unsigned int vector)
  170. {
  171. msi_set_mask_bit(vector, 0);
  172. }
  173. static unsigned int startup_msi_irq_wo_maskbit(unsigned int vector)
  174. {
  175. struct msi_desc *entry;
  176. unsigned long flags;
  177. spin_lock_irqsave(&msi_lock, flags);
  178. entry = msi_desc[vector];
  179. if (!entry || !entry->dev) {
  180. spin_unlock_irqrestore(&msi_lock, flags);
  181. return 0;
  182. }
  183. entry->msi_attrib.state = 1; /* Mark it active */
  184. spin_unlock_irqrestore(&msi_lock, flags);
  185. return 0; /* never anything pending */
  186. }
  187. static unsigned int startup_msi_irq_w_maskbit(unsigned int vector)
  188. {
  189. startup_msi_irq_wo_maskbit(vector);
  190. unmask_MSI_irq(vector);
  191. return 0; /* never anything pending */
  192. }
  193. static void shutdown_msi_irq(unsigned int vector)
  194. {
  195. struct msi_desc *entry;
  196. unsigned long flags;
  197. spin_lock_irqsave(&msi_lock, flags);
  198. entry = msi_desc[vector];
  199. if (entry && entry->dev)
  200. entry->msi_attrib.state = 0; /* Mark it not active */
  201. spin_unlock_irqrestore(&msi_lock, flags);
  202. }
  203. static void end_msi_irq_wo_maskbit(unsigned int vector)
  204. {
  205. move_native_irq(vector);
  206. ack_APIC_irq();
  207. }
  208. static void end_msi_irq_w_maskbit(unsigned int vector)
  209. {
  210. move_native_irq(vector);
  211. unmask_MSI_irq(vector);
  212. ack_APIC_irq();
  213. }
  214. static void do_nothing(unsigned int vector)
  215. {
  216. }
  217. /*
  218. * Interrupt Type for MSI-X PCI/PCI-X/PCI-Express Devices,
  219. * which implement the MSI-X Capability Structure.
  220. */
  221. static struct hw_interrupt_type msix_irq_type = {
  222. .typename = "PCI-MSI-X",
  223. .startup = startup_msi_irq_w_maskbit,
  224. .shutdown = shutdown_msi_irq,
  225. .enable = unmask_MSI_irq,
  226. .disable = mask_MSI_irq,
  227. .ack = mask_MSI_irq,
  228. .end = end_msi_irq_w_maskbit,
  229. .set_affinity = set_msi_affinity
  230. };
  231. /*
  232. * Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices,
  233. * which implement the MSI Capability Structure with
  234. * Mask-and-Pending Bits.
  235. */
  236. static struct hw_interrupt_type msi_irq_w_maskbit_type = {
  237. .typename = "PCI-MSI",
  238. .startup = startup_msi_irq_w_maskbit,
  239. .shutdown = shutdown_msi_irq,
  240. .enable = unmask_MSI_irq,
  241. .disable = mask_MSI_irq,
  242. .ack = mask_MSI_irq,
  243. .end = end_msi_irq_w_maskbit,
  244. .set_affinity = set_msi_affinity
  245. };
  246. /*
  247. * Interrupt Type for MSI PCI/PCI-X/PCI-Express Devices,
  248. * which implement the MSI Capability Structure without
  249. * Mask-and-Pending Bits.
  250. */
  251. static struct hw_interrupt_type msi_irq_wo_maskbit_type = {
  252. .typename = "PCI-MSI",
  253. .startup = startup_msi_irq_wo_maskbit,
  254. .shutdown = shutdown_msi_irq,
  255. .enable = do_nothing,
  256. .disable = do_nothing,
  257. .ack = do_nothing,
  258. .end = end_msi_irq_wo_maskbit,
  259. .set_affinity = set_msi_affinity
  260. };
  261. static int msi_free_vector(struct pci_dev* dev, int vector, int reassign);
  262. static int assign_msi_vector(void)
  263. {
  264. static int new_vector_avail = 1;
  265. int vector;
  266. unsigned long flags;
  267. /*
  268. * msi_lock is provided to ensure that successful allocation of MSI
  269. * vector is assigned unique among drivers.
  270. */
  271. spin_lock_irqsave(&msi_lock, flags);
  272. if (!new_vector_avail) {
  273. int free_vector = 0;
  274. /*
  275. * vector_irq[] = -1 indicates that this specific vector is:
  276. * - assigned for MSI (since MSI have no associated IRQ) or
  277. * - assigned for legacy if less than 16, or
  278. * - having no corresponding 1:1 vector-to-IOxAPIC IRQ mapping
  279. * vector_irq[] = 0 indicates that this vector, previously
  280. * assigned for MSI, is freed by hotplug removed operations.
  281. * This vector will be reused for any subsequent hotplug added
  282. * operations.
  283. * vector_irq[] > 0 indicates that this vector is assigned for
  284. * IOxAPIC IRQs. This vector and its value provides a 1-to-1
  285. * vector-to-IOxAPIC IRQ mapping.
  286. */
  287. for (vector = FIRST_DEVICE_VECTOR; vector < NR_IRQS; vector++) {
  288. if (vector_irq[vector] != 0)
  289. continue;
  290. free_vector = vector;
  291. if (!msi_desc[vector])
  292. break;
  293. else
  294. continue;
  295. }
  296. if (!free_vector) {
  297. spin_unlock_irqrestore(&msi_lock, flags);
  298. return -EBUSY;
  299. }
  300. vector_irq[free_vector] = -1;
  301. nr_released_vectors--;
  302. spin_unlock_irqrestore(&msi_lock, flags);
  303. if (msi_desc[free_vector] != NULL) {
  304. struct pci_dev *dev;
  305. int tail;
  306. /* free all linked vectors before re-assign */
  307. do {
  308. spin_lock_irqsave(&msi_lock, flags);
  309. dev = msi_desc[free_vector]->dev;
  310. tail = msi_desc[free_vector]->link.tail;
  311. spin_unlock_irqrestore(&msi_lock, flags);
  312. msi_free_vector(dev, tail, 1);
  313. } while (free_vector != tail);
  314. }
  315. return free_vector;
  316. }
  317. vector = assign_irq_vector(AUTO_ASSIGN);
  318. last_alloc_vector = vector;
  319. if (vector == LAST_DEVICE_VECTOR)
  320. new_vector_avail = 0;
  321. spin_unlock_irqrestore(&msi_lock, flags);
  322. return vector;
  323. }
  324. static int get_new_vector(void)
  325. {
  326. int vector = assign_msi_vector();
  327. if (vector > 0)
  328. set_intr_gate(vector, interrupt[vector]);
  329. return vector;
  330. }
  331. static int msi_init(void)
  332. {
  333. static int status = -ENOMEM;
  334. if (!status)
  335. return status;
  336. if (pci_msi_quirk) {
  337. pci_msi_enable = 0;
  338. printk(KERN_WARNING "PCI: MSI quirk detected. MSI disabled.\n");
  339. status = -EINVAL;
  340. return status;
  341. }
  342. status = msi_arch_init();
  343. if (status < 0) {
  344. pci_msi_enable = 0;
  345. printk(KERN_WARNING
  346. "PCI: MSI arch init failed. MSI disabled.\n");
  347. return status;
  348. }
  349. if (! msi_ops) {
  350. printk(KERN_WARNING
  351. "PCI: MSI ops not registered. MSI disabled.\n");
  352. status = -EINVAL;
  353. return status;
  354. }
  355. last_alloc_vector = assign_irq_vector(AUTO_ASSIGN);
  356. status = msi_cache_init();
  357. if (status < 0) {
  358. pci_msi_enable = 0;
  359. printk(KERN_WARNING "PCI: MSI cache init failed\n");
  360. return status;
  361. }
  362. if (last_alloc_vector < 0) {
  363. pci_msi_enable = 0;
  364. printk(KERN_WARNING "PCI: No interrupt vectors available for MSI\n");
  365. status = -EBUSY;
  366. return status;
  367. }
  368. vector_irq[last_alloc_vector] = 0;
  369. nr_released_vectors++;
  370. return status;
  371. }
  372. static int get_msi_vector(struct pci_dev *dev)
  373. {
  374. return get_new_vector();
  375. }
  376. static struct msi_desc* alloc_msi_entry(void)
  377. {
  378. struct msi_desc *entry;
  379. entry = kmem_cache_zalloc(msi_cachep, GFP_KERNEL);
  380. if (!entry)
  381. return NULL;
  382. entry->link.tail = entry->link.head = 0; /* single message */
  383. entry->dev = NULL;
  384. return entry;
  385. }
  386. static void attach_msi_entry(struct msi_desc *entry, int vector)
  387. {
  388. unsigned long flags;
  389. spin_lock_irqsave(&msi_lock, flags);
  390. msi_desc[vector] = entry;
  391. spin_unlock_irqrestore(&msi_lock, flags);
  392. }
  393. static void irq_handler_init(int cap_id, int pos, int mask)
  394. {
  395. unsigned long flags;
  396. spin_lock_irqsave(&irq_desc[pos].lock, flags);
  397. if (cap_id == PCI_CAP_ID_MSIX)
  398. irq_desc[pos].chip = &msix_irq_type;
  399. else {
  400. if (!mask)
  401. irq_desc[pos].chip = &msi_irq_wo_maskbit_type;
  402. else
  403. irq_desc[pos].chip = &msi_irq_w_maskbit_type;
  404. }
  405. spin_unlock_irqrestore(&irq_desc[pos].lock, flags);
  406. }
  407. static void enable_msi_mode(struct pci_dev *dev, int pos, int type)
  408. {
  409. u16 control;
  410. pci_read_config_word(dev, msi_control_reg(pos), &control);
  411. if (type == PCI_CAP_ID_MSI) {
  412. /* Set enabled bits to single MSI & enable MSI_enable bit */
  413. msi_enable(control, 1);
  414. pci_write_config_word(dev, msi_control_reg(pos), control);
  415. dev->msi_enabled = 1;
  416. } else {
  417. msix_enable(control);
  418. pci_write_config_word(dev, msi_control_reg(pos), control);
  419. dev->msix_enabled = 1;
  420. }
  421. if (pci_find_capability(dev, PCI_CAP_ID_EXP)) {
  422. /* PCI Express Endpoint device detected */
  423. pci_intx(dev, 0); /* disable intx */
  424. }
  425. }
  426. void disable_msi_mode(struct pci_dev *dev, int pos, int type)
  427. {
  428. u16 control;
  429. pci_read_config_word(dev, msi_control_reg(pos), &control);
  430. if (type == PCI_CAP_ID_MSI) {
  431. /* Set enabled bits to single MSI & enable MSI_enable bit */
  432. msi_disable(control);
  433. pci_write_config_word(dev, msi_control_reg(pos), control);
  434. dev->msi_enabled = 0;
  435. } else {
  436. msix_disable(control);
  437. pci_write_config_word(dev, msi_control_reg(pos), control);
  438. dev->msix_enabled = 0;
  439. }
  440. if (pci_find_capability(dev, PCI_CAP_ID_EXP)) {
  441. /* PCI Express Endpoint device detected */
  442. pci_intx(dev, 1); /* enable intx */
  443. }
  444. }
  445. static int msi_lookup_vector(struct pci_dev *dev, int type)
  446. {
  447. int vector;
  448. unsigned long flags;
  449. spin_lock_irqsave(&msi_lock, flags);
  450. for (vector = FIRST_DEVICE_VECTOR; vector < NR_IRQS; vector++) {
  451. if (!msi_desc[vector] || msi_desc[vector]->dev != dev ||
  452. msi_desc[vector]->msi_attrib.type != type ||
  453. msi_desc[vector]->msi_attrib.default_vector != dev->irq)
  454. continue;
  455. spin_unlock_irqrestore(&msi_lock, flags);
  456. /* This pre-assigned MSI vector for this device
  457. already exits. Override dev->irq with this vector */
  458. dev->irq = vector;
  459. return 0;
  460. }
  461. spin_unlock_irqrestore(&msi_lock, flags);
  462. return -EACCES;
  463. }
  464. void pci_scan_msi_device(struct pci_dev *dev)
  465. {
  466. if (!dev)
  467. return;
  468. if (pci_find_capability(dev, PCI_CAP_ID_MSIX) > 0)
  469. nr_msix_devices++;
  470. else if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0)
  471. nr_reserved_vectors++;
  472. }
  473. #ifdef CONFIG_PM
  474. int pci_save_msi_state(struct pci_dev *dev)
  475. {
  476. int pos, i = 0;
  477. u16 control;
  478. struct pci_cap_saved_state *save_state;
  479. u32 *cap;
  480. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  481. if (pos <= 0 || dev->no_msi)
  482. return 0;
  483. pci_read_config_word(dev, msi_control_reg(pos), &control);
  484. if (!(control & PCI_MSI_FLAGS_ENABLE))
  485. return 0;
  486. save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u32) * 5,
  487. GFP_KERNEL);
  488. if (!save_state) {
  489. printk(KERN_ERR "Out of memory in pci_save_msi_state\n");
  490. return -ENOMEM;
  491. }
  492. cap = &save_state->data[0];
  493. pci_read_config_dword(dev, pos, &cap[i++]);
  494. control = cap[0] >> 16;
  495. pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, &cap[i++]);
  496. if (control & PCI_MSI_FLAGS_64BIT) {
  497. pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, &cap[i++]);
  498. pci_read_config_dword(dev, pos + PCI_MSI_DATA_64, &cap[i++]);
  499. } else
  500. pci_read_config_dword(dev, pos + PCI_MSI_DATA_32, &cap[i++]);
  501. if (control & PCI_MSI_FLAGS_MASKBIT)
  502. pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT, &cap[i++]);
  503. save_state->cap_nr = PCI_CAP_ID_MSI;
  504. pci_add_saved_cap(dev, save_state);
  505. return 0;
  506. }
  507. void pci_restore_msi_state(struct pci_dev *dev)
  508. {
  509. int i = 0, pos;
  510. u16 control;
  511. struct pci_cap_saved_state *save_state;
  512. u32 *cap;
  513. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSI);
  514. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  515. if (!save_state || pos <= 0)
  516. return;
  517. cap = &save_state->data[0];
  518. control = cap[i++] >> 16;
  519. pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, cap[i++]);
  520. if (control & PCI_MSI_FLAGS_64BIT) {
  521. pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, cap[i++]);
  522. pci_write_config_dword(dev, pos + PCI_MSI_DATA_64, cap[i++]);
  523. } else
  524. pci_write_config_dword(dev, pos + PCI_MSI_DATA_32, cap[i++]);
  525. if (control & PCI_MSI_FLAGS_MASKBIT)
  526. pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT, cap[i++]);
  527. pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
  528. enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
  529. pci_remove_saved_cap(save_state);
  530. kfree(save_state);
  531. }
  532. int pci_save_msix_state(struct pci_dev *dev)
  533. {
  534. int pos;
  535. int temp;
  536. int vector, head, tail = 0;
  537. u16 control;
  538. struct pci_cap_saved_state *save_state;
  539. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  540. if (pos <= 0 || dev->no_msi)
  541. return 0;
  542. /* save the capability */
  543. pci_read_config_word(dev, msi_control_reg(pos), &control);
  544. if (!(control & PCI_MSIX_FLAGS_ENABLE))
  545. return 0;
  546. save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u16),
  547. GFP_KERNEL);
  548. if (!save_state) {
  549. printk(KERN_ERR "Out of memory in pci_save_msix_state\n");
  550. return -ENOMEM;
  551. }
  552. *((u16 *)&save_state->data[0]) = control;
  553. /* save the table */
  554. temp = dev->irq;
  555. if (msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
  556. kfree(save_state);
  557. return -EINVAL;
  558. }
  559. vector = head = dev->irq;
  560. while (head != tail) {
  561. struct msi_desc *entry;
  562. entry = msi_desc[vector];
  563. read_msi_msg(entry, &entry->msg_save);
  564. tail = msi_desc[vector]->link.tail;
  565. vector = tail;
  566. }
  567. dev->irq = temp;
  568. save_state->cap_nr = PCI_CAP_ID_MSIX;
  569. pci_add_saved_cap(dev, save_state);
  570. return 0;
  571. }
  572. void pci_restore_msix_state(struct pci_dev *dev)
  573. {
  574. u16 save;
  575. int pos;
  576. int vector, head, tail = 0;
  577. struct msi_desc *entry;
  578. int temp;
  579. struct pci_cap_saved_state *save_state;
  580. save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX);
  581. if (!save_state)
  582. return;
  583. save = *((u16 *)&save_state->data[0]);
  584. pci_remove_saved_cap(save_state);
  585. kfree(save_state);
  586. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  587. if (pos <= 0)
  588. return;
  589. /* route the table */
  590. temp = dev->irq;
  591. if (msi_lookup_vector(dev, PCI_CAP_ID_MSIX))
  592. return;
  593. vector = head = dev->irq;
  594. while (head != tail) {
  595. entry = msi_desc[vector];
  596. write_msi_msg(entry, &entry->msg_save);
  597. tail = msi_desc[vector]->link.tail;
  598. vector = tail;
  599. }
  600. dev->irq = temp;
  601. pci_write_config_word(dev, msi_control_reg(pos), save);
  602. enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
  603. }
  604. #endif
  605. static int msi_register_init(struct pci_dev *dev, struct msi_desc *entry)
  606. {
  607. int status;
  608. struct msi_msg msg;
  609. int pos, vector = dev->irq;
  610. u16 control;
  611. pos = entry->msi_attrib.pos;
  612. pci_read_config_word(dev, msi_control_reg(pos), &control);
  613. /* Configure MSI capability structure */
  614. status = msi_ops->setup(dev, vector, &msg.address_hi, &msg.address_lo, &msg.data);
  615. if (status < 0)
  616. return status;
  617. write_msi_msg(entry, &msg);
  618. if (entry->msi_attrib.maskbit) {
  619. unsigned int maskbits, temp;
  620. /* All MSIs are unmasked by default, Mask them all */
  621. pci_read_config_dword(dev,
  622. msi_mask_bits_reg(pos, is_64bit_address(control)),
  623. &maskbits);
  624. temp = (1 << multi_msi_capable(control));
  625. temp = ((temp - 1) & ~temp);
  626. maskbits |= temp;
  627. pci_write_config_dword(dev,
  628. msi_mask_bits_reg(pos, is_64bit_address(control)),
  629. maskbits);
  630. }
  631. return 0;
  632. }
  633. /**
  634. * msi_capability_init - configure device's MSI capability structure
  635. * @dev: pointer to the pci_dev data structure of MSI device function
  636. *
  637. * Setup the MSI capability structure of device function with a single
  638. * MSI vector, regardless of device function is capable of handling
  639. * multiple messages. A return of zero indicates the successful setup
  640. * of an entry zero with the new MSI vector or non-zero for otherwise.
  641. **/
  642. static int msi_capability_init(struct pci_dev *dev)
  643. {
  644. int status;
  645. struct msi_desc *entry;
  646. int pos, vector;
  647. u16 control;
  648. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  649. pci_read_config_word(dev, msi_control_reg(pos), &control);
  650. /* MSI Entry Initialization */
  651. entry = alloc_msi_entry();
  652. if (!entry)
  653. return -ENOMEM;
  654. vector = get_msi_vector(dev);
  655. if (vector < 0) {
  656. kmem_cache_free(msi_cachep, entry);
  657. return -EBUSY;
  658. }
  659. entry->link.head = vector;
  660. entry->link.tail = vector;
  661. entry->msi_attrib.type = PCI_CAP_ID_MSI;
  662. entry->msi_attrib.state = 0; /* Mark it not active */
  663. entry->msi_attrib.is_64 = is_64bit_address(control);
  664. entry->msi_attrib.entry_nr = 0;
  665. entry->msi_attrib.maskbit = is_mask_bit_support(control);
  666. entry->msi_attrib.default_vector = dev->irq; /* Save IOAPIC IRQ */
  667. entry->msi_attrib.pos = pos;
  668. dev->irq = vector;
  669. entry->dev = dev;
  670. if (is_mask_bit_support(control)) {
  671. entry->mask_base = (void __iomem *)(long)msi_mask_bits_reg(pos,
  672. is_64bit_address(control));
  673. }
  674. /* Replace with MSI handler */
  675. irq_handler_init(PCI_CAP_ID_MSI, vector, entry->msi_attrib.maskbit);
  676. /* Configure MSI capability structure */
  677. status = msi_register_init(dev, entry);
  678. if (status != 0) {
  679. dev->irq = entry->msi_attrib.default_vector;
  680. kmem_cache_free(msi_cachep, entry);
  681. return status;
  682. }
  683. attach_msi_entry(entry, vector);
  684. /* Set MSI enabled bits */
  685. enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
  686. return 0;
  687. }
  688. /**
  689. * msix_capability_init - configure device's MSI-X capability
  690. * @dev: pointer to the pci_dev data structure of MSI-X device function
  691. * @entries: pointer to an array of struct msix_entry entries
  692. * @nvec: number of @entries
  693. *
  694. * Setup the MSI-X capability structure of device function with a
  695. * single MSI-X vector. A return of zero indicates the successful setup of
  696. * requested MSI-X entries with allocated vectors or non-zero for otherwise.
  697. **/
  698. static int msix_capability_init(struct pci_dev *dev,
  699. struct msix_entry *entries, int nvec)
  700. {
  701. struct msi_desc *head = NULL, *tail = NULL, *entry = NULL;
  702. struct msi_msg msg;
  703. int status;
  704. int vector, pos, i, j, nr_entries, temp = 0;
  705. unsigned long phys_addr;
  706. u32 table_offset;
  707. u16 control;
  708. u8 bir;
  709. void __iomem *base;
  710. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  711. /* Request & Map MSI-X table region */
  712. pci_read_config_word(dev, msi_control_reg(pos), &control);
  713. nr_entries = multi_msix_capable(control);
  714. pci_read_config_dword(dev, msix_table_offset_reg(pos), &table_offset);
  715. bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
  716. table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
  717. phys_addr = pci_resource_start (dev, bir) + table_offset;
  718. base = ioremap_nocache(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
  719. if (base == NULL)
  720. return -ENOMEM;
  721. /* MSI-X Table Initialization */
  722. for (i = 0; i < nvec; i++) {
  723. entry = alloc_msi_entry();
  724. if (!entry)
  725. break;
  726. vector = get_msi_vector(dev);
  727. if (vector < 0) {
  728. kmem_cache_free(msi_cachep, entry);
  729. break;
  730. }
  731. j = entries[i].entry;
  732. entries[i].vector = vector;
  733. entry->msi_attrib.type = PCI_CAP_ID_MSIX;
  734. entry->msi_attrib.state = 0; /* Mark it not active */
  735. entry->msi_attrib.is_64 = 1;
  736. entry->msi_attrib.entry_nr = j;
  737. entry->msi_attrib.maskbit = 1;
  738. entry->msi_attrib.default_vector = dev->irq;
  739. entry->msi_attrib.pos = pos;
  740. entry->dev = dev;
  741. entry->mask_base = base;
  742. if (!head) {
  743. entry->link.head = vector;
  744. entry->link.tail = vector;
  745. head = entry;
  746. } else {
  747. entry->link.head = temp;
  748. entry->link.tail = tail->link.tail;
  749. tail->link.tail = vector;
  750. head->link.head = vector;
  751. }
  752. temp = vector;
  753. tail = entry;
  754. /* Replace with MSI-X handler */
  755. irq_handler_init(PCI_CAP_ID_MSIX, vector, 1);
  756. /* Configure MSI-X capability structure */
  757. status = msi_ops->setup(dev, vector,
  758. &msg.address_hi,
  759. &msg.address_lo,
  760. &msg.data);
  761. if (status < 0)
  762. break;
  763. write_msi_msg(entry, &msg);
  764. attach_msi_entry(entry, vector);
  765. }
  766. if (i != nvec) {
  767. i--;
  768. for (; i >= 0; i--) {
  769. vector = (entries + i)->vector;
  770. msi_free_vector(dev, vector, 0);
  771. (entries + i)->vector = 0;
  772. }
  773. return -EBUSY;
  774. }
  775. /* Set MSI-X enabled bits */
  776. enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
  777. return 0;
  778. }
  779. /**
  780. * pci_msi_supported - check whether MSI may be enabled on device
  781. * @dev: pointer to the pci_dev data structure of MSI device function
  782. *
  783. * MSI must be globally enabled and supported by the device and its root
  784. * bus. But, the root bus is not easy to find since some architectures
  785. * have virtual busses on top of the PCI hierarchy (for instance the
  786. * hypertransport bus), while the actual bus where MSI must be supported
  787. * is below. So we test the MSI flag on all parent busses and assume
  788. * that no quirk will ever set the NO_MSI flag on a non-root bus.
  789. **/
  790. static
  791. int pci_msi_supported(struct pci_dev * dev)
  792. {
  793. struct pci_bus *bus;
  794. if (!pci_msi_enable || !dev || dev->no_msi)
  795. return -EINVAL;
  796. /* check MSI flags of all parent busses */
  797. for (bus = dev->bus; bus; bus = bus->parent)
  798. if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI)
  799. return -EINVAL;
  800. return 0;
  801. }
  802. /**
  803. * pci_enable_msi - configure device's MSI capability structure
  804. * @dev: pointer to the pci_dev data structure of MSI device function
  805. *
  806. * Setup the MSI capability structure of device function with
  807. * a single MSI vector upon its software driver call to request for
  808. * MSI mode enabled on its hardware device function. A return of zero
  809. * indicates the successful setup of an entry zero with the new MSI
  810. * vector or non-zero for otherwise.
  811. **/
  812. int pci_enable_msi(struct pci_dev* dev)
  813. {
  814. int pos, temp, status;
  815. if (pci_msi_supported(dev) < 0)
  816. return -EINVAL;
  817. temp = dev->irq;
  818. status = msi_init();
  819. if (status < 0)
  820. return status;
  821. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  822. if (!pos)
  823. return -EINVAL;
  824. WARN_ON(!msi_lookup_vector(dev, PCI_CAP_ID_MSI));
  825. /* Check whether driver already requested for MSI-X vectors */
  826. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  827. if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
  828. printk(KERN_INFO "PCI: %s: Can't enable MSI. "
  829. "Device already has MSI-X vectors assigned\n",
  830. pci_name(dev));
  831. dev->irq = temp;
  832. return -EINVAL;
  833. }
  834. status = msi_capability_init(dev);
  835. if (!status) {
  836. if (!pos)
  837. nr_reserved_vectors--; /* Only MSI capable */
  838. else if (nr_msix_devices > 0)
  839. nr_msix_devices--; /* Both MSI and MSI-X capable,
  840. but choose enabling MSI */
  841. }
  842. return status;
  843. }
  844. void pci_disable_msi(struct pci_dev* dev)
  845. {
  846. struct msi_desc *entry;
  847. int pos, default_vector;
  848. u16 control;
  849. unsigned long flags;
  850. if (!pci_msi_enable)
  851. return;
  852. if (!dev)
  853. return;
  854. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  855. if (!pos)
  856. return;
  857. pci_read_config_word(dev, msi_control_reg(pos), &control);
  858. if (!(control & PCI_MSI_FLAGS_ENABLE))
  859. return;
  860. disable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
  861. spin_lock_irqsave(&msi_lock, flags);
  862. entry = msi_desc[dev->irq];
  863. if (!entry || !entry->dev || entry->msi_attrib.type != PCI_CAP_ID_MSI) {
  864. spin_unlock_irqrestore(&msi_lock, flags);
  865. return;
  866. }
  867. if (entry->msi_attrib.state) {
  868. spin_unlock_irqrestore(&msi_lock, flags);
  869. printk(KERN_WARNING "PCI: %s: pci_disable_msi() called without "
  870. "free_irq() on MSI vector %d\n",
  871. pci_name(dev), dev->irq);
  872. BUG_ON(entry->msi_attrib.state > 0);
  873. } else {
  874. default_vector = entry->msi_attrib.default_vector;
  875. spin_unlock_irqrestore(&msi_lock, flags);
  876. msi_free_vector(dev, dev->irq, 0);
  877. /* Restore dev->irq to its default pin-assertion vector */
  878. dev->irq = default_vector;
  879. }
  880. }
  881. static int msi_free_vector(struct pci_dev* dev, int vector, int reassign)
  882. {
  883. struct msi_desc *entry;
  884. int head, entry_nr, type;
  885. void __iomem *base;
  886. unsigned long flags;
  887. msi_ops->teardown(vector);
  888. spin_lock_irqsave(&msi_lock, flags);
  889. entry = msi_desc[vector];
  890. if (!entry || entry->dev != dev) {
  891. spin_unlock_irqrestore(&msi_lock, flags);
  892. return -EINVAL;
  893. }
  894. type = entry->msi_attrib.type;
  895. entry_nr = entry->msi_attrib.entry_nr;
  896. head = entry->link.head;
  897. base = entry->mask_base;
  898. msi_desc[entry->link.head]->link.tail = entry->link.tail;
  899. msi_desc[entry->link.tail]->link.head = entry->link.head;
  900. entry->dev = NULL;
  901. if (!reassign) {
  902. vector_irq[vector] = 0;
  903. nr_released_vectors++;
  904. }
  905. msi_desc[vector] = NULL;
  906. spin_unlock_irqrestore(&msi_lock, flags);
  907. kmem_cache_free(msi_cachep, entry);
  908. if (type == PCI_CAP_ID_MSIX) {
  909. if (!reassign)
  910. writel(1, base +
  911. entry_nr * PCI_MSIX_ENTRY_SIZE +
  912. PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  913. if (head == vector)
  914. iounmap(base);
  915. }
  916. return 0;
  917. }
  918. /**
  919. * pci_enable_msix - configure device's MSI-X capability structure
  920. * @dev: pointer to the pci_dev data structure of MSI-X device function
  921. * @entries: pointer to an array of MSI-X entries
  922. * @nvec: number of MSI-X vectors requested for allocation by device driver
  923. *
  924. * Setup the MSI-X capability structure of device function with the number
  925. * of requested vectors upon its software driver call to request for
  926. * MSI-X mode enabled on its hardware device function. A return of zero
  927. * indicates the successful configuration of MSI-X capability structure
  928. * with new allocated MSI-X vectors. A return of < 0 indicates a failure.
  929. * Or a return of > 0 indicates that driver request is exceeding the number
  930. * of vectors available. Driver should use the returned value to re-send
  931. * its request.
  932. **/
  933. int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec)
  934. {
  935. int status, pos, nr_entries, free_vectors;
  936. int i, j, temp;
  937. u16 control;
  938. unsigned long flags;
  939. if (!entries || pci_msi_supported(dev) < 0)
  940. return -EINVAL;
  941. status = msi_init();
  942. if (status < 0)
  943. return status;
  944. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  945. if (!pos)
  946. return -EINVAL;
  947. pci_read_config_word(dev, msi_control_reg(pos), &control);
  948. nr_entries = multi_msix_capable(control);
  949. if (nvec > nr_entries)
  950. return -EINVAL;
  951. /* Check for any invalid entries */
  952. for (i = 0; i < nvec; i++) {
  953. if (entries[i].entry >= nr_entries)
  954. return -EINVAL; /* invalid entry */
  955. for (j = i + 1; j < nvec; j++) {
  956. if (entries[i].entry == entries[j].entry)
  957. return -EINVAL; /* duplicate entry */
  958. }
  959. }
  960. temp = dev->irq;
  961. WARN_ON(!msi_lookup_vector(dev, PCI_CAP_ID_MSIX));
  962. /* Check whether driver already requested for MSI vector */
  963. if (pci_find_capability(dev, PCI_CAP_ID_MSI) > 0 &&
  964. !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
  965. printk(KERN_INFO "PCI: %s: Can't enable MSI-X. "
  966. "Device already has an MSI vector assigned\n",
  967. pci_name(dev));
  968. dev->irq = temp;
  969. return -EINVAL;
  970. }
  971. spin_lock_irqsave(&msi_lock, flags);
  972. /*
  973. * msi_lock is provided to ensure that enough vectors resources are
  974. * available before granting.
  975. */
  976. free_vectors = pci_vector_resources(last_alloc_vector,
  977. nr_released_vectors);
  978. /* Ensure that each MSI/MSI-X device has one vector reserved by
  979. default to avoid any MSI-X driver to take all available
  980. resources */
  981. free_vectors -= nr_reserved_vectors;
  982. /* Find the average of free vectors among MSI-X devices */
  983. if (nr_msix_devices > 0)
  984. free_vectors /= nr_msix_devices;
  985. spin_unlock_irqrestore(&msi_lock, flags);
  986. if (nvec > free_vectors) {
  987. if (free_vectors > 0)
  988. return free_vectors;
  989. else
  990. return -EBUSY;
  991. }
  992. status = msix_capability_init(dev, entries, nvec);
  993. if (!status && nr_msix_devices > 0)
  994. nr_msix_devices--;
  995. return status;
  996. }
  997. void pci_disable_msix(struct pci_dev* dev)
  998. {
  999. int pos, temp;
  1000. u16 control;
  1001. if (!pci_msi_enable)
  1002. return;
  1003. if (!dev)
  1004. return;
  1005. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  1006. if (!pos)
  1007. return;
  1008. pci_read_config_word(dev, msi_control_reg(pos), &control);
  1009. if (!(control & PCI_MSIX_FLAGS_ENABLE))
  1010. return;
  1011. disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
  1012. temp = dev->irq;
  1013. if (!msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
  1014. int state, vector, head, tail = 0, warning = 0;
  1015. unsigned long flags;
  1016. vector = head = dev->irq;
  1017. dev->irq = temp; /* Restore pin IRQ */
  1018. while (head != tail) {
  1019. spin_lock_irqsave(&msi_lock, flags);
  1020. state = msi_desc[vector]->msi_attrib.state;
  1021. tail = msi_desc[vector]->link.tail;
  1022. spin_unlock_irqrestore(&msi_lock, flags);
  1023. if (state)
  1024. warning = 1;
  1025. else if (vector != head) /* Release MSI-X vector */
  1026. msi_free_vector(dev, vector, 0);
  1027. vector = tail;
  1028. }
  1029. msi_free_vector(dev, vector, 0);
  1030. if (warning) {
  1031. printk(KERN_WARNING "PCI: %s: pci_disable_msix() called without "
  1032. "free_irq() on all MSI-X vectors\n",
  1033. pci_name(dev));
  1034. BUG_ON(warning > 0);
  1035. }
  1036. }
  1037. }
  1038. /**
  1039. * msi_remove_pci_irq_vectors - reclaim MSI(X) vectors to unused state
  1040. * @dev: pointer to the pci_dev data structure of MSI(X) device function
  1041. *
  1042. * Being called during hotplug remove, from which the device function
  1043. * is hot-removed. All previous assigned MSI/MSI-X vectors, if
  1044. * allocated for this device function, are reclaimed to unused state,
  1045. * which may be used later on.
  1046. **/
  1047. void msi_remove_pci_irq_vectors(struct pci_dev* dev)
  1048. {
  1049. int state, pos, temp;
  1050. unsigned long flags;
  1051. if (!pci_msi_enable || !dev)
  1052. return;
  1053. temp = dev->irq; /* Save IOAPIC IRQ */
  1054. pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
  1055. if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSI)) {
  1056. spin_lock_irqsave(&msi_lock, flags);
  1057. state = msi_desc[dev->irq]->msi_attrib.state;
  1058. spin_unlock_irqrestore(&msi_lock, flags);
  1059. if (state) {
  1060. printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
  1061. "called without free_irq() on MSI vector %d\n",
  1062. pci_name(dev), dev->irq);
  1063. BUG_ON(state > 0);
  1064. } else /* Release MSI vector assigned to this device */
  1065. msi_free_vector(dev, dev->irq, 0);
  1066. dev->irq = temp; /* Restore IOAPIC IRQ */
  1067. }
  1068. pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
  1069. if (pos > 0 && !msi_lookup_vector(dev, PCI_CAP_ID_MSIX)) {
  1070. int vector, head, tail = 0, warning = 0;
  1071. void __iomem *base = NULL;
  1072. vector = head = dev->irq;
  1073. while (head != tail) {
  1074. spin_lock_irqsave(&msi_lock, flags);
  1075. state = msi_desc[vector]->msi_attrib.state;
  1076. tail = msi_desc[vector]->link.tail;
  1077. base = msi_desc[vector]->mask_base;
  1078. spin_unlock_irqrestore(&msi_lock, flags);
  1079. if (state)
  1080. warning = 1;
  1081. else if (vector != head) /* Release MSI-X vector */
  1082. msi_free_vector(dev, vector, 0);
  1083. vector = tail;
  1084. }
  1085. msi_free_vector(dev, vector, 0);
  1086. if (warning) {
  1087. iounmap(base);
  1088. printk(KERN_WARNING "PCI: %s: msi_remove_pci_irq_vectors() "
  1089. "called without free_irq() on all MSI-X vectors\n",
  1090. pci_name(dev));
  1091. BUG_ON(warning > 0);
  1092. }
  1093. dev->irq = temp; /* Restore IOAPIC IRQ */
  1094. }
  1095. }
  1096. void pci_no_msi(void)
  1097. {
  1098. pci_msi_enable = 0;
  1099. }
  1100. EXPORT_SYMBOL(pci_enable_msi);
  1101. EXPORT_SYMBOL(pci_disable_msi);
  1102. EXPORT_SYMBOL(pci_enable_msix);
  1103. EXPORT_SYMBOL(pci_disable_msix);