Get rid of the type field on zmessage
This commit is contained in:
parent
7bd6aa42b0
commit
685070d65e
|
@ -35,8 +35,7 @@ z_err_t Channel::WriteStr(const char* msg) {
|
||||||
if (!chan_cap_) {
|
if (!chan_cap_) {
|
||||||
return Z_ERR_NULL;
|
return Z_ERR_NULL;
|
||||||
}
|
}
|
||||||
uint64_t type = 0;
|
return ZChannelSend(chan_cap_, strlen(msg),
|
||||||
return ZChannelSend(chan_cap_, type, strlen(msg),
|
|
||||||
reinterpret_cast<const uint8_t*>(msg), 0, 0);
|
reinterpret_cast<const uint8_t*>(msg), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +43,9 @@ z_err_t Channel::ReadStr(char* buffer, uint64_t* size) {
|
||||||
if (!chan_cap_) {
|
if (!chan_cap_) {
|
||||||
return Z_ERR_NULL;
|
return Z_ERR_NULL;
|
||||||
}
|
}
|
||||||
uint64_t type;
|
|
||||||
uint64_t num_caps;
|
uint64_t num_caps;
|
||||||
return ZChannelRecv(chan_cap_, *size, reinterpret_cast<uint8_t*>(buffer), 0,
|
return ZChannelRecv(chan_cap_, *size, reinterpret_cast<uint8_t*>(buffer), 0,
|
||||||
0, &type, size, &num_caps);
|
0, size, &num_caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t CreateChannels(Channel& c1, Channel& c2) {
|
z_err_t CreateChannels(Channel& c1, Channel& c2) {
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
Port::Port(uint64_t port_cap) : port_cap_(port_cap) {}
|
Port::Port(uint64_t port_cap) : port_cap_(port_cap) {}
|
||||||
|
|
||||||
z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
|
z_err_t Port::PollForIntCap(uint64_t *msg, uint64_t *cap) {
|
||||||
uint64_t bytes, caps, type;
|
uint64_t bytes, caps;
|
||||||
RET_ERR(ZPortPoll(port_cap_, sizeof(uint64_t),
|
RET_ERR(ZPortPoll(port_cap_, sizeof(uint64_t),
|
||||||
reinterpret_cast<uint8_t *>(msg), /* num_caps= */ 1, cap,
|
reinterpret_cast<uint8_t *>(msg), /* num_caps= */ 1, cap,
|
||||||
&type, &bytes, &caps));
|
&bytes, &caps));
|
||||||
|
|
||||||
if (bytes != sizeof(uint64_t)) {
|
if (bytes != sizeof(uint64_t)) {
|
||||||
return Z_ERR_INVALID;
|
return Z_ERR_INVALID;
|
||||||
|
|
|
@ -140,8 +140,8 @@ void AhciDriver::DumpPorts() {
|
||||||
void AhciDriver::InterruptLoop() {
|
void AhciDriver::InterruptLoop() {
|
||||||
dbgln("Starting interrupt loop");
|
dbgln("Starting interrupt loop");
|
||||||
while (true) {
|
while (true) {
|
||||||
uint64_t type, bytes, caps;
|
uint64_t bytes, caps;
|
||||||
check(ZPortRecv(irq_port_cap_, 0, 0, 0, 0, &type, &bytes, &caps));
|
check(ZPortRecv(irq_port_cap_, 0, 0, 0, 0, &bytes, &caps));
|
||||||
for (uint64_t i = 0; i < 32; i++) {
|
for (uint64_t i = 0; i < 32; i++) {
|
||||||
if (devices_[i] != nullptr && devices_[i]->IsInit() &&
|
if (devices_[i] != nullptr && devices_[i]->IsInit() &&
|
||||||
(ahci_hba_->interrupt_status & (1 << i))) {
|
(ahci_hba_->interrupt_status & (1 << i))) {
|
||||||
|
|
|
@ -19,9 +19,13 @@ z_err_t DenaliServer::RunServer() {
|
||||||
while (true) {
|
while (true) {
|
||||||
uint64_t buff_size = kBuffSize;
|
uint64_t buff_size = kBuffSize;
|
||||||
uint64_t cap_size = 0;
|
uint64_t cap_size = 0;
|
||||||
uint64_t type = DENALI_INVALID;
|
|
||||||
RET_ERR(ZChannelRecv(channel_cap_, buff_size, read_buffer_, 0, nullptr,
|
RET_ERR(ZChannelRecv(channel_cap_, buff_size, read_buffer_, 0, nullptr,
|
||||||
&type, &buff_size, &cap_size));
|
&buff_size, &cap_size));
|
||||||
|
if (buff_size < sizeof(uint64_t)) {
|
||||||
|
dbgln("Skipping invalid message");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
uint64_t type = *reinterpret_cast<uint64_t*>(read_buffer_);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Z_INVALID:
|
case Z_INVALID:
|
||||||
dbgln(reinterpret_cast<char*>(read_buffer_));
|
dbgln(reinterpret_cast<char*>(read_buffer_));
|
||||||
|
@ -55,6 +59,6 @@ void DenaliServer::HandleResponse(uint64_t lba, uint64_t size, uint64_t cap) {
|
||||||
.lba = lba,
|
.lba = lba,
|
||||||
.size = size,
|
.size = size,
|
||||||
};
|
};
|
||||||
check(ZChannelSend(channel_cap_, DENALI_READ, sizeof(resp),
|
check(ZChannelSend(channel_cap_, sizeof(resp),
|
||||||
reinterpret_cast<uint8_t*>(&resp), 1, &cap));
|
reinterpret_cast<uint8_t*>(&resp), 1, &cap));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define DENALI_READ 100
|
#define DENALI_READ 100
|
||||||
|
|
||||||
struct DenaliRead {
|
struct DenaliRead {
|
||||||
|
uint64_t request_type = DENALI_READ;
|
||||||
uint64_t device_id;
|
uint64_t device_id;
|
||||||
|
|
||||||
uint64_t lba;
|
uint64_t lba;
|
||||||
|
|
|
@ -22,17 +22,15 @@ uint64_t main(uint64_t port_cap) {
|
||||||
.lba = 0,
|
.lba = 0,
|
||||||
.size = 1,
|
.size = 1,
|
||||||
};
|
};
|
||||||
check(ZChannelSend(local.cap(), DENALI_READ, sizeof(DenaliRead),
|
check(ZChannelSend(local.cap(), sizeof(DenaliRead),
|
||||||
reinterpret_cast<uint8_t*>(&read), 0, nullptr));
|
reinterpret_cast<uint8_t*>(&read), 0, nullptr));
|
||||||
|
|
||||||
DenaliReadResponse resp;
|
DenaliReadResponse resp;
|
||||||
uint64_t mem_cap, type, bytes, caps;
|
uint64_t mem_cap, bytes, caps;
|
||||||
|
|
||||||
check(ZChannelRecv(local.cap(), sizeof(resp),
|
check(ZChannelRecv(local.cap(), sizeof(resp),
|
||||||
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &type,
|
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &bytes,
|
||||||
&bytes, &caps));
|
&caps));
|
||||||
|
|
||||||
dbgln("Resp: %u", type);
|
|
||||||
|
|
||||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr));
|
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr));
|
||||||
uint32_t* mbr = reinterpret_cast<uint32_t*>(vaddr + 0x1FE);
|
uint32_t* mbr = reinterpret_cast<uint32_t*>(vaddr + 0x1FE);
|
||||||
|
|
|
@ -36,13 +36,12 @@ void ZThreadExit();
|
||||||
uint64_t* vmmo_size);
|
uint64_t* vmmo_size);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2);
|
[[nodiscard]] z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2);
|
||||||
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type,
|
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes,
|
||||||
uint64_t num_bytes, const uint8_t* bytes,
|
const uint8_t* bytes, uint64_t num_caps,
|
||||||
uint64_t num_caps, const z_cap_t* caps);
|
const z_cap_t* caps);
|
||||||
[[nodiscard]] z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
uint8_t* bytes, uint64_t num_caps,
|
||||||
z_cap_t* caps, uint64_t* type,
|
z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes,
|
|
||||||
uint64_t* actual_caps);
|
uint64_t* actual_caps);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZPortCreate(z_cap_t* port_cap);
|
[[nodiscard]] z_err_t ZPortCreate(z_cap_t* port_cap);
|
||||||
|
@ -51,12 +50,12 @@ void ZThreadExit();
|
||||||
z_cap_t* caps);
|
z_cap_t* caps);
|
||||||
[[nodiscard]] z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
uint8_t* bytes, uint64_t num_caps,
|
||||||
z_cap_t* caps, uint64_t* type,
|
z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps);
|
uint64_t* actual_caps);
|
||||||
[[nodiscard]] z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
uint8_t* bytes, uint64_t num_caps,
|
||||||
z_cap_t* caps, uint64_t* type,
|
z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps);
|
uint64_t* actual_caps);
|
||||||
[[nodiscard]] z_err_t ZIrqRegister(uint64_t irq_num, z_cap_t* port_cap);
|
[[nodiscard]] z_err_t ZIrqRegister(uint64_t irq_num, z_cap_t* port_cap);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZCapDuplicate(z_cap_t cap_in, z_cap_t* cap_out);
|
[[nodiscard]] z_err_t ZCapDuplicate(z_cap_t cap_in, z_cap_t* cap_out);
|
||||||
|
|
|
@ -34,7 +34,6 @@ z_err_t Channel::Read(ZMessage& msg) {
|
||||||
return Z_ERR_BUFF_SIZE;
|
return Z_ERR_BUFF_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.type = next_msg->type;
|
|
||||||
msg.num_bytes = next_msg->num_bytes;
|
msg.num_bytes = next_msg->num_bytes;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
|
@ -59,7 +58,6 @@ z_err_t Channel::EnqueueMessage(const ZMessage& msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto message = MakeShared<Message>();
|
auto message = MakeShared<Message>();
|
||||||
message->type = msg.type;
|
|
||||||
|
|
||||||
// Copy Message body.
|
// Copy Message body.
|
||||||
message->num_bytes = msg.num_bytes;
|
message->num_bytes = msg.num_bytes;
|
||||||
|
|
|
@ -35,8 +35,6 @@ class Channel : public KernelObject {
|
||||||
Mutex mutex_{"channel"};
|
Mutex mutex_{"channel"};
|
||||||
|
|
||||||
struct Message {
|
struct Message {
|
||||||
uint64_t type;
|
|
||||||
|
|
||||||
uint64_t num_bytes;
|
uint64_t num_bytes;
|
||||||
uint8_t* bytes;
|
uint8_t* bytes;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ z_err_t Port::Write(const ZMessage& msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto message = MakeShared<Message>();
|
auto message = MakeShared<Message>();
|
||||||
message->type = msg.type, message->num_bytes = msg.num_bytes;
|
message->num_bytes = msg.num_bytes;
|
||||||
message->bytes = new uint8_t[msg.num_bytes];
|
message->bytes = new uint8_t[msg.num_bytes];
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
message->bytes[i] = msg.bytes[i];
|
message->bytes[i] = msg.bytes[i];
|
||||||
|
@ -54,7 +54,6 @@ z_err_t Port::Read(ZMessage& msg) {
|
||||||
return Z_ERR_BUFF_SIZE;
|
return Z_ERR_BUFF_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.type = next_msg->type;
|
|
||||||
msg.num_bytes = next_msg->num_bytes;
|
msg.num_bytes = next_msg->num_bytes;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
|
@ -76,7 +75,6 @@ void Port::WriteKernel(uint64_t init, RefPtr<Capability> cap) {
|
||||||
MutexHolder h(mutex_);
|
MutexHolder h(mutex_);
|
||||||
|
|
||||||
auto msg = MakeShared<Message>();
|
auto msg = MakeShared<Message>();
|
||||||
msg->type = 0;
|
|
||||||
msg->bytes = new uint8_t[8];
|
msg->bytes = new uint8_t[8];
|
||||||
msg->num_bytes = sizeof(init);
|
msg->num_bytes = sizeof(init);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ class Port : public KernelObject {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Message {
|
struct Message {
|
||||||
uint64_t type;
|
|
||||||
uint64_t num_bytes;
|
uint64_t num_bytes;
|
||||||
uint8_t* bytes;
|
uint8_t* bytes;
|
||||||
|
|
||||||
|
|
|
@ -125,14 +125,12 @@ z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type, uint64_t num_bytes,
|
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes, const uint8_t* bytes,
|
||||||
const uint8_t* bytes, uint64_t num_caps,
|
uint64_t num_caps, const z_cap_t* caps) {
|
||||||
const z_cap_t* caps) {
|
|
||||||
ZChannelSendReq req{
|
ZChannelSendReq req{
|
||||||
.chan_cap = chan_cap,
|
.chan_cap = chan_cap,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.type = type,
|
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = const_cast<uint8_t*>(bytes),
|
.bytes = const_cast<uint8_t*>(bytes),
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
|
@ -143,13 +141,12 @@ z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t type, uint64_t num_bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZChannelRecvReq req{
|
ZChannelRecvReq req{
|
||||||
.chan_cap = chan_cap,
|
.chan_cap = chan_cap,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.type = 0,
|
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.bytes = bytes,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
|
@ -157,7 +154,6 @@ z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
z_err_t ret = SysCall1(Z_CHANNEL_RECV, &req);
|
z_err_t ret = SysCall1(Z_CHANNEL_RECV, &req);
|
||||||
*type = req.message.type;
|
|
||||||
*actual_bytes = req.message.num_bytes;
|
*actual_bytes = req.message.num_bytes;
|
||||||
*actual_caps = req.message.num_caps;
|
*actual_caps = req.message.num_caps;
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -174,7 +170,6 @@ z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const uint8_t* bytes,
|
||||||
uint64_t num_caps, z_cap_t* caps) {
|
uint64_t num_caps, z_cap_t* caps) {
|
||||||
ZPortSendReq req{.port_cap = port_cap,
|
ZPortSendReq req{.port_cap = port_cap,
|
||||||
.message = {
|
.message = {
|
||||||
.type = 0,
|
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = const_cast<uint8_t*>(bytes),
|
.bytes = const_cast<uint8_t*>(bytes),
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
|
@ -184,13 +179,12 @@ z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const uint8_t* bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZPortRecvReq req{
|
ZPortRecvReq req{
|
||||||
.port_cap = port_cap,
|
.port_cap = port_cap,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.type = 0,
|
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.bytes = bytes,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
|
@ -198,20 +192,18 @@ z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
z_err_t ret = SysCall1(Z_PORT_RECV, &req);
|
z_err_t ret = SysCall1(Z_PORT_RECV, &req);
|
||||||
*type = req.message.type;
|
|
||||||
*actual_bytes = req.message.num_bytes;
|
*actual_bytes = req.message.num_bytes;
|
||||||
*actual_caps = req.message.num_caps;
|
*actual_caps = req.message.num_caps;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* type,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_bytes, uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZPortRecvReq req{
|
ZPortRecvReq req{
|
||||||
.port_cap = port_cap,
|
.port_cap = port_cap,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.type = 0,
|
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.bytes = bytes,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
|
@ -219,7 +211,6 @@ z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
z_err_t ret = SysCall1(Z_PORT_POLL, &req);
|
z_err_t ret = SysCall1(Z_PORT_POLL, &req);
|
||||||
*type = req.message.type;
|
|
||||||
*actual_bytes = req.message.num_bytes;
|
*actual_bytes = req.message.num_bytes;
|
||||||
*actual_caps = req.message.num_caps;
|
*actual_caps = req.message.num_caps;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -69,8 +69,6 @@ struct ZChannelCreateResp {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ZMessage {
|
struct ZMessage {
|
||||||
uint64_t type;
|
|
||||||
|
|
||||||
uint64_t num_bytes;
|
uint64_t num_bytes;
|
||||||
uint8_t* bytes;
|
uint8_t* bytes;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue