Subversion Repositories HelenOS-historic

Rev

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

Rev 125 Rev 128
1
/*
1
/*
2
 * Copyright (C) 2001-2005 Jakub Jermar
2
 * Copyright (C) 2001-2005 Jakub Jermar
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
#ifdef __SMP__
29
#ifdef __SMP__
30
 
30
 
31
#include <arch/pm.h>
-
 
32
#include <config.h>
31
#include <config.h>
33
#include <print.h>
32
#include <print.h>
34
#include <panic.h>
33
#include <debug.h>
35
#include <arch/smp/mps.h>
34
#include <arch/smp/mps.h>
36
#include <arch/smp/ap.h>
-
 
37
#include <arch/smp/apic.h>
35
#include <arch/smp/apic.h>
-
 
36
#include <arch/smp/smp.h>
38
#include <func.h>
37
#include <func.h>
39
#include <arch/types.h>
38
#include <arch/types.h>
40
#include <typedefs.h>
39
#include <typedefs.h>
41
#include <synch/waitq.h>
-
 
42
#include <time/delay.h>
-
 
43
#include <mm/heap.h>
-
 
44
#include <mm/page.h>
40
#include <mm/page.h>
45
#include <mm/frame.h>
-
 
46
#include <cpu.h>
41
#include <cpu.h>
47
#include <arch/i8259.h>
-
 
48
#include <arch/asm.h>
42
#include <arch/asm.h>
49
#include <arch/bios/bios.h>
43
#include <arch/bios/bios.h>
50
#include <arch/acpi/madt.h>
-
 
51
 
44
 
52
/*
45
/*
53
 * MultiProcessor Specification detection code.
46
 * MultiProcessor Specification detection code.
54
 */
47
 */
55
 
48
 
56
#define FS_SIGNATURE    0x5f504d5f
49
#define FS_SIGNATURE    0x5f504d5f
57
#define CT_SIGNATURE    0x504d4350
50
#define CT_SIGNATURE    0x504d4350
58
 
51
 
59
int mps_fs_check(__u8 *base);
52
int mps_fs_check(__u8 *base);
60
int mps_ct_check(void);
53
int mps_ct_check(void);
61
 
54
 
62
int configure_via_ct(void);
55
int configure_via_ct(void);
63
int configure_via_default(__u8 n);
56
int configure_via_default(__u8 n);
64
 
57
 
65
int ct_processor_entry(struct __processor_entry *pr);
58
int ct_processor_entry(struct __processor_entry *pr);
66
void ct_bus_entry(struct __bus_entry *bus);
59
void ct_bus_entry(struct __bus_entry *bus);
67
void ct_io_apic_entry(struct __io_apic_entry *ioa);
60
void ct_io_apic_entry(struct __io_apic_entry *ioa);
68
void ct_io_intr_entry(struct __io_intr_entry *iointr);
61
void ct_io_intr_entry(struct __io_intr_entry *iointr);
69
void ct_l_intr_entry(struct __l_intr_entry *lintr);
62
void ct_l_intr_entry(struct __l_intr_entry *lintr);
70
 
63
 
71
void ct_extended_entries(void);
64
void ct_extended_entries(void);
72
 
65
 
73
static struct mps_fs *fs;
66
static struct mps_fs *fs;
74
static struct mps_ct *ct;
67
static struct mps_ct *ct;
75
 
68
 
76
struct __processor_entry *processor_entries = NULL;
69
struct __processor_entry *processor_entries = NULL;
77
struct __bus_entry *bus_entries = NULL;
70
struct __bus_entry *bus_entries = NULL;
78
struct __io_apic_entry *io_apic_entries = NULL;
71
struct __io_apic_entry *io_apic_entries = NULL;
79
struct __io_intr_entry *io_intr_entries = NULL;
72
struct __io_intr_entry *io_intr_entries = NULL;
80
struct __l_intr_entry *l_intr_entries = NULL;
73
struct __l_intr_entry *l_intr_entries = NULL;
81
 
