OpenOCD
dmem.c File Reference

This file implements support for the Direct memory access to CoreSight Access Ports (APs) or emulate the same to access CoreSight debug registers directly. More...

Include dependency graph for dmem.c:

Go to the source code of this file.

Data Structures

struct  dmem_emu_ap_info
 

Macros

#define ARM_APB_PADDR31   BIT(31)
 
#define DMEM_DEV_PATH_DEFAULT   "/dev/mem"
 
#define DMEM_MAX_EMULATE_APS   5
 

Functions

 COMMAND_HANDLER (dmem_dap_ap_offset_command)
 
 COMMAND_HANDLER (dmem_dap_base_address_command)
 
 COMMAND_HANDLER (dmem_dap_config_info_command)
 
 COMMAND_HANDLER (dmem_dap_device_command)
 
 COMMAND_HANDLER (dmem_dap_max_aps_command)
 
 COMMAND_HANDLER (dmem_emu_ap_list_command)
 
 COMMAND_HANDLER (dmem_emu_base_address_command)
 
static int dmem_ap_q_abort (struct adiv5_dap *dap, uint8_t *ack)
 
static int dmem_ap_q_read (struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
 
static int dmem_ap_q_write (struct adiv5_ap *ap, unsigned int reg, uint32_t data)
 
static int dmem_connect (struct adiv5_dap *dap)
 
static int dmem_dap_init (void)
 
static int dmem_dap_khz (int khz, int *jtag_speed)
 
static int dmem_dap_quit (void)
 
static int dmem_dap_reset (int req_trst, int req_srst)
 
static int dmem_dap_speed (int speed)
 
static int dmem_dap_speed_div (int speed, int *khz)
 
static int dmem_dp_q_read (struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
 
static int dmem_dp_q_write (struct adiv5_dap *dap, unsigned int reg, uint32_t data)
 
static int dmem_dp_run (struct adiv5_dap *dap)
 
static int dmem_emu_ap_q_read (unsigned int ap_idx, unsigned int reg, uint32_t *data)
 
static int dmem_emu_ap_q_write (unsigned int ap_idx, unsigned int reg, uint32_t data)
 
static uint32_t dmem_emu_get_ap_reg (uint64_t addr)
 
static void dmem_emu_set_ap_reg (uint64_t addr, uint32_t val)
 
static uint32_t dmem_get_ap_reg (struct adiv5_ap *ap, unsigned int reg)
 
static uint32_t dmem_get_ap_reg_offset (struct adiv5_ap *ap, unsigned int reg)
 
static bool dmem_is_emulated_ap (struct adiv5_ap *ap, unsigned int *idx)
 
static uint32_t dmem_memap_tar_inc (uint32_t csw)
 
static void dmem_set_ap_reg (struct adiv5_ap *ap, unsigned int reg, uint32_t val)
 

Variables

struct adapter_driver dmem_dap_adapter_driver
 
static uint32_t dmem_dap_ap_offset = 0x100
 
static uint64_t dmem_dap_base_address
 
static const struct command_registration dmem_dap_command_handlers []
 
static unsigned int dmem_dap_max_aps = 1
 
static const struct dap_ops dmem_dap_ops
 
static int dmem_dap_retval = ERROR_OK
 
static const struct command_registration dmem_dap_subcommand_handlers []
 
static const char *const dmem_dap_transport [] = { "dapdirect_swd", NULL }
 
static char * dmem_dev_path
 
static unsigned int dmem_emu_ap_count
 
static struct dmem_emu_ap_info dmem_emu_ap_list [DMEM_MAX_EMULATE_APS]
 
static uint64_t dmem_emu_base_address
 
static void * dmem_emu_map_base
 
static size_t dmem_emu_mapped_size
 
static uint64_t dmem_emu_size
 
static void * dmem_emu_virt_base_addr
 
static void * dmem_map_base
 
static size_t dmem_mapped_size
 
static void * dmem_virt_base_addr
 

Detailed Description

This file implements support for the Direct memory access to CoreSight Access Ports (APs) or emulate the same to access CoreSight debug registers directly.

Definition in file dmem.c.

Macro Definition Documentation

◆ ARM_APB_PADDR31

#define ARM_APB_PADDR31   BIT(31)

Definition at line 39 of file dmem.c.

◆ DMEM_DEV_PATH_DEFAULT

#define DMEM_DEV_PATH_DEFAULT   "/dev/mem"

Definition at line 45 of file dmem.c.

◆ DMEM_MAX_EMULATE_APS

#define DMEM_MAX_EMULATE_APS   5

Definition at line 59 of file dmem.c.

Function Documentation

◆ COMMAND_HANDLER() [1/7]

COMMAND_HANDLER ( dmem_dap_ap_offset_command  )

◆ COMMAND_HANDLER() [2/7]

COMMAND_HANDLER ( dmem_dap_base_address_command  )

◆ COMMAND_HANDLER() [3/7]

◆ COMMAND_HANDLER() [4/7]

COMMAND_HANDLER ( dmem_dap_device_command  )

Definition at line 328 of file dmem.c.

References CMD_ARGC, CMD_ARGV, dmem_dev_path, ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.

◆ COMMAND_HANDLER() [5/7]

COMMAND_HANDLER ( dmem_dap_max_aps_command  )

◆ COMMAND_HANDLER() [6/7]

COMMAND_HANDLER ( dmem_emu_ap_list_command  )

◆ COMMAND_HANDLER() [7/7]

COMMAND_HANDLER ( dmem_emu_base_address_command  )

◆ dmem_ap_q_abort()

static int dmem_ap_q_abort ( struct adiv5_dap dap,
uint8_t *  ack 
)
static

Definition at line 308 of file dmem.c.

References ERROR_OK.

◆ dmem_ap_q_read()

static int dmem_ap_q_read ( struct adiv5_ap ap,
unsigned int  reg,
uint32_t *  data 
)
static

◆ dmem_ap_q_write()

static int dmem_ap_q_write ( struct adiv5_ap ap,
unsigned int  reg,
uint32_t  data 
)
static

◆ dmem_connect()

static int dmem_connect ( struct adiv5_dap dap)
static

Definition at line 323 of file dmem.c.

References ERROR_OK.

◆ dmem_dap_init()

◆ dmem_dap_khz()

static int dmem_dap_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 584 of file dmem.c.

References ERROR_OK.

◆ dmem_dap_quit()

static int dmem_dap_quit ( void  )
static

◆ dmem_dap_reset()

static int dmem_dap_reset ( int  req_trst,
int  req_srst 
)
static

Definition at line 574 of file dmem.c.

References ERROR_OK.

◆ dmem_dap_speed()

static int dmem_dap_speed ( int  speed)
static

Definition at line 579 of file dmem.c.

References ERROR_OK.

◆ dmem_dap_speed_div()

static int dmem_dap_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 590 of file dmem.c.

◆ dmem_dp_q_read()

static int dmem_dp_q_read ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t *  data 
)
static

Definition at line 239 of file dmem.c.

References CDBGPWRUPACK, CSYSPWRUPACK, DP_CTRL_STAT, and ERROR_OK.

◆ dmem_dp_q_write()

static int dmem_dp_q_write ( struct adiv5_dap dap,
unsigned int  reg,
uint32_t  data 
)
static

Definition at line 257 of file dmem.c.

References ERROR_OK.

◆ dmem_dp_run()

static int dmem_dp_run ( struct adiv5_dap dap)
static

Definition at line 313 of file dmem.c.

References dmem_dap_retval, and ERROR_OK.

◆ dmem_emu_ap_q_read()

◆ dmem_emu_ap_q_write()

◆ dmem_emu_get_ap_reg()

static uint32_t dmem_emu_get_ap_reg ( uint64_t  addr)
static

Definition at line 103 of file dmem.c.

References addr, ARM_APB_PADDR31, and dmem_emu_virt_base_addr.

Referenced by dmem_emu_ap_q_read().

◆ dmem_emu_set_ap_reg()

static void dmem_emu_set_ap_reg ( uint64_t  addr,
uint32_t  val 
)
static

Definition at line 96 of file dmem.c.

References addr, ARM_APB_PADDR31, and dmem_emu_virt_base_addr.

Referenced by dmem_emu_ap_q_write().

◆ dmem_get_ap_reg()

static uint32_t dmem_get_ap_reg ( struct adiv5_ap ap,
unsigned int  reg 
)
static

Definition at line 233 of file dmem.c.

References dmem_get_ap_reg_offset(), and dmem_virt_base_addr.

Referenced by dmem_ap_q_read().

◆ dmem_get_ap_reg_offset()

static uint32_t dmem_get_ap_reg_offset ( struct adiv5_ap ap,
unsigned int  reg 
)
static

Definition at line 222 of file dmem.c.

References adiv5_ap::ap_num, and dmem_dap_ap_offset.

Referenced by dmem_get_ap_reg(), and dmem_set_ap_reg().

◆ dmem_is_emulated_ap()

static bool dmem_is_emulated_ap ( struct adiv5_ap ap,
unsigned int *  idx 
)
static

Definition at line 85 of file dmem.c.

References dmem_emu_ap_info::ap_num, adiv5_ap::ap_num, dmem_emu_ap_count, and dmem_emu_ap_list.

Referenced by dmem_ap_q_read(), and dmem_ap_q_write().

◆ dmem_memap_tar_inc()

static uint32_t dmem_memap_tar_inc ( uint32_t  csw)
static

Definition at line 67 of file dmem.c.

References CSW_ADDRINC_MASK, and CSW_SIZE_MASK.

Referenced by dmem_emu_ap_q_read(), and dmem_emu_ap_q_write().

◆ dmem_set_ap_reg()

static void dmem_set_ap_reg ( struct adiv5_ap ap,
unsigned int  reg,
uint32_t  val 
)
static

Definition at line 227 of file dmem.c.

References dmem_get_ap_reg_offset(), and dmem_virt_base_addr.

Referenced by dmem_ap_q_write().

Variable Documentation

◆ dmem_dap_adapter_driver

struct adapter_driver dmem_dap_adapter_driver
Initial value:
= {
.name = "dmem",
.transports = dmem_dap_transport,
.init = dmem_dap_init,
.quit = dmem_dap_quit,
.reset = dmem_dap_reset,
.speed = dmem_dap_speed,
.khz = dmem_dap_khz,
.speed_div = dmem_dap_speed_div,
.dap_swd_ops = &dmem_dap_ops,
}
static int dmem_dap_khz(int khz, int *jtag_speed)
Definition: dmem.c:584
static const struct dap_ops dmem_dap_ops
Definition: dmem.c:597
static const struct command_registration dmem_dap_command_handlers[]
Definition: dmem.c:474
static int dmem_dap_reset(int req_trst, int req_srst)
Definition: dmem.c:574
static int dmem_dap_speed(int speed)
Definition: dmem.c:579
static const char *const dmem_dap_transport[]
Definition: dmem.c:607
static int dmem_dap_speed_div(int speed, int *khz)
Definition: dmem.c:590
static int dmem_dap_init(void)
Definition: dmem.c:485
static int dmem_dap_quit(void)
Definition: dmem.c:562

Definition at line 607 of file dmem.c.

◆ dmem_dap_ap_offset

uint32_t dmem_dap_ap_offset = 0x100
static

Definition at line 49 of file dmem.c.

Referenced by COMMAND_HANDLER(), dmem_dap_init(), and dmem_get_ap_reg_offset().

◆ dmem_dap_base_address

uint64_t dmem_dap_base_address
static

Definition at line 47 of file dmem.c.

Referenced by COMMAND_HANDLER(), and dmem_dap_init().

◆ dmem_dap_command_handlers

const struct command_registration dmem_dap_command_handlers[]
static
Initial value:
= {
{
.name = "dmem",
.mode = COMMAND_ANY,
.help = "Perform dmem (Direct Memory) DAP management and configuration",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration dmem_dap_subcommand_handlers[]
Definition: dmem.c:421
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241

Definition at line 397 of file dmem.c.

◆ dmem_dap_max_aps

unsigned int dmem_dap_max_aps = 1
static

Definition at line 48 of file dmem.c.

Referenced by COMMAND_HANDLER(), and dmem_dap_init().

◆ dmem_dap_ops

const struct dap_ops dmem_dap_ops
static
Initial value:
= {
.connect = dmem_connect,
.queue_dp_read = dmem_dp_q_read,
.queue_dp_write = dmem_dp_q_write,
.queue_ap_read = dmem_ap_q_read,
.queue_ap_write = dmem_ap_q_write,
.queue_ap_abort = dmem_ap_q_abort,
.run = dmem_dp_run,
}
static int dmem_ap_q_write(struct adiv5_ap *ap, unsigned int reg, uint32_t data)
Definition: dmem.c:285
static int dmem_dp_q_read(struct adiv5_dap *dap, unsigned int reg, uint32_t *data)
Definition: dmem.c:239
static int dmem_dp_run(struct adiv5_dap *dap)
Definition: dmem.c:313
static int dmem_ap_q_read(struct adiv5_ap *ap, unsigned int reg, uint32_t *data)
Definition: dmem.c:262
static int dmem_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack)
Definition: dmem.c:308
static int dmem_connect(struct adiv5_dap *dap)
Definition: dmem.c:323
static int dmem_dp_q_write(struct adiv5_dap *dap, unsigned int reg, uint32_t data)
Definition: dmem.c:257

Definition at line 590 of file dmem.c.

◆ dmem_dap_retval

int dmem_dap_retval = ERROR_OK
static

Definition at line 52 of file dmem.c.

Referenced by dmem_dp_run(), dmem_emu_ap_q_read(), and dmem_emu_ap_q_write().

◆ dmem_dap_subcommand_handlers

const struct command_registration dmem_dap_subcommand_handlers[]
static

Definition at line 397 of file dmem.c.

◆ dmem_dap_transport

const char* const dmem_dap_transport[] = { "dapdirect_swd", NULL }
static

Definition at line 607 of file dmem.c.

◆ dmem_dev_path

char* dmem_dev_path
static

Definition at line 46 of file dmem.c.

Referenced by COMMAND_HANDLER(), and dmem_dap_init().

◆ dmem_emu_ap_count

unsigned int dmem_emu_ap_count
static

Definition at line 60 of file dmem.c.

Referenced by COMMAND_HANDLER(), dmem_dap_init(), dmem_dap_quit(), and dmem_is_emulated_ap().

◆ dmem_emu_ap_list

struct dmem_emu_ap_info dmem_emu_ap_list[DMEM_MAX_EMULATE_APS]
static

◆ dmem_emu_base_address

uint64_t dmem_emu_base_address
static

Definition at line 55 of file dmem.c.

Referenced by COMMAND_HANDLER(), and dmem_dap_init().

◆ dmem_emu_map_base

void* dmem_emu_map_base
static

Definition at line 57 of file dmem.c.

Referenced by dmem_dap_init(), and dmem_dap_quit().

◆ dmem_emu_mapped_size

size_t dmem_emu_mapped_size
static

Definition at line 58 of file dmem.c.

Referenced by dmem_dap_init(), and dmem_dap_quit().

◆ dmem_emu_size

uint64_t dmem_emu_size
static

Definition at line 56 of file dmem.c.

Referenced by COMMAND_HANDLER(), and dmem_dap_init().

◆ dmem_emu_virt_base_addr

void * dmem_emu_virt_base_addr
static

Definition at line 57 of file dmem.c.

Referenced by dmem_dap_init(), dmem_emu_get_ap_reg(), and dmem_emu_set_ap_reg().

◆ dmem_map_base

void* dmem_map_base
static

Definition at line 41 of file dmem.c.

Referenced by dmem_dap_init(), and dmem_dap_quit().

◆ dmem_mapped_size

size_t dmem_mapped_size
static

Definition at line 42 of file dmem.c.

Referenced by dmem_dap_init(), and dmem_dap_quit().

◆ dmem_virt_base_addr

void * dmem_virt_base_addr
static

Definition at line 41 of file dmem.c.

Referenced by dmem_dap_init(), dmem_get_ap_reg(), and dmem_set_ap_reg().