drivers: crypto: rsa_mod_exp: Add manual relocation for ops->mod_exp()
[oweals/u-boot.git] / drivers / crypto / rsa_mod_exp / mod_exp_uclass.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2014 Freescale Semiconductor, Inc
4  * Author: Ruchika Gupta <ruchika.gupta@freescale.com>
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <u-boot/rsa-mod-exp.h>
10 #include <errno.h>
11 #include <fdtdec.h>
12 #include <malloc.h>
13 #include <asm/io.h>
14 #include <linux/list.h>
15
16 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
17 DECLARE_GLOBAL_DATA_PTR;
18 #endif
19
20 int rsa_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
21                 struct key_prop *node, uint8_t *out)
22 {
23         struct mod_exp_ops *ops = (struct mod_exp_ops *)device_get_ops(dev);
24
25 #if !defined(USE_HOSTCC) && defined(CONFIG_NEEDS_MANUAL_RELOC)
26         static bool done;
27
28         if (!done) {
29                 done = true;
30                 ops->mod_exp += gd->reloc_off;
31         }
32 #endif
33
34         if (!ops->mod_exp)
35                 return -ENOSYS;
36
37         return ops->mod_exp(dev, sig, sig_len, node, out);
38 }
39
40 UCLASS_DRIVER(mod_exp) = {
41         .id             = UCLASS_MOD_EXP,
42         .name           = "rsa_mod_exp",
43 };