74
 
82
int processor_entry_cnt = 0;
75
int processor_entry_cnt = 0;
83
int bus_entry_cnt = 0;
76
int bus_entry_cnt = 0;
84
int io_apic_entry_cnt = 0;
77
int io_apic_entry_cnt = 0;
85
int io_intr_entry_cnt = 0;
78
int io_intr_entry_cnt = 0;
86
int l_intr_entry_cnt = 0;
79
int l_intr_entry_cnt = 0;
87
 
80
 
88
waitq_t ap_completion_wq;
81
waitq_t ap_completion_wq;
89
waitq_t kmp_completion_wq;
82
waitq_t kmp_completion_wq;
90
 
83
 
-
 
84
 
-
 
85
/*
-
 
86
 * Implementation of IA-32 SMP configuration interface.
-
 
87
 */
-
 
88
static count_t get_cpu_count(void);
-
 
89
static bool is_cpu_enabled(index_t i);
-
 
90
static bool is_bsp(index_t i);
-
 
91
static __u8 get_cpu_apic_id(index_t i);
-
 
92
 
-
 
93
struct smp_config_operations mps_config_operations = {
-
 
94
    .cpu_count = get_cpu_count,
-
 
95
    .cpu_enabled = is_cpu_enabled,
-
 
96
    .cpu_bootstrap = is_bsp,
-
 
97
    .cpu_apic_id = get_cpu_apic_id
-
 
98
};
-
 
99
 
-
 
100
count_t get_cpu_count(void)
-
 
101
{
-
 
102
    return processor_entry_cnt;
-
 
103
}
-
 
104
 
-
 
105
bool is_cpu_enabled(index_t i)
-
 
106
{
-
 
107
    ASSERT(i < processor_entry_cnt);
-
 
108
    return processor_entries[i].cpu_flags & 0x1;
-
 
109
}
-
 
110
 
-
 
111
bool is_bsp(index_t i)
-
 
112
{
-
 
113
    ASSERT(i < processor_entry_cnt);
-
 
114
    return processor_entries[i].cpu_flags & 0x2;
-
 
115
}
-
 
116
 
-
 
117
__u8 get_cpu_apic_id(index_t i)
-
 
118
{
-
 
119
    ASSERT(i < processor_entry_cnt);
-
 
120
    return processor_entries[i].l_apic_id;
-
 
121
}
-
 
122
 
-
 
123
 
91
/*
124
/*
92
 * Used to check the integrity of the MP Floating Structure.
125
 * Used to check the integrity of the MP Floating Structure.
93
 */
126
 */
94
int mps_fs_check(__u8 *base)
127
int mps_fs_check(__u8 *base)
95
{
128
{
96
    int i;
129
    int i;
97
    __u8 sum;
130
    __u8 sum;
98
   
131
   
99
    for (i = 0, sum = 0; i < 16; i++)
132
    for (i = 0, sum = 0; i < 16; i++)
100
        sum += base[i];
133
        sum += base[i];
101
   
134
   
102
    return !sum;
135
    return !sum;
103
}
136
}
104
 
137
 
105
/*
138
/*
106
 * Used to check the integrity of the MP Configuration Table.
139
 * Used to check the integrity of the MP Configuration Table.
107
 */
140
 */
108
int mps_ct_check(void)
141
int mps_ct_check(void)
109
{
142
{
110
    __u8 *base = (__u8 *) ct;
143
    __u8 *base = (__u8 *) ct;
111
    __u8 *ext = base + ct->base_table_length;
144
    __u8 *ext = base + ct->base_table_length;
112
    __u8 sum;
145
    __u8 sum;
113
    int i; 
146
    int i; 
114
   
147
   
115
    /* count the checksum for the base table */
148
    /* count the checksum for the base table */
116
    for (i=0,sum=0; i < ct->base_table_length; i++)
149
    for (i=0,sum=0; i < ct->base_table_length; i++)
117
        sum += base[i];
150
        sum += base[i];
118
       
151
       
119
    if (sum)
152
    if (sum)
120
        return 0;
153
        return 0;
121
       
154
       
122
    /* count the checksum for the extended table */
155
    /* count the checksum for the extended table */
123
    for (i=0,sum=0; i < ct->ext_table_length; i++)
156
    for (i=0,sum=0; i < ct->ext_table_length; i++)
124
        sum += ext[i];
157
        sum += ext[i];
125
       
158
       
126
    return sum == ct->ext_table_checksum;
159
    return sum == ct->ext_table_checksum;
127
}
160
}
128
 
