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
6 * Copyright (C) 2001-2004, 2006 Silicon Graphics, Inc. All rights reserved.
9 #include <linux/interrupt.h>
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <linux/pci.h>
13 #include <asm/sn/addrs.h>
14 #include <asm/sn/geo.h>
15 #include <asm/sn/pcibr_provider.h>
16 #include <asm/sn/pcibus_provider_defs.h>
17 #include <asm/sn/pcidev.h>
18 #include <asm/sn/sn_sal.h>
19 #include <asm/sn/pic.h>
20 #include <asm/sn/sn2/sn_hwperf.h>
21 #include "xtalk/xwidgetdev.h"
22 #include "xtalk/hubdev.h"
25 sal_pcibr_slot_enable(struct pcibus_info
*soft
, int device
, void *resp
,
28 struct ia64_sal_retval ret_stuff
;
35 segment
= soft
->pbi_buscommon
.bs_persist_segment
;
36 busnum
= soft
->pbi_buscommon
.bs_persist_busnum
;
37 SAL_CALL_NOLOCK(ret_stuff
, (u64
) SN_SAL_IOIF_SLOT_ENABLE
, segment
,
38 busnum
, (u64
) device
, (u64
) resp
, (u64
)ia64_tpa(ssdt
),
41 return (int)ret_stuff
.v0
;
45 sal_pcibr_slot_disable(struct pcibus_info
*soft
, int device
, int action
,
48 struct ia64_sal_retval ret_stuff
;
55 segment
= soft
->pbi_buscommon
.bs_persist_segment
;
56 busnum
= soft
->pbi_buscommon
.bs_persist_busnum
;
57 SAL_CALL_NOLOCK(ret_stuff
, (u64
) SN_SAL_IOIF_SLOT_DISABLE
,
58 segment
, busnum
, (u64
) device
, (u64
) action
,
61 return (int)ret_stuff
.v0
;
64 static int sal_pcibr_error_interrupt(struct pcibus_info
*soft
)
66 struct ia64_sal_retval ret_stuff
;
72 segment
= soft
->pbi_buscommon
.bs_persist_segment
;
73 busnum
= soft
->pbi_buscommon
.bs_persist_busnum
;
74 SAL_CALL_NOLOCK(ret_stuff
,
75 (u64
) SN_SAL_IOIF_ERROR_INTERRUPT
,
76 (u64
) segment
, (u64
) busnum
, 0, 0, 0, 0, 0);
78 return (int)ret_stuff
.v0
;
81 u16
sn_ioboard_to_pci_bus(struct pci_bus
*pci_bus
)
84 u16
uninitialized_var(ioboard
); /* GCC be quiet */
85 nasid_t nasid
= NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus
)->bs_base
);
87 rc
= ia64_sn_sysctl_ioboard_get(nasid
, &ioboard
);
89 printk(KERN_WARNING
"ia64_sn_sysctl_ioboard_get failed: %ld\n",
98 * PCI Bridge Error interrupt handler. Gets invoked whenever a PCI
99 * bridge sends an error interrupt.
102 pcibr_error_intr_handler(int irq
, void *arg
)
104 struct pcibus_info
*soft
= arg
;
106 if (sal_pcibr_error_interrupt(soft
) < 0)
107 panic("pcibr_error_intr_handler(): Fatal Bridge Error");
113 pcibr_bus_fixup(struct pcibus_bussoft
*prom_bussoft
, struct pci_controller
*controller
)
116 struct hubdev_info
*hubdev_info
;
117 struct pcibus_info
*soft
;
118 struct sn_flush_device_kernel
*sn_flush_device_kernel
;
119 struct sn_flush_device_common
*common
;
121 if (! IS_PCI_BRIDGE_ASIC(prom_bussoft
->bs_asic_type
)) {
126 * Allocate kernel bus soft and copy from prom.
129 soft
= kmalloc(sizeof(struct pcibus_info
), GFP_KERNEL
);
134 memcpy(soft
, prom_bussoft
, sizeof(struct pcibus_info
));
135 soft
->pbi_buscommon
.bs_base
= (unsigned long)
136 ioremap(REGION_OFFSET(soft
->pbi_buscommon
.bs_base
),
139 spin_lock_init(&soft
->pbi_lock
);
142 * register the bridge's error interrupt handler
144 if (request_irq(SGI_PCIASIC_ERROR
, pcibr_error_intr_handler
,
145 IRQF_SHARED
, "PCIBR error", (void *)(soft
))) {
147 "pcibr cannot allocate interrupt for error handler\n");
149 sn_set_err_irq_affinity(SGI_PCIASIC_ERROR
);
152 * Update the Bridge with the "kernel" pagesize
154 if (PAGE_SIZE
< 16384) {
155 pcireg_control_bit_clr(soft
, PCIBR_CTRL_PAGE_SIZE
);
157 pcireg_control_bit_set(soft
, PCIBR_CTRL_PAGE_SIZE
);
160 nasid
= NASID_GET(soft
->pbi_buscommon
.bs_base
);
161 cnode
= nasid_to_cnodeid(nasid
);
162 hubdev_info
= (struct hubdev_info
*)(NODEPDA(cnode
)->pdinfo
);
164 if (hubdev_info
->hdi_flush_nasid_list
.widget_p
) {
165 sn_flush_device_kernel
= hubdev_info
->hdi_flush_nasid_list
.
166 widget_p
[(int)soft
->pbi_buscommon
.bs_xid
];
167 if (sn_flush_device_kernel
) {
168 for (j
= 0; j
< DEV_PER_WIDGET
;
169 j
++, sn_flush_device_kernel
++) {
170 common
= sn_flush_device_kernel
->common
;
171 if (common
->sfdl_slot
== -1)
173 if ((common
->sfdl_persistent_segment
==
174 soft
->pbi_buscommon
.bs_persist_segment
) &&
175 (common
->sfdl_persistent_busnum
==
176 soft
->pbi_buscommon
.bs_persist_busnum
))
177 common
->sfdl_pcibus_info
=
183 /* Setup the PMU ATE map */
184 soft
->pbi_int_ate_resource
.lowest_free_index
= 0;
185 soft
->pbi_int_ate_resource
.ate
=
186 kzalloc(soft
->pbi_int_ate_size
* sizeof(u64
), GFP_KERNEL
);
188 if (!soft
->pbi_int_ate_resource
.ate
) {
196 void pcibr_force_interrupt(struct sn_irq_info
*sn_irq_info
)
198 struct pcidev_info
*pcidev_info
;
199 struct pcibus_info
*pcibus_info
;
200 int bit
= sn_irq_info
->irq_int_bit
;
202 if (! sn_irq_info
->irq_bridge
)
205 pcidev_info
= (struct pcidev_info
*)sn_irq_info
->irq_pciioinfo
;
208 (struct pcibus_info
*)pcidev_info
->pdi_host_pcidev_info
->
210 pcireg_force_intr_set(pcibus_info
, bit
);
214 void pcibr_target_interrupt(struct sn_irq_info
*sn_irq_info
)
216 struct pcidev_info
*pcidev_info
;
217 struct pcibus_info
*pcibus_info
;
218 int bit
= sn_irq_info
->irq_int_bit
;
219 u64 xtalk_addr
= sn_irq_info
->irq_xtalkaddr
;
221 pcidev_info
= (struct pcidev_info
*)sn_irq_info
->irq_pciioinfo
;
224 (struct pcibus_info
*)pcidev_info
->pdi_host_pcidev_info
->
227 /* Disable the device's IRQ */
228 pcireg_intr_enable_bit_clr(pcibus_info
, (1 << bit
));
230 /* Change the device's IRQ */
231 pcireg_intr_addr_addr_set(pcibus_info
, bit
, xtalk_addr
);
233 /* Re-enable the device's IRQ */
234 pcireg_intr_enable_bit_set(pcibus_info
, (1 << bit
));
236 pcibr_force_interrupt(sn_irq_info
);
241 * Provider entries for PIC/CP
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
,
249 .force_interrupt
= pcibr_force_interrupt
,
250 .target_interrupt
= pcibr_target_interrupt
254 pcibr_init_provider(void)
256 sn_pci_provider
[PCIIO_ASIC_TYPE_PIC
] = &pcibr_provider
;
257 sn_pci_provider
[PCIIO_ASIC_TYPE_TIOCP
] = &pcibr_provider
;
262 EXPORT_SYMBOL_GPL(sal_pcibr_slot_enable
);
263 EXPORT_SYMBOL_GPL(sal_pcibr_slot_disable
);
264 EXPORT_SYMBOL_GPL(sn_ioboard_to_pci_bus
);