Broadcom SDK6.4.4驅動架構簡單理解

static bde_ctrl_t _devices[LINUX_BDE_MAX_DEVICES];

首先在linux-kernel-bde模塊裏

1.基與spi,pci設備驅動之上,再抽象一個結構體數組

static bde_ctrl_t _devices[LINUX_BDE_MAX_DEVICES]

來存儲spi,pci設備。

2.定義一個結構體_ibde,存儲操作spi,pci設備的相關函數

static ibde_t _ibde = {

    name: _name,

    num_devices: _num_devices, //管理的_devices個數

    get_dev: _get_dev,

    get_dev_type: _get_dev_type,

    pci_conf_read: _pci_conf_read,

    pci_conf_write: _pci_conf_write,

    pci_bus_features: _pci_bus_features,

    read: _read,

    write: _write,

    salloc: _salloc,

    sfree: _sfree,

    sinval: _sinval,

    sflush: _sflush,

    interrupt_connect: _interrupt_connect, //註冊中斷服務號

    interrupt_disconnect: _interrupt_disconnect,

    l2p: _l2p,

    p2l: _p2l,

#if defined(BCM_ROBO_SUPPORT)

    spi_read: _spi_read,

    spi_write: _spi_write,

#else

    NULL,

    NULL,

#endif /* defined(BCM_ROBO_SUPPORT) */

    iproc_read: _iproc_read,

    iproc_write: _iproc_write,

};

3..在linux-kernel-bde模塊裏創建一個函數linux_bde_create 用來獲取這個_ibde結構體,再EXPORT_SYMBOL(linux_bde_create),這樣bcm-core模塊裏就可以調用這個函數。

4.在bcm-core模塊裏調用函數linux_bde_create獲取_ibde,藉助這個實現對spi,pci設備的操作。

在bcm-core模塊裏定義了一個

typedef struct

{

    soc_cm_dev_t              dev;

    soc_cm_device_vectors_t     vectors;

} cm_device_t;

cm_device_t     soc_cm_device[SOC_MAX_NUM_DEVICES];

 

來 管理linux-kernel-bde模塊裏掃描到的設備

soc_cm_device可以理解爲是linux-kernel-bde模塊裏_devices的拷貝及強化版,

bcm-core模塊調用linux_bde_create來獲取_ibde,並用它填充soc_cm_device,並在之後的初始化處理流程裏,將使用soc_cm_device.

5. bcm-core模塊裏定義了

soc_control_t   *soc_control[SOC_MAX_NUM_DEVICES];

來管理芯片

soc_control是芯片層面的

 

整個流程是:

1. linux-kerenl-bde模塊先探測設備,註冊驅動,並用static bde_ctrl_t _devices[LINUX_BDE_MAX_DEVICES] 來存儲設備相關信息,用static ibde_t _ibde = {…}來存儲設備相關函數,同時創建一個函數linux_bde_create來獲取該_ibde,並export_symbol(linux_bde_create).

2.Bcm-core模塊調用linux_bde_create 獲取_ibde,進而獲取設備信息,並用cm_device_t  soc_cm_device[SOC_MAX_NUM_DEVICES]存儲這些設備信息,其中包括芯片id,pci/spi讀寫函數,中斷註冊函數,struct dev結構體等

bcm-core 模塊,init處理流程

1.bcore_sysconf_probe

bde_create 初始化bde,該bde是bcm-core的bde,實際指向了linun-kernel-bde模塊的bde

soc_cm_device_create   創建soc_cm_device並簡單初始化其中的soc_cm_dev_t dev成員

2.bcore_sysconf_attach

通過soc_cm_device的定義可以看成,soc_cm_device包含兩個成員,其中dev成員已在bcore_sysconf_probe中初始化過了,所以在bcore_sysconf_attach中首先初始化vectors ,接着調用soc_cm_device_init,在soc_cm_device_init中,使用的soc_cm_device

 如果是robo系列芯片,進入soc_robo_attach

soc_robo_attach可以看成是創建對應芯片的soc_control,並對其初始化

在soc_robo_attach裏,首先創建soc_control[unit], soc_control對應了SOC層的芯片管理,並初始化它的chip_driver

soc->chip_driver = soc_robo_chip_driver_find(dev_id, rev_id);

通過dev id獲取芯片的driver,所有bcm芯片的driver都是存放在soc_robo_base_driver_table數組中,這裏的driver包含了和芯片相關的一些函數,這些函數在後續的芯片初始化中會被調用。

soc_robo_info_config(unit, soc);

初始化soc_control的info成員soc_feature_init(unit); 初始化featrue以及相關信號量等

如果是esw系列芯片,進入soc_attach

soc_attach與soc_robo_attach類似,也是先創建對應芯片的soc_control,並對其初始化,

soc->chip_driver = soc_chip_driver_find(dev_id, rev_id);

soc->soc_functions = _soc_functions_find(soc->chip_driver);

soc_feature_init(unit);

//註冊中斷服務

soc_cm_interrupt_connect(unit, iph, INT_TO_PTR(unit))

//以及創建一系列的“mutex”,信號量

soc->socControlMutex = sal_mutex_create("SOC_CONTROL"))

回顧以上可以看出:

bcore_sysconf_probe中最主要的功能是創建soc_cm_device[unit],與芯片一一對應,來源於linux-kernel-bde模塊的_devices,描述的是驅動層面的芯片。

bcore_sysconf_attach 中最主要是創建soc_control[unit],與芯片一一對應,基於soc_cm_device,描述的是SOC層的芯片。

後續的芯片初始化就是基於soc_control。

 

轉自http://sai03300427.m.blog.chinaunix.net/uid-29827071-id-5766412.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章