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