gfx: the console and the crash screen stop drawing on a driver by name

Same disease as the network stack, one subsystem over. kernel/dev/vga.c
was three things wearing one name: the owner of the framebuffer, a
bitmap drawing library, and the text console. Only the first is a
driver, and because they shared a file they shared a prefix -- so
panic.c drew the crash screen with vga_fill_rect, console.c printed with
vga_putc, /dev/fb0 handed out vga_fb_phys, and every one of those files
named a display driver it had no business knowing about.

Split three ways:

  - kernel/drivers/gpu/vga/vga_fb.c owns the VBE framebuffer -- the mode
    the loader programmed and handed over, the aperture, and the display
    class vtable. It is a driver and now lives with the driver that
    finds the card on the bus.
  - kernel/dev/gfx.c draws: pixels, shapes, glyphs, the cursor, scroll,
    the ANSI erase operations. It names no driver. The framebuffer
    arrives through gfx_attach_scanout(), so a driver publishes what it
    owns and this file draws on it without knowing what it is.
  - include/gfx.h is the interface, and says why it is deliberately not
    the display class: that one is about frames -- acquire, present,
    vblank -- and the crash screen has to work when nothing else does.

main() no longer calls a display driver. platform_register_devices()
takes the framebuffer address and brings up whatever owns it, which is
where driver names belong; kernel/drivers/registry.c is the file whose
entire job is naming every driver in the kernel.

virtio-gpu got the e1000 treatment as well: instances in an array, the
instance hung on dev->priv by an `attached` hook, and every op reading
it rather than a file-static. It refused the second adapter outright
before, which is not hypothetical -- integrated plus discrete is an
ordinary laptop. The VGA driver deliberately has no such hook, and says
so: there is one framebuffer the loader programmed however many
VGA-class controllers the bus turns up, and a second one publishing the
same scanout is the truth rather than a bug.

Private headers moved next to their drivers: include/virtio.h and
include/xhci.h each had exactly one includer. include/ is for headers
the rest of the kernel needs.

Deleted rather than moved: consoleinit() programmed the sixteen ANSI
colours into the VGA DAC and disabled text-mode blink, by writing ports
0x3C0-0x3C9 from the console. The comment three lines above the colour
table already said this does nothing in a 32bpp linear mode -- there is
no palette to index -- so it was both dead and in the wrong file.

Verified, and this is a refactor so the evidence is that nothing moved:
  - bootcheck -Fb -Net: 59 [ok], no failures. That covers the console
    through every command, /dev/fb0's geometry, writing pixels through
    write() and mapping the framebuffer through mmap.
  - make crashshot: the crash screen renders exactly as before --
    shapes, glyphs, logo and QR code -- which is the whole of gfx.c
    exercised at once, in a panic, with the scanout attached by a driver.
  - make schcom-test: five pixel assertions from the host oracle still
    pass, so the display class and the compositor above it are unmoved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Nexoniarz 2026-08-15 17:04:10 +02:00
commit 817d666068
22 changed files with 942 additions and 752 deletions

View file

@ -13,6 +13,7 @@
#include "types.h"
#include "defs.h"
#include "gfx.h"
#include "param.h"
#include "mmu.h"
#include "proc.h"
@ -35,7 +36,7 @@ chan(struct fb_bitfield *f, unsigned int offset, unsigned int length)
f->msb_right = 0;
}
// Pixel layout for the depths vga_draw_pixel knows how to write. Keeping the
// Pixel layout for the depths gfx_draw_pixel knows how to write. Keeping the
// two in step matters: this is the kernel telling userspace how to build a
// pixel, and if it disagrees with how the kernel builds one, every colour
// drawn by a program is wrong in a way that looks like a hardware fault.
@ -52,7 +53,7 @@ pixel_format(struct fb_var_screeninfo *v, unsigned int bpp)
chan(&v->transp, 0, 0);
break;
case 16:
// RGB565, matching the packing vga_draw_pixel does for this depth.
// RGB565, matching the packing gfx_draw_pixel does for this depth.
chan(&v->red, 11, 5); chan(&v->green, 5, 6); chan(&v->blue, 0, 5);
chan(&v->transp, 0, 0);
break;
@ -66,8 +67,8 @@ pixel_format(struct fb_var_screeninfo *v, unsigned int bpp)
int
fbread(struct inode *ip, uint64 off, char *dst, int n)
{
volatile uchar *fb = vga_fb_ptr();
uint64 size = vga_fb_size();
volatile uchar *fb = gfx_fb_ptr();
uint64 size = gfx_fb_size();
if (!fb)
return -ENODEV;
@ -100,8 +101,8 @@ fb_mapped(void)
int
fbwrite(struct inode *ip, uint64 off, char *src, int n)
{
volatile uchar *fb = vga_fb_ptr();
uint64 size = vga_fb_size();
volatile uchar *fb = gfx_fb_ptr();
uint64 size = gfx_fb_size();
if (!fb)
return -ENODEV;
@ -137,7 +138,7 @@ fbclose(struct inode *ip)
// indistinguishable from a bug -- and this is the only place in the system
// that wipes the display without being asked to.
cprintf("fb0: released by pid %d, console restored\n", myproc() ? myproc()->pid : -1);
vga_screen_reset();
gfx_screen_reset();
}
// FBIO* handling, called from sys_ioctl once it has established that the fd
@ -151,10 +152,10 @@ fb_ioctl(int request, addr_t arg)
{
int w, h;
if (!vga_fb_ptr())
if (!gfx_fb_ptr())
return -ENODEV;
vga_dims(&w, &h);
gfx_dims(&w, &h);
switch (request) {
case FBIOGET_VSCREENINFO: {
@ -165,7 +166,7 @@ fb_ioctl(int request, addr_t arg)
memset(v, 0, sizeof(*v));
v->xres = v->xres_virtual = (unsigned int)w;
v->yres = v->yres_virtual = (unsigned int)h;
v->bits_per_pixel = vga_fb_bpp();
v->bits_per_pixel = gfx_fb_bpp();
v->activate = FB_ACTIVATE_NOW;
pixel_format(v, v->bits_per_pixel);
// height/width (physical millimetres) and every timing field stay zero:
@ -180,11 +181,11 @@ fb_ioctl(int request, addr_t arg)
return -EFAULT;
memset(f, 0, sizeof(*f));
safestrcpy(f->id, "schosfb", sizeof(f->id));
f->smem_start = (unsigned long)vga_fb_phys();
f->smem_len = (unsigned int)vga_fb_size();
f->smem_start = (unsigned long)gfx_fb_phys();
f->smem_len = (unsigned int)gfx_fb_size();
f->type = FB_TYPE_PACKED_PIXELS;
f->visual = FB_VISUAL_TRUECOLOR;
f->line_length = vga_fb_stride();
f->line_length = gfx_fb_stride();
return 0;
}