]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/contrib/octeon-sdk/cvmx-hfa.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / contrib / octeon-sdk / cvmx-hfa.c
1 /***********************license start***************
2  * Copyright (c) 2011  Cavium Inc. (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 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
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 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**************************************/
39
40
41
42
43
44
45
46 /**
47  * @file
48  *
49  * Support library for the CN63XX, CN68XX hardware HFA engine.
50  *
51  */
52 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
53 #include <asm/octeon/cvmx.h>
54 #include <asm/octeon/cvmx-config.h>
55 #include <asm/octeon/cvmx-pko.h>
56 #include <asm/octeon/cvmx-helper.h>
57 #include <asm/octeon/cvmx-clock.h>
58 #include <asm/octeon/cvmx-dfa-defs.h>
59 #include <asm/octeon/cvmx-hfa.h>
60 #else
61 #include "executive-config.h"
62 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
63
64 #include "cvmx-config.h"
65 #include "cvmx.h"
66 #include "cvmx-fau.h"
67 #include "cvmx-cmd-queue.h"
68 #include "cvmx-hfa.h"
69 #endif
70 #endif
71
72 #ifdef CVMX_ENABLE_DFA_FUNCTIONS
73
74 /**
75  * Initialize the DFA block
76  *
77  * @return Zero on success, negative on failure
78  */
79 int cvmx_hfa_initialize(void)
80 {
81     cvmx_dfa_difctl_t control;
82     cvmx_cmd_queue_result_t result;
83     void *initial_base_address;
84     int cmdsize;
85
86     cmdsize = ((CVMX_FPA_DFA_POOL_SIZE - 8) / sizeof (cvmx_dfa_command_t)) *
87         sizeof (cvmx_dfa_command_t);
88     result = cvmx_cmd_queue_initialize(CVMX_CMD_QUEUE_DFA, 0,
89                                        CVMX_FPA_DFA_POOL, cmdsize + 8);
90     if (result != CVMX_CMD_QUEUE_SUCCESS)
91         return -1;
92
93     control.u64 = 0;
94     control.s.dwbcnt = CVMX_FPA_DFA_POOL_SIZE / 128;
95     control.s.pool = CVMX_FPA_DFA_POOL;
96     control.s.size = cmdsize / sizeof(cvmx_dfa_command_t);
97     CVMX_SYNCWS;
98     cvmx_write_csr(CVMX_DFA_DIFCTL, control.u64);
99     initial_base_address = cvmx_cmd_queue_buffer(CVMX_CMD_QUEUE_DFA);
100     CVMX_SYNCWS;
101     cvmx_write_csr(CVMX_DFA_DIFRDPTR, cvmx_ptr_to_phys(initial_base_address));
102     cvmx_read_csr(CVMX_DFA_DIFRDPTR); /* Read to make sure setup is complete */
103     return 0;
104 }
105 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
106 EXPORT_SYMBOL(cvmx_hfa_initialize);
107 #endif
108
109 /**
110  * Shutdown the DFA block. DFA must be idle when
111  * this function is called.
112  *
113  * @return Zero on success, negative on failure
114  */
115 int cvmx_hfa_shutdown(void)
116 {
117     if (cvmx_cmd_queue_length(CVMX_CMD_QUEUE_DFA))
118     {
119         cvmx_dprintf("ERROR: cvmx_hfa_shutdown: DFA not idle.\n");
120         return -1;
121     }
122     cvmx_cmd_queue_shutdown(CVMX_CMD_QUEUE_DFA);
123     return 0;
124 }
125 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
126 EXPORT_SYMBOL(cvmx_hfa_shutdown);
127 #endif
128
129 /**
130  * Submit a command to the DFA block
131  *
132  * @param command DFA command to submit
133  *
134  * @return Zero on success, negative on failure
135  */
136 int cvmx_hfa_submit(cvmx_dfa_command_t *command)
137 {
138     cvmx_cmd_queue_result_t result = cvmx_cmd_queue_write(CVMX_CMD_QUEUE_DFA, 1, 4, command->u64);
139     if (result == CVMX_CMD_QUEUE_SUCCESS)
140         cvmx_write_csr(CVMX_DFA_DBELL, 1);
141     return result;
142 }
143 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
144 EXPORT_SYMBOL(cvmx_hfa_submit);
145 #endif
146
147 void *hfa_bootmem_alloc (uint64_t size, uint64_t alignment)
148 {
149     int64_t address;
150
151     address = cvmx_bootmem_phy_alloc(size, 0, 0, alignment, 0);
152
153     if (address > 0)
154         return cvmx_phys_to_ptr(address);
155     else
156         return NULL;
157 }
158
159 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
160 EXPORT_SYMBOL(hfa_bootmem_alloc);
161 #endif
162
163 int  hfa_bootmem_free (void *ptr, uint64_t size)
164 {       
165         uint64_t address;
166         address = cvmx_ptr_to_phys (ptr);
167         return __cvmx_bootmem_phy_free (address, size, 0);
168 }
169
170 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
171 EXPORT_SYMBOL(hfa_bootmem_free);
172 #endif
173
174 #endif