1210284Sjmallett/***********************license start*************** 2215990Sjmallett * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 3215990Sjmallett * reserved. 4210284Sjmallett * 5210284Sjmallett * 6215990Sjmallett * Redistribution and use in source and binary forms, with or without 7215990Sjmallett * modification, are permitted provided that the following conditions are 8215990Sjmallett * met: 9210284Sjmallett * 10215990Sjmallett * * Redistributions of source code must retain the above copyright 11215990Sjmallett * notice, this list of conditions and the following disclaimer. 12210284Sjmallett * 13215990Sjmallett * * Redistributions in binary form must reproduce the above 14215990Sjmallett * copyright notice, this list of conditions and the following 15215990Sjmallett * disclaimer in the documentation and/or other materials provided 16215990Sjmallett * with the distribution. 17215990Sjmallett 18215990Sjmallett * * Neither the name of Cavium Networks nor the names of 19215990Sjmallett * its contributors may be used to endorse or promote products 20215990Sjmallett * derived from this software without specific prior written 21215990Sjmallett * permission. 22215990Sjmallett 23215990Sjmallett * This Software, including technical data, may be subject to U.S. export control 24215990Sjmallett * laws, including the U.S. Export Administration Act and its associated 25215990Sjmallett * regulations, and may be subject to export or import regulations in other 26215990Sjmallett * countries. 27215990Sjmallett 28215990Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29215990Sjmallett * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR 30215990Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 31215990Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 32215990Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 33215990Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 34215990Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 35215990Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36215990Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 37215990Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 38210284Sjmallett ***********************license end**************************************/ 39210284Sjmallett 40210284Sjmallett 41210284Sjmallett 42210284Sjmallett 43210284Sjmallett 44215990Sjmallett 45210284Sjmallett#ifndef __CVMX_CSR_DB_H__ 46210284Sjmallett#define __CVMX_CSR_DB_H__ 47210284Sjmallett 48210284Sjmallett/** 49210284Sjmallett * @file 50210284Sjmallett * Interface for the Octeon CSR database. 51210284Sjmallett * 52210284Sjmallett * 53215990Sjmallett * <hr>$Revision: 49507 $<hr> 54210284Sjmallett * 55210284Sjmallett */ 56215990Sjmallett#if !defined(CVMX_BUILD_FOR_LINUX_KERNEL) && !defined(CVMX_BUILD_FOR_FREEBSD_KERNEL) 57210284Sjmallett#include "cvmx-platform.h" 58215990Sjmallett#endif 59210284Sjmallett 60210284Sjmallett#ifdef __cplusplus 61210284Sjmallettextern "C" { 62210284Sjmallett#endif 63210284Sjmallett 64210284Sjmalletttypedef enum { 65210284Sjmallett CVMX_CSR_DB_TYPE_RSL, /**< Octeon internal address, but indirect and slow (not used for addresses) */ 66210284Sjmallett CVMX_CSR_DB_TYPE_NCB, /**< Octeon internal address */ 67210284Sjmallett CVMX_CSR_DB_TYPE_PCI_NCB, /**< Can be accessed through PCI BAR0, also an NCB alias (not used for addresses) */ 68210284Sjmallett CVMX_CSR_DB_TYPE_PCICONFIG, /**< PCI Config, also an NCB alias */ 69210284Sjmallett CVMX_CSR_DB_TYPE_PCI, /**< PCI BAR0 (only) */ 70210284Sjmallett CVMX_CSR_DB_TYPE_PEXP, /**< PCIe BAR 0 address only */ 71210284Sjmallett CVMX_CSR_DB_TYPE_PEXP_NCB, /**< NCB-direct and PCIe BAR0 address */ 72210284Sjmallett CVMX_CSR_DB_TYPE_PCICONFIGEP, /**< PCIe config address (EP mode) + indirect through PESC*_CFG_RD/PESC*_CFG_WR */ 73215990Sjmallett CVMX_CSR_DB_TYPE_PCICONFIGRC, /**< PCICONFIGRC - PCIe config address (RC mode) + indirect through PESC*_CFG_RD/PESC*_CFG_WR */ 74215990Sjmallett CVMX_CSR_DB_TYPE_SRIOMAINT /**< SRIOMAINT - SRIO maintenance registers */ 75210284Sjmallett} CVMX_CSR_DB_TYPE_FIELD; 76210284Sjmallett 77210284Sjmallett/** 78210284Sjmallett * the structure for the cvmx_csr_db_addresses[] array that 79210284Sjmallett * holds all possible Octeon CSR addresses 80210284Sjmallett */ 81210284Sjmalletttypedef struct { 82210284Sjmallett char * name; /**< CSR name at the supplied address */ 83210284Sjmallett uint64_t address; /**< Address = octeon internal, PCI BAR0 relative, PCI CONFIG relative */ 84210284Sjmallett CVMX_CSR_DB_TYPE_FIELD type:8; /**< the type */ 85210284Sjmallett uint8_t widthbits; /**< the width of the CSR in bits */ 86210284Sjmallett uint16_t csroff; /**< position of the CSR in cvmx_csr_db[] */ 87210284Sjmallett} __attribute__ ((packed)) CVMX_CSR_DB_ADDRESS_TYPE; 88210284Sjmallett 89210284Sjmallett/** 90210284Sjmallett * the structure for the cvmx_csr_db_fields[] array that 91210284Sjmallett * holds all possible Octeon CSR fields 92210284Sjmallett */ 93210284Sjmalletttypedef struct { 94210284Sjmallett char * name; /**< name of the field */ 95210284Sjmallett uint8_t startbit; /**< starting bit position of the field */ 96210284Sjmallett uint8_t sizebits; /**< the size of the field in bits */ 97210284Sjmallett uint16_t csroff; /**< position of the CSR containing the field in cvmx_csr_db[] (get alias from there) */ 98210284Sjmallett char * type; /**< the type of the field R/W, R/W1C, ... */ 99210284Sjmallett uint8_t rst_unp; /**< set if the reset value is unknown */ 100210284Sjmallett uint8_t typ_unp; /**< set if the typical value is unknown */ 101210284Sjmallett uint64_t rst_val; /**< the reset value of the field */ 102210284Sjmallett uint64_t typ_val; /**< the typical value of the field */ 103210284Sjmallett} __attribute__ ((packed)) CVMX_CSR_DB_FIELD_TYPE; 104210284Sjmallett 105210284Sjmallett/** 106210284Sjmallett * the structure for the cvmx_csr_db[] array that holds all 107210284Sjmallett * possible Octeon CSR forms 108210284Sjmallett */ 109210284Sjmalletttypedef struct { 110210284Sjmallett char *basename; /**< the base name of the CSR */ 111210284Sjmallett CVMX_CSR_DB_TYPE_FIELD type:8; /**< the type */ 112210284Sjmallett uint8_t widthbits; /**< the width of the CSR in bits */ 113210284Sjmallett uint16_t addoff; /**< the position of the first address in cvmx_csr_db_csr_addresses[] (numblocks*indexnum is #) */ 114210284Sjmallett uint8_t numfields; /**< the number of fields in the CSR (and in cvmx_csr_db_csr_fields[]) */ 115210284Sjmallett uint16_t fieldoff; /**< the position of the first field in cvmx_csr_db_csr_fields[] */ 116210284Sjmallett} __attribute__ ((packed)) CVMX_CSR_DB_TYPE; 117210284Sjmallett 118210284Sjmallett 119210284Sjmallett/** 120210284Sjmallett * This NULL terminated array contains the CVMX_CSR_DB_TYPE 121210284Sjmallett * arrays for each chip. Each array entry is another NULL 122210284Sjmallett * terminated array of CSRs. 123210284Sjmallett */ 124210284Sjmallettextern const CVMX_CSR_DB_TYPE *cvmx_csr_db[]; 125210284Sjmallett 126210284Sjmallett/** 127210284Sjmallett * This NULL terminated array contains the CVMX_CSR_DB_ADDRESS_TYPE 128210284Sjmallett * arrays for each chip. Each array entry is another NULL 129210284Sjmallett * terminated array of CSR addresses. 130210284Sjmallett */ 131210284Sjmallettextern const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_addresses[]; 132210284Sjmallett 133210284Sjmallett/** 134210284Sjmallett * This NULL terminated array contains the CVMX_CSR_DB_FIELD_TYPE 135210284Sjmallett * arrays for each chip. Each array entry is another NULL 136210284Sjmallett * terminated array of CSR fields. 137210284Sjmallett */ 138210284Sjmallettextern const CVMX_CSR_DB_FIELD_TYPE *cvmx_csr_db_fields[]; 139210284Sjmallett 140210284Sjmallett/** 141210284Sjmallett * Figure out which database to use for this chip. The passed 142210284Sjmallett * identifier can be a processor ID or a PCI ID. 143210284Sjmallett * 144210284Sjmallett * @param identifier processor ID or a PCI ID 145210284Sjmallett * 146210284Sjmallett * @return index into the csr db 147210284Sjmallett */ 148210284Sjmallettextern int cvmx_db_get_chipindex(int identifier); 149210284Sjmallett 150210284Sjmallett/** 151210284Sjmallett * Get the CSR DB entry for the passed Octeon model and CSR name. The 152210284Sjmallett * model can either be specified as a processor id or PCI id. 153210284Sjmallett * 154210284Sjmallett * @param identifier Identifer to choose the CSR DB with 155210284Sjmallett * @param name CSR name to lookup 156210284Sjmallett * 157210284Sjmallett * @return CSR DB entry or NULL on failure 158210284Sjmallett */ 159210284Sjmallettextern const CVMX_CSR_DB_ADDRESS_TYPE *cvmx_csr_db_get(int identifier, const char *name); 160210284Sjmallett 161210284Sjmallett/** 162210284Sjmallett * Decode a CSR value into named bitfields. The model can either 163210284Sjmallett * be specified as a processor id or PCI id. 164210284Sjmallett * 165210284Sjmallett * @param identifier Identifer to choose the CSR DB with 166210284Sjmallett * @param address CSR address being decoded 167210284Sjmallett * @param value Value to decode 168210284Sjmallett */ 169210284Sjmallettextern void cvmx_csr_db_decode(int identifier, uint64_t address, uint64_t value); 170210284Sjmallett 171210284Sjmallett/** 172215990Sjmallett * Decode a CSR value into named bitfields. The model can either 173215990Sjmallett * be specified as a processor id or PCI id. 174215990Sjmallett * 175215990Sjmallett * @param identifier Identifer to choose the CSR DB with 176215990Sjmallett * @param name CSR name to decode 177215990Sjmallett * @param value Value to decode 178215990Sjmallett */ 179215990Sjmallettextern void cvmx_csr_db_decode_by_name(int identifier, const char *name, uint64_t value); 180215990Sjmallett 181215990Sjmallett/** 182210284Sjmallett * Print a list of csrs begimning with a prefix. The 183210284Sjmallett * model can either be specified as a processor id or PCI id. 184210284Sjmallett * 185210284Sjmallett * @param identifier Identifer to choose the CSR DB with 186210284Sjmallett * @param prefix Beginning prefix to look for 187210284Sjmallett */ 188210284Sjmallettextern void cvmx_csr_db_display_list(int identifier, const char *prefix); 189210284Sjmallett 190210284Sjmallett#ifdef __cplusplus 191210284Sjmallett} 192210284Sjmallett#endif 193210284Sjmallett 194210284Sjmallett#endif 195