2023-04-03 16:59:14 +01:00
|
|
|
#include <socks/status.h>
|
|
|
|
|
#include <socks/object.h>
|
|
|
|
|
#include <socks/device.h>
|
|
|
|
|
|
|
|
|
|
static struct device *root_device = NULL;
|
2023-04-12 20:17:11 +01:00
|
|
|
static struct object_type device_type = {
|
2023-04-03 16:59:14 +01:00
|
|
|
.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)
|
|
|
|
|
{
|
2023-04-12 20:17:11 +01:00
|
|
|
struct object *dev_object = object_create(&device_type);
|
2023-04-03 16:59:14 +01:00
|
|
|
if (!dev_object) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return object_data(dev_object);
|
|
|
|
|
}
|