blob: 14631a776c7079f8d949218214f259b3d3aaa70d [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 Wadekarfa99b222017-08-23 16:02:06 -070026 cluster_id = (mpidr >> (u_register_t)MPIDR_AFF1_SHIFT) &
27 (u_register_t)MPIDR_AFFLVL_MASK;
28 cpu_id = (mpidr >> (u_register_t)MPIDR_AFF0_SHIFT) &
29 (u_register_t)MPIDR_AFFLVL_MASK;
Varun Wadekara78bb1b2015-08-07 10:03:00 +053030
Varun Wadekarfa99b222017-08-23 16:02:06 -070031 /* CorePos = CoreId + (ClusterId * cpus per cluster) */
32 result = (int32_t)cpu_id + ((int32_t)cluster_id *
33 PLATFORM_MAX_CPUS_PER_CLUSTER);
Varun Wadekare34bc3d2017-04-28 08:43:33 -070034
35 if (cluster_id >= (u_register_t)PLATFORM_CLUSTER_COUNT) {
36 result = PSCI_E_NOT_PRESENT;
37 }
Varun Wadekara78bb1b2015-08-07 10:03:00 +053038
39 /*
40 * Validate cpu_id by checking whether it represents a CPU in
41 * one of the two clusters present on the platform.
42 */
Varun Wadekare34bc3d2017-04-28 08:43:33 -070043 if (cpu_id >= (u_register_t)PLATFORM_MAX_CPUS_PER_CLUSTER) {
44 result = PSCI_E_NOT_PRESENT;
45 }
Varun Wadekara78bb1b2015-08-07 10:03:00 +053046
Varun Wadekare34bc3d2017-04-28 08:43:33 -070047 return result;
Varun Wadekarb316e242015-05-19 16:48:04 +053048}