summaryrefslogtreecommitdiff
path: root/cesar/hal/phy/src/pbdma.c
blob: c536d97fcc63ec038d26ae1f5286dee190ee955b (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
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/src/pbdma.c
 * \brief   HAL Phy PB DMA functions.
 * \ingroup hal_phy
 */
#include "common/std.h"

#include "inc/context.h"
#include "inc/regs.h"

void
phy_pbdma_start (phy_t *ctx, bool bypass_aes, const u32 iv[3],
                 const u32 nek[4], uint nb_total, uint nb_ready,
                 uint nb_pb_it, phy_pb_t *first_pb)
{
    dbg_assert (ctx);
    dbg_assert ((bypass_aes == true)
                || (bypass_aes == false && iv && nek));
    dbg_assert (nb_total > 0 && nb_total < 255
                && nb_total >= nb_ready
                && nb_total >= nb_pb_it);
    dbg_assert_ptr (first_pb);
    PHY_PBDMA_PTR_PB_DESC = (u32) first_pb;
    PHY_PBDMA_CONFIG_PB = BF_FILL (PHY_PBDMA_CONFIG_PB,
                                   (PB_NB_TOTAL, nb_total),
                                   (PB_NB_READY, nb_ready),
                                   (PB_NB_IT, nb_pb_it));
    if (!bypass_aes)
    {
        PHY_PBDMA_IV_0 = iv[0];
        PHY_PBDMA_IV_1 = iv[1];
        PHY_PBDMA_IV_2 = iv[2];
        PHY_PBDMA_KEY_0 = nek[0];
        PHY_PBDMA_KEY_1 = nek[1];
        PHY_PBDMA_KEY_2 = nek[2];
        PHY_PBDMA_KEY_3 = nek[3];
    }
    u32 conf = PHY_PBDMA_CTRL_CONFIG;
    if (bypass_aes)
        conf |= BF_MASK (PHY_PBDMA_CTRL_CONFIG__AES_BYPASS);
    else
        conf &= ~BF_MASK (PHY_PBDMA_CTRL_CONFIG__AES_BYPASS);
    PHY_PBDMA_CTRL_CONFIG = conf | PHY_PBDMA_CTRL_CONFIG__START_DATA;
}

void
phy_pbdma_update (phy_t *ctx, uint nb_ready, uint nb_pb_it)
{
    dbg_assert (ctx);
    uint nb_total = BF_GET (PHY_PBDMA_CONFIG_PB__PB_NB_TOTAL,
                            PHY_PBDMA_CONFIG_PB);
    dbg_assert (nb_total > 0 && nb_total < 255
                && nb_total >= nb_ready
                && nb_total >= nb_pb_it);
    PHY_PBDMA_CONFIG_PB = BF_FILL (PHY_PBDMA_CONFIG_PB,
                                   (PB_NB_TOTAL, nb_total),
                                   (PB_NB_READY, nb_ready),
                                   (PB_NB_IT, nb_pb_it));
}

phy_pb_t *
phy_pbdma_get_tail (phy_t *ctx)
{
    return (phy_pb_t *) PHY_PBDMA_PTR_PB_DESC;
}

volatile const u32 *
phy_pbdma_get_crc_bitmap (phy_t *ctx)
{
    return &PHY_PBDMA_SACKI_BITMAP_0;
}

void
phy_pbdma_start_chandata (phy_t *ctx, phy_chandata_t *first_chandata)
{
    dbg_assert (ctx);
    dbg_assert_ptr (first_chandata);
    PHY_PBDMA_PTR_CHANDATA = (u32) first_chandata;
    PHY_PBDMA_CTRL_CONFIG = PHY_PBDMA_CTRL_CONFIG
        | PHY_PBDMA_CTRL_CONFIG__START_CHANDATA;
}