diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a077488..96e72b4 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -5,7 +5,7 @@ #define OFFSET(ptr, off) (((void *)(ptr)) + (off)) -extern uint32_t serviceId; +extern uint32_t serviceId, xhciEvent; typedef struct { uint8_t size; diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a077488..96e72b4 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -5,7 +5,7 @@ #define OFFSET(ptr, off) (((void *)(ptr)) + (off)) -extern uint32_t serviceId; +extern uint32_t serviceId, xhciEvent; typedef struct { uint8_t size; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8bbf51a..1b1e3c1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -3,7 +3,7 @@ #include -uint32_t serviceId; +uint32_t serviceId, xhciEvent; REQUEST(getBaseAddress, "lspci", "getBaseAddress"); REQUEST(getDeviceClass, "lspci", "getDeviceClass"); @@ -131,10 +131,8 @@ int32_t main() { serviceId = getServiceId(); - // this is needed so we can decide wether or not sys_get_event - // returns no event or an event TODO: start event indexing - // with index 1 or add a sensible default event - createEvent("unused"); + // xhciEvent will carry data corresponding to the data in the xhci event + xhciEvent = createEvent("xhciEvent"); for (uint32_t i = 0; i < 100; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a077488..96e72b4 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -5,7 +5,7 @@ #define OFFSET(ptr, off) (((void *)(ptr)) + (off)) -extern uint32_t serviceId; +extern uint32_t serviceId, xhciEvent; typedef struct { uint8_t size; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8bbf51a..1b1e3c1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -3,7 +3,7 @@ #include -uint32_t serviceId; +uint32_t serviceId, xhciEvent; REQUEST(getBaseAddress, "lspci", "getBaseAddress"); REQUEST(getDeviceClass, "lspci", "getDeviceClass"); @@ -131,10 +131,8 @@ int32_t main() { serviceId = getServiceId(); - // this is needed so we can decide wether or not sys_get_event - // returns no event or an event TODO: start event indexing - // with index 1 or add a sensible default event - createEvent("unused"); + // xhciEvent will carry data corresponding to the data in the xhci event + xhciEvent = createEvent("xhciEvent"); for (uint32_t i = 0; i < 100; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index ae50fc1..895b73d 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -13,9 +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; - return PTR(await(serviceId, eventId)); + return PTR(awaitCode(serviceId, xhciEvent, commandAddress)); } void addressDevice(SlotXHCI *slot, bool BSR) { @@ -76,8 +75,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); + CommandCompletionEvent *completionEvent = PTR(awaitCode(serviceId, xhciEvent, commandAddress)); return buffer; } diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a077488..96e72b4 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -5,7 +5,7 @@ #define OFFSET(ptr, off) (((void *)(ptr)) + (off)) -extern uint32_t serviceId; +extern uint32_t serviceId, xhciEvent; typedef struct { uint8_t size; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8bbf51a..1b1e3c1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -3,7 +3,7 @@ #include -uint32_t serviceId; +uint32_t serviceId, xhciEvent; REQUEST(getBaseAddress, "lspci", "getBaseAddress"); REQUEST(getDeviceClass, "lspci", "getDeviceClass"); @@ -131,10 +131,8 @@ int32_t main() { serviceId = getServiceId(); - // this is needed so we can decide wether or not sys_get_event - // returns no event or an event TODO: start event indexing - // with index 1 or add a sensible default event - createEvent("unused"); + // xhciEvent will carry data corresponding to the data in the xhci event + xhciEvent = createEvent("xhciEvent"); for (uint32_t i = 0; i < 100; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index ae50fc1..895b73d 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -13,9 +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; - return PTR(await(serviceId, eventId)); + return PTR(awaitCode(serviceId, xhciEvent, commandAddress)); } void addressDevice(SlotXHCI *slot, bool BSR) { @@ -76,8 +75,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); + CommandCompletionEvent *completionEvent = PTR(awaitCode(serviceId, xhciEvent, commandAddress)); return buffer; } diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index e5a63b1..85ac9f5 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,14 +142,11 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - uint32_t eventId = getDirectEvent(serviceId, trb->dataLow); - printf("event %i [%x %x %x %x]: %i -> %i\n", + printf("event %i [%x %x %x %x]: %i\n", globalController->events.dequeue, trb->dataLow, trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F, eventId); - if (eventId) { - fireEvent(eventId, U32(trb)); - } + trb->control >> 10 & 0x3F); + fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } } diff --git a/src/include/hlib.h b/src/include/hlib.h index 49d6382..bcd6966 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -35,6 +35,7 @@ uint32_t parameter1, uint32_t parameter2, uint32_t parameter3); extern void fireEvent(uint32_t eventId, uint32_t data); +extern void fireEventCode(uint32_t eventId, uint32_t data, uint32_t code); extern void subscribeEvent(uint32_t service, uint32_t event, void(handler)(void *, uint32_t)); extern uint32_t getEvent(uint32_t service, char *name); @@ -57,6 +58,7 @@ extern bool stackContains(uint32_t serviceId); extern uint32_t await(uint32_t service, uint32_t event); +extern uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code); extern void gets(char *buffer); extern void memcpy(void *from, void *to, uint32_t size); diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index fb48cc4..8de7b24 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -43,7 +43,7 @@ extern Service *currentService; extern void scheduleFunction(ServiceFunction *provider, Syscall *respondingTo, ...); -extern void fireEvent(Event *event, uint32_t data1); +extern void fireEvent(Event *event, uint32_t data, uint32_t code); extern void installKernelEvents(); #endif diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index 57f92ae..e4bfa39 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -41,7 +41,7 @@ Service *service = call->service; Event *event = listGet(service->events, call->parameters[0]); if (event) { - fireEvent(event, call->parameters[1]); + fireEvent(event, call->parameters[1], call->parameters[2]); } } diff --git a/src/kernel/service/events.c b/src/kernel/service/events.c index 3da186c..8aca4d3 100644 --- a/src/kernel/service/events.c +++ b/src/kernel/service/events.c @@ -16,19 +16,25 @@ extern ListElement *callsToProcess; -void fireEvent(Event *event, uint32_t data) { +void fireEvent(Event *event, uint32_t data, uint32_t code) { foreach (event->subscriptions, ServiceFunction *, function, { scheduleFunction(function, NULL, data); }) ; + ListElement *newWaiting = NULL; for (ListElement *current = event->waitingSyscalls; current;) { Syscall *call = current->data; - call->returnValue = data; - listAdd(&callsToProcess, call); ListElement *old = current; current = current->next; free(old); + if (call->parameters[2] && call->parameters[2] != code) { + // the call is waiting for a specific data value and currently isn't the right one + listAdd(&newWaiting, call); + continue; + } + call->returnValue = data; + listAdd(&callsToProcess, call); } - event->waitingSyscalls = NULL; + event->waitingSyscalls = newWaiting; } void installKernelEvents() { diff --git a/src/kernel/service/service.c b/src/kernel/service/service.c index 49eb68a..41784cd 100644 --- a/src/kernel/service/service.c +++ b/src/kernel/service/service.c @@ -35,7 +35,7 @@ service->name = serviceName; service->nameHash = insertString(serviceName); service->id = listCount(services); - fireEvent(loadInitrdEvent, service->nameHash); + fireEvent(loadInitrdEvent, service->nameHash, 0); void *current = &functionsStart; if (hlib) { service->pagingInfo.pageDirectory[0x3FC].pageTableID = diff --git a/src/userland/hlib/service/events.c b/src/userland/hlib/service/events.c index 39e33fa..9429c44 100644 --- a/src/userland/hlib/service/events.c +++ b/src/userland/hlib/service/events.c @@ -20,8 +20,12 @@ return syscall(SYS_GET_EVENT, service, id, 0, 0); } +void fireEventCode(uint32_t eventNumber, uint32_t data, uint32_t code) { + syscall(SYS_FIRE_EVENT, eventNumber, data, code, 0); +} + void fireEvent(uint32_t eventNumber, uint32_t data) { - syscall(SYS_FIRE_EVENT, eventNumber, data, 0, 0); + fireEventCode(eventNumber, data, 0); } void subscribeEvent(uint32_t service, uint32_t event, @@ -29,8 +33,12 @@ syscall(SYS_SUBSCRIBE_EVENT, service, event, U32(handler), 0); } +uint32_t awaitCode(uint32_t service, uint32_t event, uint32_t code) { + return syscall(SYS_AWAIT, service, event, code, 0); +} + uint32_t await(uint32_t service, uint32_t event) { - return syscall(SYS_AWAIT, service, event, 0, 0); + return awaitCode(service, event, 0); } uint32_t getDirectEvent(uint32_t serviceId, uint32_t id) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a077488..96e72b4 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -5,7 +5,7 @@ #define OFFSET(ptr, off) (((void *)(ptr)) + (off)) -extern uint32_t serviceId; +extern uint32_t serviceId, xhciEvent; typedef struct { uint8_t size; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8bbf51a..1b1e3c1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -3,7 +3,7 @@ #include -uint32_t serviceId; +uint32_t serviceId, xhciEvent; REQUEST(getBaseAddress, "lspci", "getBaseAddress"); REQUEST(getDeviceClass, "lspci", "getDeviceClass"); @@ -131,10 +131,8 @@ int32_t main() { serviceId = getServiceId(); - // this is needed so we can decide wether or not sys_get_event - // returns no event or an event TODO: start event indexing - // with index 1 or add a sensible default event - createEvent("unused"); + // xhciEvent will carry data corresponding to the data in the xhci event + xhciEvent = createEvent("xhciEvent"); for (uint32_t i = 0; i < 100; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/userland/usb/xhci/commands.c b/src/userland/usb/xhci/commands.c index ae50fc1..895b73d 100644 --- a/src/userland/usb/xhci/commands.c +++ b/src/userland/usb/xhci/commands.c @@ -13,9 +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; - return PTR(await(serviceId, eventId)); + return PTR(awaitCode(serviceId, xhciEvent, commandAddress)); } void addressDevice(SlotXHCI *slot, bool BSR) { @@ -76,8 +75,7 @@ enqueueCommand(slot->controlRing, (void *)&data); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - CommandCompletionEvent *completionEvent = PTR(await(serviceId, eventId)); + CommandCompletionEvent *completionEvent = PTR(awaitCode(serviceId, xhciEvent, commandAddress)); return buffer; } diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index e5a63b1..85ac9f5 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,14 +142,11 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - uint32_t eventId = getDirectEvent(serviceId, trb->dataLow); - printf("event %i [%x %x %x %x]: %i -> %i\n", + printf("event %i [%x %x %x %x]: %i\n", globalController->events.dequeue, trb->dataLow, trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F, eventId); - if (eventId) { - fireEvent(eventId, U32(trb)); - } + trb->control >> 10 & 0x3F); + fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } } diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 5090676..f5b89fc 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -36,7 +36,7 @@ printf("port %i: connecting to slot %i\n", portIndex, slot->slotIndex); slot->port->status |= 1 << 4; - await(serviceId, createDirectEventSave(slot->portIndex << 24)); + awaitCode(serviceId, xhciEvent, slot->portIndex << 24); if (!(slot->port->status & 1 << 1)) { printf("port %i reset not succesful, aborting\n", portIndex); return NULL; @@ -129,9 +129,8 @@ enqueueCommand(slot->controlRing, (void *)&setup); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - await(serviceId, eventId); + awaitCode(serviceId, xhciEvent, commandAddress); } void setProtocol(SlotXHCI *slot) { @@ -156,9 +155,8 @@ enqueueCommand(slot->controlRing, (void *)&setup); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - await(serviceId, eventId); + awaitCode(serviceId, xhciEvent, commandAddress); } void setIdle(SlotXHCI *slot) { @@ -183,9 +181,8 @@ enqueueCommand(slot->controlRing, (void *)&setup); uint32_t commandAddress = U32(enqueueCommand(slot->controlRing, (void *)&status)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = 1; - await(serviceId, eventId); + awaitCode(serviceId, xhciEvent, commandAddress); } void setupHID(SlotXHCI *slot, uint32_t endpointIndex, void *buffer) { @@ -206,9 +203,8 @@ while (1) { uint32_t commandAddress = U32(enqueueCommand( slot->endpointRings[endpointIndex], (void *)&normal)); - uint32_t eventId = createDirectEventSave(commandAddress); slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; - await(serviceId, eventId); + awaitCode(serviceId, xhciEvent, commandAddress); MouseReport *report = buffer; x += report->x; y += report->y;