|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "dma.h"
|
|
|
|
|
#include "YBaseLib/Log.h"
|
|
|
|
|
#include "bus.h"
|
|
|
|
|
#include "gpu.h"
|
|
|
|
|
Log_SetChannel(DMA);
|
|
|
|
|
|
|
|
|
|
DMA::DMA() = default;
|
|
|
|
@ -60,7 +61,7 @@ void DMA::WriteRegister(u32 offset, u32 value)
|
|
|
|
|
{
|
|
|
|
|
case 0x00:
|
|
|
|
|
{
|
|
|
|
|
state.base_address = value & BASE_ADDRESS_MASK;
|
|
|
|
|
state.base_address = value & ADDRESS_MASK;
|
|
|
|
|
Log_DebugPrintf("DMA channel %u base address <- 0x%08X", channel_index, state.base_address);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -136,44 +137,97 @@ bool DMA::CanRunChannel(Channel channel) const
|
|
|
|
|
void DMA::RunDMA(Channel channel)
|
|
|
|
|
{
|
|
|
|
|
ChannelState& cs = m_state[static_cast<u32>(channel)];
|
|
|
|
|
const PhysicalMemoryAddress memory_address = cs.base_address;
|
|
|
|
|
const bool copy_to_device = cs.channel_control.copy_to_device;
|
|
|
|
|
Log_DebugPrintf("Running DMA for channel %u", static_cast<u32>(channel));
|
|
|
|
|
Assert(Common::IsAlignedPow2(memory_address, 4));
|
|
|
|
|
|
|
|
|
|
// start/trigger bit is cleared on beginning of transfer
|
|
|
|
|
cs.channel_control.start_trigger = false;
|
|
|
|
|
|
|
|
|
|
PhysicalMemoryAddress current_address = cs.base_address & ~UINT32_C(3);
|
|
|
|
|
const PhysicalMemoryAddress increment = cs.channel_control.address_step_reverse ? static_cast<u32>(-4) : UINT32_C(4);
|
|
|
|
|
switch (cs.channel_control.sync_mode)
|
|
|
|
|
{
|
|
|
|
|
case SyncMode::Manual:
|
|
|
|
|
{
|
|
|
|
|
const u32 word_count = cs.block_control.manual.GetWordCount();
|
|
|
|
|
Log_DebugPrintf(" ... copying %u words %s 0x%08X", word_count, copy_to_device ? "from" : "to", memory_address);
|
|
|
|
|
Log_DebugPrintf(" ... copying %u words %s 0x%08X", word_count, copy_to_device ? "from" : "to", current_address);
|
|
|
|
|
if (copy_to_device)
|
|
|
|
|
{
|
|
|
|
|
for (u32 i = 0; i < word_count; i++)
|
|
|
|
|
u32 words_remaining = word_count;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
u32 memory_value = 0;
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Read, MemoryAccessSize::Word>(memory_address, memory_address,
|
|
|
|
|
memory_value);
|
|
|
|
|
DMAWrite(channel, memory_value);
|
|
|
|
|
}
|
|
|
|
|
words_remaining--;
|
|
|
|
|
|
|
|
|
|
u32 value = 0;
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Read, MemoryAccessSize::Word>(current_address, current_address,
|
|
|
|
|
value);
|
|
|
|
|
DMAWrite(channel, value, current_address, words_remaining);
|
|
|
|
|
|
|
|
|
|
current_address = (current_address + increment) & ADDRESS_MASK;
|
|
|
|
|
} while (words_remaining > 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (u32 i = 0; i < word_count; i++)
|
|
|
|
|
u32 words_remaining = word_count;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
u32 memory_value = DMARead(channel);
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Write, MemoryAccessSize::Word>(memory_address, memory_address,
|
|
|
|
|
memory_value);
|
|
|
|
|
words_remaining--;
|
|
|
|
|
|
|
|
|
|
u32 value = DMARead(channel, current_address, words_remaining);
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Write, MemoryAccessSize::Word>(current_address, current_address,
|
|
|
|
|
value);
|
|
|
|
|
|
|
|
|
|
current_address = (current_address + increment) & ADDRESS_MASK;
|
|
|
|
|
} while (words_remaining > 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SyncMode::LinkedList:
|
|
|
|
|
{
|
|
|
|
|
if (!copy_to_device)
|
|
|
|
|
{
|
|
|
|
|
Panic("Linked list not implemented for DMA reads");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
u32 header;
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Read, MemoryAccessSize::Word>(current_address, current_address,
|
|
|
|
|
header);
|
|
|
|
|
|
|
|
|
|
const u32 word_count = header >> 24;
|
|
|
|
|
const u32 next_address = header & UINT32_C(0xFFFFFF);
|
|
|
|
|
Log_DebugPrintf(" .. linked list entry at 0x%08X size=%u(%u words) next=0x%08X", current_address,
|
|
|
|
|
word_count * UINT32_C(4), word_count, next_address);
|
|
|
|
|
current_address += sizeof(header);
|
|
|
|
|
|
|
|
|
|
if (word_count > 0)
|
|
|
|
|
{
|
|
|
|
|
u32 words_remaining = word_count;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
words_remaining--;
|
|
|
|
|
|
|
|
|
|
u32 memory_value = 0;
|
|
|
|
|
m_bus->DispatchAccess<MemoryAccessType::Read, MemoryAccessSize::Word>(current_address, current_address,
|
|
|
|
|
memory_value);
|
|
|
|
|
DMAWrite(channel, memory_value, current_address, words_remaining);
|
|
|
|
|
current_address = (current_address + UINT32_C(4)) & ADDRESS_MASK;
|
|
|
|
|
} while (words_remaining > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (next_address & UINT32_C(0x800000))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
current_address = next_address & ADDRESS_MASK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SyncMode::Request:
|
|
|
|
|
case SyncMode::LinkedList:
|
|
|
|
|
default:
|
|
|
|
|
Panic("Unimplemented sync mode");
|
|
|
|
|
break;
|
|
|
|
@ -183,29 +237,44 @@ void DMA::RunDMA(Channel channel)
|
|
|
|
|
cs.channel_control.enable_busy = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 DMA::DMARead(Channel channel)
|
|
|
|
|
u32 DMA::DMARead(Channel channel, PhysicalMemoryAddress dst_address, u32 remaining_words)
|
|
|
|
|
{
|
|
|
|
|
switch (channel)
|
|
|
|
|
{
|
|
|
|
|
case Channel::OTC:
|
|
|
|
|
{
|
|
|
|
|
// we just return zeros here.. guessing it's pulled low?
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// clear ordering table
|
|
|
|
|
return (remaining_words == 0) ? UINT32_C(0xFFFFFF) : ((dst_address - UINT32_C(4)) & ADDRESS_MASK);
|
|
|
|
|
|
|
|
|
|
case Channel::GPU:
|
|
|
|
|
return m_gpu->DMARead();
|
|
|
|
|
|
|
|
|
|
case Channel::MDECin:
|
|
|
|
|
case Channel::MDECout:
|
|
|
|
|
case Channel::GPU:
|
|
|
|
|
case Channel::CDROM:
|
|
|
|
|
case Channel::SPU:
|
|
|
|
|
case Channel::PIO:
|
|
|
|
|
default:
|
|
|
|
|
Panic("Unhandled DMA channel write");
|
|
|
|
|
Panic("Unhandled DMA channel read");
|
|
|
|
|
return UINT32_C(0xFFFFFFFF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DMA::DMAWrite(Channel channel, u32 value)
|
|
|
|
|
void DMA::DMAWrite(Channel channel, u32 value, PhysicalMemoryAddress src_address, u32 remaining_words)
|
|
|
|
|
{
|
|
|
|
|
Panic("Unhandled DMA channel write");
|
|
|
|
|
switch (channel)
|
|
|
|
|
{
|
|
|
|
|
case Channel::GPU:
|
|
|
|
|
m_gpu->DMAWrite(value);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case Channel::MDECin:
|
|
|
|
|
case Channel::MDECout:
|
|
|
|
|
case Channel::CDROM:
|
|
|
|
|
case Channel::SPU:
|
|
|
|
|
case Channel::PIO:
|
|
|
|
|
case Channel::OTC:
|
|
|
|
|
default:
|
|
|
|
|
Panic("Unhandled DMA channel write");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|