1 /* Blackfin device support.
3 Copyright (C) 2010-2011 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/>. */
25 #include "hw-device.h"
26 #include "dv-bfin_cec.h"
27 #include "dv-bfin_mmu.h"
30 bfin_mmr_invalid (struct hw *me, SIM_CPU *cpu, address_word addr,
31 unsigned nr_bytes, bool write)
34 cpu = hw_system_cpu (me);
36 /* Only throw a fit if the cpu is doing the access. DMA/GDB simply
37 go unnoticed. Not exactly hardware behavior, but close enough. */
40 sim_io_eprintf (hw_system (me), "%s: invalid MMR access @ %#x\n",
45 HW_TRACE ((me, "invalid MMR %s to 0x%08lx length %u",
46 write ? "write" : "read", (unsigned long) addr, nr_bytes));
48 /* XXX: is this what hardware does ? */
49 if (addr >= BFIN_CORE_MMR_BASE)
50 /* XXX: This should be setting up CPLB fault addrs ? */
51 mmu_process_fault (cpu, addr, write, false, false, true);
53 /* XXX: Newer parts set up an interrupt from EBIU and program
54 EBIU_ERRADDR with the address. */
55 cec_hwerr (cpu, HWERR_SYSTEM_MMR);
59 dv_bfin_mmr_invalid (struct hw *me, address_word addr, unsigned nr_bytes,
62 bfin_mmr_invalid (me, NULL, addr, nr_bytes, write);
66 dv_bfin_mmr_require (struct hw *me, address_word addr, unsigned nr_bytes,
67 unsigned size, bool write)
70 dv_bfin_mmr_invalid (me, addr, nr_bytes, write);
74 bfin_mmr_check (struct hw *me, SIM_CPU *cpu, address_word addr,
75 unsigned nr_bytes, bool write)
77 if (addr >= BFIN_CORE_MMR_BASE)
79 /* All Core MMRs are aligned 32bits. */
80 if ((addr & 3) == 0 && nr_bytes == 4)
83 else if (addr >= BFIN_SYSTEM_MMR_BASE)
85 /* All System MMRs are 32bit aligned, but can be 16bits or 32bits. */
86 if ((addr & 0x3) == 0 && (nr_bytes == 2 || nr_bytes == 4))
92 /* Still here ? Must be crap. */
93 bfin_mmr_invalid (me, cpu, addr, nr_bytes, write);
99 dv_bfin_mmr_check (struct hw *me, address_word addr, unsigned nr_bytes,
102 return bfin_mmr_check (me, NULL, addr, nr_bytes, write);
106 device_io_read_buffer (device *me, void *source, int space,
107 address_word addr, unsigned nr_bytes,
108 SIM_DESC sd, SIM_CPU *cpu, sim_cia cia)
110 struct hw *dv_me = (struct hw *) me;
112 if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
115 if (bfin_mmr_check (dv_me, cpu, addr, nr_bytes, false))
118 sim_cpu_hw_io_read_buffer (cpu, cia, dv_me, source, space,
123 return sim_hw_io_read_buffer (sd, dv_me, source, space, addr, nr_bytes);
129 device_io_write_buffer (device *me, const void *source, int space,
130 address_word addr, unsigned nr_bytes,
131 SIM_DESC sd, SIM_CPU *cpu, sim_cia cia)
133 struct hw *dv_me = (struct hw *) me;
135 if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
138 if (bfin_mmr_check (dv_me, cpu, addr, nr_bytes, true))
141 sim_cpu_hw_io_write_buffer (cpu, cia, dv_me, source, space,
146 return sim_hw_io_write_buffer (sd, dv_me, source, space, addr, nr_bytes);
151 void device_error (device *me, const char *message, ...)
153 /* Don't bother doing anything here -- any place in common code that
154 calls device_error() follows it with sim_hw_abort(). Since the
155 device isn't bound to the system yet, we can't call any common
156 hardware error funcs on it or we'll hit a NULL pointer. */
159 unsigned int dv_get_bus_num (struct hw *me)
161 const hw_unit *unit = hw_unit_address (me);
162 return unit->cells[unit->nr_cells - 1];