1 /***************************************************************************
2 * Copyright (C) 2013 by Andes Technology *
3 * Hsiangkai Wang <hkwang@andestech.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
19 ***************************************************************************/
23 #include <target/nds32_edm.h>
25 #define ERROR_AICE_DISCONNECT (-200)
26 #define ERROR_AICE_TIMEOUT (-201)
28 enum aice_target_state_s {
35 AICE_TARGET_DEBUG_RUNNING,
38 enum aice_srst_type_s {
40 AICE_RESET_HOLD = 0x8,
43 enum aice_target_endian {
44 AICE_LITTLE_ENDIAN = 0,
78 AICE_SET_CUSTOM_SRST_SCRIPT,
79 AICE_SET_CUSTOM_TRST_SCRIPT,
80 AICE_SET_CUSTOM_RESTART_SCRIPT,
81 AICE_SET_COUNT_TO_CHECK_DBGER,
91 enum aice_cache_ctl_type {
92 AICE_CACHE_CTL_L1D_INVALALL = 0,
93 AICE_CACHE_CTL_L1D_VA_INVAL,
94 AICE_CACHE_CTL_L1D_WBALL,
95 AICE_CACHE_CTL_L1D_VA_WB,
96 AICE_CACHE_CTL_L1I_INVALALL,
97 AICE_CACHE_CTL_L1I_VA_INVAL,
100 struct aice_port_param_s {
115 struct aice_port_param_s param;
117 const struct aice_port *port;
119 uint32_t retry_times;
121 uint32_t count_to_check_dbger;
125 extern struct aice_port_api_s aice_usb_layout_api;
128 struct aice_port_api_s {
130 int (*open)(struct aice_port_param_s *param);
136 int (*assert_srst)(enum aice_srst_type_s srst);
144 int (*read_reg)(uint32_t num, uint32_t *val);
146 int (*write_reg)(uint32_t num, uint32_t val);
148 int (*read_reg_64)(uint32_t num, uint64_t *val);
150 int (*write_reg_64)(uint32_t num, uint64_t val);
152 int (*read_mem_unit)(uint32_t addr, uint32_t size, uint32_t count,
155 int (*write_mem_unit)(uint32_t addr, uint32_t size, uint32_t count,
156 const uint8_t *buffer);
158 int (*read_mem_bulk)(uint32_t addr, uint32_t length,
161 int (*write_mem_bulk)(uint32_t addr, uint32_t length,
162 const uint8_t *buffer);
164 int (*read_debug_reg)(uint32_t addr, uint32_t *val);
166 int (*write_debug_reg)(uint32_t addr, const uint32_t val);
169 int (*idcode)(uint32_t *idcode, uint8_t *num_of_idcode);
171 int (*state)(enum aice_target_state_s *state);
174 int (*set_jtag_clock)(uint32_t a_clock);
176 int (*select_target)(uint32_t target_id);
179 int (*memory_access)(enum nds_memory_access a_access);
181 int (*memory_mode)(enum nds_memory_select mem_select);
184 int (*read_tlb)(uint32_t virtual_address, uint32_t *physical_address);
187 int (*cache_ctl)(uint32_t subtype, uint32_t address);
190 int (*set_retry_times)(uint32_t a_retry_times);
193 int (*program_edm)(char *command_sequence);
196 int (*pack_command)(bool enable_pack_command);
199 int (*execute)(uint32_t *instructions, uint32_t instruction_num);
202 int (*set_custom_srst_script)(const char *script);
205 int (*set_custom_trst_script)(const char *script);
208 int (*set_custom_restart_script)(const char *script);
211 int (*set_count_to_check_dbger)(uint32_t count_to_check);
214 int (*set_data_endian)(enum aice_target_endian target_data_endian);
217 #define AICE_PORT_UNKNOWN 0
218 #define AICE_PORT_AICE_USB 1
219 #define AICE_PORT_AICE_PIPE 2
228 struct aice_port_api_s *api;
232 const struct aice_port *aice_port_get_list(void);