msi.h 3.5 KB
Newer Older
1 2 3
#ifndef LINUX_MSI_H
#define LINUX_MSI_H

4
#include <linux/kobject.h>
5 6
#include <linux/list.h>

7 8 9 10 11 12
struct msi_msg {
	u32	address_lo;	/* low 32 bits of msi message address */
	u32	address_hi;	/* high 32 bits of msi message address */
	u32	data;		/* 16 bits of msi message data */
};

13
extern int pci_msi_ignore_mask;
S
Satoru Takeuchi 已提交
14
/* Helper functions */
15
struct irq_data;
16
struct msi_desc;
17 18
void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
19

20 21
struct msi_desc {
	struct {
22
		__u8	is_msix	: 1;
23 24
		__u8	multiple: 3;	/* log2 num of messages allocated */
		__u8	multi_cap : 3;	/* log2 num of messages supported */
25 26 27 28
		__u8	maskbit	: 1;	/* mask-pending bit supported ? */
		__u8	is_64	: 1;	/* Address size: 0=32bit 1=64bit */
		__u16	entry_nr;	/* specific enabled entry */
		unsigned default_irq;	/* default pre-assigned irq */
29
	} msi_attrib;
30

31
	u32 masked;			/* mask bits */
32
	unsigned int irq;
33
	unsigned int nvec_used;		/* number of messages */
34
	struct list_head list;
35

36 37 38 39
	union {
		void __iomem *mask_base;
		u8 mask_pos;
	};
40 41
	struct pci_dev *dev;

42 43
	/* Last set MSI message */
	struct msi_msg msg;
44 45
};

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/* Helpers to hide struct msi_desc implementation details */
#define msi_desc_to_dev(desc)		(&(desc)->dev.dev)
#define dev_to_msi_list(dev)		(&to_pci_dev((dev))->msi_list)
#define first_msi_entry(dev)		\
	list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list)
#define for_each_msi_entry(desc, dev)	\
	list_for_each_entry((desc), dev_to_msi_list((dev)), list)

#ifdef CONFIG_PCI_MSI
#define first_pci_msi_entry(pdev)	first_msi_entry(&(pdev)->dev)
#define for_each_pci_msi_entry(desc, pdev)	\
	for_each_msi_entry((desc), &(pdev)->dev)

static inline struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc)
{
	return desc->dev;
}
#endif /* CONFIG_PCI_MSI */

65
void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
66 67 68
void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);

69 70 71 72 73
u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);
void pci_msi_mask_irq(struct irq_data *data);
void pci_msi_unmask_irq(struct irq_data *data);

74 75 76 77 78 79 80 81 82
/* Conversion helpers. Should be removed after merging */
static inline void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
{
	__pci_write_msi_msg(entry, msg);
}
static inline void write_msi_msg(int irq, struct msi_msg *msg)
{
	pci_write_msi_msg(irq, msg);
}
83 84 85 86 87 88 89 90
static inline void mask_msi_irq(struct irq_data *data)
{
	pci_msi_mask_irq(data);
}
static inline void unmask_msi_irq(struct irq_data *data)
{
	pci_msi_unmask_irq(data);
}
91

92
/*
93 94 95
 * The arch hooks to setup up msi irqs. Those functions are
 * implemented as weak symbols so that they /can/ be overriden by
 * architecture specific code if needed.
96
 */
97
int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);
98
void arch_teardown_msi_irq(unsigned int irq);
99 100
int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
void arch_teardown_msi_irqs(struct pci_dev *dev);
101
void arch_restore_msi_irqs(struct pci_dev *dev);
102 103

void default_teardown_msi_irqs(struct pci_dev *dev);
104
void default_restore_msi_irqs(struct pci_dev *dev);
105

106
struct msi_controller {
107 108
	struct module *owner;
	struct device *dev;
109 110
	struct device_node *of_node;
	struct list_head list;
111

112
	int (*setup_irq)(struct msi_controller *chip, struct pci_dev *dev,
113
			 struct msi_desc *desc);
114
	void (*teardown_irq)(struct msi_controller *chip, unsigned int irq);
115 116
};

117
#endif /* LINUX_MSI_H */