xref: /freebsd/sys/dev/cfi/cfi_var.h (revision e30a620063b852f51e8955dd6f993680d5da6223)
1 /*-
2  * Copyright (c) 2007, Juniper Networks, Inc.
3  * Copyright (c) 2012-2013, SRI International
4  * All rights reserved.
5  *
6  * Portions of this software were developed by SRI International and the
7  * University of Cambridge Computer Laboratory under DARPA/AFRL contract
8  * (FA8750-10-C-0237) ("CTSRD"), as part of the DARPA CRASH research
9  * programme.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the author nor the names of any co-contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * $FreeBSD$
36  */
37 
38 #ifndef _DEV_CFI_VAR_H_
39 #define	_DEV_CFI_VAR_H_
40 
41 enum cfi_wait_cmd {
42 	CFI_TIMEOUT_ERASE,
43 	CFI_TIMEOUT_WRITE,
44 	CFI_TIMEOUT_BUFWRITE
45 };
46 
47 struct cfi_region {
48 	u_int		r_blocks;
49 	u_int		r_blksz;
50 };
51 
52 struct cfi_softc {
53 	device_t	sc_dev;
54 
55 	struct resource	*sc_res;
56 	bus_space_handle_t sc_handle;
57 	bus_space_tag_t	sc_tag;
58 	int		sc_rid;
59 
60 	u_int		sc_size;	/* Flash size. */
61 	u_int		sc_width;	/* Interface width. */
62 	u_int		sc_regions;	/* Erase regions. */
63 	struct cfi_region *sc_region;	/* Array of region info. */
64 
65 	u_int		sc_cmdset;
66 	sbintime_t	sc_typical_timeouts[3];
67 	sbintime_t	sc_max_timeouts[3];
68 	u_int		sc_tto_counts[3];
69 	u_int		sc_mto_counts[3];
70 
71 	u_int		sc_maxbuf;
72 
73 	struct cdev	*sc_nod;
74 	struct proc	*sc_opened;	/* Process that has us opened. */
75 
76 	u_char		*sc_wrbuf;
77 	u_char		*sc_wrbufcpy;
78 	u_int		sc_wrbufsz;
79 	u_int		sc_wrofs;
80 	u_int		sc_writing;
81 };
82 
83 extern char cfi_driver_name[];
84 extern devclass_t cfi_devclass;
85 extern devclass_t cfi_diskclass;
86 
87 int cfi_probe(device_t);
88 int cfi_attach(device_t);
89 int cfi_detach(device_t);
90 
91 uint32_t cfi_read_raw(struct cfi_softc *, u_int);
92 uint32_t cfi_read(struct cfi_softc *, u_int);
93 uint8_t cfi_read_qry(struct cfi_softc *, u_int);
94 int cfi_write_block(struct cfi_softc *);
95 int cfi_block_start(struct cfi_softc *, u_int);
96 int cfi_block_finish(struct cfi_softc *);
97 
98 #ifdef CFI_SUPPORT_STRATAFLASH
99 int	cfi_intel_get_factory_pr(struct cfi_softc *sc, uint64_t *);
100 int	cfi_intel_get_oem_pr(struct cfi_softc *sc, uint64_t *);
101 int	cfi_intel_set_oem_pr(struct cfi_softc *sc, uint64_t);
102 int	cfi_intel_get_plr(struct cfi_softc *sc, uint32_t *);
103 int	cfi_intel_set_plr(struct cfi_softc *sc);
104 #endif /* CFI_SUPPORT_STRATAFLASH */
105 #endif /* _DEV_CFI_VAR_H_ */
106