msi_ia64.c 4.2 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
static int ia64_set_msi_irq_affinity(unsigned int irq,
16
				      const cpumask_t *cpu_mask)
17
{
18
	struct msi_msg msg;
19
	u32 addr, data;
20
	int cpu = first_cpu(*cpu_mask);
21

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

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

28
	read_msi_msg(irq, &msg);
29

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

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

40
	write_msi_msg(irq, &msg);
41
	cpumask_copy(irq_desc[irq].affinity, cpumask_of(cpu));
42 43

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

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

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

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

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

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

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

79
	return 0;
80 81
}

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

87 88
static void ia64_ack_msi_irq(unsigned int irq)
{
89
	irq_complete_move(irq);
90 91 92 93 94 95
	move_native_irq(irq);
	ia64_eoi();
}

static int ia64_msi_retrigger_irq(unsigned int irq)
{
96
	unsigned int vector = irq_to_vector(irq);
97 98 99 100 101
	ia64_resend_irq(vector);

	return 1;
}

102
/*
103
 * Generic ops used on most IA64 platforms.
104
 */
105 106 107 108 109 110 111 112 113
static struct irq_chip ia64_msi_chip = {
	.name		= "PCI-MSI",
	.mask		= mask_msi_irq,
	.unmask		= unmask_msi_irq,
	.ack		= ia64_ack_msi_irq,
#ifdef CONFIG_SMP
	.set_affinity	= ia64_set_msi_irq_affinity,
#endif
	.retrigger	= ia64_msi_retrigger_irq,
114
};
115 116


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

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

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);
}
132 133 134

#ifdef CONFIG_DMAR
#ifdef CONFIG_SMP
135
static int dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
136 137 138
{
	struct irq_cfg *cfg = irq_cfg + irq;
	struct msi_msg msg;
139
	int cpu = cpumask_first(mask);
140 141

	if (!cpu_online(cpu))
142
		return -1;
143 144

	if (irq_prepare_move(irq, cpu))
145
		return -1;
146 147 148 149 150

	dmar_msi_read(irq, &msg);

	msg.data &= ~MSI_DATA_VECTOR_MASK;
	msg.data |= MSI_DATA_VECTOR(cfg->vector);
151 152
	msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
	msg.address_lo |= MSI_ADDR_DEST_ID_CPU(cpu_physical_id(cpu));
153 154

	dmar_msi_write(irq, &msg);
155
	cpumask_copy(irq_desc[irq].affinity, mask);
156 157

	return 0;
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
}
#endif /* CONFIG_SMP */

struct irq_chip dmar_msi_type = {
	.name = "DMAR_MSI",
	.unmask = dmar_msi_unmask,
	.mask = dmar_msi_mask,
	.ack = ia64_ack_msi_irq,
#ifdef CONFIG_SMP
	.set_affinity = dmar_msi_set_affinity,
#endif
	.retrigger = ia64_msi_retrigger_irq,
};

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 |
185
		MSI_ADDR_DEST_MODE_PHYS |
186
		MSI_ADDR_REDIRECTION_CPU |
187
		MSI_ADDR_DEST_ID_CPU(dest);
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

	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 */