/lib/lufa/Demos/Device/ClassDriver/Mouse/Config/

s-git' href='ssh://git@git.panaceas.org/git/xen/xen' title='xen/xen Git repository'/>
aboutsummaryrefslogtreecommitdiffstats
path: root/xen/arch/powerpc/external.c
blob: 135f808fdca1d7e4cff0cfb4c5fefd8bed386218 (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/*
 * 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, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright (C) IBM Corp. 2005, 2006
 *
 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
 */

#include <xen/config.h>
#include <xen/types.h>
#include <xen/sched.h>
#include <xen/lib.h>
#include <xen/event.h>
#include <xen/irq.h>
#include <public/xen.h>
#include <asm/current.h>
#include <asm/hardirq.h>
#include <asm/mpic.h>
#include "mpic_init.h"
#include "exceptions.h"

#undef DEBUG
#ifdef DEBUG
#define DBG(fmt...) printk(fmt)
#else
#define DBG(fmt...)
#endif

int vector_irq[NR_VECTORS] __read_mostly = { [0 ... NR_VECTORS - 1] = -1};

unsigned long io_apic_irqs;
int ioapic_ack_new = 1;

static struct hw_interrupt_type *hc_irq;

/* deliver_ee: called with interrupts off when resuming every vcpu */
void deliver_ee(struct cpu_user_regs *regs)
{
    const ulong srr_mask = ~(MSR_IR | MSR_DR | MSR_FE0 | MSR_FE1 | MSR_EE |
                             MSR_RI |
                             MSR_BE | MSR_FP | MSR_PMM | MSR_PR | MSR_SE);

    BUG_ON(mfmsr() & MSR_EE);
    BUG_ON(regs->msr & MSR_HV);

    if (!local_events_need_delivery())
        return;

    /* XXX OS error: EE was set but RI was not. We could trigger a machine
     * check, or kill the domain... for now just crash Xen so we notice. */
    BUG_ON(!(regs->msr & MSR_RI));

    regs->srr0 = regs->pc;
    /* zero SRR1[33:36] and SRR1[42:47] */
    regs->srr1 = regs->msr & ~0x00000000783f0000;
    regs->pc = 0x500;
    regs->msr &= srr_mask;
    regs->msr |= MSR_SF | MSR_ME;

    DBG("<HV: pc=0x%lx, msr=0x%lx\n", regs->pc, regs->msr);
}

void do_external(struct cpu_user_regs *regs)
{
    int vec;
    static unsigned spur_count;

    BUG_ON(!(regs->msr & MSR_EE));
    BUG_ON(mfmsr() & MSR_EE);

    vec = xen_mpic_get_irq(regs);

    if (irq_desc[vec].status & IRQ_PER_CPU) {
        /* x86 do_IRQ does not respect the per cpu flag.  */
        irq_desc_t *desc = &irq_desc[vec];
        regs->entry_vector = vec;
        desc->handler->ack(vec);
        desc->action->handler(vector_to_irq(vec), desc->action->dev_id, regs);
        desc->handler->end(vec);
    } else if (vec != -1) {
        DBG("EE:0x%lx isrc: %d\n", regs->msr, vec);
        regs->entry_vector = vec;
        do_IRQ(regs);

        BUG_ON(mfmsr() & MSR_EE);
        spur_count = 0;
    } else {
        ++spur_count;
        if (spur_count > 100)
            panic("Too many (%d) spurrious interrupts in a row\n"
                  "  Known problem, please halt and let machine idle/cool "
                  "  then reboot\n",
                  100);
    }
}

static int xen_local_irq(unsigned int irq)
{
    irq_desc_t *desc;
    unsigned int vector;

    vector = irq_to_vector(irq);
    desc = &irq_desc[vector];

    return !(desc->status & IRQ_GUEST);
}

static unsigned int xen_startup_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        return hc_irq->startup(irq);
    }
    return 0;
}

static void xen_shutdown_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        hc_irq->shutdown(irq);
    }
}

static void xen_enable_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        hc_irq->enable(irq);
    }
}

static void xen_disable_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        hc_irq->disable(irq);
    }
}
    
static void xen_ack_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        if (hc_irq->ack) hc_irq->ack(irq);
    }
}

static void xen_end_irq(unsigned int irq)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        hc_irq->end(irq);
    }
}

static void xen_set_affinity(unsigned int irq, cpumask_t mask)
{
    DBG("%s(%d)\n", __func__, irq);
    if (xen_local_irq(irq)) {
        if (hc_irq->set_affinity) hc_irq->set_affinity(irq, mask);
    }
}

static struct hw_interrupt_type xen_irq = {
    .startup = xen_startup_irq,
    .enable = xen_enable_irq,
    .disable = xen_disable_irq,
    .shutdown = xen_shutdown_irq,
    .ack = xen_ack_irq,
    .end = xen_end_irq,
    .set_affinity = xen_set_affinity,
};

void init_IRQ(void)
{
    hc_irq = xen_mpic_init(&xen_irq);
}

void ack_APIC_irq(void)
{
    panic("%s: EOI the whole MPIC?\n", __func__);
}

void ack_bad_irq(unsigned int irq)
{
    printk("unexpected IRQ trap at vector %02x\n", irq);
    /*
     * Currently unexpected vectors happen only on SMP and APIC.
     * We _must_ ack these because every local APIC has only N
     * irq slots per priority level, and a 'hanging, unacked' IRQ
     * holds up an irq slot - in excessive cases (when multiple
     * unexpected vectors occur) that might lock up the APIC
     * completely.
     */
    ack_APIC_irq();
}

extern void dump_ioapic_irq_info(void);
void dump_ioapic_irq_info(void)
{
    printk("%s: can't dump yet\n", __func__);
}

/* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
u8 irq_vector[NR_IRQ_VECTORS] __read_mostly = { FIRST_DEVICE_VECTOR , 0 };
int assign_irq_vector(int irq)
{
    static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;

    BUG_ON(irq >= NR_IRQ_VECTORS);
    if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0)
        return IO_APIC_VECTOR(irq);
next:
    current_vector += 8;

    /* Skip the hypercall vector. */
    if (current_vector == HYPERCALL_VECTOR)
        goto next;

    /* Skip the Linux/BSD fast-trap vector. */
    if (current_vector == FAST_TRAP)
        goto next;

    if (current_vector >= FIRST_SYSTEM_VECTOR) {
        offset++;
        if (!(offset%8))
            return -ENOSPC;
        current_vector = FIRST_DEVICE_VECTOR + offset;
    }

    vector_irq[current_vector] = irq;
    if (irq != AUTO_ASSIGN)
        IO_APIC_VECTOR(irq) = current_vector;

    return current_vector;
}

int ioapic_guest_read(unsigned long physbase, unsigned int reg, u32 *pval)
{
    BUG_ON(pval != pval);

    return 0;
}

int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
{
    BUG_ON(val != val);
    return 0;
}

void send_IPI_mask(cpumask_t mask, int vector)
{
    unsigned int cpus;
    int const bits = 8 * sizeof(cpus);

    switch(vector) {
    case CALL_FUNCTION_VECTOR:
    case EVENT_CHECK_VECTOR:
        break;
    default:
        BUG();
        return;
    }

    BUG_ON(NR_CPUS > bits);
    BUG_ON(fls(mask.bits[0]) > bits);

    cpus = mask.bits[0];
    mpic_send_ipi(vector, cpus);
}