Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / i386 / include / apic.h
1 /*
2  * Copyright (c) 1996, by Peter Wemm and Steve Passe
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. The name of the developer may NOT be used to endorse or promote products
11  *    derived from this software without specific prior written permission.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD: src/sys/i386/include/apic.h,v 1.14.2.2 2003/03/21 21:46:15 jhb Exp $
26  * $DragonFly: src/sys/i386/include/Attic/apic.h,v 1.2 2003/06/17 04:28:35 dillon Exp $
27  */
28
29 #ifndef _MACHINE_APIC_H_
30 #define _MACHINE_APIC_H_
31
32 /*
33  * Local && I/O APIC definitions.
34  */
35
36 /*
37  * Pentium P54C+ Build-in APIC
38  * (Advanced programmable Interrupt Controller)
39  * 
40  * Base Address of Build-in APIC in memory location
41  * is 0xfee00000.
42  * 
43  * Map of APIC REgisters:
44  * 
45  * Offset (hex)    Description                     Read/Write state
46  * 000             Reserved
47  * 010             Reserved
48  * 020 ID          Local APIC ID                   R/W
49  * 030 VER         Local APIC Version              R
50  * 040             Reserved
51  * 050             Reserved
52  * 060             Reserved
53  * 070             Reserved
54  * 080             Task Priority Register          R/W
55  * 090             Arbitration Priority Register   R
56  * 0A0             Processor Priority Register     R
57  * 0B0             EOI Register                    W
58  * 0C0 RRR         Remote read                     R
59  * 0D0             Logical Destination             R/W
60  * 0E0             Destination Format Register     0..27 R;  28..31 R/W
61  * 0F0 SVR         Spurious Interrupt Vector Reg.  0..3  R;  4..9   R/W
62  * 100             ISR  000-031                    R
63  * 110             ISR  032-063                    R
64  * 120             ISR  064-095                    R
65  * 130             ISR  095-128                    R
66  * 140             ISR  128-159                    R
67  * 150             ISR  160-191                    R
68  * 160             ISR  192-223                    R
69  * 170             ISR  224-255                    R
70  * 180             TMR  000-031                    R
71  * 190             TMR  032-063                    R
72  * 1A0             TMR  064-095                    R
73  * 1B0             TMR  095-128                    R
74  * 1C0             TMR  128-159                    R
75  * 1D0             TMR  160-191                    R
76  * 1E0             TMR  192-223                    R
77  * 1F0             TMR  224-255                    R
78  * 200             IRR  000-031                    R
79  * 210             IRR  032-063                    R
80  * 220             IRR  064-095                    R
81  * 230             IRR  095-128                    R
82  * 240             IRR  128-159                    R
83  * 250             IRR  160-191                    R
84  * 260             IRR  192-223                    R
85  * 270             IRR  224-255                    R
86  * 280             Error Status Register           R
87  * 290             Reserved
88  * 2A0             Reserved
89  * 2B0             Reserved
90  * 2C0             Reserved
91  * 2D0             Reserved
92  * 2E0             Reserved
93  * 2F0             Reserved
94  * 300 ICR_LOW     Interrupt Command Reg. (0-31)   R/W
95  * 310 ICR_HI      Interrupt Command Reg. (32-63)  R/W
96  * 320             Local Vector Table (Timer)      R/W
97  * 330             Reserved
98  * 340             Reserved
99  * 350 LVT1        Local Vector Table (LINT0)      R/W
100  * 360 LVT2        Local Vector Table (LINT1)      R/W
101  * 370 LVT3        Local Vector Table (ERROR)      R/W
102  * 380             Initial Count Reg. for Timer    R/W
103  * 390             Current Count of Timer          R
104  * 3A0             Reserved
105  * 3B0             Reserved
106  * 3C0             Reserved
107  * 3D0             Reserved
108  * 3E0             Timer Divide Configuration Reg. R/W
109  * 3F0             Reserved
110  */
111
112
113 /******************************************************************************
114  * global defines, etc.
115  */
116
117
118 /******************************************************************************
119  * LOCAL APIC structure
120  */
121
122 #ifndef LOCORE
123 #include <sys/types.h>
124
125 #define PAD3    int : 32; int : 32; int : 32
126 #define PAD4    int : 32; int : 32; int : 32; int : 32
127
128 struct LAPIC {
129         /* reserved */          PAD4;
130         /* reserved */          PAD4;
131         u_int32_t id;           PAD3;
132         u_int32_t version;      PAD3;
133         /* reserved */          PAD4;
134         /* reserved */          PAD4;
135         /* reserved */          PAD4;
136         /* reserved */          PAD4;
137         u_int32_t tpr;          PAD3;
138         u_int32_t apr;          PAD3;
139         u_int32_t ppr;          PAD3;
140         u_int32_t eoi;          PAD3;
141         /* reserved */          PAD4;
142         u_int32_t ldr;          PAD3;
143         u_int32_t dfr;          PAD3;
144         u_int32_t svr;          PAD3;
145         u_int32_t isr0;         PAD3;
146         u_int32_t isr1;         PAD3;
147         u_int32_t isr2;         PAD3;
148         u_int32_t isr3;         PAD3;
149         u_int32_t isr4;         PAD3;
150         u_int32_t isr5;         PAD3;
151         u_int32_t isr6;         PAD3;
152         u_int32_t isr7;         PAD3;
153         u_int32_t tmr0;         PAD3;
154         u_int32_t tmr1;         PAD3;
155         u_int32_t tmr2;         PAD3;
156         u_int32_t tmr3;         PAD3;
157         u_int32_t tmr4;         PAD3;
158         u_int32_t tmr5;         PAD3;
159         u_int32_t tmr6;         PAD3;
160         u_int32_t tmr7;         PAD3;
161         u_int32_t irr0;         PAD3;
162         u_int32_t irr1;         PAD3;
163         u_int32_t irr2;         PAD3;
164         u_int32_t irr3;         PAD3;
165         u_int32_t irr4;         PAD3;
166         u_int32_t irr5;         PAD3;
167         u_int32_t irr6;         PAD3;
168         u_int32_t irr7;         PAD3;
169         u_int32_t esr;          PAD3;
170         /* reserved */          PAD4;
171         /* reserved */          PAD4;
172         /* reserved */          PAD4;
173         /* reserved */          PAD4;
174         /* reserved */          PAD4;
175         /* reserved */          PAD4;
176         /* reserved */          PAD4;
177         u_int32_t icr_lo;       PAD3;
178         u_int32_t icr_hi;       PAD3;
179         u_int32_t lvt_timer;    PAD3;
180         /* reserved */          PAD4;
181         u_int32_t lvt_pcint;    PAD3;
182         u_int32_t lvt_lint0;    PAD3;
183         u_int32_t lvt_lint1;    PAD3;
184         u_int32_t lvt_error;    PAD3;
185         u_int32_t icr_timer;    PAD3;
186         u_int32_t ccr_timer;    PAD3;
187         /* reserved */          PAD4;
188         /* reserved */          PAD4;
189         /* reserved */          PAD4;
190         /* reserved */          PAD4;
191         u_int32_t dcr_timer;    PAD3;
192         /* reserved */          PAD4;
193 };
194
195 typedef struct LAPIC lapic_t;
196
197 /******************************************************************************
198  * I/O APIC structure
199  */
200
201 struct IOAPIC {
202         u_int32_t ioregsel;     PAD3;
203         u_int32_t iowin;        PAD3;
204 };
205
206 typedef struct IOAPIC ioapic_t;
207
208 #undef PAD4
209 #undef PAD3
210
211 #endif  /* !LOCORE */
212
213
214 /******************************************************************************
215  * various code 'logical' values
216  */
217
218 #ifdef GRAB_LOPRIO
219 #define LOPRIO_LEVEL            0x00000010      /* TPR of CPU accepting INTs */
220 #define ALLHWI_LEVEL            0x00000000      /* TPR of CPU grabbing INTs */
221 #endif /** GRAB_LOPRIO */
222
223 /* XXX these 2 don't really belong here... */
224 #define COUNT_FIELD             0x00ffffff      /* count portion of the lock */
225 #define CPU_FIELD               0xff000000      /* cpu portion of the lock */
226 #define FREE_LOCK               0xffffffff      /* value of lock when free */
227
228 /*
229  * XXX This code assummes that the reserved field of the
230  *      local APIC TPR can be written with all 0s.
231  *     This saves quite a few memory accesses.
232  *     If the silicon ever changes then things will break!
233  *     It affects mplock.s, swtch.s, and possibly other files.
234  */
235 #define CHEAP_TPR
236
237
238 /******************************************************************************
239  * LOCAL APIC defines
240  */
241
242 /* default physical locations of LOCAL (CPU) APICs */
243 #define DEFAULT_APIC_BASE       0xfee00000
244
245 /* fields in VER */
246 #define APIC_VER_VERSION        0x000000ff
247 #define APIC_VER_MAXLVT         0x00ff0000
248 #define MAXLVTSHIFT             16
249
250 /* fields in SVR */
251 #define APIC_SVR_VECTOR         0x000000ff
252 #define APIC_SVR_VEC_PROG       0x000000f0
253 #define APIC_SVR_VEC_FIX        0x0000000f
254 #define APIC_SVR_ENABLE         0x00000100
255 # define APIC_SVR_SWDIS         0x00000000
256 # define APIC_SVR_SWEN          0x00000100
257 #define APIC_SVR_FOCUS          0x00000200
258 # define APIC_SVR_FEN           0x00000000
259 # define APIC_SVR_FDIS          0x00000200
260
261 /* fields in TPR */
262 #define APIC_TPR_PRIO           0x000000ff
263 # define APIC_TPR_INT           0x000000f0
264 # define APIC_TPR_SUB           0x0000000f
265
266
267 /* fields in ICR_LOW */
268 #define APIC_VECTOR_MASK        0x000000ff
269
270 #define APIC_DELMODE_MASK       0x00000700
271 # define APIC_DELMODE_FIXED     0x00000000
272 # define APIC_DELMODE_LOWPRIO   0x00000100
273 # define APIC_DELMODE_SMI       0x00000200
274 # define APIC_DELMODE_RR        0x00000300
275 # define APIC_DELMODE_NMI       0x00000400
276 # define APIC_DELMODE_INIT      0x00000500
277 # define APIC_DELMODE_STARTUP   0x00000600
278 # define APIC_DELMODE_RESV      0x00000700
279
280 #define APIC_DESTMODE_MASK      0x00000800
281 # define APIC_DESTMODE_PHY      0x00000000
282 # define APIC_DESTMODE_LOG      0x00000800
283
284 #define APIC_DELSTAT_MASK       0x00001000
285 # define APIC_DELSTAT_IDLE      0x00000000
286 # define APIC_DELSTAT_PEND      0x00001000
287
288 #define APIC_RESV1_MASK         0x00002000
289
290 #define APIC_LEVEL_MASK         0x00004000
291 # define APIC_LEVEL_DEASSERT    0x00000000
292 # define APIC_LEVEL_ASSERT      0x00004000
293
294 #define APIC_TRIGMOD_MASK       0x00008000
295 # define APIC_TRIGMOD_EDGE      0x00000000
296 # define APIC_TRIGMOD_LEVEL     0x00008000
297
298 #define APIC_RRSTAT_MASK        0x00030000
299 # define APIC_RRSTAT_INVALID    0x00000000
300 # define APIC_RRSTAT_INPROG     0x00010000
301 # define APIC_RRSTAT_VALID      0x00020000
302 # define APIC_RRSTAT_RESV       0x00030000
303
304 #define APIC_DEST_MASK          0x000c0000
305 # define APIC_DEST_DESTFLD      0x00000000
306 # define APIC_DEST_SELF         0x00040000
307 # define APIC_DEST_ALLISELF     0x00080000
308 # define APIC_DEST_ALLESELF     0x000c0000
309
310 #define APIC_RESV2_MASK         0xfff00000
311
312
313 /* fields in ICR_HIGH */
314 #define APIC_ID_MASK            0xff000000
315
316
317 /* fields in LVT1/2 */
318 #define APIC_LVT_VECTOR         0x000000ff
319 #define APIC_LVT_DM             0x00000700
320 # define APIC_LVT_DM_FIXED      0x00000000
321 # define APIC_LVT_DM_NMI        0x00000400
322 # define APIC_LVT_DM_EXTINT     0x00000700
323 #define APIC_LVT_DS             0x00001000
324 #define APIC_LVT_IIPP           0x00002000
325 #define APIC_LVT_IIPP_INTALO    0x00002000
326 #define APIC_LVT_IIPP_INTAHI    0x00000000
327 #define APIC_LVT_RIRR           0x00004000
328 #define APIC_LVT_TM             0x00008000
329 #define APIC_LVT_M              0x00010000
330
331
332 /* fields in LVT Timer */
333 #define APIC_LVTT_VECTOR        0x000000ff
334 #define APIC_LVTT_DS            0x00001000
335 #define APIC_LVTT_M             0x00010000
336 #define APIC_LVTT_TM            0x00020000
337
338
339 /* fields in TDCR */
340 #define APIC_TDCR_2             0x00
341 #define APIC_TDCR_4             0x01
342 #define APIC_TDCR_8             0x02
343 #define APIC_TDCR_16            0x03
344 #define APIC_TDCR_32            0x08
345 #define APIC_TDCR_64            0x09
346 #define APIC_TDCR_128           0x0a
347 #define APIC_TDCR_1             0x0b
348
349
350 /*
351  * fields in IRR
352  * ISA INTerrupts are in bits 16-31 of the 1st IRR register.
353  * these masks DON'T EQUAL the isa IRQs of the same name.
354  */
355 #define APIC_IRQ0               0x00000001
356 #define APIC_IRQ1               0x00000002
357 #define APIC_IRQ2               0x00000004
358 #define APIC_IRQ3               0x00000008
359 #define APIC_IRQ4               0x00000010
360 #define APIC_IRQ5               0x00000020
361 #define APIC_IRQ6               0x00000040
362 #define APIC_IRQ7               0x00000080
363 #define APIC_IRQ8               0x00000100
364 #define APIC_IRQ9               0x00000200
365 #define APIC_IRQ10              0x00000400
366 #define APIC_IRQ11              0x00000800
367 #define APIC_IRQ12              0x00001000
368 #define APIC_IRQ13              0x00002000
369 #define APIC_IRQ14              0x00004000
370 #define APIC_IRQ15              0x00008000
371 #define APIC_IRQ16              0x00010000
372 #define APIC_IRQ17              0x00020000
373 #define APIC_IRQ18              0x00040000
374 #define APIC_IRQ19              0x00080000
375 #define APIC_IRQ20              0x00100000
376 #define APIC_IRQ21              0x00200000
377 #define APIC_IRQ22              0x00400000
378 #define APIC_IRQ23              0x00800000
379
380
381 /******************************************************************************
382  * I/O APIC defines
383  */
384
385 /* default physical locations of an IO APIC */
386 #define DEFAULT_IO_APIC_BASE    0xfec00000
387
388 /* window register offset */
389 #define IOAPIC_WINDOW           0x10
390
391 /* indexes into IO APIC */
392 #define IOAPIC_ID               0x00
393 #define IOAPIC_VER              0x01
394 #define IOAPIC_ARB              0x02
395 #define IOAPIC_REDTBL           0x10
396 #define IOAPIC_REDTBL0          IOAPIC_REDTBL
397 #define IOAPIC_REDTBL1          (IOAPIC_REDTBL+0x02)
398 #define IOAPIC_REDTBL2          (IOAPIC_REDTBL+0x04)
399 #define IOAPIC_REDTBL3          (IOAPIC_REDTBL+0x06)
400 #define IOAPIC_REDTBL4          (IOAPIC_REDTBL+0x08)
401 #define IOAPIC_REDTBL5          (IOAPIC_REDTBL+0x0a)
402 #define IOAPIC_REDTBL6          (IOAPIC_REDTBL+0x0c)
403 #define IOAPIC_REDTBL7          (IOAPIC_REDTBL+0x0e)
404 #define IOAPIC_REDTBL8          (IOAPIC_REDTBL+0x10)
405 #define IOAPIC_REDTBL9          (IOAPIC_REDTBL+0x12)
406 #define IOAPIC_REDTBL10         (IOAPIC_REDTBL+0x14)
407 #define IOAPIC_REDTBL11         (IOAPIC_REDTBL+0x16)
408 #define IOAPIC_REDTBL12         (IOAPIC_REDTBL+0x18)
409 #define IOAPIC_REDTBL13         (IOAPIC_REDTBL+0x1a)
410 #define IOAPIC_REDTBL14         (IOAPIC_REDTBL+0x1c)
411 #define IOAPIC_REDTBL15         (IOAPIC_REDTBL+0x1e)
412 #define IOAPIC_REDTBL16         (IOAPIC_REDTBL+0x20)
413 #define IOAPIC_REDTBL17         (IOAPIC_REDTBL+0x22)
414 #define IOAPIC_REDTBL18         (IOAPIC_REDTBL+0x24)
415 #define IOAPIC_REDTBL19         (IOAPIC_REDTBL+0x26)
416 #define IOAPIC_REDTBL20         (IOAPIC_REDTBL+0x28)
417 #define IOAPIC_REDTBL21         (IOAPIC_REDTBL+0x2a)
418 #define IOAPIC_REDTBL22         (IOAPIC_REDTBL+0x2c)
419 #define IOAPIC_REDTBL23         (IOAPIC_REDTBL+0x2e)
420
421 /* fields in VER */
422 #define IOART_VER_VERSION       0x000000ff
423 #define IOART_VER_MAXREDIR      0x00ff0000
424 #define MAXREDIRSHIFT           16
425
426 /*
427  * fields in the IO APIC's redirection table entries
428  */
429 #define IOART_DEST      APIC_ID_MASK    /* broadcast addr: all APICs */
430
431 #define IOART_RESV      0x00fe0000      /* reserved */
432
433 #define IOART_INTMASK   0x00010000      /* R/W: INTerrupt mask */
434 # define IOART_INTMCLR  0x00000000      /*       clear, allow INTs */
435 # define IOART_INTMSET  0x00010000      /*       set, inhibit INTs */
436
437 #define IOART_TRGRMOD   0x00008000      /* R/W: trigger mode */
438 # define IOART_TRGREDG  0x00000000      /*       edge */
439 # define IOART_TRGRLVL  0x00008000      /*       level */
440
441 #define IOART_REM_IRR   0x00004000      /* RO: remote IRR */
442
443 #define IOART_INTPOL    0x00002000      /* R/W: INT input pin polarity */
444 # define IOART_INTAHI   0x00000000      /*      active high */
445 # define IOART_INTALO   0x00002000      /*      active low */
446
447 #define IOART_DELIVS    0x00001000      /* RO: delivery status */
448
449 #define IOART_DESTMOD   0x00000800      /* R/W: destination mode */
450 # define IOART_DESTPHY  0x00000000      /*      physical */
451 # define IOART_DESTLOG  0x00000800      /*      logical */
452
453 #define IOART_DELMOD    0x00000700      /* R/W: delivery mode */
454 # define IOART_DELFIXED 0x00000000      /*       fixed */
455 # define IOART_DELLOPRI 0x00000100      /*       lowest priority */
456 # define IOART_DELSMI   0x00000200      /*       System Management INT */
457 # define IOART_DELRSV1  0x00000300      /*       reserved */
458 # define IOART_DELNMI   0x00000400      /*       NMI signal */
459 # define IOART_DELINIT  0x00000500      /*       INIT signal */
460 # define IOART_DELRSV2  0x00000600      /*       reserved */
461 # define IOART_DELEXINT 0x00000700      /*       External INTerrupt */
462
463 #define IOART_INTVEC    0x000000ff      /* R/W: INTerrupt vector field */
464
465 #endif /* _MACHINE_APIC_H_ */