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