Subversion Repositories Kolibri OS

Rev

Rev 4539 | Rev 6084 | Go to most recent revision | Details | Compare with Previous | 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
 
4293 Serge 36
 
4104 Serge 37
#if 0
38
static void
39
drm_clflush_page(struct page *page)
40
{
41
	uint8_t *page_virtual;
42
	unsigned int i;
43
	const int size = boot_cpu_data.x86_clflush_size;
44
 
45
	if (unlikely(page == NULL))
46
		return;
47
 
48
	page_virtual = kmap_atomic(page);
49
	for (i = 0; i < PAGE_SIZE; i += size)
50
		clflush(page_virtual + i);
51
	kunmap_atomic(page_virtual);
52
}
53
 
54
static void drm_cache_flush_clflush(struct page *pages[],
55
				    unsigned long num_pages)
56
{
57
	unsigned long i;
58
 
59
	mb();
60
	for (i = 0; i < num_pages; i++)
61
		drm_clflush_page(*pages++);
62
	mb();
63
}
64
 
65
static void
66
drm_clflush_ipi_handler(void *null)
67
{
68
	wbinvd();
69
}
70
#endif
71
 
72
void
73
drm_clflush_pages(struct page *pages[], unsigned long num_pages)
74
{
4293 Serge 75
    uint8_t *pva;
4104 Serge 76
    unsigned int i, j;
77
 
4293 Serge 78
    pva = AllocKernelSpace(4096);
4104 Serge 79
 
4293 Serge 80
    if(pva != NULL)
4104 Serge 81
    {
82
        dma_addr_t *src, *dst;
83
        u32 count;
84
 
85
        for (i = 0; i < num_pages; i++)
86
        {
87
            mb();
4293 Serge 88
            MapPage(pva, page_to_phys(pages[i]), 0x001);
4104 Serge 89
            for (j = 0; j < PAGE_SIZE; j += x86_clflush_size)
4293 Serge 90
                clflush(pva + j);
4104 Serge 91
        }
4293 Serge 92
        FreeKernelSpace(pva);
4104 Serge 93
    }
4293 Serge 94
    mb();
4104 Serge 95
}
96
EXPORT_SYMBOL(drm_clflush_pages);
97
 
98
void
99
drm_clflush_sg(struct sg_table *st)
100
{
4539 Serge 101
    struct sg_page_iter sg_iter;
4293 Serge 102
    struct page *page;
4104 Serge 103
 
4293 Serge 104
    uint8_t *pva;
105
    unsigned int i;
106
 
107
    pva = AllocKernelSpace(4096);
108
    if( pva != NULL)
109
    {
4539 Serge 110
        mb();
111
        for_each_sg_page(st->sgl, &sg_iter, st->nents, 0)
4293 Serge 112
        {
113
            page = sg_page_iter_page(&sg_iter);
4104 Serge 114
 
4293 Serge 115
            MapPage(pva,page_to_phys(page), 0x001);
4104 Serge 116
 
4293 Serge 117
            for (i = 0; i < PAGE_SIZE; i += x86_clflush_size)
118
                clflush(pva + i);
119
        };
120
        FreeKernelSpace(pva);
121
    };
122
    mb();
4104 Serge 123
}
124
EXPORT_SYMBOL(drm_clflush_sg);
125
 
4293 Serge 126
#if 0
4104 Serge 127
void
128
drm_clflush_virt_range(char *addr, unsigned long length)
129
{
130
#if defined(CONFIG_X86)
131
	if (cpu_has_clflush) {
132
		char *end = addr + length;
133
		mb();
134
		for (; addr < end; addr += boot_cpu_data.x86_clflush_size)
135
			clflush(addr);
136
		clflush(end - 1);
137
		mb();
138
		return;
139
	}
140
 
141
	if (on_each_cpu(drm_clflush_ipi_handler, NULL, 1) != 0)
142
		printk(KERN_ERR "Timed out waiting for cache flush.\n");
143
#else
144
	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
145
	WARN_ON_ONCE(1);
146
#endif
147
}
148
EXPORT_SYMBOL(drm_clflush_virt_range);
149
 
150
#endif