BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); switch (fdwReason) { case DLL_PROCESS_ATTACH: init_cxx_funcs(); init_lockit(); init_exception(hinstDLL); init_locale(hinstDLL); init_io(hinstDLL); init_misc(hinstDLL); break; case DLL_PROCESS_DETACH: if (lpvReserved) break; free_io(); free_locale(); free_lockit(); free_misc(); break; } return TRUE; }
void hd_scan_misc(hd_data_t *hd_data) { hd_t *hd; hd_res_t *res; int fd, i; char *s = NULL; bios_info_t *bt = NULL; char par[] = "parport0"; int fd_ser0, fd_ser1; if(!hd_probe_feature(hd_data, pr_misc)) return; hd_data->module = mod_misc; /* some clean-up */ remove_hd_entries(hd_data); hd_data->misc = free_misc(hd_data->misc); PROGRESS(9, 0, "kernel log"); read_klog(hd_data); if((hd_data->debug & HD_DEB_MISC)) dump_klog(hd_data); PROGRESS(1, 0, "misc data"); hd_data->misc = new_mem(sizeof *hd_data->misc); /* this is enough to load the module */ fd_ser0 = fd_ser1 = -1; #if !defined(__sparc__) /* On sparc, the close needs too long */ if(hd_probe_feature(hd_data, pr_misc_serial)) { PROGRESS(1, 1, "open serial"); fd_ser0 = open("/dev/ttyS0", O_RDONLY | O_NONBLOCK); fd_ser1 = open("/dev/ttyS1", O_RDONLY | O_NONBLOCK); /* keep the devices open until the resources have been read */ } #endif /* this is enough to load the module */ if(!hd_data->flags.no_parport && hd_probe_feature(hd_data, pr_misc_par)) { PROGRESS(1, 2, "open parallel"); /* what can the BIOS tell us? */ for(hd = hd_data->hd; hd; hd = hd->next) { if( hd->base_class.id == bc_internal && hd->sub_class.id == sc_int_bios && hd->detail && hd->detail->type == hd_detail_bios && hd->detail->bios.data ) break; } if(hd) { bt = hd->detail->bios.data; if(bt->par_port0) { str_printf(&s, 0, "io=0x%x", bt->par_port0); if(bt->par_port1) { str_printf(&s, -1, ",0x%x", bt->par_port1); if(bt->par_port2) str_printf(&s, -1, ",0x%x", bt->par_port2); } str_printf(&s, -1, " irq=none,none,none"); } unload_module(hd_data, "parport_probe"); unload_module(hd_data, "lp"); unload_module(hd_data, "parport_pc"); unload_module(hd_data, "parport"); /* now load it with the right io */ load_module(hd_data, "parport"); load_module_with_params(hd_data, "parport_pc", s); free_mem(s); } /* now load the rest of the modules */ fd = open("/dev/lp0", O_RDONLY | O_NONBLOCK); if(fd >= 0) close(fd); } /* * floppy driver resources are allocated only temporarily, * so we access it just before we read the resources */ if(hd_probe_feature(hd_data, pr_misc_floppy)) { /* look for a floppy *device* entry... */ for(hd = hd_data->hd; hd; hd = hd->next) { if( hd->base_class.id == bc_storage_device && hd->sub_class.id == sc_sdev_floppy && hd->unix_dev_name && !strncmp(hd->unix_dev_name, "/dev/fd", sizeof "/dev/fd" - 1) ) { PROGRESS(1, 3, "read floppy"); i = 5; hd->block0 = read_block0(hd_data, hd->unix_dev_name, &i); hd->is.notready = hd->block0 ? 0 : 1; if(i < 0) { hd->tag.remove = 1; ADD2LOG("misc.floppy: removing floppy entry %u (timed out)\n", hd->idx); } if(!hd->is.notready) { struct hd_geometry geo; int fd; unsigned size, blk_size = 0x200; fd = open(hd->unix_dev_name, O_RDONLY | O_NONBLOCK); if(fd >= 0) { if(!ioctl(fd, HDIO_GETGEO, &geo)) { ADD2LOG("floppy ioctl(geo) ok\n"); res = add_res_entry(&hd->res, new_mem(sizeof *res)); res->disk_geo.type = res_disk_geo; res->disk_geo.cyls = geo.cylinders; res->disk_geo.heads = geo.heads; res->disk_geo.sectors = geo.sectors; res->disk_geo.geotype = geo_logical; size = geo.cylinders * geo.heads * geo.sectors; for(res = hd->res; res; res = res->next) { if(res->any.type == res_size && res->size.unit == size_unit_sectors) { res->size.val1 = size; res->size.val2 = blk_size; break; } } if(!res) { res = add_res_entry(&hd->res, new_mem(sizeof *res)); res->size.type = res_size; res->size.unit = size_unit_sectors; res->size.val1 = size; res->size.val2 = blk_size; } } close(fd); } } break; } } remove_tagged_hd_entries(hd_data); } PROGRESS(2, 1, "io"); read_ioports(hd_data->misc); PROGRESS(2, 2, "dma"); read_dmas(hd_data->misc); PROGRESS(2, 3, "irq"); read_irqs(hd_data->misc); if((hd_data->debug & HD_DEB_MISC)) dump_misc_proc_data(hd_data); if(fd_ser0 >= 0) close(fd_ser0); if(fd_ser1 >= 0) close(fd_ser1); /* now create some system generic entries */ /* FPU */ PROGRESS(3, 0, "FPU"); res = NULL; gather_resources(hd_data->misc, &res, "fpu", 0); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_internal; hd->sub_class.id = sc_int_fpu; hd->res = res; } /* DMA */ PROGRESS(3, 1, "DMA"); res = NULL; gather_resources(hd_data->misc, &res, "dma1", 0); gather_resources(hd_data->misc, &res, "dma2", 0); gather_resources(hd_data->misc, &res, "dma page reg", 0); gather_resources(hd_data->misc, &res, "cascade", W_DMA); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_system; hd->sub_class.id = sc_sys_dma; hd->res = res; } /* PIC */ PROGRESS(3, 2, "PIC"); res = NULL; gather_resources(hd_data->misc, &res, "pic1", 0); gather_resources(hd_data->misc, &res, "pic2", 0); gather_resources(hd_data->misc, &res, "cascade", W_IRQ); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_system; hd->sub_class.id = sc_sys_pic; hd->res = res; } /* timer */ PROGRESS(3, 3, "timer"); res = NULL; gather_resources(hd_data->misc, &res, "timer", 0); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_system; hd->sub_class.id = sc_sys_timer; hd->res = res; } /* real time clock */ PROGRESS(3, 4, "RTC"); res = NULL; gather_resources(hd_data->misc, &res, "rtc", 0); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_system; hd->sub_class.id = sc_sys_rtc; hd->res = res; } /* keyboard */ res = NULL; gather_resources(hd_data->misc, &res, "keyboard", 0); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_input; hd->sub_class.id = sc_inp_keyb; hd->res = res; } /* parallel ports */ for(i = 0; i < 1; i++, par[sizeof par - 2]++) { res = NULL; gather_resources(hd_data->misc, &res, par, 0); if(res) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_comm; hd->sub_class.id = sc_com_par; str_printf(&hd->unix_dev_name, 0, "/dev/lp%d", i); hd->res = res; } } /* floppy controller */ res = NULL; gather_resources(hd_data->misc, &res, "floppy", 0); gather_resources(hd_data->misc, &res, "floppy DIR", 0); if(res) { /* look for an existing entry */ for(hd = hd_data->hd; hd; hd = hd->next) { if(hd->base_class.id == bc_storage && hd->sub_class.id == sc_sto_floppy) break; } /* missing, so create one */ if(!hd) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_storage; hd->sub_class.id = sc_sto_floppy; } hd->res = res; } /* * look for PS/2 port * * The catch is, that sometimes /dev/psaux is accessible only for root, * so the open() may fail but there are irq events registered. * */ fd = open(DEV_PSAUX, O_RDONLY | O_NONBLOCK); if(fd >= 0) close(fd); res = NULL; gather_resources(hd_data->misc, &res, "PS/2 Mouse", 0); if(res || fd >= 0) { hd = add_hd_entry(hd_data, __LINE__, 0); hd->base_class.id = bc_ps2; if(res) { hd->res = res; } } }