summaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/sn1/irq.c
blob: b487f88d4583ef71323c4b77525a332d5278a861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * Platform dependent support for SGI SN1
 *
 * Copyright (C) 2000   Silicon Graphics
 * Copyright (C) 2000   Jack Steiner (steiner@sgi.com)
 * Copyright (C) 2000   Alan Mayer (ajm@sgi.com)
 */

#include <linux/config.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <asm/current.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <asm/sn/sgi.h>
#include <asm/sn/iograph.h>
#include <asm/sn/invent.h>
#include <linux/devfs_fs_kernel.h>
#include <asm/sn/hcl.h>
#include <asm/sn/types.h>
#include <asm/sn/pci/bridge.h>
#include <asm/sn/pci/pciio.h>
#include <asm/sn/pci/pciio_private.h>
#include <asm/sn/sn_cpuid.h>
#include <asm/sn/sn1/bedrock.h>
#include <asm/sn/intr.h>
#include <asm/sn/addrs.h>
#include <asm/sn/sn1/addrs.h>
#include <asm/sn/iobus.h>
#include <asm/sn/sn1/arch.h>
#include <asm/sn/synergy.h>


int bit_pos_to_irq(int bit);
int irq_to_bit_pos(int irq);
void add_interrupt_randomness(int irq);
void * kmalloc(size_t size, int flags);
void kfree(const void *);
int sgi_pci_intr_support (unsigned int, device_desc_t *, devfs_handle_t *, pciio_intr_line_t *, devfs_handle_t *);
pciio_intr_t pciio_intr_alloc(devfs_handle_t, device_desc_t, pciio_intr_line_t, devfs_handle_t);
int request_irq(unsigned int, void (*)(int, void *, struct pt_regs *), unsigned long, const char *, void *);

/* This should be dynamically allocated, at least part of it. */
/* For the time being, though, we'll statically allocate it */
/* because kmalloc hasn't been initiallized at the time this */
/* array is initiallized.  One way to do it would be to statically */
/* allocate the data for node 0, then let other nodes, as they */
/* need it, dynamically allocate their own data space. */

struct sn1_cnode_action_list *sn1_node_actions[MAX_COMPACT_NODES];
struct sn1_cnode_action_list sn1_actions[MAX_COMPACT_NODES][256];


extern int numnodes;

static unsigned int
sn1_startup_irq(unsigned int irq)
{
        return(0);
}

static void
sn1_shutdown_irq(unsigned int irq)
{
}

static void
sn1_disable_irq(unsigned int irq)
{
}

static void
sn1_enable_irq(unsigned int irq)
{
}

static void
sn1_ack_irq(unsigned int irq)
{
}

static void
sn1_end_irq(unsigned int irq)
{
}

static void
sn1_set_affinity_irq(unsigned int irq, unsigned long mask)
{
}


static void
sn1_handle_irq(int irq, void *dummy, struct pt_regs *regs)
{
	int bit, cnode;
	struct sn1_cnode_action_list *alp;
	struct sn1_intr_action *ap;
	void (*handler)(int, void *, struct pt_regs *);
	unsigned long flags = 0;
	int cpuid = smp_processor_id();


	bit = irq_to_bit_pos(irq);
	LOCAL_HUB_CLR_INTR(bit);
	cnode = cpuid_to_cnodeid(cpuid);
	alp = sn1_node_actions[cnode];
	ap = alp[irq].action_list;
	if (ap == NULL) {
		return;
	}
	while (ap) {
		flags |= ap->flags;
		handler = ap->handler;
		(*handler)(irq,ap->intr_arg,regs);
		ap = ap->next;
	}
	if ((flags & SA_SAMPLE_RANDOM) != 0)
                add_interrupt_randomness(irq);

        return;
}

struct hw_interrupt_type irq_type_sn1 = {
        "sn1_irq",
        sn1_startup_irq,
        sn1_shutdown_irq,
        sn1_enable_irq,
        sn1_disable_irq,
        sn1_ack_irq,
        sn1_end_irq,
        sn1_set_affinity_irq
};

