1 /* $OpenBSD: cn30xxfpavar.h,v 1.9 2024/05/20 23:13:33 jsg 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 AUTHORS 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 AUTHORS 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 int cn30xxfpa_buf_init(int, size_t, size_t, struct cn30xxfpa_buf **);
49 void *cn30xxfpa_buf_get(struct cn30xxfpa_buf *);
50 uint64_t cn30xxfpa_query(int);
51
52 /*
53 * operations
54 */
55
56 static inline uint64_t
cn30xxfpa_load(uint64_t fpapool)57 cn30xxfpa_load(uint64_t fpapool)
58 {
59 uint64_t addr;
60
61 addr =
62 (0x1ULL << 48) |
63 (0x5ULL << 43) |
64 (fpapool & 0x07ULL) << 40;
65
66 return octeon_xkphys_read_8(addr);
67 }
68
69 #ifdef notyet
70 static inline uint64_t
cn30xxfpa_iobdma(struct cn30xxfpa_softc * sc,int srcaddr,int len)71 cn30xxfpa_iobdma(struct cn30xxfpa_softc *sc, int srcaddr, int len)
72 {
73 /* XXX */
74 return 0ULL;
75 }
76 #endif
77
78 static inline void
cn30xxfpa_store(uint64_t addr,uint64_t fpapool,uint64_t dwbcount)79 cn30xxfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount)
80 {
81 uint64_t ptr;
82
83 ptr =
84 (0x1ULL << 48) |
85 (0x5ULL << 43) |
86 (fpapool & 0x07ULL) << 40 |
87 (addr & 0xffffffffffULL);
88
89 mips_sync();
90 octeon_xkphys_write_8(ptr, (dwbcount & 0x0ffULL));
91 }
92
93 static inline paddr_t
cn30xxfpa_buf_get_paddr(struct cn30xxfpa_buf * fb)94 cn30xxfpa_buf_get_paddr(struct cn30xxfpa_buf *fb)
95 {
96 return cn30xxfpa_load(fb->fb_poolno);
97 }
98
99 static inline void
cn30xxfpa_buf_put_paddr(struct cn30xxfpa_buf * fb,paddr_t paddr)100 cn30xxfpa_buf_put_paddr(struct cn30xxfpa_buf *fb, paddr_t paddr)
101 {
102 KASSERT(paddr >= fb->fb_paddr);
103 KASSERT(paddr < fb->fb_paddr + fb->fb_len);
104 cn30xxfpa_store(paddr, fb->fb_poolno, fb->fb_size / CACHELINESIZE);
105 }
106
107 static inline void
cn30xxfpa_buf_put(struct cn30xxfpa_buf * fb,void * addr)108 cn30xxfpa_buf_put(struct cn30xxfpa_buf *fb, void *addr)
109 {
110 paddr_t paddr;
111
112 KASSERT((vaddr_t)addr >= fb->fb_addr);
113 KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len);
114 paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr);
115 cn30xxfpa_buf_put_paddr(fb, paddr);
116 }
117
118 #endif
119