00001
00002
00011
00012
00013
00014
00015
00016
00017 #include <l4/sys/types.h>
00018 #include <l4/env/errno.h>
00019 #include <l4/sys/ipc.h>
00020 #include <l4/sigma0/kip.h>
00021 #include <l4/util/getopt.h>
00022 #include <l4/rmgr/librmgr.h>
00023 #include <l4/names/libnames.h>
00024 #include <l4/log/l4log.h>
00025 #include <l4/thread/thread.h>
00026 #include <l4/generic_io/types.h>
00027 #include <l4/generic_io/generic_io-server.h>
00028
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032
00033
00034 #include "io.h"
00035 #include "__config.h"
00036 #include "__macros.h"
00037
00038
00039 #include "res.h"
00040 #include "pci.h"
00041 #include "jiffies.h"
00042 #include "events.h"
00043 #include "omega0lib.h"
00044
00045
00046
00047
00048
00051 l4io_info_t io_info;
00052
00054 char LOG_tag[9] = IO_NAMES_STR;
00055
00057 l4_ssize_t l4libc_heapsize = 1 << 20;
00058
00060 const int l4thread_max_threads = IO_MAX_THREADS;
00061
00064 const l4_size_t l4thread_stack_size = 16 << 10;
00065
00066 static int cfg_events;
00067 static int cfg_dev_list = 1;
00068 static char *cfg_platform;
00069
00070
00071
00072
00073
00076 static io_client_t io_self;
00077
00078
00097 long
00098 l4_io_register_client_component (CORBA_Object _dice_corba_obj,
00099 l4_io_drv_t type,
00100 CORBA_Server_Environment *_dice_corba_env)
00101 {
00102 io_client_t *c, *p;
00103 l4io_drv_t *drv = (l4io_drv_t *) & type;
00104
00105
00106 if (!(c = malloc(sizeof(io_client_t))))
00107 {
00108 LOGdL(DEBUG_ERRORS, "getting %ld bytes of mem",
00109 (unsigned long)sizeof(io_client_t));
00110 return -L4_ENOMEM;
00111 }
00112
00113
00114 c->next = NULL;
00115 c->c_l4id = *_dice_corba_obj;
00116 c->drv = *drv;
00117
00118 LOGd(DEBUG_REGDRV, "registering "l4util_idfmt" {%x, %x, %x}",
00119 l4util_idstr(c->c_l4id), (unsigned char) c->drv.src,
00120 (unsigned char) c->drv.dsi, (unsigned char) c->drv.drv_class);
00121
00122 for (p = &io_self; p->next; p = p->next)
00123 ;
00124 p->next = c;
00125
00126 return 0;
00127 }
00128
00146 long
00147 l4_io_unregister_client_component (CORBA_Object _dice_corba_obj,
00148 const l4_threadid_t *client,
00149 CORBA_Server_Environment *_dice_corba_env)
00150 {
00151 io_client_t *c, *p, tmp;
00152
00153 LOGd(DEBUG_REGDRV,
00154 "unregistering "l4util_idfmt" (called by "l4util_idfmt")",
00155 l4util_idstr(*client), l4util_idstr(*_dice_corba_obj));
00156
00157 if (!l4_tasknum_equal(*_dice_corba_obj, io_self.c_l4id) &&
00158 !l4_tasknum_equal(*_dice_corba_obj, *client))
00159
00160 {
00161 LOGd(DEBUG_REGDRV, "=> not allowed");
00162 return -L4_EPERM;
00163 }
00164
00165 tmp.c_l4id = *client;
00166
00167 for (p = &io_self, c = io_self.next; c; p = c, c = c->next)
00168 {
00169 if (client_equal(c, &tmp))
00170 {
00171 p->next = c->next;
00172 return 0;
00173 }
00174 }
00175
00176 LOGd(DEBUG_REGDRV, "=> not found");
00177 return -L4_ENOTFOUND;
00178 }
00179
00194 long
00195 l4_io_map_info_component (CORBA_Object _dice_corba_obj,
00196 l4_snd_fpage_t *info,
00197 CORBA_Server_Environment *_dice_corba_env)
00198 {
00199 io_client_t *c;
00200
00201 c = (io_client_t *) (_dice_corba_env->user_data);
00202
00203
00204
00205
00206 info->snd_base = 0;
00207 info->fpage = l4_fpage((l4_addr_t) & io_info,
00208 L4_LOG2_PAGESIZE, L4_FPAGE_RO, L4_FPAGE_MAP);
00209
00210 LOGd(DEBUG_MAP, "sending info fpage {0x%08lx, 0x%08lx}",
00211 (unsigned long)info->fpage.fp.page << 12, 1UL << info->fpage.fp.size);
00212
00213
00214 return 0;
00215 }
00216
00226 static int io_info_init(void)
00227 {
00228 io_info.magic = L4IO_INFO_MAGIC;
00229 io_info.jiffies = 0;
00230 io_info.hz = IOJIFFIES_HZ;
00231
00232 return 0;
00233 }
00234
00250 static void io_loop(void)
00251 {
00252 CORBA_Server_Environment _env = dice_default_environment;
00253 _env.user_data = (void *) &io_self;
00254
00255 l4_io_server_loop(&_env);
00256
00257 Panic("Left _infinite_ I/O server loop.");
00258 }
00259
00263 static void do_args(int argc, char *argv[])
00264 {
00265 signed char c;
00266
00267 static int long_check;
00268 static int long_optind;
00269 static struct option long_options[] =
00270 {
00271 {"nolist", no_argument, &long_check, 2},
00272 {"include", required_argument, &long_check, 4},
00273 {"exclude", required_argument, &long_check, 5},
00274 {"events", no_argument, &long_check, 7},
00275 {"platform", required_argument, &long_check, 99},
00276 {0, 0, 0, 0}
00277 };
00278
00279
00280 optind = 0;
00281 long_optind = 0;
00282 while (1)
00283 {
00284 c = getopt_long_only(argc, argv, "", long_options, &long_optind);
00285
00286 if (c == -1)
00287 break;
00288
00289 switch (c)
00290 {
00291 case 0:
00292 switch (long_check)
00293 {
00294 case 2:
00295 cfg_dev_list = 0;
00296 LOG_printf("Disabling listing of PCI devices.\n");
00297 break;
00298 case 4:
00299 if(add_device_inclusion(optarg))
00300 LOG_Error("invalid vendor:device string \"%s\"", optarg);
00301 break;
00302 case 5:
00303 if(add_device_exclusion(optarg))
00304 LOG_Error("invalid vendor:device string \"%s\"", optarg);
00305 break;
00306 case 7:
00307 cfg_events = 1;
00308 LOG_printf("Enabling events support.\n");
00309 break;
00310 default:
00311
00312 break;
00313 case 99:
00314 cfg_platform = optarg;
00315 break;
00316 }
00317 break;
00318 default:
00319
00320 break;
00321 }
00322 }
00323 }
00324
00329 int main(int argc, char *argv[])
00330 {
00331 int error;
00332
00333 rmgr_init();
00334
00335 #ifdef ARCH_arm
00336 cfg_platform = "__none_selected__";
00337 #else
00338 cfg_platform = "x86";
00339 #endif
00340
00341 do_args(argc, argv);
00342
00343
00344 if ((error = io_info_init()))
00345 {
00346 LOGdL(DEBUG_ERRORS, "I/O info page initialization failed (%d)", error);
00347 return error;
00348 }
00349
00350
00351 io_self.next = NULL;
00352 io_self.c_l4id = l4thread_l4_id(l4thread_myself());
00353 strcpy(io_self.name, "IO SERVER");
00354 io_self.drv = L4IO_DRV_INVALID;
00355
00356
00357 if ((error = io_jiffies_init()))
00358 {
00359 LOGdL(DEBUG_ERRORS, "jiffies initialization failed (%d)", error);
00360 return error;
00361 }
00362
00363
00364 if ((error = io_res_init(&io_self)))
00365 {
00366 LOGdL(DEBUG_ERRORS, "res initialization failed (%d)\n", error);
00367 return error;
00368 }
00369
00370 if (!l4sigma0_kip_kernel_is_ux())
00371 {
00372 if ((error = io_static_cfg_init(&io_info, cfg_platform)))
00373 {
00374 LOGdL(DEBUG_ERRORS, "static cfg initialization failed (%d)\n", error);
00375 return error;
00376 }
00377
00378 if ((error = io_pci_init(cfg_dev_list)))
00379 {
00380 LOGdL(DEBUG_ERRORS, "pci initialization failed (%d)\n", error);
00381 return error;
00382 }
00383 }
00384 else
00385
00386 if ((error = io_ux_init())) return error;
00387
00388 #ifndef ARCH_arm
00389 if ((error = OMEGA0_init()))
00390 {
00391 LOGdL(DEBUG_ERRORS, "omega0 initialization failed (%d)\n", error);
00392 return error;
00393 }
00394 io_info.omega0 = 1;
00395 #endif
00396
00397
00398 if (!names_register(IO_NAMES_STR))
00399 {
00400 LOGdL(DEBUG_ERRORS, "can't register at names");
00401 return -L4_ENOTFOUND;
00402 }
00403
00404 if (cfg_events) init_events();
00405
00406
00407 io_loop();
00408
00409 exit(0);
00410 }