XenevaOS
Loading...
Searching...
No Matches
cache.h
Go to the documentation of this file.
1#ifndef __ASM_CACHE_H
2#define __ASM_CACHE_H
3
4/*
5 * DCL <asm/cache.h> -- cache-line geometry for aarch64.
6 *
7 * mainline gets these from arch/arm64/include/asm/cache.h, which is not
8 * present here (there is no arch/ tree in BaseHdr at all; asm/ holds only the
9 * few headers a ported source names directly). The values are the ones the
10 * architecture guarantees: AArch64 has a 64-byte D-cache line, so
11 * L1_CACHE_SHIFT is 6.
12 *
13 * They are not decoration. virtio-rng.c sizes its entropy buffer as
14 *
15 * #if SMP_CACHE_BYTES < 32
16 * u8 data[32];
17 * #else
18 * u8 data[SMP_CACHE_BYTES];
19 * #endif
20 *
21 * so this number decides whether the driver allocates 32 or 64 bytes, and
22 * the size flows into the device's minimum read and into copy_data()'s clamp.
23 * mainline's comment calls it "minimal size returned by rng_buffer_size()".
24 */
25
26#ifndef L1_CACHE_SHIFT
27#define L1_CACHE_SHIFT 6
28#endif
29
30#ifndef L1_CACHE_BYTES
31#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
32#endif
33
34#ifndef L1_CACHE_ALIGN
35#define L1_CACHE_ALIGN(x) (((x) + (L1_CACHE_BYTES - 1)) & ~(L1_CACHE_BYTES - 1))
36#endif
37
38/*
39 * ARCH_DMA_MINALIGN -- the alignment DMA-capable allocations must have, which
40 * mainline takes from arch/arm64/include/asm/cache.h. A number here rather
41 * than mainline's `____cacheline_aligned` attribute spelling: both call sites
42 * in this tree wrap it in __aligned(), and `__aligned(__attribute__(...))`
43 * does not parse. L1_CACHE_BYTES (64) is the same value mainline's spelling
44 * produces, which is the point -- an allocation DMA'd into must start on a
45 * cache line or the device and the CPU disagree about which line it is.
46 *
47 * The one caller is drm_managed.c:56, `u8 __aligned(ARCH_DMA_MINALIGN) data[]`
48 * inside struct drmres, so a managed allocation gets its payload on a line of
49 * its own.
50 *
51 * ARCH_HAS_DMA_MINALIGN is deliberately *not* defined alongside it.
52 * dma-mapping.h tests that one and switches ____dma_from_device_aligned to
53 * the aligned spelling; flipping it would change virtio-rng.c's buffer
54 * layout, which the note there records as a decision rather than an omission.
55 */
56#ifndef ARCH_DMA_MINALIGN
57#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
58#endif
59
60#endif /* __ASM_CACHE_H */