3 * \brief Device manager for Barrelfish.
5 * Interacts with the SKB / PCI to start cores, drivers etc.
10 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
11 * All rights reserved.
13 * This file is distributed under the terms in the attached LICENSE file.
14 * If you do not find this file, copies can be found by writing to:
15 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
23 #include <errors/errno.h>
25 #include <barrelfish/barrelfish.h>
26 #include <barrelfish/cpu_arch.h>
27 #include <barrelfish/nameservice_client.h>
29 #include <if/monitor_defs.h>
32 #include <octopus/octopus.h>
37 coreid_t my_core_id = 0; // Core ID
38 uint32_t my_arch_id = 0; // APIC ID
40 extern char **environ;
43 static void add_start_function_overrides(void)
45 set_start_function("e1000n", start_networking);
46 set_start_function("rtl8029", start_networking);
49 static void parse_arguments(int argc, char** argv)
51 for (int i = 1; i < argc; i++) {
52 if (strncmp(argv[i], "apicid=", sizeof("apicid")) == 0) {
53 my_arch_id = strtol(argv[i] + sizeof("apicid"), NULL, 10);
55 else if(strcmp(argv[i], "boot") == 0) {
61 static inline errval_t wait_for_pci(void)
64 return nameservice_blocking_lookup("pci_discovery_done", &iref);
67 int main(int argc, char** argv)
74 coreid_t my_core_id = disp_get_core_id();
75 parse_arguments(argc, argv);
77 // We need to run on core 0
78 // (we are responsible for booting all the other cores)
79 assert(my_core_id == BSP_CORE_ID);
80 printf("Kaluga running.\n");
82 debug_printf("Kaluga running on ARM. Skipping skb_client_connect()...\n");
85 err = skb_client_connect();
86 if (err_is_fail(err)) {
87 USER_PANIC_ERR(err, "Connect to SKB.");
90 // Make sure the driver db is loaded
91 err = skb_execute("[device_db].");
92 if (err_is_fail(err)) {
93 USER_PANIC_ERR(err, "Device DB not loaded.");
96 printf("Kaluga: intializing octopus\n");
99 if (err_is_fail(err)) {
100 USER_PANIC_ERR(err, "Initialize octopus service.");
103 printf("Kaluga: parse boot modules...\n");
105 err = init_boot_modules();
106 if (err_is_fail(err)) {
107 USER_PANIC_ERR(err, "Parse boot modules.");
109 add_start_function_overrides();
111 debug_printf("Kaluga running on ARM. Skipping oct_barrier_enter()...\n");
113 // The current boot protocol needs us to have
114 // knowledge about how many CPUs are available at boot
115 // time in order to start-up properly.
117 err = oct_barrier_enter("barrier.acpi", &record, 2);
121 debug_printf("Kaluga running on ARM. Skipping cores(), pci_root_bridge(), ...\n");
123 err = start_sdcard();
124 assert(err_is_ok(err));
127 err = watch_for_cores();
128 if (err_is_fail(err)) {
129 USER_PANIC_ERR(err, "Watching cores.");
132 printf("Kaluga: pci_root_bridge\n");
134 err = watch_for_pci_root_bridge();
135 if (err_is_fail(err)) {
136 USER_PANIC_ERR(err, "Watching PCI root bridges.");
139 printf("Kaluga: pci_devices\n");
141 err = watch_for_pci_devices();
142 if (err_is_fail(err)) {
143 USER_PANIC_ERR(err, "Watching PCI devices.");
146 // XXX: This is a bit silly, I add this record
147 // because it was previously in spawnd so
148 // there may be code out there who relies on this
149 // It might be better to get rid of this completely
150 err = oct_set("all_spawnds_up { iref: 0 }");
151 assert(err_is_ok(err));
153 printf("Kaluga: THC_Finish()\n");