Re: Accesing vt(4) framebuffer
- In reply to: Adrian Chadd : "Re: Accesing vt(4) framebuffer"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 Oct 2025 12:35:31 UTC
On Mon Oct 20, 2025 at 9:49 AM +0300, Adrian Chadd wrote:
> On Wed, 3 Sept 2025 at 09:36, Ahmad Khalifa <ahmadkhalifa570@gmail.com>
> wrote:
>
>> On Wed Sep 3, 2025 at 6:23 PM +0300, Adrian Chadd wrote:
>> > 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?!
>>
>> We can access it through mmap (see vd_fb_mmap). This patch just seems to
>> expose some framebuffer attributes. Although I think (?) that this info
>> is available through FBIOGTYPE.
>
>
> i tried this tonight (as I'm debugging some fb font stuff, and i want to
> try writing to the framebuffer from userland).
>
> FBIOGTYPE however just exposes/copies a kernel struct, without scrubbing it
> (pointers and all), and its inside
> #ifdef KERNEL.
>
> So i do think it's worth creating a struct thats specifically the useful
> userland contract bits.
struct fbtype should be used for userland, not struct fb_info. FBIOGTYPE
just copies the first 6 members of struct fb_info, not the entire thing.
The following should work:
#include <sys/ioctl.h>
#include <sys/fbio.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
int main(void) {
struct fbtype info;
uint8_t *fbuf;
int fd;
if ((fd = open("/dev/ttyv0", O_RDWR | O_NONBLOCK)) < 0) {
perror("open(\"/dev/ttyv0\")");
return -1;
}
if (ioctl(fd, FBIOGTYPE, &info) == -1) {
perror("ioctl(FBIOGTYPE)");
return -1;
}
printf("Depth= %d, width= %d, height= %d\n",
info.fb_depth, info.fb_width, info.fb_height);
if ((fbuf = mmap(NULL, info.fb_size,
PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
perror("mmap");
return -1;
}
printf("Got fbuf at %p\n", fbuf);
for (int i = 0; i < info.fb_size; i++)
fbuf[i] = ~0; /* something interesting */
}