summaryrefslogtreecommitdiff
blob: 1c10533f234fdecb1bf6fddfc5c0318bd51f502d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
diff -ru usr/src/nv/Makefile.kbuild usr/src/nv.2419292/Makefile.kbuild
--- usr/src/nv/Makefile.kbuild	2008-05-19 00:37:02.000000000 -0700
+++ usr/src/nv.2419292/Makefile.kbuild	2008-05-21 12:07:57.551201274 -0700
@@ -166,10 +166,6 @@
 CFLAGS += -DNV_MAP_REGISTERS_EARLY
 endif
 
-ifeq ($(shell echo $(NV_BUILD_NV_PAT_SUPPORT)),1)
-CFLAGS += -DNV_BUILD_NV_PAT_SUPPORT
-endif
-
 ifneq ($(PATCHLEVEL), 4)
  COMPILE_TESTS = \
 	remap_page_range \
diff -ru usr/src/nv/Makefile.nvidia usr/src/nv.2419292/Makefile.nvidia
--- usr/src/nv/Makefile.nvidia	2008-05-19 00:37:02.000000000 -0700
+++ usr/src/nv.2419292/Makefile.nvidia	2008-05-21 12:08:08.771840702 -0700
@@ -56,10 +56,6 @@
 CFLAGS += -DNV_MAP_REGISTERS_EARLY
 endif
 
-ifeq ($(shell echo $(NV_BUILD_NV_PAT_SUPPORT)),1)
-CFLAGS += -DNV_BUILD_NV_PAT_SUPPORT
-endif
-
 INCLUDES += -I$(KERNEL_HEADERS)
 
 COMPILE_TESTS = \
diff -ru usr/src/nv/nv-linux.h usr/src/nv.2419292/nv-linux.h
--- usr/src/nv/nv-linux.h	2008-05-19 00:37:01.000000000 -0700
+++ usr/src/nv.2419292/nv-linux.h	2008-05-21 12:07:19.741046595 -0700
@@ -145,16 +145,19 @@
 #endif
 
 #if (defined(NVCPU_X86) || defined(NVCPU_X86_64)) && !defined(CONFIG_XEN)
-#define NV_BUILD_NV_PAT_SUPPORT 1
+#define NV_ENABLE_PAT_SUPPORT
 #endif
 
-#if defined(NV_BUILD_NV_PAT_SUPPORT)
-#include "pat.h"
+#define NV_PAT_MODE_DISABLED    0
+#define NV_PAT_MODE_KERNEL      1
+#define NV_PAT_MODE_BUILTIN     2
+
+extern int nv_pat_mode;
+
 #if defined(CONFIG_HOTPLUG_CPU)
 #include <linux/cpu.h>              /* CPU hotplug support              */
 #include <linux/notifier.h>         /* struct notifier_block, etc       */
 #endif
-#endif
 
 #if (defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE))
 #include <linux/i2c.h>
@@ -681,6 +684,13 @@
 #define nv_down(lock)                   down(&lock)
 #define nv_up(lock)                     up(&lock)
 
+#define NV_INIT_MUTEX(mutex)                       \
+    {                                              \
+        struct semaphore __mutex =                 \
+            __SEMAPHORE_INITIALIZER(*(mutex), 1);  \
+        *(mutex) = __mutex;                        \
+    }
+
 #if defined (KERNEL_2_4)
 #  define NV_IS_SUSER()                 suser()
 #  define NV_PCI_DEVICE_NAME(dev)       ((dev)->name)
@@ -1029,20 +1039,6 @@
         return new_prot;
     }
 #endif
-
-#if defined(NV_BUILD_NV_PAT_SUPPORT) && !defined (pgprot_writecombined)
-static inline pgprot_t pgprot_writecombined(pgprot_t old_prot)
-    {
-        pgprot_t new_prot = old_prot;
-        if (boot_cpu_data.x86 > 3)
-        {
-            pgprot_val(old_prot) &= ~(_PAGE_PCD | _PAGE_PWT);
-            new_prot = __pgprot(pgprot_val(old_prot) | _PAGE_WRTCOMB);
-        }
-        return new_prot;
-    }
-#endif
-
 #endif /* defined(NVCPU_X86) || defined(NVCPU_X86_64) */
 
 #if defined(KERNEL_2_4) && defined(NVCPU_X86) && !defined(pfn_to_page)
