1997-04-26 11:46:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996, by Steve Passe
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. The name of the developer may NOT be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
|
1998-03-07 20:16:49 +00:00
|
|
|
#include "opt_cpu.h"
|
2001-09-12 08:38:13 +00:00
|
|
|
#include "opt_kstack_pages.h"
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-12-08 23:00:24 +00:00
|
|
|
#ifdef SMP
|
|
|
|
#include <machine/smptests.h>
|
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
|
|
|
|
1997-08-25 21:28:08 +00:00
|
|
|
#include <sys/param.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
#include <sys/systm.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cons.h> /* cngetc() */
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#ifdef GPROF
|
|
|
|
#include <sys/gmon.h>
|
|
|
|
#endif
|
1997-08-26 18:10:38 +00:00
|
|
|
#include <sys/kernel.h>
|
2001-10-11 17:53:43 +00:00
|
|
|
#include <sys/ktr.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
1999-05-08 17:48:22 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/memrange.h>
|
2000-10-20 07:58:15 +00:00
|
|
|
#include <sys/mutex.h>
|
2001-06-18 19:06:14 +00:00
|
|
|
#include <sys/pcpu.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
2001-04-27 19:28:25 +00:00
|
|
|
#include <sys/smp.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/user.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
1997-06-22 16:04:22 +00:00
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/vm_extern.h>
|
1997-12-08 23:00:24 +00:00
|
|
|
#include <vm/vm_map.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
#include <machine/apic.h>
|
1999-07-20 06:52:35 +00:00
|
|
|
#include <machine/atomic.h>
|
2001-04-27 19:28:25 +00:00
|
|
|
#include <machine/cpu.h>
|
1999-07-20 06:52:35 +00:00
|
|
|
#include <machine/cpufunc.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
#include <machine/mpapic.h>
|
1999-07-20 06:52:35 +00:00
|
|
|
#include <machine/psl.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
#include <machine/segments.h>
|
2002-03-07 04:43:51 +00:00
|
|
|
#include <machine/smp.h>
|
1997-07-26 01:55:19 +00:00
|
|
|
#include <machine/smptests.h> /** TEST_DEFAULT_CONFIG, TEST_TEST1 */
|
1997-06-22 16:04:22 +00:00
|
|
|
#include <machine/tss.h>
|
1997-06-24 17:26:07 +00:00
|
|
|
#include <machine/specialreg.h>
|
2001-08-25 02:20:02 +00:00
|
|
|
#include <machine/privatespace.h>
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-04-28 00:25:00 +00:00
|
|
|
#if defined(APIC_IO)
|
1997-07-08 23:46:00 +00:00
|
|
|
#include <machine/md_var.h> /* setidt() */
|
|
|
|
#include <i386/isa/icu.h> /* IPIs */
|
|
|
|
#include <i386/isa/intr_machdep.h> /* IPIs */
|
1997-04-28 00:25:00 +00:00
|
|
|
#endif /* APIC_IO */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-08-09 23:01:03 +00:00
|
|
|
#if defined(TEST_DEFAULT_CONFIG)
|
|
|
|
#define MPFPS_MPFB1 TEST_DEFAULT_CONFIG
|
|
|
|
#else
|
|
|
|
#define MPFPS_MPFB1 mpfps->mpfb1
|
|
|
|
#endif /* TEST_DEFAULT_CONFIG */
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
#define WARMBOOT_TARGET 0
|
|
|
|
#define WARMBOOT_OFF (KERNBASE + 0x0467)
|
|
|
|
#define WARMBOOT_SEG (KERNBASE + 0x0469)
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1998-10-08 16:15:22 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#define BIOS_BASE (0xe8000)
|
|
|
|
#define BIOS_SIZE (0x18000)
|
|
|
|
#else
|
1997-06-27 23:33:17 +00:00
|
|
|
#define BIOS_BASE (0xf0000)
|
|
|
|
#define BIOS_SIZE (0x10000)
|
1998-10-08 16:15:22 +00:00
|
|
|
#endif
|
1997-06-27 23:33:17 +00:00
|
|
|
#define BIOS_COUNT (BIOS_SIZE/4)
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
#define CMOS_REG (0x70)
|
|
|
|
#define CMOS_DATA (0x71)
|
|
|
|
#define BIOS_RESET (0x0f)
|
|
|
|
#define BIOS_WARM (0x0a)
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
#define PROCENTRY_FLAG_EN 0x01
|
|
|
|
#define PROCENTRY_FLAG_BP 0x02
|
|
|
|
#define IOAPICENTRY_FLAG_EN 0x01
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
/* MP Floating Pointer Structure */
|
|
|
|
typedef struct MPFPS {
|
|
|
|
char signature[4];
|
|
|
|
void *pap;
|
|
|
|
u_char length;
|
|
|
|
u_char spec_rev;
|
|
|
|
u_char checksum;
|
|
|
|
u_char mpfb1;
|
|
|
|
u_char mpfb2;
|
|
|
|
u_char mpfb3;
|
|
|
|
u_char mpfb4;
|
|
|
|
u_char mpfb5;
|
|
|
|
} *mpfps_t;
|
|
|
|
|
|
|
|
/* MP Configuration Table Header */
|
|
|
|
typedef struct MPCTH {
|
|
|
|
char signature[4];
|
|
|
|
u_short base_table_length;
|
|
|
|
u_char spec_rev;
|
|
|
|
u_char checksum;
|
|
|
|
u_char oem_id[8];
|
|
|
|
u_char product_id[12];
|
|
|
|
void *oem_table_pointer;
|
|
|
|
u_short oem_table_size;
|
|
|
|
u_short entry_count;
|
|
|
|
void *apic_address;
|
|
|
|
u_short extended_table_length;
|
|
|
|
u_char extended_table_checksum;
|
|
|
|
u_char reserved;
|
|
|
|
} *mpcth_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct PROCENTRY {
|
|
|
|
u_char type;
|
|
|
|
u_char apic_id;
|
|
|
|
u_char apic_version;
|
|
|
|
u_char cpu_flags;
|
|
|
|
u_long cpu_signature;
|
|
|
|
u_long feature_flags;
|
|
|
|
u_long reserved1;
|
|
|
|
u_long reserved2;
|
|
|
|
} *proc_entry_ptr;
|
|
|
|
|
|
|
|
typedef struct BUSENTRY {
|
|
|
|
u_char type;
|
|
|
|
u_char bus_id;
|
|
|
|
char bus_type[6];
|
|
|
|
} *bus_entry_ptr;
|
|
|
|
|
|
|
|
typedef struct IOAPICENTRY {
|
|
|
|
u_char type;
|
|
|
|
u_char apic_id;
|
|
|
|
u_char apic_version;
|
|
|
|
u_char apic_flags;
|
|
|
|
void *apic_address;
|
|
|
|
} *io_apic_entry_ptr;
|
|
|
|
|
|
|
|
typedef struct INTENTRY {
|
|
|
|
u_char type;
|
|
|
|
u_char int_type;
|
|
|
|
u_short int_flags;
|
|
|
|
u_char src_bus_id;
|
|
|
|
u_char src_bus_irq;
|
|
|
|
u_char dst_apic_id;
|
|
|
|
u_char dst_apic_int;
|
|
|
|
} *int_entry_ptr;
|
|
|
|
|
|
|
|
/* descriptions of MP basetable entries */
|
|
|
|
typedef struct BASETABLE_ENTRY {
|
|
|
|
u_char type;
|
|
|
|
u_char length;
|
|
|
|
char name[16];
|
|
|
|
} basetable_entry;
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
|
|
|
* this code MUST be enabled here and in mpboot.s.
|
|
|
|
* it follows the very early stages of AP boot by placing values in CMOS ram.
|
|
|
|
* it NORMALLY will never be needed and thus the primitive method for enabling.
|
|
|
|
*
|
|
|
|
#define CHECK_POINTS
|
|
|
|
*/
|
|
|
|
|
1998-10-10 09:38:02 +00:00
|
|
|
#if defined(CHECK_POINTS) && !defined(PC98)
|
1997-04-26 11:46:25 +00:00
|
|
|
#define CHECK_READ(A) (outb(CMOS_REG, (A)), inb(CMOS_DATA))
|
|
|
|
#define CHECK_WRITE(A,D) (outb(CMOS_REG, (A)), outb(CMOS_DATA, (D)))
|
|
|
|
|
|
|
|
#define CHECK_INIT(D); \
|
|
|
|
CHECK_WRITE(0x34, (D)); \
|
|
|
|
CHECK_WRITE(0x35, (D)); \
|
|
|
|
CHECK_WRITE(0x36, (D)); \
|
|
|
|
CHECK_WRITE(0x37, (D)); \
|
|
|
|
CHECK_WRITE(0x38, (D)); \
|
|
|
|
CHECK_WRITE(0x39, (D));
|
|
|
|
|
|
|
|
#define CHECK_PRINT(S); \
|
|
|
|
printf("%s: %d, %d, %d, %d, %d, %d\n", \
|
|
|
|
(S), \
|
|
|
|
CHECK_READ(0x34), \
|
|
|
|
CHECK_READ(0x35), \
|
|
|
|
CHECK_READ(0x36), \
|
|
|
|
CHECK_READ(0x37), \
|
|
|
|
CHECK_READ(0x38), \
|
|
|
|
CHECK_READ(0x39));
|
|
|
|
|
|
|
|
#else /* CHECK_POINTS */
|
|
|
|
|
|
|
|
#define CHECK_INIT(D)
|
|
|
|
#define CHECK_PRINT(S)
|
|
|
|
|
|
|
|
#endif /* CHECK_POINTS */
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
/*
|
|
|
|
* Values to send to the POST hardware.
|
|
|
|
*/
|
|
|
|
#define MP_BOOTADDRESS_POST 0x10
|
|
|
|
#define MP_PROBE_POST 0x11
|
1997-09-07 22:04:09 +00:00
|
|
|
#define MPTABLE_PASS1_POST 0x12
|
|
|
|
|
|
|
|
#define MP_START_POST 0x13
|
|
|
|
#define MP_ENABLE_POST 0x14
|
1997-06-27 23:33:17 +00:00
|
|
|
#define MPTABLE_PASS2_POST 0x15
|
1997-09-07 22:04:09 +00:00
|
|
|
|
|
|
|
#define START_ALL_APS_POST 0x16
|
|
|
|
#define INSTALL_AP_TRAMP_POST 0x17
|
|
|
|
#define START_AP_POST 0x18
|
|
|
|
|
|
|
|
#define MP_ANNOUNCE_POST 0x19
|
|
|
|
|
2003-01-08 01:33:18 +00:00
|
|
|
static int need_hyperthreading_fixup;
|
|
|
|
static u_int logical_cpus;
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
/* used to hold the AP's until we are ready to release them */
|
2001-04-20 01:09:05 +00:00
|
|
|
static struct mtx ap_boot_mtx;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
/** XXX FIXME: where does this really belong, isa.h/isa.c perhaps? */
|
1997-07-07 00:06:51 +00:00
|
|
|
int current_postcode;
|
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
/** XXX FIXME: what system files declare these??? */
|
1997-04-26 11:46:25 +00:00
|
|
|
extern struct region_descriptor r_gdt, r_idt;
|
|
|
|
|
1997-08-24 20:33:32 +00:00
|
|
|
int bsp_apic_ready = 0; /* flags useability of BSP apic */
|
1997-05-26 09:23:30 +00:00
|
|
|
int mp_naps; /* # of Applications processors */
|
|
|
|
int mp_nbusses; /* # of busses */
|
|
|
|
int mp_napics; /* # of IO APICs */
|
|
|
|
int boot_cpu_id; /* designated BSP */
|
1997-04-26 11:46:25 +00:00
|
|
|
vm_offset_t cpu_apic_address;
|
1997-05-25 02:49:03 +00:00
|
|
|
vm_offset_t io_apic_address[NAPICID]; /* NAPICID is more than enough */
|
1997-09-21 05:50:02 +00:00
|
|
|
extern int nkpt;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2000-09-22 23:40:10 +00:00
|
|
|
u_int32_t cpu_apic_versions[MAXCPU];
|
|
|
|
u_int32_t *io_apic_versions;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1998-03-03 22:56:30 +00:00
|
|
|
#ifdef APIC_INTR_REORDER
|
|
|
|
struct {
|
|
|
|
volatile int *location;
|
|
|
|
int bit;
|
|
|
|
} apic_isrbit_location[32];
|
|
|
|
#endif
|
|
|
|
|
1998-09-06 22:41:42 +00:00
|
|
|
struct apic_intmapinfo int_to_apicintpin[APIC_INTMAPSIZE];
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
1997-05-25 02:49:03 +00:00
|
|
|
* APIC ID logical/physical mapping structures.
|
|
|
|
* We oversize these to simplify boot-time config.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
1997-05-25 02:49:03 +00:00
|
|
|
int cpu_num_to_apic_id[NAPICID];
|
|
|
|
int io_num_to_apic_id[NAPICID];
|
1997-04-26 11:46:25 +00:00
|
|
|
int apic_id_to_logical[NAPICID];
|
|
|
|
|
1997-10-05 03:19:29 +00:00
|
|
|
|
1999-04-28 01:04:33 +00:00
|
|
|
/* AP uses this during bootstrap. Do not staticize. */
|
|
|
|
char *bootSTK;
|
1999-06-23 21:47:24 +00:00
|
|
|
static int bootAP;
|
1997-06-22 16:04:22 +00:00
|
|
|
|
|
|
|
/* Hotwire a 0->4MB V==P mapping */
|
1997-08-26 18:10:38 +00:00
|
|
|
extern pt_entry_t *KPTphys;
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1999-04-28 01:04:33 +00:00
|
|
|
/* SMP page table page */
|
|
|
|
extern pt_entry_t *SMPpt;
|
1997-08-26 18:10:38 +00:00
|
|
|
|
2000-09-22 23:40:10 +00:00
|
|
|
struct pcb stoppcbs[MAXCPU];
|
1998-05-17 22:12:14 +00:00
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
#ifdef APIC_IO
|
|
|
|
/* Variables needed for SMP tlb shootdown. */
|
|
|
|
vm_offset_t smp_tlb_addr1;
|
|
|
|
vm_offset_t smp_tlb_addr2;
|
|
|
|
volatile int smp_tlb_wait;
|
|
|
|
static struct mtx smp_tlb_mtx;
|
|
|
|
#endif
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
1997-07-08 23:46:00 +00:00
|
|
|
* Local data and functions.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
|
2001-01-24 12:35:55 +00:00
|
|
|
/* Set to 1 once we're ready to let the APs out of the pen. */
|
|
|
|
static volatile int aps_ready = 0;
|
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
static int mp_capable;
|
|
|
|
static u_int boot_address;
|
|
|
|
static u_int base_memory;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
static int picmode; /* 0: virtual wire mode, 1: PIC mode */
|
|
|
|
static mpfps_t mpfps;
|
|
|
|
static int search_for_sig(u_int32_t target, int count);
|
|
|
|
static void mp_enable(u_int boot_addr);
|
|
|
|
|
2003-01-08 01:33:18 +00:00
|
|
|
static void mptable_hyperthread_fixup(u_int id_mask);
|
2000-09-22 23:40:10 +00:00
|
|
|
static void mptable_pass1(void);
|
1997-05-26 09:23:30 +00:00
|
|
|
static int mptable_pass2(void);
|
|
|
|
static void default_mp_table(int type);
|
1997-08-09 23:01:03 +00:00
|
|
|
static void fix_mp_table(void);
|
1998-09-06 22:41:42 +00:00
|
|
|
static void setup_apic_irq_mapping(void);
|
1997-07-23 20:47:19 +00:00
|
|
|
static void init_locks(void);
|
1997-05-26 09:23:30 +00:00
|
|
|
static int start_all_aps(u_int boot_addr);
|
|
|
|
static void install_ap_tramp(u_int boot_addr);
|
|
|
|
static int start_ap(int logicalCpu, u_int boot_addr);
|
2001-01-24 09:48:52 +00:00
|
|
|
void ap_init(void);
|
2000-01-04 22:24:59 +00:00
|
|
|
static int apic_int_is_bus_type(int intr, int bus_type);
|
2000-09-07 01:33:02 +00:00
|
|
|
static void release_aps(void *dummy);
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2001-01-24 09:48:52 +00:00
|
|
|
/*
|
|
|
|
* initialize all the SMP locks
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* lock region used by kernel profiling */
|
2001-06-28 04:03:29 +00:00
|
|
|
int mcount_lock;
|
2001-01-24 09:48:52 +00:00
|
|
|
|
|
|
|
#ifdef USE_COMLOCK
|
|
|
|
/* locks com (tty) data/hardware accesses: a FASTINTR() */
|
2001-01-24 12:35:55 +00:00
|
|
|
struct mtx com_mtx;
|
2001-01-24 09:48:52 +00:00
|
|
|
#endif /* USE_COMLOCK */
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_locks(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef USE_COMLOCK
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&com_mtx, "com", NULL, MTX_SPIN);
|
2001-01-24 09:48:52 +00:00
|
|
|
#endif /* USE_COMLOCK */
|
2002-07-12 07:56:11 +00:00
|
|
|
#ifdef APIC_IO
|
|
|
|
mtx_init(&smp_tlb_mtx, "tlb", NULL, MTX_SPIN);
|
|
|
|
#endif
|
2001-01-24 09:48:52 +00:00
|
|
|
}
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
1997-07-08 23:46:00 +00:00
|
|
|
* Calculate usable address in base memory for AP trampoline code.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
u_int
|
|
|
|
mp_bootaddress(u_int basemem)
|
|
|
|
{
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MP_BOOTADDRESS_POST);
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
base_memory = basemem * 1024; /* convert to bytes */
|
|
|
|
|
|
|
|
boot_address = base_memory & ~0xfff; /* round down to 4k boundary */
|
|
|
|
if ((base_memory - boot_address) < bootMP_size)
|
|
|
|
boot_address -= 4096; /* not enough, lower by 4k */
|
|
|
|
|
|
|
|
return boot_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
/*
|
|
|
|
* Look for an Intel MP spec table (ie, SMP capable hardware).
|
|
|
|
*/
|
2001-04-27 19:28:25 +00:00
|
|
|
void
|
|
|
|
i386_mp_probe(void)
|
1997-05-26 09:23:30 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
u_long segment;
|
|
|
|
u_int32_t target;
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MP_PROBE_POST);
|
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
/* see if EBDA exists */
|
1999-01-28 01:59:53 +00:00
|
|
|
if ((segment = (u_long) * (u_short *) (KERNBASE + 0x40e)) != 0) {
|
1997-05-26 09:23:30 +00:00
|
|
|
/* search first 1K of EBDA */
|
|
|
|
target = (u_int32_t) (segment << 4);
|
|
|
|
if ((x = search_for_sig(target, 1024 / 4)) >= 0)
|
|
|
|
goto found;
|
|
|
|
} else {
|
|
|
|
/* last 1K of base memory, effective 'top of base' passed in */
|
|
|
|
target = (u_int32_t) (base_memory - 0x400);
|
|
|
|
if ((x = search_for_sig(target, 1024 / 4)) >= 0)
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search the BIOS */
|
|
|
|
target = (u_int32_t) BIOS_BASE;
|
|
|
|
if ((x = search_for_sig(target, BIOS_COUNT)) >= 0)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
/* nothing found */
|
|
|
|
mpfps = (mpfps_t)0;
|
|
|
|
mp_capable = 0;
|
2001-04-27 19:28:25 +00:00
|
|
|
return;
|
1997-05-26 09:23:30 +00:00
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
found:
|
1997-05-26 09:23:30 +00:00
|
|
|
/* calculate needed resources */
|
|
|
|
mpfps = (mpfps_t)x;
|
2000-09-22 23:40:10 +00:00
|
|
|
mptable_pass1();
|
1997-05-26 09:23:30 +00:00
|
|
|
|
|
|
|
/* flag fact that we are running multiple processors */
|
|
|
|
mp_capable = 1;
|
|
|
|
}
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
int
|
|
|
|
cpu_mp_probe(void)
|
|
|
|
{
|
2001-07-26 18:47:46 +00:00
|
|
|
/*
|
|
|
|
* Record BSP in CPU map
|
|
|
|
* This is done here so that MBUF init code works correctly.
|
|
|
|
*/
|
|
|
|
all_cpus = 1;
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
return (mp_capable);
|
|
|
|
}
|
1997-05-26 09:23:30 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
2000-09-07 01:33:02 +00:00
|
|
|
* Initialize the SMP hardware and the APIC and start up the AP's.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-04-27 19:28:25 +00:00
|
|
|
cpu_mp_start(void)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MP_START_POST);
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* look for MP capable motherboard */
|
1997-05-26 09:23:30 +00:00
|
|
|
if (mp_capable)
|
1997-04-26 11:46:25 +00:00
|
|
|
mp_enable(boot_address);
|
1997-05-24 18:48:53 +00:00
|
|
|
else
|
1997-05-26 09:23:30 +00:00
|
|
|
panic("MP hardware not found!");
|
2001-04-27 19:28:25 +00:00
|
|
|
|
|
|
|
cpu_setregs();
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-07-08 23:46:00 +00:00
|
|
|
* Print various information about the SMP system hardware and setup.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-04-27 19:28:25 +00:00
|
|
|
cpu_mp_announce(void)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MP_ANNOUNCE_POST);
|
|
|
|
|
1997-07-18 03:58:14 +00:00
|
|
|
printf(" cpu0 (BSP): apic id: %2d", CPU_TO_ID(0));
|
1997-06-22 16:04:22 +00:00
|
|
|
printf(", version: 0x%08x", cpu_apic_versions[0]);
|
|
|
|
printf(", at 0x%08x\n", cpu_apic_address);
|
1997-04-26 11:46:25 +00:00
|
|
|
for (x = 1; x <= mp_naps; ++x) {
|
1997-07-20 18:05:20 +00:00
|
|
|
printf(" cpu%d (AP): apic id: %2d", x, CPU_TO_ID(x));
|
1997-06-22 16:04:22 +00:00
|
|
|
printf(", version: 0x%08x", cpu_apic_versions[x]);
|
|
|
|
printf(", at 0x%08x\n", cpu_apic_address);
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
for (x = 0; x < mp_napics; ++x) {
|
1997-07-18 03:58:14 +00:00
|
|
|
printf(" io%d (APIC): apic id: %2d", x, IO_TO_ID(x));
|
1997-06-22 16:04:22 +00:00
|
|
|
printf(", version: 0x%08x", io_apic_versions[x]);
|
|
|
|
printf(", at 0x%08x\n", io_apic_address[x]);
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
printf(" Warning: APIC I/O disabled\n");
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AP cpu's call this to sync up protected mode.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
init_secondary(void)
|
|
|
|
{
|
1997-09-21 15:03:59 +00:00
|
|
|
int gsel_tss;
|
1999-06-23 21:47:24 +00:00
|
|
|
int x, myid = bootAP;
|
2002-01-16 00:44:29 +00:00
|
|
|
u_int cr0;
|
1999-04-28 01:04:33 +00:00
|
|
|
|
|
|
|
gdt_segs[GPRIV_SEL].ssd_base = (int) &SMP_prvspace[myid];
|
|
|
|
gdt_segs[GPROC0_SEL].ssd_base =
|
2001-12-11 23:33:44 +00:00
|
|
|
(int) &SMP_prvspace[myid].pcpu.pc_common_tss;
|
|
|
|
SMP_prvspace[myid].pcpu.pc_prvspace =
|
|
|
|
&SMP_prvspace[myid].pcpu;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1999-04-28 01:04:33 +00:00
|
|
|
for (x = 0; x < NGDT; x++) {
|
|
|
|
ssdtosd(&gdt_segs[x], &gdt[myid * NGDT + x].sd);
|
|
|
|
}
|
|
|
|
|
|
|
|
r_gdt.rd_limit = NGDT * sizeof(gdt[0]) - 1;
|
|
|
|
r_gdt.rd_base = (int) &gdt[myid * NGDT];
|
1997-07-08 23:46:00 +00:00
|
|
|
lgdt(&r_gdt); /* does magic intra-segment return */
|
1999-04-28 01:04:33 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
lidt(&r_idt);
|
1999-04-28 01:04:33 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
lldt(_default_ldt);
|
2000-09-08 03:36:09 +00:00
|
|
|
PCPU_SET(currentldt, _default_ldt);
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1999-04-28 01:04:33 +00:00
|
|
|
gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
|
|
|
|
gdt[myid * NGDT + GPROC0_SEL].sd.sd_type = SDT_SYS386TSS;
|
2001-01-10 04:43:51 +00:00
|
|
|
PCPU_SET(common_tss.tss_esp0, 0); /* not used until after switch */
|
|
|
|
PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
|
|
|
|
PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
|
|
|
|
PCPU_SET(tss_gdt, &gdt[myid * NGDT + GPROC0_SEL].sd);
|
|
|
|
PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
|
1997-04-26 11:46:25 +00:00
|
|
|
ltr(gsel_tss);
|
|
|
|
|
2002-01-16 00:44:29 +00:00
|
|
|
/*
|
|
|
|
* Set to a known state:
|
|
|
|
* Set by mpboot.s: CR0_PG, CR0_PE
|
|
|
|
* Set by cpu_setregs: CR0_NE, CR0_MP, CR0_TS, CR0_WP, CR0_AM
|
|
|
|
*/
|
|
|
|
cr0 = rcr0();
|
|
|
|
cr0 &= ~(CR0_CD | CR0_NW | CR0_EM);
|
|
|
|
load_cr0(cr0);
|
|
|
|
|
1999-06-23 21:47:24 +00:00
|
|
|
pmap_set_opt();
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(APIC_IO)
|
1997-07-08 23:46:00 +00:00
|
|
|
/*
|
|
|
|
* Final configuration of the BSP's local APIC:
|
|
|
|
* - disable 'pic mode'.
|
|
|
|
* - disable 'virtual wire mode'.
|
|
|
|
* - enable NMI.
|
|
|
|
*/
|
1997-04-26 11:46:25 +00:00
|
|
|
void
|
1997-07-08 23:46:00 +00:00
|
|
|
bsp_apic_configure(void)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1997-07-08 23:46:00 +00:00
|
|
|
u_char byte;
|
|
|
|
u_int32_t temp;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
/* leave 'pic mode' if necessary */
|
1997-04-26 11:46:25 +00:00
|
|
|
if (picmode) {
|
|
|
|
outb(0x22, 0x70); /* select IMCR */
|
|
|
|
byte = inb(0x23); /* current contents */
|
1997-07-08 23:46:00 +00:00
|
|
|
byte |= 0x01; /* mask external INTR */
|
1997-04-26 11:46:25 +00:00
|
|
|
outb(0x23, byte); /* disconnect 8259s/NMI */
|
|
|
|
}
|
1997-06-27 22:27:18 +00:00
|
|
|
|
|
|
|
/* mask lint0 (the 8259 'virtual wire' connection) */
|
1997-06-22 16:04:22 +00:00
|
|
|
temp = lapic.lvt_lint0;
|
1997-07-08 23:46:00 +00:00
|
|
|
temp |= APIC_LVT_M; /* set the mask */
|
1997-06-22 16:04:22 +00:00
|
|
|
lapic.lvt_lint0 = temp;
|
1997-06-27 22:27:18 +00:00
|
|
|
|
|
|
|
/* setup lint1 to handle NMI */
|
|
|
|
temp = lapic.lvt_lint1;
|
1997-07-08 23:46:00 +00:00
|
|
|
temp &= ~APIC_LVT_M; /* clear the mask */
|
1997-06-27 22:27:18 +00:00
|
|
|
lapic.lvt_lint1 = temp;
|
1997-07-08 23:46:00 +00:00
|
|
|
|
1997-07-13 01:22:48 +00:00
|
|
|
if (bootverbose)
|
1997-07-20 18:05:20 +00:00
|
|
|
apic_dump("bsp_apic_configure()");
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1997-06-27 23:33:17 +00:00
|
|
|
#endif /* APIC_IO */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* local functions and data
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start the SMP system
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mp_enable(u_int boot_addr)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
int apic;
|
|
|
|
u_int ux;
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MP_ENABLE_POST);
|
|
|
|
|
1997-07-08 23:46:00 +00:00
|
|
|
/* turn on 4MB of V == P addressing so we can get to MP table */
|
1998-08-16 00:41:40 +00:00
|
|
|
*(int *)PTD = PG_V | PG_RW | ((uintptr_t)(void *)KPTphys & PG_FRAME);
|
1997-06-22 16:04:22 +00:00
|
|
|
invltlb();
|
|
|
|
|
|
|
|
/* examine the MP table for needed info, uses physical addresses */
|
1997-05-26 09:23:30 +00:00
|
|
|
x = mptable_pass2();
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-06-22 16:04:22 +00:00
|
|
|
*(int *)PTD = 0;
|
|
|
|
invltlb();
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* can't process default configs till the CPU APIC is pmapped */
|
|
|
|
if (x)
|
|
|
|
default_mp_table(x);
|
|
|
|
|
1997-08-09 23:01:03 +00:00
|
|
|
/* post scan cleanup */
|
|
|
|
fix_mp_table();
|
1998-09-06 22:41:42 +00:00
|
|
|
setup_apic_irq_mapping();
|
1997-08-09 23:01:03 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
#if defined(APIC_IO)
|
1997-07-13 01:22:48 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* fill the LOGICAL io_apic_versions table */
|
|
|
|
for (apic = 0; apic < mp_napics; ++apic) {
|
|
|
|
ux = io_apic_read(apic, IOAPIC_VER);
|
|
|
|
io_apic_versions[apic] = ux;
|
2000-05-31 21:37:28 +00:00
|
|
|
io_apic_set_id(apic, IO_TO_ID(apic));
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
1997-04-28 01:08:47 +00:00
|
|
|
/* program each IO APIC in the system */
|
1997-04-26 11:46:25 +00:00
|
|
|
for (apic = 0; apic < mp_napics; ++apic)
|
1997-05-29 05:07:10 +00:00
|
|
|
if (io_apic_setup(apic) < 0)
|
|
|
|
panic("IO APIC setup failure");
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-07-13 01:22:48 +00:00
|
|
|
/* install a 'Spurious INTerrupt' vector */
|
|
|
|
setidt(XSPURIOUSINT_OFFSET, Xspuriousint,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
|
|
|
|
1997-04-27 21:17:56 +00:00
|
|
|
/* install an inter-CPU IPI for TLB invalidation */
|
1997-06-27 23:33:17 +00:00
|
|
|
setidt(XINVLTLB_OFFSET, Xinvltlb,
|
1997-04-28 01:08:47 +00:00
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
2002-07-12 07:56:11 +00:00
|
|
|
setidt(XINVLPG_OFFSET, Xinvlpg,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
|
|
|
setidt(XINVLRNG_OFFSET, Xinvlrng,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
1997-06-27 23:33:17 +00:00
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
/* install an inter-CPU IPI for forwarding hardclock() */
|
|
|
|
setidt(XHARDCLOCK_OFFSET, Xhardclock,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
|
|
|
|
|
|
|
/* install an inter-CPU IPI for forwarding statclock() */
|
|
|
|
setidt(XSTATCLOCK_OFFSET, Xstatclock,
|
1997-12-08 23:00:24 +00:00
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
|
|
|
|
1999-07-20 06:52:35 +00:00
|
|
|
/* install an inter-CPU IPI for all-CPU rendezvous */
|
|
|
|
setidt(XRENDEZVOUS_OFFSET, Xrendezvous,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
|
|
|
|
1997-12-08 23:00:24 +00:00
|
|
|
/* install an inter-CPU IPI for forcing an additional software trap */
|
|
|
|
setidt(XCPUAST_OFFSET, Xcpuast,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
2001-01-21 19:25:07 +00:00
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
/* install an inter-CPU IPI for CPU stop/restart */
|
|
|
|
setidt(XCPUSTOP_OFFSET, Xcpustop,
|
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
1997-07-07 00:06:51 +00:00
|
|
|
|
1997-07-13 01:22:48 +00:00
|
|
|
#if defined(TEST_TEST1)
|
1997-07-18 21:27:53 +00:00
|
|
|
/* install a "fake hardware INTerrupt" vector */
|
1997-07-13 01:22:48 +00:00
|
|
|
setidt(XTEST1_OFFSET, Xtest1,
|
1997-07-07 00:06:51 +00:00
|
|
|
SDT_SYS386IGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
|
1997-07-13 01:22:48 +00:00
|
|
|
#endif /** TEST_TEST1 */
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
#endif /* APIC_IO */
|
|
|
|
|
1997-07-23 20:47:19 +00:00
|
|
|
/* initialize all SMP locks */
|
|
|
|
init_locks();
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* start each Application Processor */
|
|
|
|
start_all_aps(boot_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* look for the MP spec signature
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* string defined by the Intel MP Spec as identifying the MP table */
|
|
|
|
#define MP_SIG 0x5f504d5f /* _MP_ */
|
|
|
|
#define NEXT(X) ((X) += 4)
|
|
|
|
static int
|
|
|
|
search_for_sig(u_int32_t target, int count)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
u_int32_t *addr = (u_int32_t *) (KERNBASE + target);
|
|
|
|
|
|
|
|
for (x = 0; x < count; NEXT(x))
|
|
|
|
if (addr[x] == MP_SIG)
|
|
|
|
/* make array index a byte index */
|
|
|
|
return (target + (x * sizeof(u_int32_t)));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static basetable_entry basetable_entry_types[] =
|
|
|
|
{
|
|
|
|
{0, 20, "Processor"},
|
|
|
|
{1, 8, "Bus"},
|
|
|
|
{2, 8, "I/O APIC"},
|
|
|
|
{3, 8, "I/O INT"},
|
|
|
|
{4, 8, "Local INT"}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct BUSDATA {
|
|
|
|
u_char bus_id;
|
|
|
|
enum busTypes bus_type;
|
|
|
|
} bus_datum;
|
|
|
|
|
|
|
|
typedef struct INTDATA {
|
|
|
|
u_char int_type;
|
|
|
|
u_short int_flags;
|
|
|
|
u_char src_bus_id;
|
|
|
|
u_char src_bus_irq;
|
|
|
|
u_char dst_apic_id;
|
|
|
|
u_char dst_apic_int;
|
1998-09-06 22:41:42 +00:00
|
|
|
u_char int_vector;
|
1997-04-26 11:46:25 +00:00
|
|
|
} io_int, local_int;
|
|
|
|
|
|
|
|
typedef struct BUSTYPENAME {
|
|
|
|
u_char type;
|
|
|
|
char name[7];
|
|
|
|
} bus_type_name;
|
|
|
|
|
|
|
|
static bus_type_name bus_type_table[] =
|
|
|
|
{
|
|
|
|
{CBUS, "CBUS"},
|
|
|
|
{CBUSII, "CBUSII"},
|
|
|
|
{EISA, "EISA"},
|
2000-01-13 09:09:02 +00:00
|
|
|
{MCA, "MCA"},
|
1997-04-26 11:46:25 +00:00
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{ISA, "ISA"},
|
2000-01-13 09:09:02 +00:00
|
|
|
{MCA, "MCA"},
|
1997-04-26 11:46:25 +00:00
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{PCI, "PCI"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"},
|
|
|
|
{XPRESS, "XPRESS"},
|
|
|
|
{UNKNOWN_BUSTYPE, "---"}
|
|
|
|
};
|
|
|
|
/* from MP spec v1.4, table 5-1 */
|
|
|
|
static int default_data[7][5] =
|
|
|
|
{
|
|
|
|
/* nbus, id0, type0, id1, type1 */
|
|
|
|
{1, 0, ISA, 255, 255},
|
|
|
|
{1, 0, EISA, 255, 255},
|
|
|
|
{1, 0, EISA, 255, 255},
|
2000-01-13 09:09:02 +00:00
|
|
|
{1, 0, MCA, 255, 255},
|
1997-04-26 11:46:25 +00:00
|
|
|
{2, 0, ISA, 1, PCI},
|
|
|
|
{2, 0, EISA, 1, PCI},
|
2000-01-13 09:09:02 +00:00
|
|
|
{2, 0, MCA, 1, PCI}
|
1997-04-26 11:46:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* the bus data */
|
2000-09-22 23:40:10 +00:00
|
|
|
static bus_datum *bus_data;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* the IO INT data, one entry per possible APIC INTerrupt */
|
2000-09-22 23:40:10 +00:00
|
|
|
static io_int *io_apic_ints;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
static int nintrs;
|
|
|
|
|
2002-03-23 14:27:06 +00:00
|
|
|
static int processor_entry(proc_entry_ptr entry, int cpu);
|
|
|
|
static int bus_entry(bus_entry_ptr entry, int bus);
|
|
|
|
static int io_apic_entry(io_apic_entry_ptr entry, int apic);
|
|
|
|
static int int_entry(int_entry_ptr entry, int intr);
|
|
|
|
static int lookup_bus_type(char *name);
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-05-26 09:23:30 +00:00
|
|
|
* 1st pass on motherboard's Intel MP specification table.
|
|
|
|
*
|
|
|
|
* initializes:
|
|
|
|
* mp_ncpus = 1
|
|
|
|
*
|
|
|
|
* determines:
|
|
|
|
* cpu_apic_address (common to all CPUs)
|
|
|
|
* io_apic_address[N]
|
|
|
|
* mp_naps
|
|
|
|
* mp_nbusses
|
|
|
|
* mp_napics
|
|
|
|
* nintrs
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
2000-09-22 23:40:10 +00:00
|
|
|
static void
|
1997-05-26 09:23:30 +00:00
|
|
|
mptable_pass1(void)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1997-05-25 02:49:03 +00:00
|
|
|
int x;
|
|
|
|
mpcth_t cth;
|
|
|
|
int totalSize;
|
|
|
|
void* position;
|
|
|
|
int count;
|
|
|
|
int type;
|
2003-01-08 01:33:18 +00:00
|
|
|
u_int id_mask;
|
1997-05-25 02:49:03 +00:00
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MPTABLE_PASS1_POST);
|
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
/* clear various tables */
|
|
|
|
for (x = 0; x < NAPICID; ++x) {
|
|
|
|
io_apic_address[x] = ~0; /* IO APIC address table */
|
|
|
|
}
|
1997-05-25 02:49:03 +00:00
|
|
|
|
|
|
|
/* init everything to empty */
|
|
|
|
mp_naps = 0;
|
|
|
|
mp_nbusses = 0;
|
|
|
|
mp_napics = 0;
|
|
|
|
nintrs = 0;
|
2003-01-08 01:33:18 +00:00
|
|
|
id_mask = 0;
|
1997-05-25 02:49:03 +00:00
|
|
|
|
|
|
|
/* check for use of 'default' configuration */
|
1997-08-09 23:01:03 +00:00
|
|
|
if (MPFPS_MPFB1 != 0) {
|
1997-05-25 02:49:03 +00:00
|
|
|
/* use default addresses */
|
|
|
|
cpu_apic_address = DEFAULT_APIC_BASE;
|
|
|
|
io_apic_address[0] = DEFAULT_IO_APIC_BASE;
|
|
|
|
|
|
|
|
/* fill in with defaults */
|
1997-06-24 06:55:30 +00:00
|
|
|
mp_naps = 2; /* includes BSP */
|
2002-03-05 10:01:46 +00:00
|
|
|
mp_maxid = 1;
|
1997-08-09 23:01:03 +00:00
|
|
|
mp_nbusses = default_data[MPFPS_MPFB1 - 1][0];
|
1997-05-25 02:49:03 +00:00
|
|
|
#if defined(APIC_IO)
|
|
|
|
mp_napics = 1;
|
|
|
|
nintrs = 16;
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
|
|
|
else {
|
1997-05-26 09:23:30 +00:00
|
|
|
if ((cth = mpfps->pap) == 0)
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("MP Configuration Table Header MISSING!");
|
|
|
|
|
|
|
|
cpu_apic_address = (vm_offset_t) cth->apic_address;
|
|
|
|
|
|
|
|
/* walk the table, recording info of interest */
|
|
|
|
totalSize = cth->base_table_length - sizeof(struct MPCTH);
|
|
|
|
position = (u_char *) cth + sizeof(struct MPCTH);
|
|
|
|
count = cth->entry_count;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
switch (type = *(u_char *) position) {
|
|
|
|
case 0: /* processor_entry */
|
|
|
|
if (((proc_entry_ptr)position)->cpu_flags
|
2002-03-05 10:01:46 +00:00
|
|
|
& PROCENTRY_FLAG_EN) {
|
1997-05-25 02:49:03 +00:00
|
|
|
++mp_naps;
|
2002-03-05 10:01:46 +00:00
|
|
|
mp_maxid++;
|
2003-01-08 01:33:18 +00:00
|
|
|
id_mask |= 1 <<
|
|
|
|
((proc_entry_ptr)position)->apic_id;
|
2002-03-05 10:01:46 +00:00
|
|
|
}
|
1997-05-25 02:49:03 +00:00
|
|
|
break;
|
|
|
|
case 1: /* bus_entry */
|
|
|
|
++mp_nbusses;
|
|
|
|
break;
|
|
|
|
case 2: /* io_apic_entry */
|
|
|
|
if (((io_apic_entry_ptr)position)->apic_flags
|
|
|
|
& IOAPICENTRY_FLAG_EN)
|
|
|
|
io_apic_address[mp_napics++] =
|
|
|
|
(vm_offset_t)((io_apic_entry_ptr)
|
|
|
|
position)->apic_address;
|
|
|
|
break;
|
|
|
|
case 3: /* int_entry */
|
|
|
|
++nintrs;
|
|
|
|
break;
|
|
|
|
case 4: /* int_entry */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("mpfps Base Table HOSED!");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
totalSize -= basetable_entry_types[type].length;
|
|
|
|
(u_char*)position += basetable_entry_types[type].length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* qualify the numbers */
|
2000-09-22 23:40:10 +00:00
|
|
|
if (mp_naps > MAXCPU) {
|
1997-05-25 02:49:03 +00:00
|
|
|
printf("Warning: only using %d of %d available CPUs!\n",
|
2000-09-22 23:40:10 +00:00
|
|
|
MAXCPU, mp_naps);
|
|
|
|
mp_naps = MAXCPU;
|
1997-05-25 02:49:03 +00:00
|
|
|
}
|
|
|
|
|
2003-01-08 01:33:18 +00:00
|
|
|
/* See if we need to fixup HT logical CPUs. */
|
|
|
|
mptable_hyperthread_fixup(id_mask);
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
/*
|
|
|
|
* Count the BSP.
|
|
|
|
* This is also used as a counter while starting the APs.
|
|
|
|
*/
|
|
|
|
mp_ncpus = 1;
|
|
|
|
|
|
|
|
--mp_naps; /* subtract the BSP */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-05-26 09:23:30 +00:00
|
|
|
* 2nd pass on motherboard's Intel MP specification table.
|
|
|
|
*
|
|
|
|
* sets:
|
|
|
|
* boot_cpu_id
|
|
|
|
* ID_TO_IO(N), phy APIC ID to log CPU/IO table
|
|
|
|
* CPU_TO_ID(N), logical CPU to APIC ID table
|
|
|
|
* IO_TO_ID(N), logical IO to APIC ID table
|
|
|
|
* bus_data[N]
|
|
|
|
* io_apic_ints[N]
|
1997-05-25 02:49:03 +00:00
|
|
|
*/
|
|
|
|
static int
|
1997-05-26 09:23:30 +00:00
|
|
|
mptable_pass2(void)
|
1997-05-25 02:49:03 +00:00
|
|
|
{
|
2003-01-08 01:33:18 +00:00
|
|
|
struct PROCENTRY proc;
|
1997-05-25 02:49:03 +00:00
|
|
|
int x;
|
|
|
|
mpcth_t cth;
|
|
|
|
int totalSize;
|
|
|
|
void* position;
|
|
|
|
int count;
|
|
|
|
int type;
|
|
|
|
int apic, bus, cpu, intr;
|
2000-09-22 23:40:10 +00:00
|
|
|
int i, j;
|
|
|
|
int pgeflag;
|
1997-05-25 02:49:03 +00:00
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(MPTABLE_PASS2_POST);
|
|
|
|
|
2003-01-08 01:33:18 +00:00
|
|
|
/* Initialize fake proc entry for use with HT fixup. */
|
|
|
|
bzero(&proc, sizeof(proc));
|
|
|
|
proc.type = 0;
|
|
|
|
proc.cpu_flags = PROCENTRY_FLAG_EN;
|
|
|
|
|
2000-09-22 23:40:10 +00:00
|
|
|
pgeflag = 0; /* XXX - Not used under SMP yet. */
|
|
|
|
|
|
|
|
MALLOC(io_apic_versions, u_int32_t *, sizeof(u_int32_t) * mp_napics,
|
2003-01-21 08:56:16 +00:00
|
|
|
M_DEVBUF, 0);
|
2000-09-22 23:40:10 +00:00
|
|
|
MALLOC(ioapic, volatile ioapic_t **, sizeof(ioapic_t *) * mp_napics,
|
2003-01-21 08:56:16 +00:00
|
|
|
M_DEVBUF, 0);
|
2000-12-06 03:47:14 +00:00
|
|
|
MALLOC(io_apic_ints, io_int *, sizeof(io_int) * (nintrs + 1),
|
2003-01-21 08:56:16 +00:00
|
|
|
M_DEVBUF, 0);
|
2000-09-22 23:40:10 +00:00
|
|
|
MALLOC(bus_data, bus_datum *, sizeof(bus_datum) * mp_nbusses,
|
2003-01-21 08:56:16 +00:00
|
|
|
M_DEVBUF, 0);
|
2000-09-22 23:40:10 +00:00
|
|
|
|
|
|
|
bzero(ioapic, sizeof(ioapic_t *) * mp_napics);
|
|
|
|
|
|
|
|
for (i = 0; i < mp_napics; i++) {
|
|
|
|
for (j = 0; j < mp_napics; j++) {
|
|
|
|
/* same page frame as a previous IO apic? */
|
|
|
|
if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) ==
|
|
|
|
(io_apic_address[i] & PG_FRAME)) {
|
|
|
|
ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
|
|
|
|
+ (NPTEPG-2-j) * PAGE_SIZE
|
|
|
|
+ (io_apic_address[i] & PAGE_MASK));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* use this slot if available */
|
|
|
|
if (((vm_offset_t)SMPpt[NPTEPG-2-j] & PG_FRAME) == 0) {
|
|
|
|
SMPpt[NPTEPG-2-j] = (pt_entry_t)(PG_V | PG_RW |
|
|
|
|
pgeflag | (io_apic_address[i] & PG_FRAME));
|
|
|
|
ioapic[i] = (ioapic_t *)((u_int)SMP_prvspace
|
|
|
|
+ (NPTEPG-2-j) * PAGE_SIZE
|
|
|
|
+ (io_apic_address[i] & PAGE_MASK));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
/* clear various tables */
|
|
|
|
for (x = 0; x < NAPICID; ++x) {
|
|
|
|
ID_TO_IO(x) = -1; /* phy APIC ID to log CPU/IO table */
|
|
|
|
CPU_TO_ID(x) = -1; /* logical CPU to APIC ID table */
|
|
|
|
IO_TO_ID(x) = -1; /* logical IO to APIC ID table */
|
|
|
|
}
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* clear bus data table */
|
2000-09-22 23:40:10 +00:00
|
|
|
for (x = 0; x < mp_nbusses; ++x)
|
1997-04-26 11:46:25 +00:00
|
|
|
bus_data[x].bus_id = 0xff;
|
|
|
|
|
|
|
|
/* clear IO APIC INT table */
|
2000-12-06 03:47:14 +00:00
|
|
|
for (x = 0; x < (nintrs + 1); ++x) {
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_ints[x].int_type = 0xff;
|
1998-09-06 22:41:42 +00:00
|
|
|
io_apic_ints[x].int_vector = 0xff;
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* setup the cpu/apic mapping arrays */
|
|
|
|
boot_cpu_id = -1;
|
|
|
|
|
|
|
|
/* record whether PIC or virtual-wire mode */
|
1997-05-26 09:23:30 +00:00
|
|
|
picmode = (mpfps->mpfb2 & 0x80) ? 1 : 0;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* check for use of 'default' configuration */
|
1997-08-09 23:01:03 +00:00
|
|
|
if (MPFPS_MPFB1 != 0)
|
|
|
|
return MPFPS_MPFB1; /* return default configuration type */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-26 09:23:30 +00:00
|
|
|
if ((cth = mpfps->pap) == 0)
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("MP Configuration Table Header MISSING!");
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
/* walk the table, recording info of interest */
|
1997-04-26 11:46:25 +00:00
|
|
|
totalSize = cth->base_table_length - sizeof(struct MPCTH);
|
|
|
|
position = (u_char *) cth + sizeof(struct MPCTH);
|
|
|
|
count = cth->entry_count;
|
1997-05-25 02:49:03 +00:00
|
|
|
apic = bus = intr = 0;
|
|
|
|
cpu = 1; /* pre-count the BSP */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
switch (type = *(u_char *) position) {
|
|
|
|
case 0:
|
1997-05-25 02:49:03 +00:00
|
|
|
if (processor_entry(position, cpu))
|
|
|
|
++cpu;
|
2003-01-08 01:33:18 +00:00
|
|
|
|
|
|
|
if (need_hyperthreading_fixup) {
|
|
|
|
/*
|
|
|
|
* Create fake mptable processor entries
|
|
|
|
* and feed them to processor_entry() to
|
|
|
|
* enumerate the logical CPUs.
|
|
|
|
*/
|
|
|
|
proc.apic_id = ((proc_entry_ptr)position)->apic_id;
|
|
|
|
for (i = 1; i < logical_cpus; i++) {
|
|
|
|
proc.apic_id++;
|
|
|
|
(void)processor_entry(&proc, cpu);
|
|
|
|
cpu++;
|
|
|
|
}
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
1997-05-25 02:49:03 +00:00
|
|
|
if (bus_entry(position, bus))
|
|
|
|
++bus;
|
1997-04-26 11:46:25 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
1997-05-25 02:49:03 +00:00
|
|
|
if (io_apic_entry(position, apic))
|
|
|
|
++apic;
|
1997-04-26 11:46:25 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
1997-05-25 02:49:03 +00:00
|
|
|
if (int_entry(position, intr))
|
|
|
|
++intr;
|
1997-04-26 11:46:25 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* int_entry(position); */
|
|
|
|
break;
|
|
|
|
default:
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("mpfps Base Table HOSED!");
|
1997-04-26 11:46:25 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
totalSize -= basetable_entry_types[type].length;
|
|
|
|
(u_char *) position += basetable_entry_types[type].length;
|
|
|
|
}
|
|
|
|
|
1997-05-24 18:48:53 +00:00
|
|
|
if (boot_cpu_id == -1)
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("NO BSP found!");
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* report fact that its NOT a default configuration */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-08 01:33:18 +00:00
|
|
|
/*
|
|
|
|
* Check if we should perform a hyperthreading "fix-up" to
|
|
|
|
* enumerate any logical CPU's that aren't already listed
|
|
|
|
* in the table.
|
|
|
|
*
|
|
|
|
* XXX: We assume that all of the physical CPUs in the
|
|
|
|
* system have the same number of logical CPUs.
|
|
|
|
*
|
|
|
|
* XXX: We assume that APIC ID's are allocated such that
|
|
|
|
* the APIC ID's for a physical processor are aligned
|
|
|
|
* with the number of logical CPU's in the processor.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mptable_hyperthread_fixup(u_int id_mask)
|
|
|
|
{
|
|
|
|
u_int i, id;
|
|
|
|
|
|
|
|
/* Nothing to do if there is no HTT support. */
|
|
|
|
if ((cpu_feature & CPUID_HTT) == 0)
|
|
|
|
return;
|
2003-01-22 17:54:12 +00:00
|
|
|
logical_cpus = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
|
2003-01-08 01:33:18 +00:00
|
|
|
if (logical_cpus <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For each APIC ID of a CPU that is set in the mask,
|
|
|
|
* scan the other candidate APIC ID's for this
|
|
|
|
* physical processor. If any of those ID's are
|
|
|
|
* already in the table, then kill the fixup.
|
|
|
|
*/
|
|
|
|
for (id = 0; id <= MAXCPU; id++) {
|
|
|
|
if ((id_mask & 1 << id) == 0)
|
|
|
|
continue;
|
|
|
|
/* First, make sure we are on a logical_cpus boundary. */
|
|
|
|
if (id % logical_cpus != 0)
|
|
|
|
return;
|
|
|
|
for (i = id + 1; i < id + logical_cpus; i++)
|
|
|
|
if ((id_mask & 1 << i) != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, the ID's checked out, so enable the fixup. We have to fixup
|
|
|
|
* mp_naps and mp_maxid right now.
|
|
|
|
*/
|
|
|
|
need_hyperthreading_fixup = 1;
|
|
|
|
mp_maxid *= logical_cpus;
|
|
|
|
mp_naps *= logical_cpus;
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2000-01-04 22:24:59 +00:00
|
|
|
void
|
1998-09-06 22:41:42 +00:00
|
|
|
assign_apic_irq(int apic, int intpin, int irq)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
if (int_to_apicintpin[irq].ioapic != -1)
|
|
|
|
panic("assign_apic_irq: inconsistent table");
|
|
|
|
|
|
|
|
int_to_apicintpin[irq].ioapic = apic;
|
|
|
|
int_to_apicintpin[irq].int_pin = intpin;
|
|
|
|
int_to_apicintpin[irq].apic_address = ioapic[apic];
|
|
|
|
int_to_apicintpin[irq].redirindex = IOAPIC_REDTBL + 2 * intpin;
|
|
|
|
|
|
|
|
for (x = 0; x < nintrs; x++) {
|
|
|
|
if ((io_apic_ints[x].int_type == 0 ||
|
|
|
|
io_apic_ints[x].int_type == 3) &&
|
|
|
|
io_apic_ints[x].int_vector == 0xff &&
|
|
|
|
io_apic_ints[x].dst_apic_id == IO_TO_ID(apic) &&
|
|
|
|
io_apic_ints[x].dst_apic_int == intpin)
|
|
|
|
io_apic_ints[x].int_vector = irq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-04 22:24:59 +00:00
|
|
|
void
|
|
|
|
revoke_apic_irq(int irq)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int oldapic;
|
|
|
|
int oldintpin;
|
|
|
|
|
|
|
|
if (int_to_apicintpin[irq].ioapic == -1)
|
2002-04-17 22:41:58 +00:00
|
|
|
panic("revoke_apic_irq: inconsistent table");
|
2000-01-04 22:24:59 +00:00
|
|
|
|
|
|
|
oldapic = int_to_apicintpin[irq].ioapic;
|
|
|
|
oldintpin = int_to_apicintpin[irq].int_pin;
|
|
|
|
|
|
|
|
int_to_apicintpin[irq].ioapic = -1;
|
|
|
|
int_to_apicintpin[irq].int_pin = 0;
|
|
|
|
int_to_apicintpin[irq].apic_address = NULL;
|
|
|
|
int_to_apicintpin[irq].redirindex = 0;
|
|
|
|
|
|
|
|
for (x = 0; x < nintrs; x++) {
|
|
|
|
if ((io_apic_ints[x].int_type == 0 ||
|
|
|
|
io_apic_ints[x].int_type == 3) &&
|
2002-04-17 18:27:10 +00:00
|
|
|
io_apic_ints[x].int_vector != 0xff &&
|
2000-01-04 22:24:59 +00:00
|
|
|
io_apic_ints[x].dst_apic_id == IO_TO_ID(oldapic) &&
|
|
|
|
io_apic_ints[x].dst_apic_int == oldintpin)
|
|
|
|
io_apic_ints[x].int_vector = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-06 00:04:03 +00:00
|
|
|
|
2001-01-28 01:07:54 +00:00
|
|
|
static void
|
|
|
|
allocate_apic_irq(int intr)
|
|
|
|
{
|
|
|
|
int apic;
|
|
|
|
int intpin;
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
if (io_apic_ints[intr].int_vector != 0xff)
|
|
|
|
return; /* Interrupt handler already assigned */
|
|
|
|
|
|
|
|
if (io_apic_ints[intr].int_type != 0 &&
|
|
|
|
(io_apic_ints[intr].int_type != 3 ||
|
|
|
|
(io_apic_ints[intr].dst_apic_id == IO_TO_ID(0) &&
|
|
|
|
io_apic_ints[intr].dst_apic_int == 0)))
|
|
|
|
return; /* Not INT or ExtInt on != (0, 0) */
|
|
|
|
|
|
|
|
irq = 0;
|
|
|
|
while (irq < APIC_INTMAPSIZE &&
|
|
|
|
int_to_apicintpin[irq].ioapic != -1)
|
|
|
|
irq++;
|
|
|
|
|
|
|
|
if (irq >= APIC_INTMAPSIZE)
|
|
|
|
return; /* No free interrupt handlers */
|
|
|
|
|
|
|
|
apic = ID_TO_IO(io_apic_ints[intr].dst_apic_id);
|
|
|
|
intpin = io_apic_ints[intr].dst_apic_int;
|
|
|
|
|
|
|
|
assign_apic_irq(apic, intpin, irq);
|
|
|
|
io_apic_setup_intpin(apic, intpin);
|
|
|
|
}
|
|
|
|
|
2000-08-06 00:04:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
swap_apic_id(int apic, int oldid, int newid)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int oapic;
|
|
|
|
|
|
|
|
|
|
|
|
if (oldid == newid)
|
|
|
|
return; /* Nothing to do */
|
|
|
|
|
|
|
|
printf("Changing APIC ID for IO APIC #%d from %d to %d in MP table\n",
|
|
|
|
apic, oldid, newid);
|
|
|
|
|
|
|
|
/* Swap physical APIC IDs in interrupt entries */
|
|
|
|
for (x = 0; x < nintrs; x++) {
|
|
|
|
if (io_apic_ints[x].dst_apic_id == oldid)
|
|
|
|
io_apic_ints[x].dst_apic_id = newid;
|
|
|
|
else if (io_apic_ints[x].dst_apic_id == newid)
|
|
|
|
io_apic_ints[x].dst_apic_id = oldid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swap physical APIC IDs in IO_TO_ID mappings */
|
|
|
|
for (oapic = 0; oapic < mp_napics; oapic++)
|
|
|
|
if (IO_TO_ID(oapic) == newid)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (oapic < mp_napics) {
|
|
|
|
printf("Changing APIC ID for IO APIC #%d from "
|
|
|
|
"%d to %d in MP table\n",
|
|
|
|
oapic, newid, oldid);
|
|
|
|
IO_TO_ID(oapic) = oldid;
|
|
|
|
}
|
|
|
|
IO_TO_ID(apic) = newid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
fix_id_to_io_mapping(void)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for (x = 0; x < NAPICID; x++)
|
|
|
|
ID_TO_IO(x) = -1;
|
|
|
|
|
|
|
|
for (x = 0; x <= mp_naps; x++)
|
|
|
|
if (CPU_TO_ID(x) < NAPICID)
|
|
|
|
ID_TO_IO(CPU_TO_ID(x)) = x;
|
|
|
|
|
|
|
|
for (x = 0; x < mp_napics; x++)
|
|
|
|
if (IO_TO_ID(x) < NAPICID)
|
|
|
|
ID_TO_IO(IO_TO_ID(x)) = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
first_free_apic_id(void)
|
|
|
|
{
|
|
|
|
int freeid, x;
|
|
|
|
|
|
|
|
for (freeid = 0; freeid < NAPICID; freeid++) {
|
|
|
|
for (x = 0; x <= mp_naps; x++)
|
|
|
|
if (CPU_TO_ID(x) == freeid)
|
|
|
|
break;
|
|
|
|
if (x <= mp_naps)
|
|
|
|
continue;
|
|
|
|
for (x = 0; x < mp_napics; x++)
|
|
|
|
if (IO_TO_ID(x) == freeid)
|
|
|
|
break;
|
|
|
|
if (x < mp_napics)
|
|
|
|
continue;
|
|
|
|
return freeid;
|
|
|
|
}
|
|
|
|
return freeid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
io_apic_id_acceptable(int apic, int id)
|
|
|
|
{
|
|
|
|
int cpu; /* Logical CPU number */
|
|
|
|
int oapic; /* Logical IO APIC number for other IO APIC */
|
|
|
|
|
|
|
|
if (id >= NAPICID)
|
|
|
|
return 0; /* Out of range */
|
|
|
|
|
|
|
|
for (cpu = 0; cpu <= mp_naps; cpu++)
|
|
|
|
if (CPU_TO_ID(cpu) == id)
|
|
|
|
return 0; /* Conflict with CPU */
|
|
|
|
|
|
|
|
for (oapic = 0; oapic < mp_napics && oapic < apic; oapic++)
|
|
|
|
if (IO_TO_ID(oapic) == id)
|
|
|
|
return 0; /* Conflict with other APIC */
|
|
|
|
|
|
|
|
return 1; /* ID is acceptable for IO APIC */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
|
|
|
* parse an Intel MP specification table
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fix_mp_table(void)
|
|
|
|
{
|
1997-04-29 22:12:32 +00:00
|
|
|
int x;
|
|
|
|
int id;
|
1999-01-12 00:19:33 +00:00
|
|
|
int bus_0 = 0; /* Stop GCC warning */
|
|
|
|
int bus_pci = 0; /* Stop GCC warning */
|
1997-04-29 22:12:32 +00:00
|
|
|
int num_pci_bus;
|
2000-08-06 00:04:03 +00:00
|
|
|
int apic; /* IO APIC unit number */
|
|
|
|
int freeid; /* Free physical APIC ID */
|
|
|
|
int physid; /* Current physical IO APIC ID */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fix mis-numbering of the PCI bus and its INT entries if the BIOS
|
|
|
|
* did it wrong. The MP spec says that when more than 1 PCI bus
|
|
|
|
* exists the BIOS must begin with bus entries for the PCI bus and use
|
|
|
|
* actual PCI bus numbering. This implies that when only 1 PCI bus
|
|
|
|
* exists the BIOS can choose to ignore this ordering, and indeed many
|
|
|
|
* MP motherboards do ignore it. This causes a problem when the PCI
|
|
|
|
* sub-system makes requests of the MP sub-system based on PCI bus
|
|
|
|
* numbers. So here we look for the situation and renumber the
|
|
|
|
* busses and associated INTs in an effort to "make it right".
|
|
|
|
*/
|
|
|
|
|
1997-04-29 22:12:32 +00:00
|
|
|
/* find bus 0, PCI bus, count the number of PCI busses */
|
1997-04-26 11:46:25 +00:00
|
|
|
for (num_pci_bus = 0, x = 0; x < mp_nbusses; ++x) {
|
1997-04-29 22:12:32 +00:00
|
|
|
if (bus_data[x].bus_id == 0) {
|
|
|
|
bus_0 = x;
|
|
|
|
}
|
|
|
|
if (bus_data[x].bus_type == PCI) {
|
1997-04-26 11:46:25 +00:00
|
|
|
++num_pci_bus;
|
1997-04-29 22:12:32 +00:00
|
|
|
bus_pci = x;
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1997-04-29 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* bus_0 == slot of bus with ID of 0
|
|
|
|
* bus_pci == slot of last PCI bus encountered
|
|
|
|
*/
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* check the 1 PCI bus case for sanity */
|
2000-08-10 17:33:24 +00:00
|
|
|
/* if it is number 0 all is well */
|
|
|
|
if (num_pci_bus == 1 &&
|
|
|
|
bus_data[bus_pci].bus_id != 0) {
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* mis-numbered, swap with whichever bus uses slot 0 */
|
|
|
|
|
1997-04-29 22:12:32 +00:00
|
|
|
/* swap the bus entry types */
|
|
|
|
bus_data[bus_pci].bus_type = bus_data[bus_0].bus_type;
|
|
|
|
bus_data[bus_0].bus_type = PCI;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* swap each relavant INTerrupt entry */
|
1997-04-29 22:12:32 +00:00
|
|
|
id = bus_data[bus_pci].bus_id;
|
|
|
|
for (x = 0; x < nintrs; ++x) {
|
|
|
|
if (io_apic_ints[x].src_bus_id == id) {
|
|
|
|
io_apic_ints[x].src_bus_id = 0;
|
|
|
|
}
|
|
|
|
else if (io_apic_ints[x].src_bus_id == 0) {
|
|
|
|
io_apic_ints[x].src_bus_id = id;
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-06 00:04:03 +00:00
|
|
|
|
|
|
|
/* Assign IO APIC IDs.
|
|
|
|
*
|
|
|
|
* First try the existing ID. If a conflict is detected, try
|
|
|
|
* the ID in the MP table. If a conflict is still detected, find
|
|
|
|
* a free id.
|
|
|
|
*
|
|
|
|
* We cannot use the ID_TO_IO table before all conflicts has been
|
|
|
|
* resolved and the table has been corrected.
|
|
|
|
*/
|
|
|
|
for (apic = 0; apic < mp_napics; ++apic) { /* For all IO APICs */
|
|
|
|
|
|
|
|
/* First try to use the value set by the BIOS */
|
|
|
|
physid = io_apic_get_id(apic);
|
|
|
|
if (io_apic_id_acceptable(apic, physid)) {
|
|
|
|
if (IO_TO_ID(apic) != physid)
|
|
|
|
swap_apic_id(apic, IO_TO_ID(apic), physid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then check if the value in the MP table is acceptable */
|
|
|
|
if (io_apic_id_acceptable(apic, IO_TO_ID(apic)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Last resort, find a free APIC ID and use it */
|
|
|
|
freeid = first_free_apic_id();
|
|
|
|
if (freeid >= NAPICID)
|
|
|
|
panic("No free physical APIC IDs found");
|
|
|
|
|
|
|
|
if (io_apic_id_acceptable(apic, freeid)) {
|
|
|
|
swap_apic_id(apic, IO_TO_ID(apic), freeid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
panic("Free physical APIC ID not usable");
|
|
|
|
}
|
|
|
|
fix_id_to_io_mapping();
|
2000-12-06 03:47:14 +00:00
|
|
|
|
|
|
|
/* detect and fix broken Compaq MP table */
|
|
|
|
if (apic_int_type(0, 0) == -1) {
|
|
|
|
printf("APIC_IO: MP table broken: 8259->APIC entry missing!\n");
|
|
|
|
io_apic_ints[nintrs].int_type = 3; /* ExtInt */
|
|
|
|
io_apic_ints[nintrs].int_vector = 0xff; /* Unassigned */
|
|
|
|
/* XXX fixme, set src bus id etc, but it doesn't seem to hurt */
|
|
|
|
io_apic_ints[nintrs].dst_apic_id = IO_TO_ID(0);
|
|
|
|
io_apic_ints[nintrs].dst_apic_int = 0; /* Pin 0 */
|
|
|
|
nintrs++;
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-04 22:24:59 +00:00
|
|
|
/* Assign low level interrupt handlers */
|
1998-09-06 22:41:42 +00:00
|
|
|
static void
|
|
|
|
setup_apic_irq_mapping(void)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int int_vector;
|
|
|
|
|
2000-01-04 22:24:59 +00:00
|
|
|
/* Clear array */
|
1998-09-06 22:41:42 +00:00
|
|
|
for (x = 0; x < APIC_INTMAPSIZE; x++) {
|
|
|
|
int_to_apicintpin[x].ioapic = -1;
|
|
|
|
int_to_apicintpin[x].int_pin = 0;
|
|
|
|
int_to_apicintpin[x].apic_address = NULL;
|
|
|
|
int_to_apicintpin[x].redirindex = 0;
|
|
|
|
}
|
2000-01-04 22:24:59 +00:00
|
|
|
|
|
|
|
/* First assign ISA/EISA interrupts */
|
|
|
|
for (x = 0; x < nintrs; x++) {
|
|
|
|
int_vector = io_apic_ints[x].src_bus_irq;
|
|
|
|
if (int_vector < APIC_INTMAPSIZE &&
|
|
|
|
io_apic_ints[x].int_vector == 0xff &&
|
|
|
|
int_to_apicintpin[int_vector].ioapic == -1 &&
|
|
|
|
(apic_int_is_bus_type(x, ISA) ||
|
|
|
|
apic_int_is_bus_type(x, EISA)) &&
|
|
|
|
io_apic_ints[x].int_type == 0) {
|
|
|
|
assign_apic_irq(ID_TO_IO(io_apic_ints[x].dst_apic_id),
|
|
|
|
io_apic_ints[x].dst_apic_int,
|
|
|
|
int_vector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-28 01:07:54 +00:00
|
|
|
/* Assign ExtInt entry if no ISA/EISA interrupt 0 entry */
|
1998-09-06 22:41:42 +00:00
|
|
|
for (x = 0; x < nintrs; x++) {
|
2001-01-28 01:07:54 +00:00
|
|
|
if (io_apic_ints[x].dst_apic_int == 0 &&
|
1998-09-06 22:41:42 +00:00
|
|
|
io_apic_ints[x].dst_apic_id == IO_TO_ID(0) &&
|
|
|
|
io_apic_ints[x].int_vector == 0xff &&
|
2001-01-28 01:07:54 +00:00
|
|
|
int_to_apicintpin[0].ioapic == -1 &&
|
|
|
|
io_apic_ints[x].int_type == 3) {
|
|
|
|
assign_apic_irq(0, 0, 0);
|
|
|
|
break;
|
1998-09-06 22:41:42 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-28 01:07:54 +00:00
|
|
|
/* PCI interrupt assignment is deferred */
|
1998-09-06 22:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
static int
|
|
|
|
processor_entry(proc_entry_ptr entry, int cpu)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
/* check for usability */
|
2000-01-07 08:49:25 +00:00
|
|
|
if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
|
1997-05-25 02:49:03 +00:00
|
|
|
return 0;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2000-08-06 00:04:03 +00:00
|
|
|
if(entry->apic_id >= NAPICID)
|
|
|
|
panic("CPU APIC ID out of range (0..%d)", NAPICID - 1);
|
1997-04-26 11:46:25 +00:00
|
|
|
/* check for BSP flag */
|
|
|
|
if (entry->cpu_flags & PROCENTRY_FLAG_BP) {
|
|
|
|
boot_cpu_id = entry->apic_id;
|
1997-05-25 02:49:03 +00:00
|
|
|
CPU_TO_ID(0) = entry->apic_id;
|
|
|
|
ID_TO_CPU(entry->apic_id) = 0;
|
|
|
|
return 0; /* its already been counted */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
/* add another AP to list, if less than max number of CPUs */
|
2000-09-22 23:40:10 +00:00
|
|
|
else if (cpu < MAXCPU) {
|
1997-05-25 02:49:03 +00:00
|
|
|
CPU_TO_ID(cpu) = entry->apic_id;
|
|
|
|
ID_TO_CPU(entry->apic_id) = cpu;
|
|
|
|
return 1;
|
|
|
|
}
|
2000-01-07 08:49:25 +00:00
|
|
|
|
|
|
|
return 0;
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
static int
|
|
|
|
bus_entry(bus_entry_ptr entry, int bus)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1997-05-25 02:49:03 +00:00
|
|
|
int x;
|
|
|
|
char c, name[8];
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* encode the name into an index */
|
1997-05-25 02:49:03 +00:00
|
|
|
for (x = 0; x < 6; ++x) {
|
|
|
|
if ((c = entry->bus_type[x]) == ' ')
|
1997-04-26 11:46:25 +00:00
|
|
|
break;
|
1997-05-25 02:49:03 +00:00
|
|
|
name[x] = c;
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1997-05-25 02:49:03 +00:00
|
|
|
name[x] = '\0';
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
if ((x = lookup_bus_type(name)) == UNKNOWN_BUSTYPE)
|
|
|
|
panic("unknown bus type: '%s'", name);
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
bus_data[bus].bus_id = entry->bus_id;
|
|
|
|
bus_data[bus].bus_type = x;
|
|
|
|
|
|
|
|
return 1;
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
static int
|
|
|
|
io_apic_entry(io_apic_entry_ptr entry, int apic)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
|
1997-05-25 02:49:03 +00:00
|
|
|
return 0;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
IO_TO_ID(apic) = entry->apic_id;
|
2000-08-06 00:04:03 +00:00
|
|
|
if (entry->apic_id < NAPICID)
|
|
|
|
ID_TO_IO(entry->apic_id) = apic;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
return 1;
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
lookup_bus_type(char *name)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for (x = 0; x < MAX_BUSTYPE; ++x)
|
|
|
|
if (strcmp(bus_type_table[x].name, name) == 0)
|
|
|
|
return bus_type_table[x].type;
|
|
|
|
|
|
|
|
return UNKNOWN_BUSTYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
static int
|
|
|
|
int_entry(int_entry_ptr entry, int intr)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1998-11-26 23:14:23 +00:00
|
|
|
int apic;
|
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
io_apic_ints[intr].int_type = entry->int_type;
|
|
|
|
io_apic_ints[intr].int_flags = entry->int_flags;
|
|
|
|
io_apic_ints[intr].src_bus_id = entry->src_bus_id;
|
|
|
|
io_apic_ints[intr].src_bus_irq = entry->src_bus_irq;
|
1998-11-26 23:14:23 +00:00
|
|
|
if (entry->dst_apic_id == 255) {
|
|
|
|
/* This signal goes to all IO APICS. Select an IO APIC
|
|
|
|
with sufficient number of interrupt pins */
|
|
|
|
for (apic = 0; apic < mp_napics; apic++)
|
|
|
|
if (((io_apic_read(apic, IOAPIC_VER) &
|
|
|
|
IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) >=
|
|
|
|
entry->dst_apic_int)
|
|
|
|
break;
|
|
|
|
if (apic < mp_napics)
|
|
|
|
io_apic_ints[intr].dst_apic_id = IO_TO_ID(apic);
|
|
|
|
else
|
|
|
|
io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
|
|
|
|
} else
|
|
|
|
io_apic_ints[intr].dst_apic_id = entry->dst_apic_id;
|
1997-05-25 02:49:03 +00:00
|
|
|
io_apic_ints[intr].dst_apic_int = entry->dst_apic_int;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-05-25 02:49:03 +00:00
|
|
|
return 1;
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
apic_int_is_bus_type(int intr, int bus_type)
|
|
|
|
{
|
|
|
|
int bus;
|
|
|
|
|
|
|
|
for (bus = 0; bus < mp_nbusses; ++bus)
|
|
|
|
if ((bus_data[bus].bus_id == io_apic_ints[intr].src_bus_id)
|
|
|
|
&& ((int) bus_data[bus].bus_type == bus_type))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-06-25 21:01:52 +00:00
|
|
|
* Given a traditional ISA INT mask, return an APIC mask.
|
1997-05-03 17:42:01 +00:00
|
|
|
*/
|
1997-05-05 22:56:37 +00:00
|
|
|
u_int
|
1997-06-25 21:01:52 +00:00
|
|
|
isa_apic_mask(u_int isa_mask)
|
1997-05-03 17:42:01 +00:00
|
|
|
{
|
1997-06-25 21:01:52 +00:00
|
|
|
int isa_irq;
|
|
|
|
int apic_pin;
|
1997-05-03 17:42:01 +00:00
|
|
|
|
1997-07-07 00:06:51 +00:00
|
|
|
#if defined(SKIP_IRQ15_REDIRECT)
|
|
|
|
if (isa_mask == (1 << 15)) {
|
|
|
|
printf("skipping ISA IRQ15 redirect\n");
|
|
|
|
return isa_mask;
|
|
|
|
}
|
|
|
|
#endif /* SKIP_IRQ15_REDIRECT */
|
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
isa_irq = ffs(isa_mask); /* find its bit position */
|
|
|
|
if (isa_irq == 0) /* doesn't exist */
|
1997-05-03 17:42:01 +00:00
|
|
|
return 0;
|
1997-06-25 21:01:52 +00:00
|
|
|
--isa_irq; /* make it zero based */
|
1997-05-03 17:42:01 +00:00
|
|
|
|
1998-09-06 22:41:42 +00:00
|
|
|
apic_pin = isa_apic_irq(isa_irq); /* look for APIC connection */
|
1997-06-25 21:01:52 +00:00
|
|
|
if (apic_pin == -1)
|
|
|
|
return 0;
|
1997-05-03 17:42:01 +00:00
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
return (1 << apic_pin); /* convert pin# to a mask */
|
1997-05-03 17:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
1997-06-25 21:01:52 +00:00
|
|
|
* Determine which APIC pin an ISA/EISA INT is attached to.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
1997-06-25 21:01:52 +00:00
|
|
|
#define INTTYPE(I) (io_apic_ints[(I)].int_type)
|
|
|
|
#define INTPIN(I) (io_apic_ints[(I)].dst_apic_int)
|
1998-09-06 22:41:42 +00:00
|
|
|
#define INTIRQ(I) (io_apic_ints[(I)].int_vector)
|
|
|
|
#define INTAPIC(I) (ID_TO_IO(io_apic_ints[(I)].dst_apic_id))
|
1997-06-25 21:01:52 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
#define SRCBUSIRQ(I) (io_apic_ints[(I)].src_bus_irq)
|
|
|
|
int
|
1998-09-06 22:41:42 +00:00
|
|
|
isa_apic_irq(int isa_irq)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
int intr;
|
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
for (intr = 0; intr < nintrs; ++intr) { /* check each record */
|
|
|
|
if (INTTYPE(intr) == 0) { /* standard INT */
|
|
|
|
if (SRCBUSIRQ(intr) == isa_irq) {
|
|
|
|
if (apic_int_is_bus_type(intr, ISA) ||
|
2001-01-28 01:07:54 +00:00
|
|
|
apic_int_is_bus_type(intr, EISA)) {
|
|
|
|
if (INTIRQ(intr) == 0xff)
|
|
|
|
return -1; /* unassigned */
|
1998-09-06 22:41:42 +00:00
|
|
|
return INTIRQ(intr); /* found */
|
2001-01-28 01:07:54 +00:00
|
|
|
}
|
1997-06-25 21:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1; /* NOT found */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-06-25 21:01:52 +00:00
|
|
|
* Determine which APIC pin a PCI INT is attached to.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
|
|
|
#define SRCBUSID(I) (io_apic_ints[(I)].src_bus_id)
|
|
|
|
#define SRCBUSDEVICE(I) ((io_apic_ints[(I)].src_bus_irq >> 2) & 0x1f)
|
|
|
|
#define SRCBUSLINE(I) (io_apic_ints[(I)].src_bus_irq & 0x03)
|
|
|
|
int
|
1998-09-06 22:41:42 +00:00
|
|
|
pci_apic_irq(int pciBus, int pciDevice, int pciInt)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
int intr;
|
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
--pciInt; /* zero based */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
for (intr = 0; intr < nintrs; ++intr) /* check each record */
|
|
|
|
if ((INTTYPE(intr) == 0) /* standard INT */
|
1997-04-26 11:46:25 +00:00
|
|
|
&& (SRCBUSID(intr) == pciBus)
|
|
|
|
&& (SRCBUSDEVICE(intr) == pciDevice)
|
|
|
|
&& (SRCBUSLINE(intr) == pciInt)) /* a candidate IRQ */
|
2001-01-28 01:07:54 +00:00
|
|
|
if (apic_int_is_bus_type(intr, PCI)) {
|
|
|
|
if (INTIRQ(intr) == 0xff)
|
|
|
|
allocate_apic_irq(intr);
|
|
|
|
if (INTIRQ(intr) == 0xff)
|
|
|
|
return -1; /* unassigned */
|
1998-09-06 22:41:42 +00:00
|
|
|
return INTIRQ(intr); /* exact match */
|
2001-01-28 01:07:54 +00:00
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-06-25 21:01:52 +00:00
|
|
|
return -1; /* NOT found */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1998-04-01 21:07:37 +00:00
|
|
|
|
|
|
|
int
|
1998-09-06 22:41:42 +00:00
|
|
|
next_apic_irq(int irq)
|
1998-04-01 21:07:37 +00:00
|
|
|
{
|
|
|
|
int intr, ointr;
|
|
|
|
int bus, bustype;
|
|
|
|
|
|
|
|
bus = 0;
|
|
|
|
bustype = 0;
|
|
|
|
for (intr = 0; intr < nintrs; intr++) {
|
1998-09-06 22:41:42 +00:00
|
|
|
if (INTIRQ(intr) != irq || INTTYPE(intr) != 0)
|
1998-04-01 21:07:37 +00:00
|
|
|
continue;
|
|
|
|
bus = SRCBUSID(intr);
|
|
|
|
bustype = apic_bus_type(bus);
|
|
|
|
if (bustype != ISA &&
|
|
|
|
bustype != EISA &&
|
|
|
|
bustype != PCI)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (intr >= nintrs) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (ointr = intr + 1; ointr < nintrs; ointr++) {
|
|
|
|
if (INTTYPE(ointr) != 0)
|
|
|
|
continue;
|
|
|
|
if (bus != SRCBUSID(ointr))
|
|
|
|
continue;
|
|
|
|
if (bustype == PCI) {
|
|
|
|
if (SRCBUSDEVICE(intr) != SRCBUSDEVICE(ointr))
|
|
|
|
continue;
|
|
|
|
if (SRCBUSLINE(intr) != SRCBUSLINE(ointr))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (bustype == ISA || bustype == EISA) {
|
|
|
|
if (SRCBUSIRQ(intr) != SRCBUSIRQ(ointr))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (INTPIN(intr) == INTPIN(ointr))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ointr >= nintrs) {
|
|
|
|
return -1;
|
|
|
|
}
|
1998-09-06 22:41:42 +00:00
|
|
|
return INTIRQ(ointr);
|
1998-04-01 21:07:37 +00:00
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
#undef SRCBUSLINE
|
|
|
|
#undef SRCBUSDEVICE
|
|
|
|
#undef SRCBUSID
|
1998-04-01 21:07:37 +00:00
|
|
|
#undef SRCBUSIRQ
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
#undef INTPIN
|
1998-09-06 22:41:42 +00:00
|
|
|
#undef INTIRQ
|
|
|
|
#undef INTAPIC
|
1997-04-26 11:46:25 +00:00
|
|
|
#undef INTTYPE
|
|
|
|
|
|
|
|
|
1997-05-05 22:56:37 +00:00
|
|
|
/*
|
1997-06-25 21:01:52 +00:00
|
|
|
* Reprogram the MB chipset to NOT redirect an ISA INTerrupt.
|
|
|
|
*
|
|
|
|
* XXX FIXME:
|
|
|
|
* Exactly what this means is unclear at this point. It is a solution
|
|
|
|
* for motherboards that redirect the MBIRQ0 pin. Generically a motherboard
|
|
|
|
* could route any of the ISA INTs to upper (>15) IRQ values. But most would
|
|
|
|
* NOT be redirected via MBIRQ0, thus "undirect()ing" them would NOT be an
|
|
|
|
* option.
|
1997-05-05 22:56:37 +00:00
|
|
|
*/
|
1997-04-26 11:46:25 +00:00
|
|
|
int
|
1997-06-25 21:01:52 +00:00
|
|
|
undirect_isa_irq(int rirq)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
|
|
|
#if defined(READY)
|
1999-01-20 04:24:22 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("Freeing redirected ISA irq %d.\n", rirq);
|
1997-05-05 22:56:37 +00:00
|
|
|
/** FIXME: tickle the MB redirector chip */
|
2001-01-12 08:24:25 +00:00
|
|
|
return -1;
|
1997-05-05 22:56:37 +00:00
|
|
|
#else
|
1999-01-20 04:24:22 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("Freeing (NOT implemented) redirected ISA irq %d.\n", rirq);
|
1997-05-05 22:56:37 +00:00
|
|
|
return 0;
|
|
|
|
#endif /* READY */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1997-06-25 21:01:52 +00:00
|
|
|
* Reprogram the MB chipset to NOT redirect a PCI INTerrupt
|
1997-05-05 22:56:37 +00:00
|
|
|
*/
|
|
|
|
int
|
1997-06-25 21:01:52 +00:00
|
|
|
undirect_pci_irq(int rirq)
|
1997-05-05 22:56:37 +00:00
|
|
|
{
|
|
|
|
#if defined(READY)
|
1997-06-25 21:01:52 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("Freeing redirected PCI irq %d.\n", rirq);
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/** FIXME: tickle the MB redirector chip */
|
2001-01-12 08:24:25 +00:00
|
|
|
return -1;
|
1997-04-26 11:46:25 +00:00
|
|
|
#else
|
1997-06-25 21:01:52 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("Freeing (NOT implemented) redirected PCI irq %d.\n",
|
|
|
|
rirq);
|
1997-04-26 11:46:25 +00:00
|
|
|
return 0;
|
1997-05-05 22:56:37 +00:00
|
|
|
#endif /* READY */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a bus ID, return:
|
|
|
|
* the bus type if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_bus_type(int id)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for (x = 0; x < mp_nbusses; ++x)
|
|
|
|
if (bus_data[x].bus_id == id)
|
|
|
|
return bus_data[x].bus_type;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a LOGICAL APIC# and pin#, return:
|
|
|
|
* the associated src bus ID if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_src_bus_id(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* search each of the possible INTerrupt sources */
|
|
|
|
for (x = 0; x < nintrs; ++x)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int))
|
|
|
|
return (io_apic_ints[x].src_bus_id);
|
|
|
|
|
|
|
|
return -1; /* NOT found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a LOGICAL APIC# and pin#, return:
|
|
|
|
* the associated src bus IRQ if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_src_bus_irq(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for (x = 0; x < nintrs; x++)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int))
|
|
|
|
return (io_apic_ints[x].src_bus_irq);
|
|
|
|
|
|
|
|
return -1; /* NOT found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a LOGICAL APIC# and pin#, return:
|
|
|
|
* the associated INTerrupt type if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_int_type(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* search each of the possible INTerrupt sources */
|
|
|
|
for (x = 0; x < nintrs; ++x)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int))
|
|
|
|
return (io_apic_ints[x].int_type);
|
|
|
|
|
|
|
|
return -1; /* NOT found */
|
|
|
|
}
|
|
|
|
|
1998-09-06 22:41:42 +00:00
|
|
|
int
|
|
|
|
apic_irq(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
for (x = 0; x < nintrs; ++x)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int)) {
|
|
|
|
res = io_apic_ints[x].int_vector;
|
|
|
|
if (res == 0xff)
|
|
|
|
return -1;
|
|
|
|
if (apic != int_to_apicintpin[res].ioapic)
|
|
|
|
panic("apic_irq: inconsistent table");
|
|
|
|
if (pin != int_to_apicintpin[res].int_pin)
|
|
|
|
panic("apic_irq inconsistent table (2)");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* given a LOGICAL APIC# and pin#, return:
|
|
|
|
* the associated trigger mode if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_trigger(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* search each of the possible INTerrupt sources */
|
|
|
|
for (x = 0; x < nintrs; ++x)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int))
|
|
|
|
return ((io_apic_ints[x].int_flags >> 2) & 0x03);
|
|
|
|
|
|
|
|
return -1; /* NOT found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given a LOGICAL APIC# and pin#, return:
|
|
|
|
* the associated 'active' level if found
|
|
|
|
* -1 if NOT found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
apic_polarity(int apic, int pin)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
/* search each of the possible INTerrupt sources */
|
|
|
|
for (x = 0; x < nintrs; ++x)
|
|
|
|
if ((apic == ID_TO_IO(io_apic_ints[x].dst_apic_id)) &&
|
|
|
|
(pin == io_apic_ints[x].dst_apic_int))
|
|
|
|
return (io_apic_ints[x].int_flags & 0x03);
|
|
|
|
|
|
|
|
return -1; /* NOT found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set data according to MP defaults
|
|
|
|
* FIXME: probably not complete yet...
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
default_mp_table(int type)
|
|
|
|
{
|
|
|
|
int ap_cpu_id;
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
int io_apic_id;
|
|
|
|
int pin;
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf(" MP default config type: %d\n", type);
|
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
printf(" bus: ISA, APIC: 82489DX\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf(" bus: EISA, APIC: 82489DX\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
printf(" bus: EISA, APIC: 82489DX\n");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
printf(" bus: MCA, APIC: 82489DX\n");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
printf(" bus: ISA+PCI, APIC: Integrated\n");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
printf(" bus: EISA+PCI, APIC: Integrated\n");
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
printf(" bus: MCA+PCI, APIC: Integrated\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf(" future type\n");
|
|
|
|
break;
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
#endif /* 0 */
|
|
|
|
|
1997-06-22 16:04:22 +00:00
|
|
|
boot_cpu_id = (lapic.id & APIC_ID_MASK) >> 24;
|
1997-04-26 11:46:25 +00:00
|
|
|
ap_cpu_id = (boot_cpu_id == 0) ? 1 : 0;
|
|
|
|
|
|
|
|
/* BSP */
|
|
|
|
CPU_TO_ID(0) = boot_cpu_id;
|
|
|
|
ID_TO_CPU(boot_cpu_id) = 0;
|
|
|
|
|
|
|
|
/* one and only AP */
|
|
|
|
CPU_TO_ID(1) = ap_cpu_id;
|
|
|
|
ID_TO_CPU(ap_cpu_id) = 1;
|
|
|
|
|
|
|
|
#if defined(APIC_IO)
|
1997-05-25 02:49:03 +00:00
|
|
|
/* one and only IO APIC */
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_id = (io_apic_read(0, IOAPIC_ID) & APIC_ID_MASK) >> 24;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sanity check, refer to MP spec section 3.6.6, last paragraph
|
|
|
|
* necessary as some hardware isn't properly setting up the IO APIC
|
|
|
|
*/
|
|
|
|
#if defined(REALLY_ANAL_IOAPICID_VALUE)
|
|
|
|
if (io_apic_id != 2) {
|
|
|
|
#else
|
|
|
|
if ((io_apic_id == 0) || (io_apic_id == 1) || (io_apic_id == 15)) {
|
|
|
|
#endif /* REALLY_ANAL_IOAPICID_VALUE */
|
2000-05-31 21:37:28 +00:00
|
|
|
io_apic_set_id(0, 2);
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_id = 2;
|
|
|
|
}
|
|
|
|
IO_TO_ID(0) = io_apic_id;
|
|
|
|
ID_TO_IO(io_apic_id) = 0;
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
|
|
|
|
/* fill out bus entries */
|
|
|
|
switch (type) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2000-01-13 09:09:02 +00:00
|
|
|
case 4:
|
1997-04-26 11:46:25 +00:00
|
|
|
case 5:
|
|
|
|
case 6:
|
2000-01-13 09:09:02 +00:00
|
|
|
case 7:
|
1997-04-26 11:46:25 +00:00
|
|
|
bus_data[0].bus_id = default_data[type - 1][1];
|
|
|
|
bus_data[0].bus_type = default_data[type - 1][2];
|
|
|
|
bus_data[1].bus_id = default_data[type - 1][3];
|
|
|
|
bus_data[1].bus_type = default_data[type - 1][4];
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* case 4: case 7: MCA NOT supported */
|
|
|
|
default: /* illegal/reserved */
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("BAD default MP config: %d", type);
|
1997-05-24 18:48:53 +00:00
|
|
|
/* NOTREACHED */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
/* general cases from MP v1.4, table 5-2 */
|
|
|
|
for (pin = 0; pin < 16; ++pin) {
|
|
|
|
io_apic_ints[pin].int_type = 0;
|
1997-07-28 03:59:54 +00:00
|
|
|
io_apic_ints[pin].int_flags = 0x05; /* edge/active-hi */
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_ints[pin].src_bus_id = 0;
|
1997-07-28 03:59:54 +00:00
|
|
|
io_apic_ints[pin].src_bus_irq = pin; /* IRQ2 caught below */
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_ints[pin].dst_apic_id = io_apic_id;
|
1997-07-28 03:59:54 +00:00
|
|
|
io_apic_ints[pin].dst_apic_int = pin; /* 1-to-1 */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* special cases from MP v1.4, table 5-2 */
|
|
|
|
if (type == 2) {
|
|
|
|
io_apic_ints[2].int_type = 0xff; /* N/C */
|
|
|
|
io_apic_ints[13].int_type = 0xff; /* N/C */
|
|
|
|
#if !defined(APIC_MIXED_MODE)
|
|
|
|
/** FIXME: ??? */
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("sorry, can't support type 2 default yet");
|
1997-04-26 11:46:25 +00:00
|
|
|
#endif /* APIC_MIXED_MODE */
|
1997-05-22 22:35:42 +00:00
|
|
|
}
|
|
|
|
else
|
1997-04-26 11:46:25 +00:00
|
|
|
io_apic_ints[2].src_bus_irq = 0; /* ISA IRQ0 is on APIC INT 2 */
|
|
|
|
|
|
|
|
if (type == 7)
|
|
|
|
io_apic_ints[0].int_type = 0xff; /* N/C */
|
|
|
|
else
|
|
|
|
io_apic_ints[0].int_type = 3; /* vectored 8259 */
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start each AP in our list
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
start_all_aps(u_int boot_addr)
|
|
|
|
{
|
1999-04-28 01:04:33 +00:00
|
|
|
int x, i, pg;
|
1997-04-26 11:46:25 +00:00
|
|
|
u_char mpbiosreason;
|
|
|
|
u_long mpbioswarmvec;
|
2001-12-11 23:33:44 +00:00
|
|
|
struct pcpu *pc;
|
1997-09-21 05:50:02 +00:00
|
|
|
char *stack;
|
2001-03-15 05:10:06 +00:00
|
|
|
uintptr_t kptbase;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(START_ALL_APS_POST);
|
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN);
|
2001-04-27 19:28:25 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* initialize BSP's local APIC */
|
1997-07-08 23:46:00 +00:00
|
|
|
apic_initialize();
|
1997-08-24 20:33:32 +00:00
|
|
|
bsp_apic_ready = 1;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* install the AP 1st level boot code */
|
|
|
|
install_ap_tramp(boot_addr);
|
|
|
|
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* save the current value of the warm-start vector */
|
|
|
|
mpbioswarmvec = *((u_long *) WARMBOOT_OFF);
|
1998-10-10 13:37:16 +00:00
|
|
|
#ifndef PC98
|
1997-04-26 11:46:25 +00:00
|
|
|
outb(CMOS_REG, BIOS_RESET);
|
|
|
|
mpbiosreason = inb(CMOS_DATA);
|
1998-10-10 09:38:02 +00:00
|
|
|
#endif
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2001-03-15 05:10:06 +00:00
|
|
|
/* set up temporary P==V mapping for AP boot */
|
|
|
|
/* XXX this is a hack, we should boot the AP on its own stack/PTD */
|
|
|
|
kptbase = (uintptr_t)(void *)KPTphys;
|
|
|
|
for (x = 0; x < NKPT; x++)
|
|
|
|
PTD[x] = (pd_entry_t)(PG_V | PG_RW |
|
|
|
|
((kptbase + x * PAGE_SIZE) & PG_FRAME));
|
1999-04-28 01:04:33 +00:00
|
|
|
invltlb();
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* start each AP */
|
|
|
|
for (x = 1; x <= mp_naps; ++x) {
|
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/* This is a bit verbose, it will go away soon. */
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1999-04-28 01:04:33 +00:00
|
|
|
/* first page of AP's private space */
|
|
|
|
pg = x * i386_btop(sizeof(struct privatespace));
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/* allocate a new private data page */
|
2001-12-11 23:33:44 +00:00
|
|
|
pc = (struct pcpu *)kmem_alloc(kernel_map, PAGE_SIZE);
|
1997-06-22 16:04:22 +00:00
|
|
|
|
|
|
|
/* wire it into the private page table page */
|
2001-12-11 23:33:44 +00:00
|
|
|
SMPpt[pg] = (pt_entry_t)(PG_V | PG_RW | vtophys(pc));
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/* allocate and set up an idle stack data page */
|
2001-09-12 08:38:13 +00:00
|
|
|
stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE); /* XXXKSE */
|
|
|
|
for (i = 0; i < KSTACK_PAGES; i++)
|
2001-01-30 04:02:28 +00:00
|
|
|
SMPpt[pg + 1 + i] = (pt_entry_t)
|
1999-04-28 01:04:33 +00:00
|
|
|
(PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/* prime data page for it to use */
|
2001-12-11 23:33:44 +00:00
|
|
|
pcpu_init(pc, x, sizeof(struct pcpu));
|
1997-06-22 16:04:22 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* setup a vector to our boot code */
|
|
|
|
*((volatile u_short *) WARMBOOT_OFF) = WARMBOOT_TARGET;
|
|
|
|
*((volatile u_short *) WARMBOOT_SEG) = (boot_addr >> 4);
|
1998-10-10 13:37:16 +00:00
|
|
|
#ifndef PC98
|
1997-04-26 11:46:25 +00:00
|
|
|
outb(CMOS_REG, BIOS_RESET);
|
|
|
|
outb(CMOS_DATA, BIOS_WARM); /* 'warm-start' */
|
1998-10-10 09:38:02 +00:00
|
|
|
#endif
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
bootSTK = &SMP_prvspace[x].idlekstack[KSTACK_PAGES * PAGE_SIZE];
|
1999-06-23 21:47:24 +00:00
|
|
|
bootAP = x;
|
1999-04-28 01:04:33 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* attempt to start the Application Processor */
|
|
|
|
CHECK_INIT(99); /* setup checkpoints */
|
|
|
|
if (!start_ap(x, boot_addr)) {
|
|
|
|
printf("AP #%d (PHY# %d) failed!\n", x, CPU_TO_ID(x));
|
|
|
|
CHECK_PRINT("trace"); /* show checkpoints */
|
1997-05-26 09:23:30 +00:00
|
|
|
/* better panic as the AP may be running loose */
|
|
|
|
printf("panic y/n? [y] ");
|
1997-05-24 18:48:53 +00:00
|
|
|
if (cngetc() != 'n')
|
1997-05-25 02:49:03 +00:00
|
|
|
panic("bye-bye");
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1997-06-27 23:33:17 +00:00
|
|
|
CHECK_PRINT("trace"); /* show checkpoints */
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* record its version info */
|
|
|
|
cpu_apic_versions[x] = cpu_apic_versions[0];
|
1997-06-27 23:33:17 +00:00
|
|
|
|
|
|
|
all_cpus |= (1 << x); /* record AP in CPU map */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
/* build our map of 'other' CPUs */
|
2002-01-05 09:41:37 +00:00
|
|
|
PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
|
1997-06-27 23:33:17 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* fill in our (BSP) APIC version */
|
1997-06-22 16:04:22 +00:00
|
|
|
cpu_apic_versions[0] = lapic.version;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* restore the warmstart vector */
|
|
|
|
*(u_long *) WARMBOOT_OFF = mpbioswarmvec;
|
1998-10-10 13:37:16 +00:00
|
|
|
#ifndef PC98
|
1997-04-26 11:46:25 +00:00
|
|
|
outb(CMOS_REG, BIOS_RESET);
|
|
|
|
outb(CMOS_DATA, mpbiosreason);
|
1998-10-10 09:38:02 +00:00
|
|
|
#endif
|
1997-04-26 11:46:25 +00:00
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/*
|
|
|
|
* Set up the idle context for the BSP. Similar to above except
|
|
|
|
* that some was done by locore, some by pmap.c and some is implicit
|
|
|
|
* because the BSP is cpu#0 and the page is initially zero, and also
|
|
|
|
* because we can refer to variables by name on the BSP..
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Allocate and setup BSP idle stack */
|
2001-09-12 08:38:13 +00:00
|
|
|
stack = (char *)kmem_alloc(kernel_map, KSTACK_PAGES * PAGE_SIZE);
|
|
|
|
for (i = 0; i < KSTACK_PAGES; i++)
|
2001-01-30 04:02:28 +00:00
|
|
|
SMPpt[1 + i] = (pt_entry_t)
|
1999-04-28 01:04:33 +00:00
|
|
|
(PG_V | PG_RW | vtophys(PAGE_SIZE * i + stack));
|
1997-08-26 18:10:38 +00:00
|
|
|
|
2001-03-15 05:10:06 +00:00
|
|
|
for (x = 0; x < NKPT; x++)
|
|
|
|
PTD[x] = 0;
|
1999-06-23 21:47:24 +00:00
|
|
|
pmap_set_opt();
|
1997-07-17 19:45:01 +00:00
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* number of APs actually started */
|
|
|
|
return mp_ncpus - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load the 1st level AP boot code into base memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* targets for relocation */
|
|
|
|
extern void bigJump(void);
|
|
|
|
extern void bootCodeSeg(void);
|
|
|
|
extern void bootDataSeg(void);
|
|
|
|
extern void MPentry(void);
|
|
|
|
extern u_int MP_GDT;
|
|
|
|
extern u_int mp_gdtbase;
|
|
|
|
|
|
|
|
static void
|
|
|
|
install_ap_tramp(u_int boot_addr)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int size = *(int *) ((u_long) & bootMP_size);
|
|
|
|
u_char *src = (u_char *) ((u_long) bootMP);
|
|
|
|
u_char *dst = (u_char *) boot_addr + KERNBASE;
|
|
|
|
u_int boot_base = (u_int) bootMP;
|
|
|
|
u_int8_t *dst8;
|
|
|
|
u_int16_t *dst16;
|
|
|
|
u_int32_t *dst32;
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(INSTALL_AP_TRAMP_POST);
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
for (x = 0; x < size; ++x)
|
|
|
|
*dst++ = *src++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* modify addresses in code we just moved to basemem. unfortunately we
|
|
|
|
* need fairly detailed info about mpboot.s for this to work. changes
|
|
|
|
* to mpboot.s might require changes here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* boot code is located in KERNEL space */
|
|
|
|
dst = (u_char *) boot_addr + KERNBASE;
|
|
|
|
|
|
|
|
/* modify the lgdt arg */
|
|
|
|
dst32 = (u_int32_t *) (dst + ((u_int) & mp_gdtbase - boot_base));
|
|
|
|
*dst32 = boot_addr + ((u_int) & MP_GDT - boot_base);
|
|
|
|
|
|
|
|
/* modify the ljmp target for MPentry() */
|
|
|
|
dst32 = (u_int32_t *) (dst + ((u_int) bigJump - boot_base) + 1);
|
|
|
|
*dst32 = ((u_int) MPentry - KERNBASE);
|
|
|
|
|
|
|
|
/* modify the target for boot code segment */
|
|
|
|
dst16 = (u_int16_t *) (dst + ((u_int) bootCodeSeg - boot_base));
|
|
|
|
dst8 = (u_int8_t *) (dst16 + 1);
|
|
|
|
*dst16 = (u_int) boot_addr & 0xffff;
|
|
|
|
*dst8 = ((u_int) boot_addr >> 16) & 0xff;
|
|
|
|
|
|
|
|
/* modify the target for boot data segment */
|
|
|
|
dst16 = (u_int16_t *) (dst + ((u_int) bootDataSeg - boot_base));
|
|
|
|
dst8 = (u_int8_t *) (dst16 + 1);
|
|
|
|
*dst16 = (u_int) boot_addr & 0xffff;
|
|
|
|
*dst8 = ((u_int) boot_addr >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this function starts the AP (application processor) identified
|
|
|
|
* by the APIC ID 'physicalCpu'. It does quite a "song and dance"
|
|
|
|
* to accomplish this. This is necessary because of the nuances
|
|
|
|
* of the different hardware we might encounter. It ain't pretty,
|
|
|
|
* but it seems to work.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
start_ap(int logical_cpu, u_int boot_addr)
|
|
|
|
{
|
|
|
|
int physical_cpu;
|
|
|
|
int vector;
|
|
|
|
int cpus;
|
|
|
|
u_long icr_lo, icr_hi;
|
|
|
|
|
1997-06-27 23:33:17 +00:00
|
|
|
POSTCODE(START_AP_POST);
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/* get the PHYSICAL APIC ID# */
|
|
|
|
physical_cpu = CPU_TO_ID(logical_cpu);
|
|
|
|
|
|
|
|
/* calculate the vector */
|
|
|
|
vector = (boot_addr >> 12) & 0xff;
|
|
|
|
|
|
|
|
/* used as a watchpoint to signal AP startup */
|
|
|
|
cpus = mp_ncpus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first we do an INIT/RESET IPI this INIT IPI might be run, reseting
|
|
|
|
* and running the target CPU. OR this INIT IPI might be latched (P5
|
|
|
|
* bug), CPU waiting for STARTUP IPI. OR this INIT IPI might be
|
|
|
|
* ignored.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* setup the address for the target AP */
|
1997-06-22 16:04:22 +00:00
|
|
|
icr_hi = lapic.icr_hi & ~APIC_ID_MASK;
|
1997-04-26 11:46:25 +00:00
|
|
|
icr_hi |= (physical_cpu << 24);
|
1997-06-22 16:04:22 +00:00
|
|
|
lapic.icr_hi = icr_hi;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* do an INIT IPI: assert RESET */
|
1997-06-22 16:04:22 +00:00
|
|
|
icr_lo = lapic.icr_lo & 0xfff00000;
|
|
|
|
lapic.icr_lo = icr_lo | 0x0000c500;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* wait for pending status end */
|
1997-06-22 16:04:22 +00:00
|
|
|
while (lapic.icr_lo & APIC_DELSTAT_MASK)
|
1997-04-26 11:46:25 +00:00
|
|
|
/* spin */ ;
|
|
|
|
|
|
|
|
/* do an INIT IPI: deassert RESET */
|
1997-06-22 16:04:22 +00:00
|
|
|
lapic.icr_lo = icr_lo | 0x00008500;
|
1997-04-26 11:46:25 +00:00
|
|
|
|
|
|
|
/* wait for pending status end */
|
|
|
|
u_sleep(10000); /* wait ~10mS */
|
1997-06-22 16:04:22 +00:00
|
|
|
while (lapic.icr_lo & APIC_DELSTAT_MASK)
|
1997-04-26 11:46:25 +00:00
|
|
|
/* spin */ ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* next we do a STARTUP IPI: the previous INIT IPI might still be
|
|
|
|
* latched, (P5 bug) this 1st STARTUP would then terminate
|
|
|
|
* immediately, and the previously started INIT IPI would continue. OR
|
|
|
|
* the previous INIT IPI has already run. and this STARTUP IPI will
|
|
|
|
* run. OR the previous INIT IPI was ignored. and this STARTUP IPI
|
|
|
|
* will run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* do a STARTUP IPI */
|
1997-06-22 16:04:22 +00:00
|
|
|
lapic.icr_lo = icr_lo | 0x00000600 | vector;
|
|
|
|
while (lapic.icr_lo & APIC_DELSTAT_MASK)
|
1997-04-26 11:46:25 +00:00
|
|
|
/* spin */ ;
|
|
|
|
u_sleep(200); /* wait ~200uS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* finally we do a 2nd STARTUP IPI: this 2nd STARTUP IPI should run IF
|
|
|
|
* the previous STARTUP IPI was cancelled by a latched INIT IPI. OR
|
|
|
|
* this STARTUP IPI will be ignored, as only ONE STARTUP IPI is
|
|
|
|
* recognized after hardware RESET or INIT IPI.
|
|
|
|
*/
|
|
|
|
|
1997-06-22 16:04:22 +00:00
|
|
|
lapic.icr_lo = icr_lo | 0x00000600 | vector;
|
|
|
|
while (lapic.icr_lo & APIC_DELSTAT_MASK)
|
1997-04-26 11:46:25 +00:00
|
|
|
/* spin */ ;
|
|
|
|
u_sleep(200); /* wait ~200uS */
|
|
|
|
|
|
|
|
/* wait for it to start */
|
|
|
|
set_apic_timer(5000000);/* == 5 seconds */
|
|
|
|
while (read_apic_timer())
|
|
|
|
if (mp_ncpus > cpus)
|
|
|
|
return 1; /* return SUCCESS */
|
|
|
|
|
|
|
|
return 0; /* return FAILURE */
|
|
|
|
}
|
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
#if defined(APIC_IO)
|
|
|
|
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
u_int xhits_gbl[MAXCPU];
|
|
|
|
u_int xhits_pg[MAXCPU];
|
|
|
|
u_int xhits_rng[MAXCPU];
|
|
|
|
SYSCTL_NODE(_debug, OID_AUTO, xhits, CTLFLAG_RW, 0, "");
|
|
|
|
SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, global, CTLFLAG_RW, &xhits_gbl,
|
|
|
|
sizeof(xhits_gbl), "IU", "");
|
|
|
|
SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, page, CTLFLAG_RW, &xhits_pg,
|
|
|
|
sizeof(xhits_pg), "IU", "");
|
|
|
|
SYSCTL_OPAQUE(_debug_xhits, OID_AUTO, range, CTLFLAG_RW, &xhits_rng,
|
|
|
|
sizeof(xhits_rng), "IU", "");
|
|
|
|
|
|
|
|
u_int ipi_global;
|
|
|
|
u_int ipi_page;
|
|
|
|
u_int ipi_range;
|
|
|
|
u_int ipi_range_size;
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_global, CTLFLAG_RW, &ipi_global, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_page, CTLFLAG_RW, &ipi_page, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range, CTLFLAG_RW, &ipi_range, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_range_size, CTLFLAG_RW, &ipi_range_size,
|
|
|
|
0, "");
|
|
|
|
|
|
|
|
u_int ipi_masked_global;
|
|
|
|
u_int ipi_masked_page;
|
|
|
|
u_int ipi_masked_range;
|
|
|
|
u_int ipi_masked_range_size;
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_global, CTLFLAG_RW,
|
|
|
|
&ipi_masked_global, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_page, CTLFLAG_RW,
|
|
|
|
&ipi_masked_page, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range, CTLFLAG_RW,
|
|
|
|
&ipi_masked_range, 0, "");
|
|
|
|
SYSCTL_INT(_debug_xhits, OID_AUTO, ipi_masked_range_size, CTLFLAG_RW,
|
|
|
|
&ipi_masked_range_size, 0, "");
|
2002-07-11 08:31:10 +00:00
|
|
|
#endif
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
/*
|
|
|
|
* Flush the TLB on all other CPU's
|
2002-07-12 07:56:11 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
smp_tlb_shootdown(u_int vector, vm_offset_t addr1, vm_offset_t addr2)
|
|
|
|
{
|
|
|
|
u_int ncpu;
|
|
|
|
register_t eflags;
|
|
|
|
|
|
|
|
ncpu = mp_ncpus - 1; /* does not shootdown self */
|
|
|
|
if (ncpu < 1)
|
|
|
|
return; /* no other cpus */
|
|
|
|
eflags = read_eflags();
|
|
|
|
if ((eflags & PSL_I) == 0)
|
|
|
|
panic("absolutely cannot call smp_ipi_shootdown with interrupts already disabled");
|
|
|
|
mtx_lock_spin(&smp_tlb_mtx);
|
|
|
|
smp_tlb_addr1 = addr1;
|
|
|
|
smp_tlb_addr2 = addr2;
|
|
|
|
atomic_store_rel_int(&smp_tlb_wait, 0);
|
|
|
|
ipi_all_but_self(vector);
|
|
|
|
while (smp_tlb_wait < ncpu)
|
|
|
|
ia32_pause();
|
|
|
|
mtx_unlock_spin(&smp_tlb_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is about as magic as it gets. fortune(1) has got similar code
|
|
|
|
* for reversing bits in a word. Who thinks up this stuff??
|
|
|
|
*
|
|
|
|
* Yes, it does appear to be consistently faster than:
|
|
|
|
* while (i = ffs(m)) {
|
|
|
|
* m >>= i;
|
|
|
|
* bits++;
|
|
|
|
* }
|
|
|
|
* and
|
|
|
|
* while (lsb = (m & -m)) { // This is magic too
|
|
|
|
* m &= ~lsb; // or: m ^= lsb
|
|
|
|
* bits++;
|
|
|
|
* }
|
|
|
|
* Both of these latter forms do some very strange things on gcc-3.1 with
|
|
|
|
* -mcpu=pentiumpro and/or -march=pentiumpro and/or -O or -O2.
|
|
|
|
* There is probably an SSE or MMX popcnt instruction.
|
2002-02-27 09:51:33 +00:00
|
|
|
*
|
2002-07-12 07:56:11 +00:00
|
|
|
* I wonder if this should be in libkern?
|
|
|
|
*
|
|
|
|
* XXX Stop the presses! Another one:
|
|
|
|
* static __inline u_int32_t
|
|
|
|
* popcnt1(u_int32_t v)
|
|
|
|
* {
|
|
|
|
* v -= ((v >> 1) & 0x55555555);
|
|
|
|
* v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
|
|
|
|
* v = (v + (v >> 4)) & 0x0F0F0F0F;
|
|
|
|
* return (v * 0x01010101) >> 24;
|
|
|
|
* }
|
|
|
|
* The downside is that it has a multiply. With a pentium3 with
|
|
|
|
* -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
|
|
|
|
* an imull, and in that case it is faster. In most other cases
|
|
|
|
* it appears slightly slower.
|
1997-04-26 11:46:25 +00:00
|
|
|
*/
|
2002-07-12 07:56:11 +00:00
|
|
|
static __inline u_int32_t
|
|
|
|
popcnt(u_int32_t m)
|
|
|
|
{
|
|
|
|
|
|
|
|
m = (m & 0x55555555) + ((m & 0xaaaaaaaa) >> 1);
|
|
|
|
m = (m & 0x33333333) + ((m & 0xcccccccc) >> 2);
|
|
|
|
m = (m & 0x0f0f0f0f) + ((m & 0xf0f0f0f0) >> 4);
|
|
|
|
m = (m & 0x00ff00ff) + ((m & 0xff00ff00) >> 8);
|
|
|
|
m = (m & 0x0000ffff) + ((m & 0xffff0000) >> 16);
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
smp_targeted_tlb_shootdown(u_int mask, u_int vector, vm_offset_t addr1, vm_offset_t addr2)
|
|
|
|
{
|
|
|
|
int ncpu, othercpus;
|
|
|
|
register_t eflags;
|
|
|
|
|
|
|
|
othercpus = mp_ncpus - 1;
|
|
|
|
if (mask == (u_int)-1) {
|
|
|
|
ncpu = othercpus;
|
|
|
|
if (ncpu < 1)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* XXX there should be a pcpu self mask */
|
|
|
|
mask &= ~(1 << PCPU_GET(cpuid));
|
|
|
|
if (mask == 0)
|
|
|
|
return;
|
|
|
|
ncpu = popcnt(mask);
|
|
|
|
if (ncpu > othercpus) {
|
|
|
|
/* XXX this should be a panic offence */
|
|
|
|
printf("SMP: tlb shootdown to %d other cpus (only have %d)\n",
|
|
|
|
ncpu, othercpus);
|
|
|
|
ncpu = othercpus;
|
|
|
|
}
|
|
|
|
/* XXX should be a panic, implied by mask == 0 above */
|
|
|
|
if (ncpu < 1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
eflags = read_eflags();
|
|
|
|
if ((eflags & PSL_I) == 0)
|
|
|
|
panic("absolutely cannot call smp_targeted_ipi_shootdown with interrupts already disabled");
|
|
|
|
mtx_lock_spin(&smp_tlb_mtx);
|
|
|
|
smp_tlb_addr1 = addr1;
|
|
|
|
smp_tlb_addr2 = addr2;
|
|
|
|
atomic_store_rel_int(&smp_tlb_wait, 0);
|
|
|
|
if (mask == (u_int)-1)
|
|
|
|
ipi_all_but_self(vector);
|
|
|
|
else
|
|
|
|
ipi_selected(mask, vector);
|
|
|
|
while (smp_tlb_wait < ncpu)
|
|
|
|
ia32_pause();
|
|
|
|
mtx_unlock_spin(&smp_tlb_mtx);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-04-26 11:46:25 +00:00
|
|
|
void
|
1997-04-28 00:25:00 +00:00
|
|
|
smp_invltlb(void)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
1997-05-03 17:42:01 +00:00
|
|
|
#if defined(APIC_IO)
|
2002-07-12 07:56:11 +00:00
|
|
|
if (smp_started) {
|
|
|
|
smp_tlb_shootdown(IPI_INVLTLB, 0, 0);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_global++;
|
|
|
|
#endif
|
|
|
|
}
|
1997-05-03 17:42:01 +00:00
|
|
|
#endif /* APIC_IO */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-12 07:56:11 +00:00
|
|
|
smp_invlpg(vm_offset_t addr)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
2002-07-12 07:56:11 +00:00
|
|
|
#if defined(APIC_IO)
|
|
|
|
if (smp_started) {
|
|
|
|
smp_tlb_shootdown(IPI_INVLPG, addr, 0);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_page++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
1997-04-28 00:25:00 +00:00
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
void
|
|
|
|
smp_invlpg_range(vm_offset_t addr1, vm_offset_t addr2)
|
|
|
|
{
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
if (smp_started) {
|
|
|
|
smp_tlb_shootdown(IPI_INVLRNG, addr1, addr2);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_range++;
|
|
|
|
ipi_range_size += (addr2 - addr1) / PAGE_SIZE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-12 07:56:11 +00:00
|
|
|
smp_masked_invltlb(u_int mask)
|
1997-04-26 11:46:25 +00:00
|
|
|
{
|
2002-07-12 07:56:11 +00:00
|
|
|
#if defined(APIC_IO)
|
|
|
|
if (smp_started) {
|
|
|
|
smp_targeted_tlb_shootdown(mask, IPI_INVLTLB, 0, 0);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_masked_global++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
1997-04-28 00:25:00 +00:00
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
void
|
|
|
|
smp_masked_invlpg(u_int mask, vm_offset_t addr)
|
|
|
|
{
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
if (smp_started) {
|
|
|
|
smp_targeted_tlb_shootdown(mask, IPI_INVLPG, addr, 0);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_masked_page++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
}
|
1997-04-26 11:46:25 +00:00
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
void
|
|
|
|
smp_masked_invlpg_range(u_int mask, vm_offset_t addr1, vm_offset_t addr2)
|
|
|
|
{
|
|
|
|
#if defined(APIC_IO)
|
|
|
|
if (smp_started) {
|
|
|
|
smp_targeted_tlb_shootdown(mask, IPI_INVLRNG, addr1, addr2);
|
|
|
|
#ifdef COUNT_XINVLTLB_HITS
|
|
|
|
ipi_masked_range++;
|
|
|
|
ipi_masked_range_size += (addr2 - addr1) / PAGE_SIZE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
1997-04-26 11:46:25 +00:00
|
|
|
}
|
1997-06-27 23:33:17 +00:00
|
|
|
|
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/*
|
|
|
|
* This is called once the rest of the system is up and running and we're
|
|
|
|
* ready to let the AP's out of the pen.
|
|
|
|
*/
|
|
|
|
void
|
2000-09-07 01:33:02 +00:00
|
|
|
ap_init(void)
|
1997-08-26 18:10:38 +00:00
|
|
|
{
|
|
|
|
u_int apic_id;
|
|
|
|
|
2001-01-24 12:35:55 +00:00
|
|
|
/* spin until all the AP's are ready */
|
|
|
|
while (!aps_ready)
|
2002-08-28 23:24:05 +00:00
|
|
|
ia32_pause();
|
2001-01-24 12:35:55 +00:00
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
/* BSP may have changed PTD while we were waiting */
|
2002-07-12 07:56:11 +00:00
|
|
|
invltlb();
|
1999-06-23 21:47:24 +00:00
|
|
|
|
1998-03-07 20:16:49 +00:00
|
|
|
#if defined(I586_CPU) && !defined(NO_F00F_HACK)
|
|
|
|
lidt(&r_idt);
|
|
|
|
#endif
|
|
|
|
|
2000-08-11 09:05:12 +00:00
|
|
|
/* set up CPU registers and state */
|
|
|
|
cpu_setregs();
|
1997-08-26 18:10:38 +00:00
|
|
|
|
1999-09-05 20:17:40 +00:00
|
|
|
/* set up FPU state on the AP */
|
|
|
|
npxinit(__INITIAL_NPXCW__);
|
|
|
|
|
2001-07-12 06:32:51 +00:00
|
|
|
/* set up SSE registers */
|
|
|
|
enable_sse();
|
|
|
|
|
1997-08-26 18:10:38 +00:00
|
|
|
/* A quick check from sanity claus */
|
|
|
|
apic_id = (apic_id_to_logical[(lapic.id & 0x0f000000) >> 24]);
|
2001-01-10 04:43:51 +00:00
|
|
|
if (PCPU_GET(cpuid) != apic_id) {
|
|
|
|
printf("SMP: cpuid = %d\n", PCPU_GET(cpuid));
|
1997-08-26 18:10:38 +00:00
|
|
|
printf("SMP: apic_id = %d\n", apic_id);
|
1998-08-24 02:28:16 +00:00
|
|
|
printf("PTD[MPPTDI] = %p\n", (void *)PTD[MPPTDI]);
|
1997-08-26 18:10:38 +00:00
|
|
|
panic("cpuid mismatch! boom!!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init local apic for irq's */
|
|
|
|
apic_initialize();
|
|
|
|
|
1999-04-30 22:09:45 +00:00
|
|
|
/* Set memory range attributes for this CPU to match the BSP */
|
|
|
|
mem_range_AP_init();
|
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
mtx_lock_spin(&ap_boot_mtx);
|
|
|
|
|
|
|
|
smp_cpus++;
|
|
|
|
|
2002-09-30 07:03:16 +00:00
|
|
|
CTR1(KTR_SMP, "SMP: AP CPU #%d Launched", PCPU_GET(cpuid));
|
2002-09-30 15:39:57 +00:00
|
|
|
printf("SMP: AP CPU #%d Launched!\n", PCPU_GET(cpuid));
|
2002-09-30 07:03:16 +00:00
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
/* Build our map of 'other' CPUs. */
|
2002-01-05 09:41:37 +00:00
|
|
|
PCPU_SET(other_cpus, all_cpus & ~PCPU_GET(cpumask));
|
2001-12-17 23:14:35 +00:00
|
|
|
|
2002-07-12 07:56:11 +00:00
|
|
|
if (bootverbose)
|
|
|
|
apic_dump("ap_init()");
|
|
|
|
|
1998-09-06 22:41:42 +00:00
|
|
|
if (smp_cpus == mp_ncpus) {
|
2002-08-28 23:24:05 +00:00
|
|
|
/* enable IPI's, tlb shootdown, freezes etc */
|
|
|
|
atomic_store_rel_int(&smp_started, 1);
|
1998-09-06 22:41:42 +00:00
|
|
|
smp_active = 1; /* historic */
|
|
|
|
}
|
2000-09-07 01:33:02 +00:00
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock_spin(&ap_boot_mtx);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
|
|
|
/* wait until all the AP's are up */
|
|
|
|
while (smp_started == 0)
|
2002-08-28 23:24:05 +00:00
|
|
|
ia32_pause();
|
|
|
|
|
|
|
|
/* ok, now grab sched_lock and enter the scheduler */
|
|
|
|
mtx_lock_spin(&sched_lock);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2002-02-22 13:32:01 +00:00
|
|
|
binuptime(PCPU_PTR(switchtime));
|
2001-01-10 04:43:51 +00:00
|
|
|
PCPU_SET(switchticks, ticks);
|
2000-09-07 01:33:02 +00:00
|
|
|
|
|
|
|
cpu_throw(); /* doesn't return */
|
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
panic("scheduler returned us to %s", __func__);
|
1997-08-26 18:10:38 +00:00
|
|
|
}
|
1997-10-05 03:19:29 +00:00
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
/*
|
|
|
|
* For statclock, we send an IPI to all CPU's to have them call this
|
|
|
|
* function.
|
2002-03-27 05:39:23 +00:00
|
|
|
*
|
|
|
|
* WARNING! unpend() will call statclock_process() directly and skip this
|
|
|
|
* routine.
|
2001-04-27 19:28:25 +00:00
|
|
|
*/
|
1997-12-08 23:00:24 +00:00
|
|
|
void
|
2001-04-27 19:28:25 +00:00
|
|
|
forwarded_statclock(struct trapframe frame)
|
1997-12-08 23:00:24 +00:00
|
|
|
{
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2003-02-01 12:17:09 +00:00
|
|
|
statclock_process(curthread->td_kse, TRAPF_PC(&frame),
|
|
|
|
TRAPF_USERMODE(&frame));
|
2001-04-27 19:28:25 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
1997-12-08 23:00:24 +00:00
|
|
|
}
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
void
|
|
|
|
forward_statclock(void)
|
1997-12-08 23:00:24 +00:00
|
|
|
{
|
|
|
|
int map;
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
CTR0(KTR_SMP, "forward_statclock");
|
2001-01-24 09:48:52 +00:00
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
if (!smp_started || cold || panicstr)
|
1997-12-08 23:00:24 +00:00
|
|
|
return;
|
|
|
|
|
2001-01-10 04:43:51 +00:00
|
|
|
map = PCPU_GET(other_cpus) & ~stopped_cpus ;
|
1997-12-15 01:14:10 +00:00
|
|
|
if (map != 0)
|
2001-04-27 19:28:25 +00:00
|
|
|
ipi_selected(map, IPI_STATCLOCK);
|
1997-12-08 23:00:24 +00:00
|
|
|
}
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
/*
|
|
|
|
* For each hardclock(), we send an IPI to all other CPU's to have them
|
|
|
|
* execute this function. It would be nice to reduce contention on
|
|
|
|
* sched_lock if we could simply peek at the CPU to determine the user/kernel
|
|
|
|
* state and call hardclock_process() on the CPU receiving the clock interrupt
|
|
|
|
* and then just use a simple IPI to handle any ast's if needed.
|
2002-03-27 05:39:23 +00:00
|
|
|
*
|
|
|
|
* WARNING! unpend() will call hardclock_process() directly and skip this
|
|
|
|
* routine.
|
2001-04-27 19:28:25 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
forwarded_hardclock(struct trapframe frame)
|
1998-03-03 20:55:26 +00:00
|
|
|
{
|
2001-01-24 09:48:52 +00:00
|
|
|
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock_spin(&sched_lock);
|
2001-09-12 08:38:13 +00:00
|
|
|
hardclock_process(curthread, TRAPF_USERMODE(&frame));
|
2001-04-27 19:28:25 +00:00
|
|
|
mtx_unlock_spin(&sched_lock);
|
1998-03-03 20:55:26 +00:00
|
|
|
}
|
1998-03-03 22:56:30 +00:00
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
void
|
|
|
|
forward_hardclock(void)
|
1998-05-17 22:12:14 +00:00
|
|
|
{
|
|
|
|
u_int map;
|
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
CTR0(KTR_SMP, "forward_hardclock");
|
2001-01-24 09:48:52 +00:00
|
|
|
|
2001-12-17 23:14:35 +00:00
|
|
|
if (!smp_started || cold || panicstr)
|
1998-05-17 22:12:14 +00:00
|
|
|
return;
|
2001-01-24 09:48:52 +00:00
|
|
|
|
2001-04-27 19:28:25 +00:00
|
|
|
map = PCPU_GET(other_cpus) & ~stopped_cpus ;
|
|
|
|
if (map != 0)
|
|
|
|
ipi_selected(map, IPI_HARDCLOCK);
|
2001-01-24 09:48:52 +00:00
|
|
|
}
|
|
|
|
|
1998-03-03 22:56:30 +00:00
|
|
|
#ifdef APIC_INTR_REORDER
|
|
|
|
/*
|
|
|
|
* Maintain mapping from softintr vector to isr bit in local apic.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
set_lapic_isrloc(int intr, int vector)
|
|
|
|
{
|
|
|
|
if (intr < 0 || intr > 32)
|
|
|
|
panic("set_apic_isrloc: bad intr argument: %d",intr);
|
|
|
|
if (vector < ICU_OFFSET || vector > 255)
|
|
|
|
panic("set_apic_isrloc: bad vector argument: %d",vector);
|
|
|
|
apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
|
|
|
|
apic_isrbit_location[intr].bit = (1<<(vector & 31));
|
|
|
|
}
|
|
|
|
#endif
|
1999-07-20 06:52:35 +00:00
|
|
|
|
2001-04-10 21:04:32 +00:00
|
|
|
/*
|
|
|
|
* send an IPI to a set of cpus.
|
|
|
|
*/
|
|
|
|
void
|
2001-04-11 17:06:02 +00:00
|
|
|
ipi_selected(u_int32_t cpus, u_int ipi)
|
2001-04-10 21:04:32 +00:00
|
|
|
{
|
|
|
|
|
2002-01-18 04:41:23 +00:00
|
|
|
CTR3(KTR_SMP, "%s: cpus: %x ipi: %x", __func__, cpus, ipi);
|
2001-04-10 21:04:32 +00:00
|
|
|
selected_apic_ipi(cpus, ipi, APIC_DELMODE_FIXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send an IPI INTerrupt containing 'vector' to all CPUs, including myself
|
|
|
|
*/
|
|
|
|
void
|
2001-04-11 17:06:02 +00:00
|
|
|
ipi_all(u_int ipi)
|
2001-04-10 21:04:32 +00:00
|
|
|
{
|
|
|
|
|
2002-01-18 04:41:23 +00:00
|
|
|
CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
|
2001-04-10 21:04:32 +00:00
|
|
|
apic_ipi(APIC_DEST_ALLISELF, ipi, APIC_DELMODE_FIXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send an IPI to all CPUs EXCEPT myself
|
|
|
|
*/
|
|
|
|
void
|
2001-04-11 17:06:02 +00:00
|
|
|
ipi_all_but_self(u_int ipi)
|
2001-04-10 21:04:32 +00:00
|
|
|
{
|
|
|
|
|
2002-01-18 04:41:23 +00:00
|
|
|
CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
|
2001-04-10 21:04:32 +00:00
|
|
|
apic_ipi(APIC_DEST_ALLESELF, ipi, APIC_DELMODE_FIXED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send an IPI to myself
|
|
|
|
*/
|
|
|
|
void
|
2001-04-11 17:06:02 +00:00
|
|
|
ipi_self(u_int ipi)
|
2001-04-10 21:04:32 +00:00
|
|
|
{
|
|
|
|
|
2002-01-18 04:41:23 +00:00
|
|
|
CTR2(KTR_SMP, "%s: ipi: %x", __func__, ipi);
|
2001-04-10 21:04:32 +00:00
|
|
|
apic_ipi(APIC_DEST_SELF, ipi, APIC_DELMODE_FIXED);
|
|
|
|
}
|
|
|
|
|
2002-10-16 08:57:14 +00:00
|
|
|
static void
|
2000-09-07 01:33:02 +00:00
|
|
|
release_aps(void *dummy __unused)
|
|
|
|
{
|
2002-08-28 23:24:05 +00:00
|
|
|
|
|
|
|
mtx_lock_spin(&sched_lock);
|
2001-01-24 12:35:55 +00:00
|
|
|
atomic_store_rel_int(&aps_ready, 1);
|
2002-08-28 23:24:05 +00:00
|
|
|
while (smp_started == 0)
|
|
|
|
ia32_pause();
|
|
|
|
mtx_unlock_spin(&sched_lock);
|
2000-09-07 01:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, release_aps, NULL);
|