irq.c 9.7 KB
Newer Older
1 2 3
/*
 * This module supports the iSeries PCI bus interrupt handling
 * Copyright (C) 20yy  <Robert L Holtorf> <IBM Corp>
4
 * Copyright (C) 2004-2005 IBM Corporation
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the:
 * Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * Change Activity:
 *   Created, December 13, 2000 by Wayne Holm
 * End Change Activity
 */
26
#include <linux/config.h>
L
Linus Torvalds 已提交
27 28 29 30 31 32 33 34 35 36 37
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/threads.h>
#include <linux/smp.h>
#include <linux/param.h>
#include <linux/string.h>
#include <linux/bootmem.h>
#include <linux/ide.h>
#include <linux/irq.h>
#include <linux/spinlock.h>

38
#include <asm/paca.h>
39
#include <asm/iseries/hv_types.h>
40
#include <asm/iseries/hv_lp_event.h>
41
#include <asm/iseries/hv_call_xm.h>
42
#include <asm/iseries/it_lp_queue.h>
43 44

#include "irq.h"
45
#include "call_pci.h"
L
Linus Torvalds 已提交
46

47 48 49 50
#if defined(CONFIG_SMP)
extern void iSeries_smp_message_recv(struct pt_regs *);
#endif

51 52
#ifdef CONFIG_PCI

53 54 55 56 57 58 59 60 61 62
enum pci_event_type {
	pe_bus_created		= 0,	/* PHB has been created */
	pe_bus_error		= 1,	/* PHB has failed */
	pe_bus_failed		= 2,	/* Msg to Secondary, Primary failed bus */
	pe_node_failed		= 4,	/* Multi-adapter bridge has failed */
	pe_node_recovered	= 5,	/* Multi-adapter bridge has recovered */
	pe_bus_recovered	= 12,	/* PHB has been recovered */
	pe_unquiese_bus		= 18,	/* Secondary bus unqiescing */
	pe_bridge_error		= 21,	/* Bridge Error */
	pe_slot_interrupt	= 22	/* Slot interrupt */
63 64
};

65 66
struct pci_event {
	struct HvLpEvent event;
67
	union {
68
		u64 __align;		/* Align on an 8-byte boundary */
69 70
		struct {
			u32		fisr;
71 72 73 74 75 76 77 78 79 80 81 82 83 84
			HvBusNumber	bus_number;
			HvSubBusNumber	sub_bus_number;
			HvAgentId	dev_id;
		} slot;
		struct {
			HvBusNumber	bus_number;
			HvSubBusNumber	sub_bus_number;
		} bus;
		struct {
			HvBusNumber	bus_number;
			HvSubBusNumber	sub_bus_number;
			HvAgentId	dev_id;
		} node;
	} data;
85 86
};

87 88 89 90
static DEFINE_SPINLOCK(pending_irqs_lock);
static int num_pending_irqs;
static int pending_irqs[NR_IRQS];

91
static void int_received(struct pci_event *event, struct pt_regs *regs)
92 93 94
{
	int irq;

95 96 97
	switch (event->event.xSubtype) {
	case pe_slot_interrupt:
		irq = event->event.xCorrelationToken;
98 99 100 101 102 103 104 105 106 107 108 109
		if (irq < NR_IRQS) {
			spin_lock(&pending_irqs_lock);
			pending_irqs[irq]++;
			num_pending_irqs++;
			spin_unlock(&pending_irqs_lock);
		} else {
			printk(KERN_WARNING "int_received: bad irq number %d\n",
					irq);
			HvCallPci_eoi(event->data.slot.bus_number,
					event->data.slot.sub_bus_number,
					event->data.slot.dev_id);
		}
110 111
		break;
		/* Ignore error recovery events for now */
112 113 114
	case pe_bus_created:
		printk(KERN_INFO "int_received: system bus %d created\n",
			event->data.bus.bus_number);
115
		break;
116 117 118 119
	case pe_bus_error:
	case pe_bus_failed:
		printk(KERN_INFO "int_received: system bus %d failed\n",
			event->data.bus.bus_number);
120
		break;
121 122 123 124
	case pe_bus_recovered:
	case pe_unquiese_bus:
		printk(KERN_INFO "int_received: system bus %d recovered\n",
			event->data.bus.bus_number);
125
		break;
126 127
	case pe_node_failed:
	case pe_bridge_error:
128
		printk(KERN_INFO
129 130 131 132
			"int_received: multi-adapter bridge %d/%d/%d failed\n",
			event->data.node.bus_number,
			event->data.node.sub_bus_number,
			event->data.node.dev_id);
133
		break;
134
	case pe_node_recovered:
135
		printk(KERN_INFO
136 137 138 139
			"int_received: multi-adapter bridge %d/%d/%d recovered\n",
			event->data.node.bus_number,
			event->data.node.sub_bus_number,
			event->data.node.dev_id);
140 141 142
		break;
	default:
		printk(KERN_ERR
143 144
			"int_received: unrecognized event subtype 0x%x\n",
			event->event.xSubtype);
145 146 147 148
		break;
	}
}