@@ -1142,8 +1138,6 @@
     struct semaphore at_lock;
 } nv_linux_state_t;
 
-extern int nv_pat_enabled;
-
 #if defined(NV_LINUX_ACPI_EVENTS_SUPPORTED)
 /*
  * acpi data storage structure
diff -ru usr/src/nv/nv-reg.h usr/src/nv.2419292/nv-reg.h
--- usr/src/nv/nv-reg.h	2008-05-19 00:37:01.000000000 -0700
+++ usr/src/nv.2419292/nv-reg.h	2008-05-21 12:07:23.313250167 -0700
@@ -471,6 +471,37 @@
 #define __NV_RM_EDGE_INTR_CHECK  RMEdgeIntrCheck
 #define NV_REG_RM_EDGE_INTR_CHECK NV_REG_STRING(__NV_RM_EDGE_INTR_CHECK)
 
+/*
+ * Option: UsePageAttributeTable
+ *
+ * Description:
+ *
+ * Enable/disable use of the page attribute table (PAT) available in
+ * modern x86/x86-64 processors to set the effective memory type of memory
+ * mappings to write-combining (WC). If disabled, the driver will fall
+ * back to using MTRRs, if possible.
+ *
+ * If enabled, an x86 processor with PAT support is present and the host
+ * system's Linux kernel did not configure one of the PAT entries to
+ * indicate the WC memory type, the driver will change the second entry in
+ * the PAT from its default (write-through (WT)) to WC at module load
+ * time. If the kernel did update one of the PAT entries, the driver will
+ * not modify the PAT.
+ *
+ * In both cases, the driver will honor attempts to map memory with the WC
+ * memory type by selecting the appropriate PAT entry using the correct
+ * set of PTE flags.
+ *
+ * Possible values:
+ *
+ * ~0 = use the NVIDIA driver's default logic (default)
+ *  1 = enable use of the PAT for WC mappings.
+ *  0 = disable use of the PAT for WC mappings.
+ */
+
+#define __NV_USE_PAGE_ATTRIBUTE_TABLE UsePageAttributeTable
+#define NV_USE_PAGE_ATTRIBUTE_TABLE NV_REG_STRING(__NV_USE_PAGE_ATTRIBUTE_TABLE)
+
 
 
 #if defined(NV_DEFINE_REGISTRY_KEY_TABLE)
@@ -495,6 +526,7 @@
 NV_DEFINE_REG_ENTRY(__NV_UPDATE_MEMORY_TYPES, ~0);
 NV_DEFINE_REG_ENTRY(__NV_USE_VBIOS, 1);
 NV_DEFINE_REG_ENTRY(__NV_RM_EDGE_INTR_CHECK, 1);
+NV_DEFINE_REG_ENTRY(__NV_USE_PAGE_ATTRIBUTE_TABLE, ~0);
 
 #if defined(NV_LINUX)
 NV_DEFINE_REG_STRING_ENTRY(__NV_REGISTRY_DWORDS, NULL);
@@ -540,6 +572,7 @@
     NV_DEFINE_PARAMS_TABLE_ENTRY(__NV_UPDATE_MEMORY_TYPES),
     NV_DEFINE_PARAMS_TABLE_ENTRY(__NV_USE_VBIOS),
     NV_DEFINE_PARAMS_TABLE_ENTRY(__NV_RM_EDGE_INTR_CHECK),
+    NV_DEFINE_PARAMS_TABLE_ENTRY(__NV_USE_PAGE_ATTRIBUTE_TABLE),
     {NULL, NULL, NULL}
 };
 
diff -ru usr/src/nv/nv.c usr/src/nv.2419292/nv.c
--- usr/src/nv/nv.c	2008-05-19 00:37:01.000000000 -0700
+++ usr/src/nv.2419292/nv.c	2008-05-21 12:07:28.313535114 -0700
@@ -22,10 +22,9 @@
 #endif
 
 #if defined(KERNEL_2_4) && (defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE))
-// weak linking?
 extern int i2c_add_adapter (struct i2c_adapter *) __attribute__ ((weak));
 extern int i2c_del_adapter (struct i2c_adapter *) __attribute__ ((weak));
