blob: 9a2d091bea669ca13e5a0e276c80c985360e1bbe [file] [log] [blame]
Patrick Rudolphcb42bc82024-10-23 15:20:08 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2024 9elements GmbH
4 */
5
6#include <cpu.h>
7#include <init.h>
8#include <log.h>
9#include <linux/arm-smccc.h>
10
11#define SMC_SIP_FUNCTION_ID(n) (0xC2000000 | (n))
12
13#define SIP_SVC_VERSION SMC_SIP_FUNCTION_ID(1)
14#define SIP_SVC_GET_GIC SMC_SIP_FUNCTION_ID(100)
15#define SIP_SVC_GET_GIC_ITS SMC_SIP_FUNCTION_ID(101)
16#define SIP_SVC_GET_CPU_COUNT SMC_SIP_FUNCTION_ID(200)
17#define SIP_SVC_GET_CPU_NODE SMC_SIP_FUNCTION_ID(201)
18#define SIP_SVC_GET_MEMORY_NODE_COUNT SMC_SIP_FUNCTION_ID(300)
19#define SIP_SVC_GET_MEMORY_NODE SMC_SIP_FUNCTION_ID(301)
20
21int smc_get_mpidr(unsigned long id, u64 *mpidr)
22{
23 struct arm_smccc_res res;
24
25 res.a0 = ~0;
26 arm_smccc_smc(SIP_SVC_GET_CPU_NODE, id, 0, 0, 0, 0, 0, 0, &res);
27
28 if (!res.a0)
29 *mpidr = res.a2;
30
31 return res.a0;
32}
33
34int smc_get_gic_dist_base(u64 *base)
35{
36 struct arm_smccc_res res;
37
38 res.a0 = ~0;
39 arm_smccc_smc(SIP_SVC_GET_GIC, 0, 0, 0, 0, 0, 0, 0, &res);
40
41 if (!res.a0)
42 *base = res.a1;
43
44 return res.a0;
45}
46
47int smc_get_gic_redist_base(u64 *base)
48{
49 struct arm_smccc_res res;
50
51 res.a0 = ~0;
52 arm_smccc_smc(SIP_SVC_GET_GIC, 0, 0, 0, 0, 0, 0, 0, &res);
53
54 if (!res.a0)
55 *base = res.a2;
56
57 return res.a0;
58}
59
60int smc_get_gic_its_base(u64 *base)
61{
62 struct arm_smccc_res res;
63
64 res.a0 = ~0;
65 arm_smccc_smc(SIP_SVC_GET_GIC_ITS, 0, 0, 0, 0, 0, 0, 0, &res);
66
67 if (!res.a0)
68 *base = res.a1;
69
70 return res.a0;
71}