在郵件清單裡討論了一下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;