LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* using /dev/mem to talk to peripherals on VIIP system
@ 2006-07-28 17:35 scott
  2006-07-28 17:51 ` Dan Malek
  0 siblings, 1 reply; 3+ messages in thread
From: scott @ 2006-07-28 17:35 UTC (permalink / raw)
  To: linuxppc-embedded

[-- Attachment #1: Type: text/plain, Size: 1845 bytes --]

Hello again,
well i didn't get any responses at all to my last post so I thought i'd try this again.

I have kernel 2.4.26 installed on a Xilinx XUP board and everything works well except I can't seem to communicate with peripherals on the OPB or PLB bus through devfs.  devfs is on and mounted and everything, and I'm able open a file handle to it w/ the following code:

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

  fd = open("/dev/mem", O_RDWR);
  if(fd == -1) {
    printf("Err: cannot open /dev/mem\n");
    return -1;
  }

  ptr = MAP_FAILED; // Initialize to bad value
  ptr = (int *) mmap(0, 256, PROT_READ|PROT_WRITE, MAP_SHARED, fd, USER_LOGIC_BASEADDR);

  if(ptr==MAP_FAILED) {
    printf("Err: cannot access address!\n");
    return -1;
  }

  *ptr = 0xA0000000;
  ...


mmap also seems to work, and returns a virtual address that is supposed to point to the location in physical memory at USER_LOGIC_BASEADDR.  when I try to use ptr, however, I either get 
bus error

or

do_wp_page: bogus page at address 3001a000 (page 0xc2c4c004)
VM: killing process led_test.o

depending on whether I use MAP_SHARED or MAP_PRIVATE.

These errors occur if I try to access any device on either PLB or OPB - even the OPB UART (which i KNOW is working).  This technique DOES work, however, for address ranges in RAM.  This indicates to me that it's some sort of higher level memory management problem w/ linuxppc such that it doesn't realize these address ranges are valid.  I assume this is a function of the BSP that gets generated in EDK?  Anybody have any idea how I can tell linux to let me use these addresses?  Any other thoughts?

If I'm being too vague or something please let me know and I'll resolve it immediately...

Thanks much, --scott


Other details:
linuxppc-2.4.26
busybox 1.1.0
powerpc-405-linux-gnu-gcc 3.4.1



[-- Attachment #2: Type: text/html, Size: 2335 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using /dev/mem to talk to peripherals on VIIP system
  2006-07-28 17:35 using /dev/mem to talk to peripherals on VIIP system scott
@ 2006-07-28 17:51 ` Dan Malek
  2006-07-28 19:54   ` scott
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Malek @ 2006-07-28 17:51 UTC (permalink / raw)
  To: scott; +Cc: linuxppc-embedded


On Jul 28, 2006, at 1:35 PM, scott wrote:

>   ptr = MAP_FAILED; // Initialize to bad value
>   ptr = (int *) mmap(0, 256, PROT_READ|PROT_WRITE, MAP_SHARED, fd,  
> USER_LOGIC_BASEADDR);

Well, this isn't going to detect an error, since the error code
is returned instead of an address.

>
>   if(ptr==MAP_FAILED) {

	if ((int)ptr == -1) {
>     printf("Err: cannot access address!\n");
>     return -1;
>   }
>

> ....  Any other thoughts?

Your mmap is failing because the size is not modulo PAGE_SIZE.


	-- Dan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using /dev/mem to talk to peripherals on VIIP system
  2006-07-28 17:51 ` Dan Malek
@ 2006-07-28 19:54   ` scott
  0 siblings, 0 replies; 3+ messages in thread
From: scott @ 2006-07-28 19:54 UTC (permalink / raw)
  To: linuxppc-embedded

[-- Attachment #1: Type: text/plain, Size: 1783 bytes --]

Hi Dan, thanks for your quick response!  I was using a reference to mmap from this page:
http://www.opengroup.org/onlinepubs/000095399/functions/mmap.html
which states that mmap will return MAP_FAILED if there is an error and the error will be located in errno.    please correct me if this is wrong.  As such i don't believe that the map is failing.

i did in any case make the size modulo with PAGE_SIZE (=4096) as found in asm-ppc/page.h which unfortunately did not fix the problem.  just for the heck of it I also tried every size from 1 up to 65536...

It's worth noting that I also tried treating /dev/mem as a file (as it was intended) by using functions lseek, read, and write.  read and write returned a value of zero upon completion, indicating that no bytes were read/written.  I get the feeling that file I/O functions failing on /dev/mem indicates something important, but I'm not sure what. especially since /dev/mem operations DO work on other parts of physical memory (such as RAM).

--scott

----- Original Message ----
From: Dan Malek <dan@embeddedalley.com>
To: scott <scotto2hot-green@yahoo.com>
Cc: linuxppc-embedded@ozlabs.org
Sent: Friday, July 28, 2006 11:51:03 AM
Subject: Re: using /dev/mem to talk to peripherals on VIIP system


On Jul 28, 2006, at 1:35 PM, scott wrote:

>   ptr = MAP_FAILED; // Initialize to bad value
>   ptr = (int *) mmap(0, 256, PROT_READ|PROT_WRITE, MAP_SHARED, fd,  
> USER_LOGIC_BASEADDR);

Well, this isn't going to detect an error, since the error code
is returned instead of an address.

>
>   if(ptr==MAP_FAILED) {

    if ((int)ptr == -1) {
>     printf("Err: cannot access address!\n");
>     return -1;
>   }
>

> ....  Any other thoughts?

Your mmap is failing because the size is not modulo PAGE_SIZE.


    -- Dan






[-- Attachment #2: Type: text/html, Size: 2606 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-07-28 19:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-28 17:35 using /dev/mem to talk to peripherals on VIIP system scott
2006-07-28 17:51 ` Dan Malek
2006-07-28 19:54   ` scott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox