summaryrefslogtreecommitdiff
path: root/ext/nomali/lib/gpublock.cc
blob: 7bc88de7ee8f58e351ffeb2aafd7ec710a2098a2 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (c) 2014-2015 ARM Limited
 * All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Authors: Andreas Sandberg
 */

#include "gpublock.hh"

#include "gpu.hh"
#include "regutils.hh"

namespace NoMali {

GPUBlock::GPUBlock(GPU &_gpu)
    : gpu(_gpu), regs(BLOCK_NUM_REGS)
{
}

GPUBlock::GPUBlock(GPU &_gpu, RegVector::size_type no_regs)
    : gpu(_gpu), regs(no_regs)
{
}

GPUBlock::GPUBlock(GPUBlock &&rhs)
    : gpu(rhs.gpu),
      regs(std::move(rhs.regs))
{
}

GPUBlock::~GPUBlock()
{
}

void
GPUBlock::reset()
{
    for (auto &r : regs)
        r = 0;
}

uint32_t
GPUBlock::readReg(RegAddr addr)
{
    return readRegRaw(addr);
}

void
GPUBlock::writeReg(RegAddr addr, uint32_t value)
{
    writeRegRaw(addr, value);
}

uint32_t
GPUBlock::readRegRaw(RegAddr addr)
{
    return regs[addr];
}

void
GPUBlock::writeRegRaw(RegAddr addr, uint32_t value)
{
    regs[addr] = value;
}



GPUBlockInt::GPUBlockInt(GPU &_gpu,
                         const RegAddr &irq_raw_stat,
                         const RegAddr &irq_clear,
                         const RegAddr &irq_mask,
                         const RegAddr &irq_stat)
    : GPUBlock(_gpu),
      addrIrqRawStat(irq_raw_stat), addrIrqClear(irq_clear),
      addrIrqMask(irq_mask), addrIrqStat(irq_stat)
{
}

GPUBlockInt::~GPUBlockInt()
{
}

uint32_t
GPUBlockInt::readReg(RegAddr addr)
{
    if (addr == addrIrqStat) {
        return irqStatus();
    } else {
        return GPUBlock::readReg(addr);
    }
}

void
GPUBlockInt::writeReg(RegAddr addr, uint32_t value)
{
    if (addr == addrIrqRawStat) {
        raiseInterrupt(value);
    } else if (addr == addrIrqClear) {
        clearInterrupt(value);
    } else if (addr == addrIrqMask ) {
        const bool old_int(intAsserted());
        GPUBlock::writeReg(addr, value);
        if (old_int != intAsserted())
            onInterrupt(intAsserted());
    } else if (addr == addrIrqStat ) {
        // Ignore writes to the IRQ status register
    } else {
        // Handle addrIrqMask & defaults
        GPUBlock::writeReg(addr, value);
    }
}



void
GPUBlockInt::raiseInterrupt(uint32_t ints)
{
    const bool old_int(intAsserted());

    regs[addrIrqRawStat] |= ints;
    // Is the interrupt line going high?
    if (!old_int && intAsserted())
        onInterrupt(1);
}

void
GPUBlockInt::clearInterrupt(uint32_t ints)
{
    const bool old_int(intAsserted());

    regs[addrIrqRawStat] &= ~ints;
    // Is the interrupt line going low?
    if (old_int && !intAsserted())
        onInterrupt(0);
}

uint32_t
GPUBlockInt::irqStatus() const
{
    return regs[addrIrqRawStat] & regs[addrIrqMask];
}


}