cfb6d86c831f128ba7f744a64f9b92e52b1de461
[fw/openocd] / src / target / nds32_aice.c
1 /***************************************************************************
2  *   Copyright (C) 2013 Andes technology.                                  *
3  *   Hsiangkai Wang <hkwang@andestech.com>                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <helper/log.h>
25 #include "nds32_aice.h"
26
27 int aice_read_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t *val)
28 {
29         if (aice->port->api->read_reg_64 == NULL) {
30                 LOG_WARNING("Not implemented: %s", __func__);
31                 return ERROR_FAIL;
32         }
33
34         return aice->port->api->read_reg_64(aice->coreid, num, val);
35 }
36
37 int aice_write_reg_64(struct aice_port_s *aice, uint32_t num, uint64_t val)
38 {
39         if (aice->port->api->write_reg_64 == NULL) {
40                 LOG_WARNING("Not implemented: %s", __func__);
41                 return ERROR_FAIL;
42         }
43
44         return aice->port->api->write_reg_64(aice->coreid, num, val);
45 }
46
47 int aice_read_tlb(struct aice_port_s *aice, uint32_t virtual_address,
48                 uint32_t *physical_address)
49 {
50         if (aice->port->api->read_tlb == NULL) {
51                 LOG_WARNING("Not implemented: %s", __func__);
52                 return ERROR_FAIL;
53         }
54
55         return aice->port->api->read_tlb(aice->coreid, virtual_address, physical_address);
56 }
57
58 int aice_cache_ctl(struct aice_port_s *aice, uint32_t subtype, uint32_t address)
59 {
60         if (aice->port->api->cache_ctl == NULL) {
61                 LOG_WARNING("Not implemented: %s", __func__);
62                 return ERROR_FAIL;
63         }
64
65         return aice->port->api->cache_ctl(aice->coreid, subtype, address);
66 }
67
68 int aice_set_retry_times(struct aice_port_s *aice, uint32_t a_retry_times)
69 {
70         if (aice->port->api->set_retry_times == NULL) {
71                 LOG_WARNING("Not implemented: %s", __func__);
72                 return ERROR_FAIL;
73         }
74
75         return aice->port->api->set_retry_times(a_retry_times);
76 }
77
78 int aice_program_edm(struct aice_port_s *aice, char *command_sequence)
79 {
80         if (aice->port->api->program_edm == NULL) {
81                 LOG_WARNING("Not implemented: %s", __func__);
82                 return ERROR_FAIL;
83         }
84
85         return aice->port->api->program_edm(aice->coreid, command_sequence);
86 }
87
88 int aice_set_command_mode(struct aice_port_s *aice,
89                 enum aice_command_mode command_mode)
90 {
91         if (aice->port->api->set_command_mode == NULL) {
92                 LOG_WARNING("Not implemented: %s", __func__);
93                 return ERROR_FAIL;
94         }
95
96         return aice->port->api->set_command_mode(command_mode);
97 }
98
99 int aice_execute(struct aice_port_s *aice, uint32_t *instructions,
100                 uint32_t instruction_num)
101 {
102         if (aice->port->api->execute == NULL) {
103                 LOG_WARNING("Not implemented: %s", __func__);
104                 return ERROR_FAIL;
105         }
106
107         return aice->port->api->execute(aice->coreid, instructions, instruction_num);
108 }
109
110 int aice_set_custom_srst_script(struct aice_port_s *aice, const char *script)
111 {
112         if (aice->port->api->set_custom_srst_script == NULL) {
113                 LOG_WARNING("Not implemented: %s", __func__);
114                 return ERROR_FAIL;
115         }
116
117         return aice->port->api->set_custom_srst_script(script);
118 }
119
120 int aice_set_custom_trst_script(struct aice_port_s *aice, const char *script)
121 {
122         if (aice->port->api->set_custom_trst_script == NULL) {
123                 LOG_WARNING("Not implemented: %s", __func__);
124                 return ERROR_FAIL;
125         }
126
127         return aice->port->api->set_custom_trst_script(script);
128 }
129
130 int aice_set_custom_restart_script(struct aice_port_s *aice, const char *script)
131 {
132         if (aice->port->api->set_custom_restart_script == NULL) {
133                 LOG_WARNING("Not implemented: %s", __func__);
134                 return ERROR_FAIL;
135         }
136
137         return aice->port->api->set_custom_restart_script(script);
138 }
139
140 int aice_set_count_to_check_dbger(struct aice_port_s *aice, uint32_t count_to_check)
141 {
142         if (aice->port->api->set_count_to_check_dbger == NULL) {
143                 LOG_WARNING("Not implemented: %s", __func__);
144                 return ERROR_FAIL;
145         }
146
147         return aice->port->api->set_count_to_check_dbger(count_to_check);
148 }
149
150 int aice_profiling(struct aice_port_s *aice, uint32_t interval, uint32_t iteration,
151                 uint32_t reg_no, uint32_t *samples, uint32_t *num_samples)
152 {
153         if (aice->port->api->profiling == NULL) {
154                 LOG_WARNING("Not implemented: %s", __func__);
155                 return ERROR_FAIL;
156         }
157
158         return aice->port->api->profiling(aice->coreid, interval, iteration,
159                         reg_no, samples, num_samples);
160 }