1 /* $OpenBSD: cn30xxfpavar.h,v 1.7 2017/11/05 04:57:28 visa Exp $ */ 2 /* 3 * Copyright (c) 2007 Internet Initiative Japan, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _CN30XXFPAVAR_H_ 29 #define _CN30XXFPAVAR_H_ 30 31 struct cn30xxfpa_buf { 32 int fb_poolno; /* pool # */ 33 34 size_t fb_size; /* element size */ 35 size_t fb_nelems; /* # of elements */ 36 37 paddr_t fb_paddr; /* physical address */ 38 vaddr_t fb_addr; /* virtual address */ 39 size_t fb_len; /* total length */ 40 41 bus_dma_tag_t fb_dmat; 42 bus_dmamap_t fb_dmah; 43 bus_dma_segment_t 44 *fb_dma_segs; 45 int fb_dma_nsegs; 46 }; 47 48 uint64_t cn30xxfpa_int_summary(void); 49 int cn30xxfpa_buf_init(int, size_t, size_t, struct cn30xxfpa_buf **); 50 void *cn30xxfpa_buf_get(struct cn30xxfpa_buf *); 51 uint64_t cn30xxfpa_query(int); 52 53 /* 54 * operations 55 */ 56 57 static inline uint64_t 58 cn30xxfpa_load(uint64_t fpapool) 59 { 60 uint64_t addr; 61 62 addr = 63 (0x1ULL << 48) | 64 (0x5ULL << 43) | 65 (fpapool & 0x07ULL) << 40; 66 67 return octeon_xkphys_read_8(addr); 68 } 69 70 #ifdef notyet 71 static inline uint64_t 72 cn30xxfpa_iobdma(struct cn30xxfpa_softc *sc, int srcaddr, int len) 73 { 74 /* XXX */ 75 return 0ULL; 76 } 77 #endif 78 79 static inline void 80 cn30xxfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount) 81 { 82 uint64_t ptr; 83 84 ptr = 85 (0x1ULL << 48) | 86 (0x5ULL << 43) | 87 (fpapool & 0x07ULL) << 40 | 88 (addr & 0xffffffffffULL); 89 90 mips_sync(); 91 octeon_xkphys_write_8(ptr, (dwbcount & 0x0ffULL)); 92 } 93 94 static inline paddr_t 95 cn30xxfpa_buf_get_paddr(struct cn30xxfpa_buf *fb) 96 { 97 return cn30xxfpa_load(fb->fb_poolno); 98 } 99 100 static inline void 101 cn30xxfpa_buf_put_paddr(struct cn30xxfpa_buf *fb, paddr_t paddr) 102 { 103 KASSERT(paddr >= fb->fb_paddr); 104 KASSERT(paddr < fb->fb_paddr + fb->fb_len); 105 cn30xxfpa_store(paddr, fb->fb_poolno, fb->fb_size / CACHELINESIZE); 106 } 107 108 static inline void 109 cn30xxfpa_buf_put(struct cn30xxfpa_buf *fb, void *addr) 110 { 111 paddr_t paddr; 112 113 KASSERT((vaddr_t)addr >= fb->fb_addr); 114 KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len); 115 paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr); 116 cn30xxfpa_buf_put_paddr(fb, paddr); 117 } 118 119 #endif 120