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>
78 lines
3.4 KiB
C
78 lines
3.4 KiB
C
#pragma once
|
|
|
|
// Drawing, and the text console under it, on whatever display is bound.
|
|
//
|
|
// This was kernel/dev/vga.c, and every consumer called it by that name:
|
|
// panic.c drew the crash screen with vga_fill_rect, the console printed with
|
|
// vga_putc, /dev/fb0 handed out vga_fb_phys(). None of that code has anything
|
|
// to do with a VGA -- it is bitmap drawing over a linear framebuffer, and the
|
|
// only VGA-specific part was where the framebuffer came from.
|
|
//
|
|
// So the driver pushes its scanout in here (gfx_attach_scanout) and everything
|
|
// above draws through these calls. A second display driver becomes a second
|
|
// caller of one function rather than an edit to the crash screen. This is the
|
|
// same arrangement as include/netdev.h, for the same reason.
|
|
//
|
|
// Not the same thing as the display class in include/display.h. That is the
|
|
// compositor's interface -- acquire a back buffer, present a rectangle, wait
|
|
// for vblank -- and it is about *frames*. This is the kernel's own drawing
|
|
// surface, used by the console and the crash screen, which do not double
|
|
// buffer and must keep working when nothing else in the system does.
|
|
|
|
// A linear framebuffer, exactly as the hardware presents it.
|
|
struct fb_info {
|
|
volatile uchar *ptr; // kernel-mapped base, or 0 if there is none
|
|
uint64 phys; // physical base, for mmap and for page tables
|
|
uint64 size; // bytes, stride * height rather than w * h * bpp
|
|
uint32 stride; // bytes per row, which may exceed width * bpp/8
|
|
uint32 bpp;
|
|
uint32 width, height;
|
|
};
|
|
|
|
// A driver publishing the framebuffer it owns. Called once, early: the console
|
|
// draws long before any bus is enumerated, so whoever owns the display the
|
|
// loader left running has to say so before then.
|
|
void gfx_attach_scanout(const struct fb_info *);
|
|
|
|
// The scanout as attached, for the few callers that need the memory itself --
|
|
// /dev/fb0 maps it, and fork copies the mapping. Returns 0 if none.
|
|
const struct fb_info *gfx_scanout(void);
|
|
|
|
int gfx_ready(void);
|
|
void gfx_dims(int *w, int *h);
|
|
uint32 gfx_width(void);
|
|
uint32 gfx_height(void);
|
|
uint64 gfx_fb_phys(void);
|
|
uint64 gfx_fb_size(void);
|
|
uint32 gfx_fb_stride(void);
|
|
uint32 gfx_fb_bpp(void);
|
|
volatile uchar *gfx_fb_ptr(void);
|
|
|
|
// Pixels and shapes.
|
|
void gfx_draw_pixel(int x, int y, uint32 color);
|
|
void gfx_clear(uint32 color);
|
|
void gfx_fill_rect(int x, int y, int w, int h, uint32 color);
|
|
void gfx_fill_circle(int cx, int cy, int r, uint32 color);
|
|
void gfx_draw_logo(int x, int y, uint32 color, uint32 bg);
|
|
void gfx_logo_centered(int cy, uint32 color, uint32 bg);
|
|
|
|
// The built-in 8x16 font: glyphs at a position, and text that leaves the
|
|
// cursor alone. The crash screen lays itself out rather than printing, which
|
|
// is what needs the second one.
|
|
void gfx_draw_char(int x, int y, uchar c, uint32 color);
|
|
void gfx_text_at(int x, int y, const char *s, uint32 color);
|
|
int gfx_char_w(void);
|
|
int gfx_char_h(void);
|
|
|
|
// The text console: a cursor, scrolling, and the erase operations an ANSI
|
|
// escape parser needs. See kernel/core/console.c.
|
|
void gfx_putc(int c, uint32 color);
|
|
void gfx_puts(int x, int y, char *s, uint32 color);
|
|
void gfx_set_bg(uint32 color);
|
|
void gfx_screen_reset(void);
|
|
int gfx_cols(void);
|
|
int gfx_rows(void);
|
|
void gfx_cursor_get(int *col, int *row);
|
|
void gfx_cursor_set(int col, int row);
|
|
void gfx_erase_display(int mode);
|
|
void gfx_erase_line(int mode);
|