blob: d51c1abd186328d9f862aba4febeabcc8fdf4eb1 [file] [log] [blame]
Wolfgang Denk932394a2005-08-17 12:55:25 +02001/*
William Juulcfa460a2007-10-31 13:53:06 +01002 * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $
Wolfgang Denk932394a2005-08-17 12:55:25 +02003 *
Wolfgang Denkac7eb8a2005-09-14 23:53:32 +02004 * Portions of MTD ABI definition which are shared by kernel and user space
Wolfgang Denk932394a2005-08-17 12:55:25 +02005 */
6
7#ifndef __MTD_ABI_H__
8#define __MTD_ABI_H__
9
William Juulcfa460a2007-10-31 13:53:06 +010010#if 1
Mike Frysinger7b15e2b2012-04-09 13:39:55 +000011#include <linux/compat.h>
William Juulcfa460a2007-10-31 13:53:06 +010012#endif
13
Kim Phillips0d4c1c92012-10-29 13:34:24 +000014#include <linux/compiler.h>
15
Wolfgang Denk932394a2005-08-17 12:55:25 +020016struct erase_info_user {
17 uint32_t start;
18 uint32_t length;
19};
20
21struct mtd_oob_buf {
22 uint32_t start;
23 uint32_t length;
William Juulcfa460a2007-10-31 13:53:06 +010024 unsigned char __user *ptr;
Wolfgang Denk932394a2005-08-17 12:55:25 +020025};
26
Sergey Lapindfe64e22013-01-14 03:46:50 +000027/*
28 * MTD operation modes
29 *
30 * @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
31 * @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
32 * which are defined by the internal ecclayout
33 * @MTD_OPS_RAW: data are transferred as-is, with no error correction;
34 * this mode implies %MTD_OPS_PLACE_OOB
35 *
36 * These modes can be passed to ioctl(MEMWRITE) and are also used internally.
37 * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
38 * %MTD_FILE_MODE_RAW.
39 */
40enum {
41 MTD_OPS_PLACE_OOB = 0,
42 MTD_OPS_AUTO_OOB = 1,
43 MTD_OPS_RAW = 2,
44};
45
Wolfgang Denk932394a2005-08-17 12:55:25 +020046#define MTD_ABSENT 0
47#define MTD_RAM 1
48#define MTD_ROM 2
49#define MTD_NORFLASH 3
50#define MTD_NANDFLASH 4
William Juulcfa460a2007-10-31 13:53:06 +010051#define MTD_DATAFLASH 6
52#define MTD_UBIVOLUME 7
Wolfgang Denk932394a2005-08-17 12:55:25 +020053
William Juulcfa460a2007-10-31 13:53:06 +010054#define MTD_WRITEABLE 0x400 /* Device is writeable */
55#define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
56#define MTD_NO_ERASE 0x1000 /* No erase necessary */
57#define MTD_STUPID_LOCK 0x2000 /* Always locked after reset */
Wolfgang Denk932394a2005-08-17 12:55:25 +020058
Wolfgang Denk4b070802008-08-14 14:41:06 +020059/* Some common devices / combinations of capabilities */
Wolfgang Denk932394a2005-08-17 12:55:25 +020060#define MTD_CAP_ROM 0
William Juulcfa460a2007-10-31 13:53:06 +010061#define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
62#define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
63#define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
Wolfgang Denk932394a2005-08-17 12:55:25 +020064
65/* ECC byte placement */
Wolfgang Denk4b070802008-08-14 14:41:06 +020066#define MTD_NANDECC_OFF 0 /* Switch off ECC (Not recommended) */
67#define MTD_NANDECC_PLACE 1 /* Use the given placement in the structure (YAFFS1 legacy mode) */
68#define MTD_NANDECC_AUTOPLACE 2 /* Use the default placement scheme */
69#define MTD_NANDECC_PLACEONLY 3 /* Use the given placement in the structure (Do not store ecc result on read) */
70#define MTD_NANDECC_AUTOPL_USR 4 /* Use the given autoplacement scheme rather than using the default */
William Juulcfa460a2007-10-31 13:53:06 +010071
72/* OTP mode selection */
73#define MTD_OTP_OFF 0
74#define MTD_OTP_FACTORY 1
75#define MTD_OTP_USER 2
Wolfgang Denk932394a2005-08-17 12:55:25 +020076
77struct mtd_info_user {
78 uint8_t type;
79 uint32_t flags;
Wolfgang Denk4b070802008-08-14 14:41:06 +020080 uint32_t size; /* Total size of the MTD */
Wolfgang Denk932394a2005-08-17 12:55:25 +020081 uint32_t erasesize;
William Juulcfa460a2007-10-31 13:53:06 +010082 uint32_t writesize;
Wolfgang Denk4b070802008-08-14 14:41:06 +020083 uint32_t oobsize; /* Amount of OOB data per block (e.g. 16) */
William Juulcfa460a2007-10-31 13:53:06 +010084 /* The below two fields are obsolete and broken, do not use them
85 * (TODO: remove at some point) */
Wolfgang Denk932394a2005-08-17 12:55:25 +020086 uint32_t ecctype;
87 uint32_t eccsize;
88};
89
90struct region_info_user {
Wolfgang Denkac7eb8a2005-09-14 23:53:32 +020091 uint32_t offset; /* At which this region starts,
Wolfgang Denk932394a2005-08-17 12:55:25 +020092 * from the beginning of the MTD */
93 uint32_t erasesize; /* For this region */
94 uint32_t numblocks; /* Number of blocks in this region */
95 uint32_t regionindex;
96};
97
William Juulcfa460a2007-10-31 13:53:06 +010098struct otp_info {
99 uint32_t start;
100 uint32_t length;
101 uint32_t locked;
102};
103
Sergey Lapindfe64e22013-01-14 03:46:50 +0000104/* Get basic MTD characteristics info (better to use sysfs) */
William Juulcfa460a2007-10-31 13:53:06 +0100105#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000106/* Erase segment of MTD */
William Juulcfa460a2007-10-31 13:53:06 +0100107#define MEMERASE _IOW('M', 2, struct erase_info_user)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000108/* Write out-of-band data from MTD */
William Juulcfa460a2007-10-31 13:53:06 +0100109#define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000110/* Read out-of-band data from MTD */
William Juulcfa460a2007-10-31 13:53:06 +0100111#define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000112/* Lock a chip (for MTD that supports it) */
William Juulcfa460a2007-10-31 13:53:06 +0100113#define MEMLOCK _IOW('M', 5, struct erase_info_user)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000114/* Unlock a chip (for MTD that supports it) */
William Juulcfa460a2007-10-31 13:53:06 +0100115#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000116/* Get the number of different erase regions */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200117#define MEMGETREGIONCOUNT _IOR('M', 7, int)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000118/* Get information about the erase region for a specific index */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200119#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000120/* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200121#define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
122#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000123/* Check if an eraseblock is bad */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200124#define MEMGETBADBLOCK _IOW('M', 11, loff_t)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000125/* Mark an eraseblock as bad */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200126#define MEMSETBADBLOCK _IOW('M', 12, loff_t)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000127/* Set OTP (One-Time Programmable) mode (factory vs. user) */
William Juulcfa460a2007-10-31 13:53:06 +0100128#define OTPSELECT _IOR('M', 13, int)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000129/* Get number of OTP (One-Time Programmable) regions */
William Juulcfa460a2007-10-31 13:53:06 +0100130#define OTPGETREGIONCOUNT _IOW('M', 14, int)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000131/* Get all OTP (One-Time Programmable) info about MTD */
William Juulcfa460a2007-10-31 13:53:06 +0100132#define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000133/* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
William Juulcfa460a2007-10-31 13:53:06 +0100134#define OTPLOCK _IOR('M', 16, struct otp_info)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000135/* Get ECC layout (deprecated) */
William Juulcfa460a2007-10-31 13:53:06 +0100136#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000137/* Get statistics about corrected/uncorrected errors */
William Juulcfa460a2007-10-31 13:53:06 +0100138#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
Sergey Lapindfe64e22013-01-14 03:46:50 +0000139/* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
William Juulcfa460a2007-10-31 13:53:06 +0100140#define MTDFILEMODE _IO('M', 19)
Wolfgang Denk932394a2005-08-17 12:55:25 +0200141
William Juulcfa460a2007-10-31 13:53:06 +0100142/*
143 * Obsolete legacy interface. Keep it in order not to break userspace
144 * interfaces
145 */
Wolfgang Denk932394a2005-08-17 12:55:25 +0200146struct nand_oobinfo {
147 uint32_t useecc;
148 uint32_t eccbytes;
149 uint32_t oobfree[8][2];
Sergei Poselenov248ae5c2008-06-06 15:42:43 +0200150 uint32_t eccpos[48];
Wolfgang Denk932394a2005-08-17 12:55:25 +0200151};
152
William Juulcfa460a2007-10-31 13:53:06 +0100153struct nand_oobfree {
154 uint32_t offset;
155 uint32_t length;
156};
157
158#define MTD_MAX_OOBFREE_ENTRIES 8
159/*
160 * ECC layout control structure. Exported to userspace for
161 * diagnosis and to allow creation of raw images
162 */
163struct nand_ecclayout {
164 uint32_t eccbytes;
Sandeep Paulrajbb3e9822009-11-16 13:31:47 -0500165 uint32_t eccpos[128];
William Juulcfa460a2007-10-31 13:53:06 +0100166 uint32_t oobavail;
167 struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
168};
169
170/**
171 * struct mtd_ecc_stats - error correction stats
172 *
173 * @corrected: number of corrected bits
174 * @failed: number of uncorrectable errors
175 * @badblocks: number of bad blocks in this partition
176 * @bbtblocks: number of blocks reserved for bad block tables
177 */
178struct mtd_ecc_stats {
179 uint32_t corrected;
180 uint32_t failed;
181 uint32_t badblocks;
182 uint32_t bbtblocks;
183};
184
185/*
Sergey Lapindfe64e22013-01-14 03:46:50 +0000186 * MTD file modes - for read/write access to MTD
187 *
188 * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled
189 * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode
190 * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode
191 * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled
192 *
193 * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained
194 * separately for each open file descriptor.
195 *
196 * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
197 * raw access to the flash, without error correction or autoplacement schemes.
198 * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
199 * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
200 * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
William Juulcfa460a2007-10-31 13:53:06 +0100201 */
202enum mtd_file_modes {
203 MTD_MODE_NORMAL = MTD_OTP_OFF,
204 MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
205 MTD_MODE_OTP_USER = MTD_OTP_USER,
206 MTD_MODE_RAW,
207};
208
Wolfgang Denk932394a2005-08-17 12:55:25 +0200209#endif /* __MTD_ABI_H__ */