nds32: support multi-target debugging
[openocd.git] / src / jtag / aice / aice_pipe.c
blob44eade2d536b84a4cf424fba6337946543ca0c74
1 /***************************************************************************
2 * Copyright (C) 2013 by 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
24 #ifdef _WIN32
25 #include <windows.h>
26 #else
27 #include <signal.h>
28 #endif
30 #include <helper/log.h>
31 #include <helper/time_support.h>
32 #include "aice_port.h"
33 #include "aice_pipe.h"
35 #define AICE_PIPE_MAXLINE 8192
37 #ifdef _WIN32
38 PROCESS_INFORMATION proc_info;
40 HANDLE aice_pipe_output[2];
41 HANDLE aice_pipe_input[2];
43 static int aice_pipe_write(const void *buffer, int count)
45 BOOL success;
46 DWORD written;
48 success = WriteFile(aice_pipe_output[1], buffer, count, &written, NULL);
49 if (!success) {
50 LOG_ERROR("(WIN32) write to pipe failed, error code: 0x%08lx", GetLastError());
51 return -1;
54 return written;
57 static int aice_pipe_read(void *buffer, int count)
59 BOOL success;
60 DWORD has_read;
62 success = ReadFile(aice_pipe_input[0], buffer, count, &has_read, NULL);
63 if (!success || (has_read == 0)) {
64 LOG_ERROR("(WIN32) read from pipe failed, error code: 0x%08lx", GetLastError());
65 return -1;
68 return has_read;
71 static int aice_pipe_child_init(struct aice_port_param_s *param)
73 STARTUPINFO start_info;
74 BOOL success;
76 ZeroMemory(&proc_info, sizeof(PROCESS_INFORMATION));
77 ZeroMemory(&start_info, sizeof(STARTUPINFO));
78 start_info.cb = sizeof(STARTUPINFO);
79 start_info.hStdError = aice_pipe_input[1];
80 start_info.hStdOutput = aice_pipe_input[1];
81 start_info.hStdInput = aice_pipe_output[0];
82 start_info.dwFlags |= STARTF_USESTDHANDLES;
84 success = CreateProcess(NULL,
85 param->adapter_name,
86 NULL,
87 NULL,
88 TRUE,
90 NULL,
91 NULL,
92 &start_info,
93 &proc_info);
95 if (!success) {
96 LOG_ERROR("Create new process failed");
97 return ERROR_FAIL;
100 return ERROR_OK;
103 static int aice_pipe_parent_init(struct aice_port_param_s *param)
105 /* send open to adapter */
106 char line[AICE_PIPE_MAXLINE];
107 char command[AICE_PIPE_MAXLINE];
109 command[0] = AICE_OPEN;
110 set_u16(command + 1, param->vid);
111 set_u16(command + 3, param->pid);
113 if (aice_pipe_write(command, 5) != 5) {
114 LOG_ERROR("write failed\n");
115 return ERROR_FAIL;
118 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) {
119 LOG_ERROR("read failed\n");
120 return ERROR_FAIL;
123 if (line[0] == AICE_OK)
124 return ERROR_OK;
125 else
126 return ERROR_FAIL;
129 static int aice_pipe_open(struct aice_port_param_s *param)
131 SECURITY_ATTRIBUTES attribute;
133 attribute.nLength = sizeof(SECURITY_ATTRIBUTES);
134 attribute.bInheritHandle = TRUE;
135 attribute.lpSecurityDescriptor = NULL;
137 if (!CreatePipe(&aice_pipe_output[0], &aice_pipe_output[1],
138 &attribute, AICE_PIPE_MAXLINE)) {
139 LOG_ERROR("Create pipes failed");
140 return ERROR_FAIL;
142 if (!CreatePipe(&aice_pipe_input[0], &aice_pipe_input[1],
143 &attribute, AICE_PIPE_MAXLINE)) {
144 LOG_ERROR("Create pipes failed");
145 return ERROR_FAIL;
148 /* do not inherit aice_pipe_output[1] & aice_pipe_input[0] to child process */
149 if (!SetHandleInformation(aice_pipe_output[1], HANDLE_FLAG_INHERIT, 0))
150 return ERROR_FAIL;
151 if (!SetHandleInformation(aice_pipe_input[0], HANDLE_FLAG_INHERIT, 0))
152 return ERROR_FAIL;
154 aice_pipe_child_init(param);
156 aice_pipe_parent_init(param);
158 return ERROR_OK;
161 #else
163 int aice_pipe_output[2];
164 int aice_pipe_input[2];
166 static int aice_pipe_write(const void *buffer, int count)
168 if (write(aice_pipe_output[1], buffer, count) != count) {
169 LOG_ERROR("write to pipe failed");
170 return -1;
173 return count;
176 static int aice_pipe_read(void *buffer, int count)
178 int n;
179 long long then, cur;
181 then = timeval_ms();
183 while (1) {
184 n = read(aice_pipe_input[0], buffer, count);
186 if ((n == -1) && (errno == EAGAIN)) {
187 cur = timeval_ms();
188 if (cur - then > 500)
189 keep_alive();
190 continue;
191 } else if (n > 0)
192 break;
193 else {
194 LOG_ERROR("read from pipe failed");
195 break;
199 return n;
202 static int aice_pipe_child_init(struct aice_port_param_s *param)
204 close(aice_pipe_output[1]);
205 close(aice_pipe_input[0]);
207 if (aice_pipe_output[0] != STDIN_FILENO) {
208 if (dup2(aice_pipe_output[0], STDIN_FILENO) != STDIN_FILENO) {
209 LOG_ERROR("Map aice_pipe to STDIN failed");
210 return ERROR_FAIL;
212 close(aice_pipe_output[0]);
215 if (aice_pipe_input[1] != STDOUT_FILENO) {
216 if (dup2(aice_pipe_input[1], STDOUT_FILENO) != STDOUT_FILENO) {
217 LOG_ERROR("Map aice_pipe to STDOUT failed");
218 return ERROR_FAIL;
220 close(aice_pipe_input[1]);
223 if (execl(param->adapter_name, param->adapter_name, (char *)0) < 0) {
224 LOG_ERROR("Execute aice_pipe failed");
225 return ERROR_FAIL;
228 return ERROR_OK;
231 static int aice_pipe_parent_init(struct aice_port_param_s *param)
233 close(aice_pipe_output[0]);
234 close(aice_pipe_input[1]);
236 /* set read end of pipe as non-blocking */
237 if (fcntl(aice_pipe_input[0], F_SETFL, O_NONBLOCK))
238 return ERROR_FAIL;
240 /* send open to adapter */
241 char line[AICE_PIPE_MAXLINE];
242 char command[AICE_PIPE_MAXLINE];
244 command[0] = AICE_OPEN;
245 set_u16(command + 1, param->vid);
246 set_u16(command + 3, param->pid);
248 if (aice_pipe_write(command, 5) != 5) {
249 LOG_ERROR("write failed\n");
250 return ERROR_FAIL;
253 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0) {
254 LOG_ERROR("read failed\n");
255 return ERROR_FAIL;
258 if (line[0] == AICE_OK)
259 return ERROR_OK;
260 else
261 return ERROR_FAIL;
264 static void sig_pipe(int signo)
266 exit(1);
269 static int aice_pipe_open(struct aice_port_param_s *param)
271 pid_t pid;
273 if (signal(SIGPIPE, sig_pipe) == SIG_ERR) {
274 LOG_ERROR("Register SIGPIPE handler failed");
275 return ERROR_FAIL;
278 if (pipe(aice_pipe_output) < 0 || pipe(aice_pipe_input) < 0) {
279 LOG_ERROR("Create pipes failed");
280 return ERROR_FAIL;
283 pid = fork();
284 if (pid < 0) {
285 LOG_ERROR("Fork new process failed");
286 return ERROR_FAIL;
287 } else if (pid == 0) {
288 if (aice_pipe_child_init(param) != ERROR_OK) {
289 LOG_ERROR("AICE_PIPE child process initial error");
290 return ERROR_FAIL;
291 } else {
292 if (aice_pipe_parent_init(param) != ERROR_OK) {
293 LOG_ERROR("AICE_PIPE parent process initial error");
294 return ERROR_FAIL;
299 return ERROR_OK;
301 #endif
303 static int aice_pipe_close(void)
305 char line[AICE_PIPE_MAXLINE];
306 char command[AICE_PIPE_MAXLINE];
308 command[0] = AICE_CLOSE;
310 if (aice_pipe_write(command, 1) != 1)
311 return ERROR_FAIL;
313 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
314 return ERROR_FAIL;
316 if (line[0] == AICE_OK) {
317 #ifdef _WIN32
318 WaitForSingleObject(proc_info.hProcess, INFINITE);
319 CloseHandle(proc_info.hProcess);
320 CloseHandle(proc_info.hThread);
321 #endif
322 return ERROR_OK;
323 } else
324 return ERROR_FAIL;
327 static int aice_pipe_idcode(uint32_t *idcode, uint8_t *num_of_idcode)
329 char line[AICE_PIPE_MAXLINE];
330 char command[AICE_PIPE_MAXLINE];
332 command[0] = AICE_IDCODE;
334 if (aice_pipe_write(command, 1) != 1)
335 return ERROR_FAIL;
337 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
338 return ERROR_FAIL;
340 *num_of_idcode = line[0];
342 if ((*num_of_idcode == 0) || (*num_of_idcode >= 16))
343 return ERROR_FAIL;
345 for (int i = 0 ; i < *num_of_idcode ; i++)
346 idcode[i] = get_u32(line + i * 4 + 1);
348 return ERROR_OK;
351 static int aice_pipe_state(uint32_t coreid, enum aice_target_state_s *state)
353 char line[AICE_PIPE_MAXLINE];
354 char command[AICE_PIPE_MAXLINE];
356 command[0] = AICE_STATE;
358 if (aice_pipe_write(command, 1) != 1)
359 return ERROR_FAIL;
361 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
362 return ERROR_FAIL;
364 *state = (enum aice_target_state_s)line[0];
366 return ERROR_OK;
369 static int aice_pipe_reset(void)
371 char line[AICE_PIPE_MAXLINE];
372 char command[AICE_PIPE_MAXLINE];
374 command[0] = AICE_RESET;
376 if (aice_pipe_write(command, 1) != 1)
377 return ERROR_FAIL;
379 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
380 return ERROR_FAIL;
382 if (line[0] == AICE_OK)
383 return ERROR_OK;
384 else
385 return ERROR_FAIL;
388 static int aice_pipe_assert_srst(uint32_t coreid, enum aice_srst_type_s srst)
390 char line[AICE_PIPE_MAXLINE];
391 char command[AICE_PIPE_MAXLINE];
393 command[0] = AICE_ASSERT_SRST;
394 command[1] = srst;
396 if (aice_pipe_write(command, 2) != 2)
397 return ERROR_FAIL;
399 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
400 return ERROR_FAIL;
402 if (line[0] == AICE_OK)
403 return ERROR_OK;
404 else
405 return ERROR_FAIL;
408 static int aice_pipe_run(uint32_t coreid)
410 char line[AICE_PIPE_MAXLINE];
411 char command[AICE_PIPE_MAXLINE];
413 command[0] = AICE_RUN;
415 if (aice_pipe_write(command, 1) != 1)
416 return ERROR_FAIL;
418 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
419 return ERROR_FAIL;
421 if (line[0] == AICE_OK)
422 return ERROR_OK;
423 else
424 return ERROR_FAIL;
427 static int aice_pipe_halt(uint32_t coreid)
429 char line[AICE_PIPE_MAXLINE];
430 char command[AICE_PIPE_MAXLINE];
432 command[0] = AICE_HALT;
434 if (aice_pipe_write(command, 1) != 1)
435 return ERROR_FAIL;
437 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
438 return ERROR_FAIL;
440 if (line[0] == AICE_OK)
441 return ERROR_OK;
442 else
443 return ERROR_FAIL;
446 static int aice_pipe_read_reg(uint32_t coreid, uint32_t num, uint32_t *val)
448 char line[AICE_PIPE_MAXLINE];
449 char command[AICE_PIPE_MAXLINE];
451 command[0] = AICE_READ_REG;
452 set_u32(command + 1, num);
454 if (aice_pipe_write(command, 5) != 5)
455 return ERROR_FAIL;
457 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
458 return ERROR_FAIL;
460 *val = get_u32(line);
462 return ERROR_OK;
465 static int aice_pipe_write_reg(uint32_t coreid, uint32_t num, uint32_t val)
467 char line[AICE_PIPE_MAXLINE];
468 char command[AICE_PIPE_MAXLINE];
470 command[0] = AICE_WRITE_REG;
471 set_u32(command + 1, num);
472 set_u32(command + 5, val);
474 if (aice_pipe_write(command, 9) != 9)
475 return ERROR_FAIL;
477 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
478 return ERROR_FAIL;
480 if (line[0] == AICE_OK)
481 return ERROR_OK;
482 else
483 return ERROR_FAIL;
486 static int aice_pipe_read_reg_64(uint32_t coreid, uint32_t num, uint64_t *val)
488 char line[AICE_PIPE_MAXLINE];
489 char command[AICE_PIPE_MAXLINE];
491 command[0] = AICE_READ_REG_64;
492 set_u32(command + 1, num);
494 if (aice_pipe_write(command, 5) != 5)
495 return ERROR_FAIL;
497 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
498 return ERROR_FAIL;
500 *val = (((uint64_t)get_u32(line + 4)) << 32) | get_u32(line);
502 return ERROR_OK;
505 static int aice_pipe_write_reg_64(uint32_t coreid, uint32_t num, uint64_t val)
507 char line[AICE_PIPE_MAXLINE];
508 char command[AICE_PIPE_MAXLINE];
510 command[0] = AICE_WRITE_REG_64;
511 set_u32(command + 1, num);
512 set_u32(command + 5, val & 0xFFFFFFFF);
513 set_u32(command + 9, (val >> 32) & 0xFFFFFFFF);
515 if (aice_pipe_write(command, 13) != 9)
516 return ERROR_FAIL;
518 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
519 return ERROR_FAIL;
521 if (line[0] == AICE_OK)
522 return ERROR_OK;
523 else
524 return ERROR_FAIL;
527 static int aice_pipe_step(uint32_t coreid)
529 char line[AICE_PIPE_MAXLINE];
530 char command[AICE_PIPE_MAXLINE];
532 command[0] = AICE_STEP;
534 if (aice_pipe_write(command, 1) != 1)
535 return ERROR_FAIL;
537 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
538 return ERROR_FAIL;
540 if (line[0] == AICE_OK)
541 return ERROR_OK;
542 else
543 return ERROR_FAIL;
546 static int aice_pipe_read_mem_unit(uint32_t coreid, uint32_t addr, uint32_t size,
547 uint32_t count, uint8_t *buffer)
549 char command[AICE_PIPE_MAXLINE];
551 command[0] = AICE_READ_MEM_UNIT;
552 set_u32(command + 1, addr);
553 set_u32(command + 5, size);
554 set_u32(command + 9, count);
556 if (aice_pipe_write(command, 13) != 13)
557 return ERROR_FAIL;
559 if (aice_pipe_read(buffer, size * count) < 0)
560 return ERROR_FAIL;
562 return ERROR_OK;
565 static int aice_pipe_write_mem_unit(uint32_t coreid, uint32_t addr, uint32_t size,
566 uint32_t count, const uint8_t *buffer)
568 char line[AICE_PIPE_MAXLINE];
569 char command[AICE_PIPE_MAXLINE];
571 command[0] = AICE_WRITE_MEM_UNIT;
572 set_u32(command + 1, addr);
573 set_u32(command + 5, size);
574 set_u32(command + 9, count);
576 /* WRITE_MEM_UNIT|addr|size|count|data */
577 memcpy(command + 13, buffer, size * count);
579 if (aice_pipe_write(command, 13 + size * count) < 0)
580 return ERROR_FAIL;
582 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
583 return ERROR_FAIL;
585 if (line[0] == AICE_OK)
586 return ERROR_OK;
587 else
588 return ERROR_FAIL;
590 return ERROR_OK;
593 static int aice_pipe_read_mem_bulk(uint32_t coreid, uint32_t addr,
594 uint32_t length, uint8_t *buffer)
596 char line[AICE_PIPE_MAXLINE + 1];
597 char command[AICE_PIPE_MAXLINE];
598 uint32_t remain_len = length;
599 uint32_t prepare_len;
600 char *received_line;
601 uint32_t received_len;
602 int read_len;
604 command[0] = AICE_READ_MEM_BULK;
605 set_u32(command + 1, addr);
606 set_u32(command + 5, length);
608 if (aice_pipe_write(command, 9) < 0)
609 return ERROR_FAIL;
611 while (remain_len > 0) {
612 if (remain_len > AICE_PIPE_MAXLINE)
613 prepare_len = AICE_PIPE_MAXLINE;
614 else
615 prepare_len = remain_len;
617 prepare_len++;
618 received_len = 0;
619 received_line = line;
620 do {
621 read_len = aice_pipe_read(received_line, prepare_len - received_len);
622 if (read_len < 0)
623 return ERROR_FAIL;
624 received_line += read_len;
625 received_len += read_len;
626 } while (received_len < prepare_len);
628 if (line[0] != AICE_OK)
629 return ERROR_FAIL;
631 prepare_len--;
632 memcpy(buffer, line + 1, prepare_len);
633 remain_len -= prepare_len;
634 buffer += prepare_len;
637 return ERROR_OK;
640 static int aice_pipe_write_mem_bulk(uint32_t coreid, uint32_t addr,
641 uint32_t length, const uint8_t *buffer)
643 char line[AICE_PIPE_MAXLINE];
644 char command[AICE_PIPE_MAXLINE + 4];
645 uint32_t remain_len = length;
646 uint32_t written_len = 0;
647 uint32_t write_len;
649 command[0] = AICE_WRITE_MEM_BULK;
650 set_u32(command + 1, addr);
651 set_u32(command + 5, length);
653 /* Send command first */
654 if (aice_pipe_write(command, 9) < 0)
655 return ERROR_FAIL;
657 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
658 return ERROR_FAIL;
660 if (line[0] == AICE_ERROR)
661 return ERROR_FAIL;
663 while (remain_len > 0) {
664 if (remain_len > AICE_PIPE_MAXLINE)
665 write_len = AICE_PIPE_MAXLINE;
666 else
667 write_len = remain_len;
669 set_u32(command, write_len);
670 memcpy(command + 4, buffer + written_len, write_len); /* data only */
672 if (aice_pipe_write(command, write_len + 4) < 0)
673 return ERROR_FAIL;
675 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
676 return ERROR_FAIL;
678 if (line[0] == AICE_ERROR)
679 return ERROR_FAIL;
681 remain_len -= write_len;
682 written_len += write_len;
685 if (line[0] == AICE_OK)
686 return ERROR_OK;
687 else
688 return ERROR_FAIL;
691 static int aice_pipe_read_debug_reg(uint32_t coreid, uint32_t addr, uint32_t *val)
693 char line[AICE_PIPE_MAXLINE];
694 char command[AICE_PIPE_MAXLINE];
696 command[0] = AICE_READ_DEBUG_REG;
697 set_u32(command + 1, addr);
699 if (aice_pipe_write(command, 5) != 5)
700 return ERROR_FAIL;
702 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
703 return ERROR_FAIL;
705 *val = get_u32(line);
707 return ERROR_OK;
710 static int aice_pipe_write_debug_reg(uint32_t coreid, uint32_t addr, const uint32_t val)
712 char line[AICE_PIPE_MAXLINE];
713 char command[AICE_PIPE_MAXLINE];
715 command[0] = AICE_WRITE_DEBUG_REG;
716 set_u32(command + 1, addr);
717 set_u32(command + 5, val);
719 if (aice_pipe_write(command, 9) != 9)
720 return ERROR_FAIL;
722 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
723 return ERROR_FAIL;
725 if (line[0] == AICE_OK)
726 return ERROR_OK;
727 else
728 return ERROR_FAIL;
731 static int aice_pipe_set_jtag_clock(uint32_t a_clock)
733 char line[AICE_PIPE_MAXLINE];
734 char command[AICE_PIPE_MAXLINE];
736 command[0] = AICE_SET_JTAG_CLOCK;
737 set_u32(command + 1, a_clock);
739 if (aice_pipe_write(command, 5) != 5)
740 return ERROR_FAIL;
742 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
743 return ERROR_FAIL;
745 if (line[0] == AICE_OK)
746 return ERROR_OK;
747 else
748 return ERROR_FAIL;
751 static int aice_pipe_memory_access(uint32_t coreid, enum nds_memory_access access_channel)
753 char line[AICE_PIPE_MAXLINE];
754 char command[AICE_PIPE_MAXLINE];
756 command[0] = AICE_MEMORY_ACCESS;
757 set_u32(command + 1, access_channel);
759 if (aice_pipe_write(command, 5) != 5)
760 return ERROR_FAIL;
762 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
763 return ERROR_FAIL;
765 if (line[0] == AICE_OK)
766 return ERROR_OK;
767 else
768 return ERROR_FAIL;
771 static int aice_pipe_memory_mode(uint32_t coreid, enum nds_memory_select mem_select)
773 char line[AICE_PIPE_MAXLINE];
774 char command[AICE_PIPE_MAXLINE];
776 command[0] = AICE_MEMORY_MODE;
777 set_u32(command + 1, mem_select);
779 if (aice_pipe_write(command, 5) != 5)
780 return ERROR_FAIL;
782 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
783 return ERROR_FAIL;
785 if (line[0] == AICE_OK)
786 return ERROR_OK;
787 else
788 return ERROR_FAIL;
791 static int aice_pipe_read_tlb(uint32_t coreid, uint32_t virtual_address,
792 uint32_t *physical_address)
794 char line[AICE_PIPE_MAXLINE];
795 char command[AICE_PIPE_MAXLINE];
797 command[0] = AICE_READ_TLB;
798 set_u32(command + 1, virtual_address);
800 if (aice_pipe_write(command, 5) != 5)
801 return ERROR_FAIL;
803 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
804 return ERROR_FAIL;
806 if (line[0] == AICE_OK) {
807 *physical_address = get_u32(line + 1);
808 return ERROR_OK;
809 } else
810 return ERROR_FAIL;
813 static int aice_pipe_cache_ctl(uint32_t coreid, uint32_t subtype, uint32_t address)
815 char line[AICE_PIPE_MAXLINE];
816 char command[AICE_PIPE_MAXLINE];
818 command[0] = AICE_CACHE_CTL;
819 set_u32(command + 1, subtype);
820 set_u32(command + 5, address);
822 if (aice_pipe_write(command, 9) != 9)
823 return ERROR_FAIL;
825 if (aice_pipe_read(line, AICE_PIPE_MAXLINE) < 0)
826 return ERROR_FAIL;
828 if (line[0] == AICE_OK)
829 return ERROR_OK;
830 else
831 return ERROR_FAIL;
834 static int aice_pipe_set_retry_times(uint32_t a_retry_times)
836 return ERROR_OK;
839 /** */
840 struct aice_port_api_s aice_pipe = {
841 /** */
842 .open = aice_pipe_open,
843 /** */
844 .close = aice_pipe_close,
845 /** */
846 .idcode = aice_pipe_idcode,
847 /** */
848 .set_jtag_clock = aice_pipe_set_jtag_clock,
849 /** */
850 .state = aice_pipe_state,
851 /** */
852 .reset = aice_pipe_reset,
853 /** */
854 .assert_srst = aice_pipe_assert_srst,
855 /** */
856 .run = aice_pipe_run,
857 /** */
858 .halt = aice_pipe_halt,
859 /** */
860 .step = aice_pipe_step,
861 /** */
862 .read_reg = aice_pipe_read_reg,
863 /** */
864 .write_reg = aice_pipe_write_reg,
865 /** */
866 .read_reg_64 = aice_pipe_read_reg_64,
867 /** */
868 .write_reg_64 = aice_pipe_write_reg_64,
869 /** */
870 .read_mem_unit = aice_pipe_read_mem_unit,
871 /** */
872 .write_mem_unit = aice_pipe_write_mem_unit,
873 /** */
874 .read_mem_bulk = aice_pipe_read_mem_bulk,
875 /** */
876 .write_mem_bulk = aice_pipe_write_mem_bulk,
877 /** */
878 .read_debug_reg = aice_pipe_read_debug_reg,
879 /** */
880 .write_debug_reg = aice_pipe_write_debug_reg,
882 /** */
883 .memory_access = aice_pipe_memory_access,
884 /** */
885 .memory_mode = aice_pipe_memory_mode,
887 /** */
888 .read_tlb = aice_pipe_read_tlb,
890 /** */
891 .cache_ctl = aice_pipe_cache_ctl,
893 /** */
894 .set_retry_times = aice_pipe_set_retry_times,