예제 #1
0
void
/*ARGSUSED*/
ptmattach(int n)
{
	extern const struct cdevsw pts_cdevsw, ptc_cdevsw;
	/* find the major and minor of the pty devices */
	if ((pts_major = cdevsw_lookup_major(&pts_cdevsw)) == -1)
		panic("ptmattach: Can't find pty slave in cdevsw");
	if ((ptc_major = cdevsw_lookup_major(&ptc_cdevsw)) == -1)
		panic("ptmattach: Can't find pty master in cdevsw");
#ifdef COMPAT_BSDPTY
	ptm = &ptm_bsdpty;
#endif
}
예제 #2
0
파일: if_tap.c 프로젝트: ryo/netbsd-src
static int
tap_fops_stat(file_t *fp, struct stat *st)
{
	int error = 0;
	struct tap_softc *sc;
	int unit = fp->f_devunit;

	(void)memset(st, 0, sizeof(*st));

	KERNEL_LOCK(1, NULL);
	sc = device_lookup_private(&tap_cd, unit);
	if (sc == NULL) {
		error = ENXIO;
		goto out;
	}

	st->st_dev = makedev(cdevsw_lookup_major(&tap_cdevsw), unit);
	st->st_atimespec = sc->sc_atime;
	st->st_mtimespec = sc->sc_mtime;
	st->st_ctimespec = st->st_birthtimespec = sc->sc_btime;
	st->st_uid = kauth_cred_geteuid(fp->f_cred);
	st->st_gid = kauth_cred_getegid(fp->f_cred);
out:
	KERNEL_UNLOCK_ONE(NULL);
	return error;
}
예제 #3
0
static int
ssdetach(device_t self, int flags)
{
	struct ss_softc *ss = device_private(self);
	int s, cmaj, mn;

	/* locate the major number */
	cmaj = cdevsw_lookup_major(&ss_cdevsw);

	/* kill any pending restart */
	callout_stop(&ss->sc_callout);

	s = splbio();

	/* Kill off any queued buffers. */
	bufq_drain(ss->buf_queue);

	bufq_free(ss->buf_queue);

	/* Kill off any pending commands. */
	scsipi_kill_pending(ss->sc_periph);

	splx(s);

	/* Nuke the vnodes for any open instances */
	mn = SSUNIT(device_unit(self));
	vdevgone(cmaj, mn, mn+SSNMINOR-1, VCHR);

	return 0;
}
예제 #4
0
void
zscninit(struct consdev *cn)
{
	struct zs_chanstate *cs;

	extern const struct cdevsw zstty_cdevsw;

	cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);

	zs_cons = (uint8_t *)MIPS_PHYS_TO_KSEG1(ZS_BASE) + ZS_CHAN_A; /* XXX */

	zs_conschan = cs = &zs_conschan_store;

	/* Setup temporary chanstate. */
	cs->cs_reg_csr  = zs_cons + ZS_CSR;
	cs->cs_reg_data = zs_cons + ZS_DATA;

	/* Initialize the pending registers. */
	memcpy(cs->cs_preg, zs_init_reg, 16);
	cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;

	cs->cs_preg[12] = BPS_TO_TCONST(PCLK / 16, ZS_DEFSPEED);
	cs->cs_preg[13] = 0;
	cs->cs_defspeed = ZS_DEFSPEED;

	/* Clear the master interrupt enable. */
	zs_write_reg(cs, 9, 0);

	/* Reset the whole SCC chip. */
	zs_write_reg(cs, 9, ZSWR9_HARD_RESET);

	/* Copy "pending" to "current" and H/W */
	zs_loadchannelregs(cs);
}
예제 #5
0
void
biconsdevattach(int n)
{
	struct tty *tp = &biconsdev_tty[0];
	int maj;

	/* locate the major number */
	maj = cdevsw_lookup_major(&biconsdev_cdevsw);

	/* Set up the tty queues now... */
	clalloc(&tp->t_rawq, 1024, 1);
	clalloc(&tp->t_canq, 1024, 1);
	/* output queue doesn't need quoting */
	clalloc(&tp->t_outq, 1024, 0);
	/* Set default line discipline. */
	tp->t_linesw = ttyldisc_default();


	tp->t_dev = makedev(maj, 0);
	tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
	tp->t_param = (int (*)(struct tty *, struct termios *))nullop;
	tp->t_winsize.ws_row = bicons_height;
	tp->t_winsize.ws_col = bicons_width;
	tp->t_winsize.ws_xpixel = bicons_xpixel;
	tp->t_winsize.ws_ypixel = bicons_ypixel;
	tp->t_oproc = biconsdev_output;
}
예제 #6
0
/* This is necessary when dynamically changing SAIP configuration. */
int
sacom_detach(struct device *self, int flags)
{
    struct sacom_softc *sc = (struct sacom_softc *)self;
    int maj, mn;

    /* locate the major number */
    maj = cdevsw_lookup_major(&sacom_cdevsw);

    /* Nuke the vnodes for any open instances. */
    mn = device_unit(self);
    vdevgone(maj, mn, mn, VCHR);

    mn |= COMDIALOUT_MASK;
    vdevgone(maj, mn, mn, VCHR);

    /* Free the receive buffer. */
    free(sc->sc_rbuf, M_DEVBUF);

    /* Detach and free the tty. */
    tty_detach(sc->sc_tty);
    ttyfree(sc->sc_tty);

    /* Unhook the soft interrupt handler. */
    softint_disestablish(sc->sc_si);

#if NRND > 0 && defined(RND_COM)
    /* Unhook the entropy source. */
    rnd_detach_source(&sc->rnd_source);
#endif

    return 0;
}
예제 #7
0
static void
zscninit(struct consdev *cn)
{
	extern const struct cdevsw zstty_cdevsw;

	cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
	cn->cn_pri = CN_REMOTE;
	zs_hwflags[0][0] = ZS_HWFLAG_CONSOLE;
}
예제 #8
0
/*
 * Attach.. plug pointer in and print some info.
 * Then try and attach a wsdisplay or ite to us.
 * Note: self is NULL durring console init.
 */
