1265056Smarcel/*-
2284080Smarcel * 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 * $FreeBSD$
27265056Smarcel */
28265056Smarcel
29265056Smarcel#ifndef _LIBBUS_SPACE_H_
30265056Smarcel#define	_LIBBUS_SPACE_H_
31265056Smarcel
32285903Smarcelint	bus_map(const char *dev, const char *resource);
33284228Smarcelint16_t	bus_read_1(int rid, long ofs);
34284228Smarcelint32_t	bus_read_2(int rid, long ofs);
35284228Smarcelint64_t bus_read_4(int rid, long ofs);
36284228Smarcelint	bus_subregion(int rid, long ofs, long sz);
37284228Smarcelint	bus_unmap(int rid);
38284228Smarcelint	bus_write_1(int rid, long ofs, uint8_t val);
39284228Smarcelint	bus_write_2(int rid, long ofs, uint16_t val);
40284228Smarcelint	bus_write_4(int rid, long ofs, uint32_t val);
41265056Smarcel
42284080Smarceltypedef unsigned long bus_addr_t;
43284080Smarceltypedef unsigned long bus_size_t;
44284080Smarceltypedef int busdma_tag_t;
45284146Smarceltypedef int busdma_md_t;
46284253Smarceltypedef int busdma_seg_t;
47284080Smarcel
48284080Smarcelint	busdma_tag_create(const char *dev, bus_addr_t align, bus_addr_t bndry,
49284080Smarcel	    bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs,
50284080Smarcel	    bus_size_t maxsegsz, u_int datarate, u_int flags,
51284080Smarcel	    busdma_tag_t *out_p);
52284080Smarcelint	busdma_tag_derive(busdma_tag_t tag, bus_addr_t align, bus_addr_t bndry,
53284080Smarcel	    bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs,
54284080Smarcel	    bus_size_t maxsegsz, u_int datarate, u_int flags,
55284080Smarcel	    busdma_tag_t *out_p);
56284080Smarcelint	busdma_tag_destroy(busdma_tag_t tag);
57284080Smarcel
58284146Smarcelint	busdma_mem_alloc(busdma_tag_t tag, u_int flags, busdma_md_t *out_p);
59284146Smarcelint	busdma_mem_free(busdma_md_t md);
60284146Smarcel
61285071Smarcelint	busdma_md_create(busdma_tag_t tag, u_int flags, busdma_md_t *out_p);
62285071Smarcelint	busdma_md_destroy(busdma_md_t md);
63285071Smarcelint	busdma_md_load(busdma_md_t md, void *buf, size_t len, u_int flags);
64285075Smarcelint	busdma_md_unload(busdma_md_t md);
65285071Smarcel
66284253Smarcel#define	BUSDMA_MD_BUS_SPACE	0
67284253Smarcel#define	BUSDMA_MD_PHYS_SPACE	1
68284253Smarcel#define	BUSDMA_MD_VIRT_SPACE	2
69284253Smarcel
70284253Smarcelint	busdma_md_first_seg(busdma_md_t, int space);
71284253Smarcelint	busdma_md_next_seg(busdma_md_t, busdma_seg_t seg);
72284253Smarcel
73284253Smarcelbus_addr_t	busdma_seg_get_addr(busdma_seg_t seg);
74284253Smarcelbus_size_t	busdma_seg_get_size(busdma_seg_t seg);
75284253Smarcel
76285075Smarcel#define	BUSDMA_SYNC_PREREAD     1
77285075Smarcel#define	BUSDMA_SYNC_POSTREAD    2
78285075Smarcel#define	BUSDMA_SYNC_PREWRITE    4
79285075Smarcel#define	BUSDMA_SYNC_POSTWRITE   8
80285075Smarcel
81286176Smarcelint	busdma_sync(busdma_md_t md, int op);
82286176Smarcelint	busdma_sync_range(busdma_md_t md, int op, bus_size_t, bus_size_t);
83285075Smarcel
84265056Smarcel#endif /* _LIBBUS_SPACE_H_ */
85