Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
34 - 1
# This is a simple script that checks the contents of /proc/mtrr to see if
2
# the BIOS maker for the computer took the easy way out in terms of
3
# specifying memory regions when there is a hole below 4GB for PCI access
4
# and the machine has 4GB or more of RAM.  When the contents of /proc/mtrr
5
# show a 4GB mapping of write-back cached RAM, minus punch out hole(s) of
6
# uncacheable regions (the area reserved for PCI access), then it becomes
7
# impossible for the ib_ipath driver to set write_combining on its PIO
8
# buffers.  To correct the problem, remap the lower memory region in various
9
# chunks up to the start of the punch out hole(s), then delete the punch out
10
# hole(s) entirely as they aren't needed any more.  That way, ib_ipath will
11
# be able to set write_combining on its PIO memory access region.
12
 
13
BEGIN {
14
	regs = 0
15
}
16
 
17
function check_base(mem)
18
{
19
	printf "Base memory data: base=0x%08x, size=0x%x\n", base[mem], size[mem] > "/dev/stderr"
20
	if (size[mem] < (512 * 1024 * 1024))
21
		return 0
22
	if (type[mem] != "write-back")
23
		return 0
24
	if (base[mem] >= (4 * 1024 * 1024 * 1024))
25
		return 0
26
	return 1
27
}
28
 
29
function check_hole(hole)
30
{
31
	printf "Hole data: base=0x%08x, size=0x%x\n", base[hole], size[hole] > "/dev/stderr"
32
	if (size[hole] > (1 * 1024 * 1024 * 1024))
33
		return 0
34
	if (type[hole] != "uncachable")
35
		return 0
36
	if ((base[hole] + size[hole]) > (4 * 1024 * 1024 * 1024))
37
		return 0
38
	return 1
39
}
40
 
41
function build_entries(start, end,     new_base, new_size, tmp_base)
42
{
43
	# mtrr registers require alignment of blocks, so a 256MB chunk must
44
	# be 256MB aligned.  Additionally, all blocks must be a power of 2
45
	# in size.  So, do the largest power of two size that we can and
46
	# still have start + block <= end, rinse and repeat.
47
	tmp_base = start
48
	do {
49
		new_base = tmp_base
50
		new_size = 4096
51
		while (((new_base + new_size) < end) &&
52
		       ((new_base % new_size) == 0))
53
			new_size = lshift(new_size, 1)
54
		if (((new_base + new_size) > end) ||
55
		    ((new_base % new_size) != 0))
56
			new_size = rshift(new_size, 1)
57
		printf "base=0x%x size=0x%x type=%s\n",
58
			new_base, new_size, type[mem] > "/dev/stderr"
59
		printf "base=0x%x size=0x%x type=%s\n",
60
			new_base, new_size, type[mem] > "/proc/mtrr"
61
		fflush("")
62
		tmp_base = new_base + new_size
63
	} while (tmp_base < end)
64
}
65
 
66
{
67
	gsub("^reg", "")
68
	gsub(": base=", " ")
69
	gsub(" [(].*), size=", " ")
70
	gsub(": ", " ")
71
	gsub(", count=.*$", "")
72
	register[regs] = strtonum($1)
73
	base[regs] = strtonum($2)
74
	size[regs] = strtonum($3)
75
	human_size[regs] = size[regs]
76
	if (match($3, "MB")) { size[regs] *= 1024*1024; mult[regs] = "MB" }
77
	else { size[regs] *= 1024; mult[regs] = "KB" }
78
	type[regs] = $4
79
	enabled[regs] = 1
80
	end[regs] = base[regs] + size[regs]
81
	regs++
82
}
83
 
84
END {
85
	# First we need to find our base memory region.  We only care about
86
	# the memory register that starts at base 0.  This is the only one
87
	# that we can reliably know is our global memory region, and the
88
	# only one that we can reliably check against overlaps.  It's entirely
89
	# possible that any memory region not starting at 0 and having an
90
	# overlap with another memory region is in fact intentional and we
91
	# shouldn't touch it.
92
	for(i=0; i<regs; i++)
93
		if (base[i] == 0)
94
			break
95
	# Did we get a valid base register?
96
	if (i == regs)
97
		exit 1
98
	mem = i
99
	if (!check_base(mem))
100
		exit 1
101
 
102
	cur_hole = 0
103
	for(i=0; i<regs; i++) {
104
		if (i == mem)
105
			continue
106
		if (base[i] < end[mem] && check_hole(i))
107
			holes[cur_hole++] = i
108
	}
109
	if (cur_hole == 0) {
110
		print "Nothing to do" > "/dev/stderr"
111
		exit 1
112
	}
113
	printf "Found %d punch-out holes\n", cur_hole > "/dev/stderr"
114
 
115
	# We need to sort the holes according to base address
116
	for(j = 0; j < cur_hole - 1; j++) {
117
		for(i = cur_hole - 1; i > j; i--) {
118
			if(base[holes[i]] < base[holes[i-1]]) {
119
				tmp = holes[i]
120
				holes[i] = holes[i-1]
121
				holes[i-1] = tmp
122
			}
123
		}
124
	}
125
	# OK, the common case would be that the BIOS is mapping holes out
126
	# of the 4GB memory range, and that our hole(s) are consecutive and
127
	# that our holes and our memory region end at the same place.  However,
128
	# things like machines with 8GB of RAM or more can foul up these
129
	# common traits.
130
	#
131
	# So, our modus operandi is to disable all of the memory/hole regions
132
	# to start, then build new base memory zones that in the end add
133
	# up to the same as our original zone minus the holes.  We know that
134
	# we will never have a hole listed here that belongs to a valid
135
	# hole punched in a write-combining memory region because you can't
136
	# overlay write-combining on top of write-back and we know our base
137
	# memory region is write-back, so in order for this hole to overlap
138
	# our base memory region it can't be also overlapping a write-combining
139
	# region.
140
	printf "disable=%d\n", register[mem] > "/dev/stderr"
141
	printf "disable=%d\n", register[mem] > "/proc/mtrr"
142
	fflush("")
143
	enabled[mem] = 0
144
	for(i=0; i < cur_hole; i++) {
145
		printf "disable=%d\n", register[holes[i]] > "/dev/stderr"
146
		printf "disable=%d\n", register[holes[i]] > "/proc/mtrr"
147
		fflush("")
148
		enabled[holes[i]] = 0
149
	}
150
	build_entries(base[mem], base[holes[0]])
151
	for(i=0; i < cur_hole - 1; i++)
152
		if (base[holes[i+1]] > end[holes[i]])
153
			build_entries(end[holes[i]], base[holes[i+1]])
154
	if (end[mem] > end[holes[i]])
155
		build_entries(end[holes[i]], end[mem])
156
	# We changed up the mtrr regs, so signal to the rdma script to
157
	# reload modules that need the mtrr regs to be right.
158
	exit 0
159
}
160