1 /***********************license start***************
2 * Copyright (c) 2003-2008 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * Utility functions for working with the CSR database
49 * <hr>$Revision: 41586 $<hr>
52 #include "cvmx-csr-db.h"
54 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
61 * Figure out which database to use for this chip. The passed
62 * identifier can be a processor ID or a PCI ID.
64 * @param identifier processor ID or a PCI ID
66 * @return index into the csr db
68 int cvmx_db_get_chipindex(int identifier)
70 /* First try and see if the identifier is a Processor ID */
71 switch (identifier & 0xffff00)
73 case 0x000d0600: /* CN50XX */
75 case 0x000d0400: /* CN56XX */
77 case 0x000d0300: /* CN58XX */
79 case 0x000d0000: /* CN38XX */
81 case 0x000d0100: /* CN31XX */
83 case 0x000d0200: /* CN3010 */
85 case 0x000d0700: /* CN52XX */
89 /* Next try PCI device IDs */
92 case 0x0003177d: /* CN38XX Pass 1 */
94 case 0x0004177d: /* CN38XX Pass 2 */
96 case 0x0005177d: /* CN38XX Pass 3 */
98 case 0x1001177d: /* Thunder */
100 case 0x0020177d: /* CN31XX Pass 1 */
102 case 0x0030177d: /* CN30XX Pass 1 */
104 case 0x0040177d: /* CN58XX Pass 2 */
106 case 0x0050177d: /* CN56XX Pass 2 */
108 case 0x0070177d: /* CN50XX Pass 1 */
110 case 0x0080177d: /* CN52XX Pass 2 */
114 /* Default to Pass 3 if we don't know */
119 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
121 * Get the CSR DB entry for the passed Octeon model and CSR name. The
122 * model can either be specified as a processor id or PCI id.
124 * @param identifier Identifer to choose the CSR DB with
125 * @param name CSR name to lookup
127 * @return CSR DB entry or NULL on failure
129 const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_get(int identifier, const char *name)
131 int chip = cvmx_db_get_chipindex(identifier);
133 if (strncasecmp(name, "CVMX_", 5) == 0)
135 while (cvmx_csr_db_addresses[chip][i].name)
137 if (strcasecmp(name, cvmx_csr_db_addresses[chip][i].name) == 0)
138 return &(cvmx_csr_db_addresses[chip][i]);
147 * Decode a CSR value into named bitfields. The model can either
148 * be specified as a processor id or PCI id.
150 * @param identifier Identifer to choose the CSR DB with
151 * @param address CSR address being decoded
152 * @param value Value to decode
154 void cvmx_csr_db_decode(int identifier, uint64_t address, uint64_t value)
156 int chip = cvmx_db_get_chipindex(identifier);
158 /* Strip off the upper 8 bits since they are normally mips addressing
160 address &= (1ull<<56)-1;
161 while (cvmx_csr_db_addresses[chip][index].name)
163 if (cvmx_csr_db_addresses[chip][index].address == address)
166 int csr = cvmx_csr_db_addresses[chip][index].csroff;
167 PRINTF("%s(0x%016llx) = 0x%016llx\n", cvmx_csr_db_addresses[chip][index].name, (unsigned long long)address, (unsigned long long)value);
168 for (field=cvmx_csr_db[chip][csr].fieldoff+cvmx_csr_db[chip][csr].numfields-1; field>=cvmx_csr_db[chip][csr].fieldoff; field--)
170 uint64_t v = (value >> cvmx_csr_db_fields[chip][field].startbit);
171 if(cvmx_csr_db_fields[chip][field].sizebits < 64)
172 v = v & ~((~0x0ull) << cvmx_csr_db_fields[chip][field].sizebits);
173 if (cvmx_csr_db_fields[chip][field].sizebits == 1)
174 PRINTF(" [ %2d] %-20s = %10llu (0x%llx)\n",
175 cvmx_csr_db_fields[chip][field].startbit, cvmx_csr_db_fields[chip][field].name,
176 (unsigned long long)v, (unsigned long long)v);
178 PRINTF(" [%2d:%2d] %-20s = %10llu (0x%llx)\n",
179 cvmx_csr_db_fields[chip][field].startbit + cvmx_csr_db_fields[chip][field].sizebits - 1,
180 cvmx_csr_db_fields[chip][field].startbit,
181 cvmx_csr_db_fields[chip][field].name,
182 (unsigned long long)v, (unsigned long long)v);
190 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
192 * Print a list of csrs begimning with a prefix. The
193 * model can either be specified as a processor id or PCI id.
195 * @param identifier Identifer to choose the CSR DB with
196 * @param prefix Beginning prefix to look for
198 void cvmx_csr_db_display_list(int identifier, const char *prefix)
201 int chip = cvmx_db_get_chipindex(identifier);
204 if (strncasecmp(prefix, "CVMX_", 5) == 0)
206 len = strlen(prefix);
209 while (cvmx_csr_db_addresses[chip][i].name)
211 if (strncasecmp(prefix, cvmx_csr_db_addresses[chip][i].name, len) == 0)
212 PRINTF("%s\n", cvmx_csr_db_addresses[chip][i].name);