Skip to content

Commit 8152eb7

Browse files
committed
cleanup
1 parent bc1e5db commit 8152eb7

13 files changed

Lines changed: 110 additions & 96 deletions

File tree

so3/arch/arm64/exception.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ ENTRY(pre_ret_to_el1)
314314
mrs x0, spsr_el2
315315
str x0, [sp, #OFFSET_PSTATE]
316316

317-
// Save userspace register. Use OFFSET_SP as it is not used on the stack frame.
317+
// Save EL0 register. Use OFFSET_SP as it is not used on the stack frame.
318318
mrs x0, sp_el0
319319
str x0, [sp, #OFFSET_SP]
320320
mrs x0, tpidr_el0
@@ -340,7 +340,7 @@ ENTRY(pre_ret_to_el1)
340340
ldr x0, [sp, #OFFSET_PSTATE]
341341
msr spsr_el2, x0
342342

343-
// Restore userspace register
343+
// Restore EL0 register
344344
ldr x0, [sp, #OFFSET_SP]
345345
msr sp_el0, x0
346346
ldr x0, [sp, #OFFSET_TLS_USR]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ ipamap_t agency_ipamap[] = {
2828
.size = 0x3000000,
2929
},
3030
{
31-
/* PCIe mapping */
31+
/* PCIe configuration ranges */
3232
.ipa_addr = 0x4010000000,
3333
.phys_addr = 0x4010000000,
3434
.size = 0x10000000
3535
},
3636
{
37-
/* PCIe mapping */
37+
/* PCIe devices IO and 32 bits memory ranges */
3838
.ipa_addr = 0x10000000,
3939
.phys_addr = 0x10000000,
40-
.size = 0x40000000
40+
.size = 0x2f000000
4141
},
4242
{
43-
/* PCIe mapping */
43+
/* PCIe devices 64 bits memory ranges */
4444
.ipa_addr = 0x8000000000,
4545
.phys_addr = 0x8000000000,
4646
.size = 0x8000000000

so3/avz/include/avz/fbdev_gnt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <soo/uapi/soo.h>
55

66
void fbdev_set_pgtable(struct domain *d, int slotID);
7-
void fbdev_set_info(fbdev_info_t *fbdev, addr_t fake_pfn);
7+
void fbdev_set_info(fbdev_info_t *fbdev);
88
void fbdev_change_focus(int new_slotID);
99
addr_t fbdev_get_addr(void);
1010

so3/avz/include/avz/gnttab.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ 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-
4035
/* Unique ref ID used by the domain which refers to this page */
4136
grant_ref_t ref;
4237
};

so3/avz/include/avz/injector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ 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 */
58+
/* IPA reserved start frame number for framebuffer */
5959
addr_t fbdev_start_pfn;
6060

6161
/* Stack frame of this domain */

so3/avz/kernel/fbdev_gnt.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
#include <heap.h>
12
#include <avz/fbdev_gnt.h>
23
#include <avz/domain.h>
34
#include <avz/memslot.h>
45
#include <avz/sched.h>
56

6-
#define MAX_FBDEV_PFN 8
7-
87
typedef struct {
98
fbdev_info_t fbdev;
10-
addr_t fake_pfn;
9+
void *fake_fbdev;
1110
int current_slotID;
1211
} fbdev_priv_t;
1312

@@ -24,29 +23,36 @@ static void __map_fbdev(struct domain *d, const fbdev_info_t *pfn_info)
2423
pgtable = (void *)d->pagetable_vaddr;
2524
ipa_addr = d->fbdev_start_pfn << PAGE_SHIFT;
2625

27-
for (i = 0; i < pfn_info->count; i++) {
28-
phys_addr = pfn_info->pfn[i] << PAGE_SHIFT;
29-
size = pfn_info->page_count[i] << PAGE_SHIFT;
26+
/* Map all distincts ranges of the framebuffer to the capsule */
27+
for (i = 0; i < pfn_info->pfn_count; i++) {
28+
phys_addr = pfn_to_phys(pfn_info->pfn[i]);
29+
size = pfn_info->page_count[i] * PAGE_SIZE;
3030

3131
__create_mapping(pgtable, ipa_addr, phys_addr, size, true, S2);
3232

3333
ipa_addr += size;
3434
}
3535
}
3636

37-
static void __map_fake_fbdev(struct domain *d, addr_t fake_pfn,
38-
const fbdev_info_t *real_fb)
37+
static void __map_fake_fbdev(struct domain *d, const fbdev_info_t *real_fb)
3938
{
4039
size_t i, j;
4140
addr_t phys_addr;
4241
addr_t ipa_addr;
4342
void *pgtable;
4443

44+
/* One time malloc of fake framebuffer page */
45+
if (priv.fake_fbdev == NULL) {
46+
priv.fake_fbdev = malloc(PAGE_SIZE);
47+
BUG_ON(!priv.fake_fbdev);
48+
}
49+
4550
pgtable = (void *)d->pagetable_vaddr;
46-
ipa_addr = d->fbdev_start_pfn << PAGE_SHIFT;
47-
phys_addr = fake_pfn << PAGE_SHIFT;
51+
ipa_addr = pfn_to_phys(d->fbdev_start_pfn);
52+
phys_addr = __pa(priv.fake_fbdev);
4853

49-
for (i = 0; i < real_fb->count; i++) {
54+
/* Map the capsule framebuffer to the fake one */
55+
for (i = 0; i < real_fb->pfn_count; i++) {
5056
for (j = 0; j < real_fb->page_count[i]; j++) {
5157
__create_mapping(pgtable, ipa_addr, phys_addr, PAGE_SIZE,
5258
true, S2);
@@ -58,40 +64,42 @@ static void __map_fake_fbdev(struct domain *d, addr_t fake_pfn,
5864

5965
void fbdev_set_pgtable(struct domain *d, int slotID)
6066
{
61-
if (slotID <= 1) {
67+
/* Only capsules have virtual framebuffer */
68+
if ((slotID < MEMSLOT_BASE) && !memslot[slotID].busy)
6269
return;
63-
}
6470

65-
if (slotID == priv.current_slotID) {
71+
if (slotID == priv.current_slotID)
6672
__map_fbdev(d, &priv.fbdev);
67-
} else {
68-
__map_fake_fbdev(d, priv.fake_pfn, &priv.fbdev);
69-
}
73+
else
74+
__map_fake_fbdev(d, &priv.fbdev);
7075
}
7176

72-
void fbdev_set_info(fbdev_info_t *fbdev, addr_t fake_pfn)
77+
void fbdev_set_info(fbdev_info_t *fbdev)
7378
{
79+
int slotID;
80+
7481
memcpy(&priv.fbdev, fbdev, sizeof(*fbdev));
75-
priv.fake_pfn = fake_pfn;
7682

77-
// TODO: check already existing capsule
83+
/* Map framebuffer to all capsules. */
84+
for (slotID = MEMSLOT_BASE; slotID < MEMSLOT_NR; slotID++)
85+
if (memslot[slotID].busy)
86+
fbdev_set_pgtable(domains[slotID], slotID);
7887
}
7988

8089
void fbdev_change_focus(int new_slotID)
8190
{
82-
if ((priv.current_slotID > 1) && memslot[priv.current_slotID].busy) {
83-
__map_fake_fbdev(domains[priv.current_slotID], priv.fake_pfn,
84-
&priv.fbdev);
85-
}
91+
/* Remap old capsule to fake framebuffer */
92+
if ((priv.current_slotID >= MEMSLOT_BASE) && memslot[priv.current_slotID].busy)
93+
__map_fake_fbdev(domains[priv.current_slotID], &priv.fbdev);
8694

87-
if ((new_slotID > 1) && memslot[new_slotID].busy) {
95+
/* Map the new capsule to the framebuffer */
96+
if ((new_slotID >= MEMSLOT_BASE) && memslot[new_slotID].busy)
8897
__map_fbdev(domains[new_slotID], &priv.fbdev);
89-
}
9098

9199
priv.current_slotID = new_slotID;
92100
}
93101

94102
addr_t fbdev_get_addr(void)
95103
{
96-
return current_domain->fbdev_start_pfn << PAGE_SHIFT;
104+
return pfn_to_phys(current_domain->fbdev_start_pfn);
97105
}

so3/avz/kernel/hypercalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void do_avz_hypercall(void *__args)
203203
}
204204

205205
case AVZ_FBDEV_SET_INFO:
206-
fbdev_set_info(&args->u.avz_fbdev_info_args.fbdev, args->u.avz_fbdev_info_args.fake_pfn);
206+
fbdev_set_info(&args->u.avz_fbdev_info_args.fbdev);
207207
break;
208208

209209
case AVZ_FBDEV_CHANGE_FOCUS:

so3/dts/virt64_capsule.dts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
status = "ok";
116116
};
117117

118+
/* Enabling framebuffer support */
118119
vfbdev {
119120
compatible = "vfbdev,frontend";
120121
status = "ok";

so3/soo/drivers/vfbdevfront/vfbdev.c

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright (C) 2026 Clément Dieperink <clement.dieperink@heig-vd.ch>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
*/
18+
119
#if 0
220
#define DEBUG
321
#endif
@@ -30,12 +48,12 @@ typedef struct {
3048

3149
uint32_t hres;
3250
uint32_t vres;
33-
size_t size;
51+
size_t memory_size;
3452
addr_t fb_paddr;
3553

3654
} vfbdev_priv_t;
3755

38-
/* Our unique uart instance. */
56+
/* Our unique vfbdev instance. */
3957
static struct vbus_device *vfbdev_dev = NULL;
4058

4159
irq_return_t vfbdev_interrupt(int irq, void *dev_id)
@@ -192,14 +210,14 @@ vdrvfront_t vfbdevdrv = { .probe = vfbdev_probe,
192210
.resume = vfbdev_resume,
193211
.connected = vfbdev_connected };
194212

195-
static int retrieve_data(vfbdev_priv_t *priv)
213+
static void retrieve_data(vfbdev_priv_t *priv)
196214
{
197215
vfbdev_request_t *ring_req;
198216
vfbdev_response_t *ring_rsp;
199217
avz_hyp_t hyp_args;
200218

201-
if (priv->size != 0) {
202-
return 1;
219+
if ((priv->memory_size != 0) && (priv->fb_paddr != 0)) {
220+
return;
203221
}
204222

205223
vdevfront_processing_begin(vfbdev_dev);
@@ -221,15 +239,13 @@ static int retrieve_data(vfbdev_priv_t *priv)
221239

222240
priv->hres = ring_rsp->hres;
223241
priv->vres = ring_rsp->vres;
224-
priv->size = ring_rsp->size;
242+
priv->memory_size = ring_rsp->memory_size;
225243

226244
vdevfront_processing_end(vfbdev_dev);
227245

228246
hyp_args.cmd = AVZ_FBDEV_GET_ADDR;
229247
avz_hypercall(&hyp_args);
230248
priv->fb_paddr = hyp_args.u.avz_fbdev_addr_args.paddr;
231-
232-
return 1;
233249
}
234250

235251
static int vfbdev_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offset)
@@ -239,17 +255,23 @@ static int vfbdev_mmap(int fd, addr_t virt_addr, uint32_t page_count, off_t offs
239255
vfbdev_priv_t *priv;
240256

241257
dev = devclass_by_fd(fd);
258+
BUG_ON(!dev);
242259
priv = devclass_get_priv(dev);
260+
BUG_ON(!priv);
243261

244-
if (!retrieve_data(priv)) {
245-
return -1;
262+
retrieve_data(priv);
263+
264+
/* Ensure that we got a framebuffer */
265+
if ((priv->memory_size == 0) || (priv->fb_paddr == 0)) {
266+
return -ENODEV;
246267
}
247268

248-
if (page_count > (priv->size / PAGE_SIZE)) {
249-
return -1;
269+
/* Ensure requested mapping size doesn't overflow actual framebuffer size */
270+
if (page_count > (priv->memory_size / PAGE_SIZE)) {
271+
return -EINVAL;
250272
}
251273

252-
create_mapping(pcb->pgtable, virt_addr, priv->fb_paddr, priv->size, true);
274+
create_mapping(pcb->pgtable, virt_addr, priv->fb_paddr, page_count * PAGE_SIZE, true);
253275

254276
return 0;
255277
}
@@ -260,11 +282,11 @@ static int vfbdev_ioctl(int fd, unsigned long cmd, unsigned long args)
260282
vfbdev_priv_t *priv;
261283

262284
dev = devclass_by_fd(fd);
285+
BUG_ON(!dev);
263286
priv = devclass_get_priv(dev);
287+
BUG_ON(!priv);
264288

265-
if (!retrieve_data(priv)) {
266-
return -EINVAL;
267-
}
289+
retrieve_data(priv);
268290

269291
switch (cmd) {
270292
case IOCTL_FB_HRES:
@@ -276,7 +298,7 @@ static int vfbdev_ioctl(int fd, unsigned long cmd, unsigned long args)
276298
return 0;
277299

278300
case IOCTL_FB_SIZE:
279-
*((uint32_t *) args) = priv->size;
301+
*((uint32_t *) args) = priv->memory_size;
280302
return 0;
281303

282304
default:
@@ -301,7 +323,6 @@ static int vfbdev_init(dev_t *dev, int fdt_offset)
301323
{
302324
vfbdev_priv_t *vfbdev_priv;
303325

304-
305326
vfbdev_priv = malloc(sizeof(vfbdev_priv_t));
306327
BUG_ON(!vfbdev_priv);
307328

so3/soo/include/soo/dev/vfbdev.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright (C) 2026 Clément Dieperink <clement.dieperink@heig-vd.ch>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
*/
18+
119
#ifndef VFBDEV_H
220
#define VFBDEV_H
321

@@ -15,7 +33,7 @@ typedef struct {
1533
typedef struct {
1634
uint32_t hres;
1735
uint32_t vres;
18-
uint64_t size;
36+
uint64_t memory_size;
1937
} vfbdev_response_t;
2038

2139
DEFINE_RING_TYPES(vfbdev, vfbdev_request_t, vfbdev_response_t);

0 commit comments

Comments
 (0)