-#endif // defined(KERNEL_2_4) && (defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE))
+#endif
 
 /*
  * our global state; one per device
@@ -41,14 +40,7 @@
 static struct pm_dev *apm_nv_dev[NV_MAX_DEVICES] = { 0 };
 #endif
 
-int nv_pat_enabled = 0;
-
-#if !defined(NV_BUILD_NV_PAT_SUPPORT)
-static int nv_disable_pat = 1;
-#else
-static int nv_disable_pat = 0;
-NV_MODULE_PARAMETER(nv_disable_pat);
-#endif
+int nv_pat_mode = NV_PAT_MODE_DISABLED;
 
 #if defined(NVCPU_X86) || defined(NVCPU_X86_64)
 NvU64 __nv_supported_pte_mask = ~_PAGE_NX;
@@ -611,7 +603,7 @@
     nv_state_t *nv;
     nv_linux_state_t *nvl;
 
-    proc_nvidia = create_proc_entry("nvidia", d_flags, proc_root_driver);
+    proc_nvidia = create_proc_entry("driver/nvidia", d_flags, NULL);
     if (!proc_nvidia)
         goto failed;
 
@@ -863,18 +855,20 @@
 static int   __nv_enable_pat_support   (void);
 static void  __nv_disable_pat_support  (void);
 
-#if defined(NV_BUILD_NV_PAT_SUPPORT)
+#if defined(NV_ENABLE_PAT_SUPPORT)
 /*
- * Private PAT support for use by the NVIDIA driver. This is an
- * interim solution until the kernel offers PAT support.
+ * Private PAT support for use by the NVIDIA driver. This is used on
+ * kernels that do not modify the PAT to include a write-combining
+ * entry.
  */
-static int   __check_pat_support       (void);
+static int   __determine_pat_mode      (void);
 static void  __nv_setup_pat_entries    (void *);
 static void  __nv_restore_pat_entries  (void *);
 
-#define NV_READ_PAT_ENTRIES(pat1, pat2)   rdmsr(IA32_CR_PAT, (pat1), (pat2))
-#define NV_WRITE_PAT_ENTRIES(pat1, pat2)  wrmsr(IA32_CR_PAT, (pat1), (pat2))
-#define NV_PAT_ENTRY(pat, index)          (((pat) & (0xff<<((index)*8)))>>((index)*8))
+#define NV_READ_PAT_ENTRIES(pat1, pat2)   rdmsr(0x277, (pat1), (pat2))
+#define NV_WRITE_PAT_ENTRIES(pat1, pat2)  wrmsr(0x277, (pat1), (pat2))
+#define NV_PAT_ENTRY(pat, index) \
+    (((pat) & (0xff << ((index)*8))) >> ((index)*8))
 
 static inline void __nv_disable_caches(unsigned long *cr4)
 {
@@ -895,39 +889,47 @@
     if (cr4 & 0x80) write_cr4(cr4);
 }
 
-static int __check_pat_support()
+static int __determine_pat_mode()
 {
     unsigned int pat1, pat2, i;
+    U008 PAT_WC_index;
 
-    if (!test_bit(X86_FEATURE_PAT, (volatile unsigned long *)&boot_cpu_data.x86_capability))
+    if (!test_bit(X86_FEATURE_PAT,
+            (volatile unsigned long *)&boot_cpu_data.x86_capability))
     {
         nv_printf(NV_DBG_ERRORS,
             "NVRM: CPU does not support the PAT, falling back to MTRRs.\n");
-        return 0;
+        return NV_PAT_MODE_DISABLED;
     }
 
     NV_READ_PAT_ENTRIES(pat1, pat2);
+    PAT_WC_index = 0xf;
 
     for (i = 0; i < 4; i++)
     {
-         // we plan to mark PAT entry 1 as WC. if it's already marked such,
-         // that's fine, since it would be no different than us setting it.
-         if ((i != 1) && NV_PAT_ENTRY(pat1, i) == 1)
-         {
-             nv_printf(NV_DBG_ERRORS, "NVRM: PAT index %d already configured for Write-Combining!\n", i);
-             nv_printf(NV_DBG_ERRORS, "NVRM: Aborting, due to PAT already being configured\n");
-             return 0;
-         }
-
-         if (NV_PAT_ENTRY(pat2, i) == 1)
-         {
-             nv_printf(NV_DBG_ERRORS, "NVRM: PAT index %d already configured for Write-Combining!\n", i + 4);
-             nv_printf(NV_DBG_ERRORS, "NVRM: Aborting, due to PAT already being configured\n");
-             return 0;
-         }
+        if (NV_PAT_ENTRY(pat1, i) == 0x01)
+        {
+            PAT_WC_index = i;
+            break;
+        }
+
+        if (NV_PAT_ENTRY(pat2, i) == 0x01)
+        {
+            PAT_WC_index = (i + 4);
+            break;
+        }
     }
 
-    return 1;
+    if (PAT_WC_index == 1)
+        return NV_PAT_MODE_KERNEL;
+    else if (PAT_WC_index != 0xf)
+    {
+        nv_printf(NV_DBG_ERRORS,
+            "NVRM: PAT configuration unsupported, falling back to MTRRs.\n");
+        return NV_PAT_MODE_DISABLED;
+    }
+    else
+        return NV_PAT_MODE_BUILTIN;
 }
 
 static unsigned long orig_pat1, orig_pat2;
