From 72ec359f52ff085f122e2e916abf731d5021d24d Mon Sep 17 00:00:00 2001 From: Arne Jansen Date: Tue, 20 Dec 2022 10:12:27 +0100 Subject: [PATCH 1/2] soc: allow regions that are not a power of 2 Align region to its power of 2, not the region size itself. --- litex/soc/integration/soc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 4ffac67b5..a63ce9bc9 100755 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -254,12 +254,13 @@ class SoCBusHandler(LiteXModule): search_regions = {"main": SoCRegion(origin=0x00000000, size=2**self.address_width-1)} # Iterate on Search_Regions to find a Candidate. + size_pow2 = 2**log2_int(size, False) for _, search_region in search_regions.items(): origin = search_region.origin while (origin + size) < (search_region.origin + search_region.size_pow2): # Align Origin on Size. - if (origin%size): - origin += (origin - origin%size) + if (origin%size_pow2): + origin += (origin - origin%size_pow2) continue # Create a Candidate. candidate = SoCRegion(origin=origin, size=size, cached=cached) From 647504d4c55e6fb28012efd72178f255aaf04fd6 Mon Sep 17 00:00:00 2001 From: Arne Jansen Date: Mon, 30 Jan 2023 07:46:37 +0100 Subject: [PATCH 2/2] align fixup --- litex/soc/integration/soc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index a63ce9bc9..bc68db3c7 100755 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -260,7 +260,7 @@ class SoCBusHandler(LiteXModule): while (origin + size) < (search_region.origin + search_region.size_pow2): # Align Origin on Size. if (origin%size_pow2): - origin += (origin - origin%size_pow2) + origin += (size_pow2 - origin%size_pow2) continue # Create a Candidate. candidate = SoCRegion(origin=origin, size=size, cached=cached)