161
 
129
void mps_init(void)
162
void mps_init(void)
130
{
163
{
131
    __u8 *addr[2] = { NULL, (__u8 *) 0xf0000 };
164
    __u8 *addr[2] = { NULL, (__u8 *) 0xf0000 };
132
    int i, j, length[2] = { 1024, 64*1024 };
165
    int i, j, length[2] = { 1024, 64*1024 };
133
   
166
   
134
 
167
 
135
    /*
168
    /*
136
     * Find MP Floating Pointer Structure
169
     * Find MP Floating Pointer Structure
137
     * 1a. search first 1K of EBDA
170
     * 1a. search first 1K of EBDA
138
     * 1b. if EBDA is undefined, search last 1K of base memory
171
     * 1b. if EBDA is undefined, search last 1K of base memory
139
     *  2. search 64K starting at 0xf0000
172
     *  2. search 64K starting at 0xf0000
140
     */
173
     */
141
 
174
 
142
    addr[0] = (__u8 *) (ebda ? ebda : 639 * 1024);
175
    addr[0] = (__u8 *) (ebda ? ebda : 639 * 1024);
143
    for (i = 0; i < 2; i++) {
176
    for (i = 0; i < 2; i++) {
144
        for (j = 0; j < length[i]; j += 16) {
177
        for (j = 0; j < length[i]; j += 16) {
145
            if (*((__u32 *) &addr[i][j]) == FS_SIGNATURE && mps_fs_check(&addr[i][j])) {
178
            if (*((__u32 *) &addr[i][j]) == FS_SIGNATURE && mps_fs_check(&addr[i][j])) {
146
                fs = (struct mps_fs *) &addr[i][j];
179
                fs = (struct mps_fs *) &addr[i][j];
147
                goto fs_found;
180
                goto fs_found;
148
            }
181
            }
149
        }
182
        }
150
    }
183
    }
151
 
184
 
152
    return;
185
    return;
153
   
186
   
154
fs_found:
187
fs_found:
155
    printf("%L: MPS Floating Pointer Structure\n", fs);
188
    printf("%L: MPS Floating Pointer Structure\n", fs);
156
 
189
 
157
    frame_not_free((__address) fs);
190
    frame_not_free((__address) fs);
158
 
191
 
159
    if (fs->config_type == 0 && fs->configuration_table) {
192
    if (fs->config_type == 0 && fs->configuration_table) {
160
        if (fs->mpfib2 >> 7) {
193
        if (fs->mpfib2 >> 7) {
161
            printf("%s: PIC mode not supported\n", __FUNCTION__);
194
            printf("%s: PIC mode not supported\n", __FUNCTION__);
162
            return;
195
            return;
163
        }
196
        }
164
 
197
 
165
        ct = fs->configuration_table;
198
        ct = fs->configuration_table;
166
        frame_not_free((__address) ct);
199
        frame_not_free((__address) ct);
167
        config.cpu_count = configure_via_ct();
200
        config.cpu_count = configure_via_ct();
168
    }
201
    }
169
    else
202
    else
170
        config.cpu_count = configure_via_default(fs->config_type);
203
        config.cpu_count = configure_via_default(fs->config_type);
171
 
204
 
172
    if (config.cpu_count > 1) {
205
    if (config.cpu_count > 1) {
173
        map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0);
206
        map_page_to_frame((__address) l_apic, (__address) l_apic, PAGE_NOT_CACHEABLE, 0);
174
    }      
207
    }      
175
   
208
   
176
   
209
   
177
    /*
210
    /*
178
     * Must be initialized outside the kmp thread, since it is waited
211
     * Must be initialized outside the kmp thread, since it is waited
179
     * on before the kmp thread is created.
212
     * on before the kmp thread is created.
180
     */
213
     */
181
    waitq_initialize(&kmp_completion_wq);
214
    waitq_initialize(&kmp_completion_wq);
182
    return;
215
    return;
183
}
216
}
184
 
