msi_ia64.c 4.4 KB
Newer Older
1 2 3 4 5 6
/*
 * MSI hooks for standard x86 apic
 */

#include <linux/pci.h>
#include <linux/irq.h>
7
#include <linux/msi.h>
8
#include <linux/dmar.h>
9
#include <asm/smp.h>
10
#include <asm/msidef.h>
11

12
static struct irq_chip	ia64_msi_chip;
13

14
#ifdef CONFIG_SMP
15 16
static int ia64_set_msi_irq_affinity(struct irq_data *idata,
				     const cpumask_t *cpu_mask, bool force)
17
{
18
	struct msi_msg msg;
19
	u32 addr, data;
20
	int cpu = first_cpu(*cpu_mask);
21
	unsigned int irq = idata->irq;
22

23
	if (!cpu_online(cpu))
24
		return -1;
25

26
	if (irq_prepare_move(irq, cpu))
27
		return -1;
28

29
	get_cached_msi_msg(irq, &msg);
30

31
	addr = msg.address_lo;
32 33
	addr &= MSI_ADDR_DEST_ID_MASK;
	addr |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
34
	msg.address_lo = addr;
35

36 37 38 39 40
	data = msg.data;
	data &= MSI_DATA_VECTOR_MASK;
	data |= MSI_DATA_VECTOR(irq_to_vector(irq));
	msg.data = data;

41
	write_msi_msg(irq, &msg);
42
	cpumask_copy(idata->affinity, cpumask_of(cpu));
43 44

	return 0;
45
}
46
#endif /* CONFIG_SMP */
47

48
int ia64_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
49
{
50
	struct msi_msg	msg;
51
	unsigned long	dest_phys_id;
52
	int	irq, vector;
53
	cpumask_t mask;
54

55 56 57 58 59
	irq = create_irq();
	if (irq < 0)
		return irq;

	set_irq_msi(irq, desc);
60 61
	cpus_and(mask, irq_to_domain(irq), cpu_online_map);
	dest_phys_id = cpu_physical_id(first_cpu(mask));
62
	vector = irq_to_vector(irq);
63

64 65
	msg.address_hi = 0;
	msg.address_lo =
66
		MSI_ADDR_HEADER |
67
		MSI_ADDR_DEST_MODE_PHYS |
68
		MSI_ADDR_REDIRECTION_CPU |
69
		MSI_ADDR_DEST_ID_CPU(dest_phys_id);
70

71
	msg.data =
72
		MSI_DATA_TRIGGER_EDGE |
73 74 75 76
		MSI_DATA_LEVEL_ASSERT |
		MSI_DATA_DELIVERY_FIXED |
		MSI_DATA_VECTOR(vector);

77 78 79
	write_msi_msg(irq, &msg);
	set_irq_chip_and_handler(irq, &ia64_msi_chip, handle_edge_irq);

80
	return 0;
81 82
}

83
void ia64_teardown_msi_irq(unsigned int irq)
84
{
85
	destroy_irq(irq);
86 87
}

88
static void ia64_ack_msi_irq(struct irq_data *data)
89
{
90
	irq_complete_move(data->irq);
T
Thomas Gleixner 已提交
91
	irq_move_irq(data);
92 93 94
	ia64_eoi();
}

95
static int ia64_msi_retrigger_irq(struct irq_data *data)
96
{
97
	unsigned int vector = irq_to_vector(data->irq);
98 99 100 101 102
	ia64_resend_irq(vector);

	return 1;
}

103
/*
104
 * Generic ops used on most IA64 platforms.
105
 */
106
static struct irq_chip ia64_msi_chip = {
107 108 109 110
	.name			= "PCI-MSI",
	.irq_mask		= mask_msi_irq,
	.irq_unmask		= unmask_msi_irq,
	.irq_ack		= ia64_ack_msi_irq,
111
#ifdef CONFIG_SMP
112
	.irq_set_affinity	= ia64_set_msi_irq_affinity,
113
#endif
114
	.irq_retrigger		= ia64_msi_retrigger_irq,
115
};
116 117


118
int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
119 120
{
	if (platform_setup_msi_irq)
121
		return platform_setup_msi_irq(pdev, desc);
122

123
	return ia64_setup_msi_irq(pdev, desc);
124 125 126 127 128 129 130 131 132
}

void arch_teardown_msi_irq(unsigned int irq)
{
	if (platform_teardown_msi_irq)
		return platform_teardown_msi_irq(irq);

	return ia64_teardown_msi_irq(irq);
}
133 134 135

#ifdef CONFIG_DMAR
#ifdef CONFIG_SMP
136 137
static int dmar_msi_set_affinity(struct irq_data *data,
				 const struct cpumask *mask, bool force)
138
{
139
	unsigned int irq = data->irq;
140 141
	struct irq_cfg *cfg = irq_cfg + irq;
	struct msi_msg msg;
142
	int cpu = cpumask_first(mask);
143 144

	if (!cpu_online(cpu))
145
		return -1;
146 147

	if (irq_prepare_move(irq, cpu))
148
		return -1;
149 150 151 152 153

	dmar_msi_read(irq, &msg);

	msg.data &= ~MSI_DATA_VECTOR_MASK;
	msg.data |= MSI_DATA_VECTOR(cfg->vector);
154 155
	msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
	msg.address_lo |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
156 157

	dmar_msi_write(irq, &msg);
158
	cpumask_copy(data->affinity, mask);
159 160

	return 0;
161 162 163
}
#endif /* CONFIG_SMP */

164
static struct irq_chip dmar_msi_type = {
165
	.name = "DMAR_MSI",
166 167
	.irq_unmask = dmar_msi_unmask,
	.irq_mask = dmar_msi_mask,
168
	.irq_ack = ia64_ack_msi_irq,
169
#ifdef CONFIG_SMP
170
	.irq_set_affinity = dmar_msi_set_affinity,
171
#endif
172
	.irq_retrigger = ia64_msi_retrigger_irq,
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
};

static int
msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
{
	struct irq_cfg *cfg = irq_cfg + irq;
	unsigned dest;
	cpumask_t mask;

	cpus_and(mask, irq_to_domain(irq), cpu_online_map);
	dest = cpu_physical_id(first_cpu(mask));

	msg->address_hi = 0;
	msg->address_lo =
		MSI_ADDR_HEADER |
188
		MSI_ADDR_DEST_MODE_PHYS |
189
		MSI_ADDR_REDIRECTION_CPU |
190
		MSI_ADDR_DEST_ID_CPU(dest);
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

	msg->data =
		MSI_DATA_TRIGGER_EDGE |
		MSI_DATA_LEVEL_ASSERT |
		MSI_DATA_DELIVERY_FIXED |
		MSI_DATA_VECTOR(cfg->vector);
	return 0;
}

int arch_setup_dmar_msi(unsigned int irq)
{
	int ret;
	struct msi_msg msg;

	ret = msi_compose_msg(NULL, irq, &msg);
	if (ret < 0)
		return ret;
	dmar_msi_write(irq, &msg);
	set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
		"edge");
	return 0;
}
#endif /* CONFIG_DMAR */