hw: eliminate -DNR_OF_CPUS, use constant instead

Fix genodelabs/genode#4752
This commit is contained in:
Stefan Kalkowski 2023-02-06 14:43:20 +01:00 committed by Christian Helmuth
parent 1d5fc3ef60
commit 0212f94809
45 changed files with 62 additions and 95 deletions

View File

@ -25,10 +25,6 @@ REP_INC_DIR += src/bootstrap
REP_INC_DIR += src/include
REP_INC_DIR += src/core/include # for boot_modules.h only
# configure multiprocessor mode
NR_OF_CPUS ?= 1
CC_OPT += -Wa,--defsym -Wa,NR_OF_CPUS=$(NR_OF_CPUS) -DNR_OF_CPUS=$(NR_OF_CPUS)
TMP := $(call select_from_repositories,lib/mk/bootstrap-hw.inc)
BASE_HW_DIR := $(TMP:%/lib/mk/bootstrap-hw.inc=%)

View File

@ -66,10 +66,6 @@ SRC_CC += heartbeat.cc
# provide Genode version information
include $(BASE_DIR)/src/core/version.inc
# configure multiprocessor mode
NR_OF_CPUS ?= 1
CC_OPT += -Wa,--defsym -Wa,NR_OF_CPUS=$(NR_OF_CPUS) -DNR_OF_CPUS=$(NR_OF_CPUS)
TMP := $(call select_from_repositories,lib/mk/core-hw.inc)
BASE_HW_DIR := $(TMP:%/lib/mk/core-hw.inc=%)

View File

@ -9,6 +9,4 @@ SRC_CC += bootstrap/spec/arm/imx6_platform.cc
SRC_CC += bootstrap/spec/arm/arm_v7_cpu.cc
SRC_CC += hw/spec/32bit/memory_map.cc
NR_OF_CPUS = 4
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -7,8 +7,6 @@ SRC_CC += bootstrap/spec/arm/arm_v7_cpu.cc
SRC_CC += hw/spec/32bit/memory_map.cc
SRC_S += bootstrap/spec/arm/crt0.s
NR_OF_CPUS = 2
#
# we need more specific compiler hints for some 'special' assembly code
# override -march=armv7-a because it conflicts with -mcpu=cortex-a7

View File

@ -9,6 +9,4 @@ SRC_CC += bootstrap/spec/arm/imx6_platform.cc
SRC_CC += bootstrap/spec/arm/arm_v7_cpu.cc
SRC_CC += hw/spec/32bit/memory_map.cc
NR_OF_CPUS = 1
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -7,8 +7,6 @@ SRC_CC += bootstrap/spec/arm/gicv2.cc
SRC_CC += hw/spec/32bit/memory_map.cc
SRC_S += bootstrap/spec/arm/crt0.s
NR_OF_CPUS = 2
CC_MARCH = -march=armv7ve -mtune=cortex-a15 -mfpu=vfpv3 -mfloat-abi=softfp
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -9,6 +9,4 @@ SRC_CC += bootstrap/spec/arm/imx6_platform.cc
SRC_CC += bootstrap/spec/arm/arm_v7_cpu.cc
SRC_CC += hw/spec/32bit/memory_map.cc
NR_OF_CPUS = 4
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -12,7 +12,5 @@ REP_INC_DIR += src/core/board/imx6q_sabrelite
# add C++ sources
SRC_CC += platform_services.cc
NR_OF_CPUS = 4
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/cortex_a9/core-hw.inc)

View File

@ -22,8 +22,6 @@ SRC_CC += vm_session_component.cc
# add assembly sources
SRC_S += spec/arm_v7/virtualization/exception_vector.s
NR_OF_CPUS = 2
#
# we need more specific compiler hints for some 'special' assembly code
# override -march=armv7-a because it conflicts with -mcpu=cortex-a7

View File

@ -12,7 +12,5 @@ REP_INC_DIR += src/core/board/nit6_solox
# add C++ sources
SRC_CC += platform_services.cc
NR_OF_CPUS = 1
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/cortex_a9/core-hw.inc)