217
 
185
int configure_via_ct(void)
218
int configure_via_ct(void)
186
{
219
{
187
    __u8 *cur;
220
    __u8 *cur;
188
    int i, cnt;
221
    int i, cnt;
189
       
222
       
190
    if (ct->signature != CT_SIGNATURE) {
223
    if (ct->signature != CT_SIGNATURE) {
191
        printf("%s: bad ct->signature\n", __FUNCTION__);
224
        printf("%s: bad ct->signature\n", __FUNCTION__);
192
        return 1;
225
        return 1;
193
    }
226
    }
194
    if (!mps_ct_check()) {
227
    if (!mps_ct_check()) {
195
        printf("%s: bad ct checksum\n", __FUNCTION__);
228
        printf("%s: bad ct checksum\n", __FUNCTION__);
196
        return 1;
229
        return 1;
197
    }
230
    }
198
    if (ct->oem_table) {
231
    if (ct->oem_table) {
199
        printf("%s: ct->oem_table not supported\n", __FUNCTION__);
232
        printf("%s: ct->oem_table not supported\n", __FUNCTION__);
200
        return 1;
233
        return 1;
201
    }
234
    }
202
   
235
   
203
    l_apic = ct->l_apic;
236
    l_apic = ct->l_apic;
204
 
237
 
205
    cnt = 0;
238
    cnt = 0;
206
    cur = &ct->base_table[0];
239
    cur = &ct->base_table[0];
207
    for (i=0; i < ct->entry_count; i++) {
240
    for (i=0; i < ct->entry_count; i++) {
208
        switch (*cur) {
241
        switch (*cur) {
209
            /* Processor entry */
242
            /* Processor entry */
210
            case 0:
243
            case 0:
211
                processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur;
244
                processor_entries = processor_entries ? processor_entries : (struct __processor_entry *) cur;
212
                processor_entry_cnt++;
245
                processor_entry_cnt++;
213
                cnt += ct_processor_entry((struct __processor_entry *) cur);
246
                cnt += ct_processor_entry((struct __processor_entry *) cur);
214
                cur += 20;
247
                cur += 20;
215
                break;
248
                break;
216
 
249
 
217
            /* Bus entry */
250
            /* Bus entry */
218
            case 1:
251
            case 1:
219
                bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur;
252
                bus_entries = bus_entries ? bus_entries : (struct __bus_entry *) cur;
220
                bus_entry_cnt++;
253
                bus_entry_cnt++;
221
                ct_bus_entry((struct __bus_entry *) cur);
254
                ct_bus_entry((struct __bus_entry *) cur);
222
                cur += 8;
255
                cur += 8;
223
                break;
256
                break;
224
               
257
               
225
            /* I/O Apic */
258
            /* I/O Apic */
226
            case 2:
259
            case 2:
227
                io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur;
260
                io_apic_entries = io_apic_entries ? io_apic_entries : (struct __io_apic_entry *) cur;
228
                io_apic_entry_cnt++;
261
                io_apic_entry_cnt++;
229
                ct_io_apic_entry((struct __io_apic_entry *) cur);
262
                ct_io_apic_entry((struct __io_apic_entry *) cur);
230
                cur += 8;
263
                cur += 8;
231
                break;
264
                break;
232
               
265
               
233
            /* I/O Interrupt Assignment */
266
            /* I/O Interrupt Assignment */
234
            case 3:
267
            case 3:
235
                io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur;
268
                io_intr_entries = io_intr_entries ? io_intr_entries : (struct __io_intr_entry *) cur;
236
                io_intr_entry_cnt++;
269
                io_intr_entry_cnt++;
237
                ct_io_intr_entry((struct __io_intr_entry *) cur);
270
                ct_io_intr_entry((struct __io_intr_entry *) cur);
238
                cur += 8;
271
                cur += 8;
239
                break;
272
                break;
240
 
273
 
241
            /* Local Interrupt Assignment */
274
            /* Local Interrupt Assignment */
242
            case 4:
275
            case 4:
243
                l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur;
276
                l_intr_entries = l_intr_entries ? l_intr_entries : (struct __l_intr_entry *) cur;
244
                l_intr_entry_cnt++;
277
                l_intr_entry_cnt++;
245
                ct_l_intr_entry((struct __l_intr_entry *) cur);
278
                ct_l_intr_entry((struct __l_intr_entry *) cur);
246
                cur += 8;
279
                cur += 8;
247
                break;
280
                break;
248
 
281
 
249
            default:
282
            default:
250
                /*
283
                /*
251
                 * Something is wrong. Fallback to UP mode.
284
                 * Something is wrong. Fallback to UP mode.
252
                 */
285
                 */
253
                 
286
                 
254
                printf("%s: ct badness\n", __FUNCTION__);
287
                printf("%s: ct badness\n", __FUNCTION__);
255
                return 1;
288
                return 1;
256
        }
289
        }
257
    }
290
    }
258
   
291
   
259
    /*
292
    /*
260
     * Process extended entries.
293
     * Process extended entries.
261
     */
294
     */
262
    ct_extended_entries();
295
    ct_extended_entries();
263
    return cnt;
296
    return cnt;
264
}
297
}
265
 
