dev: implement object callbacks for devices. add misc device

This commit is contained in:
2023-05-08 18:18:34 +01:00
parent 4d04959219
commit 1a633eee6b
2 changed files with 138 additions and 11 deletions

View File

@@ -7,6 +7,8 @@
struct device;
#define DEV_NAME_MAX OBJECT_NAME_MAX
#define BLOCK_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_BLOCK ? &(dev)->blk : NULL);
#define CHAR_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_CHAR ? &(dev)->chr : NULL);
#define NET_DEVICE(dev) ((dev)->dev_type == DEV_TYPE_NET ? &(dev)->net : NULL);
@@ -73,6 +75,7 @@ struct device {
struct device *dev_parent;
struct queue dev_children;
struct queue_entry dev_childent;
char dev_name[DEV_NAME_MAX];
void *dev_priv;
@@ -86,9 +89,19 @@ struct device {
};
extern kern_status_t device_init(void);
extern kern_status_t set_root_device(struct device *dev);
extern struct device *root_device(void);
extern struct device *misc_device(void);
extern struct device *device_alloc(void);
static inline void device_lock_irqsave(struct device *dev, unsigned long *flags)
{
object_lock(&dev->dev_base, flags);
}
static inline void device_unlock_irqrestore(struct device *dev, unsigned long flags)
{
object_unlock(&dev->dev_base, flags);
}
extern struct char_device *char_device_create(void);
extern struct block_device *block_device_create(void);