void
grfattach(device_t parent, device_t self, void *aux)
{
#if NWSDISPLAY > 0
	struct wsemuldisplaydev_attach_args wa;
	long defattr;
#endif
	struct grf_softc *gp;
	int maj;

	gp = device_private(parent);
	gp->g_device = self;
	grfsp[gp->g_unit] = gp;

	/*
	 * find our major device number
	 */
	maj = cdevsw_lookup_major(&grf_cdevsw);

	gp->g_grfdev = makedev(maj, gp->g_unit);
	if (self != NULL) {
		printf(": width %d height %d", gp->g_display.gd_dwidth,
		    gp->g_display.gd_dheight);
		if (gp->g_display.gd_colors == 2)
			printf(" monochrome\n");
		else
			printf(" colors %d\n", gp->g_display.gd_colors);
#if NWSDISPLAY > 0
		vcons_init(&gp->g_vd, gp, gp->g_screens[0], gp->g_accessops);
		gp->g_vd.init_screen = grf_init_screen;
		if (gp->g_flags & GF_CONSOLE) {
			console_vcons.scr_flags |= VCONS_SCREEN_IS_STATIC;
			vcons_init_screen(&gp->g_vd,
			    &console_vcons, 1, &defattr);
			gp->g_screens[0]->textops =
			    &console_vcons.scr_ri.ri_ops;
			wsdisplay_cnattach(gp->g_screens[0],
			    &console_vcons.scr_ri, 0, 0, defattr);
			vcons_replay_msgbuf(&console_vcons);
		}

		/* attach wsdisplay */
		wa.console = (gp->g_flags & GF_CONSOLE) != 0;
		wa.scrdata = &gp->g_screenlist;
		wa.accessops = gp->g_accessops;
		wa.accesscookie = &gp->g_vd;
		config_found(self, &wa, wsemuldisplaydevprint);
#endif  /* NWSDISPLAY > 0 */
	}

#if NWSDISPLAY == 0
	/*
	 * try and attach an ite
	 */
	amiga_config_found(cfdata, self, gp, grfprint);
#endif
}
예제 #9
0
int
rlopen(dev_t dev, int flag, int fmt, struct lwp *l)
{
	struct rl_softc * const rc = device_lookup_private(&rl_cd, DISKUNIT(dev));
	struct rlc_softc *sc;
	int error, part, mask;
	struct disklabel *dl;
	const char *msg;

	/*
	 * Make sure this is a reasonable open request.
	 */
	if (rc == NULL)
		return ENXIO;

	sc = rc->rc_rlc;
	part = DISKPART(dev);

	mutex_enter(&rc->rc_disk.dk_openlock);

	/*
	 * If there are wedges, and this is not RAW_PART, then we
	 * need to fail.
	 */
	if (rc->rc_disk.dk_nwedges != 0 && part != RAW_PART) {
		error = EBUSY;
		goto bad1;
	}

	/* Check that the disk actually is useable */
	msg = rlstate(sc, rc->rc_hwid);
	if (msg == NULL || msg == rlstates[RLMP_UNLOAD] ||
	    msg == rlstates[RLMP_SPUNDOWN]) {
		error = ENXIO;
		goto bad1;
	}
	/*
	 * If this is the first open; read in where on the disk we are.
	 */
	dl = rc->rc_disk.dk_label;
	if (rc->rc_state == DK_CLOSED) {
		u_int16_t mp;
		int maj;
		RL_WREG(RL_CS, RLCS_RHDR|(rc->rc_hwid << RLCS_USHFT));
		waitcrdy(sc);
		mp = RL_RREG(RL_MP);
		rc->rc_head = ((mp & RLMP_HS) == RLMP_HS);
		rc->rc_cyl = (mp >> 7) & 0777;
		rc->rc_state = DK_OPEN;
		/* Get disk label */
		maj = cdevsw_lookup_major(&rl_cdevsw);
		if ((msg = readdisklabel(MAKEDISKDEV(maj,
		    device_unit(rc->rc_dev), RAW_PART), rlstrategy, dl, NULL)))
			aprint_normal_dev(rc->rc_dev, "%s", msg);
		aprint_normal_dev(rc->rc_dev, "size %d sectors\n",
		    dl->d_secperunit);
	}
예제 #10
0
파일: zs.c 프로젝트: lacombar/netbsd-alc
void
zscninit(struct consdev *cn)
{
	extern const struct cdevsw zstty_cdevsw;

	cons_port = prom_getconsole(); 
	cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), cons_port);
	cn->cn_pri = CN_REMOTE;
	zs_hwflags[0][cons_port] = ZS_HWFLAG_CONSOLE;
}
예제 #11
0
/*
 * Prepare the console tty; called on first open of /dev/console
 */
