Skip to content

Commit

Permalink
ipmi: implement fake client API
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Sep 26, 2024
1 parent 7eaf118 commit 9878e91
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 23 deletions.
25 changes: 23 additions & 2 deletions orbis-kernel/include/orbis/ipmi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,21 @@ struct IpmiDataInfo {
uint64_t size;
};

// static_assert(sizeof(IpmiBufferInfo) == 0x18);
// static_assert(sizeof(IpmiDataInfo) == 0x10);
static_assert(sizeof(IpmiBufferInfo) == 0x18);
static_assert(sizeof(IpmiDataInfo) == 0x10);

struct IpmiSyncCallParams {
uint32_t method;
uint32_t numInData;
uint32_t numOutData;
uint32_t unk;
ptr<IpmiDataInfo> pInData;
ptr<IpmiBufferInfo> pOutData;
ptr<sint> pResult;
uint32_t flags;
};

static_assert(sizeof(IpmiSyncCallParams) == 0x30);

struct [[gnu::packed]] IpmiSyncMessageHeader {
orbis::ptr<void> sessionImpl;
Expand All @@ -153,6 +166,14 @@ struct [[gnu::packed]] IpmiAsyncMessageHeader {

static_assert(sizeof(IpmiSyncMessageHeader) == 0x18);

struct IpmiCreateClientParams {
ptr<void> clientImpl;
ptr<const char> name;
ptr<IpmiCreateClientConfig> config;
};

static_assert(sizeof(IpmiCreateClientParams) == 0x18);

ErrorCode ipmiCreateClient(Process *proc, void *clientImpl, const char *name,
const IpmiCreateClientConfig &config,
Ref<IpmiClient> &result);
Expand Down
22 changes: 1 addition & 21 deletions orbis-kernel/src/ipmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ orbis::ErrorCode orbis::ipmiCreateSession(Thread *thread, void *sessionImpl,
orbis::SysResult orbis::sysIpmiCreateClient(Thread *thread, ptr<uint> result,
ptr<void> params,
uint64_t paramsSz) {
struct IpmiCreateClientParams {
ptr<void> clientImpl;
ptr<const char> name;
ptr<IpmiCreateClientConfig> config;
};

static_assert(sizeof(IpmiCreateClientParams) == 0x18);

if (paramsSz != sizeof(IpmiCreateClientParams)) {
return ErrorCode::INVAL;
}
Expand Down Expand Up @@ -887,22 +879,10 @@ orbis::SysResult orbis::sysIpmiSessionGetClientPid(Thread *thread,
uwrite<uint32_t>(_params.pid, session->client->process->pid));
return uwrite<uint>(result, 0);
}

orbis::SysResult
orbis::sysIpmiClientInvokeSyncMethod(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz) {
struct IpmiSyncCallParams {
uint32_t method;
uint32_t numInData;
uint32_t numOutData;
uint32_t unk;
ptr<IpmiDataInfo> pInData;
ptr<IpmiBufferInfo> pOutData;
ptr<sint> pResult;
uint32_t flags;
};

static_assert(sizeof(IpmiSyncCallParams) == 0x30);

if (paramsSz != sizeof(IpmiSyncCallParams)) {
return ErrorCode::INVAL;
}
Expand Down
88 changes: 88 additions & 0 deletions rpcsx-os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,94 @@ static void createShellCoreObjects(orbis::Process *process) {
createSemaphore("SceNpTpip 0", 0x101, 0, 1);
}

static orbis::Process *createGuestProcess() {
auto pid = orbis::g_context.allocatePid() * 10000 + 1;
return orbis::g_context.createProcess(pid);
}

static orbis::Thread *createGuestThread() {
auto process = createGuestProcess();
auto [baseId, thread] = process->threadsMap.emplace();
thread->tproc = process;
thread->tid = process->pid + baseId;
thread->state = orbis::ThreadState::RUNNING;
return thread;
}

struct IpmiClient {
orbis::Ref<orbis::IpmiClient> clientImpl;
orbis::uint kid;
orbis::Thread *thread;

orbis::sint sendSyncMessage(std::uint32_t method, const void *data,
std::size_t size,
std::vector<std::byte> &outData) {
orbis::sint serverResult;
orbis::IpmiBufferInfo outBufferInfo = {
.data = outData.data(),
.capacity = outData.size(),
};

orbis::IpmiDataInfo inDataInfo = {
.data = orbis::ptr<void>(data),
.size = size,
};

orbis::IpmiSyncCallParams params{
.method = method,
.numInData = 1,
.numOutData = 1,
.pInData = &inDataInfo,
.pOutData = &outBufferInfo,
.pResult = &serverResult,
};

orbis::uint errorCode;
orbis::sysIpmiClientInvokeSyncMethod(thread, &errorCode, kid, &params,
sizeof(params));

outData.resize(outBufferInfo.size);
return serverResult;
}

template <typename T>
orbis::sint sendSyncMessage(std::uint32_t method, const T &data,
std::vector<std::byte> &outData) {
return sendSyncMessage(method, &data, sizeof(data), outData);
}

template <typename T>
orbis::sint sendSyncMessage(std::uint32_t method, const T &data) {
std::vector<std::byte> outData;
return sendSyncMessage(method, &data, sizeof(data), outData);
}

template <typename T>
std::vector<std::byte> sendSyncMessage(std::uint32_t method, const T &data,
std::size_t outputCapacity) {
std::vector<std::byte> outData;
outData.resize(outputCapacity);
sendSyncMessage(method, &data, sizeof(data), outData);
return outData;
}
};

static IpmiClient createIpmiClient(orbis::Thread *thread, const char *name) {
orbis::Ref<orbis::IpmiClient> client;
orbis::IpmiCreateClientConfig config{
.size = sizeof(orbis::IpmiCreateClientConfig),
};

orbis::IpmiCreateClientParams params{
.name = name,
.config = &config,
};

orbis::uint kid;
orbis::sysIpmiCreateClient(thread, &kid, &params, sizeof(params));
return {std::move(client), kid, thread};
}

static orbis::SysResult launchDaemon(orbis::Thread *thread, std::string path,
std::vector<std::string> argv,
std::vector<std::string> envv) {
Expand Down

0 comments on commit 9878e91

Please sign in to comment.