298
 
266
int configure_via_default(__u8 n)
299
int configure_via_default(__u8 n)
267
{
300
{
268
    /*
301
    /*
269
     * Not yet implemented.
302
     * Not yet implemented.
270
     */
303
     */
271
    printf("%s: not supported\n", __FUNCTION__);
304
    printf("%s: not supported\n", __FUNCTION__);
272
    return 1;
305
    return 1;
273
}
306
}
274
 
307
 
275
 
308
 
276
int ct_processor_entry(struct __processor_entry *pr)
309
int ct_processor_entry(struct __processor_entry *pr)
277
{
310
{
278
    /*
311
    /*
279
     * Ignore processors which are not marked enabled.
312
     * Ignore processors which are not marked enabled.
280
     */
313
     */
281
    if ((pr->cpu_flags & (1<<0)) == 0)
314
    if ((pr->cpu_flags & (1<<0)) == 0)
282
        return 0;
315
        return 0;
283
   
316
   
284
    apic_id_mask |= (1<<pr->l_apic_id);
317
    apic_id_mask |= (1<<pr->l_apic_id);
285
    return 1;
318
    return 1;
286
}
319
}
287
 
320
 
288
void ct_bus_entry(struct __bus_entry *bus)
321
void ct_bus_entry(struct __bus_entry *bus)
289
{
322
{
290
#ifdef MPSCT_VERBOSE
323
#ifdef MPSCT_VERBOSE
291
    char buf[7];
324
    char buf[7];
292
    memcopy((__address) bus->bus_type, (__address) buf, 6);
325
    memcopy((__address) bus->bus_type, (__address) buf, 6);
293
    buf[6] = 0;
326
    buf[6] = 0;
294
    printf("bus%d: %s\n", bus->bus_id, buf);
327
    printf("bus%d: %s\n", bus->bus_id, buf);
295
#endif
328
#endif
296
}
329
}
297
 
330
 
