1 /* $OpenBSD: cn30xxfauvar.h,v 1.3 2016/07/10 10:18:58 visa 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 _CN30XXFAUVAR_H_ 30 #define _CN30XXFAUVAR_H_ 31 32 /* ---- API */ 33 34 struct cn30xxfau_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 cn30xxfau_op_init(struct cn30xxfau_desc *, size_t, size_t); 42 uint64_t cn30xxfau_op_save(struct cn30xxfau_desc *); 43 void cn30xxfau_op_restore(struct cn30xxfau_desc *, uint64_t); 44 int64_t cn30xxfau_op_inc_8(struct cn30xxfau_desc *, int64_t); 45 int32_t cn30xxfau_op_inc_4(struct cn30xxfau_desc *, int32_t); 46 int16_t cn30xxfau_op_inc_2(struct cn30xxfau_desc *, int16_t); 47 int8_t cn30xxfau_op_inc_1(struct cn30xxfau_desc *, int8_t); 48 int64_t cn30xxfau_op_incwait_8(struct cn30xxfau_desc *, int); 49 int32_t cn30xxfau_op_incwait_4(struct cn30xxfau_desc *, int); 50 int16_t cn30xxfau_op_incwait_2(struct cn30xxfau_desc *, int); 51 int8_t cn30xxfau_op_incwait_1(struct cn30xxfau_desc *, int); 52 int64_t cn30xxfau_op_get_8(struct cn30xxfau_desc *); 53 int32_t cn30xxfau_op_get_4(struct cn30xxfau_desc *); 54 int16_t cn30xxfau_op_get_2(struct cn30xxfau_desc *); 55 int8_t cn30xxfau_op_get_1(struct cn30xxfau_desc *); 56 int64_t cn30xxfau_op_getwait_8(struct cn30xxfau_desc *); 57 int32_t cn30xxfau_op_getwait_4(struct cn30xxfau_desc *); 58 int16_t cn30xxfau_op_getwait_2(struct cn30xxfau_desc *); 59 int8_t cn30xxfau_op_getwait_1(struct cn30xxfau_desc *); 60 void cn30xxfau_op_add_8(struct cn30xxfau_desc *, int64_t); 61 void cn30xxfau_op_add_4(struct cn30xxfau_desc *, int32_t); 62 void cn30xxfau_op_add_2(struct cn30xxfau_desc *, int16_t); 63 void cn30xxfau_op_add_1(struct cn30xxfau_desc *, int8_t); 64 void cn30xxfau_op_set_8(struct cn30xxfau_desc *, int64_t); 65 void cn30xxfau_op_set_4(struct cn30xxfau_desc *, int32_t); 66 void cn30xxfau_op_set_2(struct cn30xxfau_desc *, int16_t); 67 void cn30xxfau_op_set_1(struct cn30xxfau_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 static inline void 86 cn30xxfau_op_iobdma(int index, uint64_t args) 87 { 88 uint64_t value; 89 90 value = 91 ((uint64_t)(index & 0xff) << 56) | 92 ((uint64_t)1 << 48) | 93 ((uint64_t)(CN30XXFAU_MAJORDID & 0x1f) << 43) | 94 ((uint64_t)(CN30XXFAU_SUBDID & 0x7) << 40) | 95 ((uint64_t)args & 0xfffffffffULL); 96 octeon_iobdma_write_8(value); 97 } 98 99 /* 3.4.2 IOBDMA Operations */ 100 101 /* IOBDMA Store Data for FAU Operations */ 102 103 static inline void 104 cn30xxfau_op_iobdma_store_data(int scraddr, int incval, int tagwait, 105 int size, int reg) 106 { 107 uint64_t args; 108 109 args = 110 ((uint64_t)(incval & 0x3fffff) << 14) | 111 ((uint64_t)(tagwait & 0x1) << 13) | 112 ((uint64_t)(size & 0x3) << 11) | 113 ((uint64_t)(reg & 0x7ff) << 0); 114 /* use `srcaddr` as `index' */ 115 cn30xxfau_op_iobdma((int)((uint32_t)scraddr >> 3) /* XXX */, args); 116 } 117 118 static inline void 119 cn30xxfau_op_inc_fetch_8(struct cn30xxfau_desc *fd, int64_t v) 120 { 121 cn30xxfau_op_iobdma_store_data(fd->fd_scroff, v, 0, OCT_FAU_OP_SIZE_64/* XXX */, 122 fd->fd_regno); 123 } 124 125 static inline int64_t 126 cn30xxfau_op_inc_read_8(struct cn30xxfau_desc *fd) 127 { 128 octeon_synciobdma(); 129 return octeon_cvmseg_read_8(fd->fd_scroff); 130 } 131 132 #endif /* _CN30XXFAUVAR_H_ */ 133