Merge branch 'vendor/GMP'
[dragonfly.git] / sys / platform / pc32 / include / smp.h
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD: src/sys/i386/include/smp.h,v 1.50.2.5 2001/02/13 22:32:45 tegge Exp $
10  * $DragonFly: src/sys/platform/pc32/include/smp.h,v 1.20 2006/11/07 06:43:24 dillon Exp $
11  *
12  */
13
14 #ifndef _MACHINE_SMP_H_
15 #define _MACHINE_SMP_H_
16
17 #ifdef _KERNEL
18
19 #if defined(SMP)
20
21 #ifndef LOCORE
22
23 /*
24  * For sending values to POST displays.
25  * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
26  */
27 extern int current_postcode;  /** XXX currently in mp_machdep.c */
28 #define POSTCODE(X)     current_postcode = (X), \
29                         outb(0x80, current_postcode)
30 #define POSTCODE_LO(X)  current_postcode &= 0xf0, \
31                         current_postcode |= ((X) & 0x0f), \
32                         outb(0x80, current_postcode)
33 #define POSTCODE_HI(X)  current_postcode &= 0x0f, \
34                         current_postcode |= (((X) << 4) & 0xf0), \
35                         outb(0x80, current_postcode)
36
37
38 #include <machine_base/apic/apicreg.h>
39 #include <machine/pcb.h>
40
41 /* global data in mpboot.s */
42 extern int                      bootMP_size;
43
44 /* functions in mpboot.s */
45 void    bootMP                  (void);
46
47 /* global data in apic_vector.s */
48 extern volatile cpumask_t       stopped_cpus;
49 extern volatile cpumask_t       started_cpus;
50
51 extern volatile u_int           checkstate_probed_cpus;
52 extern void (*cpustop_restartfunc) (void);
53
54 /* functions in apic_ipl.s */
55 u_int   ioapic_read             (volatile void *, int);
56 void    ioapic_write            (volatile void *, int, u_int);
57
58 /* global data in mp_machdep.c */
59 extern int                      imcr_present;
60 extern int                      mp_naps;
61 extern int                      mp_napics;
62 extern vm_offset_t              io_apic_address[];
63 extern u_int32_t                cpu_apic_versions[];
64 extern u_int32_t                *io_apic_versions;
65 extern int                      cpu_num_to_apic_id[];
66 extern int                      io_num_to_apic_id[];
67 extern int                      apic_id_to_logical[];
68 #define APIC_INTMAPSIZE 192
69 /*
70  * NOTE:
71  * - Keep size of apic_intmapinfo power of 2
72  * - Update IOAPIC_IM_SZSHIFT after changing apic_intmapinfo size
73  */
74 struct apic_intmapinfo {
75         int ioapic;
76         int int_pin;
77         volatile void *apic_address;
78         int redirindex;
79         uint32_t flags;         /* IOAPIC_IM_FLAG_ */
80         uint32_t pad[3];
81 };
82 #define IOAPIC_IM_SZSHIFT       5
83
84 #define IOAPIC_IM_FLAG_LEVEL    0x1     /* default to edge trigger */
85 #define IOAPIC_IM_FLAG_MASKED   0x2
86
87 extern struct apic_intmapinfo   int_to_apicintpin[];
88 extern struct pcb               stoppcbs[];
89
90 /* functions in mp_machdep.c */
91 void    *ioapic_map(vm_paddr_t);
92 u_int   mp_bootaddress          (u_int);
93 void    mp_start                (void);
94 void    mp_announce             (void);
95 void    mp_set_cpuids           (int, int);
96 u_int   isa_apic_mask           (u_int);
97 int     isa_apic_irq            (int);
98 int     pci_apic_irq            (int, int, int);
99 int     apic_irq                (int, int);
100 int     next_apic_irq           (int);
101 int     undirect_isa_irq        (int);
102 int     undirect_pci_irq        (int);
103 int     apic_bus_type           (int);
104 int     apic_src_bus_id         (int, int);
105 int     apic_src_bus_irq        (int, int);
106 int     apic_int_type           (int, int);
107 int     apic_trigger            (int, int);
108 int     apic_polarity           (int, int);
109 void    assign_apic_irq         (int apic, int intpin, int irq);
110 void    revoke_apic_irq         (int irq);
111 void    init_secondary          (void);
112 int     stop_cpus               (cpumask_t);
113 void    ap_init                 (void);
114 int     restart_cpus            (cpumask_t);
115 void    forward_signal          (struct proc *);
116 int     mptable_pci_int_route(int, int, int, int);
117 void    mptable_pci_int_dump(void);
118
119 #ifndef _SYS_QUEUE_H_
120 #include <sys/queue.h>
121 #endif
122
123 struct lapic_enumerator {
124         int     lapic_prio;
125         TAILQ_ENTRY(lapic_enumerator) lapic_link;
126         int     (*lapic_probe)(struct lapic_enumerator *);
127         void    (*lapic_enumerate)(struct lapic_enumerator *);
128 };
129
130 #define LAPIC_ENUM_PRIO_MPTABLE         20
131 #define LAPIC_ENUM_PRIO_MADT            40
132
133 struct ioapic_enumerator {
134         int     ioapic_prio;
135         TAILQ_ENTRY(ioapic_enumerator) ioapic_link;
136         int     (*ioapic_probe)(struct ioapic_enumerator *);
137         void    (*ioapic_enumerate)(struct ioapic_enumerator *);
138 };
139
140 #define IOAPIC_ENUM_PRIO_MPTABLE        20
141 #define IOAPIC_ENUM_PRIO_MADT           40
142
143 /* global data in mpapic.c */
144 extern volatile lapic_t         lapic;
145 extern volatile ioapic_t        **ioapic;
146 extern int                      lapic_id_max;
147
148 #ifndef _SYS_BUS_H_
149 #include <sys/bus.h>
150 #endif
151
152 /* functions in mpapic.c */
153 void    apic_dump               (char*);
154 void    lapic_init              (boolean_t);
155 void    imen_dump               (void);
156 int     apic_ipi                (int, int, int);
157 void    selected_apic_ipi       (cpumask_t, int, int);
158 void    single_apic_ipi(int cpu, int vector, int delivery_mode);
159 int     single_apic_ipi_passive(int cpu, int vector, int delivery_mode);
160 int     io_apic_setup           (int);
161 void    io_apic_setup_intpin    (int, int);
162 void    io_apic_set_id          (int, int);
163 int     io_apic_get_id          (int);
164 int     ext_int_setup           (int, int);
165 void    lapic_config(void);
166 void    lapic_enumerator_register(struct lapic_enumerator *);
167 void    ioapic_config(void);
168 void    ioapic_enumerator_register(struct ioapic_enumerator *);
169 void    ioapic_add(void *, int, int);
170 void    ioapic_intsrc(int, int, enum intr_trigger, enum intr_polarity);
171 void    *ioapic_gsi_ioaddr(int);
172 int     ioapic_gsi_pin(int);
173 void    ioapic_pin_setup(void *, int, int,
174             enum intr_trigger, enum intr_polarity);
175 void    ioapic_extpin_setup(void *, int, int);
176 int     ioapic_extpin_gsi(void);
177 int     ioapic_gsi(int, int);
178
179 extern int apic_io_enable;
180 extern int ioapic_use_old;
181
182 #if defined(READY)
183 void    clr_io_apic_mask24      (int, u_int32_t);
184 void    set_io_apic_mask24      (int, u_int32_t);
185 #endif /* READY */
186
187 void    set_apic_timer          (int);
188 int     get_apic_timer_frequency(void);
189 int     read_apic_timer         (void);
190 void    u_sleep                 (int);
191 void    cpu_send_ipiq           (int);
192 int     cpu_send_ipiq_passive   (int);
193
194 /* global data in init_smp.c */
195 extern cpumask_t                smp_active_mask;
196
197 #endif /* !LOCORE */
198 #else   /* !SMP */
199
200 #define smp_active_mask 1       /* smp_active_mask always 1 on UP machines */
201
202 #endif
203
204 #endif /* _KERNEL */
205 #endif /* _MACHINE_SMP_H_ */