View File

@ -11,7 +11,5 @@ REP_INC_DIR += src/core/board/pbxa9
# add C++ sources
SRC_CC += platform_services.cc
NR_OF_CPUS = 1
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/cortex_a9/core-hw.inc)

View File

@ -14,8 +14,6 @@ SRC_CC += vm_session_component.cc
SRC_S += spec/arm_v7/virtualization/exception_vector.s
NR_OF_CPUS = 2
CC_MARCH = -march=armv7ve -mtune=cortex-a15 -mfpu=vfpv3 -mfloat-abi=softfp
include $(call select_from_repositories,lib/mk/spec/cortex_a15/core-hw.inc)

View File

@ -12,7 +12,5 @@ REP_INC_DIR += src/core/board/wand_quad
# add C++ sources
SRC_CC += platform_services.cc
NR_OF_CPUS = 4
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/cortex_a9/core-hw.inc)

View File

@ -7,8 +7,6 @@ SRC_CC += lib/base/arm_64/kernel/interface.cc
SRC_CC += spec/64bit/memory_map.cc
SRC_S += bootstrap/spec/arm_64/crt0.s
NR_OF_CPUS = 4
vpath spec/64bit/memory_map.cc $(call select_from_repositories,src/lib/hw)
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -13,7 +13,5 @@ SRC_CC += vm_session_component.cc
#add assembly sources
SRC_S += spec/arm_v8/virtualization/exception_vector.s
NR_OF_CPUS = 4
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/arm_v8/core-hw.inc)

View File

@ -8,8 +8,6 @@
SRC_CC += kernel/cpu_up.cc
SRC_CC += kernel/lock.cc
NR_OF_CPUS = 1
# include less specific configuration
include $(call select_from_repositories,lib/mk/spec/arm_v7/core-hw.inc)

View File

@ -6,6 +6,4 @@ SRC_S += bootstrap/spec/x86_64/crt0_translation_table.s
SRC_CC += hw/spec/64bit/memory_map.cc
NR_OF_CPUS = 32
include $(call select_from_repositories,lib/mk/bootstrap-hw.inc)

View File

@ -39,7 +39,5 @@ SRC_CC += spec/64bit/memory_map.cc
vpath spec/64bit/memory_map.cc $(call select_from_repositories,src/lib/hw)
NR_OF_CPUS = 32
# include less specific configuration
include $(call select_from_repositories,lib/mk/core-hw.inc)

View File

@ -27,6 +27,8 @@ namespace Board {
using Psci = Hw::Psci<Hw::Psci_smc_functor>;
using Pic = Hw::Gicv2;
static constexpr bool NON_SECURE = true;
enum { NR_OF_CPUS = 2 };
};
#endif /* _SRC__BOOTSTRAP__SPEC__VIRT__QEMU_H_ */

View File

