blob: 8886a0bc4a11c31ad2b174f23ed7c14843ace3f7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
John Keller8ea60912006-10-04 16:49:25 -05006 * Copyright (C) 2001-2004, 2006 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/interrupt.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070010#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/pci.h>
Paul Gortmakerbd3ff192011-07-31 18:33:21 -040013#include <linux/export.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070014#include <asm/sn/addrs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/sn/geo.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070016#include <asm/sn/pcibr_provider.h>
Mark Maule9b08ebd2005-04-25 11:32:16 -070017#include <asm/sn/pcibus_provider_defs.h>
18#include <asm/sn/pcidev.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070019#include <asm/sn/sn_sal.h>
Jes Sorensen1ee27a42007-06-18 17:19:05 +020020#include <asm/sn/pic.h>
Mark Goodwin53909702005-08-16 00:51:00 -070021#include <asm/sn/sn2/sn_hwperf.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070022#include "xtalk/xwidgetdev.h"
23#include "xtalk/hubdev.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Prarit Bhargava6f354b02005-07-06 15:29:53 -070025int
John Keller6f09a922007-01-30 01:17:37 -050026sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp,
27 char **ssdt)
Prarit Bhargava6f354b02005-07-06 15:29:53 -070028{
29 struct ia64_sal_retval ret_stuff;
Prarit Bhargava53493dc2006-01-16 19:54:40 -080030 u64 busnum;
Mike Habeckac354a82006-01-11 16:40:24 -060031 u64 segment;
Prarit Bhargava6f354b02005-07-06 15:29:53 -070032
33 ret_stuff.status = 0;
34 ret_stuff.v0 = 0;
35
Mike Habeckac354a82006-01-11 16:40:24 -060036 segment = soft->pbi_buscommon.bs_persist_segment;
Prarit Bhargava6f354b02005-07-06 15:29:53 -070037 busnum = soft->pbi_buscommon.bs_persist_busnum;
Mike Habeckac354a82006-01-11 16:40:24 -060038 SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_ENABLE, segment,
John Keller6f09a922007-01-30 01:17:37 -050039 busnum, (u64) device, (u64) resp, (u64)ia64_tpa(ssdt),
40 0, 0);
Prarit Bhargava6f354b02005-07-06 15:29:53 -070041
42 return (int)ret_stuff.v0;
43}
44
45int
46sal_pcibr_slot_disable(struct pcibus_info *soft, int device, int action,
47 void *resp)
48{
49 struct ia64_sal_retval ret_stuff;
Prarit Bhargava53493dc2006-01-16 19:54:40 -080050 u64 busnum;
Mike Habeckac354a82006-01-11 16:40:24 -060051 u64 segment;
Prarit Bhargava6f354b02005-07-06 15:29:53 -070052
53 ret_stuff.status = 0;
54 ret_stuff.v0 = 0;
55
Mike Habeckac354a82006-01-11 16:40:24 -060056 segment = soft->pbi_buscommon.bs_persist_segment;
Prarit Bhargava6f354b02005-07-06 15:29:53 -070057 busnum = soft->pbi_buscommon.bs_persist_busnum;
58 SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_DISABLE,
Mike Habeckac354a82006-01-11 16:40:24 -060059 segment, busnum, (u64) device, (u64) action,
60 (u64) resp, 0, 0);
Prarit Bhargava6f354b02005-07-06 15:29:53 -070061
62 return (int)ret_stuff.v0;
63}
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static int sal_pcibr_error_interrupt(struct pcibus_info *soft)
66{
67 struct ia64_sal_retval ret_stuff;
Prarit Bhargava53493dc2006-01-16 19:54:40 -080068 u64 busnum;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 int segment;
70 ret_stuff.status = 0;
71 ret_stuff.v0 = 0;
72
Colin Ngam674c64792005-08-03 13:35:00 -070073 segment = soft->pbi_buscommon.bs_persist_segment;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 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
Prarit Bhargavaf90aa8c2006-03-08 13:30:18 -050082u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus)
83{
Matthew Wilcoxe088a4a2009-05-22 13:49:49 -070084 long rc;
Jes Sorensen256a7e02007-07-11 17:26:30 +020085 u16 uninitialized_var(ioboard); /* GCC be quiet */
Prarit Bhargavaf90aa8c2006-03-08 13:30:18 -050086 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/*
99 * PCI Bridge Error interrupt handler. Gets invoked whenever a PCI
100 * bridge sends an error interrupt.
101 */
102static irqreturn_t
Al Viroa23b7cb2006-10-09 12:47:31 +0100103pcibr_error_intr_handler(int irq, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Jeff Garzik15aafa22008-02-06 01:36:20 -0800105 struct pcibus_info *soft = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Jeff Garzik15aafa22008-02-06 01:36:20 -0800107 if (sal_pcibr_error_interrupt(soft) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 panic("pcibr_error_intr_handler(): Fatal Bridge Error");
Jeff Garzik15aafa22008-02-06 01:36:20 -0800109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return IRQ_HANDLED;
111}
112
113void *
Christoph Lameter7c2a6c62005-07-12 16:03:00 -0700114pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 int nasid, cnode, j;
117 struct hubdev_info *hubdev_info;
118 struct pcibus_info *soft;
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500119 struct sn_flush_device_kernel *sn_flush_device_kernel;
120 struct sn_flush_device_common *common;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
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
Thomas Meyera4b1d1b2011-11-19 12:26:05 +0100130 soft = kmemdup(prom_bussoft, sizeof(struct pcibus_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (!soft) {
132 return NULL;
133 }
134
Jes Sorensen1ee27a42007-06-18 17:19:05 +0200135 soft->pbi_buscommon.bs_base = (unsigned long)
136 ioremap(REGION_OFFSET(soft->pbi_buscommon.bs_base),
137 sizeof(struct pic));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 spin_lock_init(&soft->pbi_lock);
140
141 /*
142 * register the bridge's error interrupt handler
143 */
Al Viroa23b7cb2006-10-09 12:47:31 +0100144 if (request_irq(SGI_PCIASIC_ERROR, pcibr_error_intr_handler,
Thomas Gleixner121a4222006-07-01 19:29:17 -0700145 IRQF_SHARED, "PCIBR error", (void *)(soft))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 printk(KERN_WARNING
147 "pcibr cannot allocate interrupt for error handler\n");
148 }
John Keller6e9de182007-08-22 19:32:06 -0500149 sn_set_err_irq_affinity(SGI_PCIASIC_ERROR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
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) {
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500165 sn_flush_device_kernel = hubdev_info->hdi_flush_nasid_list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 widget_p[(int)soft->pbi_buscommon.bs_xid];
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500167 if (sn_flush_device_kernel) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 for (j = 0; j < DEV_PER_WIDGET;
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500169 j++, sn_flush_device_kernel++) {
170 common = sn_flush_device_kernel->common;
171 if (common->sfdl_slot == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 continue;
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500173 if ((common->sfdl_persistent_segment ==
Colin Ngam674c64792005-08-03 13:35:00 -0700174 soft->pbi_buscommon.bs_persist_segment) &&
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500175 (common->sfdl_persistent_busnum ==
Colin Ngam674c64792005-08-03 13:35:00 -0700176 soft->pbi_buscommon.bs_persist_busnum))
Prarit Bhargava6d6e4202005-12-23 13:33:25 -0500177 common->sfdl_pcibus_info =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 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 =
Jes Sorensen8ed9b2c2006-02-13 05:29:57 -0500186 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 return soft;
194}
195
196void 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
Mark Maule735e60f2005-08-03 14:06:00 -0700202 if (! sn_irq_info->irq_bridge)
203 return;
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 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
Mark Maule84096682005-08-25 11:45:00 -0700214void pcibr_target_interrupt(struct sn_irq_info *sn_irq_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
216 struct pcidev_info *pcidev_info;
217 struct pcibus_info *pcibus_info;
218 int bit = sn_irq_info->irq_int_bit;
Prarit Bhargava53493dc2006-01-16 19:54:40 -0800219 u64 xtalk_addr = sn_irq_info->irq_xtalkaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
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 */
Mark Maule6fb93a92005-11-07 15:48:50 -0600228 pcireg_intr_enable_bit_clr(pcibus_info, (1 << bit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
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 */
Mark Maule6fb93a92005-11-07 15:48:50 -0600234 pcireg_intr_enable_bit_set(pcibus_info, (1 << bit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236 pcibr_force_interrupt(sn_irq_info);
237 }
238}
Mark Maulee955d822005-04-25 11:26:03 -0700239
240/*
241 * Provider entries for PIC/CP
242 */
243
244struct 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,
Mark Maule84096682005-08-25 11:45:00 -0700249 .force_interrupt = pcibr_force_interrupt,
250 .target_interrupt = pcibr_target_interrupt
Mark Maulee955d822005-04-25 11:26:03 -0700251};
252
253int
254pcibr_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}
Prarit Bhargava6f354b02005-07-06 15:29:53 -0700261
262EXPORT_SYMBOL_GPL(sal_pcibr_slot_enable);
263EXPORT_SYMBOL_GPL(sal_pcibr_slot_disable);
Prarit Bhargavaf90aa8c2006-03-08 13:30:18 -0500264EXPORT_SYMBOL_GPL(sn_ioboard_to_pci_bus);