Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/src/smp/smp.c

    r99718a2e r99d6fd0  
    6262void smp_init(void)
    6363{
     64        uintptr_t l_apic_address, io_apic_address;
     65
    6466        if (acpi_madt) {
    6567                acpi_madt_parse();
    6668                ops = &madt_config_operations;
    6769        }
    68        
    6970        if (config.cpu_count == 1) {
    7071                mps_init();
    7172                ops = &mps_config_operations;
    7273        }
    73        
    74         if (config.cpu_count > 1) {
    75                 l_apic = (uint32_t *) hw_map((uintptr_t) l_apic, PAGE_SIZE);
    76                 io_apic = (uint32_t *) hw_map((uintptr_t) io_apic, PAGE_SIZE);
     74
     75        l_apic_address = (uintptr_t) frame_alloc(ONE_FRAME,
     76            FRAME_ATOMIC | FRAME_KA);
     77        if (!l_apic_address)
     78                panic("Cannot allocate address for l_apic.");
     79
     80        io_apic_address = (uintptr_t) frame_alloc(ONE_FRAME,
     81            FRAME_ATOMIC | FRAME_KA);
     82        if (!io_apic_address)
     83                panic("Cannot allocate address for io_apic.");
     84
     85        if (config.cpu_count > 1) {             
     86                page_mapping_insert(AS_KERNEL, l_apic_address,
     87                    (uintptr_t) l_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE);
     88                page_mapping_insert(AS_KERNEL, io_apic_address,
     89                    (uintptr_t) io_apic, PAGE_NOT_CACHEABLE | PAGE_WRITE);
     90                                 
     91                l_apic = (uint32_t *) l_apic_address;
     92                io_apic = (uint32_t *) io_apic_address;
    7793        }
    7894}
     
    90106       
    91107        ASSERT(ops != NULL);
    92        
     108
    93109        /*
    94110         * We need to access data in frame 0.
    95111         * We boldly make use of kernel address space mapping.
    96112         */
    97        
     113
    98114        /*
    99115         * Set the warm-reset vector to the real-mode address of 4K-aligned ap_boot()
    100116         */
    101117        *((uint16_t *) (PA2KA(0x467 + 0))) =
    102             (uint16_t) (((uintptr_t) ap_boot) >> 4);  /* segment */
    103         *((uint16_t *) (PA2KA(0x467 + 2))) = 0;       /* offset */
     118            (uint16_t) (((uintptr_t) ap_boot) >> 4);    /* segment */
     119        *((uint16_t *) (PA2KA(0x467 + 2))) = 0;         /* offset */
    104120       
    105121        /*
     
    107123         * BIOS will not do the POST after the INIT signal.
    108124         */
    109         pio_write_8((ioport8_t *) 0x70, 0xf);
    110         pio_write_8((ioport8_t *) 0x71, 0xa);
    111        
     125        pio_write_8((ioport8_t *)0x70, 0xf);
     126        pio_write_8((ioport8_t *)0x71, 0xa);
     127
    112128        pic_disable_irqs(0xffff);
    113129        apic_init();
    114130       
    115         for (i = 0; i < config.cpu_count; i++) {
     131        uint8_t apic = l_apic_id();
     132
     133        for (i = 0; i < ops->cpu_count(); i++) {
     134                descriptor_t *gdt_new;
     135               
    116136                /*
    117137                 * Skip processors marked unusable.
     
    119139                if (!ops->cpu_enabled(i))
    120140                        continue;
    121                
     141
    122142                /*
    123143                 * The bootstrap processor is already up.
     
    125145                if (ops->cpu_bootstrap(i))
    126146                        continue;
    127                
    128                 if (ops->cpu_apic_id(i) == bsp_l_apic) {
    129                         printf("kmp: bad processor entry #%u, will not send IPI "
    130                             "to myself\n", i);
     147
     148                if (ops->cpu_apic_id(i) == apic) {
     149                        printf("%s: bad processor entry #%u, will not send IPI "
     150                            "to myself\n", __FUNCTION__, i);
    131151                        continue;
    132152                }
     
    140160                 * the memory subsystem
    141161                 */
    142                 descriptor_t *gdt_new =
    143                     (descriptor_t *) malloc(GDT_ITEMS * sizeof(descriptor_t),
    144                     FRAME_ATOMIC);
     162                gdt_new = (descriptor_t *) malloc(GDT_ITEMS *
     163                    sizeof(descriptor_t), FRAME_ATOMIC);
    145164                if (!gdt_new)
    146165                        panic("Cannot allocate memory for GDT.");
    147                
     166
    148167                memcpy(gdt_new, gdt, GDT_ITEMS * sizeof(descriptor_t));
    149168                memsetb(&gdt_new[TSS_DES], sizeof(descriptor_t), 0);
     
    151170                protected_ap_gdtr.base = KA2PA((uintptr_t) gdt_new);
    152171                gdtr.base = (uintptr_t) gdt_new;
    153                
     172
    154173                if (l_apic_send_init_ipi(ops->cpu_apic_id(i))) {
    155174                        /*
     
    160179                        if (waitq_sleep_timeout(&ap_completion_wq, 1000000,
    161180                            SYNCH_FLAGS_NONE) == ESYNCH_TIMEOUT) {
     181                                unsigned int cpu = (config.cpu_active > i) ?
     182                                    config.cpu_active : i;
    162183                                printf("%s: waiting for cpu%u (APIC ID = %d) "
    163                                     "timed out\n", __FUNCTION__, i,
     184                                    "timed out\n", __FUNCTION__, cpu,
    164185                                    ops->cpu_apic_id(i));
    165186                        }
Note: See TracChangeset for help on using the changeset viewer.