1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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.
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
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
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. 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**************************************/
49 * Support library for the CN31XX, CN38XX, and CN58XX hardware DFA engine.
51 * <hr>$Revision: 70030 $<hr>
53 #include "executive-config.h"
54 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
56 #include "cvmx-config.h"
64 * Initialize the DFA hardware before use
66 int cvmx_dfa_initialize(void)
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))
73 cvmx_dprintf("ERROR: attempting to initialize DFA when no DFA hardware present\n.");
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);
82 cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64);
84 initial_base_address = cvmx_fpa_alloc(CVMX_FPA_DFA_POOL);
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);
91 cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address));
98 * Shutdown and cleanup resources used by the DFA
100 void cvmx_dfa_shutdown(void)
102 void *final_base_address;
103 cvmx_dfa_state_t final_state;
107 final_state.u64 = cvmx_fau_fetch_and_add64(CVMX_FAU_DFA_STATE, 0);
109 // make sure the carry is clear
110 final_base_address = CASTPTR(void, (final_state.s2.base_address_div32 * 32ull));
112 if (final_base_address)
114 cvmx_fpa_free(final_base_address, CVMX_FPA_DFA_POOL, 0);
119 cvmx_fau_atomic_write64(CVMX_FAU_DFA_STATE, final_state.u64);