@@ -978,19 +980,30 @@
     __nv_enable_caches(cr4);
     NV_RESTORE_FLAGS(eflags);
 }
-
-#endif /* defined(NV_BUILD_NV_PAT_SUPPORT) */
+#endif
 
 static int __nv_enable_pat_support()
 {
-#if defined(NV_BUILD_NV_PAT_SUPPORT)
+#if defined(NV_ENABLE_PAT_SUPPORT)
     unsigned long pat1, pat2;
 
-    if (nv_pat_enabled)
+    if (nv_pat_mode != NV_PAT_MODE_DISABLED)
         return 1;
 
-    if (!__check_pat_support())
-        return 0;
+    nv_pat_mode = __determine_pat_mode();
+
+    switch (nv_pat_mode)
+    {
+        case NV_PAT_MODE_DISABLED:
+            /* avoid the PAT if unavailable/unusable */
+            return 0;
+        case NV_PAT_MODE_KERNEL:
+            /* inherit the kernel's PAT layout */
+            return 1;
+        case NV_PAT_MODE_BUILTIN:
+            /* use builtin code to modify the PAT layout */
+            break;
+    }
 
     NV_READ_PAT_ENTRIES(orig_pat1, orig_pat2);
     nv_printf(NV_DBG_SETUP, "saved orig pats as 0x%lx 0x%lx\n", orig_pat1, orig_pat2);
@@ -1001,31 +1014,28 @@
         return 0;
     }
 
-    nv_pat_enabled = 1;
-
     NV_READ_PAT_ENTRIES(pat1, pat2);
     nv_printf(NV_DBG_SETUP, "changed pats to 0x%lx 0x%lx\n", pat1, pat2);
-#endif /* defined(NV_BUILD_NV_PAT_SUPPORT) */
-
+#endif
     return 1;
 }
 
 static void __nv_disable_pat_support()
 {
-#if defined(NV_BUILD_NV_PAT_SUPPORT)
+#if defined(NV_ENABLE_PAT_SUPPORT)
     unsigned long pat1, pat2;
 
-    if (!nv_pat_enabled)
+    if (nv_pat_mode != NV_PAT_MODE_BUILTIN)
         return;
 
     if (nv_execute_on_all_cpus(__nv_restore_pat_entries, NULL) != 0)
         return;
 
-    nv_pat_enabled = 0;
+    nv_pat_mode = NV_PAT_MODE_DISABLED;
 
     NV_READ_PAT_ENTRIES(pat1, pat2);
     nv_printf(NV_DBG_SETUP, "restored orig pats as 0x%lx 0x%lx\n", pat1, pat2);
-#endif /* defined(NV_BUILD_NV_PAT_SUPPORT) */
+#endif
 }
 
 #if defined(NV_CHANGE_PAGE_ATTR_BUG_PRESENT)
@@ -1273,7 +1283,7 @@
 #endif
 }
 
-#if defined(NV_BUILD_NV_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
+#if defined(NV_ENABLE_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
 static int
 nv_kern_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
 {
@@ -1305,8 +1315,7 @@
     .notifier_call = nv_kern_cpu_callback,
     .priority = 0
 };
