LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2023, 01:38 AM   #1
notooth
Member
 
Registered: Apr 2005
Posts: 192

Rep: Reputation: 15
Need help accessing PCI-e resources


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 : 6
Can anyone let me know what I should do to make it work?
 
Old 06-25-2023, 11:14 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
No, I don't know how to "make it work". What type of device is this (as in what is it designed to do), and what are you trying to get it to do by writing to its memory?

Last edited by dugan; 06-25-2023 at 11:25 AM.
 
Old 06-25-2023, 07:58 PM   #3
notooth
Member
 
Registered: Apr 2005
Posts: 192

Original Poster
Rep: Reputation: 15
It is a PCI-e based FPGA. I am trying to get it store data in its memory.
 
Old 06-26-2023, 12:21 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Where did this 0xfbff0000 came from? If it is a randomly choosen number, use NULL instead of it, then the kernel will give you an address.

Last edited by NevemTeve; 06-26-2023 at 01:15 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE5 resources vs windows 10 resources bob595 Linux - Newbie 11 10-13-2016 04:09 PM
Issues accessing inside resources using OpenVPN. dpdpowered83 Linux - Newbie 6 11-18-2012 12:35 PM
Can't install mini pci-e card into desktop PC through a mini pci-e to pci-e 1x card bocaiwen Linux - Hardware 3 05-15-2012 02:29 AM
LXer: Accessing Windows Resources from a Linux Desktop LXer Syndicated Linux News 0 10-04-2006 10:54 AM
Strange Delay when Accessing Internet Resources RAdams Linux - Networking 4 08-28-2006 09:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration