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 "xg_private.h"
20 #include "xc_core.h"
21 
22 #include <xen-tools/libs.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_auto_translated_physmap(const xc_dominfo_t * info)35 xc_core_arch_auto_translated_physmap(const xc_dominfo_t *info)
36 {
37     return 1;
38 }
39 
40 int
xc_core_arch_memory_map_get(xc_interface * xch,struct xc_core_arch_context * unused,xc_dominfo_t * info,shared_info_any_t * live_shinfo,xc_core_memory_map_t ** mapp,unsigned int * nr_entries)41 xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context *unused,
42                             xc_dominfo_t *info, shared_info_any_t *live_shinfo,
43                             xc_core_memory_map_t **mapp,
44                             unsigned int *nr_entries)
45 {
46     xen_pfn_t p2m_size = 0;
47     xc_core_memory_map_t *map;
48 
49     if ( xc_domain_nr_gpfns(xch, info->domid, &p2m_size) < 0 )
50         return -1;
51 
52     map = malloc(sizeof(*map));
53     if ( map == NULL )
54     {
55         PERROR("Could not allocate memory");
56         return -1;
57     }
58 
59     map->addr = 0;
60     map->size = ((uint64_t)p2m_size) << PAGE_SHIFT;
61 
62     *mapp = map;
63     *nr_entries = 1;
64     return 0;
65 }
66 
67 static int
xc_core_arch_map_p2m_rw(xc_interface * xch,struct domain_info_context * dinfo,xc_dominfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m,unsigned long * pfnp,int rw)68 xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *dinfo, xc_dominfo_t *info,
69                         shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
70                         unsigned long *pfnp, int rw)
71 {
72     errno = ENOSYS;
73     return -1;
74 }
75 
76 int
xc_core_arch_map_p2m(xc_interface * xch,unsigned int guest_width,xc_dominfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m,unsigned long * pfnp)77 xc_core_arch_map_p2m(xc_interface *xch, unsigned int guest_width, xc_dominfo_t *info,
78                         shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
79                         unsigned long *pfnp)
80 {
81     struct domain_info_context _dinfo = { .guest_width = guest_width };
82     struct domain_info_context *dinfo = &_dinfo;
83     return xc_core_arch_map_p2m_rw(xch, dinfo, info,
84                                    live_shinfo, live_p2m, pfnp, 0);
85 }
86 
87 int
xc_core_arch_map_p2m_writable(xc_interface * xch,unsigned int guest_width,xc_dominfo_t * info,shared_info_any_t * live_shinfo,xen_pfn_t ** live_p2m,unsigned long * pfnp)88 xc_core_arch_map_p2m_writable(xc_interface *xch, unsigned int guest_width, xc_dominfo_t *info,
89                               shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,
90                               unsigned long *pfnp)
91 {
92     struct domain_info_context _dinfo = { .guest_width = guest_width };
93     struct domain_info_context *dinfo = &_dinfo;
94     return xc_core_arch_map_p2m_rw(xch, dinfo, info,
95                                    live_shinfo, live_p2m, pfnp, 1);
96 }
97 
98 int
xc_core_arch_get_scratch_gpfn(xc_interface * xch,uint32_t domid,xen_pfn_t * gpfn)99 xc_core_arch_get_scratch_gpfn(xc_interface *xch, uint32_t domid,
100                               xen_pfn_t *gpfn)
101 {
102     /*
103      * The Grant Table region space is not used until the guest is
104      * booting. Use the first page for the scratch pfn.
105      */
106     BUILD_BUG_ON(GUEST_GNTTAB_SIZE < XC_PAGE_SIZE);
107 
108     *gpfn = GUEST_GNTTAB_BASE >> XC_PAGE_SHIFT;
109 
110     return 0;
111 }
112 
113 
114 /*
115  * Local variables:
116  * mode: C
117  * c-file-style: "BSD"
118  * c-basic-offset: 4
119  * tab-width: 4
120  * indent-tabs-mode: nil
121  * End:
122  */
123