Subversion Repositories HelenOS

Rev

Rev 4344 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4344 Rev 4346
1
/*
1
/*
2
 * Copyright (c) 2005 Jakub Vana
2
 * Copyright (c) 2005 Jakub Vana
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
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
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.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
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
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
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.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup ia64
29
/** @addtogroup ia64
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch.h>
35
#include <arch.h>
36
#include <arch/ski/ski.h>
36
#include <arch/ski/ski.h>
37
#include <arch/drivers/it.h>
37
#include <arch/drivers/it.h>
38
#include <arch/interrupt.h>
38
#include <arch/interrupt.h>
39
#include <arch/barrier.h>
39
#include <arch/barrier.h>
40
#include <arch/asm.h>
40
#include <arch/asm.h>
41
#include <arch/register.h>
41
#include <arch/register.h>
42
#include <arch/types.h>
42
#include <arch/types.h>
43
#include <arch/context.h>
43
#include <arch/context.h>
44
#include <arch/stack.h>
44
#include <arch/stack.h>
45
#include <arch/mm/page.h>
45
#include <arch/mm/page.h>
46
#include <mm/as.h>
46
#include <mm/as.h>
47
#include <config.h>
47
#include <config.h>
48
#include <userspace.h>
48
#include <userspace.h>
49
#include <console/console.h>
49
#include <console/console.h>
50
#include <proc/uarg.h>
50
#include <proc/uarg.h>
51
#include <syscall/syscall.h>
51
#include <syscall/syscall.h>
52
#include <ddi/irq.h>
52
#include <ddi/irq.h>
53
#include <ddi/device.h>
53
#include <ddi/device.h>
54
#include <arch/bootinfo.h>
54
#include <arch/bootinfo.h>
55
#include <genarch/kbd/i8042.h>
-
 
56
#include <genarch/kbd/ns16550.h>
-
 
57
#include <smp/smp.h>
55
#include <smp/smp.h>
58
#include <smp/ipi.h>
56
#include <smp/ipi.h>
59
#include <arch/atomic.h>
57
#include <arch/atomic.h>
60
#include <panic.h>
58
#include <panic.h>
61
#include <print.h>
59
#include <print.h>
62
 
60
 
63
#ifdef CONFIG_SMP
61
#ifdef CONFIG_SMP
64
 
62
 
65
extern char cpu_by_id_eid_list[256][256];
63
extern char cpu_by_id_eid_list[256][256];
66
 
64
 
67
static void sapic_init(void)
65
static void sapic_init(void)
68
{
66
{
69
    bootinfo->sapic = (unative_t *)(PA2KA((unative_t)(bootinfo->sapic)) |
67
    bootinfo->sapic = (unative_t *)(PA2KA((unative_t)(bootinfo->sapic)) |
70
        FW_OFFSET);
68
        FW_OFFSET);
71
}
69
}
72
 
70
 
73
static void ipi_broadcast_arch_all(int ipi)
71
static void ipi_broadcast_arch_all(int ipi)
74
{
72
{
75
    int id, eid;
73
    int id, eid;
76
    int myid, myeid;
74
    int myid, myeid;
77
   
75
   
78
    myid = ia64_get_cpu_id();
76
    myid = ia64_get_cpu_id();
79
    myeid = ia64_get_cpu_eid();
77
    myeid = ia64_get_cpu_eid();
80
   
78
   
81
    for (id = 0; id < 256; id++)
79
    for (id = 0; id < 256; id++)
82
        for (eid = 0; eid < 256; eid++)
80
        for (eid = 0; eid < 256; eid++)
83
            if ((id != myid) || (eid != myeid))
81
            if ((id != myid) || (eid != myeid))
84
                ipi_send_ipi(id, eid, ipi);
82
                ipi_send_ipi(id, eid, ipi);
85
}
83
}
86
 
84
 
87
void ipi_broadcast_arch(int ipi )
85
void ipi_broadcast_arch(int ipi )
88
{
86
{
89
    int id, eid;
87
    int id, eid;
90
    int myid, myeid;
88
    int myid, myeid;
91
   
89
   
92
    myid = ia64_get_cpu_id();
90
    myid = ia64_get_cpu_id();
93
    myeid = ia64_get_cpu_eid();
91
    myeid = ia64_get_cpu_eid();
94
 
92
 
95
    for (id = 0; id < 256; id++)
93
    for (id = 0; id < 256; id++)
96
        for (eid = 0; eid < 256; eid++)
94
        for (eid = 0; eid < 256; eid++)
97
            if ((id != myid) || (eid != myeid))
95
            if ((id != myid) || (eid != myeid))
98
                if (cpu_by_id_eid_list[id][eid])
96
                if (cpu_by_id_eid_list[id][eid])
99
                    ipi_send_ipi(id, eid, ipi);
97
                    ipi_send_ipi(id, eid, ipi);
100
}
98
}
101
 
99
 
102
void smp_init(void)
100
void smp_init(void)
103
{
101
{
104
    if (!bootinfo->hello_configured)
102
    if (!bootinfo->hello_configured)
105
        return;
103
        return;
106
   
104
   
107
    /*
105
    /*
108
     * If we have not got system prepared by hello, we are not able to start
106
     * If we have not got system prepared by hello, we are not able to start
109
     * AP's. This means we are running on a simulator.
107
     * AP's. This means we are running on a simulator.
110
     */
