OpenOCD
vdebug.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
2 
3 /* Copyright 2020-2022 Cadence Design Systems, Inc. */
4 
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #ifdef _WIN32
20 #define WIN32_LEAN_AND_MEAN
21 #include <windows.h>
22 #else
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h> /* close */
25 #endif
26 #ifdef HAVE_SYS_SOCKET_H
27 #include <sys/socket.h>
28 #endif
29 #ifdef HAVE_ARPA_INET_H
30 #include <arpa/inet.h>
31 #endif
32 #ifdef HAVE_NETDB_H
33 #include <netdb.h>
34 #endif
35 #endif
36 #include <stdio.h>
37 #ifdef HAVE_STDINT_H
38 #include <stdint.h>
39 #endif
40 #ifdef HAVE_STDLIB_H
41 #include <stdlib.h>
42 #endif
43 #include <stdarg.h>
44 #include <string.h>
45 #include <errno.h>
46 
47 #include "jtag/interface.h"
48 #include "jtag/commands.h"
49 #include "transport/transport.h"
50 #include "target/target.h"
51 #include "target/arm_adi_v5.h"
52 #include "helper/time_support.h"
53 #include "helper/replacements.h"
54 #include "helper/log.h"
55 #include "helper/list.h"
56 
57 #define VD_VERSION 50
58 #define VD_BUFFER_LEN 4024
59 #define VD_CHEADER_LEN 24
60 #define VD_SHEADER_LEN 16
61 
62 #define VD_MAX_MEMORIES 20
63 #define VD_POLL_INTERVAL 1000
64 #define VD_SCALE_PSTOMS 1000000000
65 
69 enum {
70  VD_BFM_TPIU = 0x0000, /* transactor trace TPIU */
71  VD_BFM_DAP6 = 0x0001, /* transactor DAP ADI V6 */
72  VD_BFM_SWDP = 0x0002, /* transactor DAP SWD DP */
73  VD_BFM_AHB = 0x0003, /* transactor AMBA AHB */
74  VD_BFM_APB = 0x0004, /* transactor AMBA APB */
75  VD_BFM_AXI = 0x0005, /* transactor AMBA AXI */
76  VD_BFM_JTAG = 0x0006, /* transactor serial JTAG */
77  VD_BFM_SWD = 0x0007, /* transactor serial SWD */
78 };
79 
83 enum {
84  VD_SIG_TCK = 0x0001, /* JTAG clock; tclk */
85  VD_SIG_TDI = 0x0002, /* JTAG TDI; tdi */
86  VD_SIG_TMS = 0x0004, /* JTAG TMS; tms */
87  VD_SIG_RESET = 0x0008, /* DUT reset; rst */
88  VD_SIG_TRST = 0x0010, /* JTAG Reset; trstn */
89  VD_SIG_TDO = 0x0020, /* JTAG TDO; tdo */
90  VD_SIG_POWER = 0x0100, /* BFM power; bfm_up */
91  VD_SIG_TCKDIV = 0x0200, /* JTAG clock divider; tclkdiv */
92  VD_SIG_BUF = 0x1000, /* memory buffer; mem */
93 };
94 
98 enum {
99  VD_ERR_NONE = 0x0000, /* no error */
100  VD_ERR_NOT_IMPL = 0x0100, /* feature not implemented */
101  VD_ERR_USAGE = 0x0101, /* incorrect usage */
102  VD_ERR_PARAM = 0x0102, /* incorrect parameter */
103  VD_ERR_CONFIG = 0x0107, /* incorrect configuration */
104  VD_ERR_NO_MEMORY = 0x0104, /* out of memory */
105  VD_ERR_SHM_OPEN = 0x010a, /* cannot open shared memory */
106  VD_ERR_SHM_MAP = 0x010b, /* cannot map shared memory */
107  VD_ERR_SOC_OPEN = 0x011a, /* cannot open socket */
108  VD_ERR_SOC_OPT = 0x011b, /* cannot set socket option */
109  VD_ERR_SOC_ADDR = 0x011c, /* cannot resolve host address */
110  VD_ERR_SOC_CONN = 0x011d, /* cannot connect to host */
111  VD_ERR_SOC_SEND = 0x011e, /* error sending data on socket */
112  VD_ERR_SOC_RECV = 0x011f, /* error receiving data from socket */
113  VD_ERR_LOCKED = 0x0202, /* device locked */
114  VD_ERR_NOT_RUN = 0x0204, /* transactor not running */
115  VD_ERR_NOT_OPEN = 0x0205, /* transactor not open/connected */
116  VD_ERR_LICENSE = 0x0206, /* cannot check out the license */
117  VD_ERR_VERSION = 0x0207, /* transactor version mismatch */
118  VD_ERR_TIME_OUT = 0x0301, /* time out, waiting */
119  VD_ERR_NO_POWER = 0x0302, /* power out error */
120  VD_ERR_BUS_ERROR = 0x0304, /* bus protocol error, like pslverr */
121  VD_ERR_NO_ACCESS = 0x0306, /* no access to an object */
122  VD_ERR_INV_HANDLE = 0x0307, /* invalid object handle */
123  VD_ERR_INV_SCOPE = 0x0308, /* invalid scope */
124 };
125 
126 enum {
127  VD_CMD_OPEN = 0x01,
128  VD_CMD_CLOSE = 0x02,
131  VD_CMD_WAIT = 0x09,
141 };
142 
143 enum {
144  VD_ASPACE_AP = 0x01,
145  VD_ASPACE_DP = 0x02,
146  VD_ASPACE_ID = 0x03,
147  VD_ASPACE_AB = 0x04,
148 };
149 
150 enum {
154 };
155 
156 struct vd_shm {
157  struct { /* VD_CHEADER_LEN written by client */
158  uint8_t cmd; /* 000; command */
159  uint8_t type; /* 001; interface type */
160  uint8_t waddr[2]; /* 002; write pointer */
161  uint8_t wbytes[2]; /* 004; data bytes */
162  uint8_t rbytes[2]; /* 006; data bytes to read */
163  uint8_t wwords[2]; /* 008; data words */
164  uint8_t rwords[2]; /* 00a; data words to read */
165  uint8_t rwdata[4]; /* 00c; read/write data */
166  uint8_t offset[4]; /* 010; address offset */
167  uint8_t offseth[2]; /* 014; address offset 47:32 */
168  uint8_t wid[2]; /* 016; request id*/
169  };
170  uint8_t wd8[VD_BUFFER_LEN]; /* 018; */
171  struct { /* VD_SHEADER_LEN written by server */
172  uint8_t rid[2]; /* fd0: request id read */
173  uint8_t awords[2]; /* fd2: actual data words read back */
174  uint8_t status[4]; /* fd4; */
175  uint8_t duttime[8]; /* fd8; */
176  };
177  uint8_t rd8[VD_BUFFER_LEN]; /* fe0: */
178  uint8_t state[4]; /* 1f98; connection state */
179  uint8_t count[4]; /* 1f9c; */
180  uint8_t dummy[96]; /* 1fa0; 48+40B+8B; */
181 } __attribute__((packed));
182 
183 struct vd_rdata {
184  struct list_head lh;
185  uint8_t *rdata;
186 };
187 
188 struct vd_client {
189  uint8_t trans_batch;
192  uint8_t mem_ndx;
193  uint8_t buf_width;
194  uint8_t addr_bits;
195  uint8_t bfm_type;
196  uint16_t sig_read;
197  uint16_t sig_write;
198  uint32_t bfm_period;
203  uint16_t server_port;
204  uint32_t poll_cycles;
205  uint32_t poll_min;
206  uint32_t poll_max;
207  uint32_t targ_time;
208  int hsocket;
209  int64_t poll_ts;
210  char server_name[32];
211  char bfm_path[128];
213  struct vd_rdata rdataq;
214 };
215 
216 struct vd_jtag_hdr {
217  uint64_t tlen:24;
218  uint64_t post:3;
219  uint64_t pre:3;
220  uint64_t cmd:2;
221  uint64_t wlen:16;
222  uint64_t rlen:16;
223 };
224 
225 struct vd_reg_hdr {
226  uint64_t prot:3;
227  uint64_t nonincr:1;
228  uint64_t haddr:12;
229  uint64_t tlen:11;
230  uint64_t asize:3;
231  uint64_t cmd:2;
232  uint64_t addr:32;
233 };
234 
235 static struct vd_shm *pbuf;
236 static struct vd_client vdc;
237 
238 static int vdebug_socket_error(void)
239 {
240 #ifdef _WIN32
241  return WSAGetLastError();
242 #else
243  return errno;
244 #endif
245 }
246 
247 static int vdebug_socket_open(char *server_addr, uint32_t port)
248 {
249  int hsock;
250  int rc = 0;
251  uint32_t buflen = sizeof(struct vd_shm); /* size of the send and rcv buffer */
252  struct addrinfo *ainfo = NULL;
253  struct addrinfo ahint = { 0, AF_INET, SOCK_STREAM, 0, 0, NULL, NULL, NULL };
254 
255 #ifdef _WIN32
256  hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
257  if (hsock < 0)
258  rc = vdebug_socket_error();
259 #elif defined __CYGWIN__
260  /* SO_RCVLOWAT unsupported on CYGWIN */
261  hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
262  if (hsock < 0)
263  rc = errno;
264 #else
265  uint32_t rcvwat = VD_SHEADER_LEN; /* size of the rcv header, as rcv min watermark */
266  hsock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
267  if (hsock < 0)
268  rc = errno;
269  else if (setsockopt(hsock, SOL_SOCKET, SO_RCVLOWAT, &rcvwat, sizeof(rcvwat)) < 0)
270  rc = errno;
271 #endif
272  else if (setsockopt(hsock, SOL_SOCKET, SO_SNDBUF, (const char *)&buflen, sizeof(buflen)) < 0)
273  rc = vdebug_socket_error();
274  else if (setsockopt(hsock, SOL_SOCKET, SO_RCVBUF, (const char *)&buflen, sizeof(buflen)) < 0)
275  rc = vdebug_socket_error();
276 
277  if (rc) {
278  LOG_ERROR("socket_open: cannot set socket option, error %d", rc);
279  } else if (getaddrinfo(server_addr, NULL, &ahint, &ainfo) != 0) {
280  LOG_ERROR("socket_open: cannot resolve address %s, error %d", server_addr, vdebug_socket_error());
281  rc = VD_ERR_SOC_ADDR;
282  } else {
283  h_u16_to_be((uint8_t *)ainfo->ai_addr->sa_data, port);
284  if (connect(hsock, ainfo->ai_addr, sizeof(struct sockaddr)) < 0) {
285  LOG_ERROR("socket_open: cannot connect to %s:%d, error %d", server_addr, port, vdebug_socket_error());
286  rc = VD_ERR_SOC_CONN;
287  }
288  }
289 
290  if (rc) {
291  close_socket(hsock);
292  hsock = 0;
293  }
294 
295  if (ainfo)
296  freeaddrinfo(ainfo);
297 
298  return hsock;
299 }
300 
301 static int vdebug_socket_receive(int hsock, struct vd_shm *pmem)
302 {
303  int rc;
304  int dreceived = 0;
305  int offset = &pmem->rid[0] - &pmem->cmd;
306  int to_receive = VD_SHEADER_LEN + le_to_h_u16(pmem->rbytes);
307  char *pb = (char *)pmem;
308 
309  do {
310  rc = recv(hsock, pb + offset, to_receive, 0);
311  if (rc <= 0) {
312  LOG_WARNING("socket_receive: recv failed, error %d", rc < 0 ? vdebug_socket_error() : 0);
313  return rc;
314  }
315  to_receive -= rc;
316  offset += rc;
317  LOG_DEBUG_IO("socket_receive: received %d, to receive %d", rc, to_receive);
318  dreceived += rc;
319  } while (to_receive);
320 
321  return dreceived;
322 }
323 
324 static int vdebug_socket_send(int hsock, struct vd_shm *pmem)
325 {
326  int rc = send(hsock, (const char *)&pmem->cmd, VD_CHEADER_LEN + le_to_h_u16(pmem->wbytes), 0);
327  if (rc <= 0)
328  LOG_WARNING("socket_send: send failed, error %d", vdebug_socket_error());
329  else
330  LOG_DEBUG_IO("socket_send: sent %d, to send 0", rc);
331 
332  return rc;
333 }
334 
335 static uint32_t vdebug_wait_server(int hsock, struct vd_shm *pmem)
336 {
337  if (!hsock)
338  return VD_ERR_SOC_OPEN;
339 
340  int st = vdebug_socket_send(hsock, pmem);
341  if (st <= 0)
342  return VD_ERR_SOC_SEND;
343 
344  int rd = vdebug_socket_receive(hsock, pmem);
345  if (rd <= 0)
346  return VD_ERR_SOC_RECV;
347 
348  int rc = le_to_h_u32(pmem->status);
349  LOG_DEBUG_IO("wait_server: cmd %02" PRIx8 " done, sent %d, rcvd %d, status %d",
350  pmem->cmd, st, rd, rc);
351 
352  return rc;
353 }
354 
355 static int vdebug_run_jtag_queue(int hsock, struct vd_shm *pm, unsigned int count)
356 {
357  uint8_t num_pre, num_post, tdi, tms;
358  unsigned int num, anum, bytes, hwords, words;
359  unsigned int req, waddr, rwords;
360  int64_t ts, te;
361  uint8_t *tdo;
362  int rc;
363  uint64_t jhdr;
364  struct vd_rdata *rd;
365 
366  req = 0; /* beginning of request */
367  waddr = 0;
368  rwords = 0;
371  ts = timeval_ms();
372  rc = vdebug_wait_server(hsock, pm);
373  while (!rc && (req < count)) { /* loop over requests to read data and print out */
374  jhdr = le_to_h_u64(&pm->wd8[waddr * 4]);
375  words = jhdr >> 48;
376  hwords = (jhdr >> 32) & 0xffff;
377  anum = jhdr & 0xffffff;
378  num_pre = (jhdr >> 27) & 0x7;
379  num_post = (jhdr >> 24) & 0x7;
380  if (num_post)
381  num = anum - num_pre - num_post + 1;
382  else
383  num = anum - num_pre;
384  bytes = (num + 7) / 8;
385  vdc.trans_last = (req + 1) < count ? 0 : 1;
386  vdc.trans_first = waddr ? 0 : 1;
387  if (((jhdr >> 30) & 0x3) == 3) { /* cmd is read */
388  if (!rwords) {
389  rd = &vdc.rdataq;
390  tdo = rd->rdata;
391  } else {
392  rd = list_first_entry(&vdc.rdataq.lh, struct vd_rdata, lh);
393  tdo = rd->rdata;
394  list_del(&rd->lh);
395  free(rd);
396  }
397  for (unsigned int j = 0; j < bytes; j++) {
398  tdo[j] = (pm->rd8[rwords * 8 + j] >> num_pre) | (pm->rd8[rwords * 8 + j + 1] << (8 - num_pre));
399  LOG_DEBUG_IO("%04x D0[%02x]:%02x", le_to_h_u16(pm->wid) - count + req, j, tdo[j]);
400  }
401  rwords += words; /* read data offset */
402  } else {
403  tdo = NULL;
404  }
405  waddr += sizeof(uint64_t) / 4; /* waddr past header */
406  tdi = (pm->wd8[waddr * 4] >> num_pre) | (pm->wd8[waddr * 4 + 1] << (8 - num_pre));
407  tms = (pm->wd8[waddr * 4 + 4] >> num_pre) | (pm->wd8[waddr * 4 + 4 + 1] << (8 - num_pre));
408  LOG_DEBUG_IO("%04x L:%02d O:%05x @%03x DI:%02x MS:%02x DO:%02x",
409  le_to_h_u16(pm->wid) - count + req, num, (vdc.trans_first << 14) | (vdc.trans_last << 15),
410  waddr - 2, tdi, tms, (tdo ? tdo[0] : 0xdd));
411  waddr += hwords * 2; /* start of next request */
412  req += 1;
413  }
414 
415  if (rc) {
416  LOG_ERROR("0x%x executing transaction", rc);
417  rc = ERROR_FAIL;
418  }
419 
420  te = timeval_ms();
421  vdc.targ_time += (uint32_t)(te - ts);
422  h_u16_to_le(pm->offseth, 0); /* reset buffer write address */
423  h_u32_to_le(pm->offset, 0);
424  h_u16_to_le(pm->rwords, 0);
425  h_u16_to_le(pm->waddr, 0);
426  assert(list_empty(&vdc.rdataq.lh));/* list should be empty after run queue */
427 
428  return rc;
429 }
430 
431 static int vdebug_run_reg_queue(int hsock, struct vd_shm *pm, unsigned int count)
432 {
433  unsigned int num, awidth, wwidth;
434  unsigned int req, waddr, rwords;
435  uint8_t aspace;
436  uint32_t addr;
437  int64_t ts, te;
438  uint8_t *data;
439  int rc;
440  uint64_t rhdr;
441  struct vd_rdata *rd;
442 
443  req = 0; /* beginning of request */
444  waddr = 0;
445  rwords = 0;
448  ts = timeval_ms();
449  rc = vdebug_wait_server(hsock, pm);
450  while (!rc && (req < count)) { /* loop over requests to read data and print out */
451  rhdr = le_to_h_u64(&pm->wd8[waddr * 4]);
452  addr = rhdr >> 32; /* reconstruct data for a single request */
453  num = (rhdr >> 16) & 0x7ff;
454  aspace = rhdr & 0x3;
455  awidth = (1 << ((rhdr >> 27) & 0x7));
456  wwidth = (awidth + vdc.buf_width - 1) / vdc.buf_width;
457  vdc.trans_last = (req + 1) < count ? 0 : 1;
458  vdc.trans_first = waddr ? 0 : 1;
459  if (((rhdr >> 30) & 0x3) == 2) { /* cmd is read */
460  if (num) {
461  if (!rwords) {
462  rd = &vdc.rdataq;
463  data = rd->rdata;
464  } else {
465  rd = list_first_entry(&vdc.rdataq.lh, struct vd_rdata, lh);
466  data = rd->rdata;
467  list_del(&rd->lh);
468  free(rd);
469  }
470  for (unsigned int j = 0; j < num; j++)
471  memcpy(&data[j * awidth], &pm->rd8[(rwords + j) * awidth], awidth);
472  }
473  LOG_DEBUG("read %04x AS:%1x RG:%1x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req,
474  aspace, addr << 2, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr,
475  (num ? le_to_h_u32(&pm->rd8[rwords * 4]) : 0xdead));
476  rwords += num * wwidth;
477  waddr += sizeof(uint64_t) / 4; /* waddr past header */
478  } else {
479  LOG_DEBUG("write %04x AS:%1x RG:%1x O:%05x @%03x D:%08x", le_to_h_u16(pm->wid) - count + req,
480  aspace, addr << 2, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr,
481  le_to_h_u32(&pm->wd8[(waddr + num + 1) * 4]));
482  waddr += sizeof(uint64_t) / 4 + (num * wwidth * awidth + 3) / 4;
483  }
484  req += 1;
485  }
486 
487  if (rc) {
488  LOG_ERROR("0x%x executing transaction", rc);
489  rc = ERROR_FAIL;
490  }
491 
492  te = timeval_ms();
493  vdc.targ_time += (uint32_t)(te - ts);
494  h_u16_to_le(pm->offseth, 0); /* reset buffer write address */
495  h_u32_to_le(pm->offset, 0);
496  h_u16_to_le(pm->rwords, 0);
497  h_u16_to_le(pm->waddr, 0);
498  assert(list_empty(&vdc.rdataq.lh));/* list should be empty after run queue */
499 
500  return rc;
501 }
502 
503 static int vdebug_open(int hsock, struct vd_shm *pm, const char *path,
504  uint8_t type, uint32_t period_ps, uint32_t sig_mask)
505 {
506  int rc = VD_ERR_NOT_OPEN;
507 
508  pm->cmd = VD_CMD_OPEN;
509  h_u16_to_le(pm->wid, VD_VERSION); /* client version */
510  h_u16_to_le(pm->wbytes, 0);
511  h_u16_to_le(pm->rbytes, 0);
512  h_u16_to_le(pm->wwords, 0);
513  h_u16_to_le(pm->rwords, 0);
514  rc = vdebug_wait_server(hsock, pm);
515  if (rc != 0) { /* communication problem */
516  LOG_ERROR("0x%x connecting to server", rc);
517  } else if (le_to_h_u16(pm->rid) < le_to_h_u16(pm->wid)) {
518  LOG_ERROR("server version %d too old for the client %d", le_to_h_u16(pm->rid), le_to_h_u16(pm->wid));
519  pm->cmd = VD_CMD_CLOSE; /* let server close the connection */
520  vdebug_wait_server(hsock, pm);
521  rc = VD_ERR_VERSION;
522  } else {
523  pm->cmd = VD_CMD_CONNECT;
524  pm->type = type; /* BFM type to connect to */
525  h_u32_to_le(pm->rwdata, sig_mask | VD_SIG_BUF | (VD_SIG_BUF << 16));
526  h_u16_to_le(pm->wbytes, strlen(path) + 1);
527  h_u16_to_le(pm->rbytes, 12);
528  h_u16_to_le(pm->wid, 0); /* reset wid for transaction ID */
529  h_u16_to_le(pm->wwords, 0);
530  h_u16_to_le(pm->rwords, 0);
531  memcpy(pm->wd8, path, le_to_h_u16(pm->wbytes));
532  rc = vdebug_wait_server(hsock, pm);
533  vdc.sig_read = le_to_h_u32(pm->rwdata) >> 16; /* signal read mask */
534  vdc.sig_write = le_to_h_u32(pm->rwdata); /* signal write mask */
535  vdc.bfm_period = period_ps;
536  vdc.buf_width = le_to_h_u32(&pm->rd8[0]) / 8;/* access width in bytes */
537  vdc.addr_bits = le_to_h_u32(&pm->rd8[2 * 4]); /* supported address bits */
538  }
539 
540  if (rc) {
541  LOG_ERROR("0x%x connecting to BFM %s", rc, path);
542  return ERROR_FAIL;
543  }
544 
546  LOG_DEBUG("%s type %0x, period %dps, buffer %dx%dB signals r%04xw%04x",
549 
550  return ERROR_OK;
551 }
552 
553 static int vdebug_close(int hsock, struct vd_shm *pm, uint8_t type)
554 {
555  pm->cmd = VD_CMD_DISCONNECT;
556  pm->type = type; /* BFM type, here JTAG */
557  h_u16_to_le(pm->wbytes, 0);
558  h_u16_to_le(pm->rbytes, 0);
559  h_u16_to_le(pm->wwords, 0);
560  h_u16_to_le(pm->rwords, 0);
561  vdebug_wait_server(hsock, pm);
562  pm->cmd = VD_CMD_CLOSE;
563  h_u16_to_le(pm->wid, VD_VERSION); /* client version */
564  h_u16_to_le(pm->wbytes, 0);
565  h_u16_to_le(pm->rbytes, 0);
566  h_u16_to_le(pm->wwords, 0);
567  h_u16_to_le(pm->rwords, 0);
568  vdebug_wait_server(hsock, pm);
569  LOG_DEBUG("type %0x", type);
570 
571  return ERROR_OK;
572 }
573 
574 static int vdebug_wait(int hsock, struct vd_shm *pm, uint32_t cycles)
575 {
576  if (cycles) {
577  pm->cmd = VD_CMD_WAIT;
578  h_u16_to_le(pm->wbytes, 0);
579  h_u16_to_le(pm->rbytes, 0);
580  h_u32_to_le(pm->rwdata, cycles); /* clock sycles to wait */
581  int rc = vdebug_wait_server(hsock, pm);
582  if (rc) {
583  LOG_ERROR("0x%x waiting %" PRIx32 " cycles", rc, cycles);
584  return ERROR_FAIL;
585  }
586  LOG_DEBUG("%d cycles", cycles);
587  }
588 
589  return ERROR_OK;
590 }
591 
592 static int vdebug_sig_set(int hsock, struct vd_shm *pm, uint32_t write_mask, uint32_t value)
593 {
594  pm->cmd = VD_CMD_SIGSET;
595  h_u16_to_le(pm->wbytes, 0);
596  h_u16_to_le(pm->rbytes, 0);
597  h_u32_to_le(pm->rwdata, (write_mask << 16) | (value & 0xffff)); /* mask and value of signals to set */
598  int rc = vdebug_wait_server(hsock, pm);
599  if (rc) {
600  LOG_ERROR("0x%x setting signals %04" PRIx32, rc, write_mask);
601  return ERROR_FAIL;
602  }
603 
604  LOG_DEBUG("setting signals %04" PRIx32 " to %04" PRIx32, write_mask, value);
605 
606  return ERROR_OK;
607 }
608 
609 static int vdebug_jtag_clock(int hsock, struct vd_shm *pm, uint32_t value)
610 {
611  pm->cmd = VD_CMD_JTAGCLOCK;
612  h_u16_to_le(pm->wbytes, 0);
613  h_u16_to_le(pm->rbytes, 0);
614  h_u32_to_le(pm->rwdata, value); /* divider value */
615  int rc = vdebug_wait_server(hsock, pm);
616  if (rc) {
617  LOG_ERROR("0x%x setting jtag_clock", rc);
618  return ERROR_FAIL;
619  }
620 
621  LOG_DEBUG("setting jtag clock divider to %" PRIx32, value);
622 
623  return ERROR_OK;
624 }
625 
626 static int vdebug_jtag_shift_tap(int hsock, struct vd_shm *pm, uint8_t num_pre,
627  const uint8_t tms_pre, uint32_t num, const uint8_t *tdi,
628  uint8_t num_post, const uint8_t tms_post, uint8_t *tdo,
629  uint8_t f_last)
630 {
631  const uint32_t tobits = 8;
632  uint16_t bytes, hwords, anum, words, waddr;
633  int rc = 0;
634 
635  pm->cmd = VD_CMD_JTAGSHTAP;
636  vdc.trans_last = f_last || (vdc.trans_batch == VD_BATCH_NO);
637  if (vdc.trans_first)
638  waddr = 0; /* reset buffer offset */
639  else
640  waddr = le_to_h_u32(pm->offseth); /* continue from the previous transaction */
641  if (num_post) /* actual number of bits to shift */
642  anum = num + num_pre + num_post - 1;
643  else
644  anum = num + num_pre;
645  hwords = (anum + 4 * vdc.buf_width - 1) / (4 * vdc.buf_width); /* in 4B TDI/TMS words */
646  words = (hwords + 1) / 2; /* in 8B TDO words to read */
647  bytes = (num + 7) / 8; /* data only portion in bytes */
648  /* buffer overflow check and flush */
649  if (4 * waddr + sizeof(uint64_t) + 8 * hwords + 64 > VD_BUFFER_LEN) {
650  vdc.trans_last = 1; /* force flush within 64B of buffer end */
651  } else if (4 * waddr + sizeof(uint64_t) + 8 * hwords > VD_BUFFER_LEN) {
652  /* this req does not fit, discard it */
653  LOG_ERROR("%04x L:%02d O:%05x @%04x too many bits to shift",
654  le_to_h_u16(pm->wid), anum, (vdc.trans_first << 14) | (vdc.trans_last << 15), waddr);
655  rc = ERROR_FAIL;
656  }
657 
658  if (!rc && anum) {
659  uint16_t i, j; /* portability requires to use bit operations for 8B JTAG header */
660  uint64_t jhdr = (tdo ? ((uint64_t)(words) << 48) : 0) + ((uint64_t)(hwords) << 32) +
661  ((tdo ? 3UL : 1UL) << 30) + (num_pre << 27) + (num_post << 24) + anum;
662  h_u64_to_le(&pm->wd8[4 * waddr], jhdr);
663 
664  h_u16_to_le(pm->wid, le_to_h_u16(pm->wid) + 1); /* transaction ID */
665  waddr += 2; /* waddr past header */
666  /* TDI/TMS data follows as 32 bit word pairs {TMS,TDI} */
667  pm->wd8[4 * waddr] = (tdi ? (tdi[0] << num_pre) : 0);
668  pm->wd8[4 * waddr + 4] = tms_pre; /* init with tms_pre */
669  if (num + num_pre <= 8) /* and tms_post for num <=4 */
670  pm->wd8[4 * waddr + 4] |= (tms_post << (num + num_pre - 1));
671  for (i = 1, j = 4 * waddr; i < bytes; i++) {
672  if (i == bytes - 1 && num + num_pre <= bytes * tobits)
673  pm->wd8[j + i + 4] = tms_post << ((num + num_pre - 1) % 8);
674  else
675  pm->wd8[j + i + 4] = 0x0;/* placing 4 bytes of TMS bits into high word */
676  if (!tdi) /* placing 4 bytes of TDI bits into low word */
677  pm->wd8[j + i] = 0x0;
678  else
679  pm->wd8[j + i] = (tdi[i] << num_pre) | (tdi[i - 1] >> (8 - num_pre));
680  if (i % 4 == 3)
681  j += 4;
682  }
683 
684  if (tdi)
685  if (num + num_pre > bytes * tobits) /* in case 1 additional byte needed for TDI */
686  pm->wd8[j + i] = (tdi[i - 1] >> (8 - num_pre)); /* put last TDI bits there */
687 
688  if (num + num_pre <= bytes * tobits) { /* in case no or 1 additional byte needed */
689  pm->wd8[j + i + 4] = tms_post >> (8 - (num + num_pre - 1) % 8); /* may need to add higher part */
690  /* in case exactly 1 additional byte needed */
691  } else if (num + num_pre > bytes * tobits && anum <= (bytes + 1) * tobits) {
692  pm->wd8[j + i + 4] = tms_post << ((num + num_pre - 1) % 8); /* add whole tms_post */
693  } else { /* in case 2 additional bytes, tms_post split */
694  pm->wd8[j + i + 4] = tms_post << ((num + num_pre - 1) % 8);/* add lower part of tms_post */
695  if (i % 4 == 3) /* next byte is in the next 32b word */
696  pm->wd8[j + i + 4 + 5] = tms_post >> (8 - (num + num_pre - 1) % 8); /* and higher part */
697  else /* next byte is in the same 32b word */
698  pm->wd8[j + i + 4 + 1] = tms_post >> (8 - (num + num_pre - 1) % 8); /* and higher part */
699  }
700 
701  if (tdo) {
702  struct vd_rdata *rd;
703  if (le_to_h_u16(pm->rwords) == 0) {
704  rd = &vdc.rdataq;
705  } else {
706  rd = calloc(1, sizeof(struct vd_rdata));
707  if (!rd) /* check allocation for 24B */
708  return ERROR_FAIL;
709  list_add_tail(&rd->lh, &vdc.rdataq.lh);
710  }
711  rd->rdata = tdo;
712  h_u16_to_le(pm->rwords, le_to_h_u16(pm->rwords) + words);/* keep track of the words to read */
713  }
714  h_u16_to_le(pm->wwords, waddr / 2 + hwords); /* payload size *2 to include both TDI and TMS data */
715  h_u16_to_le(pm->waddr, le_to_h_u16(pm->waddr) + 1);
716  }
717 
718  if (!waddr) /* flush issued, but buffer empty */
719  ;
720  else if (!vdc.trans_last) /* buffered request */
721  h_u16_to_le(pm->offseth, waddr + hwords * 2); /* offset for next transaction, must be even */
722  else /* execute batch of requests */
723  rc = vdebug_run_jtag_queue(hsock, pm, le_to_h_u16(pm->waddr));
724  vdc.trans_first = vdc.trans_last; /* flush forces trans_first flag */
725 
726  return rc;
727 }
728 
729 static int vdebug_reg_write(int hsock, struct vd_shm *pm, const uint32_t reg,
730  const uint32_t data, uint8_t aspace, uint8_t f_last)
731 {
732  uint32_t waddr;
733  int rc = ERROR_OK;
734 
735  pm->cmd = VD_CMD_REGWRITE;
736  vdc.trans_last = f_last || (vdc.trans_batch == VD_BATCH_NO);
737  if (vdc.trans_first)
738  waddr = 0; /* reset buffer offset */
739  else
740  waddr = le_to_h_u16(pm->offseth); /* continue from the previous transaction */
741 
742  if (4 * waddr + 2 * sizeof(uint64_t) + 4 > VD_BUFFER_LEN)
743  vdc.trans_last = 1; /* force flush, no room for next request */
744 
745  uint64_t rhdr = ((uint64_t)reg << 32) + (1UL << 30) + (2UL << 27) + (1UL << 16) + aspace;
746  h_u64_to_le(&pm->wd8[4 * waddr], rhdr);
747  h_u32_to_le(&pm->wd8[4 * (waddr + 2)], data);
748  h_u16_to_le(pm->wid, le_to_h_u16(pm->wid) + 1);
749  h_u16_to_le(pm->wwords, waddr + 3);
750  h_u16_to_le(pm->waddr, le_to_h_u16(pm->waddr) + 1);
751  if (!vdc.trans_last) /* buffered request */
752  h_u16_to_le(pm->offseth, waddr + 3);
753  else
754  rc = vdebug_run_reg_queue(hsock, pm, le_to_h_u16(pm->waddr));
755  vdc.trans_first = vdc.trans_last; /* flush forces trans_first flag */
756 
757  return rc;
758 }
759 
760 static int vdebug_reg_read(int hsock, struct vd_shm *pm, const uint32_t reg,
761  uint32_t *data, uint8_t aspace, uint8_t f_last)
762 {
763  uint32_t waddr;
764  int rc = ERROR_OK;
765 
766  pm->cmd = VD_CMD_REGREAD;
767  vdc.trans_last = f_last || (vdc.trans_batch == VD_BATCH_NO);
768  if (vdc.trans_first)
769  waddr = 0; /* reset buffer offset */
770  else
771  waddr = le_to_h_u16(pm->offseth); /* continue from the previous transaction */
772 
773  if (4 * waddr + 2 * sizeof(uint64_t) + 4 > VD_BUFFER_LEN)
774  vdc.trans_last = 1; /* force flush, no room for next request */
775 
776  uint64_t rhdr = ((uint64_t)reg << 32) + (2UL << 30) + (2UL << 27) + ((data ? 1UL : 0UL) << 16) + aspace;
777  h_u64_to_le(&pm->wd8[4 * waddr], rhdr);
778  h_u16_to_le(pm->wid, le_to_h_u16(pm->wid) + 1);
779  if (data) {
780  struct vd_rdata *rd;
781  if (le_to_h_u16(pm->rwords) == 0) {
782  rd = &vdc.rdataq;
783  } else {
784  rd = calloc(1, sizeof(struct vd_rdata));
785  if (!rd) /* check allocation for 24B */
786  return ERROR_FAIL;
787  list_add_tail(&rd->lh, &vdc.rdataq.lh);
788  }
789  rd->rdata = (uint8_t *)data;
790  h_u16_to_le(pm->rwords, le_to_h_u16(pm->rwords) + 1);
791  }
792  h_u16_to_le(pm->wwords, waddr + 2);
793  h_u16_to_le(pm->waddr, le_to_h_u16(pm->waddr) + 1);
794  if (!vdc.trans_last) /* buffered request */
795  h_u16_to_le(pm->offseth, waddr + 2);
796  else
797  rc = vdebug_run_reg_queue(hsock, pm, le_to_h_u16(pm->waddr));
798  vdc.trans_first = vdc.trans_last; /* flush forces trans_first flag */
799 
800  return rc;
801 }
802 
803 static int vdebug_mem_open(int hsock, struct vd_shm *pm, const char *path, uint8_t ndx)
804 {
805  int rc;
806 
807  if (!path)
808  return ERROR_OK;
809 
810  pm->cmd = VD_CMD_MEMOPEN;
811  h_u16_to_le(pm->wbytes, strlen(path) + 1); /* includes terminating 0 */
812  h_u16_to_le(pm->rbytes, 8);
813  h_u16_to_le(pm->wwords, 0);
814  h_u16_to_le(pm->rwords, 0);
815  memcpy(pm->wd8, path, le_to_h_u16(pm->wbytes));
816  rc = vdebug_wait_server(hsock, pm);
817  if (rc) {
818  LOG_ERROR("0x%x opening memory %s", rc, path);
819  } else if (ndx != pm->rd8[2]) {
820  LOG_WARNING("Invalid memory index %" PRIu16 " returned. Direct memory access disabled", pm->rd8[2]);
821  } else {
822  vdc.mem_width[ndx] = le_to_h_u16(&pm->rd8[0]) / 8; /* memory width in bytes */
823  vdc.mem_depth[ndx] = le_to_h_u32(&pm->rd8[4]); /* memory depth in words */
824  LOG_DEBUG("%" PRIx8 ": %s memory %" PRIu32 "x%" PRIu32 "B, buffer %" PRIu32 "x%" PRIu32 "B", ndx, path,
825  vdc.mem_depth[ndx], vdc.mem_width[ndx], VD_BUFFER_LEN / vdc.mem_width[ndx], vdc.mem_width[ndx]);
826  }
827 
828  return ERROR_OK;
829 }
830 
831 static void vdebug_mem_close(int hsock, struct vd_shm *pm, uint8_t ndx)
832 {
833  pm->cmd = VD_CMD_MEMCLOSE;
834  h_u32_to_le(pm->rwdata, ndx); /* which memory */
835  h_u16_to_le(pm->wbytes, 0);
836  h_u16_to_le(pm->rbytes, 0);
837  h_u16_to_le(pm->wwords, 0);
838  h_u16_to_le(pm->rwords, 0);
839  vdebug_wait_server(hsock, pm);
840  LOG_DEBUG("%" PRIx8 ": %s", ndx, vdc.mem_path[ndx]);
841 }
842 
843 
844 /* function gets invoked through a callback every VD_POLL_INTERVAL ms
845  * if the idle time, measured by VD_POLL_INTERVAL - targ_time is more than poll_min
846  * the wait function is called and its time measured and wait cycles adjusted.
847  * The wait allows hardware to advance, when no data activity from the vdebug occurs
848  */
849 static int vdebug_poll(void *priv)
850 {
851  int64_t ts, te;
852 
853  ts = timeval_ms();
854  if (ts - vdc.poll_ts - vdc.targ_time >= vdc.poll_min) {
856  te = timeval_ms();
857  LOG_DEBUG("poll after %" PRId64 "ms, busy %" PRIu32 "ms; wait %" PRIu32 " %" PRId64 "ms",
858  ts - vdc.poll_ts, vdc.targ_time, vdc.poll_cycles, te - ts);
859 
860  if (te - ts + vdc.targ_time < vdc.poll_max / 2)
861  vdc.poll_cycles *= 2;
862  else if (te - ts + vdc.targ_time > vdc.poll_max)
863  vdc.poll_cycles /= 2;
864  } else {
865  LOG_DEBUG("poll after %" PRId64 "ms, busy %" PRIu32 "ms", ts - vdc.poll_ts, vdc.targ_time);
866  }
867  vdc.poll_ts = ts;
868  vdc.targ_time = 0; /* reset target time counter */
869 
870  return ERROR_OK;
871 }
872 
873 static int vdebug_init(void)
874 {
876  pbuf = calloc(1, sizeof(struct vd_shm));
877  if (!pbuf) {
879  vdc.hsocket = 0;
880  LOG_ERROR("cannot allocate %zu bytes", sizeof(struct vd_shm));
881  return ERROR_FAIL;
882  }
883  if (vdc.hsocket <= 0) {
884  free(pbuf);
885  pbuf = NULL;
886  LOG_ERROR("cannot connect to vdebug server %s:%" PRIu16,
888  return ERROR_FAIL;
889  }
890  vdc.trans_first = 1;
892  vdc.poll_ts = timeval_ms();
893  uint32_t sig_mask = VD_SIG_RESET;
894  if (transport_is_jtag())
895  sig_mask |= VD_SIG_TRST | VD_SIG_TCKDIV;
896 
897  int rc = vdebug_open(vdc.hsocket, pbuf, vdc.bfm_path, vdc.bfm_type, vdc.bfm_period, sig_mask);
898  if (rc != 0) {
899  LOG_ERROR("0x%x cannot connect to %s", rc, vdc.bfm_path);
901  vdc.hsocket = 0;
902  free(pbuf);
903  pbuf = NULL;
904  } else {
905  for (uint8_t i = 0; i < vdc.mem_ndx; i++) {
906  rc = vdebug_mem_open(vdc.hsocket, pbuf, vdc.mem_path[i], i);
907  if (rc != 0)
908  LOG_ERROR("0x%x cannot connect to %s", rc, vdc.mem_path[i]);
909  }
910 
913  LOG_INFO("vdebug %d connected to %s through %s:%" PRIu16,
915  }
916 
917  return rc;
918 }
919 
920 static int vdebug_quit(void)
921 {
923 
924  for (uint8_t i = 0; i < vdc.mem_ndx; i++)
925  if (vdc.mem_width[i])
927  int rc = vdebug_close(vdc.hsocket, pbuf, vdc.bfm_type);
928  LOG_INFO("vdebug %d disconnected from %s through %s:%" PRIu16 " rc:%d", VD_VERSION,
930  if (vdc.hsocket)
932  free(pbuf);
933  pbuf = NULL;
934 
935  return ERROR_OK;
936 }
937 
938 static int vdebug_reset(int trst, int srst)
939 {
940  uint16_t sig_val = 0xffff;
941  uint16_t sig_mask = 0;
942 
943  sig_mask |= VD_SIG_RESET;
944  if (srst)
945  sig_val &= ~VD_SIG_RESET;/* active low */
946  if (transport_is_jtag()) {
947  sig_mask |= VD_SIG_TRST;
948  if (trst)
949  sig_val &= ~VD_SIG_TRST; /* active low */
950  }
951 
952  LOG_INFO("rst trst:%d srst:%d mask:%" PRIx16 " val:%" PRIx16, trst, srst, sig_mask, sig_val);
953  int rc = vdebug_sig_set(vdc.hsocket, pbuf, sig_mask, sig_val);
954  if (rc == 0)
955  rc = vdebug_wait(vdc.hsocket, pbuf, 20); /* 20 clock cycles pulse */
956 
957  return rc;
958 }
959 
960 static int vdebug_jtag_tms_seq(const uint8_t *tms, int num, uint8_t f_flush)
961 {
962  LOG_DEBUG_IO("tms len:%d tms:%x", num, *tms);
963 
964  return vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num, *tms, 0, NULL, 0, 0, NULL, f_flush);
965 }
966 
967 static int vdebug_jtag_path_move(struct pathmove_command *cmd, uint8_t f_flush)
968 {
969  uint8_t tms[DIV_ROUND_UP(cmd->num_states, 8)];
970  LOG_DEBUG_IO("path num states %u", cmd->num_states);
971 
972  memset(tms, 0, DIV_ROUND_UP(cmd->num_states, 8));
973 
974  for (unsigned int i = 0; i < cmd->num_states; i++) {
975  if (tap_state_transition(tap_get_state(), true) == cmd->path[i])
976  buf_set_u32(tms, i, 1, 1);
977  tap_set_state(cmd->path[i]);
978  }
979 
980  return vdebug_jtag_tms_seq(tms, cmd->num_states, f_flush);
981 }
982 
983 static int vdebug_jtag_tlr(enum tap_state state, uint8_t f_flush)
984 {
985  int rc = ERROR_OK;
986 
987  enum tap_state cur = tap_get_state();
988  uint8_t tms_pre = tap_get_tms_path(cur, state);
989  uint8_t num_pre = tap_get_tms_path_len(cur, state);
990  LOG_DEBUG_IO("tlr from %x to %x", cur, state);
991  if (cur != state) {
992  rc = vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num_pre, tms_pre, 0, NULL, 0, 0, NULL, f_flush);
994  }
995 
996  return rc;
997 }
998 
999 static int vdebug_jtag_scan(struct scan_command *cmd, uint8_t f_flush)
1000 {
1001  int rc = ERROR_OK;
1002 
1003  enum tap_state cur = tap_get_state();
1004  uint8_t state = cmd->ir_scan ? TAP_IRSHIFT : TAP_DRSHIFT;
1005  uint8_t tms_pre = tap_get_tms_path(cur, state);
1006  uint8_t num_pre = tap_get_tms_path_len(cur, state);
1007  uint8_t tms_post = tap_get_tms_path(state, cmd->end_state);
1008  uint8_t num_post = tap_get_tms_path_len(state, cmd->end_state);
1009  const unsigned int num_bits = jtag_scan_size(cmd);
1010  LOG_DEBUG_IO("scan len:%u fields:%u ir/!dr:%d state cur:%x end:%x",
1011  num_bits, cmd->num_fields, cmd->ir_scan, cur, cmd->end_state);
1012  for (unsigned int i = 0; i < cmd->num_fields; i++) {
1013  uint8_t cur_num_pre = i == 0 ? num_pre : 0;
1014  uint8_t cur_tms_pre = i == 0 ? tms_pre : 0;
1015  uint8_t cur_num_post = i == cmd->num_fields - 1 ? num_post : 0;
1016  uint8_t cur_tms_post = i == cmd->num_fields - 1 ? tms_post : 0;
1017  uint8_t cur_flush = i == cmd->num_fields - 1 ? f_flush : 0;
1018  rc = vdebug_jtag_shift_tap(vdc.hsocket, pbuf, cur_num_pre, cur_tms_pre,
1019  cmd->fields[i].num_bits, cmd->fields[i].out_value, cur_num_post, cur_tms_post,
1020  cmd->fields[i].in_value, cur_flush);
1021  if (rc)
1022  break;
1023  }
1024 
1025  if (cur != cmd->end_state)
1026  tap_set_state(cmd->end_state);
1027 
1028  return rc;
1029 }
1030 
1031 static int vdebug_jtag_runtest(unsigned int num_cycles, enum tap_state state, uint8_t f_flush)
1032 {
1033  enum tap_state cur = tap_get_state();
1034  uint8_t tms_pre = tap_get_tms_path(cur, state);
1035  uint8_t num_pre = tap_get_tms_path_len(cur, state);
1036  LOG_DEBUG_IO("idle len:%u state cur:%x end:%x", num_cycles, cur, state);
1037  int rc = vdebug_jtag_shift_tap(vdc.hsocket, pbuf, num_pre, tms_pre, num_cycles, NULL, 0, 0, NULL, f_flush);
1038  if (cur != state)
1040 
1041  return rc;
1042 }
1043 
1044 static int vdebug_jtag_stableclocks(unsigned int num_cycles, uint8_t f_flush)
1045 {
1046  LOG_DEBUG("stab len:%u state cur:%x", num_cycles, tap_get_state());
1047 
1048  return vdebug_jtag_shift_tap(vdc.hsocket, pbuf, 0, 0, num_cycles, NULL, 0, 0, NULL, f_flush);
1049 }
1050 
1051 static int vdebug_sleep(int us)
1052 {
1053  LOG_INFO("sleep %d us", us);
1054 
1055  return vdebug_wait(vdc.hsocket, pbuf, us / 1000);
1056 }
1057 
1058 static int vdebug_jtag_speed(int speed)
1059 {
1060  unsigned int clkmax = VD_SCALE_PSTOMS / (vdc.bfm_period * 2); /* kHz */
1061  unsigned int divval = clkmax / speed;
1062  LOG_INFO("jclk speed:%d kHz set, BFM divider %u", speed, divval);
1063 
1064  return vdebug_jtag_clock(vdc.hsocket, pbuf, divval);
1065 }
1066 
1067 static int vdebug_jtag_khz(int khz, int *jtag_speed)
1068 {
1069  unsigned int clkmax = VD_SCALE_PSTOMS / (vdc.bfm_period * 2); /* kHz */
1070  unsigned int divval = khz ? clkmax / khz : 1;
1071  *jtag_speed = clkmax / divval;
1072  LOG_DEBUG("khz speed:%d from khz:%d", *jtag_speed, khz);
1073 
1074  return ERROR_OK;
1075 }
1076 
1077 static int vdebug_jtag_div(int speed, int *khz)
1078 {
1079  *khz = speed;
1080  LOG_DEBUG("div khz:%d from speed:%d", *khz, speed);
1081 
1082  return ERROR_OK;
1083 }
1084 
1085 static int vdebug_jtag_execute_queue(struct jtag_command *cmd_queue)
1086 {
1087  int rc = ERROR_OK;
1088 
1089  for (struct jtag_command *cmd = cmd_queue; rc == ERROR_OK && cmd; cmd = cmd->next) {
1090  switch (cmd->type) {
1091  case JTAG_RUNTEST:
1092  rc = vdebug_jtag_runtest(cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state, !cmd->next);
1093  break;
1094  case JTAG_STABLECLOCKS:
1095  rc = vdebug_jtag_stableclocks(cmd->cmd.stableclocks->num_cycles, !cmd->next);
1096  break;
1097  case JTAG_TLR_RESET:
1098  rc = vdebug_jtag_tlr(cmd->cmd.statemove->end_state, !cmd->next);
1099  break;
1100  case JTAG_PATHMOVE:
1101  rc = vdebug_jtag_path_move(cmd->cmd.pathmove, !cmd->next);
1102  break;
1103  case JTAG_TMS:
1104  rc = vdebug_jtag_tms_seq(cmd->cmd.tms->bits, cmd->cmd.tms->num_bits, !cmd->next);
1105  break;
1106  case JTAG_SLEEP:
1107  rc = vdebug_sleep(cmd->cmd.sleep->us);
1108  break;
1109  case JTAG_SCAN:
1110  rc = vdebug_jtag_scan(cmd->cmd.scan, !cmd->next);
1111  break;
1112  default:
1113  LOG_ERROR("Unknown JTAG command type 0x%x encountered", cmd->type);
1114  rc = ERROR_FAIL;
1115  }
1116  }
1117 
1118  return rc;
1119 }
1120 
1121 static int vdebug_dap_bankselect(struct adiv5_ap *ap, unsigned int reg)
1122 {
1123  int rc = ERROR_OK;
1124  uint64_t sel;
1125 
1126  if (is_adiv6(ap->dap)) {
1127  sel = ap->ap_num | (reg & 0x00000FF0);
1128  if (sel != (ap->dap->select & ~0xfull)) {
1129  sel |= ap->dap->select & DP_SELECT_DPBANK;
1130  if (ap->dap->asize > 32)
1131  sel |= (DP_SELECT1 >> 4) & DP_SELECT_DPBANK;
1132  ap->dap->select = sel;
1133  ap->dap->select_valid = true;
1134  rc = vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, (uint32_t)sel, VD_ASPACE_DP, 0);
1135  if (rc == ERROR_OK) {
1136  ap->dap->select_valid = true;
1137  if (ap->dap->asize > 32)
1139  (uint32_t)(sel >> 32), VD_ASPACE_DP, 0);
1140  if (rc == ERROR_OK)
1141  ap->dap->select1_valid = true;
1142  }
1143  }
1144  } else { /* ADIv5 */
1145  sel = (ap->ap_num << 24) | (reg & ADIV5_DP_SELECT_APBANK);
1146  if (sel != ap->dap->select) {
1147  ap->dap->select = sel;
1148  rc = vdebug_reg_write(vdc.hsocket, pbuf, DP_SELECT >> 2, (uint32_t)sel, VD_ASPACE_DP, 0);
1149  if (rc == ERROR_OK)
1150  ap->dap->select_valid = true;
1151  }
1152  }
1153  return rc;
1154 }
1155 
1156 static int vdebug_dap_connect(struct adiv5_dap *dap)
1157 {
1158  return dap_dp_init(dap);
1159 }
1160 
1161 static int vdebug_dap_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
1162 {
1163  return ERROR_OK;
1164 }
1165 
1166 static int vdebug_dap_queue_dp_read(struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
1167 {
1168  if (reg != DP_SELECT && reg != DP_RDBUFF
1169  && (!dap->select_valid || ((reg >> 4) & DP_SELECT_DPBANK) != (dap->select & DP_SELECT_DPBANK))) {
1170  dap->select = (dap->select & ~DP_SELECT_DPBANK) | ((reg >> 4) & DP_SELECT_DPBANK);
1172  dap->select_valid = true;
1173  }
1174  return vdebug_reg_read(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_DP, 0);
1175 }
1176 
1177 static int vdebug_dap_queue_dp_write(struct adiv5_dap *dap, unsigned int reg, uint32_t data)
1178 {
1179  if (reg != DP_SELECT && reg != DP_RDBUFF
1180  && (!dap->select_valid || ((reg >> 4) & DP_SELECT_DPBANK) != (dap->select & DP_SELECT_DPBANK))) {
1181  dap->select = (dap->select & ~DP_SELECT_DPBANK) | ((reg >> 4) & DP_SELECT_DPBANK);
1183  dap->select_valid = true;
1184  }
1185  return vdebug_reg_write(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_DP, 0);
1186 }
1187 
1188 static int vdebug_dap_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
1189 {
1191 
1193 
1194  return vdebug_reg_read(vdc.hsocket, pbuf, DP_RDBUFF >> 2, data, VD_ASPACE_DP, 0);
1195 }
1196 
1197 static int vdebug_dap_queue_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data)
1198 {
1200  return vdebug_reg_write(vdc.hsocket, pbuf, (reg & DP_SELECT_DPBANK) >> 2, data, VD_ASPACE_AP, 0);
1201 }
1202 
1203 static int vdebug_dap_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
1204 {
1205  return vdebug_reg_write(vdc.hsocket, pbuf, 0, 0x1, VD_ASPACE_AB, 0);
1206 }
1207 
1208 static int vdebug_dap_run(struct adiv5_dap *dap)
1209 {
1210  if (le_to_h_u16(pbuf->waddr))
1212 
1213  return ERROR_OK;
1214 }
1215 
1216 COMMAND_HANDLER(vdebug_set_server)
1217 {
1218  if ((CMD_ARGC != 1) || !strchr(CMD_ARGV[0], ':'))
1220 
1221  char *pchar = strchr(CMD_ARGV[0], ':');
1222  *pchar = '\0';
1223  strncpy(vdc.server_name, CMD_ARGV[0], sizeof(vdc.server_name) - 1);
1224  int port = atoi(++pchar);
1225  if (port < 0 || port > UINT16_MAX) {
1226  LOG_ERROR("invalid port number %d specified", port);
1228  }
1229  vdc.server_port = port;
1230  LOG_DEBUG("server: %s port %u", vdc.server_name, vdc.server_port);
1231 
1232  return ERROR_OK;
1233 }
1234 
1235 COMMAND_HANDLER(vdebug_set_bfm)
1236 {
1237  char prefix;
1238 
1239  if ((CMD_ARGC != 2) || (sscanf(CMD_ARGV[1], "%u%c", &vdc.bfm_period, &prefix) != 2))
1241 
1242  strncpy(vdc.bfm_path, CMD_ARGV[0], sizeof(vdc.bfm_path) - 1);
1243  switch (prefix) {
1244  case 'u':
1245  vdc.bfm_period *= 1000000;
1246  break;
1247  case 'n':
1248  vdc.bfm_period *= 1000;
1249  break;
1250  case 'p':
1251  default:
1252  break;
1253  }
1255  vdc.bfm_type = strstr(vdc.bfm_path, "dap6") ? VD_BFM_DAP6 : VD_BFM_SWDP;
1256  else
1258  LOG_DEBUG("bfm_path: %s clk_period %ups", vdc.bfm_path, vdc.bfm_period);
1259 
1260  return ERROR_OK;
1261 }
1262 
1263 COMMAND_HANDLER(vdebug_set_mem)
1264 {
1265  if (CMD_ARGC != 3)
1267 
1268  if (vdc.mem_ndx >= VD_MAX_MEMORIES) {
1269  LOG_ERROR("mem_path declared more than %d allowed times", VD_MAX_MEMORIES);
1270  return ERROR_FAIL;
1271  }
1272 
1273  strncpy(vdc.mem_path[vdc.mem_ndx], CMD_ARGV[0], sizeof(vdc.mem_path[vdc.mem_ndx]) - 1);
1276  LOG_DEBUG("mem_path: set %s @ 0x%08x+0x%08x", vdc.mem_path[vdc.mem_ndx],
1278  vdc.mem_ndx++;
1279 
1280  return ERROR_OK;
1281 }
1282 
1283 COMMAND_HANDLER(vdebug_set_batching)
1284 {
1285  if (CMD_ARGC != 1)
1287 
1288  if (isdigit((unsigned char)CMD_ARGV[0][0]))
1289  vdc.trans_batch = (CMD_ARGV[0][0] == '0' ? 0 : (CMD_ARGV[0][0] == '1' ? 1 : 2));
1290  else if (CMD_ARGV[0][0] == 'r')
1292  else if (CMD_ARGV[0][0] == 'w')
1294  else
1296  LOG_DEBUG("batching: set to %u", vdc.trans_batch);
1297 
1298  return ERROR_OK;
1299 }
1300 
1301 COMMAND_HANDLER(vdebug_set_polling)
1302 {
1303  if (CMD_ARGC != 2)
1305 
1306  vdc.poll_min = atoi(CMD_ARGV[0]);
1307  vdc.poll_max = atoi(CMD_ARGV[1]);
1308  LOG_DEBUG("polling: set min %u max %u", vdc.poll_min, vdc.poll_max);
1309 
1310  return ERROR_OK;
1311 }
1312 
1313 static const struct command_registration vdebug_command_handlers[] = {
1314  {
1315  .name = "server",
1316  .handler = &vdebug_set_server,
1317  .mode = COMMAND_CONFIG,
1318  .help = "set the vdebug server name or address",
1319  .usage = "<host:port>",
1320  },
1321  {
1322  .name = "bfm_path",
1323  .handler = &vdebug_set_bfm,
1324  .mode = COMMAND_CONFIG,
1325  .help = "set the vdebug BFM hierarchical path",
1326  .usage = "<path> <clk_period[p|n|u]s>",
1327  },
1328  {
1329  .name = "mem_path",
1330  .handler = &vdebug_set_mem,
1331  .mode = COMMAND_CONFIG,
1332  .help = "set the design memory for the code load",
1333  .usage = "<path> <base_address> <size>",
1334  },
1335  {
1336  .name = "batching",
1337  .handler = &vdebug_set_batching,
1338  .mode = COMMAND_ANY,
1339  .help = "set the transaction batching no|wr|rd [0|1|2]",
1340  .usage = "<level>",
1341  },
1342  {
1343  .name = "polling",
1344  .handler = &vdebug_set_polling,
1345  .mode = COMMAND_ANY,
1346  .help = "set the min idle time and max wait time in ms",
1347  .usage = "<min_idle> <max_wait>",
1348  },
1350 };
1351 
1352 static const struct command_registration vdebug_command[] = {
1353  {
1354  .name = "vdebug",
1355  .chain = vdebug_command_handlers,
1356  .mode = COMMAND_ANY,
1357  .help = "vdebug command group",
1358  .usage = "",
1359  },
1361 };
1362 
1363 static struct jtag_interface vdebug_jtag_ops = {
1365  .execute_queue = vdebug_jtag_execute_queue,
1366 };
1367 
1368 static const struct dap_ops vdebug_dap_ops = {
1370  .send_sequence = vdebug_dap_send_sequence,
1371  .queue_dp_read = vdebug_dap_queue_dp_read,
1372  .queue_dp_write = vdebug_dap_queue_dp_write,
1373  .queue_ap_read = vdebug_dap_queue_ap_read,
1374  .queue_ap_write = vdebug_dap_queue_ap_write,
1375  .queue_ap_abort = vdebug_dap_queue_ap_abort,
1376  .run = vdebug_dap_run,
1377  .sync = NULL, /* optional */
1378  .quit = NULL, /* optional */
1379 };
1380 
1382  .name = "vdebug",
1383  .transport_ids = TRANSPORT_JTAG | TRANSPORT_DAPDIRECT_SWD,
1384  .transport_preferred_id = TRANSPORT_JTAG,
1385  .speed = vdebug_jtag_speed,
1386  .khz = vdebug_jtag_khz,
1387  .speed_div = vdebug_jtag_div,
1388  .commands = vdebug_command,
1389  .init = vdebug_init,
1390  .quit = vdebug_quit,
1391  .reset = vdebug_reset,
1392  .jtag_ops = &vdebug_jtag_ops,
1393  .dap_swd_ops = &vdebug_dap_ops,
1394 };
bool transport_is_dapdirect_swd(void)
Returns true if the current debug session is using SWD as its transport.
int dap_dp_init(struct adiv5_dap *dap)
Initialize a DAP.
Definition: arm_adi_v5.c:779
This defines formats and data structures used to talk to ADIv5 entities.
#define DP_SELECT
Definition: arm_adi_v5.h:57
#define DP_SELECT1
Definition: arm_adi_v5.h:55
#define DP_RDBUFF
Definition: arm_adi_v5.h:58
swd_special_seq
Definition: arm_adi_v5.h:236
static bool is_adiv6(const struct adiv5_dap *dap)
Check if DAP is ADIv6.
Definition: arm_adi_v5.h:523
#define ADIV5_DP_SELECT_APBANK
Definition: arm_adi_v5.h:101
#define DP_SELECT_DPBANK
Definition: arm_adi_v5.h:102
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:34
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:400
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:440
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:251
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
unsigned int jtag_scan_size(const struct scan_command *cmd)
Definition: commands.c:181
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_STABLECLOCKS
Definition: commands.h:142
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_TMS
Definition: commands.h:143
static struct esp_usb_jtag * priv
Definition: esp_usb_jtag.c:219
enum tap_state tap_state_transition(enum tap_state cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
Definition: interface.c:223
int tap_get_tms_path_len(enum tap_state from, enum tap_state to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
Definition: interface.c:195
enum tap_state tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
Definition: interface.c:37
int tap_get_tms_path(enum tap_state from, enum tap_state to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
Definition: interface.c:190
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:188
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
Definition: interface.h:50
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1840
tap_state
Defines JTAG Test Access Port states.
Definition: jtag.h:37
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_DRSHIFT
Definition: jtag.h:43
#define list_first_entry(ptr, type, member)
Definition: list.h:131
static void list_add_tail(struct list_head *new, struct list_head *head)
Definition: list.h:203
static int list_empty(const struct list_head *head)
Definition: list.h:61
static void list_del(struct list_head *entry)
Definition: list.h:88
static void INIT_LIST_HEAD(struct list_head *list)
Definition: list.h:54
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:102
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define ERROR_FAIL
Definition: log.h:174
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
static uint32_t lh(unsigned int rd, unsigned int base, uint16_t offset) __attribute__((unused))
Definition: opcodes.h:117
static int close_socket(int sock)
Definition: replacements.h:184
target_addr_t addr
Start address to search for the control block.
Definition: rtt/rtt.c:28
Represents a driver for a debugging interface.
Definition: interface.h:208
const char *const name
The name of the interface driver.
Definition: interface.h:210
This represents an ARM Debug Interface (v5) Access Port (AP).
Definition: arm_adi_v5.h:250
uint64_t ap_num
ADIv5: Number of this AP (0~255) ADIv6: Base address of this AP (4k aligned) TODO: to be more coheren...
Definition: arm_adi_v5.h:261
struct adiv5_dap * dap
DAP this AP belongs to.
Definition: arm_adi_v5.h:254
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
Definition: arm_adi_v5.h:348
bool select_valid
Validity of DP SELECT cache.
Definition: arm_adi_v5.h:372
bool select1_valid
Definition: arm_adi_v5.h:373
uint64_t select
Cache for DP SELECT and SELECT1 (ADIv6) register.
Definition: arm_adi_v5.h:370
unsigned int asize
Definition: arm_adi_v5.h:436
const char * name
Definition: command.h:234
enum command_mode mode
Definition: command.h:236
Transport-neutral representation of queued DAP transactions, supporting both JTAG and SWD transports.
Definition: arm_adi_v5.h:446
int(* connect)(struct adiv5_dap *dap)
connect operation for SWD
Definition: arm_adi_v5.h:451
Represents a driver for a debugging interface.
Definition: interface.h:183
unsigned int supported
Bit vector listing capabilities exposed by this driver.
Definition: interface.h:187
Definition: list.h:41
Definition: register.h:111
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
Definition: commands.h:35
uint16_t sig_write
Definition: vdebug.c:197
uint8_t mem_ndx
Definition: vdebug.c:192
uint32_t mem_width[VD_MAX_MEMORIES]
Definition: vdebug.c:201
bool trans_first
Definition: vdebug.c:190
uint16_t sig_read
Definition: vdebug.c:196
uint8_t bfm_type
Definition: vdebug.c:195
uint8_t buf_width
Definition: vdebug.c:193
uint8_t trans_batch
Definition: vdebug.c:189
uint32_t mem_base[VD_MAX_MEMORIES]
Definition: vdebug.c:199
uint16_t server_port
Definition: vdebug.c:203
char mem_path[VD_MAX_MEMORIES][128]
Definition: vdebug.c:212
uint8_t addr_bits
Definition: vdebug.c:194
bool trans_last
Definition: vdebug.c:191
uint32_t bfm_period
Definition: vdebug.c:198
struct vd_rdata rdataq
Definition: vdebug.c:213
char server_name[32]
Definition: vdebug.c:210
uint32_t mem_depth[VD_MAX_MEMORIES]
Definition: vdebug.c:202
uint32_t poll_cycles
Definition: vdebug.c:204
uint32_t poll_max
Definition: vdebug.c:206
uint32_t targ_time
Definition: vdebug.c:207
int64_t poll_ts
Definition: vdebug.c:209
uint32_t mem_size[VD_MAX_MEMORIES]
Definition: vdebug.c:200
uint32_t poll_min
Definition: vdebug.c:205
char bfm_path[128]
Definition: vdebug.c:211
int hsocket
Definition: vdebug.c:208
uint64_t pre
Definition: vdebug.c:219
uint64_t wlen
Definition: vdebug.c:221
uint64_t cmd
Definition: vdebug.c:220
uint64_t post
Definition: vdebug.c:218
uint64_t tlen
Definition: vdebug.c:217
uint64_t rlen
Definition: vdebug.c:222
uint8_t * rdata
Definition: vdebug.c:185
struct list_head lh
Definition: vdebug.c:184
uint64_t haddr
Definition: vdebug.c:228
uint64_t prot
Definition: vdebug.c:226
uint64_t nonincr
Definition: vdebug.c:227
uint64_t tlen
Definition: vdebug.c:229
uint64_t asize
Definition: vdebug.c:230
uint64_t addr
Definition: vdebug.c:232
uint64_t cmd
Definition: vdebug.c:231
Definition: vdebug.c:156
uint8_t offset[4]
Definition: vdebug.c:166
uint8_t dummy[96]
Definition: vdebug.c:180
uint8_t offseth[2]
Definition: vdebug.c:167
uint8_t rwdata[4]
Definition: vdebug.c:165
uint8_t rd8[VD_BUFFER_LEN]
Definition: vdebug.c:177
uint8_t rwords[2]
Definition: vdebug.c:164
uint8_t type
Definition: vdebug.c:159
uint8_t cmd
Definition: vdebug.c:158
uint8_t waddr[2]
Definition: vdebug.c:160
uint8_t wd8[VD_BUFFER_LEN]
Definition: vdebug.c:170
uint8_t awords[2]
Definition: vdebug.c:173
uint8_t wbytes[2]
Definition: vdebug.c:161
uint8_t state[4]
Definition: vdebug.c:178
uint8_t status[4]
Definition: vdebug.c:174
uint8_t wid[2]
Definition: vdebug.c:168
uint8_t count[4]
Definition: vdebug.c:179
uint8_t rbytes[2]
Definition: vdebug.c:162
uint8_t wwords[2]
Definition: vdebug.c:163
uint8_t rid[2]
Definition: vdebug.c:172
uint8_t duttime[8]
Definition: vdebug.c:175
int target_unregister_timer_callback(int(*callback)(void *priv), void *priv)
Definition: target.c:1758
int target_register_timer_callback(int(*callback)(void *priv), unsigned int time_ms, enum target_timer_type type, void *priv)
The period is very approximate, the callback can happen much more often or much more rarely than spec...
Definition: target.c:1668
@ TARGET_TIMER_TYPE_PERIODIC
Definition: target.h:323
int64_t timeval_ms(void)
#define TRANSPORT_DAPDIRECT_SWD
Definition: transport.h:24
#define TRANSPORT_JTAG
Definition: transport.h:19
static uint64_t le_to_h_u64(const uint8_t *buf)
Definition: types.h:100
static void h_u16_to_be(uint8_t *buf, uint16_t val)
Definition: types.h:214
static uint16_t le_to_h_u16(const uint8_t *buf)
Definition: types.h:122
static void h_u32_to_le(uint8_t *buf, uint32_t val)
Definition: types.h:178
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
static void h_u16_to_le(uint8_t *buf, uint16_t val)
Definition: types.h:208
static uint32_t le_to_h_u32(const uint8_t *buf)
Definition: types.h:112
static void h_u64_to_le(uint8_t *buf, uint64_t val)
Definition: types.h:154
#define NULL
Definition: usb.h:16
static uint32_t vdebug_wait_server(int hsock, struct vd_shm *pmem)
Definition: vdebug.c:335
static int vdebug_close(int hsock, struct vd_shm *pm, uint8_t type)
Definition: vdebug.c:553
#define VD_CHEADER_LEN
Definition: vdebug.c:59
uint8_t rwords[2]
Definition: vdebug.c:7
static int vdebug_dap_bankselect(struct adiv5_ap *ap, unsigned int reg)
Definition: vdebug.c:1121
uint8_t waddr[2]
Definition: vdebug.c:3
static int vdebug_dap_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
Definition: vdebug.c:1161
@ VD_CMD_SIGGET
Definition: vdebug.c:133
@ VD_CMD_REGREAD
Definition: vdebug.c:136
@ VD_CMD_REGWRITE
Definition: vdebug.c:135
@ VD_CMD_DISCONNECT
Definition: vdebug.c:130
@ VD_CMD_OPEN
Definition: vdebug.c:127
@ VD_CMD_SIGSET
Definition: vdebug.c:132
@ VD_CMD_WAIT
Definition: vdebug.c:131
@ VD_CMD_JTAGCLOCK
Definition: vdebug.c:134
@ VD_CMD_MEMOPEN
Definition: vdebug.c:138
@ VD_CMD_CLOSE
Definition: vdebug.c:128
@ VD_CMD_JTAGSHTAP
Definition: vdebug.c:137
@ VD_CMD_CONNECT
Definition: vdebug.c:129
@ VD_CMD_MEMCLOSE
Definition: vdebug.c:139
@ VD_CMD_MEMWRITE
Definition: vdebug.c:140
static int vdebug_dap_queue_dp_write(struct adiv5_dap *dap, unsigned int reg, uint32_t data)
Definition: vdebug.c:1177
#define VD_POLL_INTERVAL
Definition: vdebug.c:63
uint8_t type
Definition: vdebug.c:2
static int vdebug_jtag_div(int speed, int *khz)
Definition: vdebug.c:1077
@ VD_ASPACE_ID
Definition: vdebug.c:146
@ VD_ASPACE_AB
Definition: vdebug.c:147
@ VD_ASPACE_AP
Definition: vdebug.c:144
@ VD_ASPACE_DP
Definition: vdebug.c:145
static int vdebug_dap_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
Definition: vdebug.c:1203
static int vdebug_reg_read(int hsock, struct vd_shm *pm, const uint32_t reg, uint32_t *data, uint8_t aspace, uint8_t f_last)
Definition: vdebug.c:760
static int vdebug_open(int hsock, struct vd_shm *pm, const char *path, uint8_t type, uint32_t period_ps, uint32_t sig_mask)
Definition: vdebug.c:503
#define VD_SHEADER_LEN
Definition: vdebug.c:60
#define VD_VERSION
Definition: vdebug.c:57
static int vdebug_dap_queue_ap_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
Definition: vdebug.c:1188
static int vdebug_jtag_path_move(struct pathmove_command *cmd, uint8_t f_flush)
Definition: vdebug.c:967
@ VD_SIG_BUF
Definition: vdebug.c:92
@ VD_SIG_RESET
Definition: vdebug.c:87
@ VD_SIG_TCK
Definition: vdebug.c:84
@ VD_SIG_TRST
Definition: vdebug.c:88
@ VD_SIG_POWER
Definition: vdebug.c:90
@ VD_SIG_TDO
Definition: vdebug.c:89
@ VD_SIG_TMS
Definition: vdebug.c:86
@ VD_SIG_TDI
Definition: vdebug.c:85
@ VD_SIG_TCKDIV
Definition: vdebug.c:91
static int vdebug_run_jtag_queue(int hsock, struct vd_shm *pm, unsigned int count)
Definition: vdebug.c:355
static int vdebug_run_reg_queue(int hsock, struct vd_shm *pm, unsigned int count)
Definition: vdebug.c:431
COMMAND_HANDLER(vdebug_set_server)
Definition: vdebug.c:1216
static struct jtag_interface vdebug_jtag_ops
Definition: vdebug.c:1363
static int vdebug_poll(void *priv)
Definition: vdebug.c:849
static int vdebug_jtag_runtest(unsigned int num_cycles, enum tap_state state, uint8_t f_flush)
Definition: vdebug.c:1031
uint8_t cmd
Definition: vdebug.c:1
#define VD_BUFFER_LEN
Definition: vdebug.c:58
struct adapter_driver vdebug_adapter_driver
Definition: vdebug.c:1381
static int vdebug_jtag_shift_tap(int hsock, struct vd_shm *pm, uint8_t num_pre, const uint8_t tms_pre, uint32_t num, const uint8_t *tdi, uint8_t num_post, const uint8_t tms_post, uint8_t *tdo, uint8_t f_last)
Definition: vdebug.c:626
#define VD_MAX_MEMORIES
Definition: vdebug.c:62
static int vdebug_dap_queue_ap_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data)
Definition: vdebug.c:1197
static int vdebug_socket_open(char *server_addr, uint32_t port)
Definition: vdebug.c:247
static struct vd_client vdc
Definition: vdebug.c:236
static int vdebug_quit(void)
Definition: vdebug.c:920
static int vdebug_jtag_speed(int speed)
Definition: vdebug.c:1058
#define VD_SCALE_PSTOMS
Definition: vdebug.c:64
static const struct dap_ops vdebug_dap_ops
Definition: vdebug.c:1368
static int vdebug_reset(int trst, int srst)
Definition: vdebug.c:938
static int vdebug_jtag_scan(struct scan_command *cmd, uint8_t f_flush)
Definition: vdebug.c:999
static int vdebug_init(void)
Definition: vdebug.c:873
static int vdebug_jtag_clock(int hsock, struct vd_shm *pm, uint32_t value)
Definition: vdebug.c:609
@ VD_BATCH_WO
Definition: vdebug.c:152
@ VD_BATCH_NO
Definition: vdebug.c:151
@ VD_BATCH_WR
Definition: vdebug.c:153
struct vd_rdata __attribute__
static int vdebug_dap_connect(struct adiv5_dap *dap)
Definition: vdebug.c:1156
static int vdebug_reg_write(int hsock, struct vd_shm *pm, const uint32_t reg, const uint32_t data, uint8_t aspace, uint8_t f_last)
Definition: vdebug.c:729
static int vdebug_dap_queue_dp_read(struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
Definition: vdebug.c:1166
static int vdebug_jtag_tms_seq(const uint8_t *tms, int num, uint8_t f_flush)
Definition: vdebug.c:960
static int vdebug_mem_open(int hsock, struct vd_shm *pm, const char *path, uint8_t ndx)
Definition: vdebug.c:803
static int vdebug_wait(int hsock, struct vd_shm *pm, uint32_t cycles)
Definition: vdebug.c:574
static int vdebug_dap_run(struct adiv5_dap *dap)
Definition: vdebug.c:1208
static void vdebug_mem_close(int hsock, struct vd_shm *pm, uint8_t ndx)
Definition: vdebug.c:831
static int vdebug_sig_set(int hsock, struct vd_shm *pm, uint32_t write_mask, uint32_t value)
Definition: vdebug.c:592
@ VD_ERR_NO_POWER
Definition: vdebug.c:119
@ VD_ERR_LICENSE
Definition: vdebug.c:116
@ VD_ERR_SOC_ADDR
Definition: vdebug.c:109
@ VD_ERR_NO_ACCESS
Definition: vdebug.c:121
@ VD_ERR_NOT_OPEN
Definition: vdebug.c:115
@ VD_ERR_TIME_OUT
Definition: vdebug.c:118
@ VD_ERR_PARAM
Definition: vdebug.c:102
@ VD_ERR_SHM_MAP
Definition: vdebug.c:106
@ VD_ERR_INV_HANDLE
Definition: vdebug.c:122
@ VD_ERR_NO_MEMORY
Definition: vdebug.c:104
@ VD_ERR_SOC_OPEN
Definition: vdebug.c:107
@ VD_ERR_SOC_CONN
Definition: vdebug.c:110
@ VD_ERR_NOT_RUN
Definition: vdebug.c:114
@ VD_ERR_SOC_RECV
Definition: vdebug.c:112
@ VD_ERR_CONFIG
Definition: vdebug.c:103
@ VD_ERR_NONE
Definition: vdebug.c:99
@ VD_ERR_SOC_OPT
Definition: vdebug.c:108
@ VD_ERR_NOT_IMPL
Definition: vdebug.c:100
@ VD_ERR_VERSION
Definition: vdebug.c:117
@ VD_ERR_INV_SCOPE
Definition: vdebug.c:123
@ VD_ERR_SOC_SEND
Definition: vdebug.c:111
@ VD_ERR_BUS_ERROR
Definition: vdebug.c:120
@ VD_ERR_LOCKED
Definition: vdebug.c:113
@ VD_ERR_SHM_OPEN
Definition: vdebug.c:105
@ VD_ERR_USAGE
Definition: vdebug.c:101
static int vdebug_jtag_execute_queue(struct jtag_command *cmd_queue)
Definition: vdebug.c:1085
static int vdebug_jtag_khz(int khz, int *jtag_speed)
Definition: vdebug.c:1067
uint8_t offset[4]
Definition: vdebug.c:9
static int vdebug_socket_error(void)
Definition: vdebug.c:238
static int vdebug_jtag_stableclocks(unsigned int num_cycles, uint8_t f_flush)
Definition: vdebug.c:1044
static int vdebug_socket_send(int hsock, struct vd_shm *pmem)
Definition: vdebug.c:324
static int vdebug_socket_receive(int hsock, struct vd_shm *pmem)
Definition: vdebug.c:301
static const struct command_registration vdebug_command[]
Definition: vdebug.c:1352
static struct vd_shm * pbuf
Definition: vdebug.c:235
uint8_t state[4]
Definition: vdebug.c:21
static int vdebug_sleep(int us)
Definition: vdebug.c:1051
static const struct command_registration vdebug_command_handlers[]
Definition: vdebug.c:1313
static int vdebug_jtag_tlr(enum tap_state state, uint8_t f_flush)
Definition: vdebug.c:983
@ VD_BFM_SWDP
Definition: vdebug.c:72
@ VD_BFM_JTAG
Definition: vdebug.c:76
@ VD_BFM_TPIU
Definition: vdebug.c:70
@ VD_BFM_SWD
Definition: vdebug.c:77
@ VD_BFM_AHB
Definition: vdebug.c:73
@ VD_BFM_APB
Definition: vdebug.c:74
@ VD_BFM_DAP6
Definition: vdebug.c:71
@ VD_BFM_AXI
Definition: vdebug.c:75
uint8_t count[4]
Definition: vdebug.c:22