Commit c6cd2468 authored by Karen Xie's avatar Karen Xie

XDMA: fixed reg_rw access beyond 32K

parent 7d44836c
...@@ -39,17 +39,14 @@ ...@@ -39,17 +39,14 @@
#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
#define MAP_SIZE (32*1024UL)
#define MAP_MASK (MAP_SIZE - 1)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd; int fd;
void *map_base, *virt_addr; void *map;
uint32_t read_result, writeval; uint32_t read_result, writeval;
off_t target; off_t target;
/* access width */ /* access width */
int access_width = 'w'; char access_width = 'w';
char *device; char *device;
/* not enough arguments given? */ /* not enough arguments given? */
...@@ -64,20 +61,14 @@ int main(int argc, char **argv) ...@@ -64,20 +61,14 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
printf("argc = %d\n", argc);
device = strdup(argv[1]); device = strdup(argv[1]);
printf("device: %s\n", device);
target = strtoul(argv[2], 0, 0); target = strtoul(argv[2], 0, 0);
printf("address: 0x%08x\n", (unsigned int)target); printf("device: %s, address: 0x%08x, access %s: %s.\n",
device, (unsigned int)target, argc >= 4 ? "write" : "read");
printf("access type: %s\n", argc >= 4 ? "write" : "read");
/* data given? */ /* data given? */
if (argc >= 4) { if (argc >= 4)
printf("access width given.\n");
access_width = tolower(argv[3][0]); access_width = tolower(argv[3][0]);
}
printf("access width: "); printf("access width: ");
if (access_width == 'b') if (access_width == 'b')
printf("byte (8-bits)\n"); printf("byte (8-bits)\n");
...@@ -86,7 +77,7 @@ int main(int argc, char **argv) ...@@ -86,7 +77,7 @@ int main(int argc, char **argv)
else if (access_width == 'w') else if (access_width == 'w')
printf("word (32-bits)\n"); printf("word (32-bits)\n");
else { else {
printf("word (32-bits)\n"); printf("default to word (32-bits)\n");
access_width = 'w'; access_width = 'w';
} }
...@@ -95,42 +86,38 @@ int main(int argc, char **argv) ...@@ -95,42 +86,38 @@ int main(int argc, char **argv)
printf("character device %s opened.\n", argv[1]); printf("character device %s opened.\n", argv[1]);
fflush(stdout); fflush(stdout);
/* map one page */ map = mmap(0, 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target);
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (map == (void *)-1)
if (map_base == (void *)-1)
FATAL; FATAL;
printf("Memory mapped at address %p.\n", map_base); printf("Memory 0x%lx mapped at address %p.\n", target, map);
fflush(stdout); fflush(stdout);
/* calculate the virtual address to be accessed */
virt_addr = map_base + target;
/* read only */ /* read only */
if (argc <= 4) { if (argc <= 4) {
//printf("Read from address %p.\n", virt_addr);
switch (access_width) { switch (access_width) {
case 'b': case 'b':
read_result = *((uint8_t *) virt_addr); read_result = *((uint8_t *) map);
printf printf
("Read 8-bits value at address 0x%08x (%p): 0x%02x\n", ("Read 8-bits value at address 0x%08x (%p): 0x%02x\n",
(unsigned int)target, virt_addr, (unsigned int)target, map,
(unsigned int)read_result); (unsigned int)read_result);
break; break;
case 'h': case 'h':
read_result = *((uint16_t *) virt_addr); read_result = *((uint16_t *) map);
/* swap 16-bit endianess if host is not little-endian */ /* swap 16-bit endianess if host is not little-endian */
read_result = ltohs(read_result); read_result = ltohs(read_result);
printf printf
("Read 16-bit value at address 0x%08x (%p): 0x%04x\n", ("Read 16-bit value at address 0x%08x (%p): 0x%04x\n",
(unsigned int)target, virt_addr, (unsigned int)target, map,
(unsigned int)read_result); (unsigned int)read_result);
break; break;
case 'w': case 'w':
read_result = *((uint32_t *) virt_addr); read_result = *((uint32_t *) map);
/* swap 32-bit endianess if host is not little-endian */ /* swap 32-bit endianess if host is not little-endian */
read_result = ltohl(read_result); read_result = ltohl(read_result);
printf printf
("Read 32-bit value at address 0x%08x (%p): 0x%08x\n", ("Read 32-bit value at address 0x%08x (%p): 0x%08x\n",
(unsigned int)target, virt_addr, (unsigned int)target, map,
(unsigned int)read_result); (unsigned int)read_result);
return (int)read_result; return (int)read_result;
break; break;
...@@ -148,11 +135,11 @@ int main(int argc, char **argv) ...@@ -148,11 +135,11 @@ int main(int argc, char **argv)
case 'b': case 'b':
printf("Write 8-bits value 0x%02x to 0x%08x (0x%p)\n", printf("Write 8-bits value 0x%02x to 0x%08x (0x%p)\n",
(unsigned int)writeval, (unsigned int)target, (unsigned int)writeval, (unsigned int)target,
virt_addr); map);
*((uint8_t *) virt_addr) = writeval; *((uint8_t *) map) = writeval;
#if 0 #if 0
if (argc > 4) { if (argc > 4) {
read_result = *((uint8_t *) virt_addr); read_result = *((uint8_t *) map);
printf("Written 0x%02x; readback 0x%02x\n", printf("Written 0x%02x; readback 0x%02x\n",
writeval, read_result); writeval, read_result);
} }
...@@ -161,13 +148,13 @@ int main(int argc, char **argv) ...@@ -161,13 +148,13 @@ int main(int argc, char **argv)
case 'h': case 'h':
printf("Write 16-bits value 0x%04x to 0x%08x (0x%p)\n", printf("Write 16-bits value 0x%04x to 0x%08x (0x%p)\n",
(unsigned int)writeval, (unsigned int)target, (unsigned int)writeval, (unsigned int)target,
virt_addr); map);
/* swap 16-bit endianess if host is not little-endian */ /* swap 16-bit endianess if host is not little-endian */
writeval = htols(writeval); writeval = htols(writeval);
*((uint16_t *) virt_addr) = writeval; *((uint16_t *) map) = writeval;
#if 0 #if 0
if (argc > 4) { if (argc > 4) {
read_result = *((uint16_t *) virt_addr); read_result = *((uint16_t *) map);
printf("Written 0x%04x; readback 0x%04x\n", printf("Written 0x%04x; readback 0x%04x\n",
writeval, read_result); writeval, read_result);
} }
...@@ -176,13 +163,13 @@ int main(int argc, char **argv) ...@@ -176,13 +163,13 @@ int main(int argc, char **argv)
case 'w': case 'w':
printf("Write 32-bits value 0x%08x to 0x%08x (0x%p)\n", printf("Write 32-bits value 0x%08x to 0x%08x (0x%p)\n",
(unsigned int)writeval, (unsigned int)target, (unsigned int)writeval, (unsigned int)target,
virt_addr); map);
/* swap 32-bit endianess if host is not little-endian */ /* swap 32-bit endianess if host is not little-endian */
writeval = htoll(writeval); writeval = htoll(writeval);
*((uint32_t *) virt_addr) = writeval; *((uint32_t *) map) = writeval;
#if 0 #if 0
if (argc > 4) { if (argc > 4) {
read_result = *((uint32_t *) virt_addr); read_result = *((uint32_t *) map);
printf("Written 0x%08x; readback 0x%08x\n", printf("Written 0x%08x; readback 0x%08x\n",
writeval, read_result); writeval, read_result);
} }
...@@ -191,7 +178,7 @@ int main(int argc, char **argv) ...@@ -191,7 +178,7 @@ int main(int argc, char **argv)
} }
fflush(stdout); fflush(stdout);
} }
if (munmap(map_base, MAP_SIZE) == -1) if (munmap(map, 4) == -1)
FATAL; FATAL;
close(fd); close(fd);
return 0; return 0;
......
SHELL = /bin/bash SHELL = /bin/bash
#
# optional makefile parameters:
# - DEBUG=<0|1>, enable verbose debug print-out in the driver
# - xvc_bar_num=, xvc pci bar #
# - xvc_bar_offset=, xvc register base offset
#
ifneq ($(xvc_bar_num),) ifneq ($(xvc_bar_num),)
XVC_FLAGS += -D__XVC_BAR_NUM__=$(xvc_bar_num) XVC_FLAGS += -D__XVC_BAR_NUM__=$(xvc_bar_num)
endif endif
...@@ -14,7 +20,9 @@ topdir := $(shell cd $(src)/.. && pwd) ...@@ -14,7 +20,9 @@ topdir := $(shell cd $(src)/.. && pwd)
TARGET_MODULE:=xdma TARGET_MODULE:=xdma
EXTRA_CFLAGS := -I$(topdir)/include $(XVC_FLAGS) EXTRA_CFLAGS := -I$(topdir)/include $(XVC_FLAGS)
#EXTRA_CFLAGS += -D__LIBXDMA_DEBUG__ ifeq ($(DEBUG),1)
EXTRA_CFLAGS += -D__LIBXDMA_DEBUG__
endif
#EXTRA_CFLAGS += -DINTERNAL_TESTING #EXTRA_CFLAGS += -DINTERNAL_TESTING
ifneq ($(KERNELRELEASE),) ifneq ($(KERNELRELEASE),)
......
...@@ -216,8 +216,7 @@ int bridge_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -216,8 +216,7 @@ int bridge_mmap(struct file *file, struct vm_area_struct *vma)
dbg_sg("mmap(): cdev->bar = %d\n", xcdev->bar); dbg_sg("mmap(): cdev->bar = %d\n", xcdev->bar);
dbg_sg("mmap(): xdev = 0x%p\n", xdev); dbg_sg("mmap(): xdev = 0x%p\n", xdev);
dbg_sg("mmap(): pci_dev = 0x%08lx\n", (unsigned long)xdev->pdev); dbg_sg("mmap(): pci_dev = 0x%08lx\n", (unsigned long)xdev->pdev);
dbg_sg("off = 0x%lx, vsize 0x%lu, psize 0x%lu.\n", off, vsize, psize);
dbg_sg("off = 0x%lx\n", off);
dbg_sg("start = 0x%llx\n", dbg_sg("start = 0x%llx\n",
(unsigned long long)pci_resource_start(xdev->pdev, (unsigned long long)pci_resource_start(xdev->pdev,
xcdev->bar)); xcdev->bar));
......
...@@ -63,9 +63,6 @@ ...@@ -63,9 +63,6 @@
*/ */
//#define XDMA_CONFIG_BAR_NUM 1 //#define XDMA_CONFIG_BAR_NUM 1
/* Switch debug printing on/off */
#define XDMA_DEBUG 0
/* SECTION: Preprocessor macros/constants */ /* SECTION: Preprocessor macros/constants */
#define XDMA_BAR_NUM (6) #define XDMA_BAR_NUM (6)
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#define DRV_MOD_MAJOR 2020 #define DRV_MOD_MAJOR 2020
#define DRV_MOD_MINOR 2 #define DRV_MOD_MINOR 2
#define DRV_MOD_PATCHLEVEL 0 #define DRV_MOD_PATCHLEVEL 1
#define DRV_MODULE_VERSION \ #define DRV_MODULE_VERSION \
__stringify(DRV_MOD_MAJOR) "." \ __stringify(DRV_MOD_MAJOR) "." \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment