void aupciattach(device_t parent, device_t self, void *aux) { struct aupci_softc *sc = device_private(self); struct aubus_attach_args *aa = (struct aubus_attach_args *)aux; uint32_t cfg; #if NPCI > 0 uint32_t mbar, mask; bus_addr_t mstart; struct pcibus_attach_args pba; #endif aupci_found = 1; sc->sc_dev = self; sc->sc_bust = aa->aa_st; if (bus_space_map(sc->sc_bust, aa->aa_addrs[0], 512, 0, &sc->sc_bush) != 0) { aprint_error(": unable to map PCI registers\n"); return; } #if NPCI > 0 /* * These physical addresses are locked in on the CPUs we have * seen. Perhaps these should be passed in via locators, thru * the configuration file. */ sc->sc_cfgbase = PCI_CONFIG_BASE; sc->sc_membase = PCI_MEM_BASE; sc->sc_iobase = PCI_IO_BASE; #endif /* * Configure byte swapping, as YAMON doesn't do it. YAMON does take * care of most of the rest of the details (clocking, etc.), however. */ #if _BYTE_ORDER == _BIG_ENDIAN /* * N.B.: This still doesn't do the DMA thing properly. I have * not yet figured out how to get DMA access to work properly * without having bytes swapped while the processor is in * big-endian mode. I'm not even sure that the Alchemy part * can do it without swapping the bytes (which would be a * bummer, since then only parts which had hardware detection * and swapping support would work without special hacks in * their drivers.) */ cfg = AUPCI_CONFIG_CH | AUPCI_CONFIG_R1H | AUPCI_CONFIG_R2H | AUPCI_CONFIG_AEN | AUPCI_CONFIG_SM | AUPCI_CONFIG_ST | AUPCI_CONFIG_SIC_DATA; #else cfg = AUPCI_CONFIG_CH | AUPCI_CONFIG_R1H | AUPCI_CONFIG_R2H | AUPCI_CONFIG_AEN; #endif bus_space_write_4(sc->sc_bust, sc->sc_bush, AUPCI_CONFIG, cfg); cfg = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_COMMAND_STATUS); aprint_normal(": Alchemy Host-PCI Bridge, %sMHz\n", (cfg & PCI_STATUS_66MHZ_SUPPORT) ? "66" : "33"); aprint_naive("\n"); #if NPCI > 0 /* * PCI configuration space. Address in this bus are * orthogonal to other spaces. We need to make the entire * 32-bit address space available. */ sc->sc_cfgt = &sc->sc_cfg_space; au_himem_space_init(sc->sc_cfgt, "pcicfg", sc->sc_cfgbase, 0x00000000, 0xffffffff, AU_HIMEM_SPACE_IO); /* * Virtual PCI memory. Configured so that we don't overlap * with PCI memory space. */ mask = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_MWMASK); mask >>= AUPCI_MWMASK_SHIFT; mask <<= AUPCI_MWMASK_SHIFT; mbar = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPCI_MBAR); mstart = (mbar & mask) + (~mask + 1); sc->sc_memt = &sc->sc_mem_space; au_himem_space_init(sc->sc_memt, "pcimem", sc->sc_membase, mstart, 0xffffffff, AU_HIMEM_SPACE_LITTLE_ENDIAN); /* * IO space. Address in this bus are orthogonal to other spaces. * 16 MB should be plenty. We don't start from zero to avoid * potential device bugs. */ sc->sc_iot = &sc->sc_io_space; au_himem_space_init(sc->sc_iot, "pciio", sc->sc_iobase, AUPCI_IO_START, AUPCI_IO_END, AU_HIMEM_SPACE_LITTLE_ENDIAN | AU_HIMEM_SPACE_IO); sc->sc_pc.pc_conf_v = sc; sc->sc_pc.pc_attach_hook = aupci_attach_hook; sc->sc_pc.pc_bus_maxdevs = aupci_bus_maxdevs; sc->sc_pc.pc_make_tag = aupci_make_tag; sc->sc_pc.pc_decompose_tag = aupci_decompose_tag; sc->sc_pc.pc_conf_read = aupci_conf_read; sc->sc_pc.pc_conf_write = aupci_conf_write; sc->sc_pc.pc_intr_v = sc; sc->sc_pc.pc_intr_map = aupci_intr_map; sc->sc_pc.pc_intr_string = aupci_intr_string; sc->sc_pc.pc_intr_establish = aupci_intr_establish; sc->sc_pc.pc_intr_disestablish = aupci_intr_disestablish; sc->sc_pc.pc_conf_interrupt = aupci_conf_interrupt; #ifdef PCI_NETBSD_CONFIGURE mem_ex = extent_create("pcimem", mstart, 0xffffffff, NULL, 0, EX_WAITOK); io_ex = extent_create("pciio", AUPCI_IO_START, AUPCI_IO_END, NULL, 0, EX_WAITOK); pci_configure_bus(&sc->sc_pc, io_ex, mem_ex, NULL, 0, mips_cache_info.mci_dcache_align); extent_destroy(mem_ex); extent_destroy(io_ex); #endif pba.pba_iot = sc->sc_iot; pba.pba_memt = sc->sc_memt; /* XXX: review dma tag logic */ pba.pba_dmat = aa->aa_dt; pba.pba_dmat64 = NULL; pba.pba_pc = &sc->sc_pc; pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY; pba.pba_bus = 0; pba.pba_bridgetag = NULL; config_found_ia(self, "pcibus", &pba, pcibusprint); #endif /* NPCI > 0 */ }
/* ARGSUSED */ void flash_attach(device_t parent, device_t self, void *aux) { struct flash_softc * const sc = device_private(self); struct flash_attach_args * const faa = aux; char pbuf[2][sizeof("9999 KB")]; sc->sc_dev = self; sc->sc_parent_dev = parent; sc->flash_if = faa->flash_if; sc->sc_partinfo = faa->partinfo; sc->hw_softc = device_private(parent); format_bytes(pbuf[0], sizeof(pbuf[0]), sc->sc_partinfo.part_size); format_bytes(pbuf[1], sizeof(pbuf[1]), sc->flash_if->erasesize); aprint_naive("\n"); switch (sc->flash_if->type) { case FLASH_TYPE_NOR: aprint_normal(": NOR flash partition size %s, offset %#jx", pbuf[0], (uintmax_t )sc->sc_partinfo.part_offset); break; case FLASH_TYPE_NAND: aprint_normal(": NAND flash partition size %s, offset %#jx", pbuf[0], (uintmax_t )sc->sc_partinfo.part_offset); break; default: aprint_normal(": %s unknown flash", pbuf[0]); } if (sc->sc_partinfo.part_flags & FLASH_PART_READONLY) { sc->sc_readonly = true; aprint_normal(", read only"); } else { sc->sc_readonly = false; } aprint_normal("\n"); if (sc->sc_partinfo.part_size == 0) { aprint_error_dev(self, "partition size must be larger than 0\n"); return; } switch (sc->flash_if->type) { case FLASH_TYPE_NOR: aprint_normal_dev(sc->sc_dev, "erase size %s bytes, write size %d bytes\n", pbuf[1], sc->flash_if->writesize); break; case FLASH_TYPE_NAND: default: aprint_normal_dev(sc->sc_dev, "erase size %s, page size %d bytes, write size %d bytes\n", pbuf[1], sc->flash_if->page_size, sc->flash_if->writesize); break; } if (!pmf_device_register1(sc->sc_dev, NULL, NULL, flash_shutdown)) aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); }
static void sackbc_attach(device_t parent, device_t self, void *aux) { struct sackbc_softc *sc = device_private(self); struct sacc_softc *psc = device_private(parent); struct sa1111_attach_args *aa = (struct sa1111_attach_args *)aux; device_t child; uint32_t tmp, clock_bit; int intr, slot; switch (aa->sa_addr) { case SACC_KBD0: clock_bit = (1<<6); intr = 21; break; case SACC_KBD1: clock_bit = (1<<5); intr = 18; break; default: return; } if (aa->sa_size <= 0) aa->sa_size = SACCKBD_SIZE; if (aa->sa_intr == SACCCF_INTR_DEFAULT) aa->sa_intr = intr; sc->dev = self; sc->iot = psc->sc_iot; if (bus_space_subregion(psc->sc_iot, psc->sc_ioh, aa->sa_addr, aa->sa_size, &sc->ioh)) { aprint_normal(": can't map subregion\n"); return; } /* enable clock for PS/2 kbd or mouse */ tmp = bus_space_read_4(psc->sc_iot, psc->sc_ioh, SACCSC_SKPCR); bus_space_write_4(psc->sc_iot, psc->sc_ioh, SACCSC_SKPCR, tmp | clock_bit); sc->ih_rx = NULL; sc->intr = aa->sa_intr; sc->polling = 0; tmp = bus_space_read_4(sc->iot, sc->ioh, SACCKBD_CR); bus_space_write_4(sc->iot, sc->ioh, SACCKBD_CR, tmp | KBDCR_ENA); /* XXX: this is necessary to get keyboard working. but I don't know why */ bus_space_write_4(sc->iot, sc->ioh, SACCKBD_CLKDIV, 2); tmp = bus_space_read_4(sc->iot, sc->ioh, SACCKBD_STAT); if ((tmp & KBDSTAT_ENA) == 0) { printf("??? can't enable KBD controller\n"); return; } printf("\n"); sc->pt = pckbport_attach(sc, &sackbc_ops); /* * Although there is no such thing as SLOT for SA-1111 kbd * controller, pckbd and pms drivers require it. */ for (slot = PCKBPORT_KBD_SLOT; slot <= PCKBPORT_AUX_SLOT; ++slot) { child = pckbport_attach_slot(self, sc->pt, slot); if (child == NULL) continue; sc->slot = slot; rnd_attach_source(&sc->rnd_source, device_xname(child), RND_TYPE_TTY, 0); /* only one of KBD_SLOT or AUX_SLOT is used. */ break; } }
void urio_attach(device_t parent, device_t self, void *aux) { struct urio_softc *sc = device_private(self); struct usb_attach_arg *uaa = aux; usbd_device_handle dev = uaa->device; usbd_interface_handle iface; char *devinfop; usbd_status err; usb_endpoint_descriptor_t *ed; u_int8_t epcount; int i; DPRINTFN(10,("urio_attach: sc=%p\n", sc)); sc->sc_dev = self; aprint_naive("\n"); aprint_normal("\n"); devinfop = usbd_devinfo_alloc(dev, 0); aprint_normal_dev(self, "%s\n", devinfop); usbd_devinfo_free(devinfop); err = usbd_set_config_no(dev, URIO_CONFIG_NO, 1); if (err) { aprint_error_dev(self, "failed to set configuration" ", err=%s\n", usbd_errstr(err)); return; } err = usbd_device2interface_handle(dev, URIO_IFACE_IDX, &iface); if (err) { aprint_error_dev(self, "getting interface handle failed\n"); return; } sc->sc_udev = dev; sc->sc_iface = iface; epcount = 0; (void)usbd_endpoint_count(iface, &epcount); sc->sc_in_addr = -1; sc->sc_out_addr = -1; for (i = 0; i < epcount; i++) { ed = usbd_interface2endpoint_descriptor(iface, i); if (ed == NULL) { aprint_error_dev(self, "couldn't get ep %d\n", i); return; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->sc_in_addr = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->sc_out_addr = ed->bEndpointAddress; } } if (sc->sc_in_addr == -1 || sc->sc_out_addr == -1) { aprint_error_dev(self, "missing endpoint\n"); return; } DPRINTFN(10, ("urio_attach: %p\n", sc->sc_udev)); usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev); return; }
static void se_attach(device_t parent, device_t self, void *args) { struct se_softc *sc = device_private(self); struct ncr5380_softc *ncr_sc = &sc->ncr_sc; struct cfdata *cf = device_cfdata(self); struct sebuf_attach_args *aa = args; volatile struct se_regs *regs; int i; ncr_sc->sc_dev = self; /* Get options from config flags if specified. */ if (cf->cf_flags) sc->sc_options = cf->cf_flags; else sc->sc_options = se_options; aprint_normal(": options=0x%x\n", sc->sc_options); sc->sc_adapter_type = aa->ca.ca_bustype; sc->sc_adapter_iv = aa->ca.ca_intvec; sc->sc_regs = regs = aa->regs; /* * MD function pointers used by the MI code. */ ncr_sc->sc_pio_out = ncr5380_pio_out; ncr_sc->sc_pio_in = ncr5380_pio_in; #if 0 /* XXX - not yet... */ ncr_sc->sc_dma_alloc = se_dma_alloc; ncr_sc->sc_dma_free = se_dma_free; ncr_sc->sc_dma_setup = se_dma_setup; ncr_sc->sc_dma_start = se_dma_start; ncr_sc->sc_dma_poll = se_dma_poll; ncr_sc->sc_dma_eop = se_dma_eop; ncr_sc->sc_dma_stop = se_dma_stop; ncr_sc->sc_intr_on = se_intr_on; ncr_sc->sc_intr_off = se_intr_off; #endif /* XXX */ /* Attach interrupt handler. */ isr_add_vectored(se_intr, (void *)sc, aa->ca.ca_intpri, aa->ca.ca_intvec); /* Reset the hardware. */ se_reset(ncr_sc); /* Do the common attach stuff. */ /* * Support the "options" (config file flags). * Disconnect/reselect is a per-target mask. * Interrupts and DMA are per-controller. */ ncr_sc->sc_no_disconnect = (sc->sc_options & SE_NO_DISCONNECT); ncr_sc->sc_parity_disable = (sc->sc_options & SE_NO_PARITY_CHK) >> 8; if (sc->sc_options & SE_FORCE_POLLING) ncr_sc->sc_flags |= NCR5380_FORCE_POLLING; #if 1 /* XXX - Temporary */ /* XXX - In case we think DMA is completely broken... */ if (sc->sc_options & SE_DISABLE_DMA) { /* Override this function pointer. */ ncr_sc->sc_dma_alloc = NULL; } #endif ncr_sc->sc_min_dma_len = MIN_DMA_LEN; /* * Initialize fields used by the MI code */ ncr_sc->sci_r0 = ®s->ncrregs[0]; ncr_sc->sci_r1 = ®s->ncrregs[1]; ncr_sc->sci_r2 = ®s->ncrregs[2]; ncr_sc->sci_r3 = ®s->ncrregs[3]; ncr_sc->sci_r4 = ®s->ncrregs[4]; ncr_sc->sci_r5 = ®s->ncrregs[5]; ncr_sc->sci_r6 = ®s->ncrregs[6]; ncr_sc->sci_r7 = ®s->ncrregs[7]; ncr_sc->sc_rev = NCR_VARIANT_NCR5380; /* * Allocate DMA handles. */ i = SCI_OPENINGS * sizeof(struct se_dma_handle); sc->sc_dma = malloc(i, M_DEVBUF, M_WAITOK); if (sc->sc_dma == NULL) panic("se: dma_malloc failed"); for (i = 0; i < SCI_OPENINGS; i++) sc->sc_dma[i].dh_flags = 0; ncr_sc->sc_channel.chan_id = 7; ncr_sc->sc_adapter.adapt_minphys = se_minphys; /* * Initialize se board itself. */ ncr5380_attach(ncr_sc); }
/* Attach */ void url_attach(device_t parent, device_t self, void *aux) { struct url_softc *sc = device_private(self); struct usb_attach_arg *uaa = aux; usbd_device_handle dev = uaa->device; usbd_interface_handle iface; usbd_status err; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; char *devinfop; struct ifnet *ifp; struct mii_data *mii; u_char eaddr[ETHER_ADDR_LEN]; int i, s; sc->sc_dev = self; aprint_naive("\n"); aprint_normal("\n"); devinfop = usbd_devinfo_alloc(dev, 0); aprint_normal_dev(self, "%s\n", devinfop); usbd_devinfo_free(devinfop); /* Move the device into the configured state. */ err = usbd_set_config_no(dev, URL_CONFIG_NO, 1); if (err) { aprint_error_dev(self, "failed to set configuration" ", err=%s\n", usbd_errstr(err)); goto bad; } usb_init_task(&sc->sc_tick_task, url_tick_task, sc, 0); rw_init(&sc->sc_mii_rwlock); usb_init_task(&sc->sc_stop_task, (void (*)(void *))url_stop_task, sc, 0); /* get control interface */ err = usbd_device2interface_handle(dev, URL_IFACE_INDEX, &iface); if (err) { aprint_error_dev(self, "failed to get interface, err=%s\n", usbd_errstr(err)); goto bad; } sc->sc_udev = dev; sc->sc_ctl_iface = iface; sc->sc_flags = url_lookup(uaa->vendor, uaa->product)->url_flags; /* get interface descriptor */ id = usbd_get_interface_descriptor(sc->sc_ctl_iface); /* find endpoints */ sc->sc_bulkin_no = sc->sc_bulkout_no = sc->sc_intrin_no = -1; for (i = 0; i < id->bNumEndpoints; i++) { ed = usbd_interface2endpoint_descriptor(sc->sc_ctl_iface, i); if (ed == NULL) { aprint_error_dev(self, "couldn't get endpoint %d\n", i); goto bad; } if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) sc->sc_bulkin_no = ed->bEndpointAddress; /* RX */ else if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT) sc->sc_bulkout_no = ed->bEndpointAddress; /* TX */ else if ((ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT && UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) sc->sc_intrin_no = ed->bEndpointAddress; /* Status */ } if (sc->sc_bulkin_no == -1 || sc->sc_bulkout_no == -1 || sc->sc_intrin_no == -1) { aprint_error_dev(self, "missing endpoint\n"); goto bad; } s = splnet(); /* reset the adapter */ url_reset(sc); /* Get Ethernet Address */ err = url_mem(sc, URL_CMD_READMEM, URL_IDR0, (void *)eaddr, ETHER_ADDR_LEN); if (err) { aprint_error_dev(self, "read MAC address failed\n"); splx(s); goto bad; } /* Print Ethernet Address */ aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(eaddr)); /* initialize interface information */ ifp = GET_IFP(sc); ifp->if_softc = sc; ifp->if_mtu = ETHERMTU; strncpy(ifp->if_xname, device_xname(self), IFNAMSIZ); ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_start = url_start; ifp->if_ioctl = url_ioctl; ifp->if_watchdog = url_watchdog; ifp->if_init = url_init; ifp->if_stop = url_stop; IFQ_SET_READY(&ifp->if_snd); /* * Do ifmedia setup. */ mii = &sc->sc_mii; mii->mii_ifp = ifp; mii->mii_readreg = url_int_miibus_readreg; mii->mii_writereg = url_int_miibus_writereg; #if 0 if (sc->sc_flags & URL_EXT_PHY) { mii->mii_readreg = url_ext_miibus_readreg; mii->mii_writereg = url_ext_miibus_writereg; } #endif mii->mii_statchg = url_miibus_statchg; mii->mii_flags = MIIF_AUTOTSLEEP; sc->sc_ec.ec_mii = mii; ifmedia_init(&mii->mii_media, 0, url_ifmedia_change, url_ifmedia_status); mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0); if (LIST_FIRST(&mii->mii_phys) == NULL) { ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL); ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE); } else ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO); /* attach the interface */ if_attach(ifp); ether_ifattach(ifp, eaddr); rnd_attach_source(&sc->rnd_source, device_xname(self), RND_TYPE_NET, 0); callout_init(&sc->sc_stat_ch, 0); sc->sc_attached = 1; splx(s); usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, dev, sc->sc_dev); return; bad: sc->sc_dying = 1; return; }
static void ohci_pci_attach(device_t parent, device_t self, void *aux) { struct ohci_pci_softc *sc = device_private(self); struct pci_attach_args *pa = (struct pci_attach_args *)aux; pci_chipset_tag_t pc = pa->pa_pc; pcitag_t tag = pa->pa_tag; char const *intrstr; pci_intr_handle_t ih; pcireg_t csr; usbd_status r; const char *vendor; char intrbuf[PCI_INTRSTR_LEN]; sc->sc.sc_dev = self; sc->sc.sc_bus.hci_private = sc; if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS && PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_USB) { sc->sc.sc_flags = OHCIF_SUPERIO; } pci_aprint_devinfo(pa, "USB Controller"); /* check if memory space access is enabled */ csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); #ifdef DEBUG printf("csr: %08x\n", csr); #endif if ((csr & PCI_COMMAND_MEM_ENABLE) == 0) { aprint_error_dev(self, "memory access is disabled\n"); return; } /* Map I/O registers */ if (pci_mapreg_map(pa, PCI_CBMEM, PCI_MAPREG_TYPE_MEM, 0, &sc->sc.iot, &sc->sc.ioh, NULL, &sc->sc.sc_size)) { sc->sc.sc_size = 0; aprint_error_dev(self, "can't map mem space\n"); return; } /* Disable interrupts, so we don't get any spurious ones. */ bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS); sc->sc_pc = pc; sc->sc_tag = tag; sc->sc.sc_bus.dmatag = pa->pa_dmat; /* Enable the device. */ pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr | PCI_COMMAND_MASTER_ENABLE); /* Map and establish the interrupt. */ if (pci_intr_map(pa, &ih)) { aprint_error_dev(self, "couldn't map interrupt\n"); goto fail; } /* * Allocate IRQ */ intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf)); sc->sc_ih = pci_intr_establish(pc, ih, IPL_SCHED, ohci_intr, sc); if (sc->sc_ih == NULL) { aprint_error_dev(self, "couldn't establish interrupt"); if (intrstr != NULL) aprint_error(" at %s", intrstr); aprint_error("\n"); goto fail; } aprint_normal_dev(self, "interrupting at %s\n", intrstr); /* Figure out vendor for root hub descriptor. */ vendor = pci_findvendor(pa->pa_id); sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id); if (vendor) strlcpy(sc->sc.sc_vendor, vendor, sizeof(sc->sc.sc_vendor)); else snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor), "vendor 0x%04x", PCI_VENDOR(pa->pa_id)); r = ohci_init(&sc->sc); if (r != USBD_NORMAL_COMPLETION) { aprint_error_dev(self, "init failed, error=%d\n", r); goto fail; } #if NEHCI > 0 usb_pci_add(&sc->sc_pci, pa, self); #endif if (!pmf_device_register1(self, ohci_suspend, ohci_resume, ohci_shutdown)) aprint_error_dev(self, "couldn't establish power handler\n"); /* Attach usb device. */ sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint); return; fail: if (sc->sc_ih) { pci_intr_disestablish(sc->sc_pc, sc->sc_ih); sc->sc_ih = NULL; } if (sc->sc.sc_size) { bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size); sc->sc.sc_size = 0; } return; }
static void sf_pci_attach(device_t parent, device_t self, void *aux) { struct sf_pci_softc *psc = device_private(self); struct sf_softc *sc = &psc->sc_starfire; struct pci_attach_args *pa = aux; pci_intr_handle_t ih; const char *intrstr = NULL; const struct sf_pci_product *spp; bus_space_tag_t iot, memt; bus_space_handle_t ioh, memh; pcireg_t reg; int error, ioh_valid, memh_valid; char intrbuf[PCI_INTRSTR_LEN]; sc->sc_dev = self; spp = sf_pci_lookup(pa); if (spp == NULL) { printf("\n"); panic("sf_pci_attach: impossible"); } printf(": %s, rev. %d\n", spp->spp_name, PCI_REVISION(pa->pa_class)); /* power up chip */ if ((error = pci_activate(pa->pa_pc, pa->pa_tag, self, NULL)) && error != EOPNOTSUPP) { aprint_error_dev(self, "cannot activate %d\n", error); return; } /* * Map the device. */ reg = pci_mapreg_type(pa->pa_pc, pa->pa_tag, SF_PCI_MEMBA); switch (reg) { case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT: case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT: memh_valid = (pci_mapreg_map(pa, SF_PCI_MEMBA, reg, 0, &memt, &memh, NULL, NULL) == 0); break; default: memh_valid = 0; } ioh_valid = (pci_mapreg_map(pa, (reg == (PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT)) ? SF_PCI_IOBA : SF_PCI_IOBA - 0x04, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, NULL, NULL) == 0); if (memh_valid) { sc->sc_st = memt; sc->sc_sh = memh; sc->sc_iomapped = 0; } else if (ioh_valid) { sc->sc_st = iot; sc->sc_sh = ioh; sc->sc_iomapped = 1; } else { aprint_error_dev(self, "unable to map device registers\n"); return; } sc->sc_dmat = pa->pa_dmat; /* Make sure bus mastering is enabled. */ pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | PCI_COMMAND_MASTER_ENABLE); /* * Map and establish our interrupt. */ if (pci_intr_map(pa, &ih)) { aprint_error_dev(self, "unable to map interrupt\n"); return; } intrstr = pci_intr_string(pa->pa_pc, ih, intrbuf, sizeof(intrbuf)); psc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_NET, sf_intr, sc); if (psc->sc_ih == NULL) { aprint_error_dev(self, "unable to establish interrupt"); if (intrstr != NULL) aprint_error(" at %s", intrstr); aprint_error("\n"); return; } aprint_normal_dev(self, "interrupting at %s\n", intrstr); /* * Finish off the attach. */ sf_attach(sc); }
void tap_attach(device_t parent, device_t self, void *aux) { struct tap_softc *sc = device_private(self); struct ifnet *ifp; #if defined(COMPAT_40) || defined(MODULAR) const struct sysctlnode *node; int error; #endif uint8_t enaddr[ETHER_ADDR_LEN] = { 0xf2, 0x0b, 0xa4, 0xff, 0xff, 0xff }; char enaddrstr[3 * ETHER_ADDR_LEN]; struct timeval tv; uint32_t ui; sc->sc_dev = self; sc->sc_sih = softint_establish(SOFTINT_CLOCK, tap_softintr, sc); getnanotime(&sc->sc_btime); sc->sc_atime = sc->sc_mtime = sc->sc_btime; if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); /* * In order to obtain unique initial Ethernet address on a host, * do some randomisation using the current uptime. It's not meant * for anything but avoiding hard-coding an address. */ getmicrouptime(&tv); ui = (tv.tv_sec ^ tv.tv_usec) & 0xffffff; memcpy(enaddr+3, (uint8_t *)&ui, 3); aprint_verbose_dev(self, "Ethernet address %s\n", ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr)); /* * Why 1000baseT? Why not? You can add more. * * Note that there are 3 steps: init, one or several additions to * list of supported media, and in the end, the selection of one * of them. */ ifmedia_init(&sc->sc_im, 0, tap_mediachange, tap_mediastatus); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_1000_T, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_1000_T|IFM_FDX, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_100_TX, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_10_T, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL); ifmedia_add(&sc->sc_im, IFM_ETHER|IFM_AUTO, 0, NULL); ifmedia_set(&sc->sc_im, IFM_ETHER|IFM_AUTO); /* * One should note that an interface must do multicast in order * to support IPv6. */ ifp = &sc->sc_ec.ec_if; strcpy(ifp->if_xname, device_xname(self)); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = tap_ioctl; ifp->if_start = tap_start; ifp->if_stop = tap_stop; ifp->if_init = tap_init; IFQ_SET_READY(&ifp->if_snd); sc->sc_ec.ec_capabilities = ETHERCAP_VLAN_MTU | ETHERCAP_JUMBO_MTU; /* Those steps are mandatory for an Ethernet driver, the fisrt call * being common to all network interface drivers. */ if_attach(ifp); ether_ifattach(ifp, enaddr); sc->sc_flags = 0; #if defined(COMPAT_40) || defined(MODULAR) /* * Add a sysctl node for that interface. * * The pointer transmitted is not a string, but instead a pointer to * the softc structure, which we can use to build the string value on * the fly in the helper function of the node. See the comments for * tap_sysctl_handler for details. * * Usually sysctl_createv is called with CTL_CREATE as the before-last * component. However, we can allocate a number ourselves, as we are * the only consumer of the net.link.<iface> node. In this case, the * unit number is conveniently used to number the node. CTL_CREATE * would just work, too. */ if ((error = sysctl_createv(NULL, 0, NULL, &node, CTLFLAG_READWRITE, CTLTYPE_STRING, device_xname(self), NULL, tap_sysctl_handler, 0, sc, 18, CTL_NET, AF_LINK, tap_node, device_unit(sc->sc_dev), CTL_EOL)) != 0) aprint_error_dev(self, "sysctl_createv returned %d, ignoring\n", error); #endif /* * Initialize the two locks for the device. * * We need a lock here because even though the tap device can be * opened only once, the file descriptor might be passed to another * process, say a fork(2)ed child. * * The Giant saves us from most of the hassle, but since the read * operation can sleep, we don't want two processes to wake up at * the same moment and both try and dequeue a single packet. * * The queue for event listeners (used by kqueue(9), see below) has * to be protected, too, but we don't need the same level of * complexity for that lock, so a simple spinning lock is fine. */ mutex_init(&sc->sc_rdlock, MUTEX_DEFAULT, IPL_NONE); simple_lock_init(&sc->sc_kqlock); selinit(&sc->sc_rsel); }
void atzscattach(device_t parent, device_t self, void *aux) { volatile struct sdmac *rp; struct sbic_softc *sc = device_private(self); struct zbus_args *zap; struct scsipi_adapter *adapt = &sc->sc_adapter; struct scsipi_channel *chan = &sc->sc_channel; zap = aux; sc->sc_dev = self; sc->sc_cregs = rp = zap->va; /* * disable ints and reset bank register */ rp->CNTR = CNTR_PDMD; amiga_membarrier(); rp->DAWR = DAWR_ATZSC; amiga_membarrier(); sc->sc_enintr = atzsc_enintr; sc->sc_dmago = atzsc_dmago; sc->sc_dmanext = atzsc_dmanext; sc->sc_dmastop = atzsc_dmastop; sc->sc_dmacmd = 0; /* * only 24 bit mem. */ sc->sc_flags |= SBICF_BADDMA; sc->sc_dmamask = ~0x00ffffff; #if 0 /* * If the users kva space is not ztwo try and allocate a bounce buffer. * XXX this needs to change if we move to multiple memory segments. */ if (kvtop(sc) & sc->sc_dmamask) { sc->sc_dmabuffer = (char *)alloc_z2mem(MAXPHYS * 8); /* XXX */ if (isztwomem(sc->sc_dmabuffer)) printf(" bounce pa 0x%x", kvtop(sc->sc_dmabuffer)); else if (sc->sc_dmabuffer) printf(" bounce pa 0x%x", PREP_DMA_MEM(sc->sc_dmabuffer)); } #endif sc->sc_sbic.sbic_asr_p = (volatile unsigned char *)rp + 0x91; sc->sc_sbic.sbic_value_p = (volatile unsigned char *)rp + 0x93; sc->sc_clkfreq = sbic_clock_override ? sbic_clock_override : 77; printf(": dmamask 0x%lx\n", ~sc->sc_dmamask); /* * Fill in the scsipi_adapter. */ memset(adapt, 0, sizeof(*adapt)); adapt->adapt_dev = self; adapt->adapt_nchannels = 1; adapt->adapt_openings = 7; adapt->adapt_max_periph = 1; adapt->adapt_request = sbic_scsipi_request; adapt->adapt_minphys = sbic_minphys; /* * Fill in the scsipi_channel. */ memset(chan, 0, sizeof(*chan)); chan->chan_adapter = adapt; chan->chan_bustype = &scsi_bustype; chan->chan_channel = 0; chan->chan_ntargets = 8; chan->chan_nluns = 8; chan->chan_id = 7; sbicinit(sc); sc->sc_isr.isr_intr = atzsc_dmaintr; sc->sc_isr.isr_arg = sc; sc->sc_isr.isr_ipl = 2; add_isr (&sc->sc_isr); /* * attach all scsi units on us */ config_found(self, chan, scsiprint); }
void pciattach(device_t parent, device_t self, void *aux) { struct pcibus_attach_args *pba = aux; struct pci_softc *sc = device_private(self); int io_enabled, mem_enabled, mrl_enabled, mrm_enabled, mwi_enabled; const char *sep = ""; static const int wildcard[PCICF_NLOCS] = { PCICF_DEV_DEFAULT, PCICF_FUNCTION_DEFAULT }; sc->sc_dev = self; pci_attach_hook(parent, self, pba); aprint_naive("\n"); aprint_normal("\n"); io_enabled = (pba->pba_flags & PCI_FLAGS_IO_OKAY); mem_enabled = (pba->pba_flags & PCI_FLAGS_MEM_OKAY); mrl_enabled = (pba->pba_flags & PCI_FLAGS_MRL_OKAY); mrm_enabled = (pba->pba_flags & PCI_FLAGS_MRM_OKAY); mwi_enabled = (pba->pba_flags & PCI_FLAGS_MWI_OKAY); if (io_enabled == 0 && mem_enabled == 0) { aprint_error_dev(self, "no spaces enabled!\n"); goto fail; } #define PRINT(str) \ do { \ aprint_verbose("%s%s", sep, str); \ sep = ", "; \ } while (/*CONSTCOND*/0) aprint_verbose_dev(self, ""); if (io_enabled) PRINT("i/o space"); if (mem_enabled) PRINT("memory space"); aprint_verbose(" enabled"); if (mrl_enabled || mrm_enabled || mwi_enabled) { if (mrl_enabled) PRINT("rd/line"); if (mrm_enabled) PRINT("rd/mult"); if (mwi_enabled) PRINT("wr/inv"); aprint_verbose(" ok"); } aprint_verbose("\n"); #undef PRINT sc->sc_iot = pba->pba_iot; sc->sc_memt = pba->pba_memt; sc->sc_dmat = pba->pba_dmat; sc->sc_dmat64 = pba->pba_dmat64; sc->sc_pc = pba->pba_pc; sc->sc_bus = pba->pba_bus; sc->sc_bridgetag = pba->pba_bridgetag; sc->sc_maxndevs = pci_bus_maxdevs(pba->pba_pc, pba->pba_bus); sc->sc_intrswiz = pba->pba_intrswiz; sc->sc_intrtag = pba->pba_intrtag; sc->sc_flags = pba->pba_flags; device_pmf_driver_set_child_register(sc->sc_dev, pci_child_register); pcirescan(sc->sc_dev, "pci", wildcard); fail: if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); }
static void pckbc_acpi_finish_attach(device_t dv) { pckbc_attach(device_private(dv)); }
static void pckbc_acpi_attach(device_t parent, device_t self, void *aux) { struct pckbc_acpi_softc *psc = device_private(self); struct pckbc_softc *sc = &psc->sc_pckbc; struct pckbc_internal *t; struct acpi_attach_args *aa = aux; bus_space_handle_t ioh_d, ioh_c; pckbc_slot_t peer; struct acpi_resources res; struct acpi_io *io0, *io1, *ioswap; struct acpi_irq *irq; ACPI_STATUS rv; sc->sc_dv = self; psc->sc_ic = aa->aa_ic; if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_kbd)) { psc->sc_slot = PCKBC_KBD_SLOT; peer = PCKBC_AUX_SLOT; } else if (acpi_match_hid(aa->aa_node->ad_devinfo, pckbc_acpi_ids_ms)) { psc->sc_slot = PCKBC_AUX_SLOT; peer = PCKBC_KBD_SLOT; } else { aprint_error(": unknown port!\n"); panic("pckbc_acpi_attach: impossible"); } aprint_naive("\n"); aprint_normal(": %s port\n", pckbc_slot_names[psc->sc_slot]); /* parse resources */ rv = acpi_resource_parse(sc->sc_dv, aa->aa_node->ad_handle, "_CRS", &res, &acpi_resource_parse_ops_default); if (ACPI_FAILURE(rv)) return; /* find our IRQ */ irq = acpi_res_irq(&res, 0); if (irq == NULL) { aprint_error_dev(self, "unable to find irq resource\n"); goto out; } psc->sc_irq = irq->ar_irq; psc->sc_ist = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL; if (psc->sc_slot == PCKBC_KBD_SLOT) first = psc; if ((!first || !first->sc_pckbc.id) && (psc->sc_slot == PCKBC_KBD_SLOT)) { io0 = acpi_res_io(&res, 0); io1 = acpi_res_io(&res, 1); if (io0 == NULL || io1 == NULL) { aprint_error_dev(self, "unable to find i/o resources\n"); goto out; } /* * JDM: Some firmware doesn't report resources in the order we * expect; sort IO resources here (lowest first) */ if (io0->ar_base > io1->ar_base) { ioswap = io0; io0 = io1; io1 = ioswap; } if (pckbc_is_console(aa->aa_iot, io0->ar_base)) { t = &pckbc_consdata; ioh_d = t->t_ioh_d; ioh_c = t->t_ioh_c; pckbc_console_attached = 1; /* t->t_cmdbyte was initialized by cnattach */ } else { if (bus_space_map(aa->aa_iot, io0->ar_base, io0->ar_length, 0, &ioh_d) || bus_space_map(aa->aa_iot, io1->ar_base, io1->ar_length, 0, &ioh_c)) panic("pckbc_acpi_attach: couldn't map"); t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK|M_ZERO); t->t_iot = aa->aa_iot; t->t_ioh_d = ioh_d; t->t_ioh_c = ioh_c; t->t_addr = io0->ar_base; t->t_cmdbyte = KC8_CPU; /* Enable ports */ callout_init(&t->t_cleanup, 0); } t->t_sc = &first->sc_pckbc; first->sc_pckbc.id = t; if (!pmf_device_register(self, NULL, pckbc_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); first->sc_pckbc.intr_establish = pckbc_acpi_intr_establish; config_defer(first->sc_pckbc.sc_dv, pckbc_acpi_finish_attach); } else if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); out: acpi_resource_cleanup(&res); }
void wdc_buddha_attach(device_t parent, device_t self, void *aux) { struct wdc_buddha_softc *sc; struct zbus_args *zap; int nchannels; int ch; sc = device_private(self); sc->sc_wdcdev.sc_atac.atac_dev = self; zap = aux; sc->ba = zap->va; sc->sc_iot.base = (bus_addr_t)sc->ba; sc->sc_iot.absm = &amiga_bus_stride_4swap; nchannels = 2; if (zap->prodid == 42) { aprint_normal(": Catweasel Z2\n"); nchannels = 3; } else if (zap->serno == 0) aprint_normal(": Buddha\n"); else aprint_normal(": Buddha Flash\n"); /* XXX pio mode setting not implemented yet. */ sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16; sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray; sc->sc_wdcdev.sc_atac.atac_nchannels = nchannels; wdc_allocate_regs(&sc->sc_wdcdev); for (ch = 0; ch < nchannels; ch++) { struct ata_channel *cp; struct wdc_regs *wdr; int i; cp = &sc->channels[ch]; sc->wdc_chanarray[ch] = cp; cp->ch_channel = ch; cp->ch_atac = &sc->sc_wdcdev.sc_atac; cp->ch_queue = malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT); if (cp->ch_queue == NULL) { aprint_error_dev(self, "can't allocate memory for command queue\n"); return; } cp->ch_ndrive = 2; /* * XXX According to the Buddha docs, we should use a method * array that adds 0x40 to the address for byte accesses, to * get the slow timing for command accesses, and the 0x00 * offset for the word (fast) accesses. This will be * reconsidered when implementing setting the timing. * * XXX We also could consider to abuse the 32bit capability, or * 32bit accesses to the words (which will read in two words) * for better performance. * -is */ wdr = CHAN_TO_WDC_REGS(cp); wdr->cmd_iot = &sc->sc_iot; if (bus_space_map(wdr->cmd_iot, 0x210+ch*0x80, 8, 0, &wdr->cmd_baseioh)) { aprint_error_dev(self, "couldn't map cmd registers\n"); return; } wdr->ctl_iot = &sc->sc_iot; if (bus_space_map(wdr->ctl_iot, 0x250+ch*0x80, 2, 0, &wdr->ctl_ioh)) { bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, 8); aprint_error_dev(self, "couldn't map ctl registers\n"); return; } for (i = 0; i < WDC_NREG; i++) { if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh, i, i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) { aprint_error_dev(self, "couldn't subregion cmd regs\n"); return; } } wdc_init_shadow_regs(cp); wdcattach(cp); } sc->sc_isr.isr_intr = wdc_buddha_intr; sc->sc_isr.isr_arg = sc; sc->sc_isr.isr_ipl = 2; add_isr (&sc->sc_isr); sc->ba[0xfc0] = 0; /* enable interrupts */ }
static void uninorth_attach(device_t parent, device_t self, void *aux) { struct uninorth_softc *sc = device_private(self); pci_chipset_tag_t pc = &sc->sc_pc; struct confargs *ca = aux; struct pcibus_attach_args pba; int len, child, node = ca->ca_node; uint32_t reg[2], busrange[2]; char compat[32]; int ver; struct ranges { uint32_t pci_hi, pci_mid, pci_lo; uint32_t host; uint32_t size_hi, size_lo; } ranges[6], *rp = ranges; printf("\n"); sc->sc_dev = self; memset(compat, 0, sizeof(compat)); OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat)); if (strcmp(compat, "u3-agp") == 0) ver = 3; else if (strcmp(compat, "u4-pcie") == 0) ver = 4; else ver = 0; /* UniNorth address */ if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8) return; /* PCI bus number */ if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) return; memset(&sc->sc_iot, 0, sizeof(sc->sc_iot)); /* find i/o tag */ len = OF_getprop(node, "ranges", ranges, sizeof(ranges)); if (len == -1) return; while (len >= sizeof(ranges[0])) { if ((rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) == OFW_PCI_PHYS_HI_SPACE_IO) { sc->sc_iot.pbs_base = rp->host; sc->sc_iot.pbs_limit = rp->host + rp->size_lo; break; } len -= sizeof(ranges[0]); rp++; } /* XXX enable gmac ethernet */ for (child = OF_child(node); child; child = OF_peer(child)) { volatile int *gmac_gbclock_en = (void *)0xf8000020; memset(compat, 0, sizeof(compat)); OF_getprop(child, "compatible", compat, sizeof(compat)); if (strcmp(compat, "gmac") == 0) *gmac_gbclock_en |= 0x02; } sc->sc_iot.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE; sc->sc_iot.pbs_offset = 0; if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_IO, node, &sc->sc_iot, "uninorth io-space") != 0) panic("Can't init uninorth io tag"); memset(&sc->sc_memt, 0, sizeof(sc->sc_memt)); sc->sc_memt.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE; sc->sc_memt.pbs_base = 0x00000000; if (ofwoea_map_space(RANGE_TYPE_PCI, RANGE_MEM, node, &sc->sc_memt, "uninorth mem-space") != 0) panic("Can't init uninorth mem tag"); macppc_pci_get_chipset_tag(pc); pc->pc_node = node; pc->pc_bus = busrange[0]; pc->pc_iot = &sc->sc_iot; pc->pc_memt = &sc->sc_memt; if (ver < 3) { pc->pc_addr = mapiodev(reg[0] + 0x800000, 4, false); pc->pc_data = mapiodev(reg[0] + 0xc00000, 8, false); pc->pc_conf_read = uninorth_conf_read; pc->pc_conf_write = uninorth_conf_write; } else { pc->pc_addr = mapiodev(reg[1] + 0x800000, 4, false); pc->pc_data = mapiodev(reg[1] + 0xc00000, 8, false); pc->pc_conf_read = uninorth_conf_read_v3; pc->pc_conf_write = uninorth_conf_write_v3; } memset(&pba, 0, sizeof(pba)); pba.pba_memt = pc->pc_memt; pba.pba_iot = pc->pc_iot; pba.pba_dmat = &pci_bus_dma_tag; pba.pba_dmat64 = NULL; pba.pba_bus = pc->pc_bus; pba.pba_bridgetag = NULL; pba.pba_pc = pc; pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY; config_found_ia(self, "pcibus", &pba, pcibusprint); }
static void sony_acpi_attach(device_t parent, device_t self, void *aux) { struct sony_acpi_softc *sc = device_private(self); struct acpi_attach_args *aa = aux; ACPI_STATUS rv; int i; aprint_naive(": Sony Miscellaneous Controller\n"); aprint_normal(": Sony Miscellaneous Controller\n"); sc->sc_node = aa->aa_node; sc->sc_dev = self; rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 100, sony_acpi_find_pic, sc, NULL); if (ACPI_FAILURE(rv)) aprint_error_dev(self, "couldn't walk namespace: %s\n", AcpiFormatException(rv)); /* * If we don't find an SNY6001 device, assume that we need the * Fn key initialization sequence. */ if (sc->sc_has_pic == false) sc->sc_quirks |= SONY_ACPI_QUIRK_FNINIT; sony_acpi_quirk_setup(sc); /* Configure suspend button and hotkeys */ sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_name = device_xname(self); sc->sc_smpsw[SONY_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP; sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE; sc->sc_smpsw[SONY_PSW_DISPLAY_CYCLE].smpsw_type = PSWITCH_TYPE_HOTKEY; sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_name = PSWITCH_HK_ZOOM_BUTTON; sc->sc_smpsw[SONY_PSW_ZOOM].smpsw_type = PSWITCH_TYPE_HOTKEY; sc->sc_smpsw_valid = 1; for (i = 0; i < SONY_PSW_LAST; i++) if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) { aprint_error_dev(self, "couldn't register %s with sysmon\n", sc->sc_smpsw[i].smpsw_name); sc->sc_smpsw_valid = 0; } /* Install notify handler */ rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_DEVICE_NOTIFY, sony_acpi_notify_handler, self); if (ACPI_FAILURE(rv)) aprint_error_dev(self, "couldn't install notify handler (%d)\n", rv); /* Install sysctl handler */ rv = AcpiWalkNamespace(ACPI_TYPE_METHOD, sc->sc_node->ad_handle, 1, sony_walk_cb, sc, NULL); #ifdef DIAGNOSTIC if (ACPI_FAILURE(rv)) aprint_error_dev(self, "Cannot walk ACPI namespace (%d)\n", rv); #endif if (!pmf_device_register(self, sony_acpi_suspend, sony_acpi_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP, sony_acpi_brightness_up, true)) aprint_error_dev(self, "couldn't register BRIGHTNESS UP handler\n"); if (!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_DOWN, sony_acpi_brightness_down, true)) aprint_error_dev(self, "couldn't register BRIGHTNESS DOWN handler\n"); }
Static void url_int_miibus_writereg(device_t dev, int phy, int reg, int data) { struct url_softc *sc; if (dev == NULL) return; sc = device_private(dev); DPRINTFN(0xff, ("%s: %s: enter, phy=%d reg=0x%04x data=0x%04x\n", device_xname(sc->sc_dev), __func__, phy, reg, data)); if (sc->sc_dying) { #ifdef DIAGNOSTIC printf("%s: %s: dying\n", device_xname(sc->sc_dev), __func__); #endif return; } /* XXX: one PHY only for the RTL8150 internal PHY */ if (phy != 0) { DPRINTFN(0xff, ("%s: %s: phy=%d is not supported\n", device_xname(sc->sc_dev), __func__, phy)); return; } url_lock_mii(sc); switch (reg) { case MII_BMCR: /* Control Register */ reg = URL_BMCR; break; case MII_BMSR: /* Status Register */ reg = URL_BMSR; break; case MII_PHYIDR1: case MII_PHYIDR2: goto W_DONE; break; case MII_ANAR: /* Autonegotiation advertisement */ reg = URL_ANAR; break; case MII_ANLPAR: /* Autonegotiation link partner abilities */ reg = URL_ANLP; break; case URLPHY_MSR: /* Media Status Register */ reg = URL_MSR; break; default: printf("%s: %s: bad register %04x\n", device_xname(sc->sc_dev), __func__, reg); goto W_DONE; break; } if (reg == URL_MSR) url_csr_write_1(sc, reg, data); else url_csr_write_2(sc, reg, data); W_DONE: url_unlock_mii(sc); return; }
static void acpicpu_attach(device_t parent, device_t self, void *aux) { struct acpicpu_softc *sc = device_private(self); struct cpu_info *ci; ACPI_HANDLE hdl; cpuid_t id; int rv; ci = acpicpu_md_attach(parent, self, aux); if (ci == NULL) return; sc->sc_ci = ci; sc->sc_dev = self; sc->sc_cold = true; hdl = acpi_match_cpu_info(ci); if (hdl == NULL) { aprint_normal(": failed to match processor\n"); return; } sc->sc_node = acpi_match_node(hdl); if (acpicpu_once_attach() != 0) { aprint_normal(": failed to initialize\n"); return; } KASSERT(acpi_softc != NULL); KASSERT(acpicpu_sc != NULL); KASSERT(sc->sc_node != NULL); id = sc->sc_ci->ci_acpiid; if (acpicpu_sc[id] != NULL) { aprint_normal(": already attached\n"); return; } aprint_naive("\n"); aprint_normal(": ACPI CPU\n"); rv = acpicpu_object(sc->sc_node->ad_handle, &sc->sc_object); if (ACPI_FAILURE(rv)) aprint_verbose_dev(self, "failed to obtain CPU object\n"); acpicpu_count++; acpicpu_sc[id] = sc; sc->sc_cap = acpicpu_cap(sc); sc->sc_ncpus = acpi_md_ncpus(); sc->sc_flags = acpicpu_md_flags(); KASSERT(acpicpu_count <= sc->sc_ncpus); KASSERT(sc->sc_node->ad_device == NULL); sc->sc_node->ad_device = self; mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE); acpicpu_cstate_attach(self); acpicpu_pstate_attach(self); acpicpu_tstate_attach(self); acpicpu_debug_print(self); acpicpu_evcnt_attach(self); (void)config_interrupts(self, acpicpu_start); (void)acpi_register_notify(sc->sc_node, acpicpu_notify); (void)pmf_device_register(self, acpicpu_suspend, acpicpu_resume); }
void tiara_mca_attach(device_t parent, device_t self, void *aux) { struct tiara_softc *isc = device_private(self); struct mb86950_softc *sc = &isc->sc_mb86950; struct mca_attach_args *ma = aux; bus_space_tag_t iot = ma->ma_iot; bus_space_handle_t ioh; u_int8_t myea[ETHER_ADDR_LEN]; int pos2; int iobase = 0, irq = 0; const struct tiara_mca_product *tra_p; pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2); tra_p = tiara_mca_lookup(ma->ma_id); switch (tra_p->tra_prodid) { case MCA_PRODUCT_TIARA: case MCA_PRODUCT_TIARA_TP: /* * POS register 2: (adf pos0) * 7 6 5 4 3 2 1 0 * \_____/ \_/ \ \__ enable: 0=disabled, 1=enabled * \ \ \___ boot rom: 0=disabled, 1=enabled * \ \______ IRQ 00=3 01=4 10=7 11=9 * \_________ Base I/O Port * 0000=0x1200 0001=0x1220 ... 1110=0x13c0 1111=0x13e0 * * POS register 3: (adf pos1) not used * POS register 4: (adf pos2) not used * * POS register 5: (adf pos3) ignored * * 7 6 5 4 3 2 1 0 * 1 1 0 X \____/ * \____EPROM Address */ iobase = 0x1200 + ((pos2 & 0xf0) << 1); irq = tiara_irq[((pos2 & 0x0c) >> 2)]; /* XXX SWAG for number pkts. */ /* My Tiara LANCard has 128K memory ?!? */ sc->txb_num_pkt = 4; sc->rxb_num_pkt = (65535 - 8192 - 4) / 64; /* XXX */ break; case MCA_PRODUCT_SMC3016: /* * POS register 2: (adf pos0) * 7 6 5 4 3 2 1 0 * \_____/ \___/ \__ enable: 0=disabled, 1=enabled * \ \_____ I/O Address (see ioaddr table) * \__________ IRQ (see irq table) * * POS register 3: (adf pos1) ignored * 7 6 5 4 3 2 1 0 * X X X X \____/ * \____EPROM Address (0000 = not used) */ iobase = smc_iobase[((pos2 & 0x0e) >> 1)]; if ((pos2 & 0x80) != 0) irq = smc_irq[((pos2 & 0x70) >> 4)]; else { aprint_error_dev(self, "unsupported irq selected\n"); return; } /* XXX SWAG for number pkts. */ /* The SMC3016 has a 12K rx buffer and a 4k tx buffer */ sc->txb_num_pkt = 2; sc->rxb_num_pkt = (12288 - 4) / 64; /* XXX */ break; }
static void acpicpu_start(device_t self) { struct acpicpu_softc *sc = device_private(self); static uint32_t count = 0; struct cpufreq cf; uint32_t i; /* * Run the state-specific initialization routines. These * must run only once, after interrupts have been enabled, * all CPUs are running, and all ACPI CPUs have attached. */ if (++count != acpicpu_count || acpicpu_count != sc->sc_ncpus) { sc->sc_cold = false; return; } /* * Set the last ACPI CPU as non-cold * only after C-states are enabled. */ if ((sc->sc_flags & ACPICPU_FLAG_C) != 0) acpicpu_cstate_start(self); sc->sc_cold = false; if ((sc->sc_flags & ACPICPU_FLAG_P) != 0) acpicpu_pstate_start(self); if ((sc->sc_flags & ACPICPU_FLAG_T) != 0) acpicpu_tstate_start(self); acpicpu_sysctl(self); aprint_debug_dev(self, "ACPI CPUs started\n"); /* * Register with cpufreq(9). */ if ((sc->sc_flags & ACPICPU_FLAG_P) != 0) { (void)memset(&cf, 0, sizeof(struct cpufreq)); cf.cf_mp = false; cf.cf_cookie = NULL; cf.cf_get_freq = acpicpu_pstate_get; cf.cf_set_freq = acpicpu_pstate_set; cf.cf_state_count = sc->sc_pstate_count; (void)strlcpy(cf.cf_name, "acpicpu", sizeof(cf.cf_name)); for (i = 0; i < sc->sc_pstate_count; i++) { if (sc->sc_pstate[i].ps_freq == 0) continue; cf.cf_state[i].cfs_freq = sc->sc_pstate[i].ps_freq; cf.cf_state[i].cfs_power = sc->sc_pstate[i].ps_power; } if (cpufreq_register(&cf) != 0) aprint_error_dev(self, "failed to register cpufreq\n"); } }
/*static*/ void ndis_attach_pci(device_t parent, device_t self, void *aux) { struct ndis_softc *sc = device_private(self); struct pci_attach_args *pa = aux; #ifdef NDIS_DBG char devinfo[256]; #endif pci_intr_handle_t ih; pcireg_t type; bus_addr_t base; bus_size_t size; int flags; ndis_resource_list *rl = NULL; struct cm_partial_resource_desc *prd = NULL; #ifdef NDIS_DBG struct pci_conf_state conf_state; int revision, i; #endif int bar; size_t rllen; printf("in ndis_attach_pci()\n"); /* initalize the softc */ //sc->ndis_hardware_type = NDIS_PCI; sc->ndis_dev = self; sc->ndis_iftype = PCIBus; sc->ndis_res_pc = pa->pa_pc; sc->ndis_res_pctag = pa->pa_tag; /* TODO: is this correct? All are just pa->pa_dmat? */ sc->ndis_mtag = pa->pa_dmat; sc->ndis_ttag = pa->pa_dmat; sc->ndis_parent_tag = pa->pa_dmat; sc->ndis_res_io = NULL; sc->ndis_res_mem = NULL; sc->ndis_res_altmem = NULL; sc->ndis_block = NULL; sc->ndis_shlist = NULL; ndis_in_isr = FALSE; printf("sc->ndis_mtag = %x\n", (unsigned int)sc->ndis_mtag); rllen = sizeof(ndis_resource_list) + sizeof(cm_partial_resource_desc) * (MAX_RESOURCES - 1); rl = malloc(rllen, M_DEVBUF, M_NOWAIT|M_ZERO); if(rl == NULL) { sc->error = ENOMEM; //printf("error: out of memory\n"); return; } rl->cprl_version = 5; rl->cprl_version = 1; rl->cprl_count = 0; prd = rl->cprl_partial_descs; #ifdef NDIS_DBG pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof devinfo); revision = PCI_REVISION(pa->pa_class); printf(": %s (rev. 0x%02x)\n", devinfo, revision); pci_conf_print(sc->ndis_res_pc, sc->ndis_res_pctag, NULL); pci_conf_capture(sc->ndis_res_pc, sc->ndis_res_pctag, &conf_state); for(i=0; i<16; i++) { printf("conf_state.reg[%d] = %x\n", i, conf_state.reg[i]); } #endif /* just do the conversion work in attach instead of calling ndis_convert_res() */ for(bar = 0x10; bar <= 0x24; bar += 0x04) { type = pci_mapreg_type(sc->ndis_res_pc, sc->ndis_res_pctag, bar); if(pci_mapreg_info(sc->ndis_res_pc, sc->ndis_res_pctag, bar, type, &base, &size, &flags)) { printf("pci_mapreg_info() failed on BAR 0x%x!\n", bar); } else { switch(type) { case PCI_MAPREG_TYPE_IO: prd->cprd_type = CmResourceTypePort; prd->cprd_flags = CM_RESOURCE_PORT_IO; prd->u.cprd_port.cprd_start.np_quad = (uint64_t)base; prd->u.cprd_port.cprd_len = (uint32_t)size; if((sc->ndis_res_io = malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) { //printf("error: out of memory\n"); sc->error = ENOMEM; goto out; } sc->ndis_res_io->res_base = base; sc->ndis_res_io->res_size = size; sc->ndis_res_io->res_tag = x86_bus_space_io; bus_space_map(sc->ndis_res_io->res_tag, sc->ndis_res_io->res_base, sc->ndis_res_io->res_size, flags, &sc->ndis_res_io->res_handle); break; case PCI_MAPREG_TYPE_MEM: prd->cprd_type = CmResourceTypeMemory; prd->cprd_flags = CM_RESOURCE_MEMORY_READ_WRITE; prd->u.cprd_mem.cprd_start.np_quad = (uint64_t)base; prd->u.cprd_mem.cprd_len = (uint32_t)size; if(sc->ndis_res_mem != NULL && sc->ndis_res_altmem != NULL) { printf("too many resources\n"); sc->error = ENXIO; goto out; } if(sc->ndis_res_mem) { if((sc->ndis_res_altmem = malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) { sc->error = ENOMEM; return; } sc->ndis_res_altmem->res_base = base; sc->ndis_res_altmem->res_size = size; sc->ndis_res_altmem->res_tag = x86_bus_space_mem; if(bus_space_map(sc->ndis_res_altmem->res_tag, sc->ndis_res_altmem->res_base, sc->ndis_res_altmem->res_size, flags|BUS_SPACE_MAP_LINEAR, &sc->ndis_res_altmem->res_handle)) { printf("bus_space_map failed\n"); } } else { if((sc->ndis_res_mem = malloc(sizeof(struct ndis_resource), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL) { sc->error = ENOMEM; goto out; } sc->ndis_res_mem->res_base = base; sc->ndis_res_mem->res_size = size; sc->ndis_res_mem->res_tag = x86_bus_space_mem; if(bus_space_map(sc->ndis_res_mem->res_tag, sc->ndis_res_mem->res_base, sc->ndis_res_mem->res_size, flags|BUS_SPACE_MAP_LINEAR, &sc->ndis_res_mem->res_handle)) { printf("bus_space_map failed\n"); } } break; default: printf("unknown type\n"); } prd->cprd_sharedisp = CmResourceShareDeviceExclusive; rl->cprl_count++; prd++; } } /* add the interrupt to the list */ prd->cprd_type = CmResourceTypeInterrupt; prd->cprd_flags = 0; /* TODO: is this all we need to save for the interrupt? */ prd->u.cprd_intr.cprd_level = pa->pa_intrline; prd->u.cprd_intr.cprd_vector = pa->pa_intrline; prd->u.cprd_intr.cprd_affinity = 0; rl->cprl_count++; pci_intr_map(pa, &ih); sc->ndis_intrhand = pci_intr_establish(pa->pa_pc, ih, IPL_NET /*| PCATCH*/, ndis_intr, sc); sc->ndis_irq = (void *)sc->ndis_intrhand; printf("pci interrupt: %s\n", pci_intr_string(pa->pa_pc, ih)); /* save resource list in the softc */ sc->ndis_rl = rl; sc->ndis_rescnt = rl->cprl_count; kthread_create(PRI_NONE, 0, NULL, ndis_attach, (void *)sc, NULL, "ndis_attach"); return; out: free(rl, M_DEVBUF); return; }
static void acpicpu_debug_print(device_t self) { struct acpicpu_softc *sc = device_private(self); struct cpu_info *ci = sc->sc_ci; struct acpicpu_cstate *cs; struct acpicpu_pstate *ps; struct acpicpu_tstate *ts; static bool once = false; struct acpicpu_dep *dep; uint32_t i, method; if (once != true) { for (i = 0; i < __arraycount(sc->sc_cstate); i++) { cs = &sc->sc_cstate[i]; if (cs->cs_method == 0) continue; aprint_verbose_dev(sc->sc_dev, "C%d: %3s, " "lat %3u us, pow %5u mW%s\n", i, acpicpu_debug_print_method_c(cs->cs_method), cs->cs_latency, cs->cs_power, (cs->cs_flags != 0) ? ", bus master check" : ""); } method = sc->sc_pstate_control.reg_spaceid; for (i = 0; i < sc->sc_pstate_count; i++) { ps = &sc->sc_pstate[i]; if (ps->ps_freq == 0) continue; aprint_verbose_dev(sc->sc_dev, "P%d: %3s, " "lat %3u us, pow %5u mW, %4u MHz%s\n", i, acpicpu_debug_print_method_pt(method), ps->ps_latency, ps->ps_power, ps->ps_freq, (ps->ps_flags & ACPICPU_FLAG_P_TURBO) != 0 ? ", turbo boost" : ""); } method = sc->sc_tstate_control.reg_spaceid; for (i = 0; i < sc->sc_tstate_count; i++) { ts = &sc->sc_tstate[i]; if (ts->ts_percent == 0) continue; aprint_verbose_dev(sc->sc_dev, "T%u: %3s, " "lat %3u us, pow %5u mW, %3u %%\n", i, acpicpu_debug_print_method_pt(method), ts->ts_latency, ts->ts_power, ts->ts_percent); } once = true; } aprint_debug_dev(sc->sc_dev, "id %u, lapic id %u, " "cap 0x%04x, flags 0x%08x\n", ci->ci_acpiid, (uint32_t)ci->ci_cpuid, sc->sc_cap, sc->sc_flags); if ((sc->sc_flags & ACPICPU_FLAG_C_DEP) != 0) { dep = &sc->sc_cstate_dep; aprint_debug_dev(sc->sc_dev, "C-state coordination: " "%u CPUs, domain %u, type %s\n", dep->dep_ncpus, dep->dep_domain, acpicpu_debug_print_dep(dep->dep_type)); } if ((sc->sc_flags & ACPICPU_FLAG_P_DEP) != 0) { dep = &sc->sc_pstate_dep; aprint_debug_dev(sc->sc_dev, "P-state coordination: " "%u CPUs, domain %u, type %s\n", dep->dep_ncpus, dep->dep_domain, acpicpu_debug_print_dep(dep->dep_type)); } if ((sc->sc_flags & ACPICPU_FLAG_T_DEP) != 0) { dep = &sc->sc_tstate_dep; aprint_debug_dev(sc->sc_dev, "T-state coordination: " "%u CPUs, domain %u, type %s\n", dep->dep_ncpus, dep->dep_domain, acpicpu_debug_print_dep(dep->dep_type)); } }
void ubsa_attach(device_t parent, device_t self, void *aux) { struct ubsa_softc *sc = device_private(self); struct usb_attach_arg *uaa = aux; usbd_device_handle dev = uaa->device; usb_config_descriptor_t *cdesc; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; char *devinfop; usbd_status err; struct ucom_attach_args uca; int i; sc->sc_dev = self; aprint_naive("\n"); aprint_normal("\n"); devinfop = usbd_devinfo_alloc(dev, 0); aprint_normal_dev(self, "%s\n", devinfop); usbd_devinfo_free(devinfop); sc->sc_udev = dev; sc->sc_config_index = UBSA_DEFAULT_CONFIG_INDEX; sc->sc_numif = 1; /* default device has one interface */ /* * initialize rts, dtr variables to something * different from boolean 0, 1 */ sc->sc_dtr = -1; sc->sc_rts = -1; /* * Quad UMTS cards use different requests to * control com settings and only some. */ sc->sc_quadumts = 0; if (uaa->vendor == USB_VENDOR_OPTIONNV) { switch (uaa->product) { case USB_PRODUCT_OPTIONNV_QUADUMTS: case USB_PRODUCT_OPTIONNV_QUADUMTS2: sc->sc_quadumts = 1; break; } } DPRINTF(("ubsa attach: sc = %p\n", sc)); /* Move the device into the configured state. */ err = usbd_set_config_index(dev, sc->sc_config_index, 1); if (err) { aprint_error_dev(self, "failed to set configuration: %s\n", usbd_errstr(err)); sc->sc_dying = 1; goto error; } /* get the config descriptor */ cdesc = usbd_get_config_descriptor(sc->sc_udev); if (cdesc == NULL) { aprint_error_dev(self, "failed to get configuration descriptor\n"); sc->sc_dying = 1; goto error; } sc->sc_intr_number = -1; sc->sc_intr_pipe = NULL; /* get the interfaces */ err = usbd_device2interface_handle(dev, UBSA_IFACE_INDEX_OFFSET, &sc->sc_iface[0]); if (err) { /* can not get main interface */ sc->sc_dying = 1; goto error; } /* Find the endpoints */ id = usbd_get_interface_descriptor(sc->sc_iface[0]); sc->sc_iface_number[0] = id->bInterfaceNumber; /* initialize endpoints */ uca.bulkin = uca.bulkout = -1; for (i = 0; i < id->bNumEndpoints; i++) { ed = usbd_interface2endpoint_descriptor(sc->sc_iface[0], i); if (ed == NULL) { aprint_error_dev(self, "no endpoint descriptor for %d\n", i); break; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { sc->sc_intr_number = ed->bEndpointAddress; sc->sc_isize = UGETW(ed->wMaxPacketSize); } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { uca.bulkin = ed->bEndpointAddress; uca.ibufsize = UGETW(ed->wMaxPacketSize); } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { uca.bulkout = ed->bEndpointAddress; uca.obufsize = UGETW(ed->wMaxPacketSize); } } /* end of Endpoint loop */ if (sc->sc_intr_number == -1) { aprint_error_dev(self, "Could not find interrupt in\n"); sc->sc_dying = 1; goto error; } if (uca.bulkin == -1) { aprint_error_dev(self, "Could not find data bulk in\n"); sc->sc_dying = 1; goto error; } if (uca.bulkout == -1) { aprint_error_dev(self, "Could not find data bulk out\n"); sc->sc_dying = 1; goto error; } uca.portno = 0; /* bulkin, bulkout set above */ uca.ibufsizepad = uca.ibufsize; uca.opkthdrlen = 0; uca.device = dev; uca.iface = sc->sc_iface[0]; uca.methods = &ubsa_methods; uca.arg = sc; uca.info = NULL; DPRINTF(("ubsa: int#=%d, in = 0x%x, out = 0x%x, intr = 0x%x\n", i, uca.bulkin, uca.bulkout, sc->sc_intr_number)); sc->sc_subdevs[0] = config_found_sm_loc(self, "ucombus", NULL, &uca, ucomprint, ucomsubmatch); usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, sc->sc_dev); return; error: return; }
/* * Initialization of interface; clear recorded pending * operations, and reinitialize UNIBUS usage. */ int ilinit(struct ifnet *ifp) { struct il_softc *sc = ifp->if_softc; int s; if (sc->sc_flags & ILF_RUNNING) return 0; if ((ifp->if_flags & IFF_RUNNING) == 0) { if (if_ubainit(&sc->sc_ifuba, device_private(device_parent(sc->sc_dev)), ETHER_MAX_LEN)) { aprint_error_dev(sc->sc_dev, "can't initialize\n"); sc->sc_if.if_flags &= ~IFF_UP; return 0; } sc->sc_ui.ui_size = sizeof(sc->sc_isu); sc->sc_ui.ui_vaddr = (void *)&sc->sc_isu; uballoc(device_private(device_parent(sc->sc_dev)), &sc->sc_ui, 0); } sc->sc_scaninterval = ILWATCHINTERVAL; ifp->if_timer = sc->sc_scaninterval; /* * Turn off source address insertion (it's faster this way), * and set board online. Former doesn't work if board is * already online (happens on ubareset), so we put it offline * first. */ s = splnet(); IL_WCSR(IL_CSR, ILC_RESET); if (ilwait(sc, "hardware diag")) { sc->sc_if.if_flags &= ~IFF_UP; goto out; } IL_WCSR(IL_CSR, ILC_CISA); while ((IL_RCSR(IL_CSR) & IL_CDONE) == 0) ; /* * If we must reprogram this board's physical ethernet * address (as for secondary XNS interfaces), we do so * before putting it on line, and starting receive requests. * If you try this on an older 1010 board, it will total * wedge the board. */ if (sc->sc_flags & ILF_SETADDR) { memcpy(&sc->sc_isu, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN); IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); IL_WCSR(IL_BCR, ETHER_ADDR_LEN); IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_LDPA); if (ilwait(sc, "setaddr")) goto out; IL_WCSR(IL_BAR, LOWORD(sc->sc_ui.ui_baddr)); IL_WCSR(IL_BCR, sizeof (struct il_stats)); IL_WCSR(IL_CSR, ((sc->sc_ui.ui_baddr >> 2) & IL_EUA)|ILC_STAT); if (ilwait(sc, "verifying setaddr")) goto out; if (memcmp(sc->sc_stats.ils_addr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN) != 0) { aprint_error_dev(sc->sc_dev, "setaddr didn't work\n"); goto out; } }
static void sdhc_attach(device_t parent, device_t self, void *aux) { struct sdhc_axi_softc *sc = device_private(self); struct axi_attach_args *aa = aux; bus_space_tag_t iot = aa->aa_iot; bus_space_handle_t ioh; u_int perclk = 0, v; sc->sc_sdhc.sc_dev = self; sc->sc_sdhc.sc_dmat = aa->aa_dmat; if (bus_space_map(iot, aa->aa_addr, AIPS2_USDHC_SIZE, 0, &ioh)) { aprint_error_dev(self, "can't map\n"); return; } aprint_normal(": Ultra Secured Digial Host Controller\n"); aprint_naive("\n"); sc->sc_sdhc.sc_host = sc->sc_hosts; switch (aa->aa_addr) { case IMX6_AIPS2_BASE + AIPS2_USDHC1_BASE: v = imx6_ccm_read(CCM_CCGR6); imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC1_CLK_ENABLE(3)); perclk = imx6_get_clock(IMX6CLK_USDHC1); imx6_set_gpio(self, "usdhc1-cd-gpio", &sc->sc_gpio_cd, &sc->sc_gpio_cd_active, GPIO_DIR_IN); break; case IMX6_AIPS2_BASE + AIPS2_USDHC2_BASE: v = imx6_ccm_read(CCM_CCGR6); imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC2_CLK_ENABLE(3)); perclk = imx6_get_clock(IMX6CLK_USDHC2); imx6_set_gpio(self, "usdhc2-cd-gpio", &sc->sc_gpio_cd, &sc->sc_gpio_cd_active, GPIO_DIR_IN); break; case IMX6_AIPS2_BASE + AIPS2_USDHC3_BASE: v = imx6_ccm_read(CCM_CCGR6); imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC3_CLK_ENABLE(3)); perclk = imx6_get_clock(IMX6CLK_USDHC3); imx6_set_gpio(self, "usdhc3-cd-gpio", &sc->sc_gpio_cd, &sc->sc_gpio_cd_active, GPIO_DIR_IN); break; case IMX6_AIPS2_BASE + AIPS2_USDHC4_BASE: v = imx6_ccm_read(CCM_CCGR6); imx6_ccm_write(CCM_CCGR6, v | CCM_CCGR6_USDHC4_CLK_ENABLE(3)); perclk = imx6_get_clock(IMX6CLK_USDHC4); imx6_set_gpio(self, "usdhc4-cd-gpio", &sc->sc_gpio_cd, &sc->sc_gpio_cd_active, GPIO_DIR_IN); break; } sc->sc_sdhc.sc_clkbase = perclk / 1000; sc->sc_sdhc.sc_flags |= SDHC_FLAG_USE_DMA | SDHC_FLAG_NO_PWR0 | SDHC_FLAG_HAVE_DVS | SDHC_FLAG_32BIT_ACCESS | SDHC_FLAG_8BIT_MODE | SDHC_FLAG_USE_ADMA2 | SDHC_FLAG_POLL_CARD_DET | SDHC_FLAG_USDHC; sc->sc_ih = intr_establish(aa->aa_irq, IPL_SDMMC, IST_LEVEL, sdhc_intr, &sc->sc_sdhc); if (sc->sc_ih == NULL) { aprint_error_dev(self, "can't establish interrupt\n"); return; } sc->sc_sdhc.sc_vendor_card_detect = imx6_sdhc_card_detect; if (sdhc_host_found(&sc->sc_sdhc, iot, ioh, AIPS2_USDHC_SIZE)) { aprint_error_dev(self, "can't initialize host\n"); return; } if (!pmf_device_register1(self, sdhc_suspend, sdhc_resume, sdhc_shutdown)) { aprint_error_dev(self, "can't establish power hook\n"); } }
static int isicattach(int flags, struct isic_softc *sc) { int ret = 0; const char *drvid; #ifdef __FreeBSD__ struct isic_softc *sc = &l1_sc[dev->id_unit]; #define PARM dev #define PARM2 dev, iobase2 #define FLAGS dev->id_flags #elif defined(__bsdi__) struct isic_softc *sc = device_private(self); #define PARM parent, self, ia #define PARM2 parent, self, ia #define FLAGS sc->sc_flags #else #define PARM sc #define PARM2 sc #define FLAGS flags #endif /* __FreeBSD__ */ static const char *ISACversion[] = { "2085 Version A1/A2 or 2086/2186 Version 1.1", "2085 Version B1", "2085 Version B2", "2085 Version V2.3 (B3)", "Unknown Version" }; static const char *HSCXversion[] = { "82525 Version A1", "Unknown (0x01)", "82525 Version A2", "Unknown (0x03)", "82525 Version A3", "82525 or 21525 Version 2.1", "Unknown Version" }; /* card dependent setup */ switch(FLAGS) { #ifdef ISICISA_DYNALINK #if defined(__bsdi__) || defined(__FreeBSD__) case FLAG_DYNALINK: ret = isic_attach_Dyn(PARM2); break; #endif #endif #ifdef ISICISA_TEL_S0_8 case FLAG_TELES_S0_8: ret = isic_attach_s08(PARM); break; #endif #ifdef ISICISA_TEL_S0_16 case FLAG_TELES_S0_16: ret = isic_attach_s016(PARM); break; #endif #ifdef ISICISA_TEL_S0_16_3 case FLAG_TELES_S0_163: ret = isic_attach_s0163(PARM); break; #endif #ifdef ISICISA_AVM_A1 case FLAG_AVM_A1: ret = isic_attach_avma1(PARM); break; #endif #ifdef ISICISA_USR_STI case FLAG_USR_ISDN_TA_INT: ret = isic_attach_usrtai(PARM); break; #endif #ifdef ISICISA_ITKIX1 case FLAG_ITK_IX1: ret = isic_attach_itkix1(PARM); break; #endif #ifdef ISICISA_ELSA_PCC16 case FLAG_ELSA_PCC16: ret = isic_attach_Eqs1pi(dev, 0); break; #endif #ifdef amiga case FLAG_BLMASTER: ret = 1; /* full detection was done in caller */ break; #endif /* ====================================================================== * Only P&P cards follow below!!! */ #ifdef __FreeBSD__ /* we've already splitted all non-ISA stuff out of this ISA specific part for the other OS */ #ifdef AVM_A1_PCMCIA case FLAG_AVM_A1_PCMCIA: ret = isic_attach_fritzpcmcia(PARM); break; #endif #ifdef TEL_S0_16_3_P case FLAG_TELES_S0_163_PnP: ret = isic_attach_s0163P(PARM2); break; #endif #ifdef CRTX_S0_P case FLAG_CREATIX_S0_PnP: ret = isic_attach_Cs0P(PARM2); break; #endif #ifdef DRN_NGO case FLAG_DRN_NGO: ret = isic_attach_drnngo(PARM2); break; #endif #ifdef SEDLBAUER case FLAG_SWS: ret = isic_attach_sws(PARM); break; #endif #ifdef ELSA_QS1ISA case FLAG_ELSA_QS1P_ISA: ret = isic_attach_Eqs1pi(PARM2); break; #endif #ifdef AVM_PNP case FLAG_AVM_PNP: ret = isic_attach_avm_pnp(PARM2); ret = 0; break; #endif #ifdef SIEMENS_ISURF2 case FLAG_SIEMENS_ISURF2: ret = isic_attach_siemens_isurf(PARM2); break; #endif #ifdef ASUSCOM_IPAC case FLAG_ASUSCOM_IPAC: ret = isic_attach_asi(PARM2); break; #endif #endif /* __FreeBSD__ / P&P specific part */ default: break; } if(ret == 0) return(0); if(sc->sc_ipac) { sc->sc_ipac_version = IPAC_READ(IPAC_ID); switch(sc->sc_ipac_version) { case IPAC_V11: case IPAC_V12: break; default: aprint_error_dev(sc->sc_dev, "Error, IPAC version %d unknown!\n", ret); return(0); break; } } else { sc->sc_isac_version = ((ISAC_READ(I_RBCH)) >> 5) & 0x03; switch(sc->sc_isac_version) { case ISAC_VA: case ISAC_VB1: case ISAC_VB2: case ISAC_VB3: break; default: printf(ISIC_FMT "Error, ISAC version %d unknown!\n", ISIC_PARM, sc->sc_isac_version); return(0); break; } sc->sc_hscx_version = HSCX_READ(0, H_VSTR) & 0xf; switch(sc->sc_hscx_version) { case HSCX_VA1: case HSCX_VA2: case HSCX_VA3: case HSCX_V21: break; default: printf(ISIC_FMT "Error, HSCX version %d unknown!\n", ISIC_PARM, sc->sc_hscx_version); return(0); break; } } sc->sc_intr_valid = ISIC_INTR_DISABLED; /* HSCX setup */ isic_bchannel_setup(sc, HSCX_CH_A, BPROT_NONE, 0); isic_bchannel_setup(sc, HSCX_CH_B, BPROT_NONE, 0); /* setup linktab */ isic_init_linktab(sc); /* set trace level */ sc->sc_trace = TRACE_OFF; sc->sc_state = ISAC_IDLE; sc->sc_ibuf = NULL; sc->sc_ib = NULL; sc->sc_ilen = 0; sc->sc_obuf = NULL; sc->sc_op = NULL; sc->sc_ol = 0; sc->sc_freeflag = 0; sc->sc_obuf2 = NULL; sc->sc_freeflag2 = 0; #if defined(__FreeBSD__) && __FreeBSD__ >=3 callout_handle_init(&sc->sc_T3_callout); callout_handle_init(&sc->sc_T4_callout); #endif #if defined(__NetBSD__) && __NetBSD_Version__ >= 104230000 callout_init(&sc->sc_T3_callout, 0); callout_init(&sc->sc_T4_callout, 0); #endif /* announce manufacturer and card type */ switch(FLAGS) { case FLAG_TELES_S0_8: drvid = "Teles S0/8 or Niccy 1008"; break; case FLAG_TELES_S0_16: drvid = "Teles S0/16, Creatix ISDN S0-16 or Niccy 1016"; break; case FLAG_TELES_S0_163: drvid = "Teles S0/16.3"; break; case FLAG_AVM_A1: drvid = "AVM A1 or AVM Fritz!Card"; break; case FLAG_AVM_A1_PCMCIA: drvid = "AVM PCMCIA Fritz!Card"; break; case FLAG_TELES_S0_163_PnP: drvid = "Teles S0/PnP"; break; case FLAG_CREATIX_S0_PnP: drvid = "Creatix ISDN S0-16 P&P"; break; case FLAG_USR_ISDN_TA_INT: drvid = "USRobotics Sportster ISDN TA intern"; break; case FLAG_DRN_NGO: drvid = "Dr. Neuhaus NICCY Go@"; break; case FLAG_DYNALINK: drvid = "Dynalink IS64PH"; break; case FLAG_SWS: drvid = "Sedlbauer WinSpeed"; break; case FLAG_BLMASTER: /* board announcement was done by caller */ drvid = (char *)0; break; case FLAG_ELSA_QS1P_ISA: drvid = "ELSA QuickStep 1000pro (ISA)"; break; case FLAG_ITK_IX1: drvid = "ITK ix1 micro"; break; case FLAG_ELSA_PCC16: drvid = "ELSA PCC-16"; break; case FLAG_ASUSCOM_IPAC: drvid = "Asuscom ISDNlink 128K PnP"; break; case FLAG_SIEMENS_ISURF2: drvid = "Siemens I-Surf 2.0"; break; default: drvid = "ERROR, unknown flag used"; break; } #ifndef __FreeBSD__ printf("\n"); #endif if (drvid) printf(ISIC_FMT "%s\n", ISIC_PARM, drvid); /* announce chip versions */ if(sc->sc_ipac) { if(sc->sc_ipac_version == IPAC_V11) printf(ISIC_FMT "IPAC PSB2115 Version 1.1\n", ISIC_PARM); else printf(ISIC_FMT "IPAC PSB2115 Version 1.2\n", ISIC_PARM); } else { if(sc->sc_isac_version >= ISAC_UNKN) { printf(ISIC_FMT "ISAC Version UNKNOWN (VN=0x%x)" TERMFMT, ISIC_PARM, sc->sc_isac_version); sc->sc_isac_version = ISAC_UNKN; } else { printf(ISIC_FMT "ISAC %s (IOM-%c)" TERMFMT, ISIC_PARM, ISACversion[sc->sc_isac_version], sc->sc_bustyp == BUS_TYPE_IOM1 ? '1' : '2'); } #ifdef __FreeBSD__ printf("(Addr=0x%lx)\n", (u_long)ISAC_BASE); #endif if(sc->sc_hscx_version >= HSCX_UNKN) { printf(ISIC_FMT "HSCX Version UNKNOWN (VN=0x%x)" TERMFMT, ISIC_PARM, sc->sc_hscx_version); sc->sc_hscx_version = HSCX_UNKN; } else { printf(ISIC_FMT "HSCX %s" TERMFMT, ISIC_PARM, HSCXversion[sc->sc_hscx_version]); } #ifdef __FreeBSD__ printf("(AddrA=0x%lx, AddrB=0x%lx)\n", (u_long)HSCX_A_BASE, (u_long)HSCX_B_BASE); #endif /* __FreeBSD__ */ } #ifdef __FreeBSD__ next_isic_unit++; #if defined(__FreeBSD_version) && __FreeBSD_version >= 300003 /* set the interrupt handler - no need to change isa_device.h */ dev->id_intr = (inthand2_t *)isicintr; #endif #endif /* __FreeBSD__ */ /* init higher protocol layers */ isic_attach_bri(sc, drvid, &isic_std_driver); return(1); #undef PARM #undef FLAGS }
Static void umass_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg) { struct scsipi_adapter *adapt = chan->chan_adapter; struct scsipi_periph *periph; struct scsipi_xfer *xs; struct umass_softc *sc = device_private(adapt->adapt_dev); struct umass_scsipi_softc *scbus = (struct umass_scsipi_softc *)sc->bus; struct scsipi_generic *cmd; int cmdlen; int dir; #ifdef UMASS_DEBUG microtime(&sc->tv); #endif switch(req) { case ADAPTER_REQ_RUN_XFER: xs = arg; periph = xs->xs_periph; DIF(UDMASS_UPPER, periph->periph_dbflags |= SCSIPI_DEBUG_FLAGS); DPRINTF(UDMASS_CMD, ("%s: umass_scsi_cmd: at %"PRIu64".%06"PRIu64": %d:%d " "xs=%p cmd=0x%02x datalen=%d (quirks=0x%x, poll=%d)\n", device_xname(sc->sc_dev), sc->tv.tv_sec, (uint64_t)sc->tv.tv_usec, periph->periph_target, periph->periph_lun, xs, xs->cmd->opcode, xs->datalen, periph->periph_quirks, xs->xs_control & XS_CTL_POLL)); #if defined(UMASS_DEBUG) && defined(SCSIPI_DEBUG) if (umassdebug & UDMASS_SCSI) show_scsipi_xs(xs); else if (umassdebug & ~UDMASS_CMD) show_scsipi_cmd(xs); #endif if (sc->sc_dying) { xs->error = XS_DRIVER_STUFFUP; goto done; } #ifdef UMASS_DEBUG if (SCSIPI_BUSTYPE_TYPE(chan->chan_bustype->bustype_type) == SCSIPI_BUSTYPE_ATAPI ? periph->periph_target != UMASS_ATAPI_DRIVE : periph->periph_target == chan->chan_id) { DPRINTF(UDMASS_SCSI, ("%s: wrong SCSI ID %d\n", device_xname(sc->sc_dev), periph->periph_target)); xs->error = XS_DRIVER_STUFFUP; goto done; } #endif cmd = xs->cmd; cmdlen = xs->cmdlen; dir = DIR_NONE; if (xs->datalen) { switch (xs->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT)) { case XS_CTL_DATA_IN: dir = DIR_IN; break; case XS_CTL_DATA_OUT: dir = DIR_OUT; break; } } if (xs->datalen > UMASS_MAX_TRANSFER_SIZE) { printf("umass_cmd: large datalen, %d\n", xs->datalen); xs->error = XS_DRIVER_STUFFUP; goto done; } if (xs->xs_control & XS_CTL_POLL) { /* Use sync transfer. XXX Broken! */ DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: sync dir=%d\n", dir)); scbus->sc_sync_status = USBD_INVAL; sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, USBD_SYNCHRONOUS, 0, xs); DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: done err=%d\n", scbus->sc_sync_status)); switch (scbus->sc_sync_status) { case USBD_NORMAL_COMPLETION: xs->error = XS_NOERROR; break; case USBD_TIMEOUT: xs->error = XS_TIMEOUT; break; default: xs->error = XS_DRIVER_STUFFUP; break; } goto done; } else { DPRINTF(UDMASS_SCSI, ("umass_scsi_cmd: async dir=%d, cmdlen=%d" " datalen=%d\n", dir, cmdlen, xs->datalen)); sc->sc_methods->wire_xfer(sc, periph->periph_lun, cmd, cmdlen, xs->data, xs->datalen, dir, xs->timeout, 0, umass_scsipi_cb, xs); return; } /* Return if command finishes early. */ done: KERNEL_LOCK(1, curlwp); scsipi_done(xs); KERNEL_UNLOCK_ONE(curlwp); return; default: /* Not supported, nothing to do. */ ; } }
/* * Attach the card */ static void isic_isa_attach(device_t parent, device_t self, void *aux) { struct isic_softc *sc = device_private(self); struct isa_attach_args *ia = aux; int flags = device_cfdata(self)->cf_flags; int ret = 0, iobase, maddr; struct isic_attach_args args; iobase = ia->ia_nio > 0 ? ia->ia_io[0].ir_addr : ISA_UNKNOWN_PORT; maddr = ia->ia_niomem > 0 ? ia->ia_iomem[0].ir_addr : ISA_UNKNOWN_IOMEM; /* Setup parameters */ sc->sc_dev = self; sc->sc_irq = ia->ia_irq[0].ir_irq; sc->sc_maddr = maddr; sc->sc_num_mappings = 0; sc->sc_maps = NULL; switch(flags) { case FLAG_TELES_S0_8: case FLAG_TELES_S0_16: case FLAG_TELES_S0_163: case FLAG_AVM_A1: case FLAG_USR_ISDN_TA_INT: setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &(sc->sc_num_mappings), NULL, NULL, NULL); MALLOC_MAPS(sc); setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &(sc->sc_num_mappings), &(sc->sc_maps[0]), NULL, NULL); break; default: /* No card type given, try to figure ... */ /* setup MI attach args */ memset(&args, 0, sizeof(args)); args.ia_flags = flags; /* Probe cards */ if (iobase == ISA_UNKNOWN_PORT) { ret = 0; #ifdef ISICISA_TEL_S0_8 /* only Teles S0/8 will work without IO */ args.ia_flags = FLAG_TELES_S0_8; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_s08(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_TEL_S0_8 */ } else if (maddr == ISA_UNKNOWN_IOMEM) { /* no shared memory, only a 16.3 based card, AVM A1, the usr sportster or an ITK would work */ ret = 0; #ifdef ISICISA_TEL_S0_16_3 args.ia_flags = FLAG_TELES_S0_163; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_s0163(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_TEL_S0_16_3 */ #ifdef ISICISA_AVM_A1 args.ia_flags = FLAG_AVM_A1; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_avma1(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_AVM_A1 */ #ifdef ISICISA_USR_STI args.ia_flags = FLAG_USR_ISDN_TA_INT; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_usrtai(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_USR_STI */ #ifdef ISICISA_ITKIX1 args.ia_flags = FLAG_ITK_IX1; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_itkix1(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_ITKIX1 */ } else { /* could be anything */ ret = 0; #ifdef ISICISA_TEL_S0_16_3 args.ia_flags = FLAG_TELES_S0_163; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_s0163(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_TEL_S0_16_3 */ #ifdef ISICISA_TEL_S0_16 args.ia_flags = FLAG_TELES_S0_16; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_s016(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_TEL_S0_16 */ #ifdef ISICISA_AVM_A1 args.ia_flags = FLAG_AVM_A1; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_avma1(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_AVM_A1 */ #ifdef ISICISA_TEL_S0_8 args.ia_flags = FLAG_TELES_S0_8; setup_io_map(args.ia_flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &args.ia_num_mappings, &args.ia_maps[0], NULL, NULL); ret = isic_probe_s08(&args); if (ret) goto found; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); #endif /* ISICISA_TEL_S0_8 */ } break; found: flags = args.ia_flags; sc->sc_num_mappings = args.ia_num_mappings; args_unmap(&args.ia_num_mappings, &args.ia_maps[0]); if (ret) { MALLOC_MAPS(sc); setup_io_map(flags, ia->ia_iot, ia->ia_memt, iobase, maddr, &(sc->sc_num_mappings), &(sc->sc_maps[0]), NULL, NULL); } else { aprint_error(": could not determine card type " "- not configured!\n"); return; } break; } /* MI initialization of card */ isicattach(flags, sc); /* * Try to get a level-triggered interrupt first. If that doesn't * work (like on NetBSD/Atari, try to establish an edge triggered * interrupt. */ if (isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_LEVEL, IPL_NET, isicintr, sc) == NULL) { if(isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq, IST_EDGE, IPL_NET, isicintr, sc) == NULL) { args_unmap(&(sc->sc_num_mappings), &(sc->sc_maps[0])); free((sc)->sc_maps, M_DEVBUF); } else { /* * XXX: This is a hack that probably needs to be * solved by setting an interrupt type in the sc * structure. I don't feel familiar enough with the * code to do this currently. Feel free to contact * me about it ([email protected]). */ isicintr(sc); } } }
/* * Attach the interface. Allocate softc structures, do * setup and ethernet/BPF attach. */ void kue_attach(device_t parent, device_t self, void *aux) { struct kue_softc *sc = device_private(self); struct usb_attach_arg *uaa = aux; char *devinfop; int s; struct ifnet *ifp; usbd_device_handle dev = uaa->device; usbd_interface_handle iface; usbd_status err; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; int i; DPRINTFN(5,(" : kue_attach: sc=%p, dev=%p", sc, dev)); sc->kue_dev = self; aprint_naive("\n"); aprint_normal("\n"); devinfop = usbd_devinfo_alloc(dev, 0); aprint_normal_dev(self, "%s\n", devinfop); usbd_devinfo_free(devinfop); err = usbd_set_config_no(dev, KUE_CONFIG_NO, 1); if (err) { aprint_error_dev(self, "failed to set configuration" ", err=%s\n", usbd_errstr(err)); return; } sc->kue_udev = dev; sc->kue_product = uaa->product; sc->kue_vendor = uaa->vendor; /* Load the firmware into the NIC. */ if (kue_load_fw(sc)) { aprint_error_dev(self, "loading firmware failed\n"); return; } err = usbd_device2interface_handle(dev, KUE_IFACE_IDX, &iface); if (err) { aprint_error_dev(self, "getting interface handle failed\n"); return; } sc->kue_iface = iface; id = usbd_get_interface_descriptor(iface); /* Find endpoints. */ for (i = 0; i < id->bNumEndpoints; i++) { ed = usbd_interface2endpoint_descriptor(iface, i); if (ed == NULL) { aprint_error_dev(self, "couldn't get ep %d\n", i); return; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->kue_ed[KUE_ENDPT_RX] = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->kue_ed[KUE_ENDPT_TX] = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) { sc->kue_ed[KUE_ENDPT_INTR] = ed->bEndpointAddress; } } if (sc->kue_ed[KUE_ENDPT_RX] == 0 || sc->kue_ed[KUE_ENDPT_TX] == 0) { aprint_error_dev(self, "missing endpoint\n"); return; } /* Read ethernet descriptor */ err = kue_ctl(sc, KUE_CTL_READ, KUE_CMD_GET_ETHER_DESCRIPTOR, 0, &sc->kue_desc, sizeof(sc->kue_desc)); if (err) { aprint_error_dev(self, "could not read Ethernet descriptor\n"); return; } sc->kue_mcfilters = malloc(KUE_MCFILTCNT(sc) * ETHER_ADDR_LEN, M_USBDEV, M_NOWAIT); if (sc->kue_mcfilters == NULL) { aprint_error_dev(self, "no memory for multicast filter buffer\n"); return; } s = splnet(); /* * A KLSI chip was detected. Inform the world. */ aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(sc->kue_desc.kue_macaddr)); /* Initialize interface info.*/ ifp = GET_IFP(sc); ifp->if_softc = sc; ifp->if_mtu = ETHERMTU; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = kue_ioctl; ifp->if_start = kue_start; ifp->if_watchdog = kue_watchdog; strncpy(ifp->if_xname, device_xname(sc->kue_dev), IFNAMSIZ); IFQ_SET_READY(&ifp->if_snd); /* Attach the interface. */ if_attach(ifp); ether_ifattach(ifp, sc->kue_desc.kue_macaddr); rnd_attach_source(&sc->rnd_source, device_xname(sc->kue_dev), RND_TYPE_NET, RND_FLAG_DEFAULT); sc->kue_attached = true; splx(s); usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->kue_udev, sc->kue_dev); return; }
static void ichsmb_attach(device_t parent, device_t self, void *aux) { struct ichsmb_softc *sc = device_private(self); struct pci_attach_args *pa = aux; struct i2cbus_attach_args iba; pcireg_t conf; bus_size_t iosize; pci_intr_handle_t ih; const char *intrstr = NULL; char intrbuf[PCI_INTRSTR_LEN]; sc->sc_dev = self; pci_aprint_devinfo(pa, NULL); /* Read configuration */ conf = pci_conf_read(pa->pa_pc, pa->pa_tag, LPCIB_SMB_HOSTC); DPRINTF(("%s: conf 0x%08x\n", device_xname(sc->sc_dev), conf)); if ((conf & LPCIB_SMB_HOSTC_HSTEN) == 0) { aprint_error_dev(self, "SMBus disabled\n"); goto out; } /* Map I/O space */ if (pci_mapreg_map(pa, LPCIB_SMB_BASE, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot, &sc->sc_ioh, NULL, &iosize)) { aprint_error_dev(self, "can't map I/O space\n"); goto out; } sc->sc_poll = 1; if (conf & LPCIB_SMB_HOSTC_SMIEN) { /* No PCI IRQ */ aprint_normal_dev(self, "interrupting at SMI\n"); } else { /* Install interrupt handler */ if (pci_intr_map(pa, &ih) == 0) { intrstr = pci_intr_string(pa->pa_pc, ih, intrbuf, sizeof(intrbuf)); sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, ichsmb_intr, sc); if (sc->sc_ih != NULL) { aprint_normal_dev(self, "interrupting at %s\n", intrstr); sc->sc_poll = 0; } } if (sc->sc_poll) aprint_normal_dev(self, "polling\n"); } /* Attach I2C bus */ mutex_init(&sc->sc_i2c_mutex, MUTEX_DEFAULT, IPL_NONE); sc->sc_i2c_tag.ic_cookie = sc; sc->sc_i2c_tag.ic_acquire_bus = ichsmb_i2c_acquire_bus; sc->sc_i2c_tag.ic_release_bus = ichsmb_i2c_release_bus; sc->sc_i2c_tag.ic_exec = ichsmb_i2c_exec; memset(&iba, 0, sizeof(iba)); iba.iba_type = I2C_TYPE_SMBUS; iba.iba_tag = &sc->sc_i2c_tag; config_found(self, &iba, iicbus_print); out: if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); }