Skip to content

Commit

Permalink
riscv_debug: Transform JTAG ID Code designer into JEP-106 internal fo…
Browse files Browse the repository at this point in the history
…rmat and store it as a DMI designer code
  • Loading branch information
perigoso authored and dragonmux committed Mar 28, 2023
1 parent bfed134 commit a61706f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/target/adiv5.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@
#define JTAG_IDCODE_PARTNO_MASK (0xffffU << JTAG_IDCODE_PARTNO_OFFSET)
#define JTAG_IDCODE_DESIGNER_OFFSET 1U
#define JTAG_IDCODE_DESIGNER_MASK (0x7ffU << JTAG_IDCODE_DESIGNER_OFFSET)
/* Bits 10:7 - JEP-106 Continuation code */
/* Bits 6:0 - JEP-106 Identity code */
#define JTAG_IDCODE_DESIGNER_JEP106_CONT_OFFSET 7U
#define JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK (0xfU << ADIV5_DP_DESIGNER_JEP106_CONT_OFFSET)
#define JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK (0x7fU)

#define JTAG_IDCODE_ARM_DPv0 UINT32_C(0x4ba00477)

Expand Down
6 changes: 2 additions & 4 deletions src/target/riscv_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ static bool riscv_hart_init(riscv_hart_s *const hart)
return true;
}

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

riscv_hart_discover_triggers(hart);
Expand Down
2 changes: 1 addition & 1 deletion src/target/riscv_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef struct riscv_dmi riscv_dmi_s;
struct riscv_dmi {
uint32_t ref_count;

uint32_t idcode;
uint16_t designer_code;
riscv_debug_version_e version;

uint8_t dev_index;
Expand Down
14 changes: 13 additions & 1 deletion src/target/riscv_jtag_dtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "jtag_scan.h"
#include "jtagtap.h"
#include "riscv_debug.h"
#include "adiv5.h"

#define IR_DTMCS 0x10U
#define IR_DMI 0x11U
Expand Down Expand Up @@ -75,12 +76,23 @@ void riscv_jtag_dtm_handler(const uint8_t dev_index)
}

/* Setup and try to discover the DMI bus */
dmi->idcode = jtag_devs[dev_index].jd_idcode;
dmi->dev_index = dev_index;
/*
* The code in JTAG_IDCODE_DESIGNER is in the form
* Bits 10:7 - JEP-106 Continuation code
* Bits 6:0 - JEP-106 Identity code
* here we convert it to our internal representation, See JEP-106 code list
*/
const uint16_t designer =
(jtag_devs[dev_index].jd_idcode & JTAG_IDCODE_DESIGNER_MASK) >> JTAG_IDCODE_DESIGNER_OFFSET;
dmi->designer_code =
(designer & JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK) << 1U | (designer & JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK);

riscv_jtag_dtm_init(dmi);
/* If we failed to find any DMs or Harts, free the structure */
if (!dmi->ref_count)
free(dmi);

/* Reset the JTAG machinary back to bypass to scan the next device in the chain */
jtag_dev_write_ir(dev_index, IR_BYPASS);
}
Expand Down

0 comments on commit a61706f

Please sign in to comment.