dev: add functions to create device objects
This commit is contained in:
12
dev/block.c
Normal file
12
dev/block.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <socks/device.h>
|
||||
|
||||
struct block_device *block_device_create(void)
|
||||
{
|
||||
struct device *dev = device_alloc();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->dev_type = DEV_TYPE_BLOCK;
|
||||
return BLOCK_DEVICE(dev);
|
||||
}
|
||||
12
dev/bus.c
Normal file
12
dev/bus.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <socks/device.h>
|
||||
|
||||
struct bus_device *bus_device_create(void)
|
||||
{
|
||||
struct device *dev = device_alloc();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->dev_type = DEV_TYPE_BUS;
|
||||
return BUS_DEVICE(dev);
|
||||
}
|
||||
12
dev/char.c
Normal file
12
dev/char.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <socks/device.h>
|
||||
|
||||
struct char_device *char_device_create(void)
|
||||
{
|
||||
struct device *dev = device_alloc();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->dev_type = DEV_TYPE_CHAR;
|
||||
return CHAR_DEVICE(dev);
|
||||
}
|
||||
40
dev/core.c
Normal file
40
dev/core.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <socks/status.h>
|
||||
#include <socks/object.h>
|
||||
#include <socks/device.h>
|
||||
|
||||
static struct device *root_device = NULL;
|
||||
static object_type_t device_type = {
|
||||
.ob_name = "device",
|
||||
.ob_size = sizeof(struct device),
|
||||
.ob_ops = {
|
||||
.destroy = NULL,
|
||||
}
|
||||
};
|
||||
|
||||
kern_status_t device_init(void)
|
||||
{
|
||||
object_type_register(&device_type);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t set_root_device(struct device *dev)
|
||||
{
|
||||
if (root_device) {
|
||||
object_deref(object_header(root_device));
|
||||
}
|
||||
|
||||
object_ref(object_header(dev));
|
||||
root_device = dev;
|
||||
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
struct device *device_alloc(void)
|
||||
{
|
||||
object_t *dev_object = object_create(&device_type);
|
||||
if (!dev_object) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return object_data(dev_object);
|
||||
}
|
||||
12
dev/input.c
Normal file
12
dev/input.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <socks/device.h>
|
||||
|
||||
struct input_device *input_device_create(void)
|
||||
{
|
||||
struct device *dev = device_alloc();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->dev_type = DEV_TYPE_INPUT;
|
||||
return INPUT_DEVICE(dev);
|
||||
}
|
||||
Reference in New Issue
Block a user