reeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org Mime-Version: 1.0 From: Ahmad Khalifa X-Mailer: aerc 0.21.0 References: <20250826160959.65024e9f008c30d46090b8ae@emorras.eu> In-Reply-To: Date: Mon, 20 Oct 2025 08:35:31 -0400 X-Gm-Features: AS18NWAswRU6x-Bu4giN94SNVBe44zWb0UsvTZYcutaY61_w9M0QiBEyHkCVEqc Message-ID: Subject: Re: Accesing vt(4) framebuffer To: Adrian Chadd Cc: =?UTF-8?Q?Eduardo_Morr=C3=A1s?= , hackers@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4cqvzF19l1z44Jy On Mon Oct 20, 2025 at 9:49 AM +0300, Adrian Chadd wrote: > On Wed, 3 Sept 2025 at 09:36, Ahmad Khalifa > 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 #include #include #include #include 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 */ }