2
* smp.c: Secondary processor bringup and initialisation.
4
* Copyright (c) 2008, Citrix Systems, Inc.
7
* Keir Fraser <keir.fraser@citrix.com>
9
* This program is free software; you can redistribute it and/or modify it
10
* under the terms and conditions of the GNU General Public License,
11
* version 2, as published by the Free Software Foundation.
13
* This program is distributed in the hope it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18
* You should have received a copy of the GNU General Public License along with
19
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20
* Place - Suite 330, Boston, MA 02111-1307 USA.
25
#include "apic_regs.h"
27
#define AP_BOOT_EIP 0x1000
28
extern char ap_boot_start[], ap_boot_end[];
30
static int ap_callin, ap_cpuid;
35
"ap_boot_start: .code16 \n"
38
" lgdt gdt_desr-ap_boot_start\n"
44
" .word gdt_end - gdt - 1 \n"
46
"ap_boot_end: .code32 \n"
47
"1: mov $0x10,%eax \n"
51
" movl $stack_top,%esp \n"
59
" .quad 0x0000000000000000 \n"
60
" .quad 0x00cf9a000000ffff \n" /* 0x08: Flat code segment */
61
" .quad 0x00cf92000000ffff \n" /* 0x10: Flat data segment */
72
void ap_start(void); /* non-static avoids unused-function compiler warning */
73
/*static*/ void ap_start(void)
75
printf(" - CPU%d ... ", ap_cpuid);
82
static void lapic_wait_ready(void)
84
while ( lapic_read(APIC_ICR) & APIC_ICR_BUSY )
88
static void boot_cpu(unsigned int cpu)
90
unsigned int icr2 = SET_APIC_DEST_FIELD(LAPIC_ID(cpu));
92
/* Initialise shared variables. */
97
/* Wake up the secondary processor: INIT-SIPI-SIPI... */
99
lapic_write(APIC_ICR2, icr2);
100
lapic_write(APIC_ICR, APIC_DM_INIT);
102
lapic_write(APIC_ICR2, icr2);
103
lapic_write(APIC_ICR, APIC_DM_STARTUP | (AP_BOOT_EIP >> 12));
105
lapic_write(APIC_ICR2, icr2);
106
lapic_write(APIC_ICR, APIC_DM_STARTUP | (AP_BOOT_EIP >> 12));
110
* Wait for the secondary processor to complete initialisation.
111
* Do not touch shared resources meanwhile.
116
/* Take the secondary processor offline. */
117
lapic_write(APIC_ICR2, icr2);
118
lapic_write(APIC_ICR, APIC_DM_INIT);
122
void smp_initialise(void)
124
unsigned int i, nr_cpus = hvm_info->nr_vcpus;
126
memcpy((void *)AP_BOOT_EIP, ap_boot_start, ap_boot_end - ap_boot_start);
128
printf("Multiprocessor initialisation:\n");
130
for ( i = 1; i < nr_cpus; i++ )