title: How to convert from virtual address to physical address and back?
body: <p>I'm given a task to write an application that will talk to a device. However this is not a driver since device is still being developed and the application is intended to exercises its first revision. </p>
  
  <p>We will be talking with a device through /dev/mem. We will have all the privileges to do that. We know that this is not the right way to do it (i.e. need to use a driver) but again this is just a test to make sure that device development is on schedule and it actually works.</p>
  
  <p>The communication protocol has read and write operations specified. The problem is that all the addresses are physical. Here is what is meant by it.</p>
  
  <p>If a host wants to write to a device it needs to give a physical address of the data which needs to be written. If a host needs to read from a device it needs to give a physical address of the buffer where data can be placed by the device.  </p>
  
  <p>Say my interface the following functions:</p>
  
  <pre><code>WriteToDevice(void *ptrToDataToWriteToADevice, unsgined numBytes);
  ReadFromDevice(void *whereToPlaceDataReadFromADevice, unsigned numBytes);
  </code></pre>
  
  <p><code>ptrToDataToWriteToADevice</code> and <code>whereToPlaceDataReadFromADevice</code> are both in application space, i.e. not  physical addresses. How do I tell to my device to find these pointers in physical memory?</p>
  
  <p>Any help is appreciated.</p>