static void
kd_init(struct kd_softc *kd)
{
	struct tty *tp;

	tp = tty_alloc();
	callout_setfunc(&tp->t_rstrt_ch, kd_later, tp);
	tp->t_oproc = kdstart;
	tp->t_param = kdparam;
	tp->t_dev = makedev(cdevsw_lookup_major(&kd_cdevsw), 0);

	tty_attach(tp);
	kd->kd_tty = tp;

	/*
	 * Get the console struct winsize.
	 */
#if defined(RASTERCONSOLE) && NFB > 0
	/* If the raster console driver is attached, copy its size */
	kd->rows = fbrcons_rows();
	kd->cols = fbrcons_cols();
	rcons_ttyinit(tp);
#endif

	/* else, consult the PROM */
	switch (prom_version()) {
	char prop[6+1];		/* Enough for six digits */
	struct eeprom *ep;
	case PROM_OLDMON:
		if ((ep = (struct eeprom *)eeprom_va) == NULL)
			break;
		if (kd->rows == 0)
			kd->rows = (u_short)ep->eeTtyRows;
		if (kd->cols == 0)
			kd->cols = (u_short)ep->eeTtyCols;
		break;

	case PROM_OBP_V0:
	case PROM_OBP_V2:
	case PROM_OBP_V3:
	case PROM_OPENFIRM:
		if (kd->rows == 0 &&
		    prom_getoption("screen-#rows", prop, sizeof prop) == 0)
			kd->rows = strtoul(prop, NULL, 10);

		if (kd->cols == 0 &&
		    prom_getoption("screen-#columns", prop, sizeof prop) == 0)
			kd->cols = strtoul(prop, NULL, 10);

		break;
	}

	return;
}
예제 #12
0
static int
dz_ebus_getmajor(void)
{
	extern const struct cdevsw dz_cdevsw;
	static int cache = -1;

	if (cache != -1)
		return cache;

	return cache = cdevsw_lookup_major(&dz_cdevsw);
}
예제 #13
0
void
prom_cnprobe(struct consdev *cd)
{
#if NPCONS > 0
	int maj;
	extern const struct cdevsw pcons_cdevsw;

	maj = cdevsw_lookup_major(&pcons_cdevsw);
	cd->cn_dev = makedev(maj, 0);
	cd->cn_pri = CN_INTERNAL;
#endif
}
예제 #14
0
/*
 * Detach a keyboard.  To keep track of users of the softc we keep
 * a reference count that's incremented while inside, e.g., read.
 * If the keyboard is active and the reference count is > 0 (0 is the
 * normal state) we post an event and then wait for the process
 * that had the reference to wake us up again.  Then we blow away the
 * vnode and return (which will deallocate the softc).
 */
