Example #1
0
int
ep_alloc(device_t dev)
{
	struct ep_softc	*	sc = device_get_softc(dev);
	int			rid;
	int			error = 0;

        rid = 0;
        sc->iobase = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
	    RF_ACTIVE);
        if (!sc->iobase) {
                device_printf(dev, "No I/O space?!\n");
		error = ENXIO;
                goto bad;
        }

        rid = 0;
        sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
        if (!sc->irq) {
                device_printf(dev, "No irq?!\n");
		error = ENXIO;
                goto bad;
        }

	if_initname(&sc->arpcom.ac_if,
		    device_get_name(dev), device_get_unit(dev));
        sc->stat = 0;   /* 16 bit access */

        sc->ep_io_addr = rman_get_start(sc->iobase);

        sc->ep_btag = rman_get_bustag(sc->iobase);
        sc->ep_bhandle = rman_get_bushandle(sc->iobase);

	sc->ep_connectors = 0;
	sc->ep_connector = 0;

        GO_WINDOW(0);
	sc->epb.cmd_off = 0;
	sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID);
	sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);

bad:
	return (error);
}
Example #2
0
static void init_uinput(struct avctp *session)
{
	char address[18], name[248 + 1];

	device_get_name(session->device, name, sizeof(name));
	if (g_str_equal(name, "Nokia CK-20W")) {
		session->key_quirks[AVC_FORWARD] |= QUIRK_NO_RELEASE;
		session->key_quirks[AVC_BACKWARD] |= QUIRK_NO_RELEASE;
		session->key_quirks[AVC_PLAY] |= QUIRK_NO_RELEASE;
		session->key_quirks[AVC_PAUSE] |= QUIRK_NO_RELEASE;
	}

	ba2str(device_get_address(session->device), address);
	session->uinput = uinput_create(address);
	if (session->uinput < 0)
		error("AVRCP: failed to init uinput for %s", address);
	else
		DBG("AVRCP: uinput initialized for %s", address);
}
Example #3
0
static int
uninorth_enable_config(struct uninorth_softc *sc, u_int bus, u_int slot,
    u_int func, u_int reg)
{
	uint32_t	cfgval;
	uint32_t	pass;

	if (resource_int_value(device_get_name(sc->pci_sc.sc_dev),
	        device_get_unit(sc->pci_sc.sc_dev), "skipslot", &pass) == 0) {
		if (pass == slot)
			return (0);
	}

	/*
	 * Issue type 0 configuration space accesses for the root bus.
	 *
	 * NOTE: On U4, issue only type 1 accesses. There is a secret
	 * PCI Express <-> PCI Express bridge not present in the device tree,
	 * and we need to route all of our configuration space through it.
	 */
	if (sc->pci_sc.sc_bus == bus && sc->sc_ver < 4) {
		/*
		 * No slots less than 11 on the primary bus on U3 and lower
		 */
		if (slot < 11)
			return (0);

		cfgval = (1 << slot) | (func << 8) | (reg & 0xfc);
	} else {
		cfgval = (bus << 16) | (slot << 11) | (func << 8) |
		    (reg & 0xfc) | 1;
	}

	/* Set extended register bits on U4 */
	if (sc->sc_ver == 4)
		cfgval |= (reg >> 8) << 28;

	do {
		out32rb(sc->sc_addr, cfgval);
	} while (in32rb(sc->sc_addr) != cfgval);

	return (1);
}
Example #4
0
static int 
sfxge_ifnet_init(struct ifnet *ifp, struct sfxge_softc *sc)
{
	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sc->enp);
	device_t dev;
	int rc;

	dev = sc->dev;
	sc->ifnet = ifp;

	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	ifp->if_init = sfxge_if_init;
	ifp->if_softc = sc;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_ioctl = sfxge_if_ioctl;

	ifp->if_capabilities = SFXGE_CAP;
	ifp->if_capenable = SFXGE_CAP_ENABLE;
	ifp->if_hwassist = CSUM_TCP | CSUM_UDP | CSUM_IP | CSUM_TSO;

	ether_ifattach(ifp, encp->enc_mac_addr);

#ifdef SFXGE_HAVE_MQ
	ifp->if_transmit = sfxge_if_transmit;
	ifp->if_qflush = sfxge_if_qflush;
#else
	ifp->if_start = sfxge_if_start;
	IFQ_SET_MAXLEN(&ifp->if_snd, SFXGE_NDESCS - 1);
	ifp->if_snd.ifq_drv_maxlen = SFXGE_NDESCS - 1;
	IFQ_SET_READY(&ifp->if_snd);

	mtx_init(&sc->tx_lock, "txq", NULL, MTX_DEF);
#endif

	if ((rc = sfxge_port_ifmedia_init(sc)) != 0)
		goto fail;

	return 0;

fail:
	ether_ifdetach(sc->ifnet);
	return rc;
}
Example #5
0
/*
 * Attach btcoex to the given interface
 */
int
ath_btcoex_attach(struct ath_softc *sc)
{
	int ret;
	struct ath_hal *ah = sc->sc_ah;
	const char *profname;

	/*
	 * No chipset bluetooth coexistence? Then do nothing.
	 */
	if (! ath_hal_btcoex_supported(ah))
		return (0);

	/*
	 * Look at the hints to determine which bluetooth
	 * profile to configure.
	 */
	ret = resource_string_value(device_get_name(sc->sc_dev),
	    device_get_unit(sc->sc_dev),
	    "btcoex_profile",
	    &profname);
	if (ret != 0) {
		/* nothing to do */
		return (0);
	}

	if (strncmp(profname, "wb195", 5) == 0) {
		ret = ath_btcoex_cfg_wb195(sc);
	} else if (strncmp(profname, "wb225", 5) == 0) {
		ret = ath_btcoex_cfg_wb225(sc);
	} else {
		return (0);
	}

	/*
	 * Propagate up failure from the actual attach phase.
	 */
	if (ret != 0)
		return (ret);

	return (0);
}
Example #6
0
/*
 * Create a calibration block from memory mapped SPI data for use by
 * various drivers.  Right now it's just ath(4) but later board support
 * will include 802.11ac NICs with calibration data in NOR flash.
 *
 * (Yes, there are a handful of QCA MIPS boards with QCA9880v2 802.11ac chips
 * with calibration data in flash..)
 */
