Subversion Repositories Kolibri OS

Rev

Rev 5271 | Rev 6131 | 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
#endif
65
 
66
void
67
drm_clflush_pages(struct page *pages[], unsigned long num_pages)
68
{
4293 Serge 69
    uint8_t *pva;
4104 Serge 70
    unsigned int i, j;
71
 
4293 Serge 72
    pva = AllocKernelSpace(4096);
4104 Serge 73
 
4293 Serge 74
    if(pva != NULL)
4104 Serge 75
    {
76
        dma_addr_t *src, *dst;
77
        u32 count;
78
 
79
        for (i = 0; i < num_pages; i++)
80
        {
81
            mb();
4293 Serge 82
            MapPage(pva, page_to_phys(pages[i]), 0x001);
4104 Serge 83
            for (j = 0; j < PAGE_SIZE; j += x86_clflush_size)
4293 Serge 84
                clflush(pva + j);
4104 Serge 85
        }
4293 Serge 86
        FreeKernelSpace(pva);
4104 Serge 87
    }
4293 Serge 88
    mb();
4104 Serge 89
}
90
EXPORT_SYMBOL(drm_clflush_pages);
91
 
92
void
93
drm_clflush_sg(struct sg_table *st)
94
{
4539 Serge 95
    struct sg_page_iter sg_iter;
4293 Serge 96
    struct page *page;
4104 Serge 97
 
4293 Serge 98
    uint8_t *pva;
99
    unsigned int i;
100
 
101
    pva = AllocKernelSpace(4096);
102
    if( pva != NULL)
103
    {
4539 Serge 104
        mb();
105
        for_each_sg_page(st->sgl, &sg_iter, st->nents, 0)
4293 Serge 106
        {
107
            page = sg_page_iter_page(&sg_iter);
4104 Serge 108
 
4293 Serge 109
            MapPage(pva,page_to_phys(page), 0x001);
4104 Serge 110
 
4293 Serge 111
            for (i = 0; i < PAGE_SIZE; i += x86_clflush_size)
112
                clflush(pva + i);
113
        };
114
        FreeKernelSpace(pva);
115
    };
116
    mb();
4104 Serge 117
}
118
EXPORT_SYMBOL(drm_clflush_sg);
119
 
4293 Serge 120
#if 0
4104 Serge 121
void
6084 serge 122
drm_clflush_virt_range(void *addr, unsigned long length)
4104 Serge 123
{
124
#if defined(CONFIG_X86)
125
	if (cpu_has_clflush) {
6084 serge 126
		const int size = boot_cpu_data.x86_clflush_size;
127
		void *end = addr + length;
128
		addr = (void *)(((unsigned long)addr) & -size);
4104 Serge 129
		mb();
6084 serge 130
		for (; addr < end; addr += size)
131
			clflushopt(addr);
4104 Serge 132
		mb();
133
		return;
134
	}
135
 
6084 serge 136
	if (wbinvd_on_all_cpus())
4104 Serge 137
		printk(KERN_ERR "Timed out waiting for cache flush.\n");
138
#else
139
	printk(KERN_ERR "Architecture has no drm_cache.c support\n");
140
	WARN_ON_ONCE(1);
141
#endif
142
}
143
EXPORT_SYMBOL(drm_clflush_virt_range);
144
 
145
#endif