298
void ct_io_apic_entry(struct __io_apic_entry *ioa)
331
void ct_io_apic_entry(struct __io_apic_entry *ioa)
299
{
332
{
300
    static int io_apic_count = 0;
333
    static int io_apic_count = 0;
301
 
334
 
302
    /* this ioapic is marked unusable */
335
    /* this ioapic is marked unusable */
303
    if (ioa->io_apic_flags & 1 == 0)
336
    if (ioa->io_apic_flags & 1 == 0)
304
        return;
337
        return;
305
   
338
   
306
    if (io_apic_count++ > 0) {
339
    if (io_apic_count++ > 0) {
307
        /*
340
        /*
308
         * Multiple IO APIC's are currently not supported.
341
         * Multiple IO APIC's are currently not supported.
309
         */
342
         */
310
        return;
343
        return;
311
    }
344
    }
312
   
345
   
313
    map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0);
346
    map_page_to_frame((__address) ioa->io_apic, (__address) ioa->io_apic, PAGE_NOT_CACHEABLE, 0);
314
   
347
   
315
    io_apic = ioa->io_apic;
348
    io_apic = ioa->io_apic;
316
}
349
}
317
 
350
 
318
//#define MPSCT_VERBOSE
351
//#define MPSCT_VERBOSE
319
void ct_io_intr_entry(struct __io_intr_entry *iointr)
352
void ct_io_intr_entry(struct __io_intr_entry *iointr)
320
{
353
{
321
#ifdef MPSCT_VERBOSE
354
#ifdef MPSCT_VERBOSE
322
    switch (iointr->intr_type) {
355
    switch (iointr->intr_type) {
323
        case 0: printf("INT"); break;
356
        case 0: printf("INT"); break;
324
        case 1: printf("NMI"); break;
357
        case 1: printf("NMI"); break;
325
        case 2: printf("SMI"); break;
358
        case 2: printf("SMI"); break;
326
        case 3: printf("ExtINT"); break;
359
        case 3: printf("ExtINT"); break;
327
    }
360
    }
328
    putchar(',');
361
    putchar(',');
329
    switch (iointr->poel&3) {
362
    switch (iointr->poel&3) {
330
        case 0: printf("bus-like"); break;
363
        case 0: printf("bus-like"); break;
331
        case 1: printf("active high"); break;
364
        case 1: printf("active high"); break;
332
        case 2: printf("reserved"); break;
365
        case 2: printf("reserved"); break;
333
        case 3: printf("active low"); break;
366
        case 3: printf("active low"); break;
334
    }
367
    }
335
    putchar(',');
368
    putchar(',');
336
    switch ((iointr->poel>>2)&3) {
369
    switch ((iointr->poel>>2)&3) {
337
        case 0: printf("bus-like"); break;
370
        case 0: printf("bus-like"); break;
338
        case 1: printf("edge-triggered"); break;
371
        case 1: printf("edge-triggered"); break;
339
        case 2: printf("reserved"); break;
372
        case 2: printf("reserved"); break;
340
        case 3: printf("level-triggered"); break;
373
        case 3: printf("level-triggered"); break;
341
    }
374
    }
342
    putchar(',');
375
    putchar(',');
343
    printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq);
376
    printf("bus%d,irq%d", iointr->src_bus_id, iointr->src_bus_irq);
344
    putchar(',');
377
    putchar(',');
345
    printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin);
378
    printf("io_apic%d,pin%d", iointr->dst_io_apic_id, iointr->dst_io_apic_pin);
346
    putchar('\n'); 
379
    putchar('\n'); 
347
#endif
380
#endif
348
}
381
}
349
 
382
 
