• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/arch/mips/include/asm/octeon/
1/***********************license start***************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2008 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT.  See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26 ***********************license end**************************************/
27
28/*
29 *
30 * File defining different Octeon model IDs and macros to
31 * compare them.
32 *
33 */
34
35#ifndef __OCTEON_MODEL_H__
36#define __OCTEON_MODEL_H__
37
38/* NOTE: These must match what is checked in common-config.mk */
39/* Defines to represent the different versions of Octeon.  */
40
41/*
42 * IMPORTANT: When the default pass is updated for an Octeon Model,
43 * the corresponding change must also be made in the oct-sim script.
44 */
45
46/*
47 * The defines below should be used with the OCTEON_IS_MODEL() macro
48 * to determine what model of chip the software is running on.  Models
49 * ending in 'XX' match multiple models (families), while specific
50 * models match only that model.  If a pass (revision) is specified,
51 * then only that revision will be matched.  Care should be taken when
52 * checking for both specific models and families that the specific
53 * models are checked for first.  While these defines are similar to
54 * the processor ID, they are not intended to be used by anything
55 * other that the OCTEON_IS_MODEL framework, and the values are
56 * subject to change at anytime without notice.
57 *
58 * NOTE: only the OCTEON_IS_MODEL() macro/function and the OCTEON_CN*
59 * macros should be used outside of this file.  All other macros are
60 * for internal use only, and may change without notice.
61 */
62
63/* Flag bits in top byte */
64/* Ignores revision in model checks */
65#define OM_IGNORE_REVISION        0x01000000
66/* Check submodels */
67#define OM_CHECK_SUBMODEL         0x02000000
68/* Match all models previous than the one specified */
69#define OM_MATCH_PREVIOUS_MODELS  0x04000000
70/* Ignores the minor revison on newer parts */
71#define OM_IGNORE_MINOR_REVISION  0x08000000
72#define OM_FLAG_MASK              0xff000000
73
74/*
75 * CN5XXX models with new revision encoding
76 */
77#define OCTEON_CN58XX_PASS1_0   0x000d0300
78#define OCTEON_CN58XX_PASS1_1   0x000d0301
79#define OCTEON_CN58XX_PASS1_2   0x000d0303
80#define OCTEON_CN58XX_PASS2_0   0x000d0308
81#define OCTEON_CN58XX_PASS2_1   0x000d0309
82#define OCTEON_CN58XX_PASS2_2   0x000d030a
83#define OCTEON_CN58XX_PASS2_3   0x000d030b
84
85#define OCTEON_CN58XX           (OCTEON_CN58XX_PASS1_0 | OM_IGNORE_REVISION)
86#define OCTEON_CN58XX_PASS1_X   (OCTEON_CN58XX_PASS1_0 \
87				 | OM_IGNORE_MINOR_REVISION)
88#define OCTEON_CN58XX_PASS2_X   (OCTEON_CN58XX_PASS2_0 \
89				 | OM_IGNORE_MINOR_REVISION)
90#define OCTEON_CN58XX_PASS1     OCTEON_CN58XX_PASS1_X
91#define OCTEON_CN58XX_PASS2     OCTEON_CN58XX_PASS2_X
92
93#define OCTEON_CN56XX_PASS1_0   0x000d0400
94#define OCTEON_CN56XX_PASS1_1   0x000d0401
95#define OCTEON_CN56XX_PASS2_0   0x000d0408
96#define OCTEON_CN56XX_PASS2_1   0x000d0409
97
98#define OCTEON_CN56XX           (OCTEON_CN56XX_PASS2_0 | OM_IGNORE_REVISION)
99#define OCTEON_CN56XX_PASS1_X   (OCTEON_CN56XX_PASS1_0 \
100				 | OM_IGNORE_MINOR_REVISION)
101#define OCTEON_CN56XX_PASS2_X   (OCTEON_CN56XX_PASS2_0 \
102				 | OM_IGNORE_MINOR_REVISION)
103#define OCTEON_CN56XX_PASS1     OCTEON_CN56XX_PASS1_X
104#define OCTEON_CN56XX_PASS2     OCTEON_CN56XX_PASS2_X
105
106#define OCTEON_CN57XX           OCTEON_CN56XX
107#define OCTEON_CN57XX_PASS1     OCTEON_CN56XX_PASS1
108#define OCTEON_CN57XX_PASS2     OCTEON_CN56XX_PASS2
109
110#define OCTEON_CN55XX           OCTEON_CN56XX
111#define OCTEON_CN55XX_PASS1     OCTEON_CN56XX_PASS1
112#define OCTEON_CN55XX_PASS2     OCTEON_CN56XX_PASS2
113
114#define OCTEON_CN54XX           OCTEON_CN56XX
115#define OCTEON_CN54XX_PASS1     OCTEON_CN56XX_PASS1
116#define OCTEON_CN54XX_PASS2     OCTEON_CN56XX_PASS2
117
118#define OCTEON_CN50XX_PASS1_0   0x000d0600
119
120#define OCTEON_CN50XX           (OCTEON_CN50XX_PASS1_0 | OM_IGNORE_REVISION)
121#define OCTEON_CN50XX_PASS1_X   (OCTEON_CN50XX_PASS1_0 \
122				 | OM_IGNORE_MINOR_REVISION)
123#define OCTEON_CN50XX_PASS1     OCTEON_CN50XX_PASS1_X
124
125/*
126 * NOTE: Octeon CN5000F model is not identifiable using the
127 * OCTEON_IS_MODEL() functions, but are treated as CN50XX.
128 */
129
130#define OCTEON_CN52XX_PASS1_0   0x000d0700
131#define OCTEON_CN52XX_PASS2_0   0x000d0708
132
133#define OCTEON_CN52XX           (OCTEON_CN52XX_PASS2_0 | OM_IGNORE_REVISION)
134#define OCTEON_CN52XX_PASS1_X   (OCTEON_CN52XX_PASS1_0 \
135				 | OM_IGNORE_MINOR_REVISION)
136#define OCTEON_CN52XX_PASS2_X   (OCTEON_CN52XX_PASS2_0 \
137				 | OM_IGNORE_MINOR_REVISION)
138#define OCTEON_CN52XX_PASS1     OCTEON_CN52XX_PASS1_X
139#define OCTEON_CN52XX_PASS2     OCTEON_CN52XX_PASS2_X
140
141/*
142 * CN3XXX models with old revision enconding
143 */
144#define OCTEON_CN38XX_PASS1     0x000d0000
145#define OCTEON_CN38XX_PASS2     0x000d0001
146#define OCTEON_CN38XX_PASS3     0x000d0003
147#define OCTEON_CN38XX           (OCTEON_CN38XX_PASS3 | OM_IGNORE_REVISION)
148
149#define OCTEON_CN36XX           OCTEON_CN38XX
150#define OCTEON_CN36XX_PASS2     OCTEON_CN38XX_PASS2
151#define OCTEON_CN36XX_PASS3     OCTEON_CN38XX_PASS3
152
153/* The OCTEON_CN31XX matches CN31XX models and the CN3020 */
154#define OCTEON_CN31XX_PASS1     0x000d0100
155#define OCTEON_CN31XX_PASS1_1   0x000d0102
156#define OCTEON_CN31XX           (OCTEON_CN31XX_PASS1 | OM_IGNORE_REVISION)
157
158/*
159 * This model is only used for internal checks, it is not a valid
160 * model for the OCTEON_MODEL environment variable.  This matches the
161 * CN3010 and CN3005 but NOT the CN3020.
162 */
163#define OCTEON_CN30XX_PASS1     0x000d0200
164#define OCTEON_CN30XX_PASS1_1   0x000d0202
165#define OCTEON_CN30XX           (OCTEON_CN30XX_PASS1 | OM_IGNORE_REVISION)
166
167#define OCTEON_CN3005_PASS1     (0x000d0210 | OM_CHECK_SUBMODEL)
168#define OCTEON_CN3005_PASS1_0   (0x000d0210 | OM_CHECK_SUBMODEL)
169#define OCTEON_CN3005_PASS1_1   (0x000d0212 | OM_CHECK_SUBMODEL)
170#define OCTEON_CN3005           (OCTEON_CN3005_PASS1 | OM_IGNORE_REVISION \
171				 | OM_CHECK_SUBMODEL)
172
173#define OCTEON_CN3010_PASS1     (0x000d0200 | OM_CHECK_SUBMODEL)
174#define OCTEON_CN3010_PASS1_0   (0x000d0200 | OM_CHECK_SUBMODEL)
175#define OCTEON_CN3010_PASS1_1   (0x000d0202 | OM_CHECK_SUBMODEL)
176#define OCTEON_CN3010           (OCTEON_CN3010_PASS1 | OM_IGNORE_REVISION \
177				 | OM_CHECK_SUBMODEL)
178
179#define OCTEON_CN3020_PASS1     (0x000d0110 | OM_CHECK_SUBMODEL)
180#define OCTEON_CN3020_PASS1_0   (0x000d0110 | OM_CHECK_SUBMODEL)
181#define OCTEON_CN3020_PASS1_1   (0x000d0112 | OM_CHECK_SUBMODEL)
182#define OCTEON_CN3020           (OCTEON_CN3020_PASS1 | OM_IGNORE_REVISION \
183				 | OM_CHECK_SUBMODEL)
184
185
186
187/* This matches the complete family of CN3xxx CPUs, and not subsequent models */
188#define OCTEON_CN3XXX           (OCTEON_CN58XX_PASS1_0 \
189				 | OM_MATCH_PREVIOUS_MODELS \
190				 | OM_IGNORE_REVISION)
191
192/* The revision byte (low byte) has two different encodings.
193 * CN3XXX:
194 *
195 *     bits
196 *     <7:5>: reserved (0)
197 *     <4>:   alternate package
198 *     <3:0>: revision
199 *
200 * CN5XXX:
201 *
202 *     bits
203 *     <7>:   reserved (0)
204 *     <6>:   alternate package
205 *     <5:3>: major revision
206 *     <2:0>: minor revision
207 *
208 */
209
210/* Masks used for the various types of model/family/revision matching */
211#define OCTEON_38XX_FAMILY_MASK      0x00ffff00
212#define OCTEON_38XX_FAMILY_REV_MASK  0x00ffff0f
213#define OCTEON_38XX_MODEL_MASK       0x00ffff10
214#define OCTEON_38XX_MODEL_REV_MASK   (OCTEON_38XX_FAMILY_REV_MASK \
215				      | OCTEON_38XX_MODEL_MASK)
216
217/* CN5XXX and later use different layout of bits in the revision ID field */
218#define OCTEON_58XX_FAMILY_MASK      OCTEON_38XX_FAMILY_MASK
219#define OCTEON_58XX_FAMILY_REV_MASK  0x00ffff3f
220#define OCTEON_58XX_MODEL_MASK       0x00ffffc0
221#define OCTEON_58XX_MODEL_REV_MASK   (OCTEON_58XX_FAMILY_REV_MASK \
222				      | OCTEON_58XX_MODEL_MASK)
223#define OCTEON_58XX_MODEL_MINOR_REV_MASK (OCTEON_58XX_MODEL_REV_MASK \
224					  & 0x00fffff8)
225
226#define __OCTEON_MATCH_MASK__(x, y, z) (((x) & (z)) == ((y) & (z)))
227
228/* NOTE: This is for internal (to this file) use only. */
229static inline int __OCTEON_IS_MODEL_COMPILE__(uint32_t arg_model,
230					      uint32_t chip_model)
231{
232	uint32_t rev_and_sub = OM_IGNORE_REVISION | OM_CHECK_SUBMODEL;
233
234	if ((arg_model & OCTEON_38XX_FAMILY_MASK) < OCTEON_CN58XX_PASS1_0) {
235		if (((arg_model & OM_FLAG_MASK) == rev_and_sub) &&
236		    __OCTEON_MATCH_MASK__(chip_model, arg_model,
237					  OCTEON_38XX_MODEL_MASK))
238			return 1;
239		if (((arg_model & OM_FLAG_MASK) == 0) &&
240		    __OCTEON_MATCH_MASK__(chip_model, arg_model,
241					  OCTEON_38XX_FAMILY_REV_MASK))
242			return 1;
243		if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_REVISION) &&
244		    __OCTEON_MATCH_MASK__(chip_model, arg_model,
245					  OCTEON_38XX_FAMILY_MASK))
246			return 1;
247		if (((arg_model & OM_FLAG_MASK) == OM_CHECK_SUBMODEL) &&
248		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
249					  OCTEON_38XX_MODEL_REV_MASK))
250			return 1;
251		if ((arg_model & OM_MATCH_PREVIOUS_MODELS) &&
252		    ((chip_model & OCTEON_38XX_MODEL_MASK) <
253			    (arg_model & OCTEON_38XX_MODEL_MASK)))
254			return 1;
255	} else {
256		if (((arg_model & OM_FLAG_MASK) == rev_and_sub) &&
257		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
258					  OCTEON_58XX_MODEL_MASK))
259			return 1;
260		if (((arg_model & OM_FLAG_MASK) == 0) &&
261		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
262					  OCTEON_58XX_FAMILY_REV_MASK))
263			return 1;
264		if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_MINOR_REVISION) &&
265		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
266					  OCTEON_58XX_MODEL_MINOR_REV_MASK))
267			return 1;
268		if (((arg_model & OM_FLAG_MASK) == OM_IGNORE_REVISION) &&
269		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
270					  OCTEON_58XX_FAMILY_MASK))
271			return 1;
272		if (((arg_model & OM_FLAG_MASK) == OM_CHECK_SUBMODEL) &&
273		    __OCTEON_MATCH_MASK__((chip_model), (arg_model),
274					  OCTEON_58XX_MODEL_REV_MASK))
275			return 1;
276		if ((arg_model & OM_MATCH_PREVIOUS_MODELS) &&
277		    ((chip_model & OCTEON_58XX_MODEL_MASK) <
278			    (arg_model & OCTEON_58XX_MODEL_MASK)))
279			return 1;
280	}
281	return 0;
282}
283
284/* forward declarations */
285static inline uint32_t cvmx_get_proc_id(void) __attribute__ ((pure));
286static inline uint64_t cvmx_read_csr(uint64_t csr_addr);
287
288/* NOTE: This for internal use only!!!!! */
289static inline int __octeon_is_model_runtime__(uint32_t model)
290{
291	uint32_t cpuid = cvmx_get_proc_id();
292
293	/*
294	 * Check for special case of mismarked 3005 samples. We only
295	 * need to check if the sub model isn't being ignored.
296	 */
297	if ((model & OM_CHECK_SUBMODEL) == OM_CHECK_SUBMODEL) {
298		if (cpuid == OCTEON_CN3010_PASS1 \
299		    && (cvmx_read_csr(0x80011800800007B8ull) & (1ull << 34)))
300			cpuid |= 0x10;
301	}
302	return __OCTEON_IS_MODEL_COMPILE__(model, cpuid);
303}
304
305/*
306 * The OCTEON_IS_MODEL macro should be used for all Octeon model
307 * checking done in a program.  This should be kept runtime if at all
308 * possible.  Any compile time (#if OCTEON_IS_MODEL) usage must be
309 * condtionalized with OCTEON_IS_COMMON_BINARY() if runtime checking
310 * support is required.
311 */
312#define OCTEON_IS_MODEL(x) __octeon_is_model_runtime__(x)
313#define OCTEON_IS_COMMON_BINARY() 1
314#undef OCTEON_MODEL
315
316const char *octeon_model_get_string(uint32_t chip_id);
317const char *octeon_model_get_string_buffer(uint32_t chip_id, char *buffer);
318
319#include "octeon-feature.h"
320
321#endif /* __OCTEON_MODEL_H__ */
322