xref: /freebsd/tools/bus_space/C/libbus.h (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 /*-
2  * Copyright (c) 2014, 2015 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _LIBBUS_SPACE_H_
30 #define	_LIBBUS_SPACE_H_
31 
32 int	bus_map(const char *dev, const char *resource);
33 int16_t	bus_read_1(int rid, long ofs);
34 int32_t	bus_read_2(int rid, long ofs);
35 int64_t bus_read_4(int rid, long ofs);
36 int	bus_subregion(int rid, long ofs, long sz);
37 int	bus_unmap(int rid);
38 int	bus_write_1(int rid, long ofs, uint8_t val);
39 int	bus_write_2(int rid, long ofs, uint16_t val);
40 int	bus_write_4(int rid, long ofs, uint32_t val);
41 
42 typedef unsigned long bus_addr_t;
43 typedef unsigned long bus_size_t;
44 typedef int busdma_tag_t;
45 typedef int busdma_md_t;
46 typedef int busdma_seg_t;
47 
48 int	busdma_tag_create(const char *dev, bus_addr_t align, bus_addr_t bndry,
49 	    bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs,
50 	    bus_size_t maxsegsz, u_int datarate, u_int flags,
51 	    busdma_tag_t *out_p);
52 int	busdma_tag_derive(busdma_tag_t tag, bus_addr_t align, bus_addr_t bndry,
53 	    bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs,
54 	    bus_size_t maxsegsz, u_int datarate, u_int flags,
55 	    busdma_tag_t *out_p);
56 int	busdma_tag_destroy(busdma_tag_t tag);
57 
58 int	busdma_mem_alloc(busdma_tag_t tag, u_int flags, busdma_md_t *out_p);
59 int	busdma_mem_free(busdma_md_t md);
60 
61 int	busdma_md_create(busdma_tag_t tag, u_int flags, busdma_md_t *out_p);
62 int	busdma_md_destroy(busdma_md_t md);
63 int	busdma_md_load(busdma_md_t md, void *buf, size_t len, u_int flags);
64 int	busdma_md_unload(busdma_md_t md);
65 
66 #define	BUSDMA_MD_BUS_SPACE	0
67 #define	BUSDMA_MD_PHYS_SPACE	1
68 #define	BUSDMA_MD_VIRT_SPACE	2
69 
70 int	busdma_md_first_seg(busdma_md_t, int space);
71 int	busdma_md_next_seg(busdma_md_t, busdma_seg_t seg);
72 
73 bus_addr_t	busdma_seg_get_addr(busdma_seg_t seg);
74 bus_size_t	busdma_seg_get_size(busdma_seg_t seg);
75 
76 #define	BUSDMA_SYNC_PREREAD     1
77 #define	BUSDMA_SYNC_POSTREAD    2
78 #define	BUSDMA_SYNC_PREWRITE    4
79 #define	BUSDMA_SYNC_POSTWRITE   8
80 
81 int	busdma_sync(busdma_md_t md, int op);
82 int	busdma_sync_range(busdma_md_t md, int op, bus_size_t, bus_size_t);
83 
84 #endif /* _LIBBUS_SPACE_H_ */
85