/* * Framebuffer.cpp * Framebuffer information storage * Copyright (c) 2025 Daniel Hammer */ #include "Framebuffer.hpp" #include #include #include #include namespace Graphics::Framebuffer { // Framebuffer state static uint32_t* g_FbBase = nullptr; static uint64_t g_FbWidth = 0; static uint64_t g_FbHeight = 0; static uint64_t g_FbPitch = 0; // in bytes static uint8_t g_Edid[256] = {}; static uint64_t g_EdidSize = 0; void Initialize(const montauk::boot::Framebuffer& framebuffer) { g_FbBase = reinterpret_cast(framebuffer.address); g_FbWidth = framebuffer.width; g_FbHeight = framebuffer.height; g_FbPitch = framebuffer.pitch; g_EdidSize = framebuffer.edidSize; if (g_EdidSize > sizeof(g_Edid)) g_EdidSize = sizeof(g_Edid); if (framebuffer.edid == nullptr) g_EdidSize = 0; for (uint64_t i = 0; i < g_EdidSize; i++) { g_Edid[i] = framebuffer.edid[i]; } Kt::KernelLogStream(Kt::OK, "Graphics") << "Framebuffer initialized (" << (uint64_t)g_FbWidth << "x" << (uint64_t)g_FbHeight << ")"; } uint32_t* GetBase() { return g_FbBase; } uint64_t GetWidth() { return g_FbWidth; } uint64_t GetHeight() { return g_FbHeight; } uint64_t GetPitch() { return g_FbPitch; } const uint8_t* GetEdid(uint64_t* size) { if (size) *size = g_EdidSize; return g_EdidSize ? g_Edid : nullptr; } void Set(uint32_t* base, uint64_t width, uint64_t height, uint64_t pitch) { g_FbBase = base; g_FbWidth = width; g_FbHeight = height; g_FbPitch = pitch; Kt::KernelLogStream(Kt::OK, "Graphics") << "Framebuffer switched (" << (uint64_t)g_FbWidth << "x" << (uint64_t)g_FbHeight << ")"; } uint64_t GetPhysBase() { return Memory::SubHHDM((uint64_t)g_FbBase); } void MapWriteCombining() { uint64_t fbPhys = GetPhysBase(); uint64_t fbSize = g_FbHeight * g_FbPitch; uint64_t numPages = (fbSize + 0xFFF) / 0x1000; for (uint64_t i = 0; i < numPages; i++) { uint64_t phys = fbPhys + i * 0x1000; Memory::VMM::g_paging->MapWC(phys, Memory::HHDM(phys)); } Memory::VMM::FlushTLB(); Kt::KernelLogStream(Kt::OK, "Graphics") << "Framebuffer mapped as Write-Combining (" << kcp::dec << numPages << " pages)"; } };