summaryrefslogtreecommitdiffstats
path: root/tools/bus_space/Python/lang.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2015-07-03 05:47:56 +0000
committermarcel <marcel@FreeBSD.org>2015-07-03 05:47:56 +0000
commitfac325d35189afbad0cf6276d1e1a195e78ceafd (patch)
treed48c492ec6003859eac44c9fc58e6201d161d6f2 /tools/bus_space/Python/lang.c
parent2c1d4a4ec108315dde35ee29b168bcf39be807ac (diff)
downloadFreeBSD-src-fac325d35189afbad0cf6276d1e1a195e78ceafd.zip
FreeBSD-src-fac325d35189afbad0cf6276d1e1a195e78ceafd.tar.gz
Implement busdma_md_unload() and busdma_sync().
While here: 1. have the Python bindings contain constants for the space identifiers and the sync operation. 2. change the segment iterators to return None when done, not ENXIO.
Diffstat (limited to 'tools/bus_space/Python/lang.c')
-rw-r--r--tools/bus_space/Python/lang.c70
1 files changed, 59 insertions, 11 deletions
diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c
index a90e0bd..0b96db3 100644
--- a/tools/bus_space/Python/lang.c
+++ b/tools/bus_space/Python/lang.c
@@ -278,6 +278,21 @@ busdma_md_load(PyObject *self, PyObject *args)
}
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;
@@ -316,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));
}
@@ -331,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));
}
@@ -370,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." },
@@ -403,6 +430,8 @@ static PyMethodDef busdma_methods[] = {
"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." },
@@ -417,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));
}
OpenPOWER on IntegriCloud