Author: bschmidt
Date: Wed Nov 17 09:28:17 2010
New Revision: 215419
URL: http://svn.freebsd.org/changeset/base/215419

Log:
  Use kmem_alloc_contig() to honour the cache_type variable.
  
  Pointed out by:       alc

Modified:
  head/sys/compat/ndis/ntoskrnl_var.h
  head/sys/compat/ndis/subr_ntoskrnl.c

Modified: head/sys/compat/ndis/ntoskrnl_var.h
==============================================================================
--- head/sys/compat/ndis/ntoskrnl_var.h Wed Nov 17 09:25:08 2010        
(r215418)
+++ head/sys/compat/ndis/ntoskrnl_var.h Wed Nov 17 09:28:17 2010        
(r215419)
@@ -162,6 +162,16 @@ typedef struct mdl mdl, ndis_buffer;
 #define        WDM_MINOR_WINXP         0x20
 #define        WDM_MINOR_WIN2003       0x30
 
+enum nt_caching_type {
+       MmNonCached                     = 0,
+       MmCached                        = 1,
+       MmWriteCombined                 = 2,
+       MmHardwareCoherentCached        = 3,
+       MmNonCachedUnordered            = 4,
+       MmUSWCCached                    = 5,
+       MmMaximumCacheType              = 6
+};
+
 /*-
  * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
  * According to the Windows DDK header files, KSPIN_LOCK is defined like this:

Modified: head/sys/compat/ndis/subr_ntoskrnl.c
==============================================================================
--- head/sys/compat/ndis/subr_ntoskrnl.c        Wed Nov 17 09:25:08 2010        
(r215418)
+++ head/sys/compat/ndis/subr_ntoskrnl.c        Wed Nov 17 09:28:17 2010        
(r215419)
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
 #include <vm/uma.h>
 #include <vm/vm_kern.h>
 #include <vm/vm_map.h>
+#include <vm/vm_extern.h>
 
 #include <compat/ndis/pe_var.h>
 #include <compat/ndis/cfg_var.h>
@@ -197,9 +198,10 @@ static uint32_t InterlockedDecrement(vol
 static void ExInterlockedAddLargeStatistic(uint64_t *, uint32_t);
 static void *MmAllocateContiguousMemory(uint32_t, uint64_t);
 static void *MmAllocateContiguousMemorySpecifyCache(uint32_t,
-       uint64_t, uint64_t, uint64_t, uint32_t);
+       uint64_t, uint64_t, uint64_t, enum nt_caching_type);
 static void MmFreeContiguousMemory(void *);
-static void MmFreeContiguousMemorySpecifyCache(void *, uint32_t, uint32_t);
+static void MmFreeContiguousMemorySpecifyCache(void *, uint32_t,
+       enum nt_caching_type);
 static uint32_t MmSizeOfMdl(void *, size_t);
 static void *MmMapLockedPages(mdl *, uint8_t);
 static void *MmMapLockedPagesSpecifyCache(mdl *,
@@ -2424,11 +2426,34 @@ MmAllocateContiguousMemorySpecifyCache(s
        uint64_t                lowest;
        uint64_t                highest;
        uint64_t                boundary;
-       uint32_t                cachetype;
+       enum nt_caching_type    cachetype;
 {
+       vm_memattr_t            memattr;
+       void                    *ret;
 
-       return (contigmalloc(size, M_DEVBUF, M_ZERO|M_NOWAIT, lowest,
-           highest, PAGE_SIZE, boundary));
+       switch (cachetype) {
+       case MmNonCached:
+               memattr = VM_MEMATTR_UNCACHEABLE;
+               break;
+       case MmWriteCombined:
+               memattr = VM_MEMATTR_WRITE_COMBINING;
+               break;
+       case MmNonCachedUnordered:
+               memattr = VM_MEMATTR_UNCACHEABLE;
+               break;
+       case MmCached:
+       case MmHardwareCoherentCached:
+       case MmUSWCCached:
+       default:
+               memattr = VM_MEMATTR_DEFAULT;
+               break;
+       }
+
+       ret = (void *)kmem_alloc_contig(kernel_map, size, M_ZERO | M_NOWAIT,
+           lowest, highest, PAGE_SIZE, boundary, memattr);
+       if (ret != NULL)
+               malloc_type_allocated(M_DEVBUF, round_page(size));
+       return (ret);
 }
 
 static void
@@ -2442,7 +2467,7 @@ static void
 MmFreeContiguousMemorySpecifyCache(base, size, cachetype)
        void                    *base;
        uint32_t                size;
-       uint32_t                cachetype;
+       enum nt_caching_type    cachetype;
 {
        contigfree(base, size, M_DEVBUF);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to