tty: implement read/write support

This commit is contained in:
2023-06-11 09:23:57 +01:00
parent 557e1dda30
commit abe4af093e
9 changed files with 124 additions and 14 deletions

View File

@@ -17,3 +17,32 @@ struct char_device *char_device_from_generic(struct device *dev)
dev->dev_type = DEV_TYPE_CHAR;
return CHAR_DEVICE(dev);
}
static kern_status_t char_device_read(struct device *dev, void *buf, size_t size, size_t *bytes_read, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
struct char_device *cdev = CHAR_DEVICE(dev);
if (cdev->c_ops && cdev->c_ops->read) {
status = cdev->c_ops->read(dev, buf, size, bytes_read, flags);
}
return status;
}
static kern_status_t char_device_write(struct device *dev, const void *buf, size_t size, size_t *bytes_read, socks_flags_t flags)
{
kern_status_t status = KERN_UNSUPPORTED;
struct char_device *cdev = CHAR_DEVICE(dev);
if (cdev->c_ops && cdev->c_ops->write) {
status = cdev->c_ops->write(dev, buf, size, bytes_read, flags);
}
return status;
}
struct device_type_ops char_type_ops = {
.read = char_device_read,
.write = char_device_write,
};

View File

@@ -19,6 +19,7 @@ static kern_status_t device_object_get_child_named(struct object *, const char *
extern kern_status_t init_driver_tree(void);
extern struct device_type_ops char_type_ops;
extern struct device_type_ops input_type_ops;
extern struct device_type_ops framebuffer_type_ops;
extern struct device_type_ops bus_type_ops;
@@ -26,7 +27,7 @@ extern struct device_type_ops bus_type_ops;
static struct device_type_ops *type_ops[] = {
[DEV_TYPE_UNKNOWN] = NULL,
[DEV_TYPE_BLOCK] = NULL,
[DEV_TYPE_CHAR] = NULL,
[DEV_TYPE_CHAR] = &char_type_ops,
[DEV_TYPE_NET] = NULL,
[DEV_TYPE_INPUT] = &input_type_ops,
[DEV_TYPE_BUS] = &bus_type_ops,
@@ -123,17 +124,24 @@ struct device *generic_device_create(void)
kern_status_t device_read(struct device *dev, void *buf, size_t size, size_t *bytes_read, socks_flags_t flags)
{
switch (dev->dev_type) {
case DEV_TYPE_INPUT:
return input_device_read(dev, buf, size, bytes_read, flags);
default:
return KERN_UNSUPPORTED;
kern_status_t status = KERN_UNSUPPORTED;
if (type_ops[dev->dev_type] && type_ops[dev->dev_type]->read) {
status = type_ops[dev->dev_type]->read(dev, buf, size, bytes_read, flags);
}
return status;
}
kern_status_t device_write(struct device *dev, const void *buf, size_t size, size_t *bytes_written, socks_flags_t flags)
{
return KERN_UNSUPPORTED;
kern_status_t status = KERN_UNSUPPORTED;
if (type_ops[dev->dev_type] && type_ops[dev->dev_type]->write) {
status = type_ops[dev->dev_type]->write(dev, buf, size, bytes_written, flags);
}
return status;
}
struct device *cast_to_device(struct object *obj)

View File

@@ -88,4 +88,5 @@ kern_status_t input_device_register(struct device *dev)
struct device_type_ops input_type_ops = {
.register_device = input_device_register,
.read = input_device_read,
};