-
-#endif /* defined(NV_BUILD_NV_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU) */
+#endif
 
 
 /***
@@ -1315,7 +1324,7 @@
 
 static int __init nvidia_init_module(void)
 {
-    int rc;
+    int rc, disable_pat = 0;
     U032 i, count, data;
     nv_state_t *nv = NV_STATE_PTR(&nv_ctl_device);
     nv_stack_t *sp = NULL;
@@ -1443,18 +1452,6 @@
         nv_printf(NV_DBG_ERRORS, "NVRM: pte cache allocation failed\n");
         goto failed;
     }
- 
-#if defined(NV_BUILD_NV_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
-    if (!nv_disable_pat)
-    {
-        if (register_hotcpu_notifier(&nv_hotcpu_nfb) != 0)
-        {
-            rc = -EIO;
-            nv_printf(NV_DBG_ERRORS, "NVRM: CPU hotplug notifier registration failed!\n");
-            goto failed;
-        }
-    }
-#endif
 
 #if defined(NV_SG_MAP_BUFFERS)
     rm_read_registry_dword(sp, nv, "NVreg", "RemapLimit", &nv_remap_limit);
@@ -1532,8 +1529,30 @@
 
     nvos_proc_add_warning_file("README", __README_warning);
 
-    if (!nv_disable_pat)
+    rc = rm_read_registry_dword(sp, nv,
+            "NVreg", NV_USE_PAGE_ATTRIBUTE_TABLE, &data);
+    if ((rc == 0) && ((int)data != ~0))
+    {
+        disable_pat = (data == 0);
+    }
+
+    if (!disable_pat)
+    {
         __nv_enable_pat_support();
+#if defined(NV_ENABLE_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
+        if (nv_pat_mode == NV_PAT_MODE_BUILTIN)
+        {
+            if (register_hotcpu_notifier(&nv_hotcpu_nfb) != 0)
+            {
+                __nv_disable_pat_support();
+                rc = -EIO;
+                nv_printf(NV_DBG_ERRORS,
+                        "NVRM: CPU hotplug notifier registration failed!\n");
+                goto failed;
+            }
+        }
+#endif
+    }
     else
     {
         nv_printf(NV_DBG_ERRORS,
@@ -1686,10 +1705,10 @@
     rm_unregister_compatible_ioctls(sp);
 #endif
 
-    if (nv_pat_enabled)
+    if (nv_pat_mode == NV_PAT_MODE_BUILTIN)
     {
         __nv_disable_pat_support();
-#if defined(NV_BUILD_NV_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
+#if defined(NV_ENABLE_PAT_SUPPORT) && defined(CONFIG_HOTPLUG_CPU)
         unregister_hotcpu_notifier(&nv_hotcpu_nfb);
 #endif
     }
@@ -1825,6 +1844,8 @@
     }
 }
 
+#if !defined(NV_VM_INSERT_PAGE_PRESENT)
+static
 struct page *nv_kern_vma_nopage(
     struct vm_area_struct *vma,
     unsigned long address,
@@ -1835,22 +1856,21 @@
 #endif
 )
 {
-#if !defined(NV_VM_INSERT_PAGE_PRESENT)
     struct page *page;
 
     page = pfn_to_page(vma->vm_pgoff);
     get_page(page);
 
     return page;
-#else
-    return NOPAGE_SIGBUS;
-#endif
 }
+#endif
 
 struct vm_operations_struct nv_vm_ops = {
     .open   = nv_kern_vma_open,
     .close  = nv_kern_vma_release,  /* "close" */
+#if !defined(NV_VM_INSERT_PAGE_PRESENT)
     .nopage = nv_kern_vma_nopage,
+#endif
 };
 
 static nv_file_private_t *
@@ -1864,7 +1884,7 @@
 
     memset(nvfp, 0, sizeof(nv_file_private_t));
 
-    sema_init(&nvfp->sp_lock, 1);
+    NV_INIT_MUTEX(&nvfp->sp_lock);
 
     // initialize this file's event queue
     init_waitqueue_head(&nvfp->waitqueue);
@@ -2214,11 +2234,12 @@
             break;
 #if defined(NVCPU_X86) || defined(NVCPU_X86_64)
         case NV_MEMORY_WRITECOMBINED:
-#if defined(NV_BUILD_NV_PAT_SUPPORT)
-            if (nv_pat_enabled &&
-                (memory_type != NV_MEMORY_TYPE_REGISTERS))
+#if defined(NV_ENABLE_PAT_SUPPORT)
+            if ((nv_pat_mode != NV_PAT_MODE_DISABLED) &&
+                    (memory_type != NV_MEMORY_TYPE_REGISTERS))
             {
-                *prot = pgprot_writecombined(*prot);
+                pgprot_val(*prot) &= ~(_PAGE_PSE | _PAGE_PCD | _PAGE_PWT);
+                *prot = __pgprot(pgprot_val(*prot) | _PAGE_PWT);
                 break;
             }
 #endif
