2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13 * Mali driver functions for Mali 400 PMU hardware
15 #include "mali_hw_core.h"
18 #include "mali_kernel_common.h"
21 static u32 mali_pmu_detect_mask(u32 number_of_pp_cores, u32 number_of_l2_caches);
23 /** @brief MALI inbuilt PMU hardware info and PMU hardware has knowledge of cores power mask
27 struct mali_hw_core hw_core;
28 u32 mali_registered_cores_power_mask;
31 static struct mali_pmu_core *mali_global_pmu_core = NULL;
33 /** @brief Register layout for hardware PMU
36 PMU_REG_ADDR_MGMT_POWER_UP = 0x00, /*< Power up register */
37 PMU_REG_ADDR_MGMT_POWER_DOWN = 0x04, /*< Power down register */
38 PMU_REG_ADDR_MGMT_STATUS = 0x08, /*< Core sleep status register */
39 PMU_REG_ADDR_MGMT_INT_MASK = 0x0C, /*< Interrupt mask register */
40 PMU_REGISTER_ADDRESS_SPACE_SIZE = 0x10, /*< Size of register space */
41 } pmu_reg_addr_mgmt_addr;
43 struct mali_pmu_core *mali_pmu_create(_mali_osk_resource_t *resource, u32 number_of_pp_cores, u32 number_of_l2_caches)
45 struct mali_pmu_core* pmu;
47 MALI_DEBUG_ASSERT(NULL == mali_global_pmu_core);
48 MALI_DEBUG_PRINT(2, ("Mali PMU: Creating Mali PMU core\n"));
50 pmu = (struct mali_pmu_core *)_mali_osk_malloc(sizeof(struct mali_pmu_core));
53 pmu->mali_registered_cores_power_mask = mali_pmu_detect_mask(number_of_pp_cores, number_of_l2_caches);
54 if (_MALI_OSK_ERR_OK == mali_hw_core_create(&pmu->hw_core, resource, PMU_REGISTER_ADDRESS_SPACE_SIZE))
56 if (_MALI_OSK_ERR_OK == mali_pmu_reset(pmu))
58 mali_global_pmu_core = pmu;
61 mali_hw_core_delete(&pmu->hw_core);
69 void mali_pmu_delete(struct mali_pmu_core *pmu)
71 MALI_DEBUG_ASSERT_POINTER(pmu);
73 mali_hw_core_delete(&pmu->hw_core);
78 _mali_osk_errcode_t mali_pmu_reset(struct mali_pmu_core *pmu)
80 /* Don't use interrupts - just poll status */
81 mali_hw_core_register_write(&pmu->hw_core, PMU_REG_ADDR_MGMT_INT_MASK, 0);
82 return _MALI_OSK_ERR_OK;
85 _mali_osk_errcode_t mali_pmu_powerdown_all(struct mali_pmu_core *pmu)
90 MALI_DEBUG_ASSERT_POINTER(pmu);
91 MALI_DEBUG_ASSERT( pmu->mali_registered_cores_power_mask != 0 );
92 MALI_DEBUG_PRINT( 4, ("Mali PMU: power down (0x%08X)\n", pmu->mali_registered_cores_power_mask) );
94 mali_hw_core_register_write(&pmu->hw_core, PMU_REG_ADDR_MGMT_POWER_DOWN, pmu->mali_registered_cores_power_mask);
96 /* Wait for cores to be powered down (100 x 100us = 100ms) */
97 timeout = MALI_REG_POLL_COUNT_SLOW ;
100 /* Get status of sleeping cores */
101 stat = mali_hw_core_register_read(&pmu->hw_core, PMU_REG_ADDR_MGMT_STATUS);
102 stat &= pmu->mali_registered_cores_power_mask;
103 if( stat == pmu->mali_registered_cores_power_mask ) break; /* All cores we wanted are now asleep */
105 } while( timeout > 0 );
109 return _MALI_OSK_ERR_TIMEOUT;
112 return _MALI_OSK_ERR_OK;
115 _mali_osk_errcode_t mali_pmu_powerup_all(struct mali_pmu_core *pmu)
120 MALI_DEBUG_ASSERT_POINTER(pmu);
121 MALI_DEBUG_ASSERT( pmu->mali_registered_cores_power_mask != 0 ); /* Shouldn't be zero */
122 MALI_DEBUG_PRINT( 4, ("Mali PMU: power up (0x%08X)\n", pmu->mali_registered_cores_power_mask) );
124 mali_hw_core_register_write(&pmu->hw_core, PMU_REG_ADDR_MGMT_POWER_UP, pmu->mali_registered_cores_power_mask);
126 /* Wait for cores to be powered up (100 x 100us = 100ms) */
127 timeout = MALI_REG_POLL_COUNT_SLOW;
130 /* Get status of sleeping cores */
131 stat = mali_hw_core_register_read(&pmu->hw_core,PMU_REG_ADDR_MGMT_STATUS);
132 stat &= pmu->mali_registered_cores_power_mask;
133 if ( stat == 0 ) break; /* All cores we wanted are now awake */
135 } while ( timeout > 0 );
139 return _MALI_OSK_ERR_TIMEOUT;
142 return _MALI_OSK_ERR_OK;
145 struct mali_pmu_core *mali_pmu_get_global_pmu_core(void)
147 return mali_global_pmu_core;
150 static u32 mali_pmu_detect_mask(u32 number_of_pp_cores, u32 number_of_l2_caches)
154 if (number_of_l2_caches == 1)
156 /* Mali-300 or Mali-400 */
165 /* Set bit for each PP core */
166 for (i = 0; i < number_of_pp_cores; i++)
171 else if (number_of_l2_caches > 1)
175 /* GP (including its L2 cache) */
178 /* There is always at least one PP (including its L2 cache) */
181 /* Additional PP cores in same L2 cache */
182 if (number_of_pp_cores >= 2)
187 /* Additional PP cores in a third L2 cache */
188 if (number_of_pp_cores >= 5)
194 MALI_DEBUG_PRINT(4, ("Mali PMU: Power mask is 0x%08X (%u + %u)\n", mask, number_of_pp_cores, number_of_l2_caches));