diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 38c527b..39e33fa 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -32,3 +32,19 @@ uint32_t await(uint32_t service, uint32_t event) { return syscall(SYS_AWAIT, service, event, 0, 0); } + +uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { + return syscall(SYS_GET_EVENT, serviceId, id, 0, 0); +} + +uint32_t createDirectEvent(uint32_t id) { + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uint32_t createDirectEventSave(uint32_t id) { + uint32_t existingEvent = getDirectEvent(getServiceId(), id); + if (existingEvent) { + return existingEvent; + } + return createDirectEvent(id); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 38c527b..39e33fa 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -32,3 +32,19 @@ uint32_t await(uint32_t service, uint32_t event) { return syscall(SYS_AWAIT, service, event, 0, 0); } + +uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { + return syscall(SYS_GET_EVENT, serviceId, id, 0, 0); +} + +uint32_t createDirectEvent(uint32_t id) { + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uint32_t createDirectEventSave(uint32_t id) { + uint32_t existingEvent = getDirectEvent(getServiceId(), id); + if (existingEvent) { + return existingEvent; + } + return createDirectEvent(id); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index cb58a2f..0285a06 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include "../hlib/include/syscalls.h" #include uint32_t serviceId; diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 38c527b..39e33fa 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -32,3 +32,19 @@ uint32_t await(uint32_t service, uint32_t event) { return syscall(SYS_AWAIT, service, event, 0, 0); } + +uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { + return syscall(SYS_GET_EVENT, serviceId, id, 0, 0); +} + +uint32_t createDirectEvent(uint32_t id) { + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uint32_t createDirectEventSave(uint32_t id) { + uint32_t existingEvent = getDirectEvent(getServiceId(), id); + if (existingEvent) { + return existingEvent; + } + return createDirectEvent(id); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index cb58a2f..0285a06 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include "../hlib/include/syscalls.h" #include uint32_t serviceId; diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index f0a99b5..ae50fc1 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -1,5 +1,4 @@ #include "commands.h" -#include "../../hlib/include/syscalls.h" #include "trbRing.h" #include "xhci.h" #include @@ -14,8 +13,8 @@ trb.status = status; trb.control = control; uint32_t commandAddress = U32(enqueueCommand(&controller->commands, &trb)); + uint32_t eventId = createDirectEventSave(commandAddress); controller->doorbells[0] = 0; - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); return PTR(await(serviceId, eventId)); } @@ -77,7 +76,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); + uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); return buffer; diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 38c527b..39e33fa 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -32,3 +32,19 @@ uint32_t await(uint32_t service, uint32_t event) { return syscall(SYS_AWAIT, service, event, 0, 0); } + +uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { + return syscall(SYS_GET_EVENT, serviceId, id, 0, 0); +} + +uint32_t createDirectEvent(uint32_t id) { + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uint32_t createDirectEventSave(uint32_t id) { + uint32_t existingEvent = getDirectEvent(getServiceId(), id); + if (existingEvent) { + return existingEvent; + } + return createDirectEvent(id); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index cb58a2f..0285a06 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include "../hlib/include/syscalls.h" #include uint32_t serviceId; diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index f0a99b5..ae50fc1 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -1,5 +1,4 @@ #include "commands.h" -#include "../../hlib/include/syscalls.h" #include "trbRing.h" #include "xhci.h" #include @@ -14,8 +13,8 @@ trb.status = status; trb.control = control; uint32_t commandAddress = U32(enqueueCommand(&controller->commands, &trb)); + uint32_t eventId = createDirectEventSave(commandAddress); controller->doorbells[0] = 0; - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); return PTR(await(serviceId, eventId)); } @@ -77,7 +76,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); + uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); return buffer; diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 8c1ab5b..d7dd5bf 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -1,5 +1,4 @@ #include "controller.h" -#include "../../hlib/include/syscalls.h" #include "commands.h" #include "trbRing.h" #include "xhci.h" @@ -143,12 +142,11 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - uint32_t eventId = - syscall(SYS_GET_EVENT, serviceId, trb->dataLow, 0, 0); - printf("event %i [%x %x %x %x]: %i\n", + uint32_t eventId = getDirectEvent(serviceId, trb->dataLow); + printf("event %i [%x %x %x %x]: %i -> %i\n", globalController->events.dequeue, trb->dataLow, trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + trb->control >> 10 & 0x3F, eventId); if (eventId) { fireEvent(eventId, U32(trb)); } diff --git a/src/include/hlib.h b/src/include/hlib.h index dac6387..49d6382 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -28,6 +28,9 @@ extern uint32_t loadFromInitrd(char *name); extern uint32_t loadFromInitrdUninitialized(char *name); extern uint32_t createEvent(char *name); +extern uint32_t createDirectEvent(uint32_t id); +extern uint32_t createDirectEventSave(uint32_t id); +extern uint32_t getDirectEvent(uint32_t serviceId, uint32_t id); extern uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 38c527b..39e33fa 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -32,3 +32,19 @@ uint32_t await(uint32_t service, uint32_t event) { return syscall(SYS_AWAIT, service, event, 0, 0); } + +uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { + return syscall(SYS_GET_EVENT, serviceId, id, 0, 0); +} + +uint32_t createDirectEvent(uint32_t id) { + return syscall(SYS_CREATE_EVENT, id, 0, 0, 0); +} + +uint32_t createDirectEventSave(uint32_t id) { + uint32_t existingEvent = getDirectEvent(getServiceId(), id); + if (existingEvent) { + return existingEvent; + } + return createDirectEvent(id); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index cb58a2f..0285a06 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -1,7 +1,6 @@ #define ALLOC_MAIN #include -#include "../hlib/include/syscalls.h" #include uint32_t serviceId; diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index f0a99b5..ae50fc1 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -1,5 +1,4 @@ #include "commands.h" -#include "../../hlib/include/syscalls.h" #include "trbRing.h" #include "xhci.h" #include @@ -14,8 +13,8 @@ trb.status = status; trb.control = control; uint32_t commandAddress = U32(enqueueCommand(&controller->commands, &trb)); + uint32_t eventId = createDirectEventSave(commandAddress); controller->doorbells[0] = 0; - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); return PTR(await(serviceId, eventId)); } @@ -77,7 +76,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = syscall(SYS_CREATE_EVENT, commandAddress, 0, 0, 0); + uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); return buffer; diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 8c1ab5b..d7dd5bf 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -1,5 +1,4 @@ #include "controller.h" -#include "../../hlib/include/syscalls.h" #include "commands.h" #include "trbRing.h" #include "xhci.h" @@ -143,12 +142,11 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - uint32_t eventId = - syscall(SYS_GET_EVENT, serviceId, trb->dataLow, 0, 0); - printf("event %i [%x %x %x %x]: %i\n", + uint32_t eventId = getDirectEvent(serviceId, trb->dataLow); + printf("event %i [%x %x %x %x]: %i -> %i\n", globalController->events.dequeue, trb->dataLow, trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + trb->control >> 10 & 0x3F, eventId); if (eventId) { fireEvent(eventId, U32(trb)); } diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 2bc5c29..5eddf3e 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -1,5 +1,4 @@ #include "xhci.h" -#include "../../hlib/include/syscalls.h" #include "commands.h" #include "controller.h" #include @@ -36,7 +35,7 @@ printf("port %i: connecting to slot %i\n", portIndex, slot->slotIndex); slot->port->status |= 1 << 4; - await(serviceId, syscall(SYS_CREATE_EVENT, slot->portIndex << 24, 0, 0, 0)); + await(serviceId, createDirectEventSave(slot->portIndex << 24)); if (!(slot->port->status & 1 << 1)) { printf("port %i reset not succesful, aborting\n", portIndex); return NULL;