108
     */
111
   
109
   
112
    sapic_init();
110
    sapic_init();
113
    ipi_broadcast_arch_all(bootinfo->wakeup_intno);
111
    ipi_broadcast_arch_all(bootinfo->wakeup_intno);
114
    volatile long long brk;
112
    volatile long long brk;
115
        for (brk = 0; brk < 100LL * 1024LL * 1024LL; brk++)
113
        for (brk = 0; brk < 100LL * 1024LL * 1024LL; brk++)
116
        ;   /* wait a while before CPUs starts */
114
        ;   /* wait a while before CPUs starts */
117
 
115
 
118
    config.cpu_count = 0;
116
    config.cpu_count = 0;
119
    int id, eid;
117
    int id, eid;
120
   
118
   
121
    for (id = 0; id < 256; id++)
119
    for (id = 0; id < 256; id++)
122
        for (eid = 0; eid < 256; eid++)
120
        for (eid = 0; eid < 256; eid++)
123
                if (cpu_by_id_eid_list[id][eid] == 1) {
121
                if (cpu_by_id_eid_list[id][eid] == 1) {
124
                    config.cpu_count++;
122
                    config.cpu_count++;
125
                    cpu_by_id_eid_list[id][eid] = 2;
123
                    cpu_by_id_eid_list[id][eid] = 2;
126
            }
124
            }
127
}
125
}
128
 
126
 
129
void kmp(void *arg __attribute__((unused)))
127
void kmp(void *arg __attribute__((unused)))
130
{
128
{
131
    int id, eid;
129
    int id, eid;
132
    int myid, myeid;
130
    int myid, myeid;
133
   
131
   
134
    myid = ia64_get_cpu_id();
132
    myid = ia64_get_cpu_id();
135
    myeid = ia64_get_cpu_eid();
133
    myeid = ia64_get_cpu_eid();
136
 
134
 
137
    for (id = 0; id < 256; id++)
135
    for (id = 0; id < 256; id++)
138
        for (eid = 0; eid < 256; eid++)
136
        for (eid = 0; eid < 256; eid++)
139
                if ((id != myid) || (eid != myeid))
137
                if ((id != myid) || (eid != myeid))
140
                    if (cpu_by_id_eid_list[id][eid] != 0) {
138
                    if (cpu_by_id_eid_list[id][eid] != 0) {
141
                        if (cpu_by_id_eid_list[id][eid] == 1) {
139
                        if (cpu_by_id_eid_list[id][eid] == 1) {
142
                            printf("Found Late CPU ID:%d "
140
                            printf("Found Late CPU ID:%d "
143
                            "EDI:%d Not added to "
141
                            "EDI:%d Not added to "
144
                            "system!!!\n", id, eid);
142
                            "system!!!\n", id, eid);
145
                            continue;
143
                            continue;
146
                    }
144
                    }
147
                    cpu_by_id_eid_list[id][eid] = 3;
145
                    cpu_by_id_eid_list[id][eid] = 3;
148
                    /*
146
                    /*
149
                     * There may be just one AP being
147
                     * There may be just one AP being
150
                     * initialized at the time. After
148
                     * initialized at the time. After
151
                     * it comes completely up, it is
149
                     * it comes completely up, it is
152
                     * supposed to wake us up.
150
                     * supposed to wake us up.
153
                     */
151
                     */
154
                    if (waitq_sleep_timeout(
152
                    if (waitq_sleep_timeout(
155
                        &ap_completion_wq, 1000000,
153
                        &ap_completion_wq, 1000000,
156
                        SYNCH_FLAGS_NONE) ==
154
                        SYNCH_FLAGS_NONE) ==
157
                        ESYNCH_TIMEOUT) {
155
                        ESYNCH_TIMEOUT) {
158
                        printf("%s: waiting for cpu "
156
                        printf("%s: waiting for cpu "
159
                            "ID:%d EID:%d timed out\n",
157
                            "ID:%d EID:%d timed out\n",
160
                            __FUNCTION__, id, eid);
158
                            __FUNCTION__, id, eid);
161
                        }
159
                        }
162
                }
160
                }
163
}
161
}
164
 
162
 
165
#endif
163
#endif
166
 
164
 
167
/** @}
165
/** @}
168
 */
166
 */
169
 
167
 
170
 
168