static int tdfx_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr) { /* * mmap(2) is called by a user process to request that an area of memory * associated with this device be mapped for the process to work with. Nprot * holds the protections requested, PROT_READ, PROT_WRITE, or both. */ /**** OLD GET CONFIG ****/ /* struct tdfx_softc* tdfx_info; */ /* Get the configuration for our card XXX*/ /*tdfx_info = dev->si_drv1; */ /************************/ struct tdfx_softc* tdfx_info[2]; tdfx_info[0] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 0); /* If, for some reason, its not configured, we bail out */ if(tdfx_info[0] == NULL) { #ifdef DEBUG printf("tdfx: tdfx_info (softc) is NULL\n"); #endif return -1; } /* We must stay within the bound of our address space */ if((offset & 0xff000000) == tdfx_info[0]->addr0) { offset &= 0xffffff; *paddr = rman_get_start(tdfx_info[0]->memrange) + offset; return 0; } if(tdfx_count > 1) { tdfx_info[1] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 1); if((offset & 0xff000000) == tdfx_info[1]->addr0) { offset &= 0xffffff; *paddr = rman_get_start(tdfx_info[1]->memrange) + offset; return 0; } } /* See if the Banshee/V3 LFB is being requested */ /*if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) == tdfx_info->addr1) { offset &= 0xffffff; return atop(rman_get_start(tdfx_info[1]->memrange2) + offset); }*/ /* VoodooNG code */ /* The ret call */ /* atop -> address to page * rman_get_start, get the (struct resource*)->r_start member, * the mapping base address. */ return -1; }
static int smapi_ioctl (struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td) { struct smapi_softc *sc; int error; error = 0; sc = devclass_get_softc(smapi_devclass, dev2unit(dev)); if (sc == NULL) { error = ENXIO; goto fail; } switch (cmd) { case SMAPIOGHEADER: bcopy((caddr_t)sc->header, data, sizeof(struct smapi_bios_header)); error = 0; break; case SMAPIOCGFUNCTION: smapi32_offset = sc->smapi32_entry; error = smapi32((struct smapi_bios_parameter *)data, (struct smapi_bios_parameter *)data); break; default: error = ENOTTY; } fail: return (error); }
static int tdfx_do_pio_wt(struct tdfx_pio_data *piod) { /* return val */ u_int8_t ret_byte; u_int workport; struct tdfx_softc *tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device); /* Replace old switch w/ massive if(...) */ /* Restricts the access of ports other than those we use */ if(((piod->port != SC_INDEX) && (piod->port != SC_DATA) && (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */ && (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max)) return -EPERM; /* All VGA STATUS REGS are byte registers, size should never be > 1 */ if(piod->size != 1) { return -EINVAL; } /* Write the data to the intended port */ copyin(piod->value, &ret_byte, sizeof(u_int8_t)); workport = piod->port; outb(workport, ret_byte); return 0; }
/* For both of these, I added a variable named workport of type u_int so * that I could eliminate the warning about my data type size. The * applications expect the port to be of type short, so I needed to change * this within the function */ static int tdfx_do_pio_rd(struct tdfx_pio_data *piod) { /* Return val */ u_int8_t ret_byte; u_int workport; struct tdfx_softc *tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device); /* Restricts the access of ports other than those we use */ if(((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) || (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ)) && (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max)) return -EPERM; /* All VGA STATUS REGS are byte registers, size should never be > 1 */ if(piod->size != 1) { return -EINVAL; } /* Write the data to the intended port */ workport = piod->port; ret_byte = inb(workport); copyout(&ret_byte, piod->value, sizeof(u_int8_t)); return 0; }
static void mpt_link_peer(struct mpt_softc *mpt) { struct mpt_softc *mpt2; if (mpt->unit == 0) { return; } /* * XXX: depends on probe order */ mpt2 = (struct mpt_softc *)devclass_get_softc(mpt_devclass,mpt->unit-1); if (mpt2 == NULL) { return; } if (pci_get_vendor(mpt2->dev) != pci_get_vendor(mpt->dev)) { return; } if (pci_get_device(mpt2->dev) != pci_get_device(mpt->dev)) { return; } mpt->mpt2 = mpt2; mpt2->mpt2 = mpt; if (mpt->verbose >= MPT_PRT_DEBUG) { mpt_prt(mpt, "linking with peer (mpt%d)\n", device_get_unit(mpt2->dev)); } }
static int ucom_dev_write(struct dev_write_args *ap) { cdev_t dev = ap->a_head.a_dev; struct ucom_softc *sc; struct tty *tp; int error; sc = devclass_get_softc(ucom_devclass, minor(dev)); lwkt_gettoken(&tty_token); tp = sc->sc_tty; DPRINTF("ucomwrite: tp = %p, flag = 0x%x\n", tp, ap->a_ioflag); #if 0 /* XXXDF */ if (sc->sc_dying) { lwkt_reltoken(&tty_token); return (EIO); } #endif error = (*linesw[tp->t_line].l_write)(tp, ap->a_uio, ap->a_ioflag); DPRINTF("ucomwrite: error = %d\n", error); lwkt_reltoken(&tty_token); return (error); }
ACPI_STATUS AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine) { struct acpi_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if (!acpi_sci_enabled()) return_ACPI_STATUS (AE_OK); if (InterruptNumber > 255 || ServiceRoutine == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL) panic("can't find ACPI device to deregister interrupt"); if (sc->acpi_irq == NULL) return_ACPI_STATUS (AE_NOT_EXIST); bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); sc->acpi_irq = NULL; InterruptHandler = NULL; return_ACPI_STATUS (AE_OK); }
/* * Print the command queue states for controller 0 (callable from DDB) */ void aac_printstate0(void) { struct aac_softc *sc; sc = devclass_get_softc(devclass_find("aac"), 0); aac_print_queues(sc); switch (sc->aac_hwif) { case AAC_HWIF_I960RX: case AAC_HWIF_NARK: device_printf(sc->aac_dev, "IDBR 0x%08x IIMR 0x%08x " "IISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_IDBR), AAC_MEM0_GETREG4(sc, AAC_RX_IIMR), AAC_MEM0_GETREG4(sc, AAC_RX_IISR)); device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x " "OISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_ODBR), AAC_MEM0_GETREG4(sc, AAC_RX_OIMR), AAC_MEM0_GETREG4(sc, AAC_RX_OISR)); AAC_MEM0_SETREG4(sc, AAC_RX_OIMR, 0/*~(AAC_DB_COMMAND_READY | AAC_DB_RESPONSE_READY | AAC_DB_PRINTF)*/); device_printf(sc->aac_dev, "ODBR 0x%08x OIMR 0x%08x " "OISR 0x%08x\n", AAC_MEM0_GETREG4(sc, AAC_RX_ODBR), AAC_MEM0_GETREG4(sc, AAC_RX_OIMR), AAC_MEM0_GETREG4(sc, AAC_RX_OISR)); break; case AAC_HWIF_STRONGARM: /* XXX implement */ break; } }
/* * Kevent handler. Writing is always possible, reading is only possible * if BSR_BULK_IN_FULL is set. Will start the cmx_tick callout and * set sc->polling. */ static int cmx_kqfilter(struct dev_kqfilter_args *ap) { cdev_t dev = ap->a_head.a_dev; struct knote *kn = ap->a_kn; struct cmx_softc *sc; struct klist *klist; ap->a_result = 0; sc = devclass_get_softc(cmx_devclass, minor(dev)); switch (kn->kn_filter) { case EVFILT_READ: kn->kn_fop = &cmx_read_filterops; kn->kn_hook = (caddr_t)sc; break; case EVFILT_WRITE: kn->kn_fop = &cmx_write_filterops; kn->kn_hook = (caddr_t)sc; break; default: ap->a_result = EOPNOTSUPP; return (0); } klist = &sc->kq.ki_note; knote_insert(klist, kn); return (0); }
/* * Close the character device. */ static int cmx_close(struct dev_close_args *ap) { cdev_t dev = ap->a_head.a_dev; struct cmx_softc *sc; sc = devclass_get_softc(cmx_devclass, minor(dev)); if (sc == NULL || sc->dying) return ENXIO; CMX_LOCK(sc); if (!sc->open) { CMX_UNLOCK(sc); return EINVAL; } if (sc->polling) { DEBUG_printf(sc->dev, "disabling polling\n"); callout_stop(&sc->ch); sc->polling = 0; CMX_UNLOCK(sc); KNOTE(&sc->kq.ki_note, 0); CMX_LOCK(sc); } sc->open = 0; CMX_UNLOCK(sc); DEBUG_printf(sc->dev, "close (flags=%b thread=%p)\n", ap->a_fflag, MODEBITS, curthread); return 0; }