From 757dc8ab1245118bd3861ee2853b42c3476c1ed4 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 9 Apr 2025 15:16:55 -0600 Subject: [PATCH] kboot: Move seg code into libkboot This code is really generic segment processing and should live here. It also interfaces primarily with Linux APIs, so it's also appropriate for this if we have a version of that runs as a FreeBSD binary using FreeBSD system calls and APIs, though that's in the future somehow... Sponsored by: Netflix --- stand/kboot/include/seg.h | 24 ++++++++++++++++++++++++ stand/kboot/kboot/Makefile | 1 - stand/kboot/kboot/kboot.h | 20 ++------------------ stand/kboot/libkboot/Makefile | 1 + stand/kboot/{kboot => libkboot}/seg.c | 2 +- 5 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 stand/kboot/include/seg.h rename stand/kboot/{kboot => libkboot}/seg.c (99%) diff --git a/stand/kboot/include/seg.h b/stand/kboot/include/seg.h new file mode 100644 index 00000000000..5ca30670bdd --- /dev/null +++ b/stand/kboot/include/seg.h @@ -0,0 +1,24 @@ +/*- + * Copyright (c) 2024, Netflix, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +struct memory_segments +{ + uint64_t start; + uint64_t end; + uint64_t type; /* MD defined */ +}; + +#define SYSTEM_RAM 1 +void init_avail(void); +void need_avail(int n); +void add_avail(uint64_t start, uint64_t end, uint64_t type); +void remove_avail(uint64_t start, uint64_t end, uint64_t type); +uint64_t first_avail(uint64_t align, uint64_t min_size, uint64_t type); +void print_avail(void); +bool populate_avail_from_iomem(void); +uint64_t space_avail(uint64_t start); diff --git a/stand/kboot/kboot/Makefile b/stand/kboot/kboot/Makefile index 064d43701eb..0f6bb994711 100644 --- a/stand/kboot/kboot/Makefile +++ b/stand/kboot/kboot/Makefile @@ -25,7 +25,6 @@ SRCS= \ hostfs.c \ init.c \ main.c \ - seg.c \ util.c \ vers.c diff --git a/stand/kboot/kboot/kboot.h b/stand/kboot/kboot/kboot.h index 49e5dea25b1..2a6e98ae551 100644 --- a/stand/kboot/kboot/kboot.h +++ b/stand/kboot/kboot/kboot.h @@ -9,13 +9,6 @@ #define DEVT_HOSTDISK 1234 -struct memory_segments -{ - uint64_t start; - uint64_t end; - uint64_t type; /* MD defined */ -}; - bool enumerate_memory_arch(void); struct preloaded_file; void bi_loadsmap(struct preloaded_file *kfp); @@ -40,19 +33,10 @@ const char *hostdisk_gen_probe(void); void hostdisk_zfs_probe(void); bool hostdisk_zfs_find_default(void); -/* seg.c */ -#define SYSTEM_RAM 1 -void init_avail(void); -void need_avail(int n); -void add_avail(uint64_t start, uint64_t end, uint64_t type); -void remove_avail(uint64_t start, uint64_t end, uint64_t type); -uint64_t first_avail(uint64_t align, uint64_t min_size, uint64_t type); -void print_avail(void); -bool populate_avail_from_iomem(void); -uint64_t space_avail(uint64_t start); - /* util.c */ bool file2str(const char *fn, char *buffer, size_t buflen); bool file2u64(const char *fn, uint64_t *val); +#include "seg.h" + #endif /* KBOOT_H */ diff --git a/stand/kboot/libkboot/Makefile b/stand/kboot/libkboot/Makefile index 7cdb3db5193..7acec951107 100644 --- a/stand/kboot/libkboot/Makefile +++ b/stand/kboot/libkboot/Makefile @@ -9,6 +9,7 @@ CFLAGS+=-I${.CURDIR} -I${.CURDIR}/arch/${MACHINE_ARCH} SRCS= crt1.c SRCS+= host_syscall.S SRCS+= host_syscalls.c +SRCS+= seg.c SRCS+= termios.c .sinclude "${.CURDIR}/arch/${MACHINE_ARCH}/Makefile.inc" diff --git a/stand/kboot/kboot/seg.c b/stand/kboot/libkboot/seg.c similarity index 99% rename from stand/kboot/kboot/seg.c rename to stand/kboot/libkboot/seg.c index 558cac50122..395c593bcab 100644 --- a/stand/kboot/kboot/seg.c +++ b/stand/kboot/libkboot/seg.c @@ -5,7 +5,7 @@ */ #include "stand.h" -#include "kboot.h" +#include "seg.h" #include