static int load_hc_modules() { char module_name[SYS_MAX_PATH_LEN]; size_t bufsize; modules_cookie cookie; struct usb_hc_module_hooks *hooks; int err; int count = 0; // scan through the host controller module dir and load all of them cookie = module_open_list(USB_HC_MODULE_NAME_PREFIX); bufsize = sizeof(module_name); while(read_next_module_name(cookie, module_name, &bufsize) >= NO_ERROR) { bufsize = sizeof(module_name); // reset this for the next iteration err = module_get(module_name, 0, (void **)&hooks); if(err < 0) continue; err = hooks->init_hc(&hc_init_callback, hooks); if(err < 0) { module_put(module_name); // it failed, put it away } count++; } close_module_list(cookie); return count; }
int main( int argc, char **argv ) { char *cfg_file; char *module_name; module_t *module; __get_args( &cfg_file, &module_name, argc, argv ); main_init(); module = module_get( module_name ); config_init( cfg_file, module->cfg_init_cb ); logger_init(); net_init(); http_init(); module->init_cb(); net_main_loop(); return 0; }
int rhine_detect(rhine **rhine_list) { int i, j; pci_module_hooks *pci; pci_info pinfo; rhine *r; *rhine_list = NULL; if(module_get(PCI_BUS_MODULE_NAME, 0, (void **)&pci) < 0) { dprintf("rhine_detect: no pci bus found..\n"); return -1; } for (i = 0; pci->get_nth_pci_info(i, &pinfo) >= NO_ERROR; i++) { for (j = 0; j < sizeof(match)/sizeof(match[0]); j++) { if (pinfo.vendor_id == match[j].vendor && pinfo.device_id == match[j].device) { // we found one dprintf("rhine_detect: found device at pci %d:%d:%d\n", pinfo.bus, pinfo.device, pinfo.function); r = kmalloc(sizeof(rhine)); if (r == NULL) { dprintf("rhine_detect: error allocating memory for rhine structure\n"); continue; } memset(r, 0, sizeof(rhine)); r->irq = pinfo.u.h0.interrupt_line; // find the memory-mapped base int range; for (range = 0; range < 6; range++) { if (pinfo.u.h0.base_registers[range] > 0xffff) { r->phys_base = pinfo.u.h0.base_registers[range]; r->phys_size = pinfo.u.h0.base_register_sizes[range]; break; } else if (pinfo.u.h0.base_registers[range] > 0) { r->io_port = pinfo.u.h0.base_registers[range]; } } if (r->phys_base == 0) { kfree(r); r = NULL; continue; } dprintf("detected rhine at irq %d, memory base 0x%lx, size 0x%lx, io base 0x%lx\n", r->irq, r->phys_base, r->phys_size, r->io_port); // add it to the list r->next = *rhine_list; *rhine_list = r; } } } module_put(PCI_BUS_MODULE_NAME); return *rhine_list ? 0 : ERR_NOT_FOUND; }
status_manager_t *module_get_status_manager(const char *name) { rbh_module_t *mod; mod = module_get(name); if (mod == NULL || mod->mod_ops.mod_get_status_manager == NULL) return NULL; return mod->mod_ops.mod_get_status_manager(); }
int rtl8139_detect(rtl8139 **rtl) { int i; pci_module_hooks *pci; pci_info pinfo; bool foundit = false; if(module_get(PCI_BUS_MODULE_NAME, 0, (void **)&pci) < 0) { dprintf("rtl8139_detect: no pci bus found..\n"); return -1; } for(i = 0; pci->get_nth_pci_info(i, &pinfo) >= NO_ERROR; i++) { if(pinfo.vendor_id == RT_VENDORID && pinfo.device_id == RT_DEVICEID_8139) { foundit = true; break; } } if(!foundit) { dprintf("rtl8139_detect: didn't find device on pci bus\n"); return -1; } // we found one dprintf("rtl8139_detect: found device at pci %d:%d:%d\n", pinfo.bus, pinfo.device, pinfo.function); *rtl = kmalloc(sizeof(rtl8139)); if(*rtl == NULL) { return ERR_NO_MEMORY; } memset(*rtl, 0, sizeof(rtl8139)); (*rtl)->irq = pinfo.u.h0.interrupt_line; // find the memory-mapped base for(i=0; i<6; i++) { if(pinfo.u.h0.base_registers[i] > 0xffff) { (*rtl)->phys_base = pinfo.u.h0.base_registers[i]; (*rtl)->phys_size = pinfo.u.h0.base_register_sizes[i]; break; } else if(pinfo.u.h0.base_registers[i] > 0) { (*rtl)->io_port = pinfo.u.h0.base_registers[i]; } } if((*rtl)->phys_base == 0) { kfree(*rtl); *rtl = NULL; return -1; } dprintf("detected rtl8139 at irq %d, memory base 0x%lx, size 0x%lx\n", (*rtl)->irq, (*rtl)->phys_base, (*rtl)->phys_size); return 0; }
int dev_bootstrap(void) { if(module_get(ISA_MODULE_NAME, 0, (void **)&isa) < 0) { dprintf("keyboard dev_bootstrap: no isa bus found..\n"); return -1; } setup_keyboard(); int_set_io_interrupt_handler(1,&handle_keyboard_interrupt, NULL, "keyb"); devfs_publish_device("keyboard", NULL, &keyboard_hooks); return NO_ERROR; }
int dev_bootstrap(void) { int err = 0; pcnet32 *nic = NULL; pci_module_hooks *bus = NULL; SHOW_FLOW0(3, "entry"); err = module_get(PCI_BUS_MODULE_NAME, 0, (void **)&bus); if(err < 0) { SHOW_FLOW(3, "Error finding ISA bus module: %d", err); return err; } SHOW_FLOW(3, "Got bus module: %p", bus); nic = pcnet32_new(bus, PCNET_INIT_MODE0 | PCNET_INIT_RXLEN_128 | PCNET_INIT_TXLEN_32, 2048, 2048); if (nic == NULL) { SHOW_FLOW0(3, "pcnet_new returned 0."); return ERR_GENERAL; } if (pcnet32_detect(nic) > -1) { if (pcnet32_init(nic) < 0) { SHOW_FLOW0(3, "pcnet_init failed."); pcnet32_delete(nic); return ERR_GENERAL; } pcnet32_start(nic); if (devfs_publish_indexed_device("net/pcnet32", nic, &pcnet32_hooks) < 0) { SHOW_FLOW0(3, "failed to register device /dev/net/pcnet32/0"); return ERR_GENERAL; } } return 0; }
PROCESS_THREAD(eeprom_write_contiki_test, ev, data) { PROCESS_BEGIN(); static config_section_t * led_conf = 0; int i; led_conf = config_cnf_create_section(config_get()); strcpy(led_conf->name, "led"); config_section_set_uint(led_conf, "ddr", 39); config_section_set_uint(led_conf, "port", 40); config_section_set_uint(led_conf, "offset", 0); config_save(); config_close(); config_init(); if (config_open() == -1) alarma(10); modules_init(); devices_init(); if (admin_get_device_by_id(2) && admin_get_device_by_id(1)) { static led_t * led_m = 0; static led_t * led = 0; led_m = (led_t *)admin_get_device_by_id(2)->device; led = (led_t *)admin_get_device_by_id(1)->device; led->init(led); led_m->init(led_m); if (module_get(MODULE_LED1)->config == led_conf) { for (i = 0; i < 10; ++i) { led->on(led); _delay_ms(50); led->off(led); _delay_ms(50); } } led->on(led); led_m->on(led_m); } PROCESS_END(); }
action_scheduler_t *module_get_scheduler(const char *name) { char mod_name[MAX_MOD_NAMELEN]; char *prefix; rbh_module_t *mod; prefix = strchr(name, '.'); if (prefix == NULL) return NULL; memcpy(mod_name, name, prefix - name); mod_name[prefix - name] = '\0'; mod = module_get(mod_name); if (mod == NULL || mod->mod_ops.mod_get_scheduler == NULL) return NULL; return mod->mod_ops.mod_get_scheduler(name); }
int main(int argc, char** argv ) { int moduleId; char value[128]; if( argc!=4){ showUsge(); return 0; } moduleId = atoi(argv[1]); if( moduleId<1 || moduleId>3){ printf("moduleId should be 1-3"); return -1; } module_get(moduleId, argv[2], argv[3], value); printf("%s\n", value); return 0; }
int module_load(const char *krev, char * modname) { struct module_t *mod; char **deps; int i; mod = module_get(krev, modname); if (!mod) { log_print(LOG_ERROR, "Module not found: %s\n", modname); return -1; } /* find dependencies and load those as well */ deps = module_get_deps(mod->map, mod->size); for (i=0; deps[i]; i++) { module_load(krev, deps[i]); free(deps[i]); } free(deps); return 0; }
int nodeup_postmove(int argc, char *argv[]) { int c, i; struct module_t *mod; const char *krev; struct utsname utsbuf; /* We're really just skipping over options here */ while ((c=getopt(argc, argv, "r:f")) != -1) { switch (c) { case 'r': break; case 'f': break; default: log_print(LOG_ERROR, "Unrecognized flag: %c\n", (char) optopt); return -1; } } if (uname(&utsbuf) != 0) { log_print(LOG_ERROR, "Failed to get kernel revision: %s\n", strerror(errno)); return -1; } krev = utsbuf.release; for (i=optind; i < argc; i++) { mod = module_get(krev, argv[i]); if (!mod || !mod->map) continue; log_print(LOG_INFO, "Loading module %s\n", argv[i]); if (modprobe(mod, 0)) log_print(LOG_ERROR, " Insmod failed: %s\n", mod_strerror(errno)); } return 0; }
static void call_xpt_bus_scan( ide_bus_info *bus ) { cam_for_driver_interface *xpt_driver; CCB_HEADER *ccb; xpt_bus_cookie bus_cookie; xpt_device_cookie device_cookie; if( module_get( CAM_FOR_DRIVER_MODULE_NAME, 0, (void **)&xpt_driver ) < 0 ) return; bus_cookie = xpt_driver->get_bus( bus->path_id ); if( bus_cookie == NULL ) goto err; device_cookie = xpt_driver->get_device( bus_cookie, XPT_BUS_GLOBAL_ID, XPT_BUS_GLOBAL_ID ); if( device_cookie == NULL ) goto err1; ccb = xpt_driver->ccb_alloc( device_cookie ); if( ccb == NULL ) goto err2; ccb->cam_func_code = XPT_SCAN_BUS; //ccb->cam_path_id = bus->path_id; ccb->cam_flags = 0; xpt_driver->action( ccb ); xpt_driver->ccb_free( ccb ); err2: xpt_driver->put_device( device_cookie ); err1: xpt_driver->put_bus( bus_cookie ); err: module_put( CAM_FOR_DRIVER_MODULE_NAME ); return; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //plugin_message //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int plugin_message(int tokencount, char *tokens[], bool from_core, module* caller) { char *filename; if (tokencount == 3 && !stricmp(tokens[2], szBActionSave)) { config_save(config_path_mainscript); return 0; } else if (!stricmp(tokens[2], szBActionSaveAs)) { if (tokencount == 4) { config_save(tokens[3]); } else { if ((filename = dialog_file(szFilterScript, "Save Configuration Script", ".rc", config_path_plugin, true))) { config_save(filename); } } return 0; } else if (tokencount == 3 && !stricmp(tokens[2], szBActionRevert)) { plugin_reconfigure(true); return 0; } else if (!stricmp(tokens[2], szBActionLoad)) { if (tokencount == 4) { config_load2(tokens[3], caller); return 0; } else if (tokencount == 3) { if ((filename = dialog_file(szFilterScript, "Load Configuration Script", ".rc", config_path_plugin, false))) { config_load2(filename, caller); } return 0; } else if (tokencount == 6) { if (0 == stricmp(tokens[4], "from")) { config_load(tokens[5], caller, tokens[3]); return 0; } else if (0 == stricmp(tokens[4], "into")) { config_load(tokens[3], module_get(tokens[5])); return 0; } } else if (tokencount == 8 && 0 == stricmp(tokens[4], "from") && 0 == stricmp(tokens[6], "into")) { config_load(tokens[5], module_get(tokens[7]), tokens[3]); return 0; } } else if (!stricmp(tokens[2], szBActionAbout)) { if (tokencount == 3) { MessageBox(NULL, szPluginAbout, szVersion, MB_OK|MB_SYSTEMMODAL); return 0; } else if (tokencount == 4 && !stricmp(tokens[3], "LastControl")) { MessageBox(NULL, szPluginAboutLastControl, szAppName, MB_OK|MB_SYSTEMMODAL); return 0; } else if (tokencount == 4 && !stricmp(tokens[3], "QuickHelp")) { MessageBox(NULL, szPluginAboutQuickRef, szAppName, MB_OK|MB_SYSTEMMODAL); return 0; } } else if (!stricmp(tokens[2], szBActionEdit)) { //SendMessage(plugin_hwnd_blackbox, BB_EDITFILE, (WPARAM)-1, (LPARAM) config_path_mainscript); //return 0; char temp[MAX_PATH]; GetBlackboxEditor(temp); BBExecute(NULL, "",temp , config_path_mainscript, NULL, SW_SHOWNORMAL, false); return 0; } else if (tokencount == 5 && !stricmp(tokens[2], szBActionSetPluginProperty)) { for (struct plugin_properties *p = plugin_properties; p->key; p++) if (p->data && 0 == stricmp(tokens[3], p->key)) { switch (p->type) { case M_BOL: if (config_set_bool(tokens[4], (bool*)p->data)) break; return 1; case M_INT: if (config_set_int(tokens[4], (int*)p->data)) break; return 1; case M_STR: if (config_set_str(tokens[4], (char**)p->data)) break; return 1; default: return 1; } if (p->update) control_invalidate(); if (from_core) menu_update_global(); return 0; } } else if (tokencount == 4 && !stricmp(tokens[2], szBActionOnLoad) ) { config_set_str(tokens[3],&(globalmodule.actions[MODULE_ACTION_ONLOAD])); return 0; } else if (tokencount == 4 && !stricmp(tokens[2], szBActionOnUnload) ) { config_set_str(tokens[3],&(globalmodule.actions[MODULE_ACTION_ONUNLOAD])); return 0; } return 1; }
static int find_and_map(void) { int err; pci_module_hooks *pci; pci_info pinfo; aspace_id kai = vm_get_kernel_aspace_id(); int i; bool foundit; if(module_get(PCI_BUS_MODULE_NAME, 0, (void **)&pci) < 0) { dprintf("vmware: no pci bus found..\n"); err = ERR_NOT_FOUND; goto error0; } foundit = false; for(i = 0; pci->get_nth_pci_info(i, &pinfo) >= NO_ERROR; i++) { dprintf("vmware: looking at 0x%x:0x%x\n", pinfo.vendor_id, pinfo.device_id); if(pinfo.vendor_id == PCI_VENDOR_ID_VMWARE && (pinfo.device_id == PCI_DEVICE_ID_VMWARE_SVGA2 || pinfo.device_id == PCI_DEVICE_ID_VMWARE_SVGA)) { foundit = true; break; } } if(!foundit) { dprintf("vmware: didn't find device on pci bus\n"); err = ERR_NOT_FOUND; goto error0; } switch(pinfo.device_id) { case PCI_DEVICE_ID_VMWARE_SVGA: dprintf("vmware SVGA device detected at pci %d:%d:%d\n", pinfo.bus, pinfo.device, pinfo.function); vcons.index_port = SVGA_LEGACY_BASE_PORT + SVGA_INDEX_PORT * 4; vcons.value_port = SVGA_LEGACY_BASE_PORT + SVGA_VALUE_PORT * 4; break; case PCI_DEVICE_ID_VMWARE_SVGA2: dprintf("vmware SVGA2 device detected at pci %d:%d:%d\n", pinfo.bus, pinfo.device, pinfo.function); vcons.index_port = pinfo.u.h0.base_registers[0] + SVGA_INDEX_PORT; vcons.value_port = pinfo.u.h0.base_registers[0] + SVGA_VALUE_PORT; break; } vcons.fb_phys_base = pinfo.u.h0.base_registers[1]; vcons.fb_size = MIN(pinfo.u.h0.base_register_sizes[1], SVGA_FB_MAX_SIZE); vcons.fifo_phys_base = pinfo.u.h0.base_registers[2]; vcons.fifo_size = MIN(pinfo.u.h0.base_register_sizes[2], SVGA_MEM_SIZE); dprintf("vmware: index port 0x%x, value port 0x%x\n", vcons.index_port, vcons.value_port); dprintf("vmware: phys base 0x%x, size 0x%X\n", vcons.fb_phys_base, vcons.fb_size); dprintf("vmware: fifo phys base 0x%x, fifo size 0x%X\n", vcons.fifo_phys_base, vcons.fifo_size); vcons.fb_region = vm_map_physical_memory(kai, "vmw:fb", (void **)&vcons.fb_base, REGION_ADDR_ANY_ADDRESS, vcons.fb_size, LOCK_KERNEL | LOCK_RW, vcons.fb_phys_base); if (vcons.fb_region < 0) { err = vcons.fb_region; dprintf("Error mapping frame buffer: %x\n", err); goto error0; } vcons.fifo_region = vm_map_physical_memory(kai, "vmw:fifo", (void **)&vcons.fifo_base, REGION_ADDR_ANY_ADDRESS, vcons.fifo_size, LOCK_KERNEL | LOCK_RW, vcons.fifo_phys_base); if (vcons.fifo_region < 0) { err = vcons.fifo_region; dprintf("Error mapping vmw::fifo: %x\n", err); goto error1; } // XXX this makes the emulation unhappy (crashes vmware) // out_reg(SVGA_REG_ID, SVGA_ID_2); // vcons.svga_id = in_reg(SVGA_REG_ID); // dprintf("vmware: svga version %d\n", vcons.svga_id); vcons.bits_per_pixel = in_reg(SVGA_REG_BITS_PER_PIXEL); dprintf("vmware: bpp %d\n", vcons.bits_per_pixel); err = NO_ERROR; goto error0; // unmap vcons.fifo_region vm_delete_region(kai, vcons.fifo_region); error1: // unmap vcons.fb_region vm_delete_region(kai, vcons.fb_region); error0: return err; }