149
static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs)
150
{
151
	if (event && (event->xType == HvLpEvent_Type_PciIo)) {
152
		if (hvlpevent_is_int(event))
153
			int_received((struct pci_event *)event, regs);
154
		else
155
			printk(KERN_ERR
156 157
				"pci_event_handler: unexpected ack received\n");
	} else if (event)
158
		printk(KERN_ERR
159 160
			"pci_event_handler: Unrecognized PCI event type 0x%x\n",
			(int)event->xType);
161
	else
162
		printk(KERN_ERR "pci_event_handler: NULL event received\n");
163 164
}

165 166 167 168 169
/*
 * This is called by init_IRQ.  set in ppc_md.init_IRQ by iSeries_setup.c
 * It must be called before the bus walk.
 */
void __init iSeries_init_IRQ(void)
170
{
171
	/* Register PCI event handler and open an event path */
172 173 174 175 176 177 178 179 180
	int ret;

	ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
			&pci_event_handler);
	if (ret == 0) {
		ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
		if (ret != 0)
			printk(KERN_ERR "iseries_init_IRQ: open event path "
					"failed with rc 0x%x\n", ret);
181
	} else
182 183
		printk(KERN_ERR "iseries_init_IRQ: register handler "
				"failed with rc 0x%x\n", ret);
L
Linus Torvalds 已提交
184 185
}

186
#define REAL_IRQ_TO_SUBBUS(irq)	(((irq) >> 14) & 0xff)
187 188 189 190
#define REAL_IRQ_TO_BUS(irq)	((((irq) >> 6) & 0xff) + 1)
#define REAL_IRQ_TO_IDSEL(irq)	((((irq) >> 3) & 7) + 1)
#define REAL_IRQ_TO_FUNC(irq)	((irq) & 7)

L
Linus Torvalds 已提交
191
/*
192 193
 * This will be called by device drivers (via enable_IRQ)
 * to enable INTA in the bridge interrupt status register.
L
Linus Torvalds 已提交
194
 */
195
static void iseries_enable_IRQ(unsigned int irq)
L
Linus Torvalds 已提交
196
{
197 198
	u32 bus, dev_id, function, mask;
	const u32 sub_bus = 0;
199
	unsigned int rirq = virt_irq_to_real_map[irq];
L
Linus Torvalds 已提交
200

201 202 203
	/* The IRQ has already been locked by the caller */
	bus = REAL_IRQ_TO_BUS(rirq);
	function = REAL_IRQ_TO_FUNC(rirq);
204
	dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
L
Linus Torvalds 已提交
205

206 207
	/* Unmask secondary INTA */
	mask = 0x80000000;
208
	HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);
L
Linus Torvalds 已提交
209 210
}

211 212
/* This is called by iseries_activate_IRQs */
static unsigned int iseries_startup_IRQ(unsigned int irq)
L
Linus Torvalds 已提交
213
{
214 215
	u32 bus, dev_id, function, mask;
	const u32 sub_bus = 0;
L
Linus Torvalds 已提交
216 217 218 219
	unsigned int rirq = virt_irq_to_real_map[irq];

	bus = REAL_IRQ_TO_BUS(rirq);
	function = REAL_IRQ_TO_FUNC(rirq);
220
	dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
L
Linus Torvalds 已提交
221 222

	/* Link the IRQ number to the bridge */
223
	HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq);
L
Linus Torvalds 已提交
224 225 226

	/* Unmask bridge interrupts in the FISR */
	mask = 0x01010000 << function;
227 228
	HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);
	iseries_enable_IRQ(irq);
L
Linus Torvalds 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	return 0;
}

/*
 * This is called out of iSeries_fixup to activate interrupt
 * generation for usable slots
 */
void __init iSeries_activate_IRQs()
{
	int irq;
	unsigned long flags;

	for_each_irq (irq) {
		irq_desc_t *desc = get_irq_desc(irq);

		if (desc && desc->handler && desc->handler->startup) {
			spin_lock_irqsave(&desc->lock, flags);
			desc->handler->startup(irq);
			spin_unlock_irqrestore(&desc->lock, flags);
		}
249
	}
L
Linus Torvalds 已提交
250 251 252
}

