blob: d7b8c3e2f0de4fb1354741be1d6fd1a4040a163d [file] [log] [blame]
Eric Biederman8ca8d762003-04-22 19:02:15 +00001#include <console/console.h>
2#include <cpu/cpu.h>
3#include <smp/start_stop.h>
4#include <arch/smp/mpspec.h>
5#include <string.h>
6#include <cpu/p5/cpuid.h>
7#include <cpu/p6/apic.h>
8
9unsigned char smp_compute_checksum(void *v, int len)
10{
11 unsigned char *bytes;
12 unsigned char checksum;
13 int i;
14 bytes = v;
15 checksum = 0;
16 for(i = 0; i < len; i++) {
17 checksum -= bytes[i];
18 }
19 return checksum;
20}
21
22void *smp_write_floating_table(unsigned long addr)
23{
24 struct intel_mp_floating *mf;
25 void *v;
26
27 /* 16 byte align the table address */
28 addr += 15;
29 addr &= ~15;
30 v = (void *)addr;
31
32 mf = v;
33 mf->mpf_signature[0] = '_';
34 mf->mpf_signature[1] = 'M';
35 mf->mpf_signature[2] = 'P';
36 mf->mpf_signature[3] = '_';
37 mf->mpf_physptr = (unsigned long)(((char *)v) + SMP_FLOATING_TABLE_LEN);
38 mf->mpf_length = 1;
39 mf->mpf_specification = 4;
40 mf->mpf_checksum = 0;
41 mf->mpf_feature1 = 0;
42 mf->mpf_feature2 = 0;
43 mf->mpf_feature3 = 0;
44 mf->mpf_feature4 = 0;
45 mf->mpf_feature5 = 0;
46 mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
47 return v;
48}
49
50void *smp_next_mpc_entry(struct mp_config_table *mc)
51{
52 void *v;
53 v = (void *)(((char *)mc) + mc->mpc_length);
54 return v;
55}
56static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned length)
57{
58 mc->mpc_length += length;
59 mc->mpc_entry_count++;
60}
61
62void *smp_next_mpe_entry(struct mp_config_table *mc)
63{
64 void *v;
65 v = (void *)(((char *)mc) + mc->mpc_length + mc->mpe_length);
66 return v;
67}
68static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe)
69{
70 mc->mpe_length += mpe->mpe_length;
71}
72
73void smp_write_processor(struct mp_config_table *mc,
74 unsigned char apicid, unsigned char apicver,
75 unsigned char cpuflag, unsigned int cpufeature,
76 unsigned int featureflag)
77{
78 struct mpc_config_processor *mpc;
79 mpc = smp_next_mpc_entry(mc);
80 memset(mpc, '\0', sizeof(*mpc));
81 mpc->mpc_type = MP_PROCESSOR;
82 mpc->mpc_apicid = apicid;
83 mpc->mpc_apicver = apicver;
84 mpc->mpc_cpuflag = cpuflag;
85 mpc->mpc_cpufeature = cpufeature;
86 mpc->mpc_featureflag = featureflag;
87 smp_add_mpc_entry(mc, sizeof(*mpc));
88}
89
90/* If we assume a symmetric processor configuration we can
91 * get all of the information we need to write the processor
92 * entry from the bootstrap processor.
93 * Plus I don't think linux really even cares.
94 * Having the proper apicid's in the table so the non-bootstrap
95 * processors can be woken up should be enough.
96 */
97void smp_write_processors(struct mp_config_table *mc,
98 unsigned long *processor_map)
99{
100 int i;
101 int processor_id;
102 unsigned apic_version;
103 unsigned cpu_features;
104 unsigned cpu_feature_flags;
105 int eax, ebx, ecx, edx;
106 processor_id = this_processors_id();
107 apic_version = apic_read(APIC_LVR) & 0xff;
108 cpuid(1, &eax, &ebx, &ecx, &edx);
109 cpu_features = eax;
110 cpu_feature_flags = edx;
Eric Biederman9bdb4602003-09-01 23:17:58 +0000111 for(i = 0; i < CONFIG_MAX_CPUS; i++) {
Eric Biederman8ca8d762003-04-22 19:02:15 +0000112 unsigned long cpu_apicid = initial_apicid[i];
113 unsigned long cpu_flag;
114 if(initial_apicid[i]==-1)
115 continue;
Eric Biederman5899fd82003-04-24 06:25:08 +0000116 cpu_flag = MPC_CPU_ENABLED;
Eric Biederman8ca8d762003-04-22 19:02:15 +0000117 if (processor_map[i] & CPU_BOOTPROCESSOR) {
118 cpu_flag |= MPC_CPU_BOOTPROCESSOR;
119 }
120 smp_write_processor(mc, cpu_apicid, apic_version,
121 cpu_flag, cpu_features, cpu_feature_flags
122 );
Eric Biederman8ca8d762003-04-22 19:02:15 +0000123 }
124}
125
126void smp_write_bus(struct mp_config_table *mc,
127 unsigned char id, unsigned char *bustype)
128{
129 struct mpc_config_bus *mpc;
130 mpc = smp_next_mpc_entry(mc);
131 memset(mpc, '\0', sizeof(*mpc));
132 mpc->mpc_type = MP_BUS;
133 mpc->mpc_busid = id;
134 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
135 smp_add_mpc_entry(mc, sizeof(*mpc));
136}
137
138void smp_write_ioapic(struct mp_config_table *mc,
139 unsigned char id, unsigned char ver,
140 unsigned long apicaddr)
141{
142 struct mpc_config_ioapic *mpc;
143 mpc = smp_next_mpc_entry(mc);
144 memset(mpc, '\0', sizeof(*mpc));
145 mpc->mpc_type = MP_IOAPIC;
146 mpc->mpc_apicid = id;
147 mpc->mpc_apicver = ver;
148 mpc->mpc_flags = MPC_APIC_USABLE;
149 mpc->mpc_apicaddr = apicaddr;
150 smp_add_mpc_entry(mc, sizeof(*mpc));
151}
152
153void smp_write_intsrc(struct mp_config_table *mc,
154 unsigned char irqtype, unsigned short irqflag,
155 unsigned char srcbus, unsigned char srcbusirq,
156 unsigned char dstapic, unsigned char dstirq)
157{
158 struct mpc_config_intsrc *mpc;
159 mpc = smp_next_mpc_entry(mc);
160 memset(mpc, '\0', sizeof(*mpc));
161 mpc->mpc_type = MP_INTSRC;
162 mpc->mpc_irqtype = irqtype;
163 mpc->mpc_irqflag = irqflag;
164 mpc->mpc_srcbus = srcbus;
165 mpc->mpc_srcbusirq = srcbusirq;
166 mpc->mpc_dstapic = dstapic;
167 mpc->mpc_dstirq = dstirq;
168 smp_add_mpc_entry(mc, sizeof(*mpc));
169#if CONFIG_DEBUG_MPTABLE == 1
170 printk_info("add intsrc srcbus 0x%x srcbusirq 0x%x, dstapic 0x%x, dstirq 0x%x\n",
171 srcbus, srcbusirq, dstapic, dstirq);
172 hexdump(__FUNCTION__, mpc, sizeof(*mpc));
173#endif
174}
175
176
177void smp_write_lintsrc(struct mp_config_table *mc,
178 unsigned char irqtype, unsigned short irqflag,
179 unsigned char srcbusid, unsigned char srcbusirq,
180 unsigned char destapic, unsigned char destapiclint)
181{
182 struct mpc_config_lintsrc *mpc;
183 mpc = smp_next_mpc_entry(mc);
184 memset(mpc, '\0', sizeof(*mpc));
185 mpc->mpc_type = MP_LINTSRC;
186 mpc->mpc_irqtype = irqtype;
187 mpc->mpc_irqflag = irqflag;
188 mpc->mpc_srcbusid = srcbusid;
189 mpc->mpc_srcbusirq = srcbusirq;
190 mpc->mpc_destapic = destapic;
191 mpc->mpc_destapiclint = destapiclint;
192 smp_add_mpc_entry(mc, sizeof(*mpc));
193}
194
195void smp_write_address_space(struct mp_config_table *mc,
196 unsigned char busid, unsigned char address_type,
197 unsigned int address_base_low, unsigned int address_base_high,
198 unsigned int address_length_low, unsigned int address_length_high)
199{
200 struct mp_exten_system_address_space *mpe;
201 mpe = smp_next_mpe_entry(mc);
202 memset(mpe, '\0', sizeof(*mpe));
203 mpe->mpe_type = MPE_SYSTEM_ADDRESS_SPACE;
204 mpe->mpe_length = sizeof(*mpe);
205 mpe->mpe_busid = busid;
206 mpe->mpe_address_type = address_type;
207 mpe->mpe_address_base_low = address_base_low;
208 mpe->mpe_address_base_high = address_base_high;
209 mpe->mpe_address_length_low = address_length_low;
210 mpe->mpe_address_length_high = address_length_high;
211 smp_add_mpe_entry(mc, (mpe_t)mpe);
212}
213
214
215void smp_write_bus_hierarchy(struct mp_config_table *mc,
216 unsigned char busid, unsigned char bus_info,
217 unsigned char parent_busid)
218{
219 struct mp_exten_bus_hierarchy *mpe;
220 mpe = smp_next_mpe_entry(mc);
221 memset(mpe, '\0', sizeof(*mpe));
222 mpe->mpe_type = MPE_BUS_HIERARCHY;
223 mpe->mpe_length = sizeof(*mpe);
224 mpe->mpe_busid = busid;
225 mpe->mpe_bus_info = bus_info;
226 mpe->mpe_parent_busid = parent_busid;
227 smp_add_mpe_entry(mc, (mpe_t)mpe);
228}
229
230void smp_write_compatibility_address_space(struct mp_config_table *mc,
231 unsigned char busid, unsigned char address_modifier,
232 unsigned int range_list)
233{
234 struct mp_exten_compatibility_address_space *mpe;
235 mpe = smp_next_mpe_entry(mc);
236 memset(mpe, '\0', sizeof(*mpe));
237 mpe->mpe_type = MPE_COMPATIBILITY_ADDRESS_SPACE;
238 mpe->mpe_length = sizeof(*mpe);
239 mpe->mpe_busid = busid;
240 mpe->mpe_address_modifier = address_modifier;
241 mpe->mpe_range_list = range_list;
242 smp_add_mpe_entry(mc, (mpe_t)mpe);
243}
244