]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/contrib/octeon-sdk/cvmx-csr-db-support.c
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / contrib / octeon-sdk / cvmx-csr-db-support.c
1 /***********************license start***************
2  *  Copyright (c) 2003-2008 Cavium Networks (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 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
21  *        permission.
22  *
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.
33  *
34  *
35  *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39
40
41
42
43
44 /**
45  * @file
46  *
47  * Utility functions for working with the CSR database
48  *
49  * <hr>$Revision: 41586 $<hr>
50  */
51 #include "cvmx.h"
52 #include "cvmx-csr-db.h"
53
54 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
55     #define PRINTF printk
56 #else
57     #define PRINTF printf
58 #endif
59
60 /**
61  * Figure out which database to use for this chip. The passed
62  * identifier can be a processor ID or a PCI ID.
63  *
64  * @param identifier processor ID or a PCI ID
65  *
66  * @return index into the csr db
67  */
68 int cvmx_db_get_chipindex(int identifier)
69 {
70     /* First try and see if the identifier is a Processor ID */
71     switch (identifier & 0xffff00)
72     {
73         case 0x000d0600: /* CN50XX */
74             return 8;
75         case 0x000d0400: /* CN56XX */
76             return 7;
77         case 0x000d0300: /* CN58XX */
78             return 5;
79         case 0x000d0000: /* CN38XX */
80             return 3;
81         case 0x000d0100: /* CN31XX */
82             return 1;
83         case 0x000d0200: /* CN3010 */
84             return 2;
85         case 0x000d0700: /* CN52XX */
86             return 10;
87     }
88
89     /* Next try PCI device IDs */
90     switch (identifier)
91     {
92         case 0x0003177d: /* CN38XX Pass 1 */
93             return 0;
94         case 0x0004177d: /* CN38XX Pass 2 */
95             return 0;
96         case 0x0005177d: /* CN38XX Pass 3 */
97             return 3;
98         case 0x1001177d: /* Thunder */
99             return 3;
100         case 0x0020177d: /* CN31XX Pass 1 */
101             return 1;
102         case 0x0030177d: /* CN30XX Pass 1 */
103             return 2;
104         case 0x0040177d: /* CN58XX Pass 2 */
105             return 5;
106         case 0x0050177d: /* CN56XX Pass 2 */
107             return 7;
108         case 0x0070177d: /* CN50XX Pass 1 */
109             return 8;
110         case 0x0080177d: /* CN52XX Pass 2 */
111             return 10;
112     }
113
114     /* Default to Pass 3 if we don't know */
115     return 3;
116 }
117
118
119 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
120 /**
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.
123  *
124  * @param identifier Identifer to choose the CSR DB with
125  * @param name       CSR name to lookup
126  *
127  * @return CSR DB entry or NULL on failure
128  */
129 const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_get(int identifier, const char *name)
130 {
131     int chip = cvmx_db_get_chipindex(identifier);
132     int i=0;
133     if (strncasecmp(name, "CVMX_", 5) == 0)
134         name += 5;
135     while (cvmx_csr_db_addresses[chip][i].name)
136     {
137         if (strcasecmp(name, cvmx_csr_db_addresses[chip][i].name) == 0)
138             return &(cvmx_csr_db_addresses[chip][i]);
139         i++;
140     }
141     return NULL;
142 }
143 #endif
144
145
146 /**
147  * Decode a CSR value into named bitfields. The model can either
148  * be specified as a processor id or PCI id.
149  *
150  * @param identifier Identifer to choose the CSR DB with
151  * @param address    CSR address being decoded
152  * @param value      Value to decode
153  */
154 void cvmx_csr_db_decode(int identifier, uint64_t address, uint64_t value)
155 {
156     int chip = cvmx_db_get_chipindex(identifier);
157     int index=0;
158     /* Strip off the upper 8 bits since they are normally mips addressing
159         modes */
160     address &= (1ull<<56)-1;
161     while (cvmx_csr_db_addresses[chip][index].name)
162     {
163         if (cvmx_csr_db_addresses[chip][index].address == address)
164         {
165             int field;
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--)
169             {
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);
177                 else
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);
183             }
184         }
185         index++;
186     }
187 }
188
189
190 #ifndef CVMX_BUILD_FOR_LINUX_KERNEL
191 /**
192  * Print a list of csrs begimning with a prefix. The
193  * model can either be specified as a processor id or PCI id.
194  *
195  * @param identifier Identifer to choose the CSR DB with
196  * @param prefix     Beginning prefix to look for
197  */
198 void cvmx_csr_db_display_list(int identifier, const char *prefix)
199 {
200     int i, len;
201     int chip = cvmx_db_get_chipindex(identifier);
202     if (prefix == NULL)
203         prefix = "";
204     if (strncasecmp(prefix, "CVMX_", 5) == 0)
205         prefix += 5;
206     len = strlen(prefix);
207
208     i=0;
209     while (cvmx_csr_db_addresses[chip][i].name)
210     {
211         if (strncasecmp(prefix, cvmx_csr_db_addresses[chip][i].name, len) == 0)
212             PRINTF("%s\n", cvmx_csr_db_addresses[chip][i].name);
213         i++;
214     }
215 }
216 #endif