1265056Smarcel/*-
2284253Smarcel * Copyright (c) 2014, 2015 Marcel Moolenaar
3265056Smarcel * All rights reserved.
4265056Smarcel *
5265056Smarcel * Redistribution and use in source and binary forms, with or without
6265056Smarcel * modification, are permitted provided that the following conditions
7265056Smarcel * are met:
8265056Smarcel *
9265056Smarcel * 1. Redistributions of source code must retain the above copyright
10265056Smarcel *    notice, this list of conditions and the following disclaimer.
11265056Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12265056Smarcel *    notice, this list of conditions and the following disclaimer in the
13265056Smarcel *    documentation and/or other materials provided with the distribution.
14265056Smarcel *
15265056Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16265056Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17265056Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18265056Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19265056Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20265056Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21265056Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22265056Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23265056Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24265056Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25265056Smarcel */
26265056Smarcel
27265056Smarcel#include <sys/cdefs.h>
28265056Smarcel__FBSDID("$FreeBSD: releng/11.0/tools/bus_space/Python/lang.c 286176 2015-08-02 01:09:30Z marcel $");
29265056Smarcel
30265056Smarcel#include <Python.h>
31265056Smarcel
32284228Smarcel#include "bus.h"
33284080Smarcel#include "busdma.h"
34265056Smarcel
35265056Smarcelstatic PyObject *
36265056Smarcelbus_read_1(PyObject *self, PyObject *args)
37265056Smarcel{
38265056Smarcel	long ofs;
39265056Smarcel	int rid;
40265056Smarcel	uint8_t val;
41265056Smarcel
42265056Smarcel	if (!PyArg_ParseTuple(args, "il", &rid, &ofs))
43265056Smarcel		return (NULL);
44265056Smarcel	if (!bs_read(rid, ofs, &val, sizeof(val))) {
45265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
46265056Smarcel		return (NULL);
47265056Smarcel	}
48265056Smarcel	return (Py_BuildValue("B", val));
49265056Smarcel}
50265056Smarcel
51265056Smarcelstatic PyObject *
52265056Smarcelbus_read_2(PyObject *self, PyObject *args)
53265056Smarcel{
54265056Smarcel	long ofs;
55265056Smarcel	int rid;
56265056Smarcel	uint16_t val;
57265056Smarcel
58265056Smarcel	if (!PyArg_ParseTuple(args, "il", &rid, &ofs))
59265056Smarcel		return (NULL);
60265056Smarcel	if (!bs_read(rid, ofs, &val, sizeof(val))) {
61265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
62265056Smarcel		return (NULL);
63265056Smarcel	}
64265056Smarcel	return (Py_BuildValue("H", val));
65265056Smarcel}
66265056Smarcel
67265056Smarcelstatic PyObject *
68265056Smarcelbus_read_4(PyObject *self, PyObject *args)
69265056Smarcel{
70265056Smarcel	long ofs;
71265056Smarcel	int rid;
72265056Smarcel	uint32_t val;
73265056Smarcel
74265056Smarcel	if (!PyArg_ParseTuple(args, "il", &rid, &ofs))
75265056Smarcel		return (NULL);
76265056Smarcel	if (!bs_read(rid, ofs, &val, sizeof(val))) {
77265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
78265056Smarcel		return (NULL);
79265056Smarcel	}
80265056Smarcel	return (Py_BuildValue("I", val));
81265056Smarcel}
82265056Smarcel
83265056Smarcelstatic PyObject *
84265056Smarcelbus_write_1(PyObject *self, PyObject *args)
85265056Smarcel{
86265056Smarcel	long ofs;
87265056Smarcel	int rid;
88265056Smarcel	uint8_t val;
89265056Smarcel
90265056Smarcel	if (!PyArg_ParseTuple(args, "ilB", &rid, &ofs, &val))
91265056Smarcel		return (NULL);
92265056Smarcel	if (!bs_write(rid, ofs, &val, sizeof(val))) {
93265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
94265056Smarcel		return (NULL);
95265056Smarcel	}
96265056Smarcel	Py_RETURN_NONE;
97265056Smarcel}
98265056Smarcel
99265056Smarcelstatic PyObject *
100265056Smarcelbus_write_2(PyObject *self, PyObject *args)
101265056Smarcel{
102265056Smarcel	long ofs;
103265056Smarcel	int rid;
104265056Smarcel	uint16_t val;
105265056Smarcel
106265056Smarcel	if (!PyArg_ParseTuple(args, "ilH", &rid, &ofs, &val))
107265056Smarcel		return (NULL);
108265056Smarcel	if (!bs_write(rid, ofs, &val, sizeof(val))) {
109265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
110265056Smarcel		return (NULL);
111265056Smarcel	}
112265056Smarcel	Py_RETURN_NONE;
113265056Smarcel}
114265056Smarcel
115265056Smarcelstatic PyObject *
116265056Smarcelbus_write_4(PyObject *self, PyObject *args)
117265056Smarcel{
118265056Smarcel	long ofs;
119265056Smarcel	int rid;
120265056Smarcel	uint32_t val;
121265056Smarcel
122265056Smarcel	if (!PyArg_ParseTuple(args, "ilI", &rid, &ofs, &val))
123265056Smarcel		return (NULL);
124265056Smarcel	if (!bs_write(rid, ofs, &val, sizeof(val))) {
125265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
126265056Smarcel		return (NULL);
127265056Smarcel	}
128265056Smarcel	Py_RETURN_NONE;
129265056Smarcel}
130265056Smarcel
131265056Smarcelstatic PyObject *
132265056Smarcelbus_map(PyObject *self, PyObject *args)
133265056Smarcel{
134285903Smarcel	char *dev, *resource;
135265056Smarcel	int rid;
136265056Smarcel
137285903Smarcel	if (!PyArg_ParseTuple(args, "ss", &dev, &resource))
138265056Smarcel		return (NULL);
139285903Smarcel	rid = bs_map(dev, resource);
140265056Smarcel	if (rid == -1) {
141265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
142265056Smarcel		return (NULL);
143265056Smarcel	}
144265056Smarcel	return (Py_BuildValue("i", rid));
145265056Smarcel}
146265056Smarcel
147265056Smarcelstatic PyObject *
148265056Smarcelbus_unmap(PyObject *self, PyObject *args)
149265056Smarcel{
150265056Smarcel	int rid;
151265056Smarcel
152265056Smarcel	if (!PyArg_ParseTuple(args, "i", &rid))
153265056Smarcel		return (NULL);
154265056Smarcel	if (!bs_unmap(rid)) {
155265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
156265056Smarcel		return (NULL);
157265056Smarcel	}
158265056Smarcel	Py_RETURN_NONE;
159265056Smarcel}
160265056Smarcel
161265056Smarcelstatic PyObject *
162265056Smarcelbus_subregion(PyObject *self, PyObject *args)
163265056Smarcel{
164265056Smarcel	long ofs, sz;
165265056Smarcel	int rid0, rid;
166265056Smarcel
167265056Smarcel	if (!PyArg_ParseTuple(args, "ill", &rid0, &ofs, &sz))
168265056Smarcel		return (NULL);
169265056Smarcel	rid = bs_subregion(rid0, ofs, sz);
170265056Smarcel	if (rid == -1) {
171265056Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
172265056Smarcel		return (NULL);
173265056Smarcel	}
174265056Smarcel	return (Py_BuildValue("i", rid));
175265056Smarcel}
176265056Smarcel
177284080Smarcelstatic PyObject *
178284080Smarcelbusdma_tag_create(PyObject *self, PyObject *args)
179284080Smarcel{
180284080Smarcel	char *dev;
181284146Smarcel	u_long align, bndry, maxaddr, maxsz, maxsegsz;
182284146Smarcel	u_int nsegs, datarate, flags;
183284146Smarcel	int tid;
184284080Smarcel
185284146Smarcel	if (!PyArg_ParseTuple(args, "skkkkIkII", &dev, &align, &bndry,
186284080Smarcel	    &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags))
187284146Smarcel		return (NULL);
188284080Smarcel	tid = bd_tag_create(dev, align, bndry, maxaddr, maxsz, nsegs,
189284080Smarcel	    maxsegsz, datarate, flags);
190284080Smarcel	if (tid == -1) {
191284080Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
192284080Smarcel		return (NULL);
193284080Smarcel	}
194284080Smarcel	return (Py_BuildValue("i", tid));
195284080Smarcel}
196284080Smarcel
197284080Smarcelstatic PyObject *
198284080Smarcelbusdma_tag_derive(PyObject *self, PyObject *args)
199284080Smarcel{
200284146Smarcel	u_long align, bndry, maxaddr, maxsz, maxsegsz;
201284146Smarcel	u_int nsegs, datarate, flags;
202284146Smarcel	int ptid, tid;
203284080Smarcel
204284146Smarcel	if (!PyArg_ParseTuple(args, "ikkkkIkII", &ptid, &align, &bndry,
205284080Smarcel	    &maxaddr, &maxsz, &nsegs, &maxsegsz, &datarate, &flags))
206284080Smarcel		return (NULL);
207284080Smarcel	tid = bd_tag_derive(ptid, align, bndry, maxaddr, maxsz, nsegs,
208284080Smarcel	    maxsegsz, datarate, flags);
209284080Smarcel	if (tid == -1) {
210284080Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
211284080Smarcel		return (NULL);
212284080Smarcel	}
213284080Smarcel	return (Py_BuildValue("i", tid));
214284080Smarcel}
215284080Smarcel
216284080Smarcelstatic PyObject *
217284080Smarcelbusdma_tag_destroy(PyObject *self, PyObject *args)
218284080Smarcel{
219284080Smarcel	int error, tid;
220284080Smarcel
221284080Smarcel	if (!PyArg_ParseTuple(args, "i", &tid))
222284080Smarcel		return (NULL);
223284080Smarcel	error = bd_tag_destroy(tid);
224284080Smarcel	if (error) {
225284080Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
226284080Smarcel		return (NULL);
227284080Smarcel	}
228284080Smarcel	Py_RETURN_NONE;
229284080Smarcel}
230284080Smarcel
231284146Smarcelstatic PyObject *
232285071Smarcelbusdma_md_create(PyObject *self, PyObject *args)
233285071Smarcel{
234285071Smarcel	u_int flags;
235285071Smarcel	int error, mdid, tid;
236285071Smarcel
237285071Smarcel	if (!PyArg_ParseTuple(args, "iI", &tid, &flags))
238285071Smarcel		return (NULL);
239285071Smarcel	mdid = bd_md_create(tid, flags);
240285071Smarcel	if (mdid == -1) {
241285071Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
242285071Smarcel		return (NULL);
243285071Smarcel	}
244285071Smarcel	return (Py_BuildValue("i", mdid));
245285071Smarcel}
246285071Smarcel
247285071Smarcelstatic PyObject *
248285071Smarcelbusdma_md_destroy(PyObject *self, PyObject *args)
249285071Smarcel{
250285071Smarcel	int error, mdid;
251285071Smarcel
252285071Smarcel	if (!PyArg_ParseTuple(args, "i", &mdid))
253285071Smarcel		return (NULL);
254285071Smarcel	error = bd_md_destroy(mdid);
255285071Smarcel	if (error) {
256285071Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
257285071Smarcel		return (NULL);
258285071Smarcel	}
259285071Smarcel	Py_RETURN_NONE;
260285071Smarcel}
261285071Smarcel
262285071Smarcelstatic PyObject *
263285071Smarcelbusdma_md_load(PyObject *self, PyObject *args)
264285071Smarcel{
265285071Smarcel	void *buf;
266285071Smarcel	u_long len;
267285071Smarcel	u_int flags;
268285071Smarcel	int error, mdid;
269285071Smarcel
270285071Smarcel	if (!PyArg_ParseTuple(args, "iwkI", &mdid, &buf, &len, &flags))
271285071Smarcel		return (NULL);
272285071Smarcel	error = bd_md_load(mdid, buf, len, flags);
273285071Smarcel	if (error) {
274285071Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
275285071Smarcel		return (NULL);
276285071Smarcel	}
277285071Smarcel	Py_RETURN_NONE;
278285071Smarcel}
279285071Smarcel
280285071Smarcelstatic PyObject *
281285075Smarcelbusdma_md_unload(PyObject *self, PyObject *args)
282285075Smarcel{
283285075Smarcel	int error, mdid;
284285075Smarcel
285285075Smarcel	if (!PyArg_ParseTuple(args, "i", &mdid))
286285075Smarcel		return (NULL);
287285075Smarcel	error = bd_md_unload(mdid);
288285075Smarcel	if (error) {
289285075Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
290285075Smarcel		return (NULL);
291285075Smarcel	}
292285075Smarcel	Py_RETURN_NONE;
293285075Smarcel}
294285075Smarcel
295285075Smarcelstatic PyObject *
296284146Smarcelbusdma_mem_alloc(PyObject *self, PyObject *args)
297284146Smarcel{
298284146Smarcel	u_int flags;
299284146Smarcel	int mdid, tid;
300284146Smarcel
301284146Smarcel	if (!PyArg_ParseTuple(args, "iI", &tid, &flags))
302284146Smarcel		return (NULL);
303284146Smarcel	mdid = bd_mem_alloc(tid, flags);
304284146Smarcel	if (mdid == -1) {
305284146Smarcel		PyErr_SetString(PyExc_IOError, strerror(errno));
306284146Smarcel		return (NULL);
307284146Smarcel	}
308284146Smarcel	return (Py_BuildValue("i", mdid));
309284146Smarcel}
310284146Smarcel
311284146Smarcelstatic PyObject *
312284146Smarcelbusdma_mem_free(PyObject *self, PyObject *args)
313284146Smarcel{
314284146Smarcel	int error, mdid;
315284146Smarcel
316284146Smarcel	if (!PyArg_ParseTuple(args, "i", &mdid))
317284146Smarcel		return (NULL);
318284146Smarcel	error = bd_mem_free(mdid);
319284146Smarcel	if (error) {
320284146Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
321284146Smarcel		return (NULL);
322284146Smarcel	}
323284146Smarcel	Py_RETURN_NONE;
324284146Smarcel}
325284146Smarcel
326284253Smarcelstatic PyObject *
327284253Smarcelbusdma_md_first_seg(PyObject *self, PyObject *args)
328284253Smarcel{
329284253Smarcel	int error, mdid, sid, what;
330284253Smarcel
331284253Smarcel	if (!PyArg_ParseTuple(args, "ii", &mdid, &what))
332284253Smarcel		return (NULL);
333284253Smarcel	sid = bd_md_first_seg(mdid, what);
334285075Smarcel	if (sid == -1)
335285075Smarcel		Py_RETURN_NONE;
336284253Smarcel	return (Py_BuildValue("i", sid));
337284253Smarcel}
338284253Smarcel
339284253Smarcelstatic PyObject *
340284253Smarcelbusdma_md_next_seg(PyObject *self, PyObject *args)
341284253Smarcel{
342284253Smarcel	int error, mdid, sid;
343284253Smarcel
344284253Smarcel	if (!PyArg_ParseTuple(args, "ii", &mdid, &sid))
345284253Smarcel		return (NULL);
346284253Smarcel	sid = bd_md_next_seg(mdid, sid);
347285075Smarcel	if (sid == -1)
348285075Smarcel		Py_RETURN_NONE;
349284253Smarcel	return (Py_BuildValue("i", sid));
350284253Smarcel}
351284253Smarcel
352284253Smarcelstatic PyObject *
353284253Smarcelbusdma_seg_get_addr(PyObject *self, PyObject *args)
354284253Smarcel{
355284253Smarcel	u_long addr;
356284253Smarcel	int error, sid;
357284253Smarcel
358284253Smarcel	if (!PyArg_ParseTuple(args, "i", &sid))
359284253Smarcel		return (NULL);
360284253Smarcel	error = bd_seg_get_addr(sid, &addr);
361284253Smarcel	if (error) {
362284253Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
363284253Smarcel		return (NULL);
364284253Smarcel	}
365284253Smarcel	return (Py_BuildValue("k", addr));
366284253Smarcel}
367284253Smarcel
368284253Smarcelstatic PyObject *
369284253Smarcelbusdma_seg_get_size(PyObject *self, PyObject *args)
370284253Smarcel{
371284253Smarcel	u_long size;
372284253Smarcel	int error, sid;
373284253Smarcel
374284253Smarcel	if (!PyArg_ParseTuple(args, "i", &sid))
375284253Smarcel		return (NULL);
376284253Smarcel	error = bd_seg_get_size(sid, &size);
377284253Smarcel	if (error) {
378284253Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
379284253Smarcel		return (NULL);
380284253Smarcel	}
381284253Smarcel	return (Py_BuildValue("k", size));
382284253Smarcel}
383284253Smarcel
384285075Smarcelstatic PyObject *
385285075Smarcelbusdma_sync(PyObject *self, PyObject *args)
386285075Smarcel{
387285075Smarcel	int error, mdid, op;
388285075Smarcel
389286176Smarcel	if (!PyArg_ParseTuple(args, "ii", &mdid, &op))
390285075Smarcel		return (NULL);
391286176Smarcel	error = bd_sync(mdid, op, 0UL, ~0UL);
392285075Smarcel	if (error) {
393285075Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
394285075Smarcel		return (NULL);
395285075Smarcel	}
396285075Smarcel	Py_RETURN_NONE;
397285075Smarcel}
398285075Smarcel
399286176Smarcelstatic PyObject *
400286176Smarcelbusdma_sync_range(PyObject *self, PyObject *args)
401286176Smarcel{
402286176Smarcel	u_long ofs, len;
403286176Smarcel	int error, mdid, op;
404286176Smarcel
405286176Smarcel	if (!PyArg_ParseTuple(args, "iikk", &mdid, &op, &ofs, &len))
406286176Smarcel		return (NULL);
407286176Smarcel	error = bd_sync(mdid, op, ofs, len);
408286176Smarcel	if (error) {
409286176Smarcel		PyErr_SetString(PyExc_IOError, strerror(error));
410286176Smarcel		return (NULL);
411286176Smarcel	}
412286176Smarcel	Py_RETURN_NONE;
413286176Smarcel}
414286176Smarcel
415284228Smarcelstatic PyMethodDef bus_methods[] = {
416265056Smarcel    { "read_1", bus_read_1, METH_VARARGS, "Read a 1-byte data item." },
417265056Smarcel    { "read_2", bus_read_2, METH_VARARGS, "Read a 2-byte data item." },
418265056Smarcel    { "read_4", bus_read_4, METH_VARARGS, "Read a 4-byte data item." },
419265056Smarcel
420265056Smarcel    { "write_1", bus_write_1, METH_VARARGS, "Write a 1-byte data item." },
421265056Smarcel    { "write_2", bus_write_2, METH_VARARGS, "Write a 2-byte data item." },
422265056Smarcel    { "write_4", bus_write_4, METH_VARARGS, "Write a 4-byte data item." },
423265056Smarcel
424265056Smarcel    { "map", bus_map, METH_VARARGS,
425265056Smarcel	"Return a resource ID for a device file created by proto(4)" },
426265056Smarcel    { "unmap", bus_unmap, METH_VARARGS,
427265056Smarcel	"Free a resource ID" },
428265056Smarcel    { "subregion", bus_subregion, METH_VARARGS,
429265056Smarcel	"Return a resource ID for a subregion of another resource ID" },
430265056Smarcel
431265056Smarcel    { NULL, NULL, 0, NULL }
432265056Smarcel};
433265056Smarcel
434284080Smarcelstatic PyMethodDef busdma_methods[] = {
435284146Smarcel    { "tag_create", busdma_tag_create, METH_VARARGS,
436284146Smarcel	"Create a root tag." },
437284146Smarcel    { "tag_derive", busdma_tag_derive, METH_VARARGS,
438284146Smarcel	"Derive a child tag." },
439284146Smarcel    { "tag_destroy", busdma_tag_destroy, METH_VARARGS,
440284146Smarcel	"Destroy a tag." },
441285071Smarcel
442285071Smarcel    { "md_create", busdma_md_create, METH_VARARGS,
443285071Smarcel	"Create a new and empty memory descriptor." },
444285071Smarcel    { "md_destroy", busdma_md_destroy, METH_VARARGS,
445285071Smarcel	"Destroy a previously created memory descriptor." },
446285071Smarcel    { "md_load", busdma_md_load, METH_VARARGS,
447285071Smarcel	"Load a buffer into a memory descriptor." },
448285075Smarcel    { "md_unload", busdma_md_unload, METH_VARARGS,
449285075Smarcel	"Unload a memory descriptor." },
450285071Smarcel
451284146Smarcel    { "mem_alloc", busdma_mem_alloc, METH_VARARGS,
452284146Smarcel	"Allocate memory according to the DMA constraints." },
453284146Smarcel    { "mem_free", busdma_mem_free, METH_VARARGS,
454284146Smarcel	"Free allocated memory." },
455284253Smarcel
456284253Smarcel    { "md_first_seg", busdma_md_first_seg, METH_VARARGS,
457284253Smarcel	"Return first segment in one of the segment lists." },
458284253Smarcel    { "md_next_seg", busdma_md_next_seg, METH_VARARGS,
459284253Smarcel	"Return next segment in the segment list." },
460284253Smarcel    { "seg_get_addr", busdma_seg_get_addr, METH_VARARGS,
461284253Smarcel	"Return the address of the segment." },
462284253Smarcel    { "seg_get_size", busdma_seg_get_size, METH_VARARGS,
463284253Smarcel	"Return the size of the segment." },
464285075Smarcel
465285075Smarcel    { "sync", busdma_sync, METH_VARARGS,
466286176Smarcel	"Make the entire memory descriptor coherent WRT to DMA." },
467286176Smarcel    { "sync_range", busdma_sync_range, METH_VARARGS,
468286176Smarcel	"Make part of the memory descriptor coherent WRT to DMA." },
469285075Smarcel
470284080Smarcel    { NULL, NULL, 0, NULL }
471284080Smarcel};
472284080Smarcel
473265056SmarcelPyMODINIT_FUNC
474284228Smarcelinitbus(void)
475265056Smarcel{
476285075Smarcel	PyObject *bus, *busdma;
477265056Smarcel
478285075Smarcel	bus = Py_InitModule("bus", bus_methods);
479285075Smarcel	if (bus == NULL)
480285075Smarcel		return;
481285075Smarcel	busdma = Py_InitModule("busdma", busdma_methods);
482285075Smarcel	if (busdma == NULL)
483285075Smarcel		return;
484285075Smarcel	PyModule_AddObject(bus, "dma", busdma);
485285075Smarcel
486285075Smarcel	PyModule_AddObject(busdma, "MD_BUS_SPACE", Py_BuildValue("i", 0));
487285075Smarcel	PyModule_AddObject(busdma, "MD_PHYS_SPACE", Py_BuildValue("i", 1));
488285075Smarcel	PyModule_AddObject(busdma, "MD_VIRT_SPACE", Py_BuildValue("i", 2));
489285075Smarcel
490285075Smarcel	PyModule_AddObject(busdma, "SYNC_PREREAD", Py_BuildValue("i", 1));
491285075Smarcel	PyModule_AddObject(busdma, "SYNC_POSTREAD", Py_BuildValue("i", 2));
492285075Smarcel	PyModule_AddObject(busdma, "SYNC_PREWRITE", Py_BuildValue("i", 4));
493285075Smarcel	PyModule_AddObject(busdma, "SYNC_POSTWRITE", Py_BuildValue("i", 8));
494265056Smarcel}
495