static void via_mapchan(const struct pci_attach_args *pa, struct pciide_channel *cp, pcireg_t interface, int (*pci_intr)(void *)) { struct ata_channel *wdc_cp; struct pciide_softc *sc; prop_bool_t compat_nat_enable; wdc_cp = &cp->ata_channel; sc = CHAN_TO_PCIIDE(&cp->ata_channel); compat_nat_enable = prop_dictionary_get( device_properties(sc->sc_wdcdev.sc_atac.atac_dev), "use-compat-native-irq"); if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel)) { /* native mode with irq 14/15 requested? */ if (compat_nat_enable != NULL && prop_bool_true(compat_nat_enable)) via_mapregs_compat_native(pa, cp); else pciide_mapregs_native(pa, cp, pci_intr); } else { pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel); if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0) pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel); } wdcattach(wdc_cp); }
bool prop_dictionary_get_bool(prop_dictionary_t dict, const char *key, bool *valp) { prop_bool_t b; b = prop_dictionary_get(dict, key); if (prop_object_type(b) != PROP_TYPE_BOOL) return (false); *valp = prop_bool_true(b); return (true); }
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); }
static int swsensor_init(void *arg) { int error, val = 0; const char *key, *str; prop_dictionary_t pd = (prop_dictionary_t)arg; prop_object_t po, obj; prop_object_iterator_t iter; prop_type_t type; const struct sme_descr_entry *descr; swsensor_sme = sysmon_envsys_create(); if (swsensor_sme == NULL) return ENOTTY; swsensor_sme->sme_name = "swsensor"; swsensor_sme->sme_cookie = &swsensor_edata; swsensor_sme->sme_refresh = swsensor_refresh; swsensor_sme->sme_set_limits = NULL; swsensor_sme->sme_get_limits = NULL; /* Set defaults in case no prop dictionary given */ swsensor_edata.units = ENVSYS_INTEGER; swsensor_edata.flags = 0; sw_sensor_mode = 0; sw_sensor_value = 0; sw_sensor_limit = 0; /* Iterate over the provided dictionary, if any */ if (pd != NULL) { iter = prop_dictionary_iterator(pd); if (iter == NULL) return ENOMEM; while ((obj = prop_object_iterator_next(iter)) != NULL) { key = prop_dictionary_keysym_cstring_nocopy(obj); po = prop_dictionary_get_keysym(pd, obj); type = prop_object_type(po); if (type == PROP_TYPE_NUMBER) val = prop_number_integer_value(po); /* Sensor type/units */ if (strcmp(key, "type") == 0) { if (type == PROP_TYPE_NUMBER) { descr = sme_find_table_entry( SME_DESC_UNITS, val); if (descr == NULL) return EINVAL; swsensor_edata.units = descr->type; continue; } if (type != PROP_TYPE_STRING) return EINVAL; str = prop_string_cstring_nocopy(po); descr = sme_find_table_desc(SME_DESC_UNITS, str); if (descr == NULL) return EINVAL; swsensor_edata.units = descr->type; continue; } /* Sensor flags */ if (strcmp(key, "flags") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; swsensor_edata.flags = val; continue; } /* Sensor limit behavior * 0 - simple sensor, no hw limits * 1 - simple sensor, hw provides initial limit * 2 - complex sensor, hw provides settable * limits and does its own limit checking */ if (strcmp(key, "mode") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; sw_sensor_mode = val; if (sw_sensor_mode > 2) sw_sensor_mode = 2; else if (sw_sensor_mode < 0) sw_sensor_mode = 0; continue; } /* Grab any limit that might be specified */ if (strcmp(key, "limit") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; sw_sensor_limit = val; continue; } /* Grab the initial value */ if (strcmp(key, "value") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; sw_sensor_value = val; continue; } /* Grab value_min and value_max */ if (strcmp(key, "value_min") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; swsensor_edata.value_min = val; swsensor_edata.flags |= ENVSYS_FVALID_MIN; continue; } if (strcmp(key, "value_max") == 0) { if (type != PROP_TYPE_NUMBER) return EINVAL; swsensor_edata.value_max = val; swsensor_edata.flags |= ENVSYS_FVALID_MAX; continue; } /* See if sensor reports percentages vs raw values */ if (strcmp(key, "percentage") == 0) { if (type != PROP_TYPE_BOOL) return EINVAL; if (prop_bool_true(po)) swsensor_edata.flags |= ENVSYS_FPERCENT; continue; } /* Unrecognized dicttionary object */ #ifdef DEBUG printf("%s: unknown attribute %s\n", __func__, key); #endif return EINVAL; } /* while */ prop_object_iterator_release(iter); } /* Initialize limit processing */ if (sw_sensor_mode >= 1) swsensor_sme->sme_get_limits = swsensor_get_limits; if (sw_sensor_mode == 2) swsensor_sme->sme_set_limits = swsensor_set_limits; if (sw_sensor_mode != 0) { swsensor_edata.flags |= ENVSYS_FMONLIMITS; swsensor_get_limits(swsensor_sme, &swsensor_edata, &sw_sensor_deflims, &sw_sensor_defprops); } strlcpy(swsensor_edata.desc, "sensor", ENVSYS_DESCLEN); /* Wait for refresh to validate the sensor value */ swsensor_edata.state = ENVSYS_SINVALID; sw_sensor_state = ENVSYS_SVALID; error = sysmon_envsys_sensor_attach(swsensor_sme, &swsensor_edata); if (error != 0) { aprint_error("sysmon_envsys_sensor_attach failed: %d\n", error); return error; } error = sysmon_envsys_register(swsensor_sme); if (error != 0) { aprint_error("sysmon_envsys_register failed: %d\n", error); return error; } sysctl_swsensor_setup(); aprint_normal("swsensor: initialized\n"); return 0; }
int module_load_vfs(const char *name, int flags, bool autoload, module_t *mod, prop_dictionary_t *filedictp) { char *path; bool nochroot; int error; prop_bool_t noload; prop_dictionary_t moduledict; nochroot = false; error = 0; path = NULL; moduledict = NULL; if (filedictp) *filedictp = NULL; path = PNBUF_GET(); if (!autoload) { if (strchr(name, '/') != NULL) { nochroot = false; snprintf(path, MAXPATHLEN, "%s", name); error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); } else error = ENOENT; } if (autoload || (error == ENOENT)) { if (strchr(name, '/') == NULL) { nochroot = true; snprintf(path, MAXPATHLEN, "%s/%s/%s.kmod", module_base, name, name); error = kobj_load_vfs(&mod->mod_kobj, path, nochroot); } else error = ENOENT; } if (error != 0) { PNBUF_PUT(path); module_print("Cannot %sload kernel object `%s'" " error=%d", autoload ? "auto" : "", name, error); return error; } /* * Load and process <module>.plist if it exists. */ if (((flags & MODCTL_NO_PROP) == 0 && filedictp) || autoload) { error = module_load_plist_vfs(path, nochroot, &moduledict); if (error != 0) { module_print("plist load returned error %d for `%s'", error, path); if (error != ENOENT) goto fail; } else if (autoload) { noload = prop_dictionary_get(moduledict, "noautoload"); if (noload != NULL && prop_bool_true(noload)) { module_error("autoloading is disallowed for %s", path); prop_object_release(moduledict); error = EPERM; goto fail; } } if (error == 0) { /* can get here if error == ENOENT */ if ((flags & MODCTL_NO_PROP) == 0 && filedictp) *filedictp = moduledict; else prop_object_release(moduledict); } } PNBUF_PUT(path); return 0; fail: kobj_unload(mod->mod_kobj); PNBUF_PUT(path); return error; }