1 #include <console/console.h>
3 #include <smp/start_stop.h>
4 #include <arch/smp/mpspec.h>
6 #include <cpu/p5/cpuid.h>
7 #include <cpu/p6/apic.h>
9 unsigned char smp_compute_checksum(void *v, int len)
12 unsigned char checksum;
16 for(i = 0; i < len; i++) {
22 void *smp_write_floating_table(unsigned long addr)
24 struct intel_mp_floating *mf;
27 /* 16 byte align the table address */
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);
39 mf->mpf_specification = 4;
46 mf->mpf_checksum = smp_compute_checksum(mf, mf->mpf_length*16);
50 void *smp_next_mpc_entry(struct mp_config_table *mc)
53 v = (void *)(((char *)mc) + mc->mpc_length);
56 static void smp_add_mpc_entry(struct mp_config_table *mc, unsigned length)
58 mc->mpc_length += length;
59 mc->mpc_entry_count++;
62 void *smp_next_mpe_entry(struct mp_config_table *mc)
65 v = (void *)(((char *)mc) + mc->mpc_length + mc->mpe_length);
68 static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe)
70 mc->mpe_length += mpe->mpe_length;
73 void 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)
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));
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.
97 void smp_write_processors(struct mp_config_table *mc,
98 unsigned long *processor_map)
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);
110 cpu_feature_flags = edx;
111 for(i = 0; i < MAX_CPUS; i++) {
112 unsigned long cpu_apicid = initial_apicid[i];
113 unsigned long cpu_flag;
114 if(initial_apicid[i]==-1)
116 cpu_flag = MPC_CPU_ENABLED;
117 if (processor_map[i] & CPU_BOOTPROCESSOR) {
118 cpu_flag |= MPC_CPU_BOOTPROCESSOR;
120 smp_write_processor(mc, cpu_apicid, apic_version,
121 cpu_flag, cpu_features, cpu_feature_flags
126 void smp_write_bus(struct mp_config_table *mc,
127 unsigned char id, unsigned char *bustype)
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;
134 memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype));
135 smp_add_mpc_entry(mc, sizeof(*mpc));
138 void smp_write_ioapic(struct mp_config_table *mc,
139 unsigned char id, unsigned char ver,
140 unsigned long apicaddr)
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));
153 void 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)
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));
177 void 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)
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));
195 void 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)
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);
215 void smp_write_bus_hierarchy(struct mp_config_table *mc,
216 unsigned char busid, unsigned char bus_info,
217 unsigned char parent_busid)
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);
230 void smp_write_compatibility_address_space(struct mp_config_table *mc,
231 unsigned char busid, unsigned char address_modifier,
232 unsigned int range_list)
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);