int
wskbd_detach(device_t self, int flags)
{
	struct wskbd_softc *sc = device_private(self);
	struct wseventvar *evar;
	int maj, mn;
	int s;

#if NWSMUX > 0
	/* Tell parent mux we're leaving. */
	if (sc->sc_base.me_parent != NULL)
		wsmux_detach_sc(&sc->sc_base);
#endif

	callout_halt(&sc->sc_repeat_ch, NULL);
	callout_destroy(&sc->sc_repeat_ch);

	if (sc->sc_isconsole) {
		KASSERT(wskbd_console_device == sc);
		wskbd_console_device = NULL;
	}

	pmf_device_deregister(self);

	evar = sc->sc_base.me_evp;
	if (evar != NULL && evar->io != NULL) {
		s = spltty();
		if (--sc->sc_refcnt >= 0) {
			struct wscons_event event;

			/* Wake everyone by generating a dummy event. */
			event.type = 0;
			event.value = 0;
			if (wsevent_inject(evar, &event, 1) != 0)
				wsevent_wakeup(evar);

			/* Wait for processes to go away. */
			if (tsleep(sc, PZERO, "wskdet", hz * 60))
				aprint_error("wskbd_detach: %s didn't detach\n",
				       device_xname(self));
		}
		splx(s);
	}

	/* locate the major number */
	maj = cdevsw_lookup_major(&wskbd_cdevsw);

	/* Nuke the vnodes for any open instances. */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	return (0);
}
void
hd64461uartcnprobe(struct consdev *cp)
{
	extern const struct cdevsw com_cdevsw;
	int maj;

	/* locate the major number */
	maj = cdevsw_lookup_major(&com_cdevsw);

	/* Initialize required fields. */
	cp->cn_dev = makedev(maj, 0);
	cp->cn_pri = CN_NORMAL;
}
예제 #16
0
파일: radio.c 프로젝트: ryo/netbsd-src
static int
radiodetach(device_t self, int flags)
{
	int maj, mn;

	/* locate the major number */
	maj = cdevsw_lookup_major(&radio_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	return (0);
}
예제 #17
0
파일: uk.c 프로젝트: ryoon/netbsd-xhci
static int
ukdetach(device_t self, int flags)
{
	int cmaj, mn;

	/* locate the major number */
	cmaj = cdevsw_lookup_major(&uk_cdevsw);

	/* Nuke the vnodes for any open instances */
	mn = device_unit(self);
	vdevgone(cmaj, mn, mn, VCHR);

	return 0;
}
예제 #18
0
int
mididetach(device_t self, int flags)
{
	struct midi_softc *sc = device_private(self);
	int maj, mn;

	DPRINTFN(2,("%s: sc=%p flags=%d\n", __func__, sc, flags));

	pmf_device_deregister(self);

	mutex_enter(sc->lock);
	sc->dying = 1;
	cv_broadcast(&sc->wchan);
	cv_broadcast(&sc->rchan);
	mutex_exit(sc->lock);

	/* locate the major number */
	maj = cdevsw_lookup_major(&midi_cdevsw);

	/*
	 * Nuke the vnodes for any open instances (calls close).
	 * Will wait until any activity on the device nodes has ceased.
	 *
	 * XXXAD NOT YET.
	 *
	 * XXXAD NEED TO PREVENT NEW REFERENCES THROUGH AUDIO_ENTER().
	 */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);
	
	if (!(sc->props & MIDI_PROP_NO_OUTPUT)) {
		evcnt_detach(&sc->xmt.bytesDiscarded);
		evcnt_detach(&sc->xmt.incompleteMessages);
	}
	if (sc->props & MIDI_PROP_CAN_INPUT) {
		evcnt_detach(&sc->rcv.bytesDiscarded);
		evcnt_detach(&sc->rcv.incompleteMessages);
	}

	if (sc->sih != NULL) {
		softint_disestablish(sc->sih);
		sc->sih = NULL;
	}

	cv_destroy(&sc->wchan);
	cv_destroy(&sc->rchan);

	return (0);
}
예제 #19
0
/*
 * iscsi_attach:
 *    One-time inits go here. Not much for now, probably even less later.
 */
