1
votes

My question is about linux device model. I did some digging myself in the source code and found that the device model works around many structures out of which some of them are:

  1. struct device
  2. struct device_driver
  3. struct bus_type
  4. There are more related to power management.

But when I looked into the char drivers implemented in linux kernel (or if I implement my own char driver) linux kernel is only implementing "struct device" and all other structures are just NULL. I have checked this through some debugging and with friendly neighbourhood API printk().

So my question is then why char drivers are not completely following the device model?

Also which drivers are completely following linux device model?

1

1 Answers

0
votes

Linux Device Model uses kobject as it's base which act as a glue to held it together.

The structures you mentioned come at a layer above kobject.

So, we can say that kobject is something that you will (almost) never come across but is still embedded everywhere.

And char drivers are no excuse:

struct cdev {
struct kobject kobj;
struct module *owner;
const struct file_operations *ops;
struct list_head list;
dev_t dev;
unsigned int count;
};

All drivers are following device model even without you know it, hence char drivers are no exception here too.

Look at implementation of cdev_add() and you will get your answer.

I suggest you go through this article and dig again inside LDM code.