Re: [PATCH] VESA framebuffer w/MTRR locks 2.4.0 on init

David Wragg
2001-01-06T01:21:03Z

Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
> > loop with no exit, as each size mtrr fails.
> > while (mtrr_add(video_base, temp_size, MTRR_TYPE_WRCOMB,
> > 1)==-EINVAL) {
> > temp_size >>= 1;
> > }
>
> Ok that one is the bug.

Even with the obvious bug fixed, that code is strange. "temp_size >>=
1" does little to improve the chances of the mtrr_add succeeding.
Something like this would be better:

if (mtrr_add(video_base, temp_size, MTRR_TYPE_WRCOMB, 1) == -EINVAL) {
/* Find the largest power-of-two */
while (temp_size & (temp_size - 1))
temp_sze &= (temp_size - 1);

mtrr_add(video_base, temp_size, MTRR_TYPE_WRCOMB, 1);
}

(But this is just a very crude way to work around the inflexibility of
the MTRRs. Rather than cluttering up calls to mtrr_add, it would be
better to fix this properly, either by implementing PAT support
(Zoltán Böszörményi said he was working on that), or by having a
user-space helper program to make more intelligent MTRR allocations,
or both.)

David Wragg