匯流排 裝置 驅動模型

2021-06-18 17:56:58 字數 2306 閱讀 9442

裝置元素:

匯流排, 驅動, 裝置

匯流排:處理器和裝置之間的通道,在裝置模型中,所有的裝置都通過匯流排相連,甚至是內部的虛擬「platform」匯流排(定時器,看門狗並沒有直接相連)。在linux裝置模型中,匯流排由bus_type結構表示,定義在

匯流排的註冊使用:

bus_register(struct bus_type *bus);

若成功,新的匯流排將被新增進系統,並可以在sysfs的/sys/bus下面看到。

匯流排的刪除:

void bus_unregister(struct bus_type *bus);

匯流排的方法:

int (*match)(struct device *dev, struct device_driver *drv);

當乙個新裝置或者驅動被新增到這個匯流排的時候,呼叫該方法。用於半段指定的驅動程式系否能處理指定的裝置。如果可以,則返回非零值。

int (*uevent)(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size);

在為使用者空間產生熱插拔事件(目錄變化)之前,這個方法允許匯流排新增環境變數。

匯流排屬性:

struct bus_attribute{

struct attribute attr;

ssize_t (*show)(struct bus_type *, char *buf);

ssize_t (*store)(stuct bus_type *, const char *buf, size_t count);

int bus_create_file(struct bus_type *bus, struct bus_attribute *attr);

新增屬性檔案

void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr);

刪》除屬性檔案

裝置:用struct device來描述。

裝置註冊:

int device_register(struct device *dev);

註冊裝置

voi device_unregister(struct device *dev);

登出裝置

匯流排也是裝置,也必須按照裝置來註冊

裝置屬性:

struct device_attribute{

struct attribute attr;

ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);

ssize_t (*store)(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);

int device_create_file(struct device *device, struct device_attribute *entry);

建立屬性

void device_remove_file(struct device *dev, struct device_attribute *attr);

刪除屬性

驅動:用struct device_driver來描述

註冊驅動:

int driver_register(struct device_driver *drv);

註冊驅動

void driver_unregister(struct device_driver *drv);

登出驅動

驅動屬性:

struct driver_attribute{

struct attribute attr;

ssize_t (*show)(struct device_driver *drv,char *buf);

ssize_t (*store)(struct device_driver *drv, const char *buf, size_t count);

int driver_create_file(struct device_driver *drv,struct driver_attribute *attr);

int driver_remove_file(struct device_driver *drv,struct driver_attribute *attr);

驅動方法:

int(*probe)(struct device *dev);

當驅動找到與之匹配的裝置的時候,會被呼叫。

匯流排裝置驅動模型

匯流排裝置驅動模型 匯流排是主機和裝置之間的通道,由bus type 結構描述。int bus register struct bus type bus 匯流排的註冊,若成功,新的匯流排將被新增進系統,並可在 sysfs 的 sys bus 下看到。void bus unregister struc...

匯流排裝置驅動模型

匯流排 乙個匯流排是處理器和乙個或多個裝置之間的通道。為裝置模型的目的,所有的裝置都通過乙個匯流排連線,甚至當它是乙個內部的虛擬的 平台 匯流排。裝置 裝置就是連線在匯流排上的物理實體。裝置是有功能之分的。具有相同功能的裝置被歸到乙個類 class 中。在linux 系統中,每個裝置由乙個 stru...

匯流排裝置驅動模型

1.匯流排裝置模型概述 2.匯流排 3.驅動 4.裝置 1.匯流排裝置模型概述 隨著技術的不斷進步,系統的拓撲結構也越來越複雜,對熱插拔,跨平台移植性的要求也越來越高,2.4核心已經難以滿足這些需求。為適應這種形勢的需要,從linux2.6核心開始提供了全新的裝置模型。匯流排裝置驅動對熱插拔要求越來...