diff options
author | marcel <marcel@FreeBSD.org> | 2015-06-11 03:02:40 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2015-06-11 03:02:40 +0000 |
commit | 7e7e822da19cf60cf9de6df938781bc539018838 (patch) | |
tree | 899e80dd4c8ad46725550110001c6e815cdf616f /tools/bus_space/Python/lang.c | |
parent | 4b0e592d9fbd3b0675f91a62d7897c125a2f8981 (diff) | |
download | FreeBSD-src-7e7e822da19cf60cf9de6df938781bc539018838.zip FreeBSD-src-7e7e822da19cf60cf9de6df938781bc539018838.tar.gz |
Add accessor functions for iterating over segments. A segment
can be in bus address space, physical memory space or virtual
memory space.
Diffstat (limited to 'tools/bus_space/Python/lang.c')
-rw-r--r-- | tools/bus_space/Python/lang.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index d119b99..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 @@ -259,6 +259,68 @@ busdma_mem_free(PyObject *self, PyObject *args) Py_RETURN_NONE; } +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." }, @@ -289,6 +351,15 @@ 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 } }; |