svn commit: r215834 - stable/8/sys/compat/ndis

Bernhard Schmidt bschmidt at FreeBSD.org
Thu Nov 25 18:50:59 UTC 2010


Author: bschmidt
Date: Thu Nov 25 18:50:59 2010
New Revision: 215834
URL: http://svn.freebsd.org/changeset/base/215834

Log:
  MFC r215135,215419,215420:
  - According to specs for MmAllocateContiguousMemorySpecifyCache() physically
    contiguous memory with requested restrictions must be allocated.
  - Use kmem_alloc_contig() to honour the cache_type variable.
  - Fix a panic on i386 for drivers using MmAllocateContiguousMemory()
    and MmAllocateContiguousMemorySpecifyCache().
  
  Submitted by:	Paul B Mahol <onemda at gmail.com>

Modified:
  stable/8/sys/compat/ndis/ntoskrnl_var.h
  stable/8/sys/compat/ndis/subr_ntoskrnl.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/compat/ndis/ntoskrnl_var.h
==============================================================================
--- stable/8/sys/compat/ndis/ntoskrnl_var.h	Thu Nov 25 18:43:18 2010	(r215833)
+++ stable/8/sys/compat/ndis/ntoskrnl_var.h	Thu Nov 25 18:50:59 2010	(r215834)
@@ -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: stable/8/sys/compat/ndis/subr_ntoskrnl.c
==============================================================================
--- stable/8/sys/compat/ndis/subr_ntoskrnl.c	Thu Nov 25 18:43:18 2010	(r215833)
+++ stable/8/sys/compat/ndis/subr_ntoskrnl.c	Thu Nov 25 18:50:59 2010	(r215834)
@@ -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,14 +2426,34 @@ MmAllocateContiguousMemorySpecifyCache(s
 	uint64_t		lowest;
 	uint64_t		highest;
 	uint64_t		boundary;
-	uint32_t		cachetype;
+	enum nt_caching_type	cachetype;
 {
-	void *addr;
-	size_t pagelength = roundup(size, PAGE_SIZE);
+	vm_memattr_t		memattr;
+	void			*ret;
 
-	addr = ExAllocatePoolWithTag(NonPagedPool, pagelength, 0);
+	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;
+	}
 
-	return (addr);
+	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
@@ -2445,9 +2467,9 @@ static void
 MmFreeContiguousMemorySpecifyCache(base, size, cachetype)
 	void			*base;
 	uint32_t		size;
-	uint32_t		cachetype;
+	enum nt_caching_type	cachetype;
 {
-	ExFreePool(base);
+	contigfree(base, size, M_DEVBUF);
 }
 
 static uint32_t
@@ -4215,8 +4237,8 @@ image_patch_table ntoskrnl_functbl[] = {
 	IMPORT_FFUNC(ExInterlockedAddLargeStatistic, 2),
 	IMPORT_SFUNC(IoAllocateMdl, 5),
 	IMPORT_SFUNC(IoFreeMdl, 1),
-	IMPORT_SFUNC(MmAllocateContiguousMemory, 2),
-	IMPORT_SFUNC(MmAllocateContiguousMemorySpecifyCache, 5),
+	IMPORT_SFUNC(MmAllocateContiguousMemory, 2 + 1),
+	IMPORT_SFUNC(MmAllocateContiguousMemorySpecifyCache, 5 + 3),
 	IMPORT_SFUNC(MmFreeContiguousMemory, 1),
 	IMPORT_SFUNC(MmFreeContiguousMemorySpecifyCache, 3),
 	IMPORT_SFUNC_MAP(MmGetPhysicalAddress, pmap_kextract, 1),


More information about the svn-src-all mailing list