static void
ar71xx_platform_create_cal_data(device_t dev, int id, long int flash_addr,
    int size)
{
	char buf[64];
	uint16_t *cal_data = (uint16_t *) MIPS_PHYS_TO_KSEG1(flash_addr);
	void *eeprom = NULL;
	const struct firmware *fw = NULL;

	device_printf(dev, "EEPROM firmware: 0x%lx @ %d bytes\n",
	    flash_addr, size);

	eeprom = malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
	if (! eeprom) {
		device_printf(dev, "%s: malloc failed for '%s', aborting EEPROM\n",
		__func__, buf);
		return;
	}

	memcpy(eeprom, cal_data, size);

	/*
	 * Generate a flash EEPROM 'firmware' from the given memory
	 * region.  Since the SPI controller will eventually
	 * go into port-IO mode instead of memory-mapped IO
	 * mode, a copy of the EEPROM contents is required.
	 */

	snprintf(buf, sizeof(buf), "%s.%d.map.%d.eeprom_firmware",
	    device_get_name(dev),
	    device_get_unit(dev),
	    id);

	fw = firmware_register(buf, eeprom, size, 1, NULL);
	if (fw == NULL) {
		device_printf(dev, "%s: firmware_register (%s) failed\n",
		    __func__, buf);
		free(eeprom, M_DEVBUF);
		return;
	}
	device_printf(dev, "device EEPROM '%s' registered\n", buf);
}
Example #7
0
static int
ahci_attach (device_t dev)
{
	struct ahci_softc *sc = device_get_softc(dev);
	char name[16];
	int error;

	sc->sc_ad = ahci_lookup_device(dev);
	if (sc->sc_ad == NULL)
		return(ENXIO);

	/*
	 * Some chipsets do not properly implement the AHCI spec and may
	 * require the link speed to be specifically requested.
	 */
	if (kgetenv("hint.ahci.force150"))
		AhciForceGen = 1;
	if (kgetenv("hint.ahci.force300"))
		AhciForceGen = 2;
	if (kgetenv("hint.ahci.force600"))
		AhciForceGen = 3;

	if (kgetenv("hint.ahci.nofeatures"))
		AhciNoFeatures = -1;

	if (kgetenv("hint.ahci.forcefbss"))
		sc->sc_flags |= AHCI_F_FORCE_FBSS;

	sysctl_ctx_init(&sc->sysctl_ctx);
	ksnprintf(name, sizeof(name), "%s%d",
		device_get_name(dev), device_get_unit(dev));
	sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
				SYSCTL_STATIC_CHILDREN(_hw),
				OID_AUTO, name, CTLFLAG_RD, 0, "");

	error = sc->sc_ad->ad_attach(dev);
	if (error) {
		sysctl_ctx_free(&sc->sysctl_ctx);
		sc->sysctl_tree = NULL;
	}
	return (error);
}
Example #8
0
static void
sfxge_mcdi_exception(void *arg, efx_mcdi_exception_t eme)
{
	struct sfxge_softc *sc;
	device_t dev;

	sc = (struct sfxge_softc *)arg;
	dev = sc->dev;

	log(LOG_WARNING, "[%s%d] MC_%s", device_get_name(dev),
	    device_get_unit(dev),
	    (eme == EFX_MCDI_EXCEPTION_MC_REBOOT)
	    ? "REBOOT"
	    : (eme == EFX_MCDI_EXCEPTION_MC_BADASSERT)
	    ? "BADASSERT" : "UNKNOWN");

	EFSYS_PROBE(mcdi_exception);

	sfxge_schedule_reset(sc);
}
Example #9
0
static void
chipc_probe_nomatch(device_t dev, device_t child)
{
	struct resource_list	*rl;
	const char		*name;

	name = device_get_name(child);
	if (name == NULL)
		name = "unknown device";

	device_printf(dev, "<%s> at", name);

	rl = BUS_GET_RESOURCE_LIST(dev, child);
	if (rl != NULL) {
		resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#jx");
		resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%jd");
	}

	printf(" (no driver attached)\n");
}
Example #10
0
static int
rlphy_probe(device_t dev)
{
	const char *nic;
	int rv;

	rv = mii_phy_dev_probe(dev, rlphys, BUS_PROBE_DEFAULT);
#ifdef __HAIKU__
	if (rv == BUS_PROBE_DEFAULT)
		return (rv);
#else
	if (rv <= 0)
		return (rv);
#endif		

	nic = device_get_name(device_get_parent(device_get_parent(dev)));
	if (strcmp(nic, "rl") == 0 || strcmp(nic, "re") == 0)
		return (mii_phy_dev_probe(dev, rlintphys, BUS_PROBE_DEFAULT));
	return (ENXIO);
}
Example #11
0
static int
i80321_dma_attach(device_t dev)
{
	struct i80321_dma_softc *softc = device_get_softc(dev);
	struct i80321_softc *sc = device_get_softc(device_get_parent(dev));
	int unit = device_get_unit(dev);
	i80321_dmadesc_t *dmadescs;

	mtx_init(&softc->mtx, "DMA engine mtx", NULL, MTX_SPIN);
	softc->sc_st = sc->sc_st;
	if (bus_space_subregion(softc->sc_st, sc->sc_sh, unit == 0 ?
	    VERDE_DMA_BASE0 : VERDE_DMA_BASE1, VERDE_DMA_SIZE, 
	    &softc->sc_dma_sh) != 0)
		panic("%s: unable to subregion DMA registers",
		    device_get_name(dev));
	if (bus_dma_tag_create(NULL, sizeof(i80321_dmadesc_t),
	    0, BUS_SPACE_MAXADDR,  BUS_SPACE_MAXADDR, NULL, NULL, 
	    DMA_RING_SIZE * sizeof(i80321_dmadesc_t), 1, 
	    sizeof(i80321_dmadesc_t), BUS_DMA_ALLOCNOW, busdma_lock_mutex,
	    &Giant, &softc->dmatag))
		panic("Couldn't create a dma tag");
	DMA_REG_WRITE(softc, 0, 0);
	if (bus_dmamem_alloc(softc->dmatag, (void **)&dmadescs,
    	    BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &softc->dmaring[0].map))
		panic("Couldn't alloc dma memory");
	for (int i = 0; i < DMA_RING_SIZE; i++) {
		if (i > 0)
			if (bus_dmamap_create(softc->dmatag, 0, 
			    &softc->dmaring[i].map))
				panic("Couldn't alloc dmamap");
		softc->dmaring[i].desc = &dmadescs[i];	
		bus_dmamap_load(softc->dmatag, softc->dmaring[i].map,
		    softc->dmaring[i].desc, sizeof(i80321_dmadesc_t),
		    i80321_mapphys, &softc->dmaring[i].phys_addr, 0);
	}
	softc->unit = unit;
	softcs[unit] = softc;
	_arm_memcpy = dma_memcpy;
	_min_memcpy_size = 1024;
	return (0);
}
Example #12
0
static gboolean
confirm_request (DBusGMethodInvocation *context,
		 DBusGProxy *device,
		 guint pin,
		 gpointer user_data)
{
	DBusGProxy *adapter = user_data;
	char *name, *long_name, *line, *text;

	name = device_get_name (device, &long_name);
	if (name == NULL)
		return FALSE;

	text = g_strdup_printf("%d", pin);
	confirm_dialog(adapter, device, name, long_name, text, context);
	g_free(text);

	g_free (long_name);

	/* translators: this is a popup telling you a particular device
	 * has asked for pairing */
	line = g_strdup_printf(_("Pairing confirmation for '%s'"), name);

	g_free(name);

	/* translators:
	 * This message is for Bluetooth 2.1 support, when the
	 * action is clicked in the notification popup, the user
	 * will get to check whether the PIN matches the one
	 * showing on the Bluetooth device */
	if (notification_supports_actions () != FALSE)
		show_notification(_("Bluetooth device"),
				    line, _("Verify PIN"), 0,
				    G_CALLBACK(notification_closed));
	else
		present_notification_dialogs ();

	g_free(line);

	return TRUE;
}
Example #13
0
static void init_uinput(struct control *control)
{
	struct audio_device *dev = control->dev;
	char address[18], name[248 + 1];

	device_get_name(dev->btd_dev, name, sizeof(name));
	if (g_str_equal(name, "Nokia CK-20W")) {
		control->key_quirks[FORWARD_OP] |= QUIRK_NO_RELEASE;
		control->key_quirks[BACKWARD_OP] |= QUIRK_NO_RELEASE;
		control->key_quirks[PLAY_OP] |= QUIRK_NO_RELEASE;
		control->key_quirks[PAUSE_OP] |= QUIRK_NO_RELEASE;
	}

	ba2str(&dev->dst, address);

	control->uinput = uinput_create(address);
	if (control->uinput < 0)
		error("AVRCP: failed to init uinput for %s", address);
	else
		debug("AVRCP: uinput initialized for %s", address);
}
Example #14
0
static struct resource *
nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
    u_long start, u_long end, u_long count, u_int flags)
{
	struct resource *rv;
	struct rman *rm;
	size_t i;

	switch (type) {
	case SYS_RES_MEMORY:
		rm = &mem_rman;
		break;
	case SYS_RES_IRQ:
		rm = &irq_rman;
		break;
	default:
		return (NULL);
	}

	for (i = 0; i < rtems_bsd_nexus_device_count; ++i) {
		const rtems_bsd_device *nd = &rtems_bsd_nexus_devices[i];

		if (strcmp(device_get_name(child), nd->name) == 0
		    && device_get_unit(child) == nd->unit) {
			if (!nexus_get_start(nd, type, &start)) {
				return (NULL);
			};
		} else {
			return (NULL);
		}
	}

	rv = rman_reserve_resource(rm, start, end, count, flags, child);
	if (rv != NULL) {
		rman_set_rid(rv, *rid);
		rman_set_bushandle(rv, rman_get_start(rv));
	}

	return (rv);
}
Example #15
0
/*
 * We add all the devices which we know about.
 * The generic attach routine will attach them if they are alive.
 */
