octeon_fauvar.h revision 1.2 1 /* $NetBSD: octeon_fauvar.h,v 1.2 2020/05/31 06:27:06 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 /* ---- API */
33
34 struct octfau_desc {
35 /* offset in scratch buffer */
36 size_t fd_scroff; /* XXX offset_t */
37 /* FAU register number */
38 size_t fd_regno; /* XXX offset_t */
39 };
40
41 void octfau_op_init(struct octfau_desc *, size_t, size_t);
42 uint64_t octfau_op_save(struct octfau_desc *);
43 void octfau_op_restore(struct octfau_desc *, uint64_t);
44 int64_t octfau_op_inc_8(struct octfau_desc *, int64_t);
45 int32_t octfau_op_inc_4(struct octfau_desc *, int32_t);
46 int16_t octfau_op_inc_2(struct octfau_desc *, int16_t);
47 int8_t octfau_op_inc_1(struct octfau_desc *, int8_t);
48 int64_t octfau_op_incwait_8(struct octfau_desc *, int);
49 int32_t octfau_op_incwait_4(struct octfau_desc *, int);
50 int16_t octfau_op_incwait_2(struct octfau_desc *, int);
51 int8_t octfau_op_incwait_1(struct octfau_desc *, int);
52 int64_t octfau_op_get_8(struct octfau_desc *);
53 int32_t octfau_op_get_4(struct octfau_desc *);
54 int16_t octfau_op_get_2(struct octfau_desc *);
55 int8_t octfau_op_get_1(struct octfau_desc *);
56 int64_t octfau_op_getwait_8(struct octfau_desc *);
57 int32_t octfau_op_getwait_4(struct octfau_desc *);
58 int16_t octfau_op_getwait_2(struct octfau_desc *);
59 int8_t octfau_op_getwait_1(struct octfau_desc *);
60 void octfau_op_add_8(struct octfau_desc *, int64_t);
61 void octfau_op_add_4(struct octfau_desc *, int32_t);
62 void octfau_op_add_2(struct octfau_desc *, int16_t);
63 void octfau_op_add_1(struct octfau_desc *, int8_t);
64 void octfau_op_set_8(struct octfau_desc *, int64_t);
65 void octfau_op_set_4(struct octfau_desc *, int32_t);
66 void octfau_op_set_2(struct octfau_desc *, int16_t);
67 void octfau_op_set_1(struct octfau_desc *, int8_t);
68
69 /* ---- old API */
70
71 /* XXX */
72 #define OCT_FAU_REG_OQ_ADDR_INDEX (0)
73 #define OCT_FAU_REG_ADDR_END (256)
74 /* XXX */
75
76 /* XXX */
77 typedef enum {
78 OCT_FAU_OP_SIZE_8 = 0,
79 OCT_FAU_OP_SIZE_16 = 1,
80 OCT_FAU_OP_SIZE_32 = 2,
81 OCT_FAU_OP_SIZE_64 = 3
82 } fau_op_size_t;
83 /* XXX */
84
85 /*
86 * XXX
87 * `scraddr' parameter of IOBDMA operation is actually `index';
88 */
89 static inline void
90 octfau_op_iobdma(int index, uint64_t args)
91 {
92 uint64_t value;
93
94 value =
95 ((uint64_t)(index & 0xff) << 56) |
96 ((uint64_t)1 << 48) |
97 ((uint64_t)(CN30XXFAU_MAJORDID & 0x1f) << 43) |
98 ((uint64_t)(CN30XXFAU_SUBDID & 0x7) << 40) |
99 ((uint64_t)args & 0xfffffffffULL);
100 octeon_iobdma_write_8(value);
101 }
102
103 /* IOBDMA Operations */
104
105 /* IOBDMA Store Data for FAU Operations */
106
107 static inline void
108 octfau_op_iobdma_store_data(int scraddr, int incval, int tagwait,
109 int size, int reg)
110 {
111 uint64_t args;
112
113 args =
114 ((uint64_t)(incval & 0x3fffff) << 14) |
115 ((uint64_t)(tagwait & 0x1) << 13) |
116 ((uint64_t)(size & 0x3) << 11) |
117 ((uint64_t)(reg & 0x7ff) << 0);
118 /*
119 * `scraddr' parameter of IOBDMA operation is actually `index';
120 */
121 octfau_op_iobdma((int)((uint32_t)scraddr >> 3) /* XXX */, args);
122 }
123
124 static inline void
125 octfau_op_inc_fetch_8(struct octfau_desc *fd, int64_t v)
126 {
127 octfau_op_iobdma_store_data(fd->fd_scroff, v, 0, OCT_FAU_OP_SIZE_64/* XXX */,
128 fd->fd_regno);
129 }
130
131 static inline int64_t
132 octfau_op_inc_read_8(struct octfau_desc *fd)
133 {
134 OCTEON_SYNCIOBDMA;
135 return octeon_cvmseg_read_8(fd->fd_scroff);
136 }
137
138 #endif /* _OCTEON_FAUVAR_H_ */
139