Skip to content

Commit 793e08d

Browse files
perigosodragonmux
authored andcommitted
riscv_debug: Transform JTAG ID Code designer into JEP-106 internal format and store it as a DMI designer code
1 parent 4503433 commit 793e08d

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/target/adiv5.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@
167167
#define JTAG_IDCODE_PARTNO_MASK (0xffffU << JTAG_IDCODE_PARTNO_OFFSET)
168168
#define JTAG_IDCODE_DESIGNER_OFFSET 1U
169169
#define JTAG_IDCODE_DESIGNER_MASK (0x7ffU << JTAG_IDCODE_DESIGNER_OFFSET)
170+
/* Bits 10:7 - JEP-106 Continuation code */
171+
/* Bits 6:0 - JEP-106 Identity code */
172+
#define JTAG_IDCODE_DESIGNER_JEP106_CONT_OFFSET 7U
173+
#define JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK (0xfU << ADIV5_DP_DESIGNER_JEP106_CONT_OFFSET)
174+
#define JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK (0x7fU)
170175

171176
#define JTAG_IDCODE_ARM_DPv0 UINT32_C(0x4ba00477)
172177

src/target/riscv_debug.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,8 @@ static bool riscv_hart_init(riscv_hart_s *const hart)
352352
return true;
353353
}
354354

355-
/* If the hart implements mvendorid, this gives us the JEP-106, otherwise use the JTAG IDCode */
356-
target->designer_code = hart->vendorid ?
357-
hart->vendorid :
358-
((hart->dbg_module->dmi_bus->idcode & JTAG_IDCODE_DESIGNER_MASK) >> JTAG_IDCODE_DESIGNER_OFFSET);
355+
/* If the hart implements mvendorid, this gives us the JEP-106, otherwise use the DTM designer code */
356+
target->designer_code = hart->vendorid ? hart->vendorid : hart->dbg_module->dmi_bus->designer_code;
359357
target->cpuid = hart->archid;
360358

361359
riscv_hart_discover_triggers(hart);

src/target/riscv_debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef struct riscv_dmi riscv_dmi_s;
9090
struct riscv_dmi {
9191
uint32_t ref_count;
9292

93-
uint32_t idcode;
93+
uint16_t designer_code;
9494
riscv_debug_version_e version;
9595

9696
uint8_t dev_index;

src/target/riscv_jtag_dtm.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "jtag_scan.h"
3636
#include "jtagtap.h"
3737
#include "riscv_debug.h"
38+
#include "adiv5.h"
3839

3940
#define IR_DTMCS 0x10U
4041
#define IR_DMI 0x11U
@@ -75,12 +76,23 @@ void riscv_jtag_dtm_handler(const uint8_t dev_index)
7576
}
7677

7778
/* Setup and try to discover the DMI bus */
78-
dmi->idcode = jtag_devs[dev_index].jd_idcode;
7979
dmi->dev_index = dev_index;
80+
/*
81+
* The code in JTAG_IDCODE_DESIGNER is in the form
82+
* Bits 10:7 - JEP-106 Continuation code
83+
* Bits 6:0 - JEP-106 Identity code
84+
* here we convert it to our internal representation, See JEP-106 code list
85+
*/
86+
const uint16_t designer =
87+
(jtag_devs[dev_index].jd_idcode & JTAG_IDCODE_DESIGNER_MASK) >> JTAG_IDCODE_DESIGNER_OFFSET;
88+
dmi->designer_code =
89+
(designer & JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK) << 1U | (designer & JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK);
90+
8091
riscv_jtag_dtm_init(dmi);
8192
/* If we failed to find any DMs or Harts, free the structure */
8293
if (!dmi->ref_count)
8394
free(dmi);
95+
8496
/* Reset the JTAG machinary back to bypass to scan the next device in the chain */
8597
jtag_dev_write_ir(dev_index, IR_BYPASS);
8698
}

0 commit comments

Comments
 (0)