pcibr_provider.c 6.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
J
John Keller 已提交
6
 * Copyright (C) 2001-2004, 2006 Silicon Graphics, Inc. All rights reserved.
L
Linus Torvalds 已提交
7 8 9
 */

#include <linux/interrupt.h>
10
#include <linux/types.h>
11
#include <linux/slab.h>
L
Linus Torvalds 已提交
12
#include <linux/pci.h>
13
#include <linux/export.h>
14
#include <asm/sn/addrs.h>
L
Linus Torvalds 已提交
15
#include <asm/sn/geo.h>
16
#include <asm/sn/pcibr_provider.h>
17 18
#include <asm/sn/pcibus_provider_defs.h>
#include <asm/sn/pcidev.h>
19
#include <asm/sn/sn_sal.h>
20
#include <asm/sn/pic.h>
21
#include <asm/sn/sn2/sn_hwperf.h>
22 23
#include "xtalk/xwidgetdev.h"
#include "xtalk/hubdev.h"
L
Linus Torvalds 已提交
24

25
int
26 27
sal_pcibr_slot_enable(struct pcibus_info *soft, int device, void *resp,
                      char **ssdt)
28 29
{
	struct ia64_sal_retval ret_stuff;
30
	u64 busnum;
31
	u64 segment;
32 33 34 35

	ret_stuff.status = 0;
	ret_stuff.v0 = 0;

36
	segment = soft->pbi_buscommon.bs_persist_segment;
37
	busnum = soft->pbi_buscommon.bs_persist_busnum;
38
	SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_ENABLE, segment,
39 40
			busnum, (u64) device, (u64) resp, (u64)ia64_tpa(ssdt),
			0, 0);
41 42 43 44 45 46 47 48 49

	return (int)ret_stuff.v0;
}

int
sal_pcibr_slot_disable(struct pcibus_info *soft, int device, int action,
		       void *resp)
{
	struct ia64_sal_retval ret_stuff;
50
	u64 busnum;
51
	u64 segment;
52 53 54 55

	ret_stuff.status = 0;
	ret_stuff.v0 = 0;

56
	segment = soft->pbi_buscommon.bs_persist_segment;
57 58
	busnum = soft->pbi_buscommon.bs_persist_busnum;
	SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_SLOT_DISABLE,
59 60
			segment, busnum, (u64) device, (u64) action,
			(u64) resp, 0, 0);
61 62 63 64

	return (int)ret_stuff.v0;
}

L
Linus Torvalds 已提交
65 66 67
static int sal_pcibr_error_interrupt(struct pcibus_info *soft)
{
	struct ia64_sal_retval ret_stuff;
68
	u64 busnum;
L
Linus Torvalds 已提交
69 70 71 72
	int segment;
	ret_stuff.status = 0;
	ret_stuff.v0 = 0;

73
	segment = soft->pbi_buscommon.bs_persist_segment;
L
Linus Torvalds 已提交
74 75 76 77 78 79 80 81
	busnum = soft->pbi_buscommon.bs_persist_busnum;
	SAL_CALL_NOLOCK(ret_stuff,
			(u64) SN_SAL_IOIF_ERROR_INTERRUPT,
			(u64) segment, (u64) busnum, 0, 0, 0, 0, 0);

	return (int)ret_stuff.v0;
}

82 83
u16 sn_ioboard_to_pci_bus(struct pci_bus *pci_bus)
{
84
	long rc;
85
	u16 uninitialized_var(ioboard);		/* GCC be quiet */
86 87 88 89 90 91 92 93 94 95 96 97
	nasid_t nasid = NASID_GET(SN_PCIBUS_BUSSOFT(pci_bus)->bs_base);

	rc = ia64_sn_sysctl_ioboard_get(nasid, &ioboard);
	if (rc) {
		printk(KERN_WARNING "ia64_sn_sysctl_ioboard_get failed: %ld\n",
		       rc);
		return 0;
	}

	return ioboard;
}

L
Linus Torvalds 已提交
98 99 100 101 102
/* 
 * PCI Bridge Error interrupt handler.  Gets invoked whenever a PCI 
 * bridge sends an error interrupt.
 */
static irqreturn_t
A
Al Viro 已提交
103
pcibr_error_intr_handler(int irq, void *arg)
L
Linus Torvalds 已提交
104
{
105
	struct pcibus_info *soft = arg;
L
Linus Torvalds 已提交
106

107
	if (sal_pcibr_error_interrupt(soft) < 0)
L
Linus Torvalds 已提交
108
		panic("pcibr_error_intr_handler(): Fatal Bridge Error");
109

L
Linus Torvalds 已提交
110 111 112 113
	return IRQ_HANDLED;
}

