From f9beb20e99abbfcbea7cf222ba692aa3cbf10df7 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 4 May 2023 14:21:42 +0100 Subject: [image] Allow for images to be hidden from lists of all images When invoking a kernel via the UEFI shim, the kernel (and potentially also a helper binary such as GRUB) must be accessible via the virtual filesystem exposed via EFI_SIMPLE_FILE_SYSTEM_PROTOCOL but must not be present in the magic initrd constructed from all registered images. Allow for images to be flagged as hidden, which will cause them to be excluded from API-level lists of all images such as the virtual filesystem directory contents, the magic initrd, or the Multiboot module list. Hidden images remain visible to iPXE commands including "imgstat", which will show a "[HIDDEN]" flag for such images. Signed-off-by: Michael Brown --- src/arch/x86/image/bzimage.c | 4 ++++ src/arch/x86/image/multiboot.c | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src/arch') diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index b15bd5563..2c776147d 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -355,6 +355,10 @@ static size_t bzimage_load_initrd ( struct image *image, size_t offset; size_t pad_len; + /* Skip hidden images */ + if ( initrd->flags & IMAGE_HIDDEN ) + return 0; + /* Create cpio header for non-prebuilt images */ offset = cpio_header ( initrd, &cpio ); diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c index c1c63bc97..cada021ab 100644 --- a/src/arch/x86/image/multiboot.c +++ b/src/arch/x86/image/multiboot.c @@ -204,6 +204,10 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start, break; } + /* Skip hidden images */ + if ( module_image->flags & IMAGE_HIDDEN ) + continue; + /* Page-align the module */ start = ( ( start + 0xfff ) & ~0xfff ); -- cgit v1.2.3-55-g7522 From cfe65aa82628f364718e8cb261e8f6b952cd9d26 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 29 Jun 2023 15:38:08 +0100 Subject: [arm] Remove redundant inclusion of io.h The PCI I/O API (supporting accesses to PCI configuration space) is not related to the general I/O API (supporting accesses to memory-mapped I/O peripherals). Remove the spurious inclusion of ipxe/io.h from the PCI I/O header. Signed-off-by: Michael Brown --- src/arch/arm/include/bits/pci_io.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/arch') diff --git a/src/arch/arm/include/bits/pci_io.h b/src/arch/arm/include/bits/pci_io.h index fba0eb979..91f507a44 100644 --- a/src/arch/arm/include/bits/pci_io.h +++ b/src/arch/arm/include/bits/pci_io.h @@ -9,6 +9,4 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#include - #endif /* _BITS_PCI_IO_H */ -- cgit v1.2.3-55-g7522 From 18af669701b5396af4073b9de4bdb6cd3aff68c1 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 29 Jun 2023 15:26:49 +0100 Subject: [arm] Add missing arch/arm/core source directory Signed-off-by: Michael Brown --- src/arch/arm/Makefile | 1 + src/arch/arm/core/arm_io.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/arch') diff --git a/src/arch/arm/Makefile b/src/arch/arm/Makefile index 3cee5f3ac..b6509dda0 100644 --- a/src/arch/arm/Makefile +++ b/src/arch/arm/Makefile @@ -9,4 +9,5 @@ INCDIRS += arch/arm/include # ARM-specific directories containing source files # +SRCDIRS += arch/arm/core SRCDIRS += arch/arm/interface/efi diff --git a/src/arch/arm/core/arm_io.c b/src/arch/arm/core/arm_io.c index 1ef571fc1..f8022715a 100644 --- a/src/arch/arm/core/arm_io.c +++ b/src/arch/arm/core/arm_io.c @@ -46,7 +46,7 @@ union arm32_io_qword { * * This is not atomic for ARM32. */ -static uint64_t arm32_readq ( volatile uint64_t *io_addr ) { +static __unused uint64_t arm32_readq ( volatile uint64_t *io_addr ) { volatile union arm32_io_qword *ptr = container_of ( io_addr, union arm32_io_qword, qword ); union arm32_io_qword tmp; @@ -64,7 +64,8 @@ static uint64_t arm32_readq ( volatile uint64_t *io_addr ) { * * This is not atomic for ARM32. */ -static void arm32_writeq ( uint64_t data, volatile uint64_t *io_addr ) { +static __unused void arm32_writeq ( uint64_t data, + volatile uint64_t *io_addr ) { volatile union arm32_io_qword *ptr = container_of ( io_addr, union arm32_io_qword, qword ); union arm32_io_qword tmp; -- cgit v1.2.3-55-g7522 From c57887bfc808c2be485ed97f2dc709f927550161 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 29 Jun 2023 15:08:23 +0100 Subject: [ioapi] Centralise definitions for dummy PIO There is no common standard for I/O-space access for non-x86 CPU families, and non-MMIO peripherals are vanishingly rare. Generalise the existing ARM definitions for dummy PIO to allow for reuse by other CPU architectures. Signed-off-by: Michael Brown --- src/arch/arm/core/arm_io.c | 2 +- src/arch/arm/include/ipxe/arm_io.h | 54 +++----------------------------- src/include/ipxe/dummy_pio.h | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 src/include/ipxe/dummy_pio.h (limited to 'src/arch') diff --git a/src/arch/arm/core/arm_io.c b/src/arch/arm/core/arm_io.c index f8022715a..41b42389a 100644 --- a/src/arch/arm/core/arm_io.c +++ b/src/arch/arm/core/arm_io.c @@ -83,7 +83,6 @@ PROVIDE_IOAPI_INLINE ( arm, readl ); PROVIDE_IOAPI_INLINE ( arm, writeb ); PROVIDE_IOAPI_INLINE ( arm, writew ); PROVIDE_IOAPI_INLINE ( arm, writel ); -PROVIDE_IOAPI_INLINE ( arm, iodelay ); PROVIDE_IOAPI_INLINE ( arm, mb ); #ifdef __aarch64__ PROVIDE_IOAPI_INLINE ( arm, readq ); @@ -92,3 +91,4 @@ PROVIDE_IOAPI_INLINE ( arm, writeq ); PROVIDE_IOAPI ( arm, readq, arm32_readq ); PROVIDE_IOAPI ( arm, writeq, arm32_writeq ); #endif +PROVIDE_DUMMY_PIO ( arm ); diff --git a/src/arch/arm/include/ipxe/arm_io.h b/src/arch/arm/include/ipxe/arm_io.h index 046cbdb06..7ed38993d 100644 --- a/src/arch/arm/include/ipxe/arm_io.h +++ b/src/arch/arm/include/ipxe/arm_io.h @@ -15,6 +15,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define IOAPI_PREFIX_arm __arm_ #endif +#include + /* * Memory space mappings * @@ -77,55 +79,6 @@ ARM_WRITEX ( w, uint16_t, "h", "" ); ARM_WRITEX ( l, uint32_t, "", "" ); #endif -/* - * Dummy PIO reads and writes up to 32 bits - * - * There is no common standard for I/O-space access for ARM, and - * non-MMIO peripherals are vanishingly rare. Provide dummy - * implementations that will allow code to link and should cause - * drivers to simply fail to detect hardware at runtime. - * - */ - -#define ARM_INX( _suffix, _type ) \ -static inline __always_inline _type \ -IOAPI_INLINE ( arm, in ## _suffix ) ( volatile _type *io_addr __unused) { \ - return ~( (_type) 0 ); \ -} \ -static inline __always_inline void \ -IOAPI_INLINE ( arm, ins ## _suffix ) ( volatile _type *io_addr __unused, \ - _type *data, unsigned int count ) { \ - memset ( data, 0xff, count * sizeof ( *data ) ); \ -} -ARM_INX ( b, uint8_t ); -ARM_INX ( w, uint16_t ); -ARM_INX ( l, uint32_t ); - -#define ARM_OUTX( _suffix, _type ) \ -static inline __always_inline void \ -IOAPI_INLINE ( arm, out ## _suffix ) ( _type data __unused, \ - volatile _type *io_addr __unused ) { \ - /* Do nothing */ \ -} \ -static inline __always_inline void \ -IOAPI_INLINE ( arm, outs ## _suffix ) ( volatile _type *io_addr __unused, \ - const _type *data __unused, \ - unsigned int count __unused ) { \ - /* Do nothing */ \ -} -ARM_OUTX ( b, uint8_t ); -ARM_OUTX ( w, uint16_t ); -ARM_OUTX ( l, uint32_t ); - -/* - * Slow down I/O - * - */ -static inline __always_inline void -IOAPI_INLINE ( arm, iodelay ) ( void ) { - /* Nothing to do */ -} - /* * Memory barrier * @@ -140,4 +93,7 @@ IOAPI_INLINE ( arm, mb ) ( void ) { #endif } +/* Dummy PIO */ +DUMMY_PIO ( arm ); + #endif /* _IPXE_ARM_IO_H */ diff --git a/src/include/ipxe/dummy_pio.h b/src/include/ipxe/dummy_pio.h new file mode 100644 index 000000000..1cdabba14 --- /dev/null +++ b/src/include/ipxe/dummy_pio.h @@ -0,0 +1,64 @@ +#ifndef _IPXE_DUMMY_PIO_H +#define _IPXE_DUMMY_PIO_H + +/** @file + * + * Dummy PIO reads and writes up to 32 bits + * + * There is no common standard for I/O-space access for non-x86 CPU + * families, and non-MMIO peripherals are vanishingly rare. Provide + * dummy implementations that will allow code to link and should cause + * drivers to simply fail to detect hardware at runtime. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#define DUMMY_INX( _prefix, _suffix, _type ) \ +static inline __always_inline _type \ +IOAPI_INLINE ( _prefix, in ## _suffix ) ( volatile _type *io_addr __unused) { \ + return ~( (_type) 0 ); \ +} \ +static inline __always_inline void \ +IOAPI_INLINE ( _prefix, ins ## _suffix ) ( volatile _type *io_addr __unused, \ + _type *data, unsigned int count ) {\ + memset ( data, 0xff, count * sizeof ( *data ) ); \ +} + +#define DUMMY_OUTX( _prefix, _suffix, _type ) \ +static inline __always_inline void \ +IOAPI_INLINE ( _prefix, out ## _suffix ) ( _type data __unused, \ + volatile _type *io_addr __unused ){\ + /* Do nothing */ \ +} \ +static inline __always_inline void \ +IOAPI_INLINE ( _prefix, outs ## _suffix ) ( volatile _type *io_addr __unused, \ + const _type *data __unused, \ + unsigned int count __unused ) { \ + /* Do nothing */ \ +} + +#define DUMMY_IODELAY( _prefix ) \ +static inline __always_inline void \ +IOAPI_INLINE ( _prefix, iodelay ) ( void ) { \ + /* Nothing to do */ \ +} + +#define DUMMY_PIO( _prefix ) \ + DUMMY_INX ( _prefix, b, uint8_t ); \ + DUMMY_INX ( _prefix, w, uint16_t ); \ + DUMMY_INX ( _prefix, l, uint32_t ); \ + DUMMY_OUTX ( _prefix, b, uint8_t ); \ + DUMMY_OUTX ( _prefix, w, uint16_t ); \ + DUMMY_OUTX ( _prefix, l, uint32_t ); \ + DUMMY_IODELAY ( _prefix ); + +#define PROVIDE_DUMMY_PIO( _prefix ) \ + PROVIDE_IOAPI_INLINE ( _prefix, inb ); \ + PROVIDE_IOAPI_INLINE ( _prefix, inw ); \ + PROVIDE_IOAPI_INLINE ( _prefix, inl ); \ + PROVIDE_IOAPI_INLINE ( _prefix, outb ); \ + PROVIDE_IOAPI_INLINE ( _prefix, outw ); \ + PROVIDE_IOAPI_INLINE ( _prefix, outl ); \ + PROVIDE_IOAPI_INLINE ( _prefix, iodelay ); + +#endif /* _IPXE_DUMMY_PIO_H */ -- cgit v1.2.3-55-g7522 From 0c67a3632dae9132b519f8b9d64453fff175322d Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Thu, 29 Jun 2023 15:30:08 +0100 Subject: [loong64] Add I/O API for LoongArch64 Signed-off-by: Xiaotian Wu Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/loong64/core/loong64_io.c | 46 +++++++++++++++++ src/arch/loong64/include/bits/io.h | 2 + src/arch/loong64/include/ipxe/loong64_io.h | 82 ++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 src/arch/loong64/core/loong64_io.c create mode 100644 src/arch/loong64/include/ipxe/loong64_io.h (limited to 'src/arch') diff --git a/src/arch/loong64/core/loong64_io.c b/src/arch/loong64/core/loong64_io.c new file mode 100644 index 000000000..6e2a78af3 --- /dev/null +++ b/src/arch/loong64/core/loong64_io.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, Xiaotian Wu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * You can also choose to distribute this program under the terms of + * the Unmodified Binary Distribution Licence (as given in the file + * COPYING.UBDL), provided that you have satisfied its requirements. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include +#include + +/** @file + * + * iPXE I/O API for LoongArch64 + * + */ + +PROVIDE_IOAPI_INLINE ( loong64, phys_to_bus ); +PROVIDE_IOAPI_INLINE ( loong64, bus_to_phys ); +PROVIDE_IOAPI_INLINE ( loong64, readb ); +PROVIDE_IOAPI_INLINE ( loong64, readw ); +PROVIDE_IOAPI_INLINE ( loong64, readl ); +PROVIDE_IOAPI_INLINE ( loong64, readq ); +PROVIDE_IOAPI_INLINE ( loong64, writeb ); +PROVIDE_IOAPI_INLINE ( loong64, writew ); +PROVIDE_IOAPI_INLINE ( loong64, writel ); +PROVIDE_IOAPI_INLINE ( loong64, writeq ); +PROVIDE_IOAPI_INLINE ( loong64, mb ); +PROVIDE_DUMMY_PIO ( loong64 ); diff --git a/src/arch/loong64/include/bits/io.h b/src/arch/loong64/include/bits/io.h index 20ca6a7ba..e9bcf2eea 100644 --- a/src/arch/loong64/include/bits/io.h +++ b/src/arch/loong64/include/bits/io.h @@ -12,4 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** Page shift */ #define PAGE_SHIFT 12 +#include + #endif /* _BITS_IO_H */ diff --git a/src/arch/loong64/include/ipxe/loong64_io.h b/src/arch/loong64/include/ipxe/loong64_io.h new file mode 100644 index 000000000..939fbf2b4 --- /dev/null +++ b/src/arch/loong64/include/ipxe/loong64_io.h @@ -0,0 +1,82 @@ +#ifndef _IPXE_LOONG64_IO_H +#define _IPXE_LOONG64_IO_H + +/** @file + * + * iPXE I/O API for LoongArch64 + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#ifdef IOAPI_LOONG64 +#define IOAPI_PREFIX_loong64 +#else +#define IOAPI_PREFIX_loong64 __loong64_ +#endif + +#include + +/* + * Memory space mappings + * + */ + +/* + * Physical<->Bus address mappings + * + */ + +static inline __always_inline unsigned long +IOAPI_INLINE ( loong64, phys_to_bus ) ( unsigned long phys_addr ) { + return phys_addr; +} + +static inline __always_inline unsigned long +IOAPI_INLINE ( loong64, bus_to_phys ) ( unsigned long bus_addr ) { + return bus_addr; +} + +/* + * MMIO reads and writes up to native word size + * + */ + +#define LOONG64_READX( _suffix, _type, _insn_suffix ) \ +static inline __always_inline _type \ +IOAPI_INLINE ( loong64, read ## _suffix ) ( volatile _type *io_addr ) { \ + _type data; \ + __asm__ __volatile__ ( "ld." _insn_suffix " %0, %1" \ + : "=r" ( data ) : "m" ( *io_addr ) ); \ + return data; \ +} +LOONG64_READX ( b, uint8_t, "bu"); +LOONG64_READX ( w, uint16_t, "hu"); +LOONG64_READX ( l, uint32_t, "wu"); +LOONG64_READX ( q, uint64_t, "d"); + +#define LOONG64_WRITEX( _suffix, _type, _insn_suffix ) \ +static inline __always_inline void \ +IOAPI_INLINE ( loong64, write ## _suffix ) ( _type data, \ + volatile _type *io_addr ) { \ + __asm__ __volatile__ ( "st." _insn_suffix " %0, %1" \ + : : "r" ( data ), "m" ( *io_addr ) ); \ +} +LOONG64_WRITEX ( b, uint8_t, "b"); +LOONG64_WRITEX ( w, uint16_t, "h"); +LOONG64_WRITEX ( l, uint32_t, "w" ); +LOONG64_WRITEX ( q, uint64_t, "d"); + +/* + * Memory barrier + * + */ +static inline __always_inline void +IOAPI_INLINE ( loong64, mb ) ( void ) { + __asm__ __volatile__ ( "dbar 0" ); +} + +/* Dummy PIO */ +DUMMY_PIO ( loong64 ); + +#endif /* _IPXE_LOONG64_IO_H */ -- cgit v1.2.3-55-g7522 From 6d98e0ca47b29c0041ce1aaea18b825105a354af Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Thu, 29 Jun 2023 15:49:27 +0100 Subject: [loong64] Add CPU sleeping API for EFI LoongArch64 Signed-off-by: Xiaotian Wu Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/loong64/Makefile | 1 + src/arch/loong64/include/bits/nap.h | 4 +- src/arch/loong64/include/ipxe/efi/efiloong64_nap.h | 18 ++++++++ src/arch/loong64/interface/efi/efiloong64_nap.c | 53 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/arch/loong64/include/ipxe/efi/efiloong64_nap.h create mode 100644 src/arch/loong64/interface/efi/efiloong64_nap.c (limited to 'src/arch') diff --git a/src/arch/loong64/Makefile b/src/arch/loong64/Makefile index f2dfc76e9..fd0bf137f 100644 --- a/src/arch/loong64/Makefile +++ b/src/arch/loong64/Makefile @@ -20,6 +20,7 @@ CFLAGS += -fshort-wchar # LoongArch64-specific directories containing source files SRCDIRS += arch/loong64/core +SRCDIRS += arch/loong64/interface/efi # Include platform-specific Makefile MAKEDEPS += arch/loong64/Makefile.$(PLATFORM) diff --git a/src/arch/loong64/include/bits/nap.h b/src/arch/loong64/include/bits/nap.h index 91e255d96..2deba3558 100644 --- a/src/arch/loong64/include/bits/nap.h +++ b/src/arch/loong64/include/bits/nap.h @@ -9,4 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#endif /* _BITS_MAP_H */ +#include + +#endif /* _BITS_NAP_H */ diff --git a/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h b/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h new file mode 100644 index 000000000..5c0d38636 --- /dev/null +++ b/src/arch/loong64/include/ipxe/efi/efiloong64_nap.h @@ -0,0 +1,18 @@ +#ifndef _IPXE_EFILOONG64_NAP_H +#define _IPXE_EFILOONG64_NAP_H + +/** @file + * + * EFI CPU sleeping + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#ifdef NAP_EFILOONG64 +#define NAP_PREFIX_efiloong64 +#else +#define NAP_PREFIX_efiloong64 __efiloong64_ +#endif + +#endif /* _IPXE_EFILOONG64_NAP_H */ diff --git a/src/arch/loong64/interface/efi/efiloong64_nap.c b/src/arch/loong64/interface/efi/efiloong64_nap.c new file mode 100644 index 000000000..5cd1c1b94 --- /dev/null +++ b/src/arch/loong64/interface/efi/efiloong64_nap.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Xiaotian Wu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * You can also choose to distribute this program under the terms of + * the Unmodified Binary Distribution Licence (as given in the file + * COPYING.UBDL), provided that you have satisfied its requirements. + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include +#include + +/** @file + * + * iPXE CPU sleeping API for EFI + * + */ + +/** + * Sleep until next interrupt + * + */ +static void efiloong64_cpu_nap ( void ) { + /* + * I can't find any EFI API that allows us to put the CPU to + * sleep. The CpuSleep() function is defined in CpuLib.h, but + * isn't part of any exposed protocol so we have no way to + * call it. + * + * The EFI shell doesn't seem to bother sleeping the CPU; it + * just sits there idly burning power. + * + */ + __asm__ __volatile__ ( "idle 0" ); +} + +PROVIDE_NAP ( efiloong64, cpu_nap, efiloong64_cpu_nap ); -- cgit v1.2.3-55-g7522 From 280942a92a4567796976e06d186d0a199ae0337e Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Thu, 29 Jun 2023 15:52:28 +0100 Subject: [loong64] Add support for building EFI binaries Signed-off-by: Xiaotian Wu Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/loong64/Makefile.efi | 14 ++++++++++++++ src/config/defaults/efi.h | 5 +++++ 2 files changed, 19 insertions(+) create mode 100644 src/arch/loong64/Makefile.efi (limited to 'src/arch') diff --git a/src/arch/loong64/Makefile.efi b/src/arch/loong64/Makefile.efi new file mode 100644 index 000000000..1c51bcd67 --- /dev/null +++ b/src/arch/loong64/Makefile.efi @@ -0,0 +1,14 @@ +# -*- makefile -*- : Force emacs to use Makefile mode + +# Specify EFI image builder +# +ELF2EFI = $(ELF2EFI64) + +# Specify EFI boot file +# +EFI_BOOT_FILE = bootloongarch64.efi + +# Include generic EFI Makefile +# +MAKEDEPS += Makefile.efi +include Makefile.efi diff --git a/src/config/defaults/efi.h b/src/config/defaults/efi.h index cb9e2348a..e39d475b7 100644 --- a/src/config/defaults/efi.h +++ b/src/config/defaults/efi.h @@ -67,4 +67,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define IMAGE_GZIP /* GZIP image support */ #endif +#if defined ( __loongarch__ ) +#define IOAPI_LOONG64 +#define NAP_EFILOONG64 +#endif + #endif /* CONFIG_DEFAULTS_EFI_H */ -- cgit v1.2.3-55-g7522 From 2524a60550b7b81d32447782e42485997b9af175 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 30 Jun 2023 10:31:52 +0100 Subject: [build] Avoid using multiple target patterns in pattern rules Multiple target patterns in pattern rules are treated as grouped targets regardless of the separator character. Newer verions of make will generate "warning: pattern recipe did not update peer target" to warn that the rule was expected to update all of the (implicitly) grouped targets. Fix by splitting all multiple target pattern rules into single target pattern rules. Signed-off-by: Michael Brown --- src/Makefile.efi | 6 +++++- src/arch/x86/Makefile.pcbios | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/arch') diff --git a/src/Makefile.efi b/src/Makefile.efi index bd479b3da..6e8ad46bc 100644 --- a/src/Makefile.efi +++ b/src/Makefile.efi @@ -50,6 +50,10 @@ $(BIN)/efidrv.cab : $(BIN)/alldrv.efis # $(ALL_drv.efi) is not yet defined $(QM)$(ECHO) " [CAB] $@" $(Q)$(LCAB) -n -q $(ALL_drv.efi) $@ -$(BIN)/%.iso $(BIN)/%.usb : $(BIN)/%.efi util/genfsimg +$(BIN)/%.iso : $(BIN)/%.efi util/genfsimg + $(QM)$(ECHO) " [GENFSIMG] $@" + $(Q)util/genfsimg -o $@ $< + +$(BIN)/%.usb : $(BIN)/%.efi util/genfsimg $(QM)$(ECHO) " [GENFSIMG] $@" $(Q)util/genfsimg -o $@ $< diff --git a/src/arch/x86/Makefile.pcbios b/src/arch/x86/Makefile.pcbios index ed8d554a7..b9f8e6c28 100644 --- a/src/arch/x86/Makefile.pcbios +++ b/src/arch/x86/Makefile.pcbios @@ -54,9 +54,15 @@ LIST_NAME_mrom := ROMS LIST_NAME_pcirom := ROMS LIST_NAME_isarom := ROMS -# ISO or FAT filesystem images +# ISO images NON_AUTO_MEDIA += iso -$(BIN)/%.iso $(BIN)/%.sdsk: $(BIN)/%.lkrn util/genfsimg +$(BIN)/%.iso : $(BIN)/%.lkrn util/genfsimg + $(QM)$(ECHO) " [GENFSIMG] $@" + $(Q)util/genfsimg -o $@ $< + +# FAT filesystem images (via syslinux) +NON_AUTO_MEDIA += sdsk +$(BIN)/%.sdsk : $(BIN)/%.lkrn util/genfsimg $(QM)$(ECHO) " [GENFSIMG] $@" $(Q)util/genfsimg -o $@ $< -- cgit v1.2.3-55-g7522 From e17568ad0642490143d0c6b154c874b9b9e285bf Mon Sep 17 00:00:00 2001 From: Geert Stappers Date: Fri, 30 Jun 2023 10:59:59 +0100 Subject: [build] Inhibit linker warnings about an implied executable stack Signed-off-by: Geert Stappers Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/arm64/core/setjmp.S | 1 + src/arch/i386/core/gdbidt.S | 1 + src/arch/i386/core/setjmp.S | 1 + src/arch/i386/tests/gdbstub_test.S | 1 + src/arch/x86/core/patch_cf.S | 1 + src/arch/x86/core/stack.S | 1 + src/arch/x86/core/stack16.S | 1 + src/arch/x86/drivers/net/undiisr.S | 1 + src/arch/x86/interface/pcbios/e820mangler.S | 1 + src/arch/x86/interface/pxe/pxe_entry.S | 1 + src/arch/x86/interface/syslinux/com32_wrapper.S | 1 + src/arch/x86/prefix/bootpart.S | 1 + src/arch/x86/prefix/dskprefix.S | 1 + src/arch/x86/prefix/exeprefix.S | 1 + src/arch/x86/prefix/hdprefix.S | 1 + src/arch/x86/prefix/libprefix.S | 1 + src/arch/x86/prefix/lkrnprefix.S | 1 + src/arch/x86/prefix/mbr.S | 1 + src/arch/x86/prefix/mromprefix.S | 1 + src/arch/x86/prefix/nbiprefix.S | 1 + src/arch/x86/prefix/nullprefix.S | 1 + src/arch/x86/prefix/pxeprefix.S | 1 + src/arch/x86/prefix/rawprefix.S | 1 + src/arch/x86/prefix/romprefix.S | 1 + src/arch/x86/prefix/undiloader.S | 1 + src/arch/x86/prefix/unlzma.S | 1 + src/arch/x86/prefix/usbdisk.S | 1 + src/arch/x86/transitions/liba20.S | 1 + src/arch/x86/transitions/libkir.S | 1 + src/arch/x86/transitions/librm.S | 2 ++ src/arch/x86_64/core/gdbidt.S | 1 + src/arch/x86_64/core/setjmp.S | 1 + 32 files changed, 33 insertions(+) (limited to 'src/arch') diff --git a/src/arch/arm64/core/setjmp.S b/src/arch/arm64/core/setjmp.S index fa47aa0af..c5c77c1fb 100644 --- a/src/arch/arm64/core/setjmp.S +++ b/src/arch/arm64/core/setjmp.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", %progbits .text /* Must match jmp_buf structure layout */ diff --git a/src/arch/i386/core/gdbidt.S b/src/arch/i386/core/gdbidt.S index 666ecce3c..78945c62c 100644 --- a/src/arch/i386/core/gdbidt.S +++ b/src/arch/i386/core/gdbidt.S @@ -9,6 +9,7 @@ * Interrupt handlers **************************************************************************** */ + .section ".note.GNU-stack", "", @progbits .section ".text", "ax", @progbits .code32 diff --git a/src/arch/i386/core/setjmp.S b/src/arch/i386/core/setjmp.S index 81d3b4911..e0bbb7ef8 100644 --- a/src/arch/i386/core/setjmp.S +++ b/src/arch/i386/core/setjmp.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code32 diff --git a/src/arch/i386/tests/gdbstub_test.S b/src/arch/i386/tests/gdbstub_test.S index 739b0527a..e0c9e6c9a 100644 --- a/src/arch/i386/tests/gdbstub_test.S +++ b/src/arch/i386/tests/gdbstub_test.S @@ -1,3 +1,4 @@ + .section ".note.GNU-stack", "", @progbits .arch i386 .section ".data", "aw", @progbits diff --git a/src/arch/x86/core/patch_cf.S b/src/arch/x86/core/patch_cf.S index 4365563fe..63730c3fd 100644 --- a/src/arch/x86/core/patch_cf.S +++ b/src/arch/x86/core/patch_cf.S @@ -22,6 +22,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/core/stack.S b/src/arch/x86/core/stack.S index baa19ff84..493453473 100644 --- a/src/arch/x86/core/stack.S +++ b/src/arch/x86/core/stack.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .arch i386 #ifdef __x86_64__ diff --git a/src/arch/x86/core/stack16.S b/src/arch/x86/core/stack16.S index ad67e4f2d..d3949a557 100644 --- a/src/arch/x86/core/stack16.S +++ b/src/arch/x86/core/stack16.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .arch i386 /**************************************************************************** diff --git a/src/arch/x86/drivers/net/undiisr.S b/src/arch/x86/drivers/net/undiisr.S index 2428d1f5d..a1098b839 100644 --- a/src/arch/x86/drivers/net/undiisr.S +++ b/src/arch/x86/drivers/net/undiisr.S @@ -10,6 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER ) #define PIC1_ICR 0x20 #define PIC2_ICR 0xa0 + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/interface/pcbios/e820mangler.S b/src/arch/x86/interface/pcbios/e820mangler.S index 296a6488b..46e1cab4d 100644 --- a/src/arch/x86/interface/pcbios/e820mangler.S +++ b/src/arch/x86/interface/pcbios/e820mangler.S @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/interface/pxe/pxe_entry.S b/src/arch/x86/interface/pxe/pxe_entry.S index 3a5a100e3..354dd1b35 100644 --- a/src/arch/x86/interface/pxe/pxe_entry.S +++ b/src/arch/x86/interface/pxe/pxe_entry.S @@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .arch i386 /**************************************************************************** diff --git a/src/arch/x86/interface/syslinux/com32_wrapper.S b/src/arch/x86/interface/syslinux/com32_wrapper.S index d59a3392c..501919565 100644 --- a/src/arch/x86/interface/syslinux/com32_wrapper.S +++ b/src/arch/x86/interface/syslinux/com32_wrapper.S @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER ) #include "librm.h" + .section ".note.GNU-stack", "", @progbits .text .code32 diff --git a/src/arch/x86/prefix/bootpart.S b/src/arch/x86/prefix/bootpart.S index 6d0c6034a..575cb1c07 100644 --- a/src/arch/x86/prefix/bootpart.S +++ b/src/arch/x86/prefix/bootpart.S @@ -5,6 +5,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define STACK_SEG 0x0200 #define STACK_SIZE 0x2000 + .section ".note.GNU-stack", "", @progbits .text .arch i386 .section ".prefix", "awx", @progbits diff --git a/src/arch/x86/prefix/dskprefix.S b/src/arch/x86/prefix/dskprefix.S index 0503f113d..bc1948879 100644 --- a/src/arch/x86/prefix/dskprefix.S +++ b/src/arch/x86/prefix/dskprefix.S @@ -24,6 +24,7 @@ FILE_LICENCE ( GPL2_ONLY ) .equ SYSSEG, 0x1000 /* system loaded at SYSSEG<<4 */ + .section ".note.GNU-stack", "", @progbits .org 0 .arch i386 .text diff --git a/src/arch/x86/prefix/exeprefix.S b/src/arch/x86/prefix/exeprefix.S index 0eab8c12a..5b2605e8d 100644 --- a/src/arch/x86/prefix/exeprefix.S +++ b/src/arch/x86/prefix/exeprefix.S @@ -36,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define PSP_CMDLINE_LEN 0x80 #define PSP_CMDLINE_START 0x81 + .section ".note.GNU-stack", "", @progbits .text .arch i386 .org 0 diff --git a/src/arch/x86/prefix/hdprefix.S b/src/arch/x86/prefix/hdprefix.S index 28c8a532d..fbf8d2e47 100644 --- a/src/arch/x86/prefix/hdprefix.S +++ b/src/arch/x86/prefix/hdprefix.S @@ -2,6 +2,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .text .arch i386 .section ".prefix", "awx", @progbits diff --git a/src/arch/x86/prefix/libprefix.S b/src/arch/x86/prefix/libprefix.S index d7f261957..380e471dd 100644 --- a/src/arch/x86/prefix/libprefix.S +++ b/src/arch/x86/prefix/libprefix.S @@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .arch i386 /* Image compression enabled */ diff --git a/src/arch/x86/prefix/lkrnprefix.S b/src/arch/x86/prefix/lkrnprefix.S index 922181f0e..2c17f79df 100644 --- a/src/arch/x86/prefix/lkrnprefix.S +++ b/src/arch/x86/prefix/lkrnprefix.S @@ -4,6 +4,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define BZI_LOAD_HIGH_ADDR 0x100000 + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/prefix/mbr.S b/src/arch/x86/prefix/mbr.S index 032c0e775..928bb338b 100644 --- a/src/arch/x86/prefix/mbr.S +++ b/src/arch/x86/prefix/mbr.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .section ".prefix", "awx", @progbits diff --git a/src/arch/x86/prefix/mromprefix.S b/src/arch/x86/prefix/mromprefix.S index d08284d7a..5f3496b28 100644 --- a/src/arch/x86/prefix/mromprefix.S +++ b/src/arch/x86/prefix/mromprefix.S @@ -41,6 +41,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define _pcirom_start _mrom_start #include "pciromprefix.S" + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/prefix/nbiprefix.S b/src/arch/x86/prefix/nbiprefix.S index de38e4af6..cae1009b3 100644 --- a/src/arch/x86/prefix/nbiprefix.S +++ b/src/arch/x86/prefix/nbiprefix.S @@ -2,6 +2,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .text .arch i386 .code16 diff --git a/src/arch/x86/prefix/nullprefix.S b/src/arch/x86/prefix/nullprefix.S index bd0ff339e..1568188d0 100644 --- a/src/arch/x86/prefix/nullprefix.S +++ b/src/arch/x86/prefix/nullprefix.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .org 0 .text .arch i386 diff --git a/src/arch/x86/prefix/pxeprefix.S b/src/arch/x86/prefix/pxeprefix.S index 52ea18039..494fbc138 100644 --- a/src/arch/x86/prefix/pxeprefix.S +++ b/src/arch/x86/prefix/pxeprefix.S @@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define PXE_HACK_EB54 0x0001 + .section ".note.GNU-stack", "", @progbits .text .arch i386 .org 0 diff --git a/src/arch/x86/prefix/rawprefix.S b/src/arch/x86/prefix/rawprefix.S index 4cf5f391e..4a3d35042 100644 --- a/src/arch/x86/prefix/rawprefix.S +++ b/src/arch/x86/prefix/rawprefix.S @@ -8,6 +8,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .arch i386 .org 0 diff --git a/src/arch/x86/prefix/romprefix.S b/src/arch/x86/prefix/romprefix.S index 4e8793c21..79fed2a35 100644 --- a/src/arch/x86/prefix/romprefix.S +++ b/src/arch/x86/prefix/romprefix.S @@ -54,6 +54,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define BUSTYPE "PCIR" #endif + .section ".note.GNU-stack", "", @progbits .text .code16 .arch i386 diff --git a/src/arch/x86/prefix/undiloader.S b/src/arch/x86/prefix/undiloader.S index 1d77110e7..e544d5048 100644 --- a/src/arch/x86/prefix/undiloader.S +++ b/src/arch/x86/prefix/undiloader.S @@ -2,6 +2,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .text .code16 .arch i386 diff --git a/src/arch/x86/prefix/unlzma.S b/src/arch/x86/prefix/unlzma.S index 979f699ee..f4bd81bd2 100644 --- a/src/arch/x86/prefix/unlzma.S +++ b/src/arch/x86/prefix/unlzma.S @@ -43,6 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); **************************************************************************** */ + .section ".note.GNU-stack", "", @progbits .text .arch i486 .section ".prefix.lib", "ax", @progbits diff --git a/src/arch/x86/prefix/usbdisk.S b/src/arch/x86/prefix/usbdisk.S index 977de6dd6..461a08379 100644 --- a/src/arch/x86/prefix/usbdisk.S +++ b/src/arch/x86/prefix/usbdisk.S @@ -2,6 +2,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #include + .section ".note.GNU-stack", "", @progbits .text .arch i386 .section ".prefix", "awx", @progbits diff --git a/src/arch/x86/transitions/liba20.S b/src/arch/x86/transitions/liba20.S index 57603353e..6c1bac672 100644 --- a/src/arch/x86/transitions/liba20.S +++ b/src/arch/x86/transitions/liba20.S @@ -24,6 +24,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .arch i386 /**************************************************************************** diff --git a/src/arch/x86/transitions/libkir.S b/src/arch/x86/transitions/libkir.S index fa9459d52..af090b266 100644 --- a/src/arch/x86/transitions/libkir.S +++ b/src/arch/x86/transitions/libkir.S @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) /* Breakpoint for when debugging under bochs */ #define BOCHSBP xchgw %bx, %bx + .section ".note.GNU-stack", "", @progbits .text .arch i386 .section ".text16", "awx", @progbits diff --git a/src/arch/x86/transitions/librm.S b/src/arch/x86/transitions/librm.S index 5dacb9b04..394313246 100644 --- a/src/arch/x86/transitions/librm.S +++ b/src/arch/x86/transitions/librm.S @@ -83,6 +83,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) #define if64 if 0 #endif + .section ".note.GNU-stack", "", @progbits + /**************************************************************************** * Global descriptor table * diff --git a/src/arch/x86_64/core/gdbidt.S b/src/arch/x86_64/core/gdbidt.S index 89280bf89..477492b47 100644 --- a/src/arch/x86_64/core/gdbidt.S +++ b/src/arch/x86_64/core/gdbidt.S @@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define SIGFPE 8 #define SIGSTKFLT 16 + .section ".note.GNU-stack", "", @progbits .section ".text.gdbmach_interrupt", "ax", @progbits .code64 diff --git a/src/arch/x86_64/core/setjmp.S b/src/arch/x86_64/core/setjmp.S index e43200d7b..5137a72c1 100644 --- a/src/arch/x86_64/core/setjmp.S +++ b/src/arch/x86_64/core/setjmp.S @@ -1,5 +1,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ) + .section ".note.GNU-stack", "", @progbits .text .code64 -- cgit v1.2.3-55-g7522 From 6f57d919357a43507935a5ea78a66702ac0f3d54 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 30 Jun 2023 12:03:41 +0100 Subject: [build] Use separate code segment if supported by linker Some versions of ld will complain that the automatically created (and unused by our build process) ELF program headers include a "LOAD segment with RWX permissions". Silence this warning by adding "-z separate-code" to the linker options, where supported. For BIOS builds, where the prefix will generally require writable access to its own (tiny) code segment, simply inhibit the warning completely via "--no-warn-rwx-segments". Signed-off-by: Michael Brown --- src/Makefile.housekeeping | 7 +++++++ src/arch/x86/Makefile.pcbios | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'src/arch') diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping index b32003ea5..4a90b3ca4 100644 --- a/src/Makefile.housekeeping +++ b/src/Makefile.housekeeping @@ -502,6 +502,13 @@ LDFLAGS += --gc-sections # LDFLAGS += -static +# Use separate code segment if supported by linker +# +ZSC_TEST = $(LD) -z separate-code --version 2>&1 > /dev/null +ZSC_FLAGS := $(shell [ -z "`$(ZSC_TEST)`" ] && \ + $(ECHO) '-z separate-code -z max-page-size=4096') +LDFLAGS += $(ZSC_FLAGS) + # compiler.h is needed for our linking and debugging system # CFLAGS += -include include/compiler.h diff --git a/src/arch/x86/Makefile.pcbios b/src/arch/x86/Makefile.pcbios index b9f8e6c28..38dfa087c 100644 --- a/src/arch/x86/Makefile.pcbios +++ b/src/arch/x86/Makefile.pcbios @@ -13,6 +13,13 @@ LDSCRIPT_PREFIX = arch/x86/scripts/prefixonly.lds # LDFLAGS += -N --no-check-sections +# Do not warn about RWX segments (required by most prefixes) +# +WRWX_TEST = $(LD) --warn-rwx-segments --version 2>&1 > /dev/null +WRWX_FLAGS := $(shell [ -z "`$(WRWX_TEST)`" ] && \ + $(ECHO) '--no-warn-rwx-segments') +LDFLAGS += $(WRWX_FLAGS) + # Media types. # MEDIA += rom -- cgit v1.2.3-55-g7522 From 3ef4f7e2ef4a22ea1e2eccc72957d7bf3fe2f945 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 4 Jul 2023 14:31:07 +0100 Subject: [console] Avoid overlap between special keys and Unicode characters The special key range (from KEY_MIN upwards) currently overlaps with the valid range for Unicode characters, and therefore prohibits the use of Unicode key values outside the ASCII range. Create space for Unicode key values by moving the special keys to the range immediately above the maximum valid Unicode character. This allows the existing encoding of special keys as an efficiently packed representation of the equivalent ANSI escape sequence to be maintained almost as-is. Signed-off-by: Michael Brown --- src/arch/x86/interface/pcbios/bios_console.c | 59 +++++++++++++++++----------- src/drivers/usb/usbkbd.c | 4 +- src/include/ipxe/keys.h | 45 ++++++++++++++++++--- 3 files changed, 77 insertions(+), 31 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/interface/pcbios/bios_console.c b/src/arch/x86/interface/pcbios/bios_console.c index 0220c8564..7263eb712 100644 --- a/src/arch/x86/interface/pcbios/bios_console.c +++ b/src/arch/x86/interface/pcbios/bios_console.c @@ -290,29 +290,38 @@ static const char *bios_ansi_input = ""; struct bios_key { /** Scancode */ uint8_t scancode; - /** Key code */ - uint16_t key; + /** Relative key value */ + uint16_t rkey; } __attribute__ (( packed )); +/** + * Define a BIOS key mapping + * + * @v scancode Scancode + * @v key iPXE key code + * @v bioskey BIOS key mapping + */ +#define BIOS_KEY( scancode, key ) { scancode, KEY_REL ( key ) } + /** Mapping from BIOS scan codes to iPXE key codes */ static const struct bios_key bios_keys[] = { - { 0x53, KEY_DC }, - { 0x48, KEY_UP }, - { 0x50, KEY_DOWN }, - { 0x4b, KEY_LEFT }, - { 0x4d, KEY_RIGHT }, - { 0x47, KEY_HOME }, - { 0x4f, KEY_END }, - { 0x49, KEY_PPAGE }, - { 0x51, KEY_NPAGE }, - { 0x3f, KEY_F5 }, - { 0x40, KEY_F6 }, - { 0x41, KEY_F7 }, - { 0x42, KEY_F8 }, - { 0x43, KEY_F9 }, - { 0x44, KEY_F10 }, - { 0x85, KEY_F11 }, - { 0x86, KEY_F12 }, + BIOS_KEY ( 0x53, KEY_DC ), + BIOS_KEY ( 0x48, KEY_UP ), + BIOS_KEY ( 0x50, KEY_DOWN ), + BIOS_KEY ( 0x4b, KEY_LEFT ), + BIOS_KEY ( 0x4d, KEY_RIGHT ), + BIOS_KEY ( 0x47, KEY_HOME ), + BIOS_KEY ( 0x4f, KEY_END ), + BIOS_KEY ( 0x49, KEY_PPAGE ), + BIOS_KEY ( 0x51, KEY_NPAGE ), + BIOS_KEY ( 0x3f, KEY_F5 ), + BIOS_KEY ( 0x40, KEY_F6 ), + BIOS_KEY ( 0x41, KEY_F7 ), + BIOS_KEY ( 0x42, KEY_F8 ), + BIOS_KEY ( 0x43, KEY_F9 ), + BIOS_KEY ( 0x44, KEY_F10 ), + BIOS_KEY ( 0x85, KEY_F11 ), + BIOS_KEY ( 0x86, KEY_F12 ), }; /** @@ -323,7 +332,7 @@ static const struct bios_key bios_keys[] = { */ static const char * bios_ansi_seq ( unsigned int scancode ) { static char buf[ 5 /* "[" + two digits + terminator + NUL */ ]; - unsigned int key; + unsigned int rkey; unsigned int terminator; unsigned int n; unsigned int i; @@ -338,9 +347,9 @@ static const char * bios_ansi_seq ( unsigned int scancode ) { continue; /* Construct escape sequence */ - key = bios_keys[i].key; - n = KEY_ANSI_N ( key ); - terminator = KEY_ANSI_TERMINATOR ( key ); + rkey = bios_keys[i].rkey; + n = KEY_ANSI_N ( rkey ); + terminator = KEY_ANSI_TERMINATOR ( rkey ); *(tmp++) = '['; if ( n ) tmp += sprintf ( tmp, "%d", n ); @@ -479,6 +488,7 @@ struct console_driver bios_console __console_driver = { static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) { unsigned int discard_a; unsigned int scancode; + unsigned int rkey; unsigned int i; uint16_t keypress; int key; @@ -521,9 +531,10 @@ static __asmcall __used void bios_inject ( struct i386_all_regs *ix86 ) { /* Handle special keys */ if ( key >= KEY_MIN ) { + rkey = KEY_REL ( key ); for ( i = 0 ; i < ( sizeof ( bios_keys ) / sizeof ( bios_keys[0] ) ) ; i++ ) { - if ( bios_keys[i].key == key ) { + if ( bios_keys[i].rkey == rkey ) { scancode = bios_keys[i].scancode; keypress = ( scancode << 8 ); break; diff --git a/src/drivers/usb/usbkbd.c b/src/drivers/usb/usbkbd.c index b284e584f..cf881ad1a 100644 --- a/src/drivers/usb/usbkbd.c +++ b/src/drivers/usb/usbkbd.c @@ -95,7 +95,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, } } else if ( keycode <= USBKBD_KEY_UP ) { /* Special keys */ - static const uint16_t special[] = { + static const unsigned int special[] = { 0, 0, 0, 0, 0, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, 0, 0, 0, KEY_IC, KEY_HOME, KEY_PPAGE, KEY_DC, KEY_END, KEY_NPAGE, KEY_RIGHT, @@ -110,7 +110,7 @@ static unsigned int usbkbd_map ( unsigned int keycode, unsigned int modifiers, if ( leds & USBKBD_LED_NUM_LOCK ) { key = "1234567890." [ keycode - USBKBD_KEY_PAD_1 ]; } else { - static const uint16_t keypad[] = { + static const unsigned int keypad[] = { KEY_END, KEY_DOWN, KEY_NPAGE, KEY_LEFT, 0, KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PPAGE, KEY_IC, KEY_DC diff --git a/src/include/ipxe/keys.h b/src/include/ipxe/keys.h index d15267a1f..23356913d 100644 --- a/src/include/ipxe/keys.h +++ b/src/include/ipxe/keys.h @@ -49,19 +49,54 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #define ESC 0x1b /* - * Special keys outside the normal ASCII range - * + * Special keys outside the normal Unicode range * * The names are chosen to match those used by curses. The values are * chosen to facilitate easy conversion from a received ANSI escape * sequence to a KEY_XXX constant. */ -#define KEY_ANSI( n, terminator ) ( 0x100 * ( (n) + 1 ) + (terminator) ) -#define KEY_ANSI_N( key ) ( ( (key) / 0x100 ) - 1 ) +/** + * Minimum value for special keypresses + * + * This value is chosen to lie above the maximum Unicode code point + * value 0x10ffff. + */ +#define KEY_MIN 0x110000 + +/** + * Construct relative key value for special key + * + * @v key Key value + * @ret rkey Relative key value + */ +#define KEY_REL( key ) ( (key) - KEY_MIN ) + +/** + * Construct ANSI escape sequence key value + * + * @v n ANSI escape sequence numeric portion, or 0 for none + * @v terminator ANSI escape sequence terminating character + * @ret key Key value + */ +#define KEY_ANSI( n, terminator ) ( KEY_MIN + ( (n) << 8 ) + (terminator) ) + +/** + * Extract ANSI escape sequence numeric portion + * + * @v key Key value (or relative key value) + * @ret n ANSI escape sequence numeric portion, or 0 for none + */ +#define KEY_ANSI_N( key ) ( ( (key) >> 8 ) & 0xff ) + +/** + * Extract ANSI escape sequence terminating character + * + * @v key Key value (or relative key value) + * @ret terminator ANSI escape sequence terminating character + */ #define KEY_ANSI_TERMINATOR( key ) ( (key) & 0xff ) -#define KEY_MIN 0x101 #define KEY_UP KEY_ANSI ( 0, 'A' ) /**< Up arrow */ #define KEY_DOWN KEY_ANSI ( 0, 'B' ) /**< Down arrow */ #define KEY_RIGHT KEY_ANSI ( 0, 'C' ) /**< Right arrow */ -- cgit v1.2.3-55-g7522 From 0aa2e4ec963597794dd8f8b36f77f4d0cf4e03c8 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 5 Sep 2023 12:46:39 +0100 Subject: [librm] Use explicit operand size when pushing a label address We currently use "push $1f" within inline assembly to push the address of the real-mode code fragment, relying on the assembler to treat this as "pushl" for 32-bit code or "pushq" for 64-bit code. As of binutils commit 5cc0077 ("x86: further adjust extend-to-32bit- address conditions"), first included in binutils-2.41, this implicit operand size is no longer calculated as expected and 64-bit builds will fail with Error: operand size mismatch for `push' Fix by adding an explicit operand size to the "push" instruction. Originally-fixed-by: Justin Cano Signed-off-by: Michael Brown --- src/arch/x86/include/librm.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/include/librm.h b/src/arch/x86/include/librm.h index 5196d390f..40f075439 100644 --- a/src/arch/x86/include/librm.h +++ b/src/arch/x86/include/librm.h @@ -250,8 +250,10 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size ); /* CODE_DEFAULT: restore default .code32/.code64 directive */ #ifdef __x86_64__ #define CODE_DEFAULT ".code64" +#define STACK_DEFAULT "q" #else #define CODE_DEFAULT ".code32" +#define STACK_DEFAULT "l" #endif /* LINE_SYMBOL: declare a symbol for the current source code line */ @@ -268,7 +270,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size ); /* REAL_CODE: declare a fragment of code that executes in real mode */ #define REAL_CODE( asm_code_str ) \ - "push $1f\n\t" \ + "push" STACK_DEFAULT " $1f\n\t" \ "call real_call\n\t" \ TEXT16_CODE ( "\n1:\n\t" \ asm_code_str \ @@ -277,7 +279,7 @@ extern void remove_user_from_rm_stack ( userptr_t data, size_t size ); /* PHYS_CODE: declare a fragment of code that executes in flat physical mode */ #define PHYS_CODE( asm_code_str ) \ - "push $1f\n\t" \ + "push" STACK_DEFAULT " $1f\n\t" \ "call phys_call\n\t" \ ".section \".text.phys\", \"ax\", @progbits\n\t"\ "\n" LINE_SYMBOL "\n\t" \ -- cgit v1.2.3-55-g7522 From ae4e85bde97c9b216736a5087039f3309a628d24 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 13 Sep 2023 16:29:59 +0100 Subject: [netdevice] Allocate private data for each network upper-layer driver Allow network upper-layer drivers (such as LLDP, which attaches to each network device in order to provide a corresponding LLDP settings block) to specify a size for private data, which will be allocated as part of the network device structure (as with the existing private data allocated for the underlying device driver). This will allow network upper-layer drivers to be simplified by omitting memory allocation and freeing code. If the upper-layer driver requires a reference counter (e.g. for interface initialisation), then it may use the network device's existing reference counter, since this is now the reference counter for the containing block of memory. Signed-off-by: Michael Brown --- src/arch/x86/interface/pxe/pxe_call.c | 3 +- src/arch/x86/interface/vmware/guestinfo.c | 8 +++- src/core/cachedhcp.c | 3 +- src/drivers/net/netfront.c | 4 +- src/include/ipxe/netdevice.h | 13 ++++-- src/interface/efi/efi_snp.c | 9 ++-- src/net/fcoe.c | 9 ++-- src/net/infiniband/xsigo.c | 4 +- src/net/ipv6.c | 4 +- src/net/lldp.c | 3 +- src/net/neighbour.c | 3 +- src/net/netdevice.c | 72 +++++++++++++++++++++++++------ src/net/vlan.c | 9 ++-- 13 files changed, 110 insertions(+), 34 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/interface/pxe/pxe_call.c b/src/arch/x86/interface/pxe/pxe_call.c index 671182991..0e8d5c5a8 100644 --- a/src/arch/x86/interface/pxe/pxe_call.c +++ b/src/arch/x86/interface/pxe/pxe_call.c @@ -375,9 +375,10 @@ int pxe_start_nbp ( void ) { * Notify BIOS of existence of network device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int pxe_notify ( struct net_device *netdev ) { +static int pxe_notify ( struct net_device *netdev, void *priv __unused ) { /* Do nothing if we already have a network device */ if ( pxe_netdev ) diff --git a/src/arch/x86/interface/vmware/guestinfo.c b/src/arch/x86/interface/vmware/guestinfo.c index a0530c8d1..b52c2e87b 100644 --- a/src/arch/x86/interface/vmware/guestinfo.c +++ b/src/arch/x86/interface/vmware/guestinfo.c @@ -207,9 +207,11 @@ struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL ) = { * Create per-netdevice GuestInfo settings * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int guestinfo_net_probe ( struct net_device *netdev ) { +static int guestinfo_net_probe ( struct net_device *netdev, + void *priv __unused ) { struct settings *settings; int rc; @@ -247,8 +249,10 @@ static int guestinfo_net_probe ( struct net_device *netdev ) { * Remove per-netdevice GuestInfo settings * * @v netdev Network device + * @v priv Private data */ -static void guestinfo_net_remove ( struct net_device *netdev ) { +static void guestinfo_net_remove ( struct net_device *netdev, + void *priv __unused ) { struct settings *parent = netdev_settings ( netdev ); struct settings *settings; diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c index 60213f02d..57226e165 100644 --- a/src/core/cachedhcp.c +++ b/src/core/cachedhcp.c @@ -295,9 +295,10 @@ struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = { * Apply cached DHCPACK to network device, if applicable * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int cachedhcp_probe ( struct net_device *netdev ) { +static int cachedhcp_probe ( struct net_device *netdev, void *priv __unused ) { /* Apply cached DHCPACK to network device, if applicable */ return cachedhcp_apply ( &cached_dhcpack, netdev ); diff --git a/src/drivers/net/netfront.c b/src/drivers/net/netfront.c index 90930a5a3..12713c5b4 100644 --- a/src/drivers/net/netfront.c +++ b/src/drivers/net/netfront.c @@ -1056,9 +1056,11 @@ struct xen_driver netfront_driver __xen_driver = { * Inhibit emulated PCI devices * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int netfront_net_probe ( struct net_device *netdev ) { +static int netfront_net_probe ( struct net_device *netdev, + void *priv __unused ) { struct netfront_nic *netfront; /* Inhibit emulated PCI devices matching an existing netfront device */ diff --git a/src/include/ipxe/netdevice.h b/src/include/ipxe/netdevice.h index a65dbfd23..caa83b44b 100644 --- a/src/include/ipxe/netdevice.h +++ b/src/include/ipxe/netdevice.h @@ -473,22 +473,27 @@ struct net_device { struct net_driver { /** Name */ const char *name; + /** Size of private data */ + size_t priv_len; /** Probe device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ - int ( * probe ) ( struct net_device *netdev ); + int ( * probe ) ( struct net_device *netdev, void *priv ); /** Notify of device or link state change * * @v netdev Network device + * @v priv Private data */ - void ( * notify ) ( struct net_device *netdev ); + void ( * notify ) ( struct net_device *netdev, void *priv ); /** Remove device * * @v netdev Network device + * @v priv Private data */ - void ( * remove ) ( struct net_device *netdev ); + void ( * remove ) ( struct net_device *netdev, void *priv ); }; /** Network driver table */ @@ -688,6 +693,8 @@ netdev_rx_frozen ( struct net_device *netdev ) { return ( netdev->state & NETDEV_RX_FROZEN ); } +extern void * netdev_priv ( struct net_device *netdev, + struct net_driver *driver ); extern void netdev_rx_freeze ( struct net_device *netdev ); extern void netdev_rx_unfreeze ( struct net_device *netdev ); extern void netdev_link_err ( struct net_device *netdev, int rc ); diff --git a/src/interface/efi/efi_snp.c b/src/interface/efi/efi_snp.c index c4f7d4ea8..8443be997 100644 --- a/src/interface/efi/efi_snp.c +++ b/src/interface/efi/efi_snp.c @@ -1777,9 +1777,10 @@ static struct efi_snp_device * efi_snp_demux ( struct net_device *netdev ) { * Create SNP device * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int efi_snp_probe ( struct net_device *netdev ) { +static int efi_snp_probe ( struct net_device *netdev, void *priv __unused ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_device *efidev; struct efi_snp_device *snpdev; @@ -2017,8 +2018,9 @@ static int efi_snp_probe ( struct net_device *netdev ) { * Handle SNP device or link state change * * @v netdev Network device + * @v priv Private data */ -static void efi_snp_notify ( struct net_device *netdev ) { +static void efi_snp_notify ( struct net_device *netdev, void *priv __unused ) { struct efi_snp_device *snpdev; /* Locate SNP device */ @@ -2042,8 +2044,9 @@ static void efi_snp_notify ( struct net_device *netdev ) { * Destroy SNP device * * @v netdev Network device + * @v priv Private data */ -static void efi_snp_remove ( struct net_device *netdev ) { +static void efi_snp_remove ( struct net_device *netdev, void *priv __unused ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_snp_device *snpdev; int leak = efi_shutdown_in_progress; diff --git a/src/net/fcoe.c b/src/net/fcoe.c index f910eeead..70804dd03 100644 --- a/src/net/fcoe.c +++ b/src/net/fcoe.c @@ -1110,9 +1110,10 @@ static void fcoe_expired ( struct retry_timer *timer, int over __unused ) { * Create FCoE port * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int fcoe_probe ( struct net_device *netdev ) { +static int fcoe_probe ( struct net_device *netdev, void *priv __unused ) { struct ll_protocol *ll_protocol = netdev->ll_protocol; struct fcoe_port *fcoe; int rc; @@ -1162,8 +1163,9 @@ static int fcoe_probe ( struct net_device *netdev ) { * Handle FCoE port device or link state change * * @v netdev Network device + * @v priv Private data */ -static void fcoe_notify ( struct net_device *netdev ) { +static void fcoe_notify ( struct net_device *netdev, void *priv __unused ) { struct fcoe_port *fcoe; /* Sanity check */ @@ -1185,8 +1187,9 @@ static void fcoe_notify ( struct net_device *netdev ) { * Destroy FCoE port * * @v netdev Network device + * @v priv Private data */ -static void fcoe_remove ( struct net_device *netdev ) { +static void fcoe_remove ( struct net_device *netdev, void *priv __unused ) { struct fcoe_port *fcoe; /* Sanity check */ diff --git a/src/net/infiniband/xsigo.c b/src/net/infiniband/xsigo.c index 4f5c618d7..5e805fa02 100644 --- a/src/net/infiniband/xsigo.c +++ b/src/net/infiniband/xsigo.c @@ -1829,8 +1829,10 @@ struct ib_driver xsigo_ib_driver __ib_driver = { * Handle device or link status change * * @v netdev Network device + * @v priv Private data */ -static void xsigo_net_notify ( struct net_device *netdev ) { +static void xsigo_net_notify ( struct net_device *netdev, + void *priv __unused ) { struct xsigo_device *xdev; struct ib_device *ibdev; struct xsigo_manager *xcm; diff --git a/src/net/ipv6.c b/src/net/ipv6.c index ef5e51daa..a0173dfb1 100644 --- a/src/net/ipv6.c +++ b/src/net/ipv6.c @@ -1224,9 +1224,11 @@ struct ipv6_settings { * Register IPv6 link-local address settings * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int ipv6_register_settings ( struct net_device *netdev ) { +static int ipv6_register_settings ( struct net_device *netdev, + void *priv __unused ) { struct settings *parent = netdev_settings ( netdev ); struct ipv6_settings *ipv6set; int rc; diff --git a/src/net/lldp.c b/src/net/lldp.c index 72e3ecdf6..2ef32cb0c 100644 --- a/src/net/lldp.c +++ b/src/net/lldp.c @@ -296,9 +296,10 @@ struct net_protocol lldp_protocol __net_protocol = { * Create LLDP settings block * * @v netdev Network device + * @v priv Private data * @ret rc Return status code */ -static int lldp_probe ( struct net_device *netdev ) { +static int lldp_probe ( struct net_device *netdev, void *priv __unused ) { struct lldp_settings *lldpset; int rc; diff --git a/src/net/neighbour.c b/src/net/neighbour.c index 7f66d9992..13a8bc3ba 100644 --- a/src/net/neighbour.c +++ b/src/net/neighbour.c @@ -383,8 +383,9 @@ int neighbour_define ( struct net_device *netdev, * Update neighbour cache on network device state change or removal * * @v netdev Network device + * @v priv Private data */ -static void neighbour_flush ( struct net_device *netdev ) { +static void neighbour_flush ( struct net_device *netdev, void *priv __unused ) { struct neighbour *neighbour; struct neighbour *tmp; diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 915178218..a9ed18134 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -109,6 +109,51 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) { return 0; } +/** + * Get offset of network device driver private data + * + * @v driver Upper-layer driver, or NULL for device driver + * @ret offset Offset of driver private data + */ +static size_t netdev_priv_offset ( struct net_driver *driver ) { + struct net_device *netdev; + unsigned int num_configs; + size_t offset; + + /* Allow space for network device */ + offset = sizeof ( *netdev ); + + /* Allow space for configurations */ + num_configs = table_num_entries ( NET_DEVICE_CONFIGURATORS ); + offset += ( num_configs * sizeof ( netdev->configs[0] ) ); + + /* Place variable-length device driver private data at end */ + if ( ! driver ) + driver = table_end ( NET_DRIVERS ); + + /* Allow space for preceding upper-layer drivers' private data */ + for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) { + offset += driver->priv_len; + } + + /* Sanity check */ + assert ( ( offset & ( sizeof ( void * ) - 1 ) ) == 0 ); + + return offset; +} + +/** + * Get network device driver private data + * + * @v netdev Network device + * @v driver Upper-layer driver, or NULL for device driver + * @ret priv Driver private data + */ +void * netdev_priv ( struct net_device *netdev, struct net_driver *driver ) { + + return ( ( ( void * ) netdev ) + netdev_priv_offset ( driver ) ); +} + /** * Notify drivers of network device or link state change * @@ -116,10 +161,12 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) { */ static void netdev_notify ( struct net_device *netdev ) { struct net_driver *driver; + void *priv; for_each_table_entry ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->notify ) - driver->notify ( netdev ); + driver->notify ( netdev, priv ); } } @@ -675,14 +722,8 @@ struct net_device * alloc_netdev ( size_t priv_len ) { struct net_device *netdev; struct net_device_configurator *configurator; struct net_device_configuration *config; - unsigned int num_configs; - size_t confs_len; - size_t total_len; - num_configs = table_num_entries ( NET_DEVICE_CONFIGURATORS ); - confs_len = ( num_configs * sizeof ( netdev->configs[0] ) ); - total_len = ( sizeof ( *netdev ) + confs_len + priv_len ); - netdev = zalloc ( total_len ); + netdev = zalloc ( netdev_priv_offset ( NULL ) + priv_len ); if ( netdev ) { ref_init ( &netdev->refcnt, free_netdev ); netdev->link_rc = -EUNKNOWN_LINK_STATUS; @@ -701,8 +742,7 @@ struct net_device * alloc_netdev ( size_t priv_len ) { &netdev->refcnt ); config++; } - netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) + - confs_len ); + netdev->priv = netdev_priv ( netdev, NULL ); } return netdev; } @@ -722,6 +762,7 @@ int register_netdev ( struct net_device *netdev ) { struct net_device *duplicate; unsigned int i; uint32_t seed; + void *priv; int rc; /* Set initial link-layer address, if not already set */ @@ -784,7 +825,9 @@ int register_netdev ( struct net_device *netdev ) { /* Probe device */ for_each_table_entry ( driver, NET_DRIVERS ) { - if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) { + priv = netdev_priv ( netdev, driver ); + if ( driver->probe && + ( rc = driver->probe ( netdev, priv ) ) != 0 ) { DBGC ( netdev, "NETDEV %s could not add %s device: " "%s\n", netdev->name, driver->name, strerror ( rc ) ); @@ -796,8 +839,9 @@ int register_netdev ( struct net_device *netdev ) { err_probe: for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->remove ) - driver->remove ( netdev ); + driver->remove ( netdev, priv ); } clear_settings ( netdev_settings ( netdev ) ); unregister_settings ( netdev_settings ( netdev ) ); @@ -896,14 +940,16 @@ void netdev_close ( struct net_device *netdev ) { */ void unregister_netdev ( struct net_device *netdev ) { struct net_driver *driver; + void *priv; /* Ensure device is closed */ netdev_close ( netdev ); /* Remove device */ for_each_table_entry_reverse ( driver, NET_DRIVERS ) { + priv = netdev_priv ( netdev, driver ); if ( driver->remove ) - driver->remove ( netdev ); + driver->remove ( netdev, priv ); } /* Unregister per-netdev configuration settings */ diff --git a/src/net/vlan.c b/src/net/vlan.c index d73a95711..c61bb850e 100644 --- a/src/net/vlan.c +++ b/src/net/vlan.c @@ -470,9 +470,10 @@ void vlan_auto ( const void *ll_addr, unsigned int tag ) { * Create automatic VLAN device * * @v trunk Trunk network device + * @v priv Private data * @ret rc Return status code */ -static int vlan_probe ( struct net_device *trunk ) { +static int vlan_probe ( struct net_device *trunk, void *priv __unused ) { int rc; /* Do nothing unless an automatic VLAN exists */ @@ -498,8 +499,9 @@ static int vlan_probe ( struct net_device *trunk ) { * Handle trunk network device link state change * * @v trunk Trunk network device + * @v priv Private data */ -static void vlan_notify ( struct net_device *trunk ) { +static void vlan_notify ( struct net_device *trunk, void *priv __unused ) { struct net_device *netdev; struct vlan_device *vlan; @@ -538,8 +540,9 @@ static int vlan_remove_first ( struct net_device *trunk ) { * Destroy all VLAN devices for a given trunk * * @v trunk Trunk network device + * @v priv Private data */ -static void vlan_remove ( struct net_device *trunk ) { +static void vlan_remove ( struct net_device *trunk, void *priv __unused ) { /* Remove all VLAN devices attached to this trunk, safe * against arbitrary net device removal. -- cgit v1.2.3-55-g7522 From 8cbf248198f3bc66c52b2340b4decf293af8af47 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 13 Sep 2023 22:43:24 +0100 Subject: [vmware] Use driver-private data to hold GuestInfo settings block Simplify the per-netdevice GuestInfo settings code by using driver-private data to hold the settings block, instead of using a separate allocation. The settings block (if existent) will be automatically unregistered when the parent network device settings block is unregistered, and no longer needs to be separately freed. The guestinfo_net_remove() function may therefore be omitted completely. Signed-off-by: Michael Brown --- src/arch/x86/interface/vmware/guestinfo.c | 48 +++++-------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) (limited to 'src/arch') diff --git a/src/arch/x86/interface/vmware/guestinfo.c b/src/arch/x86/interface/vmware/guestinfo.c index b52c2e87b..4134515c1 100644 --- a/src/arch/x86/interface/vmware/guestinfo.c +++ b/src/arch/x86/interface/vmware/guestinfo.c @@ -210,66 +210,32 @@ struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL ) = { * @v priv Private data * @ret rc Return status code */ -static int guestinfo_net_probe ( struct net_device *netdev, - void *priv __unused ) { - struct settings *settings; +static int guestinfo_net_probe ( struct net_device *netdev, void *priv ) { + struct settings *settings = priv; int rc; /* Do nothing unless we have a GuestInfo channel available */ if ( guestinfo_channel < 0 ) return 0; - /* Allocate and initialise settings block */ - settings = zalloc ( sizeof ( *settings ) ); - if ( ! settings ) { - rc = -ENOMEM; - goto err_alloc; - } - settings_init ( settings, &guestinfo_settings_operations, NULL, NULL ); - - /* Register settings */ + /* Initialise and register settings */ + settings_init ( settings, &guestinfo_settings_operations, + &netdev->refcnt, NULL ); if ( ( rc = register_settings ( settings, netdev_settings ( netdev ), "vmware" ) ) != 0 ) { DBGC ( settings, "GuestInfo %p could not register for %s: %s\n", settings, netdev->name, strerror ( rc ) ); - goto err_register; + return rc; } DBGC ( settings, "GuestInfo %p registered for %s\n", settings, netdev->name ); return 0; - - err_register: - free ( settings ); - err_alloc: - return rc; -} - -/** - * Remove per-netdevice GuestInfo settings - * - * @v netdev Network device - * @v priv Private data - */ -static void guestinfo_net_remove ( struct net_device *netdev, - void *priv __unused ) { - struct settings *parent = netdev_settings ( netdev ); - struct settings *settings; - - list_for_each_entry ( settings, &parent->children, siblings ) { - if ( settings->op == &guestinfo_settings_operations ) { - DBGC ( settings, "GuestInfo %p unregistered for %s\n", - settings, netdev->name ); - unregister_settings ( settings ); - free ( settings ); - return; - } - } } /** GuestInfo per-netdevice driver */ struct net_driver guestinfo_net_driver __net_driver = { .name = "GuestInfo", + .priv_len = sizeof ( struct settings ), .probe = guestinfo_net_probe, - .remove = guestinfo_net_remove, }; -- cgit v1.2.3-55-g7522