static void
iscsi_attach(device_t parent, device_t self, void *aux)
{

	DEBOUT(("ISCSI: iscsi_attach, parent=%p, self=%p, aux=%p\n", parent,
			self, aux));
	sc = (iscsi_softc_t *) device_private(self);
	sc->sc_dev = self;
	if (kthread_create(PRI_NONE, 0, NULL, iscsi_cleanup_thread,
	    NULL, &iscsi_cleanproc, "Cleanup") != 0) {
		panic("Can't create cleanup thread!");
	}
	aprint_normal("%s: attached.  major = %d\n", iscsi_cd.cd_name,
	    cdevsw_lookup_major(&iscsi_cdevsw));
}
예제 #20
0
static int
rnd_stat(struct file *fp, struct stat *st)
{
	struct rnd_ctx *const ctx = fp->f_data;

	/* XXX lock, if cprng allocated?  why? */
	memset(st, 0, sizeof(*st));
	st->st_dev = makedev(cdevsw_lookup_major(&rnd_cdevsw),
	    (ctx->rc_hard? RND_DEV_RANDOM : RND_DEV_URANDOM));
	/* XXX leave atimespect, mtimespec, ctimespec = 0? */

	st->st_uid = kauth_cred_geteuid(fp->f_cred);
	st->st_gid = kauth_cred_getegid(fp->f_cred);
	st->st_mode = S_IFCHR;
	return 0;
}
예제 #21
0
/*
 * Detach a mouse.  To keep track of users of the softc we keep
 * a reference count that's incremented while inside, e.g., read.
 * If the mouse is active and the reference count is > 0 (0 is the
 * normal state) we post an event and then wait for the process
 * that had the reference to wake us up again.  Then we blow away the
 * vnode and return (which will deallocate the softc).
 */