void *
114
pcibr_bus_fixup(struct pcibus_bussoft *prom_bussoft, struct pci_controller *controller)
L
Linus Torvalds 已提交
115 116 117 118
{
	int nasid, cnode, j;
	struct hubdev_info *hubdev_info;
	struct pcibus_info *soft;
119 120
	struct sn_flush_device_kernel *sn_flush_device_kernel;
	struct sn_flush_device_common *common;
L
Linus Torvalds 已提交
121 122 123 124 125 126 127 128 129

	if (! IS_PCI_BRIDGE_ASIC(prom_bussoft->bs_asic_type)) {
		return NULL;
	}

	/*
	 * Allocate kernel bus soft and copy from prom.
	 */

130
	soft = kmemdup(prom_bussoft, sizeof(struct pcibus_info), GFP_KERNEL);
L
Linus Torvalds 已提交
131 132 133 134
	if (!soft) {
		return NULL;
	}

135 136 137
	soft->pbi_buscommon.bs_base = (unsigned long)
		ioremap(REGION_OFFSET(soft->pbi_buscommon.bs_base),
			sizeof(struct pic));
L
Linus Torvalds 已提交
138 139 140 141 142 143

	spin_lock_init(&soft->pbi_lock);

	/*
	 * register the bridge's error interrupt handler
	 */
A
Al Viro 已提交
144
	if (request_irq(SGI_PCIASIC_ERROR, pcibr_error_intr_handler,
145
			IRQF_SHARED, "PCIBR error", (void *)(soft))) {
L
Linus Torvalds 已提交
146 147 148
		printk(KERN_WARNING
		       "pcibr cannot allocate interrupt for error handler\n");
	}
149
	sn_set_err_irq_affinity(SGI_PCIASIC_ERROR);
L
Linus Torvalds 已提交
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

	/* 
	 * Update the Bridge with the "kernel" pagesize 
	 */
	if (PAGE_SIZE < 16384) {
		pcireg_control_bit_clr(soft, PCIBR_CTRL_PAGE_SIZE);
	} else {
		pcireg_control_bit_set(soft, PCIBR_CTRL_PAGE_SIZE);
	}

	nasid = NASID_GET(soft->pbi_buscommon.bs_base);
	cnode = nasid_to_cnodeid(nasid);
	hubdev_info = (struct hubdev_info *)(NODEPDA(cnode)->pdinfo);

	if (hubdev_info->hdi_flush_nasid_list.widget_p) {
165
		sn_flush_device_kernel = hubdev_info->hdi_flush_nasid_list.
L
Linus Torvalds 已提交
166
		    widget_p[(int)soft->pbi_buscommon.bs_xid];
167
		if (sn_flush_device_kernel) {
L
Linus Torvalds 已提交
168
			for (j = 0; j < DEV_PER_WIDGET;
169 170 171
			     j++, sn_flush_device_kernel++) {
				common = sn_flush_device_kernel->common;
				if (common->sfdl_slot == -1)
L
Linus Torvalds 已提交
172
					continue;
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 =
L
Linus Torvalds 已提交
178 179 180 181 182 183 184 185
					    soft;
			}
		}
	}

	/* Setup the PMU ATE map */
	soft->pbi_int_ate_resource.lowest_free_index = 0;
	soft->pbi_int_ate_resource.ate =
186 187 188 189 190 191
	    kzalloc(soft->pbi_int_ate_size * sizeof(u64), GFP_KERNEL);

	if (!soft->pbi_int_ate_resource.ate) {
		kfree(soft);
		return NULL;
	}
L
Linus Torvalds 已提交
192 193 194 195 196 197 198 199 200 201

	return soft;
}

void pcibr_force_interrupt(struct sn_irq_info *sn_irq_info)
{
	struct pcidev_info *pcidev_info;
	struct pcibus_info *pcibus_info;
	int bit = sn_irq_info->irq_int_bit;

202 203 204
	if (! sn_irq_info->irq_bridge)
		return;

L
Linus Torvalds 已提交
205 206 207 208 209 210 211 212 213
	pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
	if (pcidev_info) {
		pcibus_info =
		    (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
		    pdi_pcibus_info;
		pcireg_force_intr_set(pcibus_info, bit);
	}
}

214
void pcibr_target_interrupt(struct sn_irq_info *sn_irq_info)
L
Linus Torvalds 已提交
215 216 217 218
{
	struct pcidev_info *pcidev_info;
	struct pcibus_info *pcibus_info;
	int bit = sn_irq_info->irq_int_bit;
219
	u64 xtalk_addr = sn_irq_info->irq_xtalkaddr;
L
Linus Torvalds 已提交
220 221 222 223 224 225 226 227

	pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo;
	if (pcidev_info) {
		pcibus_info =
		    (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info->
		    pdi_pcibus_info;

		/* Disable the device's IRQ   */
228
		pcireg_intr_enable_bit_clr(pcibus_info, (1 << bit));
L
Linus Torvalds 已提交
229 230 231 232 233

		/* Change the device's IRQ    */
		pcireg_intr_addr_addr_set(pcibus_info, bit, xtalk_addr);

		/* Re-enable the device's IRQ */
234
		pcireg_intr_enable_bit_set(pcibus_info, (1 << bit));
L
Linus Torvalds 已提交
235 236 237 238

		pcibr_force_interrupt(sn_irq_info);
	}
}
239 240 241 242 243 244 245 246 247 248

/*
 * Provider entries for PIC/CP
 */

struct sn_pcibus_provider pcibr_provider = {
	.dma_map = pcibr_dma_map,
	.dma_map_consistent = pcibr_dma_map_consistent,
	.dma_unmap = pcibr_dma_unmap,
	.bus_fixup = pcibr_bus_fixup,
249 250
	.force_interrupt = pcibr_force_interrupt,
	.target_interrupt = pcibr_target_interrupt
251 252 253 254 255 256 257 258 259 260
};

int
pcibr_init_provider(void)
{
	sn_pci_provider[PCIIO_ASIC_TYPE_PIC] = &pcibr_provider;
	sn_pci_provider[PCIIO_ASIC_TYPE_TIOCP] = &pcibr_provider;

	return 0;
}
261 262 263

EXPORT_SYMBOL_GPL(sal_pcibr_slot_enable);
EXPORT_SYMBOL_GPL(sal_pcibr_slot_disable);
264
EXPORT_SYMBOL_GPL(sn_ioboard_to_pci_bus);