int vcons_init(struct vcons_data *vd, void *cookie, struct wsscreen_descr *def, struct wsdisplay_accessops *ao) { /* zero out everything so we can rely on untouched fields being 0 */ memset(vd, 0, sizeof(struct vcons_data)); vd->cookie = cookie; vd->init_screen = vcons_dummy_init_screen; vd->show_screen_cb = NULL; /* keep a copy of the accessops that we replace below with our * own wrappers */ vd->ioctl = ao->ioctl; /* configure the accessops */ ao->ioctl = vcons_ioctl; ao->alloc_screen = vcons_alloc_screen; ao->free_screen = vcons_free_screen; ao->show_screen = vcons_show_screen; #ifdef WSDISPLAY_SCROLLSUPPORT ao->scroll = vcons_scroll; #endif LIST_INIT(&vd->screens); vd->active = NULL; vd->wanted = NULL; vd->currenttype = def; callout_init(&vd->switch_callout, 0); callout_setfunc(&vd->switch_callout, vcons_do_switch, vd); #ifdef VCONS_DRAW_INTR vd->cells = 0; vd->attrs = NULL; vd->chars = NULL; vd->cursor_offset = -1; #endif /* * a lock to serialize access to the framebuffer. * when switching screens we need to make sure there's no rasops * operation in progress */ #ifdef DIAGNOSTIC vd->switch_poll_count = 0; #endif #ifdef VCONS_DRAW_INTR vd->intr_softint = softint_establish(SOFTINT_SERIAL, vcons_softintr, vd); callout_init(&vd->intr, 0); callout_setfunc(&vd->intr, vcons_intr, vd); vd->intr_valid = 1; /* XXX assume that the 'dev' arg is never dereferenced */ config_interrupts((device_t)vd, vcons_intr_enable); #endif return 0; }
static void slugled_defer(device_t self) { struct slugled_softc *sc = device_private(self); struct ixp425_softc *ixsc = ixp425_softc; uint32_t reg; int s; s = splhigh(); /* Configure LED GPIO pins as output */ reg = GPIO_CONF_READ_4(ixsc, IXP425_GPIO_GPOER); reg &= ~(LEDBITS_USB0 | LEDBITS_USB1); reg &= ~(LEDBITS_READY | LEDBITS_STATUS); GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPOER, reg); /* All LEDs off */ reg = GPIO_CONF_READ_4(ixsc, IXP425_GPIO_GPOUTR); reg |= LEDBITS_USB0 | LEDBITS_USB1; reg &= ~(LEDBITS_STATUS | LEDBITS_READY); GPIO_CONF_WRITE_4(ixsc, IXP425_GPIO_GPOUTR, reg); splx(s); if (shutdownhook_establish(slugled_shutdown, sc) == NULL) aprint_error_dev(self, "WARNING - Failed to register shutdown hook\n"); callout_init(&sc->sc_usb0, 0); callout_setfunc(&sc->sc_usb0, slugled_callout, (void *)(uintptr_t)LEDBITS_USB0); callout_init(&sc->sc_usb1, 0); callout_setfunc(&sc->sc_usb1, slugled_callout, (void *)(uintptr_t)LEDBITS_USB1); callout_init(&sc->sc_usb2, 0); callout_setfunc(&sc->sc_usb2, slugled_callout, (void *)(uintptr_t)(LEDBITS_USB0 | LEDBITS_USB1)); sc->sc_usb0_ih = ixp425_intr_establish(PCI_INT_A, IPL_USB, slugled_intr0, sc); KDASSERT(sc->sc_usb0_ih != NULL); sc->sc_usb1_ih = ixp425_intr_establish(PCI_INT_B, IPL_USB, slugled_intr1, sc); KDASSERT(sc->sc_usb1_ih != NULL); sc->sc_usb2_ih = ixp425_intr_establish(PCI_INT_C, IPL_USB, slugled_intr2, sc); KDASSERT(sc->sc_usb2_ih != NULL); sc->sc_tmr_ih = ixp425_intr_establish(IXP425_INT_TMR0, IPL_CLOCK, slugled_tmr, NULL); KDASSERT(sc->sc_tmr_ih != NULL); }
static void btkbd_attach(device_t parent, device_t self, void *aux) { struct btkbd_softc *sc = device_private(self); struct bthidev_attach_args *ba = aux; struct wskbddev_attach_args wska; const char *parserr; sc->sc_output = ba->ba_output; ba->ba_input = btkbd_input; parserr = btkbd_parse_desc(sc, ba->ba_id, ba->ba_desc, ba->ba_dlen); if (parserr != NULL) { aprint_error("%s\n", parserr); return; } aprint_normal("\n"); #ifdef WSDISPLAY_COMPAT_RAWKBD #ifdef BTKBD_REPEAT callout_init(&sc->sc_repeat, 0); callout_setfunc(&sc->sc_repeat, btkbd_repeat, sc); #endif #endif wska.console = 0; wska.keymap = &btkbd_keymapdata; wska.accessops = &btkbd_accessops; wska.accesscookie = sc; sc->sc_wskbd = config_found(self, &wska, wskbddevprint); pmf_device_register(self, NULL, NULL); }
static void cpsw_attach(device_t parent, device_t self, void *aux) { struct obio_attach_args * const oa = aux; struct cpsw_softc * const sc = device_private(self); prop_dictionary_t dict = device_properties(self); struct ethercom * const ec = &sc->sc_ec; struct ifnet * const ifp = &ec->ec_if; int error; u_int i; KERNHIST_INIT(cpswhist, 4096); sc->sc_dev = self; aprint_normal(": TI CPSW Ethernet\n"); aprint_naive("\n"); callout_init(&sc->sc_tick_ch, 0); callout_setfunc(&sc->sc_tick_ch, cpsw_tick, sc); prop_data_t eaprop = prop_dictionary_get(dict, "mac-address"); if (eaprop == NULL) { /* grab mac_id0 from AM335x control module */ uint32_t reg_lo, reg_hi; if (sitara_cm_reg_read_4(OMAP2SCM_MAC_ID0_LO, ®_lo) == 0 && sitara_cm_reg_read_4(OMAP2SCM_MAC_ID0_HI, ®_hi) == 0) { sc->sc_enaddr[0] = (reg_hi >> 0) & 0xff; sc->sc_enaddr[1] = (reg_hi >> 8) & 0xff; sc->sc_enaddr[2] = (reg_hi >> 16) & 0xff; sc->sc_enaddr[3] = (reg_hi >> 24) & 0xff; sc->sc_enaddr[4] = (reg_lo >> 0) & 0xff; sc->sc_enaddr[5] = (reg_lo >> 8) & 0xff; } else {
static void tps65217pmic_power_monitor_init(struct tps65217pmic_softc *sc) { uint8_t intr, intrmask, status, ppath; intrmask = TPS65217PMIC_INT_USBM | TPS65217PMIC_INT_ACM | TPS65217PMIC_INT_PBM; status = tps65217pmic_reg_read(sc, TPS65217PMIC_STATUS); ppath = tps65217pmic_reg_read(sc, TPS65217PMIC_PPATH); /* acknowledge and disregard whatever interrupt was generated earlier */ intr = tps65217pmic_reg_read(sc, TPS65217PMIC_INT); sc->sc_usbstatus = status & TPS65217PMIC_STATUS_USBPWR; sc->sc_acstatus = status & TPS65217PMIC_STATUS_ACPWR; sc->sc_usbenabled = ppath & TPS65217PMIC_PPATH_USB_EN; sc->sc_acenabled = ppath & TPS65217PMIC_PPATH_AC_EN; if (intr & intrmask) aprint_normal_dev(sc->sc_dev, "WARNING: hardware interrupt enabled but not supported"); /* set up callout to poll for power source changes */ callout_init(&sc->sc_powerpollco, 0); callout_setfunc(&sc->sc_powerpollco, tps65217pmic_power_monitor, sc); callout_schedule(&sc->sc_powerpollco, hz); }
int testcall(struct lwp *l, void *uap, register_t *retval) { printf("test: initializing\n"); mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE); cv_init(&test_cv, "testcv"); test_sih = softint_establish(SOFTINT_MPSAFE | SOFTINT_SERIAL, test_softint, NULL); callout_init(&test_ch, CALLOUT_MPSAFE); callout_setfunc(&test_ch, test_callout, NULL); printf("test: firing\n"); callout_schedule(&test_ch, hz / 10); printf("test: waiting\n"); mutex_enter(&test_mutex); while (!test_done) { cv_wait(&test_cv, &test_mutex); } mutex_exit(&test_mutex); printf("test: finished\n"); callout_destroy(&test_ch); softint_disestablish(test_sih); mutex_destroy(&test_mutex); cv_destroy(&test_cv); return 0; }
void pcppi_attach(struct pcppi_softc *sc) { struct pcppi_attach_args pa; device_t self = sc->sc_dv; callout_init(&sc->sc_bell_ch, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_bell_ch, pcppi_bell_callout, sc); cv_init(&sc->sc_slp, "bell"); sc->sc_bellactive = sc->sc_bellpitch = 0; #if NPCKBD > 0 /* Provide a beeper for the PC Keyboard, if there isn't one already. */ pckbd_hookup_bell(pcppi_pckbd_bell, sc); #endif #if NATTIMER > 0 config_defer(sc->sc_dv, pcppi_attach_speaker); #endif if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); pa.pa_cookie = sc; config_search_loc(pcppisearch, sc->sc_dv, "pcppi", NULL, &pa); }
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 kprintf_init_callout(void) { KASSERT(!kprintf_inited_callout); callout_init(&kprnd_callout, CALLOUT_MPSAFE); callout_setfunc(&kprnd_callout, kprintf_rnd_callout, NULL); callout_schedule(&kprnd_callout, hz); kprintf_inited_callout = true; }
/* * acpitz_attach: autoconf(9) attach routine */ static void acpitz_attach(device_t parent, device_t self, void *aux) { struct acpitz_softc *sc = device_private(self); struct acpi_attach_args *aa = aux; ACPI_INTEGER val; ACPI_STATUS rv; sc->sc_first = true; sc->sc_have_fan = false; sc->sc_node = aa->aa_node; sc->sc_zone.tzp = ATZ_TZP_RATE; aprint_naive("\n"); acpitz_print_processor_list(self); aprint_normal("\n"); /* * The _TZP (ACPI 4.0, p. 430) defines the recommended * polling interval (in tenths of seconds). A value zero * means that polling "should not be necessary". */ rv = acpi_eval_integer(sc->sc_node->ad_handle, "_TZP", &val); if (ACPI_SUCCESS(rv) && val != 0) sc->sc_zone.tzp = val; aprint_debug_dev(self, "polling interval %d.%d seconds\n", sc->sc_zone.tzp / 10, sc->sc_zone.tzp % 10); sc->sc_zone_expire = ATZ_ZONE_EXPIRE / sc->sc_zone.tzp; /* * XXX: The fan controls seen here are available on * some HP laptops. Arguably these should not * appear in a generic device driver like this. */ if (acpitz_get_fanspeed(self, &sc->sc_zone.fanmin, &sc->sc_zone.fanmax, &sc->sc_zone.fancurrent) == 0) sc->sc_have_fan = true; acpitz_get_zone(self, 1); acpitz_get_status(self); (void)pmf_device_register(self, NULL, NULL); (void)acpi_power_register(sc->sc_node->ad_handle); (void)acpi_register_notify(sc->sc_node, acpitz_notify_handler); callout_init(&sc->sc_callout, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_callout, acpitz_tick, self); acpitz_init_envsys(self); callout_schedule(&sc->sc_callout, sc->sc_zone.tzp * hz / 10); }
/* * Prepare the console tty; called on first open of /dev/console */ static void kd_init(struct kd_softc *kd) { struct tty *tp; tp = tty_alloc(); callout_setfunc(&tp->t_rstrt_ch, kd_later, tp); tp->t_oproc = kdstart; tp->t_param = kdparam; tp->t_dev = makedev(cdevsw_lookup_major(&kd_cdevsw), 0); tty_attach(tp); kd->kd_tty = tp; /* * Get the console struct winsize. */ #if defined(RASTERCONSOLE) && NFB > 0 /* If the raster console driver is attached, copy its size */ kd->rows = fbrcons_rows(); kd->cols = fbrcons_cols(); rcons_ttyinit(tp); #endif /* else, consult the PROM */ switch (prom_version()) { char prop[6+1]; /* Enough for six digits */ struct eeprom *ep; case PROM_OLDMON: if ((ep = (struct eeprom *)eeprom_va) == NULL) break; if (kd->rows == 0) kd->rows = (u_short)ep->eeTtyRows; if (kd->cols == 0) kd->cols = (u_short)ep->eeTtyCols; break; case PROM_OBP_V0: case PROM_OBP_V2: case PROM_OBP_V3: case PROM_OPENFIRM: if (kd->rows == 0 && prom_getoption("screen-#rows", prop, sizeof prop) == 0) kd->rows = strtoul(prop, NULL, 10); if (kd->cols == 0 && prom_getoption("screen-#columns", prop, sizeof prop) == 0) kd->cols = strtoul(prop, NULL, 10); break; } return; }
void gpiopwm_attach(device_t parent, device_t self, void *aux) { struct gpiopwm_softc *sc = device_private(self); struct gpio_attach_args *ga = aux; const struct sysctlnode *node; sc->sc_dev = self; /* Map pin */ sc->sc_gpio = ga->ga_gpio; sc->sc_map.pm_map = sc->_map; if (gpio_pin_map(sc->sc_gpio, ga->ga_offset, ga->ga_mask, &sc->sc_map)) { aprint_error(": can't map pin\n"); return; } aprint_normal(" [%d]", sc->sc_map.pm_map[0]); pmf_device_register(self, NULL, NULL); callout_init(&sc->sc_pulse, CALLOUT_MPSAFE); callout_setfunc(&sc->sc_pulse, gpiopwm_pulse, sc); sysctl_createv(&sc->sc_log, 0, NULL, &node, 0, CTLTYPE_NODE, device_xname(sc->sc_dev), SYSCTL_DESCR("GPIO software PWM"), NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL); if (node == NULL) { printf(": can't create sysctl node\n"); return; } sysctl_createv(&sc->sc_log, 0, &node, NULL, CTLFLAG_READWRITE, CTLTYPE_INT, "on", SYSCTL_DESCR("PWM 'on' period in ticks"), gpiopwm_set_on, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL); sysctl_createv(&sc->sc_log, 0, &node, NULL, CTLFLAG_READWRITE, CTLTYPE_INT, "off", SYSCTL_DESCR("PWM 'off' period in ticks"), gpiopwm_set_off, 0, (void *)sc, 0, CTL_CREATE, CTL_EOL); aprint_normal("\n"); return; }
int vcons_init(struct vcons_data *vd, void *cookie, struct wsscreen_descr *def, struct wsdisplay_accessops *ao) { /* zero out everything so we can rely on untouched fields being 0 */ memset(vd, 0, sizeof(struct vcons_data)); vd->cookie = cookie; vd->init_screen = vcons_dummy_init_screen; vd->show_screen_cb = NULL; /* keep a copy of the accessops that we replace below with our * own wrappers */ vd->ioctl = ao->ioctl; /* configure the accessops */ ao->ioctl = vcons_ioctl; ao->alloc_screen = vcons_alloc_screen; ao->free_screen = vcons_free_screen; ao->show_screen = vcons_show_screen; #ifdef WSDISPLAY_SCROLLSUPPORT ao->scroll = vcons_scroll; #endif LIST_INIT(&vd->screens); vd->active = NULL; vd->wanted = NULL; vd->currenttype = def; callout_init(&vd->switch_callout, 0); callout_setfunc(&vd->switch_callout, vcons_do_switch, vd); /* * a lock to serialize access to the framebuffer. * when switching screens we need to make sure there's no rasops * operation in progress */ #ifdef DIAGNOSTIC vd->switch_poll_count = 0; #endif #ifdef VCONS_SWITCH_ASYNC kthread_create(PRI_NONE, 0, NULL, vcons_kthread, vd, &vd->redraw_thread, "vcons_draw"); #endif return 0; }
void sstouch_attach(device_t parent, device_t self, void *aux) { struct sstouch_softc *sc = device_private(self); struct s3c2xx0_attach_args *sa = aux; struct wsmousedev_attach_args mas; sc->dev = self; sc->iot = sa->sa_iot; if (bus_space_map(sc->iot, S3C2440_ADC_BASE, S3C2440_ADC_SIZE, 0, &sc->ioh)) { aprint_error(": failed to map registers"); return; } sc->next_stylus_intr = STYLUS_DOWN; /* XXX: Is IPL correct? */ s3c24x0_intr_establish(S3C2440_INT_TC, IPL_BIO, IST_EDGE_RISING, sstouch_tc_intr, sc); s3c24x0_intr_establish(S3C2440_INT_ADC, IPL_BIO, IST_EDGE_RISING, sstouch_adc_intr, sc); aprint_normal("\n"); mas.accessops = &sstouch_accessops; mas.accesscookie = sc; sc->wsmousedev = config_found_ia(self, "wsmousedev", &mas, wsmousedevprint); tpcalib_init(&sc->tpcalib); tpcalib_ioctl(&sc->tpcalib, WSMOUSEIO_SCALIBCOORDS, (void*)&default_calib, 0, 0); sc->sample_count = 0; /* Add CALLOUT_MPSAFE to avoid holding the global kernel lock */ callout_init(&sc->callout, 0); callout_setfunc(&sc->callout, sstouch_callout, sc); /* Actual initialization is performed by sstouch_initialize(), which is called by sstouch_enable() */ }
static void btn_obio_attach(device_t parent, device_t self, void *aux) { struct btn_obio_softc *sc; int i; aprint_naive("\n"); aprint_normal(": USL-5P buttons\n"); sc = device_private(self); sc->sc_dev = self; btn_softc = sc; callout_init(&sc->sc_guard_ch, 0); callout_setfunc(&sc->sc_guard_ch, btn_guard_timeout, sc); sc->sc_ih = extintr_establish(LANDISK_INTR_BTN, IPL_TTY, btn_intr, sc); if (sc->sc_ih == NULL) { aprint_error_dev(self, "unable to establish interrupt"); panic("extintr_establish"); } sc->sc_smpsw.smpsw_name = device_xname(self); sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_RESET; if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { aprint_error_dev(self, "unable to register with sysmon\n"); return; } sc->sc_mask |= BTN_RESET_BIT; for (i = 0; i < NBUTTON; i++) { int idx = btnlist[i].idx; sc->sc_bev[idx].bev_name = btnlist[i].name; if (btn_event_register(&sc->sc_bev[idx]) != 0) { aprint_error_dev(self, "unable to register '%s' button\n", btnlist[i].name); } else { sc->sc_mask |= btnlist[i].mask; } } }
static void powsw_attach(device_t parent, device_t self, void *aux) { struct powsw_softc *sc = device_private(self); powsw_desc_t *desc; const char *xname; int unit; int sw; unit = device_unit(self); xname = device_xname(self); desc = &powsw_desc[unit]; memset(sc, 0, sizeof(*sc)); sc->sc_dev = self; sc->sc_mask = desc->mask; sc->sc_prev = -1; powsw_reset_counter(sc); sysmon_task_queue_init(); sc->sc_smpsw.smpsw_name = xname; sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER; if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) panic("can't register with sysmon"); callout_init(&sc->sc_callout, 0); callout_setfunc(&sc->sc_callout, powsw_softintr, sc); if (shutdownhook_establish(powsw_shutdown_check, sc) == NULL) panic("%s: can't establish shutdown hook", xname); if (intio_intr_establish(desc->vector, xname, powsw_intr, sc) < 0) panic("%s: can't establish interrupt", xname); /* Set AER and enable interrupt */ sw = (mfp_get_gpip() & sc->sc_mask); powsw_set_aer(sc, sw ? 0 : 1); mfp_bit_set_ierb(sc->sc_mask); aprint_normal(": %s\n", desc->name); }
void wsmouse_attach(device_t parent, device_t self, void *aux) { struct wsmouse_softc *sc = device_private(self); struct wsmousedev_attach_args *ap = aux; #if NWSMUX > 0 int mux, error; #endif sc->sc_base.me_dv = self; sc->sc_accessops = ap->accessops; sc->sc_accesscookie = ap->accesscookie; /* Initialize button repeating. */ memset(&sc->sc_repeat, 0, sizeof(sc->sc_repeat)); sc->sc_repeat_button = -1; sc->sc_repeat_delay = 0; callout_init(&sc->sc_repeat_callout, 0); callout_setfunc(&sc->sc_repeat_callout, wsmouse_repeat, sc); #if NWSMUX > 0 sc->sc_base.me_ops = &wsmouse_srcops; mux = device_cfdata(self)->wsmousedevcf_mux; if (mux >= 0) { error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); if (error) aprint_error(" attach error=%d", error); else aprint_normal(" mux %d", mux); } #else if (device_cfdata(self)->wsmousedevcf_mux >= 0) aprint_normal(" (mux ignored)"); #endif aprint_naive("\n"); aprint_normal("\n"); if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); }
EXPORT ER tkn_lwp_init(void) { int i; int error; ER ercd; error = mutex_init(&spc_lock, 0, IPL_NONE); if ( error != 0 ) { ercd = ERRNOtoER(error); goto err_ret0; } if (tk_get_cfn("TMaxTskId", &tskid_lwp_table_maxid, 1) < 1) { ercd = E_SYS; goto err_ret1; } tskid_lwp_table = (lwp_t *)malloc(sizeof(lwp_t)*tskid_lwp_table_maxid, M_KMEM, M_NOWAIT | M_ZERO); if (tskid_lwp_table == NULL) { ercd = E_NOMEM; goto err_ret1; } for(i = 0; i < tskid_lwp_table_maxid; i++) { tskid_lwp_table[i].l_proc = &proc; tskid_lwp_table[i].l_mutex = &spc_lock; callout_init(&tskid_lwp_table[i].l_timeout_ch, 0); callout_setfunc(&tskid_lwp_table[i].l_timeout_ch, sleepq_timeout, &tskid_lwp_table[i]); } return E_OK; err_ret1: mutex_destroy(&spc_lock); err_ret0: return ercd; }
void wb_sdmmc_attach(struct wb_softc *wb) { struct sdmmcbus_attach_args saa; callout_init(&wb->wb_sdmmc_callout, 0); callout_setfunc(&wb->wb_sdmmc_callout, wb_sdmmc_discover, wb); wb->wb_sdmmc_width = 1; if (wb_sdmmc_enable(wb) == false) return; memset(&saa, 0, sizeof(saa)); saa.saa_busname = "sdmmc"; saa.saa_sct = &wb_sdmmc_chip_functions; saa.saa_sch = wb; saa.saa_clkmin = 375; saa.saa_clkmax = 24000; saa.saa_caps = SMC_CAPS_4BIT_MODE; wb->wb_sdmmc_dev = config_found(wb->wb_dev, &saa, NULL); }
/* ARGSUSED */ static void btbc_attach(device_t parent, device_t self, void *aux) { struct btbc_softc *sc = device_private(self); struct pcmcia_attach_args *pa = aux; struct pcmcia_config_entry *cfe; int error; sc->sc_dev = self; sc->sc_pf = pa->pf; MBUFQ_INIT(&sc->sc_cmdq); MBUFQ_INIT(&sc->sc_aclq); MBUFQ_INIT(&sc->sc_scoq); if ((error = pcmcia_function_configure(pa->pf, btbc_pcmcia_validate_config)) != 0) { aprint_error_dev(self, "configure failed, error=%d\n", error); return; } cfe = pa->pf->cfe; sc->sc_pcioh = cfe->iospace[0].handle; /* Attach Bluetooth unit */ sc->sc_unit = hci_attach(&btbc_hci, self, 0); if (sc->sc_unit == NULL) aprint_error_dev(self, "HCI attach failed\n"); if (!pmf_device_register(self, btbc_suspend, btbc_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); callout_init(&sc->sc_ledch, 0); callout_setfunc(&sc->sc_ledch, btbc_activity_led_timeout, sc); return; }
static void zkbd_attach(device_t parent, device_t self, void *aux) { struct zkbd_softc *sc = device_private(self); struct wskbddev_attach_args a; int pin, i; sc->sc_dev = self; zkbd_sc = sc; aprint_normal("\n"); aprint_naive("\n"); sc->sc_polling = 0; #ifdef WSDISPLAY_COMPAT_RAWKBD sc->sc_rawkbd = 0; #endif callout_init(&sc->sc_roll_to, 0); callout_setfunc(&sc->sc_roll_to, zkbd_poll, sc); #ifdef WSDISPLAY_COMPAT_RAWKBD callout_init(&sc->sc_rawrepeat_ch, 0); callout_setfunc(&sc->sc_rawrepeat_ch, zkbd_rawrepeat, sc); #endif if (ZAURUS_ISC1000 || ZAURUS_ISC3000) { sc->sc_sense_array = gpio_sense_pins_c3000; sc->sc_strobe_array = gpio_strobe_pins_c3000; sc->sc_nsense = __arraycount(gpio_sense_pins_c3000); sc->sc_nstrobe = __arraycount(gpio_strobe_pins_c3000); sc->sc_stuck_keys = stuck_keys_c3000; sc->sc_nstuck = __arraycount(stuck_keys_c3000); sc->sc_maxkbdcol = 10; sc->sc_onkey_pin = 95; sc->sc_sync_pin = 16; sc->sc_swa_pin = 97; sc->sc_swb_pin = 96; sc->sc_keymapdata = &zkbd_keymapdata; #ifdef WSDISPLAY_COMPAT_RAWKBD sc->sc_xt_keymap = xt_keymap; #endif } else if (ZAURUS_ISC860) { sc->sc_sense_array = gpio_sense_pins_c860; sc->sc_strobe_array = gpio_strobe_pins_c860; sc->sc_nsense = __arraycount(gpio_sense_pins_c860); sc->sc_nstrobe = __arraycount(gpio_strobe_pins_c860); sc->sc_stuck_keys = stuck_keys_c860; sc->sc_nstuck = __arraycount(stuck_keys_c860); sc->sc_maxkbdcol = 0; sc->sc_onkey_pin = -1; sc->sc_sync_pin = -1; sc->sc_swa_pin = -1; sc->sc_swb_pin = -1; sc->sc_keymapdata = &zkbd_keymapdata_c860; #ifdef WSDISPLAY_COMPAT_RAWKBD sc->sc_xt_keymap = xt_keymap_c860; #endif } else { /* XXX */ return; } if (!pmf_device_register(sc->sc_dev, NULL, zkbd_resume)) aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); sc->sc_okeystate = malloc(sc->sc_nsense * sc->sc_nstrobe, M_DEVBUF, M_NOWAIT); memset(sc->sc_okeystate, 0, sc->sc_nsense * sc->sc_nstrobe); sc->sc_keystate = malloc(sc->sc_nsense * sc->sc_nstrobe, M_DEVBUF, M_NOWAIT); memset(sc->sc_keystate, 0, sc->sc_nsense * sc->sc_nstrobe); /* set all the strobe bits */ for (i = 0; i < sc->sc_nstrobe; i++) { pin = sc->sc_strobe_array[i]; if (pin == -1) continue; pxa2x0_gpio_set_function(pin, GPIO_SET|GPIO_OUT); } /* set all the sense bits */ for (i = 0; i < sc->sc_nsense; i++) { pin = sc->sc_sense_array[i]; if (pin == -1) continue; pxa2x0_gpio_set_function(pin, GPIO_IN); if (ZAURUS_ISC1000 || ZAURUS_ISC3000) { pxa2x0_gpio_intr_establish(pin, IST_EDGE_BOTH, IPL_TTY, zkbd_irq_c3000, sc); } else if (ZAURUS_ISC860) { pxa2x0_gpio_intr_establish(pin, IST_EDGE_RISING, IPL_TTY, zkbd_irq_c860, sc); } } if (sc->sc_onkey_pin >= 0) pxa2x0_gpio_intr_establish(sc->sc_onkey_pin, IST_EDGE_BOTH, IPL_TTY, zkbd_on, sc); if (sc->sc_sync_pin >= 0) pxa2x0_gpio_intr_establish(sc->sc_sync_pin, IST_EDGE_RISING, IPL_TTY, zkbd_sync, sc); if (sc->sc_swa_pin >= 0) pxa2x0_gpio_intr_establish(sc->sc_swa_pin, IST_EDGE_BOTH, IPL_TTY, zkbd_hinge, sc); if (sc->sc_swb_pin >= 0) pxa2x0_gpio_intr_establish(sc->sc_swb_pin, IST_EDGE_BOTH, IPL_TTY, zkbd_hinge, sc); if (glass_console) { wskbd_cnattach(&zkbd_consops, sc, sc->sc_keymapdata); a.console = 1; } else { a.console = 0; } a.keymap = sc->sc_keymapdata; a.accessops = &zkbd_accessops; a.accesscookie = sc; zkbd_hinge(sc); /* to initialize sc_hinge */ sc->sc_wskbddev = config_found(self, &a, wskbddevprint); }
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); }
void wskbd_attach(device_t parent, device_t self, void *aux) { struct wskbd_softc *sc = device_private(self); struct wskbddev_attach_args *ap = aux; #if NWSMUX > 0 int mux, error; #endif sc->sc_base.me_dv = self; sc->sc_isconsole = ap->console; sc->sc_hotkey = NULL; sc->sc_hotkeycookie = NULL; sc->sc_evtrans_len = 0; sc->sc_evtrans = NULL; #if NWSMUX > 0 || NWSDISPLAY > 0 sc->sc_base.me_ops = &wskbd_srcops; #endif #if NWSMUX > 0 mux = device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux; if (ap->console) { /* Ignore mux for console; it always goes to the console mux. */ /* printf(" (mux %d ignored for console)", mux); */ mux = -1; } if (mux >= 0) aprint_normal(" mux %d", mux); #else if (device_cfdata(sc->sc_base.me_dv)->wskbddevcf_mux >= 0) aprint_normal(" (mux ignored)"); #endif if (ap->console) { sc->id = &wskbd_console_data; } else { sc->id = malloc(sizeof(struct wskbd_internal), M_DEVBUF, M_WAITOK|M_ZERO); sc->id->t_keymap = ap->keymap; wskbd_update_layout(sc->id, ap->keymap->layout); } callout_init(&sc->sc_repeat_ch, 0); callout_setfunc(&sc->sc_repeat_ch, wskbd_repeat, sc); sc->id->t_sc = sc; sc->sc_accessops = ap->accessops; sc->sc_accesscookie = ap->accesscookie; sc->sc_repeating = 0; sc->sc_translating = 1; sc->sc_ledstate = -1; /* force update */ if (wskbd_load_keymap(sc->id->t_keymap, &sc->sc_map, &sc->sc_maplen) != 0) panic("cannot load keymap"); sc->sc_layout = sc->id->t_keymap->layout; /* set default bell and key repeat data */ sc->sc_bell_data = wskbd_default_bell_data; sc->sc_keyrepeat_data = wskbd_default_keyrepeat_data; #ifdef WSDISPLAY_SCROLLSUPPORT sc->sc_scroll_data = wskbd_default_scroll_data; #endif if (ap->console) { KASSERT(wskbd_console_initted); KASSERT(wskbd_console_device == NULL); wskbd_console_device = sc; aprint_naive(": console keyboard"); aprint_normal(": console keyboard"); #if NWSDISPLAY > 0 wsdisplay_set_console_kbd(&sc->sc_base); /* sets me_dispv */ if (sc->sc_base.me_dispdv != NULL) aprint_normal(", using %s", device_xname(sc->sc_base.me_dispdv)); #endif } aprint_naive("\n"); aprint_normal("\n"); #if NWSMUX > 0 if (mux >= 0) { error = wsmux_attach_sc(wsmux_getmux(mux), &sc->sc_base); if (error) aprint_error_dev(sc->sc_base.me_dv, "attach error=%d\n", error); } #endif if (!pmf_device_register(self, wskbd_suspend, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); else if (!pmf_class_input_register(self)) aprint_error_dev(self, "couldn't register as input device\n"); }
static void bthidev_attach(device_t parent, device_t self, void *aux) { struct bthidev_softc *sc = device_private(self); prop_dictionary_t dict = aux; prop_object_t obj; device_t dev; struct bthidev_attach_args bha; struct bthidev *hidev; struct hid_data *d; struct hid_item h; const void *desc; int locs[BTHIDBUSCF_NLOCS]; int maxid, rep, dlen; /* * Init softc */ sc->sc_dev = self; LIST_INIT(&sc->sc_list); callout_init(&sc->sc_reconnect, 0); callout_setfunc(&sc->sc_reconnect, bthidev_timeout, sc); sc->sc_state = BTHID_CLOSED; sc->sc_flags = BTHID_CONNECTING; sc->sc_ctlpsm = L2CAP_PSM_HID_CNTL; sc->sc_intpsm = L2CAP_PSM_HID_INTR; sockopt_init(&sc->sc_mode, BTPROTO_L2CAP, SO_L2CAP_LM, 0); /* * extract config from proplist */ obj = prop_dictionary_get(dict, BTDEVladdr); bdaddr_copy(&sc->sc_laddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVraddr); bdaddr_copy(&sc->sc_raddr, prop_data_data_nocopy(obj)); obj = prop_dictionary_get(dict, BTDEVmode); if (prop_object_type(obj) == PROP_TYPE_STRING) { if (prop_string_equals_cstring(obj, BTDEVauth)) sockopt_setint(&sc->sc_mode, L2CAP_LM_AUTH); else if (prop_string_equals_cstring(obj, BTDEVencrypt)) sockopt_setint(&sc->sc_mode, L2CAP_LM_ENCRYPT); else if (prop_string_equals_cstring(obj, BTDEVsecure)) sockopt_setint(&sc->sc_mode, L2CAP_LM_SECURE); else { aprint_error(" unknown %s\n", BTDEVmode); return; } aprint_verbose(" %s %s", BTDEVmode, prop_string_cstring_nocopy(obj)); } obj = prop_dictionary_get(dict, BTHIDEVcontrolpsm); if (prop_object_type(obj) == PROP_TYPE_NUMBER) { sc->sc_ctlpsm = prop_number_integer_value(obj); if (L2CAP_PSM_INVALID(sc->sc_ctlpsm)) { aprint_error(" invalid %s\n", BTHIDEVcontrolpsm); return; } } obj = prop_dictionary_get(dict, BTHIDEVinterruptpsm); if (prop_object_type(obj) == PROP_TYPE_NUMBER) { sc->sc_intpsm = prop_number_integer_value(obj); if (L2CAP_PSM_INVALID(sc->sc_intpsm)) { aprint_error(" invalid %s\n", BTHIDEVinterruptpsm); return; } } obj = prop_dictionary_get(dict, BTHIDEVdescriptor); if (prop_object_type(obj) == PROP_TYPE_DATA) { dlen = prop_data_size(obj); desc = prop_data_data_nocopy(obj); } else { aprint_error(" no %s\n", BTHIDEVdescriptor); return; } obj = prop_dictionary_get(dict, BTHIDEVreconnect); if (prop_object_type(obj) == PROP_TYPE_BOOL && !prop_bool_true(obj)) sc->sc_flags |= BTHID_RECONNECT; /* * Parse the descriptor and attach child devices, one per report. */ maxid = -1; h.report_ID = 0; d = hid_start_parse(desc, dlen, hid_none); while (hid_get_item(d, &h)) { if (h.report_ID > maxid) maxid = h.report_ID; } hid_end_parse(d); if (maxid < 0) { aprint_error(" no reports found\n"); return; } aprint_normal("\n"); for (rep = 0 ; rep <= maxid ; rep++) { if (hid_report_size(desc, dlen, hid_feature, rep) == 0 && hid_report_size(desc, dlen, hid_input, rep) == 0 && hid_report_size(desc, dlen, hid_output, rep) == 0) continue; bha.ba_desc = desc; bha.ba_dlen = dlen; bha.ba_input = bthidev_null; bha.ba_feature = bthidev_null; bha.ba_output = bthidev_output; bha.ba_id = rep; locs[BTHIDBUSCF_REPORTID] = rep; dev = config_found_sm_loc(self, "bthidbus", locs, &bha, bthidev_print, config_stdsubmatch); if (dev != NULL) { hidev = device_private(dev); hidev->sc_dev = dev; hidev->sc_parent = self; hidev->sc_id = rep; hidev->sc_input = bha.ba_input; hidev->sc_feature = bha.ba_feature; LIST_INSERT_HEAD(&sc->sc_list, hidev, sc_next); } } /* * start bluetooth connections */ mutex_enter(bt_lock); if ((sc->sc_flags & BTHID_RECONNECT) == 0) bthidev_listen(sc); if (sc->sc_flags & BTHID_CONNECTING) bthidev_connect(sc); mutex_exit(bt_lock); }
void midi_attach(struct midi_softc *sc) { struct midi_info mi; kmutex_t *dummy; static int first = 1; if (first) { mutex_init(&hwif_softc_lock, MUTEX_DEFAULT, IPL_NONE); first = 0; } sc->hw_if->get_locks(sc->hw_hdl, &sc->lock, &dummy); callout_init(&sc->xmt_asense_co, CALLOUT_MPSAFE); callout_init(&sc->rcv_asense_co, CALLOUT_MPSAFE); callout_setfunc(&sc->xmt_asense_co, midi_xmt_asense, sc); callout_setfunc(&sc->rcv_asense_co, midi_rcv_asense, sc); sc->sih = softint_establish(SOFTINT_CLOCK | SOFTINT_MPSAFE, midi_softint, sc); cv_init(&sc->rchan, "midird"); cv_init(&sc->wchan, "midiwr"); sc->dying = 0; sc->isopen = 0; mutex_enter(&hwif_softc_lock); mutex_enter(sc->lock); hwif_softc = sc; sc->hw_if->getinfo(sc->hw_hdl, &mi); hwif_softc = NULL; mutex_exit(sc->lock); mutex_exit(&hwif_softc_lock); sc->props = mi.props; if (!(sc->props & MIDI_PROP_NO_OUTPUT)) { evcnt_attach_dynamic(&sc->xmt.bytesDiscarded, EVCNT_TYPE_MISC, NULL, device_xname(sc->dev), "xmt bytes discarded"); evcnt_attach_dynamic(&sc->xmt.incompleteMessages, EVCNT_TYPE_MISC, NULL, device_xname(sc->dev), "xmt incomplete msgs"); } if (sc->props & MIDI_PROP_CAN_INPUT) { evcnt_attach_dynamic(&sc->rcv.bytesDiscarded, EVCNT_TYPE_MISC, NULL, device_xname(sc->dev), "rcv bytes discarded"); evcnt_attach_dynamic(&sc->rcv.incompleteMessages, EVCNT_TYPE_MISC, NULL, device_xname(sc->dev), "rcv incomplete msgs"); } aprint_naive("\n"); aprint_normal(": %s\n", mi.name); if (!pmf_device_register(sc->dev, NULL, NULL)) aprint_error_dev(sc->dev, "couldn't establish power handler\n"); }
static void zapm_attach(device_t parent, device_t self, void *aux) { struct zapm_softc *sc = device_private(self); struct apmdev_attach_args aaa; sc->sc_dev = self; aprint_normal(": pseudo power management module\n"); aprint_naive("\n"); /* machine-depent part */ callout_init(&sc->sc_cyclic_poll, 0); callout_setfunc(&sc->sc_cyclic_poll, zapm_cyclic, sc); callout_init(&sc->sc_discharge_poll, 0); callout_setfunc(&sc->sc_discharge_poll, zapm_poll, sc); mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE); if (ZAURUS_ISC1000 || ZAURUS_ISC3000) { sc->sc_ac_detect_pin = GPIO_AC_IN_C3000; sc->sc_batt_cover_pin = GPIO_BATT_COVER_C3000; sc->sc_charge_comp_pin = GPIO_CHRG_CO_C3000; } else { /* XXX */ return; } pxa2x0_gpio_set_function(sc->sc_ac_detect_pin, GPIO_IN); pxa2x0_gpio_set_function(sc->sc_charge_comp_pin, GPIO_IN); pxa2x0_gpio_set_function(sc->sc_batt_cover_pin, GPIO_IN); (void)pxa2x0_gpio_intr_establish(sc->sc_ac_detect_pin, IST_EDGE_BOTH, IPL_BIO, zapm_acintr, sc); (void)pxa2x0_gpio_intr_establish(sc->sc_charge_comp_pin, IST_EDGE_BOTH, IPL_BIO, zapm_bcintr, sc); /* machine-independent part */ sc->events = 0; sc->power_state = APM_SYS_READY; sc->battery_state = APM_BATT_FLAG_UNKNOWN; sc->ac_state = APM_AC_UNKNOWN; sc->battery_life = APM_BATT_LIFE_UNKNOWN; sc->minutes_left = 0; sc->sc_standby_hook = config_hook(CONFIG_HOOK_PMEVENT, CONFIG_HOOK_PMEVENT_STANDBYREQ, CONFIG_HOOK_EXCLUSIVE, zapm_hook, sc); sc->sc_suspend_hook = config_hook(CONFIG_HOOK_PMEVENT, CONFIG_HOOK_PMEVENT_SUSPENDREQ, CONFIG_HOOK_EXCLUSIVE, zapm_hook, sc); sc->sc_battery_hook = config_hook(CONFIG_HOOK_PMEVENT, CONFIG_HOOK_PMEVENT_BATTERY, CONFIG_HOOK_SHARE, zapm_hook, sc); sc->sc_ac_hook = config_hook(CONFIG_HOOK_PMEVENT, CONFIG_HOOK_PMEVENT_AC, CONFIG_HOOK_SHARE, zapm_hook, sc); aaa.accessops = &zapm_accessops; aaa.accesscookie = sc; aaa.apm_detail = 0x0102; sc->sc_apmdev = config_found_ia(self, "apmdevif", &aaa, apmprint); if (sc->sc_apmdev != NULL) { zapm_poll1(sc, 0); callout_schedule(&sc->sc_cyclic_poll, CYCLIC_TIME); } }
static gfarm_error_t gfm_server_switch_back_channel_common( struct peer *peer, gfp_xdr_xid_t xid, size_t *sizep, int from_client, int version, const char *diag, struct relayed_request *relay) { gfarm_error_t e = GFARM_ERR_NO_ERROR, e2; struct host *host; gfp_xdr_async_peer_t async = NULL; struct local_peer *local_peer = NULL; int is_direct_connection; int i = 0; #ifdef __GNUC__ /* workaround gcc warning: might be used uninitialized */ host = NULL; #endif is_direct_connection = (peer_get_parent(peer) == NULL); giant_lock(); if (from_client) { gflog_debug(GFARM_MSG_1001995, "Operation not permitted: from_client"); e = GFARM_ERR_OPERATION_NOT_PERMITTED; } else if ((host = peer_get_host(peer)) == NULL) { gflog_debug(GFARM_MSG_1001996, "Operation not permitted: peer_get_host() failed"); e = GFARM_ERR_OPERATION_NOT_PERMITTED; } else if (is_direct_connection && (e = gfp_xdr_async_peer_new(&async)) != GFARM_ERR_NO_ERROR) { gflog_error(GFARM_MSG_1002288, "%s: gfp_xdr_async_peer_new(): %s", diag, gfarm_error_string(e)); } giant_unlock(); e2 = gfm_server_relay_put_reply(peer, xid, sizep, relay, diag, &e, "i", &i/*XXX FIXME*/); if (e2 != GFARM_ERR_NO_ERROR) return (e2); if (debug_mode) gflog_debug(GFARM_MSG_1000404, "gfp_xdr_flush"); e2 = gfp_xdr_flush(peer_get_conn(peer)); if (e2 != GFARM_ERR_NO_ERROR) { gflog_warning(GFARM_MSG_1000405, "%s: protocol flush: %s", diag, gfarm_error_string(e2)); return (e2); } else if (e != GFARM_ERR_NO_ERROR) return (e2); if (is_direct_connection) { local_peer = peer_to_local_peer(peer); local_peer_set_async(local_peer, async); /* XXXRELAY */ local_peer_set_readable_watcher(local_peer, back_channel_recv_watcher); } if (host_is_up(host)) /* throw away old connetion */ { gflog_warning(GFARM_MSG_1002440, "back_channel(%s): switching to new connection", host_name(host)); host_disconnect_request(host, NULL); } giant_lock(); peer_set_peer_type(peer, peer_type_back_channel); abstract_host_set_peer(host_to_abstract_host(host), peer, version); giant_unlock(); if (is_direct_connection) { local_peer_watch_readable(local_peer); gfarm_thr_statewait_signal( local_peer_get_statewait(local_peer), e2, diag); } callout_setfunc(host_status_callout(host), NULL /* or, use back_channel_send_manager thread pool? */, gfs_client_status_callout, host); gfs_client_status_schedule(host, 1); gflog_info(GFARM_MSG_1004035, "back_channel(%s): started", host_name(host)); return (e2); }
int dme_attach(struct dme_softc *sc, const uint8_t *enaddr) { struct ifnet *ifp = &sc->sc_ethercom.ec_if; uint8_t b[2]; uint16_t io_mode; dme_read_c(sc, DM9000_VID0, b, 2); #if BYTE_ORDER == BIG_ENDIAN sc->sc_vendor_id = (b[0] << 8) | b[1]; #else sc->sc_vendor_id = b[0] | (b[1] << 8); #endif dme_read_c(sc, DM9000_PID0, b, 2); #if BYTE_ORDER == BIG_ENDIAN sc->sc_product_id = (b[0] << 8) | b[1]; #else sc->sc_product_id = b[0] | (b[1] << 8); #endif /* TODO: Check the vendor ID as well */ if (sc->sc_product_id != 0x9000) { panic("dme_attach: product id mismatch (0x%hx != 0x9000)", sc->sc_product_id); } /* Initialize ifnet structure. */ strlcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); ifp->if_softc = sc; ifp->if_start = dme_start_output; ifp->if_init = dme_init; ifp->if_ioctl = dme_ioctl; ifp->if_stop = dme_stop; ifp->if_watchdog = NULL; /* no watchdog at this stage */ ifp->if_flags = IFF_SIMPLEX | IFF_NOTRAILERS | IFF_BROADCAST | IFF_MULTICAST; IFQ_SET_READY(&ifp->if_snd); /* Initialize ifmedia structures. */ ifmedia_init(&sc->sc_media, 0, dme_mediachange, dme_mediastatus); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_AUTO, 0, NULL); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_10_T, 0, NULL); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_100_TX, 0, NULL); ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_AUTO); if (enaddr != NULL) memcpy(sc->sc_enaddr, enaddr, sizeof(sc->sc_enaddr)); /* TODO: Support an EEPROM attached to the DM9000 chip */ callout_init(&sc->sc_link_callout, 0); callout_setfunc(&sc->sc_link_callout, dme_phy_check_link, sc); sc->sc_media_status = 0; /* Configure DM9000 with the MAC address */ dme_write_c(sc, DM9000_PAB0, sc->sc_enaddr, 6); #ifdef DM9000_DEBUG { uint8_t macAddr[6]; dme_read_c(sc, DM9000_PAB0, macAddr, 6); printf("DM9000 configured with MAC address: "); for (int i = 0; i < 6; i++) { printf("%02X:", macAddr[i]); } printf("\n"); } #endif if_attach(ifp); ether_ifattach(ifp, sc->sc_enaddr); #ifdef DM9000_DEBUG { uint8_t network_state; network_state = dme_read(sc, DM9000_NSR); printf("DM9000 Link status: "); if (network_state & DM9000_NSR_LINKST) { if (network_state & DM9000_NSR_SPEED) printf("10Mbps"); else printf("100Mbps"); } else { printf("Down"); } printf("\n"); } #endif io_mode = (dme_read(sc, DM9000_ISR) & DM9000_IOMODE_MASK) >> DM9000_IOMODE_SHIFT; if (io_mode != DM9000_MODE_16BIT ) panic("DM9000: Only 16-bit mode is supported!\n"); DPRINTF(("DM9000 Operation Mode: ")); switch( io_mode) { case DM9000_MODE_16BIT: DPRINTF(("16-bit mode")); sc->sc_data_width = 2; sc->sc_pkt_write = dme_pkt_write_2; sc->sc_pkt_read = dme_pkt_read_2; break; case DM9000_MODE_32BIT: DPRINTF(("32-bit mode")); sc->sc_data_width = 4; break; case DM9000_MODE_8BIT: DPRINTF(("8-bit mode")); sc->sc_data_width = 1; break; default: DPRINTF(("Invalid mode")); break; } DPRINTF(("\n")); callout_schedule(&sc->sc_link_callout, mstohz(2000)); return 0; }
static void aps_attach(device_t parent, device_t self, void *aux) { struct aps_softc *sc = device_private(self); struct isa_attach_args *ia = aux; int iobase, i; sc->sc_iot = ia->ia_iot; iobase = ia->ia_io[0].ir_addr; if (bus_space_map(sc->sc_iot, iobase, APS_ADDR_SIZE, 0, &sc->sc_ioh)) { aprint_error(": can't map i/o space\n"); return; } aprint_naive("\n"); aprint_normal("\n"); if (!aps_init(sc)) { aprint_error_dev(self, "failed to initialise\n"); goto out; } /* Initialize sensors */ #define INITDATA(idx, unit, string) \ sc->sc_sensor[idx].units = unit; \ strlcpy(sc->sc_sensor[idx].desc, string, \ sizeof(sc->sc_sensor[idx].desc)); INITDATA(APS_SENSOR_XACCEL, ENVSYS_INTEGER, "X_ACCEL"); INITDATA(APS_SENSOR_YACCEL, ENVSYS_INTEGER, "Y_ACCEL"); INITDATA(APS_SENSOR_TEMP1, ENVSYS_STEMP, "TEMP_1"); INITDATA(APS_SENSOR_TEMP2, ENVSYS_STEMP, "TEMP_2"); INITDATA(APS_SENSOR_XVAR, ENVSYS_INTEGER, "X_VAR"); INITDATA(APS_SENSOR_YVAR, ENVSYS_INTEGER, "Y_VAR"); INITDATA(APS_SENSOR_KBACT, ENVSYS_INDICATOR, "Keyboard Active"); INITDATA(APS_SENSOR_MSACT, ENVSYS_INDICATOR, "Mouse Active"); INITDATA(APS_SENSOR_LIDOPEN, ENVSYS_INDICATOR, "Lid Open"); sc->sc_sme = sysmon_envsys_create(); for (i = 0; i < APS_NUM_SENSORS; i++) { sc->sc_sensor[i].state = ENVSYS_SVALID; if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[i])) { sysmon_envsys_destroy(sc->sc_sme); goto out; } } /* * Register with the sysmon_envsys(9) framework. */ sc->sc_sme->sme_name = device_xname(self); sc->sc_sme->sme_flags = SME_DISABLE_REFRESH; if ((i = sysmon_envsys_register(sc->sc_sme))) { aprint_error_dev(self, "unable to register with sysmon (%d)\n", i); sysmon_envsys_destroy(sc->sc_sme); goto out; } if (!pmf_device_register(self, aps_suspend, aps_resume)) aprint_error_dev(self, "couldn't establish power handler\n"); /* Refresh sensor data every 0.5 seconds */ callout_init(&sc->sc_callout, 0); callout_setfunc(&sc->sc_callout, aps_refresh, sc); callout_schedule(&sc->sc_callout, (hz) / 2); aprint_normal_dev(self, "Thinkpad Active Protection System\n"); return; out: bus_space_unmap(sc->sc_iot, sc->sc_ioh, APS_ADDR_SIZE); }