8db40b53949531f2bedc7d05d2cd4d807218ac0f
[dragonfly.git] / sys / platform / pc64 / 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 #ifndef LOCORE
20
21 /* XXX wrong header */
22 void    initializecpu(void);
23
24 #endif  /* LOCORE */
25
26 /*
27  * Size of APIC ID list.
28  * Also used a MAX size of various other arrays.
29  */
30 #define NAPICID         256
31
32 #if defined(SMP)
33
34 #ifndef LOCORE
35
36 /*
37  * For sending values to POST displays.
38  * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
39  */
40 extern int current_postcode;  /** XXX currently in mp_machdep.c */
41 #define POSTCODE(X)     current_postcode = (X), \
42                         outb(0x80, current_postcode)
43 #define POSTCODE_LO(X)  current_postcode &= 0xf0, \
44                         current_postcode |= ((X) & 0x0f), \
45                         outb(0x80, current_postcode)
46 #define POSTCODE_HI(X)  current_postcode &= 0x0f, \
47                         current_postcode |= (((X) << 4) & 0xf0), \
48                         outb(0x80, current_postcode)
49
50
51 #include <machine_base/apic/apicreg.h>
52 #include <machine/pcb.h>
53
54 /* global symbols in mpboot.S */
55 extern char                     mptramp_start[];
56 extern char                     mptramp_end[];
57 extern u_int32_t                mptramp_pagetables;
58
59 /* functions in mpboot.s */
60 void    bootMP                  (void);
61
62 /* global data in apic_vector.s */
63 extern volatile cpumask_t       stopped_cpus;
64 extern volatile cpumask_t       started_cpus;
65
66 extern volatile u_int           checkstate_probed_cpus;
67 extern void (*cpustop_restartfunc) (void);
68
69 /* functions in apic_ipl.s */
70 u_int   ioapic_read             (volatile void *, int);
71 void    ioapic_write            (volatile void *, int, u_int);
72
73 /* global data in mp_machdep.c */
74 extern int                      imcr_present;
75 extern int                      apic_io_enable;
76 extern int                      mp_naps;
77 extern u_int32_t                cpu_apic_versions[];
78 extern int                      cpu_num_to_apic_id[];
79 extern int                      apic_id_to_logical[];
80
81 #define APIC_INTMAPSIZE 192
82 /*
83  * NOTE:
84  * - Keep size of apic_intmapinfo power of 2
85  * - Update IOAPIC_IM_SZSHIFT after changing apic_intmapinfo size
86  */
87 struct apic_intmapinfo {
88         int ioapic;
89         int int_pin;
90         volatile void *apic_address;
91         int redirindex;
92         uint32_t flags;         /* IOAPIC_IM_FLAG_ */
93         uint32_t pad[2];
94 };
95 #define IOAPIC_IM_SZSHIFT       5
96
97 #define IOAPIC_IM_FLAG_LEVEL    0x1     /* default to edge trigger */
98 #define IOAPIC_IM_FLAG_MASKED   0x2
99
100 extern struct apic_intmapinfo   int_to_apicintpin[];
101 extern struct pcb               stoppcbs[];
102
103 /* functions in mp_machdep.c */
104 void    *ioapic_map(vm_paddr_t);
105 u_int   mp_bootaddress          (u_int);
106 void    mp_start                (void);
107 void    mp_announce             (void);
108 void    mp_set_cpuids           (int, int);
109 void    init_secondary          (void);
110 int     stop_cpus               (cpumask_t);
111 void    ap_init                 (void);
112 int     restart_cpus            (cpumask_t);
113 void    forward_signal          (struct proc *);
114 int     mptable_pci_int_route(int, int, int, int);
115 void    mptable_pci_int_dump(void);
116
117 #ifndef _SYS_QUEUE_H_
118 #include <sys/queue.h>
119 #endif
120
121 struct lapic_enumerator {
122         int     lapic_prio;
123         TAILQ_ENTRY(lapic_enumerator) lapic_link;
124         int     (*lapic_probe)(struct lapic_enumerator *);
125         void    (*lapic_enumerate)(struct lapic_enumerator *);
126 };
127
128 #define LAPIC_ENUM_PRIO_MPTABLE         20
129 #define LAPIC_ENUM_PRIO_MADT            40
130
131 struct ioapic_enumerator {
132         int     ioapic_prio;
133         TAILQ_ENTRY(ioapic_enumerator) ioapic_link;
134         int     (*ioapic_probe)(struct ioapic_enumerator *);
135         void    (*ioapic_enumerate)(struct ioapic_enumerator *);
136 };
137
138 #define IOAPIC_ENUM_PRIO_MPTABLE        20
139 #define IOAPIC_ENUM_PRIO_MADT           40
140
141 /* global data in mpapic.c */
142 extern volatile lapic_t         *lapic;
143
144 #ifndef _SYS_BUS_H_
145 #include <sys/bus.h>
146 #endif
147
148 /* functions in mpapic.c */
149 void    apic_dump               (char*);
150 void    lapic_init              (boolean_t);
151 int     apic_ipi                (int, int, int);
152 void    selected_apic_ipi       (cpumask_t, int, int);
153 void    single_apic_ipi(int cpu, int vector, int delivery_mode);
154 int     single_apic_ipi_passive(int cpu, int vector, int delivery_mode);
155 void    lapic_config(void);
156 void    lapic_enumerator_register(struct lapic_enumerator *);
157 void    ioapic_config(void);
158 void    ioapic_enumerator_register(struct ioapic_enumerator *);
159 void    ioapic_add(void *, int, int);
160 void    ioapic_intsrc(int, int, enum intr_trigger, enum intr_polarity);
161 void    *ioapic_gsi_ioaddr(int);
162 int     ioapic_gsi_pin(int);
163 void    ioapic_pin_setup(void *, int, int,
164             enum intr_trigger, enum intr_polarity);
165 void    ioapic_extpin_setup(void *, int, int);
166 int     ioapic_extpin_gsi(void);
167 int     ioapic_gsi(int, int);
168
169 #if defined(READY)
170 void    clr_io_apic_mask24      (int, u_int32_t);
171 void    set_io_apic_mask24      (int, u_int32_t);
172 #endif /* READY */
173
174 void    set_apic_timer          (int);
175 int     get_apic_timer_frequency(void);
176 int     read_apic_timer         (void);
177 void    u_sleep                 (int);
178 void    cpu_send_ipiq           (int);
179 int     cpu_send_ipiq_passive   (int);
180
181 /* global data in init_smp.c */
182 extern cpumask_t                smp_active_mask;
183
184 #endif /* !LOCORE */
185 #else   /* !SMP */
186
187 #define smp_active_mask 1       /* smp_active_mask always 1 on UP machines */
188
189 #endif
190
191 #endif /* _KERNEL */
192 #endif /* _MACHINE_SMP_H_ */