From 9d7393a25cad6018b12d73a6304241272dc1ffb4 Mon Sep 17 00:00:00 2001 From: marcel Date: Sat, 6 Jun 2015 16:14:03 +0000 Subject: Add DMA tag management to the C library and Python binding. --- tools/bus_space/Python/lang.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'tools/bus_space/Python/lang.c') diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index f328a77..a515549 100644 --- a/tools/bus_space/Python/lang.c +++ b/tools/bus_space/Python/lang.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include #include "bus_space.h" +#include "busdma.h" static PyObject * bus_read_1(PyObject *self, PyObject *args) @@ -173,6 +174,58 @@ bus_subregion(PyObject *self, PyObject *args) return (Py_BuildValue("i", rid)); } +static PyObject * +busdma_tag_create(PyObject *self, PyObject *args) +{ + char *dev; + long align, bndry, maxaddr, maxsz, maxsegsz; + int tid, nsegs, datarate, flags; + + if (!PyArg_ParseTuple(args, "sllllilii", &dev, &align, &bndry, + &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags)) + return (NULL); + tid = bd_tag_create(dev, align, bndry, maxaddr, maxsz, nsegs, + maxsegsz, datarate, flags); + if (tid == -1) { + PyErr_SetString(PyExc_IOError, strerror(errno)); + return (NULL); + } + return (Py_BuildValue("i", tid)); +} + +static PyObject * +busdma_tag_derive(PyObject *self, PyObject *args) +{ + long align, bndry, maxaddr, maxsz, maxsegsz; + int ptid, tid, nsegs, datarate, flags; + + if (!PyArg_ParseTuple(args, "illllilii", &ptid, &align, &bndry, + &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags)) + return (NULL); + tid = bd_tag_derive(ptid, align, bndry, maxaddr, maxsz, nsegs, + maxsegsz, datarate, flags); + if (tid == -1) { + PyErr_SetString(PyExc_IOError, strerror(errno)); + return (NULL); + } + return (Py_BuildValue("i", tid)); +} + +static PyObject * +busdma_tag_destroy(PyObject *self, PyObject *args) +{ + int error, tid; + + if (!PyArg_ParseTuple(args, "i", &tid)) + return (NULL); + error = bd_tag_destroy(tid); + if (error) { + PyErr_SetString(PyExc_IOError, strerror(error)); + return (NULL); + } + Py_RETURN_NONE; +} + static PyMethodDef bus_space_methods[] = { { "read_1", bus_read_1, METH_VARARGS, "Read a 1-byte data item." }, { "read_2", bus_read_2, METH_VARARGS, "Read a 2-byte data item." }, @@ -192,9 +245,17 @@ static PyMethodDef bus_space_methods[] = { { NULL, NULL, 0, NULL } }; +static PyMethodDef busdma_methods[] = { + { "tag_create", busdma_tag_create, METH_VARARGS, "Create a root tag." }, + { "tag_derive", busdma_tag_derive, METH_VARARGS, "Derive a child tag." }, + { "tag_destroy", busdma_tag_destroy, METH_VARARGS, "Destroy a tag." }, + { NULL, NULL, 0, NULL } +}; + PyMODINIT_FUNC initbus_space(void) { Py_InitModule("bus_space", bus_space_methods); + Py_InitModule("busdma", busdma_methods); } -- cgit v1.1 From 440bb648898820e493ba0291411c6cd04de5c277 Mon Sep 17 00:00:00 2001 From: marcel Date: Mon, 8 Jun 2015 03:23:20 +0000 Subject: Add busdma_mem_alloc & busdma_mem_free. --- tools/bus_space/Python/lang.c | 60 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'tools/bus_space/Python/lang.c') diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index a515549..2247360 100644 --- a/tools/bus_space/Python/lang.c +++ b/tools/bus_space/Python/lang.c @@ -178,12 +178,13 @@ static PyObject * busdma_tag_create(PyObject *self, PyObject *args) { char *dev; - long align, bndry, maxaddr, maxsz, maxsegsz; - int tid, nsegs, datarate, flags; + u_long align, bndry, maxaddr, maxsz, maxsegsz; + u_int nsegs, datarate, flags; + int tid; - if (!PyArg_ParseTuple(args, "sllllilii", &dev, &align, &bndry, + if (!PyArg_ParseTuple(args, "skkkkIkII", &dev, &align, &bndry, &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags)) - return (NULL); + return (NULL); tid = bd_tag_create(dev, align, bndry, maxaddr, maxsz, nsegs, maxsegsz, datarate, flags); if (tid == -1) { @@ -196,10 +197,11 @@ busdma_tag_create(PyObject *self, PyObject *args) static PyObject * busdma_tag_derive(PyObject *self, PyObject *args) { - long align, bndry, maxaddr, maxsz, maxsegsz; - int ptid, tid, nsegs, datarate, flags; + u_long align, bndry, maxaddr, maxsz, maxsegsz; + u_int nsegs, datarate, flags; + int ptid, tid; - if (!PyArg_ParseTuple(args, "illllilii", &ptid, &align, &bndry, + if (!PyArg_ParseTuple(args, "ikkkkIkII", &ptid, &align, &bndry, &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags)) return (NULL); tid = bd_tag_derive(ptid, align, bndry, maxaddr, maxsz, nsegs, @@ -226,6 +228,37 @@ busdma_tag_destroy(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject * +busdma_mem_alloc(PyObject *self, PyObject *args) +{ + u_int flags; + int mdid, tid; + + if (!PyArg_ParseTuple(args, "iI", &tid, &flags)) + return (NULL); + mdid = bd_mem_alloc(tid, flags); + if (mdid == -1) { + PyErr_SetString(PyExc_IOError, strerror(errno)); + return (NULL); + } + return (Py_BuildValue("i", mdid)); +} + +static PyObject * +busdma_mem_free(PyObject *self, PyObject *args) +{ + int error, mdid; + + if (!PyArg_ParseTuple(args, "i", &mdid)) + return (NULL); + error = bd_mem_free(mdid); + if (error) { + PyErr_SetString(PyExc_IOError, strerror(error)); + return (NULL); + } + Py_RETURN_NONE; +} + static PyMethodDef bus_space_methods[] = { { "read_1", bus_read_1, METH_VARARGS, "Read a 1-byte data item." }, { "read_2", bus_read_2, METH_VARARGS, "Read a 2-byte data item." }, @@ -246,9 +279,16 @@ static PyMethodDef bus_space_methods[] = { }; static PyMethodDef busdma_methods[] = { - { "tag_create", busdma_tag_create, METH_VARARGS, "Create a root tag." }, - { "tag_derive", busdma_tag_derive, METH_VARARGS, "Derive a child tag." }, - { "tag_destroy", busdma_tag_destroy, METH_VARARGS, "Destroy a tag." }, + { "tag_create", busdma_tag_create, METH_VARARGS, + "Create a root tag." }, + { "tag_derive", busdma_tag_derive, METH_VARARGS, + "Derive a child tag." }, + { "tag_destroy", busdma_tag_destroy, METH_VARARGS, + "Destroy a tag." }, + { "mem_alloc", busdma_mem_alloc, METH_VARARGS, + "Allocate memory according to the DMA constraints." }, + { "mem_free", busdma_mem_free, METH_VARARGS, + "Free allocated memory." }, { NULL, NULL, 0, NULL } }; -- cgit v1.1