struct irqaction sn1_irqaction = {
	sn1_handle_irq,
	0,
	0,
	NULL,
	NULL,
	NULL,
};

void
sn1_irq_init (void)
{
	int i,j;

	for (i = 0; i <= NR_IRQS; ++i) {
		if (irq_desc[i].handler == &no_irq_type) {
			irq_desc[i].handler = &irq_type_sn1;
			if (i >=71 && i <= 181) {
				irq_desc[i].action = &sn1_irqaction;
			}
		}
	}

	for (i = 0; i < numnodes; i++) {
		sn1_node_actions[i] = sn1_actions[i];
		memset(sn1_node_actions[i], 0,
			sizeof(struct sn1_cnode_action_list) *
			(IA64_MAX_VECTORED_IRQ + 1));
		for (j=0; j<IA64_MAX_VECTORED_IRQ+1; j++) {
			spin_lock_init(&sn1_node_actions[i][j].action_list_lock);
		}
	}
}


int          
sn1_request_irq (unsigned int requested_irq, void (*handler)(int, void *, struct pt_regs *),
             unsigned long irqflags, const char * devname, void *dev_id)
{ 
	devfs_handle_t curr_dev;
	devfs_handle_t dev;
	pciio_intr_t intr_handle;
	pciio_intr_line_t line;
	device_desc_t dev_desc;
        int cpuid, bit, cnode;
	struct sn1_intr_action *ap, *new_ap;
	struct sn1_cnode_action_list *alp;
	int irq;

	if ( (requested_irq & 0xff) == 0 ) {
		int ret;

		sgi_pci_intr_support(requested_irq,
			&dev_desc, &dev, &line, &curr_dev);
		intr_handle = pciio_intr_alloc(curr_dev, NULL, line, curr_dev);
		bit = intr_handle->pi_irq;
		cpuid = intr_handle->pi_cpu;
		irq = bit_pos_to_irq(bit);
		cnode = cpuid_to_cnodeid(cpuid);
		new_ap = (struct sn1_intr_action *)kmalloc(
			sizeof(struct sn1_intr_action), GFP_KERNEL);
		irq_desc[irq].status = 0;
		new_ap->handler = handler;
		new_ap->intr_arg = dev_id;
		new_ap->flags = irqflags;
		new_ap->next = NULL;
		alp = sn1_node_actions[cnode];

		spin_lock(&alp[irq].action_list_lock);
		ap = alp[irq].action_list;
		/* check action list for "share" consistency */
		while (ap){
			if (!(ap->flags & irqflags & SA_SHIRQ) ) {
				return(-EBUSY);
				spin_unlock(&alp[irq].action_list_lock);
			}
			ap = ap->next;
		}
		ap = alp[irq].action_list;
		if (ap) {
			while (ap->next) {
				ap = ap->next;
			}
			ap->next = new_ap;
		} else {
			alp[irq].action_list = new_ap;
		}
		ret = pciio_intr_connect(intr_handle, (intr_func_t)handler, dev_id, NULL);
		if (ret) { /* connect failed, undo what we did. */
			new_ap = alp[irq].action_list;
			if (new_ap == ap) {
				alp[irq].action_list = NULL;
				kfree(ap);
			} else {
				while (new_ap->next && new_ap->next != ap) {
					new_ap = new_ap->next;
				}
				if (new_ap->next == ap) {
					new_ap->next = ap->next;
					kfree(ap);
				}
			}
		}
			
		spin_unlock(&alp[irq].action_list_lock);
		return(ret);
	} else {
		return(request_irq(requested_irq, handler, irqflags, devname, dev_id));
	}
}

#if !defined(CONFIG_IA64_SGI_IO)
void
sn1_pci_fixup(int arg)
{
}
#endif

int
bit_pos_to_irq(int bit) {
#define BIT_TO_IRQ 64

        return bit + BIT_TO_IRQ;
}

int
irq_to_bit_pos(int irq) {
#define IRQ_TO_BIT 64

        return irq - IRQ_TO_BIT;
}