ia64/xen-unstable

changeset 15843:3cde7ffdfd0f

[IA64] Foreign p2m: libxc side

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Thu Sep 06 14:37:50 2007 -0600 (2007-09-06)
parents d956779d8d47
children 005652f8e4e4
files tools/libxc/ia64/xc_ia64.h tools/libxc/ia64/xc_ia64_stubs.c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/libxc/ia64/xc_ia64.h	Thu Sep 06 14:37:50 2007 -0600
     1.3 @@ -0,0 +1,53 @@
     1.4 +/*
     1.5 + * This program is free software; you can redistribute it and/or modify
     1.6 + * it under the terms of the GNU General Public License as published by
     1.7 + * the Free Software Foundation; either version 2 of the License, or
     1.8 + * (at your option) any later version.
     1.9 + *
    1.10 + * This program is distributed in the hope that it will be useful,
    1.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.13 + * GNU General Public License for more details.
    1.14 + *
    1.15 + * You should have received a copy of the GNU General Public License
    1.16 + * along with this program; if not, write to the Free Software
    1.17 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.18 + *
    1.19 + * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
    1.20 + *                    VA Linux Systems Japan K.K.
    1.21 + *
    1.22 + */
    1.23 +
    1.24 +#ifndef _XC_IA64_H_
    1.25 +#define _XC_IA64_H_
    1.26 +
    1.27 +struct xen_ia64_p2m_table {
    1.28 +    unsigned long size;
    1.29 +    unsigned long *p2m;
    1.30 +};
    1.31 +
    1.32 +void xc_ia64_p2m_init(struct xen_ia64_p2m_table *p2m_table);
    1.33 +int xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
    1.34 +                    uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
    1.35 +                    unsigned long flag);
    1.36 +void xc_ia64_p2m_unmap(struct xen_ia64_p2m_table *p2m_table);
    1.37 +int xc_ia64_p2m_present(struct xen_ia64_p2m_table *p2m_table,
    1.38 +                        unsigned long gpfn);
    1.39 +int xc_ia64_p2m_allocated(struct xen_ia64_p2m_table *p2m_table,
    1.40 +                          unsigned long gpfn);
    1.41 +
    1.42 +unsigned long xc_ia64_p2m_mfn(struct xen_ia64_p2m_table *p2m_table,
    1.43 +                              unsigned long gpfn);
    1.44 +
    1.45 +
    1.46 +#endif /* _XC_IA64_H_ */
    1.47 +
    1.48 +/*
    1.49 + * Local variables:
    1.50 + * mode: C
    1.51 + * c-set-style: "BSD"
    1.52 + * c-basic-offset: 4
    1.53 + * tab-width: 4
    1.54 + * indent-tabs-mode: nil
    1.55 + * End:
    1.56 + */
     2.1 --- a/tools/libxc/ia64/xc_ia64_stubs.c	Thu Sep 06 14:13:38 2007 -0600
     2.2 +++ b/tools/libxc/ia64/xc_ia64_stubs.c	Thu Sep 06 14:37:50 2007 -0600
     2.3 @@ -1,11 +1,5 @@
     2.4  #include "xg_private.h"
     2.5 -#include "xenguest.h"
     2.6 -#include "xc_private.h"
     2.7 -#include "xc_elf.h"
     2.8 -#include <stdlib.h>
     2.9 -#include <zlib.h>
    2.10 -#include "xen/arch-ia64.h"
    2.11 -#include <xen/hvm/ioreq.h>
    2.12 +#include "xc_ia64.h"
    2.13  
    2.14  /* this is a very ugly way of getting FPSR_DEFAULT.  struct ia64_fpreg is
    2.15   * mysteriously declared in two places: /usr/include/asm/fpu.h and
    2.16 @@ -66,6 +60,136 @@ xc_get_max_pages(int xc_handle, uint32_t
    2.17  }
    2.18  
    2.19  /*
    2.20 + * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
    2.21 + * Should PTRS_PER_PTE be exported by arch-ia64.h?
    2.22 + */
    2.23 +#define PTRS_PER_PTE    (1UL << (PAGE_SHIFT - 3))
    2.24 +
    2.25 +static void*
    2.26 +xc_ia64_map_foreign_p2m(int xc_handle, uint32_t dom,
    2.27 +                        struct xen_ia64_memmap_info *memmap_info,
    2.28 +                        unsigned long flags, unsigned long *p2m_size_p)
    2.29 +{
    2.30 +    unsigned long gpfn_max;
    2.31 +    unsigned long p2m_size;
    2.32 +    void *addr;
    2.33 +    privcmd_hypercall_t hypercall;
    2.34 +    int ret;
    2.35 +    int saved_errno;
    2.36 +
    2.37 +    gpfn_max = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom);
    2.38 +    if (gpfn_max < 0)
    2.39 +        return NULL;
    2.40 +    p2m_size =
    2.41 +        (((gpfn_max + 1) + PTRS_PER_PTE - 1) / PTRS_PER_PTE) << PAGE_SHIFT;
    2.42 +    addr = mmap(NULL, p2m_size, PROT_READ, MAP_SHARED, xc_handle, 0);
    2.43 +    if (addr == MAP_FAILED)
    2.44 +        return NULL;
    2.45 +
    2.46 +    hypercall.op = __HYPERVISOR_ia64_dom0vp_op;
    2.47 +    hypercall.arg[0] = IA64_DOM0VP_expose_foreign_p2m;
    2.48 +    hypercall.arg[1] = (unsigned long)addr;
    2.49 +    hypercall.arg[2] = dom;
    2.50 +    hypercall.arg[3] = (unsigned long)memmap_info;
    2.51 +    hypercall.arg[4] = flags;
    2.52 +    hypercall.arg[5] = 0;
    2.53 +
    2.54 +    if (lock_pages(memmap_info,
    2.55 +                   sizeof(*memmap_info) + memmap_info->efi_memmap_size) != 0) {
    2.56 +        saved_errno = errno;
    2.57 +        munmap(addr, p2m_size);
    2.58 +        errno = saved_errno;
    2.59 +        return NULL;
    2.60 +    }
    2.61 +    ret = do_xen_hypercall(xc_handle, &hypercall);
    2.62 +    saved_errno = errno;
    2.63 +    unlock_pages(memmap_info,
    2.64 +                 sizeof(*memmap_info) + memmap_info->efi_memmap_size);
    2.65 +    if (ret < 0) {
    2.66 +        munmap(addr, p2m_size);
    2.67 +        errno = saved_errno;
    2.68 +        return NULL;
    2.69 +    }
    2.70 +
    2.71 +    *p2m_size_p = p2m_size;
    2.72 +    return addr;
    2.73 +}
    2.74 +
    2.75 +void
    2.76 +xc_ia64_p2m_init(struct xen_ia64_p2m_table *p2m_table)
    2.77 +{
    2.78 +    p2m_table->size = 0;
    2.79 +    p2m_table->p2m = NULL;
    2.80 +}
    2.81 +
    2.82 +int
    2.83 +xc_ia64_p2m_map(struct xen_ia64_p2m_table *p2m_table, int xc_handle,
    2.84 +                uint32_t domid, struct xen_ia64_memmap_info *memmap_info,
    2.85 +                unsigned long flag)
    2.86 +{
    2.87 +    p2m_table->p2m = xc_ia64_map_foreign_p2m(xc_handle, domid, memmap_info,
    2.88 +                                             flag, &p2m_table->size);
    2.89 +    if (p2m_table->p2m == NULL) {
    2.90 +        PERROR("Could not map foreign p2m. falling back to old method");
    2.91 +        return -1;
    2.92 +    }
    2.93 +    return 0;
    2.94 +}
    2.95 +
    2.96 +void
    2.97 +xc_ia64_p2m_unmap(struct xen_ia64_p2m_table *p2m_table)
    2.98 +{
    2.99 +    if (p2m_table->p2m == NULL)
   2.100 +        return;
   2.101 +    munmap(p2m_table->p2m, p2m_table->size);
   2.102 +    //p2m_table->p2m = NULL;
   2.103 +    //p2m_table->size = 0;
   2.104 +}
   2.105 +
   2.106 +/*
   2.107 + * XXX from xen/include/asm-ia64/linux-xen/asm/pgtable.h
   2.108 + * Should those be exported by arch-ia64.h?
   2.109 + */
   2.110 +#define _PAGE_P_BIT             0
   2.111 +#define _PAGE_P                 (1UL << _PAGE_P_BIT)      /* page present bit */
   2.112 +#define _PAGE_PGC_ALLOCATED_BIT 59      /* _PGC_allocated */
   2.113 +#define _PAGE_PGC_ALLOCATED     (1UL << _PAGE_PGC_ALLOCATED_BIT)
   2.114 +
   2.115 +#define IA64_MAX_PHYS_BITS      50      /* max. number of physical address bits (architected) */
   2.116 +#define _PAGE_PPN_MASK  (((1UL << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL)
   2.117 +
   2.118 +int
   2.119 +xc_ia64_p2m_present(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
   2.120 +{
   2.121 +    if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size)
   2.122 +        return !!(p2m_table->p2m[gpfn] & _PAGE_P);
   2.123 +    return 0;
   2.124 +}
   2.125 +
   2.126 +int
   2.127 +xc_ia64_p2m_allocated(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
   2.128 +{
   2.129 +    if (sizeof(p2m_table->p2m[0]) * gpfn < p2m_table->size) {
   2.130 +        unsigned long pte = p2m_table->p2m[gpfn];
   2.131 +        return !!((pte & _PAGE_P) && (pte & _PAGE_PGC_ALLOCATED));
   2.132 +    }
   2.133 +    return 0;
   2.134 +}
   2.135 +
   2.136 +unsigned long
   2.137 +xc_ia64_p2m_mfn(struct xen_ia64_p2m_table *p2m_table, unsigned long gpfn)
   2.138 +{
   2.139 +    unsigned long pte;
   2.140 +    
   2.141 +    if (sizeof(p2m_table->p2m[0]) * gpfn >= p2m_table->size)
   2.142 +        return INVALID_MFN;
   2.143 +    pte = p2m_table->p2m[gpfn];
   2.144 +    if (!(pte & _PAGE_P))
   2.145 +        return INVALID_MFN;
   2.146 +    return (pte & _PAGE_PPN_MASK) >> PAGE_SHIFT;
   2.147 +}
   2.148 +
   2.149 +/*
   2.150   * Local variables:
   2.151   * mode: C
   2.152   * c-set-style: "BSD"