1 1.1 christos /* Common Blackfin device stuff. 2 1.1 christos 3 1.11 christos Copyright (C) 2010-2024 Free Software Foundation, Inc. 4 1.1 christos Contributed by Analog Devices, Inc. 5 1.1 christos 6 1.1 christos This file is part of simulators. 7 1.1 christos 8 1.1 christos This program is free software; you can redistribute it and/or modify 9 1.1 christos it under the terms of the GNU General Public License as published by 10 1.1 christos the Free Software Foundation; either version 3 of the License, or 11 1.1 christos (at your option) any later version. 12 1.1 christos 13 1.1 christos This program is distributed in the hope that it will be useful, 14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 1.1 christos GNU General Public License for more details. 17 1.1 christos 18 1.1 christos You should have received a copy of the GNU General Public License 19 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 1.1 christos 21 1.1 christos #ifndef DEVICES_H 22 1.1 christos #define DEVICES_H 23 1.1 christos 24 1.1 christos #include "hw-base.h" 25 1.1 christos #include "hw-main.h" 26 1.1 christos #include "hw-device.h" 27 1.1 christos #include "hw-tree.h" 28 1.1 christos 29 1.11 christos #include "bfin-sim.h" 30 1.11 christos 31 1.12 christos /* We keep the same initial structure layout with DMA enabled devices. */ 32 1.1 christos struct dv_bfin { 33 1.1 christos bu32 base; 34 1.1 christos struct hw *dma_master; 35 1.1 christos bool acked; 36 1.1 christos }; 37 1.1 christos 38 1.1 christos #define BFIN_MMR_16(mmr) mmr, __pad_##mmr 39 1.1 christos 40 1.1 christos /* Most peripherals have either one interrupt or these three. */ 41 1.1 christos #define DV_PORT_TX 0 42 1.1 christos #define DV_PORT_RX 1 43 1.1 christos #define DV_PORT_STAT 2 44 1.1 christos 45 1.1 christos unsigned int dv_get_bus_num (struct hw *); 46 1.1 christos 47 1.1 christos static inline bu8 dv_load_1 (const void *ptr) 49 1.1 christos { 50 1.1 christos const unsigned char *c = ptr; 51 1.1 christos return c[0]; 52 1.1 christos } 53 1.1 christos 54 1.1 christos static inline void dv_store_1 (void *ptr, bu8 val) 55 1.1 christos { 56 1.1 christos unsigned char *c = ptr; 57 1.1 christos c[0] = val; 58 1.1 christos } 59 1.1 christos 60 1.1 christos static inline bu16 dv_load_2 (const void *ptr) 61 1.1 christos { 62 1.1 christos const unsigned char *c = ptr; 63 1.1 christos return (c[1] << 8) | dv_load_1 (ptr); 64 1.1 christos } 65 1.1 christos 66 1.1 christos static inline void dv_store_2 (void *ptr, bu16 val) 67 1.1 christos { 68 1.1 christos unsigned char *c = ptr; 69 1.1 christos c[1] = val >> 8; 70 1.1 christos dv_store_1 (ptr, val); 71 1.1 christos } 72 1.1 christos 73 1.1 christos static inline bu32 dv_load_4 (const void *ptr) 74 1.1 christos { 75 1.1 christos const unsigned char *c = ptr; 76 1.1 christos return (c[3] << 24) | (c[2] << 16) | dv_load_2 (ptr); 77 1.1 christos } 78 1.1 christos 79 1.1 christos static inline void dv_store_4 (void *ptr, bu32 val) 80 1.1 christos { 81 1.1 christos unsigned char *c = ptr; 82 1.1 christos c[3] = val >> 24; 83 1.1 christos c[2] = val >> 16; 84 1.1 christos dv_store_2 (ptr, val); 85 1.1 christos } 86 1.1 christos 87 1.1 christos /* Helpers for MMRs where only the specified bits are W1C. The 89 1.1 christos rest are left unmodified. */ 90 1.1 christos #define dv_w1c(ptr, val, bits) (*(ptr) &= ~((val) & (bits))) 91 1.1 christos static inline void dv_w1c_2 (bu16 *ptr, bu16 val, bu16 bits) 92 1.1 christos { 93 1.1 christos dv_w1c (ptr, val, bits); 94 1.1 christos } 95 1.1 christos static inline void dv_w1c_4 (bu32 *ptr, bu32 val, bu32 bits) 96 1.1 christos { 97 1.1 christos dv_w1c (ptr, val, bits); 98 1.1 christos } 99 1.1 christos 100 1.1 christos /* Helpers for MMRs where all bits are RW except for the specified 101 1.1 christos bits -- those ones are W1C. */ 102 1.1 christos #define dv_w1c_partial(ptr, val, bits) \ 103 1.1 christos (*(ptr) = ((val) | (*(ptr) & (bits))) & ~((val) & (bits))) 104 1.1 christos static inline void dv_w1c_2_partial (bu16 *ptr, bu16 val, bu16 bits) 105 1.1 christos { 106 1.1 christos dv_w1c_partial (ptr, val, bits); 107 1.1 christos } 108 1.1 christos static inline void dv_w1c_4_partial (bu32 *ptr, bu32 val, bu32 bits) 109 1.1 christos { 110 1.1 christos dv_w1c_partial (ptr, val, bits); 111 1.1 christos } 112 1.1 christos 113 1.1 christos /* XXX: Grubbing around in device internals is probably wrong, but 115 1.1 christos until someone shows me what's right ... */ 116 1.1 christos static inline struct hw * 117 1.1 christos dv_get_device (SIM_CPU *cpu, const char *device_name) 118 1.1 christos { 119 1.1 christos SIM_DESC sd = CPU_STATE (cpu); 120 1.1 christos void *root = STATE_HW (sd); 121 1.1 christos return hw_tree_find_device (root, device_name); 122 1.1 christos } 123 1.1 christos 124 1.1 christos static inline void * 125 1.1 christos dv_get_state (SIM_CPU *cpu, const char *device_name) 126 1.1 christos { 127 1.1 christos return hw_data (dv_get_device (cpu, device_name)); 128 1.1 christos } 129 1.1 christos 130 1.1 christos #define DV_STATE(cpu, dv) dv_get_state (cpu, "/core/bfin_"#dv) 131 1.1 christos 132 1.1 christos #define DV_STATE_CACHED(cpu, dv) \ 133 1.1 christos ({ \ 134 1.1 christos struct bfin_##dv *__##dv = BFIN_CPU_STATE.dv##_cache; \ 135 1.1 christos if (!__##dv) \ 136 1.1 christos BFIN_CPU_STATE.dv##_cache = __##dv = dv_get_state (cpu, "/core/bfin_"#dv); \ 137 1.1 christos __##dv; \ 138 1.6 christos }) 139 1.6 christos 140 1.6 christos void dv_bfin_mmr_invalid (struct hw *, address_word, unsigned nr_bytes, bool write); 142 1.1 christos bool dv_bfin_mmr_require (struct hw *, address_word, unsigned nr_bytes, unsigned size, bool write); 143 1.6 christos /* For 32-bit memory mapped registers that allow 16-bit or 32-bit access. */ 144 1.1 christos bool dv_bfin_mmr_require_16_32 (struct hw *, address_word, unsigned nr_bytes, bool write); 145 1.1 christos /* For 32-bit memory mapped registers that only allow 16-bit access. */ 146 1.1 christos #define dv_bfin_mmr_require_16(hw, addr, nr_bytes, write) dv_bfin_mmr_require (hw, addr, nr_bytes, 2, write) 147 1.1 christos /* For 32-bit memory mapped registers that only allow 32-bit access. */ 148 1.1 christos #define dv_bfin_mmr_require_32(hw, addr, nr_bytes, write) dv_bfin_mmr_require (hw, addr, nr_bytes, 4, write) 149 1.1 christos 150 1.1 christos #define HW_TRACE_WRITE() \ 152 1.1 christos HW_TRACE ((me, "write 0x%08lx (%s) length %u with 0x%x", \ 153 1.1 christos (unsigned long) addr, mmr_name (mmr_off), nr_bytes, value)) 154 1.1 christos #define HW_TRACE_READ() \ 155 1.1 christos HW_TRACE ((me, "read 0x%08lx (%s) length %u", \ 156 1.1 christos (unsigned long) addr, mmr_name (mmr_off), nr_bytes)) 157 1.1 christos 158 1.1 christos #define HW_TRACE_DMA_WRITE() \ 159 1.1 christos HW_TRACE ((me, "dma write 0x%08lx length %u", \ 160 1.1 christos (unsigned long) addr, nr_bytes)) 161 #define HW_TRACE_DMA_READ() \ 162 HW_TRACE ((me, "dma read 0x%08lx length %u", \ 163 (unsigned long) addr, nr_bytes)) 164 165 #endif 166