source: trunk/packages/xen-3.1/xen-3.1/tools/libxc/xc_core_x86.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 3.5 KB
Line 
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 *
16 * Copyright (c) 2007 Isaku Yamahata <yamahata at valinux co jp>
17 *                    VA Linux Systems Japan K.K.
18 *
19 */
20
21#include "xg_private.h"
22#include "xc_core.h"
23
24static int nr_gpfns(int xc_handle, domid_t domid)
25{
26    return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid) + 1;
27}
28
29int
30xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
31{
32    return info->hvm;
33}
34
35int
36xc_core_arch_memory_map_get(int xc_handle, xc_dominfo_t *info,
37                            shared_info_t *live_shinfo,
38                            xc_core_memory_map_t **mapp,
39                            unsigned int *nr_entries)
40{
41    unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
42    xc_core_memory_map_t *map;
43
44    map = malloc(sizeof(*map));
45    if ( map == NULL )
46    {
47        PERROR("Could not allocate memory");
48        return -1;
49    }
50
51    map->addr = 0;
52    map->size = p2m_size << PAGE_SHIFT;
53
54    *mapp = map;
55    *nr_entries = 1;
56    return 0;
57}
58
59int
60xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,
61                     shared_info_t *live_shinfo, xen_pfn_t **live_p2m,
62                     unsigned long *pfnp)
63{
64    /* Double and single indirect references to the live P2M table */
65    xen_pfn_t *live_p2m_frame_list_list = NULL;
66    xen_pfn_t *live_p2m_frame_list = NULL;
67    uint32_t dom = info->domid;
68    unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
69    int ret = -1;
70    int err;
71
72    if ( p2m_size < info->nr_pages  )
73    {
74        ERROR("p2m_size < nr_pages -1 (%lx < %lx", p2m_size, info->nr_pages - 1);
75        goto out;
76    }
77
78    live_p2m_frame_list_list =
79        xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
80                             live_shinfo->arch.pfn_to_mfn_frame_list_list);
81
82    if ( !live_p2m_frame_list_list )
83    {
84        PERROR("Couldn't map p2m_frame_list_list (errno %d)", errno);
85        goto out;
86    }
87
88    live_p2m_frame_list =
89        xc_map_foreign_batch(xc_handle, dom, PROT_READ,
90                             live_p2m_frame_list_list,
91                             P2M_FLL_ENTRIES);
92
93    if ( !live_p2m_frame_list )
94    {
95        PERROR("Couldn't map p2m_frame_list");
96        goto out;
97    }
98
99    *live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_READ,
100                                    live_p2m_frame_list,
101                                    P2M_FL_ENTRIES);
102
103    if ( !*live_p2m )
104    {
105        PERROR("Couldn't map p2m table");
106        goto out;
107    }
108
109    *pfnp = p2m_size;
110
111    ret = 0;
112
113out:
114    err = errno;
115
116    if ( live_p2m_frame_list_list )
117        munmap(live_p2m_frame_list_list, PAGE_SIZE);
118
119    if ( live_p2m_frame_list )
120        munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
121
122    errno = err;
123    return ret;
124}
125
126/*
127 * Local variables:
128 * mode: C
129 * c-set-style: "BSD"
130 * c-basic-offset: 4
131 * tab-width: 4
132 * indent-tabs-mode: nil
133 * End:
134 */
Note: See TracBrowser for help on using the repository browser.