rpcsx/rpcsx-os/iodev/mbus.cpp
DH 65e653f5ef [rpcsx-os/orbis-kernel] random bugfixes
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
2024-01-13 20:57:02 +03:00

69 lines
1.7 KiB
C++

#include "io-device.hpp"
#include "orbis/KernelAllocator.hpp"
#include "orbis/file.hpp"
#include "orbis/uio.hpp"
#include "orbis/utils/Logs.hpp"
#include "mbus.hpp"
struct MBusFile : orbis::File {};
static orbis::ErrorCode mbus_ioctl(orbis::File *file, std::uint64_t request,
void *argp, orbis::Thread *thread) {
ORBIS_LOG_FATAL("Unhandled mbus ioctl", request);
return {};
}
static orbis::ErrorCode mbus_read(orbis::File *file, orbis::Uio *uio,
orbis::Thread *thread) {
auto mbus = file->device.staticCast<MBusDevice>();
ORBIS_LOG_ERROR(__FUNCTION__);
MBusEvent event;
{
std::lock_guard lock(mbus->mtx);
// while (mbus->events.empty()) {
// file->mtx.unlock();
// mbus->cv.wait(mbusAv->mtx);
// file->mtx.lock();
// }
if (mbus->events.empty()) {
return orbis::ErrorCode::BUSY;
}
event = mbus->events.front();
mbus->events.pop_front();
}
return uio->write(event);
}
static const orbis::FileOps fileOps = {
.ioctl = mbus_ioctl,
.read = mbus_read,
};
void MBusDevice::emitEvent(const MBusEvent &event) {
std::lock_guard lock(mtx);
events.push_back(event);
cv.notify_one(mtx);
eventEmitter->emit(orbis::kEvFiltRead);
}
orbis::ErrorCode MBusDevice::open(orbis::Ref<orbis::File> *file, const char *path,
std::uint32_t flags, std::uint32_t mode,
orbis::Thread *thread) {
ORBIS_LOG_FATAL("mbus device open");
auto newFile = orbis::knew<MBusFile>();
newFile->ops = &fileOps;
newFile->device = this;
newFile->event = eventEmitter;
*file = newFile;
return {};
}
IoDevice *createMBusCharacterDevice() { return orbis::knew<MBusDevice>(); }