mmap : please help !

scarayol at assystembrime.com scarayol at assystembrime.com
Thu Apr 14 02:17:21 EST 2005


Hi all,

I need somme help : I wrote driver like /dev/mem to read and write into
physical memory at specific addresses. For that, I use instruction mmap
like that :


    if((mem_mc_fd = open("/dev/map_mc",O_RDWR | O_SYNC)) < 0)
    {
        printf("\nProbleme pour ouvrir /dev/map_mc\n");
        exit(-1);
    }

 // mapping de la zone correspondante
    pmapMC = (DisqueMC *)mmap (0,MC_SIZE, PROT_READ | PROT_WRITE |
PROT_EXEC, MAP_SHARED, mem_mc_fd, MC_BASE_ADDRESS);
    if (pmapMC == MAP_FAILED)
    {
        printf("Erreur de mmap pour MC:%d,%s\n",errno, strerror(errno));
         close(mem_mc_fd);
 }

I use function pread, pwrite to access datas within the driver functions
but, I should prefer to use pmapMC pointer (by the mean of this virtual
address) that points to a structure. I thought that it was the same to
access to the physical memory to use the pointer or to use read, write on
the file (by mem_mc_fd), but it seems to have different results. What is
wrong ? What is the good manner to read or write in the physical memory?

Thanks a lot.

----------------------------------------------------------
Sophie CARAYOL

TECHNOLOGIES & SYSTEMES
50 rue du Président Sadate
F - 29337 QUIMPER CEDEX

Tél: +33 2 98 10 30 06
mailto:scarayol at assystembrime.com
----------------------------------------------------------





More information about the Linuxppc-embedded mailing list