Ejemplo n.º 1
0
/** Connect the device to the virtual host controller.
 *
 * @param dev The virtual device to be (virtually) plugged in.
 * @param vhc_path Devman path to the virtual host controller.
 * @return Error code.
 */
int usbvirt_device_plug(usbvirt_device_t *dev, const char *vhc_path)
{
	if (DEV != NULL)
		return ELIMIT;
	
	devman_handle_t handle;
	int rc = devman_fun_get_handle(vhc_path, &handle, 0);
	if (rc != EOK)
		return rc;
	
	async_sess_t *hcd_sess =
	    devman_device_connect(handle, 0);
	if (!hcd_sess)
		return ENOMEM;
	
	DEV = dev;
	dev->vhc_sess = hcd_sess;
	
	async_exch_t *exch = async_exchange_begin(hcd_sess);
	
	port_id_t port;
	rc = async_create_callback_port(exch, INTERFACE_USBVIRT_CB, 0, 0,
	    callback_connection, NULL, &port);
	
	async_exchange_end(exch);
	
	if (rc != EOK)
		DEV = NULL;
	
	return rc;
}
Ejemplo n.º 2
0
/** Register root hub in devman.
 *
 * @param arg Host controller device (type <code>device_t *</code>).
 * @return Error code.
 */
int hub_register_in_devman_fibril(void *arg)
{
	ddf_fun_t *hc_dev = (ddf_fun_t *) arg;

	/*
	 * Wait until parent device is properly initialized.
	 */
	async_sess_t *sess;
	do {
		sess = devman_device_connect(EXCHANGE_SERIALIZE,
		    ddf_fun_get_handle(hc_dev), 0);
	} while (!sess);
	async_hangup(sess);

	int rc;

	usb_hc_connection_t hc_conn;
	usb_hc_connection_initialize(&hc_conn, ddf_fun_get_handle(hc_dev));

	rc = usb_hc_connection_open(&hc_conn);
	assert(rc == EOK);

	ddf_fun_t *hub_dev;
	rc = usb_hc_new_device_wrapper(ddf_fun_get_dev(hc_dev), &hc_conn, USB_SPEED_FULL,
	    pretend_port_rest, NULL, NULL, &rh_ops, hc_dev, &hub_dev);
	if (rc != EOK) {
		usb_log_fatal("Failed to create root hub: %s.\n",
		    str_error(rc));
	}

	usb_hc_connection_close(&hc_conn);

	usb_log_info("Created root hub function (handle %zu).\n",
	    (size_t) ddf_fun_get_handle(hub_dev));

	return 0;
}
Ejemplo n.º 3
0
usb_device_t * usb_device_create(devman_handle_t handle)
{
	devman_handle_t h = 0;
	int iface_no = -1;

	async_sess_t *sess = devman_device_connect(handle, IPC_FLAG_BLOCKING);
	int ret = usb_device_get_info(sess, &h, &iface_no);
	if (sess)
		async_hangup(sess);
	if (ret != EOK)
		return NULL;

	usb_device_t *usb_dev = malloc(sizeof(usb_device_t));
	if (!usb_dev)
		return NULL;

	const char* dummy = NULL;
	ret = usb_device_init(usb_dev, NULL, NULL, &dummy, handle, iface_no);
	if (ret != EOK) {
		free(usb_dev);
		usb_dev = NULL;
	}
	return usb_dev;
}
Ejemplo n.º 4
0
async_sess_t* ahci_get_sess(devman_handle_t funh, char **name)
{
	// FIXME: Use a better way than substring match
	
	*name = NULL;
	
	char devn[MAX_NAME_LENGTH];
	int rc = devman_fun_get_name(funh, devn, MAX_NAME_LENGTH);
	if (rc != EOK)
		return NULL;
	
	size_t devn_size = str_size(devn);
	
	if ((devn_size > 5) && (str_lcmp(devn, "ahci_", 5) == 0)) {
		async_sess_t *sess = devman_device_connect(funh, IPC_FLAG_BLOCKING);
		
		if (sess) {
			*name = str_dup(devn);
			return sess;
		}
	}
	
	return NULL;
}