Skip to content

Commit ababfff

Browse files
committed
add vfbdev and long page granting
1 parent ceac389 commit ababfff

23 files changed

Lines changed: 533 additions & 113 deletions

File tree

so3/arch/arm64/domain.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ void __setup_dom_pgtable(struct domain *d, addr_t paddr_start, unsigned long map
131131
d->grant_pfn[i].pfn = phys_to_pfn(memslot[slotID].ipa_addr + map_size + 2 * PAGE_SIZE) + i;
132132
d->grant_pfn[i].free = true;
133133
}
134+
135+
/* Initialize the long grant pfn area. As page count for them is unknown, they will all be mapped
136+
* contiguously from a starting point, which is behind the last normal grant pfn.
137+
*/
138+
for (i = 0; i < NR_LONG_GRANT_PFN; i++) {
139+
d->long_grant_pfn[i].pfn = 0;
140+
d->long_grant_pfn[i].page_count = 0;
141+
d->long_grant_pfn[i].free = true;
142+
}
143+
d->long_grant_start_pfn = phys_to_pfn(memslot[slotID].ipa_addr + map_size + 2 * PAGE_SIZE) + NR_GRANT_PFN;
134144
#endif /* CONFIG_SOO */
135145
}
136146

so3/arch/arm64/virt64/include/mach/ipamap.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ ipamap_t agency_ipamap[] = {
2727
.phys_addr = 0x08000000,
2828
.size = 0x3000000,
2929
},
30+
{
31+
/* PCIe mapping */
32+
.ipa_addr = 0x4010000000,
33+
.phys_addr = 0x4010000000,
34+
.size = 0x10000000
35+
},
36+
{
37+
/* PCIe mapping */
38+
.ipa_addr = 0x10000000,
39+
.phys_addr = 0x10000000,
40+
.size = 0x40000000
41+
},
42+
{
43+
/* PCIe mapping */
44+
.ipa_addr = 0x8000000000,
45+
.phys_addr = 0x8000000000,
46+
.size = 0x8000000000
47+
},
3048
};
3149

3250
/**

so3/avz/include/avz/domain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@
5454
#include <list.h>
5555

5656
#define NR_GRANT_PFN 32
57+
#define NR_LONG_GRANT_PFN 8
5758

5859
typedef struct {
5960
addr_t pfn;
61+
size_t page_count;
6062
bool free;
6163
} grant_pfn_t;
6264

@@ -117,6 +119,10 @@ struct domain {
117119

118120
/* IPA reserved page frame numbers for mapping granted pages belonging to other domains */
119121
grant_pfn_t grant_pfn[NR_GRANT_PFN];
122+
123+
/* IPA reserved information for long mapping granted pages belonging to other domains */
124+
grant_pfn_t long_grant_pfn[NR_LONG_GRANT_PFN];
125+
addr_t long_grant_start_pfn;
120126
#endif /* CONFIG_SOO */
121127

122128
int processor;

so3/avz/include/avz/gnttab.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ struct gnttab {
3232
/* (Real) physical frame number to be granted */
3333
addr_t pfn;
3434

35+
/* Page count to be granted, if set to 0 then normal granting is used
36+
* mapping one page.
37+
*/
38+
size_t page_count;
39+
3540
/* Unique ref ID used by the domain which refers to this page */
3641
grant_ref_t ref;
3742
};

