1184251Smarcel/*-
2184251Smarcel * Copyright (c) 2007, Juniper Networks, Inc.
3255207Sbrooks * Copyright (c) 2012-2013, SRI International
4184251Smarcel * All rights reserved.
5184251Smarcel *
6255207Sbrooks * Portions of this software were developed by SRI International and the
7255207Sbrooks * University of Cambridge Computer Laboratory under DARPA/AFRL contract
8255207Sbrooks * (FA8750-10-C-0237) ("CTSRD"), as part of the DARPA CRASH research
9255207Sbrooks * programme.
10255207Sbrooks *
11184251Smarcel * Redistribution and use in source and binary forms, with or without
12184251Smarcel * modification, are permitted provided that the following conditions
13184251Smarcel * are met:
14184251Smarcel * 1. Redistributions of source code must retain the above copyright
15184251Smarcel *    notice, this list of conditions and the following disclaimer.
16184251Smarcel * 2. Redistributions in binary form must reproduce the above copyright
17184251Smarcel *    notice, this list of conditions and the following disclaimer in the
18184251Smarcel *    documentation and/or other materials provided with the distribution.
19184251Smarcel * 3. Neither the name of the author nor the names of any co-contributors
20184251Smarcel *    may be used to endorse or promote products derived from this software
21184251Smarcel *    without specific prior written permission.
22184251Smarcel *
23184251Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24184251Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25184251Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26184251Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27184251Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28184251Smarcel * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29184251Smarcel * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30184251Smarcel * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31184251Smarcel * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32184251Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33184251Smarcel * SUCH DAMAGE.
34184251Smarcel *
35184251Smarcel * $FreeBSD$
36184251Smarcel */
37184251Smarcel
38184251Smarcel#ifndef _DEV_CFI_VAR_H_
39184251Smarcel#define	_DEV_CFI_VAR_H_
40184251Smarcel
41255207Sbrooksenum cfi_wait_cmd {
42255207Sbrooks	CFI_TIMEOUT_ERASE,
43255207Sbrooks	CFI_TIMEOUT_WRITE,
44255207Sbrooks	CFI_TIMEOUT_BUFWRITE
45255207Sbrooks};
46255207Sbrooks
47184251Smarcelstruct cfi_region {
48184251Smarcel	u_int		r_blocks;
49184251Smarcel	u_int		r_blksz;
50184251Smarcel};
51184251Smarcel
52184251Smarcelstruct cfi_softc {
53184251Smarcel	device_t	sc_dev;
54184251Smarcel
55184251Smarcel	struct resource	*sc_res;
56184251Smarcel	bus_space_handle_t sc_handle;
57184251Smarcel	bus_space_tag_t	sc_tag;
58184251Smarcel	int		sc_rid;
59184251Smarcel
60184251Smarcel	u_int		sc_size;	/* Flash size. */
61184251Smarcel	u_int		sc_width;	/* Interface width. */
62184251Smarcel	u_int		sc_regions;	/* Erase regions. */
63184251Smarcel	struct cfi_region *sc_region;	/* Array of region info. */
64184251Smarcel
65184251Smarcel	u_int		sc_cmdset;
66255207Sbrooks	sbintime_t	sc_typical_timeouts[3];
67255207Sbrooks	sbintime_t	sc_max_timeouts[3];
68255207Sbrooks	u_int		sc_tto_counts[3];
69255207Sbrooks	u_int		sc_mto_counts[3];
70184251Smarcel
71255207Sbrooks	u_int		sc_maxbuf;
72255207Sbrooks
73184251Smarcel	struct cdev	*sc_nod;
74184251Smarcel	struct proc	*sc_opened;	/* Process that has us opened. */
75184251Smarcel
76184251Smarcel	u_char		*sc_wrbuf;
77255207Sbrooks	u_char		*sc_wrbufcpy;
78184251Smarcel	u_int		sc_wrbufsz;
79184251Smarcel	u_int		sc_wrofs;
80184251Smarcel	u_int		sc_writing;
81184251Smarcel};
82184251Smarcel
83184251Smarcelextern char cfi_driver_name[];
84184251Smarcelextern devclass_t cfi_devclass;
85189606Ssamextern devclass_t cfi_diskclass;
86184251Smarcel
87184251Smarcelint cfi_probe(device_t);
88184251Smarcelint cfi_attach(device_t);
89184251Smarcelint cfi_detach(device_t);
90184251Smarcel
91233553Sjchandrauint32_t cfi_read_raw(struct cfi_softc *, u_int);
92184251Smarceluint32_t cfi_read(struct cfi_softc *, u_int);
93184251Smarceluint8_t cfi_read_qry(struct cfi_softc *, u_int);
94184251Smarcelint cfi_write_block(struct cfi_softc *);
95189606Ssamint cfi_block_start(struct cfi_softc *, u_int);
96189606Ssamint cfi_block_finish(struct cfi_softc *);
97184251Smarcel
98188156Ssam#ifdef CFI_SUPPORT_STRATAFLASH
99188156Ssamint	cfi_intel_get_factory_pr(struct cfi_softc *sc, uint64_t *);
100188156Ssamint	cfi_intel_get_oem_pr(struct cfi_softc *sc, uint64_t *);
101188156Ssamint	cfi_intel_set_oem_pr(struct cfi_softc *sc, uint64_t);
102188156Ssamint	cfi_intel_get_plr(struct cfi_softc *sc, uint32_t *);
103188156Ssamint	cfi_intel_set_plr(struct cfi_softc *sc);
104188156Ssam#endif /* CFI_SUPPORT_STRATAFLASH */
105184251Smarcel#endif /* _DEV_CFI_VAR_H_ */
106