Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame^] | 1 | #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 | |
| 9 | unsigned 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 | |
| 22 | void *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 | |
| 50 | void *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 | } |
| 56 | static 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 | |
| 62 | void *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 | } |
| 68 | static void smp_add_mpe_entry(struct mp_config_table *mc, mpe_t mpe) |
| 69 | { |
| 70 | mc->mpe_length += mpe->mpe_length; |
| 71 | } |
| 72 | |
| 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) |
| 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 | */ |
| 97 | void 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; |
| 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) |
| 115 | continue; |
| 116 | cpu_flag = MPC_CPU_ENABLED |
| 117 | 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 | ); |
| 123 | |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void smp_write_bus(struct mp_config_table *mc, |
| 128 | unsigned char id, unsigned char *bustype) |
| 129 | { |
| 130 | struct mpc_config_bus *mpc; |
| 131 | mpc = smp_next_mpc_entry(mc); |
| 132 | memset(mpc, '\0', sizeof(*mpc)); |
| 133 | mpc->mpc_type = MP_BUS; |
| 134 | mpc->mpc_busid = id; |
| 135 | memcpy(mpc->mpc_bustype, bustype, sizeof(mpc->mpc_bustype)); |
| 136 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 137 | } |
| 138 | |
| 139 | void smp_write_ioapic(struct mp_config_table *mc, |
| 140 | unsigned char id, unsigned char ver, |
| 141 | unsigned long apicaddr) |
| 142 | { |
| 143 | struct mpc_config_ioapic *mpc; |
| 144 | mpc = smp_next_mpc_entry(mc); |
| 145 | memset(mpc, '\0', sizeof(*mpc)); |
| 146 | mpc->mpc_type = MP_IOAPIC; |
| 147 | mpc->mpc_apicid = id; |
| 148 | mpc->mpc_apicver = ver; |
| 149 | mpc->mpc_flags = MPC_APIC_USABLE; |
| 150 | mpc->mpc_apicaddr = apicaddr; |
| 151 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 152 | } |
| 153 | |
| 154 | void smp_write_intsrc(struct mp_config_table *mc, |
| 155 | unsigned char irqtype, unsigned short irqflag, |
| 156 | unsigned char srcbus, unsigned char srcbusirq, |
| 157 | unsigned char dstapic, unsigned char dstirq) |
| 158 | { |
| 159 | struct mpc_config_intsrc *mpc; |
| 160 | mpc = smp_next_mpc_entry(mc); |
| 161 | memset(mpc, '\0', sizeof(*mpc)); |
| 162 | mpc->mpc_type = MP_INTSRC; |
| 163 | mpc->mpc_irqtype = irqtype; |
| 164 | mpc->mpc_irqflag = irqflag; |
| 165 | mpc->mpc_srcbus = srcbus; |
| 166 | mpc->mpc_srcbusirq = srcbusirq; |
| 167 | mpc->mpc_dstapic = dstapic; |
| 168 | mpc->mpc_dstirq = dstirq; |
| 169 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 170 | #if CONFIG_DEBUG_MPTABLE == 1 |
| 171 | printk_info("add intsrc srcbus 0x%x srcbusirq 0x%x, dstapic 0x%x, dstirq 0x%x\n", |
| 172 | srcbus, srcbusirq, dstapic, dstirq); |
| 173 | hexdump(__FUNCTION__, mpc, sizeof(*mpc)); |
| 174 | #endif |
| 175 | } |
| 176 | |
| 177 | |
| 178 | void smp_write_lintsrc(struct mp_config_table *mc, |
| 179 | unsigned char irqtype, unsigned short irqflag, |
| 180 | unsigned char srcbusid, unsigned char srcbusirq, |
| 181 | unsigned char destapic, unsigned char destapiclint) |
| 182 | { |
| 183 | struct mpc_config_lintsrc *mpc; |
| 184 | mpc = smp_next_mpc_entry(mc); |
| 185 | memset(mpc, '\0', sizeof(*mpc)); |
| 186 | mpc->mpc_type = MP_LINTSRC; |
| 187 | mpc->mpc_irqtype = irqtype; |
| 188 | mpc->mpc_irqflag = irqflag; |
| 189 | mpc->mpc_srcbusid = srcbusid; |
| 190 | mpc->mpc_srcbusirq = srcbusirq; |
| 191 | mpc->mpc_destapic = destapic; |
| 192 | mpc->mpc_destapiclint = destapiclint; |
| 193 | smp_add_mpc_entry(mc, sizeof(*mpc)); |
| 194 | } |
| 195 | |
| 196 | void smp_write_address_space(struct mp_config_table *mc, |
| 197 | unsigned char busid, unsigned char address_type, |
| 198 | unsigned int address_base_low, unsigned int address_base_high, |
| 199 | unsigned int address_length_low, unsigned int address_length_high) |
| 200 | { |
| 201 | struct mp_exten_system_address_space *mpe; |
| 202 | mpe = smp_next_mpe_entry(mc); |
| 203 | memset(mpe, '\0', sizeof(*mpe)); |
| 204 | mpe->mpe_type = MPE_SYSTEM_ADDRESS_SPACE; |
| 205 | mpe->mpe_length = sizeof(*mpe); |
| 206 | mpe->mpe_busid = busid; |
| 207 | mpe->mpe_address_type = address_type; |
| 208 | mpe->mpe_address_base_low = address_base_low; |
| 209 | mpe->mpe_address_base_high = address_base_high; |
| 210 | mpe->mpe_address_length_low = address_length_low; |
| 211 | mpe->mpe_address_length_high = address_length_high; |
| 212 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | void smp_write_bus_hierarchy(struct mp_config_table *mc, |
| 217 | unsigned char busid, unsigned char bus_info, |
| 218 | unsigned char parent_busid) |
| 219 | { |
| 220 | struct mp_exten_bus_hierarchy *mpe; |
| 221 | mpe = smp_next_mpe_entry(mc); |
| 222 | memset(mpe, '\0', sizeof(*mpe)); |
| 223 | mpe->mpe_type = MPE_BUS_HIERARCHY; |
| 224 | mpe->mpe_length = sizeof(*mpe); |
| 225 | mpe->mpe_busid = busid; |
| 226 | mpe->mpe_bus_info = bus_info; |
| 227 | mpe->mpe_parent_busid = parent_busid; |
| 228 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 229 | } |
| 230 | |
| 231 | void smp_write_compatibility_address_space(struct mp_config_table *mc, |
| 232 | unsigned char busid, unsigned char address_modifier, |
| 233 | unsigned int range_list) |
| 234 | { |
| 235 | struct mp_exten_compatibility_address_space *mpe; |
| 236 | mpe = smp_next_mpe_entry(mc); |
| 237 | memset(mpe, '\0', sizeof(*mpe)); |
| 238 | mpe->mpe_type = MPE_COMPATIBILITY_ADDRESS_SPACE; |
| 239 | mpe->mpe_length = sizeof(*mpe); |
| 240 | mpe->mpe_busid = busid; |
| 241 | mpe->mpe_address_modifier = address_modifier; |
| 242 | mpe->mpe_range_list = range_list; |
| 243 | smp_add_mpe_entry(mc, (mpe_t)mpe); |
| 244 | } |
| 245 | |