Camera KMD ISP學習筆記(2)-component框架

lethe1203發表於2024-04-06
參考資料:
極客筆記https://deepinout.com/camx-kmd/camera-kmd-isp-component-framework-part-1.html
https://blog.csdn.net/shikivs/article/details/103591971
僅用於個人學習,侵聯刪
一些subsystem需要有很多元件組成,kernel中的component框架是為了subsystem能夠按照一定的順序初始化裝置而提出的框架。subsystem中有較多裝置模組組成,而核心載入每個模組的時間不一定。子系統內有些模組是需要依賴其他先初始化才能進行自己初始化工作(例如v4l2 subdev和v4l2 video device),這就要用到component框架
component框架程式碼:drivers/base/component.c
struct component用來表示系統元件
struct aggregate_device(之前為master_device)表示需要構建的系統
struct component_match用來匹配系統需要的元件,並規定了元件的初始化順序,按什麼順序add就會什麼add進入
struct component {
    struct list_head node;    // 用於連結到全域性component_list中
    struct addregate_device *adev;    // 儲存本元件屬於哪個aggregate device或master device
    bool bound;    // 表示本component是否已經bind了,繫結就是初始化了
    const struct component_ops *ops;    // 本component的回撥介面
    int subcomponent;    // camera子系統暫未使用
    struct device *dev;    // 本component屬於哪個device,父類的裝置
};

struct aggregate_device {
    struct list_head node;    // 用於連結到全域性aggregate_deivces中
    bool bound;    // 表示本aggregate_device是否已經bind了
    const struct component_master_ops *ops;    // master裝置的回撥介面
    struct device *parent;    // 用於記錄本aggregate device屬於哪個struct device
    struct component_match *match;    // 按照順序儲存了本aggregate_device的所有component匹配條件
};

struct component_match {
   size_t alloc;    //  記錄分配了多少個struct component_match_array物件
   size_t num;    // 記錄儲存了多少個component匹配條件
   struct component_match_array *compare;    // 儲存了分配好的記憶體,用於儲存component匹配條件
};

static LIST_HEAD(component_list);    // 儲存整個Linux系統中所有新增到component框架裡的struct component資料結構
static LIST_HEAD(aggregate_devices);    // 儲存整個linux系統中所有的struct aggregate_device(master)資料結構

component_match_add()    // 新增一個component_match_entry例項,第一次呼叫這個函式時會建立struct component_match記憶體
component_master_add_with_match()
1、分配一個aggregate_device(master)物件,並且把所有需要match的component繫結到這個aggregate_device
2、新增aggregate_device(master)物件到全域性連結串列aggregate_devices中
3、檢查是否所有屬於該master device的所有component讀ready,如果ready就呼叫master的bind回撥介面進行初始化

component_add()
1、分配一個component物件並且新增到全域性連結串列component_list中
2、檢查系統中每一個master device的所屬component是否都ready,如果ready就呼叫master的bin回撥介面進行初始化

component_bind_all()    // 遍歷一個master裝置的component,並且順序呼叫每個component的bind回撥函式進行初始化

相關文章