350
void ct_l_intr_entry(struct __l_intr_entry *lintr)
383
void ct_l_intr_entry(struct __l_intr_entry *lintr)
351
{
384
{
352
#ifdef MPSCT_VERBOSE
385
#ifdef MPSCT_VERBOSE
353
    switch (lintr->intr_type) {
386
    switch (lintr->intr_type) {
354
        case 0: printf("INT"); break;
387
        case 0: printf("INT"); break;
355
        case 1: printf("NMI"); break;
388
        case 1: printf("NMI"); break;
356
        case 2: printf("SMI"); break;
389
        case 2: printf("SMI"); break;
357
        case 3: printf("ExtINT"); break;
390
        case 3: printf("ExtINT"); break;
358
    }
391
    }
359
    putchar(',');
392
    putchar(',');
360
    switch (lintr->poel&3) {
393
    switch (lintr->poel&3) {
361
        case 0: printf("bus-like"); break;
394
        case 0: printf("bus-like"); break;
362
        case 1: printf("active high"); break;
395
        case 1: printf("active high"); break;
363
        case 2: printf("reserved"); break;
396
        case 2: printf("reserved"); break;
364
        case 3: printf("active low"); break;
397
        case 3: printf("active low"); break;
365
    }
398
    }
366
    putchar(',');
399
    putchar(',');
367
    switch ((lintr->poel>>2)&3) {
400
    switch ((lintr->poel>>2)&3) {
368
        case 0: printf("bus-like"); break;
401
        case 0: printf("bus-like"); break;
369
        case 1: printf("edge-triggered"); break;
402
        case 1: printf("edge-triggered"); break;
370
        case 2: printf("reserved"); break;
403
        case 2: printf("reserved"); break;
371
        case 3: printf("level-triggered"); break;
404
        case 3: printf("level-triggered"); break;
372
    }
405
    }
373
    putchar(',');
406
    putchar(',');
374
    printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq);
407
    printf("bus%d,irq%d", lintr->src_bus_id, lintr->src_bus_irq);
375
    putchar(',');
408
    putchar(',');
376
    printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin);
409
    printf("l_apic%d,pin%d", lintr->dst_l_apic_id, lintr->dst_l_apic_pin);
377
    putchar('\n');
410
    putchar('\n');
378
#endif
411
#endif
379
}
412
}
380
 
413
 
381
void ct_extended_entries(void)
414
void ct_extended_entries(void)
382
{
415
{
383
    __u8 *ext = (__u8 *) ct + ct->base_table_length;
416
    __u8 *ext = (__u8 *) ct + ct->base_table_length;
384
    __u8 *cur;
417
    __u8 *cur;
385
 
418
 
386
    for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) {
419
    for (cur = ext; cur < ext + ct->ext_table_length; cur += cur[CT_EXT_ENTRY_LEN]) {
387
        switch (cur[CT_EXT_ENTRY_TYPE]) {
420
        switch (cur[CT_EXT_ENTRY_TYPE]) {
388
            default:
421
            default:
389
                printf("%L: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]);
422
                printf("%L: skipping MP Configuration Table extended entry type %d\n", cur, cur[CT_EXT_ENTRY_TYPE]);
390
                break;
423
                break;
391
        }
424
        }
392
    }
425
    }
393
}
426
}
394
 
-
 
395
 
-
 
396
/*
-
 
397
 * Kernel thread for bringing up application processors. It becomes clear
-
 
398
 * that we need an arrangement like this (AP's being initialized by a kernel
-
 
399
 * thread), for a thread has its dedicated stack. (The stack used during the
-
 
400
 * BSP initialization (prior the very first call to scheduler()) will be used
-
 
401
 * as an initialization stack for each AP.)
-
 
402
 */
-
 
403
void kmp(void *arg)
-
 
