18c2ecf20Sopenharmony_ci/***********************license start*************** 28c2ecf20Sopenharmony_ci * Author: Cavium Networks 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Contact: support@caviumnetworks.com 58c2ecf20Sopenharmony_ci * This file is part of the OCTEON SDK 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2008 Cavium Networks 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 168c2ecf20Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more 178c2ecf20Sopenharmony_ci * details. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 208c2ecf20Sopenharmony_ci * along with this file; if not, write to the Free Software 218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 228c2ecf20Sopenharmony_ci * or visit http://www.gnu.org/licenses/. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * This file may also be available under a different license from Cavium. 258c2ecf20Sopenharmony_ci * Contact Cavium Networks for more information 268c2ecf20Sopenharmony_ci ***********************license end**************************************/ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * Interface to the hardware Fetch and Add Unit. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#ifndef __CVMX_FAU_H__ 338c2ecf20Sopenharmony_ci#define __CVMX_FAU_H__ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * Octeon Fetch and Add Unit (FAU) 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define CVMX_FAU_LOAD_IO_ADDRESS cvmx_build_io_address(0x1e, 0) 408c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_SCRADDR 63, 56 418c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_LEN 55, 48 428c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_INEVAL 35, 14 438c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_TAGWAIT 13, 13 448c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_NOADD 13, 13 458c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_SIZE 12, 11 468c2ecf20Sopenharmony_ci#define CVMX_FAU_BITS_REGISTER 10, 0 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_citypedef enum { 498c2ecf20Sopenharmony_ci CVMX_FAU_OP_SIZE_8 = 0, 508c2ecf20Sopenharmony_ci CVMX_FAU_OP_SIZE_16 = 1, 518c2ecf20Sopenharmony_ci CVMX_FAU_OP_SIZE_32 = 2, 528c2ecf20Sopenharmony_ci CVMX_FAU_OP_SIZE_64 = 3 538c2ecf20Sopenharmony_ci} cvmx_fau_op_size_t; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/** 568c2ecf20Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error 578c2ecf20Sopenharmony_ci * bit will be set. Otherwise the value of the register before 588c2ecf20Sopenharmony_ci * the update will be returned. 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_citypedef struct { 618c2ecf20Sopenharmony_ci uint64_t error:1; 628c2ecf20Sopenharmony_ci int64_t value:63; 638c2ecf20Sopenharmony_ci} cvmx_fau_tagwait64_t; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/** 668c2ecf20Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error 678c2ecf20Sopenharmony_ci * bit will be set. Otherwise the value of the register before 688c2ecf20Sopenharmony_ci * the update will be returned. 698c2ecf20Sopenharmony_ci */ 708c2ecf20Sopenharmony_citypedef struct { 718c2ecf20Sopenharmony_ci uint64_t error:1; 728c2ecf20Sopenharmony_ci int32_t value:31; 738c2ecf20Sopenharmony_ci} cvmx_fau_tagwait32_t; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/** 768c2ecf20Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error 778c2ecf20Sopenharmony_ci * bit will be set. Otherwise the value of the register before 788c2ecf20Sopenharmony_ci * the update will be returned. 798c2ecf20Sopenharmony_ci */ 808c2ecf20Sopenharmony_citypedef struct { 818c2ecf20Sopenharmony_ci uint64_t error:1; 828c2ecf20Sopenharmony_ci int16_t value:15; 838c2ecf20Sopenharmony_ci} cvmx_fau_tagwait16_t; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/** 868c2ecf20Sopenharmony_ci * Tagwait return definition. If a timeout occurs, the error 878c2ecf20Sopenharmony_ci * bit will be set. Otherwise the value of the register before 888c2ecf20Sopenharmony_ci * the update will be returned. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_citypedef struct { 918c2ecf20Sopenharmony_ci uint64_t error:1; 928c2ecf20Sopenharmony_ci int8_t value:7; 938c2ecf20Sopenharmony_ci} cvmx_fau_tagwait8_t; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/** 968c2ecf20Sopenharmony_ci * Asynchronous tagwait return definition. If a timeout occurs, 978c2ecf20Sopenharmony_ci * the error bit will be set. Otherwise the value of the 988c2ecf20Sopenharmony_ci * register before the update will be returned. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_citypedef union { 1018c2ecf20Sopenharmony_ci uint64_t u64; 1028c2ecf20Sopenharmony_ci struct { 1038c2ecf20Sopenharmony_ci uint64_t invalid:1; 1048c2ecf20Sopenharmony_ci uint64_t data:63; /* unpredictable if invalid is set */ 1058c2ecf20Sopenharmony_ci } s; 1068c2ecf20Sopenharmony_ci} cvmx_fau_async_tagwait_result_t; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN_BITFIELD 1098c2ecf20Sopenharmony_ci#define SWIZZLE_8 0 1108c2ecf20Sopenharmony_ci#define SWIZZLE_16 0 1118c2ecf20Sopenharmony_ci#define SWIZZLE_32 0 1128c2ecf20Sopenharmony_ci#else 1138c2ecf20Sopenharmony_ci#define SWIZZLE_8 0x7 1148c2ecf20Sopenharmony_ci#define SWIZZLE_16 0x6 1158c2ecf20Sopenharmony_ci#define SWIZZLE_32 0x4 1168c2ecf20Sopenharmony_ci#endif 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/** 1198c2ecf20Sopenharmony_ci * Builds a store I/O address for writing to the FAU 1208c2ecf20Sopenharmony_ci * 1218c2ecf20Sopenharmony_ci * @noadd: 0 = Store value is atomically added to the current value 1228c2ecf20Sopenharmony_ci * 1 = Store value is atomically written over the current value 1238c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 1248c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 1258c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 1268c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 1278c2ecf20Sopenharmony_ci * Returns Address to store for atomic update 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistatic inline uint64_t __cvmx_fau_store_address(uint64_t noadd, uint64_t reg) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) | 1328c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_NOADD, noadd) | 1338c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg); 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/** 1378c2ecf20Sopenharmony_ci * Builds a I/O address for accessing the FAU 1388c2ecf20Sopenharmony_ci * 1398c2ecf20Sopenharmony_ci * @tagwait: Should the atomic add wait for the current tag switch 1408c2ecf20Sopenharmony_ci * operation to complete. 1418c2ecf20Sopenharmony_ci * - 0 = Don't wait 1428c2ecf20Sopenharmony_ci * - 1 = Wait for tag switch to complete 1438c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 1448c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 1458c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 1468c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 1478c2ecf20Sopenharmony_ci * @value: Signed value to add. 1488c2ecf20Sopenharmony_ci * Note: When performing 32 and 64 bit access, only the low 1498c2ecf20Sopenharmony_ci * 22 bits are available. 1508c2ecf20Sopenharmony_ci * Returns Address to read from for atomic update 1518c2ecf20Sopenharmony_ci */ 1528c2ecf20Sopenharmony_cistatic inline uint64_t __cvmx_fau_atomic_address(uint64_t tagwait, uint64_t reg, 1538c2ecf20Sopenharmony_ci int64_t value) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci return CVMX_ADD_IO_SEG(CVMX_FAU_LOAD_IO_ADDRESS) | 1568c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) | 1578c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) | 1588c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg); 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci/** 1628c2ecf20Sopenharmony_ci * Perform an atomic 64 bit add 1638c2ecf20Sopenharmony_ci * 1648c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 1658c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 1668c2ecf20Sopenharmony_ci * @value: Signed value to add. 1678c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 1688c2ecf20Sopenharmony_ci * Returns Value of the register before the update 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_cistatic inline int64_t cvmx_fau_fetch_and_add64(cvmx_fau_reg_64_t reg, 1718c2ecf20Sopenharmony_ci int64_t value) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci return cvmx_read64_int64(__cvmx_fau_atomic_address(0, reg, value)); 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci/** 1778c2ecf20Sopenharmony_ci * Perform an atomic 32 bit add 1788c2ecf20Sopenharmony_ci * 1798c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 1808c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 1818c2ecf20Sopenharmony_ci * @value: Signed value to add. 1828c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 1838c2ecf20Sopenharmony_ci * Returns Value of the register before the update 1848c2ecf20Sopenharmony_ci */ 1858c2ecf20Sopenharmony_cistatic inline int32_t cvmx_fau_fetch_and_add32(cvmx_fau_reg_32_t reg, 1868c2ecf20Sopenharmony_ci int32_t value) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci reg ^= SWIZZLE_32; 1898c2ecf20Sopenharmony_ci return cvmx_read64_int32(__cvmx_fau_atomic_address(0, reg, value)); 1908c2ecf20Sopenharmony_ci} 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci/** 1938c2ecf20Sopenharmony_ci * Perform an atomic 16 bit add 1948c2ecf20Sopenharmony_ci * 1958c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 1968c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 1978c2ecf20Sopenharmony_ci * @value: Signed value to add. 1988c2ecf20Sopenharmony_ci * Returns Value of the register before the update 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_cistatic inline int16_t cvmx_fau_fetch_and_add16(cvmx_fau_reg_16_t reg, 2018c2ecf20Sopenharmony_ci int16_t value) 2028c2ecf20Sopenharmony_ci{ 2038c2ecf20Sopenharmony_ci reg ^= SWIZZLE_16; 2048c2ecf20Sopenharmony_ci return cvmx_read64_int16(__cvmx_fau_atomic_address(0, reg, value)); 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/** 2088c2ecf20Sopenharmony_ci * Perform an atomic 8 bit add 2098c2ecf20Sopenharmony_ci * 2108c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 2118c2ecf20Sopenharmony_ci * @value: Signed value to add. 2128c2ecf20Sopenharmony_ci * Returns Value of the register before the update 2138c2ecf20Sopenharmony_ci */ 2148c2ecf20Sopenharmony_cistatic inline int8_t cvmx_fau_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci reg ^= SWIZZLE_8; 2178c2ecf20Sopenharmony_ci return cvmx_read64_int8(__cvmx_fau_atomic_address(0, reg, value)); 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci/** 2218c2ecf20Sopenharmony_ci * Perform an atomic 64 bit add after the current tag switch 2228c2ecf20Sopenharmony_ci * completes 2238c2ecf20Sopenharmony_ci * 2248c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 2258c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 2268c2ecf20Sopenharmony_ci * @value: Signed value to add. 2278c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 2288c2ecf20Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise 2298c2ecf20Sopenharmony_ci * the value of the register before the update will be 2308c2ecf20Sopenharmony_ci * returned 2318c2ecf20Sopenharmony_ci */ 2328c2ecf20Sopenharmony_cistatic inline cvmx_fau_tagwait64_t 2338c2ecf20Sopenharmony_cicvmx_fau_tagwait_fetch_and_add64(cvmx_fau_reg_64_t reg, int64_t value) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci union { 2368c2ecf20Sopenharmony_ci uint64_t i64; 2378c2ecf20Sopenharmony_ci cvmx_fau_tagwait64_t t; 2388c2ecf20Sopenharmony_ci } result; 2398c2ecf20Sopenharmony_ci result.i64 = 2408c2ecf20Sopenharmony_ci cvmx_read64_int64(__cvmx_fau_atomic_address(1, reg, value)); 2418c2ecf20Sopenharmony_ci return result.t; 2428c2ecf20Sopenharmony_ci} 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci/** 2458c2ecf20Sopenharmony_ci * Perform an atomic 32 bit add after the current tag switch 2468c2ecf20Sopenharmony_ci * completes 2478c2ecf20Sopenharmony_ci * 2488c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 2498c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 2508c2ecf20Sopenharmony_ci * @value: Signed value to add. 2518c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 2528c2ecf20Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise 2538c2ecf20Sopenharmony_ci * the value of the register before the update will be 2548c2ecf20Sopenharmony_ci * returned 2558c2ecf20Sopenharmony_ci */ 2568c2ecf20Sopenharmony_cistatic inline cvmx_fau_tagwait32_t 2578c2ecf20Sopenharmony_cicvmx_fau_tagwait_fetch_and_add32(cvmx_fau_reg_32_t reg, int32_t value) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci union { 2608c2ecf20Sopenharmony_ci uint64_t i32; 2618c2ecf20Sopenharmony_ci cvmx_fau_tagwait32_t t; 2628c2ecf20Sopenharmony_ci } result; 2638c2ecf20Sopenharmony_ci reg ^= SWIZZLE_32; 2648c2ecf20Sopenharmony_ci result.i32 = 2658c2ecf20Sopenharmony_ci cvmx_read64_int32(__cvmx_fau_atomic_address(1, reg, value)); 2668c2ecf20Sopenharmony_ci return result.t; 2678c2ecf20Sopenharmony_ci} 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci/** 2708c2ecf20Sopenharmony_ci * Perform an atomic 16 bit add after the current tag switch 2718c2ecf20Sopenharmony_ci * completes 2728c2ecf20Sopenharmony_ci * 2738c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 2748c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 2758c2ecf20Sopenharmony_ci * @value: Signed value to add. 2768c2ecf20Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise 2778c2ecf20Sopenharmony_ci * the value of the register before the update will be 2788c2ecf20Sopenharmony_ci * returned 2798c2ecf20Sopenharmony_ci */ 2808c2ecf20Sopenharmony_cistatic inline cvmx_fau_tagwait16_t 2818c2ecf20Sopenharmony_cicvmx_fau_tagwait_fetch_and_add16(cvmx_fau_reg_16_t reg, int16_t value) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci union { 2848c2ecf20Sopenharmony_ci uint64_t i16; 2858c2ecf20Sopenharmony_ci cvmx_fau_tagwait16_t t; 2868c2ecf20Sopenharmony_ci } result; 2878c2ecf20Sopenharmony_ci reg ^= SWIZZLE_16; 2888c2ecf20Sopenharmony_ci result.i16 = 2898c2ecf20Sopenharmony_ci cvmx_read64_int16(__cvmx_fau_atomic_address(1, reg, value)); 2908c2ecf20Sopenharmony_ci return result.t; 2918c2ecf20Sopenharmony_ci} 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/** 2948c2ecf20Sopenharmony_ci * Perform an atomic 8 bit add after the current tag switch 2958c2ecf20Sopenharmony_ci * completes 2968c2ecf20Sopenharmony_ci * 2978c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 2988c2ecf20Sopenharmony_ci * @value: Signed value to add. 2998c2ecf20Sopenharmony_ci * Returns If a timeout occurs, the error bit will be set. Otherwise 3008c2ecf20Sopenharmony_ci * the value of the register before the update will be 3018c2ecf20Sopenharmony_ci * returned 3028c2ecf20Sopenharmony_ci */ 3038c2ecf20Sopenharmony_cistatic inline cvmx_fau_tagwait8_t 3048c2ecf20Sopenharmony_cicvmx_fau_tagwait_fetch_and_add8(cvmx_fau_reg_8_t reg, int8_t value) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci union { 3078c2ecf20Sopenharmony_ci uint64_t i8; 3088c2ecf20Sopenharmony_ci cvmx_fau_tagwait8_t t; 3098c2ecf20Sopenharmony_ci } result; 3108c2ecf20Sopenharmony_ci reg ^= SWIZZLE_8; 3118c2ecf20Sopenharmony_ci result.i8 = cvmx_read64_int8(__cvmx_fau_atomic_address(1, reg, value)); 3128c2ecf20Sopenharmony_ci return result.t; 3138c2ecf20Sopenharmony_ci} 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci/** 3168c2ecf20Sopenharmony_ci * Builds I/O data for async operations 3178c2ecf20Sopenharmony_ci * 3188c2ecf20Sopenharmony_ci * @scraddr: Scratch pad byte address to write to. Must be 8 byte aligned 3198c2ecf20Sopenharmony_ci * @value: Signed value to add. 3208c2ecf20Sopenharmony_ci * Note: When performing 32 and 64 bit access, only the low 3218c2ecf20Sopenharmony_ci * 22 bits are available. 3228c2ecf20Sopenharmony_ci * @tagwait: Should the atomic add wait for the current tag switch 3238c2ecf20Sopenharmony_ci * operation to complete. 3248c2ecf20Sopenharmony_ci * - 0 = Don't wait 3258c2ecf20Sopenharmony_ci * - 1 = Wait for tag switch to complete 3268c2ecf20Sopenharmony_ci * @size: The size of the operation: 3278c2ecf20Sopenharmony_ci * - CVMX_FAU_OP_SIZE_8 (0) = 8 bits 3288c2ecf20Sopenharmony_ci * - CVMX_FAU_OP_SIZE_16 (1) = 16 bits 3298c2ecf20Sopenharmony_ci * - CVMX_FAU_OP_SIZE_32 (2) = 32 bits 3308c2ecf20Sopenharmony_ci * - CVMX_FAU_OP_SIZE_64 (3) = 64 bits 3318c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 3328c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 3338c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 3348c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 3358c2ecf20Sopenharmony_ci * Returns Data to write using cvmx_send_single 3368c2ecf20Sopenharmony_ci */ 3378c2ecf20Sopenharmony_cistatic inline uint64_t __cvmx_fau_iobdma_data(uint64_t scraddr, int64_t value, 3388c2ecf20Sopenharmony_ci uint64_t tagwait, 3398c2ecf20Sopenharmony_ci cvmx_fau_op_size_t size, 3408c2ecf20Sopenharmony_ci uint64_t reg) 3418c2ecf20Sopenharmony_ci{ 3428c2ecf20Sopenharmony_ci return CVMX_FAU_LOAD_IO_ADDRESS | 3438c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_SCRADDR, scraddr >> 3) | 3448c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_LEN, 1) | 3458c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_INEVAL, value) | 3468c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_TAGWAIT, tagwait) | 3478c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_SIZE, size) | 3488c2ecf20Sopenharmony_ci cvmx_build_bits(CVMX_FAU_BITS_REGISTER, reg); 3498c2ecf20Sopenharmony_ci} 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci/** 3528c2ecf20Sopenharmony_ci * Perform an async atomic 64 bit add. The old value is 3538c2ecf20Sopenharmony_ci * placed in the scratch memory at byte address scraddr. 3548c2ecf20Sopenharmony_ci * 3558c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. 3568c2ecf20Sopenharmony_ci * Must be 8 byte aligned. 3578c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 3588c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 3598c2ecf20Sopenharmony_ci * @value: Signed value to add. 3608c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 3618c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 3628c2ecf20Sopenharmony_ci */ 3638c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add64(uint64_t scraddr, 3648c2ecf20Sopenharmony_ci cvmx_fau_reg_64_t reg, 3658c2ecf20Sopenharmony_ci int64_t value) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 3688c2ecf20Sopenharmony_ci (scraddr, value, 0, CVMX_FAU_OP_SIZE_64, reg)); 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci/** 3728c2ecf20Sopenharmony_ci * Perform an async atomic 32 bit add. The old value is 3738c2ecf20Sopenharmony_ci * placed in the scratch memory at byte address scraddr. 3748c2ecf20Sopenharmony_ci * 3758c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. 3768c2ecf20Sopenharmony_ci * Must be 8 byte aligned. 3778c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 3788c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 3798c2ecf20Sopenharmony_ci * @value: Signed value to add. 3808c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 3818c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 3828c2ecf20Sopenharmony_ci */ 3838c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add32(uint64_t scraddr, 3848c2ecf20Sopenharmony_ci cvmx_fau_reg_32_t reg, 3858c2ecf20Sopenharmony_ci int32_t value) 3868c2ecf20Sopenharmony_ci{ 3878c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 3888c2ecf20Sopenharmony_ci (scraddr, value, 0, CVMX_FAU_OP_SIZE_32, reg)); 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/** 3928c2ecf20Sopenharmony_ci * Perform an async atomic 16 bit add. The old value is 3938c2ecf20Sopenharmony_ci * placed in the scratch memory at byte address scraddr. 3948c2ecf20Sopenharmony_ci * 3958c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. 3968c2ecf20Sopenharmony_ci * Must be 8 byte aligned. 3978c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 3988c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 3998c2ecf20Sopenharmony_ci * @value: Signed value to add. 4008c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 4018c2ecf20Sopenharmony_ci */ 4028c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add16(uint64_t scraddr, 4038c2ecf20Sopenharmony_ci cvmx_fau_reg_16_t reg, 4048c2ecf20Sopenharmony_ci int16_t value) 4058c2ecf20Sopenharmony_ci{ 4068c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 4078c2ecf20Sopenharmony_ci (scraddr, value, 0, CVMX_FAU_OP_SIZE_16, reg)); 4088c2ecf20Sopenharmony_ci} 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci/** 4118c2ecf20Sopenharmony_ci * Perform an async atomic 8 bit add. The old value is 4128c2ecf20Sopenharmony_ci * placed in the scratch memory at byte address scraddr. 4138c2ecf20Sopenharmony_ci * 4148c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. 4158c2ecf20Sopenharmony_ci * Must be 8 byte aligned. 4168c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 4178c2ecf20Sopenharmony_ci * @value: Signed value to add. 4188c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 4198c2ecf20Sopenharmony_ci */ 4208c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_fetch_and_add8(uint64_t scraddr, 4218c2ecf20Sopenharmony_ci cvmx_fau_reg_8_t reg, 4228c2ecf20Sopenharmony_ci int8_t value) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 4258c2ecf20Sopenharmony_ci (scraddr, value, 0, CVMX_FAU_OP_SIZE_8, reg)); 4268c2ecf20Sopenharmony_ci} 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci/** 4298c2ecf20Sopenharmony_ci * Perform an async atomic 64 bit add after the current tag 4308c2ecf20Sopenharmony_ci * switch completes. 4318c2ecf20Sopenharmony_ci * 4328c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. Must be 4338c2ecf20Sopenharmony_ci * 8 byte aligned. If a timeout occurs, the error bit (63) 4348c2ecf20Sopenharmony_ci * will be set. Otherwise the value of the register before 4358c2ecf20Sopenharmony_ci * the update will be returned 4368c2ecf20Sopenharmony_ci * 4378c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 4388c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 4398c2ecf20Sopenharmony_ci * @value: Signed value to add. 4408c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 4418c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 4428c2ecf20Sopenharmony_ci */ 4438c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add64(uint64_t scraddr, 4448c2ecf20Sopenharmony_ci cvmx_fau_reg_64_t reg, 4458c2ecf20Sopenharmony_ci int64_t value) 4468c2ecf20Sopenharmony_ci{ 4478c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 4488c2ecf20Sopenharmony_ci (scraddr, value, 1, CVMX_FAU_OP_SIZE_64, reg)); 4498c2ecf20Sopenharmony_ci} 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci/** 4528c2ecf20Sopenharmony_ci * Perform an async atomic 32 bit add after the current tag 4538c2ecf20Sopenharmony_ci * switch completes. 4548c2ecf20Sopenharmony_ci * 4558c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. Must be 4568c2ecf20Sopenharmony_ci * 8 byte aligned. If a timeout occurs, the error bit (63) 4578c2ecf20Sopenharmony_ci * will be set. Otherwise the value of the register before 4588c2ecf20Sopenharmony_ci * the update will be returned 4598c2ecf20Sopenharmony_ci * 4608c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 4618c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 4628c2ecf20Sopenharmony_ci * @value: Signed value to add. 4638c2ecf20Sopenharmony_ci * Note: Only the low 22 bits are available. 4648c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 4658c2ecf20Sopenharmony_ci */ 4668c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add32(uint64_t scraddr, 4678c2ecf20Sopenharmony_ci cvmx_fau_reg_32_t reg, 4688c2ecf20Sopenharmony_ci int32_t value) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 4718c2ecf20Sopenharmony_ci (scraddr, value, 1, CVMX_FAU_OP_SIZE_32, reg)); 4728c2ecf20Sopenharmony_ci} 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci/** 4758c2ecf20Sopenharmony_ci * Perform an async atomic 16 bit add after the current tag 4768c2ecf20Sopenharmony_ci * switch completes. 4778c2ecf20Sopenharmony_ci * 4788c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. Must be 4798c2ecf20Sopenharmony_ci * 8 byte aligned. If a timeout occurs, the error bit (63) 4808c2ecf20Sopenharmony_ci * will be set. Otherwise the value of the register before 4818c2ecf20Sopenharmony_ci * the update will be returned 4828c2ecf20Sopenharmony_ci * 4838c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 4848c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 4858c2ecf20Sopenharmony_ci * @value: Signed value to add. 4868c2ecf20Sopenharmony_ci * 4878c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 4888c2ecf20Sopenharmony_ci */ 4898c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add16(uint64_t scraddr, 4908c2ecf20Sopenharmony_ci cvmx_fau_reg_16_t reg, 4918c2ecf20Sopenharmony_ci int16_t value) 4928c2ecf20Sopenharmony_ci{ 4938c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 4948c2ecf20Sopenharmony_ci (scraddr, value, 1, CVMX_FAU_OP_SIZE_16, reg)); 4958c2ecf20Sopenharmony_ci} 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci/** 4988c2ecf20Sopenharmony_ci * Perform an async atomic 8 bit add after the current tag 4998c2ecf20Sopenharmony_ci * switch completes. 5008c2ecf20Sopenharmony_ci * 5018c2ecf20Sopenharmony_ci * @scraddr: Scratch memory byte address to put response in. Must be 5028c2ecf20Sopenharmony_ci * 8 byte aligned. If a timeout occurs, the error bit (63) 5038c2ecf20Sopenharmony_ci * will be set. Otherwise the value of the register before 5048c2ecf20Sopenharmony_ci * the update will be returned 5058c2ecf20Sopenharmony_ci * 5068c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5078c2ecf20Sopenharmony_ci * @value: Signed value to add. 5088c2ecf20Sopenharmony_ci * 5098c2ecf20Sopenharmony_ci * Returns Placed in the scratch pad register 5108c2ecf20Sopenharmony_ci */ 5118c2ecf20Sopenharmony_cistatic inline void cvmx_fau_async_tagwait_fetch_and_add8(uint64_t scraddr, 5128c2ecf20Sopenharmony_ci cvmx_fau_reg_8_t reg, 5138c2ecf20Sopenharmony_ci int8_t value) 5148c2ecf20Sopenharmony_ci{ 5158c2ecf20Sopenharmony_ci cvmx_send_single(__cvmx_fau_iobdma_data 5168c2ecf20Sopenharmony_ci (scraddr, value, 1, CVMX_FAU_OP_SIZE_8, reg)); 5178c2ecf20Sopenharmony_ci} 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci/** 5208c2ecf20Sopenharmony_ci * Perform an atomic 64 bit add 5218c2ecf20Sopenharmony_ci * 5228c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5238c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 5248c2ecf20Sopenharmony_ci * @value: Signed value to add. 5258c2ecf20Sopenharmony_ci */ 5268c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_add64(cvmx_fau_reg_64_t reg, int64_t value) 5278c2ecf20Sopenharmony_ci{ 5288c2ecf20Sopenharmony_ci cvmx_write64_int64(__cvmx_fau_store_address(0, reg), value); 5298c2ecf20Sopenharmony_ci} 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci/** 5328c2ecf20Sopenharmony_ci * Perform an atomic 32 bit add 5338c2ecf20Sopenharmony_ci * 5348c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5358c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 5368c2ecf20Sopenharmony_ci * @value: Signed value to add. 5378c2ecf20Sopenharmony_ci */ 5388c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_add32(cvmx_fau_reg_32_t reg, int32_t value) 5398c2ecf20Sopenharmony_ci{ 5408c2ecf20Sopenharmony_ci reg ^= SWIZZLE_32; 5418c2ecf20Sopenharmony_ci cvmx_write64_int32(__cvmx_fau_store_address(0, reg), value); 5428c2ecf20Sopenharmony_ci} 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci/** 5458c2ecf20Sopenharmony_ci * Perform an atomic 16 bit add 5468c2ecf20Sopenharmony_ci * 5478c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5488c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 5498c2ecf20Sopenharmony_ci * @value: Signed value to add. 5508c2ecf20Sopenharmony_ci */ 5518c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_add16(cvmx_fau_reg_16_t reg, int16_t value) 5528c2ecf20Sopenharmony_ci{ 5538c2ecf20Sopenharmony_ci reg ^= SWIZZLE_16; 5548c2ecf20Sopenharmony_ci cvmx_write64_int16(__cvmx_fau_store_address(0, reg), value); 5558c2ecf20Sopenharmony_ci} 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci/** 5588c2ecf20Sopenharmony_ci * Perform an atomic 8 bit add 5598c2ecf20Sopenharmony_ci * 5608c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5618c2ecf20Sopenharmony_ci * @value: Signed value to add. 5628c2ecf20Sopenharmony_ci */ 5638c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_add8(cvmx_fau_reg_8_t reg, int8_t value) 5648c2ecf20Sopenharmony_ci{ 5658c2ecf20Sopenharmony_ci reg ^= SWIZZLE_8; 5668c2ecf20Sopenharmony_ci cvmx_write64_int8(__cvmx_fau_store_address(0, reg), value); 5678c2ecf20Sopenharmony_ci} 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci/** 5708c2ecf20Sopenharmony_ci * Perform an atomic 64 bit write 5718c2ecf20Sopenharmony_ci * 5728c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5738c2ecf20Sopenharmony_ci * - Step by 8 for 64 bit access. 5748c2ecf20Sopenharmony_ci * @value: Signed value to write. 5758c2ecf20Sopenharmony_ci */ 5768c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_write64(cvmx_fau_reg_64_t reg, int64_t value) 5778c2ecf20Sopenharmony_ci{ 5788c2ecf20Sopenharmony_ci cvmx_write64_int64(__cvmx_fau_store_address(1, reg), value); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci/** 5828c2ecf20Sopenharmony_ci * Perform an atomic 32 bit write 5838c2ecf20Sopenharmony_ci * 5848c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5858c2ecf20Sopenharmony_ci * - Step by 4 for 32 bit access. 5868c2ecf20Sopenharmony_ci * @value: Signed value to write. 5878c2ecf20Sopenharmony_ci */ 5888c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_write32(cvmx_fau_reg_32_t reg, int32_t value) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci reg ^= SWIZZLE_32; 5918c2ecf20Sopenharmony_ci cvmx_write64_int32(__cvmx_fau_store_address(1, reg), value); 5928c2ecf20Sopenharmony_ci} 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci/** 5958c2ecf20Sopenharmony_ci * Perform an atomic 16 bit write 5968c2ecf20Sopenharmony_ci * 5978c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 5988c2ecf20Sopenharmony_ci * - Step by 2 for 16 bit access. 5998c2ecf20Sopenharmony_ci * @value: Signed value to write. 6008c2ecf20Sopenharmony_ci */ 6018c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_write16(cvmx_fau_reg_16_t reg, int16_t value) 6028c2ecf20Sopenharmony_ci{ 6038c2ecf20Sopenharmony_ci reg ^= SWIZZLE_16; 6048c2ecf20Sopenharmony_ci cvmx_write64_int16(__cvmx_fau_store_address(1, reg), value); 6058c2ecf20Sopenharmony_ci} 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci/** 6088c2ecf20Sopenharmony_ci * Perform an atomic 8 bit write 6098c2ecf20Sopenharmony_ci * 6108c2ecf20Sopenharmony_ci * @reg: FAU atomic register to access. 0 <= reg < 2048. 6118c2ecf20Sopenharmony_ci * @value: Signed value to write. 6128c2ecf20Sopenharmony_ci */ 6138c2ecf20Sopenharmony_cistatic inline void cvmx_fau_atomic_write8(cvmx_fau_reg_8_t reg, int8_t value) 6148c2ecf20Sopenharmony_ci{ 6158c2ecf20Sopenharmony_ci reg ^= SWIZZLE_8; 6168c2ecf20Sopenharmony_ci cvmx_write64_int8(__cvmx_fau_store_address(1, reg), value); 6178c2ecf20Sopenharmony_ci} 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci#endif /* __CVMX_FAU_H__ */ 620