From: kettenis Date: Thu, 13 May 2021 22:42:14 +0000 (+0000) Subject: Improve mereg_add() like I did on arm64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c070ace613a693faf3458c5d399ce4bf9982a66b;p=openbsd Improve mereg_add() like I did on arm64. --- diff --git a/sys/arch/powerpc64/powerpc64/machdep.c b/sys/arch/powerpc64/powerpc64/machdep.c index b8467449ee6..3a7bcd53301 100644 --- a/sys/arch/powerpc64/powerpc64/machdep.c +++ b/sys/arch/powerpc64/powerpc64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.68 2021/04/15 07:28:37 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.69 2021/05/13 22:42:14 kettenis Exp $ */ /* * Copyright (c) 2020 Mark Kettenis @@ -355,6 +355,23 @@ init_powernv(void *fdt, void *tocbase) void memreg_add(const struct fdt_reg *reg) { + int i; + + for (i = 0; i < nmemreg; i++) { + if (reg->addr == memreg[i].addr + memreg[i].size) { + memreg[i].size += reg->size; + return; + } + if (reg->addr + reg->size == memreg[i].addr) { + memreg[i].addr = reg->addr; + memreg[i].size += reg->size; + return; + } + } + + if (nmemreg >= nitems(memreg)) + return; + memreg[nmemreg++] = *reg; }