@ -66,7 +66,7 @@ unsigned Bootstrap::Platform::enable_mmu()
::Board::Pic pic { };
/* primary cpu wakes up all others */
if (primary_cpu && NR_OF_CPUS > 1) {
if (primary_cpu && ::Board::NR_OF_CPUS > 1) {
Cpu::invalidate_data_cache();
primary_cpu = false;
Cpu::wake_up_all_cpus(&_start_setup_stack);

View File

@ -31,6 +31,8 @@ namespace Board {
static void wake_up_all_cpus(void*);
};
enum { NR_OF_CPUS = 4 };
using Hw::Pic;
};

View File

@ -18,6 +18,13 @@
#include <base/internal/globals.h>
#include <base/internal/unmanaged_singleton.h>
using namespace Genode;
static constexpr size_t STACK_SIZE = 0x2000;
size_t bootstrap_stack_size = STACK_SIZE;
uint8_t bootstrap_stack[Board::NR_OF_CPUS][STACK_SIZE]
__attribute__((aligned(get_page_size())));
Bootstrap::Platform & Bootstrap::platform() {
return *unmanaged_singleton<Bootstrap::Platform>(); }

View File

@ -46,7 +46,7 @@ class Bootstrap::Platform
Memory_region_array early_ram_regions { };
Memory_region_array late_ram_regions { };
Mmio_space const core_mmio;
unsigned cpus { NR_OF_CPUS };
unsigned cpus { ::Board::NR_OF_CPUS };
::Board::Boot_info info { };
Board();

View File

@ -63,8 +63,10 @@
mrcne p15, 0, sp, c0, c0, 5 /* read multiprocessor affinity register */
andne sp, sp, #0xff /* set cpu id for non-boot cpu */
adr r0, _start_stack /* load stack address into r0 */
adr r1, _start_stack_size /* load stack size per cpu into r1 */
adr r0, _bootstrap_stack_local /* load stack address into r0 */
adr r1, _bootstrap_stack_size_local /* load stack size per cpu into r1 */
ldr r0, [r0]
ldr r1, [r1]
ldr r1, [r1]
add sp, #1 /* calculate stack start for CPU */
@ -101,11 +103,8 @@
_bss_local_end:
.long _bss_end
_start_stack_size:
.long STACK_SIZE
_bootstrap_stack_local:
.long bootstrap_stack
.align 3
_start_stack:
.rept NR_OF_CPUS
.space STACK_SIZE
.endr
_bootstrap_stack_size_local:
.long bootstrap_stack_size

View File

@ -145,7 +145,8 @@ unsigned Bootstrap::Platform::enable_mmu()
Cpu::Ttbr::Baddr::masked((Genode::addr_t)core_pd->table_base);
/* primary cpu wakes up all others */
if (primary && NR_OF_CPUS > 1) Cpu::wake_up_all_cpus(&_crt0_start_secondary);
if (primary && ::Board::NR_OF_CPUS > 1)
Cpu::wake_up_all_cpus(&_crt0_start_secondary);
while (Cpu::current_privilege_level() > Cpu::Current_el::EL1) {
if (Cpu::current_privilege_level() == Cpu::Current_el::EL3) {

View File

@ -114,19 +114,12 @@
** Initialize stack **
**********************/
.set STACK_SIZE, 0x2000
_cpu_number
ldr x1, =_crt0_start_stack
ldr x2, [x1]
ldr x1, =bootstrap_stack
ldr x2, =bootstrap_stack_size
ldr x2, [x2]
add x0, x0, #1
mul x0, x0, x2
add x1, x1, x0
mov sp, x1
bl init
.p2align 4
.rept NR_OF_CPUS
.space STACK_SIZE
.endr
_crt0_start_stack:
.quad STACK_SIZE

View File

@ -143,16 +143,14 @@ __gdt:
movq $1, %rcx
lock xaddq %rcx, (%rax)
/* if more CPUs started than supported, then stop them */
cmp $NR_OF_CPUS, %rcx
jge 1f
/* calculate stack depending on CPU counter */
movq $STACK_SIZE, %rax
leaq bootstrap_stack_size@GOTPCREL(%rip),%rax
movq (%rax), %rax
movq (%rax), %rax
inc %rcx
mulq %rcx
movq %rax, %rcx
leaq __bootstrap_stack@GOTPCREL(%rip),%rax
leaq bootstrap_stack@GOTPCREL(%rip),%rax
movq (%rax), %rsp
addq %rcx, %rsp
@ -182,10 +180,6 @@ __gdt:
jmp 1b
.global bootstrap_stack_size
bootstrap_stack_size:
.quad STACK_SIZE
/******************************************
** Global Descriptor Table (GDT) **
** See Intel SDM Vol. 3A, section 3.5.1 **
@ -236,14 +230,7 @@ __gdt:
*********************************/
.bss
/* stack of the temporary initial environment */
.p2align 12
.globl __bootstrap_stack
__bootstrap_stack:
.rept NR_OF_CPUS
.space STACK_SIZE
.endr
.globl __initial_ax
__initial_ax:

View File

@ -31,7 +31,7 @@ extern "C" Genode::addr_t __initial_ax;
extern "C" Genode::addr_t __initial_bx;
/* pointer to stack base */
extern "C" Genode::addr_t __bootstrap_stack;
extern "C" Genode::addr_t bootstrap_stack;
/* number of booted CPUs */
extern "C" Genode::addr_t __cpus_booted;
@ -296,7 +296,7 @@ unsigned Bootstrap::Platform::enable_mmu()
Cpu::Cr3::write(Cpu::Cr3::Pdb::masked((addr_t)core_pd->table_base));
addr_t const stack_base = reinterpret_cast<addr_t>(&__bootstrap_stack);
addr_t const stack_base = reinterpret_cast<addr_t>(&bootstrap_stack);
addr_t const this_stack = reinterpret_cast<addr_t>(&stack_base);
addr_t const cpu_id = (this_stack - stack_base) / bootstrap_stack_size;

View File

@ -17,15 +17,20 @@
/* base-hw internal includes */
#include <hw/spec/x86_64/pc_board.h>
/*
* As long as Board::NR_OF_CPUS is used as constant within pic.h
* we sadly have to include Hw::Pc_board into the namespace
* before including pic.h. This will change as soon as the number
* O CPUs is only define per function
*/
namespace Board { using namespace Hw::Pc_board; };
/* base-hw Core includes */
#include <spec/x86_64/pic.h>
#include <spec/x86_64/pit.h>
#include <spec/x86_64/cpu.h>
namespace Board {
using namespace Hw::Pc_board;
class Pic : public Local_interrupt_controller { };
enum {

View File

@ -40,7 +40,8 @@ namespace Board {
TIMER_IRQ = 30 /* PPI IRQ 14 */,
VT_TIMER_IRQ = 27,
VT_MAINTAINANCE_IRQ = 25,
VCPU_MAX = 16
VCPU_MAX = 16,
NR_OF_CPUS = 2,
};
};

View File

@ -34,6 +34,7 @@ namespace Board {
using namespace Hw::Virt_qemu_board;
enum {
NR_OF_CPUS = 4,
TIMER_IRQ = 30, /* PPI IRQ 14 */
VT_TIMER_IRQ = 11 + 16,
VT_MAINTAINANCE_IRQ = 9 + 16,

View File

@ -47,7 +47,7 @@ static inline bool running_in_kernel()
{
addr_t const stack_base = reinterpret_cast<addr_t>(&kernel_stack);
static constexpr size_t stack_size =
NR_OF_CPUS * Kernel::Cpu::KERNEL_STACK_SIZE;
Board::NR_OF_CPUS * Kernel::Cpu::KERNEL_STACK_SIZE;
/* check stack variable against kernel stack area */
return ((addr_t)&stack_base) >= stack_base &&

View File

@ -160,7 +160,7 @@ Cpu_job & Cpu::schedule()
Genode::size_t kernel_stack_size = Cpu::KERNEL_STACK_SIZE;
Genode::uint8_t kernel_stack[NR_OF_CPUS][Cpu::KERNEL_STACK_SIZE]
Genode::uint8_t kernel_stack[Board::NR_OF_CPUS][Cpu::KERNEL_STACK_SIZE]
__attribute__((aligned(Genode::get_page_size())));

View File

@ -201,7 +201,7 @@ class Kernel::Cpu_pool
Inter_processor_work_list _global_work_list {};
unsigned _nr_of_cpus;
Genode::Constructible<Cpu> _cpus[NR_OF_CPUS];
Genode::Constructible<Cpu> _cpus[Board::NR_OF_CPUS];
public:

View File

@ -65,7 +65,7 @@ struct Hypervisor::Host_context
static Hypervisor::Host_context & host_context(Cpu & cpu)
{
static Genode::Constructible<Hypervisor::Host_context>
host_context[NR_OF_CPUS];
host_context[Board::NR_OF_CPUS];
if (!host_context[cpu.id()].constructed()) {
host_context[cpu.id()].construct();
Hypervisor::Host_context & c = *host_context[cpu.id()];

View File

@ -32,7 +32,8 @@ using Kernel::Vm;
static Genode::Vm_state & host_context(Cpu & cpu)
{
static Genode::Constructible<Genode::Vm_state> host_context[NR_OF_CPUS];
static Genode::Constructible<Genode::Vm_state>
host_context[Board::NR_OF_CPUS];
if (!host_context[cpu.id()].constructed()) {
host_context[cpu.id()].construct();

View File

@ -85,7 +85,7 @@ class Board::Global_interrupt_controller : public Genode::Mmio
};
unsigned _irte_count = 0; /* number of redirection table entries */
uint8_t _lapic_id[NR_OF_CPUS]; /* unique name of the LAPIC of each CPU */
uint8_t _lapic_id[Board::NR_OF_CPUS]; /* unique name of the LAPIC of each CPU */
Irq_mode _irq_mode[IRQ_COUNT];
/**
@ -221,7 +221,7 @@ class Board::Local_interrupt_controller : public Genode::Mmio
void store_apic_id(unsigned const cpu_id)
{
if (cpu_id < NR_OF_CPUS) {
if (cpu_id < Board::NR_OF_CPUS) {
Id::access_t const lapic_id = read<Id>();
_global_irq_ctrl.lapic_id(cpu_id, (unsigned char)((lapic_id >> 24) & 0xff));
}

View File

@ -22,8 +22,8 @@ namespace Hw { template <typename> struct Boot_info; }
template <typename PLAT_INFO>
struct Hw::Boot_info
{
using Mapping_pool = Genode::Array<Mapping, 32>;
using Kernel_irqs = Genode::Array<unsigned, NR_OF_CPUS + 1>;
using Mapping_pool = Genode::Array<Mapping, 32>;
using Kernel_irqs = Genode::Array<unsigned, 32>;
addr_t const table;
addr_t const table_allocator;

View File

@ -26,6 +26,7 @@ namespace Hw::Imx53_qsb_board {
enum {
UART_BASE = UART_1_MMIO_BASE,
UART_CLOCK = 0, /* ignored value */
NR_OF_CPUS = 1,
};
}

View File

@ -31,6 +31,7 @@ namespace Hw::Imx6q_sabrelite_board {
UART_BASE = UART_2_MMIO_BASE,
UART_SIZE = UART_2_MMIO_SIZE,
UART_CLOCK = 0, /* dummy value, not used */
NR_OF_CPUS = 4
};
}

View File

@ -29,6 +29,7 @@ namespace Hw::Imx7d_sabre_board {
enum {
UART_BASE = UART_1_MMIO_BASE,
UART_CLOCK = 0, /* unsued value */
NR_OF_CPUS = 2
};
}

View File

@ -31,6 +31,7 @@ namespace Hw::Nit6_solox_board {
UART_BASE = UART_1_MMIO_BASE,
UART_SIZE = UART_1_MMIO_SIZE,
UART_CLOCK = 0, /* dummy value, not used */
NR_OF_CPUS = 1
};
}

View File

@ -31,6 +31,7 @@ namespace Hw::Pbxa9_board {
enum {
UART_BASE = PL011_0_MMIO_BASE,
UART_CLOCK = PL011_0_CLOCK,
NR_OF_CPUS = 1,
};
}

View File

@ -31,6 +31,7 @@ namespace Hw::Wand_quad_board {
UART_BASE = UART_1_MMIO_BASE,
UART_SIZE = UART_1_MMIO_SIZE,
UART_CLOCK = 0, /* dummy value, not used */
NR_OF_CPUS = 4
};
}

View File

@ -23,6 +23,8 @@ namespace Hw::Pc_board {
struct Boot_info;
struct Serial;
enum Dummies { UART_BASE, UART_CLOCK };
enum { NR_OF_CPUS = 32 };
}