1 /* $NetBSD: octeon_fauvar.h,v 1.4 2020/06/23 05:14:18 simonb Exp $ */
2
3 /*
4 * Copyright (c) 2007 Internet Initiative Japan, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #ifndef _OCTEON_FAUVAR_H_
30 #define _OCTEON_FAUVAR_H_
31
32 #include <mips/cavium/octeonreg.h>
33
34 /* ---- API */
35
36 struct octfau_desc {
37 /* offset in scratch buffer */
38 size_t fd_scroff; /* XXX offset_t */
39 /* FAU register number */
40 size_t fd_regno; /* XXX offset_t */
41 };
42
43 void octfau_op_init(struct octfau_desc *, size_t, size_t);
44 uint64_t octfau_op_save(struct octfau_desc *);
45 void octfau_op_restore(struct octfau_desc *, uint64_t);
46 int64_t octfau_op_inc_8(struct octfau_desc *, int64_t);
47 int32_t octfau_op_inc_4(struct octfau_desc *, int32_t);
48 int16_t octfau_op_inc_2(struct octfau_desc *, int16_t);
49 int8_t octfau_op_inc_1(struct octfau_desc *, int8_t);
50 int64_t octfau_op_incwait_8(struct octfau_desc *, int);
51 int32_t octfau_op_incwait_4(struct octfau_desc *, int);
52 int16_t octfau_op_incwait_2(struct octfau_desc *, int);
53 int8_t octfau_op_incwait_1(struct octfau_desc *, int);
54 int64_t octfau_op_get_8(struct octfau_desc *);
55 int32_t octfau_op_get_4(struct octfau_desc *);
56 int16_t octfau_op_get_2(struct octfau_desc *);
57 int8_t octfau_op_get_1(struct octfau_desc *);
58 int64_t octfau_op_getwait_8(struct octfau_desc *);
59 int32_t octfau_op_getwait_4(struct octfau_desc *);
60 int16_t octfau_op_getwait_2(struct octfau_desc *);
61 int8_t octfau_op_getwait_1(struct octfau_desc *);
62 void octfau_op_add_8(struct octfau_desc *, int64_t);
63 void octfau_op_add_4(struct octfau_desc *, int32_t);
64 void octfau_op_add_2(struct octfau_desc *, int16_t);
65 void octfau_op_add_1(struct octfau_desc *, int8_t);
66 void octfau_op_set_8(struct octfau_desc *, int64_t);
67 void octfau_op_set_4(struct octfau_desc *, int32_t);
68 void octfau_op_set_2(struct octfau_desc *, int16_t);
69 void octfau_op_set_1(struct octfau_desc *, int8_t);
70
71 /* ---- old API */
72
73 /* XXX */
74 #define OCT_FAU_REG_OQ_ADDR_INDEX (0)
75 #define OCT_FAU_REG_ADDR_END (256)
76 /* XXX */
77
78 /* XXX */
79 typedef enum {
80 OCT_FAU_OP_SIZE_8 = 0,
81 OCT_FAU_OP_SIZE_16 = 1,
82 OCT_FAU_OP_SIZE_32 = 2,
83 OCT_FAU_OP_SIZE_64 = 3
84 } fau_op_size_t;
85 /* XXX */
86
87 /*
88 * XXX
89 * `scraddr' parameter of IOBDMA operation is actually `index';
90 */
91 static inline void
octfau_op_iobdma(int index,uint64_t args)92 octfau_op_iobdma(int index, uint64_t args)
93 {
94 uint64_t value = IOBDMA_CREATE(FAU_MAJOR_DID, FAU_SUB_DID,
95 index, POW_IOBDMA_LEN, args);
96
97 octeon_iobdma_write_8(value);
98 }
99
100 /* IOBDMA Operations */
101
102 /* IOBDMA Store Data for FAU Operations */
103
104 static inline void
octfau_op_iobdma_store_data(int scraddr,int incval,int tagwait,int size,int reg)105 octfau_op_iobdma_store_data(int scraddr, int incval, int tagwait,
106 int size, int reg)
107 {
108 uint64_t args =
109 __SHIFTIN(incval, POW_IOBDMA_INCVAL) |
110 __SHIFTIN(tagwait, POW_IOBDMA_TAGWAIT) |
111 __SHIFTIN(size, POW_IOBDMA_SIZE) |
112 __SHIFTIN(reg, POW_IOBDMA_REG);
113
114 /* `scraddr' parameter of IOBDMA operation is actually `index' */
115 octfau_op_iobdma(scraddr / sizeof(uint64_t), args);
116 }
117
118 static inline void
octfau_op_inc_fetch_8(struct octfau_desc * fd,int64_t v)119 octfau_op_inc_fetch_8(struct octfau_desc *fd, int64_t v)
120 {
121
122 octfau_op_iobdma_store_data(fd->fd_scroff, v, 0,
123 OCT_FAU_OP_SIZE_64/* XXX */, fd->fd_regno);
124 }
125
126 static inline int64_t
octfau_op_inc_read_8(struct octfau_desc * fd)127 octfau_op_inc_read_8(struct octfau_desc *fd)
128 {
129
130 OCTEON_SYNCIOBDMA;
131 return octeon_cvmseg_read_8(fd->fd_scroff);
132 }
133
134 #endif /* _OCTEON_FAUVAR_H_ */
135