diff options
Diffstat (limited to 'tools/bus_space/Python/lang.c')
-rw-r--r-- | tools/bus_space/Python/lang.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index f328a77..2247360 100644 --- a/tools/bus_space/Python/lang.c +++ b/tools/bus_space/Python/lang.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include <Python.h> #include "bus_space.h" +#include "busdma.h" static PyObject * bus_read_1(PyObject *self, PyObject *args) @@ -173,6 +174,91 @@ bus_subregion(PyObject *self, PyObject *args) return (Py_BuildValue("i", rid)); } +static PyObject * +busdma_tag_create(PyObject *self, PyObject *args) +{ + char *dev; + u_long align, bndry, maxaddr, maxsz, maxsegsz; + u_int nsegs, datarate, flags; + int tid; + + if (!PyArg_ParseTuple(args, "skkkkIkII", &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) +{ + u_long align, bndry, maxaddr, maxsz, maxsegsz; + u_int nsegs, datarate, flags; + int ptid, tid; + + 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, + 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 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." }, @@ -192,9 +278,24 @@ 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." }, + { "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 } +}; + PyMODINIT_FUNC initbus_space(void) { Py_InitModule("bus_space", bus_space_methods); + Py_InitModule("busdma", busdma_methods); } |