Skip to content

Commit

Permalink
[rpcsx-os/orbis-kernel] random bugfixes
Browse files Browse the repository at this point in the history
ipmi: fixed respond sync, get message, try get message, try send message
event: detach event emitter from file
signals: basic implementation
linker: fixed zero symbol relocation, fixed exec relocation
shared_cv/mutex: implement eintr response support
shared_cv: fixed possible loop instead of wait
ipmi: implement invoke async, respond async, get result, get client app id, client get name
rpcsx-os: add safemode flag
  • Loading branch information
DHrpcs3 committed Jan 13, 2024
1 parent 8791312 commit 65e653f
Show file tree
Hide file tree
Showing 81 changed files with 2,582 additions and 757 deletions.
12 changes: 6 additions & 6 deletions hw/amdgpu/bridge/include/amdgpu/bridge/bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,23 @@ struct BridgePusher {
}

void sendMapDmem(std::uint32_t pid, std::uint32_t dmemIndex, std::uint64_t address, std::uint64_t size, std::uint32_t prot, std::uint64_t offset) {
if (pid == expGpuPid) {
// if (pid == expGpuPid) {
sendCommand(CommandId::MapDmem, {pid, dmemIndex, address, size, prot, offset});
}
// }
}

void sendCommandBuffer(std::uint32_t pid, std::uint64_t queue,
std::uint64_t address, std::uint64_t size) {
if (pid == expGpuPid) {
// if (pid == expGpuPid) {
sendCommand(CommandId::CommandBuffer, {pid, queue, address, size});
}
// }
}

void sendFlip(std::uint32_t pid, std::uint32_t bufferIndex,
std::uint64_t arg) {
if (pid == expGpuPid) {
// if (pid == expGpuPid) {
sendCommand(CommandId::Flip, {pid, bufferIndex, arg});
}
// }
}