404
{
-
 
405
    struct __processor_entry *pr;
-
 
406
    __address src, dst;
-
 
407
    int i;
-
 
408
 
-
 
409
    waitq_initialize(&ap_completion_wq);
-
 
410
 
-
 
411
    /*
-
 
412
     * Processor entries immediately follow the configuration table header.
-
 
413
     */
-
 
414
    pr = processor_entries;
-
 
415
 
-
 
416
    /*
-
 
417
     * We need to access data in frame 0.
-
 
418
     * We boldly make use of kernel address space mapping.
-
 
419
     */
-
 
420
 
-
 
421
    /*
-
 
422
     * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot()
-
 
423
     */
-
 
424
    *((__u16 *) (PA2KA(0x467+0))) =  ((__address) ap_boot) >> 4;    /* segment */
-
 
425
    *((__u16 *) (PA2KA(0x467+2))) =  0;             /* offset */
-
 
426
   
-
 
427
    /*
-
 
428
     * Save 0xa to address 0xf of the CMOS RAM.
-
 
429
     * BIOS will not do the POST after the INIT signal.
-
 
430
     */
-
 
431
    outb(0x70,0xf);
-
 
432
    outb(0x71,0xa);
-
 
433
 
-
 
434
    cpu_priority_high();
-
 
435
 
-
 
436
    pic_disable_irqs(0xffff);
-
 
437
    apic_init();
-
 
438
 
-
 
439
    for (i = 0; i < processor_entry_cnt; i++) {
-
 
440
        struct descriptor *gdt_new;
-
 
441
   
-
 
442
        /*
-
 
443
         * Skip processors marked unusable.
-
 
444
         */
-
 
445
        if (pr[i].cpu_flags & (1<<0) == 0)
-
 
446
            continue;
-
 
447
 
-
 
448
        /*
-
 
449
         * The bootstrap processor is already up.
-
 
450
         */
-
 
451
        if (pr[i].cpu_flags & (1<<1))
-
 
452
            continue;
-
 
453
 
-
 
454
        if (pr[i].l_apic_id == l_apic_id()) {
-
 
455
            printf("%L: bad processor entry #%d, will not send IPI to myself\n", &pr[i], i);
-
 
456
            continue;
-
 
457
        }
-
 
458
       
-
 
459
        /*
-
 
460
         * Prepare new GDT for CPU in question.
-
 
461
         */
-
 
462
        if (!(gdt_new = (struct descriptor *) malloc(GDT_ITEMS*sizeof(struct descriptor))))
-
 
463
            panic("couldn't allocate memory for GDT\n");
-
 
464
 
-
 
465
        memcopy(gdt, gdt_new, GDT_ITEMS*sizeof(struct descriptor));
-
 
466
        memsetb(&gdt_new[TSS_DES], sizeof(struct descriptor), 0);
-
 
467
        gdtr.base = KA2PA((__address) gdt_new);
-
 
468
 
-
 
469
        if (l_apic_send_init_ipi(pr[i].l_apic_id)) {
-
 
470
            /*
-
 
471
                 * There may be just one AP being initialized at
-
 
472
             * the time. After it comes completely up, it is
-
 
473
             * supposed to wake us up.
-
 
474
                 */
-
 
475
            waitq_sleep(&ap_completion_wq);
-
 
476
            cpu_priority_high();
-
 
477
        }
-
 
478
        else {
-
 
479
            printf("INIT IPI for l_apic%d failed\n", pr[i].l_apic_id);
-
 
480
        }
-
 
481
    }
-
 
482
 
-
 
483
    /*
-
 
484
     * Wakeup the kinit thread so that
-
 
485
     * system initialization can go on.
-
 
486
     */
-
 
487
    waitq_wakeup(&kmp_completion_wq, WAKEUP_FIRST);
-
 
488
}
-
 
489
 
427
 
490
int mps_irq_to_pin(int irq)
428
int mps_irq_to_pin(int irq)
491
{
429
{
492
    int i;
430
    int i;
493
   
431
   
494
    for(i=0;i<io_intr_entry_cnt;i++) {
432
    for(i=0;i<io_intr_entry_cnt;i++) {
495
        if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0)
433
        if (io_intr_entries[i].src_bus_irq == irq && io_intr_entries[i].intr_type == 0)
496
            return io_intr_entries[i].dst_io_apic_pin;
434
            return io_intr_entries[i].dst_io_apic_pin;
497
    }
435
    }
498
   
436
   
499
    return -1;
437
    return -1;
500
}
438
}
501
 
439
 
502
#endif /* __SMP__ */
440
#endif /* __SMP__ */
503
 
441