setup.c

来自「xen虚拟机源代码安装包」· C语言 代码 · 共 1,123 行 · 第 1/3 页

C
1,123
字号
#include <xen/config.h>#include <xen/init.h>#include <xen/lib.h>#include <xen/sched.h>#include <xen/domain.h>#include <xen/serial.h>#include <xen/softirq.h>#include <xen/acpi.h>#include <xen/console.h>#include <xen/serial.h>#include <xen/trace.h>#include <xen/multiboot.h>#include <xen/domain_page.h>#include <xen/version.h>#include <xen/gdbstub.h>#include <xen/percpu.h>#include <xen/hypercall.h>#include <xen/keyhandler.h>#include <xen/numa.h>#include <xen/rcupdate.h>#include <xen/vga.h>#include <xen/dmi.h>#include <public/version.h>#ifdef CONFIG_COMPAT#include <compat/platform.h>#include <compat/xen.h>#endif#include <asm/bitops.h>#include <asm/smp.h>#include <asm/processor.h>#include <asm/mpspec.h>#include <asm/apic.h>#include <asm/desc.h>#include <asm/paging.h>#include <asm/e820.h>#include <xsm/acm/acm_hooks.h>#include <xen/kexec.h>#include <asm/edd.h>#include <xsm/xsm.h>#include <asm/tboot.h>#if defined(CONFIG_X86_64)#define BOOTSTRAP_DIRECTMAP_END (1UL << 32) /* 4GB */#define maddr_to_bootstrap_virt(m) maddr_to_virt(m)#else#define BOOTSTRAP_DIRECTMAP_END (1UL << 30) /* 1GB */#define maddr_to_bootstrap_virt(m) ((void *)(long)(m))#endifextern void generic_apic_probe(void);extern void numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn);extern u16 boot_edid_caps;extern u8 boot_edid_info[128];extern struct boot_video_info boot_vid_info;/* * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the * page_info table and allocation bitmap. */static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;#if defined(CONFIG_X86_64)integer_param("xenheap_megabytes", opt_xenheap_megabytes);#endif/* opt_nosmp: If true, secondary processors are ignored. */static int opt_nosmp = 0;boolean_param("nosmp", opt_nosmp);/* maxcpus: maximum number of CPUs to activate. */static unsigned int max_cpus = NR_CPUS;integer_param("maxcpus", max_cpus);/* opt_watchdog: If true, run a watchdog NMI on each processor. */static int opt_watchdog = 0;boolean_param("watchdog", opt_watchdog);/* **** Linux config option: propagated to domain0. *//* "acpi=off":    Sisables both ACPI table parsing and interpreter. *//* "acpi=force":  Override the disable blacklist.                   *//* "acpi=strict": Disables out-of-spec workarounds.                 *//* "acpi=ht":     Limit ACPI just to boot-time to enable HT.        *//* "acpi=noirq":  Disables ACPI interrupt routing.                  */static void parse_acpi_param(char *s);custom_param("acpi", parse_acpi_param);/* **** Linux config option: propagated to domain0. *//* acpi_skip_timer_override: Skip IRQ0 overrides. */extern int acpi_skip_timer_override;boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);/* **** Linux config option: propagated to domain0. *//* noapic: Disable IOAPIC setup. */extern int skip_ioapic_setup;boolean_param("noapic", skip_ioapic_setup);/* **** Linux config option: propagated to domain0. *//* xen_cpuidle: xen control cstate. *//*static*/ int xen_cpuidle;boolean_param("cpuidle", xen_cpuidle);int early_boot = 1;cpumask_t cpu_present_map;unsigned long xen_phys_start;/* Limits of Xen heap, used to initialise the allocator. */unsigned long xenheap_phys_start, xenheap_phys_end;extern void arch_init_memory(void);extern void init_IRQ(void);extern void early_time_init(void);extern void early_cpu_init(void);extern void vesa_init(void);extern void vesa_mtrr_init(void);struct tss_struct init_tss[NR_CPUS];char __attribute__ ((__section__(".bss.stack_aligned"))) cpu0_stack[STACK_SIZE];struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;EXPORT_SYMBOL(mmu_cr4_features);int acpi_disabled;int acpi_force;char acpi_param[10] = "";static void __init parse_acpi_param(char *s){    /* Save the parameter so it can be propagated to domain0. */    safe_strcpy(acpi_param, s);    /* Interpret the parameter for use within Xen. */    if ( !strcmp(s, "off") )    {        disable_acpi();    }    else if ( !strcmp(s, "force") )    {        acpi_force = 1;        acpi_ht = 1;        acpi_disabled = 0;    }    else if ( !strcmp(s, "strict") )    {        acpi_strict = 1;    }    else if ( !strcmp(s, "ht") )    {        if ( !acpi_force )            disable_acpi();        acpi_ht = 1;    }    else if ( !strcmp(s, "noirq") )    {        acpi_noirq_set();    }}static void __init do_initcalls(void){    initcall_t *call;    for ( call = &__initcall_start; call < &__initcall_end; call++ )        (*call)();}#define EARLY_FAIL(f, a...) do {                \    printk( f , ## a );                         \    for ( ; ; ) halt();                         \} while (0)static unsigned long __initdata initial_images_start, initial_images_end;unsigned long __init initial_images_nrpages(void){    ASSERT(!(initial_images_start & ~PAGE_MASK));    ASSERT(!(initial_images_end   & ~PAGE_MASK));    return ((initial_images_end >> PAGE_SHIFT) -            (initial_images_start >> PAGE_SHIFT));}void __init discard_initial_images(void){    init_domheap_pages(initial_images_start, initial_images_end);}extern char __per_cpu_start[], __per_cpu_data_end[], __per_cpu_end[];static void __init percpu_init_areas(void){    unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;    unsigned int first_unused;    BUG_ON(data_size > PERCPU_SIZE);    /* Initialise per-cpu data area for all possible secondary CPUs. */    for ( i = 1; (i < NR_CPUS) && cpu_possible(i); i++ )        memcpy(__per_cpu_start + (i << PERCPU_SHIFT),               __per_cpu_start,               data_size);    first_unused = i;    /* Check that there are no holes in cpu_possible_map. */    for ( ; i < NR_CPUS; i++ )        BUG_ON(cpu_possible(i));#ifndef MEMORY_GUARD    init_xenheap_pages(__pa(__per_cpu_start) + (first_unused << PERCPU_SHIFT),                       __pa(__per_cpu_end));#endif    memguard_guard_range(&__per_cpu_start[first_unused << PERCPU_SHIFT],                         (NR_CPUS - first_unused) << PERCPU_SHIFT);#if defined(CONFIG_X86_64)    /* Also zap the mapping in the 1:1 area. */    memguard_guard_range(__va(__pa(__per_cpu_start)) +                         (first_unused << PERCPU_SHIFT),                         (NR_CPUS - first_unused) << PERCPU_SHIFT);#endif}static void __init init_idle_domain(void){    struct domain *idle_domain;    /* Domain creation requires that scheduler structures are initialised. */    scheduler_init();    idle_domain = domain_create(IDLE_DOMAIN_ID, 0, 0);    if ( (idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL) )        BUG();    set_current(idle_domain->vcpu[0]);    idle_vcpu[0] = this_cpu(curr_vcpu) = current;    setup_idle_pagetable();}static void __init srat_detect_node(int cpu){    unsigned node;    u32 apicid = x86_cpu_to_apicid[cpu];    node = apicid_to_node[apicid];    if ( node == NUMA_NO_NODE )        node = 0;    numa_set_node(cpu, node);    if ( acpi_numa > 0 )        printk(KERN_INFO "CPU %d APIC %d -> Node %d\n", cpu, apicid, node);}/* * Ensure a given physical memory range is present in the bootstrap mappings. * Use superpage mappings to ensure that pagetable memory needn't be allocated. */static void __init bootstrap_map(unsigned long start, unsigned long end){    unsigned long mask = (1UL << L2_PAGETABLE_SHIFT) - 1;    start = max_t(unsigned long, start & ~mask, 16UL << 20);    end   = (end + mask) & ~mask;    if ( start >= end )        return;    if ( end > BOOTSTRAP_DIRECTMAP_END )        panic("Cannot access memory beyond end of "              "bootstrap direct-map area\n");    map_pages_to_xen(        (unsigned long)maddr_to_bootstrap_virt(start),        start >> PAGE_SHIFT, (end-start) >> PAGE_SHIFT, PAGE_HYPERVISOR);}static void __init move_memory(    unsigned long dst, unsigned long src_start, unsigned long src_end){    bootstrap_map(src_start, src_end);    bootstrap_map(dst, dst + src_end - src_start);    memmove(maddr_to_bootstrap_virt(dst),            maddr_to_bootstrap_virt(src_start),            src_end - src_start);}/* A temporary copy of the e820 map that we can mess with during bootstrap. */static struct e820map __initdata boot_e820;struct boot_video_info {    u8  orig_x;             /* 0x00 */    u8  orig_y;             /* 0x01 */    u8  orig_video_mode;    /* 0x02 */    u8  orig_video_cols;    /* 0x03 */    u8  orig_video_lines;   /* 0x04 */    u8  orig_video_isVGA;   /* 0x05 */    u16 orig_video_points;  /* 0x06 */    /* VESA graphic mode -- linear frame buffer */    u32 capabilities;       /* 0x08 */    u16 lfb_linelength;     /* 0x0c */    u16 lfb_width;          /* 0x0e */    u16 lfb_height;         /* 0x10 */    u16 lfb_depth;          /* 0x12 */    u32 lfb_base;           /* 0x14 */    u32 lfb_size;           /* 0x18 */    u8  red_size;           /* 0x1c */    u8  red_pos;            /* 0x1d */    u8  green_size;         /* 0x1e */    u8  green_pos;          /* 0x1f */    u8  blue_size;          /* 0x20 */    u8  blue_pos;           /* 0x21 */    u8  rsvd_size;          /* 0x22 */    u8  rsvd_pos;           /* 0x23 */    u16 vesapm_seg;         /* 0x24 */    u16 vesapm_off;         /* 0x26 */    u16 vesa_attrib;        /* 0x28 */};static void __init parse_video_info(void){    struct boot_video_info *bvi = &bootsym(boot_vid_info);    if ( (bvi->orig_video_isVGA == 1) && (bvi->orig_video_mode == 3) )    {        vga_console_info.video_type = XEN_VGATYPE_TEXT_MODE_3;        vga_console_info.u.text_mode_3.font_height = bvi->orig_video_points;        vga_console_info.u.text_mode_3.cursor_x = bvi->orig_x;        vga_console_info.u.text_mode_3.cursor_y = bvi->orig_y;        vga_console_info.u.text_mode_3.rows = bvi->orig_video_lines;        vga_console_info.u.text_mode_3.columns = bvi->orig_video_cols;    }    else if ( bvi->orig_video_isVGA == 0x23 )    {        vga_console_info.video_type = XEN_VGATYPE_VESA_LFB;        vga_console_info.u.vesa_lfb.width = bvi->lfb_width;        vga_console_info.u.vesa_lfb.height = bvi->lfb_height;        vga_console_info.u.vesa_lfb.bytes_per_line = bvi->lfb_linelength;        vga_console_info.u.vesa_lfb.bits_per_pixel = bvi->lfb_depth;        vga_console_info.u.vesa_lfb.lfb_base = bvi->lfb_base;        vga_console_info.u.vesa_lfb.lfb_size = bvi->lfb_size;        vga_console_info.u.vesa_lfb.red_pos = bvi->red_pos;        vga_console_info.u.vesa_lfb.red_size = bvi->red_size;        vga_console_info.u.vesa_lfb.green_pos = bvi->green_pos;        vga_console_info.u.vesa_lfb.green_size = bvi->green_size;        vga_console_info.u.vesa_lfb.blue_pos = bvi->blue_pos;        vga_console_info.u.vesa_lfb.blue_size = bvi->blue_size;        vga_console_info.u.vesa_lfb.rsvd_pos = bvi->rsvd_pos;        vga_console_info.u.vesa_lfb.rsvd_size = bvi->rsvd_size;        vga_console_info.u.vesa_lfb.gbl_caps = bvi->capabilities;        vga_console_info.u.vesa_lfb.mode_attrs = bvi->vesa_attrib;    }}void __init kexec_reserve_area(struct e820map *e820){    unsigned long kdump_start = kexec_crash_area.start;    unsigned long kdump_size  = kexec_crash_area.size;    static int is_reserved = 0;    kdump_size = (kdump_size + PAGE_SIZE - 1) & PAGE_MASK;    if ( (kdump_start == 0) || (kdump_size == 0) || is_reserved )        return;    is_reserved = 1;    if ( !reserve_e820_ram(e820, kdump_start, kdump_start + kdump_size) )    {        printk("Kdump: DISABLED (failed to reserve %luMB (%lukB) at 0x%lx)"               "\n", kdump_size >> 20, kdump_size >> 10, kdump_start);        kexec_crash_area.start = kexec_crash_area.size = 0;    }    else    {        printk("Kdump: %luMB (%lukB) at 0x%lx\n",               kdump_size >> 20, kdump_size >> 10, kdump_start);    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?