msi.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2003-2004 Intel
  3. * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
  4. */
  5. #ifndef MSI_H
  6. #define MSI_H
  7. /*
  8. * MSI operation vector. Used by the msi core code (drivers/pci/msi.c)
  9. * to abstract platform-specific tasks relating to MSI address generation
  10. * and resource management.
  11. */
  12. struct msi_ops {
  13. /**
  14. * setup - generate an MSI bus address and data for a given vector
  15. * @pdev: PCI device context (in)
  16. * @vector: vector allocated by the msi core (in)
  17. * @addr_hi: upper 32 bits of PCI bus MSI address (out)
  18. * @addr_lo: lower 32 bits of PCI bus MSI address (out)
  19. * @data: MSI data payload (out)
  20. *
  21. * Description: The setup op is used to generate a PCI bus addres and
  22. * data which the msi core will program into the card MSI capability
  23. * registers. The setup routine is responsible for picking an initial
  24. * cpu to target the MSI at. The setup routine is responsible for
  25. * examining pdev to determine the MSI capabilities of the card and
  26. * generating a suitable address/data. The setup routine is
  27. * responsible for allocating and tracking any system resources it
  28. * needs to route the MSI to the cpu it picks, and for associating
  29. * those resources with the passed in vector.
  30. *
  31. * Returns 0 if the MSI address/data was successfully setup.
  32. **/
  33. int (*setup) (struct pci_dev *pdev, unsigned int vector,
  34. u32 *addr_hi, u32 *addr_lo, u32 *data);
  35. /**
  36. * teardown - release resources allocated by setup
  37. * @vector: vector context for resources (in)
  38. *
  39. * Description: The teardown op is used to release any resources
  40. * that were allocated in the setup routine associated with the passed
  41. * in vector.
  42. **/
  43. void (*teardown) (unsigned int vector);
  44. /**
  45. * target - retarget an MSI at a different cpu
  46. * @vector: vector context for resources (in)
  47. * @cpu: new cpu to direct vector at (in)
  48. * @addr_hi: new value of PCI bus upper 32 bits (in/out)
  49. * @addr_lo: new value of PCI bus lower 32 bits (in/out)
  50. *
  51. * Description: The target op is used to redirect an MSI vector
  52. * at a different cpu. addr_hi/addr_lo coming in are the existing
  53. * values that the MSI core has programmed into the card. The
  54. * target code is responsible for freeing any resources (if any)
  55. * associated with the old address, and generating a new PCI bus
  56. * addr_hi/addr_lo that will redirect the vector at the indicated cpu.
  57. **/
  58. void (*target) (unsigned int vector, unsigned int cpu,
  59. u32 *addr_hi, u32 *addr_lo);
  60. };
  61. extern int msi_register(struct msi_ops *ops);
  62. #include <asm/msi.h>
  63. /*
  64. * Assume the maximum number of hot plug slots supported by the system is about
  65. * ten. The worstcase is that each of these slots is hot-added with a device,
  66. * which has two MSI/MSI-X capable functions. To avoid any MSI-X driver, which
  67. * attempts to request all available vectors, NR_HP_RESERVED_VECTORS is defined
  68. * as below to ensure at least one message is assigned to each detected MSI/
  69. * MSI-X device function.
  70. */
  71. #define NR_HP_RESERVED_VECTORS 20
  72. extern int vector_irq[NR_VECTORS];
  73. extern void (*interrupt[NR_IRQS])(void);
  74. extern int pci_vector_resources(int last, int nr_released);
  75. /*
  76. * MSI-X Address Register
  77. */
  78. #define PCI_MSIX_FLAGS_QSIZE 0x7FF
  79. #define PCI_MSIX_FLAGS_ENABLE (1 << 15)
  80. #define PCI_MSIX_FLAGS_BIRMASK (7 << 0)
  81. #define PCI_MSIX_FLAGS_BITMASK (1 << 0)
  82. #define PCI_MSIX_ENTRY_SIZE 16
  83. #define PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET 0
  84. #define PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET 4
  85. #define PCI_MSIX_ENTRY_DATA_OFFSET 8
  86. #define PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET 12
  87. #define msi_control_reg(base) (base + PCI_MSI_FLAGS)
  88. #define msi_lower_address_reg(base) (base + PCI_MSI_ADDRESS_LO)
  89. #define msi_upper_address_reg(base) (base + PCI_MSI_ADDRESS_HI)
  90. #define msi_data_reg(base, is64bit) \
  91. ( (is64bit == 1) ? base+PCI_MSI_DATA_64 : base+PCI_MSI_DATA_32 )
  92. #define msi_mask_bits_reg(base, is64bit) \
  93. ( (is64bit == 1) ? base+PCI_MSI_MASK_BIT : base+PCI_MSI_MASK_BIT-4)
  94. #define msi_disable(control) control &= ~PCI_MSI_FLAGS_ENABLE
  95. #define multi_msi_capable(control) \
  96. (1 << ((control & PCI_MSI_FLAGS_QMASK) >> 1))
  97. #define multi_msi_enable(control, num) \
  98. control |= (((num >> 1) << 4) & PCI_MSI_FLAGS_QSIZE);
  99. #define is_64bit_address(control) (control & PCI_MSI_FLAGS_64BIT)
  100. #define is_mask_bit_support(control) (control & PCI_MSI_FLAGS_MASKBIT)
  101. #define msi_enable(control, num) multi_msi_enable(control, num); \
  102. control |= PCI_MSI_FLAGS_ENABLE
  103. #define msix_table_offset_reg(base) (base + 0x04)
  104. #define msix_pba_offset_reg(base) (base + 0x08)
  105. #define msix_enable(control) control |= PCI_MSIX_FLAGS_ENABLE
  106. #define msix_disable(control) control &= ~PCI_MSIX_FLAGS_ENABLE
  107. #define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)
  108. #define multi_msix_capable msix_table_size
  109. #define msix_unmask(address) (address & ~PCI_MSIX_FLAGS_BITMASK)
  110. #define msix_mask(address) (address | PCI_MSIX_FLAGS_BITMASK)
  111. #define msix_is_pending(address) (address & PCI_MSIX_FLAGS_PENDMASK)
  112. struct msi_desc {
  113. struct {
  114. __u8 type : 5; /* {0: unused, 5h:MSI, 11h:MSI-X} */
  115. __u8 maskbit : 1; /* mask-pending bit supported ? */
  116. __u8 state : 1; /* {0: free, 1: busy} */
  117. __u8 reserved: 1; /* reserved */
  118. __u8 entry_nr; /* specific enabled entry */
  119. __u8 default_vector; /* default pre-assigned vector */
  120. __u8 unused; /* formerly unused destination cpu*/
  121. }msi_attrib;
  122. struct {
  123. __u16 head;
  124. __u16 tail;
  125. }link;
  126. void __iomem *mask_base;
  127. struct pci_dev *dev;
  128. #ifdef CONFIG_PM
  129. /* PM save area for MSIX address/data */
  130. u32 address_hi_save;
  131. u32 address_lo_save;
  132. u32 data_save;
  133. #endif
  134. };
  135. #endif /* MSI_H */