[binutils, ARM, 5/16] BF insns infrastructure with new global reloc R_ARM_THM_BF16
[binutils-gdb.git] / sim / bfin / dv-bfin_nfc.c
blob6571a0e2b046108a5730f6d9d610df37a8907015
1 /* Blackfin NAND Flash Memory Controller (NFC) model
3 Copyright (C) 2010-2019 Free Software Foundation, Inc.
4 Contributed by Analog Devices, Inc.
6 This file is part of simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "config.h"
23 #include "sim-main.h"
24 #include "devices.h"
25 #include "dv-bfin_nfc.h"
27 /* XXX: This is merely a stub. */
29 struct bfin_nfc
31 /* This top portion matches common dv_bfin struct. */
32 bu32 base;
33 struct hw *dma_master;
34 bool acked;
36 struct hw_event *handler;
37 char saved_byte;
38 int saved_count;
40 /* Order after here is important -- matches hardware MMR layout. */
41 bu16 BFIN_MMR_16(ctl);
42 bu16 BFIN_MMR_16(stat);
43 bu16 BFIN_MMR_16(irqstat);
44 bu16 BFIN_MMR_16(irqmask);
45 bu16 BFIN_MMR_16(ecc0);
46 bu16 BFIN_MMR_16(ecc1);
47 bu16 BFIN_MMR_16(ecc2);
48 bu16 BFIN_MMR_16(ecc3);
49 bu16 BFIN_MMR_16(count);
50 bu16 BFIN_MMR_16(rst);
51 bu16 BFIN_MMR_16(pgctl);
52 bu16 BFIN_MMR_16(read);
53 bu32 _pad0[4];
54 bu16 BFIN_MMR_16(addr);
55 bu16 BFIN_MMR_16(cmd);
56 bu16 BFIN_MMR_16(data_wr);
57 bu16 BFIN_MMR_16(data_rd);
59 #define mmr_base() offsetof(struct bfin_nfc, ctl)
60 #define mmr_offset(mmr) (offsetof(struct bfin_nfc, mmr) - mmr_base())
61 #define mmr_idx(mmr) (mmr_offset (mmr) / 4)
63 static const char * const mmr_names[] =
65 "NFC_CTL", "NFC_STAT", "NFC_IRQSTAT", "NFC_IRQMASK", "NFC_ECC0", "NFC_ECC1",
66 "NFC_ECC2", "NFC_ECC3", "NFC_COUNT", "NFC_RST", "NFC_PGCTL", "NFC_READ",
67 [mmr_idx (addr)] = "NFC_ADDR", "NFC_CMD", "NFC_DATA_WR", "NFC_DATA_RD",
69 #define mmr_name(off) (mmr_names[(off) / 4] ? : "<INV>")
71 static unsigned
72 bfin_nfc_io_write_buffer (struct hw *me, const void *source, int space,
73 address_word addr, unsigned nr_bytes)
75 struct bfin_nfc *nfc = hw_data (me);
76 bu32 mmr_off;
77 bu32 value;
78 bu16 *valuep;
80 /* Invalid access mode is higher priority than missing register. */
81 if (!dv_bfin_mmr_require_16 (me, addr, nr_bytes, true))
82 return 0;
84 value = dv_load_2 (source);
85 mmr_off = addr - nfc->base;
86 valuep = (void *)((unsigned long)nfc + mmr_base() + mmr_off);
88 HW_TRACE_WRITE ();
90 switch (mmr_off)
92 case mmr_offset(ctl):
93 case mmr_offset(stat):
94 case mmr_offset(irqmask):
95 case mmr_offset(ecc0):
96 case mmr_offset(ecc1):
97 case mmr_offset(ecc2):
98 case mmr_offset(ecc3):
99 case mmr_offset(count):
100 case mmr_offset(rst):
101 case mmr_offset(pgctl):
102 case mmr_offset(read):
103 case mmr_offset(addr):
104 case mmr_offset(cmd):
105 case mmr_offset(data_wr):
106 *valuep = value;
107 break;
108 case mmr_offset(data_rd):
109 nfc->irqstat |= RD_RDY;
110 *valuep = value;
111 break;
112 case mmr_offset(irqstat):
113 dv_w1c_2 (valuep, value, -1);
114 break;
115 default:
116 dv_bfin_mmr_invalid (me, addr, nr_bytes, true);
117 return 0;
120 return nr_bytes;
123 static unsigned
124 bfin_nfc_io_read_buffer (struct hw *me, void *dest, int space,
125 address_word addr, unsigned nr_bytes)
127 struct bfin_nfc *nfc = hw_data (me);
128 bu32 mmr_off;
129 bu16 *valuep;
131 /* Invalid access mode is higher priority than missing register. */
132 if (!dv_bfin_mmr_require_16 (me, addr, nr_bytes, false))
133 return 0;
135 mmr_off = addr - nfc->base;
136 valuep = (void *)((unsigned long)nfc + mmr_base() + mmr_off);
138 HW_TRACE_READ ();
140 switch (mmr_off)
142 case mmr_offset(ctl):
143 case mmr_offset(stat):
144 case mmr_offset(irqstat):
145 case mmr_offset(irqmask):
146 case mmr_offset(ecc0):
147 case mmr_offset(ecc1):
148 case mmr_offset(ecc2):
149 case mmr_offset(ecc3):
150 case mmr_offset(count):
151 case mmr_offset(rst):
152 case mmr_offset(read):
153 dv_store_2 (dest, *valuep);
154 break;
155 case mmr_offset(pgctl):
156 case mmr_offset(addr):
157 case mmr_offset(cmd):
158 case mmr_offset(data_wr):
159 case mmr_offset(data_rd):
160 /* These regs are write only. */
161 default:
162 dv_bfin_mmr_invalid (me, addr, nr_bytes, false);
163 return 0;
166 return nr_bytes;
169 static unsigned
170 bfin_nfc_dma_read_buffer (struct hw *me, void *dest, int space,
171 unsigned_word addr, unsigned nr_bytes)
173 HW_TRACE_DMA_READ ();
174 return 0;
177 static unsigned
178 bfin_nfc_dma_write_buffer (struct hw *me, const void *source,
179 int space, unsigned_word addr,
180 unsigned nr_bytes,
181 int violate_read_only_section)
183 HW_TRACE_DMA_WRITE ();
184 return nr_bytes;
187 static const struct hw_port_descriptor bfin_nfc_ports[] =
189 { "stat", 0, 0, output_port, },
190 { NULL, 0, 0, 0, },
193 static void
194 attach_bfin_nfc_regs (struct hw *me, struct bfin_nfc *nfc)
196 address_word attach_address;
197 int attach_space;
198 unsigned attach_size;
199 reg_property_spec reg;
201 if (hw_find_property (me, "reg") == NULL)
202 hw_abort (me, "Missing \"reg\" property");
204 if (!hw_find_reg_array_property (me, "reg", 0, &reg))
205 hw_abort (me, "\"reg\" property must contain three addr/size entries");
207 hw_unit_address_to_attach_address (hw_parent (me),
208 &reg.address,
209 &attach_space, &attach_address, me);
210 hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
212 if (attach_size != BFIN_MMR_NFC_SIZE)
213 hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_NFC_SIZE);
215 hw_attach_address (hw_parent (me),
216 0, attach_space, attach_address, attach_size, me);
218 nfc->base = attach_address;
221 static void
222 bfin_nfc_finish (struct hw *me)
224 struct bfin_nfc *nfc;
226 nfc = HW_ZALLOC (me, struct bfin_nfc);
228 set_hw_data (me, nfc);
229 set_hw_io_read_buffer (me, bfin_nfc_io_read_buffer);
230 set_hw_io_write_buffer (me, bfin_nfc_io_write_buffer);
231 set_hw_dma_read_buffer (me, bfin_nfc_dma_read_buffer);
232 set_hw_dma_write_buffer (me, bfin_nfc_dma_write_buffer);
233 set_hw_ports (me, bfin_nfc_ports);
235 attach_bfin_nfc_regs (me, nfc);
237 /* Initialize the NFC. */
238 nfc->ctl = 0x0200;
239 nfc->stat = 0x0011;
240 nfc->irqstat = 0x0004;
241 nfc->irqmask = 0x001F;
244 const struct hw_descriptor dv_bfin_nfc_descriptor[] =
246 {"bfin_nfc", bfin_nfc_finish,},
247 {NULL, NULL},