+// Log_KernelPanic("MM", "TODO: Implement MM_UnmapHWPages");
+ while( Number -- )
+ {
+ MM_Unmap(VAddr);
+ VAddr += 0x1000;
+ }
+}
+
+
+/**
+ * \fn tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
+ * \brief Allocates DMA physical memory
+ * \param Pages Number of pages required
+ * \param MaxBits Maximum number of bits the physical address can have
+ * \param PhysAddr Pointer to the location to place the physical address allocated
+ * \return Virtual address allocate
+ */
+tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PhysAddr)
+{
+ tPAddr phys;
+ tVAddr ret;
+
+ // Sanity Check
+ if(MaxBits < 12 || !PhysAddr) return 0;
+
+ // Fast Allocate
+ if(Pages == 1 && MaxBits >= PHYS_BITS)
+ {
+ phys = MM_AllocPhys();
+ *PhysAddr = phys;
+ ret = MM_MapHWPages(phys, 1);
+ if(ret == 0) {
+ MM_DerefPhys(phys);
+ return 0;
+ }
+ return ret;
+ }
+
+ // Slow Allocate
+ phys = MM_AllocPhysRange(Pages, MaxBits);
+ // - Was it allocated?
+ if(phys == 0) return 0;
+
+ // Allocated successfully, now map
+ ret = MM_MapHWPages(phys, Pages);
+ if( ret == 0 ) {
+ // If it didn't map, free then return 0
+ for(;Pages--;phys+=0x1000)
+ MM_DerefPhys(phys);
+ return 0;
+ }
+
+ *PhysAddr = phys;
+ return ret;