Esempio n. 1
0
static int
ncv_pccard_probe(device_t dev)
{
	const struct ncv_product *pp;
	const char *vendorstr;
	const char *prodstr;

	if ((pp = (const struct ncv_product *) pccard_product_lookup(dev, 
	    (const struct pccard_product *) ncv_products,
	    sizeof(ncv_products[0]), NULL)) != NULL) {
		if (pp->prod.pp_name != NULL)
			device_set_desc(dev, pp->prod.pp_name);
		device_set_flags(dev, pp->flags);
		return(0);
	}
	if (pccard_get_vendor_str(dev, &vendorstr))
		return(EIO);
	if (pccard_get_product_str(dev, &prodstr))
		return(EIO);
	if (strcmp(vendorstr, "RATOC System Inc.") == 0 &&
		strncmp(prodstr, "SOUND/SCSI2 CARD", 16) == 0) {
		device_set_desc(dev, "RATOC REX-5572");
		device_set_flags(dev, FLAGS_REX5572);
		return (BUS_PROBE_DEFAULT);
	}
	return(EIO);
}
Esempio n. 2
0
void device_leave_promiscuous_mode(const char *ifname, short oldflags)
{
	if (!strncmp("any", ifname, strlen("any")))
		return;

	device_set_flags(ifname, oldflags);
}
Esempio n. 3
0
static int
vga_pci_probe(device_t dev)
{
	device_t bdev;
	int unit;
	uint16_t bctl;

	switch (pci_get_class(dev)) {
	case PCIC_DISPLAY:
		break;
	case PCIC_OLD:
		if (pci_get_subclass(dev) != PCIS_OLD_VGA)
			return (ENXIO);
		break;
	default:
		return (ENXIO);
	}

	/* Probe default display. */
	unit = device_get_unit(dev);
	bdev = device_get_parent(device_get_parent(dev));
	bctl = pci_read_config(bdev, PCIR_BRIDGECTL_1, 2);
	if (vga_pci_default_unit < 0 && (bctl & PCIB_BCR_VGA_ENABLE) != 0)
		vga_pci_default_unit = unit;
	if (vga_pci_default_unit == unit)
		device_set_flags(dev, 1);

	device_set_desc(dev, "VGA-compatible display");
	return (BUS_PROBE_GENERIC);
}
Esempio n. 4
0
int tun_open_or_die(char *name, int type)
{
	int fd, ret;
	short flags;
	struct ifreq ifr;

	if (!name)
		panic("No name provided for tundev!\n");

	fd = open_or_die("/dev/net/tun", O_RDWR);

	memset(&ifr, 0, sizeof(ifr));
	ifr.ifr_flags = type;
	strlcpy(ifr.ifr_name, name, IFNAMSIZ);

	ret = ioctl(fd, TUNSETIFF, &ifr);
	if (ret < 0)
		panic("ioctl screwed up! %s.\n", strerror(errno));

	ret = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
	if (ret < 0)
		panic("fctnl screwed up! %s.\n", strerror(errno));

	flags = device_get_flags(name);
	flags |= IFF_UP | IFF_RUNNING;
	device_set_flags(name, flags);

	return fd;
}
Esempio n. 5
0
void enter_rfmon_mac80211(const char *device, char **mondev)
{
	int ret;
	short flags;
	uint32_t n;
	char phydev_path[256];
	struct nl80211_state nlstate;

	/* XXX: is this already a monN device? */
	get_mac80211_phydev(device, phydev_path, sizeof(phydev_path));
	nl80211_init(&nlstate, device);

	for (n = 0; n < UINT_MAX; n++) {
		char mondevice[32];

		slprintf(mondevice, sizeof(mondevice), "mon%u", n);
		ret = nl80211_add_mon_if(&nlstate, device, mondevice);
		if (ret == 0) {
			*mondev = xstrdup(mondevice);

			flags = device_get_flags(*mondev);
			flags |= IFF_UP | IFF_RUNNING;
			device_set_flags(*mondev, flags);

			nl80211_cleanup(&nlstate);
			return;
		}
	}

	panic("No free monN interfaces!\n");
}
Esempio n. 6
0
short enter_promiscuous_mode(char *ifname)
{
    if (!strncmp("any", ifname, strlen("any")))
        return 0;
    short ifflags = device_get_flags(ifname);
    device_set_flags(ifname, ifflags | IFF_PROMISC);
    return ifflags;
}
Esempio n. 7
0
int
vga_pci_is_boot_display(device_t dev)
{
	int unit;
	device_t pcib;
	uint16_t config;

	/* Check that the given device is a video card */
	if ((pci_get_class(dev) != PCIC_DISPLAY &&
	    (pci_get_class(dev) != PCIC_OLD ||
	     pci_get_subclass(dev) != PCIS_OLD_VGA)))
		return (0);

	unit = device_get_unit(dev);

	if (vga_pci_default_unit >= 0) {
		/*
		 * The boot display device was determined by a previous
		 * call to this function, or the user forced it using
		 * the hw.pci.default_vgapci_unit tunable.
		 */
		return (vga_pci_default_unit == unit);
	}

	/*
	 * The primary video card used as a boot display must have the
	 * "I/O" and "Memory Address Space Decoding" bits set in its
	 * Command register.
	 *
	 * Furthermore, if the card is attached to a bridge, instead of
	 * the root PCI bus, the bridge must have the "VGA Enable" bit
	 * set in its Control register.
	 */

	pcib = device_get_parent(device_get_parent(dev));
	if (device_get_devclass(device_get_parent(pcib)) ==
	    devclass_find("pci")) {
		/*
		 * The parent bridge is a PCI-to-PCI bridge: check the
		 * value of the "VGA Enable" bit.
		 */
		config = pci_read_config(pcib, PCIR_BRIDGECTL_1, 2);
		if ((config & PCIB_BCR_VGA_ENABLE) == 0)
			return (0);
	}

	config = pci_read_config(dev, PCIR_COMMAND, 2);
	if ((config & (PCIM_CMD_PORTEN | PCIM_CMD_MEMEN)) == 0)
		return (0);

	/* This video card is the boot display: record its unit number. */
	vga_pci_default_unit = unit;
	device_set_flags(dev, 1);

	return (1);
}
Esempio n. 8
0
static int
ct_isa_match(device_t dev)
{
	struct bshw *hw;
	struct resource *port_res, *mem_res;
	struct ct_bus_access_handle ch;
	int rv;

	if (ISA_PNP_PROBE(device_get_parent(dev), dev, ct_pnp_ids) == ENXIO)
		return ENXIO;

	switch (isa_get_logicalid(dev)) {
	case 0x0100e7b1:	/* LHA-301 */
	case 0x110154dc:	/* SC-98III */
	case 0x4120acb4:	/* IFC-NN */
		/* XXX - force to SMIT mode */
		device_set_flags(dev, device_get_flags(dev) | 0x40000);
		break;
	}

	if (isa_get_port(dev) == -1)
		bus_set_resource(dev, SYS_RES_IOPORT, 0,
				 BSHW_IOBASE, BSHW_IOSZ);

	if ((hw = ct_find_hw(dev)) == NULL)
		return ENXIO;
	if (ct_space_map(dev, hw, &port_res, &mem_res) != 0)
		return ENXIO;

	bzero(&ch, sizeof(ch));
	ch.ch_iot = rman_get_bustag(port_res);
	ch.ch_ioh = rman_get_bushandle(port_res),
	ch.ch_bus_weight = ct_isa_bus_access_weight;

	rv = ctprobesubr(&ch, 0, BSHW_DEFAULT_HOSTID,
			 BSHW_DEFAULT_CHIPCLK, NULL);
	if (rv != 0)
	{
		struct bshw_softc bshw_tab;
		struct bshw_softc *bs = &bshw_tab;

		memset(bs, 0, sizeof(*bs));
		bshw_read_settings(&ch, bs);
		bus_set_resource(dev, SYS_RES_IRQ, 0, bs->sc_irq, 1);
		bus_set_resource(dev, SYS_RES_DRQ, 0, bs->sc_drq, 1);
	}

	bus_release_resource(dev, SYS_RES_IOPORT, 0, port_res);
	if (mem_res != NULL)
		bus_release_resource(dev, SYS_RES_MEMORY, 0, mem_res);

	if (rv != 0)
		return 0;
	return ENXIO;
}
Esempio n. 9
0
void leave_rfmon_mac80211(const char *device, const char *mondev)
{
	short flags;
	struct nl80211_state nlstate;

	flags = device_get_flags(mondev);
	flags &= ~(IFF_UP | IFF_RUNNING);
	device_set_flags(mondev, flags);

	nl80211_init(&nlstate, device);
	nl80211_del_mon_if(&nlstate, device, mondev);
	nl80211_cleanup(&nlstate);
}
Esempio n. 10
0
static void
isahint_add_device(device_t parent, const char *name, int unit)
{
	device_t	child;
	int		sensitive, start, count, t;
	int		order;

	/* device-specific flag overrides any wildcard */
	sensitive = 0;
	if (resource_int_value(name, unit, "sensitive", &sensitive) != 0)
		resource_int_value(name, -1, "sensitive", &sensitive);

	if (sensitive)
		order = ISA_ORDER_SENSITIVE;
	else
		order = ISA_ORDER_SPECULATIVE;

	child = BUS_ADD_CHILD(parent, parent, order, name, unit);
	if (child == 0)
		return;

	start = 0;
	count = 0;
	resource_int_value(name, unit, "port", &start);
	resource_int_value(name, unit, "portsize", &count);
	if (start > 0 || count > 0)
		bus_set_resource(child, SYS_RES_IOPORT, 0, start, count, -1);

	start = 0;
	count = 0;
	resource_int_value(name, unit, "maddr", &start);
	resource_int_value(name, unit, "msize", &count);
	if (start > 0 || count > 0)
		bus_set_resource(child, SYS_RES_MEMORY, 0, start, count, -1);

	if (resource_int_value(name, unit, "irq", &start) == 0 && start > 0) {
		bus_set_resource(child, SYS_RES_IRQ, 0, start, 1,
		    machintr_legacy_intr_cpuid(start));
	}

	if (resource_int_value(name, unit, "drq", &start) == 0 && start >= 0)
		bus_set_resource(child, SYS_RES_DRQ, 0, start, 1, -1);

	if (resource_int_value(name, unit, "flags", &t) == 0)
		device_set_flags(child, t);

	if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
		device_disable(child);
}
Esempio n. 11
0
static int
fdc_pccard_attach(device_t dev)
{
	int error;
	struct	fdc_data *fdc;
	device_t child;

	fdc = device_get_softc(dev);
	fdc->flags = FDC_NODMA | FDC_NOFAST;
	fdc->fdct = FDC_NE765;
	error = fdc_pccard_alloc_resources(dev, fdc);
	if (error == 0)
		error = fdc_attach(dev);
	if (error == 0) {
		child = fdc_add_child(dev, "fd", -1);
		device_set_flags(child, 0x24);
		error = bus_generic_attach(dev);
	}
	if (error)
		fdc_release_resources(fdc);
	return (error);
}