diff options
author | Rob Austein <sra@hactrn.net> | 2015-10-04 15:39:08 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2015-10-04 15:39:08 -0400 |
commit | e164eecc55dd96efc98d2c723e96aaaecdcfda13 (patch) | |
tree | e7f9b5b5c82c893ac92a76417bab22af51206fa7 | |
parent | 60cce0124f2fc3eddca03ed3950da9238247a612 (diff) |
off_t => hal_addr_t.
-rw-r--r-- | GNUmakefile | 2 | ||||
-rw-r--r-- | hal.h | 27 | ||||
-rw-r--r-- | hal_io_eim.c | 18 | ||||
-rw-r--r-- | hal_io_i2c.c | 26 | ||||
-rw-r--r-- | hash.c | 10 | ||||
-rw-r--r-- | modexp.c | 6 |
6 files changed, 50 insertions, 39 deletions
diff --git a/GNUmakefile b/GNUmakefile index f425c50..37d038e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -66,5 +66,5 @@ distclean: clean tags: TAGS -TAGS: *.[ch] +TAGS: *.[ch] tests/*.[ch] etags $^ @@ -459,6 +459,17 @@ typedef enum { HAL_ERROR_LIST N_HAL_ERRORS } hal_error_t; #include <stdint.h> #include <sys/types.h> +/* + * Typedef to isolate code from our current choice of representation + * for a Cryptech bus address. + */ + +typedef off_t hal_addr_t; + +/* + * Error translation. + */ + extern const char *hal_error_string(const hal_error_t err); /* @@ -466,14 +477,14 @@ extern const char *hal_error_string(const hal_error_t err); */ extern void hal_io_set_debug(int onoff); -extern hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len); -extern hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len); -extern hal_error_t hal_io_expected(off_t offset, const uint8_t *expected, size_t len); -extern hal_error_t hal_io_init(off_t offset); -extern hal_error_t hal_io_next(off_t offset); -extern hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count); -extern hal_error_t hal_io_wait_ready(off_t offset); -extern hal_error_t hal_io_wait_valid(off_t offset); +extern hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len); +extern hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len); +extern hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *expected, size_t len); +extern hal_error_t hal_io_init(hal_addr_t offset); +extern hal_error_t hal_io_next(hal_addr_t offset); +extern hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count); +extern hal_error_t hal_io_wait_ready(hal_addr_t offset); +extern hal_error_t hal_io_wait_valid(hal_addr_t offset); /* * Higher level public API. diff --git a/hal_io_eim.c b/hal_io_eim.c index 3687b95..c0f70f4 100644 --- a/hal_io_eim.c +++ b/hal_io_eim.c @@ -72,7 +72,7 @@ static hal_error_t init(void) * * sss ccccc rrrrrrrr => 00001000000000 sss 0 ccccc rrrrrrrr 00 */ -static off_t eim_offset(off_t offset) +static hal_addr_t eim_offset(hal_addr_t offset) { return EIM_BASE_ADDR + ((offset & ~0x1fff) << 3) + ((offset & 0x1fff) << 2); } @@ -93,7 +93,7 @@ static void dump(char *label, const uint8_t *buf, size_t len) } } -hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) +hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -115,7 +115,7 @@ hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) +hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) { uint8_t *rbuf = buf; int rlen = len; @@ -139,7 +139,7 @@ hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_expected(off_t offset, const uint8_t *expected, size_t len) +hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *expected, size_t len) { hal_error_t err; uint8_t buf[4]; @@ -160,19 +160,19 @@ hal_error_t hal_io_expected(off_t offset, const uint8_t *expected, size_t len) return HAL_OK; } -hal_error_t hal_io_init(off_t offset) +hal_error_t hal_io_init(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; return hal_io_write(offset, buf, sizeof(buf)); } -hal_error_t hal_io_next(off_t offset) +hal_error_t hal_io_next(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; return hal_io_write(offset, buf, sizeof(buf)); } -hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) +hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) { hal_error_t err; uint8_t buf[4]; @@ -194,13 +194,13 @@ hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) } } -hal_error_t hal_io_wait_ready(off_t offset) +hal_error_t hal_io_wait_ready(hal_addr_t offset) { int limit = EIM_IO_TIMEOUT; return hal_io_wait(offset, STATUS_READY, &limit); } -hal_error_t hal_io_wait_valid(off_t offset) +hal_error_t hal_io_wait_valid(hal_addr_t offset) { int limit = EIM_IO_TIMEOUT; return hal_io_wait(offset, STATUS_VALID, &limit); diff --git a/hal_io_i2c.c b/hal_io_i2c.c index 9788232..1dbd041 100644 --- a/hal_io_i2c.c +++ b/hal_io_i2c.c @@ -166,14 +166,14 @@ static hal_error_t i2c_read(uint8_t *b) #define UNKNOWN 0xfe #define ERROR 0xfd -static hal_error_t hal_io_send_write_cmd(off_t offset, const uint8_t *data) +static hal_error_t hal_io_send_write_cmd(hal_addr_t offset, const uint8_t *data) { uint8_t buf[9] = { SOC, WRITE_CMD, (offset >> 8) & 0xff, offset & 0xff, data[0], data[1], data[2], data[3], EOC }; return i2c_write(buf, sizeof(buf)); } -static hal_error_t hal_io_send_read_cmd(off_t offset) +static hal_error_t hal_io_send_read_cmd(hal_addr_t offset) { uint8_t buf[5] = { SOC, READ_CMD, (offset >> 8) & 0xff, offset & 0xff, EOC }; return i2c_write(buf, sizeof(buf)); @@ -233,7 +233,7 @@ static hal_error_t hal_io_compare(uint8_t *buf, const uint8_t *expected, size_t return HAL_OK; } -static hal_error_t hal_io_get_write_resp(off_t offset) +static hal_error_t hal_io_get_write_resp(hal_addr_t offset) { uint8_t buf[5]; uint8_t expected[5] = { SOR, WRITE_OK, (offset >> 8) & 0xff, offset & 0xff, EOR }; @@ -245,7 +245,7 @@ static hal_error_t hal_io_get_write_resp(off_t offset) return hal_io_compare(buf, expected, sizeof(expected)); } -static hal_error_t hal_io_get_read_resp(off_t offset, uint8_t *data) +static hal_error_t hal_io_get_read_resp(hal_addr_t offset, uint8_t *data) { uint8_t buf[9]; uint8_t expected[4] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff }; @@ -266,7 +266,7 @@ static hal_error_t hal_io_get_read_resp(off_t offset, uint8_t *data) return HAL_OK; } -static hal_error_t hal_io_get_read_resp_expected(off_t offset, const uint8_t *data) +static hal_error_t hal_io_get_read_resp_expected(hal_addr_t offset, const uint8_t *data) { uint8_t buf[9]; uint8_t expected[9] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff, @@ -281,7 +281,7 @@ static hal_error_t hal_io_get_read_resp_expected(off_t offset, const uint8_t *da return hal_io_compare(buf, expected, sizeof(buf)); } -hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) +hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -293,7 +293,7 @@ hal_error_t hal_io_write(off_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) +hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len) { hal_error_t err; @@ -305,7 +305,7 @@ hal_error_t hal_io_read(off_t offset, uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_expected(off_t offset, const uint8_t *buf, size_t len) +hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *buf, size_t len) { hal_error_t err; @@ -317,19 +317,19 @@ hal_error_t hal_io_expected(off_t offset, const uint8_t *buf, size_t len) return HAL_OK; } -hal_error_t hal_io_init(off_t offset) +hal_error_t hal_io_init(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_INIT }; return hal_io_write(offset, buf, 4); } -hal_error_t hal_io_next(off_t offset) +hal_error_t hal_io_next(hal_addr_t offset) { uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT }; return hal_io_write(offset, buf, 4); } -hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) +hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count) { hal_error_t err; uint8_t buf[4]; @@ -352,13 +352,13 @@ hal_error_t hal_io_wait(off_t offset, uint8_t status, int *count) } } -hal_error_t hal_io_wait_ready(off_t offset) +hal_error_t hal_io_wait_ready(hal_addr_t offset) { int limit = 10; return hal_io_wait(offset, STATUS_READY, &limit); } -hal_error_t hal_io_wait_valid(off_t offset) +hal_error_t hal_io_wait_valid(hal_addr_t offset) { int limit = 10; return hal_io_wait(offset, STATUS_VALID, &limit); @@ -66,11 +66,11 @@ struct hal_hash_driver { size_t length_length; /* Length of the length field */ - off_t block_addr; /* Where to write hash blocks */ - off_t ctrl_addr; /* Control register */ - off_t status_addr; /* Status register */ - off_t digest_addr; /* Where to read digest */ - off_t name_addr; /* Where to read core name */ + hal_addr_t block_addr; /* Where to write hash blocks */ + hal_addr_t ctrl_addr; /* Control register */ + hal_addr_t status_addr; /* Status register */ + hal_addr_t digest_addr; /* Where to read digest */ + hal_addr_t name_addr; /* Where to read core name */ char core_name[8]; /* Expected name of core */ uint8_t ctrl_mode; /* Digest mode, for cores that have modes */ }; @@ -76,7 +76,7 @@ void hal_modexp_set_debug(const int onoff) * Set an ordinary register. */ -static hal_error_t set_register(const off_t addr, +static hal_error_t set_register(const hal_addr_t addr, uint32_t value) { uint8_t w[4]; @@ -96,7 +96,7 @@ static hal_error_t set_register(const off_t addr, * expects. */ -static hal_error_t get_buffer(const off_t data_addr, +static hal_error_t get_buffer(const hal_addr_t data_addr, uint8_t *value, const size_t length) { @@ -116,7 +116,7 @@ static hal_error_t get_buffer(const off_t data_addr, * expects. */ -static hal_error_t set_buffer(const off_t data_addr, +static hal_error_t set_buffer(const hal_addr_t data_addr, const uint8_t * const value, const size_t length) { |