MP Implementation 2/4: Implement a poor-man's IPI messaging subsystem,
[dragonfly.git] / sys / i386 / 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/i386/include/Attic/smp.h,v 1.4 2003/07/08 06:27:27 dillon Exp $
11  *
12  */
13
14 #ifndef _MACHINE_SMP_H_
15 #define _MACHINE_SMP_H_
16
17 #ifdef _KERNEL
18
19 #if defined(SMP) && !defined(APIC_IO)
20 # error APIC_IO required for SMP, add "options APIC_IO" to your config file.
21 #endif /* SMP && !APIC_IO */
22
23 #if defined(SMP) || defined(APIC_IO)
24
25 #ifndef LOCORE
26
27 /*
28  * For sending values to POST displays.
29  * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
30  */
31 extern int current_postcode;  /** XXX currently in mp_machdep.c */
32 #define POSTCODE(X)     current_postcode = (X), \
33                         outb(0x80, current_postcode)
34 #define POSTCODE_LO(X)  current_postcode &= 0xf0, \
35                         current_postcode |= ((X) & 0x0f), \
36                         outb(0x80, current_postcode)
37 #define POSTCODE_HI(X)  current_postcode &= 0x0f, \
38                         current_postcode |= (((X) << 4) & 0xf0), \
39                         outb(0x80, current_postcode)
40
41
42 #include <machine/apic.h>
43
44 /* global data in mpboot.s */
45 extern int                      bootMP_size;
46
47 /* functions in mpboot.s */
48 void    bootMP                  __P((void));
49
50 /* global data in apic_vector.s */
51 extern volatile u_int           stopped_cpus;
52 extern volatile u_int           started_cpus;
53
54 extern volatile u_int           checkstate_probed_cpus;
55 extern volatile u_int           checkstate_need_ast;
56 extern volatile u_int           resched_cpus;
57 extern void (*cpustop_restartfunc) __P((void));
58
59 /* functions in apic_ipl.s */
60 void    apic_eoi                __P((void));
61 u_int   io_apic_read            __P((int, int));
62 void    io_apic_write           __P((int, int, u_int));
63
64 /* global data in mp_machdep.c */
65 extern int                      bsp_apic_ready;
66 extern int                      mp_naps;
67 extern int                      mp_nbusses;
68 extern int                      mp_napics;
69 extern int                      mp_picmode;
70 extern int                      boot_cpu_id;
71 extern vm_offset_t              cpu_apic_address;
72 extern vm_offset_t              io_apic_address[];
73 extern u_int32_t                cpu_apic_versions[];
74 extern u_int32_t                *io_apic_versions;
75 extern int                      cpu_num_to_apic_id[];
76 extern int                      io_num_to_apic_id[];
77 extern int                      apic_id_to_logical[];
78 #define APIC_INTMAPSIZE 24
79 struct apic_intmapinfo {
80         int ioapic;
81         int int_pin;
82         volatile void *apic_address;
83         int redirindex;
84 };
85 extern struct apic_intmapinfo   int_to_apicintpin[];
86 extern u_int                    all_cpus;
87 extern struct pcb               stoppcbs[];
88
89 /* functions in mp_machdep.c */
90 u_int   mp_bootaddress          __P((u_int));
91 int     mp_probe                __P((void));
92 void    mp_start                __P((void));
93 void    mp_announce             __P((void));
94 u_int   isa_apic_mask           __P((u_int));
95 int     isa_apic_irq            __P((int));
96 int     pci_apic_irq            __P((int, int, int));
97 int     apic_irq                __P((int, int));
98 int     next_apic_irq           __P((int));
99 int     undirect_isa_irq        __P((int));
100 int     undirect_pci_irq        __P((int));
101 int     apic_bus_type           __P((int));
102 int     apic_src_bus_id         __P((int, int));
103 int     apic_src_bus_irq        __P((int, int));
104 int     apic_int_type           __P((int, int));
105 int     apic_trigger            __P((int, int));
106 int     apic_polarity           __P((int, int));
107 void    assign_apic_irq         __P((int apic, int intpin, int irq));
108 void    revoke_apic_irq         __P((int irq));
109 void    bsp_apic_configure      __P((void));
110 void    init_secondary          __P((void));
111 int     stop_cpus               __P((u_int));
112 void    ap_init                 __P((void));
113 int     restart_cpus            __P((u_int));
114 #ifdef BETTER_CLOCK 
115 void    forward_statclock       __P((int pscnt));
116 void    forward_hardclock       __P((int pscnt));
117 #endif /* BETTER_CLOCK */
118 void    forward_signal          __P((struct proc *));
119 void    forward_roundrobin      __P((void));
120 #ifdef  APIC_INTR_REORDER
121 void    set_lapic_isrloc        __P((int, int));
122 #endif /* APIC_INTR_REORDER */
123 void    smp_rendezvous_action   __P((void));
124 void    smp_rendezvous          __P((void (*)(void *), 
125                                      void (*)(void *),
126                                      void (*)(void *),
127                                      void *arg));
128
129 /* global data in mpapic.c */
130 extern volatile lapic_t         lapic;
131 extern volatile ioapic_t        **ioapic;
132
133 /* functions in mpapic.c */
134 void    apic_dump               __P((char*));
135 void    apic_initialize         __P((void));
136 void    imen_dump               __P((void));
137 int     apic_ipi                __P((int, int, int));
138 int     selected_apic_ipi       __P((u_int, int, int));
139 int     io_apic_setup           __P((int));
140 void    io_apic_setup_intpin    __P((int, int));
141 void    io_apic_set_id          __P((int, int));
142 int     io_apic_get_id          __P((int));
143 int     ext_int_setup           __P((int, int));
144
145 #if defined(READY)
146 void    clr_io_apic_mask24      __P((int, u_int32_t));
147 void    set_io_apic_mask24      __P((int, u_int32_t));
148 #endif /* READY */
149
150 void    set_apic_timer          __P((int));
151 int     read_apic_timer         __P((void));
152 void    u_sleep                 __P((int));
153 void    cpu_send_ipiq           __P((int));
154
155 /* global data in init_smp.c */
156 extern int                      invltlb_ok;
157 extern int                      smp_active;
158 extern int                      smp_started;
159 extern volatile int             smp_idle_loops;
160
161 #endif /* !LOCORE */
162 #else   /* !SMP && !APIC_IO */
163
164 #endif
165
166 #endif /* _KERNEL */
167 #endif /* _MACHINE_SMP_H_ */