1 /* $NetBSD: flashio.h,v 1.3 2011/04/04 18:23:39 ahoka Exp $ */ 2 3 /*- 4 * Copyright (c) 2011 Department of Software Engineering, 5 * University of Szeged, Hungary 6 * Copyright (c) 2011 Adam Hoka <ahoka@NetBSD.org> 7 * Copyright (c) 2010 David Tengeri <dtengeri@inf.u-szeged.hu> 8 * All rights reserved. 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by the Department of Software Engineering, University of Szeged, Hungary 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #ifndef _FLASHIO_H_ 36 #define _FLASHIO_H_ 37 38 #include <sys/ioctl.h> 39 40 /* this header may be used fron the kernel */ 41 #if defined(_KERNEL) || defined(_STANDALONE) 42 #include <sys/types.h> 43 #else 44 #include <stdint.h> 45 #include <stdbool.h> 46 #endif 47 48 enum { 49 FLASH_ERASE_DONE = 0x0, 50 FLASH_ERASE_FAILED = 0x1 51 }; 52 53 enum { 54 FLASH_TYPE_UNKNOWN = 0x0, 55 FLASH_TYPE_NOR = 0x1, 56 FLASH_TYPE_NAND = 0x2 57 }; 58 59 /* public userspace API */ 60 61 /* common integer type to address flash */ 62 typedef int64_t flash_off_t; 63 typedef uint64_t flash_size_t; 64 65 /** 66 * struct erase_params - for ioctl erase call 67 * @addr: start address of the erase 68 * @len: length of the erase 69 */ 70 struct flash_erase_params { 71 flash_off_t ep_addr; 72 flash_off_t ep_len; 73 }; 74 75 struct flash_badblock_params { 76 flash_off_t bbp_addr; 77 bool bbp_isbad; 78 }; 79 80 struct flash_info_params { 81 flash_off_t ip_flash_size; 82 flash_size_t ip_page_size; 83 flash_size_t ip_erase_size; 84 uint8_t ip_flash_type; 85 }; 86 87 struct flash_dump_params { 88 flash_off_t dp_block; 89 flash_off_t dp_len; 90 uint8_t *dp_buf; 91 }; 92 93 enum { 94 FLASH_IOCTL_ERASE_BLOCK, 95 FLASH_IOCTL_DUMP, 96 FLASH_IOCTL_GET_INFO, 97 FLASH_IOCTL_BLOCK_ISBAD, 98 FLASH_IOCTL_BLOCK_MARKBAD 99 }; 100 101 #define FLASH_ERASE_BLOCK \ 102 _IOW('&', FLASH_IOCTL_ERASE_BLOCK, struct flash_erase_params) 103 104 #define FLASH_DUMP \ 105 _IOWR('&', FLASH_IOCTL_DUMP, struct flash_dump_params) 106 107 #define FLASH_GET_INFO \ 108 _IOWR('&', FLASH_IOCTL_GET_INFO, struct flash_info_params) 109 110 #define FLASH_BLOCK_ISBAD \ 111 _IOWR('&', FLASH_IOCTL_BLOCK_ISBAD, struct flash_badblock_params) 112 113 #define FLASH_BLOCK_MARKBAD \ 114 _IOW('&', FLASH_IOCTL_BLOCK_MARKBAD, struct flash_badblock_params) 115 116 #endif 117 118