jep106: use packed jedec manufacturer code

JEP106 encodes JEDEC-assigned manufacture code as:
a) a sequence of zero or more escape codes 0x7f;
b) an odd-parity bit of the next 7 bits;
c) 7 bits.

The same code is often represented as a single value composed by
the logical OR between:
- the number of escape codes in a), shifted left by 7 positions;
- the 7 bits in c).
This is the preferred packed representation used by this change.

Currently there are only two uses of JEP106 in openocd to get the
manufacturer name:
- to decode the JTAG IDCODE of each TAP, where the JEP106 code is
  already packed as in the preferred representation above in bits
  IDCODE[11:1];
- to decode the ARM CoreSight PIDR register, where the JEP106 code
  is split in 3 parts:
  = PIDR3[3:0], corresponding to bits [10:7] of the packed code;
  = PIDR2[2:0], corresponding to bits [6:4] of the packed code;
  = PIDR1[7:4], corresponding to bits [3:0] of the packed code.

Wrap the existing JEP106 decode function in a simpler API using
the packed code.
Simplify the callers by skipping the bit unpacking.
Change the manufacturer code in CoreSight table dap_partnums[] to
match the packed representation, by removing the always-one bit 7
erroneously taken from PIDR bit JEDEC and included in the former
table.

Change-Id: I63eb4da9e6801fab25e330f1f6b792d2fd619493
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6418
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2021-08-08 13:51:33 +02:00
parent 66175577e1
commit 7a61a006de
4 changed files with 28 additions and 25 deletions

View File

