blob: aa94393013850619b581aefd04d120a07bb8a3d9 [file] [log] [blame]
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +03001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <common/debug.h>
9#include <common/runtime_svc.h>
10#include <drivers/marvell/cache_llc.h>
11#include <drivers/marvell/mochi/ap_setup.h>
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030012#include <drivers/rambus/trng_ip_76.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/smccc.h>
14
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030015#include <marvell_plat_priv.h>
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010016#include <plat_marvell.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030018#include "comphy/phy-comphy-cp110.h"
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +010019#include "secure_dfx_access/dfx.h"
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020020#include <stdbool.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030021
22/* #define DEBUG_COMPHY */
23#ifdef DEBUG_COMPHY
24#define debug(format...) NOTICE(format)
25#else
26#define debug(format, arg...)
27#endif
28
29/* Comphy related FID's */
30#define MV_SIP_COMPHY_POWER_ON 0x82000001
31#define MV_SIP_COMPHY_POWER_OFF 0x82000002
32#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
33#define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
34#define MV_SIP_COMPHY_DIG_RESET 0x82000005
35
36/* Miscellaneous FID's' */
37#define MV_SIP_DRAM_SIZE 0x82000010
38#define MV_SIP_LLC_ENABLE 0x82000011
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010039#define MV_SIP_PMU_IRQ_ENABLE 0x82000012
40#define MV_SIP_PMU_IRQ_DISABLE 0x82000013
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +010041#define MV_SIP_DFX 0x82000014
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030042
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030043/* TRNG */
44#define MV_SIP_RNG_64 0xC200FF11
45
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030046#define MAX_LANE_NR 6
47#define MVEBU_COMPHY_OFFSET 0x441000
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020048#define MVEBU_CP_BASE_MASK (~0xffffff)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030049
50/* This macro is used to identify COMPHY related calls from SMC function ID */
51#define is_comphy_fid(fid) \
52 ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
53
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020054_Bool is_cp_range_valid(u_register_t *addr)
55{
56 int cp_nr;
57
58 *addr &= MVEBU_CP_BASE_MASK;
59 for (cp_nr = 0; cp_nr < CP_NUM; cp_nr++) {
60 if (*addr == MVEBU_CP_REGS_BASE(cp_nr))
61 return true;
62 }
63
64 return false;
65}
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030066
67uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
68 u_register_t x1,
69 u_register_t x2,
70 u_register_t x3,
71 u_register_t x4,
72 void *cookie,
73 void *handle,
74 u_register_t flags)
75{
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +010076 u_register_t ret, read;
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030077 uint32_t w2[2] = {0, 0};
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030078 int i;
79
80 debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
81 __func__, smc_fid, x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030082
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020083 if (is_comphy_fid(smc_fid)) {
84 /* validate address passed via x1 */
85 if (!is_cp_range_valid(&x1)) {
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030086 ERROR("%s: Wrong smc (0x%x) address: %lx\n",
87 __func__, smc_fid, x1);
88 SMC_RET1(handle, SMC_UNK);
89 }
90
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020091 x1 += MVEBU_COMPHY_OFFSET;
92
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030093 if (x2 >= MAX_LANE_NR) {
94 ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
95 __func__, smc_fid, x2);
96 SMC_RET1(handle, SMC_UNK);
97 }
98 }
99
100 switch (smc_fid) {
101
102 /* Comphy related FID's */
103 case MV_SIP_COMPHY_POWER_ON:
104 /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
105 ret = mvebu_cp110_comphy_power_on(x1, x2, x3);
106 SMC_RET1(handle, ret);
107 case MV_SIP_COMPHY_POWER_OFF:
108 /* x1: comphy_base, x2: comphy_index */
Igal Libermanbd51efd2018-11-15 16:13:11 +0200109 ret = mvebu_cp110_comphy_power_off(x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300110 SMC_RET1(handle, ret);
111 case MV_SIP_COMPHY_PLL_LOCK:
112 /* x1: comphy_base, x2: comphy_index */
113 ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
114 SMC_RET1(handle, ret);
115 case MV_SIP_COMPHY_XFI_TRAIN:
116 /* x1: comphy_base, x2: comphy_index */
117 ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
118 SMC_RET1(handle, ret);
119 case MV_SIP_COMPHY_DIG_RESET:
120 /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
121 ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
122 SMC_RET1(handle, ret);
123
124 /* Miscellaneous FID's' */
125 case MV_SIP_DRAM_SIZE:
Grzegorz Jaszczyk5339f6f2019-04-04 17:20:05 +0200126 ret = mvebu_get_dram_size(MVEBU_REGS_BASE);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300127 SMC_RET1(handle, ret);
128 case MV_SIP_LLC_ENABLE:
129 for (i = 0; i < ap_get_count(); i++)
130 llc_runtime_enable(i);
131
132 SMC_RET1(handle, 0);
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +0100133#ifdef MVEBU_PMU_IRQ_WA
134 case MV_SIP_PMU_IRQ_ENABLE:
135 mvebu_pmu_interrupt_enable();
136 SMC_RET1(handle, 0);
137 case MV_SIP_PMU_IRQ_DISABLE:
138 mvebu_pmu_interrupt_disable();
139 SMC_RET1(handle, 0);
140#endif
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +0100141 case MV_SIP_DFX:
Grzegorz Jaszczyk755f0782020-01-02 16:14:13 +0100142 if (x1 >= MV_SIP_DFX_THERMAL_INIT &&
143 x1 <= MV_SIP_DFX_THERMAL_SEL_CHANNEL) {
144 ret = mvebu_dfx_thermal_handle(x1, &read, x2, x3);
145 SMC_RET2(handle, ret, read);
146 }
147 SMC_RET1(handle, SMC_UNK);
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300148 case MV_SIP_RNG_64:
149 ret = eip76_rng_get_random((uint8_t *)&w2, 4 * (x1 % 2 + 1));
150 SMC_RET3(handle, ret, w2[0], w2[1]);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300151 default:
152 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
153 SMC_RET1(handle, SMC_UNK);
154 }
155}
156
157/* Define a runtime service descriptor for fast SMC calls */
158DECLARE_RT_SVC(
159 marvell_sip_svc,
160 OEN_SIP_START,
161 OEN_SIP_END,
162 SMC_TYPE_FAST,
163 NULL,
164 mrvl_sip_smc_handler
165);