int
wsmouse_detach(device_t self, int flags)
{
	struct wsmouse_softc *sc = device_private(self);
	struct wseventvar *evar;
	int maj, mn;
	int s;

#if NWSMUX > 0
	/* Tell parent mux we're leaving. */
	if (sc->sc_base.me_parent != NULL) {
		DPRINTF(("wsmouse_detach:\n"));
		wsmux_detach_sc(&sc->sc_base);
	}
#endif

	/* If we're open ... */
	evar = sc->sc_base.me_evp;
	if (evar != NULL && evar->io != NULL) {
		s = spltty();
		if (--sc->sc_refcnt >= 0) {
			struct wscons_event event;

			/* Wake everyone by generating a dummy event. */
			event.type = 0;
			event.value = 0;
			if (wsevent_inject(evar, &event, 1) != 0)
				wsevent_wakeup(evar);

			/* Wait for processes to go away. */
			if (tsleep(sc, PZERO, "wsmdet", hz * 60))
				printf("wsmouse_detach: %s didn't detach\n",
				       device_xname(self));
		}
		splx(s);
	}

	/* locate the major number */
	maj = cdevsw_lookup_major(&wsmouse_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	return (0);
}
예제 #22
0
파일: cir.c 프로젝트: ryoon/netbsd-xhci
int
cir_detach(device_t self, int flags)
{
	struct cir_softc *sc = device_private(self);
	int maj, mn;

	/* locate the major number */
	maj = cdevsw_lookup_major(&cir_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	seldestroy(&sc->sc_rdsel);

	return (0);
}
예제 #23
0
파일: ite.c 프로젝트: lacombar/netbsd-alc
int
itematch(struct device *pdp, struct cfdata *cfp, void *auxp)
{
	struct grf_softc *gp;
	int maj;

	gp = auxp;

	/*
	 * XXX
	 * normally this would be done in attach, however
	 * during early init we do not have a device pointer
	 * and thus no unit number.
	 */
	maj = cdevsw_lookup_major(&ite_cdevsw);
	gp->g_itedev = makedev(maj, cfp->cf_unit);
	return(1);
}
예제 #24
0
void
xencons_attach(device_t parent, device_t self, void *aux)
{
    struct xencons_softc *sc = device_private(self);

    aprint_normal(": Xen Virtual Console Driver\n");

    sc->sc_dev = self;
    sc->sc_tty = tty_alloc();
    tty_attach(sc->sc_tty);
    sc->sc_tty->t_oproc = xencons_start;
    sc->sc_tty->t_param = xencons_param;

    if (xencons_isconsole) {
        int maj;

        /* Locate the major number. */
        maj = cdevsw_lookup_major(&xencons_cdevsw);

        /* There can be only one, but it can have any unit number. */
        cn_tab->cn_dev = makedev(maj, device_unit(self));

        aprint_verbose_dev(self, "console major %d, unit %d\n",
                           maj, device_unit(self));

        sc->sc_tty->t_dev = cn_tab->cn_dev;

#ifdef DDB
        /* Set db_max_line to avoid paging. */
        db_max_line = 0x7fffffff;
#endif

        xencons_console_device = sc;

        xencons_resume(self, PMF_Q_NONE);
    }
    sc->polling = 0;

    if (!pmf_device_register(self, xencons_suspend, xencons_resume))
        aprint_error_dev(self, "couldn't establish power handler\n");
}
예제 #25
0
int 
urio_detach(device_t self, int flags)
{
	struct urio_softc *sc = device_private(self);
	int s;
	int maj, mn;

	DPRINTF(("urio_detach: sc=%p flags=%d\n", sc, flags));

	sc->sc_dying = 1;
	/* Abort all pipes.  Causes processes waiting for transfer to wake. */
	if (sc->sc_in_pipe != NULL) {
		usbd_abort_pipe(sc->sc_in_pipe);
		usbd_close_pipe(sc->sc_in_pipe);
		sc->sc_in_pipe = NULL;
	}
	if (sc->sc_out_pipe != NULL) {
		usbd_abort_pipe(sc->sc_out_pipe);
		usbd_close_pipe(sc->sc_out_pipe);
		sc->sc_out_pipe = NULL;
	}

	s = splusb();
	if (--sc->sc_refcnt >= 0) {
		/* Wait for processes to go away. */
		usb_detach_waitold(sc->sc_dev);
	}
	splx(s);

	/* locate the major number */
	maj = cdevsw_lookup_major(&urio_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self);
	vdevgone(maj, mn, mn, VCHR);

	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
			   sc->sc_dev);

	return (0);
}
예제 #26
0
파일: fd.c 프로젝트: lacombar/netbsd-alc
static int
fddetach(device_t self, int flags)
{
	struct fd_softc *fd = device_private(self);
	int bmaj, cmaj, i, mn;

	fd_motor_off(fd);

	/* locate the major number */
	bmaj = bdevsw_lookup_major(&fd_bdevsw);
	cmaj = cdevsw_lookup_major(&fd_cdevsw);

	/* Nuke the vnodes for any open instances. */
	for (i = 0; i < MAXPARTITIONS; i++) {
		mn = DISKMINOR(device_unit(self), i);
		vdevgone(bmaj, mn, mn, VBLK);
		vdevgone(cmaj, mn, mn, VCHR);
	}

	pmf_device_deregister(self);

#if 0 /* XXX need to undo at detach? */
	fd_set_properties(fd);
#endif
#if NRND > 0
	rnd_detach_source(&fd->rnd_source);
#endif

	disk_detach(&fd->sc_dk);
	disk_destroy(&fd->sc_dk);

	/* Kill off any queued buffers. */
	bufq_drain(fd->sc_q);

	bufq_free(fd->sc_q);

	callout_destroy(&fd->sc_motoroff_ch);
	callout_destroy(&fd->sc_motoron_ch);

	return 0;
}
예제 #27
0
void
zscnprobe(struct consdev *cd)
{
	int maj;
	extern const struct cdevsw zstty_cdevsw;

	/* locate the major number */
	maj = cdevsw_lookup_major(&zstty_cdevsw);
	/* XXX: minor number is 0 */

	if (maj == -1)
		cd->cn_pri = CN_DEAD;
	else {
#ifdef ZSCONSOLE
		cd->cn_pri = CN_REMOTE;	/* higher than ITE (CN_INTERNAL) */
#else
		cd->cn_pri = CN_NORMAL;
#endif
		cd->cn_dev = makedev(maj, 0);
	}
}
예제 #28
0
파일: zs.c 프로젝트: lacombar/netbsd-alc
static void
zscninit(struct consdev *cn)
{
	struct zs_chanstate *cs;

	extern const struct cdevsw zstty_cdevsw;
	extern int tty00_is_console;
	extern uint32_t sccport0a;

	cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
	if (tty00_is_console)
		cn->cn_pri = CN_REMOTE;
	else
		cn->cn_pri = CN_NORMAL;

	zc_cons = (struct zschan *)sccport0a; /* XXX */

	zs_conschan = cs = &zs_conschan_store;

	/* Setup temporary chanstate. */
	cs->cs_reg_csr  = &zc_cons->zc_csr;
	cs->cs_reg_data = &zc_cons->zc_data;

	/* Initialize the pending registers. */
	memcpy(cs->cs_preg, zs_init_reg, 16);
	cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;

	cs->cs_preg[12] = BPS_TO_TCONST(pclk[systype] / 16, 9600); /* XXX */
	cs->cs_preg[13] = 0;
	cs->cs_defspeed = 9600;

	/* Clear the master interrupt enable. */
	zs_write_reg(cs, 9, 0);

	/* Reset the whole SCC chip. */
	zs_write_reg(cs, 9, ZSWR9_HARD_RESET);

	/* Copy "pending" to "current" and H/W */
	zs_loadchannelregs(cs);
}
예제 #29
0
static void
uart_attach(device_t parent, device_t self, void *aux)
{
        struct obio_attach_args * const oba = aux;
        struct uart_softc * const sc = device_private(self);
	struct tty *tp;
	int maj, minor;

	sc->sc_dev = self;
        sc->sc_st = oba->oba_st;
        if (bus_space_map(oba->oba_st, oba->oba_addr, 256, 0, &sc->sc_ioh)) {
                aprint_error("unable to map device\n");
                return;
	}

	/* Establish the interrupt. */
	sc->sc_ih = adm5120_intr_establish(oba->oba_irq, INTR_FIQ, uart_intr, sc);
	if (sc->sc_ih == NULL) {
		aprint_error("unable to establish interrupt\n");
		return;
	}
	REG_WRITE(UART_CR_REG,UART_CR_PORT_EN|UART_CR_RX_INT_EN|UART_CR_RX_TIMEOUT_INT_EN);

	maj = cdevsw_lookup_major(&uart_cdevsw);
	minor = device_unit(sc->sc_dev);

	tp = tty_alloc();
	tp->t_oproc = uart_start;
	tp->t_param = uart_param;
	sc->sc_tty = tp;
	tp->t_dev = makedev(maj, minor);
	tty_attach(tp);
	if (minor == 0 && uart_consattached) {
		/* attach as console*/
		cn_tab->cn_dev = tp->t_dev;
		aprint_normal(" console");
	}
        aprint_normal("\n");
}
예제 #30
0
int 
uscanner_detach(device_t self, int flags)
{
	struct uscanner_softc *sc = device_private(self);
	int             s;
	int maj, mn;

	DPRINTF(("uscanner_detach: sc=%p flags=%d\n", sc, flags));

	sc->sc_dying = 1;
	sc->sc_dev_flags = 0;	/* make close really close device */

	/* Abort all pipes.  Causes processes waiting for transfer to wake. */
	if (sc->sc_bulkin_pipe != NULL)
		usbd_abort_pipe(sc->sc_bulkin_pipe);
	if (sc->sc_bulkout_pipe != NULL)
		usbd_abort_pipe(sc->sc_bulkout_pipe);

	s = splusb();
	if (--sc->sc_refcnt >= 0) {
		/* Wait for processes to go away. */
		usb_detach_waitold(sc->sc_dev);
	}
	splx(s);

	/* locate the major number */
	maj = cdevsw_lookup_major(&uscanner_cdevsw);

	/* Nuke the vnodes for any open instances (calls close). */
	mn = device_unit(self) * USB_MAX_ENDPOINTS;
	vdevgone(maj, mn, mn + USB_MAX_ENDPOINTS - 1, VCHR);

	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
			   sc->sc_dev);
	seldestroy(&sc->sc_selq);

	return (0);
}