2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
10 #include <l4/sys/capability>
12 #include <l4/re/util/cap_alloc>
13 #include <l4/re/namespace>
15 #include <l4/re/error_helper>
16 #include <l4/re/dataspace>
17 #include <l4/util/kip.h>
18 #include <l4/cxx/iostream>
21 #include "hw_root_bus.h"
22 #include "hw_device.h"
28 #include "vbus_factory.h"
29 #include "phys_space.h"
43 #include "cfg_parser.h"
45 using L4Re::Util::Auto_cap;
47 class Io_config_x : public Io_config
50 Io_config_x() : _do_transparent_msi(false) {}
52 bool transparent_msi(Hw::Device *) const
53 { return _do_transparent_msi; }
55 bool legacy_ide_resources(Hw::Device *) const
58 bool expansion_rom(Hw::Device *) const
61 void set_transparent_msi(bool v) { _do_transparent_msi = v; }
63 int verbose() const { return _verbose_lvl; }
64 void inc_verbosity() { ++_verbose_lvl; }
67 bool _do_transparent_msi;
71 static Io_config_x _my_cfg __attribute__((init_priority(30000)));
72 Io_config *Io_config::cfg = &_my_cfg;
78 static Hw::Root_bus _sb("System Bus");
89 template< typename X >
90 char const *type_name(X const &x)
92 char *n = const_cast<char *>(typeid(x).name());
99 Device::iterator i = Device::iterator(0, d, 100);
100 for (; i != d->end(); ++i)
102 for (int x = 0; x < i->depth(); ++x)
104 printf("%s: %s \"%s\"\n",
105 type_name(*i), i->name(),
106 i->hid() ? i->hid() : "");
107 if (dlevel(DBG_INFO))
108 i->dump(i->depth() * 2);
109 if (dlevel(DBG_DEBUG))
110 for (Resource_list::iterator r = i->resources()->begin();
111 r != i->resources()->end(); ++r)
113 r->dump(i->depth() * 2 + 2);
120 icu = L4Re::Env::env()->get_cap<L4::Icu>("icu");
127 struct Add_system_bus
129 void operator () (Vi::Device *dev)
131 Vi::System_bus *b = dynamic_cast<Vi::System_bus*>(dev);
134 d_printf(DBG_ERR, "ERROR: found non system-bus device as root device, ignored\n");
138 b->request_child_resources();
139 b->allocate_pending_child_resources();
140 b->setup_resources();
141 if (!registry->register_obj(b, b->name()).is_valid())
143 d_printf(DBG_WARN, "WARNING: Service registration failed: '%s'\n", b->name());
150 read_config(char const *cfg_file)
152 Vi::Device *vdev = 0;
154 d_printf(DBG_INFO, "Loading: config '%s'\n", cfg_file);
157 int fd = open(cfg_file, O_RDONLY);
161 d_printf(DBG_ERR, "ERROR: failed to open config file '%s'\n", cfg_file);
168 d_printf(DBG_ERR, "ERROR: failed to stat config file '%s'\n", cfg_file);
172 void *adr = mmap(NULL, sd.st_size, PROT_READ, MAP_SHARED, fd, 0);
173 if (adr == MAP_FAILED)
175 d_printf(DBG_ERR, "ERROR: failed to mmap config file '%s'\n", cfg_file);
179 char const *config_file = (char const *)adr;
181 cfg::Scanner s(config_file, config_file + sd.st_size, cfg_file);
182 cfg::Parser p(&s, 0, vdev, system_bus());
185 munmap(adr, sd.st_size);
190 std::for_each(Vi::Device::iterator(0, vdev, 0), Vi::Device::end(), Add_system_bus());
192 if (dlevel(DBG_DEBUG))
199 arg_init(int argc, char * const *argv, Io_config_x *cfg)
206 struct option opts[] =
208 { "verbose", 0, 0, 'v' },
209 { "transparent-msi", 0, 0, 1 },
213 c = getopt_long(argc, argv, "v", opts, &optidx);
220 _my_cfg.inc_verbosity();
223 d_printf(DBG_INFO, "Enabling transparent MSIs\n");
224 cfg->set_transparent_msi(true);
233 run(int argc, char * const *argv)
235 int argfileidx = arg_init(argc, argv, &_my_cfg);
237 printf("Io service\n");
238 set_debug_level(Io_config::cfg->verbose());
240 d_printf(DBG_ERR, "Verboseness level: %d\n", Io_config::cfg->verbose());
244 if (dlevel(DBG_DEBUG))
245 Phys_space::space.dump();
247 #if defined(ARCH_x86) || defined(ARCH_amd64)
248 bool is_ux = l4util_kip_kernel_is_ux(l4re_kip());
249 //res_get_ioport(0xcf8, 4);
250 res_get_ioport(0, 16);
256 system_bus()->plugin();
258 #if defined(ARCH_x86) || defined(ARCH_amd64)
260 ux_setup(system_bus());
263 for (; argfileidx < argc; ++argfileidx)
264 read_config(argv[argfileidx]);
266 if (dlevel(DBG_DEBUG))
268 printf("Real Hardware -----------------------------------\n");
272 fprintf(stderr, "Ready. Waiting for request.\n");
279 main(int argc, char * const *argv)
283 return run(argc, argv);
285 catch (L4::Runtime_error &e)
287 L4::cerr << "FATAL uncought exception: " << e
288 << "\nterminating...\n";
293 L4::cerr << "FATAL uncought exception of unknown type\n"
294 << "terminating...\n";