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

@ -491,32 +491,10 @@ void uartinit(void);
void uartintr(void);
void uartputc(int);
// vga.c
void vga_init(uint64);
void vga_draw_pixel(int, int, uint32);
void vga_draw_char(int, int, uchar, uint32);
void vga_puts(int, int, char*, uint32);
void vga_putc(int, uint32);
void vga_clear(uint32);
void vga_screen_reset(void);
void vga_set_bg(uint32);
// The mode actually in use. The resolution is a boot-time choice now, so no
// caller may hardcode it.
uint32 vga_get_width(void);
uint32 vga_get_height(void);
// Crash-screen primitives: the panic handler lays itself out rather than
// printing. See kernel/core/panic.c.
int vga_ready(void);
void vga_dims(int *w, int *h);
int vga_char_w(void);
int vga_char_h(void);
// Framebuffer geometry. vga.c reads the VBE mode info, so it is the only
// thing that knows where the framebuffer is; nobody else may assume.
uint64 vga_fb_phys(void);
uint64 vga_fb_size(void);
uint32 vga_fb_stride(void);
uint32 vga_fb_bpp(void);
volatile uchar *vga_fb_ptr(void);
// Drawing, the text console and the framebuffer geometry are NOT declared
// here: they live in include/gfx.h, and the display drivers that back them in
// include/display.h. Declaring vga_fill_rect() here is what let the crash
// screen draw on one named driver.
// fb.c -- /dev/fb0, major 2.
void fbclose(struct inode*);
@ -554,22 +532,17 @@ struct netif *net_eth_netif(int i);
struct device *net_eth_device(int i);
// registry.c
void platform_register_devices(void);
// Platform devices, and the boot framebuffer. Takes the framebuffer address
// the loader handed over, because bringing that up is the first thing it does.
void platform_register_devices(uint64 fb_addr);
// drivers/gpu/vga -- the VBE framebuffer the loader programmed. Called only
// from registry.c; everything else draws through include/gfx.h.
void vga_fb_init(uint64 phys_addr);
uint64 vga_fb_phys(void);
uint64 vga_fb_size(void);
void e820_init(void);
int acpi_init(void);
void vga_fill_rect(int x, int y, int w, int h, uint32);
void vga_fill_circle(int cx, int cy, int r, uint32);
void vga_text_at(int, int, const char*, uint32);
void vga_draw_logo(int x, int y, uint32 color, uint32 bg);
void vga_logo_centered(int cy, uint32 color, uint32 bg);
// Cursor addressing and erasing, for the console's ANSI escape parser.
int vga_cols(void);
int vga_rows(void);
void vga_cursor_get(int *col, int *row);
void vga_cursor_set(int col, int row);
void vga_erase_display(int mode);
void vga_erase_line(int mode);
// console.c / panic.c
void cons_panic_mode(void);