[driver] Fix bug in addr range check for upload/download

Device address should not be compared against LOCAL_MEM_SIZE but against
an absolute max address.  Introduce new DEVICE_MAX_ADDR for this.
This commit is contained in:
Hansung Kim
2023-10-07 21:18:27 -07:00
parent 6ffb8c37e9
commit 46a60cf58e
3 changed files with 8 additions and 7 deletions

View File

@@ -9,3 +9,4 @@ bool is_aligned(uint64_t addr, uint64_t alignment);
#define CACHE_BLOCK_SIZE 64 #define CACHE_BLOCK_SIZE 64
#define ALLOC_BASE_ADDR 0x00000000 #define ALLOC_BASE_ADDR 0x00000000
#define LOCAL_MEM_SIZE 4294967296 // 4 GB #define LOCAL_MEM_SIZE 4294967296 // 4 GB
#define DEVICE_MAX_ADDR 0xfffffffful

View File

@@ -86,7 +86,7 @@ public:
int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) { int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) {
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE); uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
if (dest_addr + asize > LOCAL_MEM_SIZE) if (dest_addr + asize > DEVICE_MAX_ADDR)
return -1; return -1;
/*printf("VXDRV: upload %ld bytes from 0x%lx:", size, uintptr_t((uint8_t*)src + src_offset)); /*printf("VXDRV: upload %ld bytes from 0x%lx:", size, uintptr_t((uint8_t*)src + src_offset));
@@ -104,7 +104,7 @@ public:
int download(void* dest, uint64_t src_addr, uint64_t size, uint64_t dest_offset) { int download(void* dest, uint64_t src_addr, uint64_t size, uint64_t dest_offset) {
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE); uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
if (src_addr + asize > LOCAL_MEM_SIZE) if (src_addr + asize > DEVICE_MAX_ADDR)
return -1; return -1;
ram_.read((uint8_t*)dest + dest_offset, src_addr, asize); ram_.read((uint8_t*)dest + dest_offset, src_addr, asize);

View File

@@ -93,7 +93,7 @@ public:
int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) { int upload(const void* src, uint64_t dest_addr, uint64_t size, uint64_t src_offset) {
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE); uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
if (dest_addr + asize > LOCAL_MEM_SIZE) if (dest_addr + asize > DEVICE_MAX_ADDR)
return -1; return -1;
ram_.write((const uint8_t*)src + src_offset, dest_addr, asize); ram_.write((const uint8_t*)src + src_offset, dest_addr, asize);
@@ -108,7 +108,7 @@ public:
int download(void* dest, uint64_t src_addr, uint64_t size, uint64_t dest_offset) { int download(void* dest, uint64_t src_addr, uint64_t size, uint64_t dest_offset) {
uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE); uint64_t asize = aligned_size(size, CACHE_BLOCK_SIZE);
if (src_addr + asize > LOCAL_MEM_SIZE) if (src_addr + asize > DEVICE_MAX_ADDR)
return -1; return -1;
ram_.read((uint8_t*)dest + dest_offset, src_addr, asize); ram_.read((uint8_t*)dest + dest_offset, src_addr, asize);