| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: drm_cache.c,v 1.7 2015/10/17 15:13:19 jmcneill Exp $ */ | | 1 | /* $NetBSD: drm_cache.c,v 1.8 2015/10/17 21:11:56 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,87 +20,98 @@ | | | @@ -20,87 +20,98 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: drm_cache.c,v 1.7 2015/10/17 15:13:19 jmcneill Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: drm_cache.c,v 1.8 2015/10/17 21:11:56 jmcneill Exp $"); |
34 | | | 34 | |
| | | 35 | #include <sys/param.h> |
35 | #include <sys/types.h> | | 36 | #include <sys/types.h> |
36 | #include <sys/xcall.h> | | 37 | #include <sys/xcall.h> |
37 | | | 38 | |
38 | #include <uvm/uvm_extern.h> | | 39 | #include <uvm/uvm_extern.h> |
39 | | | 40 | |
40 | #include <linux/mm_types.h> | | 41 | #include <linux/mm_types.h> |
41 | | | 42 | |
42 | #include <drm/drmP.h> | | 43 | #include <drm/drmP.h> |
43 | | | 44 | |
| | | 45 | #if !defined(__arm__) |
| | | 46 | #define DRM_CLFLUSH 1 |
| | | 47 | #endif |
| | | 48 | |
| | | 49 | #if defined(DRM_CLFLUSH) |
44 | static bool drm_md_clflush_finegrained_p(void); | | 50 | static bool drm_md_clflush_finegrained_p(void); |
45 | static void drm_md_clflush_all(void); | | 51 | static void drm_md_clflush_all(void); |
46 | static void drm_md_clflush_page(struct page *); | | 52 | static void drm_md_clflush_page(struct page *); |
47 | static void drm_md_clflush_virt_range(const void *, size_t); | | 53 | static void drm_md_clflush_virt_range(const void *, size_t); |
| | | 54 | #endif |
48 | | | 55 | |
49 | void | | 56 | void |
50 | drm_clflush_pages(struct page **pages, unsigned long npages) | | 57 | drm_clflush_pages(struct page **pages, unsigned long npages) |
51 | { | | 58 | { |
52 | | | 59 | #if defined(DRM_CLFLUSH) |
53 | if (drm_md_clflush_finegrained_p()) { | | 60 | if (drm_md_clflush_finegrained_p()) { |
54 | while (npages--) | | 61 | while (npages--) |
55 | drm_md_clflush_page(pages[npages]); | | 62 | drm_md_clflush_page(pages[npages]); |
56 | } else { | | 63 | } else { |
57 | drm_md_clflush_all(); | | 64 | drm_md_clflush_all(); |
58 | } | | 65 | } |
| | | 66 | #endif |
59 | } | | 67 | } |
60 | | | 68 | |
61 | void | | 69 | void |
62 | drm_clflush_pglist(struct pglist *list) | | 70 | drm_clflush_pglist(struct pglist *list) |
63 | { | | 71 | { |
64 | | | 72 | #if defined(DRM_CLFLUSH) |
65 | if (drm_md_clflush_finegrained_p()) { | | 73 | if (drm_md_clflush_finegrained_p()) { |
66 | struct vm_page *page; | | 74 | struct vm_page *page; |
67 | | | 75 | |
68 | TAILQ_FOREACH(page, list, pageq.queue) | | 76 | TAILQ_FOREACH(page, list, pageq.queue) |
69 | drm_md_clflush_page(container_of(page, struct page, | | 77 | drm_md_clflush_page(container_of(page, struct page, |
70 | p_vmp)); | | 78 | p_vmp)); |
71 | } else { | | 79 | } else { |
72 | drm_md_clflush_all(); | | 80 | drm_md_clflush_all(); |
73 | } | | 81 | } |
| | | 82 | #endif |
74 | } | | 83 | } |
75 | | | 84 | |
76 | void | | 85 | void |
77 | drm_clflush_page(struct page *page) | | 86 | drm_clflush_page(struct page *page) |
78 | { | | 87 | { |
79 | | | 88 | #if defined(DRM_CLFLUSH) |
80 | if (drm_md_clflush_finegrained_p()) | | 89 | if (drm_md_clflush_finegrained_p()) |
81 | drm_md_clflush_page(page); | | 90 | drm_md_clflush_page(page); |
82 | else | | 91 | else |
83 | drm_md_clflush_all(); | | 92 | drm_md_clflush_all(); |
| | | 93 | #endif |
84 | } | | 94 | } |
85 | | | 95 | |
86 | void | | 96 | void |
87 | drm_clflush_virt_range(const void *vaddr, size_t nbytes) | | 97 | drm_clflush_virt_range(const void *vaddr, size_t nbytes) |
88 | { | | 98 | { |
89 | | | 99 | #if defined(DRM_CLFLUSH) |
90 | if (drm_md_clflush_finegrained_p()) | | 100 | if (drm_md_clflush_finegrained_p()) |
91 | drm_md_clflush_virt_range(vaddr, nbytes); | | 101 | drm_md_clflush_virt_range(vaddr, nbytes); |
92 | else | | 102 | else |
93 | drm_md_clflush_all(); | | 103 | drm_md_clflush_all(); |
| | | 104 | #endif |
94 | } | | 105 | } |
95 | | | 106 | |
96 | #if defined(__i386__) || defined(__x86_64__) | | 107 | #if defined(__i386__) || defined(__x86_64__) |
97 | | | 108 | |
98 | #include <machine/cpufunc.h> | | 109 | #include <machine/cpufunc.h> |
99 | | | 110 | |
100 | static bool | | 111 | static bool |
101 | drm_md_clflush_finegrained_p(void) | | 112 | drm_md_clflush_finegrained_p(void) |
102 | { | | 113 | { |
103 | return ISSET(cpu_info_primary.ci_feat_val[0], CPUID_CFLUSH); | | 114 | return ISSET(cpu_info_primary.ci_feat_val[0], CPUID_CFLUSH); |
104 | } | | 115 | } |
105 | | | 116 | |
106 | static void | | 117 | static void |