ia64/xen-unstable

changeset 15127:81861796b5bb

[IA64] memmap: make libxc domain builder set up firmware instead of xen

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Mon May 21 14:05:08 2007 -0600 (2007-05-21)
parents 9d5dc8f3b2d4
children fc49dbce4868
files tools/libxc/ia64/Makefile tools/libxc/ia64/xc_dom_ia64_util.c tools/libxc/ia64/xc_dom_ia64_util.h tools/libxc/xc_dom_ia64.c
line diff
     1.1 --- a/tools/libxc/ia64/Makefile	Mon May 21 14:00:54 2007 -0600
     1.2 +++ b/tools/libxc/ia64/Makefile	Mon May 21 14:05:08 2007 -0600
     1.3 @@ -3,3 +3,46 @@ CTRL_SRCS-y += ia64/xc_ia64_stubs.c
     1.4  GUEST_SRCS-y += ia64/xc_ia64_hvm_build.c
     1.5  GUEST_SRCS-y += ia64/xc_ia64_linux_save.c
     1.6  GUEST_SRCS-y += ia64/xc_ia64_linux_restore.c
     1.7 +
     1.8 +GUEST_SRCS-y += ia64/xc_dom_ia64_util.c
     1.9 +DOMFW_SRCS_BASE := dom_fw_common.c dom_fw_domu.c dom_fw_asm.S
    1.10 +DOMFW_SRCS := $(addprefix ia64/, $(DOMFW_SRCS_BASE))
    1.11 +$(DOMFW_SRCS):
    1.12 +	ln -sf ../$(XEN_ROOT)/xen/arch/ia64/xen/$(@F) $@
    1.13 +
    1.14 +# XXX kludge: libxc/Makefile doesn't understand .S.
    1.15 +GUEST_SRCS-y += $(patsubst %.S, %.c, $(DOMFW_SRCS))
    1.16 +%.o: %.S
    1.17 +	$(CC) $(CFLAGS) -c $< -o $@
    1.18 +%.opic: %.S
    1.19 +	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) -fPIC -c -o $@ $<
    1.20 +
    1.21 +
    1.22 +CFLAGS	+= -Iia64
    1.23 +
    1.24 +DOMFW_ASM_HDRS_BASE := bundle.h dom_fw.h dom_fw_common.h dom_fw_domu.h
    1.25 +DOMFW_ASM_HDRS := $(addprefix ia64/asm/, $(DOMFW_ASM_HDRS_BASE))
    1.26 +$(DOMFW_ASM_HDRS): ia64/asm
    1.27 +	ln -sf ../../$(XEN_ROOT)/xen/include/asm-ia64/$(@F) $@
    1.28 +build: $(DOMFW_ASM_HDR)
    1.29 +
    1.30 +.PHONY: mk-symlinks-acpi ia64-clean
    1.31 +
    1.32 +IA64_HDR_DIRS := ia64/asm ia64/xen ia64/acpi ia64/acpi/platform
    1.33 +$(IA64_HDR_DIRS):
    1.34 +	mkdir -p $@
    1.35 +
    1.36 +IA64_EMPTY_FILES := ia64/asm/acpi.h ia64/xen/list.h 
    1.37 +$(IA64_EMPTY_FILES): $(IA64_HDR_DIRS)
    1.38 +	echo "/* automatically created dummy empty header file. */" > $@
    1.39 +
    1.40 +mk-symlinks-acpi: $(IA64_HDR_DIRS) $(IA64_EMPTY_FILES) $(DOMFW_ASM_HDRS)
    1.41 +	( cd ia64/acpi && ln -sf ../../$(XEN_ROOT)/xen/include/acpi/*.h .)
    1.42 +	( cd ia64/acpi/platform && ln -sf ../../../$(XEN_ROOT)/xen/include/acpi/platform/*.h .)
    1.43 +	( cd ia64/acpi/platform/ && ln -sf ../../aclinux.h .)
    1.44 +	( cd ia64/xen && ln -sf ../../$(XEN_ROOT)/xen/include/xen/acpi.h .)
    1.45 +build: mk-symlinks-acpi
    1.46 +
    1.47 +clean: ia64-clean
    1.48 +ia64-clean:
    1.49 +	rm -rf $(DOMFW_SRCS) $(DOMFW_ASM_HDRS) $(IA64_EMPTY_FILES) $(IA64_HDR_DIRS)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/libxc/ia64/xc_dom_ia64_util.c	Mon May 21 14:05:08 2007 -0600
     2.3 @@ -0,0 +1,174 @@
     2.4 +/*
     2.5 + * This program is free software; you can redistribute it and/or modify
     2.6 + * it under the terms of the GNU General Public License as published by
     2.7 + * the Free Software Foundation; either version 2 of the License, or
     2.8 + * (at your option) any later version.
     2.9 + *
    2.10 + * This program is distributed in the hope that it will be useful,
    2.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.13 + * GNU General Public License for more details.
    2.14 + *
    2.15 + * You should have received a copy of the GNU General Public License
    2.16 + * along with this program; if not, write to the Free Software
    2.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2.18 + *
    2.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    2.20 + *                    VA Linux Systems Japan K.K.
    2.21 + *
    2.22 + */
    2.23 +
    2.24 +#include "xg_private.h"
    2.25 +#include "xc_dom.h"
    2.26 +#include "asm/dom_fw.h"
    2.27 +#include "asm/dom_fw_common.h"
    2.28 +#include "ia64/xc_dom_ia64_util.h"
    2.29 +
    2.30 +uint32_t
    2.31 +xen_ia64_version(struct xc_dom_image *dom)
    2.32 +{
    2.33 +    return xc_version(dom->guest_xc, XENVER_version, NULL);   
    2.34 +}
    2.35 +
    2.36 +int
    2.37 +xen_ia64_fpswa_revision(struct xc_dom_image *dom, unsigned int *revision)
    2.38 +{
    2.39 +    int ret = -1;
    2.40 +    DECLARE_HYPERCALL;
    2.41 +    hypercall.op     = __HYPERVISOR_ia64_dom0vp_op;
    2.42 +    hypercall.arg[0] = IA64_DOM0VP_fpswa_revision;
    2.43 +    hypercall.arg[1] = (unsigned long)revision;
    2.44 +
    2.45 +    if (lock_pages(revision, sizeof(*revision)) != 0) {
    2.46 +        PERROR("Could not lock memory for xen fpswa hypercall");
    2.47 +        goto out;
    2.48 +    }
    2.49 +
    2.50 +    ret = do_xen_hypercall(dom->guest_xc, &hypercall);
    2.51 +    
    2.52 +    unlock_pages(revision, sizeof(*revision));
    2.53 +out:
    2.54 +    return ret;
    2.55 +}
    2.56 +
    2.57 +int xen_ia64_is_running_on_sim(struct xc_dom_image *dom)
    2.58 +{
    2.59 +    /*
    2.60 +     * This is only used by dom_fw_init() as
    2.61 +     * "!xen_ia64_is_dom0() || xen_ia64_is_running_on_sim()".
    2.62 +     * So this doesn't affect the result.
    2.63 +     */
    2.64 +    return 0;
    2.65 +}
    2.66 +
    2.67 +int
    2.68 +xen_ia64_is_dom0(struct xc_dom_image *unused)
    2.69 +{
    2.70 +    /* libxc is for non-dom0 domain builder */
    2.71 +    return 0;
    2.72 +}
    2.73 +
    2.74 +void*
    2.75 +xen_ia64_dom_fw_map(struct xc_dom_image *dom, unsigned long mpaddr)
    2.76 +{
    2.77 +    unsigned long page_size = XC_DOM_PAGE_SIZE(dom);
    2.78 +    void* ret;
    2.79 +    
    2.80 +    ret = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
    2.81 +                               page_size, PROT_READ | PROT_WRITE,
    2.82 +                               mpaddr / page_size);
    2.83 +    if (ret != NULL)
    2.84 +        ret = (void*)((unsigned long)ret | (mpaddr & (page_size - 1)));
    2.85 +    return ret;
    2.86 +}
    2.87 +
    2.88 +void
    2.89 +xen_ia64_dom_fw_unmap(struct xc_dom_image *dom, void *vaddr)
    2.90 +{
    2.91 +    unsigned long page_size = XC_DOM_PAGE_SIZE(dom);
    2.92 +    munmap((void*)((unsigned long)vaddr & ~(page_size - 1)), page_size);
    2.93 +}
    2.94 +
    2.95 +int
    2.96 +xen_ia64_is_vcpu_allocated(struct xc_dom_image *dom, uint32_t vcpu)
    2.97 +{
    2.98 +    // return d->vcpu[vcpu] != NULL;
    2.99 +
   2.100 +    int rc;
   2.101 +    xc_vcpuinfo_t info;
   2.102 +
   2.103 +    rc = xc_vcpu_getinfo(dom->guest_xc, dom->guest_domid,
   2.104 +                         vcpu, &info);
   2.105 +    if (rc == 0)
   2.106 +        return 1;
   2.107 +
   2.108 +    if (rc != -ESRCH)
   2.109 +        PERROR("Could not get vcpu info");
   2.110 +    return 0;
   2.111 +}
   2.112 +
   2.113 +int
   2.114 +xen_ia64_dom_fw_setup(struct xc_dom_image *d, uint64_t brkimm,
   2.115 +                      unsigned long bp_mpa, unsigned long maxmem)
   2.116 +{
   2.117 +    int rc = 0;
   2.118 +    void *imva_hypercall_base = NULL;
   2.119 +    void *imva_tables_base = NULL;
   2.120 +    struct fake_acpi_tables *imva = NULL;
   2.121 +    struct xen_ia64_boot_param *bp = NULL;
   2.122 +
   2.123 +    BUILD_BUG_ON(sizeof(struct fw_tables) >
   2.124 +                 (FW_TABLES_END_PADDR - FW_TABLES_BASE_PADDR));
   2.125 +
   2.126 +    /* Create page for hypercalls.  */
   2.127 +    imva_hypercall_base = xen_ia64_dom_fw_map(d, FW_HYPERCALL_BASE_PADDR);
   2.128 +    if (imva_hypercall_base == NULL) {
   2.129 +        rc = -errno;
   2.130 +        goto out;
   2.131 +    }
   2.132 +
   2.133 +    /* Create page for FW tables.  */
   2.134 +    imva_tables_base = xen_ia64_dom_fw_map(d, FW_TABLES_BASE_PADDR);
   2.135 +    if (imva_tables_base == NULL) {
   2.136 +        rc = -errno;
   2.137 +        goto out;
   2.138 +    }
   2.139 +        
   2.140 +    /* Create page for acpi tables.  */
   2.141 +    imva = (struct fake_acpi_tables *)
   2.142 +        xen_ia64_dom_fw_map(d, FW_ACPI_BASE_PADDR);
   2.143 +    if (imva == NULL) {
   2.144 +        rc = -errno;
   2.145 +        goto out;
   2.146 +    }
   2.147 +    dom_fw_fake_acpi(d, imva);
   2.148 +
   2.149 +    /* Create page for boot_param.  */
   2.150 +    bp = xen_ia64_dom_fw_map(d, bp_mpa);
   2.151 +    if (bp == NULL) {
   2.152 +        rc = -errno;
   2.153 +        goto out;
   2.154 +    }
   2.155 +    rc = dom_fw_init(d, brkimm, bp, imva_tables_base,
   2.156 +                     (unsigned long)imva_hypercall_base, maxmem);
   2.157 + out:
   2.158 +    if (imva_hypercall_base != NULL)
   2.159 +        xen_ia64_dom_fw_unmap(d, imva_hypercall_base);
   2.160 +    if (imva_tables_base != NULL)
   2.161 +        xen_ia64_dom_fw_unmap(d, imva_tables_base);
   2.162 +    if (imva != NULL)
   2.163 +        xen_ia64_dom_fw_unmap(d, imva);
   2.164 +    if (bp != NULL)
   2.165 +        xen_ia64_dom_fw_unmap(d, bp);
   2.166 +    return rc;
   2.167 +}
   2.168 +
   2.169 +/*
   2.170 + * Local variables:
   2.171 + * mode: C
   2.172 + * c-set-style: "BSD"
   2.173 + * c-basic-offset: 4
   2.174 + * tab-width: 4
   2.175 + * indent-tabs-mode: nil
   2.176 + * End:
   2.177 + */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxc/ia64/xc_dom_ia64_util.h	Mon May 21 14:05:08 2007 -0600
     3.3 @@ -0,0 +1,19 @@
     3.4 +#ifndef XC_IA64_DOM_IA64_UTIL_H
     3.5 +#define XC_IA64_DOM_IA64_UTIL_H
     3.6 +
     3.7 +struct xc_dom_image;
     3.8 +uint32_t xen_ia64_version(struct xc_dom_image *dom); 
     3.9 +void* xen_ia64_dom_fw_map(struct xc_dom_image *dom, unsigned long mpaddr);
    3.10 +void xen_ia64_dom_fw_unmap(struct xc_dom_image *dom, void *addr); 
    3.11 +int xen_ia64_fpswa_revision(struct xc_dom_image *dom, unsigned int *revision);
    3.12 +int xen_ia64_is_vcpu_allocated(struct xc_dom_image *dom, uint32_t vcpu); 
    3.13 +int xen_ia64_is_running_on_sim(struct xc_dom_image *dom);
    3.14 +int xen_ia64_is_dom0(struct xc_dom_image *dom);
    3.15 +
    3.16 +int
    3.17 +xen_ia64_dom_fw_setup(struct xc_dom_image *d, uint64_t brkimm,
    3.18 +                      unsigned long bp_mpa, unsigned long maxmem);
    3.19 +#define efi_systable_init_dom0(tables)	assert(0)
    3.20 +#define complete_dom0_memmap(d, tables, maxmem, num_mds) ({assert(0);0;})
    3.21 +
    3.22 +#endif /* XC_IA64_DOM_IA64_UTIL_H */
     4.1 --- a/tools/libxc/xc_dom_ia64.c	Mon May 21 14:00:54 2007 -0600
     4.2 +++ b/tools/libxc/xc_dom_ia64.c	Mon May 21 14:05:08 2007 -0600
     4.3 @@ -12,6 +12,7 @@
     4.4  #include <stdlib.h>
     4.5  #include <string.h>
     4.6  #include <inttypes.h>
     4.7 +#include <assert.h>
     4.8  
     4.9  #include <xen/xen.h>
    4.10  #include <xen/foreign/ia64.h>
    4.11 @@ -20,6 +21,9 @@
    4.12  #include "xc_dom.h"
    4.13  #include "xenctrl.h"
    4.14  
    4.15 +#include <asm/dom_fw_common.h>
    4.16 +#include "ia64/xc_dom_ia64_util.h"
    4.17 +
    4.18  /* ------------------------------------------------------------------------ */
    4.19  
    4.20  static int alloc_magic_pages(struct xc_dom_image *dom)
    4.21 @@ -49,6 +53,13 @@ static int start_info_ia64(struct xc_dom
    4.22      start_info->console.domU.mfn = dom->console_pfn;
    4.23      start_info->console.domU.evtchn = dom->console_evtchn;
    4.24  
    4.25 +    /*
    4.26 +     * domain_start and domain_size are abused for arch_setup hypercall
    4.27 +     * so that we need to clear them here.
    4.28 +     */
    4.29 +    XEN_IA64_MEMMAP_INFO_NUM_PAGES(bp) = 0;
    4.30 +    XEN_IA64_MEMMAP_INFO_PFN(bp) = 0;
    4.31 +
    4.32      if ( dom->ramdisk_blob )
    4.33      {
    4.34          start_info->mod_start = dom->ramdisk_seg.vstart;
    4.35 @@ -77,7 +88,7 @@ static int shared_info_ia64(struct xc_do
    4.36      for (i = 0; i < MAX_VIRT_CPUS; i++)
    4.37          shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
    4.38      shared_info->arch.start_info_pfn = dom->start_info_pfn;
    4.39 -    shared_info->arch.memmap_info_num_pages = 1;
    4.40 +    shared_info->arch.memmap_info_num_pages = 1; //XXX
    4.41      shared_info->arch.memmap_info_pfn = dom->start_info_pfn - 1;
    4.42      return 0;
    4.43  }
    4.44 @@ -153,6 +164,7 @@ int arch_setup_meminit(struct xc_dom_ima
    4.45  static int ia64_setup_memmap(struct xc_dom_image *dom)
    4.46  {
    4.47      unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
    4.48 +    unsigned long memmap_info_num_pages;
    4.49      unsigned long memmap_info_pfn;
    4.50      xen_ia64_memmap_info_t* memmap_info;
    4.51      unsigned int num_mds;
    4.52 @@ -162,11 +174,12 @@ static int ia64_setup_memmap(struct xc_d
    4.53      struct xen_ia64_boot_param* bp;
    4.54  
    4.55      /* setup memmap page */
    4.56 +    memmap_info_num_pages = 1;
    4.57      memmap_info_pfn = dom->start_info_pfn - 1;
    4.58 -    xc_dom_printf("%s: memmap: mfn 0x%" PRIpfn "\n",
    4.59 -		  __FUNCTION__, memmap_info_pfn);
    4.60 +    xc_dom_printf("%s: memmap: mfn 0x%" PRIpfn " pages 0x%lx\n",
    4.61 +                  __FUNCTION__, memmap_info_pfn, memmap_info_num_pages);
    4.62      memmap_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
    4.63 -                                       page_size,
    4.64 +                                       page_size * memmap_info_num_pages,
    4.65                                         PROT_READ | PROT_WRITE,
    4.66                                         memmap_info_pfn);
    4.67      if (NULL == memmap_info)
    4.68 @@ -184,10 +197,17 @@ static int ia64_setup_memmap(struct xc_d
    4.69      md[num_mds].attribute = EFI_MEMORY_WB;
    4.70      num_mds++;
    4.71      memmap_info->efi_memmap_size = num_mds * sizeof(md[0]);
    4.72 -    munmap(memmap_info, page_size);
    4.73 +    munmap(memmap_info, page_size * memmap_info_num_pages);
    4.74 +    assert(nr_mds <=
    4.75 +           (page_size * memmap_info_num_pages -
    4.76 +            offsetof(*memmap_info, memdesc))/sizeof(*md));
    4.77  
    4.78 -    /* kludge: we need to pass memmap_info page's pfn somehow.
    4.79 -     * we use xen_ia64_boot_param::efi_memmap for this purpose */
    4.80 +    /*
    4.81 +     * kludge: we need to pass memmap_info page's pfn and other magic pages
    4.82 +     * somehow.
    4.83 +     * we use xen_ia64_boot_param::efi_memmap::{efi_memmap, efi_memmap_size}
    4.84 +     * for this purpose
    4.85 +     */
    4.86      start_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
    4.87  				      page_size,
    4.88  				      PROT_READ | PROT_WRITE,
    4.89 @@ -196,9 +216,8 @@ static int ia64_setup_memmap(struct xc_d
    4.90          return -1;
    4.91      bp = (struct xen_ia64_boot_param*)(start_info + sizeof(start_info_t));
    4.92      memset(bp, 0, sizeof(*bp));
    4.93 -    bp->efi_memmap = memmap_info_pfn;
    4.94 -    /* 4 = memmap info page, start info page, xenstore page and console page */
    4.95 -    bp->efi_memmap_size = 4 * PAGE_SIZE;
    4.96 +    XEN_IA64_MEMMAP_INFO_NUM_PAGES(bp) = memmap_info_num_pages;
    4.97 +    XEN_IA64_MEMMAP_INFO_PFN(bp) = memmap_info_pfn;
    4.98      munmap(start_info, page_size);
    4.99      return 0;
   4.100  }
   4.101 @@ -217,6 +236,20 @@ int arch_setup_bootearly(struct xc_dom_i
   4.102      memset(&domctl, 0, sizeof(domctl));
   4.103      domctl.cmd = XEN_DOMCTL_arch_setup;
   4.104      domctl.domain = dom->guest_domid;
   4.105 +    domctl.u.arch_setup.flags = XEN_DOMAINSETUP_query;
   4.106 +    rc = do_domctl(dom->guest_xc, &domctl);
   4.107 +    if (rc)
   4.108 +        return rc;
   4.109 +    rc = xen_ia64_dom_fw_setup(dom, domctl.u.arch_setup.hypercall_imm,
   4.110 +                               (dom->start_info_pfn << PAGE_SHIFT) +
   4.111 +                               sizeof(start_info_t),
   4.112 +                               dom->total_pages << PAGE_SHIFT);
   4.113 +    if (rc)
   4.114 +        return rc;
   4.115 +
   4.116 +    memset(&domctl, 0, sizeof(domctl));
   4.117 +    domctl.cmd = XEN_DOMCTL_arch_setup;
   4.118 +    domctl.domain = dom->guest_domid;
   4.119      domctl.u.arch_setup.flags = 0;
   4.120  
   4.121      domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT)