From 3fc2a798b2e58f9de0b023900447430527d3e3dd Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 9 May 2017 16:43:49 +0200 Subject: [PATCH] init: heuristics for DMA buffer allocations If a child is allowed to constrain physical memory allocations but left the 'phys_start' and 'phys_size' session arguments blank, init applies builtin constraints for allocating DMA buffers. The only component that makes use of the physical-memory constraint feature is the platform driver. Since the built-in heuristics are applied to the platform driver's environment RAM session, all allocations performed by the platform driver satisfy the DMA constraints. To justify building-in these heuristics into init as opposed to supplying the values as configuration arguments, the values differ between 32 and 64 bit. The configuration approach would raise the need to differentiate init configurations for both cases, which are completely identical otherwise. Issue #2407 --- repos/os/src/init/child.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/repos/os/src/init/child.cc b/repos/os/src/init/child.cc index 4b9287a2d2..a1c1aacc11 100644 --- a/repos/os/src/init/child.cc +++ b/repos/os/src/init/child.cc @@ -572,9 +572,28 @@ void Init::Child::filter_session_args(Service::Name const &service, * Remove phys_start and phys_size RAM-session arguments unless * explicitly permitted by the child configuration. */ - if (service == "RAM" && !_constrain_phys) { - Arg_string::remove_arg(args, "phys_start"); - Arg_string::remove_arg(args, "phys_size"); + if (service == "RAM") { + + /* + * If the child is allowed to constrain physical memory allocations, + * pass the child-provided constraints as session arguments to core. + * If no constraints are specified, we apply the constraints for + * allocating DMA memory (as the only use case for the constrain-phys + * mechanism). + */ + if (_constrain_phys) { + addr_t start = 0; + addr_t size = (sizeof(long) == 4) ? 0xc0000000UL : 0x100000000UL; + + Arg_string::find_arg(args, "phys_start").ulong_value(start); + Arg_string::find_arg(args, "phys_size") .ulong_value(size); + + Arg_string::set_arg(args, args_len, "phys_start", String<32>(Hex(start)).string()); + Arg_string::set_arg(args, args_len, "phys_size", String<32>(Hex(size)) .string()); + } else { + Arg_string::remove_arg(args, "phys_start"); + Arg_string::remove_arg(args, "phys_size"); + } } }