/*  this is not called anywhere currently */
253
static void iseries_shutdown_IRQ(unsigned int irq)
L
Linus Torvalds 已提交
254
{
255 256
	u32 bus, dev_id, function, mask;
	const u32 sub_bus = 0;
L
Linus Torvalds 已提交
257 258 259 260 261
	unsigned int rirq = virt_irq_to_real_map[irq];

	/* irq should be locked by the caller */
	bus = REAL_IRQ_TO_BUS(rirq);
	function = REAL_IRQ_TO_FUNC(rirq);
262
	dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
L
Linus Torvalds 已提交
263 264

	/* Invalidate the IRQ number in the bridge */
265
	HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);
L
Linus Torvalds 已提交
266 267 268

	/* Mask bridge interrupts in the FISR */
	mask = 0x01010000 << function;
269
	HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);
L
Linus Torvalds 已提交
270 271 272 273 274 275
}

/*
 * This will be called by device drivers (via disable_IRQ)
 * to disable INTA in the bridge interrupt status register.
 */
276
static void iseries_disable_IRQ(unsigned int irq)
L
Linus Torvalds 已提交
277
{
278 279
	u32 bus, dev_id, function, mask;
	const u32 sub_bus = 0;
L
Linus Torvalds 已提交
280 281 282 283 284
	unsigned int rirq = virt_irq_to_real_map[irq];

	/* The IRQ has already been locked by the caller */
	bus = REAL_IRQ_TO_BUS(rirq);
	function = REAL_IRQ_TO_FUNC(rirq);
285
	dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
L
Linus Torvalds 已提交
286 287 288

	/* Mask secondary INTA   */
	mask = 0x80000000;
289
	HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);
L
Linus Torvalds 已提交
290 291
}

292
static void iseries_end_IRQ(unsigned int irq)
L
Linus Torvalds 已提交
293
{
294 295 296 297
	unsigned int rirq = virt_irq_to_real_map[irq];

	HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq),
		(REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq));
L
Linus Torvalds 已提交
298
}
299 300 301

static hw_irq_controller iSeries_IRQ_handler = {
	.typename = "iSeries irq controller",
302 303 304 305 306
	.startup = iseries_startup_IRQ,
	.shutdown = iseries_shutdown_IRQ,
	.enable = iseries_enable_IRQ,
	.disable = iseries_disable_IRQ,
	.end = iseries_end_IRQ
307 308 309 310 311
};

/*
 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
 * It calculates the irq value for the slot.
312
 * Note that sub_bus is always 0 (at the moment at least).
313
 */
314 315
int __init iSeries_allocate_IRQ(HvBusNumber bus,
		HvSubBusNumber sub_bus, HvAgentId dev_id)
316
{
317 318
	int virtirq;
	unsigned int realirq;
319 320
	u8 idsel = (dev_id >> 4);
	u8 function = dev_id & 7;
321

322 323
	realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)
		+ function;
324
	virtirq = virt_irq_create_mapping(realirq);
325 326 327 328

	irq_desc[virtirq].handler = &iSeries_IRQ_handler;
	return virtirq;
}
329

330 331
#endif /* CONFIG_PCI */

332 333 334 335 336 337
/*
 * Get the next pending IRQ.
 */
int iSeries_get_irq(struct pt_regs *regs)
{
	struct paca_struct *lpaca;
338 339
	/* -2 means ignore this interrupt */
	int irq = -2;
340 341 342 343 344 345 346 347 348 349 350

	lpaca = get_paca();
#ifdef CONFIG_SMP
	if (lpaca->lppaca.int_dword.fields.ipi_cnt) {
		lpaca->lppaca.int_dword.fields.ipi_cnt = 0;
		iSeries_smp_message_recv(regs);
	}
#endif /* CONFIG_SMP */
	if (hvlpevent_is_pending())
		process_hvlpevents(regs);

351
#ifdef CONFIG_PCI
352 353 354 355 356 357 358 359 360 361 362 363 364
	if (num_pending_irqs) {
		spin_lock(&pending_irqs_lock);
		for (irq = 0; irq < NR_IRQS; irq++) {
			if (pending_irqs[irq]) {
				pending_irqs[irq]--;
				num_pending_irqs--;
				break;
			}
		}
		spin_unlock(&pending_irqs_lock);
		if (irq >= NR_IRQS)
			irq = -2;
	}
365
#endif
366 367

	return irq;
368
}