socsvn commit: r324095 - in soc2017/vaibhav/head/sys: dev/xen/grant_table x86/x86 x86/xen xen
vaibhav at FreeBSD.org
vaibhav at FreeBSD.org
Thu Jun 29 20:26:13 UTC 2017
Author: vaibhav
Date: Thu Jun 29 20:26:09 2017
New Revision: 324095
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=324095
Log:
Submitted by: Vaibhav Gautam
Modified:
soc2017/vaibhav/head/sys/dev/xen/grant_table/grant_table.c
soc2017/vaibhav/head/sys/x86/x86/busdma_bounce.c
soc2017/vaibhav/head/sys/x86/xen/xenpv.c
soc2017/vaibhav/head/sys/xen/gnttab.h
Modified: soc2017/vaibhav/head/sys/dev/xen/grant_table/grant_table.c
==============================================================================
--- soc2017/vaibhav/head/sys/dev/xen/grant_table/grant_table.c Thu Jun 29 19:43:27 2017 (r324094)
+++ soc2017/vaibhav/head/sys/dev/xen/grant_table/grant_table.c Thu Jun 29 20:26:09 2017 (r324095)
@@ -132,6 +132,17 @@
mtx_unlock(&gnttab_list_lock);
}
+int
+gnttab_next_reference(grant_ref_t *gref_head)
+{
+ grant_ref_t g = *gref_head;
+
+ if (__predict_false(g == GNTTAB_LIST_END))
+ return (g);
+
+ return (gnttab_entry(g));
+}
+
/*
* Public grant-issuing interface functions
*/
@@ -630,7 +641,7 @@
* \return On success, 0. Otherwise an errno value indicating the
* type of failure.
*/
-static int
+int
granttable_attach(device_t dev)
{
int i;
Modified: soc2017/vaibhav/head/sys/x86/x86/busdma_bounce.c
==============================================================================
--- soc2017/vaibhav/head/sys/x86/x86/busdma_bounce.c Thu Jun 29 19:43:27 2017 (r324094)
+++ soc2017/vaibhav/head/sys/x86/x86/busdma_bounce.c Thu Jun 29 20:26:09 2017 (r324095)
@@ -52,6 +52,7 @@
#include <machine/md_var.h>
#include <machine/specialreg.h>
#include <x86/include/busdma_impl.h>
+#include <xen/gnttab.h>
#ifdef __i386__
#define MAX_BPAGES 512
@@ -114,6 +115,11 @@
SYSCTL_INT(_hw_busdma, OID_AUTO, total_bpages, CTLFLAG_RD, &total_bpages, 0,
"Total bounce pages");
+struct xen_gntmap {
+ grant_ref_t gm_ref;
+ vm_paddr_t gm_paddr;
+};
+
struct bus_dmamap {
struct bp_list bpages;
int pagesneeded;
@@ -123,6 +129,7 @@
bus_dmamap_callback_t *callback;
void *callback_arg;
STAILQ_ENTRY(bus_dmamap) links;
+ struct xen_gntmap *gm_map;
};
static STAILQ_HEAD(, bus_dmamap) bounce_map_waitinglist;
@@ -148,6 +155,7 @@
static int _bus_dmamap_reserve_pages(bus_dma_tag_t dmat, bus_dmamap_t map,
int flags);
+//int gnttab_alloc_grant_references (uint16_t count, grant_ref_t *head);
/*
* Allocate a device specific dma_tag.
*/
@@ -260,7 +268,10 @@
bounce_bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
{
struct bounce_zone *bz;
- int error, maxpages, pages;
+ int error, maxpages, pages, i = 0;
+ u_int nsegs;
+ grant_ref_t gm_ref;
+ struct xen_gntmap *gm_map;
error = 0;
@@ -330,6 +341,19 @@
}
if (error == 0)
dmat->map_count++;
+
+ /* Claim references from the grant table */
+ nsegs = dmat->common.nsegments;
+ (*mapp)->gm_map = gm_map = (struct xen_gntmap *) malloc (sizeof (struct xen_gntmap) * nsegs, M_DEVBUF, flags);
+
+ if (gnttab_alloc_grant_references (nsegs, &gm_ref))
+ return (ENOMEM);
+
+ for (i = 0; i < nsegs; i++) {
+ gm_map[i].gm_ref = gm_ref;
+ gm_ref = gnttab_next_reference (&gm_ref);
+ }
+
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
__func__, dmat, dmat->common.flags, error);
return (error);
@@ -666,7 +690,11 @@
{
bus_size_t sgsize;
bus_addr_t curaddr;
- int error;
+ int error, i = 0;
+ u_int nsegs;
+ grant_ref_t gm_ref;
+ struct xen_gntmap *gm_map;
+ vm_paddr_t buffer;
if (map == NULL)
map = &nobounce_dmamap;
@@ -700,6 +728,20 @@
buf += sgsize;
buflen -= sgsize;
}
+
+ /* Grant access to references */
+ nsegs = dmat->common.nsegments;
+ gm_map= map->gm_map;
+
+ for (i = 0; i< nsegs; i++) {
+ buffer = segs[i].ds_addr;
+ gm_ref = gm_map[i].gm_ref;
+
+ gnttab_grant_foreign_access_ref (gm_ref, DOMID_SELF, buffer >> PAGE_SHIFT, 1/*readonly*/);
+
+ gm_map[i].gm_paddr = buffer;
+ segs[i].ds_addr = gm_map[i].gm_ref;
+ }
/*
* Did we fit?
@@ -890,10 +932,27 @@
bounce_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
{
struct bounce_page *bpage;
+ struct xen_gntmap *gm_map;
+ u_int nsegs;
+ int i = 0;
+
+ bus_dma_segment_t *segs;
if (map == NULL)
return;
+ /* End access to reference */
+ segs = dmat->segments;
+ nsegs = dmat->common.nsegments;
+ gm_map = map->gm_map;
+
+ for (i = 0; i < nsegs; i++) {
+ gnttab_end_foreign_access_ref (gm_map[i].gm_ref);
+
+ segs[i].ds_addr = gm_map[i].gm_paddr;
+ gm_map[i].gm_paddr = 0;
+ }
+
while ((bpage = STAILQ_FIRST(&map->bpages)) != NULL) {
STAILQ_REMOVE_HEAD(&map->bpages, links);
free_bounce_page(dmat, bpage);
Modified: soc2017/vaibhav/head/sys/x86/xen/xenpv.c
==============================================================================
--- soc2017/vaibhav/head/sys/x86/xen/xenpv.c Thu Jun 29 19:43:27 2017 (r324094)
+++ soc2017/vaibhav/head/sys/x86/xen/xenpv.c Thu Jun 29 20:26:09 2017 (r324095)
@@ -95,6 +95,10 @@
{
device_t child;
+ /*printf ("...... GRANT TABLE ATTACHING ......\n");
+ granttable_attach (dev);
+ printf ("...... GRANT TABLE ATTACHED ...... \n");*/
+
/*
* Let our child drivers identify any child devices that they
* can find. Once that is done attach any devices that we
Modified: soc2017/vaibhav/head/sys/xen/gnttab.h
==============================================================================
--- soc2017/vaibhav/head/sys/xen/gnttab.h Thu Jun 29 19:43:27 2017 (r324094)
+++ soc2017/vaibhav/head/sys/xen/gnttab.h Thu Jun 29 20:26:09 2017 (r324095)
@@ -52,6 +52,9 @@
uint16_t count;
};
+int gnttab_next_reference (grant_ref_t *gref_head);
+
+int granttable_attach (device_t);
/*
* Allocate a grant table reference and return it in *result. Returns
* zero on success or errno on error.
More information about the svn-soc-all
mailing list