@@ -2242,7 +2263,6 @@
             return 1;
 #endif
         case NV_MEMORY_CACHED:
-        //case NV_MEMORY_WRITEBACK:
 #if !defined(NVCPU_X86) && !defined(NVCPU_X86_64)
             if (memory_type != NV_MEMORY_TYPE_REGISTERS)
                 break;
@@ -2264,8 +2284,6 @@
             if (memory_type == NV_MEMORY_TYPE_SYSTEM)
                 break;
 #endif
-        //case NV_MEMORY_WRITETHRU:
-        //case NV_MEMORY_WRITEPROTECT:
         default:
             if(nv_ext_encode_caching(prot, cache_type, memory_type) == 0)
                 return 0;
@@ -3502,6 +3520,10 @@
     BOOL kern
 )
 {
+#if defined(NV_SET_PAGES_UC_PRESENT) && defined(NVCPU_X86)
+    nv_printf(NV_DBG_ERRORS,
+        "NVRM: can't translate address in nv_get_phys_address()!\n");
+#else
     struct mm_struct *mm;
     pgd_t *pgd = NULL;
     pmd_t *pmd = NULL;
@@ -3514,15 +3536,7 @@
         down_read(&mm->mmap_sem);
     }
     else
-    {
-#if defined(NV_SET_PAGES_UC_PRESENT) && defined(NVCPU_X86)
-        nv_printf(NV_DBG_ERRORS,
-            "NVRM: can't translate KVA in nv_get_phys_address()!\n");
-        return 0;
-#else
         mm = NULL;
-#endif
-    }
 
     pgd = NV_PGD_OFFSET(address, kern, mm);
     if (!NV_PGD_PRESENT(pgd))
@@ -3550,6 +3564,7 @@
 failed:
     if (!kern)
         up_read(&mm->mmap_sem);
+#endif
     return 0;
 }
 
@@ -3790,8 +3805,9 @@
 
     nv_init_lock(nvl->rm_lock);
 
-    sema_init(&nvl->ldata_lock, 1);
-    sema_init(&nvl->at_lock, 1);
+    NV_INIT_MUTEX(&nvl->ldata_lock);
+    NV_INIT_MUTEX(&nvl->at_lock);
+
     NV_ATOMIC_SET(nvl->usage_count, 0);
 
     nvl->rm_lock_cpu = -1;
diff -ru usr/src/nv/os-agp.c usr/src/nv.2419292/os-agp.c
--- usr/src/nv/os-agp.c	2008-05-19 00:37:01.000000000 -0700
+++ usr/src/nv.2419292/os-agp.c	2008-05-21 12:07:30.437656163 -0700
@@ -115,7 +115,7 @@
         goto release;
     }
 
-    if (!nv_pat_enabled)
+    if (nv_pat_mode == NV_PAT_MODE_DISABLED)
     {
 #ifdef CONFIG_MTRR
         /*
@@ -175,7 +175,7 @@
 
 failed:
 #ifdef CONFIG_MTRR
-    if (!nv_pat_enabled)
+    if (nv_pat_mode == NV_PAT_MODE_DISABLED)
         mtrr_del(-1, agp_info.aper_base, agp_info.aper_size << 20);
 #endif
 release:
@@ -205,7 +205,7 @@
     nvl = NV_GET_NVL_FROM_NV_STATE(nv);
 
 #ifdef CONFIG_MTRR
-    if (!nv_pat_enabled)
+    if (nv_pat_mode == NV_PAT_MODE_DISABLED)
         mtrr_del(-1, nv->agp.address, nv->agp.size);
 #endif
 
diff -ru usr/src/nv/os-interface.c usr/src/nv.2419292/os-interface.c
--- usr/src/nv/os-interface.c	2008-05-19 00:37:01.000000000 -0700
+++ usr/src/nv.2419292/os-interface.c	2008-05-21 12:07:33.365823028 -0700
@@ -1355,7 +1355,7 @@
 
 BOOL NV_API_CALL os_pat_supported(void)
 {
-    return nv_pat_enabled;
+    return (nv_pat_mode != NV_PAT_MODE_DISABLED);
 }
 
 void NV_API_CALL os_dump_stack()