I'm trying to access a memory device (256KB) we added to our OMAP3525-based custom board under Linux. This memory device is allocated by the Xilinx Spartan 6 and hooked up to CS2 on the GPMC and mapped to physical address 0x10000000; the 7 CONFIG registers for CS2 are properly set up because
I'm able to access (reads and writes) it under u-boot without any problems.
Under Linux, I wrote a little user-space application using /dev/mem and mmap to access it. On our previous board which uses the TI Davinci processor (6446), the application works fine using mmap. On this OMAP3525-based custom board, all I get are 0's on the reads and writes; no error conditions though. This sample application can access the OMAP3525 registers fine but cannot properly access the CS2 256KB memory region created from the Xilinx FPGA. Looking at the logic analyzer, I can see the chip select when I access the memory region. Do I need to "register" the physical address (0x10000000) with the Linux kernel for mmap to work correctly? If so, how do I go about doing so? I searched the kernel and see that arch/arm/mach-omap2/io.c contains virtual and physical addresses for various memory space regions of the OMAP3; I assume this is used by kernel drivers only via ioremap. For what I'm doing, I'm not writing any driver and am just using mmap in a user-space application to access the memory device. Any advice on what I'm doing wrong; this area is not-cacheable so I added the "O_SYNC" option. Here's a snippet of my sample application. Thanks.
volatile unsigned char *p;
size_t length = 0x1000; // 4KB page
int prot = PROT_READ | PROT_WRITE;
int flags = MAP_SHARED;
int fd = open("/dev/mem", O_RDWR | O_SYNC);
off_t offset;
unsigned int offset_addr;
int index;
sscanf(argv[1], "%x", &offset_addr);
offset = (off_t)(offset_addr & 0xfffff000);
index = offset_addr & 0xfff;
if (fd < 0) {
perror("open");
return 1;
}
p = (unsigned char *)mmap(NULL, length, prot, flags, fd, offset);
if (p == MAP_FAILED) {
perror("mmap");
return 4;
}
// do something (like read or write) to p[index]
Regards,
Andy