cvmx-dfa.c revision 215990
1/***********************license start*************** 2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 3 * reserved. 4 * 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * * Redistributions in binary form must reproduce the above 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials provided 16 * with the distribution. 17 18 * * Neither the name of Cavium Networks nor the names of 19 * its contributors may be used to endorse or promote products 20 * derived from this software without specific prior written 21 * permission. 22 23 * This Software, including technical data, may be subject to U.S. export control 24 * laws, including the U.S. Export Administration Act and its associated 25 * regulations, and may be subject to export or import regulations in other 26 * countries. 27 28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR 30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 38 ***********************license end**************************************/ 39 40 41 42 43 44 45 46/** 47 * @file 48 * 49 * Support library for the CN31XX, CN38XX, and CN58XX hardware DFA engine. 50 * 51 * <hr>$Revision: 49448 $<hr> 52 */ 53#include "executive-config.h" 54#ifdef CVMX_ENABLE_DFA_FUNCTIONS 55 56#include "cvmx-config.h" 57#include "cvmx.h" 58#include "cvmx-fau.h" 59#include "cvmx-dfa.h" 60 61 62 63/** 64 * Initialize the DFA hardware before use 65 */ 66int cvmx_dfa_initialize(void) 67{ 68 cvmx_dfa_difctl_t control; 69 void *initial_base_address; 70 cvmx_dfa_state_t initial_state; 71 if (!octeon_has_feature(OCTEON_FEATURE_DFA)) 72 { 73 cvmx_dprintf("ERROR: attempting to initialize DFA when no DFA hardware present\n."); 74 return -1; 75 } 76 77 control.u64 = 0; 78 control.s.dwbcnt = CVMX_FPA_DFA_POOL_SIZE / 128; 79 control.s.pool = CVMX_FPA_DFA_POOL; 80 control.s.size = (CVMX_FPA_DFA_POOL_SIZE - 8) / sizeof(cvmx_dfa_command_t); 81 CVMX_SYNCWS; 82 cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64); 83 84 initial_base_address = cvmx_fpa_alloc(CVMX_FPA_DFA_POOL); 85 86 initial_state.u64 = 0; 87 initial_state.s.base_address_div16 = (CAST64(initial_base_address))/16; 88 cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, initial_state.u64); 89 90 CVMX_SYNCWS; 91 cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address)); 92 93 return 0; 94} 95 96 97/** 98 * Shutdown and cleanup resources used by the DFA 99 */ 100void cvmx_dfa_shutdown(void) 101{ 102 void *final_base_address; 103 cvmx_dfa_state_t final_state; 104 105 CVMX_SYNCWS; 106 107 final_state.u64 = cvmx_fau_fetch_and_add64(CVMX_FAU_DFA_STATE, 0); 108 109 // make sure the carry is clear 110 final_base_address = CASTPTR(void, (final_state.s2.base_address_div32 * 32ull)); 111 112 if (final_base_address) 113 { 114 cvmx_fpa_free(final_base_address, CVMX_FPA_DFA_POOL, 0); 115 } 116 117 CVMX_SYNCWS; 118 final_state.u64 = 0; 119 cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, final_state.u64); 120} 121 122#endif 123