前日與客戶進行 Linux device driver 教育訓練時,簡單討論到有關 JK2410 的 IO memory layout 描述方式。在 linux 2.6.20.x 的 BSP 實作中,kernel 提供用來描述 board-level(machine)IO mapping 的資料結構稱為 'struct map_desc',其定義如下:
1 /*
2 * linux/include/asm-arm/map.h
3 *
4 * Copyright (C) 1999-2000 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Page table mapping constructs and function prototypes
11 */
12 struct map_desc {
13 unsigned long virtual;
14 unsigned long pfn;
15 unsigned long length;
16 unsigned int type;
17 };
18
19 #define MT_DEVICE 0
20 #define MT_CACHECLEAN 1
21 #define MT_MINICLEAN 2
22 #define MT_LOW_VECTORS 3
23 #define MT_HIGH_VECTORS 4
24 #define MT_MEMORY 5
25 #define MT_ROM 6
26 #define MT_IXP2000_DEVICE 7
27 #define MT_NONSHARED_DEVICE 8
28
29 #ifdef CONFIG_MMU
30 extern void iotable_init(struct map_desc *, int);
31 #else
32 #define iotable_init(map,num) do { } while (0)
33 #endif
34
這是一個非常「輕薄」的設計,以 Jollen-Kit! Pro. 開發板來說,我的實作程式碼如下:
diff -Naur linux-2.6.20.4_orig/arch/arm/mach-s3c2410/mach-smdk2410.c linux-2.6.20.4/arch/arm/mach-s3c2410/mach-smdk2410.c
--- linux-2.6.20.4_orig/arch/arm/mach-s3c2410/mach-smdk2410.c 2007-03-24 03:52:51.000000000 +0800
+++ linux-2.6.20.4/arch/arm/mach-s3c2410/mach-smdk2410.c 2007-04-04 17:48:05.000000000 +0800
@@ -55,7 +55,13 @@
#include "common-smdk.h"
static struct map_desc smdk2410_iodesc[] __initdata = {
- /* nothing here yet */
+ /* ISA IO Space mapping for CS8900. Memory space is selected by A24. */
+ {
+ .virtual = 0xd0000000,
+ .pfn = S3C24XX_PA_CS8900,
+ .length = 0x00100000,
+ .type = MT_DEVICE,
+ }
};
程式碼簡單乾淨,這能讓不懂 kernel 的硬體開發人員也能快速上手維護。這讓我們了解到,一些「抽象」設計的 kernel 程式碼,雖然在某個程度來說,會讓 developer 多花一些時間才能 trace 到底層,但卻能適度提供硬體開發人員一些彈性空間。例如,不需要懂 kernel 的硬體工程師,也能有自行修改 IO mapping 設定的能力。
附帶一提,S3C24XX_PA_CS8900 是 IO memory 的實體位址(physical address)。
Jollen's Blog 使用 Github issues 與讀者交流討論。請點擊上方的文章專屬 issue,或 open a new issue
您可透過電子郵件 jollen@jollen.org,或是 Linkedin 與我連絡。更歡迎使用微信,請搜尋 WeChat ID:jollentw