static void mtattach(device_t parent, device_t self, void *aux) { struct mt_softc *sc = device_private(self); struct hpibbus_attach_args *ha = aux; int unit, hpibno, slave; sc->sc_dev = self; if (mtident(sc, ha) == 0) { aprint_error(": impossible!\n"); return; } unit = device_unit(self); hpibno = device_unit(parent); slave = ha->ha_slave; bufq_alloc(&sc->sc_tab, "fcfs", 0); callout_init(&sc->sc_start_ch, 0); callout_init(&sc->sc_intr_ch, 0); sc->sc_hpibno = hpibno; sc->sc_slave = slave; sc->sc_flags = MTF_EXISTS; /* Initialize hpib job queue entry. */ sc->sc_hq.hq_softc = sc; sc->sc_hq.hq_slave = sc->sc_slave; sc->sc_hq.hq_start = mtstart; sc->sc_hq.hq_go = mtgo; sc->sc_hq.hq_intr = mtintr; }
/* * Check the slots looking for a board we recognise * If we find one, note its address (slot) and call * the actual probe routine to check it out. */ int ahc_isa_probe(device_t parent, cfdata_t match, void *aux) { struct isa_attach_args *ia = aux; struct ahc_isa_slot *as; if (ahc_isa_slot_initialized == 0) { LIST_INIT(&ahc_isa_all_slots); ahc_isa_slot_initialized = 1; } if (ia->ia_nio < 1) return (0); if (ia->ia_nirq < 1) return (0); if (ISA_DIRECT_CONFIG(ia)) return (0); if (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT) return (ahc_isa_match(ia, ia->ia_io[0].ir_addr)); /* * Find this bus's state. If we don't yet have a slot * marker, allocate and initialize one. */ for (as = ahc_isa_all_slots.lh_first; as != NULL; as = as->link.le_next) if (as->bus == device_unit(parent)) goto found_slot_marker; /* * Don't have one, so make one. */ as = (struct ahc_isa_slot *) malloc(sizeof(struct ahc_isa_slot), M_DEVBUF, M_NOWAIT); if (as == NULL) panic("ahc_isa_probe: can't allocate slot marker"); as->bus = device_unit(parent); as->slot = AHC_ISA_MIN_SLOT; LIST_INSERT_HEAD(&ahc_isa_all_slots, as, link); found_slot_marker: for (; as->slot <= AHC_ISA_MAX_SLOT; as->slot++) { if (ahc_isa_match(ia, EISA_SLOT_ADDR(as->slot) + AHC_ISA_SLOT_OFFSET)) { as->slot++; /* next slot to search */ return (1); } } /* No matching cards were found. */ return (0); }
/* * Attempt to find the device from which we were booted. */ void device_register(struct device *dev, void *aux) { struct bootdev_data *b = bootdev_data; struct device *parent = device_parent(dev); static int found = 0, initted = 0, scsiboot = 0; static struct device *scsibusdev = NULL; if (b == NULL) return; /* There is no hope. */ if (found) return; if (!initted) { if (strcmp(b->dev_type, "sd") == 0) scsiboot = 1; initted = 1; } if (scsiboot && device_is_a(dev, "scsibus")) { /* XXX device_unit() abuse */ if (device_unit(dev) == b->bus) { scsibusdev = dev; #if 0 printf("\nscsibus = %s\n", dev->dv_xname); #endif } return; } if (!device_is_a(dev, b->dev_type)) return; if (device_is_a(dev, "sd")) { struct scsipibus_attach_args *sa = aux; if (scsiboot && scsibusdev && parent == scsibusdev && sa->sa_periph->periph_target == b->unit) { booted_device = dev; #if 0 printf("\nbooted_device = %s\n", dev->dv_xname); #endif found = 1; } return; } /* XXX device_unit() abuse */ if (device_unit(dev) == b->unit) { booted_device = dev; #if 0 printf("\nbooted_device = %s\n", dev->dv_xname); #endif found = 1; } }
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; }
/* * (Try to) put the drive online. This is done the first time the * drive is opened, or if it has fallen offline. */ int ra_putonline(dev_t dev, struct ra_softc *ra) { struct disklabel *dl; const char *msg; if (rx_putonline(ra) != MSCP_DONE) return MSCP_FAILED; dl = ra->ra_disk.dk_label; ra->ra_state = DK_RDLABEL; printf("%s", device_xname(ra->ra_dev)); if ((msg = readdisklabel( MAKEDISKDEV(major(dev), device_unit(ra->ra_dev), RAW_PART), rastrategy, dl, NULL)) == NULL) { ra->ra_havelabel = 1; ra->ra_state = DK_OPEN; } #if NRACD else if (cdevsw_lookup(dev) == &racd_cdevsw) { dl->d_partitions[0].p_offset = 0; dl->d_partitions[0].p_size = dl->d_secperunit; dl->d_partitions[0].p_fstype = FS_ISO9660; } #endif /* NRACD */ else { printf(": %s", msg); } printf(": size %d sectors\n", dl->d_secperunit); return MSCP_DONE; }
static void vme_attach(device_t parent, device_t self, void *args) { struct confargs *ca = aux; struct vme_softc *sc = device_private(self); struct confargs vmea; int unit; sc->sc_dev = self; unit = device_unit(self); aprint_normal(": (%s)\n", vme_info[unit].name); sc->sc_bustag = ca->ca_bustag; sc->sc_dmatag = ca->ca_dmatag; sc->sc_bustype = unit; vme_space_tag.cookie = sc; vme_space_tag.parent = sc->sc_bustag; vme_dma_tag = *sc->sc_dmatag; vme_dma_tag._cookie = sc; vme_dma_tag._dmamap_load = vme_dmamap_load; vmea = *ca; vmea.ca_bustag = &vme_space_tag; vmea.ca_dmatag = &vme_dma_tag; /* We know ca_bustype == BUS_VMExx */ config_search_ia(bus_scan, self, "vme", args); }
static void md_attach(device_t parent, device_t self, void *aux) { struct md_softc *sc = device_private(self); bufq_alloc(&sc->sc_buflist, "fcfs", 0); /* XXX - Could accept aux info here to set the config. */ #ifdef MEMORY_DISK_HOOKS /* * This external function might setup a pre-loaded disk. * All it would need to do is setup the md_conf struct. * See sys/dev/md_root.c for an example. */ md_attach_hook(device_unit(self), &sc->sc_md); #endif /* * Initialize and attach the disk structure. */ disk_init(&sc->sc_dkdev, device_xname(self), &mddkdriver); disk_attach(&sc->sc_dkdev); if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); }
/* 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; }
static void obsled_attach(device_t parent, device_t self, void *aux) { struct obsled_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; struct sysctlnode *node; int err, node_mib; char led_name[5]; /* int led = (1 << device_unit(sc->sc_dev)); */ snprintf(led_name, sizeof(led_name), "led%d", (1 << device_unit(sc->sc_dev)) & 0x7); aprint_naive(": OpenBlockS %s\n", led_name); aprint_normal(": OpenBlockS %s\n", led_name); sc->sc_dev = self; sc->sc_tag = ga->ga_tag; sc->sc_addr = ga->ga_addr; sc->sc_led_state = 0; obs266_led_set(OBS266_LED_OFF); /* add sysctl interface */ err = sysctl_createv(NULL, 0, NULL, NULL, 0, CTLTYPE_NODE, "hw", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_EOL); if (err != 0) return; err = sysctl_createv(NULL, 0, NULL, (const struct sysctlnode **)&node, 0, CTLTYPE_NODE, "obsled", NULL, NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); if (err != 0) return; node_mib = node->sysctl_num; err = sysctl_createv(NULL, 0, NULL, (const struct sysctlnode **)&node, CTLFLAG_READWRITE, CTLTYPE_INT, led_name, SYSCTL_DESCR("OpenBlockS LED state (0=off, 1=on)"), obsled_sysctl_verify, 0, (void *)sc, 0, CTL_HW, node_mib, CTL_CREATE, CTL_EOL); if (err != 0) return; sc->sc_led_state_mib = node->sysctl_num; #if 0 { gpio_tag_t tag = sc->sc_tag; (*(tag)->io_or_write)((tag)->cookie, sc->sc_addr, 0); } #endif }
static int rdmatch(device_t parent, cfdata_t cf, void *aux) { struct hpibbus_attach_args *ha = aux; /* * Set punit if operator specified one in the kernel * configuration file. */ if (cf->hpibbuscf_punit != HPIBBUSCF_PUNIT_DEFAULT && cf->hpibbuscf_punit < HPIB_NPUNITS) ha->ha_punit = cf->hpibbuscf_punit; if (rdident(parent, NULL, ha) == 0) { /* * XXX Some aging HP-IB drives are slow to * XXX respond; give them a chance to catch * XXX up and probe them again. */ delay(10000); ha->ha_id = hpibid(device_unit(parent), ha->ha_slave); return rdident(parent, NULL, ha); } return 1; }
static void bcm2835gpio_gpio_pin_ctl(void *arg, int pin, int flags) { struct bcmgpio_softc *sc = arg; uint32_t cmd; int epin = pin + device_unit(sc->sc_dev) * 32; if (device_unit(sc->sc_dev) > 1) { return; } DPRINTF(2, ("%s: gpio_ctl pin %d flags 0x%x\n", device_xname(sc->sc_dev), epin, flags)); if (flags & (GPIO_PIN_OUTPUT|GPIO_PIN_INPUT)) { if ((flags & GPIO_PIN_INPUT) || !(flags & GPIO_PIN_OUTPUT)) { /* for safety INPUT will overide output */ bcm2835gpio_function_select(epin, BCM2835_GPIO_IN); } else { bcm2835gpio_function_select(epin, BCM2835_GPIO_OUT); } } if (flags & (GPIO_PIN_PULLUP|GPIO_PIN_PULLDOWN)) { cmd = (flags & GPIO_PIN_PULLUP) ? BCM2835_GPIO_GPPUD_PULLUP : BCM2835_GPIO_GPPUD_PULLDOWN; } else { cmd = BCM2835_GPIO_GPPUD_PULLOFF; } /* set up control signal */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_GPIO_GPPUD, cmd); delay(1); /* wait 150 cycles */ /* set clock signal */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_GPIO_GPPUDCLK(device_unit(sc->sc_dev)), 1 << (epin % BCM2835_GPIO_GPPUD_PINS_PER_REGISTER)); delay(1); /* wait 150 cycles */ /* reset control signal and clock */ bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_GPIO_GPPUD, BCM2835_GPIO_GPPUD_PULLOFF); bus_space_write_4(sc->sc_iot, sc->sc_ioh, BCM2835_GPIO_GPPUDCLK(device_unit(sc->sc_dev)), 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); }
static int ctident(device_t parent, struct ct_softc *sc, struct hpibbus_attach_args *ha) { struct ct_describe desc; u_char stat, cmd[3]; char name[7]; int i, id, n, type, canstream; type = canstream = 0; /* Verify that we have a CS80 device. */ if ((ha->ha_id & 0x200) == 0) return 0; /* Is it one of the tapes we support? */ for (id = 0; id < nctinfo; id++) if (ha->ha_id == ctinfo[id].hwid) break; if (id == nctinfo) return 0; ha->ha_punit = ctinfo[id].punit; /* * So far, so good. Get drive parameters. Note command * is always issued to unit 0. */ cmd[0] = C_SUNIT(0); cmd[1] = C_SVOL(0); cmd[2] = C_DESC; hpibsend(device_unit(parent), ha->ha_slave, C_CMD, cmd, sizeof(cmd)); hpibrecv(device_unit(parent), ha->ha_slave, C_EXEC, &desc, 37); hpibrecv(device_unit(parent), ha->ha_slave, C_QSTAT, &stat, sizeof(stat)); memset(name, 0, sizeof(name)); if (stat == 0) { n = desc.d_name; for (i = 5; i >= 0; i--) { name[i] = (n & 0xf) + '0'; n >>= 4; } }
void parstart(void *arg) { struct par_softc *sc = arg; #ifdef DEBUG if (pardebug & PDB_FOLLOW) printf("parstart(%x)\n", device_unit(sc->sc_dev)); #endif sc->sc_flags &= ~PARF_DELAY; wakeup(sc); }
void partimo(void *arg) { struct par_softc *sc = arg; #ifdef DEBUG if (pardebug & PDB_FOLLOW) printf("partimo(%x)\n", device_unit(sc->sc_dev)); #endif sc->sc_flags &= ~(PARF_UIO|PARF_TIMO); wakeup(sc); }
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"); }
/* * Setting LED interface for inside kernel. * Argumnt `led' is 3-bit LED state (led=0-7/ON=1/OFF=0). */ void obs266_led_set(int led) { device_t dv; deviter_t di; /* * Sarching "obsled" devices from device tree. * Do you have something better idea? */ for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL; dv = deviter_next(&di)) { if (device_is_a(dv, "obsles")) { struct obsled_softc *sc = device_private(dv); sc->sc_led_state = (led & (1 << device_unit(dv))) >> device_unit(dv); obsled_set_state(sc); } } deviter_release(&di); }
/* * 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); }
static void bcm2835gpio_gpio_pin_write(void *arg, int pin, int value) { struct bcmgpio_softc *sc = arg; int epin = pin + device_unit(sc->sc_dev) * 32; bus_size_t reg; if (device_unit(sc->sc_dev) > 1) { return; } if (value == GPIO_PIN_HIGH) { reg = BCM2835_GPIO_GPSET(epin / BCM2835_GPIO_GPSET_PINS_PER_REGISTER); } else { reg = BCM2835_GPIO_GPCLR(epin / BCM2835_GPIO_GPCLR_PINS_PER_REGISTER); } bus_space_write_4(sc->sc_iot, sc->sc_ioh, reg, 1 << (epin % BCM2835_GPIO_GPSET_PINS_PER_REGISTER)); DPRINTF(2, ("%s: gpio_write pin %d<-%d\n", device_xname(sc->sc_dev), epin, (value == GPIO_PIN_HIGH))); }
static int target_to_unit(u_long bus, u_long target, u_long lun) { struct scsibus_softc *scsi; struct scsipi_periph *periph; extern struct cfdriver scsibus_cd; if (target < 0 || target > 7 || lun < 0 || lun > 7) { printf("scsi target to unit, target (%ld) or lun (%ld)" " out of range.\n", target, lun); return -1; } if (bus == -1) { for (bus = 0 ; bus < scsibus_cd.cd_ndevs ; bus++) { scsi = device_lookup_private(&scsibus_cd, bus); if (!scsi) continue; periph = scsipi_lookup_periph(scsi->sc_channel, target, lun); if (!periph) continue; return device_unit(periph->periph_dev); } return -1; } if (bus < 0 || bus >= scsibus_cd.cd_ndevs) { printf("scsi target to unit, bus (%ld) out of range.\n", bus); return -1; } scsi = device_lookup_private(&scsibus_cd, bus); if (!scsi) return -1; periph = scsipi_lookup_periph(scsi->sc_channel, target, lun); if (!periph) return -1; return device_unit(periph->periph_dev); }
/* GPIO support functions */ static int bcm2835gpio_gpio_pin_read(void *arg, int pin) { struct bcmgpio_softc *sc = arg; int epin = pin + device_unit(sc->sc_dev) * 32; uint32_t val; int res; if (device_unit(sc->sc_dev) > 1) { return 0; } val = bus_space_read_4(sc->sc_iot, sc->sc_ioh, BCM2835_GPIO_GPLEV(epin / BCM2835_GPIO_GPLEV_PINS_PER_REGISTER)); res = val & (1 << (epin % BCM2835_GPIO_GPLEV_PINS_PER_REGISTER)) ? GPIO_PIN_HIGH : GPIO_PIN_LOW; DPRINTF(2, ("%s: gpio_read pin %d->%d\n", device_xname(sc->sc_dev), epin, (res == GPIO_PIN_HIGH))); return res; }
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; }
int grfon(struct grf_softc *gp) { int unit = device_unit(&gp->g_device); /* * XXX: iteoff call relies on devices being in same order * as ITEs and the fact that iteoff only uses the minor part * of the dev arg. */ iteoff(unit, 2); return (*gp->g_sw->gd_mode)(gp, GM_GRFON, (void *) 0); }
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); }
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); }
int grfoff(struct grf_softc *gp) { int unit = device_unit(&gp->g_device); int error; #if 0 /* always fails in EINVAL... */ (void) grfunmap(dev, (void *) 0, curproc); #endif error = (*gp->g_sw->gd_mode)(gp, GM_GRFOFF, (void *) 0); /* XXX: see comment for iteoff above */ iteon(unit, 2); return error; }
static int rdident(device_t parent, struct rd_softc *sc, struct hpibbus_attach_args *ha) { struct rd_describe *desc = sc != NULL ? &sc->sc_rddesc : NULL; u_char stat, cmd[3]; char name[7]; int i, id, n, ctlr, slave; ctlr = device_unit(parent); slave = ha->ha_slave; /* Verify that we have a CS80 device. */ if ((ha->ha_id & 0x200) == 0) return 0; /* Is it one of the disks we support? */ for (id = 0; id < numrdidentinfo; id++) if (ha->ha_id == rdidentinfo[id].ri_hwid) break; if (id == numrdidentinfo || ha->ha_punit > rdidentinfo[id].ri_maxunum) return 0; /* * If we're just probing for the device, that's all the * work we need to do. */ if (sc == NULL) return 1; /* * Reset device and collect description */ rdreset(sc); cmd[0] = C_SUNIT(ha->ha_punit); cmd[1] = C_SVOL(0); cmd[2] = C_DESC; hpibsend(ctlr, slave, C_CMD, cmd, sizeof(cmd)); hpibrecv(ctlr, slave, C_EXEC, desc, 37); hpibrecv(ctlr, slave, C_QSTAT, &stat, sizeof(stat)); memset(name, 0, sizeof(name)); if (stat == 0) { n = desc->d_name; for (i = 5; i >= 0; i--) { name[i] = (n & 0xf) + '0'; n >>= 4; } }
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); }
/* * 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); }
void cpu_mainbus_attach(device_t parent, device_t self, void *aux) { struct cpu_info *ci; KASSERT(device_private(self) == NULL); ci = curcpu(); self->dv_private = ci; ci->ci_dev = self; ci->ci_cpuid = device_unit(self); if (dep_call->cpu_attach_cpu != NULL) (*dep_call->cpu_attach_cpu)(self); else if (ci->ci_cpustr) aprint_normal(": %s\n", ci->ci_cpustr); else aprint_normal("\n"); }