void com_mainbus_attach(device_t parent, device_t self, void *aux) { struct com_mainbus_softc *msc = device_private(self); struct com_softc *sc = &msc->sc_com; struct mainbus_attach_args *ma = aux; bus_space_handle_t ioh; sc->sc_dev = self; if (com_is_console(ma->ma_st, ma->ma_addr, &ioh) == 0 && bus_space_map(ma->ma_st, ma->ma_addr, COM_NPORTS, 0, &ioh) != 0) { aprint_error(": can't map i/o space\n"); return; } COM_INIT_REGS(sc->sc_regs, ma->ma_st, ioh, ma->ma_addr); sc->sc_frequency = COM_FREQ; com_attach_subr(sc); msc->sc_ih = (*algor_intr_establish)(ma->ma_irq, comintr, sc); if (msc->sc_ih == NULL) { aprint_error_dev(self, "unable to establish interrupt\n"); return; } if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) { aprint_error_dev(self, "could not establish shutdown hook"); } }
void com_jensenio_attach(device_t parent, device_t self, void *aux) { struct com_jensenio_softc *jsc = device_private(self); struct com_softc *sc = &jsc->sc_com; struct jensenio_attach_args *ja = aux; bus_space_handle_t ioh; sc->sc_dev = self; if (com_is_console(ja->ja_iot, ja->ja_ioaddr, &ioh) == 0 && bus_space_map(ja->ja_iot, ja->ja_ioaddr, COM_NPORTS, 0, &ioh) != 0) { aprint_error(": can't map i/o space\n"); return; } COM_INIT_REGS(sc->sc_regs, ja->ja_iot, ioh, ja->ja_ioaddr); sc->sc_frequency = COM_FREQ; com_attach_subr(sc); scb_set(ja->ja_irq[0], com_jensenio_intr, sc, IPL_VM); aprint_normal_dev(self, "interrupting at vector 0x%x\n", ja->ja_irq[0]); sprintf(jsc->sc_vecstr, "0x%x", ja->ja_irq[0]); evcnt_attach_dynamic(&jsc->sc_ev_intr, EVCNT_TYPE_INTR, NULL, "vector", jsc->sc_vecstr); if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) { aprint_error_dev(self, "could not establish shutdown hook"); } }
static void nouveaufb_attach_task(struct nouveau_task *task) { struct nouveaufb_softc *const sc = container_of(task, struct nouveaufb_softc, sc_attach_task); const struct nouveaufb_attach_args *const nfa = &sc->sc_nfa; const struct drmfb_attach_args da = { .da_dev = sc->sc_dev, .da_fb_helper = nfa->nfa_fb_helper, .da_fb_sizes = &nfa->nfa_fb_sizes, .da_fb_vaddr = __UNVOLATILE(nfa->nfa_fb_ptr), .da_params = &nouveaufb_drmfb_params, }; int error; error = drmfb_attach(&sc->sc_drmfb, &da); if (error) { aprint_error_dev(sc->sc_dev, "failed to attach drmfb: %d\n", error); return; } if (!pmf_device_register1(sc->sc_dev, NULL, NULL, &nouveaufb_shutdown)) aprint_error_dev(sc->sc_dev, "failed to register shutdown handler\n"); sc->sc_attached = true; } static bool nouveaufb_shutdown(device_t self, int flags) { struct nouveaufb_softc *const sc = device_private(self); return drmfb_shutdown(&sc->sc_drmfb, flags); } static paddr_t nouveaufb_drmfb_mmapfb(struct drmfb_softc *drmfb, off_t offset, int prot) { struct nouveaufb_softc *const sc = container_of(drmfb, struct nouveaufb_softc, sc_drmfb); struct drm_fb_helper *const helper = sc->sc_nfa.nfa_fb_helper; struct nouveau_fbdev *const fbdev = container_of(helper, struct nouveau_fbdev, helper); struct nouveau_bo *const nvbo = fbdev->nouveau_fb.nvbo; const unsigned num_pages __diagused = nvbo->bo.num_pages; int flags = 0; KASSERT(0 <= offset); KASSERT(offset < (num_pages << PAGE_SHIFT)); if (ISSET(nvbo->bo.mem.placement, TTM_PL_FLAG_WC)) flags |= BUS_SPACE_MAP_PREFETCHABLE; return bus_space_mmap(nvbo->bo.bdev->memt, nvbo->bo.mem.bus.base, nvbo->bo.mem.bus.offset + offset, prot, flags); }
static void panel_attach(device_t parent, device_t self, void *aux) { struct panel_softc *sc = device_private(self); struct mainbus_attach_args *maa = aux; struct hd44780_io io; static struct lcdkp_xlate keys[] = { { 0xfa, 'h' }, { 0xf6, 'k' }, { 0xde, 'l' }, { 0xee, 'j' }, { 0x7e, 's' }, { 0xbe, 'e' } }; sc->sc_lcd.sc_dev = self; sc->sc_lcd.sc_iot = maa->ma_iot; if (bus_space_map(sc->sc_lcd.sc_iot, maa->ma_addr, PANEL_REGION, 0, &sc->sc_lcd.sc_ioir)) { aprint_error(": unable to map registers\n"); return; } bus_space_subregion(sc->sc_lcd.sc_iot, sc->sc_lcd.sc_ioir, DATA_OFFSET, 1, &sc->sc_lcd.sc_iodr); printf("\n"); sc->sc_lcd.sc_dev_ok = 1; sc->sc_lcd.sc_cols = PANEL_COLS; sc->sc_lcd.sc_vcols = PANEL_VCOLS; sc->sc_lcd.sc_flags = HD_8BIT | HD_MULTILINE | HD_KEYPAD; sc->sc_lcd.sc_writereg = panel_cbt_hdwritereg; sc->sc_lcd.sc_readreg = panel_cbt_hdreadreg; hd44780_attach_subr(&sc->sc_lcd); /* Hello World */ io.dat = 0; io.len = PANEL_VCOLS * PANEL_ROWS; memcpy(io.buf, &startup_message, io.len); hd44780_ddram_io(&sc->sc_lcd, sc->sc_lcd.sc_curchip, &io, HD_DDRAM_WRITE); pmf_device_register1(self, NULL, NULL, panel_shutdown); sc->sc_kp.sc_iot = maa->ma_iot; sc->sc_kp.sc_ioh = MIPS_PHYS_TO_KSEG1(PANEL_BASE); /* XXX */ sc->sc_kp.sc_knum = sizeof(keys) / sizeof(struct lcdkp_xlate); sc->sc_kp.sc_kpad = keys; sc->sc_kp.sc_rread = panel_cbt_kprread; lcdkp_attach_subr(&sc->sc_kp); callout_init(&sc->sc_callout, 0); selinit(&sc->sc_selq); }
static void nor_attach(device_t parent, device_t self, void *aux) { struct nor_softc * const sc = device_private(self); struct nor_attach_args * const naa = aux; struct nor_chip * const chip = &sc->sc_chip; sc->sc_dev = self; sc->sc_controller_dev = parent; sc->sc_nor_if = naa->naa_nor_if; aprint_naive("\n"); aprint_normal("\n"); if (nor_scan_media(self, chip)) return; sc->sc_flash_if = nor_flash_if; sc->sc_flash_if.erasesize = chip->nc_block_size; sc->sc_flash_if.page_size = chip->nc_page_size; sc->sc_flash_if.writesize = chip->nc_page_size; /* allocate cache */ #ifdef NOTYET chip->nc_oob_cache = kmem_alloc(chip->nc_spare_size, KM_SLEEP); #endif chip->nc_page_cache = kmem_alloc(chip->nc_page_size, KM_SLEEP); mutex_init(&sc->sc_device_lock, MUTEX_DEFAULT, IPL_NONE); if (flash_sync_thread_init(&sc->sc_flash_io, self, &sc->sc_flash_if)) { goto error; } if (!pmf_device_register1(sc->sc_dev, NULL, NULL, nor_shutdown)) aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); #ifdef NOR_BBT nor_bbt_init(self); nor_bbt_scan(self); #endif /* * Attach all our devices */ config_search_ia(nor_search, self, NULL, NULL); return; error: #ifdef NOTET kmem_free(chip->nc_oob_cache, chip->nc_spare_size); #endif kmem_free(chip->nc_page_cache, chip->nc_page_size); mutex_destroy(&sc->sc_device_lock); }
void com_isa_attach(device_t parent, device_t self, void *aux) { struct com_isa_softc *isc = device_private(self); struct com_softc *sc = &isc->sc_com; int iobase, irq; bus_space_tag_t iot; bus_space_handle_t ioh; struct isa_attach_args *ia = aux; #ifdef COM_HAYESP int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 }; int *hayespp; #endif /* * We're living on an isa. */ iobase = ia->ia_io[0].ir_addr; iot = ia->ia_iot; if (!com_is_console(iot, iobase, &ioh) && bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { printf(": can't map i/o space\n"); return; } sc->sc_dev = self; COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); sc->sc_frequency = COM_FREQ; irq = ia->ia_irq[0].ir_irq; #ifdef COM_HAYESP for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) { bus_space_handle_t hayespioh; #define HAYESP_NPORTS 8 if (bus_space_map(iot, *hayespp, HAYESP_NPORTS, 0, &hayespioh)) continue; if (com_isa_isHAYESP(hayespioh, sc)) { break; } bus_space_unmap(iot, hayespioh, HAYESP_NPORTS); } #endif com_attach_subr(sc); if (!pmf_device_register1(self, com_isa_suspend, com_isa_resume, com_cleanup)) aprint_error_dev(self, "couldn't establish power handler\n"); isc->sc_ic = ia->ia_ic; isc->sc_irq = irq; isc->sc_ih = isa_intr_establish_xname(ia->ia_ic, irq, IST_EDGE, IPL_SERIAL, comintr, sc, device_xname(sc->sc_dev)); }
static void sec_attach(device_t parent, device_t self, void *aux) { struct podulebus_attach_args *pa = aux; struct sec_softc *sc = device_private(self); int i; sc->sc_sbic.sc_dev = self; /* Set up bus spaces */ sc->sc_pod_t = pa->pa_fast_t; bus_space_map(pa->pa_fast_t, pa->pa_fast_base, 0x1000, 0, &sc->sc_pod_h); sc->sc_mod_t = pa->pa_mod_t; bus_space_map(pa->pa_mod_t, pa->pa_mod_base, 0x1000, 0, &sc->sc_mod_h); sc->sc_sbic.sc_regt = sc->sc_mod_t; bus_space_subregion(sc->sc_mod_t, sc->sc_mod_h, SEC_SBIC + 0, 1, &sc->sc_sbic.sc_asr_regh); bus_space_subregion(sc->sc_mod_t, sc->sc_mod_h, SEC_SBIC + 1, 1, &sc->sc_sbic.sc_data_regh); sc->sc_sbic.sc_id = 7; sc->sc_sbic.sc_clkfreq = SEC_CLKFREQ; sc->sc_sbic.sc_dmamode = SBIC_CTL_BURST_DMA; sc->sc_sbic.sc_adapter.adapt_request = wd33c93_scsi_request; sc->sc_sbic.sc_adapter.adapt_minphys = minphys; sc->sc_sbic.sc_dmasetup = sec_dmasetup; sc->sc_sbic.sc_dmago = sec_dmago; sc->sc_sbic.sc_dmastop = sec_dmastop; sc->sc_sbic.sc_reset = sec_reset; sc->sc_mpr = 0; bus_space_write_1(sc->sc_pod_t, sc->sc_pod_h, SEC_MPR, sc->sc_mpr); for (i = 0; i < SEC_NPAGES; i++) { sec_setpage(sc, i); bus_space_set_region_2(sc->sc_mod_t, sc->sc_mod_h, SEC_SRAM, 0, SEC_PAGESIZE / 2); } wd33c93_attach(&sc->sc_sbic); evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, device_xname(self), "intr"); sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, sec_intr, sc, &sc->sc_intrcnt); sec_cli(sc); sc->sc_mpr |= SEC_MPR_IE; bus_space_write_1(sc->sc_pod_t, sc->sc_pod_h, SEC_MPR, sc->sc_mpr); pmf_device_register1(sc->sc_sbic.sc_dev, NULL, NULL, sec_shutdown); }
static void awin_fb_attach(device_t parent, device_t self, void *aux) { struct awin_fb_softc *sc = device_private(self); struct awinfb_attach_args * const afb = aux; prop_dictionary_t cfg = device_properties(self); struct genfb_ops ops; if (awin_fb_consoledev == NULL) awin_fb_consoledev = self; sc->sc_gen.sc_dev = self; sc->sc_debedev = parent; sc->sc_dmat = afb->afb_dmat; sc->sc_dmasegs = afb->afb_dmasegs; sc->sc_ndmasegs = afb->afb_ndmasegs; sc->sc_mpdev = device_find_by_driver_unit("awinmp", 0); prop_dictionary_set_uint32(cfg, "width", afb->afb_width); prop_dictionary_set_uint32(cfg, "height", afb->afb_height); prop_dictionary_set_uint8(cfg, "depth", 32); prop_dictionary_set_uint16(cfg, "linebytes", afb->afb_width * 4); prop_dictionary_set_uint32(cfg, "address", 0); prop_dictionary_set_uint32(cfg, "virtual_address", (uintptr_t)afb->afb_fb); genfb_init(&sc->sc_gen); if (sc->sc_gen.sc_width == 0 || sc->sc_gen.sc_fbsize == 0) { aprint_normal(": disabled\n"); return; } pmf_device_register1(self, NULL, NULL, awin_fb_shutdown); memset(&ops, 0, sizeof(ops)); ops.genfb_ioctl = awin_fb_ioctl; ops.genfb_mmap = awin_fb_mmap; aprint_naive("\n"); bool is_console = false; prop_dictionary_get_bool(cfg, "is_console", &is_console); if (is_console) aprint_normal(": switching to framebuffer console\n"); else aprint_normal("\n"); genfb_attach(&sc->sc_gen, &ops); }
static void tegra_genfb_attach(device_t parent, device_t self, void *aux) { struct tegra_genfb_softc * const sc = device_private(self); struct tegrafb_attach_args * const tfb = aux; prop_dictionary_t prop = device_properties(self); const bool is_console = tfb->tfb_console; struct genfb_ops ops; sc->sc_gen.sc_dev = self; sc->sc_dmat = tfb->tfb_dmat; sc->sc_dmamap = tfb->tfb_dmamap; prop_dictionary_set_bool(prop, "is_console", is_console); prop_dictionary_set_uint32(prop, "width", tfb->tfb_width); prop_dictionary_set_uint32(prop, "height", tfb->tfb_height); prop_dictionary_set_uint8(prop, "depth", tfb->tfb_depth); prop_dictionary_set_uint32(prop, "linebytes", tfb->tfb_stride); prop_dictionary_set_uint64(prop, "address", 0); prop_dictionary_set_uint64(prop, "virtual_address", (uintptr_t)tfb->tfb_dmap); genfb_init(&sc->sc_gen); if (sc->sc_gen.sc_width == 0 || sc->sc_gen.sc_fbsize == 0) { aprint_error(": disabled\n"); return; } pmf_device_register1(self, NULL, NULL, tegra_genfb_shutdown); aprint_naive("\n"); if (is_console) { aprint_normal(": switching to framebuffer console\n"); } else { aprint_normal("\n"); } memset(&ops, 0, sizeof(ops)); ops.genfb_ioctl = tegra_genfb_ioctl; ops.genfb_mmap = tegra_genfb_mmap; genfb_attach(&sc->sc_gen, &ops); #if defined(DDB) if (is_console) { tegra_genfb_consoledev = self; db_trap_callback = tegra_genfb_ddb_trap_callback; } #endif }
void com_mca_attach(device_t parent, device_t self, void *aux) { struct com_mca_softc *isc = device_private(self); struct com_softc *sc = &isc->sc_com; int iobase, irq; struct mca_attach_args *ma = aux; const struct com_mca_product *cpp; bus_space_handle_t ioh; sc->sc_dev = self; cpp = com_mca_lookup(ma->ma_id); /* get iobase and irq */ if ((*cpp->cp_getcfg)(ma, &iobase, &irq)) return; if (bus_space_map(ma->ma_iot, iobase, COM_NPORTS, 0, &ioh)) { aprint_error(": can't map i/o space\n"); return; } COM_INIT_REGS(sc->sc_regs, ma->ma_iot, ioh, iobase); sc->sc_frequency = COM_FREQ; aprint_normal(" slot %d i/o %#x-%#x irq %d", ma->ma_slot + 1, iobase, iobase + COM_NPORTS - 1, irq); com_attach_subr(sc); aprint_normal_dev(self, "%s\n", cpp->cp_name); isc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_SERIAL, comintr, sc); if (isc->sc_ih == NULL) { aprint_error_dev(self, "couldn't establish interrupt handler\n"); return; } /* * com_cleanup: shutdown hook for buggy BIOSs that don't * recognize the UART without a disabled FIFO. * XXX is this necessary on MCA ? --- jdolecek */ if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) aprint_error_dev(self, "could not establish shutdown hook\n"); }
static void vaudio_attach(device_t parent, device_t self, void *opaque) { struct vaudio_softc *sc = device_private(self); struct thunkbus_attach_args *taa = opaque; int error; aprint_naive("\n"); aprint_normal(": Virtual Audio (device = %s)\n", taa->u.vaudio.device); sc->sc_dev = self; pmf_device_register1(self, NULL, NULL, vaudio_shutdown); sc->sc_audiopath = taa->u.vaudio.device; sc->sc_audiofd = thunk_audio_open(sc->sc_audiopath); if (sc->sc_audiofd == -1) { aprint_error_dev(self, "couldn't open audio device: %d\n", thunk_geterrno()); return; } mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE); mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_AUDIO); error = auconv_create_encodings(vaudio_audio_formats, __arraycount(vaudio_audio_formats), &sc->sc_encodings); if (error) { aprint_error_dev(self, "couldn't create encodings\n"); return; } sc->sc_play.st_softc = sc; sc->sc_play.st_sih = softint_establish(SOFTINT_SERIAL|SOFTINT_MPSAFE, vaudio_softintr_play, &sc->sc_play); callout_init(&sc->sc_play.st_callout, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_play.st_callout, vaudio_intr, &sc->sc_play); sc->sc_record.st_softc = sc; sc->sc_record.st_sih = softint_establish(SOFTINT_SERIAL|SOFTINT_MPSAFE, vaudio_softintr_record, &sc->sc_record); callout_init(&sc->sc_record.st_callout, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_record.st_callout, vaudio_intr, &sc->sc_record); sc->sc_audiodev = audio_attach_mi(&vaudio_hw_if, sc, self); }
void com_sableio_attach(device_t parent, device_t self, void *aux) { struct com_sableio_softc *ssc = device_private(self); struct com_softc *sc = &ssc->sc_com; struct sableio_attach_args *sa = aux; const char *intrstr; bus_space_handle_t ioh; sc->sc_dev = self; if (com_is_console(sa->sa_iot, sa->sa_ioaddr, &ioh) == 0 && bus_space_map(sa->sa_iot, sa->sa_ioaddr, COM_NPORTS, 0, &ioh) != 0) { aprint_error(": can't map i/o space\n"); return; } COM_INIT_REGS(sc->sc_regs, sa->sa_iot, ioh, sa->sa_ioaddr); sc->sc_frequency = COM_FREQ; com_attach_subr(sc); intrstr = pci_intr_string(sa->sa_pc, sa->sa_sableirq[0]); ssc->sc_ih = pci_intr_establish(sa->sa_pc, sa->sa_sableirq[0], IPL_SERIAL, comintr, sc); if (ssc->sc_ih == NULL) { aprint_error_dev(self, "unable to establish interrupt"); if (intrstr != NULL) aprint_normal(" at %s", intrstr); aprint_normal("\n"); return; } aprint_normal_dev(self, "interrupting at %s\n", intrstr); if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) { aprint_error_dev(self, "could not establish shutdown hook"); } }
static int nouveaufb_detach(device_t self, int flags) { struct nouveaufb_softc *const sc = device_private(self); int error; if (sc->sc_scheduled) return EBUSY; if (sc->sc_attached) { pmf_device_deregister(self); error = drmfb_detach(&sc->sc_drmfb, flags); if (error) { /* XXX Ugh. */ (void)pmf_device_register1(self, NULL, NULL, &nouveaufb_shutdown); return error; } sc->sc_attached = false; } return 0; }
static void rtsx_pci_attach(device_t parent, device_t self, void *aux) { struct rtsx_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; pcireg_t reg; char const *intrstr; bus_space_tag_t iot; bus_space_handle_t ioh; bus_size_t size; uint32_t flags; char intrbuf[PCI_INTRSTR_LEN]; sc->sc.sc_dev = self; sc->sc_pc = pc; pci_aprint_devinfo(pa, NULL); if ((pci_conf_read(pc, tag, RTSX_CFG_PCI) & RTSX_CFG_ASIC) != 0) { aprint_error_dev(self, "no asic\n"); return; } if (pci_mapreg_map(pa, RTSX_PCI_BAR, PCI_MAPREG_TYPE_MEM, 0, &iot, &ioh, NULL, &size)) { aprint_error_dev(self, "couldn't map registers\n"); return; } if (pci_intr_alloc(pa, &sc->sc_pihp, NULL, 0)) { aprint_error_dev(self, "couldn't map interrupt\n"); return; } intrstr = pci_intr_string(pc, sc->sc_pihp[0], intrbuf, sizeof(intrbuf)); sc->sc_ih = pci_intr_establish(pc, sc->sc_pihp[0], IPL_SDMMC, rtsx_intr, &sc->sc); if (sc->sc_ih == NULL) { aprint_error_dev(self, "couldn't establish interrupt\n"); return; } aprint_normal_dev(self, "interrupting at %s\n", intrstr); /* Enable the device */ reg = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); reg |= PCI_COMMAND_MASTER_ENABLE; pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, reg); /* Power up the device */ pci_set_powerstate(pc, tag, PCI_PMCSR_STATE_D0); switch (PCI_PRODUCT(pa->pa_id)) { case PCI_PRODUCT_REALTEK_RTS5209: flags = RTSX_F_5209; break; case PCI_PRODUCT_REALTEK_RTS5227: flags = RTSX_F_5227; break; case PCI_PRODUCT_REALTEK_RTS5229: flags = RTSX_F_5229; break; case PCI_PRODUCT_REALTEK_RTL8402: flags = RTSX_F_8402; break; case PCI_PRODUCT_REALTEK_RTL8411: flags = RTSX_F_8411; break; case PCI_PRODUCT_REALTEK_RTL8411B: flags = RTSX_F_8411B; break; default: flags = 0; break; } if (rtsx_attach(&sc->sc, iot, ioh, size, pa->pa_dmat, flags) != 0) { aprint_error_dev(self, "couldn't initialize chip\n"); return; } if (!pmf_device_register1(self, rtsx_suspend, rtsx_resume, rtsx_shutdown)) aprint_error_dev(self, "couldn't establish powerhook\n"); }
/* * ralink_ohci_attach */ static void ralink_ohci_attach(device_t parent, device_t self, void *aux) { struct ralink_ohci_softc * const sc = device_private(self); const struct mainbus_attach_args *ma = aux; usbd_status status; int error; #ifdef RALINK_OHCI_DEBUG const char * const devname = device_xname(self); #endif aprint_naive(": OHCI USB controller\n"); aprint_normal(": OHCI USB controller\n"); sc->sc_ohci.sc_dev = self; sc->sc_ohci.sc_bus.hci_private = sc; sc->sc_ohci.iot = ma->ma_memt; sc->sc_ohci.sc_bus.dmatag = ma->ma_dmat; /* Map I/O registers */ if ((error = bus_space_map(sc->sc_ohci.iot, RT3XXX_OHCI_BASE, RT3XXX_BLOCK_SIZE, 0, &sc->sc_ohci.ioh)) != 0) { aprint_error_dev(self, "can't map OHCI registers, " "error=%d\n", error); return; } sc->sc_ohci.sc_size = RT3XXX_BLOCK_SIZE; #ifdef RALINK_OHCI_DEBUG printf("%s sc: %p ma: %p\n", devname, sc, ma); printf("%s memt: %p dmat: %p\n", devname, ma->ma_memt, ma->ma_dmat); printf("%s: OHCI HcRevision=0x%x\n", devname, OREAD4(&sc->sc_ohci, OHCI_REVISION)); printf("%s: OHCI HcControl=0x%x\n", devname, OREAD4(&sc->sc_ohci, OHCI_CONTROL)); printf("%s: OHCI HcCommandStatus=0x%x\n", devname, OREAD4(&sc->sc_ohci, OHCI_COMMAND_STATUS)); printf("%s: OHCI HcInterruptStatus=0x%x\n", devname, OREAD4(&sc->sc_ohci, OHCI_INTERRUPT_STATUS)); #endif /* Disable OHCI interrupts. */ OWRITE4(&sc->sc_ohci, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS); /* establish the MIPS level interrupt */ sc->sc_ih = ra_intr_establish(RA_IRQ_USB, ohci_intr, sc, 0); if (sc->sc_ih == NULL) { aprint_error_dev(self, "unable to establish irq %d\n", RA_IRQ_USB); goto fail_0; } /* Set vendor for root hub descriptor. */ sc->sc_ohci.sc_id_vendor = 0x1814; strlcpy(sc->sc_ohci.sc_vendor, "Ralink", sizeof(sc->sc_ohci.sc_vendor)); /* Initialize OHCI */ status = ohci_init(&sc->sc_ohci); if (status != USBD_NORMAL_COMPLETION) { aprint_error_dev(self, "init failed, error=%d\n", status); goto fail_0; } #if NEHCI > 0 ralink_usb_hc_add(&sc->sc_hc, 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_ohci.sc_child = config_found(self, &sc->sc_ohci.sc_bus, usbctlprint); return; fail_0: bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh, sc->sc_ohci.sc_size); sc->sc_ohci.sc_size = 0; }
static void xhci_pci_attach(device_t parent, device_t self, void *aux) { struct xhci_pci_softc * const psc = device_private(self); struct xhci_softc * const sc = &psc->sc_xhci; struct pci_attach_args *const pa = (struct pci_attach_args *)aux; const pci_chipset_tag_t pc = pa->pa_pc; const pcitag_t tag = pa->pa_tag; char const *intrstr; pci_intr_handle_t ih; pcireg_t csr, memtype; int err; //const char *vendor; uint32_t hccparams; char intrbuf[PCI_INTRSTR_LEN]; sc->sc_dev = self; sc->sc_bus.hci_private = sc; pci_aprint_devinfo(pa, "USB Controller"); /* Check for quirks */ sc->sc_xhci_quirks = xhci_pci_has_quirk(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)); /* 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 MMIO registers */ memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, PCI_CBMEM); switch (memtype) { case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT: case PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_64BIT: if (pci_mapreg_map(pa, PCI_CBMEM, memtype, 0, &sc->sc_iot, &sc->sc_ioh, NULL, &sc->sc_ios)) { sc->sc_ios = 0; aprint_error_dev(self, "can't map mem space\n"); return; } break; default: aprint_error_dev(self, "BAR not 64 or 32-bit MMIO\n"); return; break; } psc->sc_pc = pc; psc->sc_tag = tag; hccparams = bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0x10); if (pci_dma64_available(pa) && ((hccparams&1)==1)) sc->sc_bus.dmatag = pa->pa_dmat64; else 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_USB, xhci_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); #if 0 /* Figure out vendor for root hub descriptor. */ vendor = pci_findvendor(pa->pa_id); sc->sc_id_vendor = PCI_VENDOR(pa->pa_id); if (vendor) strlcpy(sc->sc_vendor, vendor, sizeof(sc->sc_vendor)); else snprintf(sc->sc_vendor, sizeof(sc->sc_vendor), "vendor 0x%04x", PCI_VENDOR(pa->pa_id)); #endif err = xhci_init(sc); if (err) { aprint_error_dev(self, "init failed, error=%d\n", err); goto fail; } /* Intel chipset requires SuperSpeed enable and USB2 port routing */ switch (PCI_VENDOR(pa->pa_id)) { case PCI_VENDOR_INTEL: xhci_pci_port_route(psc); break; default: break; } if (!pmf_device_register1(self, xhci_suspend, xhci_resume, xhci_shutdown)) aprint_error_dev(self, "couldn't establish power handler\n"); /* Attach usb device. */ sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint); return; fail: if (sc->sc_ih) { pci_intr_disestablish(psc->sc_pc, sc->sc_ih); sc->sc_ih = NULL; } if (sc->sc_ios) { bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_ios); sc->sc_ios = 0; } return; }
static void atw_pci_attach(device_t parent, device_t self, void *aux) { struct atw_pci_softc *psc = device_private(self); struct atw_softc *sc = &psc->psc_atw; struct pci_attach_args *pa = aux; pci_chipset_tag_t pc = pa->pa_pc; const char *intrstr = NULL; bus_space_tag_t iot, memt; bus_space_handle_t ioh, memh; int ioh_valid, memh_valid; const struct atw_pci_product *app; int error; sc->sc_dev = self; psc->psc_pc = pa->pa_pc; psc->psc_pcitag = pa->pa_tag; app = atw_pci_lookup(pa); if (app == NULL) { printf("\n"); panic("atw_pci_attach: impossible"); } /* * Get revision info, and set some chip-specific variables. */ sc->sc_rev = PCI_REVISION(pa->pa_class); printf(": %s, revision %d.%d\n", app->app_product_name, (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf); /* 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. */ ioh_valid = (pci_mapreg_map(pa, ATW_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, NULL, NULL) == 0); memh_valid = (pci_mapreg_map(pa, ATW_PCI_MMBA, PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0, &memt, &memh, NULL, NULL) == 0); if (memh_valid) { sc->sc_st = memt; sc->sc_sh = memh; } else if (ioh_valid) { sc->sc_st = iot; sc->sc_sh = ioh; } else { printf(": unable to map device registers\n"); return; } sc->sc_dmat = pa->pa_dmat; /* * Make sure bus mastering is enabled. */ pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | PCI_COMMAND_MASTER_ENABLE); /* * Get the cacheline size. */ sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag, PCI_BHLC_REG)); /* * Get PCI data moving command info. */ if (pa->pa_flags & PCI_FLAGS_MRL_OKAY) /* read line */ sc->sc_flags |= ATWF_MRL; if (pa->pa_flags & PCI_FLAGS_MRM_OKAY) /* read multiple */ sc->sc_flags |= ATWF_MRM; if (pa->pa_flags & PCI_FLAGS_MWI_OKAY) /* write invalidate */ sc->sc_flags |= ATWF_MWI; /* * Map and establish our interrupt. */ if (pci_intr_map(pa, &psc->psc_ih)) { aprint_error_dev(self, "unable to map interrupt\n"); return; } intrstr = pci_intr_string(pc, psc->psc_ih); psc->psc_intrcookie = pci_intr_establish(pc, psc->psc_ih, IPL_NET, atw_intr, sc); if (psc->psc_intrcookie == 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); /* * Bus-independent attach. */ atw_attach(sc); if (pmf_device_register1(sc->sc_dev, atw_pci_suspend, atw_pci_resume, atw_shutdown)) pmf_class_network_register(sc->sc_dev, &sc->sc_if); else aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); /* * Power down the socket. */ pmf_device_suspend(sc->sc_dev, &sc->sc_qual); }
static void vmt_attach(device_t parent, device_t self, void *aux) { int rv; struct vmt_softc *sc = device_private(self); aprint_naive("\n"); aprint_normal(": %s\n", vmt_type()); sc->sc_dev = self; sc->sc_log = NULL; callout_init(&sc->sc_tick, 0); callout_init(&sc->sc_tclo_tick, 0); callout_init(&sc->sc_clock_sync_tick, 0); sc->sc_clock_sync_period_seconds = VMT_CLOCK_SYNC_PERIOD_SECONDS; rv = vmt_sysctl_setup_root(self); if (rv != 0) { aprint_error_dev(self, "failed to initialize sysctl " "(err %d)\n", rv); goto free; } sc->sc_rpc_buf = kmem_alloc(VMT_RPC_BUFLEN, KM_SLEEP); if (sc->sc_rpc_buf == NULL) { aprint_error_dev(self, "unable to allocate buffer for RPC\n"); goto free; } if (vm_rpc_open(&sc->sc_tclo_rpc, VM_RPC_OPEN_TCLO) != 0) { aprint_error_dev(self, "failed to open backdoor RPC channel (TCLO protocol)\n"); goto free; } sc->sc_tclo_rpc_open = true; /* don't know if this is important at all yet */ if (vm_rpc_send_rpci_tx(sc, "tools.capability.hgfs_server toolbox 1") != 0) { aprint_error_dev(self, "failed to set HGFS server capability\n"); goto free; } pmf_device_register1(self, NULL, NULL, vmt_shutdown); sysmon_task_queue_init(); sc->sc_ev_power.ev_smpsw.smpsw_type = PSWITCH_TYPE_POWER; sc->sc_ev_power.ev_smpsw.smpsw_name = device_xname(self); sc->sc_ev_power.ev_code = PSWITCH_EVENT_PRESSED; sysmon_pswitch_register(&sc->sc_ev_power.ev_smpsw); sc->sc_ev_reset.ev_smpsw.smpsw_type = PSWITCH_TYPE_RESET; sc->sc_ev_reset.ev_smpsw.smpsw_name = device_xname(self); sc->sc_ev_reset.ev_code = PSWITCH_EVENT_PRESSED; sysmon_pswitch_register(&sc->sc_ev_reset.ev_smpsw); sc->sc_ev_sleep.ev_smpsw.smpsw_type = PSWITCH_TYPE_SLEEP; sc->sc_ev_sleep.ev_smpsw.smpsw_name = device_xname(self); sc->sc_ev_sleep.ev_code = PSWITCH_EVENT_RELEASED; sysmon_pswitch_register(&sc->sc_ev_sleep.ev_smpsw); sc->sc_smpsw_valid = true; callout_setfunc(&sc->sc_tick, vmt_tick, sc); callout_schedule(&sc->sc_tick, hz); callout_setfunc(&sc->sc_tclo_tick, vmt_tclo_tick, sc); callout_schedule(&sc->sc_tclo_tick, hz); sc->sc_tclo_ping = 1; callout_setfunc(&sc->sc_clock_sync_tick, vmt_clock_sync_tick, sc); callout_schedule(&sc->sc_clock_sync_tick, mstohz(sc->sc_clock_sync_period_seconds * 1000)); vmt_sync_guest_clock(sc); return; free: if (sc->sc_rpc_buf) kmem_free(sc->sc_rpc_buf, VMT_RPC_BUFLEN); pmf_device_register(self, NULL, NULL); if (sc->sc_log) sysctl_teardown(&sc->sc_log); }
/* 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 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 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; char devinfo[256]; usbd_status r; const char *vendor; const char *devname = device_xname(self); sc->sc.sc_dev = self; sc->sc.sc_bus.hci_private = sc; pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); /* 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)) { printf("%s: can't map mem space\n", devname); 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. */ csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); 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)) { printf("%s: couldn't map interrupt\n", devname); return; } intrstr = pci_intr_string(pc, ih); sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ohci_intr, sc); if (sc->sc_ih == NULL) { printf("%s: couldn't establish interrupt", devname); if (intrstr != NULL) printf(" at %s", intrstr); printf("\n"); return; } printf("%s: interrupting at %s\n", devname, 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) { printf("%s: init failed, error=%d\n", devname, r); return; } #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); }
static void sdhc_pci_attach(device_t parent, device_t self, void *aux) { struct sdhc_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; pci_intr_handle_t ih; pcireg_t csr; pcireg_t slotinfo; char const *intrstr; int nslots; int reg; int cnt; bus_space_tag_t iot; bus_space_handle_t ioh; bus_size_t size; uint32_t flags; char intrbuf[PCI_INTRSTR_LEN]; sc->sc.sc_dev = self; sc->sc.sc_dmat = pa->pa_dmat; sc->sc.sc_host = NULL; sc->sc_pc = pc; pci_aprint_devinfo(pa, NULL); /* Some controllers needs special treatment. */ flags = sdhc_pci_lookup_quirk_flags(pa); if (ISSET(flags, SDHC_PCI_QUIRK_TI_HACK)) sdhc_pci_quirk_ti_hack(pa); if (ISSET(flags, SDHC_PCI_QUIRK_FORCE_DMA)) SET(sc->sc.sc_flags, SDHC_FLAG_FORCE_DMA); if (ISSET(flags, SDHC_PCI_QUIRK_NO_PWR0)) SET(sc->sc.sc_flags, SDHC_FLAG_NO_PWR0); if (ISSET(flags, SDHC_PCI_QUIRK_RICOH_LOWER_FREQ_HACK)) sdhc_pci_quirk_ricoh_lower_freq_hack(pa); /* * Map and attach all hosts supported by the host controller. */ slotinfo = pci_conf_read(pc, tag, SDHC_PCI_CONF_SLOT_INFO); nslots = SDHC_PCI_NUM_SLOTS(slotinfo); /* Allocate an array big enough to hold all the possible hosts */ sc->sc.sc_host = malloc(sizeof(struct sdhc_host *) * nslots, M_DEVBUF, M_NOWAIT | M_ZERO); if (sc->sc.sc_host == NULL) { aprint_error_dev(self, "couldn't alloc memory\n"); goto err; } /* Enable the device. */ csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); 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 err; } intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf)); sc->sc_ih = pci_intr_establish(pc, ih, IPL_SDMMC, sdhc_intr, &sc->sc); if (sc->sc_ih == NULL) { aprint_error_dev(self, "couldn't establish interrupt\n"); goto err; } aprint_normal_dev(self, "interrupting at %s\n", intrstr); /* Enable use of DMA if supported by the interface. */ if ((PCI_INTERFACE(pa->pa_class) == SDHC_PCI_INTERFACE_DMA)) SET(sc->sc.sc_flags, SDHC_FLAG_USE_DMA); /* XXX: handle 64-bit BARs */ cnt = 0; for (reg = SDHC_PCI_BAR_START + SDHC_PCI_FIRST_BAR(slotinfo) * sizeof(uint32_t); reg < SDHC_PCI_BAR_END && nslots > 0; reg += sizeof(uint32_t), nslots--) { if (pci_mapreg_map(pa, reg, PCI_MAPREG_TYPE_MEM, 0, &iot, &ioh, NULL, &size)) { continue; } cnt++; if (sdhc_host_found(&sc->sc, iot, ioh, size) != 0) { /* XXX: sc->sc_host leak */ aprint_error_dev(self, "couldn't initialize host (0x%x)\n", reg); } } if (cnt == 0) { aprint_error_dev(self, "couldn't map register\n"); goto err; } if (!pmf_device_register1(self, sdhc_suspend, sdhc_resume, sdhc_shutdown)) { aprint_error_dev(self, "couldn't establish powerhook\n"); } return; err: if (sc->sc.sc_host != NULL) { free(sc->sc.sc_host, M_DEVBUF); sc->sc.sc_host = NULL; } }
void sabtty_attach(device_t parent, device_t self, void *aux) { struct sabtty_softc *sc = device_private(self); struct sabtty_attach_args *sa = aux; int r; int maj; int is_kgdb = 0; sc->sc_dev = self; #ifdef KGDB is_kgdb = sab_kgdb_check(sc); #endif if (!is_kgdb) { sc->sc_tty = tty_alloc(); if (sc->sc_tty == NULL) { aprint_normal(": failed to allocate tty\n"); return; } tty_attach(sc->sc_tty); sc->sc_tty->t_oproc = sabtty_start; sc->sc_tty->t_param = sabtty_param; } sc->sc_parent = device_private(parent); sc->sc_bt = sc->sc_parent->sc_bt; sc->sc_portno = sa->sbt_portno; sc->sc_rend = sc->sc_rbuf + SABTTY_RBUF_SIZE; switch (sa->sbt_portno) { case 0: /* port A */ sc->sc_pvr_dtr = SAB_PVR_DTR_A; sc->sc_pvr_dsr = SAB_PVR_DSR_A; r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh, SAB_CHAN_A, SAB_CHANLEN, &sc->sc_bh); break; case 1: /* port B */ sc->sc_pvr_dtr = SAB_PVR_DTR_B; sc->sc_pvr_dsr = SAB_PVR_DSR_B; r = bus_space_subregion(sc->sc_bt, sc->sc_parent->sc_bh, SAB_CHAN_B, SAB_CHANLEN, &sc->sc_bh); break; default: aprint_normal(": invalid channel: %u\n", sa->sbt_portno); return; } if (r != 0) { aprint_normal(": failed to allocate register subregion\n"); return; } sabtty_console_flags(sc); if (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) { struct termios t; const char *acc; /* Let residual prom output drain */ DELAY(100000); switch (sc->sc_flags & (SABTTYF_CONS_IN | SABTTYF_CONS_OUT)) { case SABTTYF_CONS_IN: acc = "input"; break; case SABTTYF_CONS_OUT: acc = "output"; break; case SABTTYF_CONS_IN|SABTTYF_CONS_OUT: default: acc = "i/o"; break; } t.c_ispeed= 0; if (sc->sc_flags & SABTTYF_IS_RSC) t.c_ospeed = 115200; else t.c_ospeed = 9600; t.c_cflag = CREAD | CS8 | HUPCL; sc->sc_tty->t_ospeed = 0; sabttyparam(sc, sc->sc_tty, &t); if (sc->sc_flags & SABTTYF_CONS_IN) { sabtty_cons_input = sc; cn_tab->cn_pollc = sab_cnpollc; cn_tab->cn_getc = sab_cngetc; maj = cdevsw_lookup_major(&sabtty_cdevsw); cn_tab->cn_dev = makedev(maj, device_unit(self)); pmf_device_register1(self, NULL, NULL, sabtty_shutdown); cn_init_magic(&sabtty_cnm_state); cn_set_magic("\047\001"); /* default magic is BREAK */ } if (sc->sc_flags & SABTTYF_CONS_OUT) { sabtty_tec_wait(sc); sabtty_cons_output = sc; cn_tab->cn_putc = sab_cnputc; maj = cdevsw_lookup_major(&sabtty_cdevsw); cn_tab->cn_dev = makedev(maj, device_unit(self)); } aprint_normal(": console %s", acc); } else { /* Not a console... */ sabtty_reset(sc); #ifdef KGDB if (is_kgdb) { sab_kgdb_init(sc); aprint_normal(": kgdb"); } #endif } aprint_normal("\n"); aprint_naive(": Serial port\n"); }
static void com_obio_attach(device_t parent, device_t self, void *aux) { struct com_obio_softc *osc = device_private(self); struct com_softc *sc = &osc->osc_com; union obio_attach_args *uoba = aux; struct sbus_attach_args *sa = &uoba->uoba_sbus; bus_space_handle_t ioh; bus_space_tag_t iot; bus_addr_t iobase; sc->sc_dev = self; if (strcmp("modem", sa->sa_name) == 0) { osc->osc_tadpole = 1; } /* * We're living on an obio that looks like an sbus slot. */ iot = sa->sa_bustag; iobase = sa->sa_offset; sc->sc_frequency = COM_FREQ; /* * XXX: It would be nice to be able to split console input and * output to different devices. For now switch to serial * console if PROM stdin is on serial (so that we can use DDB). */ if (prom_instance_to_package(prom_stdin()) == sa->sa_node) comcnattach(iot, iobase, B9600, sc->sc_frequency, COM_TYPE_NORMAL, (CLOCAL | CREAD | CS8)); if (!com_is_console(iot, iobase, &ioh) && sbus_bus_map(iot, sa->sa_slot, iobase, sa->sa_size, BUS_SPACE_MAP_LINEAR, &ioh) != 0) { aprint_error(": can't map registers\n"); return; } COM_INIT_REGS(sc->sc_regs, iot, ioh, iobase); if (osc->osc_tadpole) { *AUXIO4M_REG |= (AUXIO4M_LED|AUXIO4M_LTE); do { DELAY(100); } while (!com_probe_subr(&sc->sc_regs)); #if 0 printf("modem: attach: lcr=0x%02x iir=0x%02x\n", bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 3), bus_space_read_1(sc->sc_regs.iot, sc->sc_regs.ioh, 2)); #endif } com_attach_subr(sc); if (sa->sa_nintr != 0) { (void)bus_intr_establish(sc->sc_regs.cr_iot, sa->sa_pri, IPL_SERIAL, comintr, sc); evcnt_attach_dynamic(&osc->osc_intrcnt, EVCNT_TYPE_INTR, NULL, device_xname(self), "intr"); } if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) { aprint_error_dev(self, "could not establish shutdown hook"); } }
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); sdhc_set_gpio_cd(sc, "usdhc1-cd-gpio"); 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); sdhc_set_gpio_cd(sc, "usdhc2-cd-gpio"); 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); sdhc_set_gpio_cd(sc, "usdhc3-cd-gpio"); 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); sdhc_set_gpio_cd(sc, "usdhc4-cd-gpio"); 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"); } }
void ohci_cardbus_attach(device_t parent, device_t self, void *aux) { struct ohci_cardbus_softc *sc = device_private(self); struct cardbus_attach_args *ca = aux; cardbus_devfunc_t ct = ca->ca_ct; cardbus_chipset_tag_t cc = ct->ct_cc; cardbus_function_tag_t cf = ct->ct_cf; pcireg_t csr; char devinfo[256]; usbd_status r; const char *vendor; const char *devname = device_xname(self); sc->sc.sc_dev = self; sc->sc.sc_bus.hci_private = sc; pci_devinfo(ca->ca_id, ca->ca_class, 0, devinfo, sizeof(devinfo)); printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(ca->ca_class)); /* Map I/O registers */ if (Cardbus_mapreg_map(ct, PCI_CBMEM, PCI_MAPREG_TYPE_MEM, 0, &sc->sc.iot, &sc->sc.ioh, NULL, &sc->sc.sc_size)) { printf("%s: can't map mem space\n", devname); return; } sc->sc_cc = cc; sc->sc_cf = cf; sc->sc_ct = ct; sc->sc.sc_bus.dmatag = ca->ca_dmat; /* Enable the device. */ csr = Cardbus_conf_read(ct, ca->ca_tag, PCI_COMMAND_STATUS_REG); Cardbus_conf_write(ct, ca->ca_tag, PCI_COMMAND_STATUS_REG, csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_MEM_ENABLE); /* Disable interrupts, so we don't can any spurious ones. */ bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE, OHCI_ALL_INTRS); sc->sc_ih = Cardbus_intr_establish(ct, IPL_USB, ohci_intr, sc); if (sc->sc_ih == NULL) { printf("%s: couldn't establish interrupt\n", devname); return; } /* Figure out vendor for root hub descriptor. */ vendor = pci_findvendor(ca->ca_id); sc->sc.sc_id_vendor = PCI_VENDOR(ca->ca_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(ca->ca_id)); r = ohci_init(&sc->sc); if (r != USBD_NORMAL_COMPLETION) { printf("%s: init failed, error=%d\n", devname, r); /* Avoid spurious interrupts. */ Cardbus_intr_disestablish(ct, sc->sc_ih); sc->sc_ih = 0; return; } #if NEHCI_CARDBUS > 0 usb_cardbus_add(&sc->sc_cardbus, ca, 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); }