Пример #1
0
/**
 * xenbus_grant_ring
 * @dev: xenbus device
 * @ring_mfn: mfn of ring to grant

 * Grant access to the given @ring_mfn to the peer of the given device.  Return
 * 0 on success, or -errno on error.  On error, the device will switch to
 * XenbusStateClosing, and the error will be saved in the store.
 */
int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn)
{
	int err = gnttab_grant_foreign_access(dev->otherend_id, ring_mfn, 0);
	if (err < 0)
		xenbus_dev_fatal(dev, err, "granting access to ring page");
	return err;
}
Пример #2
0
int net_accel_grant_page(struct xenbus_device *dev, unsigned long mfn,
                         int is_iomem)
{
    int err = gnttab_grant_foreign_access(dev->otherend_id, mfn,
                                          is_iomem ? GTF_PCD : 0);
    if (err < 0)
        xenbus_dev_error(dev, err, "failed granting access to page\n");
    return err;
}
Пример #3
0
int
xenbus_grant_ring(device_t dev, unsigned long ring_mfn, grant_ref_t *refp)
{
	int error;

	error = gnttab_grant_foreign_access(
		xenbus_get_otherend_id(dev), ring_mfn, 0, refp);
	if (error) {
		xenbus_dev_fatal(dev, error, "granting access to ring page");
		return (error);
	}

	return (0);
}
Пример #4
0
int gnt_init(void)
{
	int mfn;
	int err;
	struct as_sring *sring;

	struct evtchn_alloc_unbound alloc_unbound;
	printk(KERN_INFO "gnt_init\n");

	page =  __get_free_pages(GFP_KERNEL, 0);
	if (page == 0) {
		printk(KERN_DEBUG "\nxen:DomU:could not get free page");
		return 0;
	}

	sring = (struct as_sring *)page;
	SHARED_RING_INIT(sring);
	FRONT_RING_INIT(&(info.ring), sring, PAGE_SIZE);
	mfn = virt_to_mfn(page);

	printk(KERN_INFO "grant foreign access\n");
	info.gref = gnttab_grant_foreign_access(DOM0_ID, mfn, 0);
	if (info.gref < 0) {
		printk(KERN_DEBUG "\nxen:could not grant foreign access");
		free_page((unsigned long)page);
		info.ring.sring = NULL;
		return 0;
	}
	printk(KERN_DEBUG "\n gref = %d", info.gref);
	alloc_unbound.dom = DOMID_SELF;
	alloc_unbound.remote_dom = DOM0_ID;
	err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &alloc_unbound);
	if (err) {
		printk(KERN_DEBUG "\nalloc unbound port failure");
		return err;
	}

	err = bind_evtchn_to_irqhandler(alloc_unbound.port, as_int, 0, "xen-eg", &info);
	if (err < 0) {
		printk(KERN_DEBUG "\nbind evtchn to irqhandler failure");
		return err;
	}

	info.irq = err;
	info.port = alloc_unbound.port;
	printk(KERN_DEBUG " interrupt = %d, local_port = %d", info.irq, info.port);
	printk("...\n...");
	create_procfs_entry();
	return 0;
}
Пример #5
0
int xenbus_conn(domid_t remote_dom, unsigned long *grant_ref, evtchn_port_t *local_port)
{
	struct evtchn_alloc_unbound alloc_unbound;
	int rc, rc2;

	BUG_ON(atomic_read(&xenbus_xsd_state) != XENBUS_XSD_FOREIGN_INIT);
	BUG_ON(!is_initial_xendomain());

#if defined(CONFIG_PROC_FS) && defined(CONFIG_XEN_PRIVILEGED_GUEST)
	remove_xen_proc_entry("xsd_kva");
	remove_xen_proc_entry("xsd_port");
#endif

	rc = xb_free_port(xen_store_evtchn);
	if (rc != 0)
		goto fail0;

	alloc_unbound.dom = DOMID_SELF;
	alloc_unbound.remote_dom = remote_dom;
	rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
	                                 &alloc_unbound);
	if (rc != 0)
		goto fail0;
	*local_port = xen_store_evtchn = alloc_unbound.port;

	/* keep the old page (xen_store_mfn, xen_store_interface) */
	rc = gnttab_grant_foreign_access(remote_dom, xen_store_mfn,
	                                 GTF_permit_access);
	if (rc < 0)
		goto fail1;
	*grant_ref = rc;

	rc = xb_init_comms();
	if (rc != 0)
		goto fail1;

	return 0;

fail1:
	rc2 = xb_free_port(xen_store_evtchn);
	if (rc2 != 0)
		printk(KERN_WARNING
		       "XENBUS: Error freeing xenstore event channel: %d\n",
		       rc2);
fail0:
	xen_store_evtchn = -1;
	return rc;
}
static int xenkbd_connect_backend(struct xenbus_device *dev,
				  struct xenkbd_info *info)
{
	int ret, evtchn;
	struct xenbus_transaction xbt;

	ret = gnttab_grant_foreign_access(dev->otherend_id,
	                                  virt_to_mfn(info->page), 0);
	if (ret < 0)
		return ret;
	info->gref = ret;

