Subversion Repositories HelenOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4638 rimsky 1
/*
2
 * Copyright (c) 2009 Pavel Rimsky
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup sparc64interrupt
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
#include <arch/interrupt.h>
36
#include <arch/trap/interrupt.h>
37
#include <arch/sparc64.h>
38
#include <arch/trap/interrupt.h>
39
#include <interrupt.h>
40
#include <ddi/irq.h>
41
#include <arch/types.h>
42
#include <debug.h>
43
#include <arch/asm.h>
44
#include <arch/barrier.h>
45
#include <print.h>
46
#include <arch.h>
47
#include <mm/tlb.h>
48
#include <config.h>
49
#include <synch/spinlock.h>
50
#include <arch/sun4v/hypercall.h>
51
 
52
/** number of uint64_t-s in one CPU mondo message */
53
#define CPU_MONDO_ENTRY_SIZE    8
54
 
55
/** number of entries (messages) in the CPU mondo queue */
56
#define CPU_MONDO_NENTRIES  8
57
 
58
/** number of uint64_t-s in the CPU mondo queue */
59
#define CPU_MONDO_QUEUE_SIZE    ((CPU_MONDO_NENTRIES) * (CPU_MONDO_ENTRY_SIZE))
60
 
61
/** used to identify CPU mondo queue in the hypercall */
62
#define CPU_MONDO_QUEUE_ID  0x3c
63
 
64
/** ASI for reading/writing CPU mondo head/tail registers */
65
#define ASI_QUEUE       0x25
66
 
67
/** VA for reading the CPU mondo tail */
68
#define VA_CPU_MONDO_QUEUE_TAIL 0x3c8
69
 
70
/** VA for reading/writing the CPU mondo head */
71
#define VA_CPU_MONDO_QUEUE_HEAD 0x3c0
72
 
73
/**
74
 * array which contains CPU mondo queue for every CPU
75
 */
76
uint64_t cpu_mondo_queues[MAX_NUM_STRANDS][CPU_MONDO_QUEUE_SIZE]
77
    __attribute__((aligned(
78
    CPU_MONDO_QUEUE_SIZE * sizeof(uint64_t))));
79
 
80
/**
81
 * Initializes CPU mondo queue for the current CPU.
82
 */
83
void sun4v_ipi_init(void)
84
{
85
    if (__hypercall_fast3(
86
        CPU_QCONF,
87
        CPU_MONDO_QUEUE_ID,
88
        KA2PA(cpu_mondo_queues[CPU->id]),
89
        CPU_MONDO_NENTRIES) != EOK)
90
            panic("Initializing mondo queue failed on CPU %d.\n",
91
            CPU->arch.id);
92
}
93
 
94
/**
95
 * Handler of the CPU Mondo trap. Reads the message queue, updates the head
96
 * register and processes the message (invokes a function call).
97
 */
98
void cpu_mondo(void)
99
{
100
    unsigned int tail = asi_u64_read(ASI_QUEUE, VA_CPU_MONDO_QUEUE_TAIL);
101
    unsigned int head = asi_u64_read(ASI_QUEUE, VA_CPU_MONDO_QUEUE_HEAD);
102
 
103
    while (head != tail) {
104
 
105
        uint64_t data1 = cpu_mondo_queues[CPU->id][0];
106
 
107
        head = (head + CPU_MONDO_ENTRY_SIZE * sizeof(uint64_t)) %
108
            (CPU_MONDO_QUEUE_SIZE * sizeof(uint64_t));
109
        asi_u64_write(ASI_QUEUE, VA_CPU_MONDO_QUEUE_HEAD, head);
110
 
111
        if (data1 == (uint64_t) tlb_shootdown_ipi_recv) {
112
            ((void (*)(void)) data1)();
113
        } else {
114
            printf("Spurious interrupt on %d, data = %lx.\n",
115
                CPU->arch.id, data1);
116
        }
117
 
118
    }
119
 
120
}
121
 
122
/** @}
123
 */