diff options
Diffstat (limited to 'drivers/gpu/pvr/mutils.c')
-rw-r--r-- | drivers/gpu/pvr/mutils.c | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/drivers/gpu/pvr/mutils.c b/drivers/gpu/pvr/mutils.c new file mode 100644 index 00000000000..83eab51bb1d --- /dev/null +++ b/drivers/gpu/pvr/mutils.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /********************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful but, except | ||
10 | * as otherwise stated in writing, without any warranty; without even the | ||
11 | * implied warranty of merchantability or fitness for a particular purpose. | ||
12 | * See the GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in | ||
19 | * the file called "COPYING". | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Imagination Technologies Ltd. <gpl-support@imgtec.com> | ||
23 | * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK | ||
24 | * | ||
25 | ******************************************************************************/ | ||
26 | |||
27 | #ifndef AUTOCONF_INCLUDED | ||
28 | #include <linux/config.h> | ||
29 | #endif | ||
30 | #include <linux/version.h> | ||
31 | |||
32 | #include <linux/spinlock.h> | ||
33 | #include <linux/mm.h> | ||
34 | #include <asm/page.h> | ||
35 | #include <asm/pgtable.h> | ||
36 | |||
37 | #include "img_defs.h" | ||
38 | #include "pvr_debug.h" | ||
39 | #include "mutils.h" | ||
40 | |||
41 | #if defined(SUPPORT_LINUX_X86_PAT) | ||
42 | #define PAT_LINUX_X86_WC 1 | ||
43 | |||
44 | #define PAT_X86_ENTRY_BITS 8 | ||
45 | |||
46 | #define PAT_X86_BIT_PWT 1U | ||
47 | #define PAT_X86_BIT_PCD 2U | ||
48 | #define PAT_X86_BIT_PAT 4U | ||
49 | #define PAT_X86_BIT_MASK (PAT_X86_BIT_PAT | PAT_X86_BIT_PCD | PAT_X86_BIT_PWT) | ||
50 | |||
51 | static IMG_BOOL g_write_combining_available = IMG_FALSE; | ||
52 | |||
53 | #define PROT_TO_PAT_INDEX(v, B) ((v & _PAGE_ ## B) ? PAT_X86_BIT_ ## B : 0) | ||
54 | |||
55 | static inline IMG_UINT | ||
56 | pvr_pat_index(pgprotval_t prot_val) | ||
57 | { | ||
58 | IMG_UINT ret = 0; | ||
59 | pgprotval_t val = prot_val & _PAGE_CACHE_MASK; | ||
60 | |||
61 | ret |= PROT_TO_PAT_INDEX(val, PAT); | ||
62 | ret |= PROT_TO_PAT_INDEX(val, PCD); | ||
63 | ret |= PROT_TO_PAT_INDEX(val, PWT); | ||
64 | |||
65 | return ret; | ||
66 | } | ||
67 | |||
68 | static inline IMG_UINT | ||
69 | pvr_pat_entry(u64 pat, IMG_UINT index) | ||
70 | { | ||
71 | return (IMG_UINT)(pat >> (index * PAT_X86_ENTRY_BITS)) & PAT_X86_BIT_MASK; | ||
72 | } | ||
73 | |||
74 | static IMG_VOID | ||
75 | PVRLinuxX86PATProbe(IMG_VOID) | ||
76 | { | ||
77 | |||
78 | if (cpu_has_pat) | ||
79 | { | ||
80 | u64 pat; | ||
81 | IMG_UINT pat_index; | ||
82 | IMG_UINT pat_entry; | ||
83 | |||
84 | PVR_TRACE(("%s: PAT available", __FUNCTION__)); | ||
85 | |||
86 | rdmsrl(MSR_IA32_CR_PAT, pat); | ||
87 | PVR_TRACE(("%s: Top 32 bits of PAT: 0x%.8x", __FUNCTION__, (IMG_UINT)(pat >> 32))); | ||
88 | PVR_TRACE(("%s: Bottom 32 bits of PAT: 0x%.8x", __FUNCTION__, (IMG_UINT)(pat))); | ||
89 | |||
90 | pat_index = pvr_pat_index(_PAGE_CACHE_WC); | ||
91 | PVR_TRACE(("%s: PAT index for write combining: %u", __FUNCTION__, pat_index)); | ||
92 | |||
93 | pat_entry = pvr_pat_entry(pat, pat_index); | ||
94 | PVR_TRACE(("%s: PAT entry for write combining: 0x%.2x (should be 0x%.2x)", __FUNCTION__, pat_entry, PAT_LINUX_X86_WC)); | ||
95 | |||
96 | #if defined(SUPPORT_LINUX_X86_WRITECOMBINE) | ||
97 | g_write_combining_available = (IMG_BOOL)(pat_entry == PAT_LINUX_X86_WC); | ||
98 | #endif | ||
99 | } | ||
100 | #if defined(DEBUG) | ||
101 | #if defined(SUPPORT_LINUX_X86_WRITECOMBINE) | ||
102 | if (g_write_combining_available) | ||
103 | { | ||
104 | PVR_TRACE(("%s: Write combining available via PAT", __FUNCTION__)); | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | PVR_TRACE(("%s: Write combining not available", __FUNCTION__)); | ||
109 | } | ||
110 | #else | ||
111 | PVR_TRACE(("%s: Write combining disabled in driver build", __FUNCTION__)); | ||
112 | #endif | ||
113 | #endif | ||
114 | } | ||
115 | |||
116 | pgprot_t | ||
117 | pvr_pgprot_writecombine(pgprot_t prot) | ||
118 | { | ||
119 | |||
120 | |||
121 | return (g_write_combining_available) ? | ||
122 | __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_MASK) | _PAGE_CACHE_WC) : pgprot_noncached(prot); | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | IMG_VOID | ||
127 | PVRLinuxMUtilsInit(IMG_VOID) | ||
128 | { | ||
129 | #if defined(SUPPORT_LINUX_X86_PAT) | ||
130 | PVRLinuxX86PATProbe(); | ||
131 | #endif | ||
132 | } | ||
133 | |||