diff options
Diffstat (limited to 'tools/bus_space/Python/lang.c')
-rw-r--r-- | tools/bus_space/Python/lang.c | 127 |
1 files changed, 116 insertions, 11 deletions
diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index 2127df5..0b96db3 100644 --- a/tools/bus_space/Python/lang.c +++ b/tools/bus_space/Python/lang.c @@ -229,6 +229,70 @@ busdma_tag_destroy(PyObject *self, PyObject *args) } static PyObject * +busdma_md_create(PyObject *self, PyObject *args) +{ + u_int flags; + int error, mdid, tid; + + if (!PyArg_ParseTuple(args, "iI", &tid, &flags)) + return (NULL); + mdid = bd_md_create(tid, flags); + if (mdid == -1) { + PyErr_SetString(PyExc_IOError, strerror(errno)); + return (NULL); + } + return (Py_BuildValue("i", mdid)); +} + +static PyObject * +busdma_md_destroy(PyObject *self, PyObject *args) +{ + int error, mdid; + + if (!PyArg_ParseTuple(args, "i", &mdid)) + return (NULL); + error = bd_md_destroy(mdid); + if (error) { + PyErr_SetString(PyExc_IOError, strerror(error)); + return (NULL); + } + Py_RETURN_NONE; +} + +static PyObject * +busdma_md_load(PyObject *self, PyObject *args) +{ + void *buf; + u_long len; + u_int flags; + int error, mdid; + + if (!PyArg_ParseTuple(args, "iwkI", &mdid, &buf, &len, &flags)) + return (NULL); + error = bd_md_load(mdid, buf, len, flags); + if (error) { + PyErr_SetString(PyExc_IOError, strerror(error)); + return (NULL); + } + Py_RETURN_NONE; +} + +static PyObject * +busdma_md_unload(PyObject *self, PyObject *args) +{ + int error, mdid; + + if (!PyArg_ParseTuple(args, "i", &mdid)) + return (NULL); + error = bd_md_unload(mdid); + 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; @@ -267,10 +331,8 @@ busdma_md_first_seg(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "ii", &mdid, &what)) return (NULL); sid = bd_md_first_seg(mdid, what); - if (sid == -1) { - PyErr_SetString(PyExc_IOError, strerror(errno)); - return (NULL); - } + if (sid == -1) + Py_RETURN_NONE; return (Py_BuildValue("i", sid)); } @@ -282,10 +344,8 @@ busdma_md_next_seg(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "ii", &mdid, &sid)) return (NULL); sid = bd_md_next_seg(mdid, sid); - if (sid == -1) { - PyErr_SetString(PyExc_IOError, strerror(errno)); - return (NULL); - } + if (sid == -1) + Py_RETURN_NONE; return (Py_BuildValue("i", sid)); } @@ -321,6 +381,22 @@ busdma_seg_get_size(PyObject *self, PyObject *args) return (Py_BuildValue("k", size)); } +static PyObject * +busdma_sync(PyObject *self, PyObject *args) +{ + u_long base, size; + int error, mdid, op; + + if (!PyArg_ParseTuple(args, "iikk", &mdid, &op, &base, &size)) + return (NULL); + error = bd_sync(mdid, op, base, size); + if (error) { + PyErr_SetString(PyExc_IOError, strerror(error)); + return (NULL); + } + Py_RETURN_NONE; +} + static PyMethodDef bus_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." }, @@ -347,6 +423,16 @@ static PyMethodDef busdma_methods[] = { "Derive a child tag." }, { "tag_destroy", busdma_tag_destroy, METH_VARARGS, "Destroy a tag." }, + + { "md_create", busdma_md_create, METH_VARARGS, + "Create a new and empty memory descriptor." }, + { "md_destroy", busdma_md_destroy, METH_VARARGS, + "Destroy a previously created memory descriptor." }, + { "md_load", busdma_md_load, METH_VARARGS, + "Load a buffer into a memory descriptor." }, + { "md_unload", busdma_md_unload, METH_VARARGS, + "Unload a memory descriptor." }, + { "mem_alloc", busdma_mem_alloc, METH_VARARGS, "Allocate memory according to the DMA constraints." }, { "mem_free", busdma_mem_free, METH_VARARGS, @@ -360,13 +446,32 @@ static PyMethodDef busdma_methods[] = { "Return the address of the segment." }, { "seg_get_size", busdma_seg_get_size, METH_VARARGS, "Return the size of the segment." }, + + { "sync", busdma_sync, METH_VARARGS, + "Keep memory/caches coherent WRT to DMA." }, + { NULL, NULL, 0, NULL } }; PyMODINIT_FUNC initbus(void) { - - Py_InitModule("bus", bus_methods); - Py_InitModule("busdma", busdma_methods); + PyObject *bus, *busdma; + + bus = Py_InitModule("bus", bus_methods); + if (bus == NULL) + return; + busdma = Py_InitModule("busdma", busdma_methods); + if (busdma == NULL) + return; + PyModule_AddObject(bus, "dma", busdma); + + PyModule_AddObject(busdma, "MD_BUS_SPACE", Py_BuildValue("i", 0)); + PyModule_AddObject(busdma, "MD_PHYS_SPACE", Py_BuildValue("i", 1)); + PyModule_AddObject(busdma, "MD_VIRT_SPACE", Py_BuildValue("i", 2)); + + PyModule_AddObject(busdma, "SYNC_PREREAD", Py_BuildValue("i", 1)); + PyModule_AddObject(busdma, "SYNC_POSTREAD", Py_BuildValue("i", 2)); + PyModule_AddObject(busdma, "SYNC_PREWRITE", Py_BuildValue("i", 4)); + PyModule_AddObject(busdma, "SYNC_POSTWRITE", Py_BuildValue("i", 8)); } |