dev: implement driver objects to organise and identify devices

This commit is contained in:
2023-06-02 19:35:07 +01:00
parent 577abf3bba
commit b7b0691b8f
17 changed files with 349 additions and 74 deletions

View File

@@ -44,6 +44,7 @@ static const enum input_keycode *keymaps[] = {
keymap_l4,
};
static struct driver *ps2_driver = NULL;
static struct input_device *keyboard = NULL, *mouse = NULL;
static void send_cmd(uint8_t cmd)
@@ -201,21 +202,28 @@ static int init_controller(void)
return 0;
}
static kern_status_t create_devices(void)
static kern_status_t create_devices(struct kext *self)
{
ps2_driver = driver_create(self, "ps2");
if (!ps2_driver) {
return KERN_NO_MEMORY;
}
struct input_device *kbd = input_device_create();
struct device *kbd_base = input_device_base(kbd);
snprintf(kbd_base->dev_name, sizeof kbd_base->dev_name, "ps2kbd");
struct input_device *ms = input_device_create();
struct device *ms_base = input_device_base(ms);
snprintf(ms_base->dev_name, sizeof ms_base->dev_name, "ps2mouse");
kern_status_t status = device_register(kbd_base, misc_device());
kern_status_t status = device_register(kbd_base, ps2_driver, misc_device());
if (status != KERN_OK) {
/* TODO destroy devices */
return status;
}
status = device_register(ms_base, misc_device());
status = device_register(ms_base, ps2_driver, misc_device());
if (status != KERN_OK) {
return status;
}
@@ -237,7 +245,7 @@ static kern_status_t online(struct kext *self)
return KERN_UNSUPPORTED;
}
kern_status_t status = create_devices();
kern_status_t status = create_devices(self);
if (status != KERN_OK) {
return status;
}