target: allow targets to override memory alignment
authorMathias K <kesmtp@freenet.de>
Thu, 3 Mar 2011 10:01:46 +0000 (11:01 +0100)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Thu, 17 Mar 2011 13:18:16 +0000 (14:18 +0100)
Targets can implement read/write_buffer to handle
alignment.

src/target/target.c
src/target/target_type.h

index be42b338fba3136d2cf23579edd193d8ab96a107..13d358d7c1a0fd9b5ca3faf7472689a22775da9a 100644 (file)
 #include "image.h"
 
 
+static int target_read_buffer_default(struct target *target, uint32_t address,
+               uint32_t size, uint8_t *buffer);
+static int target_write_buffer_default(struct target *target, uint32_t address,
+               uint32_t size, uint8_t *buffer);
 static int target_array2mem(Jim_Interp *interp, struct target *target,
                int argc, Jim_Obj *const *argv);
 static int target_mem2array(Jim_Interp *interp, struct target *target,
@@ -865,6 +869,13 @@ static int target_init_one(struct command_context *cmd_ctx,
                type->read_phys_memory = type->read_memory;
                type->virt2phys = identity_virt2phys;
        }
+
+       if (target->type->read_buffer == NULL)
+               target->type->read_buffer = target_read_buffer_default;
+
+       if (target->type->write_buffer == NULL)
+               target->type->write_buffer = target_write_buffer_default;
+
        return ERROR_OK;
 }
 
@@ -1333,7 +1344,6 @@ int target_arch_state(struct target *target)
  */
 int target_write_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
 {
-       int retval;
        LOG_DEBUG("writing buffer of %i byte at 0x%8.8x",
                  (int)size, (unsigned)address);
 
@@ -1356,6 +1366,13 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
                return ERROR_FAIL;
        }
 
+       return target->type->write_buffer(target, address, size, buffer);
+}
+
+static int target_write_buffer_default(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+{
+       int retval = ERROR_OK;
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_write_memory(target, address, 2, 1, buffer);
@@ -1406,7 +1423,7 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
                        return retval;
        }
 
-       return ERROR_OK;
+       return retval;
 }
 
 /* Single aligned words are guaranteed to use 16 or 32 bit access
@@ -1415,7 +1432,6 @@ int target_write_buffer(struct target *target, uint32_t address, uint32_t size,
  */
 int target_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
 {
-       int retval;
        LOG_DEBUG("reading buffer of %i byte at 0x%8.8x",
                          (int)size, (unsigned)address);
 
@@ -1438,6 +1454,13 @@ int target_read_buffer(struct target *target, uint32_t address, uint32_t size, u
                return ERROR_FAIL;
        }
 
+       return target->type->read_buffer(target, address, size, buffer);
+}
+
+static int target_read_buffer_default(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
+{
+       int retval = ERROR_OK;
+
        if (((address % 2) == 0) && (size == 2))
        {
                return target_read_memory(target, address, 2, 1, buffer);
@@ -3695,7 +3718,6 @@ static Jim_Nvp nvp_config_opts[] = {
        { .name = "-variant",          .value = TCFG_VARIANT },
        { .name = "-coreid",           .value = TCFG_COREID },
        { .name = "-chain-position",   .value = TCFG_CHAIN_POSITION },
-
        { .name = NULL, .value = -1 }
 };
 
index bfa7f9379fb35714aaa0a529a5243feed3b9383b..15598b2f17f53f6014d55ab5442947f7dfaa413f 100644 (file)
@@ -119,6 +119,12 @@ struct target_type
         */
        int (*write_memory)(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
 
+       /* Default implementation will do some fancy alignment to improve performance, target can override */
+       int (*read_buffer)(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer);
+
+       /* Default implementation will do some fancy alignment to improve performance, target can override */
+       int (*write_buffer)(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer);
+
        /**
         * Write target memory in multiples of 4 bytes, optimized for
         * writing large quantities of data.  Do @b not call this