1 /***********************license start***************
2 * Copyright (c) 2003-2010 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 * 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
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**************************************/
43 * Interface to power-throttle control, measurement, and debugging
52 #include "cvmx-power-throttle.h"
54 #define CVMX_PTH_PPID_BCAST 63
55 #define CVMX_PTH_PPID_MAX 64
59 * Set the POWLIM field as percentage% of the MAXPOW field in r.
61 static uint64_t __cvmx_power_throttle_set_powlim(uint64_t r, uint8_t percentage)
63 if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
67 assert(percentage < 101);
68 t = percentage * cvmx_power_throttle_get_field(CVMX_PTH_INDEX_MAXPOW, r) / 100;
69 r = cvmx_power_throttle_set_field(CVMX_PTH_INDEX_POWLIM, r, t);
78 * Given ppid, calculate its PowThrottle register's L2C_COP0_MAP CSR
79 * address. (ppid == PTH_PPID_BCAST is for broadcasting)
81 static uint64_t __cvmx_power_throttle_csr_addr(uint64_t ppid)
83 if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
85 uint64_t csr_addr, reg_num, reg_reg, reg_sel;
87 assert(ppid < CVMX_PTH_PPID_MAX);
89 * register 11 selection 6
93 reg_num = (ppid << 8) + (reg_reg << 3) + reg_sel;
94 csr_addr = CVMX_L2C_COP0_MAPX(0) + ((reg_num) << 3);
102 * Throttle power to percentage% of configured maximum (MAXPOW).
104 * @param percentage 0 to 100
105 * @return 0 for success
107 int cvmx_power_throttle_self(uint8_t percentage)
109 if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
113 CVMX_MF_COP0(r, COP0_POWTHROTTLE);
114 r = __cvmx_power_throttle_set_powlim(r, percentage);
115 CVMX_MT_COP0(r, COP0_POWTHROTTLE);
122 * Throttle power to percentage% of configured maximum (MAXPOW)
123 * for the cores identified in coremask.
125 * @param percentage 0 to 100
126 * @param coremask bit mask where each bit identifies a core.
127 * @return 0 for success.
129 int cvmx_power_throttle(uint8_t percentage, uint64_t coremask)
131 if (OCTEON_IS_MODEL(OCTEON_CN6XXX))
133 uint64_t ppid, csr_addr, b, r;
137 * cvmx_read_csr() for PTH_PPID_BCAST does not make sense and
138 * therefore limit ppid to less.
140 for (ppid = 0; ppid < CVMX_PTH_PPID_BCAST; ppid ++)
142 if ((b << ppid) & coremask) {
143 csr_addr = __cvmx_power_throttle_csr_addr(ppid);
144 r = cvmx_read_csr(csr_addr);
145 r = __cvmx_power_throttle_set_powlim(r, percentage);
146 cvmx_write_csr(csr_addr, r);