Subversion Repositories HelenOS

Rev

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

Rev 4338 Rev 4344
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/drivers/ega.h>
-
 
55
#include <arch/bootinfo.h>
54
#include <arch/bootinfo.h>
56
#include <genarch/kbd/i8042.h>
55
#include <genarch/kbd/i8042.h>
57
#include <genarch/kbd/ns16550.h>
56
#include <genarch/kbd/ns16550.h>
58
#include <smp/smp.h>
57
#include <smp/smp.h>
59
#include <smp/ipi.h>
58
#include <smp/ipi.h>
60
#include <arch/atomic.h>
59
#include <arch/atomic.h>
61
#include <panic.h>
60
#include <panic.h>
62
#include <print.h>
61
#include <print.h>
63
 
62
 
64
#ifdef CONFIG_SMP
63
#ifdef CONFIG_SMP
65
 
64
 
66
extern char cpu_by_id_eid_list[256][256];
65
extern char cpu_by_id_eid_list[256][256];
67
 
66
 
68
static void sapic_init(void)
67
static void sapic_init(void)
69
{
68
{
70
    bootinfo->sapic = (unative_t *)(PA2KA((unative_t)(bootinfo->sapic)) |
69
    bootinfo->sapic = (unative_t *)(PA2KA((unative_t)(bootinfo->sapic)) |
71
        FW_OFFSET);
70
        FW_OFFSET);
72
}
71
}
73
 
72
 
74
static void ipi_broadcast_arch_all(int ipi)
73
static void ipi_broadcast_arch_all(int ipi)
75
{
74
{
76
    int id, eid;
75
    int id, eid;
77
    int myid, myeid;
76
    int myid, myeid;
78
   
77
   
79
    myid = ia64_get_cpu_id();
78
    myid = ia64_get_cpu_id();
80
    myeid = ia64_get_cpu_eid();
79
    myeid = ia64_get_cpu_eid();
81
   
80
   
82
    for (id = 0; id < 256; id++)
81
    for (id = 0; id < 256; id++)
83
        for (eid = 0; eid < 256; eid++)
82
        for (eid = 0; eid < 256; eid++)
84
            if ((id != myid) || (eid != myeid))
83
            if ((id != myid) || (eid != myeid))
85
                ipi_send_ipi(id, eid, ipi);
84
                ipi_send_ipi(id, eid, ipi);
86
}
85
}
87
 
86
 
88
void ipi_broadcast_arch(int ipi )
87
void ipi_broadcast_arch(int ipi )
89
{
88
{
90
    int id, eid;
89
    int id, eid;
91
    int myid, myeid;
90
    int myid, myeid;
92
   
91
   
93
    myid = ia64_get_cpu_id();
92
    myid = ia64_get_cpu_id();
94
    myeid = ia64_get_cpu_eid();
93
    myeid = ia64_get_cpu_eid();
95
 
94
 
96
    for (id = 0; id < 256; id++)
95
    for (id = 0; id < 256; id++)
97
        for (eid = 0; eid < 256; eid++)
96
        for (eid = 0; eid < 256; eid++)
98
            if ((id != myid) || (eid != myeid))
97
            if ((id != myid) || (eid != myeid))
99
                if (cpu_by_id_eid_list[id][eid])
98
                if (cpu_by_id_eid_list[id][eid])
100
                    ipi_send_ipi(id, eid, ipi);
99
                    ipi_send_ipi(id, eid, ipi);
101
}
100
}
102
 
101
 
