2eb18138a6f5773a54adcd78810d0c3c3431c2e7
[coreboot.git] / src / arch / x86 / include / arch / smp / mpspec.h
1 #ifndef __ASM_MPSPEC_H
2 #define __ASM_MPSPEC_H
3
4 #include <device/device.h>
5 /*
6  * Structure definitions for SMP machines following the
7  * Intel Multiprocessing Specification 1.1 and 1.4.
8  */
9
10 /*
11  * This tag identifies where the SMP configuration
12  * information is.
13  */
14
15 #define SMP_MAGIC_IDENT (('_'<<24)|('P'<<16)|('M'<<8)|'_')
16
17 /*
18  * a maximum of 16 APICs with the current APIC ID architecture.
19  */
20 #define MAX_APICS 16
21
22
23 #define SMP_FLOATING_TABLE_LEN sizeof(struct intel_mp_floating)
24
25 struct intel_mp_floating
26 {
27         char mpf_signature[4];          /* "_MP_"                       */
28         unsigned long mpf_physptr;      /* Configuration table address  */
29         unsigned char mpf_length;       /* Our length (paragraphs)      */
30         unsigned char mpf_specification;/* Specification version        */
31         unsigned char mpf_checksum;     /* Checksum (makes sum 0)       */
32         unsigned char mpf_feature1;     /* Standard or configuration ?  */
33         unsigned char mpf_feature2;     /* Bit7 set for IMCR|PIC        */
34 #define MP_FEATURE_VIRTUALWIRE (1 << 7)
35 #define MP_FEATURE_PIC         (0 << 7)
36         unsigned char mpf_feature3;     /* Unused (0)                   */
37         unsigned char mpf_feature4;     /* Unused (0)                   */
38         unsigned char mpf_feature5;     /* Unused (0)                   */
39 } __attribute__((packed));
40
41 struct mp_config_table
42 {
43         char mpc_signature[4];
44 #define MPC_SIGNATURE "PCMP"
45         unsigned short mpc_length;      /* Size of table */
46         char  mpc_spec;                 /* 0x01 */
47         char  mpc_checksum;
48         char  mpc_oem[8];
49         char  mpc_productid[12];
50         unsigned long mpc_oemptr;       /* 0 if not present */
51         unsigned short mpc_oemsize;     /* 0 if not present */
52         unsigned short mpc_entry_count;
53         unsigned long mpc_lapic;        /* APIC address */
54         unsigned short mpe_length;      /* Extended Table size */
55         unsigned char mpe_checksum;     /* Extended Table checksum */
56         unsigned char reserved;
57 } __attribute__((packed));
58
59 /* Followed by entries */
60
61 #define MP_PROCESSOR    0
62 #define MP_BUS          1
63 #define MP_IOAPIC       2
64 #define MP_INTSRC       3
65 #define MP_LINTSRC      4
66
67 struct mpc_config_processor
68 {
69         unsigned char mpc_type;
70         unsigned char mpc_apicid;       /* Local APIC number */
71         unsigned char mpc_apicver;      /* Its versions */
72         unsigned char mpc_cpuflag;
73 #define MPC_CPU_ENABLED         1       /* Processor is available */
74 #define MPC_CPU_BOOTPROCESSOR   2       /* Processor is the BP */
75         unsigned long mpc_cpufeature;
76 #define MPC_CPU_STEPPING_MASK 0x0F
77 #define MPC_CPU_MODEL_MASK      0xF0
78 #define MPC_CPU_FAMILY_MASK     0xF00
79         unsigned long mpc_featureflag;  /* CPUID feature value */
80         unsigned long mpc_reserved[2];
81 } __attribute__((packed));
82
83 struct mpc_config_bus
84 {
85         unsigned char mpc_type;
86         unsigned char mpc_busid;
87         unsigned char mpc_bustype[6];
88 } __attribute__((packed));
89
90 #define BUSTYPE_EISA    "EISA"
91 #define BUSTYPE_ISA     "ISA"
92 #define BUSTYPE_INTERN  "INTERN"        /* Internal BUS */
93 #define BUSTYPE_MCA     "MCA"
94 #define BUSTYPE_VL      "VL"            /* Local bus */
95 #define BUSTYPE_PCI     "PCI"
96 #define BUSTYPE_PCMCIA  "PCMCIA"
97
98 struct mpc_config_ioapic
99 {
100         unsigned char mpc_type;
101         unsigned char mpc_apicid;
102         unsigned char mpc_apicver;
103         unsigned char mpc_flags;
104 #define MPC_APIC_USABLE         0x01
105         unsigned long mpc_apicaddr;
106 } __attribute__((packed));
107
108 struct mpc_config_intsrc
109 {
110         unsigned char mpc_type;
111         unsigned char mpc_irqtype;
112         unsigned short mpc_irqflag;
113         unsigned char mpc_srcbus;
114         unsigned char mpc_srcbusirq;
115         unsigned char mpc_dstapic;
116         unsigned char mpc_dstirq;
117 } __attribute__((packed));
118
119 enum mp_irq_source_types {
120         mp_INT = 0,
121         mp_NMI = 1,
122         mp_SMI = 2,
123         mp_ExtINT = 3
124 };
125
126 #define MP_IRQ_POLARITY_DEFAULT 0x0
127 #define MP_IRQ_POLARITY_HIGH    0x1
128 #define MP_IRQ_POLARITY_LOW     0x3
129 #define MP_IRQ_POLARITY_MASK    0x3
130 #define MP_IRQ_TRIGGER_DEFAULT  0x0
131 #define MP_IRQ_TRIGGER_EDGE     0x4
132 #define MP_IRQ_TRIGGER_LEVEL    0xc
133 #define MP_IRQ_TRIGGER_MASK     0xc
134
135
136 struct mpc_config_lintsrc
137 {
138         unsigned char mpc_type;
139         unsigned char mpc_irqtype;
140         unsigned short mpc_irqflag;
141         unsigned char mpc_srcbusid;
142         unsigned char mpc_srcbusirq;
143         unsigned char mpc_destapic;
144 #define MP_APIC_ALL     0xFF
145         unsigned char mpc_destapiclint;
146 } __attribute__((packed));
147
148 /*
149  *      Default configurations
150  *
151  *      1       2 CPU ISA 82489DX
152  *      2       2 CPU EISA 82489DX neither IRQ 0 timer nor IRQ 13 DMA chaining
153  *      3       2 CPU EISA 82489DX
154  *      4       2 CPU MCA 82489DX
155  *      5       2 CPU ISA+PCI
156  *      6       2 CPU EISA+PCI
157  *      7       2 CPU MCA+PCI
158  */
159
160 #define MAX_IRQ_SOURCES 128
161 #define MAX_MP_BUSSES 32
162 enum mp_bustype {
163         MP_BUS_ISA,
164         MP_BUS_EISA,
165         MP_BUS_PCI,
166         MP_BUS_MCA
167 };
168
169 /* Followed by entries */
170
171 #define MPE_SYSTEM_ADDRESS_SPACE        0x80
172 #define MPE_BUS_HIERARCHY               0x81
173 #define MPE_COMPATIBILITY_ADDRESS_SPACE 0x82
174
175 struct mp_exten_config {
176         unsigned char mpe_type;
177         unsigned char mpe_length;
178 } __attribute__((packed));
179
180 typedef struct mp_exten_config *mpe_t;
181
182 struct mp_exten_system_address_space {
183         unsigned char mpe_type;
184         unsigned char mpe_length;
185         unsigned char mpe_busid;
186         unsigned char mpe_address_type;
187 #define ADDRESS_TYPE_IO       0
188 #define ADDRESS_TYPE_MEM      1
189 #define ADDRESS_TYPE_PREFETCH 2
190         unsigned int  mpe_address_base_low;
191         unsigned int  mpe_address_base_high;
192         unsigned int  mpe_address_length_low;
193         unsigned int  mpe_address_length_high;
194 } __attribute__((packed));
195
196 struct mp_exten_bus_hierarchy {
197         unsigned char mpe_type;
198         unsigned char mpe_length;
199         unsigned char mpe_busid;
200         unsigned char mpe_bus_info;
201 #define BUS_SUBTRACTIVE_DECODE 1
202         unsigned char mpe_parent_busid;
203         unsigned char reserved[3];
204 } __attribute__((packed));
205
206 struct mp_exten_compatibility_address_space {
207         unsigned char mpe_type;
208         unsigned char mpe_length;
209         unsigned char mpe_busid;
210         unsigned char mpe_address_modifier;
211 #define ADDRESS_RANGE_SUBTRACT 1
212 #define ADDRESS_RANGE_ADD      0
213         unsigned int  mpe_range_list;
214 #define RANGE_LIST_IO_ISA       0
215         /* X100 - X3FF
216          * X500 - X7FF
217          * X900 - XBFF
218          * XD00 - XFFF
219          */
220 #define RANGE_LIST_IO_VGA       1
221         /* X3B0 - X3BB
222          * X3C0 - X3DF
223          * X7B0 - X7BB
224          * X7C0 - X7DF
225          * XBB0 - XBBB
226          * XBC0 - XBDF
227          * XFB0 - XFBB
228          * XFC0 - XCDF
229          */
230 } __attribute__((packed));
231
232 /* Default local apic addr */
233 #define LAPIC_ADDR 0xFEE00000
234
235 void mptable_init(struct mp_config_table *mc, u32 lapic_addr);
236
237 void *smp_next_mpc_entry(struct mp_config_table *mc);
238 void *smp_next_mpe_entry(struct mp_config_table *mc);
239
240 void smp_write_processor(struct mp_config_table *mc,
241         unsigned char apicid, unsigned char apicver,
242         unsigned char cpuflag, unsigned int cpufeature,
243         unsigned int featureflag);
244 void smp_write_processors(struct mp_config_table *mc);
245 void smp_write_ioapic(struct mp_config_table *mc,
246         unsigned char id, unsigned char ver,
247         unsigned long apicaddr);
248 void smp_write_intsrc(struct mp_config_table *mc,
249         unsigned char irqtype, unsigned short irqflag,
250         unsigned char srcbus, unsigned char srcbusirq,
251         unsigned char dstapic, unsigned char dstirq);
252 void smp_write_intsrc_pci_bridge(struct mp_config_table *mc,
253         unsigned char irqtype, unsigned short irqflag,
254         struct device *dev,
255         unsigned char dstapic, unsigned char *dstirq);
256 void smp_write_lintsrc(struct mp_config_table *mc,
257         unsigned char irqtype, unsigned short irqflag,
258         unsigned char srcbusid, unsigned char srcbusirq,
259         unsigned char destapic, unsigned char destapiclint);
260 void smp_write_address_space(struct mp_config_table *mc,
261         unsigned char busid, unsigned char address_type,
262         unsigned int address_base_low, unsigned int address_base_high,
263         unsigned int address_length_low, unsigned int address_length_high);
264 void smp_write_bus_hierarchy(struct mp_config_table *mc,
265         unsigned char busid, unsigned char bus_info,
266         unsigned char parent_busid);
267 void smp_write_compatibility_address_space(struct mp_config_table *mc,
268         unsigned char busid, unsigned char address_modifier,
269         unsigned int range_list);
270 void *smp_write_floating_table(unsigned long addr, unsigned int virtualwire);
271 unsigned long write_smp_table(unsigned long addr);
272
273 void mptable_lintsrc(struct mp_config_table *mc, unsigned long bus_isa);
274 void mptable_add_isa_interrupts(struct mp_config_table *mc, unsigned long bus_isa, unsigned long apicid, int external);
275 void mptable_write_buses(struct mp_config_table *mc, int *max_pci_bus, int *isa_bus);
276 void *mptable_finalize(struct mp_config_table *mc);
277
278 #endif
279