rpcsx/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp

3306 lines
81 KiB
C++
Raw Normal View History

2014-03-07 22:31:08 +01:00
#include "stdafx.h"
#include "Emu/Memory/Memory.h"
2014-09-30 00:28:02 +02:00
#include "Emu/System.h"
#include "Emu/SysCalls/Modules.h"
#include "Emu/SysCalls/CB_FUNC.h"
#include "Emu/IdManager.h"
#include "Emu/Event.h"
2015-03-04 22:51:14 +01:00
#include "Emu/CPU/CPUThreadManager.h"
2014-09-19 02:19:22 +02:00
#include "Emu/Cell/SPUThread.h"
2015-03-02 22:09:20 +01:00
#include "Emu/SysCalls/lv2/sleep_queue.h"
2014-12-22 01:56:04 +01:00
#include "Emu/SysCalls/lv2/sys_lwmutex.h"
#include "Emu/SysCalls/lv2/sys_lwcond.h"
#include "Emu/SysCalls/lv2/sys_spu.h"
2014-09-19 13:27:51 +02:00
#include "Emu/SysCalls/lv2/sys_ppu_thread.h"
2014-09-19 02:19:22 +02:00
#include "Emu/SysCalls/lv2/sys_memory.h"
#include "Emu/SysCalls/lv2/sys_process.h"
#include "Emu/SysCalls/lv2/sys_semaphore.h"
#include "Emu/SysCalls/lv2/sys_event.h"
#include "sysPrxForUser.h"
#include "cellSpurs.h"
2014-03-07 22:31:08 +01:00
extern Module cellSpurs;
2014-03-07 22:31:08 +01:00
bool spursKernelEntry(SPUThread & spu);
2015-02-18 23:54:31 +01:00
s32 cellSpursLookUpTasksetAddress(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u32 id);
s32 _cellSpursSendSignal(vm::ptr<CellSpursTaskset> taskset, u32 taskID);
2015-02-18 23:54:31 +01:00
s32 spursCreateLv2EventQueue(vm::ptr<CellSpurs> spurs, u32& queue_id, vm::ptr<u8> port, s32 size, u64 name_u64)
2014-09-23 01:07:40 +02:00
{
2015-05-28 21:13:35 +02:00
auto queue = Emu.GetEventManager().MakeEventQueue(SYS_SYNC_FIFO, SYS_PPU_QUEUE, name_u64, 0, size);
if (!queue) // rough
2014-09-23 01:07:40 +02:00
{
return CELL_EAGAIN;
2014-09-23 01:07:40 +02:00
}
2015-05-28 21:13:35 +02:00
queue_id = Emu.GetIdManager().add(std::move(queue));
2015-02-18 23:54:31 +01:00
if (s32 res = spursAttachLv2EventQueue(spurs, queue_id, port, 1, true))
2014-12-06 13:48:08 +01:00
{
assert(!"spursAttachLv2EventQueue() failed");
}
2014-09-19 02:19:22 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 spursInit(
2014-09-19 02:19:22 +02:00
vm::ptr<CellSpurs> spurs,
const u32 revision,
const u32 sdkVersion,
const s32 nSpus,
const s32 spuPriority,
const s32 ppuPriority,
2014-09-16 00:58:56 +02:00
u32 flags, // SpursAttrFlags
2014-09-15 20:17:30 +02:00
const char prefix[],
2014-09-19 02:19:22 +02:00
const u32 prefixSize,
const u32 container,
2014-09-16 00:58:56 +02:00
const u8 swlPriority[],
2014-09-19 02:19:22 +02:00
const u32 swlMaxSpu,
const u32 swlIsPreem)
{
2014-09-19 02:19:22 +02:00
// SPURS initialization (asserts should actually rollback and return the error instead)
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
2014-09-19 02:19:22 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (prefixSize > CELL_SPURS_NAME_MAX_LENGTH)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (process_is_spu_lock_line_reservation_address(spurs.addr(), SYS_MEMORY_ACCESS_RIGHT_SPU_THR) != CELL_OK)
{
return CELL_SPURS_CORE_ERROR_PERM;
}
2014-09-24 20:44:26 +02:00
const bool isSecond = (flags & SAF_SECOND_VERSION) != 0;
memset(spurs.get_ptr(), 0, isSecond ? CELL_SPURS_SIZE2 : CELL_SPURS_SIZE);
spurs->revision = revision;
spurs->sdkVersion = sdkVersion;
spurs->ppu0 = 0xffffffffull;
spurs->ppu1 = 0xffffffffull;
spurs->flags = flags;
memcpy(spurs->prefix, prefix, prefixSize);
spurs->prefixSize = (u8)prefixSize;
2014-09-19 02:19:22 +02:00
std::string name(prefix, prefixSize); // initialize name string
if (!isSecond)
{
spurs->wklMskA.write_relaxed(be_t<u32>::make(0xffff));
2014-09-19 02:19:22 +02:00
}
spurs->xCC = 0;
spurs->xCD = 0;
spurs->sysSrvMsgUpdateTrace = 0;
2014-09-19 02:19:22 +02:00
for (u32 i = 0; i < 8; i++)
{
spurs->sysSrvWorkload[i] = -1;
2014-09-19 02:19:22 +02:00
}
2014-10-02 12:29:20 +02:00
// default or system workload:
spurs->wklInfoSysSrv.addr.set(SPURS_IMG_ADDR_SYS_SRV_WORKLOAD);
spurs->wklInfoSysSrv.arg = 0;
spurs->wklInfoSysSrv.uniqueId.write_relaxed(0xff);
2014-09-19 02:19:22 +02:00
u32 sem;
for (u32 i = 0; i < 0x10; i++)
{
sem = Emu.GetIdManager().make<lv2_sema_t>(SYS_SYNC_PRIORITY, 1, *(u64*)"_spuWkl", 0);
2014-09-23 01:07:40 +02:00
assert(sem && ~sem); // should rollback if semaphore creation failed and return the error
spurs->wklF1[i].sem = sem;
2014-09-19 02:19:22 +02:00
}
if (isSecond)
{
for (u32 i = 0; i < 0x10; i++)
{
sem = Emu.GetIdManager().make<lv2_sema_t>(SYS_SYNC_PRIORITY, 1, *(u64*)"_spuWkl", 0);
2014-09-19 02:19:22 +02:00
assert(sem && ~sem);
spurs->wklF2[i].sem = sem;
2014-09-19 02:19:22 +02:00
}
}
sem = Emu.GetIdManager().make<lv2_sema_t>(SYS_SYNC_PRIORITY, 1, *(u64*)"_spuPrv", 0);
2014-09-19 02:19:22 +02:00
assert(sem && ~sem);
spurs->semPrv = sem;
spurs->unk11 = -1;
spurs->unk12 = -1;
spurs->unk13 = 0;
spurs->nSpus = nSpus;
spurs->spuPriority = spuPriority;
2015-02-18 23:54:31 +01:00
spurs->spuImg.addr = Memory.MainMem.AllocAlign(0x40000, 4096);
spurs->spuImg.entry_point = isSecond ? CELL_SPURS_KERNEL2_ENTRY_ADDR : CELL_SPURS_KERNEL1_ENTRY_ADDR;
2014-09-19 02:19:22 +02:00
s32 tgt = SYS_SPU_THREAD_GROUP_TYPE_NORMAL;
if (flags & SAF_SPU_TGT_EXCLUSIVE_NON_CONTEXT)
{
tgt = SYS_SPU_THREAD_GROUP_TYPE_EXCLUSIVE_NON_CONTEXT;
}
else if (flags & SAF_UNKNOWN_FLAG_0)
{
tgt = 0xC02;
}
if (flags & SAF_SPU_MEMORY_CONTAINER_SET) tgt |= SYS_SPU_THREAD_GROUP_TYPE_MEMORY_FROM_CONTAINER;
if (flags & SAF_SYSTEM_WORKLOAD_ENABLED) tgt |= SYS_SPU_THREAD_GROUP_TYPE_COOPERATE_WITH_SYSTEM;
if (flags & SAF_UNKNOWN_FLAG_7) tgt |= 0x102;
if (flags & SAF_UNKNOWN_FLAG_8) tgt |= 0xC02;
if (flags & SAF_UNKNOWN_FLAG_9) tgt |= 0x800;
spurs->spuTG = spu_thread_group_create(name + "CellSpursKernelGroup", nSpus, spuPriority, tgt, container);
assert(spurs->spuTG.data());
2014-09-19 02:19:22 +02:00
name += "CellSpursKernel0";
2014-09-24 20:44:26 +02:00
for (s32 num = 0; num < nSpus; num++, name[name.size() - 1]++)
2014-09-19 02:19:22 +02:00
{
spurs->spus[num] = spu_thread_initialize(spurs->spuTG, num, vm::ptr<sys_spu_image>::make(spurs.addr() + offsetof(CellSpurs, spuImg)),
2015-04-13 19:39:38 +02:00
name, SYS_SPU_THREAD_OPTION_DEC_SYNC_TB_ENABLE, (u64)num << 32, spurs.addr(), 0, 0, [spurs](SPUThread& SPU)
{
SPU.RegisterHleFunction(spurs->spuImg.entry_point, spursKernelEntry);
SPU.FastCall(spurs->spuImg.entry_point);
2015-04-13 19:39:38 +02:00
});
2014-09-19 02:19:22 +02:00
}
if (flags & SAF_SPU_PRINTF_ENABLED)
{
// spu_printf: attach group
if (!spu_printf_agcb || spu_printf_agcb(spurs->spuTG) != CELL_OK)
2014-09-19 02:19:22 +02:00
{
// remove flag if failed
spurs->flags &= ~SAF_SPU_PRINTF_ENABLED;
2014-09-19 02:19:22 +02:00
}
}
lwmutex_create(spurs->mutex, false, SYS_SYNC_PRIORITY, *(u64*)"_spuPrv");
lwcond_create(spurs->cond, spurs->mutex, *(u64*)"_spuPrv");
2014-09-19 02:19:22 +02:00
spurs->flags1 = (flags & SAF_EXIT_IF_NO_WORK ? SF1_EXIT_IF_NO_WORK : 0) | (isSecond ? SF1_32_WORKLOADS : 0);
spurs->wklFlagReceiver.write_relaxed(0xff);
spurs->wklFlag.flag.write_relaxed(be_t<u32>::make(-1));
spurs->xD64 = {};
spurs->xD65 = {};
spurs->xD66 = {};
spurs->ppuPriority = ppuPriority;
2014-09-19 02:19:22 +02:00
u32 queue;
2015-02-18 23:54:31 +01:00
if (s32 res = spursCreateLv2EventQueue(spurs, queue, vm::ptr<u8>::make(spurs.addr() + 0xc9), 0x2a, *(u64*)"_spuPrv"))
2014-12-06 13:48:08 +01:00
{
assert(!"spursCreateLv2EventQueue() failed");
}
spurs->queue = queue;
2014-09-19 02:19:22 +02:00
u32 port = Emu.GetIdManager().make<lv2_event_port_t>(SYS_EVENT_PORT_LOCAL, 0);
2014-09-19 02:19:22 +02:00
assert(port && ~port);
spurs->port = port;
2014-09-19 02:19:22 +02:00
2014-12-06 13:48:08 +01:00
if (s32 res = sys_event_port_connect_local(port, queue))
{
assert(!"sys_event_port_connect_local() failed");
}
2014-09-19 02:19:22 +02:00
2014-09-19 13:27:51 +02:00
name = std::string(prefix, prefixSize);
spurs->ppu0 = ppu_thread_create(0, 0, ppuPriority, 0x4000, true, false, name + "SpursHdlr0", [spurs](PPUThread& CPU)
2014-09-24 20:44:26 +02:00
{
if (spurs->flags & SAF_UNKNOWN_FLAG_30)
2014-09-30 00:28:02 +02:00
{
return;
}
2014-09-19 13:27:51 +02:00
2014-09-30 00:28:02 +02:00
while (true)
{
if (Emu.IsStopped())
{
cellSpurs.Warning("SPURS Handler Thread 0 aborted");
2014-09-30 00:28:02 +02:00
return;
}
if (spurs->flags1 & SF1_EXIT_IF_NO_WORK)
2014-09-30 00:28:02 +02:00
{
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_lock(CPU, spurs->get_lwmutex(), 0))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_lock() failed");
}
if (spurs->xD66.read_relaxed())
2014-09-30 00:28:02 +02:00
{
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_unlock(CPU, spurs->get_lwmutex()))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_unlock() failed");
}
2014-09-30 00:28:02 +02:00
return;
}
else while (true)
{
2014-12-09 17:13:03 +01:00
if (Emu.IsStopped()) break;
spurs->xD64.exchange(0);
if (spurs->exception.data() == 0)
2014-09-30 00:28:02 +02:00
{
bool do_break = false;
for (u32 i = 0; i < 16; i++)
{
if (spurs->wklState1[i].read_relaxed() == 2 &&
*((u64 *)spurs->wklInfo1[i].priority) != 0 &&
spurs->wklMaxContention[i].read_relaxed() & 0xf
2014-09-30 00:28:02 +02:00
)
{
if (spurs->wklReadyCount1[i].read_relaxed() ||
spurs->wklSignal1.read_relaxed() & (0x8000u >> i) ||
(spurs->wklFlag.flag.read_relaxed() == 0 &&
spurs->wklFlagReceiver.read_relaxed() == (u8)i
))
2014-09-30 00:28:02 +02:00
{
do_break = true;
break;
}
}
}
if (spurs->flags1 & SF1_32_WORKLOADS) for (u32 i = 0; i < 16; i++)
2014-09-30 00:28:02 +02:00
{
if (spurs->wklState2[i].read_relaxed() == 2 &&
*((u64 *)spurs->wklInfo2[i].priority) != 0 &&
spurs->wklMaxContention[i].read_relaxed() & 0xf0
2014-09-30 00:28:02 +02:00
)
{
if (spurs->wklIdleSpuCountOrReadyCount2[i].read_relaxed() ||
spurs->wklSignal2.read_relaxed() & (0x8000u >> i) ||
(spurs->wklFlag.flag.read_relaxed() == 0 &&
spurs->wklFlagReceiver.read_relaxed() == (u8)i + 0x10
))
2014-09-30 00:28:02 +02:00
{
do_break = true;
break;
}
}
}
if (do_break) break; // from while
}
spurs->xD65.exchange(1);
if (spurs->xD64.read_relaxed() == 0)
2014-09-30 00:28:02 +02:00
{
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwcond_wait(CPU, spurs->get_lwcond(), 0))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwcond_wait() failed");
}
2014-09-30 00:28:02 +02:00
}
spurs->xD65.exchange(0);
if (spurs->xD66.read_relaxed())
2014-09-30 00:28:02 +02:00
{
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_unlock(CPU, spurs->get_lwmutex()))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_unlock() failed");
}
2014-09-30 00:28:02 +02:00
return;
}
}
2014-12-09 17:13:03 +01:00
if (Emu.IsStopped()) continue;
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_unlock(CPU, spurs->get_lwmutex()))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_unlock() failed");
}
2014-09-30 00:28:02 +02:00
}
if (Emu.IsStopped()) continue;
if (s32 res = sys_spu_thread_group_start(spurs->spuTG))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_spu_thread_group_start() failed");
}
if (s32 res = sys_spu_thread_group_join(spurs->spuTG, vm::null, vm::null))
2014-09-30 00:28:02 +02:00
{
if (res == CELL_ESTAT)
{
return;
}
2014-12-06 13:48:08 +01:00
assert(!"sys_spu_thread_group_join() failed");
2014-09-30 00:28:02 +02:00
}
if (Emu.IsStopped()) continue;
if ((spurs->flags1 & SF1_EXIT_IF_NO_WORK) == 0)
2014-09-30 00:28:02 +02:00
{
assert(spurs->xD66.read_relaxed() == 1 || Emu.IsStopped());
2014-09-30 00:28:02 +02:00
return;
}
}
2015-03-04 22:51:14 +01:00
});
2014-09-24 20:44:26 +02:00
spurs->ppu1 = ppu_thread_create(0, 0, ppuPriority, 0x8000, true, false, name + "SpursHdlr1", [spurs](PPUThread& CPU)
2014-09-24 20:44:26 +02:00
{
2015-02-18 23:54:31 +01:00
// TODO
2014-09-24 20:44:26 +02:00
2015-03-04 22:51:14 +01:00
});
2014-09-19 13:27:51 +02:00
2014-09-19 21:11:43 +02:00
// enable exception event handler
if (spurs->enableEH.compare_and_swap_test(be_t<u32>::make(0), be_t<u32>::make(1)))
2014-09-19 21:11:43 +02:00
{
if (s32 res = sys_spu_thread_group_connect_event(spurs->spuTG, spurs->queue, SYS_SPU_THREAD_GROUP_EVENT_EXCEPTION))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_spu_thread_group_connect_event() failed");
}
2014-09-19 21:11:43 +02:00
}
spurs->traceBuffer.set(0);
2014-09-19 21:11:43 +02:00
// can also use cellLibprof if available (omitted)
// some unknown subroutine
spurs->sub3.unk1 = spurs.addr() + 0xc9;
spurs->sub3.unk2 = 3; // unknown const
spurs->sub3.port = (u64)spurs->port;
2014-09-19 21:11:43 +02:00
if (flags & SAF_SYSTEM_WORKLOAD_ENABLED) // initialize system workload (disabled)
2014-09-19 21:11:43 +02:00
{
2014-09-24 20:44:26 +02:00
s32 res = CELL_OK;
2015-02-18 23:54:31 +01:00
// TODO
2014-09-19 21:11:43 +02:00
assert(res == CELL_OK);
}
else if (flags & SAF_EXIT_IF_NO_WORK) // wakeup
{
2014-12-23 00:31:11 +01:00
return spursWakeUp(GetCurrentPPUThread(), spurs);
2014-09-19 21:11:43 +02:00
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursInitialize(vm::ptr<CellSpurs> spurs, s32 nSpus, s32 spuPriority, s32 ppuPriority, bool exitIfNoWork)
{
cellSpurs.Warning("cellSpursInitialize(spurs_addr=0x%x, nSpus=%d, spuPriority=%d, ppuPriority=%d, exitIfNoWork=%d)",
spurs.addr(), nSpus, spuPriority, ppuPriority, exitIfNoWork ? 1 : 0);
return spursInit(
2014-09-19 02:19:22 +02:00
spurs,
0,
0,
nSpus,
spuPriority,
ppuPriority,
2014-09-16 00:58:56 +02:00
exitIfNoWork ? SAF_EXIT_IF_NO_WORK : SAF_NONE,
2014-09-15 20:17:30 +02:00
nullptr,
0,
0,
2014-09-16 00:58:56 +02:00
nullptr,
0,
0);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursInitializeWithAttribute(vm::ptr<CellSpurs> spurs, vm::ptr<const CellSpursAttribute> attr)
{
cellSpurs.Warning("cellSpursInitializeWithAttribute(spurs_addr=0x%x, attr_addr=0x%x)", spurs.addr(), attr.addr());
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (attr->revision > 2)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
return spursInit(
2014-09-19 02:19:22 +02:00
spurs,
attr->revision,
attr->sdkVersion,
attr->nSpus,
attr->spuPriority,
attr->ppuPriority,
attr->flags | (attr->exitIfNoWork ? SAF_EXIT_IF_NO_WORK : 0),
attr->prefix,
attr->prefixSize,
attr->container,
attr->swlPriority,
attr->swlMaxSpu,
attr->swlIsPreem);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursInitializeWithAttribute2(vm::ptr<CellSpurs> spurs, vm::ptr<const CellSpursAttribute> attr)
{
cellSpurs.Warning("cellSpursInitializeWithAttribute2(spurs_addr=0x%x, attr_addr=0x%x)", spurs.addr(), attr.addr());
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (attr->revision > 2)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
return spursInit(
spurs,
attr->revision,
attr->sdkVersion,
attr->nSpus,
attr->spuPriority,
attr->ppuPriority,
attr->flags | (attr->exitIfNoWork ? SAF_EXIT_IF_NO_WORK : 0) | SAF_SECOND_VERSION,
attr->prefix,
attr->prefixSize,
attr->container,
attr->swlPriority,
attr->swlMaxSpu,
attr->swlIsPreem);
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursAttributeInitialize(vm::ptr<CellSpursAttribute> attr, u32 revision, u32 sdkVersion, u32 nSpus, s32 spuPriority, s32 ppuPriority, bool exitIfNoWork)
{
cellSpurs.Warning("_cellSpursAttributeInitialize(attr_addr=0x%x, revision=%d, sdkVersion=0x%x, nSpus=%d, spuPriority=%d, ppuPriority=%d, exitIfNoWork=%d)",
2014-09-15 20:17:30 +02:00
attr.addr(), revision, sdkVersion, nSpus, spuPriority, ppuPriority, exitIfNoWork ? 1 : 0);
2014-09-15 20:17:30 +02:00
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
2014-03-07 22:31:08 +01:00
memset(attr.get_ptr(), 0, sizeof(CellSpursAttribute));
attr->revision = revision;
attr->sdkVersion = sdkVersion;
attr->nSpus = nSpus;
attr->spuPriority = spuPriority;
attr->ppuPriority = ppuPriority;
attr->exitIfNoWork = exitIfNoWork;
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttributeSetMemoryContainerForSpuThread(vm::ptr<CellSpursAttribute> attr, u32 container)
2014-03-07 22:31:08 +01:00
{
2015-04-14 04:00:31 +02:00
cellSpurs.Warning("cellSpursAttributeSetMemoryContainerForSpuThread(attr_addr=0x%x, container=0x%x)", attr.addr(), container);
2014-09-15 20:17:30 +02:00
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
2014-09-16 00:58:56 +02:00
if (attr->flags & SAF_SPU_TGT_EXCLUSIVE_NON_CONTEXT)
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_STAT;
}
attr->container = container;
attr->flags |= SAF_SPU_MEMORY_CONTAINER_SET;
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttributeSetNamePrefix(vm::ptr<CellSpursAttribute> attr, vm::ptr<const char> prefix, u32 size)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursAttributeSetNamePrefix(attr_addr=0x%x, prefix_addr=0x%x, size=%d)", attr.addr(), prefix.addr(), size);
2014-09-15 20:17:30 +02:00
if (!attr || !prefix)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (size > CELL_SPURS_NAME_MAX_LENGTH)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
memcpy(attr->prefix, prefix.get_ptr(), size);
attr->prefixSize = size;
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttributeEnableSpuPrintfIfAvailable(vm::ptr<CellSpursAttribute> attr)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursAttributeEnableSpuPrintfIfAvailable(attr_addr=0x%x)", attr.addr());
2014-09-16 00:58:56 +02:00
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-09-16 00:58:56 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
attr->flags |= SAF_SPU_PRINTF_ENABLED;
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttributeSetSpuThreadGroupType(vm::ptr<CellSpursAttribute> attr, s32 type)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursAttributeSetSpuThreadGroupType(attr_addr=0x%x, type=%d)", attr.addr(), type);
2014-09-15 20:17:30 +02:00
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
2014-03-07 22:31:08 +01:00
2014-09-16 00:58:56 +02:00
if (type == SYS_SPU_THREAD_GROUP_TYPE_EXCLUSIVE_NON_CONTEXT)
2014-09-15 20:17:30 +02:00
{
if (attr->flags & SAF_SPU_MEMORY_CONTAINER_SET)
2014-09-15 20:17:30 +02:00
{
return CELL_SPURS_CORE_ERROR_STAT;
}
attr->flags |= SAF_SPU_TGT_EXCLUSIVE_NON_CONTEXT; // set
2014-09-15 20:17:30 +02:00
}
2014-09-16 00:58:56 +02:00
else if (type == SYS_SPU_THREAD_GROUP_TYPE_NORMAL)
2014-09-15 20:17:30 +02:00
{
attr->flags &= ~SAF_SPU_TGT_EXCLUSIVE_NON_CONTEXT; // clear
2014-09-15 20:17:30 +02:00
}
2014-09-16 00:58:56 +02:00
else
2014-09-15 20:17:30 +02:00
{
2014-09-16 00:58:56 +02:00
return CELL_SPURS_CORE_ERROR_INVAL;
2014-09-15 20:17:30 +02:00
}
2014-09-16 00:58:56 +02:00
return CELL_OK;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttributeEnableSystemWorkload(vm::ptr<CellSpursAttribute> attr, vm::ptr<const u8[8]> priority, u32 maxSpu, vm::ptr<const bool[8]> isPreemptible)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursAttributeEnableSystemWorkload(attr_addr=0x%x, priority_addr=0x%x, maxSpu=%d, isPreemptible_addr=0x%x)",
2014-09-02 03:05:13 +02:00
attr.addr(), priority.addr(), maxSpu, isPreemptible.addr());
2014-09-16 00:58:56 +02:00
if (!attr)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
2014-06-02 10:09:36 +02:00
{
2014-09-16 00:58:56 +02:00
return CELL_SPURS_CORE_ERROR_ALIGN;
}
const u32 nSpus = attr->nSpus;
2014-09-16 00:58:56 +02:00
if (!nSpus)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
2014-09-16 00:58:56 +02:00
for (u32 i = 0; i < nSpus; i++)
{
if ((*priority)[i] == 1)
2014-06-02 10:09:36 +02:00
{
2014-09-16 00:58:56 +02:00
if (!maxSpu)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (nSpus == 1 || attr->exitIfNoWork)
2014-09-16 00:58:56 +02:00
{
return CELL_SPURS_CORE_ERROR_PERM;
}
if (attr->flags & SAF_SYSTEM_WORKLOAD_ENABLED)
2014-09-16 00:58:56 +02:00
{
return CELL_SPURS_CORE_ERROR_BUSY;
}
attr->flags |= SAF_SYSTEM_WORKLOAD_ENABLED; // set flag
*(u64*)attr->swlPriority = *(u64*)*priority; // copy system workload priorities
2014-09-16 00:58:56 +02:00
u32 isPreem = 0; // generate mask from isPreemptible values
for (u32 j = 0; j < nSpus; j++)
{
if ((*isPreemptible)[j])
{
isPreem |= (1 << j);
}
}
attr->swlMaxSpu = maxSpu; // write max spu for system workload
attr->swlIsPreem = isPreem; // write isPreemptible mask
2014-09-16 00:58:56 +02:00
return CELL_OK;
2014-06-02 10:09:36 +02:00
}
}
2014-09-16 00:58:56 +02:00
return CELL_SPURS_CORE_ERROR_INVAL;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursFinalize(vm::ptr<CellSpurs> spurs)
2014-09-15 20:17:30 +02:00
{
cellSpurs.Todo("cellSpursFinalize(spurs_addr=0x%x)", spurs.addr());
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (spurs->xD66.read_relaxed())
{
return CELL_SPURS_CORE_ERROR_STAT;
}
2015-02-18 23:54:31 +01:00
// TODO
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 spursAttachLv2EventQueue(vm::ptr<CellSpurs> spurs, u32 queue, vm::ptr<u8> port, s32 isDynamic, bool wasCreated)
{
if (!spurs || !port)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (spurs->exception.data())
{
return CELL_SPURS_CORE_ERROR_STAT;
}
s32 sdk_ver;
2014-12-06 13:48:08 +01:00
if (s32 res = process_get_sdk_version(process_getpid(), sdk_ver))
{
assert(!"process_get_sdk_version() failed");
}
if (sdk_ver == -1) sdk_ver = 0x460000;
u8 _port = 0x3f;
u64 port_mask = 0;
if (isDynamic == 0)
{
_port = *port;
if (_port > 0x3f)
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (sdk_ver > 0x17ffff && _port > 0xf)
{
return CELL_SPURS_CORE_ERROR_PERM;
}
}
for (u32 i = isDynamic ? 0x10 : _port; i <= _port; i++)
{
port_mask |= 1ull << (i);
}
assert(port_mask); // zero mask will return CELL_EINVAL
if (s32 res = sys_spu_thread_group_connect_event_all_threads(spurs->spuTG, queue, port_mask, port))
{
if (res == CELL_EISCONN)
{
return CELL_SPURS_CORE_ERROR_BUSY;
}
return res;
}
if (!wasCreated)
{
spurs->spups |= be_t<u64>::make(1ull << *port); // atomic bitwise or
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAttachLv2EventQueue(vm::ptr<CellSpurs> spurs, u32 queue, vm::ptr<u8> port, s32 isDynamic)
{
2015-04-14 04:00:31 +02:00
cellSpurs.Warning("cellSpursAttachLv2EventQueue(spurs_addr=0x%x, queue=0x%x, port_addr=0x%x, isDynamic=%d)",
spurs.addr(), queue, port.addr(), isDynamic);
return spursAttachLv2EventQueue(spurs, queue, port, isDynamic, false);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursDetachLv2EventQueue(vm::ptr<CellSpurs> spurs, u8 port)
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetSpuGuid()
{
UNIMPLEMENTED_FUNC(cellSpurs);
2014-09-15 20:17:30 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetSpuThreadGroupId(vm::ptr<CellSpurs> spurs, vm::ptr<u32> group)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursGetSpuThreadGroupId(spurs_addr=0x%x, group_addr=0x%x)", spurs.addr(), group.addr());
if (!spurs || !group)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
*group = spurs->spuTG;
return CELL_OK;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetNumSpuThread(vm::ptr<CellSpurs> spurs, vm::ptr<u32> nThreads)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursGetNumSpuThread(spurs_addr=0x%x, nThreads_addr=0x%x)", spurs.addr(), nThreads.addr());
if (!spurs || !nThreads)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
*nThreads = (u32)spurs->nSpus;
return CELL_OK;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetSpuThreadId(vm::ptr<CellSpurs> spurs, vm::ptr<u32> thread, vm::ptr<u32> nThreads)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursGetSpuThreadId(spurs_addr=0x%x, thread_addr=0x%x, nThreads_addr=0x%x)", spurs.addr(), thread.addr(), nThreads.addr());
if (!spurs || !thread || !nThreads)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
const u32 count = std::min<u32>(*nThreads, spurs->nSpus);
for (u32 i = 0; i < count; i++)
{
thread[i] = spurs->spus[i];
}
*nThreads = count;
return CELL_OK;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSetMaxContention(vm::ptr<CellSpurs> spurs, u32 workloadId, u32 maxContention)
2014-03-07 22:31:08 +01:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSetPriorities(vm::ptr<CellSpurs> spurs, u32 workloadId, vm::ptr<const u8> priorities)
2014-03-07 22:31:08 +01:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSetPreemptionVictimHints(vm::ptr<CellSpurs> spurs, vm::ptr<const bool> isPreemptible)
2014-03-07 22:31:08 +01:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEnableExceptionEventHandler(vm::ptr<CellSpurs> spurs, bool flag)
2014-03-07 22:31:08 +01:00
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSetGlobalExceptionEventHandler(vm::ptr<CellSpurs> spurs, u32 eaHandler_addr, u32 arg_addr)
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursUnsetGlobalExceptionEventHandler(vm::ptr<CellSpurs> spurs)
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetInfo(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursInfo> info)
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 spursWakeUp(PPUThread& CPU, vm::ptr<CellSpurs> spurs)
{
if (!spurs)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (spurs->exception.data())
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
spurs->xD64.exchange(1);
if (spurs->xD65.read_sync())
{
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_lock(CPU, spurs->get_lwmutex(), 0))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_lock() failed");
}
2015-03-09 20:56:55 +01:00
if (s32 res = sys_lwcond_signal(CPU, spurs->get_lwcond()))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwcond_signal() failed");
}
2014-12-23 00:31:11 +01:00
if (s32 res = sys_lwmutex_unlock(CPU, spurs->get_lwmutex()))
2014-12-06 13:48:08 +01:00
{
assert(!"sys_lwmutex_unlock() failed");
}
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursWakeUp(PPUThread& CPU, vm::ptr<CellSpurs> spurs)
{
cellSpurs.Warning("%s(spurs_addr=0x%x)", __FUNCTION__, spurs.addr());
2014-12-23 00:31:11 +01:00
return spursWakeUp(CPU, spurs);
}
s32 spursAddWorkload(
vm::ptr<CellSpurs> spurs,
vm::ptr<u32> wid,
vm::ptr<const void> pm,
u32 size,
u64 data,
const u8 priorityTable[],
u32 minContention,
u32 maxContention,
2014-09-27 20:49:33 +02:00
vm::ptr<const char> nameClass,
vm::ptr<const char> nameInstance,
vm::ptr<CellSpursShutdownCompletionEventHook> hook,
vm::ptr<void> hookArg)
{
2014-09-27 20:49:33 +02:00
if (!spurs || !wid || !pm)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned() || pm % 16)
2014-09-27 20:49:33 +02:00
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (minContention == 0 || *(u64*)priorityTable & 0xf0f0f0f0f0f0f0f0ull) // check if some priority > 15
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if (spurs->exception.data())
2014-09-27 20:49:33 +02:00
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
u32 wnum;
const u32 wmax = spurs->flags1 & SF1_32_WORKLOADS ? 0x20u : 0x10u; // TODO: check if can be changed
spurs->wklMskA.atomic_op([spurs, wmax, &wnum](be_t<u32>& value)
2014-09-27 20:49:33 +02:00
{
wnum = cntlz32(~(u32)value); // found empty position
if (wnum < wmax)
{
value |= (u32)(0x80000000ull >> wnum); // set workload bit
}
});
*wid = wnum; // store workload id
if (wnum >= wmax)
{
return CELL_SPURS_POLICY_MODULE_ERROR_AGAIN;
}
2014-09-30 00:28:02 +02:00
u32 index = wnum & 0xf;
2014-09-27 20:49:33 +02:00
if (wnum <= 15)
{
assert((spurs->wklCurrentContention[wnum] & 0xf) == 0);
assert((spurs->wklPendingContention[wnum] & 0xf) == 0);
spurs->wklState1[wnum].write_relaxed(1);
spurs->wklStatus1[wnum] = 0;
spurs->wklEvent1[wnum] = 0;
spurs->wklInfo1[wnum].addr = pm;
spurs->wklInfo1[wnum].arg = data;
spurs->wklInfo1[wnum].size = size;
for (u32 i = 0; i < 8; i++)
{
spurs->wklInfo1[wnum].priority[i] = priorityTable[i];
}
spurs->wklH1[wnum].nameClass = nameClass;
spurs->wklH1[wnum].nameInstance = nameInstance;
memset(spurs->wklF1[wnum].unk0, 0, 0x20); // clear struct preserving semaphore id
memset(spurs->wklF1[wnum].unk1, 0, 0x58);
2014-09-27 20:49:33 +02:00
if (hook)
{
spurs->wklF1[wnum].hook = hook;
spurs->wklF1[wnum].hookArg = hookArg;
spurs->wklEvent1[wnum] |= 2;
2014-09-27 20:49:33 +02:00
}
if ((spurs->flags1 & SF1_32_WORKLOADS) == 0)
2014-09-27 20:49:33 +02:00
{
spurs->wklIdleSpuCountOrReadyCount2[wnum].write_relaxed(0);
spurs->wklMinContention[wnum] = minContention > 8 ? 8 : minContention;
2014-09-27 20:49:33 +02:00
}
spurs->wklReadyCount1[wnum].write_relaxed(0);
2014-09-28 21:10:13 +02:00
}
else
{
assert((spurs->wklCurrentContention[index] & 0xf0) == 0);
assert((spurs->wklPendingContention[index] & 0xf0) == 0);
spurs->wklState2[index].write_relaxed(1);
spurs->wklStatus2[index] = 0;
spurs->wklEvent2[index] = 0;
spurs->wklInfo2[index].addr = pm;
spurs->wklInfo2[index].arg = data;
spurs->wklInfo2[index].size = size;
for (u32 i = 0; i < 8; i++)
{
spurs->wklInfo2[index].priority[i] = priorityTable[i];
}
spurs->wklH2[index].nameClass = nameClass;
spurs->wklH2[index].nameInstance = nameInstance;
memset(spurs->wklF2[index].unk0, 0, 0x20); // clear struct preserving semaphore id
memset(spurs->wklF2[index].unk1, 0, 0x58);
2014-09-28 21:10:13 +02:00
if (hook)
2014-09-27 20:49:33 +02:00
{
spurs->wklF2[index].hook = hook;
spurs->wklF2[index].hookArg = hookArg;
spurs->wklEvent2[index] |= 2;
2014-09-27 20:49:33 +02:00
}
spurs->wklIdleSpuCountOrReadyCount2[wnum].write_relaxed(0);
2014-09-28 21:10:13 +02:00
}
if (wnum <= 15)
{
spurs->wklMaxContention[wnum].atomic_op([maxContention](u8& v)
2014-09-30 21:06:04 +02:00
{
v &= ~0xf;
v |= (maxContention > 8 ? 8 : maxContention);
});
spurs->wklSignal1._and_not({ be_t<u16>::make(0x8000 >> index) }); // clear bit in wklFlag1
2014-09-27 20:49:33 +02:00
}
else
{
spurs->wklMaxContention[index].atomic_op([maxContention](u8& v)
2014-09-30 21:06:04 +02:00
{
v &= ~0xf0;
v |= (maxContention > 8 ? 8 : maxContention) << 4;
});
spurs->wklSignal2._and_not({ be_t<u16>::make(0x8000 >> index) }); // clear bit in wklFlag2
2014-09-28 21:10:13 +02:00
}
spurs->wklFlagReceiver.compare_and_swap(wnum, 0xff);
2014-09-28 21:10:13 +02:00
u32 res_wkl;
CellSpurs::WorkloadInfo& wkl = wnum <= 15 ? spurs->wklInfo1[wnum] : spurs->wklInfo2[wnum & 0xf];
spurs->wklMskB.atomic_op_sync([spurs, &wkl, wnum, &res_wkl](be_t<u32>& v)
2014-09-28 21:10:13 +02:00
{
2015-01-14 00:08:00 +01:00
const u32 mask = v & ~(0x80000000u >> wnum);
2014-09-28 21:10:13 +02:00
res_wkl = 0;
for (u32 i = 0, m = 0x80000000, k = 0; i < 32; i++, m >>= 1)
{
if (mask & m)
{
CellSpurs::WorkloadInfo& current = i <= 15 ? spurs->wklInfo1[i] : spurs->wklInfo2[i & 0xf];
if (current.addr.addr() == wkl.addr.addr())
2014-09-28 21:10:13 +02:00
{
// if a workload with identical policy module found
res_wkl = current.uniqueId.read_relaxed();
2014-09-28 21:10:13 +02:00
break;
}
else
{
k |= 0x80000000 >> current.uniqueId.read_relaxed();
2014-09-28 21:10:13 +02:00
res_wkl = cntlz32(~k);
}
}
}
2014-09-27 20:49:33 +02:00
wkl.uniqueId.exchange((u8)res_wkl);
v = mask | (0x80000000u >> wnum);
2014-09-28 21:10:13 +02:00
});
assert(res_wkl <= 31);
spurs->wklState(wnum).exchange(2);
spurs->sysSrvMsgUpdateWorkload.exchange(0xff);
spurs->sysSrvMessage.exchange(0xff);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAddWorkload(
vm::ptr<CellSpurs> spurs,
vm::ptr<u32> wid,
vm::ptr<const void> pm,
u32 size,
u64 data,
vm::ptr<const u8[8]> priorityTable,
u32 minContention,
u32 maxContention)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, wid_addr=0x%x, pm_addr=0x%x, size=0x%x, data=0x%llx, priorityTable_addr=0x%x, minContention=0x%x, maxContention=0x%x)",
__FUNCTION__, spurs.addr(), wid.addr(), pm.addr(), size, data, priorityTable.addr(), minContention, maxContention);
return spursAddWorkload(
spurs,
wid,
pm,
size,
data,
*priorityTable,
minContention,
maxContention,
2015-04-21 22:26:21 +02:00
vm::null,
vm::null,
vm::null,
vm::null);
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursWorkloadAttributeInitialize(
vm::ptr<CellSpursWorkloadAttribute> attr,
u32 revision,
u32 sdkVersion,
vm::ptr<const void> pm,
u32 size,
u64 data,
vm::ptr<const u8[8]> priorityTable,
u32 minContention,
u32 maxContention)
{
cellSpurs.Warning("%s(attr_addr=0x%x, revision=%d, sdkVersion=0x%x, pm_addr=0x%x, size=0x%x, data=0x%llx, priorityTable_addr=0x%x, minContention=0x%x, maxContention=0x%x)",
__FUNCTION__, attr.addr(), revision, sdkVersion, pm.addr(), size, data, priorityTable.addr(), minContention, maxContention);
if (!attr)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (!pm)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (pm % 16)
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (minContention == 0 || *(u64*)*priorityTable & 0xf0f0f0f0f0f0f0f0ull) // check if some priority > 15
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
memset(attr.get_ptr(), 0, sizeof(CellSpursWorkloadAttribute));
attr->revision = revision;
attr->sdkVersion = sdkVersion;
attr->pm = pm;
attr->size = size;
attr->data = data;
*(u64*)attr->priority = *(u64*)*priorityTable;
attr->minContention = minContention;
attr->maxContention = maxContention;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursWorkloadAttributeSetName(vm::ptr<CellSpursWorkloadAttribute> attr, vm::ptr<const char> nameClass, vm::ptr<const char> nameInstance)
{
cellSpurs.Warning("%s(attr_addr=0x%x, nameClass_addr=0x%x, nameInstance_addr=0x%x)", __FUNCTION__, attr.addr(), nameClass.addr(), nameInstance.addr());
if (!attr)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
attr->nameClass = nameClass;
attr->nameInstance = nameInstance;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursWorkloadAttributeSetShutdownCompletionEventHook(vm::ptr<CellSpursWorkloadAttribute> attr, vm::ptr<CellSpursShutdownCompletionEventHook> hook, vm::ptr<void> arg)
{
cellSpurs.Warning("%s(attr_addr=0x%x, hook_addr=0x%x, arg=0x%x)", __FUNCTION__, attr.addr(), hook.addr(), arg.addr());
if (!attr || !hook)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
attr->hook = hook;
attr->hookArg = arg;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAddWorkloadWithAttribute(vm::ptr<CellSpurs> spurs, const vm::ptr<u32> wid, vm::ptr<const CellSpursWorkloadAttribute> attr)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, wid_addr=0x%x, attr_addr=0x%x)", __FUNCTION__, spurs.addr(), wid.addr(), attr.addr());
if (!attr)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (attr->revision != be_t<u32>::make(1))
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
return spursAddWorkload(
spurs,
wid,
attr->pm,
attr->size,
attr->data,
attr->priority,
attr->minContention,
attr->maxContention,
attr->nameClass,
attr->nameInstance,
attr->hook,
attr->hookArg);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursRemoveWorkload()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
2014-03-07 22:31:08 +01:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursWaitForWorkloadShutdown()
2014-03-07 22:31:08 +01:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursShutdownWorkload()
2014-03-07 22:31:08 +01:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursWorkloadFlagReceiver(vm::ptr<CellSpurs> spurs, u32 wid, u32 is_set)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, wid=%d, is_set=%d)", __FUNCTION__, spurs.addr(), wid, is_set);
if (!spurs)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (wid >= (spurs->flags1 & SF1_32_WORKLOADS ? 0x20u : 0x10u))
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if ((spurs->wklMskA.read_relaxed() & (0x80000000u >> wid)) == 0)
{
return CELL_SPURS_POLICY_MODULE_ERROR_SRCH;
}
if (spurs->exception.data())
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
if (s32 res = spurs->wklFlag.flag.atomic_op_sync(0, [spurs, wid, is_set](be_t<u32>& flag) -> s32
{
if (is_set)
{
if (spurs->wklFlagReceiver.read_relaxed() != 0xff)
{
return CELL_SPURS_POLICY_MODULE_ERROR_BUSY;
}
}
else
{
if (spurs->wklFlagReceiver.read_relaxed() != wid)
{
return CELL_SPURS_POLICY_MODULE_ERROR_PERM;
}
}
flag = -1;
return 0;
}))
{
return res;
}
spurs->wklFlagReceiver.atomic_op([wid, is_set](u8& FR)
{
if (is_set)
{
if (FR == 0xff)
{
FR = (u8)wid;
}
}
else
{
if (FR == wid)
{
FR = 0xff;
}
}
});
return CELL_OK;
}
s32 cellSpursGetWorkloadFlag(vm::ptr<CellSpurs> spurs, vm::pptr<CellSpursWorkloadFlag> flag)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, flag_addr=0x%x)", __FUNCTION__, spurs.addr(), flag.addr());
if (!spurs || !flag)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
flag->set(vm::get_addr(&spurs->wklFlag));
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSendWorkloadSignal(vm::ptr<CellSpurs> spurs, u32 workloadId)
{
cellSpurs.Warning("%s(spurs=0x%x, workloadId=0x%x)", __FUNCTION__, spurs.addr(), workloadId);
if (!spurs)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (workloadId >= CELL_SPURS_MAX_WORKLOAD2 || (workloadId >= CELL_SPURS_MAX_WORKLOAD && (spurs->flags1 & SF1_32_WORKLOADS) == 0))
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if ((spurs->wklMskA.read_relaxed() & (0x80000000u >> workloadId)) == 0)
{
return CELL_SPURS_POLICY_MODULE_ERROR_SRCH;
}
if (spurs->exception)
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
u8 state;
if (workloadId >= CELL_SPURS_MAX_WORKLOAD)
{
state = spurs->wklState2[workloadId & 0x0F].read_relaxed();
}
else
{
state = spurs->wklState1[workloadId].read_relaxed();
}
if (state != SPURS_WKL_STATE_RUNNABLE)
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
if (workloadId >= CELL_SPURS_MAX_WORKLOAD)
{
spurs->wklSignal2 |= be_t<u16>::make(0x8000 >> (workloadId & 0x0F));
}
else
{
spurs->wklSignal1 |= be_t<u16>::make(0x8000 >> workloadId);
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetWorkloadData(vm::ptr<CellSpurs> spurs, vm::ptr<u64> data, u32 workloadId)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, data=0x%x, workloadId=%d)", __FUNCTION__, spurs.addr(), data.addr(), workloadId);
if (!spurs || !data)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (workloadId >= CELL_SPURS_MAX_WORKLOAD2 || (workloadId >= CELL_SPURS_MAX_WORKLOAD && (spurs->flags1 & SF1_32_WORKLOADS) == 0))
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if ((spurs->wklMskA.read_relaxed() & (0x80000000u >> workloadId)) == 0)
{
return CELL_SPURS_POLICY_MODULE_ERROR_SRCH;
}
if (spurs->exception)
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
if (workloadId >= CELL_SPURS_MAX_WORKLOAD)
{
*data = spurs->wklInfo2[workloadId & 0x0F].arg;
}
else
{
*data = spurs->wklInfo1[workloadId].arg;
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursReadyCountStore(vm::ptr<CellSpurs> spurs, u32 wid, u32 value)
{
cellSpurs.Warning("%s(spurs_addr=0x%x, wid=%d, value=0x%x)", __FUNCTION__, spurs.addr(), wid, value);
if (!spurs)
{
return CELL_SPURS_POLICY_MODULE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_POLICY_MODULE_ERROR_ALIGN;
}
if (wid >= (spurs->flags1 & SF1_32_WORKLOADS ? 0x20u : 0x10u) || value > 0xff)
{
return CELL_SPURS_POLICY_MODULE_ERROR_INVAL;
}
if ((spurs->wklMskA.read_relaxed() & (0x80000000u >> wid)) == 0)
{
return CELL_SPURS_POLICY_MODULE_ERROR_SRCH;
}
if (spurs->exception.data() || spurs->wklState(wid).read_relaxed() != 2)
{
return CELL_SPURS_POLICY_MODULE_ERROR_STAT;
}
if (wid < CELL_SPURS_MAX_WORKLOAD)
{
spurs->wklReadyCount1[wid].exchange((u8)value);
}
else
{
spurs->wklIdleSpuCountOrReadyCount2[wid].exchange((u8)value);
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursReadyCountAdd()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursReadyCountCompareAndSwap()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursReadyCountSwap()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursRequestIdleSpu()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetWorkloadInfo()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursWorkloadFlagReceiver2()
{
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSetExceptionEventHandler()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursUnsetExceptionEventHandler()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursEventFlagInitialize(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursEventFlag> eventFlag, u32 flagClearMode, u32 flagDirection)
{
cellSpurs.Warning("_cellSpursEventFlagInitialize(spurs_addr=0x%x, taskset_addr=0x%x, eventFlag_addr=0x%x, flagClearMode=%d, flagDirection=%d)",
2014-09-02 03:05:13 +02:00
spurs.addr(), taskset.addr(), eventFlag.addr(), flagClearMode, flagDirection);
if ((!taskset && !spurs) || !eventFlag)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!spurs.aligned() || !taskset.aligned() || !eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskset.addr() && taskset->wid >= CELL_SPURS_MAX_WORKLOAD2)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
if (flagDirection > CELL_SPURS_EVENT_FLAG_LAST || flagClearMode > CELL_SPURS_EVENT_FLAG_CLEAR_LAST)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
memset(eventFlag.get_ptr(), 0, sizeof(CellSpursEventFlag));
eventFlag->direction = flagDirection;
eventFlag->clearMode = flagClearMode;
eventFlag->spuPort = CELL_SPURS_EVENT_FLAG_INVALID_SPU_PORT;
if (taskset.addr())
{
eventFlag->addr = taskset.addr();
}
else
{
eventFlag->isIwl = 1;
eventFlag->addr = spurs.addr();
}
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagAttachLv2EventQueue(vm::ptr<CellSpursEventFlag> eventFlag)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("cellSpursEventFlagAttachLv2EventQueue(eventFlag_addr=0x%x)", eventFlag.addr());
if (!eventFlag)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_AGAIN;
}
if (eventFlag->direction != CELL_SPURS_EVENT_FLAG_SPU2PPU && eventFlag->direction != CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
return CELL_SPURS_TASK_ERROR_PERM;
}
if (eventFlag->spuPort != CELL_SPURS_EVENT_FLAG_INVALID_SPU_PORT)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
vm::ptr<CellSpurs> spurs;
if (eventFlag->isIwl == 1)
{
spurs.set((u32)eventFlag->addr);
}
else
{
auto taskset = vm::ptr<CellSpursTaskset>::make((u32)eventFlag->addr);
spurs.set((u32)taskset->spurs.addr());
}
u32 eventQueueId;
vm::var<u8> port;
auto rc = spursCreateLv2EventQueue(spurs, eventQueueId, port, 1, *((u64 *)"_spuEvF"));
if (rc != CELL_OK)
{
// Return rc if its an error code from SPURS otherwise convert the error code to a SPURS task error code
return (rc & 0x0FFF0000) == 0x00410000 ? rc : (0x80410900 | (rc & 0xFF));
}
if (eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
vm::var<be_t<u32>> eventPortId;
rc = sys_event_port_create(vm::ref<u32>::make(eventPortId.addr()), SYS_EVENT_PORT_LOCAL, 0);
if (rc == CELL_OK)
{
rc = sys_event_port_connect_local(eventPortId.value(), eventQueueId);
if (rc == CELL_OK)
{
eventFlag->eventPortId = eventPortId;
goto success;
}
sys_event_port_destroy(eventPortId.value());
}
// TODO: Implement the following
// if (spursDetachLv2EventQueue(spurs, port, 1) == CELL_OK)
// {
// sys_event_queue_destroy(eventQueueId, SYS_EVENT_QUEUE_DESTROY_FORCE);
// }
// Return rc if its an error code from SPURS otherwise convert the error code to a SPURS task error code
return (rc & 0x0FFF0000) == 0x00410000 ? rc : (0x80410900 | (rc & 0xFF));
}
success:
eventFlag->eventQueueId = eventQueueId;
eventFlag->spuPort = port;
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagDetachLv2EventQueue(vm::ptr<CellSpursEventFlag> eventFlag)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("cellSpursEventFlagDetachLv2EventQueue(eventFlag_addr=0x%x)", eventFlag.addr());
if (!eventFlag)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_AGAIN;
}
if (eventFlag->direction != CELL_SPURS_EVENT_FLAG_SPU2PPU && eventFlag->direction != CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
return CELL_SPURS_TASK_ERROR_PERM;
}
if (eventFlag->spuPort == CELL_SPURS_EVENT_FLAG_INVALID_SPU_PORT)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
if (eventFlag->ppuWaitMask || eventFlag->ppuPendingRecv)
{
return CELL_SPURS_TASK_ERROR_BUSY;
}
auto port = eventFlag->spuPort;
eventFlag->spuPort = CELL_SPURS_EVENT_FLAG_INVALID_SPU_PORT;
vm::ptr<CellSpurs> spurs;
if (eventFlag->isIwl == 1)
{
spurs.set((u32)eventFlag->addr);
}
else
{
auto taskset = vm::ptr<CellSpursTaskset>::make((u32)eventFlag->addr);
spurs.set((u32)taskset->spurs.addr());
}
if(eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
sys_event_port_disconnect(eventFlag->eventPortId);
sys_event_port_destroy(eventFlag->eventPortId);
}
2015-02-18 23:54:31 +01:00
s32 rc = CELL_OK;
// TODO: Implement the following
// auto rc = spursDetachLv2EventQueue(spurs, port, 1);
// if (rc == CELL_OK)
// {
// rc = sys_event_queue_destroy(eventFlag->eventQueueId, SYS_EVENT_QUEUE_DESTROY_FORCE);
// }
if (rc != CELL_OK)
{
// Return rc if its an error code from SPURS otherwise convert the error code to a SPURS task error code
return (rc & 0x0FFF0000) == 0x00410000 ? rc : (0x80410900 | (rc & 0xFF));
}
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursEventFlagWait(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode, u32 block)
{
if (!eventFlag || !mask)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (mode > CELL_SPURS_EVENT_FLAG_WAIT_MODE_LAST)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
if (eventFlag->direction != CELL_SPURS_EVENT_FLAG_SPU2PPU && eventFlag->direction != CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
return CELL_SPURS_TASK_ERROR_PERM;
}
if (block && eventFlag->spuPort == CELL_SPURS_EVENT_FLAG_INVALID_SPU_PORT)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
if (eventFlag->ppuWaitMask || eventFlag->ppuPendingRecv)
{
return CELL_SPURS_TASK_ERROR_BUSY;
}
u16 relevantEvents = eventFlag->events & *mask;
if (eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
// Make sure the wait mask and mode specified does not conflict with that of the already waiting tasks.
// Conflict scenarios:
// OR vs OR - A conflict never occurs
// OR vs AND - A conflict occurs if the masks for the two tasks overlap
// AND vs AND - A conflict occurs if the masks for the two tasks are not the same
// Determine the set of all already waiting tasks whose wait mode/mask can possibly conflict with the specified wait mode/mask.
// This set is equal to 'set of all tasks waiting' - 'set of all tasks whose wait conditions have been met'.
// If the wait mode is OR, we prune the set of all tasks that are waiting in OR mode from the set since a conflict cannot occur
// with an already waiting task in OR mode.
u16 relevantWaitSlots = eventFlag->spuTaskUsedWaitSlots & ~eventFlag->spuTaskPendingRecv;
if (mode == CELL_SPURS_EVENT_FLAG_OR)
{
relevantWaitSlots &= eventFlag->spuTaskWaitMode;
}
int i = CELL_SPURS_EVENT_FLAG_MAX_WAIT_SLOTS - 1;
while (relevantWaitSlots)
{
if (relevantWaitSlots & 0x0001)
{
if (eventFlag->spuTaskWaitMask[i] & *mask && eventFlag->spuTaskWaitMask[i] != *mask)
{
return CELL_SPURS_TASK_ERROR_AGAIN;
}
}
relevantWaitSlots >>= 1;
i--;
}
}
// There is no need to block if all bits required by the wait operation have already been set or
// if the wait mode is OR and atleast one of the bits required by the wait operation has been set.
bool recv;
if ((*mask & ~relevantEvents) == 0 || (mode == CELL_SPURS_EVENT_FLAG_OR && relevantEvents))
{
// If the clear flag is AUTO then clear the bits comnsumed by this thread
if (eventFlag->clearMode == CELL_SPURS_EVENT_FLAG_CLEAR_AUTO)
{
eventFlag->events &= ~relevantEvents;
}
recv = false;
}
else
{
// If we reach here it means that the conditions for this thread have not been met.
// If this is a try wait operation then do not block but return an error code.
if (block == 0)
{
return CELL_SPURS_TASK_ERROR_BUSY;
}
eventFlag->ppuWaitSlotAndMode = 0;
if (eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
// Find an unsed wait slot
int i = 0;
u16 spuTaskUsedWaitSlots = eventFlag->spuTaskUsedWaitSlots;
while (spuTaskUsedWaitSlots & 0x0001)
{
spuTaskUsedWaitSlots >>= 1;
i++;
}
if (i == CELL_SPURS_EVENT_FLAG_MAX_WAIT_SLOTS)
{
// Event flag has no empty wait slots
return CELL_SPURS_TASK_ERROR_BUSY;
}
// Mark the found wait slot as used by this thread
eventFlag->ppuWaitSlotAndMode = (CELL_SPURS_EVENT_FLAG_MAX_WAIT_SLOTS - 1 - i) << 4;
}
// Save the wait mask and mode for this thread
eventFlag->ppuWaitSlotAndMode |= mode;
eventFlag->ppuWaitMask = *mask;
recv = true;
}
u16 receivedEventFlag;
if (recv) {
// Block till something happens
2015-03-04 05:42:04 +01:00
vm::var<sys_event_t> data;
auto rc = sys_event_queue_receive(GetCurrentPPUThread(), eventFlag->eventQueueId, data, 0);
if (rc != CELL_OK)
{
assert(0);
}
int i = 0;
if (eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
i = eventFlag->ppuWaitSlotAndMode >> 4;
}
receivedEventFlag = eventFlag->pendingRecvTaskEvents[i];
eventFlag->ppuPendingRecv = 0;
}
*mask = receivedEventFlag;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagWait(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("cellSpursEventFlagWait(eventFlag_addr=0x%x, mask_addr=0x%x, mode=%d)", eventFlag.addr(), mask.addr(), mode);
return _cellSpursEventFlagWait(eventFlag, mask, mode, 1/*block*/);
2014-06-02 05:09:42 +02:00
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagClear(vm::ptr<CellSpursEventFlag> eventFlag, u16 bits)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("cellSpursEventFlagClear(eventFlag_addr=0x%x, bits=0x%x)", eventFlag.addr(), bits);
if (!eventFlag)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
eventFlag->events &= ~bits;
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagSet(vm::ptr<CellSpursEventFlag> eventFlag, u16 bits)
{
cellSpurs.Warning("cellSpursEventFlagSet(eventFlag_addr=0x%x, bits=0x%x)", eventFlag.addr(), bits);
if (!eventFlag)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (eventFlag->direction != CELL_SPURS_EVENT_FLAG_PPU2SPU && eventFlag->direction != CELL_SPURS_EVENT_FLAG_ANY2ANY)
{
return CELL_SPURS_TASK_ERROR_PERM;
}
u16 ppuEventFlag = 0;
bool send = false;
int ppuWaitSlot = 0;
u16 eventsToClear = 0;
if (eventFlag->direction == CELL_SPURS_EVENT_FLAG_ANY2ANY && eventFlag->ppuWaitMask)
{
u16 ppuRelevantEvents = (eventFlag->events | bits) & eventFlag->ppuWaitMask;
// Unblock the waiting PPU thread if either all the bits being waited by the thread have been set or
// if the wait mode of the thread is OR and atleast one bit the thread is waiting on has been set
if ((eventFlag->ppuWaitMask & ~ppuRelevantEvents) == 0 ||
((eventFlag->ppuWaitSlotAndMode & 0x0F) == CELL_SPURS_EVENT_FLAG_OR && ppuRelevantEvents != 0))
{
eventFlag->ppuPendingRecv = 1;
eventFlag->ppuWaitMask = 0;
ppuEventFlag = ppuRelevantEvents;
eventsToClear = ppuRelevantEvents;
ppuWaitSlot = eventFlag->ppuWaitSlotAndMode >> 4;
send = true;
}
}
int i = CELL_SPURS_EVENT_FLAG_MAX_WAIT_SLOTS - 1;
int j = 0;
u16 relevantWaitSlots = eventFlag->spuTaskUsedWaitSlots & ~eventFlag->spuTaskPendingRecv;
u16 spuTaskPendingRecv = 0;
u16 pendingRecvTaskEvents[16];
while (relevantWaitSlots)
{
if (relevantWaitSlots & 0x0001)
{
u16 spuTaskRelevantEvents = (eventFlag->events | bits) & eventFlag->spuTaskWaitMask[i];
// Unblock the waiting SPU task if either all the bits being waited by the task have been set or
// if the wait mode of the task is OR and atleast one bit the thread is waiting on has been set
if ((eventFlag->spuTaskWaitMask[i] & ~spuTaskRelevantEvents) == 0 ||
(((eventFlag->spuTaskWaitMode >> j) & 0x0001) == CELL_SPURS_EVENT_FLAG_OR && spuTaskRelevantEvents != 0))
{
eventsToClear |= spuTaskRelevantEvents;
spuTaskPendingRecv |= 1 << j;
pendingRecvTaskEvents[j] = spuTaskRelevantEvents;
}
}
relevantWaitSlots >>= 1;
i--;
j++;
}
eventFlag->events |= bits;
eventFlag->spuTaskPendingRecv |= spuTaskPendingRecv;
// If the clear flag is AUTO then clear the bits comnsumed by all tasks marked to be unblocked
if (eventFlag->clearMode == CELL_SPURS_EVENT_FLAG_CLEAR_AUTO)
{
eventFlag->events &= ~eventsToClear;
}
if (send)
{
// Signal the PPU thread to be woken up
eventFlag->pendingRecvTaskEvents[ppuWaitSlot] = ppuEventFlag;
if (sys_event_port_send(eventFlag->eventPortId, 0, 0, 0) != CELL_OK)
{
assert(0);
}
}
if (spuTaskPendingRecv)
{
// Signal each SPU task whose conditions have been met to be woken up
for (int i = 0; i < CELL_SPURS_EVENT_FLAG_MAX_WAIT_SLOTS; i++)
{
if (spuTaskPendingRecv & (0x8000 >> i))
{
eventFlag->pendingRecvTaskEvents[i] = pendingRecvTaskEvents[i];
vm::var<u32> taskset;
if (eventFlag->isIwl)
{
cellSpursLookUpTasksetAddress(vm::ptr<CellSpurs>::make((u32)eventFlag->addr),
vm::ptr<CellSpursTaskset>::make(taskset.addr()),
eventFlag->waitingTaskWklId[i]);
}
else
{
taskset.value() = (u32)eventFlag->addr;
}
auto rc = _cellSpursSendSignal(vm::ptr<CellSpursTaskset>::make(taskset.addr()), eventFlag->waitingTaskId[i]);
if (rc == CELL_SPURS_TASK_ERROR_INVAL || rc == CELL_SPURS_TASK_ERROR_STAT)
{
return CELL_SPURS_TASK_ERROR_FATAL;
}
if (rc != CELL_OK)
{
assert(0);
}
}
}
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagTryWait(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u16> mask, u32 mode)
{
cellSpurs.Warning("cellSpursEventFlagTryWait(eventFlag_addr=0x%x, mask_addr=0x%x, mode=0x%x)", eventFlag.addr(), mask.addr(), mode);
return _cellSpursEventFlagWait(eventFlag, mask, mode, 0/*block*/);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagGetDirection(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u32> direction)
{
cellSpurs.Warning("cellSpursEventFlagGetDirection(eventFlag_addr=0x%x, direction_addr=0x%x)", eventFlag.addr(), direction.addr());
if (!eventFlag || !direction)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
*direction = eventFlag->direction;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagGetClearMode(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<u32> clear_mode)
{
cellSpurs.Warning("cellSpursEventFlagGetClearMode(eventFlag_addr=0x%x, clear_mode_addr=0x%x)", eventFlag.addr(), clear_mode.addr());
if (!eventFlag || !clear_mode)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
*clear_mode = eventFlag->clearMode;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursEventFlagGetTasksetAddress(vm::ptr<CellSpursEventFlag> eventFlag, vm::ptr<CellSpursTaskset> taskset)
{
cellSpurs.Warning("cellSpursEventFlagGetTasksetAddress(eventFlag_addr=0x%x, taskset_addr=0x%x)", eventFlag.addr(), taskset.addr());
if (!eventFlag || !taskset)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!eventFlag.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
taskset.set(eventFlag->isIwl ? 0 : eventFlag->addr);
return CELL_OK;
}
2014-06-07 11:32:15 +02:00
2015-02-18 23:54:31 +01:00
s32 _cellSpursLFQueueInitialize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursLFQueuePushBody()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursLFQueueDetachLv2EventQueue()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursLFQueueAttachLv2EventQueue()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursLFQueuePopBody()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursLFQueueGetTasksetAddress()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursQueueInitialize()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueuePopBody()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueuePushBody()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueAttachLv2EventQueue()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueDetachLv2EventQueue()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueGetTasksetAddress()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueClear()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueDepth()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueGetEntrySize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueSize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursQueueGetDirection()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateJobChainWithAttribute()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateJobChain()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJoinJobChain()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursKickJobChain()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursJobChainAttributeInitialize()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetJobChainId()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainSetExceptionEventHandler()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainUnsetExceptionEventHandler()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetJobChainInfo()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainGetSpursAddress()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 spursCreateTaskset(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u64 args, vm::ptr<const u8[8]> priority,
2014-12-12 21:12:09 +01:00
u32 max_contention, vm::ptr<const char> name, u32 size, s32 enable_clear_ls)
{
if (!spurs || !taskset)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!spurs.aligned() || !taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
memset(taskset.get_ptr(), 0, size);
taskset->spurs = spurs;
taskset->args = args;
taskset->enable_clear_ls = enable_clear_ls > 0 ? 1 : 0;
taskset->size = size;
2014-12-12 21:12:09 +01:00
vm::var<CellSpursWorkloadAttribute> wkl_attr;
2015-02-02 21:43:32 +01:00
_cellSpursWorkloadAttributeInitialize(wkl_attr, 1 /*revision*/, 0x33 /*sdk_version*/, vm::ptr<const void>::make(SPURS_IMG_ADDR_TASKSET_PM), 0x1E40 /*pm_size*/,
2014-12-12 21:12:09 +01:00
taskset.addr(), priority, 8 /*min_contention*/, max_contention);
// TODO: Check return code
2015-04-21 22:26:21 +02:00
cellSpursWorkloadAttributeSetName(wkl_attr, vm::null, name);
2014-12-12 21:12:09 +01:00
// TODO: Check return code
// TODO: cellSpursWorkloadAttributeSetShutdownCompletionEventHook(wkl_attr, hook, taskset);
// TODO: Check return code
vm::var<be_t<u32>> wid;
2015-04-21 22:26:21 +02:00
cellSpursAddWorkloadWithAttribute(spurs, vm::ptr<u32>::make(wid.addr()), wkl_attr);
2014-12-12 21:12:09 +01:00
// TODO: Check return code
taskset->wkl_flag_wait_task = 0x80;
taskset->wid = wid.value();
2014-12-12 21:12:09 +01:00
// TODO: cellSpursSetExceptionEventHandler(spurs, wid, hook, taskset);
// TODO: Check return code
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTasksetWithAttribute(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, vm::ptr<CellSpursTasksetAttribute> attr)
{
cellSpurs.Warning("%s(spurs=0x%x, taskset=0x%x, attr=0x%x)", __FUNCTION__, spurs.addr(), taskset.addr(), attr.addr());
2014-12-14 07:37:46 +01:00
if (!attr)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (attr->revision != CELL_SPURS_TASKSET_ATTRIBUTE_REVISION)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
auto rc = spursCreateTaskset(spurs, taskset, attr->args, vm::ptr<const u8[8]>::make(attr.addr() + offsetof(CellSpursTasksetAttribute, priority)),
attr->max_contention, vm::ptr<const char>::make(attr->name.addr()), attr->taskset_size, attr->enable_clear_ls);
2014-12-12 21:12:09 +01:00
if (attr->taskset_size >= sizeof32(CellSpursTaskset2))
2014-12-12 21:12:09 +01:00
{
// TODO: Implement this
}
return rc;
}
2014-06-02 07:42:30 +02:00
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTaskset(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u64 args, vm::ptr<const u8[8]> priority, u32 maxContention)
{
cellSpurs.Warning("cellSpursCreateTaskset(spurs_addr=0x%x, taskset_addr=0x%x, args=0x%llx, priority_addr=0x%x, maxContention=%d)",
2014-09-02 03:05:13 +02:00
spurs.addr(), taskset.addr(), args, priority.addr(), maxContention);
2015-04-21 22:26:21 +02:00
return spursCreateTaskset(spurs, taskset, args, priority, maxContention, vm::null, 6400/*CellSpursTaskset::size*/, 0);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJoinTaskset(vm::ptr<CellSpursTaskset> taskset)
{
cellSpurs.Warning("cellSpursJoinTaskset(taskset_addr=0x%x)", taskset.addr());
2014-12-14 07:37:46 +01:00
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetTasksetId(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> wid)
2014-03-07 22:31:08 +01:00
{
cellSpurs.Warning("cellSpursGetTasksetId(taskset_addr=0x%x, wid=0x%x)", taskset.addr(), wid.addr());
2014-12-14 07:37:46 +01:00
if (!taskset || !wid)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskset->wid >= CELL_SPURS_MAX_WORKLOAD)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
*wid = taskset->wid;
2014-03-07 22:31:08 +01:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursShutdownTaskset(vm::ptr<CellSpursTaskset> taskset)
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2014-03-07 22:31:08 +01:00
2014-12-13 22:49:06 +01:00
u32 _cellSpursGetSdkVersion()
{
2015-02-19 21:46:25 +01:00
// Commenting this out for now since process_get_sdk_version does not return
// the correct SDK version and instead returns a version too high for the game
// and causes SPURS to fail.
//s32 sdk_version;
//if (process_get_sdk_version(process_getpid(), sdk_version) != CELL_OK)
//{
// throw __FUNCTION__;
//}
//return sdk_version;
return 1;
2014-12-13 22:49:06 +01:00
}
2015-02-18 23:54:31 +01:00
s32 spursCreateTask(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> task_id, vm::ptr<u32> elf_addr, vm::ptr<u32> context_addr, u32 context_size, vm::ptr<CellSpursTaskLsPattern> ls_pattern, vm::ptr<CellSpursTaskArgument> arg)
2014-12-13 22:49:06 +01:00
{
if (!taskset || !elf_addr)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (elf_addr % 16)
2014-12-13 22:49:06 +01:00
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
auto sdk_version = _cellSpursGetSdkVersion();
if (sdk_version < 0x27FFFF)
{
if (context_addr % 16)
2014-12-13 22:49:06 +01:00
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
}
else
{
if (context_addr % 128)
2014-12-13 22:49:06 +01:00
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
}
u32 alloc_ls_blocks = 0;
if (context_addr.addr() != 0)
{
if (context_size < CELL_SPURS_TASK_EXECUTION_CONTEXT_SIZE)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
alloc_ls_blocks = context_size > 0x3D400 ? 0x7A : ((context_size - 0x400) >> 11);
if (ls_pattern.addr() != 0)
{
2015-02-19 21:23:05 +01:00
u128 ls_pattern_128 = u128::from64r(ls_pattern->_u64[0], ls_pattern->_u64[1]);
2015-02-19 19:24:57 +01:00
u32 ls_blocks = 0;
2015-02-04 16:29:34 +01:00
for (auto i = 0; i < 128; i++)
2014-12-13 22:49:06 +01:00
{
2015-02-19 19:24:57 +01:00
if (ls_pattern_128._bit[i])
2015-02-02 21:43:32 +01:00
{
ls_blocks++;
2014-12-13 22:49:06 +01:00
}
}
if (ls_blocks > alloc_ls_blocks)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
2015-02-04 16:29:34 +01:00
u128 _0 = u128::from32(0);
2015-02-19 19:24:57 +01:00
if ((ls_pattern_128 & u128::from32r(0xFC000000)) != _0)
2014-12-13 22:49:06 +01:00
{
// Prevent save/restore to SPURS management area
return CELL_SPURS_TASK_ERROR_INVAL;
}
}
}
else
{
alloc_ls_blocks = 0;
}
// TODO: Verify the ELF header is proper and all its load segments are at address >= 0x3000
u32 tmp_task_id;
for (tmp_task_id = 0; tmp_task_id < CELL_SPURS_MAX_TASK; tmp_task_id++)
{
if (!taskset->enabled.value()._bit[tmp_task_id])
2014-12-13 22:49:06 +01:00
{
auto enabled = taskset->enabled.value();
2015-02-02 21:43:32 +01:00
enabled._bit[tmp_task_id] = true;
taskset->enabled = enabled;
2014-12-13 22:49:06 +01:00
break;
}
}
if (tmp_task_id >= CELL_SPURS_MAX_TASK)
{
return CELL_SPURS_TASK_ERROR_AGAIN;
2014-12-13 22:49:06 +01:00
}
taskset->task_info[tmp_task_id].elf_addr.set(elf_addr.addr());
taskset->task_info[tmp_task_id].context_save_storage_and_alloc_ls_blocks = (context_addr.addr() | alloc_ls_blocks);
taskset->task_info[tmp_task_id].args = *arg;
2015-02-04 16:29:34 +01:00
if (ls_pattern.addr())
2014-12-13 22:49:06 +01:00
{
taskset->task_info[tmp_task_id].ls_pattern = *ls_pattern;
2014-12-13 22:49:06 +01:00
}
*task_id = tmp_task_id;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 spursTaskStart(vm::ptr<CellSpursTaskset> taskset, u32 taskId)
2015-02-02 21:43:32 +01:00
{
auto pendingReady = taskset->pending_ready.value();
2015-02-02 21:43:32 +01:00
pendingReady._bit[taskId] = true;
taskset->pending_ready = pendingReady;
2015-02-02 21:43:32 +01:00
cellSpursSendWorkloadSignal(taskset->spurs, taskset->wid);
auto rc = cellSpursWakeUp(GetCurrentPPUThread(), taskset->spurs);
2015-02-02 21:43:32 +01:00
if (rc != CELL_OK)
{
if (rc == CELL_SPURS_POLICY_MODULE_ERROR_STAT)
{
rc = CELL_SPURS_TASK_ERROR_STAT;
}
else
{
assert(0);
}
}
return rc;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTask(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> taskId, u32 elf_addr, u32 context_addr, u32 context_size, vm::ptr<CellSpursTaskLsPattern> lsPattern,
2014-09-02 03:05:13 +02:00
vm::ptr<CellSpursTaskArgument> argument)
{
cellSpurs.Warning("cellSpursCreateTask(taskset_addr=0x%x, taskID_addr=0x%x, elf_addr_addr=0x%x, context_addr_addr=0x%x, context_size=%d, lsPattern_addr=0x%x, argument_addr=0x%x)",
2015-02-02 21:43:32 +01:00
taskset.addr(), taskId.addr(), elf_addr, context_addr, context_size, lsPattern.addr(), argument.addr());
2014-12-14 07:37:46 +01:00
2015-02-02 21:43:32 +01:00
if (!taskset)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
2015-02-02 21:43:32 +01:00
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
2015-03-12 20:02:02 +01:00
vm::var<be_t<u32>> tmpTaskId;
2015-02-02 21:43:32 +01:00
auto rc = spursCreateTask(taskset, tmpTaskId, vm::ptr<u32>::make(elf_addr), vm::ptr<u32>::make(context_addr), context_size, lsPattern, argument);
2015-02-19 21:23:05 +01:00
if (rc != CELL_OK)
{
return rc;
}
2015-03-12 20:02:02 +01:00
rc = spursTaskStart(taskset, tmpTaskId->value());
2015-02-19 21:23:05 +01:00
if (rc != CELL_OK)
{
return rc;
}
*taskId = tmpTaskId;
return CELL_OK;
}
2014-03-07 22:31:08 +01:00
2015-02-18 23:54:31 +01:00
s32 _cellSpursSendSignal(vm::ptr<CellSpursTaskset> taskset, u32 taskId)
{
if (!taskset)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskId >= CELL_SPURS_MAX_TASK || taskset->wid >= CELL_SPURS_MAX_WORKLOAD2)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
auto _0 = be_t<u128>::make(u128::from32(0));
auto disabled = taskset->enabled.value()._bit[taskId] ? false : true;
auto invalid = (taskset->ready & taskset->pending_ready) != _0 || (taskset->running & taskset->waiting) != _0 || disabled ||
((taskset->running | taskset->ready | taskset->pending_ready | taskset->waiting | taskset->signalled) & be_t<u128>::make(~taskset->enabled.value())) != _0;
if (invalid)
{
return CELL_SPURS_TASK_ERROR_SRCH;
}
auto shouldSignal = (taskset->waiting & be_t<u128>::make(~taskset->signalled.value()) & be_t<u128>::make(u128::fromBit(taskId))) != _0 ? true : false;
auto signalled = taskset->signalled.value();
2015-02-03 06:33:49 +01:00
signalled._bit[taskId] = true;
taskset->signalled = signalled;
if (shouldSignal)
{
cellSpursSendWorkloadSignal(taskset->spurs, taskset->wid);
auto rc = cellSpursWakeUp(GetCurrentPPUThread(), taskset->spurs);
if (rc == CELL_SPURS_POLICY_MODULE_ERROR_STAT)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
if (rc != CELL_OK)
{
assert(0);
}
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTaskWithAttribute()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetAttributeSetName(vm::ptr<CellSpursTasksetAttribute> attr, vm::ptr<const char> name)
{
cellSpurs.Warning("%s(attr=0x%x, name=0x%x)", __FUNCTION__, attr.addr(), name.addr());
2014-12-14 07:37:46 +01:00
if (!attr || !name)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
attr->name = name;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetAttributeSetTasksetSize(vm::ptr<CellSpursTasksetAttribute> attr, u32 size)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("%s(attr=0x%x, size=0x%x)", __FUNCTION__, attr.addr(), size);
2014-12-14 07:37:46 +01:00
if (!attr)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (size != sizeof32(CellSpursTaskset) && size != sizeof32(CellSpursTaskset2))
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
attr->taskset_size = size;
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetAttributeEnableClearLS(vm::ptr<CellSpursTasksetAttribute> attr, s32 enable)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("%s(attr=0x%x, enable=%d)", __FUNCTION__, attr.addr(), enable);
2014-12-14 07:37:46 +01:00
if (!attr)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
attr->enable_clear_ls = enable ? 1 : 0;
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursTasksetAttribute2Initialize(vm::ptr<CellSpursTasksetAttribute2> attribute, u32 revision)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("_cellSpursTasksetAttribute2Initialize(attribute_addr=0x%x, revision=%d)", attribute.addr(), revision);
2015-02-18 23:54:31 +01:00
memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute2));
attribute->revision = revision;
attribute->name = vm::null;
attribute->args = 0;
for (s32 i = 0; i < 8; i++)
{
attribute->priority[i] = 1;
}
attribute->max_contention = 8;
attribute->enable_clear_ls = 0;
attribute->task_name_buffer.set(0);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskExitCodeGet()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskExitCodeInitialize()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskExitCodeTryGet()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskGetLoadableSegmentPattern()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskGetReadOnlyAreaPattern()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskGenerateLsPattern()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursTaskAttributeInitialize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskAttributeSetExitCodeContainer()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursTaskAttribute2Initialize(vm::ptr<CellSpursTaskAttribute2> attribute, u32 revision)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("_cellSpursTaskAttribute2Initialize(attribute_addr=0x%x, revision=%d)", attribute.addr(), revision);
2014-08-10 21:06:51 +02:00
attribute->revision = revision;
attribute->sizeContext = 0;
2015-01-02 16:29:57 +01:00
attribute->eaContext = 0;
2015-02-19 19:24:57 +01:00
for (s32 c = 0; c < 4; c++)
2014-08-10 21:06:51 +02:00
{
2015-02-19 19:24:57 +01:00
attribute->lsPattern._u32[c] = 0;
2014-08-10 21:06:51 +02:00
}
attribute->name = vm::null;
2014-08-10 21:06:51 +02:00
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTaskGetContextSaveAreaSize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTaskset2(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset2> taskset, vm::ptr<CellSpursTasksetAttribute2> attr)
{
cellSpurs.Warning("%s(spurs=0x%x, taskset=0x%x, attr=0x%x)", __FUNCTION__, spurs.addr(), taskset.addr(), attr.addr());
2014-12-14 07:37:46 +01:00
vm::ptr<CellSpursTasksetAttribute2> tmp_attr;
2014-12-12 21:12:09 +01:00
if (!attr)
{
attr.set(tmp_attr.addr());
2014-12-12 21:12:09 +01:00
_cellSpursTasksetAttribute2Initialize(attr, 0);
}
auto rc = spursCreateTaskset(spurs, vm::ptr<CellSpursTaskset>::make(taskset.addr()), attr->args,
vm::ptr<const u8[8]>::make(attr.addr() + offsetof(CellSpursTasksetAttribute, priority)),
attr->max_contention, attr->name, sizeof32(CellSpursTaskset2), (u8)attr->enable_clear_ls);
2014-12-12 21:12:09 +01:00
if (rc != CELL_OK)
{
return rc;
}
if (!attr->task_name_buffer.aligned())
2014-12-12 21:12:09 +01:00
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
// TODO: Implement rest of the function
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTask2()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJoinTask2()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTryJoinTask2()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursDestroyTaskset2()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursCreateTask2WithBinInfo()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetSetExceptionEventHandler(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u64> handler, vm::ptr<u64> arg)
{
cellSpurs.Warning("%s(taskset=0x5x, handler=0x%x, arg=0x%x)", __FUNCTION__, taskset.addr(), handler.addr(), arg.addr());
2014-12-14 07:37:46 +01:00
if (!taskset || !handler)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskset->wid >= CELL_SPURS_MAX_WORKLOAD)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
if (taskset->exception_handler)
{
return CELL_SPURS_TASK_ERROR_BUSY;
}
taskset->exception_handler = handler;
taskset->exception_handler_arg = arg;
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetUnsetExceptionEventHandler(vm::ptr<CellSpursTaskset> taskset)
{
cellSpurs.Warning("%s(taskset=0x%x)", __FUNCTION__, taskset.addr());
2014-12-14 07:37:46 +01:00
if (!taskset)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskset->wid >= CELL_SPURS_MAX_WORKLOAD)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
taskset->exception_handler.set(0);
taskset->exception_handler_arg.set(0);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursLookUpTasksetAddress(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTaskset> taskset, u32 id)
{
cellSpurs.Warning("%s(spurs=0x%x, taskset=0x%x, id=0x%x)", __FUNCTION__, spurs.addr(), taskset.addr(), id);
2014-12-14 07:37:46 +01:00
if (taskset.addr() == 0)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
vm::var<be_t<u64>> data;
2015-04-21 22:26:21 +02:00
auto rc = cellSpursGetWorkloadData(spurs, data, id);
if (rc != CELL_OK)
{
// Convert policy module error code to a task error code
return rc ^ 0x100;
}
taskset.set((u32)data.value());
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTasksetGetSpursAddress(vm::ptr<const CellSpursTaskset> taskset, vm::ptr<u32> spurs)
{
cellSpurs.Warning("%s(taskset=0x%x, spurs=0x%x)", __FUNCTION__, taskset.addr(), spurs.addr());
2014-12-14 07:37:46 +01:00
if (!taskset || !spurs)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!taskset.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
if (taskset->wid >= CELL_SPURS_MAX_WORKLOAD)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
*spurs = (u32)taskset->spurs.addr();
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetTasksetInfo()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursTasksetAttributeInitialize(vm::ptr<CellSpursTasksetAttribute> attribute, u32 revision, u32 sdk_version, u64 args, vm::ptr<const u8> priority, u32 max_contention)
2014-06-02 05:09:42 +02:00
{
cellSpurs.Warning("%s(attribute=0x%x, revision=%d, skd_version=%d, args=0x%llx, priority=0x%x, max_contention=%d)",
2014-12-14 07:37:46 +01:00
__FUNCTION__, attribute.addr(), revision, sdk_version, args, priority.addr(), max_contention);
if (!attribute)
{
return CELL_SPURS_TASK_ERROR_NULL_POINTER;
}
if (!attribute.aligned())
{
return CELL_SPURS_TASK_ERROR_ALIGN;
}
for (u32 i = 0; i < 8; i++)
{
if (priority[i] > 0xF)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
}
memset(attribute.get_ptr(), 0, sizeof(CellSpursTasksetAttribute));
attribute->revision = revision;
attribute->sdk_version = sdk_version;
attribute->args = args;
memcpy(attribute->priority, priority.get_ptr(), 8);
attribute->taskset_size = 6400/*CellSpursTaskset::size*/;
attribute->max_contention = max_contention;
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobGuardInitialize()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainAttributeSetName()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursShutdownJobChain()
2014-06-02 05:09:42 +02:00
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
2014-06-02 05:09:42 +02:00
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainAttributeSetHaltOnError()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainAttributeSetJobTypeMemoryCheck()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobGuardNotify()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobGuardReset()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursRunJobChain()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobChainGetError()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursGetJobPipelineInfo()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobSetMaxGrab()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursJobHeaderSetJobbin2Param()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAddUrgentCommand()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursAddUrgentCall()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursBarrierInitialize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursBarrierGetTasksetAddress()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 _cellSpursSemaphoreInitialize()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursSemaphoreGetTasksetAddress()
{
2014-08-27 15:11:34 +02:00
UNIMPLEMENTED_FUNC(cellSpurs);
return CELL_OK;
2014-06-02 05:09:42 +02:00
}
bool spursIsLibProfLoaded()
{
return false;
}
void spursTraceStatusUpdate(vm::ptr<CellSpurs> spurs)
{
2015-03-04 05:42:04 +01:00
LV2_LOCK;
if (spurs->xCC != 0)
{
spurs->xCD = 1;
spurs->sysSrvMsgUpdateTrace = (1 << spurs->nSpus) - 1;
spurs->sysSrvMessage.write_relaxed(0xFF);
sys_semaphore_wait((u32)spurs->semPrv, 0);
}
}
2015-02-18 23:54:31 +01:00
s32 spursTraceInitialize(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTraceInfo> buffer, u32 size, u32 mode, u32 updateStatus)
{
if (!spurs || !buffer)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned() || !buffer.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (size < sizeof32(CellSpursTraceInfo) || mode & ~(CELL_SPURS_TRACE_MODE_FLAG_MASK))
{
return CELL_SPURS_CORE_ERROR_INVAL;
}
if (spurs->traceBuffer)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
spurs->traceDataSize = size - sizeof32(CellSpursTraceInfo);
for (u32 i = 0; i < 8; i++)
{
buffer->spu_thread[i] = spurs->spus[i];
buffer->count[i] = 0;
}
buffer->spu_thread_grp = spurs->spuTG;
buffer->nspu = spurs->nSpus;
spurs->traceBuffer.set(buffer.addr() | (mode & CELL_SPURS_TRACE_MODE_FLAG_WRAP_BUFFER ? 1 : 0));
spurs->traceMode = mode;
u32 spuTraceDataCount = (u32)((spurs->traceDataSize / sizeof32(CellSpursTracePacket)) / spurs->nSpus);
for (u32 i = 0, j = 8; i < 6; i++)
{
spurs->traceStartIndex[i] = j;
j += spuTraceDataCount;
}
spurs->sysSrvTraceControl = 0;
if (updateStatus)
{
spursTraceStatusUpdate(spurs);
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTraceInitialize(vm::ptr<CellSpurs> spurs, vm::ptr<CellSpursTraceInfo> buffer, u32 size, u32 mode)
{
if (spursIsLibProfLoaded())
{
return CELL_SPURS_CORE_ERROR_STAT;
}
return spursTraceInitialize(spurs, buffer, size, mode, 1);
}
2015-02-18 23:54:31 +01:00
s32 spursTraceStart(vm::ptr<CellSpurs> spurs, u32 updateStatus)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (!spurs->traceBuffer)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
spurs->sysSrvTraceControl = 1;
if (updateStatus)
{
spursTraceStatusUpdate(spurs);
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTraceStart(vm::ptr<CellSpurs> spurs)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
return spursTraceStart(spurs, spurs->traceMode & CELL_SPURS_TRACE_MODE_FLAG_SYNCHRONOUS_START_STOP);
}
2015-02-18 23:54:31 +01:00
s32 spursTraceStop(vm::ptr<CellSpurs> spurs, u32 updateStatus)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (!spurs->traceBuffer)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
spurs->sysSrvTraceControl = 2;
if (updateStatus)
{
spursTraceStatusUpdate(spurs);
}
return CELL_OK;
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTraceStop(vm::ptr<CellSpurs> spurs)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
return spursTraceStop(spurs, spurs->traceMode & CELL_SPURS_TRACE_MODE_FLAG_SYNCHRONOUS_START_STOP);
}
2015-02-18 23:54:31 +01:00
s32 cellSpursTraceFinalize(vm::ptr<CellSpurs> spurs)
{
if (!spurs)
{
return CELL_SPURS_CORE_ERROR_NULL_POINTER;
}
if (!spurs.aligned())
{
return CELL_SPURS_CORE_ERROR_ALIGN;
}
if (!spurs->traceBuffer)
{
return CELL_SPURS_CORE_ERROR_STAT;
}
spurs->sysSrvTraceControl = 0;
spurs->traceMode = 0;
spurs->traceBuffer.set(0);
spursTraceStatusUpdate(spurs);
return CELL_OK;
}
Module cellSpurs("cellSpurs", []()
2014-03-07 22:31:08 +01:00
{
// Core
REG_FUNC(cellSpurs, cellSpursInitialize);
REG_FUNC(cellSpurs, cellSpursInitializeWithAttribute);
REG_FUNC(cellSpurs, cellSpursInitializeWithAttribute2);
REG_FUNC(cellSpurs, cellSpursFinalize);
REG_FUNC(cellSpurs, _cellSpursAttributeInitialize);
REG_FUNC(cellSpurs, cellSpursAttributeSetMemoryContainerForSpuThread);
REG_FUNC(cellSpurs, cellSpursAttributeSetNamePrefix);
REG_FUNC(cellSpurs, cellSpursAttributeEnableSpuPrintfIfAvailable);
REG_FUNC(cellSpurs, cellSpursAttributeSetSpuThreadGroupType);
REG_FUNC(cellSpurs, cellSpursAttributeEnableSystemWorkload);
REG_FUNC(cellSpurs, cellSpursGetSpuThreadGroupId);
REG_FUNC(cellSpurs, cellSpursGetNumSpuThread);
REG_FUNC(cellSpurs, cellSpursGetSpuThreadId);
REG_FUNC(cellSpurs, cellSpursGetInfo);
REG_FUNC(cellSpurs, cellSpursSetMaxContention);
REG_FUNC(cellSpurs, cellSpursSetPriorities);
REG_FUNC(cellSpurs, cellSpursSetPreemptionVictimHints);
REG_FUNC(cellSpurs, cellSpursAttachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursDetachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursEnableExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursSetGlobalExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursUnsetGlobalExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursSetExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursUnsetExceptionEventHandler);
// Event flag
REG_FUNC(cellSpurs, _cellSpursEventFlagInitialize);
REG_FUNC(cellSpurs, cellSpursEventFlagAttachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursEventFlagDetachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursEventFlagWait);
REG_FUNC(cellSpurs, cellSpursEventFlagClear);
REG_FUNC(cellSpurs, cellSpursEventFlagSet);
REG_FUNC(cellSpurs, cellSpursEventFlagTryWait);
REG_FUNC(cellSpurs, cellSpursEventFlagGetDirection);
REG_FUNC(cellSpurs, cellSpursEventFlagGetClearMode);
REG_FUNC(cellSpurs, cellSpursEventFlagGetTasksetAddress);
2014-03-07 22:31:08 +01:00
// Taskset
REG_FUNC(cellSpurs, cellSpursCreateTaskset);
REG_FUNC(cellSpurs, cellSpursCreateTasksetWithAttribute);
REG_FUNC(cellSpurs, _cellSpursTasksetAttributeInitialize);
REG_FUNC(cellSpurs, _cellSpursTasksetAttribute2Initialize);
REG_FUNC(cellSpurs, cellSpursTasksetAttributeSetName);
REG_FUNC(cellSpurs, cellSpursTasksetAttributeSetTasksetSize);
REG_FUNC(cellSpurs, cellSpursTasksetAttributeEnableClearLS);
REG_FUNC(cellSpurs, cellSpursJoinTaskset);
REG_FUNC(cellSpurs, cellSpursGetTasksetId);
REG_FUNC(cellSpurs, cellSpursShutdownTaskset);
REG_FUNC(cellSpurs, cellSpursCreateTask);
REG_FUNC(cellSpurs, cellSpursCreateTaskWithAttribute);
REG_FUNC(cellSpurs, _cellSpursTaskAttributeInitialize);
REG_FUNC(cellSpurs, _cellSpursTaskAttribute2Initialize);
REG_FUNC(cellSpurs, cellSpursTaskAttributeSetExitCodeContainer);
REG_FUNC(cellSpurs, cellSpursTaskExitCodeGet);
REG_FUNC(cellSpurs, cellSpursTaskExitCodeInitialize);
REG_FUNC(cellSpurs, cellSpursTaskExitCodeTryGet);
REG_FUNC(cellSpurs, cellSpursTaskGetLoadableSegmentPattern);
REG_FUNC(cellSpurs, cellSpursTaskGetReadOnlyAreaPattern);
REG_FUNC(cellSpurs, cellSpursTaskGenerateLsPattern);
REG_FUNC(cellSpurs, cellSpursTaskGetContextSaveAreaSize);
REG_FUNC(cellSpurs, _cellSpursSendSignal);
REG_FUNC(cellSpurs, cellSpursCreateTaskset2);
REG_FUNC(cellSpurs, cellSpursCreateTask2);
REG_FUNC(cellSpurs, cellSpursJoinTask2);
REG_FUNC(cellSpurs, cellSpursTryJoinTask2);
REG_FUNC(cellSpurs, cellSpursDestroyTaskset2);
REG_FUNC(cellSpurs, cellSpursCreateTask2WithBinInfo);
REG_FUNC(cellSpurs, cellSpursLookUpTasksetAddress);
REG_FUNC(cellSpurs, cellSpursTasksetGetSpursAddress);
REG_FUNC(cellSpurs, cellSpursGetTasksetInfo);
REG_FUNC(cellSpurs, cellSpursTasksetSetExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursTasksetUnsetExceptionEventHandler);
// Job Chain
REG_FUNC(cellSpurs, cellSpursCreateJobChain);
REG_FUNC(cellSpurs, cellSpursCreateJobChainWithAttribute);
REG_FUNC(cellSpurs, cellSpursShutdownJobChain);
REG_FUNC(cellSpurs, cellSpursJoinJobChain);
REG_FUNC(cellSpurs, cellSpursKickJobChain);
REG_FUNC(cellSpurs, cellSpursRunJobChain);
REG_FUNC(cellSpurs, cellSpursJobChainGetError);
REG_FUNC(cellSpurs, _cellSpursJobChainAttributeInitialize);
REG_FUNC(cellSpurs, cellSpursJobChainAttributeSetName);
REG_FUNC(cellSpurs, cellSpursJobChainAttributeSetHaltOnError);
REG_FUNC(cellSpurs, cellSpursJobChainAttributeSetJobTypeMemoryCheck);
REG_FUNC(cellSpurs, cellSpursGetJobChainId);
REG_FUNC(cellSpurs, cellSpursJobChainSetExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursJobChainUnsetExceptionEventHandler);
REG_FUNC(cellSpurs, cellSpursGetJobChainInfo);
REG_FUNC(cellSpurs, cellSpursJobChainGetSpursAddress);
2014-06-02 05:09:42 +02:00
// Job Guard
REG_FUNC(cellSpurs, cellSpursJobGuardInitialize);
REG_FUNC(cellSpurs, cellSpursJobGuardNotify);
REG_FUNC(cellSpurs, cellSpursJobGuardReset);
// LFQueue
REG_FUNC(cellSpurs, _cellSpursLFQueueInitialize);
REG_FUNC(cellSpurs, _cellSpursLFQueuePushBody);
REG_FUNC(cellSpurs, cellSpursLFQueueAttachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursLFQueueDetachLv2EventQueue);
REG_FUNC(cellSpurs, _cellSpursLFQueuePopBody);
REG_FUNC(cellSpurs, cellSpursLFQueueGetTasksetAddress);
// Queue
REG_FUNC(cellSpurs, _cellSpursQueueInitialize);
REG_FUNC(cellSpurs, cellSpursQueuePopBody);
REG_FUNC(cellSpurs, cellSpursQueuePushBody);
REG_FUNC(cellSpurs, cellSpursQueueAttachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursQueueDetachLv2EventQueue);
REG_FUNC(cellSpurs, cellSpursQueueGetTasksetAddress);
REG_FUNC(cellSpurs, cellSpursQueueClear);
REG_FUNC(cellSpurs, cellSpursQueueDepth);
REG_FUNC(cellSpurs, cellSpursQueueGetEntrySize);
REG_FUNC(cellSpurs, cellSpursQueueSize);
REG_FUNC(cellSpurs, cellSpursQueueGetDirection);
// Workload
REG_FUNC(cellSpurs, cellSpursWorkloadAttributeSetName);
REG_FUNC(cellSpurs, cellSpursWorkloadAttributeSetShutdownCompletionEventHook);
REG_FUNC(cellSpurs, cellSpursAddWorkloadWithAttribute);
REG_FUNC(cellSpurs, cellSpursAddWorkload);
REG_FUNC(cellSpurs, cellSpursShutdownWorkload);
REG_FUNC(cellSpurs, cellSpursWaitForWorkloadShutdown);
REG_FUNC(cellSpurs, cellSpursRemoveWorkload);
REG_FUNC(cellSpurs, cellSpursReadyCountStore);
REG_FUNC(cellSpurs, cellSpursGetWorkloadFlag);
REG_FUNC(cellSpurs, _cellSpursWorkloadFlagReceiver);
REG_FUNC(cellSpurs, _cellSpursWorkloadAttributeInitialize);
REG_FUNC(cellSpurs, cellSpursSendWorkloadSignal);
REG_FUNC(cellSpurs, cellSpursGetWorkloadData);
REG_FUNC(cellSpurs, cellSpursReadyCountAdd);
REG_FUNC(cellSpurs, cellSpursReadyCountCompareAndSwap);
REG_FUNC(cellSpurs, cellSpursReadyCountSwap);
REG_FUNC(cellSpurs, cellSpursRequestIdleSpu);
REG_FUNC(cellSpurs, cellSpursGetWorkloadInfo);
REG_FUNC(cellSpurs, cellSpursGetSpuGuid);
REG_FUNC(cellSpurs, _cellSpursWorkloadFlagReceiver2);
REG_FUNC(cellSpurs, cellSpursGetJobPipelineInfo);
REG_FUNC(cellSpurs, cellSpursJobSetMaxGrab);
REG_FUNC(cellSpurs, cellSpursJobHeaderSetJobbin2Param);
REG_FUNC(cellSpurs, cellSpursWakeUp);
REG_FUNC(cellSpurs, cellSpursAddUrgentCommand);
REG_FUNC(cellSpurs, cellSpursAddUrgentCall);
REG_FUNC(cellSpurs, cellSpursBarrierInitialize);
REG_FUNC(cellSpurs, cellSpursBarrierGetTasksetAddress);
REG_FUNC(cellSpurs, _cellSpursSemaphoreInitialize);
REG_FUNC(cellSpurs, cellSpursSemaphoreGetTasksetAddress);
// Trace
REG_FUNC(cellSpurs, cellSpursTraceInitialize);
REG_FUNC(cellSpurs, cellSpursTraceStart);
REG_FUNC(cellSpurs, cellSpursTraceStop);
REG_FUNC(cellSpurs, cellSpursTraceFinalize);
});