2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2021-05-13 16:44:59 +00:00
|
|
|
#include <atomic>
|
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2022-11-27 12:50:50 +00:00
|
|
|
#include "Common/Flag.h"
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-10 21:19:39 +00:00
|
|
|
class PointerWrap;
|
2014-02-02 13:16:43 +00:00
|
|
|
namespace MMIO
|
|
|
|
{
|
|
|
|
class Mapping;
|
|
|
|
}
|
2022-11-27 12:50:50 +00:00
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
namespace CoreTiming
|
|
|
|
{
|
|
|
|
struct EventType;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-10-10 21:19:39 +00:00
|
|
|
namespace CommandProcessor
|
|
|
|
{
|
2017-01-27 08:44:31 +00:00
|
|
|
struct SCPFifoStruct
|
|
|
|
{
|
|
|
|
// fifo registers
|
2022-11-27 12:50:50 +00:00
|
|
|
std::atomic<u32> CPBase = 0;
|
|
|
|
std::atomic<u32> CPEnd = 0;
|
2021-09-04 04:43:19 +00:00
|
|
|
u32 CPHiWatermark = 0;
|
|
|
|
u32 CPLoWatermark = 0;
|
2022-11-27 12:50:50 +00:00
|
|
|
std::atomic<u32> CPReadWriteDistance = 0;
|
|
|
|
std::atomic<u32> CPWritePointer = 0;
|
|
|
|
std::atomic<u32> CPReadPointer = 0;
|
|
|
|
std::atomic<u32> CPBreakpoint = 0;
|
|
|
|
std::atomic<u32> SafeCPReadPointer = 0;
|
2017-01-27 08:44:31 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
std::atomic<u32> bFF_GPLinkEnable = 0;
|
|
|
|
std::atomic<u32> bFF_GPReadEnable = 0;
|
|
|
|
std::atomic<u32> bFF_BPEnable = 0;
|
|
|
|
std::atomic<u32> bFF_BPInt = 0;
|
|
|
|
std::atomic<u32> bFF_Breakpoint = 0;
|
2017-01-27 08:44:31 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
std::atomic<u32> bFF_LoWatermarkInt = 0;
|
|
|
|
std::atomic<u32> bFF_HiWatermarkInt = 0;
|
2017-01-27 08:44:31 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
std::atomic<u32> bFF_LoWatermark = 0;
|
|
|
|
std::atomic<u32> bFF_HiWatermark = 0;
|
2017-11-12 16:20:59 +00:00
|
|
|
|
2021-05-17 19:55:03 +00:00
|
|
|
void Init();
|
2017-11-12 16:20:59 +00:00
|
|
|
void DoState(PointerWrap& p);
|
2017-01-27 08:44:31 +00:00
|
|
|
};
|
|
|
|
|
2009-10-10 21:19:39 +00:00
|
|
|
// internal hardware addresses
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STATUS_REGISTER = 0x00,
|
|
|
|
CTRL_REGISTER = 0x02,
|
|
|
|
CLEAR_REGISTER = 0x04,
|
2009-12-31 16:25:12 +00:00
|
|
|
PERF_SELECT = 0x06,
|
2009-10-10 21:19:39 +00:00
|
|
|
FIFO_TOKEN_REGISTER = 0x0E,
|
|
|
|
FIFO_BOUNDING_BOX_LEFT = 0x10,
|
|
|
|
FIFO_BOUNDING_BOX_RIGHT = 0x12,
|
|
|
|
FIFO_BOUNDING_BOX_TOP = 0x14,
|
|
|
|
FIFO_BOUNDING_BOX_BOTTOM = 0x16,
|
|
|
|
FIFO_BASE_LO = 0x20,
|
|
|
|
FIFO_BASE_HI = 0x22,
|
|
|
|
FIFO_END_LO = 0x24,
|
|
|
|
FIFO_END_HI = 0x26,
|
|
|
|
FIFO_HI_WATERMARK_LO = 0x28,
|
|
|
|
FIFO_HI_WATERMARK_HI = 0x2a,
|
|
|
|
FIFO_LO_WATERMARK_LO = 0x2c,
|
|
|
|
FIFO_LO_WATERMARK_HI = 0x2e,
|
|
|
|
FIFO_RW_DISTANCE_LO = 0x30,
|
|
|
|
FIFO_RW_DISTANCE_HI = 0x32,
|
|
|
|
FIFO_WRITE_POINTER_LO = 0x34,
|
|
|
|
FIFO_WRITE_POINTER_HI = 0x36,
|
|
|
|
FIFO_READ_POINTER_LO = 0x38,
|
|
|
|
FIFO_READ_POINTER_HI = 0x3A,
|
|
|
|
FIFO_BP_LO = 0x3C,
|
|
|
|
FIFO_BP_HI = 0x3E,
|
2009-12-31 16:25:12 +00:00
|
|
|
XF_RASBUSY_L = 0x40,
|
|
|
|
XF_RASBUSY_H = 0x42,
|
|
|
|
XF_CLKS_L = 0x44,
|
|
|
|
XF_CLKS_H = 0x46,
|
|
|
|
XF_WAIT_IN_L = 0x48,
|
|
|
|
XF_WAIT_IN_H = 0x4a,
|
|
|
|
XF_WAIT_OUT_L = 0x4c,
|
|
|
|
XF_WAIT_OUT_H = 0x4e,
|
|
|
|
VCACHE_METRIC_CHECK_L = 0x50,
|
|
|
|
VCACHE_METRIC_CHECK_H = 0x52,
|
|
|
|
VCACHE_METRIC_MISS_L = 0x54,
|
|
|
|
VCACHE_METRIC_MISS_H = 0x56,
|
|
|
|
VCACHE_METRIC_STALL_L = 0x58,
|
|
|
|
VCACHE_METRIC_STALL_H = 0x5A,
|
|
|
|
CLKS_PER_VTX_IN_L = 0x60,
|
|
|
|
CLKS_PER_VTX_IN_H = 0x62,
|
|
|
|
CLKS_PER_VTX_OUT = 0x64,
|
2009-10-10 21:19:39 +00:00
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-12-14 15:50:31 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
INT_CAUSE_CP = 0x800
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-12-14 15:50:31 +00:00
|
|
|
// Fifo Status Register
|
2017-01-04 11:45:40 +00:00
|
|
|
union UCPStatusReg
|
|
|
|
{
|
2009-12-14 15:50:31 +00:00
|
|
|
struct
|
|
|
|
{
|
2010-09-27 04:29:51 +00:00
|
|
|
u16 OverflowHiWatermark : 1;
|
|
|
|
u16 UnderflowLoWatermark : 1;
|
|
|
|
u16 ReadIdle : 1;
|
|
|
|
u16 CommandIdle : 1;
|
|
|
|
u16 Breakpoint : 1;
|
|
|
|
u16 : 11;
|
2009-12-14 15:50:31 +00:00
|
|
|
};
|
|
|
|
u16 Hex;
|
|
|
|
UCPStatusReg() { Hex = 0; }
|
|
|
|
UCPStatusReg(u16 _hex) { Hex = _hex; }
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-12-14 15:50:31 +00:00
|
|
|
// Fifo Control Register
|
2017-01-04 11:45:40 +00:00
|
|
|
union UCPCtrlReg
|
|
|
|
{
|
2009-12-14 15:50:31 +00:00
|
|
|
struct
|
|
|
|
{
|
2010-09-27 04:29:51 +00:00
|
|
|
u16 GPReadEnable : 1;
|
|
|
|
u16 BPEnable : 1;
|
|
|
|
u16 FifoOverflowIntEnable : 1;
|
|
|
|
u16 FifoUnderflowIntEnable : 1;
|
|
|
|
u16 GPLinkEnable : 1;
|
|
|
|
u16 BPInt : 1;
|
|
|
|
u16 : 10;
|
2009-12-14 15:50:31 +00:00
|
|
|
};
|
|
|
|
u16 Hex;
|
|
|
|
UCPCtrlReg() { Hex = 0; }
|
|
|
|
UCPCtrlReg(u16 _hex) { Hex = _hex; }
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2009-12-16 17:05:30 +00:00
|
|
|
// Fifo Clear Register
|
2017-01-04 11:45:40 +00:00
|
|
|
union UCPClearReg
|
|
|
|
{
|
2009-12-14 15:50:31 +00:00
|
|
|
struct
|
|
|
|
{
|
2010-09-27 04:29:51 +00:00
|
|
|
u16 ClearFifoOverflow : 1;
|
|
|
|
u16 ClearFifoUnderflow : 1;
|
|
|
|
u16 ClearMetrices : 1;
|
|
|
|
u16 : 13;
|
2009-12-14 15:50:31 +00:00
|
|
|
};
|
|
|
|
u16 Hex;
|
|
|
|
UCPClearReg() { Hex = 0; }
|
|
|
|
UCPClearReg(u16 _hex) { Hex = _hex; }
|
|
|
|
};
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2024-01-31 01:56:56 +00:00
|
|
|
constexpr u32 GetPhysicalAddressMask(bool is_wii)
|
|
|
|
{
|
|
|
|
// Physical addresses in CP seem to ignore some of the upper bits (depending on platform)
|
|
|
|
// This can be observed in CP MMIO registers by setting to 0xffffffff and then reading back.
|
|
|
|
return is_wii ? 0x1fffffff : 0x03ffffff;
|
|
|
|
}
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
class CommandProcessorManager
|
|
|
|
{
|
|
|
|
public:
|
2023-12-20 13:40:38 +00:00
|
|
|
explicit CommandProcessorManager(Core::System& system);
|
|
|
|
|
|
|
|
void Init();
|
2022-11-27 12:50:50 +00:00
|
|
|
void DoState(PointerWrap& p);
|
2014-02-02 13:16:43 +00:00
|
|
|
|
2023-12-20 13:40:38 +00:00
|
|
|
void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2023-12-20 13:40:38 +00:00
|
|
|
void SetCPStatusFromGPU();
|
|
|
|
void SetCPStatusFromCPU();
|
|
|
|
void GatherPipeBursted();
|
|
|
|
void UpdateInterrupts(u64 userdata);
|
|
|
|
void UpdateInterruptsFromVideoBackend(u64 userdata);
|
2015-05-27 07:08:48 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
bool IsInterruptWaiting() const;
|
2013-02-16 01:51:09 +00:00
|
|
|
|
2022-11-27 12:50:50 +00:00
|
|
|
void SetCpClearRegister();
|
2023-12-20 13:40:38 +00:00
|
|
|
void SetCpControlRegister();
|
|
|
|
void SetCpStatusRegister();
|
2017-01-27 08:44:31 +00:00
|
|
|
|
2023-12-20 13:40:38 +00:00
|
|
|
void HandleUnknownOpcode(u8 cmd_byte, const u8* buffer, bool preprocess);
|
2022-11-27 12:50:50 +00:00
|
|
|
|
|
|
|
// This one is shared between gfx thread and emulator thread.
|
|
|
|
// It is only used by the Fifo and by the CommandProcessor.
|
|
|
|
SCPFifoStruct& GetFifo() { return m_fifo; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SCPFifoStruct m_fifo;
|
|
|
|
|
|
|
|
CoreTiming::EventType* m_event_type_update_interrupts = nullptr;
|
|
|
|
|
|
|
|
// STATE_TO_SAVE
|
|
|
|
UCPStatusReg m_cp_status_reg;
|
|
|
|
UCPCtrlReg m_cp_ctrl_reg;
|
|
|
|
UCPClearReg m_cp_clear_reg;
|
|
|
|
|
|
|
|
u16 m_bbox_left = 0;
|
|
|
|
u16 m_bbox_top = 0;
|
|
|
|
u16 m_bbox_right = 0;
|
|
|
|
u16 m_bbox_bottom = 0;
|
|
|
|
u16 m_token_reg = 0;
|
|
|
|
|
|
|
|
Common::Flag m_interrupt_set;
|
|
|
|
Common::Flag m_interrupt_waiting;
|
|
|
|
|
|
|
|
bool m_is_fifo_error_seen = false;
|
2023-12-20 13:40:38 +00:00
|
|
|
|
|
|
|
Core::System& m_system;
|
2022-11-27 12:50:50 +00:00
|
|
|
};
|
2019-05-31 06:46:17 +00:00
|
|
|
|
2009-10-10 21:19:39 +00:00
|
|
|
} // namespace CommandProcessor
|