Subversion Repositories HelenOS-historic

Rev

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

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