From b20d05b4f7bd20ba177d8e46be427b76fcb46db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 18 Mar 2008 21:25:34 +0000 Subject: [PATCH] clean up, comments, header git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24452 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/arch/x86/arch_vm.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_vm.cpp b/src/system/kernel/arch/x86/arch_vm.cpp index 292fe44af8..bd7b9fe84b 100644 --- a/src/system/kernel/arch/x86/arch_vm.cpp +++ b/src/system/kernel/arch/x86/arch_vm.cpp @@ -1,5 +1,6 @@ /* * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2008, Jérôme Duval. * Distributed under the terms of the MIT License. * * Copyright 2001, Travis Geiselbrecht. All rights reserved. @@ -163,22 +164,29 @@ set_memory_type(int32 id, uint64 base, uint64 length, uint32 type) } -static int64 sols[5]; +#define MTRR_MAX_SOLUTIONS 5 // usually MTRR count is eight, keep a few for other needs +#define MTRR_MIN_SIZE 0x100000 // 1 MB +static int64 sols[MTRR_MAX_SOLUTIONS]; static int solCount; -static int64 props[5]; +static int64 props[MTRR_MAX_SOLUTIONS]; +/*! Find the nearest powers of two for a value, save current iteration, + then make recursives calls for the remaining values. + It uses at most MTRR_MAX_SOLUTIONS levels of recursion because + only that count of MTRR registers are available to map the memory. +*/ static void find_nearest(uint64 value, int iteration) { TRACE_MTRR("find_nearest %Lx %d\n", value, iteration); - if (iteration > 4 || (iteration + 1) >= solCount) + if (iteration > (MTRR_MAX_SOLUTIONS - 1) || (iteration + 1) >= solCount) return; uint64 down, up; int i; nearest_powers(value, &down, &up); props[iteration] = down; - if (value - down < 0x100000) { + if (value - down < MTRR_MIN_SIZE) { for (i=0; i<=iteration; i++) sols[i] = props[i]; solCount = iteration + 1; @@ -186,7 +194,7 @@ find_nearest(uint64 value, int iteration) } find_nearest(value - down, iteration + 1); props[iteration] = -up; - if (up - value < 0x100000) { + if (up - value < MTRR_MIN_SIZE) { for (i=0; i<=iteration; i++) sols[i] = props[i]; solCount = iteration + 1; @@ -196,17 +204,17 @@ find_nearest(uint64 value, int iteration) } +/*! Set up MTRR to map the memory to write-back using uncached if necessary */ static void set_memory_write_back(int32 id, uint64 base, uint64 length) { - int i; TRACE_MTRR("set_memory_write_back base %Lx length %Lx\n", base, length); - solCount = 5; + solCount = MTRR_MAX_SOLUTIONS; find_nearest(length, 0); #ifdef TRACE_MTRR dprintf("sols: "); - for (i=0; i