@ -27,7 +27,7 @@ static const char * const jep106[][126] = {
#include "jep106.inc"
};
const char *jep106_manufacturer(unsigned bank, unsigned id)
const char *jep106_table_manufacturer(unsigned int bank, unsigned int id)
{
if (id < 1 || id > 126) {
LOG_DEBUG("BUG: Caller passed out-of-range JEP106 ID!");

View File

@ -27,6 +27,11 @@
* manufacturer associated with bank and id, or one of the strings
* "<invalid>" and "<unknown>".
*/
const char *jep106_manufacturer(unsigned bank, unsigned id);
const char *jep106_table_manufacturer(unsigned int bank, unsigned int id);
static inline const char *jep106_manufacturer(unsigned int manufacturer)
{
return jep106_table_manufacturer(manufacturer >> 7, manufacturer & 0x7f);
}
#endif /* OPENOCD_HELPER_JEP106_H */

View File

@ -1072,8 +1072,6 @@ void jtag_sleep(uint32_t us)
#define JTAG_MAX_AUTO_TAPS 20
#define EXTRACT_JEP106_BANK(X) (((X) & 0xf00) >> 8)
#define EXTRACT_JEP106_ID(X) (((X) & 0xfe) >> 1)
#define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
#define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
#define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
@ -1141,7 +1139,7 @@ static void jtag_examine_chain_display(enum log_levels level, const char *msg,
name, msg,
(unsigned int)idcode,
(unsigned int)EXTRACT_MFG(idcode),
jep106_manufacturer(EXTRACT_JEP106_BANK(idcode), EXTRACT_JEP106_ID(idcode)),
jep106_manufacturer(EXTRACT_MFG(idcode)),
(unsigned int)EXTRACT_PART(idcode),
(unsigned int)EXTRACT_VER(idcode));
}

View File

@ -1123,7 +1123,7 @@ static int dap_read_part_id(struct adiv5_ap *ap, target_addr_t component_base, u
#define ANY_ID 0x1000
#define ARM_ID 0x4BB
#define ARM_ID 0x23B
static const struct {
uint16_t designer_id;
@ -1216,22 +1216,22 @@ static const struct {
{ ARM_ID, 0xd07, "Cortex-A57 Debug", "(Debug Unit)", },
{ ARM_ID, 0xd08, "Cortex-A72 Debug", "(Debug Unit)", },
{ ARM_ID, 0xd0b, "Cortex-A76 Debug", "(Debug Unit)", },
{ 0x097, 0x9af, "MSP432 ROM", "(ROM Table)" },
{ 0x09f, 0xcd0, "Atmel CPU with DSU", "(CPU)" },
{ 0x0c1, 0x1db, "XMC4500 ROM", "(ROM Table)" },
{ 0x0c1, 0x1df, "XMC4700/4800 ROM", "(ROM Table)" },
{ 0x0c1, 0x1ed, "XMC1000 ROM", "(ROM Table)" },
{ 0x0E5, 0x000, "SHARC+/Blackfin+", "", },
{ 0x0F0, 0x440, "Qualcomm QDSS Component v1", "(Qualcomm Designed CoreSight Component v1)", },
{ 0x1bf, 0x100, "Brahma-B53 Debug", "(Debug Unit)", },
{ 0x1bf, 0x9d3, "Brahma-B53 PMU", "(Performance Monitor Unit)", },
{ 0x1bf, 0x4a1, "Brahma-B53 ROM", "(ROM Table)", },
{ 0x1bf, 0x721, "Brahma-B53 ROM", "(ROM Table)", },
{ 0x3eb, 0x181, "Tegra 186 ROM", "(ROM Table)", },
{ 0x3eb, 0x202, "Denver ETM", "(Denver Embedded Trace)", },
{ 0x3eb, 0x211, "Tegra 210 ROM", "(ROM Table)", },
{ 0x3eb, 0x302, "Denver Debug", "(Debug Unit)", },
{ 0x3eb, 0x402, "Denver PMU", "(Performance Monitor Unit)", },
{ 0x017, 0x9af, "MSP432 ROM", "(ROM Table)" },
{ 0x01f, 0xcd0, "Atmel CPU with DSU", "(CPU)" },
{ 0x041, 0x1db, "XMC4500 ROM", "(ROM Table)" },
{ 0x041, 0x1df, "XMC4700/4800 ROM", "(ROM Table)" },
{ 0x041, 0x1ed, "XMC1000 ROM", "(ROM Table)" },
{ 0x065, 0x000, "SHARC+/Blackfin+", "", },
{ 0x070, 0x440, "Qualcomm QDSS Component v1", "(Qualcomm Designed CoreSight Component v1)", },
{ 0x0bf, 0x100, "Brahma-B53 Debug", "(Debug Unit)", },
{ 0x0bf, 0x9d3, "Brahma-B53 PMU", "(Performance Monitor Unit)", },
{ 0x0bf, 0x4a1, "Brahma-B53 ROM", "(ROM Table)", },
{ 0x0bf, 0x721, "Brahma-B53 ROM", "(ROM Table)", },
{ 0x1eb, 0x181, "Tegra 186 ROM", "(ROM Table)", },
{ 0x1eb, 0x202, "Denver ETM", "(Denver Embedded Trace)", },
{ 0x1eb, 0x211, "Tegra 210 ROM", "(ROM Table)", },
{ 0x1eb, 0x302, "Denver Debug", "(Debug Unit)", },
{ 0x1eb, 0x402, "Denver PMU", "(Performance Monitor Unit)", },
/* legacy comment: 0x113: what? */
{ ANY_ID, 0x120, "TI SDTI", "(System Debug Trace Interface)", }, /* from OMAP3 memmap */
{ ANY_ID, 0x343, "TI DAPCTL", "", }, /* from OMAP3 memmap */
@ -1276,12 +1276,12 @@ static int dap_rom_display(struct command_invocation *cmd,
uint8_t class = (cid >> 12) & 0xf;
uint16_t part_num = pid & 0xfff;
uint16_t designer_id = ((pid >> 32) & 0xf) << 8 | ((pid >> 12) & 0xff);
uint16_t designer_id = ((pid >> 32) & 0xf) << 7 | ((pid >> 12) & 0x7f);
if (designer_id & 0x80) {
if (pid & 0x00080000) {
/* JEP106 code */
command_print(cmd, "\t\tDesigner is 0x%03" PRIx16 ", %s",
designer_id, jep106_manufacturer(designer_id >> 8, designer_id & 0x7f));
designer_id, jep106_manufacturer(designer_id));
} else {
/* Legacy ASCII ID, clear invalid bits */
designer_id &= 0x7f;