Skip to content

Commit 63e28a7

Browse files
amlutoairlied
authored andcommitted
uvesafb: Clean up MTRR code
The old code allowed very strange memory types. Now it works like all the other video drivers: ioremap_wc is used unconditionally, and MTRRs are set if PAT is unavailable (unless MTRR is disabled by a module parameter). UC, WB, and WT support is gone. If there are MTRR conflicts that prevent addition of a WC MTRR, adding a non-conflicting MTRR is pointless; it's better to just turn off MTRR support entirely. As an added bonus, any MTRR added is freed on unload. Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
1 parent 07ebea2 commit 63e28a7

3 files changed

Lines changed: 23 additions & 64 deletions

File tree

‎Documentation/fb/uvesafb.txt‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,11 @@ pmipal Use the protected mode interface for palette changes.
8181

8282
mtrr:n Setup memory type range registers for the framebuffer
8383
where n:
84-
0 - disabled (equivalent to nomtrr) (default)
85-
1 - uncachable
86-
2 - write-back
87-
3 - write-combining
88-
4 - write-through
89-
90-
If you see the following in dmesg, choose the type that matches
91-
the old one. In this example, use "mtrr:2".
92-
...
93-
mtrr: type mismatch for e0000000,8000000 old: write-back new: write-combining
94-
...
84+
0 - disabled (equivalent to nomtrr)
85+
3 - write-combining (default)
86+
87+
Values other than 0 and 3 will result in a warning and will be
88+
treated just like 3.
9589

9690
nomtrr Do not use memory type range registers.
9791

‎drivers/video/uvesafb.c‎

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#ifdef CONFIG_X86
2525
#include <video/vga.h>
2626
#endif
27-
#ifdef CONFIG_MTRR
28-
#include <asm/mtrr.h>
29-
#endif
3027
#include "edid.h"
3128

3229
static struct cb_id uvesafb_cn_id = {
@@ -1540,67 +1537,30 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
15401537

15411538
static void uvesafb_init_mtrr(struct fb_info *info)
15421539
{
1543-
#ifdef CONFIG_MTRR
1540+
struct uvesafb_par *par = info->par;
1541+
15441542
if (mtrr && !(info->fix.smem_start & (PAGE_SIZE - 1))) {
15451543
int temp_size = info->fix.smem_len;
1546-
unsigned int type = 0;
15471544

1548-
switch (mtrr) {
1549-
case 1:
1550-
type = MTRR_TYPE_UNCACHABLE;
1551-
break;
1552-
case 2:
1553-
type = MTRR_TYPE_WRBACK;
1554-
break;
1555-
case 3:
1556-
type = MTRR_TYPE_WRCOMB;
1557-
break;
1558-
case 4:
1559-
type = MTRR_TYPE_WRTHROUGH;
1560-
break;
1561-
default:
1562-
type = 0;
1563-
break;
1564-
}
1545+
int rc;
15651546

1566-
if (type) {
1567-
int rc;
1547+
/* Find the largest power-of-two */
1548+
temp_size = roundup_pow_of_two(temp_size);
15681549

1569-
/* Find the largest power-of-two */
1570-
temp_size = roundup_pow_of_two(temp_size);
1550+
/* Try and find a power of two to add */
1551+
do {
1552+
rc = arch_phys_wc_add(info->fix.smem_start, temp_size);
1553+
temp_size >>= 1;
1554+
} while (temp_size >= PAGE_SIZE && rc == -EINVAL);
15711555

1572-
/* Try and find a power of two to add */
1573-
do {
1574-
rc = mtrr_add(info->fix.smem_start,
1575-
temp_size, type, 1);
1576-
temp_size >>= 1;
1577-
} while (temp_size >= PAGE_SIZE && rc == -EINVAL);
1578-
}
1556+
if (rc >= 0)
1557+
par->mtrr_handle = rc;
15791558
}
1580-
#endif /* CONFIG_MTRR */
15811559
}
15821560

15831561
static void uvesafb_ioremap(struct fb_info *info)
15841562
{
1585-
#ifdef CONFIG_X86
1586-
switch (mtrr) {
1587-
case 1: /* uncachable */
1588-
info->screen_base = ioremap_nocache(info->fix.smem_start, info->fix.smem_len);
1589-
break;
1590-
case 2: /* write-back */
1591-
info->screen_base = ioremap_cache(info->fix.smem_start, info->fix.smem_len);
1592-
break;
1593-
case 3: /* write-combining */
1594-
info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
1595-
break;
1596-
case 4: /* write-through */
1597-
default:
1598-
info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
1599-
break;
1600-
}
1601-
#else
1602-
info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
1603-
#endif /* CONFIG_X86 */
1563+
info->screen_base = ioremap_wc(info->fix.smem_start, info->fix.smem_len);
16041564
}
16051565

16061566
static ssize_t uvesafb_show_vbe_ver(struct device *dev,
@@ -1851,6 +1811,7 @@ static int uvesafb_remove(struct platform_device *dev)
18511811
unregister_framebuffer(info);
18521812
release_region(0x3c0, 32);
18531813
iounmap(info->screen_base);
1814+
arch_phys_wc_del(par->mtrr_handle);
18541815
release_mem_region(info->fix.smem_start, info->fix.smem_len);
18551816
fb_destroy_modedb(info->monspecs.modedb);
18561817
fb_dealloc_cmap(&info->cmap);
@@ -1930,6 +1891,9 @@ static int uvesafb_setup(char *options)
19301891
}
19311892
}
19321893

1894+
if (mtrr != 3 && mtrr != 1)
1895+
pr_warn("uvesafb: mtrr should be set to 0 or 3; %d is unsupported", mtrr);
1896+
19331897
return 0;
19341898
}
19351899
#endif /* !MODULE */

‎include/video/uvesafb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ struct uvesafb_par {
134134

135135
int mode_idx;
136136
struct vbe_crtc_ib crtc;
137+
int mtrr_handle;
137138
};
138139

139140
#endif /* _UVESAFB_H */

0 commit comments

Comments
 (0)