1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library 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 GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
14 *
15 * Copyright (c) 2011 Citrix Systems
16 *
17 */
18
19 #include "xc_private.h"
20 #include "xg_core.h"
21
22 #include <xen-tools/common-macros.h>
23
24 int
xc_core_arch_gpfn_may_present(struct xc_core_arch_context * arch_ctxt,unsigned long pfn)25 xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
26 unsigned long pfn)
27 {
28 /* TODO: memory from DT */
29 if (pfn >= 0x80000 && pfn < 0x88000)
30 return 1;
31 return 0;
32 }
33
34 int
xc_core_arch_memory_map_get(xc_interface * xch,struct xc_core_arch_context * unused,xc_domaininfo_t * info,shared_info_any_t * live_shinfo,xc_core_memory_map_t ** mapp,unsigned int * nr_entries)35 xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context *unused,
36 xc_domaininfo_t *info, shared_info_any_t *live_shinfo,
37 xc_core_memory_map_t **mapp,
38 unsigned int *nr_entries)
39 {
40 xen_pfn_t p2m_size = 0;
41 xc_core_memory_map_t *map;
42
43 if ( xc_domain_nr_gpfns(xch, info->domain, &p2m_size) < 0 )
44 return -1;
45
46 map = malloc(sizeof(*map));
47 if ( map == NULL )
48 {
49 PERROR("Could not allocate memory");
50 return -1;
51 }
52
53 map->addr = 0;
54 map->size = ((uint64_t)p2m_size) << PAGE_SHIFT;
55
56 *mapp = map;
57 *nr_entries = 1;
58 return 0;
59 }
60
61 static int
xc_core_arch_map_p2m_rw(xc_interface * xch,struct domain_info_context * dinfo,xc_domaininfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m,int rw)62 xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, xc_domaininfo_t *info,
63 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m, int rw)
64 {
65 errno = ENOSYS;
66 return -1;
67 }
68
69 int
xc_core_arch_map_p2m(xc_interface * xch,struct domain_info_context * dinfo,xc_domaininfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m)70 xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *dinfo, xc_domaininfo_t *info,
71 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m)
72 {
73 return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m, 0);
74 }
75
76 int
xc_core_arch_map_p2m_writable(xc_interface * xch,struct domain_info_context * dinfo,xc_domaininfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m)77 xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_context *dinfo, xc_domaininfo_t *info,
78 shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m)
79 {
80 return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m, 1);
81 }
82
83 int
xc_core_arch_get_scratch_gpfn(xc_interface * xch,uint32_t domid,xen_pfn_t * gpfn)84 xc_core_arch_get_scratch_gpfn(xc_interface *xch, uint32_t domid,
85 xen_pfn_t *gpfn)
86 {
87 /*
88 * The Grant Table region space is not used until the guest is
89 * booting. Use the first page for the scratch pfn.
90 */
91 BUILD_BUG_ON(GUEST_GNTTAB_SIZE < XC_PAGE_SIZE);
92
93 *gpfn = GUEST_GNTTAB_BASE >> XC_PAGE_SHIFT;
94
95 return 0;
96 }
97
98
99 /*
100 * Local variables:
101 * mode: C
102 * c-file-style: "BSD"
103 * c-basic-offset: 4
104 * tab-width: 4
105 * indent-tabs-mode: nil
106 * End:
107 */
108