summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorRadim Krčmář <rkrcmar@redhat.com>2015-02-17 17:30:53 +0100
committerGerd Hoffmann <kraxel@redhat.com>2015-03-03 08:33:08 +0100
commit619616ce31a5a5d167bf26f40d920b26da0a7bfd (patch)
tree6f173c8fcf5661978bd8b2164895181fc26de37b /hw
parentbb7443f6d6f09411ea10f06e6cb0d416bd1ccebd (diff)
downloadqemu-619616ce31a5a5d167bf26f40d920b26da0a7bfd.tar.gz
vga: refactor vram_size clamping and rounding
Make the code a bit more obvious. We don't have min/max, so a general helper for clamp probably isn't acceptable either. Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/display/vga.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/hw/display/vga.c b/hw/display/vga.c
index 6e4ca7e9ab..c0f7b343bb 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -2094,6 +2094,17 @@ static const GraphicHwOps vga_ops = {
.text_update = vga_update_text,
};
+static inline uint32_t uint_clamp(uint32_t val, uint32_t vmin, uint32_t vmax)
+{
+ if (val < vmin) {
+ return vmin;
+ }
+ if (val > vmax) {
+ return vmax;
+ }
+ return val;
+}
+
void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
{
int i, j, v, b;
@@ -2121,13 +2132,10 @@ void vga_common_init(VGACommonState *s, Object *obj, bool global_vmstate)
expand4to8[i] = v;
}
- /* valid range: 1 MB -> 512 MB */
- s->vram_size = 1024 * 1024;
- while (s->vram_size < (s->vram_size_mb << 20) &&
- s->vram_size < (512 << 20)) {
- s->vram_size <<= 1;
- }
- s->vram_size_mb = s->vram_size >> 20;
+ s->vram_size_mb = uint_clamp(s->vram_size_mb, 1, 512);
+ s->vram_size_mb = pow2ceil(s->vram_size_mb);
+ s->vram_size = s->vram_size_mb << 20;
+
if (!s->vbe_size) {
s->vbe_size = s->vram_size;
}