dev: implement generic devices
generic devices don't have a type (char, block, etc) and are created by bus drivers to represent the device until a suitable driver is found. generic devices are registered by the bus driver. once a more suitable driver is found, that driver will re-register the device under itself.
This commit is contained in:
31
dev/fb.c
31
dev/fb.c
@@ -17,6 +17,12 @@ struct framebuffer_device *framebuffer_device_create(void)
|
||||
return FRAMEBUFFER_DEVICE(dev);
|
||||
}
|
||||
|
||||
struct framebuffer_device *framebuffer_device_from_generic(struct device *dev)
|
||||
{
|
||||
dev->dev_type = DEV_TYPE_FRAMEBUFFER;
|
||||
return FRAMEBUFFER_DEVICE(dev);
|
||||
}
|
||||
|
||||
static kern_status_t generate_name(struct framebuffer_device *dev, char out[DEV_NAME_MAX])
|
||||
{
|
||||
snprintf(out, DEV_NAME_MAX, "fb%u", dev->fb_id);
|
||||
@@ -42,6 +48,31 @@ kern_status_t framebuffer_device_register(struct device *dev)
|
||||
return object_namespace_create_link(global_namespace(), path, &dev->dev_base);
|
||||
}
|
||||
|
||||
kern_status_t framebuffer_get_varinfo(struct device *dev, struct framebuffer_varinfo *varinfo)
|
||||
{
|
||||
struct framebuffer_device *fbdev = FRAMEBUFFER_DEVICE(dev);
|
||||
if (!fbdev) {
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
memcpy(varinfo, &fbdev->fb_varinfo, sizeof *varinfo);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
kern_status_t framebuffer_set_varinfo(struct device *dev, const struct framebuffer_varinfo *varinfo)
|
||||
{
|
||||
struct framebuffer_device *fbdev = FRAMEBUFFER_DEVICE(dev);
|
||||
if (!fbdev) {
|
||||
return KERN_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (!fbdev->fb_ops || !fbdev->fb_ops->set_varinfo) {
|
||||
return KERN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return fbdev->fb_ops->set_varinfo(dev, varinfo);
|
||||
}
|
||||
|
||||
struct device_type_ops framebuffer_type_ops = {
|
||||
.register_device = framebuffer_device_register,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user