Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Sep 2025 08:23:05 -0700
From:      Adrian Chadd <adrian@freebsd.org>
To:        =?UTF-8?Q?Eduardo_Morr=C3=A1s?= <emorras@emorras.eu>
Cc:        hackers@freebsd.org
Subject:   Re: Accesing vt(4) framebuffer
Message-ID:  <CAJ-VmoniUvHGom19s_hOnc%2BRzB%2BNTZZmSq%2BL0T8bgPskTryAzg@mail.gmail.com>
In-Reply-To: <20250826160959.65024e9f008c30d46090b8ae@emorras.eu>
References:  <20250826160959.65024e9f008c30d46090b8ae@emorras.eu>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
hi!

We put code review requests in the tool at https://reviews.freebsd.org/ .
If you've not heard back about this
then please feel free to poke me directly.

Having direct fb access from userland would be great. I thought we already
did?!



-adrian

On Tue, 26 Aug 2025 at 07:10, Eduardo Morrás <emorras@emorras.eu> wrote:

>
> Hello, I'm developing a gui/widget over vt(4) framebuffer, no X11 nor
> Wayland.
>
> For this I have created a new ioctl that allows access to framebuffer
> information and change it's content. For this I modified
> /usr/src/sys/dev/vt/hw/fb/vt_fb.c and .h, patches at end of this mail.
>
> Is this a correct way? Should I do it different? Any security problems?
>
>
> Thanks, Good Day.
>
>
> --- vt_fb.h_ORIG        2025-08-21 19:01:01.192050000 +0200
> +++ vt_fb.h     2025-08-21 19:04:58.447415000 +0200
> @@ -49,4 +49,20 @@
>  vd_fb_ioctl_t          vt_fb_ioctl;
>  vd_fb_mmap_t           vt_fb_mmap;
>
> +#ifdef _KERNEL
> +#include <sys/ioccom.h>
> +#endif
> +
> +/* Struct to expose framebuffer to userland*/
> +struct vt_fb_userinfo {
> +    uint32_t width;
> +    uint32_t height;
> +    uint32_t depth;
> +    uint32_t stride;
> +    uint32_t size;
> +};
> +
> +/* IOCTL code to work with vt_fb_userinfo */
> +#define VT_FB_GETINFO _IOR('v', 1, struct vt_fb_userinfo)
> +
>  #endif /* _DEV_VT_HW_FB_VT_FB_H_ */
>
>
> --- vt_fb.c_ORIG        2025-08-21 19:01:07.096190000 +0200
> +++ vt_fb.c     2025-08-21 19:10:22.228787000 +0200
> @@ -42,6 +42,8 @@
>  #include <vm/vm.h>
>  #include <vm/pmap.h>
>
> +#include <sys/ioccom.h> /* Userland access framebuffer */
> +
>  static struct vt_driver vt_fb_driver = {
>         .vd_name = "fb",
>         .vd_init = vt_fb_init,
> @@ -87,6 +89,24 @@
>         *(uint32_t *)(sc->fb_vbase + o) = v;
>  }
>
> +static int
> +vt_fb_userioctl(struct vt_device *vd, u_long cmd, caddr_t data)
> +{
> +       struct vt_fb_userinfo *ui = (struct vt_fb_userinfo *)data;
> +       struct fb_info *info = vd->vd_softc;
> +
> +       if (cmd != VT_FB_GETINFO)
> +               return (ENOIOCTL);
> +
> +       ui->width  = info->fb_width;
> +       ui->height = info->fb_height;
> +       ui->depth  = info->fb_bpp * 8;
> +       ui->stride = info->fb_stride;
> +       ui->size   = info->fb_size;
> +
> +       return (0);
> +}
> +
>  int
>  vt_fb_ioctl(struct vt_device *vd, u_long cmd, caddr_t data, struct thread
> *td)
>  {
> @@ -125,6 +145,10 @@
>                         return (ENOTTY);
>                 memcpy((struct fb_rgboffs *)data, &info->fb_rgboffs,
>                     sizeof(struct fb_rgboffs));
> +               break;
> +
> +       case  VT_FB_GETINFO:   /* userland framebuffer */
> +               return vt_fb_userioctl(vd, cmd, data);
>                 break;
>
>         default:
>
>
> ---   ---
> Eduardo Morrás <emorras@emorras.eu>
>
>

[-- Attachment #2 --]
<div dir="ltr"><div>hi!</div><div><br></div><div>We put code review requests in the tool at <a href="https://reviews.freebsd.org/">https://reviews.freebsd.org/</a>; . If you&#39;ve not heard back about this</div><div>then please feel free to poke me directly.</div><div><br></div><div>Having direct fb access from userland would be great. I thought we already did?!</div><div><br></div><div><br></div><div><br></div><div>-adrian</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, 26 Aug 2025 at 07:10, Eduardo Morrás &lt;<a href="mailto:emorras@emorras.eu">emorras@emorras.eu</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Hello, I&#39;m developing a gui/widget over vt(4) framebuffer, no X11 nor<br>
Wayland.<br>
<br>
For this I have created a new ioctl that allows access to framebuffer<br>
information and change it&#39;s content. For this I modified <br>
/usr/src/sys/dev/vt/hw/fb/vt_fb.c and .h, patches at end of this mail.<br>
<br>
Is this a correct way? Should I do it different? Any security problems?<br>
<br>
<br>
Thanks, Good Day.<br>
<br>
<br>
--- vt_fb.h_ORIG        2025-08-21 19:01:01.192050000 +0200<br>
+++ vt_fb.h     2025-08-21 19:04:58.447415000 +0200<br>
@@ -49,4 +49,20 @@<br>
 vd_fb_ioctl_t          vt_fb_ioctl;<br>
 vd_fb_mmap_t           vt_fb_mmap;<br>
<br>
+#ifdef _KERNEL<br>
+#include &lt;sys/ioccom.h&gt;<br>
+#endif<br>
+<br>
+/* Struct to expose framebuffer to userland*/<br>
+struct vt_fb_userinfo {<br>
+    uint32_t width;<br>
+    uint32_t height;<br>
+    uint32_t depth;<br>
+    uint32_t stride;<br>
+    uint32_t size;<br>
+};<br>
+<br>
+/* IOCTL code to work with vt_fb_userinfo */<br>
+#define VT_FB_GETINFO _IOR(&#39;v&#39;, 1, struct vt_fb_userinfo)<br>
+<br>
 #endif /* _DEV_VT_HW_FB_VT_FB_H_ */<br>
<br>
<br>
--- vt_fb.c_ORIG        2025-08-21 19:01:07.096190000 +0200<br>
+++ vt_fb.c     2025-08-21 19:10:22.228787000 +0200<br>
@@ -42,6 +42,8 @@<br>
 #include &lt;vm/vm.h&gt;<br>
 #include &lt;vm/pmap.h&gt;<br>
<br>
+#include &lt;sys/ioccom.h&gt; /* Userland access framebuffer */<br>
+<br>
 static struct vt_driver vt_fb_driver = {<br>
        .vd_name = &quot;fb&quot;,<br>
        .vd_init = vt_fb_init,<br>
@@ -87,6 +89,24 @@<br>
        *(uint32_t *)(sc-&gt;fb_vbase + o) = v;<br>
 }<br>
<br>
+static int<br>
+vt_fb_userioctl(struct vt_device *vd, u_long cmd, caddr_t data)<br>
+{<br>
+       struct vt_fb_userinfo *ui = (struct vt_fb_userinfo *)data;<br>
+       struct fb_info *info = vd-&gt;vd_softc;<br>
+<br>
+       if (cmd != VT_FB_GETINFO)<br>
+               return (ENOIOCTL);<br>
+<br>
+       ui-&gt;width  = info-&gt;fb_width;<br>
+       ui-&gt;height = info-&gt;fb_height;<br>
+       ui-&gt;depth  = info-&gt;fb_bpp * 8;<br>
+       ui-&gt;stride = info-&gt;fb_stride;<br>
+       ui-&gt;size   = info-&gt;fb_size;<br>
+<br>
+       return (0);<br>
+}<br>
+<br>
 int<br>
 vt_fb_ioctl(struct vt_device *vd, u_long cmd, caddr_t data, struct thread *td)<br>
 {<br>
@@ -125,6 +145,10 @@<br>
                        return (ENOTTY);<br>
                memcpy((struct fb_rgboffs *)data, &amp;info-&gt;fb_rgboffs,<br>
                    sizeof(struct fb_rgboffs));<br>
+               break;<br>
+<br>
+       case  VT_FB_GETINFO:   /* userland framebuffer */<br>
+               return vt_fb_userioctl(vd, cmd, data);<br>
                break;<br>
<br>
        default:<br>
<br>
<br>
---   ---<br>
Eduardo Morrás &lt;<a href="mailto:emorras@emorras.eu" target="_blank">emorras@emorras.eu</a>&gt;<br>
<br>
</blockquote></div>
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-VmoniUvHGom19s_hOnc%2BRzB%2BNTZZmSq%2BL0T8bgPskTryAzg>