]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/moe/server/src/vesa_fb.cc
Update
[l4.git] / l4 / pkg / l4re-core / moe / server / src / vesa_fb.cc
1 /*
2  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
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.
8  */
9 #include <l4/util/mb_info.h>
10 #include <l4/sys/consts.h>
11
12 #include <l4/re/dataspace>
13 #include <l4/re/video/goos>
14
15 #include <l4/sigma0/sigma0.h>
16
17 #include <l4/cxx/iostream>
18 #include <l4/cxx/l4iostream>
19
20 #include "dataspace_static.h"
21 #include "globals.h"
22 #include "name_space.h"
23 #include "page_alloc.h"
24 #include "pages.h"
25 #include "vesa_fb.h"
26
27 #include <l4/re/util/video/goos_svr>
28 #include <l4/sys/cxx/ipc_epiface>
29
30 using L4Re::Dataspace;
31
32 class Vesa_fb :
33   public L4Re::Util::Video::Goos_svr,
34   public L4::Epiface_t<Vesa_fb, L4Re::Video::Goos, Moe::Server_object>
35 {
36 private:
37   l4util_mb_vbe_ctrl_t *vbe;
38   l4util_mb_vbe_mode_t *vbi;
39   unsigned long base_offset;
40   unsigned long map_size;
41
42 public:
43   Vesa_fb(l4util_mb_info_t *mbi);
44   virtual ~Vesa_fb() {}
45 };
46
47 void
48 init_vesa_fb(l4util_mb_info_t *mbi)
49 {
50   static Vesa_fb video(mbi);
51   (void)video;
52 }
53
54 Vesa_fb::Vesa_fb(l4util_mb_info_t *mbi)
55 {
56   if (!(mbi->flags & L4UTIL_MB_VIDEO_INFO))
57     return;
58   vbe = (l4util_mb_vbe_ctrl_t*)(unsigned long)mbi->vbe_ctrl_info;
59   vbi = (l4util_mb_vbe_mode_t*)(unsigned long)mbi->vbe_mode_info;
60   if (!vbe || !vbi)
61     return;
62
63   base_offset = vbi->phys_base & (L4_SUPERPAGESIZE - 1);
64   unsigned long paddr = vbi->phys_base & ~(L4_SUPERPAGESIZE - 1);
65   unsigned long fb_size = 64 * 1024 * vbe->total_memory;
66   map_size = (fb_size + base_offset + L4_SUPERPAGESIZE - 1)
67              & ~(L4_SUPERPAGESIZE - 1);
68
69   unsigned long vaddr
70       = l4_round_size(Moe::Pages::max_addr, L4_SUPERPAGESHIFT);
71   if (vaddr >= Moe::Virt_limit::end - map_size - L4_SUPERPAGESIZE)
72     vaddr = (unsigned long)Single_page_alloc_base::_alloc(map_size);
73   if (vaddr == 0)
74     {
75       L4::cerr << "Failed to get memory for VESA video memory\n";
76       return;
77     }
78
79   switch (l4sigma0_map_iomem(Sigma0_cap, paddr, vaddr, map_size, 1)) 
80     {
81     case -2:
82       L4::cerr << "IPC error mapping video memory\n";
83       return;
84     case -3:
85       L4::cerr << "No fpage received\n";
86       return;
87     default:
88       break;
89     }
90
91   Moe::Dataspace_static *fb = new Moe::Dataspace_static((void*)vaddr, map_size, Moe::Dataspace_static::Writable | L4Re::Dataspace::Map_bufferable);
92
93   _screen_info.width = vbi->x_resolution;
94   _screen_info.height = vbi->y_resolution;
95   _screen_info.flags = L4Re::Video::Goos::F_auto_refresh;
96   _screen_info.pixel_info = L4Re::Video::Pixel_info(vbi);
97
98   _view_info.buffer_offset = base_offset;
99   _view_info.bytes_per_line = vbi->bytes_per_scanline;
100
101   init_infos();
102
103   _fb_ds = L4::cap_cast<L4Re::Dataspace>(object_pool.cap_alloc()->alloc(fb));
104
105   object_pool.cap_alloc()->alloc(this);
106   root_name_space()->register_obj("vesa", 0, this);
107
108   L4::cout << "  VESAFB: " << obj_cap() << _fb_ds
109     << " @" << (void*)(unsigned long)vbi->phys_base
110     << " (size=" << L4::hex << 64*1024*vbe->total_memory << ")\n" << L4::dec;
111
112 }
113