2 * Copyright (c) 2014 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
38 bus_read_1(int rid, long ofs)
42 return ((!bs_read(rid, ofs, &val, sizeof(val))) ? -1 : (int)val);
46 bus_read_2(int rid, long ofs)
50 return ((!bs_read(rid, ofs, &val, sizeof(val))) ? -1 : (int)val);
54 bus_read_4(int rid, long ofs)
58 return ((!bs_read(rid, ofs, &val, sizeof(val))) ? -1 : (int64_t)val);
62 bus_write_1(int rid, long ofs, uint8_t val)
65 return ((!bs_write(rid, ofs, &val, sizeof(val))) ? errno : 0);
69 bus_write_2(int rid, long ofs, uint16_t val)
72 return ((!bs_write(rid, ofs, &val, sizeof(val))) ? errno : 0);
76 bus_write_4(int rid, long ofs, uint32_t val)
79 return ((!bs_write(rid, ofs, &val, sizeof(val))) ? errno : 0);
83 bus_map(const char *dev, const char *resource)
86 return (bs_map(dev, resource));
93 return ((!bs_unmap(rid)) ? errno : 0);
97 bus_subregion(int rid, long ofs, long sz)
100 return (bs_subregion(rid, ofs, sz));
104 busdma_tag_create(const char *dev, bus_addr_t align, bus_addr_t bndry,
105 bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs, bus_size_t maxsegsz,
106 u_int datarate, u_int flags, busdma_tag_t *out_p)
110 res = bd_tag_create(dev, align, bndry, maxaddr, maxsz, nsegs, maxsegsz,
119 busdma_tag_derive(busdma_tag_t tag, bus_addr_t align, bus_addr_t bndry,
120 bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs, bus_size_t maxsegsz,
121 u_int datarate, u_int flags, busdma_tag_t *out_p)
125 res = bd_tag_derive(tag, align, bndry, maxaddr, maxsz, nsegs, maxsegsz,
134 busdma_tag_destroy(busdma_tag_t tag)
137 return (bd_tag_destroy(tag));
141 busdma_mem_alloc(busdma_tag_t tag, u_int flags, busdma_md_t *out_p)
145 res = bd_mem_alloc(tag, flags);
153 busdma_mem_free(busdma_md_t md)
156 return (bd_mem_free(md));
160 busdma_md_create(busdma_tag_t tag, u_int flags, busdma_md_t *out_p)
164 res = bd_md_create(tag, flags);
172 busdma_md_destroy(busdma_md_t md)
175 return (bd_md_destroy(md));
179 busdma_md_load(busdma_md_t md, void *buf, size_t len, u_int flags)
182 return (bd_md_load(md, buf, len, flags));
186 busdma_md_unload(busdma_md_t md)
189 return (bd_md_unload(md));
193 busdma_md_first_seg(busdma_md_t md, int space)
197 seg = bd_md_first_seg(md, space);
202 busdma_md_next_seg(busdma_md_t md, busdma_seg_t seg)
205 seg = bd_md_next_seg(md, seg);
210 busdma_seg_get_addr(busdma_seg_t seg)
215 error = bd_seg_get_addr(seg, &addr);
216 return ((error) ? ~0UL : addr);
220 busdma_seg_get_size(busdma_seg_t seg)
225 error = bd_seg_get_size(seg, &size);
226 return ((error) ? ~0UL : size);
230 busdma_sync(busdma_md_t md, int op)
233 return (bd_sync(md, op, 0UL, ~0UL));
237 busdma_sync_range(busdma_md_t md, int op, bus_size_t ofs, bus_size_t len)
240 return (bd_sync(md, op, ofs, len));