ia64/xen-unstable

changeset 17073:031c8f407e01

[IA64] Self IO EMUlator - tools part

Signed-off-by: Tristan Gingold <tgingold@free.fr>
author Alex Williamson <alex.williamson@hp.com>
date Tue Feb 19 08:12:28 2008 -0700 (2008-02-19)
parents 430a036ab261
children aaf4d6d1d83e
files tools/libxc/ia64/Makefile tools/libxc/ia64/xc_dom_ia64_util.h tools/libxc/ia64/xc_ia64_dom_fwloader.c tools/libxc/xc_dom_ia64.c
line diff
     1.1 --- a/tools/libxc/ia64/Makefile	Tue Feb 19 08:11:22 2008 -0700
     1.2 +++ b/tools/libxc/ia64/Makefile	Tue Feb 19 08:12:28 2008 -0700
     1.3 @@ -8,6 +8,8 @@ GUEST_SRCS-y += ia64/xc_ia64_linux_resto
     1.4  GUEST_SRCS-y += ia64/xc_dom_ia64_util.c
     1.5  GUEST_SRCS-y += ia64/dom_fw_acpi.c
     1.6  
     1.7 +GUEST_SRCS-y += ia64/xc_ia64_dom_fwloader.c
     1.8 +
     1.9  DOMFW_SRCS_BASE := dom_fw_common.c dom_fw_domu.c dom_fw_asm.S
    1.10  endif
    1.11  DOMFW_SRCS := $(addprefix ia64/, $(DOMFW_SRCS_BASE))
     2.1 --- a/tools/libxc/ia64/xc_dom_ia64_util.h	Tue Feb 19 08:11:22 2008 -0700
     2.2 +++ b/tools/libxc/ia64/xc_dom_ia64_util.h	Tue Feb 19 08:12:28 2008 -0700
     2.3 @@ -16,4 +16,11 @@ xen_ia64_dom_fw_setup(struct xc_dom_imag
     2.4  #define efi_systable_init_dom0(tables)	assert(0)
     2.5  #define complete_dom0_memmap(d, tables) ({assert(0);0;})
     2.6  
     2.7 +/* Defined in xc_dom_ia64.c  */
     2.8 +extern int start_info_ia64(struct xc_dom_image *dom);
     2.9 +extern int shared_info_ia64(struct xc_dom_image *dom, void *ptr);
    2.10 +
    2.11 +#define FW_MEM_BASE 0xff000000UL
    2.12 +#define FW_MEM_SIZE 0x01000000UL
    2.13 +
    2.14  #endif /* XC_IA64_DOM_IA64_UTIL_H */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxc/ia64/xc_ia64_dom_fwloader.c	Tue Feb 19 08:12:28 2008 -0700
     3.3 @@ -0,0 +1,124 @@
     3.4 +#include <stdlib.h>
     3.5 +#include <inttypes.h>
     3.6 +#include <asm/kregs.h>
     3.7 +
     3.8 +#include <xen/xen.h>
     3.9 +#include <xen/foreign/ia64.h>
    3.10 +#include <xen/io/protocols.h>
    3.11 +
    3.12 +#include "xg_private.h"
    3.13 +#include "xc_dom.h"
    3.14 +
    3.15 +#include "ia64/xc_dom_ia64_util.h"
    3.16 +
    3.17 +static const char fw_magic[16] = {'X', 'e', 'n', '-',
    3.18 +                                  'i', 'a', '6', '4',
    3.19 +                                  '-', 'f', 'w', 0,
    3.20 +                                  0, 0, 0, 0};
    3.21 +#define FW_LOAD 0xff800000UL
    3.22 +#define FW_SIZE (8 * 1024 * 1024)
    3.23 +
    3.24 +static int xc_dom_probe_fw_kernel(struct xc_dom_image *dom)
    3.25 +{
    3.26 +    if (dom->kernel_size != FW_SIZE)
    3.27 +        return -EINVAL;
    3.28 +    if (memcmp (dom->kernel_blob, fw_magic, sizeof (fw_magic)))
    3.29 +        return -EINVAL;
    3.30 +    return 0;
    3.31 +}
    3.32 +
    3.33 +static int xc_dom_parse_fw_kernel(struct xc_dom_image *dom)
    3.34 +{
    3.35 +    dom->kernel_seg.vstart = FW_LOAD;
    3.36 +    dom->kernel_seg.vend = FW_LOAD + FW_SIZE;
    3.37 +    dom->parms.virt_base = FW_MEM_BASE;
    3.38 +    dom->parms.virt_entry = FW_LOAD + sizeof (fw_magic);
    3.39 +    dom->ramdisk_blob = NULL; /* No ramdisk yet.  */
    3.40 +    dom->guest_type = "hvm-3.0-ia64-sioemu";
    3.41 +    return 0;
    3.42 +}
    3.43 +
    3.44 +static int xc_dom_load_fw_kernel(struct xc_dom_image *dom)
    3.45 +{
    3.46 +    char *dest;
    3.47 +    unsigned long i;
    3.48 +
    3.49 +    dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart);
    3.50 +    memcpy(dest, dom->kernel_blob, FW_SIZE);
    3.51 +
    3.52 +    /* Synchronize cache.  */
    3.53 +    for (i = 0; i < FW_SIZE; i += 32)
    3.54 +        asm volatile ("fc.i %0" :: "r"(dest + i) : "memory");
    3.55 +
    3.56 +    return 0;
    3.57 +}
    3.58 +
    3.59 +/* ------------------------------------------------------------------------ */
    3.60 +
    3.61 +static int alloc_magic_pages(struct xc_dom_image *dom)
    3.62 +{
    3.63 +    /* allocate special pages */
    3.64 +    dom->console_pfn = 0;
    3.65 +    dom->xenstore_pfn = 1;
    3.66 +    dom->start_info_pfn = 2;
    3.67 +    return 0;
    3.68 +}
    3.69 +
    3.70 +extern unsigned long xc_ia64_fpsr_default(void);
    3.71 +
    3.72 +static int vcpu_ia64(struct xc_dom_image *dom, void *ptr)
    3.73 +{
    3.74 +    vcpu_guest_context_ia64_t *ctxt = ptr;
    3.75 +
    3.76 +    xc_dom_printf("%s: called\n", __FUNCTION__);
    3.77 +
    3.78 +    /* clear everything */
    3.79 +    memset(ctxt, 0, sizeof(*ctxt));
    3.80 +
    3.81 +    ctxt->flags = 0;
    3.82 +    ctxt->regs.ip = dom->parms.virt_entry;
    3.83 +#ifdef __ia64__			/* FIXME */
    3.84 +    ctxt->regs.ar.fpsr = xc_ia64_fpsr_default();
    3.85 +#endif
    3.86 +    ctxt->regs.cr.isr = 1UL << 63;
    3.87 +    ctxt->regs.psr = IA64_PSR_AC | IA64_PSR_BN;
    3.88 +    ctxt->regs.cr.dcr = 0;
    3.89 +    ctxt->regs.cr.pta = 15 << 2;
    3.90 +
    3.91 +    return 0;
    3.92 +}
    3.93 +
    3.94 +static struct xc_dom_arch xc_dom_arch_ia64_fw = {
    3.95 +    .guest_type = "hvm-3.0-ia64-sioemu",
    3.96 +    .native_protocol = XEN_IO_PROTO_ABI_IA64,
    3.97 +    .page_shift = PAGE_SHIFT_IA64,
    3.98 +    .alloc_magic_pages = alloc_magic_pages,
    3.99 +    .start_info = start_info_ia64,
   3.100 +    .shared_info = shared_info_ia64,
   3.101 +    .vcpu = vcpu_ia64,
   3.102 +};
   3.103 +
   3.104 +/* ------------------------------------------------------------------------ */
   3.105 +
   3.106 +static struct xc_dom_loader fw_loader = {
   3.107 +    .name = "xen-ia64-fw",
   3.108 +    .probe = xc_dom_probe_fw_kernel,
   3.109 +    .parser = xc_dom_parse_fw_kernel,
   3.110 +    .loader = xc_dom_load_fw_kernel,
   3.111 +};
   3.112 +
   3.113 +static void __init register_fwloader(void)
   3.114 +{
   3.115 +    xc_dom_register_arch_hooks(&xc_dom_arch_ia64_fw);
   3.116 +    xc_dom_register_loader(&fw_loader);
   3.117 +}
   3.118 +
   3.119 +/*
   3.120 + * Local variables:
   3.121 + * mode: C
   3.122 + * c-set-style: "BSD"
   3.123 + * c-basic-offset: 4
   3.124 + * tab-width: 4
   3.125 + * indent-tabs-mode: nil
   3.126 + * End:
   3.127 + */
     4.1 --- a/tools/libxc/xc_dom_ia64.c	Tue Feb 19 08:11:22 2008 -0700
     4.2 +++ b/tools/libxc/xc_dom_ia64.c	Tue Feb 19 08:12:28 2008 -0700
     4.3 @@ -37,7 +37,7 @@ static int alloc_magic_pages(struct xc_d
     4.4      return 0;
     4.5  }
     4.6  
     4.7 -static int start_info_ia64(struct xc_dom_image *dom)
     4.8 +int start_info_ia64(struct xc_dom_image *dom)
     4.9  {
    4.10      start_info_ia64_t *start_info =
    4.11          xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1);
    4.12 @@ -79,7 +79,7 @@ static int start_info_ia64(struct xc_dom
    4.13      return 0;
    4.14  }
    4.15  
    4.16 -static int shared_info_ia64(struct xc_dom_image *dom, void *ptr)
    4.17 +int shared_info_ia64(struct xc_dom_image *dom, void *ptr)
    4.18  {
    4.19      shared_info_ia64_t *shared_info = ptr;
    4.20      int i;
    4.21 @@ -153,15 +153,27 @@ int arch_setup_meminit(struct xc_dom_ima
    4.22  {
    4.23      xen_pfn_t pfn;
    4.24      int rc;
    4.25 +    unsigned long start;
    4.26 +    unsigned long nbr;
    4.27  
    4.28      /* setup initial p2m */
    4.29 -    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * dom->total_pages);
    4.30 -    for ( pfn = 0; pfn < dom->total_pages; pfn++ )
    4.31 -        dom->p2m_host[pfn] = pfn;
    4.32 +    if (dom->guest_type && strcmp(dom->guest_type,
    4.33 +                                  "hvm-3.0-ia64-sioemu") == 0) {
    4.34 +        start = FW_MEM_BASE >> PAGE_SHIFT_IA64;
    4.35 +        nbr = FW_MEM_SIZE >> PAGE_SHIFT_IA64;
    4.36 +    } else {
    4.37 +        start = 0;
    4.38 +        nbr = dom->total_pages;
    4.39 +    }
    4.40 +
    4.41 +    /* setup initial p2m */
    4.42 +    dom->p2m_host = xc_dom_malloc(dom, sizeof(xen_pfn_t) * nbr);
    4.43 +    for ( pfn = 0; pfn < nbr; pfn++ )
    4.44 +        dom->p2m_host[pfn] = start + pfn;
    4.45  
    4.46      /* allocate guest memory */
    4.47      rc = xc_domain_memory_populate_physmap(dom->guest_xc, dom->guest_domid,
    4.48 -                                           dom->total_pages, 0, 0,
    4.49 +                                           nbr, 0, 0,
    4.50                                             dom->p2m_host);
    4.51      return rc;
    4.52  }
    4.53 @@ -232,7 +244,20 @@ int arch_setup_bootearly(struct xc_dom_i
    4.54      DECLARE_DOMCTL;
    4.55      int rc;
    4.56  
    4.57 -    xc_dom_printf("%s: setup firmware\n", __FUNCTION__);
    4.58 +    xc_dom_printf("%s: setup firmware for %s\n", __FUNCTION__, dom->guest_type);
    4.59 +
    4.60 +    if (dom->guest_type && strcmp(dom->guest_type,
    4.61 +                                  "hvm-3.0-ia64-sioemu") == 0) {
    4.62 +        memset(&domctl, 0, sizeof(domctl));
    4.63 +        domctl.u.arch_setup.flags = XEN_DOMAINSETUP_sioemu_guest;
    4.64 +        domctl.u.arch_setup.bp = 0;
    4.65 +        domctl.u.arch_setup.maxmem = 0;
    4.66 +        domctl.cmd = XEN_DOMCTL_arch_setup;
    4.67 +        domctl.domain = dom->guest_domid;
    4.68 +        rc = xc_domctl(dom->guest_xc, &domctl);
    4.69 +        xc_dom_printf("%s: hvm-3.0-ia64-sioemu: %d\n", __FUNCTION__, rc);
    4.70 +        return rc;
    4.71 +    }
    4.72  
    4.73      rc = ia64_setup_memmap(dom);
    4.74      if (rc)