0001
0002 #ifndef LINUX_MSI_H
0003 #define LINUX_MSI_H
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <linux/cpumask.h>
0020 #include <linux/xarray.h>
0021 #include <linux/mutex.h>
0022 #include <linux/list.h>
0023 #include <asm/msi.h>
0024
0025
0026 #ifndef arch_msi_msg_addr_lo
0027 typedef struct arch_msi_msg_addr_lo {
0028 u32 address_lo;
0029 } __attribute__ ((packed)) arch_msi_msg_addr_lo_t;
0030 #endif
0031
0032 #ifndef arch_msi_msg_addr_hi
0033 typedef struct arch_msi_msg_addr_hi {
0034 u32 address_hi;
0035 } __attribute__ ((packed)) arch_msi_msg_addr_hi_t;
0036 #endif
0037
0038 #ifndef arch_msi_msg_data
0039 typedef struct arch_msi_msg_data {
0040 u32 data;
0041 } __attribute__ ((packed)) arch_msi_msg_data_t;
0042 #endif
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 struct msi_msg {
0055 union {
0056 u32 address_lo;
0057 arch_msi_msg_addr_lo_t arch_addr_lo;
0058 };
0059 union {
0060 u32 address_hi;
0061 arch_msi_msg_addr_hi_t arch_addr_hi;
0062 };
0063 union {
0064 u32 data;
0065 arch_msi_msg_data_t arch_data;
0066 };
0067 };
0068
0069 extern int pci_msi_ignore_mask;
0070
0071 struct irq_data;
0072 struct msi_desc;
0073 struct pci_dev;
0074 struct platform_msi_priv_data;
0075 struct device_attribute;
0076
0077 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
0078 #ifdef CONFIG_GENERIC_MSI_IRQ
0079 void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
0080 #else
0081 static inline void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
0082 {
0083 }
0084 #endif
0085
0086 typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
0087 struct msi_msg *msg);
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 struct pci_msi_desc {
0104 union {
0105 u32 msi_mask;
0106 u32 msix_ctrl;
0107 };
0108 struct {
0109 u8 is_msix : 1;
0110 u8 multiple : 3;
0111 u8 multi_cap : 3;
0112 u8 can_mask : 1;
0113 u8 is_64 : 1;
0114 u8 is_virtual : 1;
0115 unsigned default_irq;
0116 } msi_attrib;
0117 union {
0118 u8 mask_pos;
0119 void __iomem *mask_base;
0120 };
0121 };
0122
0123 #define MSI_MAX_INDEX ((unsigned int)USHRT_MAX)
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 struct msi_desc {
0142
0143 unsigned int irq;
0144 unsigned int nvec_used;
0145 struct device *dev;
0146 struct msi_msg msg;
0147 struct irq_affinity_desc *affinity;
0148 #ifdef CONFIG_IRQ_MSI_IOMMU
0149 const void *iommu_cookie;
0150 #endif
0151 #ifdef CONFIG_SYSFS
0152 struct device_attribute *sysfs_attrs;
0153 #endif
0154
0155 void (*write_msi_msg)(struct msi_desc *entry, void *data);
0156 void *write_msi_msg_data;
0157
0158 u16 msi_index;
0159 struct pci_msi_desc pci;
0160 };
0161
0162
0163
0164
0165 enum msi_desc_filter {
0166
0167 MSI_DESC_ALL,
0168
0169 MSI_DESC_NOTASSOCIATED,
0170
0171 MSI_DESC_ASSOCIATED,
0172 };
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 struct msi_device_data {
0183 unsigned long properties;
0184 struct platform_msi_priv_data *platform_data;
0185 struct mutex mutex;
0186 struct xarray __store;
0187 unsigned long __iter_idx;
0188 };
0189
0190 int msi_setup_device_data(struct device *dev);
0191
0192 unsigned int msi_get_virq(struct device *dev, unsigned int index);
0193 void msi_lock_descs(struct device *dev);
0194 void msi_unlock_descs(struct device *dev);
0195
0196 struct msi_desc *msi_first_desc(struct device *dev, enum msi_desc_filter filter);
0197 struct msi_desc *msi_next_desc(struct device *dev, enum msi_desc_filter filter);
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211 #define msi_for_each_desc(desc, dev, filter) \
0212 for ((desc) = msi_first_desc((dev), (filter)); (desc); \
0213 (desc) = msi_next_desc((dev), (filter)))
0214
0215 #define msi_desc_to_dev(desc) ((desc)->dev)
0216
0217 #ifdef CONFIG_IRQ_MSI_IOMMU
0218 static inline const void *msi_desc_get_iommu_cookie(struct msi_desc *desc)
0219 {
0220 return desc->iommu_cookie;
0221 }
0222
0223 static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc,
0224 const void *iommu_cookie)
0225 {
0226 desc->iommu_cookie = iommu_cookie;
0227 }
0228 #else
0229 static inline const void *msi_desc_get_iommu_cookie(struct msi_desc *desc)
0230 {
0231 return NULL;
0232 }
0233
0234 static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc,
0235 const void *iommu_cookie)
0236 {
0237 }
0238 #endif
0239
0240 #ifdef CONFIG_PCI_MSI
0241 struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc);
0242 void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
0243 #else
0244 static inline void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
0245 {
0246 }
0247 #endif
0248
0249 int msi_add_msi_desc(struct device *dev, struct msi_desc *init_desc);
0250 void msi_free_msi_descs_range(struct device *dev, enum msi_desc_filter filter,
0251 unsigned int first_index, unsigned int last_index);
0252
0253
0254
0255
0256
0257 static inline void msi_free_msi_descs(struct device *dev)
0258 {
0259 msi_free_msi_descs_range(dev, MSI_DESC_ALL, 0, MSI_MAX_INDEX);
0260 }
0261
0262 void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
0263 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
0264
0265 void pci_msi_mask_irq(struct irq_data *data);
0266 void pci_msi_unmask_irq(struct irq_data *data);
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276 #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS
0277 int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);
0278 void arch_teardown_msi_irq(unsigned int irq);
0279 int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
0280 void arch_teardown_msi_irqs(struct pci_dev *dev);
0281 #ifdef CONFIG_SYSFS
0282 int msi_device_populate_sysfs(struct device *dev);
0283 void msi_device_destroy_sysfs(struct device *dev);
0284 #else
0285 static inline int msi_device_populate_sysfs(struct device *dev) { return 0; }
0286 static inline void msi_device_destroy_sysfs(struct device *dev) { }
0287 #endif
0288 #endif
0289
0290
0291
0292
0293
0294 bool arch_restore_msi_irqs(struct pci_dev *dev);
0295
0296 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
0297
0298 #include <linux/irqhandler.h>
0299
0300 struct irq_domain;
0301 struct irq_domain_ops;
0302 struct irq_chip;
0303 struct device_node;
0304 struct fwnode_handle;
0305 struct msi_domain_info;
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342 struct msi_domain_ops {
0343 irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info,
0344 msi_alloc_info_t *arg);
0345 int (*msi_init)(struct irq_domain *domain,
0346 struct msi_domain_info *info,
0347 unsigned int virq, irq_hw_number_t hwirq,
0348 msi_alloc_info_t *arg);
0349 void (*msi_free)(struct irq_domain *domain,
0350 struct msi_domain_info *info,
0351 unsigned int virq);
0352 int (*msi_check)(struct irq_domain *domain,
0353 struct msi_domain_info *info,
0354 struct device *dev);
0355 int (*msi_prepare)(struct irq_domain *domain,
0356 struct device *dev, int nvec,
0357 msi_alloc_info_t *arg);
0358 void (*set_desc)(msi_alloc_info_t *arg,
0359 struct msi_desc *desc);
0360 int (*domain_alloc_irqs)(struct irq_domain *domain,
0361 struct device *dev, int nvec);
0362 void (*domain_free_irqs)(struct irq_domain *domain,
0363 struct device *dev);
0364 };
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377 struct msi_domain_info {
0378 u32 flags;
0379 struct msi_domain_ops *ops;
0380 struct irq_chip *chip;
0381 void *chip_data;
0382 irq_flow_handler_t handler;
0383 void *handler_data;
0384 const char *handler_name;
0385 void *data;
0386 };
0387
0388
0389 enum {
0390
0391
0392
0393
0394 MSI_FLAG_USE_DEF_DOM_OPS = (1 << 0),
0395
0396
0397
0398
0399 MSI_FLAG_USE_DEF_CHIP_OPS = (1 << 1),
0400
0401 MSI_FLAG_MULTI_PCI_MSI = (1 << 2),
0402
0403 MSI_FLAG_PCI_MSIX = (1 << 3),
0404
0405 MSI_FLAG_ACTIVATE_EARLY = (1 << 4),
0406
0407
0408
0409
0410 MSI_FLAG_MUST_REACTIVATE = (1 << 5),
0411
0412 MSI_FLAG_LEVEL_CAPABLE = (1 << 6),
0413
0414 MSI_FLAG_DEV_SYSFS = (1 << 7),
0415
0416 MSI_FLAG_MSIX_CONTIGUOUS = (1 << 8),
0417
0418 MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS = (1 << 9),
0419
0420 MSI_FLAG_FREE_MSI_DESCS = (1 << 10),
0421 };
0422
0423 int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
0424 bool force);
0425
0426 struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
0427 struct msi_domain_info *info,
0428 struct irq_domain *parent);
0429 int __msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
0430 int nvec);
0431 int msi_domain_alloc_irqs_descs_locked(struct irq_domain *domain, struct device *dev,
0432 int nvec);
0433 int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
0434 int nvec);
0435 void __msi_domain_free_irqs(struct irq_domain *domain, struct device *dev);
0436 void msi_domain_free_irqs_descs_locked(struct irq_domain *domain, struct device *dev);
0437 void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev);
0438 struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain);
0439
0440 struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
0441 struct msi_domain_info *info,
0442 struct irq_domain *parent);
0443 int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
0444 irq_write_msi_msg_t write_msi_msg);
0445 void platform_msi_domain_free_irqs(struct device *dev);
0446
0447
0448 int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
0449 int nvec, msi_alloc_info_t *args);
0450 int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
0451 int virq, int nvec, msi_alloc_info_t *args);
0452 struct irq_domain *
0453 __platform_msi_create_device_domain(struct device *dev,
0454 unsigned int nvec,
0455 bool is_tree,
0456 irq_write_msi_msg_t write_msi_msg,
0457 const struct irq_domain_ops *ops,
0458 void *host_data);
0459
0460 #define platform_msi_create_device_domain(dev, nvec, write, ops, data) \
0461 __platform_msi_create_device_domain(dev, nvec, false, write, ops, data)
0462 #define platform_msi_create_device_tree_domain(dev, nvec, write, ops, data) \
0463 __platform_msi_create_device_domain(dev, nvec, true, write, ops, data)
0464
0465 int platform_msi_device_domain_alloc(struct irq_domain *domain, unsigned int virq,
0466 unsigned int nr_irqs);
0467 void platform_msi_device_domain_free(struct irq_domain *domain, unsigned int virq,
0468 unsigned int nvec);
0469 void *platform_msi_get_host_data(struct irq_domain *domain);
0470 #endif
0471
0472 #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
0473 struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
0474 struct msi_domain_info *info,
0475 struct irq_domain *parent);
0476 u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev);
0477 struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev);
0478 bool pci_dev_has_special_msi_domain(struct pci_dev *pdev);
0479 #else
0480 static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev)
0481 {
0482 return NULL;
0483 }
0484 #endif
0485
0486 #endif