static int
iicbus_attach(device_t dev)
{
#if SCAN_IICBUS
	unsigned char addr;
#endif
	struct iicbus_softc *sc = IICBUS_SOFTC(dev);
	int strict;

	sc->dev = dev;
	mtx_init(&sc->lock, "iicbus", NULL, MTX_DEF);
	iicbus_init_frequency(dev, 0);
	iicbus_reset(dev, IIC_FASTEST, 0, NULL);
	if (resource_int_value(device_get_name(dev),
		device_get_unit(dev), "strict", &strict) == 0)
		sc->strict = strict;
	else
		sc->strict = 1;

	/* device probing is meaningless since the bus is supposed to be
	 * hot-plug. Moreover, some I2C chips do not appreciate random
	 * accesses like stop after start to fast, reads for less than
	 * x bytes...
	 */
#if SCAN_IICBUS
	printf("Probing for devices on iicbus%d:", device_get_unit(dev));

	/* probe any devices */
	for (addr = 16; addr < 240; addr++) {
		if (iic_probe_device(dev, (u_char)addr)) {
			printf(" <%x>", addr);
		}
	}
	printf("\n");
#endif
	bus_generic_probe(dev);
	bus_enumerate_hinted_children(dev);
	bus_generic_attach(dev);
        return (0);
}
Example #16
0
static int
ipmi_smbus_attach(device_t dev)
{
	struct ipmi_softc *sc = device_get_softc(dev);
	struct ipmi_get_info info;
	int error;

	/* This should never fail. */
	if (!ipmi_smbios_identify(&info))
		return (ENXIO);

	if (info.iface_type != SSIF_MODE) {
		device_printf(dev, "No SSIF IPMI interface found\n");
		return (ENXIO);
	}

	sc->ipmi_dev = dev;

	if (info.irq != 0) {
		sc->ipmi_irq_rid = 0;
		sc->ipmi_irq_res = bus_alloc_resource(dev, SYS_RES_IRQ,
		    &sc->ipmi_irq_rid, info.irq, info.irq, 1,
		    RF_SHAREABLE | RF_ACTIVE);
	}

	device_printf(dev, "SSIF mode found at address 0x%llx on %s\n",
	    (long long)info.address, device_get_name(device_get_parent(dev)));
	error = ipmi_ssif_attach(sc, device_get_parent(dev), info.address);
	if (error)
		goto bad;

	error = ipmi_attach(dev);
	if (error)
		goto bad;

	return (0);
bad:
	ipmi_release_resources(dev);
	return (error);
}
Example #17
0
static int
ata_pcichannel_attach(device_t dev)
{
    struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
    struct ata_channel *ch = device_get_softc(dev);
    int error;

    if (ch->attached)
	return (0);
    ch->attached = 1;

    ch->dev = dev;
    ch->unit = (intptr_t)device_get_ivars(dev);

    resource_int_value(device_get_name(dev),
	device_get_unit(dev), "pm_level", &ch->pm_level);

    if ((error = ctlr->ch_attach(dev)))
	return error;

    return ata_attach(dev);
}
Example #18
0
static int
i80321_aau_attach(device_t dev)
{
	struct i80321_aau_softc *softc = device_get_softc(dev);
	struct i80321_softc *sc = device_get_softc(device_get_parent(dev));
	struct i80321_aaudesc_s *aaudescs;

	mtx_init(&softc->mtx, "AAU mtx", NULL, MTX_SPIN);
	softc->sc_st = sc->sc_st;
	if (bus_space_subregion(softc->sc_st, sc->sc_sh, VERDE_AAU_BASE,
	    VERDE_AAU_SIZE, &softc->sc_aau_sh) != 0)
		panic("%s: unable to subregion AAU registers",
		    device_get_name(dev));
	if (bus_dma_tag_create(NULL, sizeof(i80321_aaudesc_t), 0,
	    BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL,
	    AAU_RING_SIZE * sizeof(i80321_aaudesc_t),
	    1, sizeof(i80321_aaudesc_t), BUS_DMA_ALLOCNOW, busdma_lock_mutex,
	    &Giant, &softc->dmatag))
		panic("Couldn't create a dma tag");
	if (bus_dmamem_alloc(softc->dmatag, (void **)&aaudescs,
    	    BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &softc->aauring[0].map))
		panic("Couldn't alloc dma memory");

	for (int i = 0; i < AAU_RING_SIZE; i++) {
		if (i > 0)
			if (bus_dmamap_create(softc->dmatag, 0,
			    &softc->aauring[i].map))
				panic("Couldn't create dma map");
		softc->aauring[i].desc = &aaudescs[i];
		bus_dmamap_load(softc->dmatag, softc->aauring[i].map,
		    softc->aauring[i].desc, sizeof(i80321_aaudesc_t),
		    i80321_mapphys, &softc->aauring[i].phys_addr, 0);
		bzero(softc->aauring[i].desc, sizeof(i80321_aaudesc_t));
	}
	aau_softc = softc;
	_arm_bzero = aau_bzero;
	_min_bzero_size = 1024;
	return (0);
}
static struct hog_device *hog_device_new(struct btd_device *device,
        struct gatt_primary *prim)
{
    struct hog_device *dev;
    char name[248];
    uint16_t vendor, product, version;

