Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | |
3 | * License. See the file "COPYING" in the main directory of this archive | |
4 | * for more details. | |
5 | * | |
8ea6091f | 6 | * Copyright (C) 2001-2004, 2006 Silicon Graphics, Inc. All rights reserved. |
1da177e4 LT |
7 | */ |
8 | ||
1da177e4 | 9 | #include <linux/interrupt.h> |
c13cf371 | 10 | #include <linux/types.h> |
5a0e3ad6 | 11 | #include <linux/slab.h> |
1da177e4 | 12 | #include <linux/pci.h> |
bd3ff194 | 13 | #include <linux/export.h> |
c13cf371 | 14 | #include <asm/sn/addrs.h> |
1da177e4 | 15 | #include <asm/sn/geo.h> |
c13cf371 | 16 | #include <asm/sn/pcibr_provider.h> |
9b08ebd1 MM |
17 | #include <asm/sn/pcibus_provider_defs.h> |
18 | #include <asm/sn/pcidev.h> | |
c13cf371 | 19 | #include <asm/sn/sn_sal.h> |
1ee27a4e | 20 | #include <asm/sn/pic.h> |
5390970d | 21 | #include <asm/sn/sn2/sn_hwperf.h> |
c13cf371 PB |
22 | #include "xtalk/xwidgetdev.h" |
23 | #include "xtalk/hubdev.h" | |
1da177e4 | 24 | |
6f354b01 | 25 | int |
6f09a925 JK |
26 | sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp, |
27 | char **ssdt) | |
6f354b01 PB |
28 | { |
29 | struct ia64_sal_retval ret_stuff; | |
53493dcf | 30 | u64 busnum; |
ac354a89 | 31 | u64 segment; |
6f354b01 PB |
32 | |
33 | ret_stuff.status = 0; | |
34 | ret_stuff.v0 = 0; | |
35 | ||
ac354a89 | 36 | segment = soft->pbi_buscommon.bs_persist_segment; |
6f354b01 | 37 | busnum = soft->pbi_buscommon.bs_persist_busnum; |
ac354a89 | 38 | SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_ENABLE, segment, |
6f09a925 JK |
39 | busnum, (u64) device, (u64) resp, (u64)ia64_tpa(ssdt), |
40 | 0, 0); | |
6f354b01 PB |
41 | |
42 | return (int)ret_stuff.v0; | |
43 | } | |
44 | ||
45 | int | |
46 | sal_pcibr_slot_disable(struct pcibus_info *soft, int device, int action, | |
47 | void *resp) | |
48 | { | |
49 | struct ia64_sal_retval ret_stuff; | |
53493dcf | 50 | u64 busnum; |
ac354a89 | 51 | u64 segment; |
6f354b01 PB |
52 | |
53 | ret_stuff.status = 0; | |
54 | ret_stuff.v0 = 0; | |
55 | ||
ac354a89 | 56 | segment = soft->pbi_buscommon.bs_persist_segment; |
6f354b01 PB |
57 | busnum = soft->pbi_buscommon.bs_persist_busnum; |
58 | SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_DISABLE, | |
ac354a89 MH |
59 | segment, busnum, (u64) device, (u64) action, |
60 | (u64) resp, 0, 0); | |
6f354b01 PB |
61 | |
62 | return (int)ret_stuff.v0; | |
63 | } | |
64 | ||
1da177e4 LT |
65 | static int sal_pcibr_error_interrupt(struct pcibus_info *soft) |
66 | { | |
67 | struct ia64_sal_retval ret_stuff; | |
53493dcf | 68 | u64 busnum; |
1da177e4 LT |
69 | int segment; |
70 | ret_stuff.status = 0; | |
71 | ret_stuff.v0 = 0; | |
72 | ||
674c6479 | 73 | segment = soft->pbi_buscommon.bs_persist_segment; |
1da177e4 LT |
74 | busnum = soft->pbi_buscommon.bs_persist_busnum; |
75 | SAL_CALL_NOLOCK(ret_stuff, | |
76 | (u64) SN_SAL_IOIF_ERROR_INTERRUPT, | |
77 | (u64) segment, (u64) busnum, 0, 0, 0, 0, 0); | |
78 | ||
79 | return (int)ret_stuff.v0; | |
80 | } | |
81 | ||
f90aa8c4 PB |
82 | u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus) |
83 | { | |
e088a4ad | 84 | long rc; |
256a7e09 | 85 | u16 uninitialized_var(ioboard); /* GCC be quiet */ |
f90aa8c4 PB |
86 | nasid_t nasid = NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus)->bs_base); |
87 | ||
88 | rc = ia64_sn_sysctl_ioboard_get(nasid, &ioboard); | |
89 | if (rc) { | |
90 | printk(KERN_WARNING "ia64_sn_sysctl_ioboard_get failed: %ld\n", | |
91 | rc); | |
92 | return 0; | |
93 | } | |
94 | ||
95 | return ioboard; | |
96 | } | |
97 | ||
1da177e4 LT |
98 | /* |
99 | * PCI Bridge Error interrupt handler. Gets invoked whenever a PCI | |
100 | * bridge sends an error interrupt. | |
101 | */ | |
102 | static irqreturn_t | |
a23b7cb9 | 103 | pcibr_error_intr_handler(int irq, void *arg) |
1da177e4 | 104 | { |
15aafa2f | 105 | struct pcibus_info *soft = arg; |
1da177e4 | 106 | |
15aafa2f | 107 | if (sal_pcibr_error_interrupt(soft) < 0) |
1da177e4 | 108 | panic("pcibr_error_intr_handler(): Fatal Bridge Error"); |
15aafa2f | 109 | |
1da177e4 LT |
110 | return IRQ_HANDLED; |
111 | } | |
112 | ||
113 | void * | |
7c2a6c62 | 114 | pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller) |
1da177e4 LT |
115 | { |
116 | int nasid, cnode, j; | |
117 | struct hubdev_info *hubdev_info; | |
118 | struct pcibus_info *soft; | |
6d6e4200 PB |
119 | struct sn_flush_device_kernel *sn_flush_device_kernel; |
120 | struct sn_flush_device_common *common; | |
1da177e4 LT |
121 | |
122 | if (! IS_PCI_BRIDGE_ASIC(prom_bussoft->bs_asic_type)) { | |
123 | return NULL; | |
124 | } | |
125 | ||
126 | /* | |
127 | * Allocate kernel bus soft and copy from prom. | |
128 | */ | |
129 | ||
a4b1d1b3 | 130 | soft = kmemdup(prom_bussoft, sizeof(struct pcibus_info), GFP_KERNEL); |
1da177e4 LT |
131 | if (!soft) { |
132 | return NULL; | |
133 | } | |
134 | ||
1ee27a4e JS |
135 | soft->pbi_buscommon.bs_base = (unsigned long) |
136 | ioremap(REGION_OFFSET(soft->pbi_buscommon.bs_base), | |
137 | sizeof(struct pic)); | |
1da177e4 LT |
138 | |
139 | spin_lock_init(&soft->pbi_lock); | |
140 | ||
141 | /* | |
142 | * register the bridge's error interrupt handler | |
143 | */ | |
a23b7cb9 | 144 | if (request_irq(SGI_PCIASIC_ERROR, pcibr_error_intr_handler, |
121a4226 | 145 | IRQF_SHARED, "PCIBR error", (void *)(soft))) { |
1da177e4 LT |
146 | printk(KERN_WARNING |
147 | "pcibr cannot allocate interrupt for error handler\n"); | |
148 | } | |
6e9de181 | 149 | sn_set_err_irq_affinity(SGI_PCIASIC_ERROR); |
1da177e4 LT |
150 | |
151 | /* | |
152 | * Update the Bridge with the "kernel" pagesize | |
153 | */ | |
154 | if (PAGE_SIZE < 16384) { | |
155 | pcireg_control_bit_clr(soft, PCIBR_CTRL_PAGE_SIZE); | |
156 | } else { | |
157 | pcireg_control_bit_set(soft, PCIBR_CTRL_PAGE_SIZE); | |
158 | } | |
159 | ||
160 | nasid = NASID_GET(soft->pbi_buscommon.bs_base); | |
161 | cnode = nasid_to_cnodeid(nasid); | |
162 | hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo); | |
163 | ||
164 | if (hubdev_info->hdi_flush_nasid_list.widget_p) { | |
6d6e4200 | 165 | sn_flush_device_kernel = hubdev_info->hdi_flush_nasid_list. |
1da177e4 | 166 | widget_p[(int)soft->pbi_buscommon.bs_xid]; |
6d6e4200 | 167 | if (sn_flush_device_kernel) { |
1da177e4 | 168 | for (j = 0; j < DEV_PER_WIDGET; |
6d6e4200 PB |
169 | j++, sn_flush_device_kernel++) { |
170 | common = sn_flush_device_kernel->common; | |
171 | if (common->sfdl_slot == -1) | |
1da177e4 | 172 | continue; |
6d6e4200 | 173 | if ((common->sfdl_persistent_segment == |
674c6479 | 174 | soft->pbi_buscommon.bs_persist_segment) && |
6d6e4200 | 175 | (common->sfdl_persistent_busnum == |
674c6479 | 176 | soft->pbi_buscommon.bs_persist_busnum)) |
6d6e4200 | 177 | common->sfdl_pcibus_info = |
1da177e4 LT |
178 | soft; |
179 | } | |
180 | } | |
181 | } | |
182 | ||
183 | /* Setup the PMU ATE map */ | |
184 | soft->pbi_int_ate_resource.lowest_free_index = 0; | |
185 | soft->pbi_int_ate_resource.ate = | |
8ed9b2c7 JS |
186 | kzalloc(soft->pbi_int_ate_size * sizeof(u64), GFP_KERNEL); |
187 | ||
188 | if (!soft->pbi_int_ate_resource.ate) { | |
189 | kfree(soft); | |
190 | return NULL; | |
191 | } | |
1da177e4 LT |
192 | |
193 | return soft; | |
194 | } | |
195 | ||
196 | void pcibr_force_interrupt(struct sn_irq_info *sn_irq_info) | |
197 | { | |
198 | struct pcidev_info *pcidev_info; | |
199 | struct pcibus_info *pcibus_info; | |
200 | int bit = sn_irq_info->irq_int_bit; | |
201 | ||
735e60f4 MM |
202 | if (! sn_irq_info->irq_bridge) |
203 | return; | |
204 | ||
1da177e4 LT |
205 | pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo; |
206 | if (pcidev_info) { | |
207 | pcibus_info = | |
208 | (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info-> | |
209 | pdi_pcibus_info; | |
210 | pcireg_force_intr_set(pcibus_info, bit); | |
211 | } | |
212 | } | |
213 | ||
8409668b | 214 | void pcibr_target_interrupt(struct sn_irq_info *sn_irq_info) |
1da177e4 LT |
215 | { |
216 | struct pcidev_info *pcidev_info; | |
217 | struct pcibus_info *pcibus_info; | |
218 | int bit = sn_irq_info->irq_int_bit; | |
53493dcf | 219 | u64 xtalk_addr = sn_irq_info->irq_xtalkaddr; |
1da177e4 LT |
220 | |
221 | pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo; | |
222 | if (pcidev_info) { | |
223 | pcibus_info = | |
224 | (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info-> | |
225 | pdi_pcibus_info; | |
226 | ||
227 | /* Disable the device's IRQ */ | |
6fb93a92 | 228 | pcireg_intr_enable_bit_clr(pcibus_info, (1 << bit)); |
1da177e4 LT |
229 | |
230 | /* Change the device's IRQ */ | |
231 | pcireg_intr_addr_addr_set(pcibus_info, bit, xtalk_addr); | |
232 | ||
233 | /* Re-enable the device's IRQ */ | |
6fb93a92 | 234 | pcireg_intr_enable_bit_set(pcibus_info, (1 << bit)); |
1da177e4 LT |
235 | |
236 | pcibr_force_interrupt(sn_irq_info); | |
237 | } | |
238 | } | |
e955d825 MM |
239 | |
240 | /* | |
241 | * Provider entries for PIC/CP | |
242 | */ | |
243 | ||
244 | struct sn_pcibus_provider pcibr_provider = { | |
245 | .dma_map = pcibr_dma_map, | |
246 | .dma_map_consistent = pcibr_dma_map_consistent, | |
247 | .dma_unmap = pcibr_dma_unmap, | |
248 | .bus_fixup = pcibr_bus_fixup, | |
8409668b MM |
249 | .force_interrupt = pcibr_force_interrupt, |
250 | .target_interrupt = pcibr_target_interrupt | |
e955d825 MM |
251 | }; |
252 | ||
253 | int | |
254 | pcibr_init_provider(void) | |
255 | { | |
256 | sn_pci_provider[PCIIO_ASIC_TYPE_PIC] = &pcibr_provider; | |
257 | sn_pci_provider[PCIIO_ASIC_TYPE_TIOCP] = &pcibr_provider; | |
258 | ||
259 | return 0; | |
260 | } | |
6f354b01 PB |
261 | |
262 | EXPORT_SYMBOL_GPL(sal_pcibr_slot_enable); | |
263 | EXPORT_SYMBOL_GPL(sal_pcibr_slot_disable); | |
f90aa8c4 | 264 | EXPORT_SYMBOL_GPL(sn_ioboard_to_pci_bus); |