The header files sys/immu.h and sys/sysmacros.h contain constants and macros for working with page units. Some of the most useful are listed below:
NBPP | Number of bytes in a virtual memory page. |
NBPSCTR | Number of bytes (512) in a standard disk "sector." |
IO_NBPP | Number of bytes in an I/O page. |
IO_PNUMSHFT | Number of bits to right-shift an address to get the I/O page number. |
IO_POFFMASK | Mask to extract the I/O-page-offset value from an address. |
btod() | Return number of 512-byte "sectors" in a byte count (rounded up) |
btop(x) | Return number of I/O pages in a byte count (truncated) |
io_pnum(x) | Return the I/O page number from an address x. |
io_poff(x) | Return the I/O page offset from an address x. |
io_numpages( addr, len) | Return the number of I/O pages that span a given address for a length. |
io_ctob(x) | Return number of bytes in x I/O pages (rounded up). |
io_ctobt(x) | Return number of bytes in x I/O pages (truncated). |
The functions summarized in Table 9-11 are also provided as functions.
Using these functions and macros, you can make your driver independent of the size of pages. When examining an existing driver, be alert for any assumption that a virtual memory page has a particular size, or that an I/O page is the same size as a memory page, and convert the code to use portable functions and macros.