ia64/xen-unstable

changeset 14506:2734b64255b3

[LIBXC] Move domain builder hooks into arch-specific files and remove ifdefs.
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Wed Mar 21 17:02:59 2007 -0500 (2007-03-21)
parents 58e796d053ca
children ed84ed49bb81
files tools/libxc/Makefile tools/libxc/xc_dom.h tools/libxc/xc_dom_boot.c tools/libxc/xc_dom_ia64.c tools/libxc/xc_dom_x86.c
line diff
     1.1 --- a/tools/libxc/Makefile	Wed Mar 21 17:02:59 2007 -0500
     1.2 +++ b/tools/libxc/Makefile	Wed Mar 21 17:02:59 2007 -0500
     1.3 @@ -48,11 +48,9 @@ GUEST_SRCS-y += $(LIBELF_SRCS)
     1.4  GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c
     1.5  GUEST_SRCS-y += xc_dom_elfloader.c
     1.6  GUEST_SRCS-y += xc_dom_binloader.c
     1.7 -GUEST_SRCS-y += xc_dom_x86.c
     1.8 -GUEST_SRCS-y += xc_dom_ia64.c
     1.9  
    1.10 -GUEST_SRCS-$(CONFIG_X86)     += xc_dom_compat_linux.c
    1.11 -GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_compat_linux.c
    1.12 +GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c xc_dom_compat_linux.c
    1.13 +GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c xc_dom_compat_linux.c
    1.14  
    1.15  -include $(XEN_TARGET_ARCH)/Makefile
    1.16  
     2.1 --- a/tools/libxc/xc_dom.h	Wed Mar 21 17:02:59 2007 -0500
     2.2 +++ b/tools/libxc/xc_dom.h	Wed Mar 21 17:02:59 2007 -0500
     2.3 @@ -253,6 +253,10 @@ static inline xen_pfn_t xc_dom_p2m_guest
     2.4  
     2.5  /* --- arch bits --------------------------------------------------- */
     2.6  
     2.7 +int arch_setup_meminit(struct xc_dom_image *dom);
     2.8 +int arch_setup_bootearly(struct xc_dom_image *dom);
     2.9 +int arch_setup_bootlate(struct xc_dom_image *dom);
    2.10 +
    2.11  /*
    2.12   * Local variables:
    2.13   * mode: C
     3.1 --- a/tools/libxc/xc_dom_boot.c	Wed Mar 21 17:02:59 2007 -0500
     3.2 +++ b/tools/libxc/xc_dom_boot.c	Wed Mar 21 17:02:59 2007 -0500
     3.3 @@ -83,293 +83,6 @@ static int clear_page(struct xc_dom_imag
     3.4      return rc;
     3.5  }
     3.6  
     3.7 -/* ------------------------------------------------------------------------ */
     3.8 -/* arch stuff: x86 bits                                                     */
     3.9 -
    3.10 -#if defined(__i386__) || defined(__x86_64__)
    3.11 -
    3.12 -
    3.13 -static int x86_compat(int xc, domid_t domid, char *guest_type)
    3.14 -{
    3.15 -    static const struct {
    3.16 -        char           *guest;
    3.17 -        uint32_t        size;
    3.18 -    } types[] = {
    3.19 -        { "xen-3.0-x86_32p", 32 },
    3.20 -        { "xen-3.0-x86_64",  64 },
    3.21 -    };
    3.22 -    DECLARE_DOMCTL;
    3.23 -    int i,rc;
    3.24 -
    3.25 -    memset(&domctl, 0, sizeof(domctl));
    3.26 -    domctl.domain = domid;
    3.27 -    domctl.cmd    = XEN_DOMCTL_set_address_size;
    3.28 -    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
    3.29 -        if ( !strcmp(types[i].guest, guest_type) )
    3.30 -            domctl.u.address_size.size = types[i].size;
    3.31 -    if ( domctl.u.address_size.size == 0 )
    3.32 -        /* nothing to do */
    3.33 -        return 0;
    3.34 -
    3.35 -    xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__,
    3.36 -                  guest_type, domctl.u.address_size.size);
    3.37 -    rc = do_domctl(xc, &domctl);
    3.38 -    if ( rc != 0 )
    3.39 -        xc_dom_printf("%s: warning: failed (rc=%d)\n",
    3.40 -                      __FUNCTION__, rc);
    3.41 -    return rc;
    3.42 -}
    3.43 -
    3.44 -
    3.45 -static int x86_shadow(int xc, domid_t domid)
    3.46 -{
    3.47 -    int rc, mode;
    3.48 -
    3.49 -    xc_dom_printf("%s: called\n", __FUNCTION__);
    3.50 -
    3.51 -    mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
    3.52 -        XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE;
    3.53 -
    3.54 -    rc = xc_shadow_control(xc, domid,
    3.55 -                           XEN_DOMCTL_SHADOW_OP_ENABLE,
    3.56 -                           NULL, 0, NULL, mode, NULL);
    3.57 -    if ( rc != 0 )
    3.58 -    {
    3.59 -        xc_dom_panic(XC_INTERNAL_ERROR,
    3.60 -                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n",
    3.61 -                     __FUNCTION__, mode, rc);
    3.62 -        return rc;
    3.63 -    }
    3.64 -    xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode);
    3.65 -    return rc;
    3.66 -}
    3.67 -
    3.68 -static int arch_setup_meminit(struct xc_dom_image *dom)
    3.69 -{
    3.70 -    int rc = 0;
    3.71 -
    3.72 -    x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type);
    3.73 -    if ( xc_dom_feature_translated(dom) )
    3.74 -    {
    3.75 -        dom->shadow_enabled = 1;
    3.76 -        rc = x86_shadow(dom->guest_xc, dom->guest_domid);
    3.77 -    }
    3.78 -    return rc;
    3.79 -}
    3.80 -
    3.81 -static int arch_setup_bootearly(struct xc_dom_image *dom)
    3.82 -{
    3.83 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
    3.84 -    return 0;
    3.85 -}
    3.86 -
    3.87 -static int arch_setup_bootlate(struct xc_dom_image *dom)
    3.88 -{
    3.89 -    static const struct {
    3.90 -        char *guest;
    3.91 -        unsigned long pgd_type;
    3.92 -    } types[] = {
    3.93 -        { "xen-3.0-x86_32",  MMUEXT_PIN_L2_TABLE},
    3.94 -        { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE},
    3.95 -        { "xen-3.0-x86_64",  MMUEXT_PIN_L4_TABLE},
    3.96 -    };
    3.97 -    unsigned long pgd_type = 0;
    3.98 -    shared_info_t *shared_info;
    3.99 -    xen_pfn_t shinfo;
   3.100 -    int i, rc;
   3.101 -
   3.102 -    for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ )
   3.103 -        if ( !strcmp(types[i].guest, dom->guest_type) )
   3.104 -            pgd_type = types[i].pgd_type;
   3.105 -
   3.106 -    if ( !xc_dom_feature_translated(dom) )
   3.107 -    {
   3.108 -        /* paravirtualized guest */
   3.109 -        xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
   3.110 -        rc = pin_table(dom->guest_xc, pgd_type,
   3.111 -                       xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
   3.112 -                       dom->guest_domid);
   3.113 -        if ( rc != 0 )
   3.114 -        {
   3.115 -            xc_dom_panic(XC_INTERNAL_ERROR,
   3.116 -                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n",
   3.117 -                         __FUNCTION__, dom->pgtables_seg.pfn, rc);
   3.118 -            return rc;
   3.119 -        }
   3.120 -        shinfo = dom->shared_info_mfn;
   3.121 -    }
   3.122 -    else
   3.123 -    {
   3.124 -        /* paravirtualized guest with auto-translation */
   3.125 -        struct xen_add_to_physmap xatp;
   3.126 -        int i;
   3.127 -
   3.128 -        /* Map shared info frame into guest physmap. */
   3.129 -        xatp.domid = dom->guest_domid;
   3.130 -        xatp.space = XENMAPSPACE_shared_info;
   3.131 -        xatp.idx = 0;
   3.132 -        xatp.gpfn = dom->shared_info_pfn;
   3.133 -        rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
   3.134 -        if ( rc != 0 )
   3.135 -        {
   3.136 -            xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed "
   3.137 -                         "(pfn=0x%" PRIpfn ", rc=%d)\n",
   3.138 -                         __FUNCTION__, xatp.gpfn, rc);
   3.139 -            return rc;
   3.140 -        }
   3.141 -
   3.142 -        /* Map grant table frames into guest physmap. */
   3.143 -        for ( i = 0; ; i++ )
   3.144 -        {
   3.145 -            xatp.domid = dom->guest_domid;
   3.146 -            xatp.space = XENMAPSPACE_grant_table;
   3.147 -            xatp.idx = i;
   3.148 -            xatp.gpfn = dom->total_pages + i;
   3.149 -            rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
   3.150 -            if ( rc != 0 )
   3.151 -            {
   3.152 -                if ( (i > 0) && (errno == EINVAL) )
   3.153 -                {
   3.154 -                    xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__,
   3.155 -                                  i);
   3.156 -                    break;
   3.157 -                }
   3.158 -                xc_dom_panic(XC_INTERNAL_ERROR,
   3.159 -                             "%s: mapping grant tables failed " "(pfn=0x%"
   3.160 -                             PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc);
   3.161 -                return rc;
   3.162 -            }
   3.163 -        }
   3.164 -        shinfo = dom->shared_info_pfn;
   3.165 -    }
   3.166 -
   3.167 -    /* setup shared_info page */
   3.168 -    xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
   3.169 -                  __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
   3.170 -    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
   3.171 -                                       PAGE_SIZE_X86,
   3.172 -                                       PROT_READ | PROT_WRITE,
   3.173 -                                       shinfo);
   3.174 -    if ( shared_info == NULL )
   3.175 -        return -1;
   3.176 -    dom->arch_hooks->shared_info(dom, shared_info);
   3.177 -    munmap(shared_info, PAGE_SIZE_X86);
   3.178 -
   3.179 -    return 0;
   3.180 -}
   3.181 -
   3.182 -/* ------------------------------------------------------------------------ */
   3.183 -/* arch stuff: ia64                                                         */
   3.184 -
   3.185 -#elif defined(__ia64__)
   3.186 -
   3.187 -static int arch_setup_meminit(struct xc_dom_image *dom)
   3.188 -{
   3.189 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.190 -    return 0;
   3.191 -}
   3.192 -
   3.193 -static int arch_setup_bootearly(struct xc_dom_image *dom)
   3.194 -{
   3.195 -    DECLARE_DOMCTL;
   3.196 -    int rc;
   3.197 -
   3.198 -    xc_dom_printf("%s: setup firmware\n", __FUNCTION__);
   3.199 -
   3.200 -    memset(&domctl, 0, sizeof(domctl));
   3.201 -    domctl.cmd = XEN_DOMCTL_arch_setup;
   3.202 -    domctl.domain = dom->guest_domid;
   3.203 -    domctl.u.arch_setup.flags = 0;
   3.204 -
   3.205 -    domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT)
   3.206 -        + sizeof(start_info_t);
   3.207 -    /* 3 = start info page, xenstore page and console page */
   3.208 -    domctl.u.arch_setup.maxmem = (dom->total_pages - 3) << PAGE_SHIFT;
   3.209 -    rc = do_domctl(dom->guest_xc, &domctl);
   3.210 -    return rc;
   3.211 -}
   3.212 -
   3.213 -static int arch_setup_bootlate(struct xc_dom_image *dom)
   3.214 -{
   3.215 -    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
   3.216 -    shared_info_t *shared_info;
   3.217 -
   3.218 -    /* setup shared_info page */
   3.219 -    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
   3.220 -                  __FUNCTION__, dom->shared_info_mfn);
   3.221 -    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
   3.222 -                                       page_size,
   3.223 -                                       PROT_READ | PROT_WRITE,
   3.224 -                                       dom->shared_info_mfn);
   3.225 -    if ( shared_info == NULL )
   3.226 -        return -1;
   3.227 -    dom->arch_hooks->shared_info(dom, shared_info);
   3.228 -    munmap(shared_info, page_size);
   3.229 -    return 0;
   3.230 -}
   3.231 -
   3.232 -/* ------------------------------------------------------------------------ */
   3.233 -/* arch stuff: powerpc                                                      */
   3.234 -
   3.235 -#elif defined(__powerpc64__)
   3.236 -
   3.237 -static int arch_setup_meminit(struct xc_dom_image *dom)
   3.238 -{
   3.239 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.240 -    return 0;
   3.241 -}
   3.242 -
   3.243 -static int arch_setup_bootearly(struct xc_dom_image *dom)
   3.244 -{
   3.245 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.246 -    return 0;
   3.247 -}
   3.248 -
   3.249 -static int arch_setup_bootlate(struct xc_dom_image *dom)
   3.250 -{
   3.251 -    start_info_t *si =
   3.252 -        xc_dom_pfn_to_ptr(dom, dom->start_info_pfn, 1);
   3.253 -
   3.254 -    xc_dom_printf("%s: TODO: setup devtree\n", __FUNCTION__);
   3.255 -
   3.256 -#if 0
   3.257 -    load_devtree(dom->guest_xc,
   3.258 -                 dom->guest_domid,
   3.259 -                 dom->p2m_host,
   3.260 -                 devtree,           // FIXME
   3.261 -                 devtree_addr,      // FIXME
   3.262 -                 dom->ramdisk_seg.vstart,
   3.263 -                 dom->ramdisk_seg.vend - dom->ramdisk_seg.vstart,
   3.264 -                 si,
   3.265 -                 dom->start_info_pfn << PAGE_SHIFT);
   3.266 -#endif
   3.267 -    return rc;
   3.268 -}
   3.269 -
   3.270 -/* ------------------------------------------------------------------------ */
   3.271 -/* arch stuff: other                                                        */
   3.272 -
   3.273 -#else
   3.274 -
   3.275 -static int arch_setup_meminit(struct xc_dom_image *dom)
   3.276 -{
   3.277 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.278 -    return 0;
   3.279 -}
   3.280 -
   3.281 -static int arch_setup_bootearly(struct xc_dom_image *dom)
   3.282 -{
   3.283 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.284 -    return 0;
   3.285 -}
   3.286 -
   3.287 -static int arch_setup_bootlate(struct xc_dom_image *dom)
   3.288 -{
   3.289 -    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
   3.290 -    return 0;
   3.291 -}
   3.292 -
   3.293 -#endif /* arch stuff */
   3.294  
   3.295  /* ------------------------------------------------------------------------ */
   3.296  
     4.1 --- a/tools/libxc/xc_dom_ia64.c	Wed Mar 21 17:02:59 2007 -0500
     4.2 +++ b/tools/libxc/xc_dom_ia64.c	Wed Mar 21 17:02:59 2007 -0500
     4.3 @@ -128,6 +128,51 @@ static void __init register_arch_hooks(v
     4.4      xc_dom_register_arch_hooks(&xc_dom_arch_ia64be);
     4.5  }
     4.6  
     4.7 +int arch_setup_meminit(struct xc_dom_image *dom)
     4.8 +{
     4.9 +    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
    4.10 +    return 0;
    4.11 +}
    4.12 +
    4.13 +int arch_setup_bootearly(struct xc_dom_image *dom)
    4.14 +{
    4.15 +    DECLARE_DOMCTL;
    4.16 +    int rc;
    4.17 +
    4.18 +    xc_dom_printf("%s: setup firmware\n", __FUNCTION__);
    4.19 +
    4.20 +    memset(&domctl, 0, sizeof(domctl));
    4.21 +    domctl.cmd = XEN_DOMCTL_arch_setup;
    4.22 +    domctl.domain = dom->guest_domid;
    4.23 +    domctl.u.arch_setup.flags = 0;
    4.24 +
    4.25 +    domctl.u.arch_setup.bp = (dom->start_info_pfn << PAGE_SHIFT)
    4.26 +        + sizeof(start_info_t);
    4.27 +    /* 3 = start info page, xenstore page and console page */
    4.28 +    domctl.u.arch_setup.maxmem = (dom->total_pages - 3) << PAGE_SHIFT;
    4.29 +    rc = do_domctl(dom->guest_xc, &domctl);
    4.30 +    return rc;
    4.31 +}
    4.32 +
    4.33 +int arch_setup_bootlate(struct xc_dom_image *dom)
    4.34 +{
    4.35 +    unsigned int page_size = XC_DOM_PAGE_SIZE(dom);
    4.36 +    shared_info_t *shared_info;
    4.37 +
    4.38 +    /* setup shared_info page */
    4.39 +    xc_dom_printf("%s: shared_info: mfn 0x%" PRIpfn "\n",
    4.40 +                  __FUNCTION__, dom->shared_info_mfn);
    4.41 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
    4.42 +                                       page_size,
    4.43 +                                       PROT_READ | PROT_WRITE,
    4.44 +                                       dom->shared_info_mfn);
    4.45 +    if ( shared_info == NULL )
    4.46 +        return -1;
    4.47 +    dom->arch_hooks->shared_info(dom, shared_info);
    4.48 +    munmap(shared_info, page_size);
    4.49 +    return 0;
    4.50 +}
    4.51 +
    4.52  /*
    4.53   * Local variables:
    4.54   * mode: C
     5.1 --- a/tools/libxc/xc_dom_x86.c	Wed Mar 21 17:02:59 2007 -0500
     5.2 +++ b/tools/libxc/xc_dom_x86.c	Wed Mar 21 17:02:59 2007 -0500
     5.3 @@ -569,6 +569,175 @@ static void __init register_arch_hooks(v
     5.4      xc_dom_register_arch_hooks(&xc_dom_64);
     5.5  }
     5.6  
     5.7 +static int x86_compat(int xc, domid_t domid, char *guest_type)
     5.8 +{
     5.9 +    static const struct {
    5.10 +        char           *guest;
    5.11 +        uint32_t        size;
    5.12 +    } types[] = {
    5.13 +        { "xen-3.0-x86_32p", 32 },
    5.14 +        { "xen-3.0-x86_64",  64 },
    5.15 +    };
    5.16 +    DECLARE_DOMCTL;
    5.17 +    int i,rc;
    5.18 +
    5.19 +    memset(&domctl, 0, sizeof(domctl));
    5.20 +    domctl.domain = domid;
    5.21 +    domctl.cmd    = XEN_DOMCTL_set_address_size;
    5.22 +    for ( i = 0; i < sizeof(types)/sizeof(types[0]); i++ )
    5.23 +        if ( !strcmp(types[i].guest, guest_type) )
    5.24 +            domctl.u.address_size.size = types[i].size;
    5.25 +    if ( domctl.u.address_size.size == 0 )
    5.26 +        /* nothing to do */
    5.27 +        return 0;
    5.28 +
    5.29 +    xc_dom_printf("%s: guest %s, address size %" PRId32 "\n", __FUNCTION__,
    5.30 +                  guest_type, domctl.u.address_size.size);
    5.31 +    rc = do_domctl(xc, &domctl);
    5.32 +    if ( rc != 0 )
    5.33 +        xc_dom_printf("%s: warning: failed (rc=%d)\n",
    5.34 +                      __FUNCTION__, rc);
    5.35 +    return rc;
    5.36 +}
    5.37 +
    5.38 +
    5.39 +static int x86_shadow(int xc, domid_t domid)
    5.40 +{
    5.41 +    int rc, mode;
    5.42 +
    5.43 +    xc_dom_printf("%s: called\n", __FUNCTION__);
    5.44 +
    5.45 +    mode = XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT |
    5.46 +        XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE;
    5.47 +
    5.48 +    rc = xc_shadow_control(xc, domid,
    5.49 +                           XEN_DOMCTL_SHADOW_OP_ENABLE,
    5.50 +                           NULL, 0, NULL, mode, NULL);
    5.51 +    if ( rc != 0 )
    5.52 +    {
    5.53 +        xc_dom_panic(XC_INTERNAL_ERROR,
    5.54 +                     "%s: SHADOW_OP_ENABLE (mode=0x%x) failed (rc=%d)\n",
    5.55 +                     __FUNCTION__, mode, rc);
    5.56 +        return rc;
    5.57 +    }
    5.58 +    xc_dom_printf("%s: shadow enabled (mode=0x%x)\n", __FUNCTION__, mode);
    5.59 +    return rc;
    5.60 +}
    5.61 +
    5.62 +int arch_setup_meminit(struct xc_dom_image *dom)
    5.63 +{
    5.64 +    int rc = 0;
    5.65 +
    5.66 +    x86_compat(dom->guest_xc, dom->guest_domid, dom->guest_type);
    5.67 +    if ( xc_dom_feature_translated(dom) )
    5.68 +    {
    5.69 +        dom->shadow_enabled = 1;
    5.70 +        rc = x86_shadow(dom->guest_xc, dom->guest_domid);
    5.71 +    }
    5.72 +    return rc;
    5.73 +}
    5.74 +
    5.75 +int arch_setup_bootearly(struct xc_dom_image *dom)
    5.76 +{
    5.77 +    xc_dom_printf("%s: doing nothing\n", __FUNCTION__);
    5.78 +    return 0;
    5.79 +}
    5.80 +
    5.81 +int arch_setup_bootlate(struct xc_dom_image *dom)
    5.82 +{
    5.83 +    static const struct {
    5.84 +        char *guest;
    5.85 +        unsigned long pgd_type;
    5.86 +    } types[] = {
    5.87 +        { "xen-3.0-x86_32",  MMUEXT_PIN_L2_TABLE},
    5.88 +        { "xen-3.0-x86_32p", MMUEXT_PIN_L3_TABLE},
    5.89 +        { "xen-3.0-x86_64",  MMUEXT_PIN_L4_TABLE},
    5.90 +    };
    5.91 +    unsigned long pgd_type = 0;
    5.92 +    shared_info_t *shared_info;
    5.93 +    xen_pfn_t shinfo;
    5.94 +    int i, rc;
    5.95 +
    5.96 +    for ( i = 0; i < sizeof(types) / sizeof(types[0]); i++ )
    5.97 +        if ( !strcmp(types[i].guest, dom->guest_type) )
    5.98 +            pgd_type = types[i].pgd_type;
    5.99 +
   5.100 +    if ( !xc_dom_feature_translated(dom) )
   5.101 +    {
   5.102 +        /* paravirtualized guest */
   5.103 +        xc_dom_unmap_one(dom, dom->pgtables_seg.pfn);
   5.104 +        rc = pin_table(dom->guest_xc, pgd_type,
   5.105 +                       xc_dom_p2m_host(dom, dom->pgtables_seg.pfn),
   5.106 +                       dom->guest_domid);
   5.107 +        if ( rc != 0 )
   5.108 +        {
   5.109 +            xc_dom_panic(XC_INTERNAL_ERROR,
   5.110 +                         "%s: pin_table failed (pfn 0x%" PRIpfn ", rc=%d)\n",
   5.111 +                         __FUNCTION__, dom->pgtables_seg.pfn, rc);
   5.112 +            return rc;
   5.113 +        }
   5.114 +        shinfo = dom->shared_info_mfn;
   5.115 +    }
   5.116 +    else
   5.117 +    {
   5.118 +        /* paravirtualized guest with auto-translation */
   5.119 +        struct xen_add_to_physmap xatp;
   5.120 +        int i;
   5.121 +
   5.122 +        /* Map shared info frame into guest physmap. */
   5.123 +        xatp.domid = dom->guest_domid;
   5.124 +        xatp.space = XENMAPSPACE_shared_info;
   5.125 +        xatp.idx = 0;
   5.126 +        xatp.gpfn = dom->shared_info_pfn;
   5.127 +        rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
   5.128 +        if ( rc != 0 )
   5.129 +        {
   5.130 +            xc_dom_panic(XC_INTERNAL_ERROR, "%s: mapping shared_info failed "
   5.131 +                         "(pfn=0x%" PRIpfn ", rc=%d)\n",
   5.132 +                         __FUNCTION__, xatp.gpfn, rc);
   5.133 +            return rc;
   5.134 +        }
   5.135 +
   5.136 +        /* Map grant table frames into guest physmap. */
   5.137 +        for ( i = 0; ; i++ )
   5.138 +        {
   5.139 +            xatp.domid = dom->guest_domid;
   5.140 +            xatp.space = XENMAPSPACE_grant_table;
   5.141 +            xatp.idx = i;
   5.142 +            xatp.gpfn = dom->total_pages + i;
   5.143 +            rc = xc_memory_op(dom->guest_xc, XENMEM_add_to_physmap, &xatp);
   5.144 +            if ( rc != 0 )
   5.145 +            {
   5.146 +                if ( (i > 0) && (errno == EINVAL) )
   5.147 +                {
   5.148 +                    xc_dom_printf("%s: %d grant tables mapped\n", __FUNCTION__,
   5.149 +                                  i);
   5.150 +                    break;
   5.151 +                }
   5.152 +                xc_dom_panic(XC_INTERNAL_ERROR,
   5.153 +                             "%s: mapping grant tables failed " "(pfn=0x%"
   5.154 +                             PRIpfn ", rc=%d)\n", __FUNCTION__, xatp.gpfn, rc);
   5.155 +                return rc;
   5.156 +            }
   5.157 +        }
   5.158 +        shinfo = dom->shared_info_pfn;
   5.159 +    }
   5.160 +
   5.161 +    /* setup shared_info page */
   5.162 +    xc_dom_printf("%s: shared_info: pfn 0x%" PRIpfn ", mfn 0x%" PRIpfn "\n",
   5.163 +                  __FUNCTION__, dom->shared_info_pfn, dom->shared_info_mfn);
   5.164 +    shared_info = xc_map_foreign_range(dom->guest_xc, dom->guest_domid,
   5.165 +                                       PAGE_SIZE_X86,
   5.166 +                                       PROT_READ | PROT_WRITE,
   5.167 +                                       shinfo);
   5.168 +    if ( shared_info == NULL )
   5.169 +        return -1;
   5.170 +    dom->arch_hooks->shared_info(dom, shared_info);
   5.171 +    munmap(shared_info, PAGE_SIZE_X86);
   5.172 +
   5.173 +    return 0;
   5.174 +}
   5.175 +
   5.176  /*
   5.177   * Local variables:
   5.178   * mode: C