1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (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 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
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 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**************************************/
49 * Utility functions for working with the CSR database
51 * <hr>$Revision: 49507 $<hr>
53 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
55 #include <asm/octeon/cvmx.h>
56 #include <asm/octeon/cvmx-csr-db.h>
60 #include "cvmx-csr-db.h"
64 * Figure out which database to use for this chip. The passed
65 * identifier can be a processor ID or a PCI ID.
67 * @param identifier processor ID or a PCI ID
69 * @return index into the csr db
71 int cvmx_db_get_chipindex(int identifier)
73 /* First try and see if the identifier is a Processor ID */
74 switch (identifier & 0xffff00)
76 case 0x000d0600: /* CN50XX */
78 case 0x000d0400: /* CN56XX */
80 case 0x000d0300: /* CN58XX */
82 case 0x000d0000: /* CN38XX */
84 case 0x000d0100: /* CN31XX */
86 case 0x000d0200: /* CN3010 */
88 case 0x000d0700: /* CN52XX */
90 case 0x000d9000: /* CN63XX */
94 /* Next try PCI device IDs */
97 case 0x0003177d: /* CN38XX Pass 1 */
99 case 0x0004177d: /* CN38XX Pass 2 */
101 case 0x0005177d: /* CN38XX Pass 3 */
103 case 0x1001177d: /* Thunder */
105 case 0x0020177d: /* CN31XX Pass 1 */
107 case 0x0030177d: /* CN30XX Pass 1 */
109 case 0x0040177d: /* CN58XX Pass 2 */
111 case 0x0050177d: /* CN56XX Pass 2 */
113 case 0x0070177d: /* CN50XX Pass 1 */
115 case 0x0080177d: /* CN52XX Pass 2 */
117 case 0x0090177d: /* CN63XX Pass 1 */
121 /* Default to Pass 3 if we don't know */
126 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
128 * Get the CSR DB entry for the passed Octeon model and CSR name. The
129 * model can either be specified as a processor id or PCI id.
131 * @param identifier Identifer to choose the CSR DB with
132 * @param name CSR name to lookup
134 * @return CSR DB entry or NULL on failure
136 const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_get(int identifier, const char *name)
138 int chip = cvmx_db_get_chipindex(identifier);
140 if (strncasecmp(name, "CVMX_", 5) == 0)
142 while (cvmx_csr_db_addresses[chip][i].name)
144 if (strcasecmp(name, cvmx_csr_db_addresses[chip][i].name) == 0)
145 return &(cvmx_csr_db_addresses[chip][i]);
152 static void __cvmx_csr_db_decode_csr(int chip, int index, uint64_t value)
155 int csr = cvmx_csr_db_addresses[chip][index].csroff;
156 PRINTF("%s(0x%016llx) = 0x%016llx\n", cvmx_csr_db_addresses[chip][index].name, (unsigned long long)cvmx_csr_db_addresses[chip][index].address, (unsigned long long)value);
157 for (field=cvmx_csr_db[chip][csr].fieldoff+cvmx_csr_db[chip][csr].numfields-1; field>=cvmx_csr_db[chip][csr].fieldoff; field--)
159 uint64_t v = (value >> cvmx_csr_db_fields[chip][field].startbit);
160 if(cvmx_csr_db_fields[chip][field].sizebits < 64)
161 v = v & ~((~0x0ull) << cvmx_csr_db_fields[chip][field].sizebits);
162 if (cvmx_csr_db_fields[chip][field].sizebits == 1)
163 PRINTF(" [ %2d] %-20s = %10llu (0x%llx)\n",
164 cvmx_csr_db_fields[chip][field].startbit, cvmx_csr_db_fields[chip][field].name,
165 (unsigned long long)v, (unsigned long long)v);
167 PRINTF(" [%2d:%2d] %-20s = %10llu (0x%llx)\n",
168 cvmx_csr_db_fields[chip][field].startbit + cvmx_csr_db_fields[chip][field].sizebits - 1,
169 cvmx_csr_db_fields[chip][field].startbit,
170 cvmx_csr_db_fields[chip][field].name,
171 (unsigned long long)v, (unsigned long long)v);
176 * Decode a CSR value into named bitfields. The model can either
177 * be specified as a processor id or PCI id.
179 * @param identifier Identifer to choose the CSR DB with
180 * @param address CSR address being decoded
181 * @param value Value to decode
183 void cvmx_csr_db_decode(int identifier, uint64_t address, uint64_t value)
185 int chip = cvmx_db_get_chipindex(identifier);
187 /* Strip off the upper 8 bits since they are normally mips addressing
189 address &= (1ull<<56)-1;
190 while (cvmx_csr_db_addresses[chip][index].name)
192 if (cvmx_csr_db_addresses[chip][index].address == address)
193 __cvmx_csr_db_decode_csr(chip, index, value);
199 * Decode a CSR value into named bitfields. The model can either
200 * be specified as a processor id or PCI id.
202 * @param identifier Identifer to choose the CSR DB with
203 * @param name CSR name to decode
204 * @param value Value to decode
206 void cvmx_csr_db_decode_by_name(int identifier, const char *name, uint64_t value)
208 int chip = cvmx_db_get_chipindex(identifier);
210 while (cvmx_csr_db_addresses[chip][index].name)
212 if (strcasecmp(name, cvmx_csr_db_addresses[chip][index].name) == 0)
214 __cvmx_csr_db_decode_csr(chip, index, value);
222 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
224 * Print a list of csrs begimning with a prefix. The
225 * model can either be specified as a processor id or PCI id.
227 * @param identifier Identifer to choose the CSR DB with
228 * @param prefix Beginning prefix to look for
230 void cvmx_csr_db_display_list(int identifier, const char *prefix)
233 int chip = cvmx_db_get_chipindex(identifier);
236 if (strncasecmp(prefix, "CVMX_", 5) == 0)
238 len = strlen(prefix);
241 while (cvmx_csr_db_addresses[chip][i].name)
243 if (strncasecmp(prefix, cvmx_csr_db_addresses[chip][i].name, len) == 0)
244 PRINTF("%s\n", cvmx_csr_db_addresses[chip][i].name);