Example #1
0
static void
fd_set_properties(struct fd_softc *fd)
{
	prop_dictionary_t disk_info, odisk_info, geom;
	const struct fd_type *fdt;
	int secsize;

	fdt = fd->sc_type;
	if (fdt == NULL) {
		fdt = fd->sc_deftype;
		if (fdt == NULL)
			return;
	}

	disk_info = prop_dictionary_create();

	geom = prop_dictionary_create();

	prop_dictionary_set_uint64(geom, "sectors-per-unit",
	    fdt->size);

	switch (fdt->secsize) {
	case 2:
		secsize = 512;
		break;
	case 3:
		secsize = 1024;
		break;
	default:
		secsize = 0;
	}

	prop_dictionary_set_uint32(geom, "sector-size",
	    secsize);

	prop_dictionary_set_uint16(geom, "sectors-per-track",
	    fdt->sectrac);

	prop_dictionary_set_uint16(geom, "tracks-per-cylinder",
	    fdt->heads);

	prop_dictionary_set_uint64(geom, "cylinders-per-unit",
	    fdt->cyls);

	prop_dictionary_set(disk_info, "geometry", geom);
	prop_object_release(geom);

	prop_dictionary_set(device_properties(fd->sc_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.
	 */

	odisk_info = fd->sc_dk.dk_info;
	fd->sc_dk.dk_info = disk_info;
	if (odisk_info)
		prop_object_release(odisk_info);
}
Example #2
0
File: sdp.c Project: ryo/netbsd-src
/*
 * Configure PnP Information results
 */
static int
config_pnp(prop_dictionary_t dict, sdp_data_t *rec)
{
	sdp_data_t value;
	uintmax_t v;
	uint16_t attr;
	int vendor, product, source;

	vendor = -1;
	product = -1;
	source = -1;

	while (sdp_get_attr(rec, &attr, &value)) {
		switch (attr) {
		case 0x0201:	/* Vendor ID */
			if (sdp_get_uint(&value, &v)
			    && v <= UINT16_MAX)
				vendor = (int)v;

			break;

		case 0x0202:	/* Product ID */
			if (sdp_get_uint(&value, &v)
			    && v <= UINT16_MAX)
				product = (int)v;

			break;

		case 0x0205:	/* Vendor ID Source */
			if (sdp_get_uint(&value, &v)
			    && v <= UINT16_MAX)
				source = (int)v;

			break;

		default:
			break;
		}
	}

	if (vendor == -1 || product == -1)
		return ENOATTR;

	if (source != 0x0002)	/* "USB Implementers Forum" */
		return ENOATTR;

	if (!prop_dictionary_set_uint16(dict, BTDEVvendor, (uint16_t)vendor))
		return errno;

	if (!prop_dictionary_set_uint16(dict, BTDEVproduct, (uint16_t)product))
		return errno;

	return 0;
}
Example #3
0
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;
}
Example #4
0
static int
hdaudioctl_get(int fd, int argc, char *argv[])
{
	prop_dictionary_t request, response;
	prop_array_t config;
	uint16_t nid, codecid;
	const char *xml;
	int error;

	if (argc != 2)
		usage();

	codecid = strtol(argv[0], NULL, 0);
	nid = strtol(argv[1], NULL, 0);

	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);

	error = prop_dictionary_sendrecv_ioctl(request, fd,
	    HDAUDIO_FGRP_GETCONFIG, &response);
	if (error != 0) {
		perror("HDAUDIO_FGRP_GETCONFIG failed");
		return error;
	}

	config = prop_dictionary_get(response, "pin-config");
	xml = prop_array_externalize(config);

	printf("%s\n", xml);

	prop_object_release(response);
	prop_object_release(request);

	return 0;
}
Example #5
0
int
npf_nat_setnpt66(nl_nat_t *nt, uint16_t adj)
{
	prop_dictionary_t rldict = nt->nrl_dict;
	int error;

	if ((error = npf_nat_setalgo(nt, NPF_ALGO_NPT66)) != 0) {
		return error;
	}
	prop_dictionary_set_uint16(rldict, "npt66-adjustment", adj);
	return 0;
}
static void
awin_fb_attach(device_t parent, device_t self, void *aux)
{
	struct awin_fb_softc *sc = device_private(self);
	struct awinfb_attach_args * const afb = aux;
	prop_dictionary_t cfg = device_properties(self);
	struct genfb_ops ops;

	if (awin_fb_consoledev == NULL)
		awin_fb_consoledev = self;

	sc->sc_gen.sc_dev = self;
	sc->sc_debedev = parent;
	sc->sc_dmat = afb->afb_dmat;
	sc->sc_dmasegs = afb->afb_dmasegs;
	sc->sc_ndmasegs = afb->afb_ndmasegs;
	sc->sc_mpdev = device_find_by_driver_unit("awinmp", 0);

	prop_dictionary_set_uint32(cfg, "width", afb->afb_width);
	prop_dictionary_set_uint32(cfg, "height", afb->afb_height);
	prop_dictionary_set_uint8(cfg, "depth", 32);
	prop_dictionary_set_uint16(cfg, "linebytes", afb->afb_width * 4);
	prop_dictionary_set_uint32(cfg, "address", 0);
	prop_dictionary_set_uint32(cfg, "virtual_address",
	    (uintptr_t)afb->afb_fb);

	genfb_init(&sc->sc_gen);

	if (sc->sc_gen.sc_width == 0 || sc->sc_gen.sc_fbsize == 0) {
		aprint_normal(": disabled\n");
		return;
	}

	pmf_device_register1(self, NULL, NULL, awin_fb_shutdown);

	memset(&ops, 0, sizeof(ops));
	ops.genfb_ioctl = awin_fb_ioctl;
	ops.genfb_mmap = awin_fb_mmap;

	aprint_naive("\n");

	bool is_console = false;
	prop_dictionary_get_bool(cfg, "is_console", &is_console);

	if (is_console)
		aprint_normal(": switching to framebuffer console\n");
	else
		aprint_normal("\n");

	genfb_attach(&sc->sc_gen, &ops);
}
Example #7
0
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;
}
Example #8
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);
}
Example #9
0
void
device_register(device_t dev, void *aux)
{
#if NPCI > 0
	static bool found_console = false;
	struct pci_attach_args *paa = aux;
#endif

	/*
	 * Handle network interfaces here, the attachment information is
	 * not available driver-independently later.
	 *
	 * For disks, there is nothing useful available at attach time.
	 */
	if (device_class(dev) == DV_IFNET) {
		struct btinfo_netif *bin = lookup_bootinfo(BTINFO_NETIF);
		if (bin == NULL)
			return;

		/*
		 * We don't check the driver name against the device name
		 * passed by the boot ROM.  The ROM should stay usable if
		 * the driver becomes obsolete.  The physical attachment
		 * information (checked below) must be sufficient to
		 * idenfity the device.
		 */
		if (bin->bus == BI_BUS_ISA &&
		    device_is_a(device_parent(dev), "isa")) {
			struct isa_attach_args *iaa = aux;

			/* Compare IO base address */
			/* XXXJRT What about multiple IO addrs? */
			if (iaa->ia_nio > 0 &&
			    bin->addr.iobase == iaa->ia_io[0].ir_addr)
			    	goto found;
		}
#if NPCI > 0
		if (bin->bus == BI_BUS_PCI &&
		    device_is_a(device_parent(dev), "pci")) {
			int b, d, f;

			/*
			 * Calculate BIOS representation of:
			 *
			 *	<bus,device,function>
			 *
			 * and compare.
			 */
			pci_decompose_tag(paa->pa_pc, paa->pa_tag, &b, &d, &f);
			if (bin->addr.tag == ((b << 8) | (d << 3) | f))
				goto found;
		}
#endif /* NPCI > 0 */
	}
#if NISA > 0 && NACPICA > 0
#if notyet
	if (device_is_a(dev, "isa") && acpi_active) {
		if (!(AcpiGbl_FADT.BootFlags & ACPI_FADT_LEGACY_DEVICES))
			prop_dictionary_set_bool(device_properties(dev),
			    "no-legacy-devices", true);
	}
#endif
#endif /* NISA > 0 && NACPICA > 0 */
#if NPCI > 0
	if (device_parent(dev) && device_is_a(device_parent(dev), "pci") &&
	    found_console == false) {
		struct btinfo_framebuffer *fbinfo;
		struct pci_attach_args *pa = aux;
		prop_dictionary_t dict;
#if NACPICA > 0
		struct genfb_parameter_callback *gpc;
		int b, d, f;
#endif

		if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) {
#if NWSDISPLAY > 0 && NGENFB > 0
			extern struct vcons_screen x86_genfb_console_screen;
			struct rasops_info *ri;

			ri = &x86_genfb_console_screen.scr_ri;
#endif

			fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER);
			dict = device_properties(dev);
			/*
			 * framebuffer drivers other than genfb can work
			 * without the address property
			 */
			if (fbinfo != NULL) {
				if (fbinfo->physaddr != 0) {
				prop_dictionary_set_uint32(dict, "width",
				    fbinfo->width);
				prop_dictionary_set_uint32(dict, "height",
				    fbinfo->height);
				prop_dictionary_set_uint8(dict, "depth",
				    fbinfo->depth);
				prop_dictionary_set_uint16(dict, "linebytes",
				    fbinfo->stride);

				prop_dictionary_set_uint64(dict, "address",
				    fbinfo->physaddr);
#if NWSDISPLAY > 0 && NGENFB > 0
				if (ri->ri_bits != NULL) {
					prop_dictionary_set_uint64(dict,
					    "virtual_address",
					    (vaddr_t)ri->ri_bits);
				}
#endif
				}
#if notyet
				prop_dictionary_set_bool(dict, "splash",
				    fbinfo->flags & BI_FB_SPLASH ?
				     true : false);
#endif
				if (fbinfo->depth == 8) {
					gfb_cb.gcc_cookie = NULL;
					gfb_cb.gcc_set_mapreg = 
					    x86_genfb_set_mapreg;
					prop_dictionary_set_uint64(dict,
					    "cmap_callback",
					    (uint64_t)(uintptr_t)&gfb_cb);
				}
				if (fbinfo->physaddr != 0) {
					mode_cb.gmc_setmode = x86_genfb_setmode;
					prop_dictionary_set_uint64(dict,
					    "mode_callback",
					    (uint64_t)(uintptr_t)&mode_cb);
				}

#if NWSDISPLAY > 0 && NGENFB > 0
				if (device_is_a(dev, "genfb")) {
					x86_genfb_set_console_dev(dev);
#ifdef DDB
					db_trap_callback =
					    x86_genfb_ddb_trap_callback;
#endif
				}
#endif
			}
			prop_dictionary_set_bool(dict, "is_console", true);
			prop_dictionary_set_bool(dict, "clear-screen", false);
#if NWSDISPLAY > 0 && NGENFB > 0
			prop_dictionary_set_uint16(dict, "cursor-row",
			    x86_genfb_console_screen.scr_ri.ri_crow);
#endif
#if notyet
			prop_dictionary_set_bool(dict, "splash",
			    fbinfo->flags & BI_FB_SPLASH ? true : false);
#endif
			pmf_cb.gpc_suspend = x86_genfb_suspend;
			pmf_cb.gpc_resume = x86_genfb_resume;
			prop_dictionary_set_uint64(dict,
			    "pmf_callback", (uint64_t)(uintptr_t)&pmf_cb);
#if NACPICA > 0
			pci_decompose_tag(paa->pa_pc, paa->pa_tag, &b, &d, &f);
			gpc = acpidisp_md_out_find(b, d, f);
			if (gpc != NULL)
				prop_dictionary_set_uint64(dict,
				    "brightness_callback", (uint64_t)(vaddr_t)gpc);
#endif
#ifdef VGA_POST
			vga_posth = vga_post_init(pa->pa_bus, pa->pa_device,
			    pa->pa_function);
#endif
			found_console = true;
			return;
		}
	}
