Subversion Repositories HelenOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4638 rimsky 1
/*
2
 * Copyright (c) 2006 Jakub Jermar
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 sparc64
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
#include <smp/ipi.h>
36
#include <cpu.h>
37
#include <config.h>
38
#include <interrupt.h>
39
#include <arch/asm.h>
40
#include <arch/cpu.h>
41
#include <arch/sun4v/hypercall.h>
42
#include <arch/sun4v/ipi.h>
43
 
44
#define IPI_MESSAGE_SIZE    8
45
 
46
static uint64_t data[MAX_NUM_STRANDS][IPI_MESSAGE_SIZE]
47
    __attribute__ ((aligned (64)));
48
 
49
static uint16_t ipi_cpu_list[MAX_NUM_STRANDS][MAX_NUM_STRANDS];
50
 
51
/**
52
 * Sends an inter-processor interrupt to all virtual processors whose IDs are
53
 * listed in the list.
54
 *
55
 * @param func      address of the function to be invoked on the recipient
56
 * @param cpu_list  list of CPU IDs (16-bit identifiers) of the recipients
57
 * @param list_size number of recipients (number of valid cpu_list entries)
58
 *
59
 * @return      error code returned by the CPU_MONDO_SEND hypercall
60
 */
61
uint64_t ipi_brodcast_to(void (*func)(void), uint16_t cpu_list[MAX_NUM_STRANDS],
62
        uint64_t list_size) {
63
 
64
    data[CPU->arch.id][0] = (uint64_t) func;
65
 
66
    unsigned int i;
67
    for (i = 0; i < list_size; i++) {
68
        ipi_cpu_list[CPU->arch.id][i] = cpu_list[i];
69
    }
70
 
71
    return __hypercall_fast3(CPU_MONDO_SEND, list_size,
72
        KA2PA(ipi_cpu_list[CPU->arch.id]), KA2PA(data[CPU->arch.id]));
73
}
74
 
75
/**
76
 * Send an inter-processor interrupt to a particular CPU.
77
 *
78
 * @param func      address of the function to be invoked on the recipient
79
 * @param cpu_is    CPU ID (16-bit identifier) of the recipient
80
 *
81
 * @return      error code returned by the CPU_MONDO_SEND hypercall
82
 */
83
uint64_t ipi_unicast_to(void (*func)(void), uint16_t cpu_id) {
84
    ipi_cpu_list[CPU->arch.id][0] = cpu_id;
85
    return ipi_brodcast_to(func, ipi_cpu_list[CPU->arch.id], 1);
86
}
87
 
88
/*
89
 * Deliver IPI to all processors except the current one.
90
 *
91
 * We assume that interrupts are disabled.
92
 *
93
 * @param ipi IPI number.
94
 */
95
void ipi_broadcast_arch(int ipi)
96
{
97
    void (* func)(void);
98
 
99
    switch (ipi) {
100
    case IPI_TLB_SHOOTDOWN:
101
        func = tlb_shootdown_ipi_recv;
102
        break;
103
    default:
104
        panic("Unknown IPI (%d).\n", ipi);
105
        break;
106
    }
107
 
108
    unsigned int i;
109
    unsigned idx = 0;
110
    for (i = 0; i < config.cpu_active; i++) {
111
        if (&cpus[i] == CPU) {
112
            continue;
113
        }
114
 
115
        ipi_cpu_list[CPU->id][idx] = (uint16_t) cpus[i].id;
116
        idx++;
117
    }
118
 
119
    ipi_brodcast_to(func, ipi_cpu_list[CPU->arch.id], idx);
120
}
121
 
122
/** @}
123
 */