Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 1 | /* |
Jagdish Gediya | 4df2d37 | 2024-04-22 13:30:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2024, ARM Limited and Contributors. All rights reserved. |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <platform_def.h> |
| 10 | #include <cpu_macros.S> |
| 11 | |
Jagdish Gediya | 71d2d2b | 2024-07-17 15:34:28 +0100 | [diff] [blame] | 12 | #define TC_HANDLER(rev) plat_reset_handler_tc##rev |
| 13 | #define PLAT_RESET_HANDLER(rev) TC_HANDLER(rev) |
| 14 | |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 15 | .globl plat_arm_calc_core_pos |
| 16 | .globl plat_reset_handler |
| 17 | |
| 18 | /* --------------------------------------------------------------------- |
| 19 | * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) |
| 20 | * |
Usama Arif | f151362 | 2021-04-09 17:07:41 +0100 | [diff] [blame] | 21 | * Function to calculate the core position on TC. |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 22 | * |
| 23 | * (ClusterId * PLAT_MAX_CPUS_PER_CLUSTER * PLAT_MAX_PE_PER_CPU) + |
| 24 | * (CPUId * PLAT_MAX_PE_PER_CPU) + |
| 25 | * ThreadId |
| 26 | * |
| 27 | * which can be simplified as: |
| 28 | * |
| 29 | * ((ClusterId * PLAT_MAX_CPUS_PER_CLUSTER + CPUId) * PLAT_MAX_PE_PER_CPU) |
| 30 | * + ThreadId |
| 31 | * --------------------------------------------------------------------- |
| 32 | */ |
| 33 | func plat_arm_calc_core_pos |
| 34 | /* |
| 35 | * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it |
| 36 | * look as if in a multi-threaded implementation. |
| 37 | */ |
| 38 | tst x0, #MPIDR_MT_MASK |
| 39 | lsl x3, x0, #MPIDR_AFFINITY_BITS |
| 40 | csel x3, x3, x0, eq |
| 41 | |
| 42 | /* Extract individual affinity fields from MPIDR */ |
| 43 | ubfx x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS |
| 44 | ubfx x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS |
| 45 | ubfx x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS |
| 46 | |
| 47 | /* Compute linear position */ |
| 48 | mov x4, #PLAT_MAX_CPUS_PER_CLUSTER |
| 49 | madd x1, x2, x4, x1 |
| 50 | mov x5, #PLAT_MAX_PE_PER_CPU |
| 51 | madd x0, x1, x5, x0 |
| 52 | ret |
| 53 | endfunc plat_arm_calc_core_pos |
| 54 | |
Jagdish Gediya | bfab8eb | 2024-07-23 15:41:34 +0100 | [diff] [blame] | 55 | func mark_extllc_presence |
| 56 | #ifdef MCN_CONFIG_ADDR |
| 57 | mov_imm x0, (MCN_CONFIG_ADDR) |
| 58 | ldr w1, [x0] |
| 59 | ubfx x1, x1, #MCN_CONFIG_SLC_PRESENT_BIT, #1 |
| 60 | sysreg_bitfield_insert_from_gpr CPUECTLR_EL1, x1, \ |
| 61 | CPUECTLR_EL1_EXTLLC_BIT, 1 |
| 62 | #endif |
| 63 | ret |
| 64 | endfunc mark_extllc_presence |
| 65 | |
Jagdish Gediya | 71d2d2b | 2024-07-17 15:34:28 +0100 | [diff] [blame] | 66 | func enable_dsu_pmu_el1_access |
| 67 | sysreg_bit_set actlr_el2, CPUACTLR_CLUSTERPMUEN |
| 68 | sysreg_bit_set actlr_el3, CPUACTLR_CLUSTERPMUEN |
| 69 | ret |
| 70 | endfunc enable_dsu_pmu_el1_access |
| 71 | |
| 72 | func TC_HANDLER(2) |
| 73 | ret |
| 74 | endfunc TC_HANDLER(2) |
| 75 | |
| 76 | func TC_HANDLER(3) |
| 77 | mov x9, lr |
Jagdish Gediya | bfab8eb | 2024-07-23 15:41:34 +0100 | [diff] [blame] | 78 | bl mark_extllc_presence |
Jagdish Gediya | 71d2d2b | 2024-07-17 15:34:28 +0100 | [diff] [blame] | 79 | bl enable_dsu_pmu_el1_access |
| 80 | mov lr, x9 |
| 81 | ret |
| 82 | endfunc TC_HANDLER(3) |
| 83 | |
Jackson Cooper-Driver | 3653ded | 2023-12-14 14:32:40 +0000 | [diff] [blame] | 84 | func TC_HANDLER(4) |
Jagdish Gediya | eb0bcdf | 2024-06-19 06:59:22 +0000 | [diff] [blame] | 85 | mov x9, lr |
| 86 | bl enable_dsu_pmu_el1_access |
| 87 | mov lr, x9 |
Jackson Cooper-Driver | 3653ded | 2023-12-14 14:32:40 +0000 | [diff] [blame] | 88 | ret |
| 89 | endfunc TC_HANDLER(4) |
| 90 | |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 91 | /* ----------------------------------------------------- |
| 92 | * void plat_reset_handler(void); |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 93 | * ----------------------------------------------------- |
| 94 | */ |
| 95 | func plat_reset_handler |
Jagdish Gediya | 71d2d2b | 2024-07-17 15:34:28 +0100 | [diff] [blame] | 96 | mov x8, lr |
| 97 | bl PLAT_RESET_HANDLER(TARGET_PLATFORM) |
| 98 | mov lr, x8 |
Usama Arif | bec5afd | 2020-04-17 16:13:39 +0100 | [diff] [blame] | 99 | ret |
| 100 | endfunc plat_reset_handler |