1local require = require
2local pairs = pairs
3local collectgarbage = collectgarbage
4
5local _ENV = {};
6local L4 = require("L4");
7
8-- The defaults for loading the services
9loader = L4.default_loader;
10
11local rom = L4.Env.rom;
12
13local bus_rtc;
14local bus_usbhid;
15local bus_gfx;
16local bus_ps2;
17local rtc_if;
18local hid_ev;
19
20
21-- start the IO server, with the given arguments.
22-- @return A capability table, containing all the
23--         capabilities to the buses specified in the config files
24--         of IO.
25function io(busses, ...)
26  bus_rtc    = loader:new_channel();
27  bus_usbhid = loader:new_channel();
28  bus_gfx    = loader:new_channel();
29  bus_ps2    = loader:new_channel();
30
31  local io_caps = {
32    rom = rom;
33    icu = L4.Env.icu;
34    sigma0 = L4.cast(L4.Proto.Factory, L4.Env.sigma0):create(L4.Proto.Sigma0);
35
36    rtc_bus    = bus_rtc:svr();
37    bus_usbhid = bus_usbhid:svr();
38    bus        = bus_ps2:svr();
39    fb_bus     = bus_gfx:svr();
40  };
41
42  for k, v in pairs(busses) do
43    io_caps[k] = v:svr();
44  end
45
46  loader:startv({
47    caps = io_caps,
48    log = {"io", "red"}, l4re_dbg = L4.Dbg.Warn + L4.Dbg.Loader,
49    scheduler = L4.Env.user_factory:create(L4.Proto.Scheduler, 0x90, 0x80)
50  }, "rom/io", ...);
51  return io_caps;
52end
53
54-- Start the RTC server, used on x86 for l4linux
55-- @return The namespace capability of RTC, containing 'rtc'
56--         as service cap.
57function rtc(...)
58
59  rtc_if = loader:new_channel();
60
61  local rtc_caps = {
62    rom  = rom;
63    vbus = bus_rtc;
64    rtc  = rtc_if:svr();
65  };
66
67  -- drop bus_rtc reference it is no longer needed in ned
68  bus_rtc = nil;
69
70  loader:startv({caps = rtc_caps, log = {"rtc", "green"}}, "rom/rtc", ...);
71  return rtc_if;
72end
73
74
75-- Start the HID server.
76-- @return A capability to the hid name space.
77--
78-- Also saves the name-space capability for later use e.g. by gui
79function hid(...)
80  -- do not start the HID Linux on AMD64
81  if L4.Info.arch() == "amd64" then
82    return;
83  end
84  hid_ev = loader:create_namespace({ ev_irq = "ph", ev_buf="ph" });
85
86  local hid_caps = {
87    rom  = rom;
88    vbus = bus_usbhid;
89    rtc  = rtc_if;
90    ev   = hid_ev:m("rws");
91  };
92
93  bus_usbhid = nil;
94  rtc_if = nil;
95
96  loader:startv({
97    caps = hid_caps,
98    log = {"hid", "m"},
99    scheduler = L4.Env.user_factory:create(L4.Proto.Scheduler, 0x80, 0x70)
100  }, "rom/vmlinuzusbv", "init=none", "showpfexc=0", "mem=12M",
101     "l4x_cpus=4", "l4ser.vkey_enable=1", "console=ttyLv0", ...);
102
103  return hid_caps;
104end
105
106
107-- Start the GUI server
108-- @return The capability to the GUI-server name space.
109function gui(svc_caps, fb, ...)
110
111  local gui_caps = {
112    rom  = rom;
113    vbus = bus_ps2;
114    fb   = fb;
115  };
116
117  bus_ps2 = nil;
118
119  for k, v in pairs(svc_caps) do
120    gui_caps[k] = v:svr();
121  end
122
123  local input_drv = "";
124  if not hid_ev then -- run mag with libinput
125    input_drv = "input-libinput";
126  else
127    gui_caps.ev = hid_ev;
128    hid_ev = nil;
129    input_drv = "input-lxdd";
130  end
131
132  loader:start({
133    caps = gui_caps,
134    log = { "gui", "yellow" },
135    scheduler =  L4.Env.user_factory:create(L4.Proto.Scheduler, 0x78, 0x70)
136  },
137  "rom/mag " .. input_drv .." client_fb mag_client", ...);
138
139  return gui_caps;
140end
141
142
143-- Get the Hw frame-buffer capability.
144-- This function either uses the 'vesa' capability provided by moe
145-- or starts fb-drv if 'vesa' is not available.
146-- @return The capability to the Hw Goos object.
147function fb(...)
148  local fb = L4.Env.vesa;
149  if fb then
150    return fb;
151  end
152
153  local fb_caps = {
154    rom  = rom;
155    vbus = bus_gfx;
156    fb   = loader:new_channel():svr(); -- gfx
157  };
158
159  bus_gfx = nil;
160
161  loader:startv({caps = fb_caps, log = {"fb-drv","blue"}}, "rom/fb-drv", "-m", ...);
162
163  return fb_caps.fb:m("rw"); --client
164end
165
166function cleanup()
167  collectgarbage();
168end
169
170return _ENV;
171