Skip to content

Commit 05c2a70

Browse files
Gilad Ben-Yossefherbertx
authored andcommitted
crypto: ccree - rework cache parameters handling
Rework the setting of DMA cache parameters, program more appropriate values and explicitly set sharability domain. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent aeb4d8c commit 05c2a70

3 files changed

Lines changed: 63 additions & 20 deletions

File tree

‎drivers/crypto/ccree/cc_driver.c‎

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,57 @@ static const struct of_device_id arm_ccree_dev_of_match[] = {
100100
};
101101
MODULE_DEVICE_TABLE(of, arm_ccree_dev_of_match);
102102

103+
static void init_cc_cache_params(struct cc_drvdata *drvdata)
104+
{
105+
struct device *dev = drvdata_to_dev(drvdata);
106+
u32 cache_params, ace_const, val, mask;
107+
108+
/* compute CC_AXIM_CACHE_PARAMS */
109+
cache_params = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS));
110+
dev_dbg(dev, "Cache params previous: 0x%08X\n", cache_params);
111+
112+
/* non cached or write-back, write allocate */
113+
val = drvdata->coherent ? 0xb : 0x2;
114+
115+
mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_AWCACHE);
116+
cache_params &= ~mask;
117+
cache_params |= FIELD_PREP(mask, val);
118+
119+
mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_AWCACHE_LAST);
120+
cache_params &= ~mask;
121+
cache_params |= FIELD_PREP(mask, val);
122+
123+
mask = CC_GENMASK(CC_AXIM_CACHE_PARAMS_ARCACHE);
124+
cache_params &= ~mask;
125+
cache_params |= FIELD_PREP(mask, val);
126+
127+
drvdata->cache_params = cache_params;
128+
129+
dev_dbg(dev, "Cache params current: 0x%08X\n", cache_params);
130+
131+
if (drvdata->hw_rev <= CC_HW_REV_710)
132+
return;
133+
134+
/* compute CC_AXIM_ACE_CONST */
135+
ace_const = cc_ioread(drvdata, CC_REG(AXIM_ACE_CONST));
136+
dev_dbg(dev, "ACE-const previous: 0x%08X\n", ace_const);
137+
138+
/* system or outer-sharable */
139+
val = drvdata->coherent ? 0x2 : 0x3;
140+
141+
mask = CC_GENMASK(CC_AXIM_ACE_CONST_ARDOMAIN);
142+
ace_const &= ~mask;
143+
ace_const |= FIELD_PREP(mask, val);
144+
145+
mask = CC_GENMASK(CC_AXIM_ACE_CONST_AWDOMAIN);
146+
ace_const &= ~mask;
147+
ace_const |= FIELD_PREP(mask, val);
148+
149+
dev_dbg(dev, "ACE-const current: 0x%08X\n", ace_const);
150+
151+
drvdata->ace_const = ace_const;
152+
}
153+
103154
static u32 cc_read_idr(struct cc_drvdata *drvdata, const u32 *idr_offsets)
104155
{
105156
int i;
@@ -218,9 +269,9 @@ bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata)
218269
return false;
219270
}
220271

221-
int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe)
272+
int init_cc_regs(struct cc_drvdata *drvdata)
222273
{
223-
unsigned int val, cache_params;
274+
unsigned int val;
224275
struct device *dev = drvdata_to_dev(drvdata);
225276

226277
/* Unmask all AXI interrupt sources AXI_CFG1 register */
@@ -245,19 +296,9 @@ int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe)
245296

246297
cc_iowrite(drvdata, CC_REG(HOST_IMR), ~val);
247298

248-
cache_params = (drvdata->coherent ? CC_COHERENT_CACHE_PARAMS : 0x0);
249-
250-
val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS));
251-
252-
if (is_probe)
253-
dev_dbg(dev, "Cache params previous: 0x%08X\n", val);
254-
255-
cc_iowrite(drvdata, CC_REG(AXIM_CACHE_PARAMS), cache_params);
256-
val = cc_ioread(drvdata, CC_REG(AXIM_CACHE_PARAMS));
257-
258-
if (is_probe)
259-
dev_dbg(dev, "Cache params current: 0x%08X (expect: 0x%08X)\n",
260-
val, cache_params);
299+
cc_iowrite(drvdata, CC_REG(AXIM_CACHE_PARAMS), drvdata->cache_params);
300+
if (drvdata->hw_rev >= CC_HW_REV_712)
301+
cc_iowrite(drvdata, CC_REG(AXIM_ACE_CONST), drvdata->ace_const);
261302

262303
return 0;
263304
}
@@ -445,7 +486,9 @@ static int init_cc_resources(struct platform_device *plat_dev)
445486
}
446487
dev_dbg(dev, "Registered to IRQ: %d\n", irq);
447488

448-
rc = init_cc_regs(new_drvdata, true);
489+
init_cc_cache_params(new_drvdata);
490+
491+
rc = init_cc_regs(new_drvdata);
449492
if (rc) {
450493
dev_err(dev, "init_cc_regs failed\n");
451494
goto post_pm_err;

‎drivers/crypto/ccree/cc_driver.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ enum cc_std_body {
5050
CC_STD_ALL = 0x3
5151
};
5252

53-
#define CC_COHERENT_CACHE_PARAMS 0xEEE
54-
5553
#define CC_PINS_FULL 0x0
5654
#define CC_PINS_SLIM 0x9F
5755

@@ -156,6 +154,8 @@ struct cc_drvdata {
156154
int std_bodies;
157155
bool sec_disabled;
158156
u32 comp_mask;
157+
u32 cache_params;
158+
u32 ace_const;
159159
};
160160

161161
struct cc_crypto_alg {
@@ -206,7 +206,7 @@ static inline void dump_byte_array(const char *name, const u8 *the_array,
206206
}
207207

208208
bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata);
209-
int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe);
209+
int init_cc_regs(struct cc_drvdata *drvdata);
210210
void fini_cc_regs(struct cc_drvdata *drvdata);
211211
unsigned int cc_get_default_hash_len(struct cc_drvdata *drvdata);
212212

‎drivers/crypto/ccree/cc_pm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int cc_pm_resume(struct device *dev)
4545
}
4646

4747
cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
48-
rc = init_cc_regs(drvdata, false);
48+
rc = init_cc_regs(drvdata);
4949
if (rc) {
5050
dev_err(dev, "init_cc_regs (%x)\n", rc);
5151
return rc;

0 commit comments

Comments
 (0)