1/*
2 * Copyright (c) 2014-2015 ARM Limited
3 * All rights reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "gpu.hh"
19
20#include "gpucontrol.hh"
21#include "jobcontrol.hh"
22#include "mmu.hh"
23#include "regutils.hh"
24
25namespace NoMali {
26
27GPU::GPU(GPUControl &gc, JobControl &jc, MMU &_mmu)
28    : gpuControl(gc), jobControl(jc), mmu(_mmu),
29      blocks({&gpuControl, // REG_BLOCK_GPU
30              &jobControl, // REG_BLOCK_JOB
31              &mmu})       // REG_BLOCK_MMU
32{
33}
34
35GPU::~GPU()
36{
37}
38
39void
40GPU::reset()
41{
42    for (auto *block : blocks)
43        block->reset();
44}
45
46uint32_t
47GPU::readReg(RegAddr addr)
48{
49    GPUBlock * const block(getGPUBlock(addr));
50
51    return block ? block->readReg(getBlockReg(addr)) : 0;
52}
53
54void
55GPU::writeReg(RegAddr addr, uint32_t value)
56{
57    GPUBlock * const block(getGPUBlock(addr));
58
59    if (block)
60        block->writeReg(getBlockReg(addr), value);
61}
62
63uint32_t
64GPU::readRegRaw(RegAddr addr)
65{
66    GPUBlock * const block(getGPUBlock(addr));
67
68    return block ? block->readRegRaw(getBlockReg(addr)) : 0;
69}
70
71void
72GPU::writeRegRaw(RegAddr addr, uint32_t value)
73{
74    GPUBlock * const block(getGPUBlock(addr));
75
76    if (block)
77        block->writeRegRaw(getBlockReg(addr), value);
78}
79
80
81bool
82GPU::intGPUAsserted() const
83{
84    return gpuControl.intAsserted();
85}
86
87bool
88GPU::intJobAsserted() const
89{
90    return jobControl.intAsserted();
91}
92
93bool
94GPU::intMMUAsserted() const
95{
96    return mmu.intAsserted();
97}
98
99
100GPUBlock *
101GPU::getGPUBlock(RegAddr addr)
102{
103    const RegBlock block(getRegBlock(addr));
104    const uint16_t block_no(static_cast<uint16_t>(block));
105
106    if (block_no < blocks.size())
107        return blocks[block_no];
108    else
109        return nullptr;
110}
111
112}
113