16 #include <linux/pci.h>
25 #ifndef PCI_CFG_SPACE_EXP_SIZE
26 #define PCI_CFG_SPACE_EXP_SIZE 4096
29 #define PCIE_EXT_CAP_LST 0x100
31 #define XLNX_XVC_EXT_CAP 0x00
32 #define XLNX_XVC_VSEC_HDR 0x04
33 #define XLNX_XVC_LEN_REG 0x0C
34 #define XLNX_XVC_TMS_REG 0x10
35 #define XLNX_XVC_TDX_REG 0x14
37 #define XLNX_XVC_CAP_SIZE 0x20
38 #define XLNX_XVC_VSEC_ID 0x8
39 #define XLNX_XVC_MAX_BITS 0x20
41 #define MASK_ACK(x) (((x) >> 9) & 0x7)
42 #define MASK_PAR(x) ((int)((x) & 0x1))
64 if (err !=
sizeof(res)) {
85 if (err !=
sizeof(val)) {
86 LOG_ERROR(
"Failed to write offset: %x with value: %" PRIx32,
116 LOG_DEBUG_IO(
"Transact num_bits: %zu, tms: %" PRIx32
", tdi: %" PRIx32
", tdo: %" PRIx32,
117 num_bits, tms, tdi, *tdo);
119 LOG_DEBUG_IO(
"Transact num_bits: %zu, tms: %" PRIx32
", tdi: %" PRIx32
", tdo: <null>",
127 size_t left =
cmd->cmd.stableclocks->num_cycles;
131 LOG_DEBUG(
"stableclocks %u cycles",
cmd->cmd.runtest->num_cycles);
152 LOG_DEBUG(
"statemove starting at (skip: %zu) %s end in %s", skip,
170 LOG_DEBUG(
"runtest %u cycles, end in %i",
171 cmd->cmd.runtest->num_cycles,
172 cmd->cmd.runtest->end_state);
183 size_t left =
cmd->cmd.runtest->num_cycles;
203 unsigned int num_states =
cmd->cmd.pathmove->num_states;
207 LOG_DEBUG(
"pathmove: %u states, end in %i",
208 cmd->cmd.pathmove->num_states,
209 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
211 for (
unsigned int i = 0; i < num_states; i++) {
217 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition.",
236 bool ir_scan =
cmd->cmd.scan->ir_scan;
237 uint32_t tdi, tms, tdo;
238 uint8_t *buf, *rd_ptr;
245 LOG_DEBUG(
"%s scan type %d %d bits; starts in %s end in %s",
246 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR",
type, scan_size,
281 rd_ptr +=
sizeof(uint32_t);
299 LOG_DEBUG(
"reset trst: %i srst: %i",
cmd->cmd.reset->trst,
300 cmd->cmd.reset->srst);
306 usleep(
cmd->cmd.sleep->us);
311 const size_t num_bits =
cmd->cmd.tms->num_bits;
312 const uint8_t *
bits =
cmd->cmd.tms->bits;
357 LOG_ERROR(
"BUG: Unknown JTAG command type encountered.");
384 char filename[PATH_MAX];
388 snprintf(filename, PATH_MAX,
"/sys/bus/pci/devices/%s/config",
392 LOG_ERROR(
"Failed to open device: %s", filename);
396 LOG_INFO(
"Scanning PCIe device %s's for Xilinx XVC/PCIe ...",
406 LOG_DEBUG(
"Checking capability at 0x%x; id=0x%04" PRIx32
" version=0x%" PRIx32
" next=0x%" PRIx32,
409 PCI_EXT_CAP_VER(cap),
410 PCI_EXT_CAP_NEXT(cap));
411 if (PCI_EXT_CAP_ID(cap) == PCI_EXT_CAP_ID_VNDR) {
415 LOG_DEBUG(
"Checking possible match at 0x%x; id: 0x%" PRIx32
"; rev: 0x%" PRIx32
"; length: 0x%" PRIx32,
417 PCI_VNDR_HEADER_ID(vh),
418 PCI_VNDR_HEADER_REV(vh),
419 PCI_VNDR_HEADER_LEN(vh));
466 .handler = xlnx_pcie_xvc_handle_config_command,
468 .help =
"Configure XVC/PCIe JTAG adapter",
476 .
name =
"xlnx_pcie_xvc",
478 .help =
"perform xlnx_pcie_xvc management",
503 seq +=
sizeof(uint32_t);
525 LOG_ERROR(
"Sequence %d not supported", seq);
535 uint32_t ap_delay_clk);
544 uint32_t ap_delay_clk)
546 uint32_t res, ack, rpar;
598 LOG_DEBUG_IO(
"No valid acknowledge: ack=%02"PRIx32, ack);
607 uint32_t ap_delay_clk)
655 LOG_DEBUG_IO(
"No valid acknowledge: ack=%02"PRIx32, ack);
675 LOG_DEBUG(
"SWD queue return value: %02x", err);
696 .
name =
"xlnx_pcie_xvc",
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
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.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
@ SCAN_IN
From device to host,.
@ SCAN_OUT
From host to device,.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#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...
#define ERROR_JTAG_DEVICE_ERROR
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
static const unsigned int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const unsigned int swd_seq_swd_to_jtag_len
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static struct jtag_interface xlnx_pcie_xvc_jtag_ops
static int xlnx_pcie_xvc_execute_scan(struct jtag_command *cmd)
static int xlnx_pcie_xvc_write_reg(const int offset, const uint32_t val)
static void xlnx_pcie_xvc_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static const char *const xlnx_pcie_xvc_transports[]
static int xlnx_pcie_xvc_transact(size_t num_bits, uint32_t tms, uint32_t tdi, uint32_t *tdo)
COMMAND_HANDLER(xlnx_pcie_xvc_handle_config_command)
struct adapter_driver xlnx_pcie_xvc_adapter_driver
static int xlnx_pcie_xvc_execute_pathmove(struct jtag_command *cmd)
#define XLNX_XVC_CAP_SIZE
static int xlnx_pcie_xvc_quit(void)
static int xlnx_pcie_xvc_swd_init(void)
#define XLNX_XVC_VSEC_HDR
static int xlnx_pcie_xvc_execute_statemove(size_t skip)
static void swd_clear_sticky_errors(void)
static const struct command_registration xlnx_pcie_xvc_command_handlers[]
static int xlnx_pcie_xvc_execute_command(struct jtag_command *cmd)
static const struct swd_driver xlnx_pcie_xvc_swd_ops
static int xlnx_pcie_xvc_swd_sequence(const uint8_t *seq, size_t length)
static int xlnx_pcie_xvc_read_reg(const int offset, uint32_t *val)
static int xlnx_pcie_xvc_swd_switch_seq(enum swd_special_seq seq)
static int xlnx_pcie_xvc_init(void)
static int xlnx_pcie_xvc_execute_stableclocks(struct jtag_command *cmd)
static void xlnx_pcie_xvc_execute_reset(struct jtag_command *cmd)
static int xlnx_pcie_xvc_execute_queue(struct jtag_command *cmd_queue)
static int xlnx_pcie_xvc_execute_tms(struct jtag_command *cmd)
static void xlnx_pcie_xvc_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
#define XLNX_XVC_MAX_BITS
static struct xlnx_pcie_xvc xlnx_pcie_xvc_state
static void xlnx_pcie_xvc_execute_sleep(struct jtag_command *cmd)
static int xlnx_pcie_xvc_swd_run_queue(void)
#define PCI_CFG_SPACE_EXP_SIZE
static const struct command_registration xlnx_pcie_xvc_subcommand_handlers[]
static int xlnx_pcie_xvc_execute_runtest(struct jtag_command *cmd)