Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
0004  *
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0018  *
0019  */
0020 
0021 #ifndef __MTD_ABI_H__
0022 #define __MTD_ABI_H__
0023 
0024 #include <linux/types.h>
0025 
0026 struct erase_info_user {
0027     __u32 start;
0028     __u32 length;
0029 };
0030 
0031 struct erase_info_user64 {
0032     __u64 start;
0033     __u64 length;
0034 };
0035 
0036 struct mtd_oob_buf {
0037     __u32 start;
0038     __u32 length;
0039     unsigned char __user *ptr;
0040 };
0041 
0042 struct mtd_oob_buf64 {
0043     __u64 start;
0044     __u32 pad;
0045     __u32 length;
0046     __u64 usr_ptr;
0047 };
0048 
0049 /**
0050  * MTD operation modes
0051  *
0052  * @MTD_OPS_PLACE_OOB:  OOB data are placed at the given offset (default)
0053  * @MTD_OPS_AUTO_OOB:   OOB data are automatically placed at the free areas
0054  *          which are defined by the internal ecclayout
0055  * @MTD_OPS_RAW:    data are transferred as-is, with no error correction;
0056  *          this mode implies %MTD_OPS_PLACE_OOB
0057  *
0058  * These modes can be passed to ioctl(MEMWRITE) and are also used internally.
0059  * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
0060  * %MTD_FILE_MODE_RAW.
0061  */
0062 enum {
0063     MTD_OPS_PLACE_OOB = 0,
0064     MTD_OPS_AUTO_OOB = 1,
0065     MTD_OPS_RAW = 2,
0066 };
0067 
0068 /**
0069  * struct mtd_write_req - data structure for requesting a write operation
0070  *
0071  * @start:  start address
0072  * @len:    length of data buffer (only lower 32 bits are used)
0073  * @ooblen: length of OOB buffer (only lower 32 bits are used)
0074  * @usr_data:   user-provided data buffer
0075  * @usr_oob:    user-provided OOB buffer
0076  * @mode:   MTD mode (see "MTD operation modes")
0077  * @padding:    reserved, must be set to 0
0078  *
0079  * This structure supports ioctl(MEMWRITE) operations, allowing data and/or OOB
0080  * writes in various modes. To write to OOB-only, set @usr_data == NULL, and to
0081  * write data-only, set @usr_oob == NULL. However, setting both @usr_data and
0082  * @usr_oob to NULL is not allowed.
0083  */
0084 struct mtd_write_req {
0085     __u64 start;
0086     __u64 len;
0087     __u64 ooblen;
0088     __u64 usr_data;
0089     __u64 usr_oob;
0090     __u8 mode;
0091     __u8 padding[7];
0092 };
0093 
0094 #define MTD_ABSENT      0
0095 #define MTD_RAM         1
0096 #define MTD_ROM         2
0097 #define MTD_NORFLASH        3
0098 #define MTD_NANDFLASH       4   /* SLC NAND */
0099 #define MTD_DATAFLASH       6
0100 #define MTD_UBIVOLUME       7
0101 #define MTD_MLCNANDFLASH    8   /* MLC NAND (including TLC) */
0102 
0103 #define MTD_WRITEABLE       0x400   /* Device is writeable */
0104 #define MTD_BIT_WRITEABLE   0x800   /* Single bits can be flipped */
0105 #define MTD_NO_ERASE        0x1000  /* No erase necessary */
0106 #define MTD_POWERUP_LOCK    0x2000  /* Always locked after reset */
0107 #define MTD_SLC_ON_MLC_EMULATION 0x4000 /* Emulate SLC behavior on MLC NANDs */
0108 
0109 /* Some common devices / combinations of capabilities */
0110 #define MTD_CAP_ROM     0
0111 #define MTD_CAP_RAM     (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
0112 #define MTD_CAP_NORFLASH    (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
0113 #define MTD_CAP_NANDFLASH   (MTD_WRITEABLE)
0114 #define MTD_CAP_NVRAM       (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
0115 
0116 /* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */
0117 #define MTD_NANDECC_OFF     0   /* Switch off ECC (Not recommended) */
0118 #define MTD_NANDECC_PLACE   1   /* Use the given placement in the structure (YAFFS1 legacy mode) */
0119 #define MTD_NANDECC_AUTOPLACE   2   /* Use the default placement scheme */
0120 #define MTD_NANDECC_PLACEONLY   3   /* Use the given placement in the structure (Do not store ecc result on read) */
0121 #define MTD_NANDECC_AUTOPL_USR  4   /* Use the given autoplacement scheme rather than using the default */
0122 
0123 /* OTP mode selection */
0124 #define MTD_OTP_OFF     0
0125 #define MTD_OTP_FACTORY     1
0126 #define MTD_OTP_USER        2
0127 
0128 struct mtd_info_user {
0129     __u8 type;
0130     __u32 flags;
0131     __u32 size; /* Total size of the MTD */
0132     __u32 erasesize;
0133     __u32 writesize;
0134     __u32 oobsize;  /* Amount of OOB data per block (e.g. 16) */
0135     __u64 padding;  /* Old obsolete field; do not use */
0136 };
0137 
0138 struct region_info_user {
0139     __u32 offset;       /* At which this region starts,
0140                  * from the beginning of the MTD */
0141     __u32 erasesize;    /* For this region */
0142     __u32 numblocks;    /* Number of blocks in this region */
0143     __u32 regionindex;
0144 };
0145 
0146 struct otp_info {
0147     __u32 start;
0148     __u32 length;
0149     __u32 locked;
0150 };
0151 
0152 /*
0153  * Note, the following ioctl existed in the past and was removed:
0154  * #define MEMSETOOBSEL           _IOW('M', 9, struct nand_oobinfo)
0155  * Try to avoid adding a new ioctl with the same ioctl number.
0156  */
0157 
0158 /* Get basic MTD characteristics info (better to use sysfs) */
0159 #define MEMGETINFO      _IOR('M', 1, struct mtd_info_user)
0160 /* Erase segment of MTD */
0161 #define MEMERASE        _IOW('M', 2, struct erase_info_user)
0162 /* Write out-of-band data from MTD */
0163 #define MEMWRITEOOB     _IOWR('M', 3, struct mtd_oob_buf)
0164 /* Read out-of-band data from MTD */
0165 #define MEMREADOOB      _IOWR('M', 4, struct mtd_oob_buf)
0166 /* Lock a chip (for MTD that supports it) */
0167 #define MEMLOCK         _IOW('M', 5, struct erase_info_user)
0168 /* Unlock a chip (for MTD that supports it) */
0169 #define MEMUNLOCK       _IOW('M', 6, struct erase_info_user)
0170 /* Get the number of different erase regions */
0171 #define MEMGETREGIONCOUNT   _IOR('M', 7, int)
0172 /* Get information about the erase region for a specific index */
0173 #define MEMGETREGIONINFO    _IOWR('M', 8, struct region_info_user)
0174 /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
0175 #define MEMGETOOBSEL        _IOR('M', 10, struct nand_oobinfo)
0176 /* Check if an eraseblock is bad */
0177 #define MEMGETBADBLOCK      _IOW('M', 11, __kernel_loff_t)
0178 /* Mark an eraseblock as bad */
0179 #define MEMSETBADBLOCK      _IOW('M', 12, __kernel_loff_t)
0180 /* Set OTP (One-Time Programmable) mode (factory vs. user) */
0181 #define OTPSELECT       _IOR('M', 13, int)
0182 /* Get number of OTP (One-Time Programmable) regions */
0183 #define OTPGETREGIONCOUNT   _IOW('M', 14, int)
0184 /* Get all OTP (One-Time Programmable) info about MTD */
0185 #define OTPGETREGIONINFO    _IOW('M', 15, struct otp_info)
0186 /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
0187 #define OTPLOCK         _IOR('M', 16, struct otp_info)
0188 /* Get ECC layout (deprecated) */
0189 #define ECCGETLAYOUT        _IOR('M', 17, struct nand_ecclayout_user)
0190 /* Get statistics about corrected/uncorrected errors */
0191 #define ECCGETSTATS     _IOR('M', 18, struct mtd_ecc_stats)
0192 /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
0193 #define MTDFILEMODE     _IO('M', 19)
0194 /* Erase segment of MTD (supports 64-bit address) */
0195 #define MEMERASE64      _IOW('M', 20, struct erase_info_user64)
0196 /* Write data to OOB (64-bit version) */
0197 #define MEMWRITEOOB64       _IOWR('M', 21, struct mtd_oob_buf64)
0198 /* Read data from OOB (64-bit version) */
0199 #define MEMREADOOB64        _IOWR('M', 22, struct mtd_oob_buf64)
0200 /* Check if chip is locked (for MTD that supports it) */
0201 #define MEMISLOCKED     _IOR('M', 23, struct erase_info_user)
0202 /*
0203  * Most generic write interface; can write in-band and/or out-of-band in various
0204  * modes (see "struct mtd_write_req"). This ioctl is not supported for flashes
0205  * without OOB, e.g., NOR flash.
0206  */
0207 #define MEMWRITE        _IOWR('M', 24, struct mtd_write_req)
0208 /* Erase a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
0209 #define OTPERASE        _IOW('M', 25, struct otp_info)
0210 
0211 /*
0212  * Obsolete legacy interface. Keep it in order not to break userspace
0213  * interfaces
0214  */
0215 struct nand_oobinfo {
0216     __u32 useecc;
0217     __u32 eccbytes;
0218     __u32 oobfree[8][2];
0219     __u32 eccpos[32];
0220 };
0221 
0222 struct nand_oobfree {
0223     __u32 offset;
0224     __u32 length;
0225 };
0226 
0227 #define MTD_MAX_OOBFREE_ENTRIES 8
0228 #define MTD_MAX_ECCPOS_ENTRIES  64
0229 /*
0230  * OBSOLETE: ECC layout control structure. Exported to user-space via ioctl
0231  * ECCGETLAYOUT for backwards compatbility and should not be mistaken as a
0232  * complete set of ECC information. The ioctl truncates the larger internal
0233  * structure to retain binary compatibility with the static declaration of the
0234  * ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of
0235  * the user struct, not the MAX size of the internal OOB layout representation.
0236  */
0237 struct nand_ecclayout_user {
0238     __u32 eccbytes;
0239     __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES];
0240     __u32 oobavail;
0241     struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
0242 };
0243 
0244 /**
0245  * struct mtd_ecc_stats - error correction stats
0246  *
0247  * @corrected:  number of corrected bits
0248  * @failed: number of uncorrectable errors
0249  * @badblocks:  number of bad blocks in this partition
0250  * @bbtblocks:  number of blocks reserved for bad block tables
0251  */
0252 struct mtd_ecc_stats {
0253     __u32 corrected;
0254     __u32 failed;
0255     __u32 badblocks;
0256     __u32 bbtblocks;
0257 };
0258 
0259 /*
0260  * MTD file modes - for read/write access to MTD
0261  *
0262  * @MTD_FILE_MODE_NORMAL:   OTP disabled, ECC enabled
0263  * @MTD_FILE_MODE_OTP_FACTORY:  OTP enabled in factory mode
0264  * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode
0265  * @MTD_FILE_MODE_RAW:      OTP disabled, ECC disabled
0266  *
0267  * These modes can be set via ioctl(MTDFILEMODE). The mode will be retained
0268  * separately for each open file descriptor.
0269  *
0270  * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
0271  * raw access to the flash, without error correction or autoplacement schemes.
0272  * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
0273  * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
0274  * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
0275  */
0276 enum mtd_file_modes {
0277     MTD_FILE_MODE_NORMAL = MTD_OTP_OFF,
0278     MTD_FILE_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
0279     MTD_FILE_MODE_OTP_USER = MTD_OTP_USER,
0280     MTD_FILE_MODE_RAW,
0281 };
0282 
0283 static inline int mtd_type_is_nand_user(const struct mtd_info_user *mtd)
0284 {
0285     return mtd->type == MTD_NANDFLASH || mtd->type == MTD_MLCNANDFLASH;
0286 }
0287 
0288 #endif /* __MTD_ABI_H__ */