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