title: Accessing hardware registers in Linux userspace
body: <p>I wpuld like to write to hardware registers on OMAP3530 in Linux userspace. Please, find below code. Mmap returns error:</p>
  
  <p>Memory map failed. error -1</p>
  
  <p>mmap: Permission denied</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  
  #define BASE_ADDRESS 0x48050000
  
  int main()
  {
          int mem;
          unsigned int *value;
          void *ptr;
  
          /* Open /dev/mem */
          if ((mem = open ("/dev/mem", O_RDONLY | O_SYNC)) == -1)
                  fprintf(stderr, "Cannot open /dev/mem\n"), exit(1);
  
          ptr = mmap (0, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, mem, BASE_ADDRESS);
  
          if(ptr == (void *) -1) {
                  printf("Memory map failed. error %i\n", ptr);
                  perror("mmap");
                  }
  
          value = (unsigned int*)(ptr + 0x4BC+((1-1)*0x90)+(0*0x04));
          *value = 479*799*3-4;
          printf("value = %i", value);
  
          value = (unsigned int*)(ptr + 0x4C4+((-1)*0x90));
          *value = 1;
          printf("value = %i", value);
  
          value = (unsigned int*)(ptr + 0x4C8+((-1)*0x90));
          *value = 1;
          printf("value = %i", value);
          return 0;
  }
  </code></pre>