2 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
9 #include <l4/util/mb_info.h>
10 #include <l4/sys/consts.h>
12 #include <l4/re/dataspace>
13 #include <l4/re/video/goos>
14 #include <l4/re/video/goos-sys.h>
15 #include <l4/re/protocols>
17 #include <l4/sigma0/sigma0.h>
19 #include <l4/cxx/iostream>
20 #include <l4/cxx/l4iostream>
22 #include "dataspace_static.h"
24 #include "name_space.h"
25 #include "page_alloc.h"
29 #include <l4/re/util/video/goos_svr>
31 using L4Re::Dataspace;
33 class Vesa_fb : public L4Re::Util::Video::Goos_svr, public Moe::Server_object
36 l4util_mb_vbe_ctrl_t *vbe;
37 l4util_mb_vbe_mode_t *vbi;
38 unsigned long base_offset;
39 unsigned long map_size;
42 Vesa_fb(l4util_mb_info_t *mbi);
45 int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios)
46 { return L4Re::Util::Video::Goos_svr::dispatch(obj, ios); }
51 init_vesa_fb(l4util_mb_info_t *mbi)
53 static Vesa_fb video(mbi);
57 Vesa_fb::Vesa_fb(l4util_mb_info_t *mbi)
59 if (!(mbi->flags & L4UTIL_MB_VIDEO_INFO))
61 vbe = (l4util_mb_vbe_ctrl_t*)(unsigned long)mbi->vbe_ctrl_info;
62 vbi = (l4util_mb_vbe_mode_t*)(unsigned long)mbi->vbe_mode_info;
66 base_offset = vbi->phys_base & (L4_SUPERPAGESIZE - 1);
67 unsigned long paddr = vbi->phys_base & ~(L4_SUPERPAGESIZE - 1);
68 unsigned long fb_size = 64 * 1024 * vbe->total_memory;
69 map_size = (fb_size + base_offset + L4_SUPERPAGESIZE - 1)
70 & ~(L4_SUPERPAGESIZE - 1);
73 = l4_round_size(Moe::Pages::max_addr, L4_SUPERPAGESHIFT);
74 if (vaddr >= Moe::Virt_limit::end - map_size - L4_SUPERPAGESIZE)
75 vaddr = (unsigned long)Single_page_alloc_base::_alloc(map_size);
78 L4::cerr << "Failed to get memory for VESA video memory\n";
82 switch (l4sigma0_map_iomem(Sigma0_cap, paddr, vaddr, map_size, 1))
85 L4::cerr << "IPC error mapping video memory\n";
88 L4::cerr << "No fpage received\n";
94 Moe::Dataspace_static *fb = new Moe::Dataspace_static((void*)vaddr, map_size, Moe::Dataspace_static::Writable | (L4_FPAGE_BUFFERABLE << 16));
96 _screen_info.width = vbi->x_resolution;
97 _screen_info.height = vbi->y_resolution;
98 _screen_info.flags = L4Re::Video::Goos::F_auto_refresh;
99 _screen_info.pixel_info = L4Re::Video::Pixel_info(vbi);
101 _view_info.buffer_offset = base_offset;
102 _view_info.bytes_per_line = vbi->bytes_per_scanline;
106 _fb_ds = L4::cap_cast<L4Re::Dataspace>(object_pool.cap_alloc()->alloc(fb));
108 object_pool.cap_alloc()->alloc(this);
109 root_name_space()->register_obj("vesa", L4Re::Util::Names::Obj(0, this));
111 L4::cout << " VESAFB: " << obj_cap() << _fb_ds
112 << " @" << (void*)(unsigned long)vbi->phys_base
113 << " (size=" << L4::hex << 64*1024*vbe->total_memory << ")\n" << L4::dec;