    if (device_name_known(device))
        device_get_name(device, name, sizeof(name));
    else
        strcpy(name, "bluez-hog-device");

    vendor = btd_device_get_vendor(device);
    product = btd_device_get_product(device);
    version = btd_device_get_version(device);

    DBG("name=%s vendor=0x%X, product=0x%X, version=0x%X", name, vendor,
        product, version);

    dev = new0(struct hog_device, 1);
    dev->device = btd_device_ref(device);
    dev->hog = bt_hog_new_default(name, vendor, product, version, prim);

    /*
     * TODO: Remove attio callback and use .accept once using
     * bt_gatt_client.
     */
    dev->attioid = btd_device_add_attio_callback(device,
                   attio_connected_cb,
                   attio_disconnected_cb,
                   dev);

    if (!devices)
        devices = queue_new();

    queue_push_tail(devices, dev);

    return dev;
}
Example #20
0
static int
saost_attach(device_t dev)
{
	struct saost_softc *sc = device_get_softc(dev);
	struct sa11x0_softc *sa = device_get_softc(device_get_parent(dev));

	sc->sc_dev = dev;
	sc->sc_iot = sa->sc_iot;
	sc->sc_baseaddr = 0x90000000;

	saost_sc = sc;

	if(bus_space_map(sa->sc_iot, sc->sc_baseaddr, 8, 0, 
			&sc->sc_ioh))
		panic("%s: Cannot map registers", device_get_name(dev));

	/* disable all channel and clear interrupt status */
	bus_space_write_4(saost_sc->sc_iot, saost_sc->sc_ioh, SAOST_IR, 0);
	bus_space_write_4(saost_sc->sc_iot, saost_sc->sc_ioh, SAOST_SR, 0xf);
	return (0);

}
Example #21
0
static void
gst_osx_video_src_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstOSXVideoSrc *src = GST_OSX_VIDEO_SRC (object);

  switch (prop_id) {
    case ARG_DEVICE:
      if (!src->device_id)
        device_set_default (src);
      g_value_set_string (value, src->device_id);
      break;
    case ARG_DEVICE_NAME:
      if (!src->device_name)
        device_get_name (src);
      g_value_set_string (value, src->device_name);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Example #22
0
void
XX_PortalSetInfo(device_t dev)
{
	char *dev_name;
	struct dpaa_portals_softc *sc;
	int i, type, len;

	dev_name = malloc(sizeof(*dev_name), M_TEMP, M_WAITOK |
	    M_ZERO);

	len = strlen("bman-portals");

	strncpy(dev_name, device_get_name(dev), len);

	if (strncmp(dev_name, "bman-portals", len) && strncmp(dev_name,
	    "qman-portals", len))
		goto end;

	if (strncmp(dev_name, "bman-portals", len) == 0)
		type = BM_PORTAL;
	else
		type = QM_PORTAL;

	sc = device_get_softc(dev);

	for (i = 0; sc->sc_dp[i].dp_ce_pa != 0; i++) {
		XX_PInfo.portal_ce_pa[type][i] = sc->sc_dp[i].dp_ce_pa;
		XX_PInfo.portal_ci_pa[type][i] = sc->sc_dp[i].dp_ci_pa;
		XX_PInfo.portal_ce_size[type][i] = sc->sc_dp[i].dp_ce_size;
		XX_PInfo.portal_ci_size[type][i] = sc->sc_dp[i].dp_ci_size;
		XX_PInfo.portal_intr[type][i] = sc->sc_dp[i].dp_intr_num;
	}

	XX_PInfo.portal_ce_va[type] = rman_get_bushandle(sc->sc_rres[0]);
	XX_PInfo.portal_ci_va[type] = rman_get_bushandle(sc->sc_rres[1]);
end:
	free(dev_name, M_TEMP);
}
Example #23
0
static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
						char *pinbuf, bool *display,
						unsigned int attempt)
{
	uint16_t vendor, product;
	char addr[18], name[25];
	unsigned int i;

	/* Only try the pin code once per device. If it's not correct then it's
	 * an unknown device. */
	if (attempt > 1)
		return 0;

	ba2str(device_get_address(device), addr);

	vendor = btd_device_get_vendor(device);
	product = btd_device_get_product(device);

	device_get_name(device, name, sizeof(name));
	name[sizeof(name) - 1] = 0;

	for (i = 0; i < G_N_ELEMENTS(wii_ids); ++i) {
		if (vendor == wii_ids[i][0] && product == wii_ids[i][1])
			goto found;
	}

	for (i = 0; i < G_N_ELEMENTS(wii_names); ++i) {
		if (g_str_equal(name, wii_names[i]))
			goto found;
	}

	return 0;

found:
	DBG("Forcing fixed pin on detected wiimote %s", addr);
	memcpy(pinbuf, adapter_get_address(adapter), 6);
	return 6;
}
Example #24
0
/*
 * If we negotiate a 10Mbps mode, we need to check for an alternate
 * PHY and make sure it's enabled and set correctly.
 */
