cvmx-power-throttle.h revision 215990
173149Snyan/***********************license start***************
273149Snyan * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
373149Snyan * reserved.
473149Snyan *
573149Snyan *
673149Snyan * Redistribution and use in source and binary forms, with or without
773149Snyan * modification, are permitted provided that the following conditions are
873149Snyan * met:
973149Snyan *
1073149Snyan *   * Redistributions of source code must retain the above copyright
1173149Snyan *     notice, this list of conditions and the following disclaimer.
1273149Snyan *
1373149Snyan *   * Redistributions in binary form must reproduce the above
1473149Snyan *     copyright notice, this list of conditions and the following
1573149Snyan *     disclaimer in the documentation and/or other materials provided
1673149Snyan *     with the distribution.
1773149Snyan
1873149Snyan *   * Neither the name of Cavium Networks nor the names of
1973149Snyan *     its contributors may be used to endorse or promote products
2073149Snyan *     derived from this software without specific prior written
2173149Snyan *     permission.
2273149Snyan
2373149Snyan * This Software, including technical data, may be subject to U.S. export  control
2473149Snyan * laws, including the U.S. Export Administration Act and its  associated
2573149Snyan * regulations, and may be subject to export or import  regulations in other
2673149Snyan * countries.
2773149Snyan
2873149Snyan * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
2973149Snyan * AND WITH ALL FAULTS AND CAVIUM  NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
3073149Snyan * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
3173149Snyan * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
3273149Snyan * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
3373149Snyan * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
3473149Snyan * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
3573149Snyan * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
3673149Snyan * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK ARISING OUT OF USE OR
3773149Snyan * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
3873149Snyan ***********************license end**************************************/
3973149Snyan
4073149Snyan/**
4173149Snyan * @file
4273149Snyan *
4373149Snyan * Interface to power-throttle control, measurement, and debugging
4473149Snyan * facilities.
4573149Snyan *
4673149Snyan * <hr>$Revision<hr>
4773149Snyan *
4873149Snyan */
4973149Snyan
5073149Snyan#ifndef __CVMX_POWER_THROTTLE_H__
5173149Snyan#define __CVMX_POWER_THROTTLE_H__
5273149Snyan#ifdef	__cplusplus
5373149Snyanextern "C" {
5473149Snyan#endif
5573149Snyan
5673149Snyan/**
5773149Snyan * a field of the POWTHROTTLE register
5873149Snyan */
5973149Snyanstatic struct cvmx_power_throttle_rfield_t {
6073149Snyan	char	name[16];	/* the field's name */
6173149Snyan	int32_t	pos;		/* position of the field's LSb */
6273149Snyan	int32_t	len;		/* the field's length */
6373149Snyan} cvmx_power_throttle_rfield[] = {
6473149Snyan#define CVMX_PTH_INDEX_MAXPOW	0
6573149Snyan	{"MAXPOW",   56,  8},
6673149Snyan#define CVMX_PTH_INDEX_POWER		1
6773149Snyan	{"POWER" ,   48,  8},
6873149Snyan#define CVMX_PTH_INDEX_THROTT	2
6973149Snyan	{"THROTT",   40,  8},
7073149Snyan#define CVMX_PTH_INDEX_RESERVED	3
7173149Snyan	{"Reserved", 28, 12},
7273149Snyan#define CVMX_PTH_INDEX_DISTAG	4
7373149Snyan	{"DISTAG",   27,  1},
7473149Snyan#define CVMX_PTH_INDEX_PERIOD	5
7573149Snyan	{"PERIOD",   24,  3},
7673149Snyan#define CVMX_PTH_INDEX_POWLIM	6
7773149Snyan	{"POWLIM",   16,  8},
7873149Snyan#define CVMX_PTH_INDEX_MAXTHR	7
7973149Snyan	{"MAXTHR",    8,  8},
8073149Snyan#define CVMX_PTH_INDEX_MINTHR	8
8173149Snyan	{"MINTHR",    0,  8}
8273149Snyan#define CVMX_PTH_INDEX_MAX		9
8373149Snyan};
8473149Snyan
8573149Snyan#define CVMX_PTH_GET_MASK(len, pos) \
8673149Snyan	((((uint64_t)1 << (len)) - 1) << (pos))
87
88/**
89 * Get the i'th field of power-throttle register r.
90 */
91static inline uint64_t cvmx_power_throttle_get_field(int i, uint64_t r)
92{
93    if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
94    {
95        uint64_t m;
96        struct cvmx_power_throttle_rfield_t *p;
97
98        assert((i >= 0) && (i < CVMX_PTH_INDEX_MAX));
99
100        p = &cvmx_power_throttle_rfield[i];
101        m = CVMX_PTH_GET_MASK(p->len, p->pos);
102
103        return((r & m) >> p->pos);
104    }
105    return 0;
106}
107
108/**
109 * Set the i'th field of power-throttle register r to v.
110 */
111static inline int cvmx_power_throttle_set_field(int i, uint64_t r, uint64_t v)
112{
113    if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
114    {
115        uint64_t m;
116        struct cvmx_power_throttle_rfield_t *p;
117
118        assert((i >= 0) && (i < CVMX_PTH_INDEX_MAX));
119
120        p = &cvmx_power_throttle_rfield[i];
121        m = CVMX_PTH_GET_MASK(p->len, p->pos);
122
123        return((~m & r) | ((v << p->pos) & m));
124    }
125    return 0;
126}
127
128/**
129 * API Function Prototypes
130 */
131extern int cvmx_power_throttle_self(uint8_t percentage);
132extern int cvmx_power_throttle(uint8_t percentage, uint64_t coremask);
133
134#ifdef	__cplusplus
135}
136#endif
137#endif /* __CVMX_POWER_THROTTLE_H__ */
138