+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1155389/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1155389/nv-linux.h 2004-11-04 11:47:05.000000000 +0100
-@@ -729,12 +729,21 @@
- return order;
- }
-
-+/* mark memory UC-, rather than UC (don't use _PAGE_PWT) */
-+static inline pgprot_t pgprot_noncached_weak(pgprot_t old_prot)
-+ {
-+ pgprot_t new_prot = old_prot;
-+ if (boot_cpu_data.x86 > 3)
-+ new_prot = __pgprot(pgprot_val(old_prot) | _PAGE_PCD);
-+ return new_prot;
-+ }
-+
- #if !defined (pgprot_noncached)
- static inline pgprot_t pgprot_noncached(pgprot_t old_prot)
- {
- pgprot_t new_prot = old_prot;
- if (boot_cpu_data.x86 > 3)
-- new_prot = __pgprot(pgprot_val(old_prot) | _PAGE_PCD);
-+ new_prot = __pgprot(pgprot_val(old_prot) | _PAGE_PCD | _PAGE_PWT);
- return new_prot;
- }
- #endif
-diff -ru usr/src/nv/nv.c usr/src/nv.1155389/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1155389/nv.c 2004-11-04 11:47:05.000000000 +0100
-@@ -1551,7 +1551,7 @@
- /* NV fb space */
- else if (IS_FB_OFFSET(nv, NV_VMA_OFFSET(vma), vma->vm_end - vma->vm_start))
- {
-- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
-+ vma->vm_page_prot = pgprot_noncached_weak(vma->vm_page_prot);
- if (NV_REMAP_PAGE_RANGE(vma->vm_start,
- NV_VMA_OFFSET(vma),
- vma->vm_end - vma->vm_start,
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1161283/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1161283/nv-linux.h 2004-11-16 22:56:41.000000000 +0100
-@@ -429,6 +429,30 @@
- free_pages(ptr, order); \
- }
-
-+#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type) \
-+ { \
-+ kmem_cache = kmem_cache_create(name, sizeof(type), \
-+ 0, 0, NULL, NULL); \
-+ }
-+
-+#define NV_KMEM_CACHE_DESTROY(kmem_cache) \
-+ { \
-+ kmem_cache_destroy(kmem_cache); \
-+ kmem_cache = NULL; \
-+ }
-+
-+#define NV_KMEM_CACHE_ALLOC(ptr, kmem_cache, type) \
-+ { \
-+ (ptr) = kmem_cache_alloc(kmem_cache, GFP_KERNEL); \
-+ KM_ALLOC_RECORD(ptr, sizeof(type), "km_cache_alloc"); \
-+ }
-+
-+#define NV_KMEM_CACHE_FREE(ptr, type, kmem_cache) \
-+ { \
-+ KM_FREE_RECORD(ptr, sizeof(type), "km_cache_free"); \
-+ kmem_cache_free(kmem_cache, ptr); \
-+ }
-+
- #endif /* !defined NVWATCH */
-
-
-@@ -776,6 +800,9 @@
- unsigned long phys_addr;
- unsigned long virt_addr;
- dma_addr_t dma_addr;
-+#ifdef NV_SG_MAP_BUFFERS
-+ struct scatterlist sg_list;
-+#endif
- #ifdef CONFIG_SWIOTLB
- unsigned long orig_phys_addr;
- unsigned long orig_virt_addr;
-@@ -789,15 +816,11 @@
- unsigned int num_pages;
- unsigned int order;
- unsigned int size;
-- nv_pte_t *page_table; /* list of physical pages allocated */
-+ nv_pte_t **page_table; /* list of physical pages allocated */
- void *key_mapping; /* mapping used as a key for finding this nv_alloc_t */
- /* may be the same as page_table */
- unsigned int class;
- void *priv_data;
--#if defined(NV_SG_MAP_BUFFERS)
-- struct pci_dev *dev;
-- struct scatterlist *sg_list; /* list of physical pages allocated */
--#endif
- } nv_alloc_t;
-
-
-diff -ru usr/src/nv/nv-vm.c usr/src/nv.1161283/nv-vm.c
---- usr/src/nv/nv-vm.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1161283/nv-vm.c 2004-11-16 22:56:41.000000000 +0100
-@@ -138,13 +138,18 @@
- */
-
- int nv_vm_malloc_pages(
-- nv_alloc_t *at
-+ nv_state_t *nv,
-+ nv_alloc_t *at
- )
- {
- /* point page_ptr at the start of the actual page list */
-- nv_pte_t *page_ptr = at->page_table;
-+ nv_pte_t *page_ptr = *at->page_table;
- int i;
- unsigned long virt_addr = 0, phys_addr;
-+#if defined(NV_SG_MAP_BUFFERS)
-+ nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-+ struct pci_dev *dev = nvl->dev;
-+#endif
-
- nv_printf(NV_DBG_MEMINFO, "NVRM: VM: nv_vm_malloc_pages: %d pages\n",
- at->num_pages);
-@@ -175,7 +180,7 @@
- // for amd 64-bit platforms, remap pages to make them 32-bit addressable
- // in this case, we need the final remapping to be contiguous, so we
- // have to do the whole mapping at once, instead of page by page
-- if (nv_sg_map_buffer(at->dev, &at->sg_list[0],
-+ if (nv_sg_map_buffer(dev, &at->page_table[0]->sg_list,
- (void *) virt_addr, at->num_pages))
- {
- nv_printf(NV_DBG_ERRORS,
-@@ -224,7 +229,7 @@
- /* lock the page for dma purposes */
- SetPageReserved(NV_GET_PAGE_STRUCT(phys_addr));
-
-- page_ptr = &at->page_table[i];
-+ page_ptr = at->page_table[i];
- page_ptr->phys_addr = phys_addr;
- page_ptr->virt_addr = virt_addr;
- page_ptr->dma_addr = page_ptr->phys_addr;
-@@ -235,7 +240,7 @@
- #if defined(NV_SG_MAP_BUFFERS)
- if (!NV_ALLOC_MAPPING_CONTIG(at->flags))
- {
-- if (nv_sg_map_buffer(at->dev, &at->sg_list[i],
-+ if (nv_sg_map_buffer(dev, &at->page_table[i]->sg_list,
- __va(page_ptr->phys_addr), 1))
- {
- nv_printf(NV_DBG_ERRORS,
-@@ -243,7 +248,7 @@
- goto failed;
- }
- }
-- nv_sg_load(&at->sg_list[i], page_ptr);
-+ nv_sg_load(&at->page_table[i]->sg_list, page_ptr);
- #endif
- virt_addr += PAGE_SIZE;
- }
-@@ -258,7 +263,7 @@
-
- for (; i >= 0; i--)
- {
-- page_ptr = &at->page_table[i];
-+ page_ptr = at->page_table[i];
-
- // if we failed when allocating this page, skip over it
- // but if we failed pci_map_sg, make sure to free this page
-@@ -267,7 +272,7 @@
- NV_UNLOCK_PAGE(page_ptr);
- #if defined(NV_SG_MAP_BUFFERS)
- if (!NV_ALLOC_MAPPING_CONTIG(at->flags))
-- nv_sg_unmap_buffer(at->dev, &at->sg_list[i], page_ptr);
-+ nv_sg_unmap_buffer(dev, &at->page_table[i]->sg_list, page_ptr);
- #endif
- if (!NV_ALLOC_MAPPING_CACHED(at->flags))
- NV_SET_PAGE_ATTRIB_CACHED(page_ptr);
-@@ -279,15 +284,15 @@
-
- if (NV_ALLOC_MAPPING_CONTIG(at->flags))
- {
-- page_ptr = at->page_table;
-+ page_ptr = *at->page_table;
- #if defined(NV_SG_MAP_BUFFERS)
-- nv_sg_unmap_buffer(at->dev, &at->sg_list[0], page_ptr);
-+ nv_sg_unmap_buffer(dev, &at->page_table[0]->sg_list, page_ptr);
- #endif
- NV_FREE_PAGES(page_ptr->virt_addr, at->order);
- }
- else if (NV_ALLOC_MAPPING_VMALLOC(at->flags))
- {
-- page_ptr = at->page_table;
-+ page_ptr = *at->page_table;
- NV_VFREE((void *) page_ptr->virt_addr, at->size);
- }
-
-@@ -296,7 +301,7 @@
-
- // unlock the pages we've locked down for dma purposes
- void nv_vm_unlock_pages(
-- nv_alloc_t *at
-+ nv_alloc_t *at
- )
- {
- nv_pte_t *page_ptr;
-@@ -315,17 +320,22 @@
-
- for (i = 0; i < at->num_pages; i++)
- {
-- page_ptr = &at->page_table[i];
-+ page_ptr = at->page_table[i];
- NV_UNLOCK_PAGE(page_ptr);
- }
- }
-
- void nv_vm_free_pages(
-- nv_alloc_t *at
-+ nv_state_t *nv,
-+ nv_alloc_t *at
- )
- {
- nv_pte_t *page_ptr;
- int i;
-+#if defined(NV_SG_MAP_BUFFERS)
-+ nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-+ struct pci_dev *dev = nvl->dev;
-+#endif
-
- nv_printf(NV_DBG_MEMINFO, "NVRM: VM: nv_vm_free_pages: %d pages\n",
- at->num_pages);
-@@ -339,10 +349,10 @@
-
- for (i = 0; i < at->num_pages; i++)
- {
-- page_ptr = &at->page_table[i];
-+ page_ptr = at->page_table[i];
- #if defined(NV_SG_MAP_BUFFERS)
- if (!NV_ALLOC_MAPPING_CONTIG(at->flags))
-- nv_sg_unmap_buffer(at->dev, &at->sg_list[i], page_ptr);
-+ nv_sg_unmap_buffer(dev, &at->page_table[i]->sg_list, page_ptr);
- #endif
- if (!NV_ALLOC_MAPPING_CACHED(at->flags))
- NV_SET_PAGE_ATTRIB_CACHED(page_ptr);
-@@ -353,15 +363,15 @@
-
- if (NV_ALLOC_MAPPING_CONTIG(at->flags))
- {
-- page_ptr = at->page_table;
-+ page_ptr = *at->page_table;
- #if defined(NV_SG_MAP_BUFFERS)
-- nv_sg_unmap_buffer(at->dev, &at->sg_list[0], page_ptr);
-+ nv_sg_unmap_buffer(dev, &at->page_table[0]->sg_list, page_ptr);
- #endif
- NV_FREE_PAGES(page_ptr->virt_addr, at->order);
- }
- else if (NV_ALLOC_MAPPING_VMALLOC(at->flags))
- {
-- page_ptr = at->page_table;
-+ page_ptr = *at->page_table;
- NV_VFREE((void *) page_ptr->virt_addr, at->size);
- }
- }
-diff -ru usr/src/nv/nv-vm.h usr/src/nv.1161283/nv-vm.h
---- usr/src/nv/nv-vm.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1161283/nv-vm.h 2004-11-16 22:56:41.000000000 +0100
-@@ -11,9 +11,9 @@
- #ifndef _NV_VM_H_
- #define _NV_VM_H_
-
--int nv_vm_malloc_pages(nv_alloc_t *);
-+int nv_vm_malloc_pages(nv_state_t *, nv_alloc_t *);
- void nv_vm_unlock_pages(nv_alloc_t *);
--void nv_vm_free_pages(nv_alloc_t *);
-+void nv_vm_free_pages(nv_state_t *, nv_alloc_t *);
-
- #if defined(NV_DBG_MEM)
- void nv_vm_list_page_count(nv_pte_t *, unsigned long);
-@@ -21,11 +21,12 @@
- #define nv_vm_list_page_count(page_ptr, num_pages)
- #endif
-
--#define nv_vm_unlock_and_free_pages(at_count, at) \
-- if (at->page_table) { \
-- if (at_count == 0) \
-- nv_vm_unlock_pages(at); \
-- nv_vm_free_pages(at); \
-+#define NV_VM_UNLOCK_AND_FREE_PAGES(nv, at_count, at) \
-+ if (at->page_table) \
-+ { \
-+ if (at_count == 0) \
-+ nv_vm_unlock_pages(at); \
-+ nv_vm_free_pages(nv, at); \
- }
-
- #endif
-diff -ru usr/src/nv/nv.c usr/src/nv.1161283/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1161283/nv.c 2004-11-16 22:57:24.000000000 +0100
-@@ -63,6 +63,8 @@
- int nv_swiotlb = 0;
- #endif
-
-+static kmem_cache_t *nv_pte_t_cache = NULL;
-+
- // allow an easy way to convert all debug printfs related to events
- // back and forth between 'info' and 'errors'
- #if defined(NV_DBG_EVENTS)
-@@ -266,42 +268,41 @@
- )
- {
- nv_alloc_t *at;
-- int pt_size;
-+ unsigned int pt_size, i;
-
- NV_KMALLOC(at, sizeof(nv_alloc_t));
- if (at == NULL)
- {
-- nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate alloc_t\n");
-+ nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate alloc info\n");
- return NULL;
- }
-
- memset(at, 0, sizeof(nv_alloc_t));
-
-- pt_size = num_pages * sizeof(nv_pte_t);
-- NV_KMALLOC(at->page_table, pt_size);
-- if (at->page_table == NULL)
-+ pt_size = num_pages * sizeof(nv_pte_t *);
-+ if (os_alloc_mem((void **)&at->page_table, pt_size) != RM_OK)
- {
- nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate page table\n");
- NV_KFREE(at, sizeof(nv_alloc_t));
- return NULL;
- }
-+
- memset(at->page_table, 0, pt_size);
- at->num_pages = num_pages;
- NV_ATOMIC_SET(at->usage_count, 0);
-
--#if defined(NV_SG_MAP_BUFFERS)
-- at->dev = dev;
-- pt_size = num_pages * sizeof(struct scatterlist);
-- NV_KMALLOC(at->sg_list, pt_size);
-- if (at->sg_list == NULL)
-+ for (i = 0; i < at->num_pages; i++)
- {
-- nv_printf(NV_DBG_ERRORS, "NVRM: failed to allocate scatter gather list\n");
-- NV_KFREE(at->page_table, pt_size);
-- NV_KFREE(at, sizeof(nv_alloc_t));
-- return NULL;
-+ NV_KMEM_CACHE_ALLOC(at->page_table[i], nv_pte_t_cache, nv_pte_t);
-+ if (at->page_table[i] == NULL)
-+ {
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: failed to allocate page table entry\n");
-+ nvos_free_alloc(at);
-+ return NULL;
-+ }
-+ memset(at->page_table[i], 0, sizeof(nv_pte_t));
- }
-- memset(at->sg_list, 0, pt_size);
--#endif
-
- return at;
- }
-@@ -311,6 +312,8 @@
- nv_alloc_t *at
- )
- {
-+ unsigned int pt_size, i;
-+
- if (at == NULL)
- return -1;
-
-@@ -320,13 +323,16 @@
- // we keep the page_table around after freeing the pages
- // for bookkeeping reasons. Free the page_table and assume
- // the underlying pages are already unlocked and freed.
-- if (at->page_table)
-- NV_KFREE(at->page_table, at->num_pages * sizeof(nv_pte_t));
--
--#if defined(NV_SG_MAP_BUFFERS)
-- if (at->sg_list)
-- NV_KFREE(at->sg_list, at->num_pages * sizeof(struct scatterlist));
--#endif
-+ if (at->page_table != NULL)
-+ {
-+ for (i = 0; i < at->num_pages; i++)
-+ {
-+ if (at->page_table[i] != NULL)
-+ NV_KMEM_CACHE_FREE(at->page_table[i], nv_pte_t, nv_pte_t_cache);
-+ }
-+ pt_size = at->num_pages * sizeof(nv_pte_t *);
-+ os_free_mem(at->page_table);
-+ }
-
- NV_KFREE(at, sizeof(nv_alloc_t));
-
-@@ -594,7 +600,7 @@
- int i;
- for (i = 0; i < at->num_pages; i++)
- {
-- unsigned long offset = at->page_table[i].phys_addr;
-+ unsigned long offset = at->page_table[i]->phys_addr;
- if ((address >= offset) &&
- (address < (offset + PAGE_SIZE)))
- return at;
-@@ -931,6 +937,13 @@
- }
- #endif
-
-+ NV_KMEM_CACHE_CREATE(nv_pte_t_cache, "nv_pte_t", nv_pte_t);
-+ if (nv_pte_t_cache == NULL)
-+ {
-+ nv_printf(NV_DBG_ERRORS, "NVRM: pte cache allocation failed\n");
-+ goto failed;
-+ }
-+
- // Init the resource manager
- if (!rm_init_rm())
- {
-@@ -972,6 +985,14 @@
- return 0;
-
- failed:
-+ if (nv_pte_t_cache != NULL)
-+ NV_KMEM_CACHE_DESTROY(nv_pte_t_cache);
-+
-+#if defined(NV_PM_SUPPORT_APM)
-+ for (i = 0; i < num_nv_devices; i++)
-+ if (apm_nv_dev[i] != NULL) pm_unregister(apm_nv_dev[i]);
-+#endif
-+
- #ifdef CONFIG_DEVFS_FS
- NV_DEVFS_REMOVE_CONTROL();
- for (i = 0; i < num_nv_devices; i++)
-@@ -1101,6 +1122,8 @@
- nv_printf(NV_DBG_ERRORS, "NVRM: final mem usage: vm 0x%x km 0x%x fp 0x%x\n",
- vm_usage, km_usage, fp_usage);
- #endif
-+
-+ NV_KMEM_CACHE_DESTROY(nv_pte_t_cache);
- }
-
- module_init(nvidia_init_module);
-@@ -1249,15 +1272,15 @@
- index = (address - vma->vm_start)>>PAGE_SHIFT;
-
- // save that index into our page list (make sure it doesn't already exist)
-- if (at->page_table[index].phys_addr)
-+ if (at->page_table[index]->phys_addr)
- {
- nv_printf(NV_DBG_ERRORS, "NVRM: page slot already filled in nopage handler!\n");
- os_dbg_breakpoint();
- }
-
-- at->page_table[index].phys_addr = (page_to_pfn(page_ptr) << PAGE_SHIFT);
-- at->page_table[index].dma_addr = (page_to_pfn(page_ptr) << PAGE_SHIFT);
-- at->page_table[index].virt_addr = (unsigned long) __va(page_to_pfn(page_ptr) << PAGE_SHIFT);
-+ at->page_table[index]->phys_addr = (page_to_pfn(page_ptr) << PAGE_SHIFT);
-+ at->page_table[index]->dma_addr = (page_to_pfn(page_ptr) << PAGE_SHIFT);
-+ at->page_table[index]->virt_addr = (unsigned long) __va(page_to_pfn(page_ptr) << PAGE_SHIFT);
-
- return page_ptr;
- #endif
-@@ -1670,7 +1693,7 @@
- start = vma->vm_start;
- while (pages--)
- {
-- page = (unsigned long) at->page_table[i++].phys_addr;
-+ page = (unsigned long) at->page_table[i++]->phys_addr;
- if (NV_REMAP_PAGE_RANGE(start, page, PAGE_SIZE, vma->vm_page_prot))
- return -EAGAIN;
- start += PAGE_SIZE;
-@@ -2368,8 +2391,8 @@
-
- for (i = 0; i < at->num_pages; i++)
- {
-- if (address == at->page_table[i].phys_addr)
-- return (void *)(at->page_table[i].virt_addr + offset);
-+ if (address == at->page_table[i]->phys_addr)
-+ return (void *)(at->page_table[i]->virt_addr + offset);
- }
- }
-
-@@ -2400,8 +2423,8 @@
-
- for (i = 0; i < at->num_pages; i++)
- {
-- if (address == at->page_table[i].phys_addr)
-- return (unsigned long)at->page_table[i].dma_addr + offset;
-+ if (address == at->page_table[i]->phys_addr)
-+ return (unsigned long)at->page_table[i]->dma_addr + offset;
- }
- }
-
-@@ -2427,9 +2450,9 @@
- unsigned long address = dma_address & PAGE_MASK;
- for (i = 0; i < at->num_pages; i++)
- {
-- if (address == at->page_table[i].dma_addr)
-+ if (address == at->page_table[i]->dma_addr)
- {
-- return at->page_table[i].phys_addr + offset;
-+ return at->page_table[i]->phys_addr + offset;
- }
- }
- }
-@@ -2466,7 +2489,7 @@
- int i;
- for (i = 0; i < at->num_pages; i++)
- {
-- if (address == (unsigned long) at->page_table[i].dma_addr)
-+ if (address == (unsigned long) at->page_table[i]->dma_addr)
- {
- return (void *)((unsigned long) at->key_mapping +
- (i * PAGE_SIZE));
-@@ -2630,7 +2653,7 @@
- nvl_add_alloc(nvl, at);
- } else {
- /* use nvidia's nvagp support */
-- if (nv_vm_malloc_pages(at))
-+ if (nv_vm_malloc_pages(nv, at))
- goto failed;
-
- at->class = class;
-@@ -2654,7 +2677,7 @@
- if (rm_status)
- {
- nvl_remove_alloc(nvl, at);
-- nv_vm_unlock_and_free_pages(NV_ATOMIC_READ(at->usage_count), at);
-+ NV_VM_UNLOCK_AND_FREE_PAGES(nv, NV_ATOMIC_READ(at->usage_count), at);
- goto failed;
- }
- at->priv_data = *priv_data;
-@@ -2666,12 +2689,12 @@
- else
- {
-
-- if (nv_vm_malloc_pages(at))
-+ if (nv_vm_malloc_pages(nv, at))
- goto failed;
-
- if (kernel)
- {
-- *pAddress = (void *) at->page_table[0].virt_addr;
-+ *pAddress = (void *) at->page_table[0]->virt_addr;
- }
- else
- {
-@@ -2679,7 +2702,7 @@
- * so use the first page, which is page-aligned. this way, our
- * allocated page table does not need to be page-aligned
- */
-- *pAddress = (void *) at->page_table[0].phys_addr;
-+ *pAddress = (void *) at->page_table[0]->phys_addr;
- }
-
- nvl_add_alloc(nvl, at);
-@@ -2743,7 +2766,7 @@
- rmStatus = rm_free_agp_pages(nv, pAddress, priv_data);
- if (rmStatus == RM_OK)
- {
-- nv_vm_unlock_and_free_pages(NV_ATOMIC_READ(at->usage_count), at);
-+ NV_VM_UNLOCK_AND_FREE_PAGES(nv, NV_ATOMIC_READ(at->usage_count), at);
- }
- }
- } else {
-@@ -2759,7 +2782,7 @@
-
- NV_ATOMIC_DEC(at->usage_count);
-
-- nv_vm_unlock_and_free_pages(NV_ATOMIC_READ(at->usage_count), at);
-+ NV_VM_UNLOCK_AND_FREE_PAGES(nv, NV_ATOMIC_READ(at->usage_count), at);
- }
-
- if (NV_ATOMIC_READ(at->usage_count) == 0)
-@@ -3065,7 +3088,7 @@
- }
-
- /* get the physical address of this page */
-- *paddr = (U032) ((NV_UINTPTR_T)at->page_table[index].dma_addr);
-+ *paddr = (U032) ((NV_UINTPTR_T)at->page_table[index]->dma_addr);
-
- return RM_OK;
- }
+++ /dev/null
-diff -ru usr/src/nv/nv.c usr/src/nv.1165235/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1165235/nv.c 2004-11-25 16:45:04.000000000 +0100
-@@ -1604,9 +1604,8 @@
- }
- nv_vm_list_page_count(at->page_table, at->num_pages);
-
-- /* prevent the swapper from swapping it out */
-- /* mark the memory i/o so the buffers aren't dumped on core dumps */
-- vma->vm_flags |= (VM_LOCKED | VM_IO);
-+ // mark it as IO so that we don't dump it on core dump
-+ vma->vm_flags |= VM_IO;
- }
-
- /* Magic allocator */
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1171869/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1171869/nv-linux.h 2004-12-03 11:34:45.000000000 +0100
-@@ -480,12 +480,22 @@
- #define NV_PCI_RESOURCE_SIZE(dev, bar) ((dev)->resource[(bar) - 1].end - (dev)->resource[(bar) - 1].start + 1)
-
- #define NV_PCI_BUS_NUMBER(dev) (dev)->bus->number
--#define NV_PCI_SLOT_NUMBER(dev) PCI_SLOT((dev)->devfn)
-+#define NV_PCI_DEVFN(dev) (dev)->devfn
-+#define NV_PCI_SLOT_NUMBER(dev) PCI_SLOT(NV_PCI_DEVFN(dev))
-
- #ifdef NV_PCI_GET_CLASS_PRESENT
- #define NV_PCI_DEV_PUT(dev) pci_dev_put(dev)
- #define NV_PCI_GET_DEVICE(vendor,device,from) pci_get_device(vendor,device,from)
--#define NV_PCI_GET_SLOT(bus,devfn) pci_get_slot(pci_find_bus(0,bus),devfn)
-+#define NV_PCI_GET_SLOT(bus,devfn) \
-+ ({ \
-+ struct pci_dev *__dev = NULL; \
-+ while ((__dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, __dev))) \
-+ { \
-+ if (NV_PCI_BUS_NUMBER(__dev) == bus \
-+ && NV_PCI_DEVFN(__dev) == devfn) break; \
-+ } \
-+ __dev; \
-+ })
- #define NV_PCI_GET_CLASS(class,from) pci_get_class(class,from)
- #else
- #define NV_PCI_DEV_PUT(dev)
-diff -ru usr/src/nv/os-interface.c usr/src/nv.1171869/os-interface.c
---- usr/src/nv/os-interface.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1171869/os-interface.c 2004-12-03 11:34:51.000000000 +0100
-@@ -866,7 +866,8 @@
- )
- {
- struct pci_dev *dev;
-- dev = NV_PCI_GET_SLOT(bus, PCI_DEVFN(slot, function));
-+ unsigned int devfn = PCI_DEVFN(slot, function);
-+ dev = NV_PCI_GET_SLOT(bus, devfn);
- if (dev) {
- if (vendor) *vendor = dev->vendor;
- if (device) *device = dev->device;
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1175225/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1175225/nv-linux.h 2004-12-21 21:03:33.000000000 +0100
-@@ -533,6 +533,7 @@
- */
- #if defined(CONFIG_SWIOTLB)
- #define NV_SWIOTLB 1
-+#define NV_SWIOTLB_MAX_RETRIES 16
- extern int nv_swiotlb;
- #endif
-
-@@ -950,10 +951,48 @@
- sg_ptr->offset = (unsigned long)base & ~PAGE_MASK;
- sg_ptr->length = num_pages * PAGE_SIZE;
-
-+#if defined(NV_SWIOTLB)
-+ i = NV_SWIOTLB_MAX_RETRIES;
-+ do {
-+ if (pci_map_sg(dev, sg_ptr, 1, PCI_DMA_BIDIRECTIONAL) == 0)
-+ return 1;
-+
-+ if (sg_ptr->dma_address & ~PAGE_MASK)
-+ {
-+ struct scatterlist sg_tmp;
-+ pci_unmap_sg(dev, sg_ptr, num_pages, PCI_DMA_BIDIRECTIONAL);
-+
-+ memset(&sg_tmp, 0, sizeof(struct scatterlist));
-+ sg_tmp.page = sg_ptr->page;
-+ sg_tmp.offset = sg_ptr->offset;
-+ sg_tmp.length = 2048;
-+
-+ if (pci_map_sg(dev, &sg_tmp, 1, PCI_DMA_BIDIRECTIONAL) == 0)
-+ return 1;
-+
-+ if (pci_map_sg(dev, sg_ptr, 1, PCI_DMA_BIDIRECTIONAL) == 0)
-+ {
-+ pci_unmap_sg(dev, &sg_tmp, num_pages, PCI_DMA_BIDIRECTIONAL);
-+ return 1;
-+ }
-+
-+ pci_unmap_sg(dev, &sg_tmp, num_pages, PCI_DMA_BIDIRECTIONAL);
-+ }
-+ } while (i-- && sg_ptr->dma_address & ~PAGE_MASK);
-+#else
- if (pci_map_sg(dev, sg_ptr, 1, PCI_DMA_BIDIRECTIONAL) == 0)
- {
- return 1;
- }
-+#endif
-+
-+ if (sg_ptr->dma_address & ~PAGE_MASK)
-+ {
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: VM: nv_sg_map_buffer: failed to obtain aligned mapping\n");
-+ pci_unmap_sg(dev, sg_ptr, num_pages, PCI_DMA_BIDIRECTIONAL);
-+ return 1;
-+ }
-
- NV_FIXUP_SWIOTLB_VIRT_ADDR_BUG(sg_ptr->dma_address);
-
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1182399/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1182399/nv-linux.h 2004-12-21 18:58:41.000000000 +0100
-@@ -155,6 +155,10 @@
- #endif
- #endif /* defined(NVCPU_X86) */
-
-+#ifndef get_cpu
-+#define get_cpu() smp_processor_id()
-+#define put_cpu()
-+#endif
-
- #if !defined (list_for_each)
- #define list_for_each(pos, head) \
-diff -ru usr/src/nv/nv.c usr/src/nv.1182399/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1182399/nv.c 2004-12-21 18:58:55.000000000 +0100
-@@ -2769,21 +2769,13 @@
- }
-
-
--/* avoid compiler warnings on UP kernels,
-- * when spinlock macros are defined away
-- */
--#define NO_COMPILER_WARNINGS(nvl) \
-- if (nvl == NULL) return
--
--
- static void nv_lock_init_locks
- (
- nv_state_t *nv
- )
- {
-- nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
--
-- NO_COMPILER_WARNINGS(nvl);
-+ nv_linux_state_t *nvl;
-+ nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-
- spin_lock_init(&nvl->rm_lock);
-
-@@ -2799,28 +2791,33 @@
- nv_state_t *nv
- )
- {
-- nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-- NO_COMPILER_WARNINGS(nvl);
-+ nv_linux_state_t *nvl;
-+ int cpu;
-+
-+ nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-+ cpu = get_cpu();
-
-- if (nvl->rm_lock_cpu == smp_processor_id())
-+ if (nvl->rm_lock_cpu == cpu)
- {
- nvl->rm_lock_count++;
-+ put_cpu();
- return;
- }
-
-+ put_cpu();
- spin_unlock_wait(&nvl->rm_lock);
- spin_lock_irq(&nvl->rm_lock);
-
-- nvl->rm_lock_cpu = smp_processor_id();
-- nvl->rm_lock_count = 1;
-+ nvl->rm_lock_cpu = smp_processor_id();
-+ nvl->rm_lock_count = 1;
- }
-
- void NV_API_CALL nv_unlock_rm(
- nv_state_t *nv
- )
- {
-- nv_linux_state_t *nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-- NO_COMPILER_WARNINGS(nvl);
-+ nv_linux_state_t *nvl;
-+ nvl = NV_GET_NVL_FROM_NV_STATE(nv);
-
- if (--nvl->rm_lock_count)
- return;
-diff -ru usr/src/nv/os-interface.c usr/src/nv.1182399/os-interface.c
---- usr/src/nv/os-interface.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1182399/os-interface.c 2004-12-21 18:58:47.000000000 +0100
-@@ -732,10 +732,17 @@
- //
- inline void NV_API_CALL out_string(const char *str)
- {
-+#if DEBUG
- static int was_newline = 0;
-
-- if (was_newline) printk("%d: %s", smp_processor_id(), str);
-- else printk("%s", str);
-+ if (NV_NUM_CPUS() > 1 && was_newline)
-+ {
-+ printk("%d: %s", get_cpu(), str);
-+ put_cpu();
-+ }
-+ else
-+#endif
-+ printk("%s", str);
-
- #if DEBUG
- if (NV_NUM_CPUS() > 1)
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1189413/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1189413/nv-linux.h 2005-01-07 15:44:01.000000000 +0100
-@@ -627,75 +627,109 @@
- #define NV_REMAP_PAGE_RANGE(x...) remap_page_range(x)
- #endif
-
-+
-+#define NV_PGD_OFFSET(address, kernel, mm) \
-+ ({ \
-+ pgd_t *__pgd; \
-+ if (!kernel) \
-+ __pgd = pgd_offset(mm, address); \
-+ else \
-+ __pgd = pgd_offset_k(address); \
-+ __pgd; \
-+ })
-+
-+#define NV_PGD_PRESENT(pgd) \
-+ ({ \
-+ if ((pgd != NULL) && \
-+ (pgd_bad(*pgd) || pgd_none(*pgd))) \
-+ /* static */ pgd = NULL; \
-+ pgd != NULL; \
-+ })
-+
- #if defined(pmd_offset_map)
--#define NV_PMD_OFFSET(addres, pg_dir, pg_mid_dir) \
-- { \
-- pg_mid_dir = pmd_offset_map(pg_dir, address); \
-- }
--#define NV_PMD_UNMAP(pg_mid_dir) \
-- { \
-- pmd_unmap(pg_mid_dir); \
-- }
-+#define NV_PMD_OFFSET(address, pgd) \
-+ ({ \
-+ pmd_t *__pmd; \
-+ __pmd = pmd_offset_map(pgd, address); \
-+ })
-+#define NV_PMD_UNMAP(pmd) pmd_unmap(pmd);
- #else
--#define NV_PMD_OFFSET(addres, pg_dir, pg_mid_dir) \
-- { \
-- pg_mid_dir = pmd_offset(pg_dir, address); \
-- }
--#define NV_PMD_UNMAP(pg_mid_dir)
-+#if defined(PUD_SHIFT) /* 4-level pgtable */
-+#define NV_PMD_OFFSET(address, pgd) \
-+ ({ \
-+ pmd_t *__pmd = NULL; \
-+ pud_t *__pud; \
-+ __pud = pud_offset(pgd, address); \
-+ if ((__pud != NULL) && \
-+ !(pud_bad(*__pud) || pud_none(*__pud))) \
-+ __pmd = pmd_offset(__pud, address); \
-+ __pmd; \
-+ })
-+#else /* 3-level pgtable */
-+#define NV_PMD_OFFSET(address, pgd) \
-+ ({ \
-+ pmd_t *__pmd; \
-+ __pmd = pmd_offset(pgd, address); \
-+ })
-+#endif
-+#define NV_PMD_UNMAP(pmd)
- #endif
-
--#define NV_PMD_PRESENT(pg_mid_dir) \
-- ({ \
-- if ( (pg_mid_dir) && (pmd_none(*pg_mid_dir))) { \
-- NV_PMD_UNMAP(pg_mid_dir); pg_mid_dir = NULL; \
-- } pg_mid_dir != NULL; \
-+#define NV_PMD_PRESENT(pmd) \
-+ ({ \
-+ if ((pmd != NULL) && \
-+ (pmd_bad(*pmd) || pmd_none(*pmd))) \
-+ { \
-+ NV_PMD_UNMAP(pmd); \
-+ pmd = NULL; /* mark invalid */ \
-+ } \
-+ pmd != NULL; \
- })
-
- #if defined(pte_offset_atomic)
--#define NV_PTE_OFFSET(addres, pg_mid_dir, pte) \
-- { \
-- pte = pte_offset_atomic(pg_mid_dir, address); \
-- NV_PMD_UNMAP(pg_mid_dir); \
-- }
--#define NV_PTE_UNMAP(pte) \
-- { \
-- pte_kunmap(pte); \
-- }
-+#define NV_PTE_OFFSET(address, pmd) \
-+ ({ \
-+ pte_t *__pte; \
-+ __pte = pte_offset_atomic(pmd, address); \
-+ NV_PMD_UNMAP(pmd); __pte; \
-+ })
-+#define NV_PTE_UNMAP(pte) pte_kunmap(pte);
- #elif defined(pte_offset)
--#define NV_PTE_OFFSET(addres, pg_mid_dir, pte) \
-- { \
-- pte = pte_offset(pg_mid_dir, address); \
-- NV_PMD_UNMAP(pg_mid_dir); \
-- }
-+#define NV_PTE_OFFSET(address, pmd) \
-+ ({ \
-+ pte_t *__pte; \
-+ __pte = pte_offset(pmd, address); \
-+ NV_PMD_UNMAP(pmd); __pte; \
-+ })
- #define NV_PTE_UNMAP(pte)
- #else
--#define NV_PTE_OFFSET(addres, pg_mid_dir, pte) \
-- { \
-- pte = pte_offset_map(pg_mid_dir, address); \
-- NV_PMD_UNMAP(pg_mid_dir); \
-- }
--#define NV_PTE_UNMAP(pte) \
-- { \
-- pte_unmap(pte); \
-- }
-+#define NV_PTE_OFFSET(address, pmd) \
-+ ({ \
-+ pte_t *__pte; \
-+ __pte = pte_offset_map(pmd, address); \
-+ NV_PMD_UNMAP(pmd); __pte; \
-+ })
-+#define NV_PTE_UNMAP(pte) pte_unmap(pte);
- #endif
-
--#define NV_PTE_PRESENT(pte) \
-- ({ \
-- if (pte) { \
-- if (!pte_present(*pte)) { \
-- NV_PTE_UNMAP(pte); pte = NULL; \
-- } \
-- } pte != NULL; \
-+#define NV_PTE_PRESENT(pte) \
-+ ({ \
-+ if ((pte != NULL) && !pte_present(*pte)) \
-+ { \
-+ NV_PTE_UNMAP(pte); \
-+ pte = NULL; /* mark invalid */ \
-+ } \
-+ pte != NULL; \
- })
-
--#define NV_PTE_VALUE(pte) \
-- ({ \
-- unsigned long __pte_value = pte_val(*pte); \
-- NV_PTE_UNMAP(pte); \
-- __pte_value; \
-+#define NV_PTE_VALUE(pte) \
-+ ({ \
-+ unsigned long __pte_value = pte_val(*pte); \
-+ NV_PTE_UNMAP(pte); \
-+ __pte_value; \
- })
-
-+
- #define NV_PAGE_ALIGN(addr) ( ((addr) + PAGE_SIZE - 1) / PAGE_SIZE)
- #define NV_MASK_OFFSET(addr) ( (addr) & (PAGE_SIZE - 1) )
-
-diff -ru usr/src/nv/nv-vm.c usr/src/nv.1189413/nv-vm.c
---- usr/src/nv/nv-vm.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1189413/nv-vm.c 2005-01-07 15:43:22.000000000 +0100
-@@ -53,12 +53,13 @@
- * conflicts. we try to rely on the kernel's provided interfaces when possible,
- * but need additional flushing on earlier kernels.
- */
--
-+#if defined(KERNEL_2_4)
- /* wrap CACHE_FLUSH so we can pass it to smp_call_function */
- static void cache_flush(void *p)
- {
- CACHE_FLUSH();
- }
-+#endif
-
- /*
- * 2.4 kernels handle flushing in the change_page_attr() call, but kernels
-diff -ru usr/src/nv/nv.c usr/src/nv.1189413/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1189413/nv.c 2005-01-07 15:43:22.000000000 +0100
-@@ -2492,26 +2492,23 @@
- )
- {
- struct mm_struct *mm;
-- pgd_t *pg_dir;
-- pmd_t *pg_mid_dir;
-- pte_t *pte;
-+ pgd_t *pgd = NULL;
-+ pmd_t *pmd = NULL;
-+ pte_t *pte = NULL;
- unsigned long retval;
-
- mm = (kern) ? &init_mm : current->mm;
- spin_lock(&mm->page_table_lock);
-
-- if (kern) pg_dir = pgd_offset_k(address);
-- else pg_dir = pgd_offset(mm, address);
--
-- if (!pg_dir || pgd_none(*pg_dir))
-+ pgd = NV_PGD_OFFSET(address, kern, mm);
-+ if (!NV_PGD_PRESENT(pgd))
- goto failed;
-
-- NV_PMD_OFFSET(address, pg_dir, pg_mid_dir);
-- if (!NV_PMD_PRESENT(pg_mid_dir))
-+ pmd = NV_PMD_OFFSET(address, pgd);
-+ if (!NV_PMD_PRESENT(pmd))
- goto failed;
-
-- NV_PTE_OFFSET(address, pg_mid_dir, pte);
--
-+ pte = NV_PTE_OFFSET(address, pmd);
- if (!NV_PTE_PRESENT(pte))
- goto failed;
-
+++ /dev/null
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.1201042/nv-linux.h
---- usr/src/nv/nv-linux.h 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1201042/nv-linux.h 2005-01-22 14:34:35.000000000 +0100
-@@ -565,11 +565,6 @@
- #define PCI_CAP_ID_EXP 0x10
- #endif
-
--#if defined(KERNEL_2_6) && defined(AGPGART)
--typedef struct agp_kern_info agp_kern_info;
--typedef struct agp_memory agp_memory;
--#endif
--
- #if defined(CONFIG_DEVFS_FS)
- # if defined(KERNEL_2_6)
- typedef void* devfs_handle_t;
-diff -ru usr/src/nv/nv.c usr/src/nv.1201042/nv.c
---- usr/src/nv/nv.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1201042/nv.c 2005-01-22 14:34:35.000000000 +0100
-@@ -2987,32 +2987,39 @@
- */
- if ( (!NV_AGP_ENABLED(nv)) && (config & NVOS_AGP_CONFIG_NVAGP) )
- {
-- /* make sure the user does not have agpgart loaded */
-- if (inter_module_get("drm_agp")) {
-+#if defined(KERNEL_2_4)
-+ if (inter_module_get("drm_agp"))
-+ {
- inter_module_put("drm_agp");
-- nv_printf(NV_DBG_WARNINGS, "NVRM: not using NVAGP, AGPGART is loaded!!\n");
-- } else {
--#if defined(CONFIG_X86_64) && defined(CONFIG_GART_IOMMU)
-+ nv_printf(NV_DBG_WARNINGS, "NVRM: not using NVAGP, AGPGART is loaded!\n");
-+ return -1;
-+ }
-+#elif defined(AGPGART)
-+ int error;
-+ if ((error = agp_backend_acquire()) != -EINVAL)
-+ {
-+ if (!error) agp_backend_release();
- nv_printf(NV_DBG_WARNINGS,
-- "NVRM: not using NVAGP, kernel was compiled with GART_IOMMU support!!\n");
--#else
-- status = rm_init_agp(nv);
-- if (status == RM_OK)
-- {
-- nv->agp_config = NVOS_AGP_CONFIG_NVAGP;
-- nv->agp_status = NV_AGP_STATUS_ENABLED;
-- }
-+ "NVRM: not using NVAGP, an AGPGART backend is loaded!\n");
-+ return -1;
-+ }
- #endif
-+#if defined(CONFIG_X86_64) && defined(CONFIG_GART_IOMMU)
-+ nv_printf(NV_DBG_WARNINGS,
-+ "NVRM: not using NVAGP, kernel was compiled with GART_IOMMU support!\n");
-+#else
-+ status = rm_init_agp(nv);
-+ if (status == RM_OK)
-+ {
-+ nv->agp_config = NVOS_AGP_CONFIG_NVAGP;
-+ nv->agp_status = NV_AGP_STATUS_ENABLED;
- }
-+#endif
- }
-
- if (NV_AGP_ENABLED(nv))
- old_error = 0; /* report new errors */
-
-- nv_printf(NV_DBG_SETUP,
-- "NVRM: agp_init finished with status 0x%x and config %d\n",
-- status, nv->agp_config);
--
- return status;
- }
-
-@@ -3036,9 +3043,6 @@
- nv->agp_config = NVOS_AGP_CONFIG_DISABLE_AGP;
- nv->agp_status = NV_AGP_STATUS_DISABLED;
-
-- nv_printf(NV_DBG_SETUP, "NVRM: teardown finished with status 0x%x\n",
-- status);
--
- return status;
- }
-
-diff -ru usr/src/nv/os-agp.c usr/src/nv.1201042/os-agp.c
---- usr/src/nv/os-agp.c 2004-11-03 22:53:00.000000000 +0100
-+++ usr/src/nv.1201042/os-agp.c 2005-01-22 14:34:35.000000000 +0100
-@@ -25,6 +25,13 @@
-
- #ifdef AGPGART
-
-+#if defined(KERNEL_2_6)
-+typedef struct agp_kern_info agp_kern_info;
-+typedef struct agp_memory agp_memory;
-+#elif defined(KERNEL_2_4)
-+const drm_agp_t *drm_agp_p; /* functions */
-+#endif
-+
- typedef struct {
- agp_memory *ptr;
- int num_pages;
-@@ -45,7 +52,6 @@
-
- agp_kern_info agpinfo;
- agp_gart gart;
--const drm_agp_t *drm_agp_p;
-
- #if defined(CONFIG_MTRR)
- #define MTRR_DEL(gart) if ((gart).mtrr > 0) mtrr_del((gart).mtrr, 0, 0);
-@@ -53,6 +59,26 @@
- #define MTRR_DEL(gart)
- #endif
-
-+#if defined(KERNEL_2_6)
-+#define NV_AGPGART_BACKEND_ACQUIRE(o) agp_backend_acquire()
-+#define NV_AGPGART_BACKEND_ENABLE(o,mode) agp_enable(mode)
-+#define NV_AGPGART_BACKEND_RELEASE(o) agp_backend_release()
-+#define NV_AGPGART_COPY_INFO(o,p) agp_copy_info(p)
-+#define NV_AGPGART_ALLOCATE_MEMORY(o,count,type) agp_allocate_memory(count,type)
-+#define NV_AGPGART_FREE_MEMORY(o,p) agp_free_memory(p)
-+#define NV_AGPGART_BIND_MEMORY(o,p,offset) agp_bind_memory(p,offset)
-+#define NV_AGPGART_UNBIND_MEMORY(o,p) agp_unbind_memory(p)
-+#elif defined(KERNEL_2_4)
-+#define NV_AGPGART_BACKEND_ACQUIRE(o) ({ (o)->acquire(); 0; })
-+#define NV_AGPGART_BACKEND_ENABLE(o,mode) (o)->enable(mode)
-+#define NV_AGPGART_BACKEND_RELEASE(o) ((o)->release())
-+#define NV_AGPGART_COPY_INFO(o,p) ({ (o)->copy_info(p); 0; })
-+#define NV_AGPGART_ALLOCATE_MEMORY(o,count,type) (o)->allocate_memory(count,type)
-+#define NV_AGPGART_FREE_MEMORY(o,p) (o)->free_memory(p)
-+#define NV_AGPGART_BIND_MEMORY(o,p,offset) (o)->bind_memory(p,offset)
-+#define NV_AGPGART_UNBIND_MEMORY(o,p) (o)->unbind_memory(p)
-+#endif
-+
- #endif /* AGPGART */
-
- BOOL KernInitAGP(
-@@ -73,8 +99,10 @@
-
- memset( (void *) &gart, 0, sizeof(agp_gart));
-
-+#if defined(KERNEL_2_4)
- if (!(drm_agp_p = inter_module_get_request("drm_agp", "agpgart")))
- return 1;
-+#endif
-
- /* NOTE: from here down, return an error code of '-1'
- * that indicates that agpgart is loaded, but we failed to use it
-@@ -82,11 +110,10 @@
- * the memory controller.
- */
-
-- if (drm_agp_p->acquire())
-+ if (NV_AGPGART_BACKEND_ACQUIRE(drm_agp_p))
- {
-- nv_printf(NV_DBG_ERRORS, "NVRM: AGPGART: backend in use\n");
-- inter_module_put("drm_agp");
-- return -1;
-+ nv_printf(NV_DBG_INFO, "NVRM: AGPGART: no backend available\n");
-+ goto bailout;
- }
-
- if (rm_read_registry_dword(nv, "NVreg", "ReqAGPRate", &agp_rate) == RM_ERROR)
-@@ -101,21 +128,12 @@
- agp_fw = 1;
- agp_fw &= 0x00000001;
-
--#if defined(KERNEL_2_4)
-- /*
-- * The original Linux 2.4 AGP GART driver interface declared copy_info to
-- * return nothing. This changed in Linux 2.5, which reports unsupported
-- * chipsets via this function. If this Linux 2.4 kernels behaves the same
-- * way, we have no way to know.
-- */
-- drm_agp_p->copy_info(&agpinfo);
--#else
-- if (drm_agp_p->copy_info(&agpinfo)) {
-+ if (NV_AGPGART_COPY_INFO(drm_agp_p, &agpinfo))
-+ {
- nv_printf(NV_DBG_ERRORS,
- "NVRM: AGPGART: kernel reports chipset as unsupported\n");
- goto failed;
- }
--#endif
-
- #ifdef CONFIG_MTRR
- /*
-@@ -170,7 +188,7 @@
- if (!(agp_rate & 0x00000004)) agpinfo.mode &= ~0x00000004;
- if (!(agp_rate & 0x00000002)) agpinfo.mode &= ~0x00000002;
-
-- drm_agp_p->enable(agpinfo.mode);
-+ NV_AGPGART_BACKEND_ENABLE(drm_agp_p, agpinfo.mode);
-
- *ap_phys_base = (void*) agpinfo.aper_base;
- *ap_mapped_base = (void*) gart.aperture;
-@@ -182,8 +200,11 @@
-
- failed:
- MTRR_DEL(gart); /* checks gart.mtrr */
-- drm_agp_p->release();
-+ NV_AGPGART_BACKEND_RELEASE(drm_agp_p);
-+bailout:
-+#if defined(KERNEL_2_4)
- inter_module_put("drm_agp");
-+#endif
-
- return -1;
-
-@@ -213,9 +234,10 @@
- NV_IOUNMAP(gart.aperture, RM_PAGE_SIZE);
- }
-
-- drm_agp_p->release();
--
-+ NV_AGPGART_BACKEND_RELEASE(drm_agp_p);
-+#if defined(KERNEL_2_4)
- inter_module_put("drm_agp");
-+#endif
-
- if (rm_clear_agp_bitmap(nv, &bitmap))
- {
-@@ -244,7 +266,6 @@
- return RM_ERROR;
- #else
- agp_memory *ptr;
-- int err;
- agp_priv_data *data;
- RM_STATUS status;
-
-@@ -262,7 +283,7 @@
- return RM_ERROR;
- }
-
-- ptr = drm_agp_p->allocate_memory(PageCount, AGP_NORMAL_MEMORY);
-+ ptr = NV_AGPGART_ALLOCATE_MEMORY(drm_agp_p, PageCount, AGP_NORMAL_MEMORY);
- if (ptr == NULL)
- {
- *pAddress = (void*) 0;
-@@ -270,8 +291,7 @@
- return RM_ERR_NO_FREE_MEM;
- }
-
-- err = drm_agp_p->bind_memory(ptr, *Offset);
-- if (err)
-+ if (NV_AGPGART_BIND_MEMORY(drm_agp_p, ptr, *Offset))
- {
- // this happens a lot when the aperture itself fills up..
- // not a big deal, so don't alarm people with an error message
-@@ -280,14 +300,11 @@
- goto fail;
- }
-
-- /* return the agp aperture address */
-- *pAddress = (void *) (agpinfo.aper_base + (*Offset << PAGE_SHIFT));
--
- status = os_alloc_mem((void **)&data, sizeof(agp_priv_data));
- if (status != RM_OK)
- {
- nv_printf(NV_DBG_ERRORS, "NVRM: AGPGART: memory allocation failed\n");
-- drm_agp_p->unbind_memory(ptr);
-+ NV_AGPGART_UNBIND_MEMORY(drm_agp_p, ptr);
- goto fail;
- }
-
-@@ -302,7 +319,7 @@
- return RM_OK;
-
- fail:
-- drm_agp_p->free_memory(ptr);
-+ NV_AGPGART_FREE_MEMORY(drm_agp_p, ptr);
- *pAddress = (void*) 0;
-
- return RM_ERROR;
-@@ -342,7 +359,7 @@
- {
- nv_printf(NV_DBG_ERRORS, "NVRM: AGPGART: unable to remap %lu pages\n",
- (unsigned long)agp_data->num_pages);
-- drm_agp_p->unbind_memory(agp_data->ptr);
-+ NV_AGPGART_UNBIND_MEMORY(drm_agp_p, agp_data->ptr);
- goto fail;
- }
-
-@@ -441,8 +458,8 @@
- {
- size_t pages = ptr->page_count;
-
-- drm_agp_p->unbind_memory(ptr);
-- drm_agp_p->free_memory(ptr);
-+ NV_AGPGART_UNBIND_MEMORY(drm_agp_p, ptr);
-+ NV_AGPGART_FREE_MEMORY(drm_agp_p, ptr);
-
- nv_printf(NV_DBG_INFO, "NVRM: AGPGART: freed %ld pages\n",
- (unsigned long)pages);
+++ /dev/null
-diff -ru usr/src/nv/Makefile.kbuild usr/src/nv.U012206/Makefile.kbuild
---- usr/src/nv/Makefile.kbuild 2005-12-15 01:57:35.000000000 +0100
-+++ usr/src/nv.U012206/Makefile.kbuild 2006-01-22 15:32:35.775636750 +0100
-@@ -186,6 +186,18 @@
- ifeq ($(shell $(CONFTEST) sysctl_max_map_count), 1)
- EXTRA_CFLAGS += -DNV_SYSCTL_MAX_MAP_COUNT_PRESENT
- endif
-+
-+ ifeq ($(shell $(CONFTEST) pm_message_t), 1)
-+ EXTRA_CFLAGS += -DNV_PM_MESSAGE_T_PRESENT
-+ endif
-+
-+ ifeq ($(shell $(CONFTEST) pci_choose_state), 1)
-+ EXTRA_CFLAGS += -DNV_PCI_CHOOSE_STATE_PRESENT
-+ endif
-+
-+ ifeq ($(shell $(CONFTEST) vm_insert_page), 1)
-+ EXTRA_CFLAGS += -DNV_VM_INSERT_PAGE_PRESENT
-+ endif
- endif
-
- ifeq ($(shell $(CONFTEST) remap_pfn_range), 1)
-diff -ru usr/src/nv/conftest.sh usr/src/nv.U012206/conftest.sh
---- usr/src/nv/conftest.sh 2005-12-15 01:57:35.000000000 +0100
-+++ usr/src/nv.U012206/conftest.sh 2006-01-22 15:32:06.353798000 +0100
-@@ -22,8 +22,8 @@
- OUTPUT=$4
-
- CFLAGS="-D__KERNEL__ \
---nostdinc -isystem $ISYSTEM \
---Werror-implicit-function-declaration"
-+-DKBUILD_BASENAME=\"#conftest$$\" -DKBUILD_MODNAME=\"#conftest$$\" \
-+-nostdinc -isystem $ISYSTEM"
-
- if [ "$OUTPUT" != "$SOURCES" ]; then
- ARCH=`uname -m | sed -e 's/i.86/i386/'`
-@@ -40,9 +40,22 @@
- #
-
- echo "#include <linux/mm.h>
-- int nv_remap_page_range(void) {
-+ void conftest_remap_page_range(void) {
-+ remap_page_range();
-+ }" > conftest$$.c
-+
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-+ rm -f conftest$$.c
-+
-+ if [ -f conftest$$.o ]; then
-+ rm -f conftest$$.o
-+ exit 1
-+ fi
-+
-+ echo "#include <linux/mm.h>
-+ int conftest_remap_page_range(void) {
- pgprot_t pgprot = __pgprot(0);
-- remap_page_range(NULL, 0L, 0L, 0L, pgprot);
-+ return remap_page_range(NULL, 0L, 0L, 0L, pgprot);
- }" > conftest$$.c
-
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-@@ -55,9 +68,9 @@
- fi
-
- echo "#include <linux/mm.h>
-- int nv_remap_page_range(void) {
-+ int conftest_remap_page_range(void) {
- pgprot_t pgprot = __pgprot(0);
-- remap_page_range(0L, 0L, 0L, pgprot);
-+ return remap_page_range(0L, 0L, 0L, pgprot);
- }" > conftest$$.c
-
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-@@ -330,7 +343,7 @@
- return 0;
- }" > conftest$$.c
-
-- $HOSTCC $CFLAGS -Wno-error -o conftest$$ conftest$$.c > /dev/null 2>&1
-+ $HOSTCC $CFLAGS -o conftest$$ conftest$$.c > /dev/null 2>&1
- rm -f conftest$$.c
-
- if [ -f conftest$$ ]; then
-@@ -483,8 +496,8 @@
- #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
- #include <asm/cacheflush.h>
- #endif
-- int nv_change_page_attr(struct page *pp, int i, pgprot_t prot) {
-- return change_page_attr(pp, i, prot);
-+ void conftest_change_page_attr() {
-+ change_page_attr();
- }" > conftest$$.c
-
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-@@ -492,9 +505,9 @@
-
- if [ -f conftest$$.o ]; then
- rm -f conftest$$.o
-- echo 1
-- else
- echo 0
-+ else
-+ echo 1
- fi
- ;;
-
-@@ -504,9 +517,8 @@
- #
-
- echo "#include <linux/pci.h>
-- struct pci_dev*
-- nv_pci_get_class(unsigned int class, struct pci_dev *from) {
-- return pci_get_class(class, from);
-+ void conftest_pci_get_class(void) {
-+ pci_get_class();
- }" > conftest$$.c
-
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-@@ -514,9 +526,9 @@
-
- if [ -f conftest$$.o ]; then
- rm -f conftest$$.o
-- echo 1
-- else
- echo 0
-+ else
-+ echo 1
- fi
- ;;
-
-@@ -526,9 +538,8 @@
- #
-
- echo "#include <linux/mm.h>
-- int nv_remap_pfn_range(void) {
-- pgprot_t pgprot = __pgprot(0);
-- remap_pfn_range(NULL, 0L, 0L, 0L, pgprot);
-+ void conftest_remap_pfn_range(void) {
-+ remap_pfn_range();
- }" > conftest$$.c
-
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-@@ -536,9 +547,9 @@
-
- if [ -f conftest$$.o ]; then
- rm -f conftest$$.o
-- echo 1
-- else
- echo 0
-+ else
-+ echo 1
- fi
- ;;
-
-@@ -548,11 +559,11 @@
- #
-
- echo "#include <linux/sched.h>
-- struct rlimit *nv_signal_struct_rlim(void) {
-+ struct rlimit *conftest_signal_struct_rlim(void) {
- return current->signal->rlim;
- }" > conftest$$.c
-
-- $CC $CFLAGS -Wno-error -c conftest$$.c > /dev/null 2>&1
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
- rm -f conftest$$.c
-
- if [ -f conftest$$.o ]; then
-@@ -572,7 +583,7 @@
- echo "#include <linux/types.h>
- #include <linux/agp_backend.h>
- typedef struct agp_bridge_data agp_bridge_data;
-- agp_bridge_data *nv_agp_backend_acquire(struct pci_dev *dev) {
-+ agp_bridge_data *conftest_agp_backend_acquire(struct pci_dev *dev) {
- return agp_backend_acquire(dev);
- }" > conftest$$.c
-
-@@ -594,9 +605,23 @@
- #
-
- echo "#include <linux/vmalloc.h>
-- void *nv_vmap(struct page **pg, int cnt) {
-+ void conftest_vmap(void) {
-+ vmap();
-+ }" > conftest$$.c
-+
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-+ rm -f conftest$$.c
-+
-+ if [ -f conftest$$.o ]; then
-+ rm -f conftest$$.o
-+ exit 1
-+ fi
-+
-+ echo "#include <linux/vmalloc.h>
-+ void *conftest_vmap(struct page **pg, int cnt) {
- return vmap(pg, cnt);
- }" > conftest$$.c
-+
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
- rm -f conftest$$.c
-
-@@ -608,9 +633,10 @@
-
- echo "#include <linux/vmalloc.h>
- #include <linux/mm.h>
-- void *nv_vmap(struct page **pg, int cnt) {
-+ void *conftest_vmap(struct page **pg, int cnt) {
- return vmap(pg, cnt, 0, PAGE_KERNEL);
- }" > conftest$$.c
-+
- $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
- rm -f conftest$$.c
-
-@@ -618,7 +644,11 @@
- rm -f conftest$$.o
- echo 4
- else
-- exit 1 # there ain't no vmap()
-+ #
-+ # We couldn't determine the number of arguments expected by the
-+ # vmap() function.
-+ #
-+ exit 1
- fi
- ;;
-
-@@ -629,7 +659,7 @@
- #
-
- echo "#include <linux/sched.h>
-- int nv_test_sysctl_max_map_count(void) {
-+ int conftest_sysctl_max_map_count(void) {
- return sysctl_max_map_count;
- }" > conftest$$.c
-
-@@ -644,4 +674,67 @@
- fi
- ;;
-
-+ pm_message_t)
-+ #
-+ # Does linux/pm.h declare the pm_message_t type?
-+ #
-+
-+ echo "#include <linux/pm.h>
-+ void conftest_pm_message_t(pm_message_t state) {
-+ pm_message_t *p = &state;
-+ }" > conftest$$.c
-+
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-+ rm -f conftest$$.c
-+
-+ if [ -f conftest$$.o ]; then
-+ rm -f conftest$$.o
-+ echo 1
-+ else
-+ echo 0
-+ fi
-+ ;;
-+
-+ pci_choose_state)
-+ #
-+ # Determine if pci_choose_state() is present.
-+ #
-+
-+ echo "#include <linux/pci.h>
-+ void conftest_pci_choose_state(void) {
-+ pci_choose_state();
-+ }" > conftest$$.c
-+
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-+ rm -f conftest$$.c
-+
-+ if [ -f conftest$$.o ]; then
-+ rm -f conftest$$.o
-+ echo 0
-+ else
-+ echo 1
-+ fi
-+ ;;
-+
-+ vm_insert_page)
-+ #
-+ # Determine if vm_insert_page() is present.
-+ #
-+
-+ echo "#include <linux/mm.h>
-+ void conftest_vm_insert_page(void) {
-+ vm_insert_page();
-+ }" > conftest$$.c
-+
-+ $CC $CFLAGS -c conftest$$.c > /dev/null 2>&1
-+ rm -f conftest$$.c
-+
-+ if [ -f conftest$$.o ]; then
-+ rm -f conftest$$.o
-+ echo 0
-+ else
-+ echo 1
-+ fi
-+ ;;
-+
- esac
-diff -ru usr/src/nv/nv-linux.h usr/src/nv.U012206/nv-linux.h
---- usr/src/nv/nv-linux.h 2005-12-15 01:57:35.000000000 +0100
-+++ usr/src/nv.U012206/nv-linux.h 2006-01-22 15:32:35.775636750 +0100
-@@ -642,15 +642,49 @@
- #define NV_PRINT_AT(at)
- #endif
-
--// acpi support has been back-ported to the 2.4 kernel, but the 2.4 driver
--// model is not sufficient for full acpi support. it may work in some cases,
--// but not enough for us to officially support this configuration.
--#if defined(CONFIG_ACPI) && defined(KERNEL_2_6)
--#define NV_PM_SUPPORT_ACPI
-+/*
-+ * On Linux 2.6, we support both APM and ACPI power management. On Linux
-+ * 2.4, we support APM, only. ACPI support has been back-ported to the
-+ * Linux 2.4 kernel, but the Linux 2.4 driver model is not sufficient for
-+ * full ACPI support: it may work with some systems, but not reliably
-+ * enough for us to officially support this configuration.
-+ *
-+ * We support two Linux kernel power managment interfaces: the original
-+ * pm_register()/pm_unregister() on Linux 2.4 and the device driver model
-+ * backed PCI driver power management callbacks introduced with Linux
-+ * 2.6.
-+ *
-+ * The code below determines which interface to support on this kernel
-+ * version, if any; if built for Linux 2.6, it will also determine if the
-+ * kernel comes with ACPI or APM power management support.
-+ */
-+#if defined(KERNEL_2_6) && (defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) || defined(CONFIG_ACPI))
-+#define NV_PM_SUPPORT_DEVICE_DRIVER_MODEL
-+#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
-+#define NV_PM_SUPPORT_NEW_STYLE_APM
-+#endif
- #endif
-
--#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
--#define NV_PM_SUPPORT_APM
-+/*
-+ * On Linux 2.6 kernels >= 2.6.11, the PCI subsystem provides a new
-+ * interface that allows PCI drivers to determine the correct power state
-+ * for a given system power state; our suspend/resume callbacks now use
-+ * this interface and operate on PCI power state defines.
-+ *
-+ * Define these new PCI power state #define's here for compatibility with
-+ * older Linux 2.6 kernels.
-+ */
-+#if defined(KERNEL_2_6) && !defined(PCI_D0)
-+#define PCI_D0 PM_SUSPEND_ON
-+#define PCI_D3hot PM_SUSPEND_MEM
-+#endif
-+
-+#if defined(KERNEL_2_6) && !defined(NV_PM_MESSAGE_T_PRESENT)
-+typedef u32 pm_message_t;
-+#endif
-+
-+#if defined(KERNEL_2_4) && (defined(CONFIG_APM) || defined(CONFIG_APM_MODULE))
-+#define NV_PM_SUPPORT_OLD_STYLE_APM
- #endif
-
- #ifndef minor
-@@ -666,9 +700,13 @@
- #define PCI_CAP_ID_EXP 0x10
- #endif
-
-+#if defined(NV_VM_INSERT_PAGE_PRESENT)
-+#define NV_VM_INSERT_PAGE(vma, addr, page) \
-+ vm_insert_page(vma, addr, page)
-+#endif
- #if defined(NV_REMAP_PFN_RANGE_PRESENT)
- #define NV_REMAP_PAGE_RANGE(from, offset, x...) \
-- remap_pfn_range(vma, from, ((offset) >> PAGE_SHIFT), x)
-+ remap_pfn_range(vma, from, ((offset) >> PAGE_SHIFT), x)
- #elif defined(NV_REMAP_PAGE_RANGE_5_PRESENT)
- #define NV_REMAP_PAGE_RANGE(x...) remap_page_range(vma, x)
- #elif defined(NV_REMAP_PAGE_RANGE_4_PRESENT)
-@@ -840,11 +878,7 @@
- }
- #endif
-
--#if !defined(page_to_pfn)
--#define page_to_pfn(page) ((page) - mem_map)
--#endif
--
--#if !defined(pfn_to_page)
-+#if defined(KERNEL_2_4) && defined(NVCPU_X86) && !defined(pfn_to_page)
- #define pfn_to_page(pfn) (mem_map + (pfn))
- #endif
-
-diff -ru usr/src/nv/nv-vm.c usr/src/nv.U012206/nv-vm.c
---- usr/src/nv/nv-vm.c 2005-12-15 01:57:35.000000000 +0100
-+++ usr/src/nv.U012206/nv-vm.c 2006-01-22 15:32:35.775636750 +0100
-@@ -105,6 +105,15 @@
- #endif
- }
-
-+static inline BOOL nv_page_locked(nv_pte_t *page_ptr)
-+{
-+ BOOL locked = FALSE;
-+#if defined(PageReserved)
-+ locked = PageReserved(NV_GET_PAGE_STRUCT(page_ptr->phys_addr));
-+#endif
-+ return locked;
-+}
-+
- #if defined(NV_SG_MAP_BUFFERS)
-
- /* track how much memory has been remapped through the iommu/swiotlb */
-@@ -704,7 +713,7 @@
- if (!NV_ALLOC_MAPPING_CONTIG(at->flags))
- nv_sg_unmap_buffer(dev, &page_ptr->sg_list, page_ptr);
- #endif
-- if (!NV_ALLOC_MAPPING_CONTIG(at->flags) && !NV_ALLOC_MAPPING_VMALLOC(at->flags))
-+ if (!NV_ALLOC_MAPPING_CONTIG(at->flags) && !NV_ALLOC_MAPPING_VMALLOC(at->flags) && !nv_page_locked(page_ptr))
- NV_FREE_PAGES(page_ptr->virt_addr, 0);
- }
- nv_flush_caches();
-diff -ru usr/src/nv/nv.c usr/src/nv.U012206/nv.c
---- usr/src/nv/nv.c 2005-12-15 01:57:35.000000000 +0100
-+++ usr/src/nv.U012206/nv.c 2006-01-22 15:32:35.775636750 +0100
-@@ -29,7 +29,7 @@
-
- static nv_linux_state_t nv_linux_devices[NV_MAX_DEVICES];
-
--#if defined(NV_PM_SUPPORT_APM)
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
- static struct pm_dev *apm_nv_dev[NV_MAX_DEVICES] = { 0 };
- #endif
-
-@@ -244,8 +244,8 @@
- void nv_kern_isr_bh(unsigned long);
- irqreturn_t nv_kern_isr(int, void *, struct pt_regs *);
- void nv_kern_rc_timer(unsigned long);
--#if defined(NV_PM_SUPPORT_APM)
--int nv_kern_apm_event(struct pm_dev *dev, pm_request_t rqst, void *data);
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
-+static int nv_kern_apm_event(struct pm_dev *, pm_request_t, void *);
- #endif
-
- static int nv_kern_read_cardinfo(char *, char **, off_t off, int, int *, void *);
-@@ -265,9 +265,10 @@
- unsigned int nv_kern_ctl_poll(struct file *, poll_table *);
-
- int nv_kern_probe(struct pci_dev *, const struct pci_device_id *);
--#if defined(NV_PM_SUPPORT_ACPI)
--int nv_kern_acpi_standby(struct pci_dev *, u32);
--int nv_kern_acpi_resume(struct pci_dev *);
-+
-+#if defined(NV_PM_SUPPORT_DEVICE_DRIVER_MODEL)
-+static int nv_kern_suspend(struct pci_dev *, pm_message_t);
-+static int nv_kern_resume(struct pci_dev *);
- #endif
-
- /***
-@@ -292,9 +293,9 @@
- .name = "nvidia",
- .id_table = nv_pci_table,
- .probe = nv_kern_probe,
--#if defined(NV_PM_SUPPORT_ACPI)
-- .suspend = nv_kern_acpi_standby,
-- .resume = nv_kern_acpi_resume,
-+#if defined(NV_PM_SUPPORT_DEVICE_DRIVER_MODEL)
-+ .suspend = nv_kern_suspend,
-+ .resume = nv_kern_resume,
- #endif
- };
-
-@@ -852,7 +853,8 @@
-
- if (!test_bit(X86_FEATURE_PAT, (volatile unsigned long *)&boot_cpu_data.x86_capability))
- {
-- nv_printf(NV_DBG_ERRORS, "NVRM: cpu does not support PAT, aborting..\n");
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: CPU does not support the PAT, falling back to MTRRs.\n");
- return 0;
- }
-
-@@ -1084,9 +1086,12 @@
-
- // broken kernels may get confused after splitting the page and
- // restore the page before returning to us. detect that case.
-- if ( (pte_val(*kpte) == kpte_val) &&
-- (pte_val(*kpte) & _PAGE_PSE))
-+ if (((pte_val(*kpte) & ~_PAGE_NX) == kpte_val) &&
-+ (pte_val(*kpte) & _PAGE_PSE))
- {
-+ if ((pte_val(*kpte) & _PAGE_NX) &&
-+ (__nv_supported_pte_mask & _PAGE_NX) == 0)
-+ clear_bit(_PAGE_BIT_NX, kpte);
- spin_unlock(&init_mm.page_table_lock);
- // don't change the page back, as it's already been reverted
- put_page(kpte_page);
-@@ -1299,7 +1304,7 @@
- nv_lock_init_locks(nv_ctl);
- }
-
--#if defined(NV_PM_SUPPORT_APM)
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
- for (i = 0; i < num_nv_devices; i++)
- {
- apm_nv_dev[i] = pm_register(PM_PCI_DEV, PM_SYS_VGA, nv_kern_apm_event);
-@@ -1407,8 +1412,11 @@
-
- #if defined(NV_BUILD_NV_PAT_SUPPORT)
- if (!nv_disable_pat)
-- {
- __nv_enable_pat_support();
-+ else
-+ {
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: builtin PAT support disabled, falling back to MTRRs.\n");
- }
- #endif
-
-@@ -1418,7 +1426,7 @@
- if (nv_pte_t_cache != NULL)
- NV_KMEM_CACHE_DESTROY(nv_pte_t_cache);
-
--#if defined(NV_PM_SUPPORT_APM)
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
- for (i = 0; i < num_nv_devices; i++)
- if (apm_nv_dev[i] != NULL) pm_unregister(apm_nv_dev[i]);
- #endif
-@@ -1473,10 +1481,10 @@
- inter_module_unregister("nv_linux_devices");
- #endif
-
--#if defined(NV_PM_SUPPORT_APM)
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
- for (i = 0; i < num_nv_devices; i++)
- {
-- pm_unregister(apm_nv_dev[i]);
-+ if (apm_nv_dev[i] != NULL) pm_unregister(apm_nv_dev[i]);
- }
- #endif
-
-@@ -1889,9 +1897,6 @@
- // allow setting or refusal of specific caching types
- switch (cache_type)
- {
-- case NV_MEMORY_CACHED:
-- //case NV_MEMORY_WRITEBACK:
-- break;
- case NV_MEMORY_UNCACHED_WEAK:
- *prot = pgprot_noncached_weak(*prot);
- break;
-@@ -1899,19 +1904,53 @@
- *prot = pgprot_noncached(*prot);
- break;
- case NV_MEMORY_WRITECOMBINED:
-- if (nv_pat_enabled)
-+ if (nv_pat_enabled &&
-+ (memory_type != NV_MEMORY_TYPE_REGISTERS))
- {
- *prot = pgprot_writecombined(*prot);
- break;
- }
-- /* agp allocations should be covered by an mtrr if pat isn't enabled */
-+ /*
-+ * If PAT support is unavailable and the memory space isn't
-+ * NV_MEMORY_TYPE_AGP, we need to return an error code to
-+ * the caller, but do not print a warning message.
-+ *
-+ * In the case of AGP memory, we will have attempted to add
-+ * a WC MTRR for the AGP aperture and aborted the AGP
-+ * initialization if this failed, so we can safely return
-+ * success here.
-+ *
-+ * For frame buffer memory, callers are expected to use the
-+ * UC- memory type if we report WC as unsupported, which
-+ * translates to the effective memory type WC if a WC MTRR
-+ * exists or else UC.
-+ */
- if (memory_type == NV_MEMORY_TYPE_AGP)
- break;
-+ return 1;
-+ case NV_MEMORY_CACHED:
-+ //case NV_MEMORY_WRITEBACK:
-+ /*
-+ * RAM is cached on Linux by default, we can assume there's
-+ * nothing to be done here. This is not the case for the
-+ * other memory spaces: as commented on above, we will have
-+ * added a WC MTRR for the AGP aperture (or else aborted
-+ * AGP initialization), and we will have made an attempt to
-+ * add a WC MTRR for the frame buffer.
-+ *
-+ * If a WC MTRR is present, we can't satisfy the WB mapping
-+ * attempt here, since the achievable effective memory
-+ * types in that case are WC and UC, if not it's typically
-+ * UC (MTRRdefType is UC); we could only satisfy WB mapping
-+ * requests with a WB MTRR.
-+ */
-+ if (memory_type == NV_MEMORY_TYPE_SYSTEM)
-+ break;
- //case NV_MEMORY_WRITETHRU:
- //case NV_MEMORY_WRITEPROTECT:
- default:
- nv_printf(NV_DBG_ERRORS,
-- "NVRM: memory caching type 0x%x not supported for memory space %d!\n",
-+ "NVRM: VM: memory type %d not supported for memory space %d!\n",
- cache_type, memory_type);
- return 1;
- }
-@@ -2118,8 +2157,13 @@
- for (j = i; j < (i + pages); j++)
- {
- nv_verify_page_mappings(at->page_table[j], NV_ALLOC_MAPPING(at->flags));
-+#if defined(NV_VM_INSERT_PAGE_PRESENT)
-+ if (NV_VM_INSERT_PAGE(vma, start,
-+ NV_GET_PAGE_STRUCT(at->page_table[j]->phys_addr)))
-+#else
- if (NV_REMAP_PAGE_RANGE(start, at->page_table[j]->phys_addr,
- PAGE_SIZE, vma->vm_page_prot))
-+#endif
- {
- NV_ATOMIC_DEC(at->usage_count);
- return -EAGAIN;
-@@ -2429,9 +2473,9 @@
- mod_timer(&nvl->rc_timer, jiffies + HZ); /* set another timeout in 1 second */
- }
-
--#if defined(NV_PM_SUPPORT_APM)
-+#if defined(NV_PM_SUPPORT_OLD_STYLE_APM)
- /* kernel calls us with a power management event */
--int
-+static int
- nv_kern_apm_event(
- struct pm_dev *dev,
- pm_request_t rqst,
-@@ -2466,7 +2510,6 @@
-
- switch (rqst)
- {
--#if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
- case PM_RESUME:
- nv_printf(NV_DBG_INFO, "NVRM: APM: received resume event\n");
- status = rm_power_management(nv, 0, NV_PM_APM_RESUME);
-@@ -2476,15 +2519,12 @@
- nv_printf(NV_DBG_INFO, "NVRM: APM: received suspend event\n");
- status = rm_power_management(nv, 0, NV_PM_APM_SUSPEND);
- break;
--#endif
-
--#if defined(KERNEL_2_4)
- // 2.4 kernels sent a PM_SAVE_STATE request when powering down via
- // ACPI. just ignore it and return success so the power down works
- case PM_SAVE_STATE:
- status = RM_OK;
- break;
--#endif
-
- default:
- nv_printf(NV_DBG_WARNINGS, "NVRM: APM: unsupported event: %d\n", rqst);
-@@ -2496,7 +2536,7 @@
-
- return status;
- }
--#endif
-+#endif /* defined(NV_PM_SUPPORT_OLD_STYLE_APM) */
-
- /*
- ** nv_kern_ctl_open
-@@ -3739,6 +3779,7 @@
- nvl = &nv_linux_devices[num_nv_devices];
- nv = NV_STATE_PTR(nvl);
-
-+ pci_set_drvdata(dev, (void *)nvl);
- nvl->dev = dev;
- nv->vendor_id = dev->vendor;
- nv->device_id = dev->device;
-@@ -3816,11 +3857,10 @@
- #endif
- }
-
--#if defined(NV_PM_SUPPORT_ACPI)
-+#if defined(NV_PM_SUPPORT_DEVICE_DRIVER_MODEL)
-
--int
--nv_acpi_event
--(
-+static int
-+nv_power_management(
- struct pci_dev *dev,
- u32 state
- )
-@@ -3828,70 +3868,77 @@
- nv_state_t *nv;
- nv_linux_state_t *lnv = NULL;
- int status = RM_OK;
-- U032 i;
-
-- nv_printf(NV_DBG_INFO, "NVRM: nv_acpi_event: %d\n", state);
--
-- for (i = 0; i < num_nv_devices; i++)
-- {
-- if (nv_linux_devices[i].dev == dev)
-- {
-- lnv = &nv_linux_devices[i];
-- break;
-- }
-- }
-+ nv_printf(NV_DBG_INFO, "NVRM: nv_power_management: %d\n", state);
-+ lnv = pci_get_drvdata(dev);
-
- if ((!lnv) || (lnv->dev != dev))
- {
-- nv_printf(NV_DBG_WARNINGS, "NVRM: ACPI: invalid device!\n");
-+ nv_printf(NV_DBG_WARNINGS, "NVRM: PM: invalid device!\n");
- return -1;
- }
-
- nv = NV_STATE_PTR(lnv);
-+ nv_verify_pci_config(NV_STATE_PTR(lnv), TRUE);
-
- switch (state)
- {
-- case PM_SUSPEND_MEM:
-+#if defined(NV_PM_SUPPORT_NEW_STYLE_APM)
-+ case PCI_D3hot:
-+ nv_printf(NV_DBG_INFO, "NVRM: APM: received suspend event\n");
-+ status = rm_power_management(nv, 0, NV_PM_APM_SUSPEND);
-+ break;
-+
-+ case PCI_D0:
-+ nv_printf(NV_DBG_INFO, "NVRM: APM: received resume event\n");
-+ status = rm_power_management(nv, 0, NV_PM_APM_RESUME);
-+ break;
-+#else
-+ case PCI_D3hot:
- nv_printf(NV_DBG_INFO, "NVRM: ACPI: received suspend event\n");
- status = rm_power_management(nv, 0, NV_PM_ACPI_STANDBY);
- break;
-
-- case PM_SUSPEND_ON:
-+ case PCI_D0:
- nv_printf(NV_DBG_INFO, "NVRM: ACPI: received resume event\n");
- status = rm_power_management(nv, 0, NV_PM_ACPI_RESUME);
- break;
--
-+#endif
- default:
-- nv_printf(NV_DBG_WARNINGS, "NVRM: ACPI: unsupported event: %d\n", state);
-+ nv_printf(NV_DBG_WARNINGS, "NVRM: PM: unsupported event: %d\n", state);
- return -1;
- }
-
- if (status != RM_OK)
-- nv_printf(NV_DBG_ERRORS, "NVRM: ACPI: failed event: %d\n", state);
-+ nv_printf(NV_DBG_ERRORS, "NVRM: PM: failed event: %d\n", state);
-
- return status;
- }
-
--int
--nv_kern_acpi_standby
--(
-- struct pci_dev *dev,
-- u32 state
-+static int nv_kern_suspend(
-+ struct pci_dev *dev,
-+ pm_message_t state
- )
- {
-- return nv_acpi_event(dev, state);
-+ int power_state = -1;
-+
-+#if !defined(NV_PM_MESSAGE_T_PRESENT)
-+ power_state = state;
-+#elif defined(NV_PCI_CHOOSE_STATE_PRESENT)
-+ power_state = pci_choose_state(dev, state);
-+#endif
-+
-+ return nv_power_management(dev, power_state);
- }
-
--int
--nv_kern_acpi_resume
--(
-+static int nv_kern_resume(
- struct pci_dev *dev
- )
- {
-- return nv_acpi_event(dev, PM_SUSPEND_ON);
-+ return nv_power_management(dev, PCI_D0);
- }
-
--#endif
-+#endif /* defined(NV_PM_SUPPORT_DEVICE_DRIVER_MODEL) */
-
- void* NV_API_CALL nv_get_adapter_state(
- U016 bus,
+++ /dev/null
---- NVIDIA-Linux-x86-1.0-6111-pkg1/usr/src/nv/nv.c.orig 2004-10-27 18:24:52.617102752 +0200
-+++ NVIDIA-Linux-x86-1.0-6111-pkg1/usr/src/nv/nv.c 2004-10-27 18:26:34.998538408 +0200
-@@ -1225,6 +1225,7 @@
- {
- nv_state_t *nv = NV_STATE_PTR(&nv_linux_devices[i]);
- release_mem_region(nv->bar.regs.address, nv->bar.regs.size);
-+ pci_disable_device(nv_linux_devices[i].dev);
- }
- }
-
-@@ -3517,6 +3518,28 @@
- return -1;
- }
-
-+ // enable io, mem, and bus-mastering in pci config space
-+ if (pci_enable_device(dev) != 0)
-+ {
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: pci_enable_device failed, aborting\n");
-+ return -1;
-+ }
-+
-+ // request ownership of our bars
-+ // keeps other drivers from banging our registers.
-+ // only do this for registers, as vesafb requests our framebuffer and will
-+ // keep us from working properly
-+ if (!request_mem_region(dev->resource[0].start,
-+ dev->resource[0].end - dev->resource[0].start + 1,
-+ "nvidia"))
-+ {
-+ nv_printf(NV_DBG_ERRORS,
-+ "NVRM: pci_request_regions failed, aborting\n");
-+ goto err_disable_dev;
-+ }
-+ pci_set_master(dev);
-+
- /* initialize bus-dependent config state */
- nvl = &nv_linux_devices[num_nv_devices];
- nv = NV_STATE_PTR(nvl);
-@@ -3546,7 +3569,7 @@
- nv_printf(NV_DBG_ERRORS, "NVRM: Please check your BIOS settings. \n");
- nv_printf(NV_DBG_ERRORS, "NVRM: [Plug & Play OS ] should be set to NO \n");
- nv_printf(NV_DBG_ERRORS, "NVRM: [Assign IRQ to VGA] should be set to YES \n");
-- return -1;
-+ goto err_zero_dev;
- }
-
- /* sanity check the IO apertures */
-@@ -3570,39 +3593,9 @@
- nv->bar.fb.address, nv->bar.fb.size);
- }
-
-- /* Clear out the data */
-- os_mem_set(nvl, 0, sizeof(nv_linux_state_t));
--
-- return -1;
-- }
--
-- // request ownership of our bars
-- // keeps other drivers from banging our registers.
-- // only do this for registers, as vesafb requests our framebuffer and will
-- // keep us from working properly
-- if (!request_mem_region(nv->bar.regs.address, nv->bar.regs.size, "nvidia"))
-- {
-- nv_printf(NV_DBG_ERRORS,
-- "NVRM: pci_request_regions failed, aborting\n");
--
-- /* Clear out the data */
-- os_mem_set(nvl, 0, sizeof(nv_linux_state_t));
--
-- return -1;
-+ goto err_zero_dev;
- }
-
-- // enable io, mem, and bus-mastering in pci config space
-- if (pci_enable_device(dev) != 0)
-- {
-- nv_printf(NV_DBG_ERRORS,
-- "NVRM: pci_enable_device failed, aborting\n");
--
-- pci_release_regions(dev);
-- os_mem_set(nvl, 0, sizeof(nv_linux_state_t));
--
-- return -1;
-- }
-- pci_set_master(nvl->dev);
-
- #if defined(NV_BUILD_NV_PAT_SUPPORT)
- if (nvos_find_pci_express_capability(nvl->dev))
-@@ -3619,13 +3612,7 @@
- if (nv->bar.regs.map == NULL)
- {
- nv_printf(NV_DBG_ERRORS, "NVRM: failed to map registers!!\n");
--
-- pci_release_regions(dev);
--
-- /* Clear out the data */
-- os_mem_set(nvl, 0, sizeof(nv_linux_state_t));
--
-- return -1;
-+ goto err_zero_dev;
- }
- nv->flags |= NV_FLAG_MAP_REGS_EARLY;
- #endif
-@@ -3642,6 +3629,15 @@
- num_nv_devices++;
-
- return 0;
-+
-+err_zero_dev:
-+ os_mem_set(nvl, 0, sizeof(nv_linux_state_t));
-+ release_mem_region(dev->resource[0].start,
-+ dev->resource[0].end - dev->resource[0].start + 1);
-+
-+err_disable_dev:
-+ pci_disable_device(dev);
-+ return -1;
- }
-
- int NV_API_CALL nv_no_incoherent_mappings
+++ /dev/null
-diff -uNr NVIDIA-Linux-x86-1.0-5336-pkg1/usr/src/nv/nv.c NVIDIA-Linux-x86-1.0-5336-pkg1.fixed/usr/src/nv/nv.c
---- NVIDIA-Linux-x86-1.0-5336-pkg1/usr/src/nv/nv.c 2004-01-15 04:29:11.000000000 +0100
-+++ NVIDIA-Linux-x86-1.0-5336-pkg1.fixed/usr/src/nv/nv.c 2004-02-17 20:53:36.000000000 +0100
-@@ -1496,6 +1496,7 @@
- .open = nv_kern_vma_open,
- .close = nv_kern_vma_release, /* "close" */
- .nopage = nv_kern_vma_nopage,
-+ .populate = 0
- };
-
- static nv_file_private_t *
---- NVIDIA-Linux-x86_64-1.0-8178-pkg1/usr/src/nv/conftest.sh.orig 2005-12-15 02:34:40.000000000 +0100
-+++ NVIDIA-Linux-x86_64-1.0-8178-pkg1/usr/src/nv/conftest.sh 2006-01-26 19:21:46.000000000 +0100
-@@ -23,7 +23,7 @@
-
- CFLAGS="-D__KERNEL__ \
- -nostdinc -isystem $ISYSTEM \
---Werror -Wimplicit-function-declaration"
-+-Werror-implicit-function-declaration"
-
- if [ "$OUTPUT" != "$SOURCES" ]; then
- ARCH=`uname -m | sed -e 's/i.86/i386/'`
+++ /dev/null
---- NVIDIA-Linux-x86-1.0-6111-pkg1/usr/src/nv/nv.c.orig 2004-10-27 18:26:34.998538408 +0200
-+++ NVIDIA-Linux-x86-1.0-6111-pkg1/usr/src/nv/nv.c 2004-10-27 18:27:13.447693248 +0200
-@@ -3689,9 +3689,16 @@
- return -1;
- }
-
-+ // Fix up problems with PM_SAVE_STATE being removed from 2.6.9
-+ #ifdef PM_SAVE_STATE
-+ #define PM_TMP PM_SAVE_STATE
-+ #else
-+ #define PM_TMP PM_SUSPEND
-+ #endif
-+
- switch (state)
- {
-- case PM_SAVE_STATE:
-+ case PM_TMP:
- nv_printf(NV_DBG_INFO, "NVRM: ACPI: received standby event\n");
- status = rm_power_management(nv, 0, NV_PM_ACPI_STANDBY);
- break;