Subversion Repositories HelenOS-historic

Rev

Rev 512 | Rev 514 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 512 Rev 513
Line 41... Line 41...
41
 
41
 
42
/*
42
/*
43
 * Advanced Programmable Interrupt Controller for SMP systems.
43
 * Advanced Programmable Interrupt Controller for SMP systems.
44
 * Tested on:
44
 * Tested on:
45
 *  Bochs 2.0.2 - Bochs 2.2 with 2-8 CPUs
45
 *  Bochs 2.0.2 - Bochs 2.2 with 2-8 CPUs
46
 *  Simics 2.0.28 - Simics 2.2.14 2-4 CPUs
46
 *  Simics 2.0.28 - Simics 2.2.19 2-8 CPUs
47
 *  ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
47
 *  ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
48
 *  ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs
48
 *  ASUS PCH-DL with 2x 3000Mhz Pentium 4 Xeon (HT) CPUs
49
 *  MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs
49
 *  MSI K7D Master-L with 2x 2100MHz Athlon MP CPUs
50
 */
50
 */
51
 
51
 
Line 62... Line 62...
62
 
62
 
63
__u32 apic_id_mask = 0;
63
__u32 apic_id_mask = 0;
64
 
64
 
65
int apic_poll_errors(void);
65
int apic_poll_errors(void);
66
 
66
 
-
 
