1 /******************************************************************************
2 * xc_foreign_memory.c
3 *
4 * Functions for mapping foreign domain's memory.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation;
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #define XC_BUILDING_COMPAT_MAP_FOREIGN_API
21 #include "xc_private.h"
22
xc_map_foreign_pages(xc_interface * xch,uint32_t dom,int prot,const xen_pfn_t * arr,int num)23 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
24 const xen_pfn_t *arr, int num)
25 {
26 if (num < 0) {
27 errno = EINVAL;
28 return NULL;
29 }
30
31 return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, NULL);
32 }
33
xc_map_foreign_range(xc_interface * xch,uint32_t dom,int size,int prot,unsigned long mfn)34 void *xc_map_foreign_range(xc_interface *xch,
35 uint32_t dom, int size, int prot,
36 unsigned long mfn)
37 {
38 xen_pfn_t *arr;
39 int num;
40 int i;
41 void *ret;
42
43 num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
44 arr = calloc(num, sizeof(xen_pfn_t));
45 if ( arr == NULL )
46 return NULL;
47
48 for ( i = 0; i < num; i++ )
49 arr[i] = mfn + i;
50
51 ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
52 free(arr);
53 return ret;
54 }
55
xc_map_foreign_ranges(xc_interface * xch,uint32_t dom,size_t size,int prot,size_t chunksize,privcmd_mmap_entry_t entries[],int nentries)56 void *xc_map_foreign_ranges(xc_interface *xch,
57 uint32_t dom, size_t size,
58 int prot, size_t chunksize,
59 privcmd_mmap_entry_t entries[],
60 int nentries)
61 {
62 xen_pfn_t *arr;
63 int num_per_entry;
64 int num;
65 int i;
66 int j;
67 void *ret;
68
69 num_per_entry = chunksize >> XC_PAGE_SHIFT;
70 num = num_per_entry * nentries;
71 arr = calloc(num, sizeof(xen_pfn_t));
72 if ( arr == NULL )
73 return NULL;
74
75 for ( i = 0; i < nentries; i++ )
76 for ( j = 0; j < num_per_entry; j++ )
77 arr[i * num_per_entry + j] = entries[i].mfn + j;
78
79 ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
80 free(arr);
81 return ret;
82 }
83
xc_map_foreign_bulk(xc_interface * xch,uint32_t dom,int prot,const xen_pfn_t * arr,int * err,unsigned int num)84 void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
85 const xen_pfn_t *arr, int *err, unsigned int num)
86 {
87 return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, err);
88 }
89
90 /*
91 * Local variables:
92 * mode: C
93 * c-file-style: "BSD"
94 * c-basic-offset: 4
95 * tab-width: 4
96 * indent-tabs-mode: nil
97 * End:
98 */
99