summaryrefslogtreecommitdiff
path: root/xen/arch/arm/tee/tee.c
blob: 3964a8a5cddf1d0afbf9de95b44b6dac1a2d5c64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * xen/arch/arm/tee/tee.c
 *
 * Generic part of TEE mediator subsystem
 *
 * Volodymyr Babchuk <volodymyr_babchuk@epam.com>
 * Copyright (c) 2018-2019 EPAM Systems.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <xen/errno.h>
#include <xen/init.h>
#include <xen/types.h>

#include <asm/tee/tee.h>

extern const struct tee_mediator_desc _steemediator[], _eteemediator[];
static const struct tee_mediator_desc __read_mostly *cur_mediator;

/*
 * TODO: Add function to alter Dom0 DTB, so we can properly describe
 * present TEE.
 */

bool tee_handle_call(struct cpu_user_regs *regs)
{
    if ( unlikely(!cur_mediator) )
        return false;

    return cur_mediator->ops->handle_call(regs);
}

int tee_domain_init(struct domain *d, uint16_t tee_type)
{
    if ( tee_type == XEN_DOMCTL_CONFIG_TEE_NONE )
        return 0;

    if ( !cur_mediator )
        return -ENODEV;

    if ( cur_mediator->tee_type != tee_type )
        return -EINVAL;

    return cur_mediator->ops->domain_init(d);
}

int tee_relinquish_resources(struct domain *d)
{
    if ( !cur_mediator )
        return 0;

    return cur_mediator->ops->relinquish_resources(d);
}

uint16_t tee_get_type(void)
{
    if ( !cur_mediator )
        return XEN_DOMCTL_CONFIG_TEE_NONE;

    return cur_mediator->tee_type;
}


static int __init tee_init(void)
{
    const struct tee_mediator_desc *desc;

    for ( desc = _steemediator; desc != _eteemediator; desc++ )
    {
        if ( desc->ops->probe() )
        {
            printk(XENLOG_INFO "Using TEE mediator for %s\n", desc->name);
            cur_mediator = desc;
            return 0;
        }
    }

    return 0;
}

__initcall(tee_init);

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */