Subversion Repositories Kolibri OS

Rev

Rev 4293 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4104 Serge 1
/**************************************************************************
2
 *
3
 * Copyright (c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
4
 * All Rights Reserved.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sub license, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * The above copyright notice and this permission notice (including the
15
 * next paragraph) shall be included in all copies or substantial portions
16
 * of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25
 *
26
 **************************************************************************/
27
/*
28
 * Authors: Thomas Hellström 
29
 */
30
 
31
#include 
32
#include 
33
 
34
extern int x86_clflush_size;
35
 
36
static inline void clflush(volatile void *__p)
37
{
38
    asm volatile("clflush %0" : "+m" (*(volatile char*)__p));
39
}
40
#if 0
41
static void
42
drm_clflush_page(struct page *page)
43
{
44
	uint8_t *page_virtual;
45
	unsigned int i;
46
	const int size = boot_cpu_data.x86_clflush_size;
47
 
48
	if (unlikely(page == NULL))
49
		return;
50
 
51
	page_virtual = kmap_atomic(page);
52
	for (i = 0; i < PAGE_SIZE; i += size)
53
		clflush(page_virtual + i);
54
	kunmap_atomic(page_virtual);
55
}
56
 
57
static void drm_cache_flush_clflush(struct page *pages[],
58
				    unsigned long num_pages)
59
{
60
	unsigned long i;
61
 
62
	mb();
63
	for (i = 0; i < num_pages; i++)
64
		drm_clflush_page(*pages++);
65
	mb();
66
}
67
 
68
static void
69
drm_clflush_ipi_handler(void *null)
70
{
71
	wbinvd();
72
}
73
#endif
74
 
75
void
76
drm_clflush_pages(struct page *pages[], unsigned long num_pages)
77
{
78
    uint8_t *page_virtual;
79
    unsigned int i, j;
80
 
81
    page_virtual = AllocKernelSpace(4096);
82
 
83
    if(page_virtual != NULL)
84
    {
85
        dma_addr_t *src, *dst;
86
        u32 count;
87
 
88
        for (i = 0; i < num_pages; i++)
89
        {
90
            mb();
91
//            asm volatile("mfence");
92
 
93
            MapPage(page_virtual,*pages++, 0x001);
94
            for (j = 0; j < PAGE_SIZE; j += x86_clflush_size)
95
                clflush(page_virtual + j);
96
            mb();
97
        }
98
        FreeKernelSpace(page_virtual);
99
    }
100
 
101
}
102
EXPORT_SYMBOL(drm_clflush_pages);
103
 
104
#if 0
105
void
106
drm_clflush_sg(struct sg_table *st)
107
{
108
#if defined(CONFIG_X86)
109
	if (cpu_has_clflush) {
110
		struct sg_page_iter sg_iter;
111
 
112
		mb();
113
		for_each_sg_page(st->sgl, &sg_iter, st->nents, 0)
114
			drm_clflush_page(sg_page_iter_page(&sg_iter));
115
		mb();
116
 
117
		return;
118
	}
119
 
120
	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
121
		printk(KERN_ERR "Timed out waiting for cache flush.\n");
122
#else
123
	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
124
	WARN_ON_ONCE(1);
125
#endif
126
}
127
EXPORT_SYMBOL(drm_clflush_sg);
128
 
129
void
130
drm_clflush_virt_range(char *addr, unsigned long length)
131
{
132
#if defined(CONFIG_X86)
133
	if (cpu_has_clflush) {
134
		char *end = addr + length;
135
		mb();
136
		for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
137
			clflush(addr);
138
		clflush(end - 1);
139
		mb();
140
		return;
141
	}
142
 
143
	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
144
		printk(KERN_ERR "Timed out waiting for cache flush.\n");
145
#else
146
	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
147
	WARN_ON_ONCE(1);
148
#endif
149
}
150
EXPORT_SYMBOL(drm_clflush_virt_range);
151
 
152
#endif