2020-12-19 08:41:12 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2021-10-23 19:00:31 +00:00
|
|
|
Copyright (C) 2018-21 divingkatae and maximum
|
2020-12-19 08:41:12 +00:00
|
|
|
(theweirdo) spatium
|
|
|
|
|
|
|
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Highspeed Memory Controller emulation.
|
|
|
|
|
|
|
|
Author: Max Poliakovski
|
|
|
|
*/
|
|
|
|
|
2022-01-26 15:45:21 +00:00
|
|
|
#include <devices/common/hwcomponent.h>
|
2021-10-23 18:17:47 +00:00
|
|
|
#include <devices/memctrl/hmc.h>
|
2020-12-19 08:41:12 +00:00
|
|
|
|
|
|
|
HMC::HMC() : MemCtrlBase()
|
|
|
|
{
|
|
|
|
this->name = "Highspeed Memory Controller";
|
|
|
|
|
2022-01-26 15:45:21 +00:00
|
|
|
supports_types(HWCompType::MEM_CTRL | HWCompType::MMIO_DEV);
|
|
|
|
|
2020-12-19 08:41:12 +00:00
|
|
|
/* add memory mapped I/O region for the HMC control register */
|
2021-09-30 20:55:10 +00:00
|
|
|
add_mmio_region(0x50F40000, 0x10000, this);
|
2020-12-19 08:41:12 +00:00
|
|
|
|
2021-12-07 21:48:33 +00:00
|
|
|
this->ctrl_reg = 0ULL;
|
2020-12-19 08:41:12 +00:00
|
|
|
this->bit_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size)
|
|
|
|
{
|
|
|
|
if (!offset)
|
2021-12-07 21:48:33 +00:00
|
|
|
return !!(this->ctrl_reg & (1ULL << this->bit_pos++));
|
2020-12-19 08:41:12 +00:00
|
|
|
else
|
|
|
|
return 0; /* FIXME: what should be returned for invalid offsets? */
|
|
|
|
}
|
|
|
|
|
|
|
|
void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
|
|
|
uint64_t bit;
|
|
|
|
|
|
|
|
switch(offset) {
|
|
|
|
case 0:
|
|
|
|
bit = 1ULL << this->bit_pos++;
|
2021-12-07 21:48:33 +00:00
|
|
|
this->ctrl_reg = (value & 1) ? this->ctrl_reg | bit :
|
|
|
|
this->ctrl_reg & ~bit;
|
2020-12-19 08:41:12 +00:00
|
|
|
break;
|
|
|
|
case 8: /* writing to HMCBase + 8 resets internal bit position */
|
|
|
|
this->bit_pos = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|