設(shè)備樹(shù):
- 是描述硬件信息的asiII文本文件,其書(shū)寫(xiě)符合人類(lèi)思維習(xí)慣。
歷史:
- 在linux更新維護(hù)過(guò)程中,linux創(chuàng)始人linus發(fā)現(xiàn)在收到arm平臺(tái)負(fù)責(zé)人的維護(hù)郵件后,提出了linux內(nèi)核中由來(lái)已久存在的問(wèn)題。
即硬件代碼在linux內(nèi)核中,管理無(wú)序混亂,冗余,效率低。提出借鑒powerPC架構(gòu)的FDT機(jī)制,來(lái)描述硬件。由此在linux3.0以后的版本
引入了設(shè)備樹(shù)的概念。其中比較顯著的特點(diǎn),設(shè)備樹(shù)是以外部參數(shù)的形式將硬件信息導(dǎo)入內(nèi)核。
關(guān)鍵詞:
- 1.DTC 是編譯設(shè)備樹(shù)的小工具
- 2.DTS 是描述硬件信息的asiII文本文件
- 3.DTB 是編譯后的二進(jìn)制文件,可被bootloader識(shí)別并解析
- 4.DTSI 類(lèi)似頭文件,描述平臺(tái)共性
設(shè)備樹(shù)的內(nèi)容:
-
1.節(jié)點(diǎn):是描述某個(gè)具體設(shè)備或參數(shù)
- 1.1根節(jié)點(diǎn) 每個(gè)平臺(tái)設(shè)備樹(shù),有且只有一個(gè)根節(jié)點(diǎn),根節(jié)點(diǎn)包含所有子節(jié)點(diǎn),根節(jié)點(diǎn)以“/”命名
- 1.2子節(jié)點(diǎn):子節(jié)點(diǎn)可互相包含,命名方式是[name]@<adress>,其中name為必寫(xiě)項(xiàng),adress為可寫(xiě)項(xiàng),一般adress
寫(xiě)的話(huà),如果該設(shè)備有地址,就寫(xiě)該設(shè)備地址,沒(méi)有寫(xiě)序號(hào)。 - 1.3子節(jié)點(diǎn)描述的設(shè)備類(lèi)型:
- 1.3.1 CPU
- 1.3.2 內(nèi)存
- 1.3.3 總線(xiàn)和橋
- 1.3.4 gpio控制器
- 1.3.5 中斷控制器
- 1.3.6 clk時(shí)鐘
- 1.3.7 外設(shè)
2.屬性 是描述節(jié)點(diǎn)的特性。屬性的表現(xiàn)形式為name=value,其中name的含義和value的含義由具體相關(guān)平臺(tái)給出。
-
2.1屬性的值的類(lèi)型:
- 1.u32
- 2.u64
- 3.字符串
- 4.字符串?dāng)?shù)組
- 5.結(jié)構(gòu)體
- 6.結(jié)構(gòu)體數(shù)組
- 7.phandle值
-
2.1重要屬性:
- 1.compatible: 其值為字符串,兼容性。是設(shè)備樹(shù)和驅(qū)動(dòng)匹配的標(biāo)識(shí)
- 2.reg: 描述節(jié)點(diǎn)的地址資源屬性。其值為結(jié)構(gòu)體數(shù)組,一般以adress size成組出現(xiàn)。
- 3.#adress-cells: 規(guī)定子節(jié)點(diǎn)的reg的value值的adress的個(gè)數(shù),其值為u32
- 4.#size-cells:規(guī)定子節(jié)點(diǎn)的reg的value值的size的個(gè)數(shù),其值為u32
- 5.interrupts: 描述節(jié)點(diǎn)的中斷源,其值的含義需查看相關(guān)文檔,其值為結(jié)構(gòu)體數(shù)組,
- 6.intrerupt-parent: 描述節(jié)點(diǎn)的父中斷節(jié)點(diǎn)。其為phandle值,表現(xiàn)<&標(biāo)號(hào)>,實(shí)際是一個(gè)u32
- 7.interrupt-controller: 描述節(jié)點(diǎn)為中斷控制器,其值為空值。
- 8.interrupt-cells:描述子中斷節(jié)點(diǎn)的interrupts屬性的value的cell個(gè)數(shù)。其值為u32,它只能在擁有interrupt-controller屬性的節(jié)點(diǎn)出現(xiàn)。
- 1.compatible: 其值為字符串,兼容性。是設(shè)備樹(shù)和驅(qū)動(dòng)匹配的標(biāo)識(shí)
中斷: 當(dāng)cpu遇到突發(fā)事件,轉(zhuǎn)而去處理突發(fā)事件,處理完成后,返回到正常狀態(tài)
中斷按來(lái)源分類(lèi):
- 外部中斷
- 內(nèi)部中斷
按可屏蔽:
- 可屏蔽中斷
- 不可屏蔽中斷
按入口地址:
- 向量中斷(硬件提供入口地址)和非向量中斷(軟件提供入口地址)
ARM平臺(tái)支持GIC中斷控制器:
- GIC所支持的中斷類(lèi)型:
- 1.PPI:私有中斷,中斷必須綁定一個(gè)固定CPU核,當(dāng)處理該中斷時(shí),必須由綁定的CPU核處理
- 2.SPI:共享中斷,中斷的處理可被任意的CPU核處理
- 3.SWI:軟中斷,用于處理核間通信和調(diào)度。
------------------------------------------------
內(nèi)核 --|- cpu ----- GIC---------中斷控制器 ........---|---外設(shè)
-------------------------------------------------
soc內(nèi)部
中斷編程:
- 1.申請(qǐng)中斷號(hào)
**
* request_threaded_irq - allocate an interrupt line
* @irq: Interrupt line to allocate
* @handler: Function to be called when the IRQ occurs.
* @irqflags: Interrupt type flags
* @devname: An ascii name for the claiming device
* @dev_id: A cookie passed back to the handler function
*
* This call allocates interrupt resources and enables the
* interrupt line and IRQ handling. From the point this
* call is made your handler function may be invoked. Since
* your handler function must clear any interrupt the board
* raises, you must take care both to initialise your hardware
* and to set up the interrupt handler in the right order.
*
* If you want to set up a threaded irq handler for your device
* then you need to supply @handler and @thread_fn. @handler is
* still called in hard interrupt context and has to check
* whether the interrupt originates from the device. If yes it
* needs to disable the interrupt on the device and return
* IRQ_WAKE_THREAD which will wake up the handler thread and run
* @thread_fn. This split handler design is necessary to support
* shared interrupts.
*
* Dev_id must be globally unique. Normally the address of the
* device data structure is used as the cookie. Since the handler
* receives this value it makes sense to use it.
*
* If your interrupt is shared you must pass a non NULL dev_id
* as this is required when freeing the interrupt.
*
* Flags:
*
* IRQF_SHARED Interrupt is shared
* IRQF_TRIGGER_* Specify active edge(s) or level
*
*/
static inline int __must_check
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags, const char *name, void *dev)
extern void free_irq(unsigned int, void *);