/*
 * Copyright (c) 2000-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * sys/flashio.h: raw flash memory ioctl interface
 */


#ifndef _sys_flashio_H_
#define _sys_flashio_H_

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Information structure returned by the flashinfo() function
 */
struct flashinfo {
    char 		name[32];	/* dev name */
    unsigned long	base;		/* dev base (phys address) */
    unsigned int	size;		/* dev size */
    unsigned long	mapbase; 	/* memory mapped base (phys addr) */
    unsigned char	unit;		/* unit byte size (1,2,4,8 or 16) */
    unsigned int	maxssize; 	/* maximum sector size */
    unsigned int	soffs;		/* base offset of specified sector */
    unsigned int	ssize;		/* size of specified sector */
    int			sprot;		/* specified sector is protected */
};


/* flash partition information */
struct flashpart {
    int			type;		/* partition type */
    unsigned int	offs;		/* base of partition */
    unsigned int	size;		/* size of partition */
};


#define FLASHNPART	8		/* max number of partitions */

/* partition table */
struct flashparts {
    struct flashpart	part[FLASHNPART];
};


/* flash partition types */
#define FLASHPART_RAW		0	/* raw (whole) device */
#define FLASHPART_BOOT		1	/* boot partition */
#define FLASHPART_POST		2	/* post partition (self test) */
#define FLASHPART_ENV		3	/* non-volatile environment */
#define FLASHPART_FFS		4	/* flash file system partition */
#define FLASHPART_UNDEF		255	/* undefined partition */

/* programming/access mode flags */
#define FLASHFLGS_REBOOT	0x01	/* reboot after next write */
#define FLASHFLGS_NOCOPY	0x02	/* don't copy prog code to ram */
#define FLASHFLGS_MERGE		0x04	/* merge partially written sectors */
#define FLASHFLGS_CODE_EB	0x08	/* access as if big-endian code */
#define FLASHFLGS_CODE_EL	0x00	/* access as if little-endian code */
#if #endian(big)
#define FLASHFLGS_CODE		FLASHFLGS_CODE_EB
#else
#define FLASHFLGS_CODE		FLASHFLGS_CODE_EL
#endif
#define FLASHFLGS_STREAM	0x10	/* access as byte stream */

/* ioctl interface */
#define	FLASHIOINFO	 _IOWR('h', 0, struct flashinfo)/* get flash info */
#define	FLASHIOGPART	 _IOR('h', 1, struct flashpart) /* get partition */
#define	FLASHIOGFLGS	 _IOR('h', 2, unsigned int)	/* get flags */
#define	FLASHIOSFLGS	 _IOW('h', 3, unsigned int)	/* set flags */
#define	FLASHIOERASEDEV	 _IO('h', 4)			/* erase device */
#define	FLASHIOERASESECT _IOW('h', 5, unsigned int)	/* erase sector */
#define	FLASHIOGPARTS	 _IOR('h', 7, struct flashparts)/* get all partns */
#define	FLASHIOSPARTS	 _IOR('h', 8, struct flashparts)/* set all partns */
#define	FLASHIOFLUSH	 _IO('h', 9) 			/* flush writes */

#ifdef __cplusplus
}
#endif

#endif /* _sys_flashio_H_ */
