linux核心裡面writel是如何?的

來源:互聯網
上載者:User
在郵件清單裡討論了一下writel是如何?的,這個函數實現在作業系統層,有記憶體保護的情況下,往一個寄存器或者記憶體位址寫一個資料。 在arch/alpha/kernel/io.c中有

188 void writel(u32 b, volatile void __iomem *addr)
189 {
190 __raw_writel(b, addr);
191 mb();
192 }

 這樣一個writel函數的作用應該是向一個地址上寫一個值,我想知道這個函數底下具體實現的細節,於是往下繼續跟蹤代碼:__raw_writel(b, addr);

129 void __raw_writel(u32 b, volatile void __iomem *addr)
130 {
131 IO_CONCAT(__IO_PREFIX,writel)(b, addr);
132 }

再往下跟蹤 IO_CONCAT,在對應的io.h中的定義如下:

134 #define IO_CONCAT(a,b) _IO_CONCAT(a,b)
135 #define _IO_CONCAT(a,b) a ## _ ## b

這段代碼前幾天問過了,是標示將兩邊的字串串連起來的意思。

 

跟蹤__IO_PREFIX 定義如下

501 #undef __IO_PREFIX
502 #define __IO_PREFIX apecs

 到這裡就結束了,再往下我就暈了,有問題如下:1、到底是怎麼將資料寫入地址的?我把這些單獨提取出來,進行先行編譯,宏展開後,發現是這樣的:

void __raw_writel(u32 b, volatile void __iomem *addr)
{
apecs_writel(b, addr);
}

但是在核心雷根本就沒找到apecs_writel函數,請幫忙解釋下。

 For the first question,
you should refer to the file "arch\alpha\kernle\Machvec_impl.h"
"~\Machve.h" "~\io.c" "~\io.h" "~\core_**.h".

as you have analysized before, in the file Machvec_impl.h and Machve.h,
DO_CIA_IO,IO,IO_LITE, these three macros implement the symbole
connection between ** arch and writel function, and the function
pointer initializations.
so, the details implementation to writel is to init the
alpha_machine_vector structure and the definition to the relevant
function pointer invoked to complete the low-level write operation.

.mv_writel =CAT(low,_writel),<---IO(CIA,cia)<-->cia_writel(b, addr); <---

|
writel(b, addr)-->__raw_writel(b, addr);--->cia_writel(b,addr)---------------


For the second quesiton,
mb()--->__asm__ __volatile__("mb": : :"memory");
so, it is a memory barrier for alpha architecture to ensure some
operations before some actions could be occured.
and, it is similiar with the barrier() in x86 platform/arm platform.

 繼續閱讀代碼,看看定義__IO_PREFIX之後緊接著包含了哪個標頭檔。在哪個頭文
件裡面尋找答案。對於你的apsec,看看以下程式碼片段(linux-2.6.28-rc4)

arch/alpha/include/asm/core_apecs.h
------------------------------------------
#undef __IO_PREFIX
#define __IO_PREFIX apecs
#define apecs_trivial_io_bw 0
#define apecs_trivial_io_lq 0
#define apecs_trivial_rw_bw 2
#define apecs_trivial_rw_lq 1
#define apecs_trivial_iounmap 1
#include <asm/io_trivial.h>
------------------------------------------

arch/alpha/include/asm/io_trivial.h
------------------------------------------
__EXTERN_INLINE void
IO_CONCAT(__IO_PREFIX,writel)(u32 b, volatile void __iomem *a)
{
*(volatile u32 __force *)a = b;
}

 就是最終通過*(volatile u32 __force *)a = b;
來寫入資料的。  如果在沒有os,沒有mmu的情況下,當開發板裸跑的時候,我們只需要一句話就一切ok:*(unsigned long *)addr = value;

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.