static prop_dictionary_t pkgdict_init(void) { prop_array_t a; prop_dictionary_t d; d = prop_dictionary_create(); ATF_REQUIRE(d != NULL); a = provides_init(); ATF_REQUIRE_EQ(prop_dictionary_set(d, "provides", a), true); return d; }
static void parse_int_param(prop_dictionary_t props, const char *name, const char *value) { int64_t intvalue; assert(name != NULL); assert(value != NULL); if (dehumanize_number(value, &intvalue) != 0) err(EXIT_FAILURE, "Invalid integer value `%s'", value); prop_dictionary_set(props, name, prop_number_create_integer(intvalue)); }
bool prop_dictionary_set_bool(prop_dictionary_t dict, const char *key, bool val) { prop_bool_t b; int rv; b = prop_bool_create(val); if (b == NULL) return (false); rv = prop_dictionary_set(dict, key, b); prop_object_release(b); return (rv); }
nl_nat_t * npf_nat_create(int type, u_int flags, const char *ifname, int af, npf_addr_t *addr, npf_netmask_t mask, in_port_t port) { nl_rule_t *rl; prop_dictionary_t rldict; prop_data_t addrdat; uint32_t attr; size_t sz; if (af == AF_INET) { sz = sizeof(struct in_addr); } else if (af == AF_INET6) { sz = sizeof(struct in6_addr); } else { return NULL; } attr = NPF_RULE_PASS | NPF_RULE_FINAL | (type == NPF_NATOUT ? NPF_RULE_OUT : NPF_RULE_IN); /* Create a rule for NAT policy. Next, will add translation data. */ rl = npf_rule_create(NULL, attr, ifname); if (rl == NULL) { return NULL; } rldict = rl->nrl_dict; /* Translation type and flags. */ prop_dictionary_set_int32(rldict, "type", type); prop_dictionary_set_uint32(rldict, "flags", flags); /* Translation IP and mask. */ addrdat = prop_data_create_data(addr, sz); if (addrdat == NULL) { npf_rule_destroy(rl); return NULL; } prop_dictionary_set(rldict, "translation-ip", addrdat); prop_dictionary_set_uint32(rldict, "translation-mask", mask); prop_object_release(addrdat); /* Translation port (for redirect case). */ prop_dictionary_set_uint16(rldict, "translation-port", port); return (nl_nat_t *)rl; }
static void armadillo9_device_register(device_t dev, void *aux) { /* MAC address for the built-in Ethernet. */ if (device_is_a(dev, "epe")) { prop_data_t pd = prop_data_create_data_nocopy( armadillo9_ethaddr, ETHER_ADDR_LEN); KASSERT(pd != NULL); if (prop_dictionary_set(device_properties(dev), "mac-address", pd) == false) { printf("WARNING: unable to set mac-addr property " "for %s\n", device_xname(dev)); } prop_object_release(pd); } }
static int hdaudioctl_set(int fd, int argc, char *argv[]) { prop_dictionary_t request, response; prop_array_t config = NULL; uint16_t nid, codecid; int error; if (argc < 2 || argc > 3) usage(); codecid = strtol(argv[0], NULL, 0); nid = strtol(argv[1], NULL, 0); if (argc == 3) { config = prop_array_internalize_from_file(argv[2]); if (config == NULL) { fprintf(stderr, "couldn't load configuration from %s\n", argv[2]); return EIO; } } request = prop_dictionary_create(); if (request == NULL) { fprintf(stderr, "out of memory\n"); return ENOMEM; } prop_dictionary_set_uint16(request, "codecid", codecid); prop_dictionary_set_uint16(request, "nid", nid); if (config) prop_dictionary_set(request, "pin-config", config); error = prop_dictionary_sendrecv_ioctl(request, fd, HDAUDIO_FGRP_SETCONFIG, &response); if (error != 0) { perror("HDAUDIO_FGRP_SETCONFIG failed"); return error; } prop_object_release(response); prop_object_release(request); return 0; }
/* * Get list of all available targets from global * target list and sent them back to libdevmapper. */ int dm_list_versions_ioctl(prop_dictionary_t dm_dict) { prop_array_t target_list; uint32_t flags; flags = 0; prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags); dm_dbg_print_flags(flags); target_list = dm_target_prop_list(); prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list); prop_object_release(target_list); return 0; }
int npf_config_submit(nl_config_t *ncf, int fd) { const char *plist = ncf->ncf_plist; prop_dictionary_t npf_dict; prop_array_t rlset; int error = 0; npf_dict = prop_dictionary_create(); if (npf_dict == NULL) { return ENOMEM; } prop_dictionary_set_uint32(npf_dict, "version", NPF_VERSION); rlset = _npf_ruleset_transform(ncf->ncf_rules_list); if (rlset == NULL) { prop_object_release(npf_dict); return ENOMEM; } prop_object_release(ncf->ncf_rules_list); ncf->ncf_rules_list = rlset; prop_dictionary_set(npf_dict, "rules", ncf->ncf_rules_list); prop_dictionary_set(npf_dict, "algs", ncf->ncf_alg_list); prop_dictionary_set(npf_dict, "rprocs", ncf->ncf_rproc_list); prop_dictionary_set(npf_dict, "tables", ncf->ncf_table_list); prop_dictionary_set(npf_dict, "translation", ncf->ncf_nat_list); prop_dictionary_set_bool(npf_dict, "flush", ncf->ncf_flush); if (ncf->ncf_debug) { prop_dictionary_set(npf_dict, "debug", ncf->ncf_debug); } if (plist) { if (!prop_dictionary_externalize_to_file(npf_dict, plist)) { error = errno; } prop_object_release(npf_dict); return error; } if (fd) { error = prop_dictionary_sendrecv_ioctl(npf_dict, fd, IOC_NPF_RELOAD, &ncf->ncf_err); if (error) { prop_object_release(npf_dict); assert(ncf->ncf_err == NULL); return error; } prop_dictionary_get_int32(ncf->ncf_err, "errno", &error); } prop_object_release(npf_dict); return error; }
int nbsd_dmi_add_version(const int *version, prop_dictionary_t dm_dict) { prop_array_t ver; size_t i; if ((ver = prop_array_create()) == NULL) return -1; for (i=0;i<3;i++) prop_array_set_uint32(ver,i,version[i]); if ((prop_dictionary_set(dm_dict,"version",ver)) == false) return -1; prop_object_release(ver); return 0; }
/* * Save the firmware package handle inside the properties dictionary * of a device_t. */ static void device_setofnode(device_t dev, int node) { prop_dictionary_t props; prop_object_t obj; if (dev == NULL) return; props = device_properties(dev); if (props == NULL) return; obj = prop_number_create_integer(node); if (obj == NULL) return; prop_dictionary_set(props, OFNODEKEY, obj); prop_object_release(obj); DPRINTF(ACDB_BOOTDEV, (" [device %s has node %x] ", device_xname(dev), node)); }
prop_dictionary_t testcase_get_result_dict(prop_dictionary_t testcase) { prop_dictionary_t result_dict; int r; result_dict = prop_dictionary_get(testcase, "result"); if (result_dict == NULL) { result_dict = prop_dictionary_create(); if (result_dict == NULL) err(1, "could not allocate new result dict"); r = prop_dictionary_set(testcase, "result", result_dict); if (r == 0) err(1, "prop_dictionary operation failed"); } return result_dict; }
int npf_rule_insert(nl_config_t *ncf, nl_rule_t *parent, nl_rule_t *rl) { prop_dictionary_t rldict = rl->nrl_dict; prop_array_t rlset; if (parent) { prop_dictionary_t pdict = parent->nrl_dict; rlset = prop_dictionary_get(pdict, "subrules"); if (rlset == NULL) { rlset = prop_array_create(); prop_dictionary_set(pdict, "subrules", rlset); prop_object_release(rlset); } } else { rlset = ncf->ncf_rules_list; } prop_array_add(rlset, rldict); return 0; }
prop_array_t udev_getdevs(int devfd) { prop_dictionary_t pd, rpd; prop_string_t ps; prop_array_t pa; pd = prop_dictionary_create(); if (pd == NULL) { err(1, "prop_dictionary_create()"); } ps = prop_string_create_cstring("getdevs"); if (ps == NULL) { prop_object_release(pd); err(1, "prop_string_create_cstring()"); } if (prop_dictionary_set(pd, "command", ps) == false) { prop_object_release(ps); prop_object_release(pd); err(1, "prop_dictionary_set()"); } prop_object_release(ps); /* Send dictionary to kernel space */ if (prop_dictionary_sendrecv_ioctl(pd, devfd, UDEVPROP, &rpd) != 0) err(1, "prop_array_recv_ioctl()"); prop_object_release(pd); pa = prop_dictionary_get(rpd, "array"); if (pa == NULL) goto out; prop_object_retain(pa); out: prop_object_release(rpd); return pa; }
void device_register(struct device *dev, void *aux) { struct device *pdev; /* * We don't ever know the boot device. But that's because the * firmware only loads from the network or the parallel port. */ /* * Fetch the MAC address for the built-in Ethernet (we grab it * from PMON earlier in the boot process). */ if ((pdev = device_parent(dev)) != NULL && device_is_a(pdev, "pci")) { struct pci_attach_args *pa = aux; if (BUILTIN_ETHERNET_P(pa)) { prop_data_t pd = prop_data_create_data_nocopy( algor_ethaddr, ETHER_ADDR_LEN); KASSERT(pd != NULL); if (prop_dictionary_set(device_properties(dev), "mac-addr", pd) == false) { printf("WARNING: unable to set mac-addr " "property for %s\n", dev->dv_xname); } prop_object_release(pd); #if defined(ALGOR_P4032) /* * XXX This is gross, disgusting, and otherwise vile, * XXX but V962 rev. < B2 have broken DMA FIFOs. Give * XXX the on-board Ethernet a different DMA window * XXX that has pre-fetching disabled so that Ethernet * XXX performance doesn't completely suck. */ pa->pa_dmat = &p4032_configuration.ac_pci_pf_dmat; pa->pa_dmat64 = NULL; #endif /* ALGOR_P4032 */ } } }
static void bthub_attach(device_t parent, device_t self, void *aux) { bdaddr_t *addr = aux; prop_dictionary_t dict; prop_object_t obj; dict = device_properties(self); obj = prop_data_create_data(addr, sizeof(*addr)); prop_dictionary_set(dict, BTDEVladdr, obj); prop_object_release(obj); aprint_verbose(" %s %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", BTDEVladdr, addr->b[5], addr->b[4], addr->b[3], addr->b[2], addr->b[1], addr->b[0]); aprint_normal("\n"); pmf_device_register(self, NULL, NULL); }
int npf_rule_setcode(nl_rule_t *rl, int type, const void *code, size_t len) { prop_dictionary_t rldict = rl->nrl_dict; prop_data_t cdata; switch (type) { case NPF_CODE_NC: case NPF_CODE_BPF: break; default: return ENOTSUP; } prop_dictionary_set_uint32(rldict, "code-type", type); if ((cdata = prop_data_create_data(code, len)) == NULL) { return ENOMEM; } prop_dictionary_set(rldict, "code", cdata); prop_object_release(cdata); return 0; }
int npf_sessions_send(int fd, const char *fpath) { prop_dictionary_t sdict; int error; if (fpath) { sdict = prop_dictionary_internalize_from_file(fpath); if (sdict == NULL) { return errno; } } else { /* Empty: will flush the sessions. */ prop_array_t selist = prop_array_create(); sdict = prop_dictionary_create(); prop_dictionary_set(sdict, "session-list", selist); prop_object_release(selist); } error = prop_dictionary_send_ioctl(sdict, fd, IOC_NPF_SESSIONS_LOAD); prop_object_release(sdict); return error; }
gboolean drvctl_find_device(const gchar *devnode, prop_dictionary_t *properties) { prop_dictionary_t command_dict; prop_dictionary_t args_dict; prop_dictionary_t results_dict; int err; command_dict = prop_dictionary_create (); args_dict = prop_dictionary_create (); prop_dictionary_set_cstring_nocopy (command_dict, "drvctl-command", "get-properties"); prop_dictionary_set_cstring_nocopy (args_dict, "device-name", devnode); prop_dictionary_set (command_dict, "drvctl-arguments", args_dict); prop_object_release (args_dict); err = prop_dictionary_sendrecv_ioctl (command_dict, drvctl_fd, DRVCTLCOMMAND, &results_dict); prop_object_release (command_dict); if (err) return FALSE; if (prop_dictionary_get_int8 (results_dict, "drvctl-error", &err) == false || err != 0) { prop_object_release (results_dict); return FALSE; } if (properties) { prop_dictionary_t result_data; result_data = prop_dictionary_get (results_dict, "drvctl-result-data"); if (result_data) *properties = prop_dictionary_copy (result_data); } prop_object_release (results_dict); return TRUE; }
int npf_ruleset_remkey(int fd, const char *rname, const void *key, size_t len) { prop_dictionary_t rldict; prop_data_t keyobj; rldict = prop_dictionary_create(); if (rldict == NULL) { return ENOMEM; } prop_dictionary_set_cstring(rldict, "ruleset-name", rname); prop_dictionary_set_uint32(rldict, "command", NPF_CMD_RULE_REMKEY); keyobj = prop_data_create_data(key, len); if (keyobj == NULL) { prop_object_release(rldict); return ENOMEM; } prop_dictionary_set(rldict, "key", keyobj); prop_object_release(keyobj); return prop_dictionary_send_ioctl(rldict, fd, IOC_NPF_RULE); }
static void parse_bool_param(prop_dictionary_t props, const char *name, const char *value) { bool boolvalue; assert(name != NULL); assert(value != NULL); if (strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0) boolvalue = true; else if (strcasecmp(value, "0") == 0 || strcasecmp(value, "false") == 0 || strcasecmp(value, "no") == 0) boolvalue = false; else errx(EXIT_FAILURE, "Invalid boolean value `%s'", value); prop_dictionary_set(props, name, prop_bool_create(boolvalue)); }
int npf_table_add_entry(nl_table_t *tl, int af, const npf_addr_t *addr, const npf_netmask_t mask) { prop_dictionary_t tldict = tl->ntl_dict, entdict; prop_array_t tblents; prop_data_t addrdata; unsigned alen; /* Create the table entry. */ entdict = prop_dictionary_create(); if (entdict == NULL) { return ENOMEM; } switch (af) { case AF_INET: alen = sizeof(struct in_addr); break; case AF_INET6: alen = sizeof(struct in6_addr); break; default: return EINVAL; } addrdata = prop_data_create_data(addr, alen); prop_dictionary_set(entdict, "addr", addrdata); prop_dictionary_set_uint8(entdict, "mask", mask); prop_object_release(addrdata); tblents = prop_dictionary_get(tldict, "entries"); prop_array_add(tblents, entdict); prop_object_release(entdict); return 0; }
static int bthub_pioctl(dev_t devno, unsigned long cmd, prop_dictionary_t dict, int flag, struct lwp *l) { prop_data_t laddr, raddr; prop_string_t service; prop_dictionary_t prop; prop_object_t obj; device_t dev, self; deviter_t di; int unit; /* validate local address */ laddr = prop_dictionary_get(dict, BTDEVladdr); if (prop_data_size(laddr) != sizeof(bdaddr_t)) return EINVAL; /* locate the relevant bthub */ for (unit = 0 ; ; unit++) { if (unit == bthub_cd.cd_ndevs) return ENXIO; self = device_lookup(&bthub_cd, unit); if (self == NULL) continue; prop = device_properties(self); obj = prop_dictionary_get(prop, BTDEVladdr); if (prop_data_equals(laddr, obj)) break; } /* validate remote address */ raddr = prop_dictionary_get(dict, BTDEVraddr); if (prop_data_size(raddr) != sizeof(bdaddr_t) || bdaddr_any(prop_data_data_nocopy(raddr))) return EINVAL; /* validate service name */ service = prop_dictionary_get(dict, BTDEVservice); if (prop_object_type(service) != PROP_TYPE_STRING) return EINVAL; /* locate matching child device, if any */ deviter_init(&di, 0); while ((dev = deviter_next(&di)) != NULL) { if (device_parent(dev) != self) continue; prop = device_properties(dev); obj = prop_dictionary_get(prop, BTDEVraddr); if (!prop_object_equals(raddr, obj)) continue; obj = prop_dictionary_get(prop, BTDEVservice); if (!prop_object_equals(service, obj)) continue; break; } deviter_release(&di); switch (cmd) { case BTDEV_ATTACH: /* attach BTDEV */ if (dev != NULL) return EADDRINUSE; dev = config_found(self, dict, bthub_print); if (dev == NULL) return ENXIO; prop = device_properties(dev); prop_dictionary_set(prop, BTDEVladdr, laddr); prop_dictionary_set(prop, BTDEVraddr, raddr); prop_dictionary_set(prop, BTDEVservice, service); break; case BTDEV_DETACH: /* detach BTDEV */ if (dev == NULL) return ENXIO; config_detach(dev, DETACH_FORCE); break; } return 0; }
void disk_set_info(device_t dev, struct disk *dk, const char *type) { struct disk_geom *dg = &dk->dk_geom; if (dg->dg_secsize == 0) { #ifdef DIAGNOSTIC printf("%s: fixing 0 sector size\n", dk->dk_name); #endif dg->dg_secsize = DEV_BSIZE; } dk->dk_blkshift = DK_BSIZE2BLKSHIFT(dg->dg_secsize); dk->dk_byteshift = DK_BSIZE2BYTESHIFT(dg->dg_secsize); if (dg->dg_secperunit == 0 && dg->dg_ncylinders == 0) { #ifdef DIAGNOSTIC printf("%s: secperunit and ncylinders are zero\n", dk->dk_name); #endif return; } if (dg->dg_secperunit == 0) { if (dg->dg_nsectors == 0 || dg->dg_ntracks == 0) { #ifdef DIAGNOSTIC printf("%s: secperunit and (sectors or tracks) " "are zero\n", dk->dk_name); #endif return; } dg->dg_secperunit = (int64_t) dg->dg_nsectors * dg->dg_ntracks * dg->dg_ncylinders; } if (dg->dg_ncylinders == 0) { if (dg->dg_ntracks && dg->dg_nsectors) dg->dg_ncylinders = dg->dg_secperunit / (dg->dg_ntracks * dg->dg_nsectors); } prop_dictionary_t disk_info, odisk_info, geom; disk_info = prop_dictionary_create(); geom = prop_dictionary_create(); prop_dictionary_set_uint64(geom, "sectors-per-unit", dg->dg_secperunit); prop_dictionary_set_uint32(geom, "sector-size", dg->dg_secsize); if (dg->dg_nsectors) prop_dictionary_set_uint16(geom, "sectors-per-track", dg->dg_nsectors); if (dg->dg_ntracks) prop_dictionary_set_uint16(geom, "tracks-per-cylinder", dg->dg_ntracks); if (dg->dg_ncylinders) prop_dictionary_set_uint64(geom, "cylinders-per-unit", dg->dg_ncylinders); prop_dictionary_set(disk_info, "geometry", geom); if (type) prop_dictionary_set_cstring_nocopy(disk_info, "type", type); prop_object_release(geom); odisk_info = dk->dk_info; dk->dk_info = disk_info; if (dev) prop_dictionary_set(device_properties(dev), "disk-info", disk_info); /* * Don't release disk_info here; we keep a reference to it. * disk_detach() will release it when we go away. */ if (odisk_info) prop_object_release(odisk_info); }
/* * Called back during autoconfiguration for each device found */ void device_register(device_t dev, void *aux) { device_t busdev = device_parent(dev); int ofnode = 0; /* * We don't know the type of 'aux' - it depends on the * bus this device attaches to. We are only interested in * certain bus types, this only is used to find the boot * device. */ if (busdev == NULL) { /* * Ignore mainbus0 itself, it certainly is not a boot * device. */ } else if (device_is_a(busdev, "mainbus")) { struct mainbus_attach_args *ma = aux; ofnode = ma->ma_node; } else if (device_is_a(busdev, "pci")) { struct pci_attach_args *pa = aux; ofnode = PCITAG_NODE(pa->pa_tag); } else if (device_is_a(busdev, "sbus") || device_is_a(busdev, "dma") || device_is_a(busdev, "ledma")) { struct sbus_attach_args *sa = aux; ofnode = sa->sa_node; } else if (device_is_a(busdev, "ebus")) { struct ebus_attach_args *ea = aux; ofnode = ea->ea_node; } else if (device_is_a(busdev, "iic")) { struct i2c_attach_args *ia = aux; if (ia->ia_name == NULL) /* indirect config */ return; ofnode = (int)ia->ia_cookie; } else if (device_is_a(dev, "sd") || device_is_a(dev, "cd")) { struct scsipibus_attach_args *sa = aux; struct scsipi_periph *periph = sa->sa_periph; int off = 0; /* * There are two "cd" attachments: * atapibus -> atabus -> controller * scsibus -> controller * We want the node of the controller. */ if (device_is_a(busdev, "atapibus")) { busdev = device_parent(busdev); /* * if the atapibus is connected to the secondary * channel of the atabus, we need an offset of 2 * to match OF's idea of the target number. * (i.e. on U5/U10 "cdrom" and "disk2" have the * same target encoding, though different names) */ if (periph->periph_channel->chan_channel == 1) off = 2; } ofnode = device_ofnode(device_parent(busdev)); dev_path_drive_match(dev, ofnode, periph->periph_target + off, 0, periph->periph_lun); return; } else if (device_is_a(dev, "wd")) { struct ata_device *adev = aux; ofnode = device_ofnode(device_parent(busdev)); dev_path_drive_match(dev, ofnode, adev->adev_channel*2+ adev->adev_drv_data->drive, 0, 0); return; } if (busdev == NULL) return; if (ofnode != 0) { uint8_t eaddr[ETHER_ADDR_LEN]; char tmpstr[32]; char tmpstr2[32]; int node; uint32_t id = 0; uint64_t nwwn = 0, pwwn = 0; prop_dictionary_t dict; prop_data_t blob; prop_number_t pwwnd = NULL, nwwnd = NULL; prop_number_t idd = NULL; device_setofnode(dev, ofnode); dev_path_exact_match(dev, ofnode); if (OF_getprop(ofnode, "name", tmpstr, sizeof(tmpstr)) <= 0) tmpstr[0] = 0; if (OF_getprop(ofnode, "device_type", tmpstr2, sizeof(tmpstr2)) <= 0) tmpstr2[0] = 0; /* * If this is a network interface, note the * mac address. */ if (strcmp(tmpstr, "network") == 0 || strcmp(tmpstr, "ethernet") == 0 || strcmp(tmpstr2, "network") == 0 || strcmp(tmpstr2, "ethernet") == 0 || OF_getprop(ofnode, "mac-address", &eaddr, sizeof(eaddr)) >= ETHER_ADDR_LEN || OF_getprop(ofnode, "local-mac-address", &eaddr, sizeof(eaddr)) >= ETHER_ADDR_LEN) { dict = device_properties(dev); /* * Is it a network interface with FCode? */ if (strcmp(tmpstr, "network") == 0 || strcmp(tmpstr2, "network") == 0) { prop_dictionary_set_bool(dict, "without-seeprom", true); prom_getether(ofnode, eaddr); } else { if (!prom_get_node_ether(ofnode, eaddr)) goto noether; } blob = prop_data_create_data(eaddr, ETHER_ADDR_LEN); prop_dictionary_set(dict, "mac-address", blob); prop_object_release(blob); of_to_dataprop(dict, ofnode, "shared-pins", "shared-pins"); } noether: /* is this a FC node? */ if (strcmp(tmpstr, "scsi-fcp") == 0) { dict = device_properties(dev); if (OF_getprop(ofnode, "port-wwn", &pwwn, sizeof(pwwn)) == sizeof(pwwn)) { pwwnd = prop_number_create_unsigned_integer(pwwn); prop_dictionary_set(dict, "port-wwn", pwwnd); prop_object_release(pwwnd); } if (OF_getprop(ofnode, "node-wwn", &nwwn, sizeof(nwwn)) == sizeof(nwwn)) { nwwnd = prop_number_create_unsigned_integer(nwwn); prop_dictionary_set(dict, "node-wwn", nwwnd); prop_object_release(nwwnd); } } /* is this an spi device? look for scsi-initiator-id */ if (strcmp(tmpstr2, "scsi") == 0 || strcmp(tmpstr2, "scsi-2") == 0) { dict = device_properties(dev); for (node = ofnode; node != 0; node = OF_parent(node)) { if (OF_getprop(node, "scsi-initiator-id", &id, sizeof(id)) <= 0) continue; idd = prop_number_create_unsigned_integer(id); prop_dictionary_set(dict, "scsi-initiator-id", idd); prop_object_release(idd); break; } } } /* * Check for I2C busses and add data for their direct configuration. */ if (device_is_a(dev, "iic")) { int busnode = device_ofnode(busdev); if (busnode) { prop_dictionary_t props = device_properties(busdev); prop_object_t cfg = prop_dictionary_get(props, "i2c-child-devices"); if (!cfg) { int node; const char *name; /* * pmu's i2c devices are under the "i2c" node, * so find it out. */ name = prom_getpropstring(busnode, "name"); if (strcmp(name, "pmu") == 0) { for (node = OF_child(busnode); node != 0; node = OF_peer(node)) { name = prom_getpropstring(node, "name"); if (strcmp(name, "i2c") == 0) { busnode = node; break; } } } of_enter_i2c_devs(props, busnode, sizeof(cell_t)); } } /* * Add SPARCle spdmem devices (0x50 and 0x51) that the * firmware does not know about. */ if (!strcmp(machine_model, "TAD,SPARCLE")) { prop_dictionary_t props = device_properties(busdev); prop_array_t cfg = prop_array_create(); int i; DPRINTF(ACDB_PROBE, ("\nAdding spdmem for SPARCle ")); for (i = 0x50; i <= 0x51; i++) { prop_dictionary_t spd = prop_dictionary_create(); prop_dictionary_set_cstring(spd, "name", "dimm-spd"); prop_dictionary_set_uint32(spd, "addr", i); prop_dictionary_set_uint64(spd, "cookie", 0); prop_array_add(cfg, spd); prop_object_release(spd); } prop_dictionary_set(props, "i2c-child-devices", cfg); prop_object_release(cfg); } } /* set properties for PCI framebuffers */ if (device_is_a(busdev, "pci")) { /* see if this is going to be console */ struct pci_attach_args *pa = aux; prop_dictionary_t dict; int sub; int console = 0; dict = device_properties(dev); /* we only care about display devices from here on */ if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY) return; console = (ofnode == console_node); if (!console) { /* * see if any child matches since OF attaches * nodes for each head and /chosen/stdout * points to the head rather than the device * itself in this case */ sub = OF_child(ofnode); while ((sub != 0) && (sub != console_node)) { sub = OF_peer(sub); } if (sub == console_node) { console = true; } } copyprops(busdev, ofnode, dict, console); if (console) { uint64_t cmap_cb; prop_dictionary_set_uint32(dict, "instance_handle", console_instance); gfb_cb.gcc_cookie = (void *)(intptr_t)console_instance; gfb_cb.gcc_set_mapreg = of_set_palette; cmap_cb = (uint64_t)(uintptr_t)&gfb_cb; prop_dictionary_set_uint64(dict, "cmap_callback", cmap_cb); } #ifdef notyet else { int width; /* * the idea is to 'open' display devices with no useful * properties, in the hope that the firmware will * properly initialize them and we can run things like * genfb on them */ if (OF_getprop(node, "width", &width, sizeof(width)) != 4) { instance = OF_open(name); #endif } } /* * Called back after autoconfiguration of a device is done */ void device_register_post_config(device_t dev, void *aux) { if (booted_device == NULL && device_is_a(dev, "sd")) { struct scsipibus_attach_args *sa = aux; struct scsipi_periph *periph = sa->sa_periph; uint64_t wwn = 0; int ofnode; /* * If this is a FC-AL drive it will have * aquired its WWN device property by now, * so we can properly match it. */ if (prop_dictionary_get_uint64(device_properties(dev), "port-wwn", &wwn)) { /* * Different to what we do in device_register, * we do not pass the "controller" ofnode, * because FC-AL devices attach below a "fp" node, * E.g.: /pci/SUNW,qlc@4/fp@0,0/disk * and we need the parent of "disk" here. */ ofnode = device_ofnode( device_parent(device_parent(dev))); for (ofnode = OF_child(ofnode); ofnode != 0 && booted_device == NULL; ofnode = OF_peer(ofnode)) { dev_path_drive_match(dev, ofnode, periph->periph_target, wwn, periph->periph_lun); } } } } static void copyprops(device_t busdev, int node, prop_dictionary_t dict, int is_console) { device_t cntrlr; prop_dictionary_t psycho; paddr_t fbpa, mem_base = 0; uint32_t temp, fboffset; uint32_t fbaddr = 0; int options; char output_device[256]; char *pos; cntrlr = device_parent(busdev); if (cntrlr != NULL) { psycho = device_properties(cntrlr); prop_dictionary_get_uint64(psycho, "mem_base", &mem_base); } if (is_console) prop_dictionary_set_bool(dict, "is_console", 1); of_to_uint32_prop(dict, node, "width", "width"); of_to_uint32_prop(dict, node, "height", "height"); of_to_uint32_prop(dict, node, "linebytes", "linebytes"); if (!of_to_uint32_prop(dict, node, "depth", "depth") && /* Some cards have an extra space in the property name */ !of_to_uint32_prop(dict, node, "depth ", "depth")) { /* * XXX we should check linebytes vs. width but those * FBs that don't have a depth property ( /chaos/control... ) * won't have linebytes either */ prop_dictionary_set_uint32(dict, "depth", 8); } OF_getprop(node, "address", &fbaddr, sizeof(fbaddr)); if (fbaddr != 0) { pmap_extract(pmap_kernel(), fbaddr, &fbpa); #ifdef DEBUG printf("membase: %lx fbpa: %lx\n", (unsigned long)mem_base, (unsigned long)fbpa); #endif if (mem_base == 0) { /* XXX this is guesswork */ fboffset = (uint32_t)(fbpa & 0xffffffff); } fboffset = (uint32_t)(fbpa - mem_base); prop_dictionary_set_uint32(dict, "address", fboffset); } if (!of_to_dataprop(dict, node, "EDID", "EDID")) of_to_dataprop(dict, node, "edid", "EDID"); temp = 0; if (OF_getprop(node, "ATY,RefCLK", &temp, sizeof(temp)) != 4) { OF_getprop(OF_parent(node), "ATY,RefCLK", &temp, sizeof(temp)); } if (temp != 0) prop_dictionary_set_uint32(dict, "refclk", temp / 10); /* * finally, let's see if there's a video mode specified in * output-device and pass it on so drivers like radeonfb * can do their thing */ if (!is_console) return; options = OF_finddevice("/options"); if ((options == 0) || (options == -1)) return; if (OF_getprop(options, "output-device", output_device, 256) == 0) return; /* find the mode string if there is one */ pos = strstr(output_device, ":r"); if (pos == NULL) return; prop_dictionary_set_cstring(dict, "videomode", pos + 2); } static void of_set_palette(void *cookie, int index, int r, int g, int b) { int ih = (int)((intptr_t)cookie); OF_call_method_1("color!", ih, 4, r, g, b, index); }
prop_dictionary_t testcase_from_struct(struct testcase *testcase) { int i, r; prop_dictionary_t dict, testcase_dict; prop_array_t a; char *s; testcase_dict = prop_dictionary_create(); if (testcase_dict == NULL) err(1, "could not create testcase dict"); r = prop_dictionary_set_cstring(testcase_dict, "name", testcase->name); if (r == 0) err(1, "prop_dictionary operation failed"); r = prop_dictionary_set_cstring(testcase_dict, "type", testcase->type_str); if (r == 0) err(1, "prop_dictionary operation failed"); a = prop_array_create_with_capacity(testcase->argc+1); if (a == NULL) err(1, "prop_array_create for argv failed"); s = strrchr(testcase->name, '/'); r = prop_array_set_cstring(a, 0, (s == NULL) ? testcase->name : s+1); if (r == 0) err(1, "prop_array_set_cstring operation failed"); for (i = 1; i <= testcase->argc; i++) { r = prop_array_set_cstring(a, i, testcase->argv[i-1]); if (r == 0) err(1, "prop_array_set_cstring operation failed"); } r = prop_dictionary_set(testcase_dict, "args", a); if (r == 0) err(1, "prop_dictionary_set \"args\" failed"); dict = prop_dictionary_create(); if (dict == NULL) err(1, "could not create dict"); r = prop_dictionary_set_int32(dict, "timeout_in_secs", (int32_t)testcase->opts.timeout_in_secs); if (r == 0) err(1, "prop_dictionary operation failed"); r = prop_dictionary_set_uint32(dict, "flags", testcase->opts.flags); if (r == 0) err(1, "prop_dictionary operation failed"); if (testcase->opts.pre_cmd != NULL) { r = prop_dictionary_set_cstring(dict, "pre_cmd", testcase->opts.pre_cmd); if (r == 0) err(1, "prop_dictionary operation failed"); } if (testcase->opts.post_cmd != NULL) { r = prop_dictionary_set_cstring(dict, "post_cmd", testcase->opts.post_cmd); if (r == 0) err(1, "prop_dictionary operation failed"); } r = prop_dictionary_set_uint32(dict, "runas_uid", (uint32_t)testcase->opts.runas_uid); if (r == 0) err(1, "prop_dictionary operation failed"); r = prop_dictionary_set_cstring(dict, "make_cmd", (testcase->opts.make_cmd != NULL) ? testcase->opts.make_cmd : "make"); if (r == 0) err(1, "prop_dictionary operation failed"); r = prop_dictionary_set(testcase_dict, "opts", dict); if (r == 0) err(1, "prop_dictionary operation failed"); return testcase_dict; }
/* Parse given dm task structure to proplib dictionary. */ static int _flatten(struct dm_task *dmt, prop_dictionary_t dm_dict) { prop_array_t cmd_array; prop_dictionary_t target_spec; struct target *t; size_t len; char type[DM_MAX_TYPE_NAME]; uint32_t major, flags; int count = 0; char *str = NULL; const int (*version)[3]; flags = 0; version = &_cmd_data_v4[dmt->type].version; cmd_array = prop_array_create(); for (t = dmt->head; t; t = t->next) { target_spec = prop_dictionary_create(); prop_dictionary_set_uint64(target_spec,DM_TABLE_START,t->start); prop_dictionary_set_uint64(target_spec,DM_TABLE_LENGTH,t->length); strlcpy(type,t->type,DM_MAX_TYPE_NAME); prop_dictionary_set_cstring(target_spec,DM_TABLE_TYPE,type); prop_dictionary_set_cstring(target_spec,DM_TABLE_PARAMS,t->params); prop_dictionary_get_cstring(target_spec, DM_TABLE_PARAMS, (char **) &str); prop_array_set(cmd_array,count,target_spec); prop_object_release(target_spec); count++; } if (count && (dmt->sector || dmt->message)) { log_error("targets and message are incompatible"); return -1; } if (count && dmt->newname) { log_error("targets and newname are incompatible"); return -1; } if (count && dmt->geometry) { log_error("targets and geometry are incompatible"); return -1; } if (dmt->newname && (dmt->sector || dmt->message)) { log_error("message and newname are incompatible"); return -1; } if (dmt->newname && dmt->geometry) { log_error("geometry and newname are incompatible"); return -1; } if (dmt->geometry && (dmt->sector || dmt->message)) { log_error("geometry and message are incompatible"); return -1; } if (dmt->sector && !dmt->message) { log_error("message is required with sector"); return -1; } if (dmt->newname) len += strlen(dmt->newname) + 1; if (dmt->message) len += sizeof(struct dm_target_msg) + strlen(dmt->message) + 1; if (dmt->geometry) len += strlen(dmt->geometry) + 1; nbsd_dmi_add_version((*version), dm_dict); nbsd_get_dm_major(&major, DM_BLOCK_MAJOR); /* * Only devices with major which is equal to netbsd dm major * dm devices in NetBSD can't have more majors then one assigned to dm. */ if (dmt->major != major && dmt->major != -1) return -1; if (dmt->minor >= 0) { flags |= DM_PERSISTENT_DEV_FLAG; prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmt->minor); } /* Set values to dictionary. */ if (dmt->dev_name) prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmt->dev_name); if (dmt->uuid) prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmt->uuid); if (dmt->type == DM_DEVICE_SUSPEND) flags |= DM_SUSPEND_FLAG; if (dmt->no_flush) flags |= DM_NOFLUSH_FLAG; if (dmt->read_only) flags |= DM_READONLY_FLAG; if (dmt->skip_lockfs) flags |= DM_SKIP_LOCKFS_FLAG; if (dmt->query_inactive_table) { if (_dm_version_minor < 16) log_warn("WARNING: Inactive table query unsupported " "by kernel. It will use live table."); flags |= DM_QUERY_INACTIVE_TABLE_FLAG; } prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags); prop_dictionary_set_uint32(dm_dict, DM_IOCTL_EVENT, dmt->event_nr); if (dmt->newname) prop_array_set_cstring(cmd_array, 0, dmt->newname); /* Add array for all COMMAND specific data. */ prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array); prop_object_release(cmd_array); return 0; }
void device_register(device_t dev, void *aux) { static int found, initted, scsiboot, netboot; device_t parent = device_parent(dev); if (mach_type == MACH_SGI_IP32 && parent != NULL && device_is_a(parent, "pci")) { struct pci_attach_args *pa = aux; if (BUILTIN_AHC_P(pa)) { if (prop_dictionary_set_bool(device_properties(dev), "aic7xxx-use-target-defaults", true) == false) { printf("WARNING: unable to set " "aic7xxx-use-target-defaults property " "for %s\n", device_xname(dev)); } if (prop_dictionary_set_bool(device_properties(dev), "aic7xxx-override-ultra", true) == false) { printf("WARNING: unable to set " "aic7xxx-override-ultra property for %s\n", device_xname(dev)); } } } /* * The Set Engineering GIO Fast Ethernet controller has restrictions * on DMA boundaries. */ if (device_is_a(dev, "tl")) { device_t grandparent; prop_number_t gfe_boundary; grandparent = device_parent(parent); if (grandparent != NULL && device_is_a(grandparent, "giopci")) { gfe_boundary = prop_number_create_integer(PAGE_SIZE); KASSERT(gfe_boundary != NULL); if (prop_dictionary_set(device_properties(dev), "tl-dma-page-boundary", gfe_boundary) == false) { printf("WARNING: unable to set " "tl-dma-page-boundary property " "for %s\n", device_xname(dev)); } prop_object_release(gfe_boundary); return; } } if (found) return; if (!initted && booted_protocol) { scsiboot = strcmp(booted_protocol, "SCSI") == 0; netboot = (strcmp(booted_protocol, "BOOTP") == 0); initted = 1; } /* * Handle SCSI boot device definitions * wdsc -- IP12/22/24 * ahc -- IP32 */ if ( (scsiboot && device_is_a(dev, "wdsc")) || (scsiboot && device_is_a(dev, "ahc")) ) { /* XXX device_unit() abuse */ if (device_unit(dev) == booted_slot) booted_controller = dev; return; } /* * If we found the boot controller, if check disk/tape/cdrom device * on that controller matches. */ if (booted_controller && (device_is_a(dev, "sd") || device_is_a(dev, "st") || device_is_a(dev, "cd"))) { struct scsipibus_attach_args *sa = aux; if (device_parent(parent) != booted_controller) return; if (booted_unit != sa->sa_periph->periph_target) return; booted_device = dev; found = 1; return; } /* * Check if netboot device. */ if (netboot && (device_is_a(dev, "sq") || device_is_a(dev, "mec"))) { /* XXX Check unit number? (Which we don't parse yet) */ booted_device = dev; found = 1; return; } }
/* * Get list of physical devices for active table. * Get dev_t from pdev vnode and insert it into cmd_array. * * XXX. This function is called from lvm2tools to get information * about physical devices, too e.g. during vgcreate. */ int dm_table_deps_ioctl(prop_dictionary_t dm_dict) { dm_dev_t *dmv; dm_table_t *tbl; dm_table_entry_t *table_en; prop_array_t cmd_array; const char *name, *uuid; uint32_t flags, minor; int table_type; size_t i; name = NULL; uuid = NULL; dmv = NULL; flags = 0; i = 0; prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name); prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid); prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags); prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor); /* create array for dev_t's */ cmd_array = prop_array_create(); if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) { DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG); return ENOENT; } prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor); prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name); prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid); aprint_debug("Getting table deps for device: %s\n", dmv->name); /* * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query * INACTIVE TABLE */ if (flags & DM_QUERY_INACTIVE_TABLE_FLAG) table_type = DM_TABLE_INACTIVE; else table_type = DM_TABLE_ACTIVE; tbl = dm_table_get_entry(&dmv->table_head, table_type); SLIST_FOREACH(table_en, tbl, next) table_en->target->deps(table_en, cmd_array); dm_table_release(&dmv->table_head, table_type); dm_dev_unbusy(dmv); prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array); prop_object_release(cmd_array); return 0; }
/* * Configure HID results */ static int config_hid(prop_dictionary_t dict, sdp_data_t *rec) { prop_object_t obj; int32_t control_psm, interrupt_psm, reconnect_initiate, hid_length; uint8_t *hid_descriptor; sdp_data_t value; const char *mode; uint16_t attr; control_psm = -1; interrupt_psm = -1; reconnect_initiate = -1; hid_descriptor = NULL; hid_length = -1; while (sdp_get_attr(rec, &attr, &value)) { switch (attr) { case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: control_psm = parse_pdl(&value, SDP_UUID_PROTOCOL_L2CAP); break; case SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS: interrupt_psm = parse_apdl(&value, SDP_UUID_PROTOCOL_L2CAP); break; case 0x0205: /* HIDReconnectInitiate */ reconnect_initiate = parse_boolean(&value); break; case 0x0206: /* HIDDescriptorList */ if (parse_hid_descriptor(&value)) { hid_descriptor = value.next; hid_length = value.end - value.next; } break; default: break; } } if (control_psm == -1 || interrupt_psm == -1 || reconnect_initiate == -1 || hid_descriptor == NULL || hid_length == -1) return ENOATTR; obj = prop_string_create_cstring_nocopy("bthidev"); if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj)) return errno; prop_object_release(obj); obj = prop_number_create_integer(control_psm); if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVcontrolpsm, obj)) return errno; prop_object_release(obj); obj = prop_number_create_integer(interrupt_psm); if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVinterruptpsm, obj)) return errno; prop_object_release(obj); obj = prop_data_create_data(hid_descriptor, hid_length); if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVdescriptor, obj)) return errno; mode = hid_mode(obj); prop_object_release(obj); obj = prop_string_create_cstring_nocopy(mode); if (obj == NULL || !prop_dictionary_set(dict, BTDEVmode, obj)) return errno; prop_object_release(obj); if (!reconnect_initiate) { obj = prop_bool_create(true); if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVreconnect, obj)) return errno; prop_object_release(obj); } return 0; }
int main(int argc, char **argv) { int c, mode; char *attr = 0; extern char *optarg; extern int optind; int fd, res; size_t children; struct devpmargs paa = {.devname = "", .flags = 0}; struct devlistargs laa = {.l_devname = "", .l_childname = NULL, .l_children = 0}; struct devdetachargs daa; struct devrescanargs raa; int *locs, i; prop_dictionary_t command_dict, args_dict, results_dict, data_dict; prop_string_t string; prop_number_t number; char *xml; mode = 0; while ((c = getopt(argc, argv, OPTS)) != -1) { switch (c) { case 'Q': case 'R': case 'S': case 'd': case 'l': case 'p': case 'r': mode = c; break; case 'a': attr = optarg; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (argc < 1 || mode == 0) usage(); fd = open(DRVCTLDEV, OPEN_MODE(mode), 0); if (fd < 0) err(2, "open %s", DRVCTLDEV); switch (mode) { case 'Q': paa.flags = DEVPM_F_SUBTREE; /*FALLTHROUGH*/ case 'R': strlcpy(paa.devname, argv[0], sizeof(paa.devname)); if (ioctl(fd, DRVRESUMEDEV, &paa) == -1) err(3, "DRVRESUMEDEV"); break; case 'S': strlcpy(paa.devname, argv[0], sizeof(paa.devname)); if (ioctl(fd, DRVSUSPENDDEV, &paa) == -1) err(3, "DRVSUSPENDDEV"); break; case 'd': strlcpy(daa.devname, argv[0], sizeof(daa.devname)); if (ioctl(fd, DRVDETACHDEV, &daa) == -1) err(3, "DRVDETACHDEV"); break; case 'l': strlcpy(laa.l_devname, argv[0], sizeof(laa.l_devname)); if (ioctl(fd, DRVLISTDEV, &laa) == -1) err(3, "DRVLISTDEV"); children = laa.l_children; laa.l_childname = malloc(children * sizeof(laa.l_childname[0])); if (laa.l_childname == NULL) err(5, "DRVLISTDEV"); if (ioctl(fd, DRVLISTDEV, &laa) == -1) err(3, "DRVLISTDEV"); if (laa.l_children > children) err(6, "DRVLISTDEV: number of children grew"); for (i = 0; i < laa.l_children; i++) printf("%s %s\n", laa.l_devname, laa.l_childname[i]); break; case 'r': memset(&raa, 0, sizeof(raa)); strlcpy(raa.busname, argv[0], sizeof(raa.busname)); if (attr) strlcpy(raa.ifattr, attr, sizeof(raa.ifattr)); if (argc > 1) { locs = malloc((argc - 1) * sizeof(int)); if (!locs) err(5, "malloc int[%d]", argc - 1); for (i = 0; i < argc - 1; i++) locs[i] = atoi(argv[i + 1]); raa.numlocators = argc - 1; raa.locators = locs; } if (ioctl(fd, DRVRESCANBUS, &raa) == -1) err(3, "DRVRESCANBUS"); break; case 'p': command_dict = prop_dictionary_create(); args_dict = prop_dictionary_create(); string = prop_string_create_cstring_nocopy("get-properties"); prop_dictionary_set(command_dict, "drvctl-command", string); prop_object_release(string); string = prop_string_create_cstring(argv[0]); prop_dictionary_set(args_dict, "device-name", string); prop_object_release(string); prop_dictionary_set(command_dict, "drvctl-arguments", args_dict); prop_object_release(args_dict); res = prop_dictionary_sendrecv_ioctl(command_dict, fd, DRVCTLCOMMAND, &results_dict); prop_object_release(command_dict); if (res) errx(3, "DRVCTLCOMMAND: %s", strerror(res)); number = prop_dictionary_get(results_dict, "drvctl-error"); if (prop_number_integer_value(number) != 0) { errx(3, "get-properties: %s", strerror((int)prop_number_integer_value(number))); } data_dict = prop_dictionary_get(results_dict, "drvctl-result-data"); if (data_dict == NULL) { errx(3, "get-properties: failed to return result data"); } xml = prop_dictionary_externalize(data_dict); prop_object_release(results_dict); printf("Properties for device `%s':\n%s", argv[0], xml); free(xml); break; default: errx(4, "unknown command"); } return (0); }