1
2
3
4
5
6
7
8
9#include <linux/types.h>
10#include <linux/irq.h>
11#include <linux/pci.h>
12#include <linux/cpumask.h>
13#include <linux/msi.h>
14
15#include <asm/sn/addrs.h>
16#include <asm/sn/intr.h>
17#include <asm/sn/pcibus_provider_defs.h>
18#include <asm/sn/pcidev.h>
19#include <asm/sn/nodepda.h>
20
21struct sn_msi_info {
22 u64 pci_addr;
23 struct sn_irq_info *sn_irq_info;
24};
25
26static struct sn_msi_info sn_msi_info[NR_IRQS];
27
28static struct irq_chip sn_msi_chip;
29
30void sn_teardown_msi_irq(unsigned int irq)
31{
32 nasid_t nasid;
33 int widget;
34 struct pci_dev *pdev;
35 struct pcidev_info *sn_pdev;
36 struct sn_irq_info *sn_irq_info;
37 struct pcibus_bussoft *bussoft;
38 struct sn_pcibus_provider *provider;
39
40 sn_irq_info = sn_msi_info[irq].sn_irq_info;
41 if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
42 return;
43
44 sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
45 pdev = sn_pdev->pdi_linux_pcidev;
46 provider = SN_PCIDEV_BUSPROVIDER(pdev);
47
48 (*provider->dma_unmap)(pdev,
49 sn_msi_info[irq].pci_addr,
50 PCI_DMA_FROMDEVICE);
51 sn_msi_info[irq].pci_addr = 0;
52
53 bussoft = SN_PCIDEV_BUSSOFT(pdev);
54 nasid = NASID_GET(bussoft->bs_base);
55 widget = (nasid & 1) ?
56 TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
57 SWIN_WIDGETNUM(bussoft->bs_base);
58
59 sn_intr_free(nasid, widget, sn_irq_info);
60 sn_msi_info[irq].sn_irq_info = NULL;
61
62 destroy_irq(irq);
63}
64
65int sn_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *entry)
66{
67 struct msi_msg msg;
68 int widget;
69 int status;
70 nasid_t nasid;
71 u64 bus_addr;
72 struct sn_irq_info *sn_irq_info;
73 struct pcibus_bussoft *bussoft = SN_PCIDEV_BUSSOFT(pdev);
74 struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
75 int irq;
76
77 if (!entry->msi_attrib.is_64)
78 return -EINVAL;
79
80 if (bussoft == NULL)
81 return -EINVAL;
82
83 if (provider == NULL || provider->dma_map_consistent == NULL)
84 return -EINVAL;
85
86 irq = create_irq();
87 if (irq < 0)
88 return irq;
89
90
91
92
93
94
95 nasid = NASID_GET(bussoft->bs_base);
96 widget = (nasid & 1) ?
97 TIO_SWIN_WIDGETNUM(bussoft->bs_base) :
98 SWIN_WIDGETNUM(bussoft->bs_base);
99
100 sn_irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);
101 if (! sn_irq_info) {
102 destroy_irq(irq);
103 return -ENOMEM;
104 }
105
106 status = sn_intr_alloc(nasid, widget, sn_irq_info, irq, -1, -1);
107 if (status) {
108 kfree(sn_irq_info);
109 destroy_irq(irq);
110 return -ENOMEM;
111 }
112
113 sn_irq_info->irq_int_bit = -1;
114 sn_irq_fixup(pdev, sn_irq_info);
115
116
117 sn_irq_info->irq_bridge_type = bussoft->bs_asic_type;
118 sn_irq_info->irq_bridge = (void *)bussoft->bs_base;
119
120
121
122
123 bus_addr = (*provider->dma_map_consistent)(pdev,
124 sn_irq_info->irq_xtalkaddr,
125 sizeof(sn_irq_info->irq_xtalkaddr),
126 SN_DMA_MSI|SN_DMA_ADDR_XIO);
127 if (! bus_addr) {
128 sn_intr_free(nasid, widget, sn_irq_info);
129 kfree(sn_irq_info);
130 destroy_irq(irq);
131 return -ENOMEM;
132 }
133
134 sn_msi_info[irq].sn_irq_info = sn_irq_info;
135 sn_msi_info[irq].pci_addr = bus_addr;
136
137 msg.address_hi = (u32)(bus_addr >> 32);
138 msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
139
140
141
142
143
144 msg.data = 0x100 + irq;
145
146 set_irq_msi(irq, entry);
147 write_msi_msg(irq, &msg);
148 set_irq_chip_and_handler(irq, &sn_msi_chip, handle_edge_irq);
149
150 return 0;
151}
152
153#ifdef CONFIG_SMP
154static int sn_set_msi_irq_affinity(unsigned int irq,
155 const struct cpumask *cpu_mask)
156{
157 struct msi_msg msg;
158 int slice;
159 nasid_t nasid;
160 u64 bus_addr;
161 struct pci_dev *pdev;
162 struct pcidev_info *sn_pdev;
163 struct sn_irq_info *sn_irq_info;
164 struct sn_irq_info *new_irq_info;
165 struct sn_pcibus_provider *provider;
166 unsigned int cpu;
167
168 cpu = cpumask_first(cpu_mask);
169 sn_irq_info = sn_msi_info[irq].sn_irq_info;
170 if (sn_irq_info == NULL || sn_irq_info->irq_int_bit >= 0)
171 return -1;
172
173
174
175
176
177 read_msi_msg(irq, &msg);
178 sn_pdev = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
179 pdev = sn_pdev->pdi_linux_pcidev;
180 provider = SN_PCIDEV_BUSPROVIDER(pdev);
181
182 bus_addr = (u64)(msg.address_hi) << 32 | (u64)(msg.address_lo);
183 (*provider->dma_unmap)(pdev, bus_addr, PCI_DMA_FROMDEVICE);
184 sn_msi_info[irq].pci_addr = 0;
185
186 nasid = cpuid_to_nasid(cpu);
187 slice = cpuid_to_slice(cpu);
188
189 new_irq_info = sn_retarget_vector(sn_irq_info, nasid, slice);
190 sn_msi_info[irq].sn_irq_info = new_irq_info;
191 if (new_irq_info == NULL)
192 return -1;
193
194
195
196
197
198 bus_addr = (*provider->dma_map_consistent)(pdev,
199 new_irq_info->irq_xtalkaddr,
200 sizeof(new_irq_info->irq_xtalkaddr),
201 SN_DMA_MSI|SN_DMA_ADDR_XIO);
202
203 sn_msi_info[irq].pci_addr = bus_addr;
204 msg.address_hi = (u32)(bus_addr >> 32);
205 msg.address_lo = (u32)(bus_addr & 0x00000000ffffffff);
206
207 write_msi_msg(irq, &msg);
208 cpumask_copy(irq_desc[irq].affinity, cpu_mask);
209
210 return 0;
211}
212#endif
213
214static void sn_ack_msi_irq(unsigned int irq)
215{
216 move_native_irq(irq);
217 ia64_eoi();
218}
219
220static int sn_msi_retrigger_irq(unsigned int irq)
221{
222 unsigned int vector = irq;
223 ia64_resend_irq(vector);
224
225 return 1;
226}
227
228static struct irq_chip sn_msi_chip = {
229 .name = "PCI-MSI",
230 .mask = mask_msi_irq,
231 .unmask = unmask_msi_irq,
232 .ack = sn_ack_msi_irq,
233#ifdef CONFIG_SMP
234 .set_affinity = sn_set_msi_irq_affinity,
235#endif
236 .retrigger = sn_msi_retrigger_irq,
237};
238