blob: cc2d58c0138e67de51aab96e0e5e33269c94f88c [file] [log] [blame]
Yann Gautierece4c252023-06-13 18:45:03 +02001/*
2 * Copyright (c) 2024, STMicroelectronics - All Rights Reserved
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <lib/psci/psci.h>
8#include <plat/common/platform.h>
9
10#include <platform_def.h>
11
12/* 1 cluster, all cores into */
13static const unsigned char stm32mp2_power_domain_tree_desc[] = {
14 PLATFORM_CLUSTER_COUNT,
15 PLATFORM_CORE_COUNT,
16};
17
18/* This function returns the platform topology */
19const unsigned char *plat_get_power_domain_tree_desc(void)
20{
21 return stm32mp2_power_domain_tree_desc;
22}
23
24/*******************************************************************************
25 * This function implements a part of the critical interface between the psci
26 * generic layer and the platform that allows the former to query the platform
27 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
28 * in case the MPIDR is invalid.
29 ******************************************************************************/
30int plat_core_pos_by_mpidr(u_register_t mpidr)
31{
32 unsigned int cluster_id, cpu_id;
33 u_register_t mpidr_copy = mpidr;
34
35 mpidr_copy &= MPIDR_AFFINITY_MASK;
36
37 if ((mpidr_copy & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) != 0U) {
38 return -1;
39 }
40
41 cluster_id = (mpidr_copy >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
42 cpu_id = (mpidr_copy >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
43
44 if (cluster_id >= PLATFORM_CLUSTER_COUNT) {
45 return -1;
46 }
47
48 /*
49 * Validate cpu_id by checking whether it represents a CPU in one
50 * of the two clusters present on the platform.
51 */
52 if (cpu_id >= PLATFORM_CORE_COUNT) {
53 return -1;
54 }
55
56 return (int)cpu_id;
57}