Blame view

drivers/pci/irq.c 2.37 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
388c8c16a   James Bottomley   PCI: add routines...
2
  /*
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
3
   * PCI IRQ handling code
388c8c16a   James Bottomley   PCI: add routines...
4
5
   *
   * Copyright (c) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
6
   * Copyright (C) 2017 Christoph Hellwig.
388c8c16a   James Bottomley   PCI: add routines...
7
   */
388c8c16a   James Bottomley   PCI: add routines...
8
9
  #include <linux/device.h>
  #include <linux/kernel.h>
363c75db1   Paul Gortmaker   pci: Fix files ne...
10
  #include <linux/export.h>
388c8c16a   James Bottomley   PCI: add routines...
11
  #include <linux/pci.h>
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  /**
   * pci_request_irq - allocate an interrupt line for a PCI device
   * @dev:	PCI device to operate on
   * @nr:		device-relative interrupt vector index (0-based).
   * @handler:	Function to be called when the IRQ occurs.
   *		Primary handler for threaded interrupts.
   *		If NULL and thread_fn != NULL the default primary handler is
   *		installed.
   * @thread_fn:	Function called from the IRQ handler thread
   *		If NULL, no IRQ thread is created
   * @dev_id:	Cookie passed back to the handler function
   * @fmt:	Printf-like format string naming the handler
   *
   * This call allocates interrupt resources and enables the interrupt line and
   * IRQ handling. From the point this call is made @handler and @thread_fn may
   * be invoked.  All interrupts requested using this function might be shared.
   *
   * @dev_id must not be NULL and must be globally unique.
   */
  int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,
  		irq_handler_t thread_fn, void *dev_id, const char *fmt, ...)
  {
  	va_list ap;
  	int ret;
  	char *devname;
f7368a550   Heiner Kallweit   PCI: Use IRQF_ONE...
37
38
39
40
  	unsigned long irqflags = IRQF_SHARED;
  
  	if (!handler)
  		irqflags |= IRQF_ONESHOT;
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
41
42
43
44
45
46
  
  	va_start(ap, fmt);
  	devname = kvasprintf(GFP_KERNEL, fmt, ap);
  	va_end(ap);
  
  	ret = request_threaded_irq(pci_irq_vector(dev, nr), handler, thread_fn,
f7368a550   Heiner Kallweit   PCI: Use IRQF_ONE...
47
  				   irqflags, devname, dev_id);
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  	if (ret)
  		kfree(devname);
  	return ret;
  }
  EXPORT_SYMBOL(pci_request_irq);
  
  /**
   * pci_free_irq - free an interrupt allocated with pci_request_irq
   * @dev:	PCI device to operate on
   * @nr:		device-relative interrupt vector index (0-based).
   * @dev_id:	Device identity to free
   *
   * Remove an interrupt handler. The handler is removed and if the interrupt
   * line is no longer in use by any driver it is disabled.  The caller must
   * ensure the interrupt is disabled on the device before calling this function.
   * The function does not return until any executing interrupts for this IRQ
   * have completed.
   *
   * This function must not be called from interrupt context.
   */
  void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id)
  {
  	kfree(free_irq(pci_irq_vector(dev, nr), dev_id));
  }
  EXPORT_SYMBOL(pci_free_irq);