Files
mango/dev/core.c

43 lines
787 B
C

#include <socks/status.h>
#include <socks/object.h>
#include <socks/device.h>
#define DEVICE_CAST(p) OBJECT_C_CAST(struct device, dev_base, &device_type, p)
static struct device *root_device = NULL;
static struct object_type 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(&root_device->dev_base);
}
object_ref(&dev->dev_base);
root_device = dev;
return KERN_OK;
}
struct device *device_alloc(void)
{
struct object *dev_object = object_create(&device_type);
if (!dev_object) {
return NULL;
}
return DEVICE_CAST(dev_object);
}