103
void smp_init(void)
102
void smp_init(void)
104
{
103
{
105
    if (!bootinfo->hello_configured)
104
    if (!bootinfo->hello_configured)
106
        return;
105
        return;
107
   
106
   
108
    /*
107
    /*
109
     * If we have not got system prepared by hello, we are not able to start
108
     * If we have not got system prepared by hello, we are not able to start
110
     * AP's. This means we are running on a simulator.
109
     * AP's. This means we are running on a simulator.
111
     */
110
     */
112
   
111
   
113
    sapic_init();
112
    sapic_init();
114
    ipi_broadcast_arch_all(bootinfo->wakeup_intno);
113
    ipi_broadcast_arch_all(bootinfo->wakeup_intno);
115
    volatile long long brk;
114
    volatile long long brk;
116
        for (brk = 0; brk < 100LL * 1024LL * 1024LL; brk++)
115
        for (brk = 0; brk < 100LL * 1024LL * 1024LL; brk++)
117
        ;   /* wait a while before CPUs starts */
116
        ;   /* wait a while before CPUs starts */
118
 
117
 
119
    config.cpu_count = 0;
118
    config.cpu_count = 0;
120
    int id, eid;
119
    int id, eid;
121
   
120
   
122
    for (id = 0; id < 256; id++)
121
    for (id = 0; id < 256; id++)
123
        for (eid = 0; eid < 256; eid++)
122
        for (eid = 0; eid < 256; eid++)
124
                if (cpu_by_id_eid_list[id][eid] == 1) {
123
                if (cpu_by_id_eid_list[id][eid] == 1) {
125
                    config.cpu_count++;
124
                    config.cpu_count++;
126
                    cpu_by_id_eid_list[id][eid] = 2;
125
                    cpu_by_id_eid_list[id][eid] = 2;
127
            }
126
            }
128
}
127
}
129
 
128
 
130
void kmp(void *arg __attribute__((unused)))
129
void kmp(void *arg __attribute__((unused)))
131
{
130
{
132
    int id, eid;
131
    int id, eid;
133
    int myid, myeid;
132
    int myid, myeid;
134
   
133
   
135
    myid = ia64_get_cpu_id();
134
    myid = ia64_get_cpu_id();
136
    myeid = ia64_get_cpu_eid();
135
    myeid = ia64_get_cpu_eid();
137
 
136
 
138
    for (id = 0; id < 256; id++)
137
    for (id = 0; id < 256; id++)
139
        for (eid = 0; eid < 256; eid++)
138
        for (eid = 0; eid < 256; eid++)
140
                if ((id != myid) || (eid != myeid))
139
                if ((id != myid) || (eid != myeid))
141
                    if (cpu_by_id_eid_list[id][eid] != 0) {
140
                    if (cpu_by_id_eid_list[id][eid] != 0) {
142
                        if (cpu_by_id_eid_list[id][eid] == 1) {
141
                        if (cpu_by_id_eid_list[id][eid] == 1) {
143
                            printf("Found Late CPU ID:%d "
142
                            printf("Found Late CPU ID:%d "
144
                            "EDI:%d Not added to "
143
                            "EDI:%d Not added to "
145
                            "system!!!\n", id, eid);
144
                            "system!!!\n", id, eid);
146
                            continue;
145
                            continue;
147
                    }
146
                    }
148
                    cpu_by_id_eid_list[id][eid] = 3;
147
                    cpu_by_id_eid_list[id][eid] = 3;
149
                    /*
148
                    /*
150
                     * There may be just one AP being
149
                     * There may be just one AP being
151
                     * initialized at the time. After
150
                     * initialized at the time. After
152
                     * it comes completely up, it is
151
                     * it comes completely up, it is
153
                     * supposed to wake us up.
152
                     * supposed to wake us up.
154
                     */
153
                     */
155
                    if (waitq_sleep_timeout(
154
                    if (waitq_sleep_timeout(
156
                        &ap_completion_wq, 1000000,
155
                        &ap_completion_wq, 1000000,
157
                        SYNCH_FLAGS_NONE) ==
156
                        SYNCH_FLAGS_NONE) ==
158
                        ESYNCH_TIMEOUT) {
157
                        ESYNCH_TIMEOUT) {
159
                        printf("%s: waiting for cpu "
158
                        printf("%s: waiting for cpu "
160
                            "ID:%d EID:%d timed out\n",
159
                            "ID:%d EID:%d timed out\n",
161
                            __FUNCTION__, id, eid);
160
                            __FUNCTION__, id, eid);
162
                        }
161
                        }
163
                }
162
                }
164
}
163
}
165
 
164
 
166
#endif
165
#endif
167
 
166
 
168
/** @}
167
/** @}
169
 */
168
 */
170
 
169
 
171
 
170