static void
mlphy_status(struct mii_softc *sc)
{
	struct mlphy_softc	*msc = (struct mlphy_softc *)sc;
	struct mii_data		*mii = msc->ml_mii.mii_pdata;
	struct mii_softc	*other = NULL;
	device_t		*devlist;
	int			devs, i;

	/* See if there's another PHY on the bus with us. */
	device_get_children(msc->ml_mii.mii_dev, &devlist, &devs);
	for (i = 0; i < devs; i++) {
		if (strcmp(device_get_name(devlist[i]), "mlphy")) {
			other = device_get_softc(devlist[i]);
			break;
		}
	}
	kfree(devlist, M_TEMP);

	if (other == NULL)
		return;

	ukphy_status(sc);

	if (IFM_SUBTYPE(mii->mii_media_active) != IFM_10_T) {
		msc->ml_state = ML_STATE_AUTO_SELF;
		mii_phy_reset(other);
		PHY_WRITE(other, MII_BMCR, BMCR_ISO);
	}

	if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T) {
		msc->ml_state = ML_STATE_AUTO_OTHER;
		mlphy_reset(&msc->ml_mii);
		PHY_WRITE(&msc->ml_mii, MII_BMCR, BMCR_ISO);
		mii_phy_reset(other);
		mii_phy_auto(other, 1);
	}
}
Example #25
0
static void init_uinput(struct avctp *session)
{
	struct audio_device *dev;
	char address[18], name[248 + 1];

	dev = manager_get_device(&session->server->src, &session->dst, FALSE);

	device_get_name(dev->btd_dev, name, sizeof(name));
	if (g_str_equal(name, "Nokia CK-20W")) {
		session->key_quirks[FORWARD_OP] |= QUIRK_NO_RELEASE;
		session->key_quirks[BACKWARD_OP] |= QUIRK_NO_RELEASE;
		session->key_quirks[PLAY_OP] |= QUIRK_NO_RELEASE;
		session->key_quirks[PAUSE_OP] |= QUIRK_NO_RELEASE;
	}

	ba2str(&session->dst, address);

	session->uinput = uinput_create(address);
	if (session->uinput < 0)
		error("AVRCP: failed to init uinput for %s", address);
	else
		DBG("AVRCP: uinput initialized for %s", address);
}
Example #26
0
static int
gpioled_attach(device_t dev)
{
	struct gpioled_softc *sc;
#ifdef FDT
	phandle_t node;
	char *name;
#else
	const char *name;
#endif

	sc = device_get_softc(dev);
	sc->sc_dev = dev;
	sc->sc_busdev = device_get_parent(dev);
	GPIOLED_LOCK_INIT(sc);
#ifdef FDT
	name = NULL;
	if ((node = ofw_bus_get_node(dev)) == -1)
		return (ENXIO);
	if (OF_getprop_alloc(node, "label", 1, (void **)&name) == -1)
		OF_getprop_alloc(node, "name", 1, (void **)&name);
#else
	if (resource_string_value(device_get_name(dev), 
	    device_get_unit(dev), "name", &name))
		name = NULL;
#endif

	sc->sc_leddev = led_create(gpioled_control, sc, name ? name :
	    device_get_nameunit(dev));
#ifdef FDT
	if (name != NULL)
		free(name, M_OFWPROP);
#endif

	return (0);
}
Example #27
0
static int
gx_attach(device_t dev)
{
	struct ifnet *ifp;
	struct gx_softc *sc;
	uint8_t mac[6];
	int error;
	int rid;

	sc = device_get_softc(dev);
	sc->sc_dev = dev;
	sc->sc_port = device_get_unit(dev);

	/* Read MAC address.  */
	GXEMUL_ETHER_DEV_WRITE(GXEMUL_ETHER_DEV_MAC, (uintptr_t)mac);

	/* Allocate and establish interrupt.  */
	rid = 0;
	sc->sc_intr = bus_alloc_resource(sc->sc_dev, SYS_RES_IRQ, &rid,
	    GXEMUL_ETHER_DEV_IRQ - 2, GXEMUL_ETHER_DEV_IRQ - 2, 1, RF_ACTIVE);
	if (sc->sc_intr == NULL) {
		device_printf(dev, "unable to allocate IRQ.\n");
		return (ENXIO);
	}

	error = bus_setup_intr(sc->sc_dev, sc->sc_intr, INTR_TYPE_NET, NULL,
	    gx_rx_intr, sc, &sc->sc_intr_cookie);
	if (error != 0) {
		device_printf(dev, "unable to setup interrupt.\n");
		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr);
		return (ENXIO);
	}

	bus_describe_intr(sc->sc_dev, sc->sc_intr, sc->sc_intr_cookie, "rx");

	ifp = if_alloc(IFT_ETHER);
	if (ifp == NULL) {
		device_printf(dev, "cannot allocate ifnet.\n");
		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr);
		return (ENOMEM);
	}

	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	ifp->if_mtu = ETHERMTU;
	ifp->if_init = gx_init;
	ifp->if_softc = sc;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST | IFF_ALLMULTI;
	ifp->if_ioctl = gx_ioctl;

	sc->sc_ifp = ifp;
	sc->sc_flags = ifp->if_flags;

	ifmedia_init(&sc->sc_ifmedia, 0, gx_medchange, gx_medstat);

	ifmedia_add(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO, 0, NULL);
	ifmedia_set(&sc->sc_ifmedia, IFM_ETHER | IFM_AUTO);

	mtx_init(&sc->sc_mtx, "GXemul Ethernet", NULL, MTX_DEF);

	ether_ifattach(ifp, mac);

	ifp->if_transmit = gx_transmit;

	return (bus_generic_attach(dev));
}
Example #28
0
static int
ohci_ec_attach(device_t dev)
{
	struct ec_ohci_softc *sc = device_get_softc(dev);
	bus_space_handle_t bsh;
	int err;
	int rid;

	/* initialise some bus fields */
	sc->sc_ohci.sc_bus.parent = dev;
	sc->sc_ohci.sc_bus.devices = sc->sc_ohci.sc_devices;
	sc->sc_ohci.sc_bus.devices_max = OHCI_MAX_DEVICES;

	/* get all DMA memory */
	if (usb_bus_mem_alloc_all(&sc->sc_ohci.sc_bus,
	    USB_GET_DMA_TAG(dev), &ohci_iterate_hw_softc)) {
		return (ENOMEM);
	}
	sc->sc_ohci.sc_dev = dev;

	rid = MEM_RID;

	sc->sc_ohci.sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
	    &rid, RF_ACTIVE);

	if (!(sc->sc_ohci.sc_io_res)) {
		err = ENOMEM;
		goto error;
	}
	sc->sc_ohci.sc_io_tag = rman_get_bustag(sc->sc_ohci.sc_io_res);
	bsh = rman_get_bushandle(sc->sc_ohci.sc_io_res);
	/* Undocumented magic initialization */
	bus_space_write_4((sc)->sc_ohci.sc_io_tag, bsh,0x04, 0x146);

	bus_space_write_4((sc)->sc_ohci.sc_io_tag, bsh,0x44, 0x0200);

	DELAY(1000);

	sc->sc_ohci.sc_io_size = rman_get_size(sc->sc_ohci.sc_io_res);

	if (bus_space_subregion(sc->sc_ohci.sc_io_tag, bsh, 0x4000000,
	    sc->sc_ohci.sc_io_size, &sc->sc_ohci.sc_io_hdl) != 0)
		panic("%s: unable to subregion USB host registers",
		    device_get_name(dev));

	rid = 0;
	sc->sc_ohci.sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
	    RF_ACTIVE);
	if (!(sc->sc_ohci.sc_irq_res)) {
		goto error;
	}
	sc->sc_ohci.sc_bus.bdev = device_add_child(dev, "usbus", -1);
	if (!(sc->sc_ohci.sc_bus.bdev)) {
		goto error;
	}
	device_set_ivars(sc->sc_ohci.sc_bus.bdev, &sc->sc_ohci.sc_bus);

	strlcpy(sc->sc_ohci.sc_vendor, "Cavium",
		sizeof(sc->sc_ohci.sc_vendor));

