2 * Copyright (c) 2014-2015 ARM Limited
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * Authors: Andreas Sandberg
20 #include "gpublock.hh"
23 #include "regutils.hh"
27 GPUBlock::GPUBlock(GPU
&_gpu
)
28 : gpu(_gpu
), regs(BLOCK_NUM_REGS
)
32 GPUBlock::GPUBlock(GPU
&_gpu
, RegVector::size_type no_regs
)
33 : gpu(_gpu
), regs(no_regs
)
37 GPUBlock::GPUBlock(GPUBlock
&&rhs
)
39 regs(std::move(rhs
.regs
))
55 GPUBlock::readReg(RegAddr addr
)
57 return readRegRaw(addr
);
61 GPUBlock::writeReg(RegAddr addr
, uint32_t value
)
63 writeRegRaw(addr
, value
);
67 GPUBlock::readRegRaw(RegAddr addr
)
73 GPUBlock::writeRegRaw(RegAddr addr
, uint32_t value
)
80 GPUBlockInt::GPUBlockInt(GPU
&_gpu
,
81 const RegAddr
&irq_raw_stat
,
82 const RegAddr
&irq_clear
,
83 const RegAddr
&irq_mask
,
84 const RegAddr
&irq_stat
)
86 addrIrqRawStat(irq_raw_stat
), addrIrqClear(irq_clear
),
87 addrIrqMask(irq_mask
), addrIrqStat(irq_stat
)
91 GPUBlockInt::~GPUBlockInt()
96 GPUBlockInt::readReg(RegAddr addr
)
98 if (addr
== addrIrqStat
) {
101 return GPUBlock::readReg(addr
);
106 GPUBlockInt::writeReg(RegAddr addr
, uint32_t value
)
108 if (addr
== addrIrqRawStat
) {
109 raiseInterrupt(value
);
110 } else if (addr
== addrIrqClear
) {
111 clearInterrupt(value
);
112 } else if (addr
== addrIrqMask
) {
113 const bool old_int(intAsserted());
114 GPUBlock::writeReg(addr
, value
);
115 if (old_int
!= intAsserted())
116 onInterrupt(intAsserted());
117 } else if (addr
== addrIrqStat
) {
118 // Ignore writes to the IRQ status register
120 // Handle addrIrqMask & defaults
121 GPUBlock::writeReg(addr
, value
);
128 GPUBlockInt::raiseInterrupt(uint32_t ints
)
130 const bool old_int(intAsserted());
132 regs
[addrIrqRawStat
] |= ints
;
133 // Is the interrupt line going high?
134 if (!old_int
&& intAsserted())
139 GPUBlockInt::clearInterrupt(uint32_t ints
)
141 const bool old_int(intAsserted());
143 regs
[addrIrqRawStat
] &= ~ints
;
144 // Is the interrupt line going low?
145 if (old_int
&& !intAsserted())
150 GPUBlockInt::irqStatus() const
152 return regs
[addrIrqRawStat
] & regs
[addrIrqMask
];