	ret = xenbus_alloc_evtchn(dev, &evtchn);
	if (ret)
		goto error_grant;
	ret = bind_evtchn_to_irqhandler(evtchn, input_handler,
					0, dev->devicetype, info);
	if (ret < 0) {
		xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
		goto error_evtchan;
	}
	info->irq = ret;

 again:
	ret = xenbus_transaction_start(&xbt);
	if (ret) {
		xenbus_dev_fatal(dev, ret, "starting transaction");
		goto error_irqh;
	}
	ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu",
			    virt_to_mfn(info->page));
	if (ret)
		goto error_xenbus;
	ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
	if (ret)
		goto error_xenbus;
	ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u",
			    evtchn);
	if (ret)
		goto error_xenbus;
	ret = xenbus_transaction_end(xbt, 0);
	if (ret) {
		if (ret == -EAGAIN)
			goto again;
		xenbus_dev_fatal(dev, ret, "completing transaction");
		goto error_irqh;
	}

	xenbus_switch_state(dev, XenbusStateInitialised);
	return 0;

 error_xenbus:
	xenbus_transaction_end(xbt, 1);
	xenbus_dev_fatal(dev, ret, "writing xenstore");
 error_irqh:
	unbind_from_irqhandler(info->irq, info);
	info->irq = -1;
 error_evtchan:
	xenbus_free_evtchn(dev, evtchn);
 error_grant:
	gnttab_end_foreign_access_ref(info->gref, 0);
	info->gref = -1;
	return ret;
}
Пример #7
0
/**
 * Connect the OpenXT input device to the corresponding backend.
 *
 * @param dev The device to be connected.
 * @param info The information structure that corresponds to the given device.
 *
 * @return int Zero on success, or an error code on failure.
 */
static int oxtkbd_connect_backend(struct xenbus_device *dev,
                  struct openxt_kbd_info *info)
{
    int ret, evtchn;
    struct xenbus_transaction xbt;

    //To communicate with the backend, we'll share a single page of memory
    //We'll start this process by granting out our "shared page".
    ret = gnttab_grant_foreign_access(dev->otherend_id, virt_to_mfn(info->page), 0);
    if (ret < 0)
        return ret;

    info->gref = ret;

    //Next, we'll need to create an event channel we can use to signal that data
    //has changed in our shared page.
    ret = xenbus_alloc_evtchn(dev, &evtchn);
    if (ret)
        goto error_grant;

    //Bind our input handler to our event channel-- ensuring we're recieve any
    //"new data" notifications.
    ret = bind_evtchn_to_irqhandler(evtchn, input_handler, 0, dev->devicetype, info);
    if (ret < 0) {
        xenbus_dev_fatal(dev, ret, "bind_evtchn_to_irqhandler");
        goto error_evtchan;
    }

    info->irq = ret;

 again:

    //Now that we've set up our shared assets, we'll need to communicate them
    //to the backend. First, we'll start a xenbus transaction, so we can dump
    //all of our data into the XenStore simultaneously.
    ret = xenbus_transaction_start(&xbt);
    if (ret) {
        xenbus_dev_fatal(dev, ret, "starting transaction");
        goto error_irqh;
    }

    //Provide a direct reference to the page. This allows backends that want
    //to use foreign mappings (i.e. legacy backends) to map in the shared page
    //without touching grants.
    ret = xenbus_printf(xbt, dev->nodename, "page-ref", "%lu", virt_to_mfn(info->page));
    if (ret)
        goto error_xenbus;

    //And provide our grant reference. This is the preferred way of getting the
    //shared page.
    ret = xenbus_printf(xbt, dev->nodename, "page-gref", "%u", info->gref);
    if (ret)
        goto error_xenbus;

    //Provide the number for our event channel, so the backend can signal
    //new informatino to us.
    ret = xenbus_printf(xbt, dev->nodename, "event-channel", "%u", evtchn);
    if (ret)
        goto error_xenbus;

    //Attempt to apply all of our changes at once.
    ret = xenbus_transaction_end(xbt, 0);

    //If our transaction failed...
    if (ret) {

        //... it may have been because the XenStore was busy. If this is the case,
        //repeat out transaction until we succeed, or hit an error.
        if (ret == -EAGAIN)
            goto again;

        //Otherwise, we couldn't connect. Bail out!
        xenbus_dev_fatal(dev, ret, "completing transaction");
        goto error_irqh;
    }

    //Finally, switch our state to "intialized", hopefully cueing the backend
    //to connect.
    xenbus_switch_state(dev, XenbusStateInitialised);
    return 0;

 error_xenbus:
    xenbus_transaction_end(xbt, 1);
    xenbus_dev_fatal(dev, ret, "writing xenstore");
 error_irqh:
    unbind_from_irqhandler(info->irq, info);
    info->irq = -1;
 error_evtchan:
    xenbus_free_evtchn(dev, evtchn);
 error_grant:
    gnttab_end_foreign_access(info->gref, 0, 0UL);
    info->gref = -1;
    return ret;
}