Kernel - Added fast random (ala /dev/urandom), good random is stubbed
[tpg/acess2.git] / KernelLand / Kernel / arch / x86 / mm_virt.c
index d15c3d7..13562f2 100644 (file)
@@ -414,13 +414,14 @@ void MM_Deallocate(tVAddr VAddr)
  * \fn tPAddr MM_GetPhysAddr(tVAddr Addr)
  * \brief Checks if the passed address is accesable
  */
-tPAddr MM_GetPhysAddr(tVAddr Addr)
+tPAddr MM_GetPhysAddr(const void *Addr)
 {
-       if( !(gaPageDir[Addr >> 22] & 1) )
+       tVAddr  addr = (tVAddr)Addr;
+       if( !(gaPageDir[addr >> 22] & 1) )
                return 0;
-       if( !(gaPageTable[Addr >> 12] & 1) )
+       if( !(gaPageTable[addr >> 12] & 1) )
                return 0;
-       return (gaPageTable[Addr >> 12] & ~0xFFF) | (Addr & 0xFFF);
+       return (gaPageTable[addr >> 12] & ~0xFFF) | (addr & 0xFFF);
 }
 
 /**
@@ -717,7 +718,8 @@ tVAddr MM_NewKStack(void)
        for(base = MM_KERNEL_STACKS; base < MM_KERNEL_STACKS_END; base += MM_KERNEL_STACK_SIZE)
        {
                // Check if space is free
-               if(MM_GetPhysAddr(base) != 0)   continue;
+               if(MM_GetPhysAddr( (void*) base) != 0)
+                       continue;
                // Allocate
                //for(i = MM_KERNEL_STACK_SIZE; i -= 0x1000 ; )
                for(i = 0; i < MM_KERNEL_STACK_SIZE; i += 0x1000 )
@@ -1069,7 +1071,6 @@ tVAddr MM_MapHWPages(tPAddr PAddr, Uint Number)
  */
 tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
 {
-       tPAddr  maxCheck = (1 << MaxBits);
        tPAddr  phys;
        tVAddr  ret;
        
@@ -1079,23 +1080,20 @@ tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
                MaxBits = PHYS_BITS;
        
        // Sanity Check
-       if(MaxBits < 12 || !PhysAddr) {
+       if(MaxBits < 12) {
                LEAVE('i', 0);
                return 0;
        }
        
-       // Bound
-       if(MaxBits >= PHYS_BITS)        maxCheck = -1;
-       
        // Fast Allocate
        if(Pages == 1 && MaxBits >= PHYS_BITS)
        {
                phys = MM_AllocPhys();
+               if( PhysAddr )
+                       *PhysAddr = phys;
                if( !phys ) {
-                       *PhysAddr = 0;
                        LEAVE_RET('i', 0);
                }
-               *PhysAddr = phys;
                ret = MM_MapHWPages(phys, 1);
                if(ret == 0) {
                        MM_DerefPhys(phys);
@@ -1124,7 +1122,8 @@ tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
                return 0;
        }
        
-       *PhysAddr = phys;
+       if( PhysAddr )
+               *PhysAddr = phys;
        LEAVE('x', ret);
        return ret;
 }
@@ -1150,6 +1149,7 @@ void MM_UnmapHWPages(tVAddr VAddr, Uint Number)
        {
                MM_DerefPhys( gaPageTable[ i + j ] & ~0xFFF );
                gaPageTable[ i + j ] = 0;
+               INVLPG( (tVAddr)(i+j) << 12 );
        }
        
        Mutex_Release( &glTempMappings );

UCC git Repository :: git.ucc.asn.au