Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Accessing Memory-mapped I/O

by Anonymous Monk
on Oct 31, 2019 at 15:47 UTC ( [id://11108182]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to access a memory-mapped register outside of system ram. I am opening /dev/mem to do so. When using seek, I only get access to the address space of the system ram. Using an address above that limit gives me a "Bad address" error.

Doing a similar operation in 'C' allows access to addresses above that limitation. Why does perl limit my access? Is there anyway around the limitation?

Replies are listed 'Best First'.
Re: Accessing Memory-mapped I/O
by stevieb (Canon) on Oct 31, 2019 at 15:56 UTC

    Would you please provide the smallest snippet of code that doesn't work, so that we can reproduce the problem to better understand it?

    Adding the C example showing it working would be of benefit as well.

      Here is a snippet of perl code:

      open(FH, "<", "/dev/mem"); binmode(FH); seek(FH,0xff230180,0); #Fails with bad address

      Here is a snippet of C code:

      devmem_fd = open("/dev/mem", O_RDWR | O_SYNC); bridge_map = (uint32_t*)mmap(NULL, 0x100, PROT_READ|PROT_WRITE, MAP_SHARED, devmem_fd, 0xff230180); reg = (uint32_t*) bridge_map; printf("Register contents: 0x08x\n", *reg); munmap (bridge_map, 0x100); close(devmem_fd);

        You're doing two completely different thing between the Perl code and the C code. Does the C code still work when using seek? Does the Perl code work when using (for example) File::Map?

Re: Accessing Memory-mapped I/O
by jdmonk (Initiate) on Nov 04, 2019 at 19:29 UTC
    So, I found a way to install the Sys::Mmap module. With it, I am able to access the memory-mapped registers.
Re: Accessing Memory-mapped I/O
by jcb (Parson) on Nov 04, 2019 at 01:32 UTC

    Perl is not limiting your access, but you are using buffered I/O to access MMIO space, so perl is trying to read much more than you actually have. Try sysopen/sysseek/sysread/syswrite instead.

      I've tried using sysseek and have the same problem: bad address.
Re: Accessing Memory-mapped I/O
by Anonymous Monk on Nov 01, 2019 at 13:23 UTC
    You need to publish your C-code to let us demonstrate that it works. I do not think that it does. In any case what you really want to do is to use system-calls to directly map the requested address space ... not rely on /dev/mem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11108182]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-23 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found