2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2009-2012 Semihalf
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _NANDSIM_CHIP_H
32 #define _NANDSIM_CHIP_H
34 #include <sys/malloc.h>
35 #include <sys/callout.h>
36 #include <dev/nand/nand.h>
37 #include <dev/nand/nandsim.h>
38 #include <dev/nand/nandsim_swap.h>
40 MALLOC_DECLARE(M_NANDSIM);
45 typedef void nandsim_evh_t(struct nandsim_chip *chip, uint32_t ev, void *data);
54 struct nandsim_softc {
55 struct nand_softc nand_dev;
58 struct nandsim_chip *chips[MAX_CS_NUM];
59 struct nandsim_chip *active_chip;
61 uint8_t address_cycle;
62 enum addr_type address_type;
69 STAILQ_ENTRY(nandsim_ev) links;
70 struct nandsim_chip *chip;
81 struct nandsim_block_state {
86 #define NANDSIM_CHIP_ACTIVE 0x1
87 #define NANDSIM_CHIP_FROZEN 0x2
88 #define NANDSIM_CHIP_GET_STATUS 0x4
91 struct nandsim_softc *sc;
92 struct thread *nandsim_td;
94 STAILQ_HEAD(, nandsim_ev) nandsim_events;
95 nandsim_evh_t *ev_handler;
97 struct callout ns_callout;
101 struct onfi_params params;
102 struct nandsim_data data;
103 struct nandsim_block_state *blk_state;
105 struct chip_swap *swap;
107 uint32_t error_ratio;
110 uint32_t sm_addr_cycle;
112 uint32_t erase_delay;
115 struct timeval delay_tv;
123 struct sim_ctrl_conf {
129 device_t sim_ctrl_dev;
130 struct sim_chip *chips[MAX_CTRL_CS];
131 uint16_t ecc_layout[MAX_ECC_BYTES];
132 char filename[FILENAME_SIZE];
135 #define NANDSIM_STATE_IDLE 0x0
136 #define NANDSIM_STATE_WAIT_ADDR_BYTE 0x1
137 #define NANDSIM_STATE_WAIT_CMD 0x2
138 #define NANDSIM_STATE_TIMEOUT 0x3
139 #define NANDSIM_STATE_WAIT_ADDR_ROW 0x4
140 #define NANDSIM_STATE_WAIT_ADDR_COL 0x5
142 #define NANDSIM_EV_START 0x1
143 #define NANDSIM_EV_CMD 0x2
144 #define NANDSIM_EV_ADDR 0x3
145 #define NANDSIM_EV_TIMEOUT 0x4
146 #define NANDSIM_EV_EXIT 0xff
148 struct nandsim_chip *nandsim_chip_init(struct nandsim_softc *,
149 uint8_t, struct sim_chip *);
150 void nandsim_chip_destroy(struct nandsim_chip *);
151 void nandsim_chip_freeze(struct nandsim_chip *);
152 void nandsim_chip_timeout(struct nandsim_chip *);
153 int nandsim_chip_check_bad_block(struct nandsim_chip *, int);
155 uint8_t nandchip_get_status(struct nandsim_chip *);
157 void destroy_event(struct nandsim_ev *);
158 int send_event(struct nandsim_ev *);
159 struct nandsim_ev *create_event(struct nandsim_chip *, uint8_t, uint8_t);
161 #endif /* _NANDSIM_CHIP_H */