Article 6CEZK Need help accessing PCI-e resources

Need help accessing PCI-e resources

by
notooth
from LinuxQuestions.org on (#6CEZK)
I have the following C code to access memory on a PCI-e card:
Code:#include <fcntl.h>
#include <sys/mman.h>
#include <stdio.h>

int main(int argc, char *argv[]) {

int fd = open("/sys/bus/pci/devices/0000:17:00.0/resource0", O_RDWR | O_SYNC);
void* base_address = (void*)0xfbff0000;
size_t size = 4;
void* void_memory = mmap(base_address,
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fd,
0);
char* memory = (char*)void_memory;

printf("memory[0] before: %d\n", (int)memory[0]);
memory[0] = 255;
sleep(1);
printf("memory[0] after : %d\n", (int)memory[0]);

}and it failed to write values to the memory on the card:

Code:memory[0] before: 6
memory[0] after : 6Can anyone let me know what I should do to make it work?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments