All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brett McNerney" <mcnernbm@notes.udayton.edu>
To: <linuxppc-embedded@ozlabs.org>
Subject: mmap
Date: Thu, 5 Jan 2006 01:16:29 -0500	[thread overview]
Message-ID: <000c01c611bf$92d5f900$0202a8c0@lilmac> (raw)

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

I have been trying to work with mmap to read and write to a custom hardware
module on a Xilinx virtex 4 board with linux running on the ppc.  But I have
gotten many different errors.  But the main one I am seeing is segmentation
error.  Below is the code I am using.  The device has a 256 address size
specified in the Xilinx tools and the base address I set in the Xilinx tools
was 0x81000000.  Am I doing something wrong in the code?  Any help would be
greatly appreciated as we have decided to try this method instead of using a
driver built into the kernel as this allows us some more flexibility.  Also
the hardware module I am using for testing contains 3 hardware registers
which adds two of the registers and returns the result in the third one.

 

I am open for other options on how I can do this other then mmap.  And am
still not against a driver built into the kernel if someone has a an example
I could see and can explain how to add it in so it builds into the kernel
since I have had no success on that either and have tried a couple different
tutorials I found online with no success.

Thanks for any help anyone can provide.

Brett

 

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <sys/mman.h>

 

int main(void) {

      int fd;

      int *p;

      fd = open("/dev/mem, O_RDWR);

      p = (int *)mmap(0, 256, PROT_READ|PROT_WRITE,

                              MAP_PRIVATE, fd, 0x81000000);

      if (p == MAP_FAILED) {

            printf("Err: cannot access adder!/n");

            return -1;

      }

      printf("input two numbers: ");

      scanf("%d", &p);

      scanf("%d", &p+1);

      printf("%d + %d = %d\n", *p, *(p+1), *(p+2));

      munmap(p,256);

      close(fd);

      return 0;

}

 


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

             reply	other threads:[~2006-01-05  6:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-05  6:16 Brett McNerney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-08-23 13:06 mmap Christophe Hauser
2012-08-23 14:18 ` mmap Mulyadi Santosa
2011-12-02 12:20 mmap Sébastien Paumier
2011-12-02 14:45 ` mmap Eric Dumazet
2006-10-26  0:48 mmap Sudharsan Rangarajan
2006-10-26  1:02 ` mmap Ian McDonald
2006-10-26  1:02 ` mmap Hagen Paul Pfeifer
2006-01-05 10:03 mmap Fillod Stephane
2001-07-02 14:00 mmap mdaljeet
2001-07-03 17:47 ` mmap Jens Axboe
2001-05-15 10:08 mmap mdaljeet
2001-05-15  6:47 mmap mdaljeet
2001-05-15  7:33 ` mmap Gerd Knorr
2001-05-15  9:42 ` mmap Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000c01c611bf$92d5f900$0202a8c0@lilmac' \
    --to=mcnernbm@notes.udayton.edu \
    --cc=linuxppc-embedded@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.