/** The page table */
extern struct page_table page_table;
+/** Maximum number of I/O pages */
+#define MAP_PAGE_COUNT \
+ ( sizeof ( page_table.pte ) / sizeof ( page_table.pte[0] ) )
+
/** I/O page size
*
* We choose to use 1GB "gigapages", since these are supported by all
/* Calculate number of pages required */
count = ( ( offset + len + MAP_PAGE_SIZE - 1 ) / MAP_PAGE_SIZE );
assert ( count != 0 );
- assert ( count < ( sizeof ( page_table.pte ) /
- sizeof ( page_table.pte[0] ) ) );
+ assert ( count <= MAP_PAGE_COUNT );
/* Round up number of pages to a power of two */
stride = ( 1 << fls ( count - 1 ) );
assert ( count <= stride );
/* Allocate pages */
- for ( first = 0 ; first < ( sizeof ( page_table.pte ) /
- sizeof ( page_table.pte[0] ) ) ;
- first += stride ) {
+ for ( first = 0 ; first < MAP_PAGE_COUNT ; first += stride ) {
/* Calculate virtual address */
virt = ( MAP_BASE + ( first * MAP_PAGE_SIZE ) + offset );
/* Calculate first page table entry */
first = ( ( virt - MAP_BASE ) / MAP_PAGE_SIZE );
+ /* Ignore unmappings outside of the I/O range */
+ if ( first >= MAP_PAGE_COUNT )
+ return;
+
/* Clear page table entries */
for ( i = first ; ; i++ ) {
/** The I/O space page table */
extern struct page_table io_pages;
+/** Maximum number of I/O pages */
+#define IO_PAGE_COUNT \
+ ( sizeof ( io_pages.page ) / sizeof ( io_pages.page[0] ) )
+
/** I/O page size
*
* We choose to use 2MB pages for I/O space, to minimise the number of
/* Calculate number of pages required */
count = ( ( offset + len + IO_PAGE_SIZE - 1 ) / IO_PAGE_SIZE );
assert ( count != 0 );
- assert ( count < ( sizeof ( io_pages.page ) /
- sizeof ( io_pages.page[0] ) ) );
+ assert ( count <= IO_PAGE_COUNT );
/* Round up number of pages to a power of two */
stride = ( 1 << fls ( count - 1 ) );
assert ( count <= stride );
/* Allocate pages */
- for ( first = 0 ; first < ( sizeof ( io_pages.page ) /
- sizeof ( io_pages.page[0] ) ) ;
- first += stride ) {
+ for ( first = 0 ; first < IO_PAGE_COUNT ; first += stride ) {
/* Calculate I/O address */
io_addr = ( IO_BASE + ( first * IO_PAGE_SIZE ) + offset );
/* Calculate first page table entry */
first = ( ( io_addr - IO_BASE ) / IO_PAGE_SIZE );
+ /* Ignore unmappings outside of the I/O range */
+ if ( first >= IO_PAGE_COUNT )
+ return;
+
/* Clear page table entries */
for ( i = first ; ; i++ ) {