1 /*
2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
3 */
4
5 /*
6 * Copyright(c) 2006-2007 Tungsten Graphics, Inc., Cedar Park, TX., USA
7 * Copyright (c) 2009, 2012, Intel Corporation.
8 * All Rights Reserved.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files(the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sub license, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice(including the
19 * next paragraph) shall be included in all copies or substantial portions
20 * of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
28 * USE OR OTHER DEALINGS IN THE SOFTWARE.
29 *
30 */
31 /*
32 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
33 */
34
35 #include <sys/x86_archext.h>
36 #include <vm/seg_kmem.h>
37 #include "drmP.h"
38
39 extern void clflush_insn(caddr_t addr);
40 extern void mfence_insn(void);
41
42 static void
drm_clflush_page(caddr_t page)43 drm_clflush_page(caddr_t page)
44 {
45 unsigned int i;
46
47 if (page == NULL)
48 return;
49
50 for (i = 0; i < PAGE_SIZE; i += x86_clflush_size)
51 clflush_insn(page + i);
52 mfence_insn();
53 }
54
55 void
drm_clflush_pages(caddr_t * pages,unsigned long num_pages)56 drm_clflush_pages(caddr_t *pages, unsigned long num_pages)
57 {
58
59 if (is_x86_feature(x86_featureset, X86FSET_CLFSH)) {
60 unsigned long i;
61
62 for (i = 0; i < num_pages; i++)
63 drm_clflush_page(pages[i]);
64 }
65 }
66