]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/moe/server/src/vesa_fb.cc
ee0f9c4f480baddceddf98c9372574e650502570
[l4.git] / l4 / pkg / moe / server / src / vesa_fb.cc
1 /*
2  * (c) 2008-2009 Technische Universität Dresden
3  * This file is part of TUD:OS and distributed under the terms of the
4  * GNU General Public License 2.
5  * Please see the COPYING-GPL-2 file for details.
6  */
7 #include <l4/util/mb_info.h>
8 #include <l4/sys/consts.h>
9
10 #include <l4/re/dataspace>
11 #include <l4/re/video/goos>
12 #include <l4/re/video/goos-sys.h>
13 #include <l4/re/protocols>
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 "vesa_fb.h"
24
25 #include <l4/re/util/video/goos_svr>
26
27 using L4Re::Dataspace;
28
29 class Vesa_fb : public L4Re::Util::Video::Goos_svr, public Moe::Server_object
30 {
31 private:
32   l4util_mb_vbe_ctrl_t *vbe;
33   l4util_mb_vbe_mode_t *vbi;
34   unsigned long base_offset;
35   unsigned long map_size;
36
37 public:
38   Vesa_fb(l4util_mb_info_t *mbi);
39   virtual ~Vesa_fb() {}
40
41   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios)
42   { return L4Re::Util::Video::Goos_svr::dispatch(obj, ios); }
43 };
44
45
46 void
47 init_vesa_fb(l4util_mb_info_t *mbi)
48 {
49   static Vesa_fb video(mbi);
50   (void)video;
51 }
52
53 Vesa_fb::Vesa_fb(l4util_mb_info_t *mbi)
54 {
55   if (!(mbi->flags & L4UTIL_MB_VIDEO_INFO))
56     return;
57   vbe = (l4util_mb_vbe_ctrl_t*)mbi->vbe_ctrl_info;
58   vbi = (l4util_mb_vbe_mode_t*)mbi->vbe_mode_info;
59   if (!vbe || !vbi)
60     return;
61
62   base_offset = vbi->phys_base & (L4_SUPERPAGESIZE - 1);
63   unsigned long paddr = vbi->phys_base & ~(L4_SUPERPAGESIZE - 1);
64   unsigned long vaddr = 0xa0000000;
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   switch (l4sigma0_map_iomem(Sigma0_cap, paddr, vaddr, map_size, 1)) 
70     {
71     case -2:
72       L4::cerr << "IPC error mapping video memory\n";
73       return;
74     case -3:
75       L4::cerr << "No fpage received\n";
76       return;
77     default:
78       break;
79     }
80
81   Moe::Dataspace_static *fb = new Moe::Dataspace_static((void*)vaddr, map_size, Moe::Dataspace_static::Writable | (L4_FPAGE_BUFFERABLE << 16));
82
83   _screen_info.width = vbi->x_resolution;
84   _screen_info.height = vbi->y_resolution;
85   _screen_info.flags = L4Re::Video::Goos::F_auto_refresh;
86   _screen_info.pixel_info = L4Re::Video::Pixel_info(vbi);
87
88   _view_info.buffer_offset = base_offset;
89   _view_info.bytes_per_line = vbi->bytes_per_scanline;
90   
91   init_infos();
92
93   _fb_ds = L4::cap_cast<L4Re::Dataspace>(object_pool.cap_alloc()->alloc(fb));
94
95   object_pool.cap_alloc()->alloc(this);
96   root_name_space()->register_obj("vesa", L4Re::Util::Names::Obj(0, this));
97
98   L4::cout << "  VESAFB: " << obj_cap() << _fb_ds
99     << " @" << (void*)vbi->phys_base
100     << " (size=" << L4::hex << 64*1024*vbe->total_memory << ")\n" << L4::dec;
101
102 }
103