2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
|
|
|
Copyright (C) 2018-20 divingkatae and maximum
|
|
|
|
(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/>.
|
|
|
|
*/
|
2020-01-05 17:38:32 +00:00
|
|
|
|
2020-02-25 02:50:52 +00:00
|
|
|
#include <thirdparty/loguru.hpp>
|
2019-08-23 21:34:19 +00:00
|
|
|
#include <cinttypes>
|
|
|
|
#include <iostream>
|
|
|
|
#include "macio.h"
|
2019-08-27 12:14:12 +00:00
|
|
|
#include "viacuda.h"
|
2020-03-15 16:24:40 +00:00
|
|
|
#include "awacs.h"
|
2020-03-18 16:34:03 +00:00
|
|
|
#include "dbdma.h"
|
2020-03-14 14:39:34 +00:00
|
|
|
#include "machines/machinebase.h"
|
2019-08-23 21:34:19 +00:00
|
|
|
|
2019-10-07 01:18:18 +00:00
|
|
|
/** Heathrow Mac I/O device emulation.
|
|
|
|
|
|
|
|
Author: Max Poliakovski 2019
|
|
|
|
*/
|
|
|
|
|
2019-08-23 21:34:19 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2019-08-27 12:14:12 +00:00
|
|
|
HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
|
|
|
|
{
|
2020-03-15 16:24:40 +00:00
|
|
|
this->nvram = new NVram();
|
2020-03-14 14:39:34 +00:00
|
|
|
|
2020-03-15 16:24:40 +00:00
|
|
|
this->viacuda = new ViaCuda();
|
2020-03-14 14:39:34 +00:00
|
|
|
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
2020-03-15 16:24:40 +00:00
|
|
|
|
|
|
|
this->screamer = new AWACDevice();
|
2020-03-18 16:34:03 +00:00
|
|
|
this->snd_out_dma = new DMAChannel();
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeathrowIC::~HeathrowIC()
|
|
|
|
{
|
2020-01-07 10:52:38 +00:00
|
|
|
if (this->nvram)
|
|
|
|
delete(this->nvram);
|
|
|
|
|
2019-08-27 12:14:12 +00:00
|
|
|
if (this->viacuda)
|
|
|
|
delete(this->viacuda);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-23 21:34:19 +00:00
|
|
|
uint32_t HeathrowIC::pci_cfg_read(uint32_t reg_offs, uint32_t size)
|
|
|
|
{
|
|
|
|
return this->pci_cfg_hdr[reg_offs & 0xFF];
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeathrowIC::pci_cfg_write(uint32_t reg_offs, uint32_t value, uint32_t size)
|
|
|
|
{
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (reg_offs) {
|
2019-08-23 21:34:19 +00:00
|
|
|
case CFG_REG_BAR0: // base address register
|
2020-02-27 02:51:07 +00:00
|
|
|
value = LE2BE(value);
|
2019-08-23 21:34:19 +00:00
|
|
|
if (value == 0xFFFFFFFF) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(ERROR, "%s err: BAR0 block size determination not \
|
|
|
|
implemented yet \n", this->name.c_str());
|
2020-02-27 02:51:07 +00:00
|
|
|
}
|
|
|
|
else if (value & 1) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(ERROR, "%s err: BAR0 I/O space not supported! \n", this->name.c_str());
|
2020-02-27 02:51:07 +00:00
|
|
|
}
|
|
|
|
else if (value & 0x06) {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(ERROR, "%s err: BAR0 64-bit I/O space not supported! \n", this->name.c_str());
|
2020-02-27 02:51:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-08-27 12:14:12 +00:00
|
|
|
this->base_addr = value & 0xFFF80000;
|
2019-08-23 21:34:19 +00:00
|
|
|
this->host_instance->pci_register_mmio_region(this->base_addr, 0x80000, this);
|
2020-02-25 02:55:33 +00:00
|
|
|
LOG_F(INFO, "%s base address set to %x \n", this->name.c_str(), this->base_addr);
|
2019-08-23 21:34:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 16:34:03 +00:00
|
|
|
uint32_t HeathrowIC::dma_read(uint32_t offset, int size)
|
|
|
|
{
|
|
|
|
uint32_t res = 0;
|
|
|
|
|
|
|
|
switch(offset >> 8) {
|
|
|
|
case 8:
|
|
|
|
res = this->snd_out_dma->reg_read(offset & 0xFF, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(WARNING, "Unsupported DMA channel read, offset=0x%X", offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeathrowIC::dma_write(uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
|
|
|
switch(offset >> 8) {
|
|
|
|
case 8:
|
|
|
|
this->snd_out_dma->reg_write(offset & 0xFF, value, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG_F(WARNING, "Unsupported DMA channel write, offset=0x%X, val=0x%X", offset, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-23 21:34:19 +00:00
|
|
|
uint32_t HeathrowIC::read(uint32_t offset, int size)
|
|
|
|
{
|
2019-08-27 12:14:12 +00:00
|
|
|
uint32_t res = 0;
|
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "%s: reading from offset %x \n", this->name.c_str(), offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-01-08 18:33:38 +00:00
|
|
|
unsigned sub_addr = (offset >> 12) & 0x7F;
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (sub_addr) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0:
|
|
|
|
res = mio_ctrl_read(offset, size);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-03-18 16:34:03 +00:00
|
|
|
res = dma_read(offset - 0x8000, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x14:
|
2020-03-15 16:24:40 +00:00
|
|
|
res = this->screamer->snd_ctrl_read(offset - 0x14000, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x16:
|
|
|
|
case 0x17:
|
|
|
|
res = this->viacuda->read((offset - 0x16000) >> 9);
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-08 18:33:38 +00:00
|
|
|
if (sub_addr >= 0x60) {
|
|
|
|
res = this->nvram->read_byte((offset - 0x60000) >> 4);
|
2020-02-27 02:51:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Attempting to read unmapped I/O space: %x \n", offset);
|
2020-01-08 18:33:38 +00:00
|
|
|
}
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2019-08-23 21:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HeathrowIC::write(uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "%s: writing to offset %x \n", this->name.c_str(), offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-01-08 18:33:38 +00:00
|
|
|
unsigned sub_addr = (offset >> 12) & 0x7F;
|
2019-08-27 12:14:12 +00:00
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (sub_addr) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0:
|
|
|
|
mio_ctrl_write(offset, value, size);
|
|
|
|
break;
|
|
|
|
case 8:
|
2020-03-18 16:34:03 +00:00
|
|
|
dma_write(offset - 0x8000, value, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x14:
|
2020-03-15 16:24:40 +00:00
|
|
|
this->screamer->snd_ctrl_write(offset - 0x14000, value, size);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
case 0x16:
|
|
|
|
case 0x17:
|
|
|
|
this->viacuda->write((offset - 0x16000) >> 9, value);
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-08 18:33:38 +00:00
|
|
|
if (sub_addr >= 0x60) {
|
|
|
|
this->nvram->write_byte((offset - 0x60000) >> 4, value);
|
2020-02-27 02:51:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "Attempting to write to unmapped I/O space: %x \n", offset);
|
2020-01-08 18:33:38 +00:00
|
|
|
}
|
2019-08-27 12:14:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HeathrowIC::mio_ctrl_read(uint32_t offset, int size)
|
|
|
|
{
|
|
|
|
uint32_t res = 0;
|
|
|
|
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (offset & 0xFF) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x24:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Int_Mask1 register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->int_mask1;
|
|
|
|
break;
|
|
|
|
case 0x28:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Int_Clear1 register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->int_clear1;
|
|
|
|
break;
|
2019-10-07 01:18:18 +00:00
|
|
|
case 0x34: /* heathrowIDs / HEATHROW_MBCR (Linux): media bay config reg? */
|
|
|
|
res = 0xF0700000UL;
|
|
|
|
break;
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x38:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "read from MIO:Feat_Ctrl register \n");
|
2019-08-27 12:14:12 +00:00
|
|
|
res = this->feat_ctrl;
|
|
|
|
break;
|
|
|
|
default:
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeathrowIC::mio_ctrl_write(uint32_t offset, uint32_t value, int size)
|
|
|
|
{
|
2020-02-27 02:51:07 +00:00
|
|
|
switch (offset & 0xFF) {
|
2019-08-27 12:14:12 +00:00
|
|
|
case 0x24:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Mask1 register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->int_mask1 = value;
|
|
|
|
break;
|
|
|
|
case 0x28:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Int_Clear1 register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->int_clear1 = value;
|
|
|
|
break;
|
|
|
|
case 0x38:
|
2020-02-27 02:51:07 +00:00
|
|
|
LOG_F(9, "write %x to MIO:Feat_Ctrl register \n", value);
|
2019-08-27 12:14:12 +00:00
|
|
|
this->feat_ctrl = value;
|
|
|
|
break;
|
|
|
|
default:
|
2020-02-25 02:50:52 +00:00
|
|
|
LOG_F(WARNING, "unknown MIO register at %x \n", offset);
|
2019-08-27 12:14:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-02-28 16:04:28 +00:00
|
|
|
}
|