]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-power-throttle.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-power-throttle.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  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  * 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
26  * countries.
27
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**************************************/
39
40 /**
41  * @file
42  *
43  * Interface to power-throttle control, measurement, and debugging
44  * facilities.
45  *
46  * <hr>$Revision<hr>
47  *
48  */
49
50 #ifndef __CVMX_POWER_THROTTLE_H__
51 #define __CVMX_POWER_THROTTLE_H__
52 #ifdef  __cplusplus
53 extern "C" {
54 #endif
55
56 /**
57  * a field of the POWTHROTTLE register
58  */
59 static struct cvmx_power_throttle_rfield_t {
60         char    name[16];       /* the field's name */
61         int32_t pos;            /* position of the field's LSb */
62         int32_t len;            /* the field's length */
63 } cvmx_power_throttle_rfield[] = {
64 #define CVMX_PTH_INDEX_MAXPOW   0
65         {"MAXPOW",   56,  8},
66 #define CVMX_PTH_INDEX_POWER            1
67         {"POWER" ,   48,  8},
68 #define CVMX_PTH_INDEX_THROTT   2
69         {"THROTT",   40,  8},
70 #define CVMX_PTH_INDEX_RESERVED 3
71         {"Reserved", 28, 12},
72 #define CVMX_PTH_INDEX_DISTAG   4
73         {"DISTAG",   27,  1},
74 #define CVMX_PTH_INDEX_PERIOD   5
75         {"PERIOD",   24,  3},
76 #define CVMX_PTH_INDEX_POWLIM   6
77         {"POWLIM",   16,  8},
78 #define CVMX_PTH_INDEX_MAXTHR   7
79         {"MAXTHR",    8,  8},
80 #define CVMX_PTH_INDEX_MINTHR   8
81         {"MINTHR",    0,  8}
82 #define CVMX_PTH_INDEX_MAX              9
83 };
84
85 #define CVMX_PTH_GET_MASK(len, pos) \
86         ((((uint64_t)1 << (len)) - 1) << (pos))
87
88 /**
89  * Get the i'th field of power-throttle register r.
90  */
91 static 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  */
111 static 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  */
131 extern int cvmx_power_throttle_self(uint8_t percentage);
132 extern int cvmx_power_throttle(uint8_t percentage, uint64_t coremask);
133
134 #ifdef  __cplusplus
135 }
136 #endif
137 #endif /* __CVMX_POWER_THROTTLE_H__ */