so3/avz/include/avz/injector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ struct dom_context {
5555
/* IPA reserved page frame numbers for granted pages */
5656
grant_pfn_t grant_pfn[NR_GRANT_PFN];
5757

58+
/* IPA reserved page frame numbers for long granted pages */
59+
grant_pfn_t long_grant_pfn[NR_LONG_GRANT_PFN];
60+
addr_t long_grant_start_pfn;
61+
5862
/* Stack frame of this domain */
5963
struct cpu_regs stack_frame;
6064

so3/avz/kernel/gnttab.c

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ gnttab_t *pick_granted_entry(grant_ref_t ref, domid_t origin_domid)
8181

8282
/**
8383
* @brief Create a new grant table entry in the gnttab of a domain
84-
*
84+
*
8585
* @param d The domain containing the grant table
8686
* @param target_domid The domain concerned by this grant
8787
* @param pfn The real frame number of the page to be granted
88+
* @param page_count The number of page to grant
8889
*/
89-
gnttab_t *new_gnttab_entry(struct domain *d, domid_t target_domid, addr_t pfn)
90+
gnttab_t *new_gnttab_entry(struct domain *d, domid_t target_domid, addr_t pfn, size_t page_count)
9091
{
9192
gnttab_t *gnttab;
9293

@@ -96,6 +97,7 @@ gnttab_t *new_gnttab_entry(struct domain *d, domid_t target_domid, addr_t pfn)
9697
gnttab->origin_domid = d->avz_shared->domID;
9798
gnttab->target_domid = target_domid;
9899
gnttab->pfn = pfn;
100+
gnttab->page_count = page_count;
99101

100102
/* Determine the ref number for this entry */
101103
gnttab->ref = get_ref_max(&d->gnttab) + 1;
@@ -142,6 +144,31 @@ addr_t allocate_grant_pfn(struct domain *d)
142144
return 0; /* Make gcc happy :-) */
143145
}
144146

147+
/**
148+
* @brief Find a free long grant pfn
149+
*
150+
* @param d Domain to search for the free pfn
151+
* @return grant pfn object to be used for mapping the granted pages
152+
*/
153+
grant_pfn_t *allocate_long_grant_pfn(struct domain *d)
154+
{
155+
int i;
156+
addr_t start_pfn = d->long_grant_start_pfn;
157+
158+
for (i = 0; i < NR_LONG_GRANT_PFN; i++) {
159+
if (d->long_grant_pfn[i].free) {
160+
d->long_grant_pfn[i].free = false;
161+
d->long_grant_pfn[i].pfn = start_pfn;
162+
return &d->long_grant_pfn[i];
163+
}
164+
165+
start_pfn += d->long_grant_pfn[i].page_count;
166+
}
167+
168+
BUG();
169+
return NULL;
170+
}
171+
145172
/**
146173
* @brief Map the grant page associated to vbstore in the IPA domain of the ME
147174
*
@@ -179,14 +206,16 @@ addr_t map_vbstore_pfn(int target_domid, int pfn)
179206

180207
/**
181208
* @brief Hypercall entry for grant table related operations.
182-
*
209+
*
183210
* @param args gnttab detail structure
184211
*/
185212
void do_gnttab(gnttab_op_t *args)
186213
{
187214
struct domain *d;
188215
addr_t paddr, grant_paddr;
216+
size_t page_count;
189217
gnttab_t *gnttab;
218+
grant_pfn_t *grant_pfn;
190219

191220
spin_lock(&gnttab_lock);
192221

@@ -198,8 +227,9 @@ void do_gnttab(gnttab_op_t *args)
198227
/* Create a new entry in the list of gnttab page */
199228

200229
paddr = ipa_to_pa(DOM_TO_MEMSLOT(d->avz_shared->domID), pfn_to_phys(args->pfn));
230+
page_count = args->page_count == 0 ? 1 : args->page_count;
201231

202-
gnttab = new_gnttab_entry(d, args->domid, phys_to_pfn(paddr));
232+
gnttab = new_gnttab_entry(d, args->domid, phys_to_pfn(paddr), page_count);
203233

204234
args->ref = gnttab->ref;
205235

@@ -215,13 +245,23 @@ void do_gnttab(gnttab_op_t *args)
215245
gnttab = pick_granted_entry(args->ref, args->domid);
216246
BUG_ON(!gnttab);
217247

218-
/* Here, we get an IPA address corresponding to the grant page */
219-
grant_paddr = pfn_to_phys(allocate_grant_pfn(d));
248+
page_count = gnttab->page_count;
249+
if (page_count == 1) {
250+
/* Here, we get an IPA address corresponding to the grant page */
251+
grant_paddr = pfn_to_phys(allocate_grant_pfn(d));
252+
} else {
253+
grant_pfn = allocate_long_grant_pfn(d);
254+
255+
grant_pfn->page_count = page_count;
256+
grant_paddr = pfn_to_phys(grant_pfn->pfn);
257+
}
220258

221259
/* This pfn will be exported to the domain */
222260
args->pfn = phys_to_pfn(grant_paddr);
261+
args->page_count = page_count;
223262

224-
__create_mapping((addr_t *) d->pagetable_vaddr, grant_paddr, pfn_to_phys(gnttab->pfn), PAGE_SIZE, true, S2);
263+
__create_mapping((addr_t *) d->pagetable_vaddr, grant_paddr, pfn_to_phys(gnttab->pfn), PAGE_SIZE * page_count,
264+
true, S2);
225265

226266
break;
227267

so3/avz/kernel/injector.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ static void build_domain_context(unsigned int ME_slotID, struct domain *me, stru
165165
domctxt->pause_flags = me->pause_flags;
166166

167167
memcpy(&domctxt->grant_pfn, &me->grant_pfn, sizeof(me->grant_pfn));
168+
memcpy(&domctxt->long_grant_pfn, &me->long_grant_pfn, sizeof(me->long_grant_pfn));
169+
memcpy(&domctxt->long_grant_start_pfn, &me->long_grant_start_pfn, sizeof(me->long_grant_start_pfn));
168170

169171
memcpy(&(domctxt->pause_count), &(me->pause_count), sizeof(me->pause_count));
170172

@@ -281,6 +283,8 @@ void restore_domain_context(unsigned int ME_slotID, struct domain *me, struct do
281283
me->pause_flags = domctxt->pause_flags;
282284

283285
memcpy(&me->grant_pfn, &domctxt->grant_pfn, sizeof(me->grant_pfn));
286+
memcpy(&me->long_grant_pfn, &domctxt->long_grant_pfn, sizeof(me->long_grant_pfn));
287+
memcpy(&me->long_grant_start_pfn, &domctxt->long_grant_start_pfn, sizeof(me->long_grant_start_pfn));
284288

285289
memcpy(&(me->pause_count), &(domctxt->pause_count), sizeof(me->pause_count));
286290

so3/configs/virt64_capsule_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ CONFIG_VUART_FRONTEND=y
104104
# CONFIG_VSENSELED_FRONTEND is not set
105105
# CONFIG_VSENSEJ_FRONTEND is not set
106106
CONFIG_VLOGS_FRONTEND=y
107+
CONFIG_VFBDEV_FRONTEND=y

so3/devices/fb/pl111.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int fb_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset)
106106
create_mapping(pcb->pgtable, virt_addr + (i * PAGE_SIZE), page, PAGE_SIZE, false);
107107
}
108108

109-
return virt_addr;
109+
return 0;
110110
}
111111

112112
int fb_ioctl(int fd, unsigned long cmd, unsigned long args)

so3/devices/fb/ramfb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ int fb_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset)
281281
}
282282
#endif
283283

284-
return virt_addr;
284+
return 0;
285285
}
286286

287287
int fb_ioctl(int fd, unsigned long cmd, unsigned long args)

0 commit comments

Comments
 (0)