dev: add functions to create device objects
This commit is contained in:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user