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 27 #ifndef _LIBBUS_SPACE_H_ 28 #define _LIBBUS_SPACE_H_ 29 30 int bus_map(const char *dev, const char *resource); 31 int16_t bus_read_1(int rid, long ofs); 32 int32_t bus_read_2(int rid, long ofs); 33 int64_t bus_read_4(int rid, long ofs); 34 int bus_subregion(int rid, long ofs, long sz); 35 int bus_unmap(int rid); 36 int bus_write_1(int rid, long ofs, uint8_t val); 37 int bus_write_2(int rid, long ofs, uint16_t val); 38 int bus_write_4(int rid, long ofs, uint32_t val); 39 40 typedef unsigned long bus_addr_t; 41 typedef unsigned long bus_size_t; 42 typedef int busdma_tag_t; 43 typedef int busdma_md_t; 44 typedef int busdma_seg_t; 45 46 int busdma_tag_create(const char *dev, bus_addr_t align, bus_addr_t bndry, 47 bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs, 48 bus_size_t maxsegsz, u_int datarate, u_int flags, 49 busdma_tag_t *out_p); 50 int busdma_tag_derive(busdma_tag_t tag, bus_addr_t align, bus_addr_t bndry, 51 bus_addr_t maxaddr, bus_size_t maxsz, u_int nsegs, 52 bus_size_t maxsegsz, u_int datarate, u_int flags, 53 busdma_tag_t *out_p); 54 int busdma_tag_destroy(busdma_tag_t tag); 55 56 int busdma_mem_alloc(busdma_tag_t tag, u_int flags, busdma_md_t *out_p); 57 int busdma_mem_free(busdma_md_t md); 58 59 int busdma_md_create(busdma_tag_t tag, u_int flags, busdma_md_t *out_p); 60 int busdma_md_destroy(busdma_md_t md); 61 int busdma_md_load(busdma_md_t md, void *buf, size_t len, u_int flags); 62 int busdma_md_unload(busdma_md_t md); 63 64 #define BUSDMA_MD_BUS_SPACE 0 65 #define BUSDMA_MD_PHYS_SPACE 1 66 #define BUSDMA_MD_VIRT_SPACE 2 67 68 int busdma_md_first_seg(busdma_md_t, int space); 69 int busdma_md_next_seg(busdma_md_t, busdma_seg_t seg); 70 71 bus_addr_t busdma_seg_get_addr(busdma_seg_t seg); 72 bus_size_t busdma_seg_get_size(busdma_seg_t seg); 73 74 #define BUSDMA_SYNC_PREREAD 1 75 #define BUSDMA_SYNC_POSTREAD 2 76 #define BUSDMA_SYNC_PREWRITE 4 77 #define BUSDMA_SYNC_POSTWRITE 8 78 79 int busdma_sync(busdma_md_t md, int op); 80 int busdma_sync_range(busdma_md_t md, int op, bus_size_t, bus_size_t); 81 82 #endif /* _LIBBUS_SPACE_H_ */ 83