Path: blob/21.2-virgl/src/intel/common/intel_clflush.h
4547 views
/*1* Copyright © 2017 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef INTEL_CLFLUSH_H24#define INTEL_CLFLUSH_H2526#define CACHELINE_SIZE 6427#define CACHELINE_MASK 632829static inline void30intel_clflush_range(void *start, size_t size)31{32void *p = (void *) (((uintptr_t) start) & ~CACHELINE_MASK);33void *end = start + size;3435while (p < end) {36__builtin_ia32_clflush(p);37p += CACHELINE_SIZE;38}39}4041static inline void42intel_flush_range(void *start, size_t size)43{44__builtin_ia32_mfence();45intel_clflush_range(start, size);46}4748static inline void49intel_invalidate_range(void *start, size_t size)50{51intel_clflush_range(start, size);5253/* Modern Atom CPUs (Baytrail+) have issues with clflush serialization,54* where mfence is not a sufficient synchronization barrier. We must55* double clflush the last cacheline. This guarantees it will be ordered56* after the preceding clflushes, and then the mfence guards against57* prefetches crossing the clflush boundary.58*59* See kernel commit 396f5d62d1a5fd99421855a08ffdef8edb43c76e60* ("drm: Restore double clflush on the last partial cacheline")61* and https://bugs.freedesktop.org/show_bug.cgi?id=92845.62*/63__builtin_ia32_clflush(start + size - 1);64__builtin_ia32_mfence();65}6667#endif686970