#if (__FreeBSD_version >= 700031)
	err = bus_setup_intr(dev, sc->sc_ohci.sc_irq_res,
	    INTR_TYPE_BIO | INTR_MPSAFE,  NULL,
	    (driver_intr_t *)ohci_interrupt, sc,
	    &sc->sc_ohci.sc_intr_hdl);
#else
	err = bus_setup_intr(dev, sc->sc_ohci.sc_irq_res,
	    INTR_TYPE_BIO | INTR_MPSAFE,
	    (driver_intr_t *)ohci_interrupt, sc,
	    &sc->sc_ohci.sc_intr_hdl);
#endif
	if (err) {
		sc->sc_ohci.sc_intr_hdl = NULL;
		goto error;
	}

	bus_space_write_4(sc->sc_ohci.sc_io_tag, sc->sc_ohci.sc_io_hdl,
	    OHCI_CONTROL, 0);

	err = ohci_init(&sc->sc_ohci);
	if (!err) {
		err = device_probe_and_attach(sc->sc_ohci.sc_bus.bdev);
	}
	if (err) {
		goto error;
	}
	return (0);

error:
	ohci_ec_detach(dev);
	return (ENXIO);
}
Example #29
0
/*
 * Attach the interface.
 */
static int
lgue_attach(device_t dev)
{
	struct lgue_softc *sc;
	struct usb_attach_arg *uaa;
	struct ifnet *ifp;
	usb_interface_descriptor_t *id;
	usb_endpoint_descriptor_t *ed;
	int i;
	u_char eaddr[ETHER_ADDR_LEN];
	usbd_status err;

	sc = device_get_softc(dev);
	uaa = device_get_ivars(dev);

	sc->lgue_ctl_iface = uaa->iface;
	sc->lgue_udev = uaa->device;

	/* It has only config but in case... */
	if (usbd_set_config_no(sc->lgue_udev, LGUE_CONFIG_NO, 0)) {
		device_printf(dev, "setting config no %d failed\n",
		    LGUE_CONFIG_NO);
		return(ENXIO);
	}

	/* Get control and data intefaces */
	id = usbd_get_interface_descriptor(uaa->iface);
	sc->lgue_ctl_iface_no = id->bInterfaceNumber;
	sc->lgue_data_iface_no = lgue_get_data_iface_no(sc->lgue_udev, id);

	if (sc->lgue_data_iface_no == -1) {
		device_printf(dev, "no data interface number\n");
		goto bad;
	}

	/* Claim data interface */
	for (i = 0; i < uaa->nifaces; ++i) {
		if (uaa->ifaces[i] != NULL) {
			id = usbd_get_interface_descriptor(uaa->ifaces[i]);
			if (id != NULL &&
			    id->bInterfaceNumber == sc->lgue_data_iface_no) {
				err = usbd_set_interface(uaa->ifaces[i],
				    LGUE_ALTERNATE_SETTING);
				if ( err != USBD_NORMAL_COMPLETION) {
					device_printf(dev,
					    "no alternate data interface. err:%s\n",
					    usbd_errstr(err));
					goto bad;
				}
				sc->lgue_data_iface = uaa->ifaces[i];
				uaa->ifaces[i] = NULL;
			}
		}
	}
	if (sc->lgue_data_iface == NULL) {
		device_printf(dev, "no data interface\n");
		goto bad;
	}

	/* Find data interface endpoints */
	id = usbd_get_interface_descriptor(sc->lgue_data_iface);
	sc->lgue_ed[LGUE_ENDPT_RX] = sc->lgue_ed[LGUE_ENDPT_TX] = -1;
	for (i = 0; i < id->bNumEndpoints; ++i) {
		ed = usbd_interface2endpoint_descriptor(sc->lgue_data_iface, i);
		if (!ed) {
			device_printf(dev,
			    "couldn't get endpoint descriptor %d\n", i);
			goto bad;
		}
		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
				UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
			sc->lgue_ed[LGUE_ENDPT_RX] = ed->bEndpointAddress;
		} else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
			sc->lgue_ed[LGUE_ENDPT_TX] = ed->bEndpointAddress;
		}
	}

	if (sc->lgue_ed[LGUE_ENDPT_RX] == -1) {
		device_printf(dev, "couldn't find data bilk in\n");
		goto bad;
	}
	if (sc->lgue_ed[LGUE_ENDPT_TX] == -1) {
		device_printf(dev, "couldn't find data bilk out\n");
		goto bad;
	}

	/* Find control interface endpoint */
	id = usbd_get_interface_descriptor(sc->lgue_ctl_iface);
	sc->lgue_ed[LGUE_ENDPT_INTR] = -1;
	for (i = 0; i < id->bNumEndpoints; ++i) {
		ed = usbd_interface2endpoint_descriptor(sc->lgue_ctl_iface, i);
		if (!ed) {
			device_printf(dev,
			    "couldn't get endpoint descriptor %d\n", i);
			goto bad;
		}
		if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
		    UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) {
			sc->lgue_ed[LGUE_ENDPT_INTR] = ed->bEndpointAddress;
		}
	}

	if (sc->lgue_ed[LGUE_ENDPT_INTR] == -1) {
		device_printf(dev, "couldn't find interrupt bilk in\n");
		goto bad;
	}

	/* Create interface */
	ifp = &sc->lgue_arpcom.ac_if;
	ifp->if_softc = sc;
	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
	lgue_getmac(sc, eaddr);

	ifp->if_mtu = lgue_getmtu(sc);
	ifp->if_data.ifi_mtu = ifp->if_mtu;
	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
	ifp->if_baudrate = 10000000;
	ifp->if_ioctl = lgue_ioctl;
	ifp->if_start = lgue_start;
	ifp->if_watchdog = lgue_watchdog;
	ifp->if_init = lgue_init;
	ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN);
	ifq_set_ready(&ifp->if_snd);

	/* Call attach routine */
	ether_ifattach(ifp, eaddr, NULL);
	usb_register_netisr();
	sc->lgue_dying = 0;
	return(0);

