Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / sys / i386 / apic / apicvar.h
1 /*-
2  * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
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. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/sys/i386/include/apicvar.h,v 1.5 2003/11/14 22:21:30 peter Exp $
30  * $DragonFly: src/sys/i386/apic/Attic/apicvar.h,v 1.2 2004/06/27 08:52:46 dillon Exp $
31  */
32
33 #ifndef _MACHINE_APICVAR_H_
34 #define _MACHINE_APICVAR_H_
35
36 /*
37  * Local && I/O APIC variable definitions.
38  */
39
40 /*
41  * Layout of local APIC interrupt vectors:
42  *
43  *      0xff (255)  +-------------+
44  *                  |             | 15 (Spurious / IPIs / Local Interrupts)
45  *      0xf0 (240)  +-------------+
46  *                  |             | 14 (I/O Interrupts)
47  *      0xe0 (224)  +-------------+
48  *                  |             | 13 (I/O Interrupts)
49  *      0xd0 (208)  +-------------+
50  *                  |             | 12 (I/O Interrupts)
51  *      0xc0 (192)  +-------------+
52  *                  |             | 11 (I/O Interrupts)
53  *      0xb0 (176)  +-------------+
54  *                  |             | 10 (I/O Interrupts)
55  *      0xa0 (160)  +-------------+
56  *                  |             | 9 (I/O Interrupts)
57  *      0x90 (144)  +-------------+
58  *                  |             | 8 (I/O Interrupts / System Calls)
59  *      0x80 (128)  +-------------+
60  *                  |             | 7 (I/O Interrupts)
61  *      0x70 (112)  +-------------+
62  *                  |             | 6 (I/O Interrupts)
63  *      0x60 (96)   +-------------+
64  *                  |             | 5 (I/O Interrupts)
65  *      0x50 (80)   +-------------+
66  *                  |             | 4 (I/O Interrupts)
67  *      0x40 (64)   +-------------+
68  *                  |             | 3 (I/O Interrupts)
69  *      0x30 (48)   +-------------+
70  *                  |             | 2 (ATPIC Interrupts)
71  *      0x20 (32)   +-------------+
72  *                  |             | 1 (Exceptions, traps, faults, etc.)
73  *      0x10 (16)   +-------------+
74  *                  |             | 0 (Exceptions, traps, faults, etc.)
75  *      0x00 (0)    +-------------+
76  *
77  * Note: 0x80 needs to be handled specially and not allocated to an
78  * I/O device!
79  */
80
81 #define APIC_ID_ALL     0xff
82 #define APIC_IO_INTS    (IDT_IO_INTS + 16)
83 #define APIC_NUM_IOINTS 192
84
85 #define APIC_LOCAL_INTS 240
86
87 /* XXX put APIC interrupt and IPI assignments here */
88
89 #define APIC_SPURIOUS_INT 255
90
91 #define LVT_LINT0       0
92 #define LVT_LINT1       1
93 #define LVT_TIMER       2
94 #define LVT_ERROR       3
95 #define LVT_PMC         4
96 #define LVT_THERMAL     5
97 #define LVT_MAX         LVT_THERMAL
98
99 #ifndef LOCORE
100
101 #define APIC_IPI_DEST_SELF      -1
102 #define APIC_IPI_DEST_ALL       -2
103 #define APIC_IPI_DEST_OTHERS    -3
104
105 /*
106  * An APIC enumerator is a psuedo bus driver that enumerates APIC's including
107  * CPU's and I/O APIC's.
108  */
109 struct apic_enumerator {
110         const char *apic_name;
111         int (*apic_probe)(void);
112         int (*apic_probe_cpus)(void);
113         int (*apic_setup_local)(void);
114         int (*apic_setup_io)(void);
115         SLIST_ENTRY(apic_enumerator) apic_next;
116 };
117
118 #if 0
119 inthand_t
120         IDTVEC(apic_isr1), IDTVEC(apic_isr2), IDTVEC(apic_isr3),
121         IDTVEC(apic_isr4), IDTVEC(apic_isr5), IDTVEC(apic_isr6),
122         IDTVEC(apic_isr7), IDTVEC(spuriousint);
123 #endif
124
125 u_int   apic_irq_to_idt(u_int irq);
126 u_int   apic_idt_to_irq(u_int vector);
127 void    apic_register_enumerator(struct apic_enumerator *enumerator);
128 void    *ioapic_create(uintptr_t addr, int32_t id, int intbase);
129 int     ioapic_disable_pin(void *cookie, u_int pin);
130 void    ioapic_enable_mixed_mode(void);
131 int     ioapic_get_vector(void *cookie, u_int pin);
132 int     ioapic_next_logical_cluster(void);
133 void    ioapic_register(void *cookie);
134 int     ioapic_remap_vector(void *cookie, u_int pin, int vector);
135 int     ioapic_set_extint(void *cookie, u_int pin);
136 int     ioapic_set_nmi(void *cookie, u_int pin);
137 int     ioapic_set_polarity(void *cookie, u_int pin, char activehi);
138 int     ioapic_set_triggermode(void *cookie, u_int pin, char edgetrigger);
139 int     ioapic_set_smi(void *cookie, u_int pin);
140 void    lapic_create(u_int apic_id, int boot_cpu);
141 void    lapic_disable(void);
142 void    lapic_dump(const char *str);
143 void    lapic_enable_intr(u_int vector);
144 void    lapic_eoi(void);
145 int     lapic_id(void);
146 void    lapic_init(uintptr_t addr);
147 int     lapic_intr_pending(u_int vector);
148 void    lapic_ipi_raw(register_t icrlo, u_int dest);
149 void    lapic_ipi_vectored(u_int vector, int dest);
150 int     lapic_ipi_wait(int delay);
151 void    lapic_handle_intr(struct intrframe frame);
152 void    lapic_set_logical_id(u_int apic_id, u_int cluster, u_int cluster_id);
153 int     lapic_set_lvt_mask(u_int apic_id, u_int lvt, u_char masked);
154 int     lapic_set_lvt_mode(u_int apic_id, u_int lvt, u_int32_t mode);
155 int     lapic_set_lvt_polarity(u_int apic_id, u_int lvt, u_char activehi);
156 int     lapic_set_lvt_triggermode(u_int apic_id, u_int lvt, u_char edgetrigger);
157 void    lapic_setup(void);
158
159 #endif /* !LOCORE */
160 #endif /* _MACHINE_APICVAR_H_ */