static int mem_modevent(module_t mod, int type, void *data) { switch(type) { case MOD_LOAD: if (bootverbose) printf("mem: <memory & I/O>\n"); /* Initialise memory range handling */ if (mem_range_softc.mr_op != NULL) mem_range_softc.mr_op->init(&mem_range_softc); memdev = make_dev(&mem_cdevsw, 0, UID_ROOT, GID_KMEM, 0640, "mem"); kmemdev = make_dev(&mem_cdevsw, 1, UID_ROOT, GID_KMEM, 0640, "kmem"); iodev = make_dev(&mem_cdevsw, 14, UID_ROOT, GID_WHEEL, 0600, "io"); return (0); case MOD_UNLOAD: destroy_dev(memdev); destroy_dev(kmemdev); destroy_dev(iodev); return (0); case MOD_SHUTDOWN: return (0); default: return (EOPNOTSUPP); } }
static int streams_modevent(module_t mod, int type, void *unused) { switch (type) { case MOD_LOAD: dt_ptm = make_dev(&streams_cdevsw, dev_ptm, 0, 0, 0666, "ptm"); dt_arp = make_dev(&streams_cdevsw, dev_arp, 0, 0, 0666, "arp"); dt_icmp = make_dev(&streams_cdevsw, dev_icmp, 0, 0, 0666, "icmp"); dt_ip = make_dev(&streams_cdevsw, dev_ip, 0, 0, 0666, "ip"); dt_tcp = make_dev(&streams_cdevsw, dev_tcp, 0, 0, 0666, "tcp"); dt_udp = make_dev(&streams_cdevsw, dev_udp, 0, 0, 0666, "udp"); dt_rawip = make_dev(&streams_cdevsw, dev_rawip, 0, 0, 0666, "rawip"); dt_unix_dgram = make_dev(&streams_cdevsw, dev_unix_dgram, 0, 0, 0666, "ticlts"); dt_unix_stream = make_dev(&streams_cdevsw, dev_unix_stream, 0, 0, 0666, "ticots"); dt_unix_ord_stream = make_dev(&streams_cdevsw, dev_unix_ord_stream, 0, 0, 0666, "ticotsord"); if (! (dt_ptm && dt_arp && dt_icmp && dt_ip && dt_tcp && dt_udp && dt_rawip && dt_unix_dgram && dt_unix_stream && dt_unix_ord_stream)) { printf("WARNING: device config for STREAMS failed\n"); printf("Suggest unloading streams KLD\n"); } return 0; case MOD_UNLOAD: /* XXX should check to see if it's busy first */ destroy_dev(dt_ptm); destroy_dev(dt_arp); destroy_dev(dt_icmp); destroy_dev(dt_ip); destroy_dev(dt_tcp); destroy_dev(dt_udp); destroy_dev(dt_rawip); destroy_dev(dt_unix_dgram); destroy_dev(dt_unix_stream); destroy_dev(dt_unix_ord_stream); return 0; default: return EOPNOTSUPP; break; } return 0; }
/* * pti_done() releases the reference and checks to see if both sides have * been closed on a unix98 pty, allowing us to destroy the device and * release resources. * * We do not release resources on non-unix98 ptys. Those are left * statically allocated. */ static void pti_done(struct pt_ioctl *pti) { lwkt_gettoken(&tty_token); if (--pti->pt_refs == 0) { #ifdef UNIX98_PTYS cdev_t dev; int uminor_no; /* * Only unix09 ptys are freed up */ if ((pti->pt_flags & PF_UNIX98) == 0) { lwkt_reltoken(&tty_token); return; } /* * Interlock open attempts against termination by setting * PF_TERMINATED. This allows us to block while cleaning * out the device infrastructure. * * Do not terminate the tty if it still has a session * association (t_refs). */ if ((pti->pt_flags & (PF_SOPEN|PF_MOPEN)) == 0 && pti->pt_tty.t_refs == 0) { pti->pt_flags |= PF_TERMINATED; uminor_no = pti->pt_uminor; if ((dev = pti->devs) != NULL) { dev->si_drv1 = NULL; pti->devs = NULL; destroy_dev(dev); } if ((dev = pti->devc) != NULL) { dev->si_drv1 = NULL; pti->devc = NULL; destroy_dev(dev); } ttyunregister(&pti->pt_tty); devfs_clone_bitmap_put(&DEVFS_CLONE_BITMAP(pty), uminor_no); kfree(pti, M_PTY); } #endif } lwkt_reltoken(&tty_token); }
static int dektec_detach (device_t dev) { struct dektec_sc *sc = (struct dektec_sc *) device_get_softc (dev); if (sc->legacy_plx) reset_plx (dev); free_buffer (dev, sc, &sc->rx_buffer); free_buffer (dev, sc, &sc->tx_buffer); destroy_buffer (sc, &sc->tx_buffer); destroy_buffer (sc, &sc->rx_buffer); bus_dma_tag_destroy (sc->desc_dma_tag); bus_dma_tag_destroy (sc->buffer_dma_tag); bus_teardown_intr (dev, sc->irq_res, sc->irq_cookie); bus_release_resource (dev, SYS_RES_IRQ, sc->irq_id, sc->irq_res); if (sc->legacy_plx) { bus_release_resource (dev, SYS_RES_MEMORY, sc->dta_base_id, sc->dta_base_res); bus_release_resource (dev, SYS_RES_MEMORY, sc->plx_base_id, sc->plx_base_res); } else { bus_release_resource (dev, SYS_RES_MEMORY, sc->dta_base_id, sc->dta_base_res); } destroy_dev (sc->cdev); mtx_destroy (&sc->dektec_mtx); return 0; }
int pccard_device_destroy(struct pccard_softc *sc) { if (sc->cisdev) destroy_dev(sc->cisdev); return (0); }
/* Stop IR module */ int sms1xxx_ir_exit(struct sms1xxx_softc *sc) { TRACE(TRACE_IR,"\n"); if(!sc->ir.module_started) { return (ENXIO); } /* Wake up reader */ if(sc->ir.state & IR_SLEEP) { wakeup(&sc->ir); } /* Destroy device */ if(sc->ir.dev != NULL) { TRACE(TRACE_MODULE,"destroying ir0, addr=%p\n",sc->ir.dev); destroy_dev(sc->ir.dev); sc->ir.dev = NULL; } /* Un-initialize data handling */ sc->ir.woff = sc->ir.wavail = sc->ir.roff = sc->ir.ravail = 0; mtx_destroy(&sc->ir.lock); sc->ir.module_started = 0; return (0); }
void nand_destroy_dev(struct nand_chip *chip) { if (chip->cdev) destroy_dev(chip->cdev); }
/* clean up so we can unload the driver. */ int ips_adapter_free(ips_softc_t *sc) { int error = 0; intrmask_t mask; if(sc->state & IPS_DEV_OPEN) return EBUSY; if((error = ips_diskdev_free(sc))) return error; if(ips_cmdqueue_free(sc)){ device_printf(sc->dev, "trying to exit when command queue is not empty!\n"); return EBUSY; } DEVICE_PRINTF(1, sc->dev, "free\n"); mask = splbio(); untimeout(ips_timeout, sc, sc->timer); splx(mask); if (mtx_initialized(&sc->cmd_mtx)) mtx_destroy(&sc->cmd_mtx); if(sc->sg_dmatag) bus_dma_tag_destroy(sc->sg_dmatag); if(sc->command_dmatag) bus_dma_tag_destroy(sc->command_dmatag); if(sc->device_file) destroy_dev(sc->device_file); return 0; }
static int ipf_modunload(void) { int error, i; if (fr_refcnt) return EBUSY; if (fr_running >= 0) { ipf_pfil_unhook(); ipf_event_dereg(); WRITE_ENTER(&ipf_global); error = ipfdetach(); RWLOCK_EXIT(&ipf_global); if (error != 0) return error; } else error = 0; RW_DESTROY(&ipf_global); RW_DESTROY(&ipf_mutex); RW_DESTROY(&ipf_frcache); fr_running = -2; for (i = 0; ipf_devfiles[i]; i++) { if (ipf_devs[i] != NULL) destroy_dev(ipf_devs[i]); } printf("%s unloaded\n", ipfilter_version); return error; }
int nsmb_dev_close(dev_t dev, int flag, int fmt, struct proc *p) { struct smb_dev *sdp; struct smb_vc *vcp; struct smb_share *ssp; struct smb_cred scred; int s; SMB_CHECKMINOR(dev); s = splnet(); if ((sdp->sd_flags & NSMBFL_OPEN) == 0) { splx(s); return EBADF; } smb_makescred(&scred, p, NULL); ssp = sdp->sd_share; if (ssp != NULL) smb_share_rele(ssp, &scred); vcp = sdp->sd_vc; if (vcp != NULL) smb_vc_rele(vcp, &scred); /* smb_flushq(&sdp->sd_rqlist); smb_flushq(&sdp->sd_rplist); */ smb_devtbl[minor(dev)] = NULL; free(sdp, M_SMBDATA); #ifndef __NetBSD__ destroy_dev(dev); #endif splx(s); return 0; }
static int cyapa_detach(device_t dev) { struct cyapa_softc *sc; sc = device_get_softc(dev); /* Cleanup poller thread */ cyapa_lock(sc); while (sc->poll_thread_running) { sc->detaching = 1; mtx_sleep(&sc->detaching, &sc->mutex, PCATCH, "cyapadet", hz); } cyapa_unlock(sc); destroy_dev(sc->devnode); knlist_clear(&sc->selinfo.si_note, 0); seldrain(&sc->selinfo); knlist_destroy(&sc->selinfo.si_note); mtx_destroy(&sc->mutex); return (0); }
static int openfirm_modevent(module_t mod, int type, void *data) { switch(type) { case MOD_LOAD: if (bootverbose) printf("openfirm: <Open Firmware control device>\n"); /* * Allow only root access by default; this device may allow * users to peek into firmware passwords, and likely to crash * the machine on some boxen due to firmware quirks. */ openfirm_dev = make_dev(&openfirm_cdevsw, OPENFIRM_MINOR, UID_ROOT, GID_WHEEL, 0600, "openfirm"); return 0; case MOD_UNLOAD: destroy_dev(openfirm_dev); return 0; case MOD_SHUTDOWN: return 0; default: return EOPNOTSUPP; } }
static int sysvipc_modevent(module_t mod, int type, void *unused) { struct sysvipc_softc *sysv; switch (type) { case MOD_LOAD: sysvipc_dev = make_dev(&sysvipc_dev_ops, 0, UID_ROOT, GID_WHEEL, 0600, "sysvipc"); kprintf("sysv ipc driver ready!\n"); return 0; case MOD_UNLOAD: sysv = sysvipc_dev->si_drv1; if(sysv != NULL) sysvipc_unregister(sysvipc_dev); destroy_dev(sysvipc_dev); kprintf("sysv ipc driver unloaded.\n"); return 0; } return EINVAL; }
static void __exit mac_static_exit(void) { destroy_dev(bdgfndev); // revert to the default netmap learning bridge bdgfnreg(0, bdg_learning); }
/******************************************************************************** * Free all of the resources associated with (sc). * * Should not be called if the controller is active. */ static void twe_free(struct twe_softc *sc) { struct twe_request *tr; debug_called(4); /* throw away any command buffers */ while ((tr = twe_dequeue_free(sc)) != NULL) twe_free_request(tr); /* destroy the data-transfer DMA tag */ if (sc->twe_buffer_dmat) bus_dma_tag_destroy(sc->twe_buffer_dmat); /* disconnect the interrupt handler */ if (sc->twe_intr) bus_teardown_intr(sc->twe_dev, sc->twe_irq, sc->twe_intr); if (sc->twe_irq != NULL) bus_release_resource(sc->twe_dev, SYS_RES_IRQ, 0, sc->twe_irq); /* destroy the parent DMA tag */ if (sc->twe_parent_dmat) bus_dma_tag_destroy(sc->twe_parent_dmat); /* release the register window mapping */ if (sc->twe_io != NULL) bus_release_resource(sc->twe_dev, SYS_RES_IOPORT, TWE_IO_CONFIG_REG, sc->twe_io); /* destroy control device */ if (sc->twe_dev_t != (dev_t)NULL) destroy_dev(sc->twe_dev_t); }
static int dcons_detach(int port) { struct tty *tp; struct dcons_softc *dc; dc = &sc[port]; tp = dc->dev->si_tty; if (tp->t_state & TS_ISOPEN) { printf("dcons: still opened\n"); (*linesw[tp->t_line].l_close)(tp, 0); tp->t_gen++; ttyclose(tp); ttwakeup(tp); ttwwakeup(tp); } /* XXX * must wait until all device are closed. */ tsleep((void *)dc, PWAIT, "dcodtc", hz/4); destroy_dev(dc->dev); return(0); }
int pci_iov_detach_method(device_t bus, device_t dev) { struct pci_devinfo *dinfo; struct pcicfg_iov *iov; mtx_lock(&Giant); dinfo = device_get_ivars(dev); iov = dinfo->cfg.iov; if (iov == NULL) { mtx_unlock(&Giant); return (0); } if (iov->iov_num_vfs != 0 || iov->iov_flags & IOV_BUSY) { mtx_unlock(&Giant); return (EBUSY); } dinfo->cfg.iov = NULL; if (iov->iov_cdev) { destroy_dev(iov->iov_cdev); iov->iov_cdev = NULL; } nvlist_destroy(iov->iov_schema); free(iov, M_SRIOV); mtx_unlock(&Giant); return (0); }
static int cdev_load(module_t mod, int cmd, void *arg) { int err = 0; switch (cmd) { case MOD_LOAD: /* Do any initialization that you should do with the kernel */ /* if we make it to here, print copyright on console*/ printf("\nSample Loaded kld character device driver\n"); printf("Copyright (c) 1998\n"); printf("Rajesh Vaidheeswarran\n"); printf("All rights reserved\n"); sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev"); break; /* Success*/ case MOD_UNLOAD: printf("Unloaded kld character device driver\n"); destroy_dev(sdev); break; /* Success*/ default: /* we only understand load/unload*/ err = EOPNOTSUPP; break; } return(err); }
void terasic_mtl_reg_detach(struct terasic_mtl_softc *sc) { if (sc->mtl_reg_cdev != NULL) destroy_dev(sc->mtl_reg_cdev); }
/* * Bus independant device detachment routine. Makes sure all * allocated resources are freed, callouts disabled and waiting * processes unblocked. */ int cmx_detach(device_t dev) { struct cmx_softc *sc = device_get_softc(dev); DEBUG_printf(dev, "called\n"); sc->dying = 1; CMX_LOCK(sc); if (sc->polling) { DEBUG_printf(sc->dev, "disabling polling\n"); callout_stop(&sc->ch); sc->polling = 0; CMX_UNLOCK(sc); callout_drain(&sc->ch); selwakeuppri(&sc->sel, PZERO); } else { CMX_UNLOCK(sc); } wakeup(sc); destroy_dev(sc->cdev); DEBUG_printf(dev, "releasing resources\n"); cmx_release_resources(dev); return 0; }
static int zy7_devcfg_detach(device_t dev) { struct zy7_devcfg_softc *sc = device_get_softc(dev); if (device_is_attached(dev)) bus_generic_detach(dev); /* Get rid of /dev/devcfg0. */ if (sc->sc_ctl_dev != NULL) destroy_dev(sc->sc_ctl_dev); /* Teardown and release interrupt. */ if (sc->irq_res != NULL) { if (sc->intrhandle) bus_teardown_intr(dev, sc->irq_res, sc->intrhandle); bus_release_resource(dev, SYS_RES_IRQ, rman_get_rid(sc->irq_res), sc->irq_res); } /* Release memory resource. */ if (sc->mem_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(sc->mem_res), sc->mem_res); zy7_devcfg_softc_p = NULL; DEVCFG_SC_LOCK_DESTROY(sc); return (0); }
void ql_del_cdev(qla_host_t *ha) { if (ha->ioctl_dev != NULL) destroy_dev(ha->ioctl_dev); return; }
void altpll_detach(struct altpll_softc *sc) { if (sc->ap_reg_cdev != NULL) destroy_dev(sc->ap_reg_cdev); }
static int tdfx_detach(device_t dev) { struct tdfx_softc* tdfx_info; int retval; tdfx_info = device_get_softc(dev); /* Delete allocated resource, of course */ bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid, tdfx_info->memrange); /* Release extended Voodoo3/Banshee resources */ if(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE || pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) { if(tdfx_info->memrange2 != NULL) bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2, tdfx_info->memrange); /* if(tdfx_info->piorange != NULL) bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid, tdfx_info->piorange);*/ } /* Though it is safe to leave the WRCOMB support since the mem driver checks for it, we should remove it in order to free an MTRR for another device */ retval = tdfx_clrmtrr(dev); #ifdef DEBUG if(retval != 0) printf("tdfx: For some reason, I couldn't clear the mtrr\n"); #endif /* Remove device entry when it can no longer be accessed */ destroy_dev(tdfx_info->devt); return(0); }
int cardbus_device_destroy(struct cardbus_devinfo *devi) { if (devi->sc_cisdev) destroy_dev(devi->sc_cisdev); return (0); }
/* * module handeling */ static int ata_module_event_handler(module_t mod, int what, void *arg) { static struct cdev *atacdev; switch (what) { case MOD_LOAD: /* register controlling device */ atacdev = make_dev(&ata_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "ata"); if (cold) { /* register boot attach to be run when interrupts are enabled */ if (!(ata_delayed_attach = (struct intr_config_hook *) malloc(sizeof(struct intr_config_hook), M_TEMP, M_NOWAIT | M_ZERO))) { printf("ata: malloc of delayed attach hook failed\n"); return EIO; } ata_delayed_attach->ich_func = (void*)ata_boot_attach; if (config_intrhook_establish(ata_delayed_attach) != 0) { printf("ata: config_intrhook_establish failed\n"); free(ata_delayed_attach, M_TEMP); } } return 0; case MOD_UNLOAD: /* deregister controlling device */ destroy_dev(atacdev); return 0; default: return EOPNOTSUPP; } }
int ida_detach(device_t dev) { struct ida_softc *ida; int error; ida = (struct ida_softc *)device_get_softc(dev); error = bus_generic_detach(dev); if (error) return (error); error = device_delete_children(dev); if (error) return (error); /* * XXX * before detaching, we must make sure that the system is * quiescent; nothing mounted, no pending activity. */ /* * XXX * now, how are we supposed to maintain a list of our drives? * iterate over our "child devices"? */ destroy_dev(ida->ida_dev_t); ida_free(ida); return (error); }
int proto_detach(device_t dev) { struct proto_softc *sc; struct proto_res *r; u_int res; sc = device_get_softc(dev); /* Don't detach if we have open device files. */ for (res = 0; res < sc->sc_rescnt; res++) { r = sc->sc_res + res; if (r->r_opened) return (EBUSY); } for (res = 0; res < sc->sc_rescnt; res++) { r = sc->sc_res + res; switch (r->r_type) { case SYS_RES_IRQ: /* XXX TODO */ bus_release_resource(dev, r->r_type, r->r_rid, r->r_d.res); break; case SYS_RES_DRQ: bus_release_resource(dev, r->r_type, r->r_rid, r->r_d.res); break; case SYS_RES_MEMORY: case SYS_RES_IOPORT: bus_release_resource(dev, r->r_type, r->r_rid, r->r_d.res); destroy_dev(r->r_u.cdev); break; case PROTO_RES_PCICFG: destroy_dev(r->r_u.cdev); break; case PROTO_RES_BUSDMA: proto_busdma_detach(sc, r->r_d.busdma); destroy_dev(r->r_u.cdev); break; } r->r_type = PROTO_RES_UNUSED; } sc->sc_rescnt = 0; return (0); }
void mps_detach_user(struct mps_softc *sc) { /* XXX: do a purge of pending requests? */ destroy_dev(sc->mps_cdev); dev_ops_remove_minor(&mps_ops, device_get_unit(sc->mps_dev)); }
void athp_ioctl_teardown(struct ath10k *ar) { if (ar->sc_cdev == NULL) return; destroy_dev(ar->sc_cdev); ar->sc_cdev = NULL; }