#endif
	return;

 found:
	if (booted_device) {
		/* XXX should be a panic() */
		printf("WARNING: double match for boot device (%s, %s)\n",
		    device_xname(booted_device), device_xname(dev));
		return;
	}
	booted_device = dev;
}
Example #10
0
int
drmfb_attach(struct drmfb_softc *sc, const struct drmfb_attach_args *da)
{
	const struct drm_fb_helper_surface_size *const sizes = da->da_fb_sizes;
	const prop_dictionary_t dict = device_properties(da->da_dev);
#if NVGA > 0
	struct drm_device *const dev = da->da_fb_helper->dev;
#endif
	static const struct genfb_ops zero_genfb_ops;
	struct genfb_ops genfb_ops = zero_genfb_ops;
	enum { CONS_VGA, CONS_GENFB, CONS_NONE } what_was_cons;
	int error;

	/* genfb requires this.  */
	KASSERTMSG((void *)&sc->sc_genfb == device_private(da->da_dev),
	    "drmfb_softc must be first member of device softc");

	sc->sc_da = *da;

	prop_dictionary_set_uint32(dict, "width", sizes->surface_width);
	prop_dictionary_set_uint32(dict, "height", sizes->surface_height);
	prop_dictionary_set_uint8(dict, "depth", sizes->surface_bpp);
	prop_dictionary_set_uint16(dict, "linebytes",
	    roundup2((sizes->surface_width * howmany(sizes->surface_bpp, 8)),
		64));
	prop_dictionary_set_uint32(dict, "address", 0); /* XXX >32-bit */
	CTASSERT(sizeof(uintptr_t) <= sizeof(uint64_t));
	prop_dictionary_set_uint64(dict, "virtual_address",
	    (uint64_t)(uintptr_t)da->da_fb_vaddr);

	prop_dictionary_set_uint64(dict, "mode_callback",
	    (uint64_t)(uintptr_t)&drmfb_genfb_mode_callback);

	/* XXX Whattakludge!  */
#if NVGA > 0
	if ((da->da_params->dp_is_vga_console != NULL) &&
	    (*da->da_params->dp_is_vga_console)(dev)) {
		what_was_cons = CONS_VGA;
		prop_dictionary_set_bool(dict, "is_console", true);
		vga_cndetach();
		if (da->da_params->dp_disable_vga)
			(*da->da_params->dp_disable_vga)(dev);
	} else
#endif
	if (genfb_is_console() && genfb_is_enabled()) {
		what_was_cons = CONS_GENFB;
		prop_dictionary_set_bool(dict, "is_console", true);
	} else {
		what_was_cons = CONS_NONE;
		prop_dictionary_set_bool(dict, "is_console", false);
	}

	sc->sc_genfb.sc_dev = sc->sc_da.da_dev;
	genfb_init(&sc->sc_genfb);
	genfb_ops.genfb_ioctl = drmfb_genfb_ioctl;
	genfb_ops.genfb_mmap = drmfb_genfb_mmap;
	genfb_ops.genfb_enable_polling = drmfb_genfb_enable_polling;
	genfb_ops.genfb_disable_polling = drmfb_genfb_disable_polling;

	error = genfb_attach(&sc->sc_genfb, &genfb_ops);
	if (error) {
		aprint_error_dev(sc->sc_da.da_dev,
		    "failed to attach genfb: %d\n", error);
		goto fail0;
	}

	/* Success!  */
	return 0;

fail0:	KASSERT(error);
	/* XXX Restore console...  */
	switch (what_was_cons) {
	case CONS_VGA:
		break;
	case CONS_GENFB:
		break;
	case CONS_NONE:
		break;
	default:
		break;
	}
	return error;
}