void wait() {
Expand Down
13 changes: 8 additions & 5 deletions orbis-kernel/include/orbis/KernelContext.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#pragma once
#include "AudioOut.hpp"
#include "KernelAllocator.hpp"
#include "evf.hpp"
#include "ipmi.hpp"
#include "orbis/utils/IdMap.hpp"
#include "osem.hpp"
#include "thread/types.hpp"
#include "utils/IdMap.hpp"
#include "utils/LinkedNode.hpp"
#include "utils/SharedCV.hpp"
#include "utils/SharedMutex.hpp"

#include "AudioOut.hpp"
#include "KernelAllocator.hpp"
#include "orbis/thread/types.hpp"
#include <algorithm>
#include <cstdint>
#include <mutex>
#include <pthread.h>
Expand Down Expand Up @@ -175,6 +174,10 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final {
AudioOut *audioOut = nullptr;
uint sdkVersion{};
uint fwSdkVersion{};
uint safeMode{};

shared_mutex regMgrMtx;
kmap<std::uint32_t, std::uint32_t> regMgrInt;

private:
mutable pthread_mutex_t m_heap_mtx;
Expand Down
10 changes: 7 additions & 3 deletions orbis-kernel/include/orbis/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct FileOps {
Thread *thread) = nullptr;
ErrorCode (*sendmsg)(orbis::File *file, msghdr *msg, sint flags,
Thread *thread) = nullptr;
ErrorCode (*recvfrom)(orbis::File *file, void *buf, size_t len,
sint flags, SocketAddress *from, uint32_t *fromlenaddr,
ErrorCode (*recvfrom)(orbis::File *file, void *buf, size_t len, sint flags,
SocketAddress *from, uint32_t *fromlenaddr,
Thread *thread) = nullptr;
ErrorCode (*recvmsg)(orbis::File *file, msghdr *msg, sint flags,
Thread *thread) = nullptr;
Expand All @@ -75,11 +75,15 @@ struct FileOps {

struct File : RcBase {
shared_mutex mtx;
EventEmitter event;
Ref<EventEmitter> event;
const FileOps *ops = nullptr;
Ref<RcBase> device;
std::uint64_t nextOff = 0;
int flags = 0;
int mode = 0;
int hostFd = -1;
utils::kvector<Dirent> dirEntries;

bool noBlock() const { return (flags & 4) != 0; }
};
} // namespace orbis
62 changes: 45 additions & 17 deletions orbis-kernel/include/orbis/ipmi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Thread;

struct IpmiServer : RcBase {
struct IpmiPacketInfo {
ptr<void> userData;
ulong inputSize;
uint type;
uint clientKid;
ptr<void> eventHandler;
Expand All @@ -26,6 +26,8 @@ struct IpmiServer : RcBase {

struct Packet {
IpmiPacketInfo info;
lwpid_t clientTid;
Ref<IpmiSession> session;
kvector<std::byte> message;
};

Expand All @@ -36,6 +38,7 @@ struct IpmiServer : RcBase {
slong serverTid{};
};

kmap<std::uint32_t, std::uint32_t> tidToClientTid;
kstring name;
ptr<void> serverImpl;
ptr<void> eventHandler;
Expand All @@ -51,24 +54,36 @@ struct IpmiServer : RcBase {
};

struct IpmiClient : RcBase {
struct MessageQueue {
shared_cv messageCv;
kdeque<kvector<std::byte>> messages;
};

struct AsyncResponse {
uint methodId;
sint errorCode;
kvector<kvector<std::byte>> data;
};

kstring name;
ptr<void> clientImpl;
ptr<void> userData;
Ref<IpmiSession> session;
shared_mutex mutex;
shared_cv sessionCv;
sint pid;
kdeque<kvector<std::byte>> messages;
Process *process;
kdeque<MessageQueue> messageQueues;
kdeque<EventFlag> eventFlags;
shared_cv messageCv;
kdeque<AsyncResponse> asyncResponses;

explicit IpmiClient(kstring name) : name(std::move(name)) {}
};

struct IpmiSession : RcBase {
struct MessageResponse {
struct SyncResponse {
sint errorCode;
kvector<std::byte> data;
std::uint32_t callerTid;
kvector<kvector<std::byte>> data;
};

ptr<void> sessionImpl;
Expand All @@ -77,9 +92,9 @@ struct IpmiSession : RcBase {
Ref<IpmiServer> server;
shared_mutex mutex;
shared_cv responseCv;
kdeque<MessageResponse> messageResponses;
kdeque<SyncResponse> syncResponses;
shared_cv connectCv;
bool expectedOutput = false; // TODO: verify
uint expectedOutput{0};
sint connectionStatus{0};
};

Expand Down Expand Up @@ -108,31 +123,38 @@ static_assert(sizeof(IpmiCreateClientConfig) == 0x150);

struct IpmiBufferInfo {
ptr<void> data;
uint64_t capacity;
uint64_t size;
};


struct IpmiDataInfo {
ptr<void> data;
uint64_t size;
uint64_t capacity; //?
};

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

struct IpmiSyncMessageHeader {
struct [[gnu::packed]] IpmiSyncMessageHeader {
orbis::ptr<void> sessionImpl;
orbis::uint pid;
orbis::uint methodId;
orbis::uint numInData;
orbis::uint numOutData;
};

struct [[gnu::packed]] IpmiAsyncMessageHeader {
orbis::ptr<void> sessionImpl;
orbis::uint methodId;
orbis::uint pid;
orbis::uint numInData;
};

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

ErrorCode ipmiCreateClient(Process *proc, void *clientImpl, const char *name,
const IpmiCreateClientConfig &config, Ref<IpmiClient> &result);
const IpmiCreateClientConfig &config,
Ref<IpmiClient> &result);
ErrorCode ipmiCreateServer(Process *proc, void *serverImpl, const char *name,
const IpmiCreateServerConfig &config,
Ref<IpmiServer> &result);
Expand Down Expand Up @@ -162,9 +184,10 @@ SysResult sysIpmiSessionRespondSync(Thread *thread, ptr<uint> result, uint kid,
SysResult sysIpmiClientInvokeAsyncMethod(Thread *thread, ptr<uint> result,
uint kid, ptr<void> params,
uint64_t paramsSz);
SysResult sysIpmiClientTryGetResult(Thread *thread, ptr<uint> result,
uint kid, ptr<void> params,
uint64_t paramsSz);
SysResult sysImpiSessionRespondAsync(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientTryGetResult(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientGetMessage(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientTryGetMessage(Thread *thread, ptr<uint> result, uint kid,
Expand All @@ -181,10 +204,15 @@ SysResult sysIpmiClientInvokeSyncMethod(Thread *thread, ptr<uint> result,
uint64_t paramsSz);
SysResult sysIpmiClientConnect(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiSessionGetClientAppId(Thread *thread, ptr<uint> result,
uint kid, ptr<void> params,
uint64_t paramsSz);
SysResult sysIpmiSessionGetUserData(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiServerGetName(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientGetName(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientWaitEventFlag(Thread *thread, ptr<uint> result, uint kid,
ptr<void> params, uint64_t paramsSz);
SysResult sysIpmiClientPollEventFlag(Thread *thread, ptr<uint> result, uint kid,
Expand Down
2 changes: 1 addition & 1 deletion orbis-kernel/include/orbis/note.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct KNote {
~KNote();
};

struct EventEmitter {
struct EventEmitter : orbis::RcBase {
shared_mutex mutex;
std::set<KNote *, std::less<>, kallocator<KNote *>> notes;

Expand Down
Loading

0 comments on commit 65e653f

Please sign in to comment.