Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
Varun Wadekar | 43dad67 | 2017-01-31 14:53:37 -0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 7 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <arch.h> |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 10 | #include <platform.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <lib/psci/psci.h> |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 12 | |
Varun Wadekar | 43dad67 | 2017-01-31 14:53:37 -0800 | [diff] [blame] | 13 | #pragma weak plat_core_pos_by_mpidr |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 14 | |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 15 | /******************************************************************************* |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 16 | * This function implements a part of the critical interface between the psci |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 17 | * 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 Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 20 | ******************************************************************************/ |
Anthony Zhou | f9f0f5c | 2017-05-08 20:34:11 +0800 | [diff] [blame] | 21 | int32_t plat_core_pos_by_mpidr(u_register_t mpidr) |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 22 | { |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 23 | u_register_t cluster_id, cpu_id; |
Anthony Zhou | f9f0f5c | 2017-05-08 20:34:11 +0800 | [diff] [blame] | 24 | int32_t result; |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 25 | |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 26 | 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 Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 28 | |
Anthony Zhou | f9f0f5c | 2017-05-08 20:34:11 +0800 | [diff] [blame] | 29 | result = (int32_t)cpu_id + ((int32_t)cluster_id * 4); |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 30 | |
| 31 | if (cluster_id >= (u_register_t)PLATFORM_CLUSTER_COUNT) { |
| 32 | result = PSCI_E_NOT_PRESENT; |
| 33 | } |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 34 | |
| 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 Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 39 | if (cpu_id >= (u_register_t)PLATFORM_MAX_CPUS_PER_CLUSTER) { |
| 40 | result = PSCI_E_NOT_PRESENT; |
| 41 | } |
Varun Wadekar | a78bb1b | 2015-08-07 10:03:00 +0530 | [diff] [blame] | 42 | |
Varun Wadekar | e34bc3d | 2017-04-28 08:43:33 -0700 | [diff] [blame] | 43 | return result; |
Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 44 | } |