1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* Redistribution and use in source and binary forms, with
* or without modification, are permitted provided that the
* following conditions are met:
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and
* the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of ARM nor the names of its
* contributors may be used to endorse or promote products
* derived from this software without specific prior written
* permission.
*/
#ifndef __CACHE_GEOM_H__
#define __CACHE_GEOM_H__
#define MAX_CACHE_LEVELS 0x8
/* Target cpu cache relative to host cpu cache size */
#define TCSZ_EQUAL 0x0
#define TCSZ_SMALL 0x1
#define TCSZ_BIG 0x2
#define get_setway_reg(a, b , c, d, e) ((a << __clz(b)) | (c << (d + 4)) | (e << 1))
#define get_cache_type(clidr, lvl) ((clidr >> (lvl * 0x3)) & 0x7)
#define get_cache_level(reg) (reg >> 1) & 0x7
#define get_cache_linesz(cg, lvl) (cg->ccsidr[lvl] & 0x7)
#define get_cache_assoc(cg, lvl) ((cg->ccsidr[lvl] >> 3) & 0x3ff)
#define get_cache_numsets(cg, lvl) ((cg->ccsidr[lvl] >> 13) & 0x7fff)
/*
* Data structure that stores the foreseeable differences
* between the host and target caches at each implemented
* cache level.
* Absolute cache line numbers are calculated relative to
* the cache line size of the smaller cache to get the
* maximum granularity.
*/
typedef struct cache_diff {
/* Stores whether target cache is =,<,> host cache */
unsigned csize_diff;
/*
* Stores factor by which target cache line
* has to be multiplied to get absolute line
* no.
*/
unsigned tcline_factor;
/*
* Stores factor by which absolute cache line
* no. has to be divided to get host cache line
* no.
*/
unsigned hcline_factor;
/* Max absolute target cpu cache line number */
unsigned tnumabs_clines;
/* Max absolute host cpu cache line number */
unsigned hnumabs_clines;
} cache_diff;
/*
* Data structure that defines the cache topology of a cpu
*/
typedef struct cache_geom {
unsigned clidr;
/*
* One for each cpu to store the cache level
* the OS thinks its operating on.
*/
unsigned ccselr;
/* One for each cache level */
unsigned ccsidr[MAX_CACHE_LEVELS];
} cache_geometry;
/*
* Data structure to hold cache virtualisation statistics.
* Reset for each switchover.
*/
typedef struct cache_stats {
/* Number of cm ops which did not cover the whole cache */
unsigned part_cmop_cnt;
/* Number of cm ops which spanned the entire cache */
unsigned cmpl_cmop_cnt;
} cache_stats;
extern unsigned map_cache_geometries(cache_geometry *,
cache_geometry *,
cache_diff *);
extern void find_cache_geometry(cache_geometry *);
extern void find_cache_diff(cache_geometry *,
cache_geometry *,
cache_diff *);
extern void handle_cm_op(unsigned,
void (*) (unsigned),
cache_geometry *,
cache_geometry *,
cache_diff *);
#endif /* __CACHE_GEOM_H__ */
|