1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/path.h>
5 #include <arch/smp/mpspec.h>
8 #include <cpu/x86/lapic.h>
10 unsigned char smp_compute_checksum(void *v, int len)
13 unsigned char checksum;
17 for(i = 0; i < len; i++) {
23 void *smp_write_floating_table(unsigned long addr)
25 struct intel_mp_floating *mf;
28 /* 16 byte align the table address */
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);
40 mf->mpf_specification = 4;
47 mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
51 void *smp_next_mpc_entry(struct mp_config_table *mc)
54 v = (void *)(((char *)mc) + mc->mpc_length);
57 static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned length)
59 mc->mpc_length += length;
60 mc->mpc_entry_count++;
63 void *smp_next_mpe_entry(struct mp_config_table *mc)
66 v = (void *)(((char *)mc) + mc->mpc_length + mc->mpe_length);
69 static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe)
71 mc->mpe_length += mpe->mpe_length;
74 void 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)
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));
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.
98 void smp_write_processors(struct mp_config_table *mc)
101 unsigned apic_version;
102 unsigned cpu_features;
103 unsigned cpu_feature_flags;
104 struct cpuid_result result;
107 boot_apic_id = lapicid();
108 apic_version = lapic_read(LAPIC_LVR) & 0xff;
110 cpu_features = result.eax;
111 cpu_feature_flags = result.edx;
112 for(cpu = all_devices; cpu; cpu = cpu->next) {
113 unsigned long cpu_flag;
114 if ((cpu->path.type != DEVICE_PATH_APIC) ||
115 (cpu->bus->dev->path.type != DEVICE_PATH_APIC_CLUSTER))
122 cpu_flag = MPC_CPU_ENABLED;
123 if (boot_apic_id == cpu->path.u.apic.apic_id) {
124 cpu_flag = MPC_CPU_ENABLED | MPC_CPU_BOOTPROCESSOR;
126 smp_write_processor(mc,
127 cpu->path.u.apic.apic_id, apic_version,
128 cpu_flag, cpu_features, cpu_feature_flags
133 void smp_write_bus(struct mp_config_table *mc,
134 unsigned char id, unsigned char *bustype)
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;
141 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
142 smp_add_mpc_entry(mc, sizeof(*mpc));
145 void smp_write_ioapic(struct mp_config_table *mc,
146 unsigned char id, unsigned char ver,
147 unsigned long apicaddr)
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));
160 void 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)
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));
184 void 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)
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));
202 void 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)
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);
222 void smp_write_bus_hierarchy(struct mp_config_table *mc,
223 unsigned char busid, unsigned char bus_info,
224 unsigned char parent_busid)
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);
237 void smp_write_compatibility_address_space(struct mp_config_table *mc,
238 unsigned char busid, unsigned char address_modifier,
239 unsigned int range_list)
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);