67
/** Initialize APIC on BSP. */
67
void apic_init(void)
68
void apic_init(void)
68
{
69
{
69
    __u32 tmp, id, i;
70
    __u32 tmp, id, i;
70
 
71
 
71
    trap_register(VECTOR_APIC_SPUR, apic_spurious);
72
    trap_register(VECTOR_APIC_SPUR, apic_spurious);
Line 83... Line 84...
83
    trap_register(VECTOR_CLK, l_apic_timer_interrupt);
84
    trap_register(VECTOR_CLK, l_apic_timer_interrupt);
84
    for (i=0; i<16; i++) {
85
    for (i=0; i<16; i++) {
85
        int pin;
86
        int pin;
86
   
87
   
87
        if ((pin = smp_irq_to_pin(i)) != -1) {
88
        if ((pin = smp_irq_to_pin(i)) != -1) {
88
            io_apic_change_ioredtbl(pin,0xff,IVT_IRQBASE+i,LOPRI);
89
            io_apic_change_ioredtbl(pin, 0xff, IVT_IRQBASE+i, LOPRI);
89
        }
90
        }
90
    }
91
    }
91
   
92
   
92
 
93
 
93
    /*
94
    /*
Line 145... Line 146...
145
/*
146
/*
146
 * Send all CPUs excluding CPU IPI vector.
147
 * Send all CPUs excluding CPU IPI vector.
147
 */
148
 */
148
int l_apic_broadcast_custom_ipi(__u8 vector)
149
int l_apic_broadcast_custom_ipi(__u8 vector)
149
{
150
{
150
    __u32 lo;
151
    icr_t icr;
151
 
152
 
152
    /*
153
    icr.lo = l_apic[ICRlo];
-
 
154
    icr.delmod = DELMOD_FIXED;
153
     * Read the ICR register in and zero all non-reserved fields.
155
    icr.destmod = DESTMOD_LOGIC;
154
     */
156
    icr.level = LEVEL_ASSERT;
-
 
157
    icr.shorthand = SHORTHAND_ALL_EXCL;
155
    lo = l_apic[ICRlo] & ICRloClear;
158
    icr.trigger_mode = TRIGMOD_LEVEL;
-
 
159
    icr.vector = vector;
156
 
160
 
157
    lo |= DLVRMODE_FIXED | DESTMODE_LOGIC | LEVEL_ASSERT | SHORTHAND_EXCL | TRGRMODE_LEVEL | vector;
-
 
158
   
-
 
159
    l_apic[ICRlo] = lo;
161
    l_apic[ICRlo] = icr.lo;
160
 
162
 
161
    lo = l_apic[ICRlo] & ICRloClear;
163
    icr.lo = l_apic[ICRlo];
162
    if (lo & SEND_PENDING)
164
    if (icr.lo & SEND_PENDING)
163
        printf("IPI is pending.\n");
165
        printf("IPI is pending.\n");
164
 
166
 
165
    return apic_poll_errors();
167
    return apic_poll_errors();
166
}
168
}
167
 
169
 
168
/*
170
/*
169
 * Universal Start-up Algorithm for bringing up the AP processors.
171
 * Universal Start-up Algorithm for bringing up the AP processors.
170
 */
172
 */
171
int l_apic_send_init_ipi(__u8 apicid)
173
int l_apic_send_init_ipi(__u8 apicid)
172
{
174
{
173
    __u32 lo, hi;
175
    icr_t icr;
174
    int i;
176
    int i;
175
 
177
 
176
    /*
178
    /*
177
     * Read the ICR register in and zero all non-reserved fields.
179
     * Read the ICR register in and zero all non-reserved fields.
178
     */
180
     */
179
    lo = l_apic[ICRlo] & ICRloClear;
181
    icr.lo = l_apic[ICRlo];
180
    hi = l_apic[ICRhi] & ICRhiClear;
182
    icr.hi = l_apic[ICRhi];
181
   
183
   
-
 
184
    icr.delmod = DELMOD_INIT;
-
 
185
    icr.destmod = DESTMOD_PHYS;
-
 
186
    icr.level = LEVEL_ASSERT;
182
    lo |= DLVRMODE_INIT | DESTMODE_PHYS | LEVEL_ASSERT | SHORTHAND_DEST | TRGRMODE_LEVEL;
187
    icr.trigger_mode = TRIGMOD_LEVEL;
-
 
188
    icr.shorthand = SHORTHAND_NONE;
-
 
189
    icr.vector = 0;
183
    hi |= apicid << 24;
190
    icr.dest = apicid;
184
   
191
   
185
    l_apic[ICRhi] = hi;
192
    l_apic[ICRhi] = icr.hi;
186
    l_apic[ICRlo] = lo;
193
    l_apic[ICRlo] = icr.lo;
187
 
194
 
188
    /*
195
    /*
189
     * According to MP Specification, 20us should be enough to
196
     * According to MP Specification, 20us should be enough to
190
     * deliver the IPI.
197
     * deliver the IPI.
191
     */
198
     */
192
    delay(20);
199
    delay(20);
193
 
200
 
194
    if (!apic_poll_errors()) return 0;
201
    if (!apic_poll_errors()) return 0;
195
 
202
 
196
    lo = l_apic[ICRlo] & ICRloClear;
203
    icr.lo = l_apic[ICRlo];
197
    if (lo & SEND_PENDING)
204
    if (icr.lo & SEND_PENDING)
198
        printf("IPI is pending.\n");
205
        printf("IPI is pending.\n");
199
 
206
 
-
 
207
    icr.delmod = DELMOD_INIT;
-
 
208
    icr.destmod = DESTMOD_PHYS;
-
 
209
    icr.level = LEVEL_DEASSERT;
-
 
210
    icr.shorthand = SHORTHAND_NONE;
200
    l_apic[ICRlo] = lo | DLVRMODE_INIT | DESTMODE_PHYS | LEVEL_DEASSERT | SHORTHAND_DEST | TRGRMODE_LEVEL;
211
    icr.trigger_mode = TRIGMOD_LEVEL;
-
 
212
    icr.vector = 0;
-
 
213
    l_apic[ICRlo] = icr.lo;
201
 
214
 
202
    /*
215
    /*
203
     * Wait 10ms as MP Specification specifies.
216
     * Wait 10ms as MP Specification specifies.
204
     */
217
     */
205
    delay(10000);
218
    delay(10000);
Line 207... Line 220...
207
    if (!is_82489DX_apic(l_apic[LAVR])) {
220
    if (!is_82489DX_apic(l_apic[LAVR])) {
208
        /*
221
        /*
209
         * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
222
         * If this is not 82489DX-based l_apic we must send two STARTUP IPI's.
210
         */
223
         */
211
        for (i = 0; i<2; i++) {
224
        for (i = 0; i<2; i++) {
212
            lo = l_apic[ICRlo] & ICRloClear;
225
            icr.lo = l_apic[ICRlo];
213
            lo |= ((__address) ap_boot) / 4096; /* calculate the reset vector */
226
            icr.vector = ((__address) ap_boot) / 4096; /* calculate the reset vector */
-
 
227
            icr.delmod = DELMOD_STARTUP;
-
 
228
            icr.destmod = DESTMOD_PHYS;
-
 
229
            icr.level = LEVEL_ASSERT;
-
 
230
            icr.shorthand = SHORTHAND_NONE;
214
            l_apic[ICRlo] = lo | DLVRMODE_STUP | DESTMODE_PHYS | LEVEL_ASSERT | SHORTHAND_DEST | TRGRMODE_LEVEL;
231
            icr.trigger_mode = TRIGMOD_LEVEL;
-
 
232
            l_apic[ICRlo] = icr.lo;
215
            delay(200);
233
            delay(200);
216
        }
234
        }
217
    }
235
    }
218
   
236
   
219
   
237
   
220
    return apic_poll_errors();
238
    return apic_poll_errors();
221
}
239
}
222
 
240
 
223
void l_apic_init(void)
241
void l_apic_init(void)
224
{
242
{
-
 
243
    lvt_error_t error;
-
 
244
    lvt_lint_t lint;
-
 
245
    svr_t svr;
-
 
246
    lvt_tm_t tm;
-
 
247
    icr_t icr;
225
    __u32 tmp, t1, t2;
248
    __u32 t1, t2;
226
 
249
 
-
 
250
    /* Initialize LVT Error register. */
-
 
251
    error.value = l_apic[LVT_Err];
-
 
252
    error.masked = true;
227
    l_apic[LVT_Err] |= (1<<16);
253
    l_apic[LVT_Err] = error.value;
-
 
254
 
-
 
255
    /* Initialize LVT LINT0 register. */
-
 
256
    lint.value = l_apic[LVT_LINT0];
-
 
257
    lint.masked = true;
228
    l_apic[LVT_LINT0] |= (1<<16);
258
    l_apic[LVT_LINT0] = lint.value;
-
 
259
 
-
 
260
    /* Initialize LVT LINT1 register. */
-
 
261
    lint.value = l_apic[LVT_LINT1];
-
 
262
    lint.masked = true;
229
    l_apic[LVT_LINT1] |= (1<<16);
263
    l_apic[LVT_LINT1] = lint.value;
230
 
264
   
-
 
265
    /* Spurious-Interrupt Vector Register initialization. */
231
    tmp = l_apic[SVR] & SVRClear;
266
    svr.value = l_apic[SVR];
232
    l_apic[SVR] = tmp | (1<<8) | (VECTOR_APIC_SPUR);
267
    svr.vector = VECTOR_APIC_SPUR;
-
 
268
    svr.lapic_enabled = true;
-
 
269
    l_apic[SVR] = svr.value;
233
 
270
 
234
    l_apic[TPR] &= TPRClear;
271
    l_apic[TPR] &= TPRClear;
235
 
272
 
236
    if (CPU->arch.family >= 6)
273
    if (CPU->arch.family >= 6)
237
        enable_l_apic_in_msr();
274
        enable_l_apic_in_msr();
238
   
275
   
-
 
276
    /* Interrupt Command Register initialization. */
239
    tmp = l_apic[ICRlo] & ICRloClear;
277
    icr.lo = l_apic[ICRlo];
-
 
278
    icr.delmod = DELMOD_INIT;
-
 
279
    icr.destmod = DESTMOD_PHYS;
-
 
280
    icr.level = LEVEL_DEASSERT;
240
    l_apic[ICRlo] = tmp | DLVRMODE_INIT | DESTMODE_PHYS | LEVEL_DEASSERT | SHORTHAND_INCL | TRGRMODE_LEVEL;
281
    icr.shorthand = SHORTHAND_ALL_INCL;
-
 
282
    icr.trigger_mode = TRIGMOD_LEVEL;
-
 
283
    l_apic[ICRlo] = icr.lo;
241
   
284
   
242
    /*
285
    /*
243
     * Program the timer for periodic mode and respective vector.
286
     * Program the timer for periodic mode and respective vector.
244
     */
287
     */
245
 
288
 
246
    l_apic[TDCR] &= TDCRClear;
289
    l_apic[TDCR] &= TDCRClear;
247
    l_apic[TDCR] |= 0xb;
290
    l_apic[TDCR] |= 0xb;
-
 
291
 
248
    tmp = l_apic[LVT_Tm] | (1<<17) | (VECTOR_CLK);
292
    tm.value = l_apic[LVT_Tm];
-
 
293
    tm.vector = VECTOR_CLK;
-
 
294
    tm.mode = TIMER_PERIODIC;
-
 
295
    tm.masked = false;
249
    l_apic[LVT_Tm] = tmp & ~(1<<16);
296
    l_apic[LVT_Tm] = tm.value;
250
 
297
 
251
    t1 = l_apic[CCRT];
298
    t1 = l_apic[CCRT];
252
    l_apic[ICRT] = 0xffffffff;
299
    l_apic[ICRT] = 0xffffffff;
253
 
300
 
254
    while (l_apic[CCRT] == t1)
301
    while (l_apic[CCRT] == t1)