mtd_info
mtd_info는 메모리 장치의 특성을 나타내는 구조체
59 struct mtd_info {
60 u_char type;
61 u_int32_t flags;
62 u_int32_t size; // Total size of the MTD
63
64 /* "Major" erase size for the device. Naive users may take this
65 * to be the only erase size available, or may use the more detailed
66 * information below if they desire
67 */
68 u_int32_t erasesize;
85
86 // Kernel-only stuff starts here.
87 char *name;
88 int index;
89
90 // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO)
91 struct nand_oobinfo oobinfo;
92 u_int32_t oobavail; // Number of bytes in OOB area available for fs
93
94 /* Data for variable erase regions. If numeraseregions is zero,
95 * it means that the whole device has erasesize as given above.
96 */
97 int numeraseregions;
98 struct mtd_erase_region_info *eraseregions;
99
100 /* This really shouldn't be here. It can go away in 2.5 */
101 u_int32_t bank_size;
102
103 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
104
105 /* This stuff for eXecute-In-Place */
106 int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
107
108 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
109 void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
110
111
112 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
113 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
114
115 int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
116 int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel);
117
118 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
119 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
120
121 /*
122 * Methods to access the protection register area, present in some
123 * flash devices. The user data is one time programmable but the
124 * factory data is read only.
125 */
126 int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
127 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
128 int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
129 int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
130 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
131 int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
132
133 /* kvec-based read/write methods. We need these especially for NAND flash,
134 with its limited number of write cycles per erase.
135 NB: The 'count' parameter is the number of _vectors_, each of
136 which contains an (ofs, len) tuple.
137 */
138 int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
139 int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
140 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
141 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
142 int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
143 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
144
145 /* Sync */
146 void (*sync) (struct mtd_info *mtd);
147
148 /* Chip-supported device locking */
149 int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
150 int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
151
152 /* Power Management functions */
153 int (*suspend) (struct mtd_info *mtd);
154 void (*resume) (struct mtd_info *mtd);
155
156 /* Bad block management functions */
157 int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
158 int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
159
160 struct notifier_block reboot_notifier; /* default mode before reboot */
161
162 void *priv;
163
164 struct module *owner;
165 int usecount;
166 };
플랫폼 디바이스 드라이버
플랫폼 드라이버 s3c2440_nand_driver 는 다음과 같이 정의된다.
Linux 2.6에서 나오는 Platform Device Driver model이다.
KObject을 기반으로, 객체 기반의 계층적 디바이스 드라이버 모델이다. (마치 Windows WDM처럼)
등록된 버스 디바이스가 있고, 버스에 새로운 디바이스가 붙으면 버스 드라이버가 디바이스를 탐지해서 해당 디바이스에 맞는 디바이스 드라이버를 구동하는 식이다.
아래는 플랫폼 디바이스 정의다.
16 struct platform_device {
17 const char * name;
18 u32 id;
19 struct device dev;
20 u32 num_resources;
21 struct resource * resource;
22 };
아래는 플랫폼 드라이버 정의다.
47 struct platform_driver {
48 int (*probe)(struct platform_device *);
49 int (*remove)(struct platform_device *);
50 void (*shutdown)(struct platform_device *);
51 int (*suspend)(struct platform_device *, pm_message_t state);
52 int (*resume)(struct platform_device *);
53 struct device_driver driver;
54 };
예로 s3c2440의 nand platform driver는 다음처럼 정의되고,
705 static struct platform_driver s3c2440_nand_driver = {
706 .probe = s3c2440_nand_probe,
707 .remove = s3c2410_nand_remove,
708 .driver = {
709 .name = "s3c2440-nand",
710 .owner = THIS_MODULE,
711 },
712 };
device는 아래처럼 정의된다.
120 /* NAND Controller */
121
122 static struct resource s3c_nand_resource[] = {
123 [0] = {
124 .start = S3C2410_PA_NAND,
125 .end = S3C2410_PA_NAND + S3C24XX_SZ_NAND - 1,
126 .flags = IORESOURCE_MEM,
127 }
128 };
130 struct platform_device s3c_device_nand = {
131 .name = "s3c2410-nand",
132 .id = -1,
133 .num_resources = ARRAY_SIZE(s3c_nand_resource),
134 .resource = s3c_nand_resource,
135 };
일단 smdk2440 board machine init할때 nand 플랫폼 디바이스는 등록된다.
112 static struct platform_device __initdata *smdk_devs[] = {
113 &s3c_device_nand,
114 };
102 static struct s3c2410_platform_nand smdk_nand_info = {
103 .tacls = 20,
104 .twrph0 = 60,
105 .twrph1 = 20,
106 .nr_sets = ARRAY_SIZE(smdk_nand_sets),
107 .sets = smdk_nand_sets,
108 };
116 void __init smdk_machine_init(void)
117 {
118 /* Configure the LEDs (even if we have no LED support)*/
119
120 s3c2410_gpio_cfgpin(S3C2410_GPF4, S3C2410_GPF4_OUTP);
121 s3c2410_gpio_cfgpin(S3C2410_GPF5, S3C2410_GPF5_OUTP);
122 s3c2410_gpio_cfgpin(S3C2410_GPF6, S3C2410_GPF6_OUTP);
123 s3c2410_gpio_cfgpin(S3C2410_GPF7, S3C2410_GPF7_OUTP);
124
125 s3c2410_gpio_setpin(S3C2410_GPF4, 1);
126 s3c2410_gpio_setpin(S3C2410_GPF5, 1);
127 s3c2410_gpio_setpin(S3C2410_GPF6, 1);
128 s3c2410_gpio_setpin(S3C2410_GPF7, 1);
129
130 s3c_device_nand.dev.platform_data = &smdk_nand_info;
131
132 platform_add_devices(smdk_devs, ARRAY_SIZE(smdk_devs)); <--- 여기
133
134 s3c2410_pm_init();
135 }
mtd_blktrans_ops
35 struct mtd_blktrans_ops {
36 char *name;
37 int major;
38 int part_bits;
39
40 /* Access functions */
41 int (*readsect)(struct mtd_blktrans_dev *dev,
42 unsigned long block, char *buffer);
43 int (*writesect)(struct mtd_blktrans_dev *dev,
44 unsigned long block, char *buffer);
45
46 /* Block layer ioctls */
47 int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
48 int (*flush)(struct mtd_blktrans_dev *dev);
49
50 /* Called with mtd_table_mutex held; no race with add/remove */
51 int (*open)(struct mtd_blktrans_dev *dev);
52 int (*release)(struct mtd_blktrans_dev *dev);
53
54 /* Called on {de,}registration and on subsequent addition/removal
55 of devices, with mtd_table_mutex held. */
56 void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
57 void (*remove_dev)(struct mtd_blktrans_dev *dev);
58
59 struct list_head devs;
60 struct list_head list;
61 struct module *owner;
62
63 struct mtd_blkcore_priv *blkcore_priv;
64 };
'KB > C/C++' 카테고리의 다른 글
do{}while(0)를 하는 이유 (0) | 2007.05.25 |
---|---|
C와 어셈블리 호출 (0) | 2006.08.15 |
VC++.NET 새 키워드 (0) | 2006.06.28 |
cl.exe Episode XIII: Attack of the Standards: VC6, 7에서 C++ 표준 적용 사항 (0) | 2006.06.28 |
typeof (0) | 2006.06.28 |