4 #include <barrelfish/barrelfish.h>
5 #include <barrelfish/spawn_client.h>
8 #include <if/monitor_blocking_rpcclient_defs.h>
13 extern char **environ;
16 errval_t default_start_function(coreid_t where, struct module_info* mi,
20 errval_t err = SYS_ERR_OK;
22 * XXX: there may be more device using this driver, so starting it a second time
25 if (is_started(mi) && strcmp("xeon_phi",mi->binary)) {
26 return KALUGA_ERR_DRIVER_ALREADY_STARTED;
29 if (!is_auto_driver(mi)) {
30 return KALUGA_ERR_DRIVER_NOT_AUTO;
33 // Construct additional command line arguments containing pci-id.
34 // We need one extra entry for the new argument.
35 uint64_t vendor_id, device_id, bus, dev, fun;
36 char **argv = mi->argv;
39 err = oct_read(record,
40 "_ { bus: %d, device: %d, function: %d, vendor: %d, device_id: %d }",
41 &bus, &dev, &fun, &vendor_id, &device_id);
44 // We assume that we're starting a device if the query above succeeds
45 // and therefore append the pci vendor and device id to the argument
47 argv = malloc((mi->argc+1) * sizeof(char *));
48 memcpy(argv, mi->argv, mi->argc * sizeof(char *));
49 char *pci_id = malloc(26);
50 // Make sure pci vendor and device id fit into our argument
51 assert(vendor_id < 0x9999 && device_id < 0x9999);
52 snprintf(pci_id, 26, "%04"PRIx64":%04"PRIx64":%04"PRIx64":%04"
53 PRIx64":%04"PRIx64, vendor_id, device_id, bus, dev, fun);
55 argv[mi->argc] = pci_id;
56 argv[mi->argc+1] = NULL;
60 if (is_started(mi) && !strcmp("xeon_phi",mi->binary)) {
64 err = spawn_program(where, mi->path, argv,
65 environ, 0, &mi->did);
67 if (err_is_fail(err)) {
68 DEBUG_ERR(err, "Spawning %s failed.", mi->path);
71 // alloc'd string is the last of our array
80 errval_t start_networking(coreid_t core,
81 struct module_info* driver,
84 assert(driver != NULL);
85 errval_t err = SYS_ERR_OK;
87 if (is_started(driver)) {
88 return KALUGA_ERR_DRIVER_ALREADY_STARTED;
91 if (!is_auto_driver(driver)) {
92 return KALUGA_ERR_DRIVER_NOT_AUTO;
95 struct module_info* netd = find_module("netd");
96 if (netd == NULL || !is_auto_driver(netd)) {
97 KALUGA_DEBUG("netd not found or not declared as auto.");
98 return KALUGA_ERR_DRIVER_NOT_AUTO;
101 struct module_info* ngd_mng = find_module("NGD_mng");
102 if (ngd_mng == NULL || !is_auto_driver(ngd_mng)) {
103 KALUGA_DEBUG("NGD_mng not found or not declared as auto.");
104 return KALUGA_ERR_DRIVER_NOT_AUTO;
107 err = spawn_program(core,
113 if (err_is_fail(err)) {
114 DEBUG_ERR(err, "Spawning %s failed.", driver->path);
118 // XXX: Manually add cardname (overwrite first (auto) argument)
119 // +Weird convention, e1000n binary but cardname=e1000
121 strcmp(driver->binary, "e1000n") == 0 ? "e1000" : driver->binary;
123 size_t name_len = strlen("cardname=") + strlen(cardname) + 1;
124 char* card_argument = malloc(name_len);
125 sprintf(card_argument, "cardname=%s", cardname);
126 printf("############# starting network with arguments %s\n", card_argument);
128 // Spawn netd and ngd_mng
129 netd->argv[0] = card_argument;
130 err = spawn_program(core, netd->path, netd->argv, environ, 0, &netd->did);
132 ngd_mng->argv[0] = card_argument;
133 err = spawn_program(core,
144 /* errval_t start_usb_manager(void) */
147 /* struct module_info* driver = find_module("usb_manager"); */
148 /* if (driver == NULL || !is_auto_driver(driver)) { */
149 /* KALUGA_DEBUG("NGD_mng not found or not declared as auto."); */
150 /* return KALUGA_ERR_DRIVER_NOT_AUTO; */
153 /* debug_printf("doing pandaboard related setup...\n"); */
156 /* struct monitor_blocking_rpc_client *cl = get_monitor_blocking_rpc_client(); */
157 /* assert(cl != NULL); */
159 /* // Request I/O Cap */
160 /* struct capref requested_caps; */
161 /* errval_t error_code; */
163 /* err = cl->vtbl.get_io_cap(cl, &requested_caps, &error_code); */
164 /* assert(err_is_ok(err) && err_is_ok(error_code)); */
166 /* // Copy into correct slot */
168 /* struct capref device_range_cap = NULL_CAP; */
170 /* err = slot_alloc(&device_range_cap); */
171 /* if (err_is_fail(err)) { */
172 /* printf("slot alloc failed. Step 1\n"); */
175 /* struct capref tiler_cap = NULL_CAP; */
177 /* err = slot_alloc(&tiler_cap); */
178 /* if (err_is_fail(err)) { */
179 /* DEBUG_ERR(err, "slot_alloc failed. Step 1\n"); */
183 /* err = cap_retype(device_range_cap, requested_caps, ObjType_DevFrame, 29); */
185 /* struct capref l3_ocm_ram = NULL_CAP; */
187 /* err = slot_alloc(&l3_ocm_ram); */
188 /* if (err_is_fail(err)) { */
189 /* DEBUG_ERR(err, "slot_alloc failed. Step 2\n"); */
193 /* err = cap_retype(l3_ocm_ram, device_range_cap, ObjType_DevFrame, 26); */
194 /* if (err_is_fail(err)) { */
195 /* DEBUG_ERR(err, "failed to retype the dev cap. Step 3\n"); */
199 /* struct capref l3_config_registers_cap; */
200 /* err = slot_alloc(&l3_config_registers_cap); */
201 /* if (err_is_fail(err)) { */
202 /* DEBUG_ERR(err, "slot alloc failed. Step 4\n"); */
206 /* struct capref l4_domains_cap; */
207 /* err = slot_alloc(&l4_domains_cap); */
208 /* if (err_is_fail(err)) { */
209 /* DEBUG_ERR(err, "slot_alloc failed. Step 5\n"); */
213 /* struct capref emif_registers_cap; */
214 /* err = slot_alloc(&emif_registers_cap); */
215 /* if (err_is_fail(err)) { */
216 /* DEBUG_ERR(err, "slot_alloc failed. Step 6\n"); */
220 /* struct capref gpmc_iss_cap; */
221 /* err = slot_alloc(&gpmc_iss_cap); */
222 /* if (err_is_fail(err)) { */
223 /* DEBUG_ERR(err, "slot_alloc failed. Step 7\n"); */
227 /* struct capref l3_emu_m3_sgx_cap; */
228 /* err = slot_alloc(&l3_emu_m3_sgx_cap); */
229 /* if (err_is_fail(err)) { */
230 /* DEBUG_ERR(err, "slot_alloc failed. Step 8\n"); */
234 /* struct capref display_iva_cap; */
235 /* err = slot_alloc(&display_iva_cap); */
236 /* if (err_is_fail(err)) { */
237 /* DEBUG_ERR(err, "slot_alloc failed. Step 9\n"); */
240 /* struct capref tmp_cap = display_iva_cap; */
241 /* tmp_cap.slot++; */
242 /* cap_delete(tmp_cap); */
244 /* struct capref l4_PER_domain_cap; */
245 /* err = slot_alloc(&l4_PER_domain_cap); */
246 /* if (err_is_fail(err)) { */
247 /* DEBUG_ERR(err, "slot_alloc failed. Step 12\n"); */
251 /* struct capref l4_ABE_domain_cap; */
252 /* err = slot_alloc(&l4_ABE_domain_cap); */
253 /* if (err_is_fail(err)) { */
254 /* DEBUG_ERR(err, "slot_alloc failed. Step 11\n"); */
258 /* struct capref l4_CFG_domain_cap; */
259 /* err = slot_alloc(&l4_CFG_domain_cap); */
260 /* if (err_is_fail(err)) { */
261 /* DEBUG_ERR(err, "slot_alloc failed. Step 12\n"); */
265 /* err = cap_retype(l4_PER_domain_cap, l4_domains_cap, ObjType_DevFrame, 24); */
266 /* if (err_is_fail(err)) { */
267 /* DEBUG_ERR(err, "failed to retype the cap. Step 13\n"); */
270 /* tmp_cap = l4_CFG_domain_cap; */
271 /* tmp_cap.slot++; */
272 /* cap_delete(tmp_cap); */
274 /* struct frame_identity frameid; // = { 0, 0 }; */
276 /* err = invoke_frame_identify(l4_CFG_domain_cap, &frameid); */
277 /* if (err_is_fail(err)) { */
278 /* DEBUG_ERR(err, "could not identify the frame. Step 14\n"); */
281 /* // get the 32 bit */
282 /* uint32_t last = (uint32_t) (0xFFFFFFFF & (frameid.base)); */
283 /* uint32_t size2 = frameid.bits; */
285 /* /\* the L4 CFG domain cap must have address 0x4A000000 *\/ */
286 /* assert(last == 0x4a000000); */
288 /* /\* the size of the L4 CFG domain is 16k *\/ */
289 /* assert(((1 << size2) / 1024) == (16 * 1024)); */
291 /* #define USB_SUBSYSTEM_L4_OFFSET 0x00062000 */
292 /* //#define USB_OHCI_OFFSET (0x000A9000-USB_SUBSYSTEM_L4_OFFSET) */
293 /* #define USB_OHCI_OFFSET 0x00002800 */
294 /* #define USB_EHCI_OFFSET 0x00002C00 */
296 /* #define USB_ARM_EHCI_IRQ 109 */
298 /* uint32_t tmp = (uint32_t) USB_EHCI_OFFSET + USB_SUBSYSTEM_L4_OFFSET; */
301 /* uint8_t offset = 0; */
302 /* driver->cmdargs = buf; */
303 /* driver->argc = 3; */
304 /* driver->argv[0] = driver->cmdargs+0; */
306 /* snprintf(buf+offset, 255-offset, "ehci\0"); */
307 /* offset += strlen(driver->argv[0])+1; */
308 /* driver->argv[1] = driver->cmdargs+offset; */
309 /* snprintf(buf+offset, 255-offset, "%u\0", tmp); */
310 /* offset += strlen(driver->argv[1])+1; */
311 /* driver->argv[2] = driver->cmdargs+offset; */
312 /* snprintf(buf+offset, 255-offset, "%u\0", USB_ARM_EHCI_IRQ); */
314 /* err = SYS_ERR_OK; */
315 /* coreid_t core = 0; */
317 /* if (is_started(driver)) { */
318 /* debug_printf("driver is already started..."); */
319 /* return KALUGA_ERR_DRIVER_ALREADY_STARTED; */
322 /* err = spawn_program_with_caps(core, driver->path, driver->argv, environ, */
323 /* NULL_CAP, l4_CFG_domain_cap, 0, &driver->did); */
324 /* if (err_is_fail(err)) { */
325 /* DEBUG_ERR(err, "Spawning %s failed.", driver->path); */