summaryrefslogtreecommitdiffstats
path: root/tools/bus_space/Python/lang.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/bus_space/Python/lang.c')
-rw-r--r--tools/bus_space/Python/lang.c81
1 files changed, 76 insertions, 5 deletions
diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c
index 2247360..2127df5 100644
--- a/tools/bus_space/Python/lang.c
+++ b/tools/bus_space/Python/lang.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2014 Marcel Moolenaar
+ * Copyright (c) 2014, 2015 Marcel Moolenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,7 @@ __FBSDID("$FreeBSD$");
#include <Python.h>
-#include "bus_space.h"
+#include "bus.h"
#include "busdma.h"
static PyObject *
@@ -259,7 +259,69 @@ busdma_mem_free(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static PyMethodDef bus_space_methods[] = {
+static PyObject *
+busdma_md_first_seg(PyObject *self, PyObject *args)
+{
+ int error, mdid, sid, what;
+
+ 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);
+ }
+ return (Py_BuildValue("i", sid));
+}
+
+static PyObject *
+busdma_md_next_seg(PyObject *self, PyObject *args)
+{
+ int error, mdid, sid;
+
+ 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);
+ }
+ return (Py_BuildValue("i", sid));
+}
+
+static PyObject *
+busdma_seg_get_addr(PyObject *self, PyObject *args)
+{
+ u_long addr;
+ int error, sid;
+
+ if (!PyArg_ParseTuple(args, "i", &sid))
+ return (NULL);
+ error = bd_seg_get_addr(sid, &addr);
+ if (error) {
+ PyErr_SetString(PyExc_IOError, strerror(error));
+ return (NULL);
+ }
+ return (Py_BuildValue("k", addr));
+}
+
+static PyObject *
+busdma_seg_get_size(PyObject *self, PyObject *args)
+{
+ u_long size;
+ int error, sid;
+
+ if (!PyArg_ParseTuple(args, "i", &sid))
+ return (NULL);
+ error = bd_seg_get_size(sid, &size);
+ if (error) {
+ PyErr_SetString(PyExc_IOError, strerror(error));
+ return (NULL);
+ }
+ return (Py_BuildValue("k", size));
+}
+
+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." },
{ "read_4", bus_read_4, METH_VARARGS, "Read a 4-byte data item." },
@@ -289,13 +351,22 @@ static PyMethodDef busdma_methods[] = {
"Allocate memory according to the DMA constraints." },
{ "mem_free", busdma_mem_free, METH_VARARGS,
"Free allocated memory." },
+
+ { "md_first_seg", busdma_md_first_seg, METH_VARARGS,
+ "Return first segment in one of the segment lists." },
+ { "md_next_seg", busdma_md_next_seg, METH_VARARGS,
+ "Return next segment in the segment list." },
+ { "seg_get_addr", busdma_seg_get_addr, METH_VARARGS,
+ "Return the address of the segment." },
+ { "seg_get_size", busdma_seg_get_size, METH_VARARGS,
+ "Return the size of the segment." },
{ NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC
-initbus_space(void)
+initbus(void)
{
- Py_InitModule("bus_space", bus_space_methods);
+ Py_InitModule("bus", bus_methods);
Py_InitModule("busdma", busdma_methods);
}
OpenPOWER on IntegriCloud