blob: 4f6cf932e6cfad04cb2dbb2c9b5483633240c6f5 [file] [log] [blame]
Varun Wadekarb316e242015-05-19 16:48:04 +05301/*
Varun Wadekar43dad672017-01-31 14:53:37 -08002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Varun Wadekarb316e242015-05-19 16:48:04 +05303 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarb316e242015-05-19 16:48:04 +05305 */
6
Varun Wadekarb316e242015-05-19 16:48:04 +05307#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch.h>
Varun Wadekare34bc3d2017-04-28 08:43:33 -070010#include <platform.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <lib/psci/psci.h>
Varun Wadekarb316e242015-05-19 16:48:04 +053012
Varun Wadekar43dad672017-01-31 14:53:37 -080013#pragma weak plat_core_pos_by_mpidr
Varun Wadekara78bb1b2015-08-07 10:03:00 +053014
Varun Wadekarb316e242015-05-19 16:48:04 +053015/*******************************************************************************
Varun Wadekarb316e242015-05-19 16:48:04 +053016 * This function implements a part of the critical interface between the psci
Varun Wadekara78bb1b2015-08-07 10:03:00 +053017 * generic layer and the platform that allows the former to query the platform
18 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
19 * in case the MPIDR is invalid.
Varun Wadekarb316e242015-05-19 16:48:04 +053020 ******************************************************************************/
Anthony Zhouf9f0f5c2017-05-08 20:34:11 +080021int32_t plat_core_pos_by_mpidr(u_register_t mpidr)
Varun Wadekarb316e242015-05-19 16:48:04 +053022{
Varun Wadekare34bc3d2017-04-28 08:43:33 -070023 u_register_t cluster_id, cpu_id;
Anthony Zhouf9f0f5c2017-05-08 20:34:11 +080024 int32_t result;
Varun Wadekara78bb1b2015-08-07 10:03:00 +053025
Varun Wadekare34bc3d2017-04-28 08:43:33 -070026 cluster_id = (mpidr >> (u_register_t)MPIDR_AFF1_SHIFT) & (u_register_t)MPIDR_AFFLVL_MASK;
27 cpu_id = (mpidr >> (u_register_t)MPIDR_AFF0_SHIFT) & (u_register_t)MPIDR_AFFLVL_MASK;
Varun Wadekara78bb1b2015-08-07 10:03:00 +053028
Anthony Zhouf9f0f5c2017-05-08 20:34:11 +080029 result = (int32_t)cpu_id + ((int32_t)cluster_id * 4);
Varun Wadekare34bc3d2017-04-28 08:43:33 -070030
31 if (cluster_id >= (u_register_t)PLATFORM_CLUSTER_COUNT) {
32 result = PSCI_E_NOT_PRESENT;
33 }
Varun Wadekara78bb1b2015-08-07 10:03:00 +053034
35 /*
36 * Validate cpu_id by checking whether it represents a CPU in
37 * one of the two clusters present on the platform.
38 */
Varun Wadekare34bc3d2017-04-28 08:43:33 -070039 if (cpu_id >= (u_register_t)PLATFORM_MAX_CPUS_PER_CLUSTER) {
40 result = PSCI_E_NOT_PRESENT;
41 }
Varun Wadekara78bb1b2015-08-07 10:03:00 +053042
Varun Wadekare34bc3d2017-04-28 08:43:33 -070043 return result;
Varun Wadekarb316e242015-05-19 16:48:04 +053044}