[fb] Use system_map_mmio to map framebuffer

Update fb driver to use new j6_init_desc_framebuffer format with
physical address, and system_map_mmio to map the framebuffer into its
memory.
This commit is contained in:
Justin C. Miller
2021-02-04 20:44:27 -08:00
parent fe05d45cde
commit e4aafca7c3
3 changed files with 35 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
#include "j6/init.h"
#include "j6/errors.h"
#include "j6/flags.h"
#include "j6/signals.h"
#include "j6/syscalls.h"
#include "j6/types.h"
@@ -18,6 +19,7 @@ extern "C" {
}
extern j6_handle_t __handle_sys;
extern j6_handle_t __handle_self;
struct entry
{
@@ -45,15 +47,35 @@ main(int argc, const char **argv)
}
}
if (!fb || fb->addr == nullptr) {
if (!fb || fb->addr == 0) {
j6_system_log("fb driver didn't find a framebuffer, exiting");
return 1;
}
j6_handle_t fb_handle = j6_handle_invalid;
uint32_t flags =
j6_vm_flag_write |
j6_vm_flag_write_combine;
j6_status_t s = j6_system_map_mmio(__handle_sys, &fb_handle, fb->addr, fb->size, flags);
if (s != j6_status_ok) {
return s;
}
s = j6_vma_map(fb_handle, __handle_self, fb->addr);
if (s != j6_status_ok) {
return s;
}
const screen::pixel_order order = (fb->flags & 1) ?
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
screen scr(fb->addr, fb->horizontal, fb->vertical, order);
screen scr(
reinterpret_cast<void*>(fb->addr),
fb->horizontal,
fb->vertical,
fb->scanline,
order);
font fnt;
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);

View File

@@ -2,13 +2,14 @@
#include <string.h>
#include "screen.h"
screen::screen(void *addr, unsigned hres, unsigned vres, pixel_order order) :
m_fb(static_cast<pixel_t *>(addr)),
screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order) :
m_fb(static_cast<volatile pixel_t *>(addr)),
m_order(order),
m_scanline(scanline),
m_resx(hres),
m_resy(vres)
{
m_back = reinterpret_cast<pixel_t*>(malloc(hres*vres*sizeof(pixel_t)));
m_back = reinterpret_cast<pixel_t*>(malloc(scanline*vres*sizeof(pixel_t)));
}
screen::pixel_t
@@ -46,5 +47,7 @@ screen::draw_pixel(unsigned x, unsigned y, pixel_t color)
void
screen::update()
{
memcpy(m_fb, m_back, m_resx*m_resy*sizeof(pixel_t));
const size_t len = m_scanline * m_resy * sizeof(pixel_t);
asm volatile ( "rep movsb" : :
"c"(len), "S"(m_back), "D"(m_fb) );
}

View File

@@ -9,7 +9,7 @@ public:
enum class pixel_order : uint8_t { bgr8, rgb8, };
screen(void *addr, unsigned hres, unsigned vres, pixel_order order);
screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order);
unsigned width() const { return m_resx; }
unsigned height() const { return m_resy; }
@@ -22,8 +22,10 @@ public:
void update();
private:
pixel_t *m_fb, *m_back;
volatile pixel_t *m_fb;
pixel_t *m_back;
pixel_order m_order;
unsigned m_scanline;
unsigned m_resx, m_resy;
screen() = delete;