blob: 4e17390cecf8315075b8ed66321720db4533b728 [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"
Alex Leibovich6a99b192019-12-25 09:22:48 +020020#include "ddr_phy_access.h"
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020021#include <stdbool.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030022
23/* #define DEBUG_COMPHY */
24#ifdef DEBUG_COMPHY
25#define debug(format...) NOTICE(format)
26#else
27#define debug(format, arg...)
28#endif
29
30/* Comphy related FID's */
31#define MV_SIP_COMPHY_POWER_ON 0x82000001
32#define MV_SIP_COMPHY_POWER_OFF 0x82000002
33#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
34#define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
35#define MV_SIP_COMPHY_DIG_RESET 0x82000005
36
37/* Miscellaneous FID's' */
38#define MV_SIP_DRAM_SIZE 0x82000010
39#define MV_SIP_LLC_ENABLE 0x82000011
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010040#define MV_SIP_PMU_IRQ_ENABLE 0x82000012
41#define MV_SIP_PMU_IRQ_DISABLE 0x82000013
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +010042#define MV_SIP_DFX 0x82000014
Alex Leibovich6a99b192019-12-25 09:22:48 +020043#define MV_SIP_DDR_PHY_WRITE 0x82000015
44#define MV_SIP_DDR_PHY_READ 0x82000016
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030045
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030046/* TRNG */
47#define MV_SIP_RNG_64 0xC200FF11
48
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030049#define MAX_LANE_NR 6
50#define MVEBU_COMPHY_OFFSET 0x441000
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020051#define MVEBU_CP_BASE_MASK (~0xffffff)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030052
Alex Evraevb0a74302020-06-24 22:24:56 +030053/* Common PHY register */
54#define COMPHY_TRX_TRAIN_CTRL_REG_0_OFFS 0x120a2c
55
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030056/* This macro is used to identify COMPHY related calls from SMC function ID */
57#define is_comphy_fid(fid) \
58 ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
59
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020060_Bool is_cp_range_valid(u_register_t *addr)
61{
62 int cp_nr;
63
64 *addr &= MVEBU_CP_BASE_MASK;
65 for (cp_nr = 0; cp_nr < CP_NUM; cp_nr++) {
66 if (*addr == MVEBU_CP_REGS_BASE(cp_nr))
67 return true;
68 }
69
70 return false;
71}
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030072
73uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
74 u_register_t x1,
75 u_register_t x2,
76 u_register_t x3,
77 u_register_t x4,
78 void *cookie,
79 void *handle,
80 u_register_t flags)
81{
Alex Evraevb0a74302020-06-24 22:24:56 +030082 u_register_t ret, read, x5 = x1;
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030083 uint32_t w2[2] = {0, 0};
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030084 int i;
85
86 debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
87 __func__, smc_fid, x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030088
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020089 if (is_comphy_fid(smc_fid)) {
90 /* validate address passed via x1 */
91 if (!is_cp_range_valid(&x1)) {
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030092 ERROR("%s: Wrong smc (0x%x) address: %lx\n",
93 __func__, smc_fid, x1);
94 SMC_RET1(handle, SMC_UNK);
95 }
96
Alex Evraevb0a74302020-06-24 22:24:56 +030097 x5 = x1 + COMPHY_TRX_TRAIN_CTRL_REG_0_OFFS;
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020098 x1 += MVEBU_COMPHY_OFFSET;
99
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300100 if (x2 >= MAX_LANE_NR) {
101 ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
102 __func__, smc_fid, x2);
103 SMC_RET1(handle, SMC_UNK);
104 }
105 }
106
107 switch (smc_fid) {
108
109 /* Comphy related FID's */
110 case MV_SIP_COMPHY_POWER_ON:
111 /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
Alex Evraevb0a74302020-06-24 22:24:56 +0300112 ret = mvebu_cp110_comphy_power_on(x1, x2, x3, x5);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300113 SMC_RET1(handle, ret);
114 case MV_SIP_COMPHY_POWER_OFF:
115 /* x1: comphy_base, x2: comphy_index */
Igal Libermanbd51efd2018-11-15 16:13:11 +0200116 ret = mvebu_cp110_comphy_power_off(x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300117 SMC_RET1(handle, ret);
118 case MV_SIP_COMPHY_PLL_LOCK:
119 /* x1: comphy_base, x2: comphy_index */
120 ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
121 SMC_RET1(handle, ret);
122 case MV_SIP_COMPHY_XFI_TRAIN:
123 /* x1: comphy_base, x2: comphy_index */
124 ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
125 SMC_RET1(handle, ret);
126 case MV_SIP_COMPHY_DIG_RESET:
127 /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
128 ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
129 SMC_RET1(handle, ret);
130
131 /* Miscellaneous FID's' */
132 case MV_SIP_DRAM_SIZE:
Grzegorz Jaszczyk5339f6f2019-04-04 17:20:05 +0200133 ret = mvebu_get_dram_size(MVEBU_REGS_BASE);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300134 SMC_RET1(handle, ret);
135 case MV_SIP_LLC_ENABLE:
136 for (i = 0; i < ap_get_count(); i++)
137 llc_runtime_enable(i);
138
139 SMC_RET1(handle, 0);
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +0100140#ifdef MVEBU_PMU_IRQ_WA
141 case MV_SIP_PMU_IRQ_ENABLE:
142 mvebu_pmu_interrupt_enable();
143 SMC_RET1(handle, 0);
144 case MV_SIP_PMU_IRQ_DISABLE:
145 mvebu_pmu_interrupt_disable();
146 SMC_RET1(handle, 0);
147#endif
Grzegorz Jaszczyka3173d62019-12-18 15:58:27 +0100148 case MV_SIP_DFX:
Grzegorz Jaszczyk755f0782020-01-02 16:14:13 +0100149 if (x1 >= MV_SIP_DFX_THERMAL_INIT &&
150 x1 <= MV_SIP_DFX_THERMAL_SEL_CHANNEL) {
151 ret = mvebu_dfx_thermal_handle(x1, &read, x2, x3);
152 SMC_RET2(handle, ret, read);
153 }
Grzegorz Jaszczyk7d509722020-01-03 09:35:21 +0100154 if (x1 >= MV_SIP_DFX_SREAD && x1 <= MV_SIP_DFX_SWRITE) {
155 ret = mvebu_dfx_misc_handle(x1, &read, x2, x3);
156 SMC_RET2(handle, ret, read);
157 }
158
Grzegorz Jaszczyk755f0782020-01-02 16:14:13 +0100159 SMC_RET1(handle, SMC_UNK);
Alex Leibovich6a99b192019-12-25 09:22:48 +0200160 case MV_SIP_DDR_PHY_WRITE:
161 ret = mvebu_ddr_phy_write(x1, x2);
162 SMC_RET1(handle, ret);
163 case MV_SIP_DDR_PHY_READ:
164 read = 0;
165 ret = mvebu_ddr_phy_read(x1, (uint16_t *)&read);
166 SMC_RET2(handle, ret, read);
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300167 case MV_SIP_RNG_64:
168 ret = eip76_rng_get_random((uint8_t *)&w2, 4 * (x1 % 2 + 1));
169 SMC_RET3(handle, ret, w2[0], w2[1]);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300170 default:
171 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
172 SMC_RET1(handle, SMC_UNK);
173 }
174}
175
176/* Define a runtime service descriptor for fast SMC calls */
177DECLARE_RT_SVC(
178 marvell_sip_svc,
179 OEN_SIP_START,
180 OEN_SIP_END,
181 SMC_TYPE_FAST,
182 NULL,
183 mrvl_sip_smc_handler
184);