bad:
	return(ENXIO);
}
Example #30
0
int
ata_attach(device_t dev)
{
    struct ata_channel *ch = device_get_softc(dev);
    int error, rid;
    struct cam_devq *devq;
    const char *res;
    char buf[64];
    int i, mode;

    /* check that we have a virgin channel to attach */
    if (ch->r_irq)
	return EEXIST;

    /* initialize the softc basics */
    ch->dev = dev;
    ch->state = ATA_IDLE;
    bzero(&ch->state_mtx, sizeof(struct mtx));
    mtx_init(&ch->state_mtx, "ATA state lock", NULL, MTX_DEF);
    TASK_INIT(&ch->conntask, 0, ata_conn_event, dev);
	for (i = 0; i < 16; i++) {
		ch->user[i].revision = 0;
		snprintf(buf, sizeof(buf), "dev%d.sata_rev", i);
		if (resource_int_value(device_get_name(dev),
		    device_get_unit(dev), buf, &mode) != 0 &&
		    resource_int_value(device_get_name(dev),
		    device_get_unit(dev), "sata_rev", &mode) != 0)
			mode = -1;
		if (mode >= 0)
			ch->user[i].revision = mode;
		ch->user[i].mode = 0;
		snprintf(buf, sizeof(buf), "dev%d.mode", i);
		if (resource_string_value(device_get_name(dev),
		    device_get_unit(dev), buf, &res) == 0)
			mode = ata_str2mode(res);
		else if (resource_string_value(device_get_name(dev),
		    device_get_unit(dev), "mode", &res) == 0)
			mode = ata_str2mode(res);
		else
			mode = -1;
		if (mode >= 0)
			ch->user[i].mode = mode;
		if (ch->flags & ATA_SATA)
			ch->user[i].bytecount = 8192;
		else
			ch->user[i].bytecount = MAXPHYS;
		ch->user[i].caps = 0;
		ch->curr[i] = ch->user[i];
		if (ch->flags & ATA_SATA) {
			if (ch->pm_level > 0)
				ch->user[i].caps |= CTS_SATA_CAPS_H_PMREQ;
			if (ch->pm_level > 1)
				ch->user[i].caps |= CTS_SATA_CAPS_D_PMREQ;
		} else {
			if (!(ch->flags & ATA_NO_48BIT_DMA))
				ch->user[i].caps |= CTS_ATA_CAPS_H_DMA48;
		}
	}
	callout_init(&ch->poll_callout, 1);

    /* allocate DMA resources if DMA HW present*/
    if (ch->dma.alloc)
	ch->dma.alloc(dev);

    /* setup interrupt delivery */
    rid = ATA_IRQ_RID;
    ch->r_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
				       RF_SHAREABLE | RF_ACTIVE);
    if (!ch->r_irq) {
	device_printf(dev, "unable to allocate interrupt\n");
	return ENXIO;
    }
    if ((error = bus_setup_intr(dev, ch->r_irq, ATA_INTR_FLAGS, NULL,
				ata_interrupt, ch, &ch->ih))) {
	bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq);
	device_printf(dev, "unable to setup interrupt\n");
	return error;
    }

	if (ch->flags & ATA_PERIODIC_POLL)
		callout_reset(&ch->poll_callout, hz, ata_periodic_poll, ch);
	mtx_lock(&ch->state_mtx);
	/* Create the device queue for our SIM. */
	devq = cam_simq_alloc(1);
	if (devq == NULL) {
		device_printf(dev, "Unable to allocate simq\n");
		error = ENOMEM;
		goto err1;
	}
	/* Construct SIM entry */
	ch->sim = cam_sim_alloc(ataaction, atapoll, "ata", ch,
	    device_get_unit(dev), &ch->state_mtx, 1, 0, devq);
	if (ch->sim == NULL) {
		device_printf(dev, "unable to allocate sim\n");
		cam_simq_free(devq);
		error = ENOMEM;
		goto err1;
	}
	if (xpt_bus_register(ch->sim, dev, 0) != CAM_SUCCESS) {
		device_printf(dev, "unable to register xpt bus\n");
		error = ENXIO;
		goto err2;
	}
	if (xpt_create_path(&ch->path, /*periph*/NULL, cam_sim_path(ch->sim),
	    CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
		device_printf(dev, "unable to create path\n");
		error = ENXIO;
		goto err3;
	}
	mtx_unlock(&ch->state_mtx);
	return (0);

err3:
	xpt_bus_deregister(cam_sim_path(ch->sim));
err2:
	cam_sim_free(ch->sim, /*free_devq*/TRUE);
	ch->sim = NULL;
err1:
	bus_release_resource(dev, SYS_RES_IRQ, rid, ch->r_irq);
	mtx_unlock(&ch->state_mtx);
	if (ch->flags & ATA_PERIODIC_POLL)
		callout_drain(&ch->poll_callout);
	return (error);
}