]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/dev/isf/isf.h
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / sys / dev / isf / isf.h
1 /*-
2  * Copyright (c) 2012 Robert N. M. Watson
3  * Copyright (c) 2012 SRI International
4  * All rights reserved.
5  *
6  * This software was developed by SRI International and the University of
7  * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8  * ("CTSRD"), as part of the DARPA CRASH research programme.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33
34 #ifndef _DEV_ISF_H_
35 #define _DEV_ISF_H_
36
37 struct isf_range {
38         off_t   ir_off;         /* Offset of range to delete (set to 0xFF) */
39         size_t  ir_size;        /* Size of range */
40 };
41
42 #define ISF_ERASE       _IOW('I', 1, struct isf_range)
43
44 /*
45  * Ordinary read and write operations are limited to 512 bytes.
46  * We support erasing 128K blocks and ignore the fact that portions of the
47  * flash are in fact divided into 32K blocks.
48  */
49 #define ISF_SECTORSIZE  (512)
50 #define ISF_ERASE_BLOCK (128 * 1024)
51
52 #ifdef _KERNEL
53 MALLOC_DECLARE(M_ISF);
54
55 enum bstate {
56         BS_STEADY = 0,
57         BS_ERASING
58 };
59
60 struct isf_softc {
61         device_t                 isf_dev;
62         int                      isf_unit;
63         struct resource         *isf_res;
64         int                      isf_rid;
65         struct mtx               isf_lock;
66         struct disk             *isf_disk;
67         struct proc             *isf_proc;
68         int                      isf_doomed;
69
70         /*
71          * Fields relating to in-progress and pending I/O, if any.
72          */
73         struct bio_queue_head    isf_bioq;
74         uint16_t                 isf_rbuf[ISF_SECTORSIZE / 2];
75         int                      isf_erasing;
76         enum bstate             *isf_bstate;
77 };
78
79 #define ISF_LOCK(sc)            mtx_lock(&(sc)->isf_lock)
80 #define ISF_LOCK_ASSERT(sc)     mtx_assert(&(sc)->isf_lock, MA_OWNED)
81 #define ISF_LOCK_DESTROY(sc)    mtx_destroy(&(sc)->isf_lock)
82 #define ISF_LOCK_INIT(sc)       mtx_init(&(sc)->isf_lock, "isf", NULL,  \
83                                     MTX_DEF)
84 #define ISF_SLEEP(sc, wait, timo)       mtx_sleep((wait),               \
85                                             &(sc)->isf_lock, PRIBIO,    \
86                                             "isf", (timo))
87 #define ISF_UNLOCK(sc)                  mtx_unlock(&(sc)->isf_lock)
88 #define ISF_WAKEUP(sc)                  wakeup((sc))
89
90 int     isf_attach(struct isf_softc *sc);
91 void    isf_detach(struct isf_softc *sc);
92
93 extern devclass_t       isf_devclass;
94 #endif /* _KERNEL */
95
96 #endif  /* _DEV_ISF_H_ */