diff options
author | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
---|---|---|
committer | nthnluu <nate1299@me.com> | 2024-01-28 21:20:27 -0500 |
commit | c63f340d90800895f007de64b7d2d14624263331 (patch) | |
tree | 2c0849fa597dd6da831c8707b6f2603403778d7b /kernel/include/drivers/chardev.h |
Created student weenix repository
Diffstat (limited to 'kernel/include/drivers/chardev.h')
-rw-r--r-- | kernel/include/drivers/chardev.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/kernel/include/drivers/chardev.h b/kernel/include/drivers/chardev.h new file mode 100644 index 0000000..f6083d8 --- /dev/null +++ b/kernel/include/drivers/chardev.h @@ -0,0 +1,51 @@ +#pragma once + +#include "drivers/dev.h" +#include "util/list.h" + +struct vnode; +struct pframe; + +struct chardev_ops; +struct mobj; + +typedef struct chardev +{ + devid_t cd_id; + struct chardev_ops *cd_ops; + list_link_t cd_link; +} chardev_t; + +typedef struct chardev_ops +{ + ssize_t (*read)(chardev_t *dev, size_t pos, void *buf, size_t count); + + ssize_t (*write)(chardev_t *dev, size_t pos, const void *buf, size_t count); + + long (*mmap)(struct vnode *file, struct mobj **ret); + + long (*fill_pframe)(struct vnode *file, struct pframe *pf); + + long (*flush_pframe)(struct vnode *file, struct pframe *pf); +} chardev_ops_t; + +/** + * Initializes the byte device subsystem. + */ +void chardev_init(void); + +/** + * Registers the given byte device. + * + * @param dev the byte device to register + */ +long chardev_register(chardev_t *dev); + +/** + * Finds a byte device with a given device id. + * + * @param id the device id of the byte device to find + * @return the byte device with the given id if it exists, or NULL if + * it cannot be found + */ +chardev_t *chardev_lookup(devid_t id); |