pci memory access in user mode?
- From: mich1985 <florian.harmuth@xxxxxxxxxxxxxx>
- Date: Fri, 28 Mar 2008 07:04:29 -0700 (PDT)
Hello all,
at the moment i try to access the memory on my pci device. If i check
the value on 0xc0 i get the correct value. If i now try to set one bit
in my memory (the bit is linked to a led) nothing happens. Looks my
attached code correct?
Here is my sample code:
<code>
int main()
{
int fd;
void *mem_ptr;
unsigned int *val;
int pagesize = getpagesize(); /* really necessary? */
fd = open("/sys/bus/pci/devices/0000:07:04.0/resource0",O_RDWR);
if (fd < 0)
{
printf("Can't open resource file!");
return 0;
}
mem_ptr = mmap(0, pagesize,PROT_READ | PROT_WRITE,MAP_SHARED,fd,
0x0);
/* should i use the real memory size (0x80 byte?) instead of the
pagesize? */
if (mem_ptr==MAP_FAILED)
{
printf("mmap problem!");
} else
{
val = mem_ptr;
/* version check works well */
if (val[0x0C]!=0xa511)
printf("Bitte Version pruefen! (0x%x != 0xA511)\n",val[0x0C]);
/* gives me 0xc001 instead of 0x1 or 0xc004 instead of 0x4 */
printf("Read: 0x%x\n", val[0x0]);
/* set io enable bit */
*(val+0x18)= (unsigned int) 0x200;
/* turn on my led */
*val = (unsigned int) 0x1;
munmap(mem_ptr,2);
}
close(fd);
return 0;
}
</code>
Thanks for reading.
Regards,
flo
.
- Follow-Ups:
- Re: pci memory access in user mode?
- From: Mike
- Re: pci memory access in user mode?
- Prev by Date: Re: Boolean algebra error in 2.6.24?
- Next by Date: determine cpu count from module.ko
- Previous by thread: physical memory allocated to a program
- Next by thread: Re: pci memory access in user mode?
- Index(es):
Relevant Pages
|